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