2 * SPDX-License-Identifier: BSD-3-Clause
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 #define ENA_CDESC_RING_SIZE_ALIGNMENT (1 << 12) /* 4K */
56 /*****************************************************************************/
57 /*****************************************************************************/
58 /* ENA adaptive interrupt moderation settings */
60 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS ENA_INTR_INITIAL_TX_INTERVAL_USECS_PLAT
61 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0
62 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
64 #define ENA_HASH_KEY_SIZE 40
66 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
68 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
70 struct ena_llq_configurations {
71 enum ena_admin_llq_header_location llq_header_location;
72 enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
73 enum ena_admin_llq_stride_ctrl llq_stride_ctrl;
74 enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
75 u16 llq_ring_entry_size_value;
78 enum queue_direction {
79 ENA_COM_IO_QUEUE_DIRECTION_TX,
80 ENA_COM_IO_QUEUE_DIRECTION_RX
84 dma_addr_t paddr; /**< Buffer physical address */
85 u16 len; /**< Buffer length in bytes */
88 struct ena_com_rx_buf_info {
93 struct ena_com_io_desc_addr {
94 u8 __iomem *pbuf_dev_addr; /* LLQ address */
97 ena_mem_handle_t mem_handle;
100 struct ena_com_tx_meta {
104 u16 l4_hdr_len; /* In words */
107 struct ena_com_llq_info {
108 u16 header_location_ctrl;
109 u16 desc_stride_ctrl;
110 u16 desc_list_entry_size_ctrl;
111 u16 desc_list_entry_size;
112 u16 descs_num_before_header;
114 u16 max_entries_in_tx_burst;
115 bool disable_meta_caching;
118 struct ena_com_io_cq {
119 struct ena_com_io_desc_addr cdesc_addr;
122 /* Interrupt unmask register */
123 u32 __iomem *unmask_reg;
125 /* The completion queue head doorbell register */
126 u32 __iomem *cq_head_db_reg;
128 /* numa configuration register (for TPH) */
129 u32 __iomem *numa_node_cfg_reg;
131 /* The value to write to the above register to unmask
132 * the interrupt of this queue
136 enum queue_direction direction;
138 /* holds the number of cdesc of the current packet */
139 u16 cur_rx_pkt_cdesc_count;
140 /* save the firt cdesc idx of the current packet */
141 u16 cur_rx_pkt_cdesc_start_idx;
147 /* Device queue index */
150 u16 last_head_update;
152 u8 cdesc_entry_size_in_bytes;
154 } ____cacheline_aligned;
156 struct ena_com_io_bounce_buffer_control {
160 u16 buffers_num; /* Must be a power of 2 */
163 /* This struct is to keep tracking the current location of the next llq entry */
164 struct ena_com_llq_pkt_ctrl {
167 u16 descs_left_in_line;
170 struct ena_com_io_sq {
171 struct ena_com_io_desc_addr desc_addr;
174 u32 __iomem *db_addr;
175 u8 __iomem *header_addr;
177 enum queue_direction direction;
178 enum ena_admin_placement_policy_type mem_queue_type;
180 bool disable_meta_caching;
183 struct ena_com_tx_meta cached_tx_meta;
184 struct ena_com_llq_info llq_info;
185 struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
186 struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
194 u16 llq_last_copy_tail;
195 u32 tx_max_header_size;
199 u16 entries_in_tx_burst_left;
200 } ____cacheline_aligned;
202 struct ena_com_admin_cq {
203 struct ena_admin_acq_entry *entries;
204 ena_mem_handle_t mem_handle;
211 struct ena_com_admin_sq {
212 struct ena_admin_aq_entry *entries;
213 ena_mem_handle_t mem_handle;
216 u32 __iomem *db_addr;
224 struct ena_com_stats_admin {
232 struct ena_com_admin_queue {
235 struct ena_com_dev *ena_dev;
236 ena_spinlock_t q_lock; /* spinlock for the admin queue */
238 struct ena_comp_ctx *comp_ctx;
239 u32 completion_timeout;
241 struct ena_com_admin_cq cq;
242 struct ena_com_admin_sq sq;
244 /* Indicate if the admin queue should poll for completion */
247 /* Define if fallback to polling mode should occur */
252 /* Indicate that the ena was initialized and can
253 * process new admin commands
257 /* Count the number of outstanding admin commands */
258 ena_atomic32_t outstanding_cmds;
260 struct ena_com_stats_admin stats;
263 struct ena_aenq_handlers;
265 struct ena_com_aenq {
268 struct ena_admin_aenq_entry *entries;
270 ena_mem_handle_t mem_handle;
272 struct ena_aenq_handlers *aenq_handlers;
275 struct ena_com_mmio_read {
276 struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
277 dma_addr_t read_resp_dma_addr;
278 ena_mem_handle_t read_resp_mem_handle;
279 u32 reg_read_to; /* in us */
281 bool readless_supported;
282 /* spin lock to ensure a single outstanding read */
288 u16 *host_rss_ind_tbl;
289 struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
290 dma_addr_t rss_ind_tbl_dma_addr;
291 ena_mem_handle_t rss_ind_tbl_mem_handle;
295 enum ena_admin_hash_functions hash_func;
296 struct ena_admin_feature_rss_flow_hash_control *hash_key;
297 dma_addr_t hash_key_dma_addr;
298 ena_mem_handle_t hash_key_mem_handle;
302 struct ena_admin_feature_rss_hash_control *hash_ctrl;
303 dma_addr_t hash_ctrl_dma_addr;
304 ena_mem_handle_t hash_ctrl_mem_handle;
308 struct ena_host_attribute {
310 u8 *debug_area_virt_addr;
311 dma_addr_t debug_area_dma_addr;
312 ena_mem_handle_t debug_area_dma_handle;
315 /* Host information */
316 struct ena_admin_host_info *host_info;
317 dma_addr_t host_info_dma_addr;
318 ena_mem_handle_t host_info_dma_handle;
321 /* Each ena_dev is a PCI function. */
323 struct ena_com_admin_queue admin_queue;
324 struct ena_com_aenq aenq;
325 struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
326 struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
328 void __iomem *mem_bar;
331 ena_netdev *net_device;
333 enum ena_admin_placement_policy_type tx_mem_queue_type;
334 u32 tx_max_header_size;
335 u16 stats_func; /* Selected function for extended statistic dump */
336 u16 stats_queue; /* Selected queue for extended statistic dump */
338 struct ena_com_mmio_read mmio_read;
341 u32 supported_features;
344 struct ena_host_attribute host_attr;
345 bool adaptive_coalescing;
346 u16 intr_delay_resolution;
348 /* interrupt moderation intervals are in usec divided by
349 * intr_delay_resolution, which is supplied by the device.
351 u32 intr_moder_tx_interval;
352 u32 intr_moder_rx_interval;
354 struct ena_intr_moder_entry *intr_moder_tbl;
356 struct ena_com_llq_info llq_info;
358 u32 ena_min_poll_delay_us;
361 struct ena_com_dev_get_features_ctx {
362 struct ena_admin_queue_feature_desc max_queues;
363 struct ena_admin_queue_ext_feature_desc max_queue_ext;
364 struct ena_admin_device_attr_feature_desc dev_attr;
365 struct ena_admin_feature_aenq_desc aenq;
366 struct ena_admin_feature_offload_desc offload;
367 struct ena_admin_ena_hw_hints hw_hints;
368 struct ena_admin_feature_llq_desc llq;
371 struct ena_com_create_io_ctx {
372 enum ena_admin_placement_policy_type mem_queue_type;
373 enum queue_direction direction;
380 typedef void (*ena_aenq_handler)(void *data,
381 struct ena_admin_aenq_entry *aenq_e);
383 /* Holds aenq handlers. Indexed by AENQ event group */
384 struct ena_aenq_handlers {
385 ena_aenq_handler handlers[ENA_MAX_HANDLERS];
386 ena_aenq_handler unimplemented_handler;
389 /*****************************************************************************/
390 /*****************************************************************************/
391 #if defined(__cplusplus)
395 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
396 * @ena_dev: ENA communication layer struct
398 * Initialize the register read mechanism.
400 * @note: This method must be the first stage in the initialization sequence.
402 * @return - 0 on success, negative value on failure.
404 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
406 /* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism
407 * @ena_dev: ENA communication layer struct
408 * @readless_supported: readless mode (enable/disable)
410 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
411 bool readless_supported);
413 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
414 * value physical address.
415 * @ena_dev: ENA communication layer struct
417 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
419 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
420 * @ena_dev: ENA communication layer struct
422 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
424 /* ena_com_admin_init - Init the admin and the async queues
425 * @ena_dev: ENA communication layer struct
426 * @aenq_handlers: Those handlers to be called upon event.
428 * Initialize the admin submission and completion queues.
429 * Initialize the asynchronous events notification queues.
431 * @return - 0 on success, negative value on failure.
433 int ena_com_admin_init(struct ena_com_dev *ena_dev,
434 struct ena_aenq_handlers *aenq_handlers);
436 /* ena_com_admin_destroy - Destroy the admin and the async events queues.
437 * @ena_dev: ENA communication layer struct
439 * @note: Before calling this method, the caller must validate that the device
440 * won't send any additional admin completions/aenq.
441 * To achieve that, a FLR is recommended.
443 void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
445 /* ena_com_dev_reset - Perform device FLR to the device.
446 * @ena_dev: ENA communication layer struct
447 * @reset_reason: Specify what is the trigger for the reset in case of an error.
449 * @return - 0 on success, negative value on failure.
451 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
452 enum ena_regs_reset_reason_types reset_reason);
454 /* ena_com_create_io_queue - Create io queue.
455 * @ena_dev: ENA communication layer struct
456 * @ctx - create context structure
458 * Create the submission and the completion queues.
460 * @return - 0 on success, negative value on failure.
462 int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
463 struct ena_com_create_io_ctx *ctx);
465 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
466 * @ena_dev: ENA communication layer struct
467 * @qid - the caller virtual queue id.
469 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
471 /* ena_com_get_io_handlers - Return the io queue handlers
472 * @ena_dev: ENA communication layer struct
473 * @qid - the caller virtual queue id.
474 * @io_sq - IO submission queue handler
475 * @io_cq - IO completion queue handler.
477 * @return - 0 on success, negative value on failure.
479 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
480 struct ena_com_io_sq **io_sq,
481 struct ena_com_io_cq **io_cq);
483 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
484 * @ena_dev: ENA communication layer struct
486 * After this method, aenq event can be received via AENQ.
488 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
490 /* ena_com_set_admin_running_state - Set the state of the admin queue
491 * @ena_dev: ENA communication layer struct
493 * Change the state of the admin queue (enable/disable)
495 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
497 /* ena_com_get_admin_running_state - Get the admin queue state
498 * @ena_dev: ENA communication layer struct
500 * Retrieve the state of the admin queue (enable/disable)
502 * @return - current polling mode (enable/disable)
504 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
506 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
507 * @ena_dev: ENA communication layer struct
508 * @polling: ENAble/Disable polling mode
510 * Set the admin completion mode.
512 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
514 /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
515 * @ena_dev: ENA communication layer struct
517 * Get the admin completion mode.
518 * If polling mode is on, ena_com_execute_admin_command will perform a
519 * polling on the admin completion queue for the commands completion,
520 * otherwise it will wait on wait event.
524 bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
526 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
527 * @ena_dev: ENA communication layer struct
528 * @polling: Enable/Disable polling mode
530 * Set the autopolling mode.
531 * If autopolling is on:
532 * In case of missing interrupt when data is available switch to polling.
534 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
537 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
538 * @ena_dev: ENA communication layer struct
540 * This method goes over the admin completion queue and wakes up all the pending
541 * threads that wait on the commands wait event.
543 * @note: Should be called after MSI-X interrupt.
545 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
547 /* ena_com_aenq_intr_handler - AENQ interrupt handler
548 * @ena_dev: ENA communication layer struct
550 * This method goes over the async event notification queue and calls the proper
553 void ena_com_aenq_intr_handler(struct ena_com_dev *ena_dev, void *data);
555 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
556 * @ena_dev: ENA communication layer struct
558 * This method aborts all the outstanding admin commands.
559 * The caller should then call ena_com_wait_for_abort_completion to make sure
560 * all the commands were completed.
562 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
564 /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
565 * @ena_dev: ENA communication layer struct
567 * This method waits until all the outstanding admin commands are completed.
569 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
571 /* ena_com_validate_version - Validate the device parameters
572 * @ena_dev: ENA communication layer struct
574 * This method verifies the device parameters are the same as the saved
575 * parameters in ena_dev.
576 * This method is useful after device reset, to validate the device mac address
577 * and the device offloads are the same as before the reset.
579 * @return - 0 on success negative value otherwise.
581 int ena_com_validate_version(struct ena_com_dev *ena_dev);
583 /* ena_com_get_link_params - Retrieve physical link parameters.
584 * @ena_dev: ENA communication layer struct
585 * @resp: Link parameters
587 * Retrieve the physical link parameters,
588 * like speed, auto-negotiation and full duplex support.
590 * @return - 0 on Success negative value otherwise.
592 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
593 struct ena_admin_get_feat_resp *resp);
595 /* ena_com_get_dma_width - Retrieve physical dma address width the device
597 * @ena_dev: ENA communication layer struct
599 * Retrieve the maximum physical address bits the device can handle.
601 * @return: > 0 on Success and negative value otherwise.
603 int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
605 /* ena_com_set_aenq_config - Set aenq groups configurations
606 * @ena_dev: ENA communication layer struct
607 * @groups flag: bit fields flags of enum ena_admin_aenq_group.
609 * Configure which aenq event group the driver would like to receive.
611 * @return: 0 on Success and negative value otherwise.
613 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
615 /* ena_com_get_dev_attr_feat - Get device features
616 * @ena_dev: ENA communication layer struct
617 * @get_feat_ctx: returned context that contain the get features.
619 * @return: 0 on Success and negative value otherwise.
621 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
622 struct ena_com_dev_get_features_ctx *get_feat_ctx);
624 /* ena_com_get_dev_basic_stats - Get device basic statistics
625 * @ena_dev: ENA communication layer struct
626 * @stats: stats return value
628 * @return: 0 on Success and negative value otherwise.
630 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
631 struct ena_admin_basic_stats *stats);
633 /* ena_com_get_eni_stats - Get extended network interface statistics
634 * @ena_dev: ENA communication layer struct
635 * @stats: stats return value
637 * @return: 0 on Success and negative value otherwise.
639 int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
640 struct ena_admin_eni_stats *stats);
642 /* ena_com_set_dev_mtu - Configure the device mtu.
643 * @ena_dev: ENA communication layer struct
646 * @return: 0 on Success and negative value otherwise.
648 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
650 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
651 * @ena_dev: ENA communication layer struct
652 * @offlad: offload return value
654 * @return: 0 on Success and negative value otherwise.
656 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
657 struct ena_admin_feature_offload_desc *offload);
659 /* ena_com_rss_init - Init RSS
660 * @ena_dev: ENA communication layer struct
661 * @log_size: indirection log size
663 * Allocate RSS/RFS resources.
664 * The caller then can configure rss using ena_com_set_hash_function,
665 * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
667 * @return: 0 on Success and negative value otherwise.
669 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
671 /* ena_com_rss_destroy - Destroy rss
672 * @ena_dev: ENA communication layer struct
674 * Free all the RSS/RFS resources.
676 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
678 /* ena_com_get_current_hash_function - Get RSS hash function
679 * @ena_dev: ENA communication layer struct
681 * Return the current hash function.
682 * @return: 0 or one of the ena_admin_hash_functions values.
684 int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
686 /* ena_com_fill_hash_function - Fill RSS hash function
687 * @ena_dev: ENA communication layer struct
688 * @func: The hash function (Toeplitz or crc)
689 * @key: Hash key (for toeplitz hash)
690 * @key_len: key length (max length 10 DW)
691 * @init_val: initial value for the hash function
693 * Fill the ena_dev resources with the desire hash function, hash key, key_len
694 * and key initial value (if needed by the hash function).
695 * To flush the key into the device the caller should call
696 * ena_com_set_hash_function.
698 * @return: 0 on Success and negative value otherwise.
700 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
701 enum ena_admin_hash_functions func,
702 const u8 *key, u16 key_len, u32 init_val);
704 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
706 * @ena_dev: ENA communication layer struct
708 * Flush the hash function and it dependencies (key, key length and
709 * initial value) if needed.
711 * @note: Prior to this method the caller should call ena_com_fill_hash_function
713 * @return: 0 on Success and negative value otherwise.
715 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
717 /* ena_com_get_hash_function - Retrieve the hash function from the device.
718 * @ena_dev: ENA communication layer struct
719 * @func: hash function
721 * Retrieve the hash function from the device.
723 * @note: If the caller called ena_com_fill_hash_function but didn't flush
724 * it to the device, the new configuration will be lost.
726 * @return: 0 on Success and negative value otherwise.
728 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
729 enum ena_admin_hash_functions *func);
731 /* ena_com_get_hash_key - Retrieve the hash key
732 * @ena_dev: ENA communication layer struct
735 * Retrieve the hash key.
737 * @note: If the caller called ena_com_fill_hash_key but didn't flush
738 * it to the device, the new configuration will be lost.
740 * @return: 0 on Success and negative value otherwise.
742 int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
743 /* ena_com_fill_hash_ctrl - Fill RSS hash control
744 * @ena_dev: ENA communication layer struct.
745 * @proto: The protocol to configure.
746 * @hash_fields: bit mask of ena_admin_flow_hash_fields
748 * Fill the ena_dev resources with the desire hash control (the ethernet
749 * fields that take part of the hash) for a specific protocol.
750 * To flush the hash control to the device, the caller should call
751 * ena_com_set_hash_ctrl.
753 * @return: 0 on Success and negative value otherwise.
755 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
756 enum ena_admin_flow_hash_proto proto,
759 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
760 * @ena_dev: ENA communication layer struct
762 * Flush the hash control (the ethernet fields that take part of the hash)
764 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
766 * @return: 0 on Success and negative value otherwise.
768 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
770 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
771 * @ena_dev: ENA communication layer struct
772 * @proto: The protocol to retrieve.
773 * @fields: bit mask of ena_admin_flow_hash_fields.
775 * Retrieve the hash control from the device.
777 * @note: If the caller called ena_com_fill_hash_ctrl but didn't flush
778 * it to the device, the new configuration will be lost.
780 * @return: 0 on Success and negative value otherwise.
782 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
783 enum ena_admin_flow_hash_proto proto,
786 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
788 * @ena_dev: ENA communication layer struct
790 * Fill the ena_dev resources with the default hash control configuration.
791 * To flush the hash control to the device, the caller should call
792 * ena_com_set_hash_ctrl.
794 * @return: 0 on Success and negative value otherwise.
796 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
798 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
800 * @ena_dev: ENA communication layer struct.
801 * @entry_idx - indirection table entry.
802 * @entry_value - redirection value
804 * Fill a single entry of the RSS indirection table in the ena_dev resources.
805 * To flush the indirection table to the device, the called should call
806 * ena_com_indirect_table_set.
808 * @return: 0 on Success and negative value otherwise.
810 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
811 u16 entry_idx, u16 entry_value);
813 /* ena_com_indirect_table_set - Flush the indirection table to the device.
814 * @ena_dev: ENA communication layer struct
816 * Flush the indirection hash control to the device.
817 * Prior to this method the caller should call ena_com_indirect_table_fill_entry
819 * @return: 0 on Success and negative value otherwise.
821 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
823 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
824 * @ena_dev: ENA communication layer struct
825 * @ind_tbl: indirection table
827 * Retrieve the RSS indirection table from the device.
829 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush
830 * it to the device, the new configuration will be lost.
832 * @return: 0 on Success and negative value otherwise.
834 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
836 /* ena_com_allocate_host_info - Allocate host info resources.
837 * @ena_dev: ENA communication layer struct
839 * @return: 0 on Success and negative value otherwise.
841 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
843 /* ena_com_allocate_debug_area - Allocate debug area.
844 * @ena_dev: ENA communication layer struct
845 * @debug_area_size - debug area size.
847 * @return: 0 on Success and negative value otherwise.
849 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
850 u32 debug_area_size);
852 /* ena_com_delete_debug_area - Free the debug area resources.
853 * @ena_dev: ENA communication layer struct
855 * Free the allocated debug area.
857 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
859 /* ena_com_delete_host_info - Free the host info resources.
860 * @ena_dev: ENA communication layer struct
862 * Free the allocated host info.
864 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
866 /* ena_com_set_host_attributes - Update the device with the host
867 * attributes (debug area and host info) base address.
868 * @ena_dev: ENA communication layer struct
870 * @return: 0 on Success and negative value otherwise.
872 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
874 /* ena_com_create_io_cq - Create io completion queue.
875 * @ena_dev: ENA communication layer struct
876 * @io_cq - io completion queue handler
878 * Create IO completion queue.
880 * @return - 0 on success, negative value on failure.
882 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
883 struct ena_com_io_cq *io_cq);
885 /* ena_com_destroy_io_cq - Destroy io completion queue.
886 * @ena_dev: ENA communication layer struct
887 * @io_cq - io completion queue handler
889 * Destroy IO completion queue.
891 * @return - 0 on success, negative value on failure.
893 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
894 struct ena_com_io_cq *io_cq);
896 /* ena_com_execute_admin_command - Execute admin command
897 * @admin_queue: admin queue.
898 * @cmd: the admin command to execute.
899 * @cmd_size: the command size.
900 * @cmd_completion: command completion return value.
901 * @cmd_comp_size: command completion size.
903 * Submit an admin command and then wait until the device returns a
905 * The completion will be copied into cmd_comp.
907 * @return - 0 on success, negative value on failure.
909 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
910 struct ena_admin_aq_entry *cmd,
912 struct ena_admin_acq_entry *cmd_comp,
913 size_t cmd_comp_size);
915 /* ena_com_init_interrupt_moderation - Init interrupt moderation
916 * @ena_dev: ENA communication layer struct
918 * @return - 0 on success, negative value on failure.
920 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
922 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
923 * capability is supported by the device.
925 * @return - supported or not.
927 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
929 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
930 * non-adaptive interval in Tx direction.
931 * @ena_dev: ENA communication layer struct
932 * @tx_coalesce_usecs: Interval in usec.
934 * @return - 0 on success, negative value on failure.
936 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
937 u32 tx_coalesce_usecs);
939 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
940 * non-adaptive interval in Rx direction.
941 * @ena_dev: ENA communication layer struct
942 * @rx_coalesce_usecs: Interval in usec.
944 * @return - 0 on success, negative value on failure.
946 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
947 u32 rx_coalesce_usecs);
949 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
950 * non-adaptive interval in Tx direction.
951 * @ena_dev: ENA communication layer struct
953 * @return - interval in usec
955 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
957 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
958 * non-adaptive interval in Rx direction.
959 * @ena_dev: ENA communication layer struct
961 * @return - interval in usec
963 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
965 /* ena_com_config_dev_mode - Configure the placement policy of the device.
966 * @ena_dev: ENA communication layer struct
967 * @llq_features: LLQ feature descriptor, retrieve via
968 * ena_com_get_dev_attr_feat.
969 * @ena_llq_config: The default driver LLQ parameters configurations
971 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
972 struct ena_admin_feature_llq_desc *llq_features,
973 struct ena_llq_configurations *llq_default_config);
975 /* ena_com_io_sq_to_ena_dev - Extract ena_com_dev using contained field io_sq.
976 * @io_sq: IO submit queue struct
978 * @return - ena_com_dev struct extracted from io_sq
980 static inline struct ena_com_dev *ena_com_io_sq_to_ena_dev(struct ena_com_io_sq *io_sq)
982 return container_of(io_sq, struct ena_com_dev, io_sq_queues[io_sq->qid]);
985 /* ena_com_io_cq_to_ena_dev - Extract ena_com_dev using contained field io_cq.
986 * @io_sq: IO submit queue struct
988 * @return - ena_com_dev struct extracted from io_sq
990 static inline struct ena_com_dev *ena_com_io_cq_to_ena_dev(struct ena_com_io_cq *io_cq)
992 return container_of(io_cq, struct ena_com_dev, io_cq_queues[io_cq->qid]);
995 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
997 return ena_dev->adaptive_coalescing;
1000 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
1002 ena_dev->adaptive_coalescing = true;
1005 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
1007 ena_dev->adaptive_coalescing = false;
1010 /* ena_com_update_intr_reg - Prepare interrupt register
1011 * @intr_reg: interrupt register to update.
1012 * @rx_delay_interval: Rx interval in usecs
1013 * @tx_delay_interval: Tx interval in usecs
1014 * @unmask: unmask enable/disable
1016 * Prepare interrupt update register with the supplied parameters.
1018 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
1019 u32 rx_delay_interval,
1020 u32 tx_delay_interval,
1023 intr_reg->intr_control = 0;
1024 intr_reg->intr_control |= rx_delay_interval &
1025 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
1027 intr_reg->intr_control |=
1028 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
1029 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
1032 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
1035 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
1037 u16 size, buffers_num;
1040 size = bounce_buf_ctrl->buffer_size;
1041 buffers_num = bounce_buf_ctrl->buffers_num;
1043 buf = bounce_buf_ctrl->base_buffer +
1044 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
1046 prefetchw(bounce_buf_ctrl->base_buffer +
1047 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1052 #ifdef ENA_EXTENDED_STATS
1053 int ena_com_get_dev_extended_stats(struct ena_com_dev *ena_dev, char *buff,
1056 int ena_com_extended_stats_set_func_queue(struct ena_com_dev *ena_dev,
1059 #if defined(__cplusplus)
1061 #endif /* __cplusplus */
1062 #endif /* !(ENA_COM) */