2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2015-2021 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;
329 ena_netdev *net_device;
331 enum ena_admin_placement_policy_type tx_mem_queue_type;
332 u32 tx_max_header_size;
333 u16 stats_func; /* Selected function for extended statistic dump */
334 u16 stats_queue; /* Selected queue for extended statistic dump */
336 struct ena_com_mmio_read mmio_read;
339 u32 supported_features;
342 struct ena_host_attribute host_attr;
343 bool adaptive_coalescing;
344 u16 intr_delay_resolution;
346 /* interrupt moderation intervals are in usec divided by
347 * intr_delay_resolution, which is supplied by the device.
349 u32 intr_moder_tx_interval;
350 u32 intr_moder_rx_interval;
352 struct ena_intr_moder_entry *intr_moder_tbl;
354 struct ena_com_llq_info llq_info;
356 u32 ena_min_poll_delay_us;
359 struct ena_com_dev_get_features_ctx {
360 struct ena_admin_queue_feature_desc max_queues;
361 struct ena_admin_queue_ext_feature_desc max_queue_ext;
362 struct ena_admin_device_attr_feature_desc dev_attr;
363 struct ena_admin_feature_aenq_desc aenq;
364 struct ena_admin_feature_offload_desc offload;
365 struct ena_admin_ena_hw_hints hw_hints;
366 struct ena_admin_feature_llq_desc llq;
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 *ena_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_get_eni_stats - Get extended network interface statistics
632 * @ena_dev: ENA communication layer struct
633 * @stats: stats return value
635 * @return: 0 on Success and negative value otherwise.
637 int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
638 struct ena_admin_eni_stats *stats);
640 /* ena_com_set_dev_mtu - Configure the device mtu.
641 * @ena_dev: ENA communication layer struct
644 * @return: 0 on Success and negative value otherwise.
646 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, u32 mtu);
648 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
649 * @ena_dev: ENA communication layer struct
650 * @offlad: offload return value
652 * @return: 0 on Success and negative value otherwise.
654 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
655 struct ena_admin_feature_offload_desc *offload);
657 /* ena_com_rss_init - Init RSS
658 * @ena_dev: ENA communication layer struct
659 * @log_size: indirection log size
661 * Allocate RSS/RFS resources.
662 * The caller then can configure rss using ena_com_set_hash_function,
663 * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
665 * @return: 0 on Success and negative value otherwise.
667 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
669 /* ena_com_rss_destroy - Destroy rss
670 * @ena_dev: ENA communication layer struct
672 * Free all the RSS/RFS resources.
674 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
676 /* ena_com_get_current_hash_function - Get RSS hash function
677 * @ena_dev: ENA communication layer struct
679 * Return the current hash function.
680 * @return: 0 or one of the ena_admin_hash_functions values.
682 int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
684 /* ena_com_fill_hash_function - Fill RSS hash function
685 * @ena_dev: ENA communication layer struct
686 * @func: The hash function (Toeplitz or crc)
687 * @key: Hash key (for toeplitz hash)
688 * @key_len: key length (max length 10 DW)
689 * @init_val: initial value for the hash function
691 * Fill the ena_dev resources with the desire hash function, hash key, key_len
692 * and key initial value (if needed by the hash function).
693 * To flush the key into the device the caller should call
694 * ena_com_set_hash_function.
696 * @return: 0 on Success and negative value otherwise.
698 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
699 enum ena_admin_hash_functions func,
700 const u8 *key, u16 key_len, u32 init_val);
702 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
704 * @ena_dev: ENA communication layer struct
706 * Flush the hash function and it dependencies (key, key length and
707 * initial value) if needed.
709 * @note: Prior to this method the caller should call ena_com_fill_hash_function
711 * @return: 0 on Success and negative value otherwise.
713 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
715 /* ena_com_get_hash_function - Retrieve the hash function from the device.
716 * @ena_dev: ENA communication layer struct
717 * @func: hash function
719 * Retrieve the hash function from the device.
721 * @note: If the caller called ena_com_fill_hash_function but didn't flush
722 * it to the device, the new configuration will be lost.
724 * @return: 0 on Success and negative value otherwise.
726 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
727 enum ena_admin_hash_functions *func);
729 /* ena_com_get_hash_key - Retrieve the hash key
730 * @ena_dev: ENA communication layer struct
733 * Retrieve the hash key.
735 * @note: If the caller called ena_com_fill_hash_key but didn't flush
736 * it to the device, the new configuration will be lost.
738 * @return: 0 on Success and negative value otherwise.
740 int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
741 /* ena_com_fill_hash_ctrl - Fill RSS hash control
742 * @ena_dev: ENA communication layer struct.
743 * @proto: The protocol to configure.
744 * @hash_fields: bit mask of ena_admin_flow_hash_fields
746 * Fill the ena_dev resources with the desire hash control (the ethernet
747 * fields that take part of the hash) for a specific protocol.
748 * To flush the hash control to the device, the caller should call
749 * ena_com_set_hash_ctrl.
751 * @return: 0 on Success and negative value otherwise.
753 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
754 enum ena_admin_flow_hash_proto proto,
757 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
758 * @ena_dev: ENA communication layer struct
760 * Flush the hash control (the ethernet fields that take part of the hash)
762 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
764 * @return: 0 on Success and negative value otherwise.
766 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
768 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
769 * @ena_dev: ENA communication layer struct
770 * @proto: The protocol to retrieve.
771 * @fields: bit mask of ena_admin_flow_hash_fields.
773 * Retrieve the hash control from the device.
775 * @note: If the caller called ena_com_fill_hash_ctrl but didn't flush
776 * it to the device, the new configuration will be lost.
778 * @return: 0 on Success and negative value otherwise.
780 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
781 enum ena_admin_flow_hash_proto proto,
784 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
786 * @ena_dev: ENA communication layer struct
788 * Fill the ena_dev resources with the default hash control configuration.
789 * To flush the hash control to the device, the caller should call
790 * ena_com_set_hash_ctrl.
792 * @return: 0 on Success and negative value otherwise.
794 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
796 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
798 * @ena_dev: ENA communication layer struct.
799 * @entry_idx - indirection table entry.
800 * @entry_value - redirection value
802 * Fill a single entry of the RSS indirection table in the ena_dev resources.
803 * To flush the indirection table to the device, the called should call
804 * ena_com_indirect_table_set.
806 * @return: 0 on Success and negative value otherwise.
808 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
809 u16 entry_idx, u16 entry_value);
811 /* ena_com_indirect_table_set - Flush the indirection table to the device.
812 * @ena_dev: ENA communication layer struct
814 * Flush the indirection hash control to the device.
815 * Prior to this method the caller should call ena_com_indirect_table_fill_entry
817 * @return: 0 on Success and negative value otherwise.
819 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
821 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
822 * @ena_dev: ENA communication layer struct
823 * @ind_tbl: indirection table
825 * Retrieve the RSS indirection table from the device.
827 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush
828 * it to the device, the new configuration will be lost.
830 * @return: 0 on Success and negative value otherwise.
832 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
834 /* ena_com_allocate_host_info - Allocate host info resources.
835 * @ena_dev: ENA communication layer struct
837 * @return: 0 on Success and negative value otherwise.
839 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
841 /* ena_com_allocate_debug_area - Allocate debug area.
842 * @ena_dev: ENA communication layer struct
843 * @debug_area_size - debug area size.
845 * @return: 0 on Success and negative value otherwise.
847 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
848 u32 debug_area_size);
850 /* ena_com_delete_debug_area - Free the debug area resources.
851 * @ena_dev: ENA communication layer struct
853 * Free the allocated debug area.
855 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
857 /* ena_com_delete_host_info - Free the host info resources.
858 * @ena_dev: ENA communication layer struct
860 * Free the allocated host info.
862 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
864 /* ena_com_set_host_attributes - Update the device with the host
865 * attributes (debug area and host info) base address.
866 * @ena_dev: ENA communication layer struct
868 * @return: 0 on Success and negative value otherwise.
870 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
872 /* ena_com_create_io_cq - Create io completion queue.
873 * @ena_dev: ENA communication layer struct
874 * @io_cq - io completion queue handler
876 * Create IO completion queue.
878 * @return - 0 on success, negative value on failure.
880 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
881 struct ena_com_io_cq *io_cq);
883 /* ena_com_destroy_io_cq - Destroy io completion queue.
884 * @ena_dev: ENA communication layer struct
885 * @io_cq - io completion queue handler
887 * Destroy IO completion queue.
889 * @return - 0 on success, negative value on failure.
891 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
892 struct ena_com_io_cq *io_cq);
894 /* ena_com_execute_admin_command - Execute admin command
895 * @admin_queue: admin queue.
896 * @cmd: the admin command to execute.
897 * @cmd_size: the command size.
898 * @cmd_completion: command completion return value.
899 * @cmd_comp_size: command completion size.
901 * Submit an admin command and then wait until the device returns a
903 * The completion will be copied into cmd_comp.
905 * @return - 0 on success, negative value on failure.
907 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
908 struct ena_admin_aq_entry *cmd,
910 struct ena_admin_acq_entry *cmd_comp,
911 size_t cmd_comp_size);
913 /* ena_com_init_interrupt_moderation - Init interrupt moderation
914 * @ena_dev: ENA communication layer struct
916 * @return - 0 on success, negative value on failure.
918 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
920 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
921 * capability is supported by the device.
923 * @return - supported or not.
925 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
927 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
928 * non-adaptive interval in Tx direction.
929 * @ena_dev: ENA communication layer struct
930 * @tx_coalesce_usecs: Interval in usec.
932 * @return - 0 on success, negative value on failure.
934 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
935 u32 tx_coalesce_usecs);
937 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
938 * non-adaptive interval in Rx direction.
939 * @ena_dev: ENA communication layer struct
940 * @rx_coalesce_usecs: Interval in usec.
942 * @return - 0 on success, negative value on failure.
944 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
945 u32 rx_coalesce_usecs);
947 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
948 * non-adaptive interval in Tx direction.
949 * @ena_dev: ENA communication layer struct
951 * @return - interval in usec
953 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
955 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
956 * non-adaptive interval in Rx direction.
957 * @ena_dev: ENA communication layer struct
959 * @return - interval in usec
961 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
963 /* ena_com_config_dev_mode - Configure the placement policy of the device.
964 * @ena_dev: ENA communication layer struct
965 * @llq_features: LLQ feature descriptor, retrieve via
966 * ena_com_get_dev_attr_feat.
967 * @ena_llq_config: The default driver LLQ parameters configurations
969 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
970 struct ena_admin_feature_llq_desc *llq_features,
971 struct ena_llq_configurations *llq_default_config);
973 /* ena_com_io_sq_to_ena_dev - Extract ena_com_dev using contained field io_sq.
974 * @io_sq: IO submit queue struct
976 * @return - ena_com_dev struct extracted from io_sq
978 static inline struct ena_com_dev *ena_com_io_sq_to_ena_dev(struct ena_com_io_sq *io_sq)
980 return container_of(io_sq, struct ena_com_dev, io_sq_queues[io_sq->qid]);
983 /* ena_com_io_cq_to_ena_dev - Extract ena_com_dev using contained field io_cq.
984 * @io_sq: IO submit queue struct
986 * @return - ena_com_dev struct extracted from io_sq
988 static inline struct ena_com_dev *ena_com_io_cq_to_ena_dev(struct ena_com_io_cq *io_cq)
990 return container_of(io_cq, struct ena_com_dev, io_cq_queues[io_cq->qid]);
993 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
995 return ena_dev->adaptive_coalescing;
998 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
1000 ena_dev->adaptive_coalescing = true;
1003 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
1005 ena_dev->adaptive_coalescing = false;
1008 /* ena_com_update_intr_reg - Prepare interrupt register
1009 * @intr_reg: interrupt register to update.
1010 * @rx_delay_interval: Rx interval in usecs
1011 * @tx_delay_interval: Tx interval in usecs
1012 * @unmask: unmask enable/disable
1014 * Prepare interrupt update register with the supplied parameters.
1016 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
1017 u32 rx_delay_interval,
1018 u32 tx_delay_interval,
1021 intr_reg->intr_control = 0;
1022 intr_reg->intr_control |= rx_delay_interval &
1023 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
1025 intr_reg->intr_control |=
1026 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
1027 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
1030 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
1033 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
1035 u16 size, buffers_num;
1038 size = bounce_buf_ctrl->buffer_size;
1039 buffers_num = bounce_buf_ctrl->buffers_num;
1041 buf = bounce_buf_ctrl->base_buffer +
1042 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
1044 prefetchw(bounce_buf_ctrl->base_buffer +
1045 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1050 #ifdef ENA_EXTENDED_STATS
1051 int ena_com_get_dev_extended_stats(struct ena_com_dev *ena_dev, char *buff,
1054 int ena_com_extended_stats_set_func_queue(struct ena_com_dev *ena_dev,
1057 #if defined(__cplusplus)
1059 #endif /* __cplusplus */
1060 #endif /* !(ENA_COM) */