4 * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #define ENA_MAX_NUM_IO_QUEUES 128U
40 /* We need to queues for each IO (on for Tx and one for Rx) */
41 #define ENA_TOTAL_NUM_QUEUES (2 * (ENA_MAX_NUM_IO_QUEUES))
43 #define ENA_MAX_HANDLERS 256
45 #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48
48 #define ENA_REG_READ_TIMEOUT 200000
50 #define ADMIN_SQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aq_entry))
51 #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry))
52 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
54 /*****************************************************************************/
55 /*****************************************************************************/
56 /* ENA adaptive interrupt moderation settings */
58 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS ENA_INTR_INITIAL_TX_INTERVAL_USECS_PLAT
59 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0
60 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
62 #define ENA_HASH_KEY_SIZE 40
64 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
66 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
68 struct ena_llq_configurations {
69 enum ena_admin_llq_header_location llq_header_location;
70 enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
71 enum ena_admin_llq_stride_ctrl llq_stride_ctrl;
72 enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
73 u16 llq_ring_entry_size_value;
76 enum queue_direction {
77 ENA_COM_IO_QUEUE_DIRECTION_TX,
78 ENA_COM_IO_QUEUE_DIRECTION_RX
82 dma_addr_t paddr; /**< Buffer physical address */
83 u16 len; /**< Buffer length in bytes */
86 struct ena_com_rx_buf_info {
91 struct ena_com_io_desc_addr {
92 u8 __iomem *pbuf_dev_addr; /* LLQ address */
95 ena_mem_handle_t mem_handle;
98 struct ena_com_tx_meta {
102 u16 l4_hdr_len; /* In words */
105 struct ena_com_llq_info {
106 u16 header_location_ctrl;
107 u16 desc_stride_ctrl;
108 u16 desc_list_entry_size_ctrl;
109 u16 desc_list_entry_size;
110 u16 descs_num_before_header;
112 u16 max_entries_in_tx_burst;
113 bool disable_meta_caching;
116 struct ena_com_io_cq {
117 struct ena_com_io_desc_addr cdesc_addr;
120 /* Interrupt unmask register */
121 u32 __iomem *unmask_reg;
123 /* The completion queue head doorbell register */
124 u32 __iomem *cq_head_db_reg;
126 /* numa configuration register (for TPH) */
127 u32 __iomem *numa_node_cfg_reg;
129 /* The value to write to the above register to unmask
130 * the interrupt of this queue
134 enum queue_direction direction;
136 /* holds the number of cdesc of the current packet */
137 u16 cur_rx_pkt_cdesc_count;
138 /* save the firt cdesc idx of the current packet */
139 u16 cur_rx_pkt_cdesc_start_idx;
145 /* Device queue index */
148 u16 last_head_update;
150 u8 cdesc_entry_size_in_bytes;
152 } ____cacheline_aligned;
154 struct ena_com_io_bounce_buffer_control {
158 u16 buffers_num; /* Must be a power of 2 */
161 /* This struct is to keep tracking the current location of the next llq entry */
162 struct ena_com_llq_pkt_ctrl {
165 u16 descs_left_in_line;
168 struct ena_com_io_sq {
169 struct ena_com_io_desc_addr desc_addr;
172 u32 __iomem *db_addr;
173 u8 __iomem *header_addr;
175 enum queue_direction direction;
176 enum ena_admin_placement_policy_type mem_queue_type;
178 bool disable_meta_caching;
181 struct ena_com_tx_meta cached_tx_meta;
182 struct ena_com_llq_info llq_info;
183 struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
184 struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
192 u16 llq_last_copy_tail;
193 u32 tx_max_header_size;
197 u16 entries_in_tx_burst_left;
198 } ____cacheline_aligned;
200 struct ena_com_admin_cq {
201 struct ena_admin_acq_entry *entries;
202 ena_mem_handle_t mem_handle;
209 struct ena_com_admin_sq {
210 struct ena_admin_aq_entry *entries;
211 ena_mem_handle_t mem_handle;
214 u32 __iomem *db_addr;
222 struct ena_com_stats_admin {
230 struct ena_com_admin_queue {
233 struct ena_com_dev *ena_dev;
234 ena_spinlock_t q_lock; /* spinlock for the admin queue */
236 struct ena_comp_ctx *comp_ctx;
237 u32 completion_timeout;
239 struct ena_com_admin_cq cq;
240 struct ena_com_admin_sq sq;
242 /* Indicate if the admin queue should poll for completion */
245 /* Define if fallback to polling mode should occur */
250 /* Indicate that the ena was initialized and can
251 * process new admin commands
255 /* Count the number of outstanding admin commands */
256 ena_atomic32_t outstanding_cmds;
258 struct ena_com_stats_admin stats;
261 struct ena_aenq_handlers;
263 struct ena_com_aenq {
266 struct ena_admin_aenq_entry *entries;
268 ena_mem_handle_t mem_handle;
270 struct ena_aenq_handlers *aenq_handlers;
273 struct ena_com_mmio_read {
274 struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
275 dma_addr_t read_resp_dma_addr;
276 ena_mem_handle_t read_resp_mem_handle;
277 u32 reg_read_to; /* in us */
279 bool readless_supported;
280 /* spin lock to ensure a single outstanding read */
286 u16 *host_rss_ind_tbl;
287 struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
288 dma_addr_t rss_ind_tbl_dma_addr;
289 ena_mem_handle_t rss_ind_tbl_mem_handle;
293 enum ena_admin_hash_functions hash_func;
294 struct ena_admin_feature_rss_flow_hash_control *hash_key;
295 dma_addr_t hash_key_dma_addr;
296 ena_mem_handle_t hash_key_mem_handle;
300 struct ena_admin_feature_rss_hash_control *hash_ctrl;
301 dma_addr_t hash_ctrl_dma_addr;
302 ena_mem_handle_t hash_ctrl_mem_handle;
306 struct ena_host_attribute {
308 u8 *debug_area_virt_addr;
309 dma_addr_t debug_area_dma_addr;
310 ena_mem_handle_t debug_area_dma_handle;
313 /* Host information */
314 struct ena_admin_host_info *host_info;
315 dma_addr_t host_info_dma_addr;
316 ena_mem_handle_t host_info_dma_handle;
319 /* Each ena_dev is a PCI function. */
321 struct ena_com_admin_queue admin_queue;
322 struct ena_com_aenq aenq;
323 struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
324 struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
326 void __iomem *mem_bar;
330 enum ena_admin_placement_policy_type tx_mem_queue_type;
331 u32 tx_max_header_size;
332 u16 stats_func; /* Selected function for extended statistic dump */
333 u16 stats_queue; /* Selected queue for extended statistic dump */
335 struct ena_com_mmio_read mmio_read;
338 u32 supported_features;
341 struct ena_host_attribute host_attr;
342 bool adaptive_coalescing;
343 u16 intr_delay_resolution;
345 /* interrupt moderation intervals are in usec divided by
346 * intr_delay_resolution, which is supplied by the device.
348 u32 intr_moder_tx_interval;
349 u32 intr_moder_rx_interval;
351 struct ena_intr_moder_entry *intr_moder_tbl;
353 struct ena_com_llq_info llq_info;
355 u32 ena_min_poll_delay_us;
358 struct ena_com_dev_get_features_ctx {
359 struct ena_admin_queue_feature_desc max_queues;
360 struct ena_admin_queue_ext_feature_desc max_queue_ext;
361 struct ena_admin_device_attr_feature_desc dev_attr;
362 struct ena_admin_feature_aenq_desc aenq;
363 struct ena_admin_feature_offload_desc offload;
364 struct ena_admin_ena_hw_hints hw_hints;
365 struct ena_admin_feature_llq_desc llq;
366 struct ena_admin_feature_rss_ind_table ind_table;
369 struct ena_com_create_io_ctx {
370 enum ena_admin_placement_policy_type mem_queue_type;
371 enum queue_direction direction;
378 typedef void (*ena_aenq_handler)(void *data,
379 struct ena_admin_aenq_entry *aenq_e);
381 /* Holds aenq handlers. Indexed by AENQ event group */
382 struct ena_aenq_handlers {
383 ena_aenq_handler handlers[ENA_MAX_HANDLERS];
384 ena_aenq_handler unimplemented_handler;
387 /*****************************************************************************/
388 /*****************************************************************************/
389 #if defined(__cplusplus)
393 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
394 * @ena_dev: ENA communication layer struct
396 * Initialize the register read mechanism.
398 * @note: This method must be the first stage in the initialization sequence.
400 * @return - 0 on success, negative value on failure.
402 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
404 /* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism
405 * @ena_dev: ENA communication layer struct
406 * @readless_supported: readless mode (enable/disable)
408 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
409 bool readless_supported);
411 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
412 * value physical address.
413 * @ena_dev: ENA communication layer struct
415 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
417 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
418 * @ena_dev: ENA communication layer struct
420 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
422 /* ena_com_admin_init - Init the admin and the async queues
423 * @ena_dev: ENA communication layer struct
424 * @aenq_handlers: Those handlers to be called upon event.
426 * Initialize the admin submission and completion queues.
427 * Initialize the asynchronous events notification queues.
429 * @return - 0 on success, negative value on failure.
431 int ena_com_admin_init(struct ena_com_dev *ena_dev,
432 struct ena_aenq_handlers *aenq_handlers);
434 /* ena_com_admin_destroy - Destroy the admin and the async events queues.
435 * @ena_dev: ENA communication layer struct
437 * @note: Before calling this method, the caller must validate that the device
438 * won't send any additional admin completions/aenq.
439 * To achieve that, a FLR is recommended.
441 void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
443 /* ena_com_dev_reset - Perform device FLR to the device.
444 * @ena_dev: ENA communication layer struct
445 * @reset_reason: Specify what is the trigger for the reset in case of an error.
447 * @return - 0 on success, negative value on failure.
449 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
450 enum ena_regs_reset_reason_types reset_reason);
452 /* ena_com_create_io_queue - Create io queue.
453 * @ena_dev: ENA communication layer struct
454 * @ctx - create context structure
456 * Create the submission and the completion queues.
458 * @return - 0 on success, negative value on failure.
460 int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
461 struct ena_com_create_io_ctx *ctx);
463 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
464 * @ena_dev: ENA communication layer struct
465 * @qid - the caller virtual queue id.
467 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
469 /* ena_com_get_io_handlers - Return the io queue handlers
470 * @ena_dev: ENA communication layer struct
471 * @qid - the caller virtual queue id.
472 * @io_sq - IO submission queue handler
473 * @io_cq - IO completion queue handler.
475 * @return - 0 on success, negative value on failure.
477 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
478 struct ena_com_io_sq **io_sq,
479 struct ena_com_io_cq **io_cq);
481 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
482 * @ena_dev: ENA communication layer struct
484 * After this method, aenq event can be received via AENQ.
486 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
488 /* ena_com_set_admin_running_state - Set the state of the admin queue
489 * @ena_dev: ENA communication layer struct
491 * Change the state of the admin queue (enable/disable)
493 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
495 /* ena_com_get_admin_running_state - Get the admin queue state
496 * @ena_dev: ENA communication layer struct
498 * Retrieve the state of the admin queue (enable/disable)
500 * @return - current polling mode (enable/disable)
502 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
504 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
505 * @ena_dev: ENA communication layer struct
506 * @polling: ENAble/Disable polling mode
508 * Set the admin completion mode.
510 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
512 /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
513 * @ena_dev: ENA communication layer struct
515 * Get the admin completion mode.
516 * If polling mode is on, ena_com_execute_admin_command will perform a
517 * polling on the admin completion queue for the commands completion,
518 * otherwise it will wait on wait event.
522 bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
524 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
525 * @ena_dev: ENA communication layer struct
526 * @polling: Enable/Disable polling mode
528 * Set the autopolling mode.
529 * If autopolling is on:
530 * In case of missing interrupt when data is available switch to polling.
532 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
535 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
536 * @ena_dev: ENA communication layer struct
538 * This method goes over the admin completion queue and wakes up all the pending
539 * threads that wait on the commands wait event.
541 * @note: Should be called after MSI-X interrupt.
543 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
545 /* ena_com_aenq_intr_handler - AENQ interrupt handler
546 * @ena_dev: ENA communication layer struct
548 * This method goes over the async event notification queue and calls the proper
551 void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data);
553 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
554 * @ena_dev: ENA communication layer struct
556 * This method aborts all the outstanding admin commands.
557 * The caller should then call ena_com_wait_for_abort_completion to make sure
558 * all the commands were completed.
560 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
562 /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
563 * @ena_dev: ENA communication layer struct
565 * This method waits until all the outstanding admin commands are completed.
567 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
569 /* ena_com_validate_version - Validate the device parameters
570 * @ena_dev: ENA communication layer struct
572 * This method verifies the device parameters are the same as the saved
573 * parameters in ena_dev.
574 * This method is useful after device reset, to validate the device mac address
575 * and the device offloads are the same as before the reset.
577 * @return - 0 on success negative value otherwise.
579 int ena_com_validate_version(struct ena_com_dev *ena_dev);
581 /* ena_com_get_link_params - Retrieve physical link parameters.
582 * @ena_dev: ENA communication layer struct
583 * @resp: Link parameters
585 * Retrieve the physical link parameters,
586 * like speed, auto-negotiation and full duplex support.
588 * @return - 0 on Success negative value otherwise.
590 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
591 struct ena_admin_get_feat_resp *resp);
593 /* ena_com_get_dma_width - Retrieve physical dma address width the device
595 * @ena_dev: ENA communication layer struct
597 * Retrieve the maximum physical address bits the device can handle.
599 * @return: > 0 on Success and negative value otherwise.
601 int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
603 /* ena_com_set_aenq_config - Set aenq groups configurations
604 * @ena_dev: ENA communication layer struct
605 * @groups flag: bit fields flags of enum ena_admin_aenq_group.
607 * Configure which aenq event group the driver would like to receive.
609 * @return: 0 on Success and negative value otherwise.
611 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
613 /* ena_com_get_dev_attr_feat - Get device features
614 * @ena_dev: ENA communication layer struct
615 * @get_feat_ctx: returned context that contain the get features.
617 * @return: 0 on Success and negative value otherwise.
619 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
620 struct ena_com_dev_get_features_ctx *get_feat_ctx);
622 /* ena_com_get_dev_basic_stats - Get device basic statistics
623 * @ena_dev: ENA communication layer struct
624 * @stats: stats return value
626 * @return: 0 on Success and negative value otherwise.
628 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
629 struct ena_admin_basic_stats *stats);
631 /* ena_com_set_dev_mtu - Configure the device mtu.
632 * @ena_dev: ENA communication layer struct
635 * @return: 0 on Success and negative value otherwise.
637 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
639 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
640 * @ena_dev: ENA communication layer struct
641 * @offlad: offload return value
643 * @return: 0 on Success and negative value otherwise.
645 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
646 struct ena_admin_feature_offload_desc *offload);
648 /* ena_com_rss_init - Init RSS
649 * @ena_dev: ENA communication layer struct
650 * @log_size: indirection log size
652 * Allocate RSS/RFS resources.
653 * The caller then can configure rss using ena_com_set_hash_function,
654 * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
656 * @return: 0 on Success and negative value otherwise.
658 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
660 /* ena_com_rss_destroy - Destroy rss
661 * @ena_dev: ENA communication layer struct
663 * Free all the RSS/RFS resources.
665 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
667 /* ena_com_get_current_hash_function - Get RSS hash function
668 * @ena_dev: ENA communication layer struct
670 * Return the current hash function.
671 * @return: 0 or one of the ena_admin_hash_functions values.
673 int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
675 /* ena_com_fill_hash_function - Fill RSS hash function
676 * @ena_dev: ENA communication layer struct
677 * @func: The hash function (Toeplitz or crc)
678 * @key: Hash key (for toeplitz hash)
679 * @key_len: key length (max length 10 DW)
680 * @init_val: initial value for the hash function
682 * Fill the ena_dev resources with the desire hash function, hash key, key_len
683 * and key initial value (if needed by the hash function).
684 * To flush the key into the device the caller should call
685 * ena_com_set_hash_function.
687 * @return: 0 on Success and negative value otherwise.
689 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
690 enum ena_admin_hash_functions func,
691 const u8 *key, u16 key_len, u32 init_val);
693 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
695 * @ena_dev: ENA communication layer struct
697 * Flush the hash function and it dependencies (key, key length and
698 * initial value) if needed.
700 * @note: Prior to this method the caller should call ena_com_fill_hash_function
702 * @return: 0 on Success and negative value otherwise.
704 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
706 /* ena_com_get_hash_function - Retrieve the hash function from the device.
707 * @ena_dev: ENA communication layer struct
708 * @func: hash function
710 * Retrieve the hash function from the device.
712 * @note: If the caller called ena_com_fill_hash_function but didn't flush
713 * it to the device, the new configuration will be lost.
715 * @return: 0 on Success and negative value otherwise.
717 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
718 enum ena_admin_hash_functions *func);
720 /* ena_com_get_hash_key - Retrieve the hash key
721 * @ena_dev: ENA communication layer struct
724 * Retrieve the hash key.
726 * @note: If the caller called ena_com_fill_hash_key but didn't flush
727 * it to the device, the new configuration will be lost.
729 * @return: 0 on Success and negative value otherwise.
731 int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
732 /* ena_com_fill_hash_ctrl - Fill RSS hash control
733 * @ena_dev: ENA communication layer struct.
734 * @proto: The protocol to configure.
735 * @hash_fields: bit mask of ena_admin_flow_hash_fields
737 * Fill the ena_dev resources with the desire hash control (the ethernet
738 * fields that take part of the hash) for a specific protocol.
739 * To flush the hash control to the device, the caller should call
740 * ena_com_set_hash_ctrl.
742 * @return: 0 on Success and negative value otherwise.
744 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
745 enum ena_admin_flow_hash_proto proto,
748 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
749 * @ena_dev: ENA communication layer struct
751 * Flush the hash control (the ethernet fields that take part of the hash)
753 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
755 * @return: 0 on Success and negative value otherwise.
757 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
759 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
760 * @ena_dev: ENA communication layer struct
761 * @proto: The protocol to retrieve.
762 * @fields: bit mask of ena_admin_flow_hash_fields.
764 * Retrieve the hash control from the device.
766 * @note: If the caller called ena_com_fill_hash_ctrl but didn't flush
767 * it to the device, the new configuration will be lost.
769 * @return: 0 on Success and negative value otherwise.
771 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
772 enum ena_admin_flow_hash_proto proto,
775 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
777 * @ena_dev: ENA communication layer struct
779 * Fill the ena_dev resources with the default hash control configuration.
780 * To flush the hash control to the device, the caller should call
781 * ena_com_set_hash_ctrl.
783 * @return: 0 on Success and negative value otherwise.
785 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
787 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
789 * @ena_dev: ENA communication layer struct.
790 * @entry_idx - indirection table entry.
791 * @entry_value - redirection value
793 * Fill a single entry of the RSS indirection table in the ena_dev resources.
794 * To flush the indirection table to the device, the called should call
795 * ena_com_indirect_table_set.
797 * @return: 0 on Success and negative value otherwise.
799 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
800 u16 entry_idx, u16 entry_value);
802 /* ena_com_indirect_table_set - Flush the indirection table to the device.
803 * @ena_dev: ENA communication layer struct
805 * Flush the indirection hash control to the device.
806 * Prior to this method the caller should call ena_com_indirect_table_fill_entry
808 * @return: 0 on Success and negative value otherwise.
810 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
812 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
813 * @ena_dev: ENA communication layer struct
814 * @ind_tbl: indirection table
816 * Retrieve the RSS indirection table from the device.
818 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush
819 * it to the device, the new configuration will be lost.
821 * @return: 0 on Success and negative value otherwise.
823 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
825 /* ena_com_allocate_host_info - Allocate host info resources.
826 * @ena_dev: ENA communication layer struct
828 * @return: 0 on Success and negative value otherwise.
830 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
832 /* ena_com_allocate_debug_area - Allocate debug area.
833 * @ena_dev: ENA communication layer struct
834 * @debug_area_size - debug area size.
836 * @return: 0 on Success and negative value otherwise.
838 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
839 u32 debug_area_size);
841 /* ena_com_delete_debug_area - Free the debug area resources.
842 * @ena_dev: ENA communication layer struct
844 * Free the allocated debug area.
846 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
848 /* ena_com_delete_host_info - Free the host info resources.
849 * @ena_dev: ENA communication layer struct
851 * Free the allocated host info.
853 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
855 /* ena_com_set_host_attributes - Update the device with the host
856 * attributes (debug area and host info) base address.
857 * @ena_dev: ENA communication layer struct
859 * @return: 0 on Success and negative value otherwise.
861 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
863 /* ena_com_create_io_cq - Create io completion queue.
864 * @ena_dev: ENA communication layer struct
865 * @io_cq - io completion queue handler
867 * Create IO completion queue.
869 * @return - 0 on success, negative value on failure.
871 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
872 struct ena_com_io_cq *io_cq);
874 /* ena_com_destroy_io_cq - Destroy io completion queue.
875 * @ena_dev: ENA communication layer struct
876 * @io_cq - io completion queue handler
878 * Destroy IO completion queue.
880 * @return - 0 on success, negative value on failure.
882 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
883 struct ena_com_io_cq *io_cq);
885 /* ena_com_execute_admin_command - Execute admin command
886 * @admin_queue: admin queue.
887 * @cmd: the admin command to execute.
888 * @cmd_size: the command size.
889 * @cmd_completion: command completion return value.
890 * @cmd_comp_size: command completion size.
892 * Submit an admin command and then wait until the device returns a
894 * The completion will be copied into cmd_comp.
896 * @return - 0 on success, negative value on failure.
898 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
899 struct ena_admin_aq_entry *cmd,
901 struct ena_admin_acq_entry *cmd_comp,
902 size_t cmd_comp_size);
904 /* ena_com_init_interrupt_moderation - Init interrupt moderation
905 * @ena_dev: ENA communication layer struct
907 * @return - 0 on success, negative value on failure.
909 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
911 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
912 * capability is supported by the device.
914 * @return - supported or not.
916 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
918 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
919 * non-adaptive interval in Tx direction.
920 * @ena_dev: ENA communication layer struct
921 * @tx_coalesce_usecs: Interval in usec.
923 * @return - 0 on success, negative value on failure.
925 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
926 u32 tx_coalesce_usecs);
928 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
929 * non-adaptive interval in Rx direction.
930 * @ena_dev: ENA communication layer struct
931 * @rx_coalesce_usecs: Interval in usec.
933 * @return - 0 on success, negative value on failure.
935 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
936 u32 rx_coalesce_usecs);
938 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
939 * non-adaptive interval in Tx direction.
940 * @ena_dev: ENA communication layer struct
942 * @return - interval in usec
944 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
946 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
947 * non-adaptive interval in Rx direction.
948 * @ena_dev: ENA communication layer struct
950 * @return - interval in usec
952 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
954 /* ena_com_config_dev_mode - Configure the placement policy of the device.
955 * @ena_dev: ENA communication layer struct
956 * @llq_features: LLQ feature descriptor, retrieve via
957 * ena_com_get_dev_attr_feat.
958 * @ena_llq_config: The default driver LLQ parameters configurations
960 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
961 struct ena_admin_feature_llq_desc *llq_features,
962 struct ena_llq_configurations *llq_default_config);
964 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
966 return ena_dev->adaptive_coalescing;
969 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
971 ena_dev->adaptive_coalescing = true;
974 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
976 ena_dev->adaptive_coalescing = false;
979 /* ena_com_update_intr_reg - Prepare interrupt register
980 * @intr_reg: interrupt register to update.
981 * @rx_delay_interval: Rx interval in usecs
982 * @tx_delay_interval: Tx interval in usecs
983 * @unmask: unmask enable/disable
985 * Prepare interrupt update register with the supplied parameters.
987 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
988 u32 rx_delay_interval,
989 u32 tx_delay_interval,
992 intr_reg->intr_control = 0;
993 intr_reg->intr_control |= rx_delay_interval &
994 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
996 intr_reg->intr_control |=
997 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
998 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
1001 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
1004 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
1006 u16 size, buffers_num;
1009 size = bounce_buf_ctrl->buffer_size;
1010 buffers_num = bounce_buf_ctrl->buffers_num;
1012 buf = bounce_buf_ctrl->base_buffer +
1013 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
1015 prefetchw(bounce_buf_ctrl->base_buffer +
1016 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1021 #ifdef ENA_EXTENDED_STATS
1022 int ena_com_get_dev_extended_stats(struct ena_com_dev *ena_dev, char *buff,
1025 int ena_com_extended_stats_set_func_queue(struct ena_com_dev *ena_dev,
1028 #if defined(__cplusplus)
1030 #endif /* __cplusplus */
1031 #endif /* !(ENA_COM) */