1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
11 #define ENA_MAX_NUM_IO_QUEUES 128U
12 /* We need to queues for each IO (on for Tx and one for Rx) */
13 #define ENA_TOTAL_NUM_QUEUES (2 * (ENA_MAX_NUM_IO_QUEUES))
15 #define ENA_MAX_HANDLERS 256
17 #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48
20 #define ENA_REG_READ_TIMEOUT 200000
22 #define ADMIN_SQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aq_entry))
23 #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry))
24 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
26 /*****************************************************************************/
27 /*****************************************************************************/
28 /* ENA adaptive interrupt moderation settings */
30 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS ENA_INTR_INITIAL_TX_INTERVAL_USECS_PLAT
31 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0
32 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
34 #define ENA_HASH_KEY_SIZE 40
36 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
38 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
40 struct ena_llq_configurations {
41 enum ena_admin_llq_header_location llq_header_location;
42 enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
43 enum ena_admin_llq_stride_ctrl llq_stride_ctrl;
44 enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
45 u16 llq_ring_entry_size_value;
48 enum queue_direction {
49 ENA_COM_IO_QUEUE_DIRECTION_TX,
50 ENA_COM_IO_QUEUE_DIRECTION_RX
54 dma_addr_t paddr; /**< Buffer physical address */
55 u16 len; /**< Buffer length in bytes */
58 struct ena_com_rx_buf_info {
63 struct ena_com_io_desc_addr {
64 u8 __iomem *pbuf_dev_addr; /* LLQ address */
67 ena_mem_handle_t mem_handle;
70 struct ena_com_tx_meta {
74 u16 l4_hdr_len; /* In words */
77 struct ena_com_llq_info {
78 u16 header_location_ctrl;
80 u16 desc_list_entry_size_ctrl;
81 u16 desc_list_entry_size;
82 u16 descs_num_before_header;
84 u16 max_entries_in_tx_burst;
87 struct ena_com_io_cq {
88 struct ena_com_io_desc_addr cdesc_addr;
91 /* Interrupt unmask register */
92 u32 __iomem *unmask_reg;
94 /* The completion queue head doorbell register */
95 u32 __iomem *cq_head_db_reg;
97 /* numa configuration register (for TPH) */
98 u32 __iomem *numa_node_cfg_reg;
100 /* The value to write to the above register to unmask
101 * the interrupt of this queue
105 enum queue_direction direction;
107 /* holds the number of cdesc of the current packet */
108 u16 cur_rx_pkt_cdesc_count;
109 /* save the firt cdesc idx of the current packet */
110 u16 cur_rx_pkt_cdesc_start_idx;
116 /* Device queue index */
119 u16 last_head_update;
121 u8 cdesc_entry_size_in_bytes;
123 } ____cacheline_aligned;
125 struct ena_com_io_bounce_buffer_control {
129 u16 buffers_num; /* Must be a power of 2 */
132 /* This struct is to keep tracking the current location of the next llq entry */
133 struct ena_com_llq_pkt_ctrl {
136 u16 descs_left_in_line;
139 struct ena_com_io_sq {
140 struct ena_com_io_desc_addr desc_addr;
143 u32 __iomem *db_addr;
144 u8 __iomem *header_addr;
146 enum queue_direction direction;
147 enum ena_admin_placement_policy_type mem_queue_type;
150 struct ena_com_tx_meta cached_tx_meta;
151 struct ena_com_llq_info llq_info;
152 struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
153 struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
161 u16 llq_last_copy_tail;
162 u32 tx_max_header_size;
166 u16 entries_in_tx_burst_left;
167 } ____cacheline_aligned;
169 struct ena_com_admin_cq {
170 struct ena_admin_acq_entry *entries;
171 ena_mem_handle_t mem_handle;
178 struct ena_com_admin_sq {
179 struct ena_admin_aq_entry *entries;
180 ena_mem_handle_t mem_handle;
183 u32 __iomem *db_addr;
191 struct ena_com_stats_admin {
199 struct ena_com_admin_queue {
202 ena_spinlock_t q_lock; /* spinlock for the admin queue */
204 struct ena_comp_ctx *comp_ctx;
205 u32 completion_timeout;
207 struct ena_com_admin_cq cq;
208 struct ena_com_admin_sq sq;
210 /* Indicate if the admin queue should poll for completion */
213 /* Define if fallback to polling mode should occur */
218 /* Indicate that the ena was initialized and can
219 * process new admin commands
223 /* Count the number of outstanding admin commands */
224 ena_atomic32_t outstanding_cmds;
226 struct ena_com_stats_admin stats;
229 struct ena_aenq_handlers;
231 struct ena_com_aenq {
234 struct ena_admin_aenq_entry *entries;
236 ena_mem_handle_t mem_handle;
238 struct ena_aenq_handlers *aenq_handlers;
241 struct ena_com_mmio_read {
242 struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
243 dma_addr_t read_resp_dma_addr;
244 ena_mem_handle_t read_resp_mem_handle;
245 u32 reg_read_to; /* in us */
247 bool readless_supported;
248 /* spin lock to ensure a single outstanding read */
254 u16 *host_rss_ind_tbl;
255 struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
256 dma_addr_t rss_ind_tbl_dma_addr;
257 ena_mem_handle_t rss_ind_tbl_mem_handle;
261 enum ena_admin_hash_functions hash_func;
262 struct ena_admin_feature_rss_flow_hash_control *hash_key;
263 dma_addr_t hash_key_dma_addr;
264 ena_mem_handle_t hash_key_mem_handle;
268 struct ena_admin_feature_rss_hash_control *hash_ctrl;
269 dma_addr_t hash_ctrl_dma_addr;
270 ena_mem_handle_t hash_ctrl_mem_handle;
274 struct ena_host_attribute {
276 u8 *debug_area_virt_addr;
277 dma_addr_t debug_area_dma_addr;
278 ena_mem_handle_t debug_area_dma_handle;
281 /* Host information */
282 struct ena_admin_host_info *host_info;
283 dma_addr_t host_info_dma_addr;
284 ena_mem_handle_t host_info_dma_handle;
287 struct ena_extra_properties_strings {
290 ena_mem_handle_t dma_handle;
294 /* Each ena_dev is a PCI function. */
296 struct ena_com_admin_queue admin_queue;
297 struct ena_com_aenq aenq;
298 struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
299 struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
301 void __iomem *mem_bar;
305 enum ena_admin_placement_policy_type tx_mem_queue_type;
306 u32 tx_max_header_size;
307 u16 stats_func; /* Selected function for extended statistic dump */
308 u16 stats_queue; /* Selected queue for extended statistic dump */
310 struct ena_com_mmio_read mmio_read;
313 u32 supported_features;
316 struct ena_host_attribute host_attr;
317 bool adaptive_coalescing;
318 u16 intr_delay_resolution;
320 /* interrupt moderation intervals are in usec divided by
321 * intr_delay_resolution, which is supplied by the device.
323 u32 intr_moder_tx_interval;
324 u32 intr_moder_rx_interval;
326 struct ena_intr_moder_entry *intr_moder_tbl;
328 struct ena_com_llq_info llq_info;
329 struct ena_extra_properties_strings extra_properties_strings;
332 struct ena_com_dev_get_features_ctx {
333 struct ena_admin_queue_feature_desc max_queues;
334 struct ena_admin_queue_ext_feature_desc max_queue_ext;
335 struct ena_admin_device_attr_feature_desc dev_attr;
336 struct ena_admin_feature_aenq_desc aenq;
337 struct ena_admin_feature_offload_desc offload;
338 struct ena_admin_ena_hw_hints hw_hints;
339 struct ena_admin_feature_llq_desc llq;
340 struct ena_admin_feature_rss_ind_table ind_table;
343 struct ena_com_create_io_ctx {
344 enum ena_admin_placement_policy_type mem_queue_type;
345 enum queue_direction direction;
352 typedef void (*ena_aenq_handler)(void *data,
353 struct ena_admin_aenq_entry *aenq_e);
355 /* Holds aenq handlers. Indexed by AENQ event group */
356 struct ena_aenq_handlers {
357 ena_aenq_handler handlers[ENA_MAX_HANDLERS];
358 ena_aenq_handler unimplemented_handler;
361 /*****************************************************************************/
362 /*****************************************************************************/
363 #if defined(__cplusplus)
367 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
368 * @ena_dev: ENA communication layer struct
370 * Initialize the register read mechanism.
372 * @note: This method must be the first stage in the initialization sequence.
374 * @return - 0 on success, negative value on failure.
376 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
378 /* ena_com_set_mmio_read_mode - Enable/disable the mmio reg read mechanism
379 * @ena_dev: ENA communication layer struct
380 * @readless_supported: readless mode (enable/disable)
382 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
383 bool readless_supported);
385 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
386 * value physical address.
387 * @ena_dev: ENA communication layer struct
389 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
391 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
392 * @ena_dev: ENA communication layer struct
394 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
396 /* ena_com_admin_init - Init the admin and the async queues
397 * @ena_dev: ENA communication layer struct
398 * @aenq_handlers: Those handlers to be called upon event.
400 * Initialize the admin submission and completion queues.
401 * Initialize the asynchronous events notification queues.
403 * @return - 0 on success, negative value on failure.
405 int ena_com_admin_init(struct ena_com_dev *ena_dev,
406 struct ena_aenq_handlers *aenq_handlers);
408 /* ena_com_admin_destroy - Destroy the admin and the async events queues.
409 * @ena_dev: ENA communication layer struct
411 * @note: Before calling this method, the caller must validate that the device
412 * won't send any additional admin completions/aenq.
413 * To achieve that, a FLR is recommended.
415 void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
417 /* ena_com_dev_reset - Perform device FLR to the device.
418 * @ena_dev: ENA communication layer struct
419 * @reset_reason: Specify what is the trigger for the reset in case of an error.
421 * @return - 0 on success, negative value on failure.
423 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
424 enum ena_regs_reset_reason_types reset_reason);
426 /* ena_com_create_io_queue - Create io queue.
427 * @ena_dev: ENA communication layer struct
428 * @ctx - create context structure
430 * Create the submission and the completion queues.
432 * @return - 0 on success, negative value on failure.
434 int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
435 struct ena_com_create_io_ctx *ctx);
437 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
438 * @ena_dev: ENA communication layer struct
439 * @qid - the caller virtual queue id.
441 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
443 /* ena_com_get_io_handlers - Return the io queue handlers
444 * @ena_dev: ENA communication layer struct
445 * @qid - the caller virtual queue id.
446 * @io_sq - IO submission queue handler
447 * @io_cq - IO completion queue handler.
449 * @return - 0 on success, negative value on failure.
451 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
452 struct ena_com_io_sq **io_sq,
453 struct ena_com_io_cq **io_cq);
455 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
456 * @ena_dev: ENA communication layer struct
458 * After this method, aenq event can be received via AENQ.
460 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
462 /* ena_com_set_admin_running_state - Set the state of the admin queue
463 * @ena_dev: ENA communication layer struct
465 * Change the state of the admin queue (enable/disable)
467 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
469 /* ena_com_get_admin_running_state - Get the admin queue state
470 * @ena_dev: ENA communication layer struct
472 * Retrieve the state of the admin queue (enable/disable)
474 * @return - current polling mode (enable/disable)
476 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
478 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
479 * @ena_dev: ENA communication layer struct
480 * @polling: ENAble/Disable polling mode
482 * Set the admin completion mode.
484 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
486 /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
487 * @ena_dev: ENA communication layer struct
489 * Get the admin completion mode.
490 * If polling mode is on, ena_com_execute_admin_command will perform a
491 * polling on the admin completion queue for the commands completion,
492 * otherwise it will wait on wait event.
496 bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
498 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
499 * @ena_dev: ENA communication layer struct
500 * @polling: Enable/Disable polling mode
502 * Set the autopolling mode.
503 * If autopolling is on:
504 * In case of missing interrupt when data is available switch to polling.
506 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
509 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
510 * @ena_dev: ENA communication layer struct
512 * This method go over the admin completion queue and wake up all the pending
513 * threads that wait on the commands wait event.
515 * @note: Should be called after MSI-X interrupt.
517 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
519 /* ena_com_aenq_intr_handler - AENQ interrupt handler
520 * @ena_dev: ENA communication layer struct
522 * This method go over the async event notification queue and call the proper
525 void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data);
527 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
528 * @ena_dev: ENA communication layer struct
530 * This method aborts all the outstanding admin commands.
531 * The caller should then call ena_com_wait_for_abort_completion to make sure
532 * all the commands were completed.
534 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
536 /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
537 * @ena_dev: ENA communication layer struct
539 * This method wait until all the outstanding admin commands will be completed.
541 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
543 /* ena_com_validate_version - Validate the device parameters
544 * @ena_dev: ENA communication layer struct
546 * This method validate the device parameters are the same as the saved
547 * parameters in ena_dev.
548 * This method is useful after device reset, to validate the device mac address
549 * and the device offloads are the same as before the reset.
551 * @return - 0 on success negative value otherwise.
553 int ena_com_validate_version(struct ena_com_dev *ena_dev);
555 /* ena_com_get_link_params - Retrieve physical link parameters.
556 * @ena_dev: ENA communication layer struct
557 * @resp: Link parameters
559 * Retrieve the physical link parameters,
560 * like speed, auto-negotiation and full duplex support.
562 * @return - 0 on Success negative value otherwise.
564 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
565 struct ena_admin_get_feat_resp *resp);
567 /* ena_com_extra_properties_strings_init - Initialize the extra properties strings buffer.
568 * @ena_dev: ENA communication layer struct
570 * Initialize the extra properties strings buffer.
572 int ena_com_extra_properties_strings_init(struct ena_com_dev *ena_dev);
574 /* ena_com_delete_extra_properties_strings - Free the extra properties strings buffer.
575 * @ena_dev: ENA communication layer struct
577 * Free the allocated extra properties strings buffer.
579 void ena_com_delete_extra_properties_strings(struct ena_com_dev *ena_dev);
581 /* ena_com_get_extra_properties_flags - Retrieve extra properties flags.
582 * @ena_dev: ENA communication layer struct
583 * @resp: Extra properties flags.
585 * Retrieve the extra properties flags.
587 * @return - 0 on Success negative value otherwise.
589 int ena_com_get_extra_properties_flags(struct ena_com_dev *ena_dev,
590 struct ena_admin_get_feat_resp *resp);
592 /* ena_com_get_dma_width - Retrieve physical dma address width the device
594 * @ena_dev: ENA communication layer struct
596 * Retrieve the maximum physical address bits the device can handle.
598 * @return: > 0 on Success and negative value otherwise.
600 int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
602 /* ena_com_set_aenq_config - Set aenq groups configurations
603 * @ena_dev: ENA communication layer struct
604 * @groups flag: bit fields flags of enum ena_admin_aenq_group.
606 * Configure which aenq event group the driver would like to receive.
608 * @return: 0 on Success and negative value otherwise.
610 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
612 /* ena_com_get_dev_attr_feat - Get device features
613 * @ena_dev: ENA communication layer struct
614 * @get_feat_ctx: returned context that contain the get features.
616 * @return: 0 on Success and negative value otherwise.
618 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
619 struct ena_com_dev_get_features_ctx *get_feat_ctx);
621 /* ena_com_get_dev_basic_stats - Get device basic statistics
622 * @ena_dev: ENA communication layer struct
623 * @stats: stats return value
625 * @return: 0 on Success and negative value otherwise.
627 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
628 struct ena_admin_basic_stats *stats);
630 /* ena_com_set_dev_mtu - Configure the device mtu.
631 * @ena_dev: ENA communication layer struct
634 * @return: 0 on Success and negative value otherwise.
636 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
638 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
639 * @ena_dev: ENA communication layer struct
640 * @offlad: offload return value
642 * @return: 0 on Success and negative value otherwise.
644 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
645 struct ena_admin_feature_offload_desc *offload);
647 /* ena_com_rss_init - Init RSS
648 * @ena_dev: ENA communication layer struct
649 * @log_size: indirection log size
651 * Allocate RSS/RFS resources.
652 * The caller then can configure rss using ena_com_set_hash_function,
653 * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
655 * @return: 0 on Success and negative value otherwise.
657 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
659 /* ena_com_rss_destroy - Destroy rss
660 * @ena_dev: ENA communication layer struct
662 * Free all the RSS/RFS resources.
664 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
666 /* ena_com_fill_hash_function - Fill RSS hash function
667 * @ena_dev: ENA communication layer struct
668 * @func: The hash function (Toeplitz or crc)
669 * @key: Hash key (for toeplitz hash)
670 * @key_len: key length (max length 10 DW)
671 * @init_val: initial value for the hash function
673 * Fill the ena_dev resources with the desire hash function, hash key, key_len
674 * and key initial value (if needed by the hash function).
675 * To flush the key into the device the caller should call
676 * ena_com_set_hash_function.
678 * @return: 0 on Success and negative value otherwise.
680 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
681 enum ena_admin_hash_functions func,
682 const u8 *key, u16 key_len, u32 init_val);
684 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
686 * @ena_dev: ENA communication layer struct
688 * Flush the hash function and it dependencies (key, key length and
689 * initial value) if needed.
691 * @note: Prior to this method the caller should call ena_com_fill_hash_function
693 * @return: 0 on Success and negative value otherwise.
695 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
697 /* ena_com_get_hash_function - Retrieve the hash function and the hash key
699 * @ena_dev: ENA communication layer struct
700 * @func: hash function
703 * Retrieve the hash function and the hash key from the device.
705 * @note: If the caller called ena_com_fill_hash_function but didn't flash
706 * it to the device, the new configuration will be lost.
708 * @return: 0 on Success and negative value otherwise.
710 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
711 enum ena_admin_hash_functions *func,
714 /* ena_com_fill_hash_ctrl - Fill RSS hash control
715 * @ena_dev: ENA communication layer struct.
716 * @proto: The protocol to configure.
717 * @hash_fields: bit mask of ena_admin_flow_hash_fields
719 * Fill the ena_dev resources with the desire hash control (the ethernet
720 * fields that take part of the hash) for a specific protocol.
721 * To flush the hash control to the device, the caller should call
722 * ena_com_set_hash_ctrl.
724 * @return: 0 on Success and negative value otherwise.
726 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
727 enum ena_admin_flow_hash_proto proto,
730 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
731 * @ena_dev: ENA communication layer struct
733 * Flush the hash control (the ethernet fields that take part of the hash)
735 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
737 * @return: 0 on Success and negative value otherwise.
739 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
741 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
742 * @ena_dev: ENA communication layer struct
743 * @proto: The protocol to retrieve.
744 * @fields: bit mask of ena_admin_flow_hash_fields.
746 * Retrieve the hash control from the device.
748 * @note, If the caller called ena_com_fill_hash_ctrl but didn't flash
749 * it to the device, the new configuration will be lost.
751 * @return: 0 on Success and negative value otherwise.
753 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
754 enum ena_admin_flow_hash_proto proto,
757 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
759 * @ena_dev: ENA communication layer struct
761 * Fill the ena_dev resources with the default hash control configuration.
762 * To flush the hash control to the device, the caller should call
763 * ena_com_set_hash_ctrl.
765 * @return: 0 on Success and negative value otherwise.
767 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
769 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
771 * @ena_dev: ENA communication layer struct.
772 * @entry_idx - indirection table entry.
773 * @entry_value - redirection value
775 * Fill a single entry of the RSS indirection table in the ena_dev resources.
776 * To flush the indirection table to the device, the called should call
777 * ena_com_indirect_table_set.
779 * @return: 0 on Success and negative value otherwise.
781 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
782 u16 entry_idx, u16 entry_value);
784 /* ena_com_indirect_table_set - Flush the indirection table to the device.
785 * @ena_dev: ENA communication layer struct
787 * Flush the indirection hash control to the device.
788 * Prior to this method the caller should call ena_com_indirect_table_fill_entry
790 * @return: 0 on Success and negative value otherwise.
792 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
794 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
795 * @ena_dev: ENA communication layer struct
796 * @ind_tbl: indirection table
798 * Retrieve the RSS indirection table from the device.
800 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flash
801 * it to the device, the new configuration will be lost.
803 * @return: 0 on Success and negative value otherwise.
805 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
807 /* ena_com_allocate_host_info - Allocate host info resources.
808 * @ena_dev: ENA communication layer struct
810 * @return: 0 on Success and negative value otherwise.
812 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
814 /* ena_com_allocate_debug_area - Allocate debug area.
815 * @ena_dev: ENA communication layer struct
816 * @debug_area_size - debug area size.
818 * @return: 0 on Success and negative value otherwise.
820 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
821 u32 debug_area_size);
823 /* ena_com_delete_debug_area - Free the debug area resources.
824 * @ena_dev: ENA communication layer struct
826 * Free the allocate debug area.
828 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
830 /* ena_com_delete_host_info - Free the host info resources.
831 * @ena_dev: ENA communication layer struct
833 * Free the allocate host info.
835 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
837 /* ena_com_set_host_attributes - Update the device with the host
838 * attributes (debug area and host info) base address.
839 * @ena_dev: ENA communication layer struct
841 * @return: 0 on Success and negative value otherwise.
843 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
845 /* ena_com_create_io_cq - Create io completion queue.
846 * @ena_dev: ENA communication layer struct
847 * @io_cq - io completion queue handler
849 * Create IO completion queue.
851 * @return - 0 on success, negative value on failure.
853 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
854 struct ena_com_io_cq *io_cq);
856 /* ena_com_destroy_io_cq - Destroy io completion queue.
857 * @ena_dev: ENA communication layer struct
858 * @io_cq - io completion queue handler
860 * Destroy IO completion queue.
862 * @return - 0 on success, negative value on failure.
864 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
865 struct ena_com_io_cq *io_cq);
867 /* ena_com_execute_admin_command - Execute admin command
868 * @admin_queue: admin queue.
869 * @cmd: the admin command to execute.
870 * @cmd_size: the command size.
871 * @cmd_completion: command completion return value.
872 * @cmd_comp_size: command completion size.
874 * Submit an admin command and then wait until the device will return a
876 * The completion will be copyed into cmd_comp.
878 * @return - 0 on success, negative value on failure.
880 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
881 struct ena_admin_aq_entry *cmd,
883 struct ena_admin_acq_entry *cmd_comp,
884 size_t cmd_comp_size);
886 /* ena_com_init_interrupt_moderation - Init interrupt moderation
887 * @ena_dev: ENA communication layer struct
889 * @return - 0 on success, negative value on failure.
891 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
893 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
894 * capability is supported by the device.
896 * @return - supported or not.
898 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
900 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
901 * non-adaptive interval in Tx direction.
902 * @ena_dev: ENA communication layer struct
903 * @tx_coalesce_usecs: Interval in usec.
905 * @return - 0 on success, negative value on failure.
907 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
908 u32 tx_coalesce_usecs);
910 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
911 * non-adaptive interval in Rx direction.
912 * @ena_dev: ENA communication layer struct
913 * @rx_coalesce_usecs: Interval in usec.
915 * @return - 0 on success, negative value on failure.
917 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
918 u32 rx_coalesce_usecs);
920 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
921 * non-adaptive interval in Tx direction.
922 * @ena_dev: ENA communication layer struct
924 * @return - interval in usec
926 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
928 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
929 * non-adaptive interval in Rx direction.
930 * @ena_dev: ENA communication layer struct
932 * @return - interval in usec
934 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
936 /* ena_com_config_dev_mode - Configure the placement policy of the device.
937 * @ena_dev: ENA communication layer struct
938 * @llq_features: LLQ feature descriptor, retrieve via
939 * ena_com_get_dev_attr_feat.
940 * @ena_llq_config: The default driver LLQ parameters configurations
942 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
943 struct ena_admin_feature_llq_desc *llq_features,
944 struct ena_llq_configurations *llq_default_config);
946 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
948 return ena_dev->adaptive_coalescing;
951 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
953 ena_dev->adaptive_coalescing = true;
956 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
958 ena_dev->adaptive_coalescing = false;
961 /* ena_com_update_intr_reg - Prepare interrupt register
962 * @intr_reg: interrupt register to update.
963 * @rx_delay_interval: Rx interval in usecs
964 * @tx_delay_interval: Tx interval in usecs
965 * @unmask: unask enable/disable
967 * Prepare interrupt update register with the supplied parameters.
969 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
970 u32 rx_delay_interval,
971 u32 tx_delay_interval,
974 intr_reg->intr_control = 0;
975 intr_reg->intr_control |= rx_delay_interval &
976 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
978 intr_reg->intr_control |=
979 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
980 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
983 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
986 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
988 u16 size, buffers_num;
991 size = bounce_buf_ctrl->buffer_size;
992 buffers_num = bounce_buf_ctrl->buffers_num;
994 buf = bounce_buf_ctrl->base_buffer +
995 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
997 prefetchw(bounce_buf_ctrl->base_buffer +
998 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1003 #if defined(__cplusplus)
1005 #endif /* __cplusplus */
1006 #endif /* !(ENA_COM) */