1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
11 #define ENA_MAX_NUM_IO_QUEUES 128U
12 /* We need to queues for each IO (on for Tx and one for Rx) */
13 #define ENA_TOTAL_NUM_QUEUES (2 * (ENA_MAX_NUM_IO_QUEUES))
15 #define ENA_MAX_HANDLERS 256
17 #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48
20 #define ENA_REG_READ_TIMEOUT 200000
22 #define ADMIN_SQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aq_entry))
23 #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry))
24 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
26 /*****************************************************************************/
27 /*****************************************************************************/
28 /* ENA adaptive interrupt moderation settings */
30 #define ENA_INTR_LOWEST_USECS (0)
31 #define ENA_INTR_LOWEST_PKTS (3)
32 #define ENA_INTR_LOWEST_BYTES (2 * 1524)
34 #define ENA_INTR_LOW_USECS (32)
35 #define ENA_INTR_LOW_PKTS (12)
36 #define ENA_INTR_LOW_BYTES (16 * 1024)
38 #define ENA_INTR_MID_USECS (80)
39 #define ENA_INTR_MID_PKTS (48)
40 #define ENA_INTR_MID_BYTES (64 * 1024)
42 #define ENA_INTR_HIGH_USECS (128)
43 #define ENA_INTR_HIGH_PKTS (96)
44 #define ENA_INTR_HIGH_BYTES (128 * 1024)
46 #define ENA_INTR_HIGHEST_USECS (192)
47 #define ENA_INTR_HIGHEST_PKTS (128)
48 #define ENA_INTR_HIGHEST_BYTES (192 * 1024)
50 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS 196
51 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 4
52 #define ENA_INTR_DELAY_OLD_VALUE_WEIGHT 6
53 #define ENA_INTR_DELAY_NEW_VALUE_WEIGHT 4
54 #define ENA_INTR_MODER_LEVEL_STRIDE 1
55 #define ENA_INTR_BYTE_COUNT_NOT_SUPPORTED 0xFFFFFF
57 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
59 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
61 enum ena_intr_moder_level {
62 ENA_INTR_MODER_LOWEST = 0,
66 ENA_INTR_MODER_HIGHEST,
67 ENA_INTR_MAX_NUM_OF_LEVELS,
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 struct ena_intr_moder_entry {
79 unsigned int intr_moder_interval;
80 unsigned int pkts_per_interval;
81 unsigned int bytes_per_interval;
84 enum queue_direction {
85 ENA_COM_IO_QUEUE_DIRECTION_TX,
86 ENA_COM_IO_QUEUE_DIRECTION_RX
90 dma_addr_t paddr; /**< Buffer physical address */
91 u16 len; /**< Buffer length in bytes */
94 struct ena_com_rx_buf_info {
99 struct ena_com_io_desc_addr {
100 u8 __iomem *pbuf_dev_addr; /* LLQ address */
102 dma_addr_t phys_addr;
103 ena_mem_handle_t mem_handle;
106 struct ena_com_tx_meta {
110 u16 l4_hdr_len; /* In words */
113 struct ena_com_llq_info {
114 u16 header_location_ctrl;
115 u16 desc_stride_ctrl;
116 u16 desc_list_entry_size_ctrl;
117 u16 desc_list_entry_size;
118 u16 descs_num_before_header;
120 u16 max_entries_in_tx_burst;
123 struct ena_com_io_cq {
124 struct ena_com_io_desc_addr cdesc_addr;
127 /* Interrupt unmask register */
128 u32 __iomem *unmask_reg;
130 /* The completion queue head doorbell register */
131 u32 __iomem *cq_head_db_reg;
133 /* numa configuration register (for TPH) */
134 u32 __iomem *numa_node_cfg_reg;
136 /* The value to write to the above register to unmask
137 * the interrupt of this queue
141 enum queue_direction direction;
143 /* holds the number of cdesc of the current packet */
144 u16 cur_rx_pkt_cdesc_count;
145 /* save the firt cdesc idx of the current packet */
146 u16 cur_rx_pkt_cdesc_start_idx;
152 /* Device queue index */
155 u16 last_head_update;
157 u8 cdesc_entry_size_in_bytes;
159 } ____cacheline_aligned;
161 struct ena_com_io_bounce_buffer_control {
165 u16 buffers_num; /* Must be a power of 2 */
168 /* This struct is to keep tracking the current location of the next llq entry */
169 struct ena_com_llq_pkt_ctrl {
172 u16 descs_left_in_line;
175 struct ena_com_io_sq {
176 struct ena_com_io_desc_addr desc_addr;
179 u32 __iomem *db_addr;
180 u8 __iomem *header_addr;
182 enum queue_direction direction;
183 enum ena_admin_placement_policy_type mem_queue_type;
186 struct ena_com_tx_meta cached_tx_meta;
187 struct ena_com_llq_info llq_info;
188 struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
189 struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
197 u16 llq_last_copy_tail;
198 u32 tx_max_header_size;
202 u16 entries_in_tx_burst_left;
203 } ____cacheline_aligned;
205 struct ena_com_admin_cq {
206 struct ena_admin_acq_entry *entries;
207 ena_mem_handle_t mem_handle;
214 struct ena_com_admin_sq {
215 struct ena_admin_aq_entry *entries;
216 ena_mem_handle_t mem_handle;
219 u32 __iomem *db_addr;
227 struct ena_com_stats_admin {
235 struct ena_com_admin_queue {
238 ena_spinlock_t q_lock; /* spinlock for the admin queue */
240 struct ena_comp_ctx *comp_ctx;
241 u32 completion_timeout;
243 struct ena_com_admin_cq cq;
244 struct ena_com_admin_sq sq;
246 /* Indicate if the admin queue should poll for completion */
249 /* Define if fallback to polling mode should occur */
254 /* Indicate that the ena was initialized and can
255 * process new admin commands
259 /* Count the number of outstanding admin commands */
260 ena_atomic32_t outstanding_cmds;
262 struct ena_com_stats_admin stats;
265 struct ena_aenq_handlers;
267 struct ena_com_aenq {
270 struct ena_admin_aenq_entry *entries;
272 ena_mem_handle_t mem_handle;
274 struct ena_aenq_handlers *aenq_handlers;
277 struct ena_com_mmio_read {
278 struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
279 dma_addr_t read_resp_dma_addr;
280 ena_mem_handle_t read_resp_mem_handle;
281 u32 reg_read_to; /* in us */
283 bool readless_supported;
284 /* spin lock to ensure a single outstanding read */
290 u16 *host_rss_ind_tbl;
291 struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
292 dma_addr_t rss_ind_tbl_dma_addr;
293 ena_mem_handle_t rss_ind_tbl_mem_handle;
297 enum ena_admin_hash_functions hash_func;
298 struct ena_admin_feature_rss_flow_hash_control *hash_key;
299 dma_addr_t hash_key_dma_addr;
300 ena_mem_handle_t hash_key_mem_handle;
304 struct ena_admin_feature_rss_hash_control *hash_ctrl;
305 dma_addr_t hash_ctrl_dma_addr;
306 ena_mem_handle_t hash_ctrl_mem_handle;
310 struct ena_host_attribute {
312 u8 *debug_area_virt_addr;
313 dma_addr_t debug_area_dma_addr;
314 ena_mem_handle_t debug_area_dma_handle;
317 /* Host information */
318 struct ena_admin_host_info *host_info;
319 dma_addr_t host_info_dma_addr;
320 ena_mem_handle_t host_info_dma_handle;
323 struct ena_extra_properties_strings {
326 ena_mem_handle_t dma_handle;
330 /* Each ena_dev is a PCI function. */
332 struct ena_com_admin_queue admin_queue;
333 struct ena_com_aenq aenq;
334 struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
335 struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
337 void __iomem *mem_bar;
341 enum ena_admin_placement_policy_type tx_mem_queue_type;
342 u32 tx_max_header_size;
343 u16 stats_func; /* Selected function for extended statistic dump */
344 u16 stats_queue; /* Selected queue for extended statistic dump */
346 struct ena_com_mmio_read mmio_read;
349 u32 supported_features;
352 struct ena_host_attribute host_attr;
353 bool adaptive_coalescing;
354 u16 intr_delay_resolution;
355 u32 intr_moder_tx_interval;
356 struct ena_intr_moder_entry *intr_moder_tbl;
358 struct ena_com_llq_info llq_info;
359 struct ena_extra_properties_strings extra_properties_strings;
362 struct ena_com_dev_get_features_ctx {
363 struct ena_admin_queue_feature_desc max_queues;
364 struct ena_admin_queue_ext_feature_desc max_queue_ext;
365 struct ena_admin_device_attr_feature_desc dev_attr;
366 struct ena_admin_feature_aenq_desc aenq;
367 struct ena_admin_feature_offload_desc offload;
368 struct ena_admin_ena_hw_hints hw_hints;
369 struct ena_admin_feature_llq_desc llq;
370 struct ena_admin_feature_rss_ind_table ind_table;
373 struct ena_com_create_io_ctx {
374 enum ena_admin_placement_policy_type mem_queue_type;
375 enum queue_direction direction;
382 typedef void (*ena_aenq_handler)(void *data,
383 struct ena_admin_aenq_entry *aenq_e);
385 /* Holds aenq handlers. Indexed by AENQ event group */
386 struct ena_aenq_handlers {
387 ena_aenq_handler handlers[ENA_MAX_HANDLERS];
388 ena_aenq_handler unimplemented_handler;
391 /*****************************************************************************/
392 /*****************************************************************************/
393 #if defined(__cplusplus)
397 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
398 * @ena_dev: ENA communication layer struct
400 * Initialize the register read mechanism.
402 * @note: This method must be the first stage in the initialization sequence.
404 * @return - 0 on success, negative value on failure.
406 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
408 /* ena_com_set_mmio_read_mode - Enable/disable the mmio reg read mechanism
409 * @ena_dev: ENA communication layer struct
410 * @readless_supported: readless mode (enable/disable)
412 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
413 bool readless_supported);
415 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
416 * value physical address.
417 * @ena_dev: ENA communication layer struct
419 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
421 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
422 * @ena_dev: ENA communication layer struct
424 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
426 /* ena_com_admin_init - Init the admin and the async queues
427 * @ena_dev: ENA communication layer struct
428 * @aenq_handlers: Those handlers to be called upon event.
430 * Initialize the admin submission and completion queues.
431 * Initialize the asynchronous events notification queues.
433 * @return - 0 on success, negative value on failure.
435 int ena_com_admin_init(struct ena_com_dev *ena_dev,
436 struct ena_aenq_handlers *aenq_handlers);
438 /* ena_com_admin_destroy - Destroy the admin and the async events queues.
439 * @ena_dev: ENA communication layer struct
441 * @note: Before calling this method, the caller must validate that the device
442 * won't send any additional admin completions/aenq.
443 * To achieve that, a FLR is recommended.
445 void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
447 /* ena_com_dev_reset - Perform device FLR to the device.
448 * @ena_dev: ENA communication layer struct
449 * @reset_reason: Specify what is the trigger for the reset in case of an error.
451 * @return - 0 on success, negative value on failure.
453 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
454 enum ena_regs_reset_reason_types reset_reason);
456 /* ena_com_create_io_queue - Create io queue.
457 * @ena_dev: ENA communication layer struct
458 * @ctx - create context structure
460 * Create the submission and the completion queues.
462 * @return - 0 on success, negative value on failure.
464 int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
465 struct ena_com_create_io_ctx *ctx);
467 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
468 * @ena_dev: ENA communication layer struct
469 * @qid - the caller virtual queue id.
471 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
473 /* ena_com_get_io_handlers - Return the io queue handlers
474 * @ena_dev: ENA communication layer struct
475 * @qid - the caller virtual queue id.
476 * @io_sq - IO submission queue handler
477 * @io_cq - IO completion queue handler.
479 * @return - 0 on success, negative value on failure.
481 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
482 struct ena_com_io_sq **io_sq,
483 struct ena_com_io_cq **io_cq);
485 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
486 * @ena_dev: ENA communication layer struct
488 * After this method, aenq event can be received via AENQ.
490 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
492 /* ena_com_set_admin_running_state - Set the state of the admin queue
493 * @ena_dev: ENA communication layer struct
495 * Change the state of the admin queue (enable/disable)
497 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
499 /* ena_com_get_admin_running_state - Get the admin queue state
500 * @ena_dev: ENA communication layer struct
502 * Retrieve the state of the admin queue (enable/disable)
504 * @return - current polling mode (enable/disable)
506 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
508 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
509 * @ena_dev: ENA communication layer struct
510 * @polling: ENAble/Disable polling mode
512 * Set the admin completion mode.
514 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
516 /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
517 * @ena_dev: ENA communication layer struct
519 * Get the admin completion mode.
520 * If polling mode is on, ena_com_execute_admin_command will perform a
521 * polling on the admin completion queue for the commands completion,
522 * otherwise it will wait on wait event.
526 bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
528 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
529 * @ena_dev: ENA communication layer struct
530 * @polling: Enable/Disable polling mode
532 * Set the autopolling mode.
533 * If autopolling is on:
534 * In case of missing interrupt when data is available switch to polling.
536 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
539 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
540 * @ena_dev: ENA communication layer struct
542 * This method go over the admin completion queue and wake up all the pending
543 * threads that wait on the commands wait event.
545 * @note: Should be called after MSI-X interrupt.
547 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
549 /* ena_com_aenq_intr_handler - AENQ interrupt handler
550 * @ena_dev: ENA communication layer struct
552 * This method go over the async event notification queue and call the proper
555 void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data);
557 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
558 * @ena_dev: ENA communication layer struct
560 * This method aborts all the outstanding admin commands.
561 * The caller should then call ena_com_wait_for_abort_completion to make sure
562 * all the commands were completed.
564 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
566 /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
567 * @ena_dev: ENA communication layer struct
569 * This method wait until all the outstanding admin commands will be completed.
571 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
573 /* ena_com_validate_version - Validate the device parameters
574 * @ena_dev: ENA communication layer struct
576 * This method validate the device parameters are the same as the saved
577 * parameters in ena_dev.
578 * This method is useful after device reset, to validate the device mac address
579 * and the device offloads are the same as before the reset.
581 * @return - 0 on success negative value otherwise.
583 int ena_com_validate_version(struct ena_com_dev *ena_dev);
585 /* ena_com_get_link_params - Retrieve physical link parameters.
586 * @ena_dev: ENA communication layer struct
587 * @resp: Link parameters
589 * Retrieve the physical link parameters,
590 * like speed, auto-negotiation and full duplex support.
592 * @return - 0 on Success negative value otherwise.
594 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
595 struct ena_admin_get_feat_resp *resp);
597 /* ena_com_extra_properties_strings_init - Initialize the extra properties strings buffer.
598 * @ena_dev: ENA communication layer struct
600 * Initialize the extra properties strings buffer.
602 int ena_com_extra_properties_strings_init(struct ena_com_dev *ena_dev);
604 /* ena_com_delete_extra_properties_strings - Free the extra properties strings buffer.
605 * @ena_dev: ENA communication layer struct
607 * Free the allocated extra properties strings buffer.
609 void ena_com_delete_extra_properties_strings(struct ena_com_dev *ena_dev);
611 /* ena_com_get_extra_properties_flags - Retrieve extra properties flags.
612 * @ena_dev: ENA communication layer struct
613 * @resp: Extra properties flags.
615 * Retrieve the extra properties flags.
617 * @return - 0 on Success negative value otherwise.
619 int ena_com_get_extra_properties_flags(struct ena_com_dev *ena_dev,
620 struct ena_admin_get_feat_resp *resp);
622 /* ena_com_get_dma_width - Retrieve physical dma address width the device
624 * @ena_dev: ENA communication layer struct
626 * Retrieve the maximum physical address bits the device can handle.
628 * @return: > 0 on Success and negative value otherwise.
630 int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
632 /* ena_com_set_aenq_config - Set aenq groups configurations
633 * @ena_dev: ENA communication layer struct
634 * @groups flag: bit fields flags of enum ena_admin_aenq_group.
636 * Configure which aenq event group the driver would like to receive.
638 * @return: 0 on Success and negative value otherwise.
640 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
642 /* ena_com_get_dev_attr_feat - Get device features
643 * @ena_dev: ENA communication layer struct
644 * @get_feat_ctx: returned context that contain the get features.
646 * @return: 0 on Success and negative value otherwise.
648 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
649 struct ena_com_dev_get_features_ctx *get_feat_ctx);
651 /* ena_com_get_dev_basic_stats - Get device basic statistics
652 * @ena_dev: ENA communication layer struct
653 * @stats: stats return value
655 * @return: 0 on Success and negative value otherwise.
657 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
658 struct ena_admin_basic_stats *stats);
660 /* ena_com_set_dev_mtu - Configure the device mtu.
661 * @ena_dev: ENA communication layer struct
664 * @return: 0 on Success and negative value otherwise.
666 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
668 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
669 * @ena_dev: ENA communication layer struct
670 * @offlad: offload return value
672 * @return: 0 on Success and negative value otherwise.
674 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
675 struct ena_admin_feature_offload_desc *offload);
677 /* ena_com_rss_init - Init RSS
678 * @ena_dev: ENA communication layer struct
679 * @log_size: indirection log size
681 * Allocate RSS/RFS resources.
682 * The caller then can configure rss using ena_com_set_hash_function,
683 * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
685 * @return: 0 on Success and negative value otherwise.
687 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
689 /* ena_com_rss_destroy - Destroy rss
690 * @ena_dev: ENA communication layer struct
692 * Free all the RSS/RFS resources.
694 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
696 /* ena_com_fill_hash_function - Fill RSS hash function
697 * @ena_dev: ENA communication layer struct
698 * @func: The hash function (Toeplitz or crc)
699 * @key: Hash key (for toeplitz hash)
700 * @key_len: key length (max length 10 DW)
701 * @init_val: initial value for the hash function
703 * Fill the ena_dev resources with the desire hash function, hash key, key_len
704 * and key initial value (if needed by the hash function).
705 * To flush the key into the device the caller should call
706 * ena_com_set_hash_function.
708 * @return: 0 on Success and negative value otherwise.
710 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
711 enum ena_admin_hash_functions func,
712 const u8 *key, u16 key_len, u32 init_val);
714 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
716 * @ena_dev: ENA communication layer struct
718 * Flush the hash function and it dependencies (key, key length and
719 * initial value) if needed.
721 * @note: Prior to this method the caller should call ena_com_fill_hash_function
723 * @return: 0 on Success and negative value otherwise.
725 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
727 /* ena_com_get_hash_function - Retrieve the hash function and the hash key
729 * @ena_dev: ENA communication layer struct
730 * @func: hash function
733 * Retrieve the hash function and the hash key from the device.
735 * @note: If the caller called ena_com_fill_hash_function but didn't flash
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_function(struct ena_com_dev *ena_dev,
741 enum ena_admin_hash_functions *func,
744 /* ena_com_fill_hash_ctrl - Fill RSS hash control
745 * @ena_dev: ENA communication layer struct.
746 * @proto: The protocol to configure.
747 * @hash_fields: bit mask of ena_admin_flow_hash_fields
749 * Fill the ena_dev resources with the desire hash control (the ethernet
750 * fields that take part of the hash) for a specific protocol.
751 * To flush the hash control to the device, the caller should call
752 * ena_com_set_hash_ctrl.
754 * @return: 0 on Success and negative value otherwise.
756 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
757 enum ena_admin_flow_hash_proto proto,
760 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
761 * @ena_dev: ENA communication layer struct
763 * Flush the hash control (the ethernet fields that take part of the hash)
765 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
767 * @return: 0 on Success and negative value otherwise.
769 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
771 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
772 * @ena_dev: ENA communication layer struct
773 * @proto: The protocol to retrieve.
774 * @fields: bit mask of ena_admin_flow_hash_fields.
776 * Retrieve the hash control from the device.
778 * @note, If the caller called ena_com_fill_hash_ctrl but didn't flash
779 * it to the device, the new configuration will be lost.
781 * @return: 0 on Success and negative value otherwise.
783 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
784 enum ena_admin_flow_hash_proto proto,
787 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
789 * @ena_dev: ENA communication layer struct
791 * Fill the ena_dev resources with the default hash control configuration.
792 * To flush the hash control to the device, the caller should call
793 * ena_com_set_hash_ctrl.
795 * @return: 0 on Success and negative value otherwise.
797 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
799 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
801 * @ena_dev: ENA communication layer struct.
802 * @entry_idx - indirection table entry.
803 * @entry_value - redirection value
805 * Fill a single entry of the RSS indirection table in the ena_dev resources.
806 * To flush the indirection table to the device, the called should call
807 * ena_com_indirect_table_set.
809 * @return: 0 on Success and negative value otherwise.
811 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
812 u16 entry_idx, u16 entry_value);
814 /* ena_com_indirect_table_set - Flush the indirection table to the device.
815 * @ena_dev: ENA communication layer struct
817 * Flush the indirection hash control to the device.
818 * Prior to this method the caller should call ena_com_indirect_table_fill_entry
820 * @return: 0 on Success and negative value otherwise.
822 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
824 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
825 * @ena_dev: ENA communication layer struct
826 * @ind_tbl: indirection table
828 * Retrieve the RSS indirection table from the device.
830 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flash
831 * it to the device, the new configuration will be lost.
833 * @return: 0 on Success and negative value otherwise.
835 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
837 /* ena_com_allocate_host_info - Allocate host info resources.
838 * @ena_dev: ENA communication layer struct
840 * @return: 0 on Success and negative value otherwise.
842 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
844 /* ena_com_allocate_debug_area - Allocate debug area.
845 * @ena_dev: ENA communication layer struct
846 * @debug_area_size - debug area size.
848 * @return: 0 on Success and negative value otherwise.
850 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
851 u32 debug_area_size);
853 /* ena_com_delete_debug_area - Free the debug area resources.
854 * @ena_dev: ENA communication layer struct
856 * Free the allocate debug area.
858 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
860 /* ena_com_delete_host_info - Free the host info resources.
861 * @ena_dev: ENA communication layer struct
863 * Free the allocate host info.
865 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
867 /* ena_com_set_host_attributes - Update the device with the host
868 * attributes (debug area and host info) base address.
869 * @ena_dev: ENA communication layer struct
871 * @return: 0 on Success and negative value otherwise.
873 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
875 /* ena_com_create_io_cq - Create io completion queue.
876 * @ena_dev: ENA communication layer struct
877 * @io_cq - io completion queue handler
879 * Create IO completion queue.
881 * @return - 0 on success, negative value on failure.
883 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
884 struct ena_com_io_cq *io_cq);
886 /* ena_com_destroy_io_cq - Destroy io completion queue.
887 * @ena_dev: ENA communication layer struct
888 * @io_cq - io completion queue handler
890 * Destroy IO completion queue.
892 * @return - 0 on success, negative value on failure.
894 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
895 struct ena_com_io_cq *io_cq);
897 /* ena_com_execute_admin_command - Execute admin command
898 * @admin_queue: admin queue.
899 * @cmd: the admin command to execute.
900 * @cmd_size: the command size.
901 * @cmd_completion: command completion return value.
902 * @cmd_comp_size: command completion size.
904 * Submit an admin command and then wait until the device will return a
906 * The completion will be copyed into cmd_comp.
908 * @return - 0 on success, negative value on failure.
910 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
911 struct ena_admin_aq_entry *cmd,
913 struct ena_admin_acq_entry *cmd_comp,
914 size_t cmd_comp_size);
916 /* ena_com_init_interrupt_moderation - Init interrupt moderation
917 * @ena_dev: ENA communication layer struct
919 * @return - 0 on success, negative value on failure.
921 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
923 /* ena_com_destroy_interrupt_moderation - Destroy interrupt moderation resources
924 * @ena_dev: ENA communication layer struct
926 void ena_com_destroy_interrupt_moderation(struct ena_com_dev *ena_dev);
928 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
929 * capability is supported by the device.
931 * @return - supported or not.
933 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
935 /* ena_com_config_default_interrupt_moderation_table - Restore the interrupt
936 * moderation table back to the default parameters.
937 * @ena_dev: ENA communication layer struct
939 void ena_com_config_default_interrupt_moderation_table(struct ena_com_dev *ena_dev);
941 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
942 * non-adaptive interval in Tx direction.
943 * @ena_dev: ENA communication layer struct
944 * @tx_coalesce_usecs: Interval in usec.
946 * @return - 0 on success, negative value on failure.
948 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
949 u32 tx_coalesce_usecs);
951 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
952 * non-adaptive interval in Rx direction.
953 * @ena_dev: ENA communication layer struct
954 * @rx_coalesce_usecs: Interval in usec.
956 * @return - 0 on success, negative value on failure.
958 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
959 u32 rx_coalesce_usecs);
961 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
962 * non-adaptive interval in Tx direction.
963 * @ena_dev: ENA communication layer struct
965 * @return - interval in usec
967 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
969 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
970 * non-adaptive interval in Rx direction.
971 * @ena_dev: ENA communication layer struct
973 * @return - interval in usec
975 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
977 /* ena_com_init_intr_moderation_entry - Update a single entry in the interrupt
979 * @ena_dev: ENA communication layer struct
980 * @level: Interrupt moderation table level
981 * @entry: Entry value
983 * Update a single entry in the interrupt moderation table.
985 void ena_com_init_intr_moderation_entry(struct ena_com_dev *ena_dev,
986 enum ena_intr_moder_level level,
987 struct ena_intr_moder_entry *entry);
989 /* ena_com_get_intr_moderation_entry - Init ena_intr_moder_entry.
990 * @ena_dev: ENA communication layer struct
991 * @level: Interrupt moderation table level
992 * @entry: Entry to fill.
994 * Initialize the entry according to the adaptive interrupt moderation table.
996 void ena_com_get_intr_moderation_entry(struct ena_com_dev *ena_dev,
997 enum ena_intr_moder_level level,
998 struct ena_intr_moder_entry *entry);
1000 /* ena_com_config_dev_mode - Configure the placement policy of the device.
1001 * @ena_dev: ENA communication layer struct
1002 * @llq_features: LLQ feature descriptor, retrieve via
1003 * ena_com_get_dev_attr_feat.
1004 * @ena_llq_config: The default driver LLQ parameters configurations
1006 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
1007 struct ena_admin_feature_llq_desc *llq_features,
1008 struct ena_llq_configurations *llq_default_config);
1010 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
1012 return ena_dev->adaptive_coalescing;
1015 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
1017 ena_dev->adaptive_coalescing = true;
1020 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
1022 ena_dev->adaptive_coalescing = false;
1025 /* ena_com_calculate_interrupt_delay - Calculate new interrupt delay
1026 * @ena_dev: ENA communication layer struct
1027 * @pkts: Number of packets since the last update
1028 * @bytes: Number of bytes received since the last update.
1029 * @smoothed_interval: Returned interval
1030 * @moder_tbl_idx: Current table level as input update new level as return
1033 static inline void ena_com_calculate_interrupt_delay(struct ena_com_dev *ena_dev,
1036 unsigned int *smoothed_interval,
1037 unsigned int *moder_tbl_idx)
1039 enum ena_intr_moder_level curr_moder_idx, new_moder_idx;
1040 struct ena_intr_moder_entry *curr_moder_entry;
1041 struct ena_intr_moder_entry *pred_moder_entry;
1042 struct ena_intr_moder_entry *new_moder_entry;
1043 struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl;
1044 unsigned int interval;
1046 /* We apply adaptive moderation on Rx path only.
1047 * Tx uses static interrupt moderation.
1049 if (!pkts || !bytes)
1050 /* Tx interrupt, or spurious interrupt,
1051 * in both cases we just use same delay values
1055 curr_moder_idx = (enum ena_intr_moder_level)(*moder_tbl_idx);
1056 if (unlikely(curr_moder_idx >= ENA_INTR_MAX_NUM_OF_LEVELS)) {
1057 ena_trc_err("Wrong moderation index %u\n", curr_moder_idx);
1061 curr_moder_entry = &intr_moder_tbl[curr_moder_idx];
1062 new_moder_idx = curr_moder_idx;
1064 if (curr_moder_idx == ENA_INTR_MODER_LOWEST) {
1065 if ((pkts > curr_moder_entry->pkts_per_interval) ||
1066 (bytes > curr_moder_entry->bytes_per_interval))
1068 (enum ena_intr_moder_level)(curr_moder_idx + ENA_INTR_MODER_LEVEL_STRIDE);
1070 pred_moder_entry = &intr_moder_tbl[curr_moder_idx - ENA_INTR_MODER_LEVEL_STRIDE];
1072 if ((pkts <= pred_moder_entry->pkts_per_interval) ||
1073 (bytes <= pred_moder_entry->bytes_per_interval))
1075 (enum ena_intr_moder_level)(curr_moder_idx - ENA_INTR_MODER_LEVEL_STRIDE);
1076 else if ((pkts > curr_moder_entry->pkts_per_interval) ||
1077 (bytes > curr_moder_entry->bytes_per_interval)) {
1078 if (curr_moder_idx != ENA_INTR_MODER_HIGHEST)
1080 (enum ena_intr_moder_level)(curr_moder_idx + ENA_INTR_MODER_LEVEL_STRIDE);
1083 new_moder_entry = &intr_moder_tbl[new_moder_idx];
1085 interval = new_moder_entry->intr_moder_interval;
1086 *smoothed_interval = (
1087 (interval * ENA_INTR_DELAY_NEW_VALUE_WEIGHT +
1088 ENA_INTR_DELAY_OLD_VALUE_WEIGHT * (*smoothed_interval)) + 5) /
1091 *moder_tbl_idx = new_moder_idx;
1094 /* ena_com_update_intr_reg - Prepare interrupt register
1095 * @intr_reg: interrupt register to update.
1096 * @rx_delay_interval: Rx interval in usecs
1097 * @tx_delay_interval: Tx interval in usecs
1098 * @unmask: unask enable/disable
1100 * Prepare interrupt update register with the supplied parameters.
1102 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
1103 u32 rx_delay_interval,
1104 u32 tx_delay_interval,
1107 intr_reg->intr_control = 0;
1108 intr_reg->intr_control |= rx_delay_interval &
1109 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
1111 intr_reg->intr_control |=
1112 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
1113 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
1116 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
1119 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
1121 u16 size, buffers_num;
1124 size = bounce_buf_ctrl->buffer_size;
1125 buffers_num = bounce_buf_ctrl->buffers_num;
1127 buf = bounce_buf_ctrl->base_buffer +
1128 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
1130 prefetchw(bounce_buf_ctrl->base_buffer +
1131 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1136 #if defined(__cplusplus)
1138 #endif /* __cplusplus */
1139 #endif /* !(ENA_COM) */