Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause */
2 : : /* Copyright (c) Amazon.com, Inc. or its affiliates.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #ifndef ENA_COM
7 : : #define ENA_COM
8 : :
9 : : #include "ena_plat.h"
10 : :
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))
14 : :
15 : : #define ENA_MAX_HANDLERS 256
16 : :
17 : : #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48
18 : :
19 : : /* Unit in usec */
20 : : #define ENA_REG_READ_TIMEOUT 200000
21 : :
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))
25 : :
26 : : /* Macros used to extract LSB/MSB from the
27 : : * enums defining the reset reasons
28 : : */
29 : : #define ENA_RESET_REASON_LSB_OFFSET 0
30 : : #define ENA_RESET_REASON_LSB_MASK 0xf
31 : : #define ENA_RESET_REASON_MSB_OFFSET 4
32 : : #define ENA_RESET_REASON_MSB_MASK 0xf0
33 : :
34 : : #define ENA_CUSTOMER_METRICS_BUFFER_SIZE 512
35 : :
36 : : /*****************************************************************************/
37 : : /*****************************************************************************/
38 : : /* ENA adaptive interrupt moderation settings */
39 : :
40 : : #define ENA_INTR_INITIAL_TX_INTERVAL_USECS ENA_INTR_INITIAL_TX_INTERVAL_USECS_PLAT
41 : : #define ENA_INTR_INITIAL_RX_INTERVAL_USECS ENA_INTR_INITIAL_RX_INTERVAL_USECS_PLAT
42 : : #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
43 : :
44 : : #define ENA_HASH_KEY_SIZE 40
45 : :
46 : : #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
47 : :
48 : : #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
49 : :
50 : : struct ena_llq_configurations {
51 : : enum ena_admin_llq_header_location llq_header_location;
52 : : enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
53 : : enum ena_admin_llq_stride_ctrl llq_stride_ctrl;
54 : : enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
55 : : u16 llq_ring_entry_size_value;
56 : : };
57 : :
58 : : enum queue_direction {
59 : : ENA_COM_IO_QUEUE_DIRECTION_TX,
60 : : ENA_COM_IO_QUEUE_DIRECTION_RX
61 : : };
62 : :
63 : : struct ena_com_buf {
64 : : dma_addr_t paddr; /**< Buffer physical address */
65 : : u16 len; /**< Buffer length in bytes */
66 : : };
67 : :
68 : : struct ena_com_rx_buf_info {
69 : : u16 len;
70 : : u16 req_id;
71 : : };
72 : :
73 : : struct ena_com_io_desc_addr {
74 : : u8 __iomem *pbuf_dev_addr; /* LLQ address */
75 : : u8 *virt_addr;
76 : : dma_addr_t phys_addr;
77 : : ena_mem_handle_t mem_handle;
78 : : };
79 : :
80 : : struct ena_com_tx_meta {
81 : : u16 mss;
82 : : u16 l3_hdr_len;
83 : : u16 l3_hdr_offset;
84 : : u16 l4_hdr_len; /* In words */
85 : : };
86 : :
87 : : struct ena_com_llq_info {
88 : : u16 header_location_ctrl;
89 : : u16 desc_stride_ctrl;
90 : : u16 desc_list_entry_size_ctrl;
91 : : u16 desc_list_entry_size;
92 : : u16 descs_num_before_header;
93 : : u16 descs_per_entry;
94 : : u16 max_entries_in_tx_burst;
95 : : bool disable_meta_caching;
96 : : };
97 : :
98 : : struct ena_com_io_cq {
99 : : struct ena_com_io_desc_addr cdesc_addr;
100 : : void *bus;
101 : :
102 : : /* Interrupt unmask register */
103 : : u32 __iomem *unmask_reg;
104 : :
105 : : /* numa configuration register (for TPH) */
106 : : u32 __iomem *numa_node_cfg_reg;
107 : :
108 : : /* The value to write to the above register to unmask
109 : : * the interrupt of this queue
110 : : */
111 : : u32 msix_vector ____cacheline_aligned;
112 : :
113 : : enum queue_direction direction;
114 : :
115 : : /* holds the number of cdesc of the current packet */
116 : : u16 cur_rx_pkt_cdesc_count;
117 : : /* save the first cdesc idx of the current packet */
118 : : u16 cur_rx_pkt_cdesc_start_idx;
119 : :
120 : : u16 q_depth;
121 : : /* Caller qid */
122 : : u16 qid;
123 : :
124 : : /* Device queue index */
125 : : u16 idx;
126 : : u16 head;
127 : : u8 phase;
128 : : u8 cdesc_entry_size_in_bytes;
129 : :
130 : : } ____cacheline_aligned;
131 : :
132 : : struct ena_com_io_bounce_buffer_control {
133 : : u8 *base_buffer;
134 : : u16 next_to_use;
135 : : u16 buffer_size;
136 : : u16 buffers_num; /* Must be a power of 2 */
137 : : };
138 : :
139 : : /* This struct is to keep tracking the current location of the next llq entry */
140 : : struct ena_com_llq_pkt_ctrl {
141 : : u8 *curr_bounce_buf;
142 : : u16 idx;
143 : : u16 descs_left_in_line;
144 : : };
145 : :
146 : : struct ena_com_io_sq {
147 : : struct ena_com_io_desc_addr desc_addr;
148 : : void *bus;
149 : :
150 : : u32 __iomem *db_addr;
151 : :
152 : : enum queue_direction direction;
153 : : enum ena_admin_placement_policy_type mem_queue_type;
154 : :
155 : : bool disable_meta_caching;
156 : :
157 : : u32 msix_vector;
158 : : struct ena_com_tx_meta cached_tx_meta;
159 : : struct ena_com_llq_info llq_info;
160 : : struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
161 : : struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
162 : :
163 : : u16 q_depth;
164 : : u16 qid;
165 : :
166 : : u16 idx;
167 : : u16 tail;
168 : : u16 next_to_comp;
169 : : u16 llq_last_copy_tail;
170 : : u32 tx_max_header_size;
171 : : u8 phase;
172 : : u8 desc_entry_size;
173 : : u8 dma_addr_bits;
174 : : u16 entries_in_tx_burst_left;
175 : : } ____cacheline_aligned;
176 : :
177 : : struct ena_com_admin_cq {
178 : : struct ena_admin_acq_entry *entries;
179 : : ena_mem_handle_t mem_handle;
180 : : dma_addr_t dma_addr;
181 : :
182 : : u16 head;
183 : : u8 phase;
184 : : };
185 : :
186 : : struct ena_com_admin_sq {
187 : : struct ena_admin_aq_entry *entries;
188 : : ena_mem_handle_t mem_handle;
189 : : dma_addr_t dma_addr;
190 : :
191 : : u32 __iomem *db_addr;
192 : :
193 : : u16 head;
194 : : u16 tail;
195 : : u8 phase;
196 : :
197 : : };
198 : :
199 : : struct ena_com_stats_admin {
200 : : u64 aborted_cmd;
201 : : u64 submitted_cmd;
202 : : u64 completed_cmd;
203 : : u64 out_of_space;
204 : : u64 no_completion;
205 : : };
206 : :
207 : : struct ena_com_stats_phc {
208 : : u64 phc_cnt;
209 : : u64 phc_exp;
210 : : u64 phc_skp;
211 : : u64 phc_err_dv;
212 : : u64 phc_err_ts;
213 : : u64 phc_err_eb;
214 : : };
215 : :
216 : : struct ena_com_admin_queue {
217 : : void *q_dmadev;
218 : : void *bus;
219 : : struct ena_com_dev *ena_dev;
220 : : ena_spinlock_t q_lock; /* spinlock for the admin queue */
221 : :
222 : : struct ena_comp_ctx *comp_ctx;
223 : : u32 completion_timeout;
224 : : u16 q_depth;
225 : : struct ena_com_admin_cq cq;
226 : : struct ena_com_admin_sq sq;
227 : :
228 : : /* Indicate if the admin queue should poll for completion */
229 : : bool polling;
230 : :
231 : : /* Define if fallback to polling mode should occur */
232 : : bool auto_polling;
233 : :
234 : : u16 curr_cmd_id;
235 : :
236 : : /* Indicate that the ena was initialized and can
237 : : * process new admin commands
238 : : */
239 : : bool running_state;
240 : :
241 : : bool is_missing_admin_interrupt;
242 : :
243 : : /* Count the number of outstanding admin commands */
244 : : ena_atomic32_t outstanding_cmds;
245 : :
246 : : struct ena_com_stats_admin stats;
247 : : };
248 : :
249 : : struct ena_aenq_handlers;
250 : :
251 : : struct ena_com_aenq {
252 : : u16 head;
253 : : u8 phase;
254 : : struct ena_admin_aenq_entry *entries;
255 : : dma_addr_t dma_addr;
256 : : ena_mem_handle_t mem_handle;
257 : : u16 q_depth;
258 : : struct ena_aenq_handlers *aenq_handlers;
259 : : };
260 : :
261 : : struct ena_com_mmio_read {
262 : : struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
263 : : dma_addr_t read_resp_dma_addr;
264 : : ena_mem_handle_t read_resp_mem_handle;
265 : : u32 reg_read_to; /* in us */
266 : : u16 seq_num;
267 : : bool readless_supported;
268 : : /* spin lock to ensure a single outstanding read */
269 : : ena_spinlock_t lock;
270 : : };
271 : :
272 : : /* PTP hardware clock (PHC) MMIO read data info */
273 : : struct ena_com_phc_info {
274 : : /* Internal PHC statistics */
275 : : struct ena_com_stats_phc stats;
276 : :
277 : : /* PHC shared memory - virtual address */
278 : : struct ena_admin_phc_resp *virt_addr;
279 : :
280 : : /* System time of last PHC request */
281 : : ena_time_high_res_t system_time;
282 : :
283 : : /* Spin lock to ensure a single outstanding PHC read */
284 : : ena_spinlock_t lock;
285 : :
286 : : /* PHC doorbell address as an offset to PCIe MMIO REG BAR */
287 : : u32 doorbell_offset;
288 : :
289 : : /* Shared memory read expire timeout (usec)
290 : : * Max time for valid PHC retrieval, passing this threshold will fail
291 : : * the get time request and block new PHC requests for block_timeout_usec
292 : : * in order to prevent floods on busy device
293 : : */
294 : : u32 expire_timeout_usec;
295 : :
296 : : /* Shared memory read abort timeout (usec)
297 : : * PHC requests block period, blocking starts once PHC request expired
298 : : * in order to prevent floods on busy device,
299 : : * any PHC requests during block period will be skipped
300 : : */
301 : : u32 block_timeout_usec;
302 : :
303 : : /* PHC shared memory - physical address */
304 : : dma_addr_t phys_addr;
305 : : ena_mem_handle_t mem_handle;
306 : :
307 : : /* Cached error bound per timestamp sample */
308 : : u32 error_bound;
309 : :
310 : : /* Request id sent to the device */
311 : : u16 req_id;
312 : :
313 : : /* True if PHC is active in the device */
314 : : bool active;
315 : : };
316 : :
317 : : struct ena_rss {
318 : : /* Indirect table */
319 : : u16 *host_rss_ind_tbl;
320 : : struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
321 : : dma_addr_t rss_ind_tbl_dma_addr;
322 : : ena_mem_handle_t rss_ind_tbl_mem_handle;
323 : : u16 tbl_log_size;
324 : :
325 : : /* Hash key */
326 : : enum ena_admin_hash_functions hash_func;
327 : : struct ena_admin_feature_rss_flow_hash_control *hash_key;
328 : : dma_addr_t hash_key_dma_addr;
329 : : ena_mem_handle_t hash_key_mem_handle;
330 : : u32 hash_init_val;
331 : :
332 : : /* Flow Control */
333 : : struct ena_admin_feature_rss_hash_control *hash_ctrl;
334 : : dma_addr_t hash_ctrl_dma_addr;
335 : : ena_mem_handle_t hash_ctrl_mem_handle;
336 : :
337 : : };
338 : :
339 : : struct ena_customer_metrics {
340 : : /* in correlation with ENA_ADMIN_CUSTOMER_METRICS_SUPPORT_MASK
341 : : * and ena_admin_customer_metrics_id
342 : : */
343 : : uint64_t supported_metrics;
344 : : dma_addr_t buffer_dma_addr;
345 : : void *buffer_virt_addr;
346 : : ena_mem_handle_t buffer_dma_handle;
347 : : u32 buffer_len;
348 : : };
349 : :
350 : : struct ena_host_attribute {
351 : : /* Debug area */
352 : : u8 *debug_area_virt_addr;
353 : : dma_addr_t debug_area_dma_addr;
354 : : ena_mem_handle_t debug_area_dma_handle;
355 : : u32 debug_area_size;
356 : :
357 : : /* Host information */
358 : : struct ena_admin_host_info *host_info;
359 : : dma_addr_t host_info_dma_addr;
360 : : ena_mem_handle_t host_info_dma_handle;
361 : : };
362 : :
363 : : /* Each ena_dev is a PCI function. */
364 : : struct ena_com_dev {
365 : : struct ena_com_admin_queue admin_queue;
366 : : struct ena_com_aenq aenq;
367 : : struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
368 : : struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
369 : : u8 __iomem *reg_bar;
370 : : void __iomem *mem_bar;
371 : : void *dmadev;
372 : : void *bus;
373 : : ena_netdev *net_device;
374 : :
375 : : enum ena_admin_placement_policy_type tx_mem_queue_type;
376 : : u32 tx_max_header_size;
377 : : u16 stats_func; /* Selected function for extended statistic dump */
378 : : u16 stats_queue; /* Selected queue for extended statistic dump */
379 : :
380 : : u32 ena_min_poll_delay_us;
381 : :
382 : : struct ena_com_mmio_read mmio_read;
383 : : struct ena_com_phc_info phc;
384 : :
385 : : struct ena_rss rss;
386 : : u32 supported_features;
387 : : u32 capabilities;
388 : : u32 dma_addr_bits;
389 : :
390 : : struct ena_host_attribute host_attr;
391 : : bool adaptive_coalescing;
392 : : u16 intr_delay_resolution;
393 : :
394 : : /* interrupt moderation intervals are in usec divided by
395 : : * intr_delay_resolution, which is supplied by the device.
396 : : */
397 : : u32 intr_moder_tx_interval;
398 : : u32 intr_moder_rx_interval;
399 : :
400 : : struct ena_intr_moder_entry *intr_moder_tbl;
401 : :
402 : : struct ena_com_llq_info llq_info;
403 : :
404 : : struct ena_customer_metrics customer_metrics;
405 : : bool use_extended_tx_cdesc;
406 : : bool use_extended_rx_cdesc;
407 : : };
408 : :
409 : : struct ena_com_dev_get_features_ctx {
410 : : struct ena_admin_queue_feature_desc max_queues;
411 : : struct ena_admin_queue_ext_feature_desc max_queue_ext;
412 : : struct ena_admin_device_attr_feature_desc dev_attr;
413 : : struct ena_admin_feature_aenq_desc aenq;
414 : : struct ena_admin_feature_offload_desc offload;
415 : : struct ena_admin_ena_hw_hints hw_hints;
416 : : struct ena_admin_feature_llq_desc llq;
417 : : };
418 : :
419 : : struct ena_com_create_io_ctx {
420 : : enum ena_admin_placement_policy_type mem_queue_type;
421 : : enum queue_direction direction;
422 : : int numa_node;
423 : : u32 msix_vector;
424 : : u16 queue_size;
425 : : u16 qid;
426 : : bool use_extended_cdesc;
427 : : };
428 : :
429 : : typedef void (*ena_aenq_handler)(void *data,
430 : : struct ena_admin_aenq_entry *aenq_e);
431 : :
432 : : /* Holds aenq handlers. Indexed by AENQ event group */
433 : : struct ena_aenq_handlers {
434 : : ena_aenq_handler handlers[ENA_MAX_HANDLERS];
435 : : ena_aenq_handler unimplemented_handler;
436 : : };
437 : :
438 : : /*****************************************************************************/
439 : : /*****************************************************************************/
440 : : #if defined(__cplusplus)
441 : : extern "C" {
442 : : #endif
443 : :
444 : : /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
445 : : * @ena_dev: ENA communication layer struct
446 : : *
447 : : * Initialize the register read mechanism.
448 : : *
449 : : * @note: This method must be the first stage in the initialization sequence.
450 : : *
451 : : * @return - 0 on success, negative value on failure.
452 : : */
453 : : int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
454 : :
455 : : /* ena_com_phc_init - Allocate and initialize PHC feature
456 : : * @ena_dev: ENA communication layer struct
457 : : * @note: This method assumes PHC is supported by the device
458 : : * @return - 0 on success, negative value on failure
459 : : */
460 : : int ena_com_phc_init(struct ena_com_dev *ena_dev);
461 : :
462 : : /* ena_com_phc_supported - Return if PHC feature is supported by the device
463 : : * @ena_dev: ENA communication layer struct
464 : : * @note: This method must be called after getting supported features
465 : : * @return - supported or not
466 : : */
467 : : bool ena_com_phc_supported(struct ena_com_dev *ena_dev);
468 : :
469 : : /* ena_com_phc_config - Configure PHC feature
470 : : * @ena_dev: ENA communication layer struct
471 : : * Configure PHC feature in driver and device
472 : : * @note: This method assumes PHC is supported by the device
473 : : * @return - 0 on success, negative value on failure
474 : : */
475 : : int ena_com_phc_config(struct ena_com_dev *ena_dev);
476 : :
477 : : /* ena_com_phc_destroy - Destroy PHC feature
478 : : * @ena_dev: ENA communication layer struct
479 : : */
480 : : void ena_com_phc_destroy(struct ena_com_dev *ena_dev);
481 : :
482 : : /* ena_com_phc_get_timestamp - Retrieve PHC timestamp
483 : : * @ena_dev: ENA communication layer struct
484 : : * @timestamp: Retrieved PHC timestamp
485 : : * @return - 0 on success, negative value on failure
486 : : */
487 : : int ena_com_phc_get_timestamp(struct ena_com_dev *ena_dev, u64 *timestamp);
488 : :
489 : : /* ena_com_phc_get_error_bound - Retrieve cached PHC error bound
490 : : * @ena_dev: ENA communication layer struct
491 : : * @error_bound: Cached PHC error bound
492 : : * @return - 0 on success, negative value on failure
493 : : */
494 : : int ena_com_phc_get_error_bound(struct ena_com_dev *ena_dev, u32 *error_bound);
495 : :
496 : : /* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism
497 : : * @ena_dev: ENA communication layer struct
498 : : * @readless_supported: readless mode (enable/disable)
499 : : */
500 : : void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
501 : : bool readless_supported);
502 : :
503 : : /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
504 : : * value physical address.
505 : : * @ena_dev: ENA communication layer struct
506 : : */
507 : : void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
508 : :
509 : : /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
510 : : * @ena_dev: ENA communication layer struct
511 : : */
512 : : void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
513 : :
514 : : /* ena_com_admin_init - Init the admin and the async queues
515 : : * @ena_dev: ENA communication layer struct
516 : : * @aenq_handlers: Those handlers to be called upon event.
517 : : *
518 : : * Initialize the admin submission and completion queues.
519 : : * Initialize the asynchronous events notification queues.
520 : : *
521 : : * @return - 0 on success, negative value on failure.
522 : : */
523 : : int ena_com_admin_init(struct ena_com_dev *ena_dev,
524 : : struct ena_aenq_handlers *aenq_handlers);
525 : :
526 : : /* ena_com_admin_destroy - Destroy the admin and the async events queues.
527 : : * @ena_dev: ENA communication layer struct
528 : : *
529 : : * @note: Before calling this method, the caller must validate that the device
530 : : * won't send any additional admin completions/aenq.
531 : : * To achieve that, a FLR is recommended.
532 : : */
533 : : void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
534 : :
535 : : /* ena_com_dev_reset - Perform device FLR to the device.
536 : : * @ena_dev: ENA communication layer struct
537 : : * @reset_reason: Specify what is the trigger for the reset in case of an error.
538 : : *
539 : : * @return - 0 on success, negative value on failure.
540 : : */
541 : : int ena_com_dev_reset(struct ena_com_dev *ena_dev,
542 : : enum ena_regs_reset_reason_types reset_reason);
543 : :
544 : : /* ena_com_create_io_queue - Create io queue.
545 : : * @ena_dev: ENA communication layer struct
546 : : * @ctx - create context structure
547 : : *
548 : : * Create the submission and the completion queues.
549 : : *
550 : : * @return - 0 on success, negative value on failure.
551 : : */
552 : : int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
553 : : struct ena_com_create_io_ctx *ctx);
554 : :
555 : : /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
556 : : * @ena_dev: ENA communication layer struct
557 : : * @qid - the caller virtual queue id.
558 : : */
559 : : void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
560 : :
561 : : /* ena_com_get_io_handlers - Return the io queue handlers
562 : : * @ena_dev: ENA communication layer struct
563 : : * @qid - the caller virtual queue id.
564 : : * @io_sq - IO submission queue handler
565 : : * @io_cq - IO completion queue handler.
566 : : *
567 : : * @return - 0 on success, negative value on failure.
568 : : */
569 : : int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
570 : : struct ena_com_io_sq **io_sq,
571 : : struct ena_com_io_cq **io_cq);
572 : :
573 : : /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
574 : : * @ena_dev: ENA communication layer struct
575 : : *
576 : : * After this method, aenq event can be received via AENQ.
577 : : */
578 : : void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
579 : :
580 : : /* ena_com_set_admin_running_state - Set the state of the admin queue
581 : : * @ena_dev: ENA communication layer struct
582 : : *
583 : : * Change the state of the admin queue (enable/disable)
584 : : */
585 : : void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
586 : :
587 : : /* ena_com_get_admin_running_state - Get the admin queue state
588 : : * @ena_dev: ENA communication layer struct
589 : : *
590 : : * Retrieve the state of the admin queue (enable/disable)
591 : : *
592 : : * @return - current polling mode (enable/disable)
593 : : */
594 : : bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
595 : :
596 : : /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
597 : : * @ena_dev: ENA communication layer struct
598 : : * @polling: ENAble/Disable polling mode
599 : : *
600 : : * Set the admin completion mode.
601 : : */
602 : : void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
603 : :
604 : : /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
605 : : * @ena_dev: ENA communication layer struct
606 : : *
607 : : * Get the admin completion mode.
608 : : * If polling mode is on, ena_com_execute_admin_command will perform a
609 : : * polling on the admin completion queue for the commands completion,
610 : : * otherwise it will wait on wait event.
611 : : *
612 : : * @return state
613 : : */
614 : : bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
615 : :
616 : : /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
617 : : * @ena_dev: ENA communication layer struct
618 : : * @polling: Enable/Disable polling mode
619 : : *
620 : : * Set the autopolling mode.
621 : : * If autopolling is on:
622 : : * In case of missing interrupt when data is available switch to polling.
623 : : */
624 : : void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
625 : : bool polling);
626 : :
627 : : /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
628 : : * @ena_dev: ENA communication layer struct
629 : : *
630 : : * This method goes over the admin completion queue and wakes up all the pending
631 : : * threads that wait on the commands wait event.
632 : : *
633 : : * @note: Should be called after MSI-X interrupt.
634 : : */
635 : : void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
636 : :
637 : : /* ena_com_aenq_intr_handler - AENQ interrupt handler
638 : : * @ena_dev: ENA communication layer struct
639 : : *
640 : : * This method goes over the async event notification queue and calls the proper
641 : : * aenq handler.
642 : : */
643 : : void ena_com_aenq_intr_handler(struct ena_com_dev *ena_dev, void *data);
644 : :
645 : : /* ena_com_aenq_has_keep_alive - Retrieve if there is a keep alive notification in the aenq
646 : : * @ena_dev: ENA communication layer struct
647 : : *
648 : : * This method goes over the async event notification queue and returns if there
649 : : * is a keep alive notification.
650 : : *
651 : : * @return - true if there is a keep alive notification in the aenq or false otherwise
652 : : */
653 : : bool ena_com_aenq_has_keep_alive(struct ena_com_dev *ena_dev);
654 : :
655 : : /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
656 : : * @ena_dev: ENA communication layer struct
657 : : *
658 : : * This method aborts all the outstanding admin commands.
659 : : * The caller should then call ena_com_wait_for_abort_completion to make sure
660 : : * all the commands were completed.
661 : : */
662 : : void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
663 : :
664 : : /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
665 : : * @ena_dev: ENA communication layer struct
666 : : *
667 : : * This method waits until all the outstanding admin commands are completed.
668 : : */
669 : : void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
670 : :
671 : : /* ena_com_validate_version - Validate the device parameters
672 : : * @ena_dev: ENA communication layer struct
673 : : *
674 : : * This method verifies the device parameters are the same as the saved
675 : : * parameters in ena_dev.
676 : : * This method is useful after device reset, to validate the device mac address
677 : : * and the device offloads are the same as before the reset.
678 : : *
679 : : * @return - 0 on success negative value otherwise.
680 : : */
681 : : int ena_com_validate_version(struct ena_com_dev *ena_dev);
682 : :
683 : : /* ena_com_get_link_params - Retrieve physical link parameters.
684 : : * @ena_dev: ENA communication layer struct
685 : : * @resp: Link parameters
686 : : *
687 : : * Retrieve the physical link parameters,
688 : : * like speed, auto-negotiation and full duplex support.
689 : : *
690 : : * @return - 0 on Success negative value otherwise.
691 : : */
692 : : int ena_com_get_link_params(struct ena_com_dev *ena_dev,
693 : : struct ena_admin_get_feat_resp *resp);
694 : :
695 : : /* ena_com_get_dma_width - Retrieve physical dma address width the device
696 : : * supports.
697 : : * @ena_dev: ENA communication layer struct
698 : : *
699 : : * Retrieve the maximum physical address bits the device can handle.
700 : : *
701 : : * @return: > 0 on Success and negative value otherwise.
702 : : */
703 : : int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
704 : :
705 : : /* ena_com_set_aenq_config - Set aenq groups configurations
706 : : * @ena_dev: ENA communication layer struct
707 : : * @groups flag: bit fields flags of enum ena_admin_aenq_group.
708 : : *
709 : : * Configure which aenq event group the driver would like to receive.
710 : : *
711 : : * @return: 0 on Success and negative value otherwise.
712 : : */
713 : : int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
714 : :
715 : : /* ena_com_get_dev_attr_feat - Get device features
716 : : * @ena_dev: ENA communication layer struct
717 : : * @get_feat_ctx: returned context that contain the get features.
718 : : *
719 : : * @return: 0 on Success and negative value otherwise.
720 : : */
721 : : int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
722 : : struct ena_com_dev_get_features_ctx *get_feat_ctx);
723 : :
724 : : /* ena_com_get_dev_basic_stats - Get device basic statistics
725 : : * @ena_dev: ENA communication layer struct
726 : : * @stats: stats return value
727 : : *
728 : : * @return: 0 on Success and negative value otherwise.
729 : : */
730 : : int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
731 : : struct ena_admin_basic_stats *stats);
732 : :
733 : : /* ena_com_get_eni_stats - Get extended network interface statistics
734 : : * @ena_dev: ENA communication layer struct
735 : : * @stats: stats return value
736 : : *
737 : : * @return: 0 on Success and negative value otherwise.
738 : : */
739 : : int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
740 : : struct ena_admin_eni_stats *stats);
741 : :
742 : : /* ena_com_get_ena_srd_info - Get ENA SRD network interface statistics
743 : : * @ena_dev: ENA communication layer struct
744 : : * @info: ena srd stats and flags
745 : : *
746 : : * @return: 0 on Success and negative value otherwise.
747 : : */
748 : : int ena_com_get_ena_srd_info(struct ena_com_dev *ena_dev,
749 : : struct ena_admin_ena_srd_info *info);
750 : :
751 : : /* ena_com_get_customer_metrics - Get customer metrics for network interface
752 : : * @ena_dev: ENA communication layer struct
753 : : * @buffer: buffer for returned customer metrics
754 : : * @len: size of the buffer
755 : : *
756 : : * @return: 0 on Success and negative value otherwise.
757 : : */
758 : : int ena_com_get_customer_metrics(struct ena_com_dev *ena_dev, char *buffer, u32 len);
759 : :
760 : : /* ena_com_set_dev_mtu - Configure the device mtu.
761 : : * @ena_dev: ENA communication layer struct
762 : : * @mtu: mtu value
763 : : *
764 : : * @return: 0 on Success and negative value otherwise.
765 : : */
766 : : int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, u32 mtu);
767 : :
768 : : /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
769 : : * @ena_dev: ENA communication layer struct
770 : : * @offlad: offload return value
771 : : *
772 : : * @return: 0 on Success and negative value otherwise.
773 : : */
774 : :
775 : : /* ena_com_rss_init - Init RSS
776 : : * @ena_dev: ENA communication layer struct
777 : : * @log_size: indirection log size
778 : : *
779 : : * Allocate RSS/RFS resources.
780 : : * The caller then can configure rss using ena_com_set_hash_function,
781 : : * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
782 : : *
783 : : * @return: 0 on Success and negative value otherwise.
784 : : */
785 : : int ena_com_rss_init(struct ena_com_dev *ena_dev);
786 : :
787 : : /* ena_com_rss_destroy - Destroy rss
788 : : * @ena_dev: ENA communication layer struct
789 : : *
790 : : * Free all the RSS/RFS resources.
791 : : */
792 : : void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
793 : :
794 : : /* ena_com_get_current_hash_function - Get RSS hash function
795 : : * @ena_dev: ENA communication layer struct
796 : : *
797 : : * Return the current hash function.
798 : : * @return: 0 or one of the ena_admin_hash_functions values.
799 : : */
800 : : int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
801 : :
802 : : /* ena_com_fill_hash_function - Fill RSS hash function
803 : : * @ena_dev: ENA communication layer struct
804 : : * @func: The hash function (Toeplitz or crc)
805 : : * @key: Hash key (for toeplitz hash)
806 : : * @key_len: key length (max length 10 DW)
807 : : * @init_val: initial value for the hash function
808 : : *
809 : : * Fill the ena_dev resources with the desire hash function, hash key, key_len
810 : : * and key initial value (if needed by the hash function).
811 : : * To flush the key into the device the caller should call
812 : : * ena_com_set_hash_function.
813 : : *
814 : : * @return: 0 on Success and negative value otherwise.
815 : : */
816 : : int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
817 : : enum ena_admin_hash_functions func,
818 : : const u8 *key, u16 key_len, u32 init_val);
819 : :
820 : : /* ena_com_set_hash_function - Flush the hash function and it dependencies to
821 : : * the device.
822 : : * @ena_dev: ENA communication layer struct
823 : : *
824 : : * Flush the hash function and it dependencies (key, key length and
825 : : * initial value) if needed.
826 : : *
827 : : * @note: Prior to this method the caller should call ena_com_fill_hash_function
828 : : *
829 : : * @return: 0 on Success and negative value otherwise.
830 : : */
831 : : int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
832 : :
833 : : /* ena_com_get_hash_function - Retrieve the hash function from the device.
834 : : * @ena_dev: ENA communication layer struct
835 : : * @func: hash function
836 : : *
837 : : * Retrieve the hash function from the device.
838 : : *
839 : : * @note: If the caller called ena_com_fill_hash_function but didn't flush
840 : : * it to the device, the new configuration will be lost.
841 : : *
842 : : * @return: 0 on Success and negative value otherwise.
843 : : */
844 : : int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
845 : : enum ena_admin_hash_functions *func);
846 : :
847 : : /* ena_com_get_hash_key - Retrieve the hash key
848 : : * @ena_dev: ENA communication layer struct
849 : : * @key: hash key
850 : : *
851 : : * Retrieve the hash key.
852 : : *
853 : : * @note: If the caller called ena_com_fill_hash_key but didn't flush
854 : : * it to the device, the new configuration will be lost.
855 : : *
856 : : * @return: 0 on Success and negative value otherwise.
857 : : */
858 : : int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
859 : : /* ena_com_fill_hash_ctrl - Fill RSS hash control
860 : : * @ena_dev: ENA communication layer struct.
861 : : * @proto: The protocol to configure.
862 : : * @hash_fields: bit mask of ena_admin_flow_hash_fields
863 : : *
864 : : * Fill the ena_dev resources with the desire hash control (the ethernet
865 : : * fields that take part of the hash) for a specific protocol.
866 : : * To flush the hash control to the device, the caller should call
867 : : * ena_com_set_hash_ctrl.
868 : : *
869 : : * @return: 0 on Success and negative value otherwise.
870 : : */
871 : : int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
872 : : enum ena_admin_flow_hash_proto proto,
873 : : u16 hash_fields);
874 : :
875 : : /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
876 : : * @ena_dev: ENA communication layer struct
877 : : *
878 : : * Flush the hash control (the ethernet fields that take part of the hash)
879 : : *
880 : : * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
881 : : *
882 : : * @return: 0 on Success and negative value otherwise.
883 : : */
884 : : int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
885 : :
886 : : /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
887 : : * @ena_dev: ENA communication layer struct
888 : : * @proto: The protocol to retrieve.
889 : : * @fields: bit mask of ena_admin_flow_hash_fields.
890 : : *
891 : : * Retrieve the hash control from the device.
892 : : *
893 : : * @note: If the caller called ena_com_fill_hash_ctrl but didn't flush
894 : : * it to the device, the new configuration will be lost.
895 : : *
896 : : * @return: 0 on Success and negative value otherwise.
897 : : */
898 : : int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
899 : : enum ena_admin_flow_hash_proto proto,
900 : : u16 *fields);
901 : :
902 : : /* ena_com_set_default_hash_ctrl - Set the hash control to a default
903 : : * configuration.
904 : : * @ena_dev: ENA communication layer struct
905 : : *
906 : : * Fill the ena_dev resources with the default hash control configuration.
907 : : * To flush the hash control to the device, the caller should call
908 : : * ena_com_set_hash_ctrl.
909 : : *
910 : : * @return: 0 on Success and negative value otherwise.
911 : : */
912 : : int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
913 : :
914 : : /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
915 : : * indirection table
916 : : * @ena_dev: ENA communication layer struct.
917 : : * @entry_idx - indirection table entry.
918 : : * @entry_value - redirection value
919 : : *
920 : : * Fill a single entry of the RSS indirection table in the ena_dev resources.
921 : : * To flush the indirection table to the device, the called should call
922 : : * ena_com_indirect_table_set.
923 : : *
924 : : * @return: 0 on Success and negative value otherwise.
925 : : */
926 : : int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
927 : : u16 entry_idx, u16 entry_value);
928 : :
929 : : /* ena_com_indirect_table_set - Flush the indirection table to the device.
930 : : * @ena_dev: ENA communication layer struct
931 : : *
932 : : * Flush the indirection hash control to the device.
933 : : * Prior to this method the caller should call ena_com_indirect_table_fill_entry
934 : : *
935 : : * @return: 0 on Success and negative value otherwise.
936 : : */
937 : : int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
938 : :
939 : : /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
940 : : * @ena_dev: ENA communication layer struct
941 : : * @ind_tbl: indirection table
942 : : *
943 : : * Retrieve the RSS indirection table from the device.
944 : : *
945 : : * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush
946 : : * it to the device, the new configuration will be lost.
947 : : *
948 : : * @return: 0 on Success and negative value otherwise.
949 : : */
950 : : int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
951 : :
952 : : /* ena_com_allocate_host_info - Allocate host info resources.
953 : : * @ena_dev: ENA communication layer struct
954 : : *
955 : : * @return: 0 on Success and negative value otherwise.
956 : : */
957 : : int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
958 : :
959 : : /* ena_com_allocate_debug_area - Allocate debug area.
960 : : * @ena_dev: ENA communication layer struct
961 : : * @debug_area_size - debug area size.
962 : : *
963 : : * @return: 0 on Success and negative value otherwise.
964 : : */
965 : : int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
966 : : u32 debug_area_size);
967 : :
968 : : /* ena_com_allocate_customer_metrics_buffer - Allocate customer metrics resources.
969 : : * @ena_dev: ENA communication layer struct
970 : : *
971 : : * @return: 0 on Success and negative value otherwise.
972 : : */
973 : : int ena_com_allocate_customer_metrics_buffer(struct ena_com_dev *ena_dev);
974 : :
975 : : /* ena_com_delete_debug_area - Free the debug area resources.
976 : : * @ena_dev: ENA communication layer struct
977 : : *
978 : : * Free the allocated debug area.
979 : : */
980 : : void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
981 : :
982 : : /* ena_com_delete_host_info - Free the host info resources.
983 : : * @ena_dev: ENA communication layer struct
984 : : *
985 : : * Free the allocated host info.
986 : : */
987 : : void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
988 : :
989 : : /* ena_com_delete_customer_metrics_buffer - Free the customer metrics resources.
990 : : * @ena_dev: ENA communication layer struct
991 : : *
992 : : * Free the allocated customer metrics area.
993 : : */
994 : : void ena_com_delete_customer_metrics_buffer(struct ena_com_dev *ena_dev);
995 : :
996 : : /* ena_com_set_host_attributes - Update the device with the host
997 : : * attributes (debug area and host info) base address.
998 : : * @ena_dev: ENA communication layer struct
999 : : *
1000 : : * @return: 0 on Success and negative value otherwise.
1001 : : */
1002 : : int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
1003 : :
1004 : : /* ena_com_create_io_cq - Create io completion queue.
1005 : : * @ena_dev: ENA communication layer struct
1006 : : * @io_cq - io completion queue handler
1007 : :
1008 : : * Create IO completion queue.
1009 : : *
1010 : : * @return - 0 on success, negative value on failure.
1011 : : */
1012 : : int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
1013 : : struct ena_com_io_cq *io_cq);
1014 : :
1015 : : /* ena_com_destroy_io_cq - Destroy io completion queue.
1016 : : * @ena_dev: ENA communication layer struct
1017 : : * @io_cq - io completion queue handler
1018 : :
1019 : : * Destroy IO completion queue.
1020 : : *
1021 : : * @return - 0 on success, negative value on failure.
1022 : : */
1023 : : int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
1024 : : struct ena_com_io_cq *io_cq);
1025 : :
1026 : : /* ena_com_execute_admin_command - Execute admin command
1027 : : * @admin_queue: admin queue.
1028 : : * @cmd: the admin command to execute.
1029 : : * @cmd_size: the command size.
1030 : : * @cmd_completion: command completion return value.
1031 : : * @cmd_comp_size: command completion size.
1032 : :
1033 : : * Submit an admin command and then wait until the device returns a
1034 : : * completion.
1035 : : * The completion will be copied into cmd_comp.
1036 : : *
1037 : : * @return - 0 on success, negative value on failure.
1038 : : */
1039 : : int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
1040 : : struct ena_admin_aq_entry *cmd,
1041 : : size_t cmd_size,
1042 : : struct ena_admin_acq_entry *cmd_comp,
1043 : : size_t cmd_comp_size);
1044 : :
1045 : : /* ena_com_init_interrupt_moderation - Init interrupt moderation
1046 : : * @ena_dev: ENA communication layer struct
1047 : : *
1048 : : * @return - 0 on success, negative value on failure.
1049 : : */
1050 : : int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
1051 : :
1052 : : /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
1053 : : * capability is supported by the device.
1054 : : *
1055 : : * @return - supported or not.
1056 : : */
1057 : : bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
1058 : :
1059 : : /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
1060 : : * non-adaptive interval in Tx direction.
1061 : : * @ena_dev: ENA communication layer struct
1062 : : * @tx_coalesce_usecs: Interval in usec.
1063 : : *
1064 : : * @return - 0 on success, negative value on failure.
1065 : : */
1066 : : int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
1067 : : u32 tx_coalesce_usecs);
1068 : :
1069 : : /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
1070 : : * non-adaptive interval in Rx direction.
1071 : : * @ena_dev: ENA communication layer struct
1072 : : * @rx_coalesce_usecs: Interval in usec.
1073 : : *
1074 : : * @return - 0 on success, negative value on failure.
1075 : : */
1076 : : int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
1077 : : u32 rx_coalesce_usecs);
1078 : :
1079 : : /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
1080 : : * non-adaptive interval in Tx direction.
1081 : : * @ena_dev: ENA communication layer struct
1082 : : *
1083 : : * @return - interval in usec
1084 : : */
1085 : : unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
1086 : :
1087 : : /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
1088 : : * non-adaptive interval in Rx direction.
1089 : : * @ena_dev: ENA communication layer struct
1090 : : *
1091 : : * @return - interval in usec
1092 : : */
1093 : : unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
1094 : :
1095 : : /* ena_com_config_dev_mode - Configure the placement policy of the device.
1096 : : * @ena_dev: ENA communication layer struct
1097 : : * @llq_features: LLQ feature descriptor, retrieve via
1098 : : * ena_com_get_dev_attr_feat.
1099 : : * @ena_llq_config: The default driver LLQ parameters configurations
1100 : : */
1101 : : int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
1102 : : struct ena_admin_feature_llq_desc *llq_features,
1103 : : struct ena_llq_configurations *llq_default_config);
1104 : :
1105 : : /* ena_com_get_missing_admin_interrupt - Return if there is a missing admin interrupt
1106 : : * @ena_dev: ENA communication layer struct
1107 : : *
1108 : : * @return - true if there is a missing admin interrupt or false otherwise
1109 : : */
1110 : : static inline bool ena_com_get_missing_admin_interrupt(struct ena_com_dev *ena_dev)
1111 : : {
1112 : : return ena_dev->admin_queue.is_missing_admin_interrupt;
1113 : : }
1114 : :
1115 : : /* ena_com_set_frag_bypass - set fragment bypass
1116 : : * @ena_dev: ENA communication layer struct
1117 : : * @enable: true if fragment bypass is enabled, false otherwise.
1118 : : *
1119 : : * @return - 0 on success, negative value on failure.
1120 : : */
1121 : : int ena_com_set_frag_bypass(struct ena_com_dev *ena_dev, bool enable);
1122 : : /* ena_com_io_sq_to_ena_dev - Extract ena_com_dev using contained field io_sq.
1123 : : * @io_sq: IO submit queue struct
1124 : : *
1125 : : * @return - ena_com_dev struct extracted from io_sq
1126 : : */
1127 : : static inline struct ena_com_dev *ena_com_io_sq_to_ena_dev(struct ena_com_io_sq *io_sq)
1128 : : {
1129 : : return container_of(io_sq, struct ena_com_dev, io_sq_queues[io_sq->qid]);
1130 : : }
1131 : :
1132 : : /* ena_com_io_cq_to_ena_dev - Extract ena_com_dev using contained field io_cq.
1133 : : * @io_sq: IO submit queue struct
1134 : : *
1135 : : * @return - ena_com_dev struct extracted from io_sq
1136 : : */
1137 : : static inline struct ena_com_dev *ena_com_io_cq_to_ena_dev(struct ena_com_io_cq *io_cq)
1138 : : {
1139 [ # # ]: 0 : return container_of(io_cq, struct ena_com_dev, io_cq_queues[io_cq->qid]);
1140 : : }
1141 : :
1142 : : static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
1143 : : {
1144 : : return ena_dev->adaptive_coalescing;
1145 : : }
1146 : :
1147 : : static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
1148 : : {
1149 : : ena_dev->adaptive_coalescing = true;
1150 : : }
1151 : :
1152 : : static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
1153 : : {
1154 : 0 : ena_dev->adaptive_coalescing = false;
1155 : : }
1156 : :
1157 : : /* ena_com_hw_timestamping_supported - query whether HW timestamping is
1158 : : * supported by the device
1159 : : * @ena_dev: ENA communication layer struct
1160 : : *
1161 : : * @return - true if the feature is supported or false otherwise
1162 : : */
1163 : : bool ena_com_hw_timestamping_supported(struct ena_com_dev *ena_dev);
1164 : :
1165 : : /* ena_com_get_hw_timestamping_support - query HW timestamping support options
1166 : : * in the device
1167 : : * @ena_dev: ENA communication layer struct
1168 : : * @tx_support: Will hold the TX side supported options
1169 : : * @rx_support: Will hold the RX side supported options
1170 : : *
1171 : : * @return - 0 on success, negative value on failure.
1172 : : */
1173 : : int ena_com_get_hw_timestamping_support(struct ena_com_dev *ena_dev,
1174 : : u8 *tx_support,
1175 : : u8 *rx_support);
1176 : :
1177 : : /* ena_com_set_hw_timestamping_configuration - set HW timestamping configuration
1178 : : *
1179 : : * @ena_dev: ENA communication layer struct
1180 : : * @tx_enable: Enable/Disable TX HW timestamping
1181 : : * @rx_enable: Enable/Disable RX HW timestamping
1182 : : *
1183 : : * @return - 0 on success, negative value on failure.
1184 : : */
1185 : : int ena_com_set_hw_timestamping_configuration(struct ena_com_dev *ena_dev,
1186 : : u8 tx_enable,
1187 : : u8 rx_enable);
1188 : :
1189 : : bool ena_com_indirection_table_config_supported(struct ena_com_dev *ena_dev);
1190 : : /* ena_com_get_cap - query whether device supports a capability.
1191 : : * @ena_dev: ENA communication layer struct
1192 : : * @cap_id: enum value representing the capability
1193 : : *
1194 : : * @return - true if capability is supported or false otherwise
1195 : : */
1196 : : static inline bool ena_com_get_cap(struct ena_com_dev *ena_dev,
1197 : : enum ena_admin_aq_caps_id cap_id)
1198 : : {
1199 [ # # # # : 0 : return !!(ena_dev->capabilities & BIT(cap_id));
# # # # #
# # # ]
1200 : : }
1201 : :
1202 : : /* ena_com_get_customer_metric_support - query whether device supports a given customer metric.
1203 : : * @ena_dev: ENA communication layer struct
1204 : : * @metric_id: enum value representing the customer metric
1205 : : *
1206 : : * @return - true if customer metric is supported or false otherwise
1207 : : */
1208 : : static inline bool ena_com_get_customer_metric_support(struct ena_com_dev *ena_dev,
1209 : : enum ena_admin_customer_metrics_id metric_id)
1210 : : {
1211 : : return !!(ena_dev->customer_metrics.supported_metrics & BIT64(metric_id));
1212 : : }
1213 : :
1214 : : /* ena_com_get_customer_metric_count - return the number of supported customer metrics.
1215 : : * @ena_dev: ENA communication layer struct
1216 : : *
1217 : : * @return - the number of supported customer metrics
1218 : : */
1219 : : static inline int ena_com_get_customer_metric_count(struct ena_com_dev *ena_dev)
1220 : : {
1221 : : return ENA_BITS_PER_U64(ena_dev->customer_metrics.supported_metrics);
1222 : : }
1223 : :
1224 : : /* ena_com_update_intr_reg - Prepare interrupt register
1225 : : * @intr_reg: interrupt register to update.
1226 : : * @rx_delay_interval: Rx interval in usecs
1227 : : * @tx_delay_interval: Tx interval in usecs
1228 : : * @unmask: unmask enable/disable
1229 : : * @no_moderation_update: 0 - Indicates that any of the TX/RX intervals was
1230 : : * updated, 1 - otherwise
1231 : : * @lost_interrupt: true - if driver heuristic indicates interrupt was lost
1232 : : * false - otherwise
1233 : : *
1234 : : * Prepare interrupt update register with the supplied parameters.
1235 : : */
1236 : : static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
1237 : : u32 rx_delay_interval,
1238 : : u32 tx_delay_interval,
1239 : : bool unmask,
1240 : : bool no_moderation_update,
1241 : : bool lost_interrupt)
1242 : : {
1243 : : intr_reg->intr_control = 0;
1244 : : intr_reg->intr_control |= rx_delay_interval &
1245 : : ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
1246 : :
1247 : : intr_reg->intr_control |=
1248 : : ENA_FIELD_PREP(tx_delay_interval,
1249 : : ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK,
1250 : : ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT);
1251 : :
1252 : : if (likely(unmask && !lost_interrupt))
1253 : : intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
1254 : :
1255 : : intr_reg->intr_control |=
1256 : : ENA_FIELD_PREP(((u32)(no_moderation_update && !lost_interrupt)),
1257 : : ENA_ETH_IO_INTR_REG_NO_MODERATION_UPDATE_MASK,
1258 : : ENA_ETH_IO_INTR_REG_NO_MODERATION_UPDATE_SHIFT);
1259 : : }
1260 : :
1261 : : static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
1262 : : {
1263 : : u16 size, buffers_num;
1264 : : u8 *buf;
1265 : :
1266 : 0 : size = bounce_buf_ctrl->buffer_size;
1267 : 0 : buffers_num = bounce_buf_ctrl->buffers_num;
1268 : :
1269 : 0 : buf = bounce_buf_ctrl->base_buffer +
1270 : 0 : (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
1271 : :
1272 : 0 : prefetchw(bounce_buf_ctrl->base_buffer +
1273 : : (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
1274 : :
1275 : : return buf;
1276 : : }
1277 : :
1278 : : #if defined(__cplusplus)
1279 : : }
1280 : : #endif /* __cplusplus */
1281 : : #endif /* !(ENA_COM) */
|