751bfcdd7e158ecc51ee3c223c486ccda6599dcc
[dpdk.git] / drivers / net / ena / base / ena_com.h
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 /*****************************************************************************/
27 /*****************************************************************************/
28 /* ENA adaptive interrupt moderation settings */
29
30 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS ENA_INTR_INITIAL_TX_INTERVAL_USECS_PLAT
31 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0
32 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1
33
34 #define ENA_HASH_KEY_SIZE                               40
35
36 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF
37
38 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1
39
40 struct ena_llq_configurations {
41         enum ena_admin_llq_header_location llq_header_location;
42         enum ena_admin_llq_ring_entry_size llq_ring_entry_size;
43         enum ena_admin_llq_stride_ctrl  llq_stride_ctrl;
44         enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header;
45         u16 llq_ring_entry_size_value;
46 };
47
48 enum queue_direction {
49         ENA_COM_IO_QUEUE_DIRECTION_TX,
50         ENA_COM_IO_QUEUE_DIRECTION_RX
51 };
52
53 struct ena_com_buf {
54         dma_addr_t paddr; /**< Buffer physical address */
55         u16 len; /**< Buffer length in bytes */
56 };
57
58 struct ena_com_rx_buf_info {
59         u16 len;
60         u16 req_id;
61 };
62
63 struct ena_com_io_desc_addr {
64         u8 __iomem *pbuf_dev_addr; /* LLQ address */
65         u8 *virt_addr;
66         dma_addr_t phys_addr;
67         ena_mem_handle_t mem_handle;
68 };
69
70 struct ena_com_tx_meta {
71         u16 mss;
72         u16 l3_hdr_len;
73         u16 l3_hdr_offset;
74         u16 l4_hdr_len; /* In words */
75 };
76
77 struct ena_com_llq_info {
78         u16 header_location_ctrl;
79         u16 desc_stride_ctrl;
80         u16 desc_list_entry_size_ctrl;
81         u16 desc_list_entry_size;
82         u16 descs_num_before_header;
83         u16 descs_per_entry;
84         u16 max_entries_in_tx_burst;
85         bool disable_meta_caching;
86 };
87
88 struct ena_com_io_cq {
89         struct ena_com_io_desc_addr cdesc_addr;
90         void *bus;
91
92         /* Interrupt unmask register */
93         u32 __iomem *unmask_reg;
94
95         /* The completion queue head doorbell register */
96         u32 __iomem *cq_head_db_reg;
97
98         /* numa configuration register (for TPH) */
99         u32 __iomem *numa_node_cfg_reg;
100
101         /* The value to write to the above register to unmask
102          * the interrupt of this queue
103          */
104         u32 msix_vector;
105
106         enum queue_direction direction;
107
108         /* holds the number of cdesc of the current packet */
109         u16 cur_rx_pkt_cdesc_count;
110         /* save the firt cdesc idx of the current packet */
111         u16 cur_rx_pkt_cdesc_start_idx;
112
113         u16 q_depth;
114         /* Caller qid */
115         u16 qid;
116
117         /* Device queue index */
118         u16 idx;
119         u16 head;
120         u16 last_head_update;
121         u8 phase;
122         u8 cdesc_entry_size_in_bytes;
123
124 } ____cacheline_aligned;
125
126 struct ena_com_io_bounce_buffer_control {
127         u8 *base_buffer;
128         u16 next_to_use;
129         u16 buffer_size;
130         u16 buffers_num;  /* Must be a power of 2 */
131 };
132
133 /* This struct is to keep tracking the current location of the next llq entry */
134 struct ena_com_llq_pkt_ctrl {
135         u8 *curr_bounce_buf;
136         u16 idx;
137         u16 descs_left_in_line;
138 };
139
140 struct ena_com_io_sq {
141         struct ena_com_io_desc_addr desc_addr;
142         void *bus;
143
144         u32 __iomem *db_addr;
145         u8 __iomem *header_addr;
146
147         enum queue_direction direction;
148         enum ena_admin_placement_policy_type mem_queue_type;
149
150         bool disable_meta_caching;
151
152         u32 msix_vector;
153         struct ena_com_tx_meta cached_tx_meta;
154         struct ena_com_llq_info llq_info;
155         struct ena_com_llq_pkt_ctrl llq_buf_ctrl;
156         struct ena_com_io_bounce_buffer_control bounce_buf_ctrl;
157
158         u16 q_depth;
159         u16 qid;
160
161         u16 idx;
162         u16 tail;
163         u16 next_to_comp;
164         u16 llq_last_copy_tail;
165         u32 tx_max_header_size;
166         u8 phase;
167         u8 desc_entry_size;
168         u8 dma_addr_bits;
169         u16 entries_in_tx_burst_left;
170 } ____cacheline_aligned;
171
172 struct ena_com_admin_cq {
173         struct ena_admin_acq_entry *entries;
174         ena_mem_handle_t mem_handle;
175         dma_addr_t dma_addr;
176
177         u16 head;
178         u8 phase;
179 };
180
181 struct ena_com_admin_sq {
182         struct ena_admin_aq_entry *entries;
183         ena_mem_handle_t mem_handle;
184         dma_addr_t dma_addr;
185
186         u32 __iomem *db_addr;
187
188         u16 head;
189         u16 tail;
190         u8 phase;
191
192 };
193
194 struct ena_com_stats_admin {
195         u32 aborted_cmd;
196         u32 submitted_cmd;
197         u32 completed_cmd;
198         u32 out_of_space;
199         u32 no_completion;
200 };
201
202 struct ena_com_admin_queue {
203         void *q_dmadev;
204         void *bus;
205         struct ena_com_dev *ena_dev;
206         ena_spinlock_t q_lock; /* spinlock for the admin queue */
207
208         struct ena_comp_ctx *comp_ctx;
209         u32 completion_timeout;
210         u16 q_depth;
211         struct ena_com_admin_cq cq;
212         struct ena_com_admin_sq sq;
213
214         /* Indicate if the admin queue should poll for completion */
215         bool polling;
216
217         /* Define if fallback to polling mode should occur */
218         bool auto_polling;
219
220         u16 curr_cmd_id;
221
222         /* Indicate that the ena was initialized and can
223          * process new admin commands
224          */
225         bool running_state;
226
227         /* Count the number of outstanding admin commands */
228         ena_atomic32_t outstanding_cmds;
229
230         struct ena_com_stats_admin stats;
231 };
232
233 struct ena_aenq_handlers;
234
235 struct ena_com_aenq {
236         u16 head;
237         u8 phase;
238         struct ena_admin_aenq_entry *entries;
239         dma_addr_t dma_addr;
240         ena_mem_handle_t mem_handle;
241         u16 q_depth;
242         struct ena_aenq_handlers *aenq_handlers;
243 };
244
245 struct ena_com_mmio_read {
246         struct ena_admin_ena_mmio_req_read_less_resp *read_resp;
247         dma_addr_t read_resp_dma_addr;
248         ena_mem_handle_t read_resp_mem_handle;
249         u32 reg_read_to; /* in us */
250         u16 seq_num;
251         bool readless_supported;
252         /* spin lock to ensure a single outstanding read */
253         ena_spinlock_t lock;
254 };
255
256 struct ena_rss {
257         /* Indirect table */
258         u16 *host_rss_ind_tbl;
259         struct ena_admin_rss_ind_table_entry *rss_ind_tbl;
260         dma_addr_t rss_ind_tbl_dma_addr;
261         ena_mem_handle_t rss_ind_tbl_mem_handle;
262         u16 tbl_log_size;
263
264         /* Hash key */
265         enum ena_admin_hash_functions hash_func;
266         struct ena_admin_feature_rss_flow_hash_control *hash_key;
267         dma_addr_t hash_key_dma_addr;
268         ena_mem_handle_t hash_key_mem_handle;
269         u32 hash_init_val;
270
271         /* Flow Control */
272         struct ena_admin_feature_rss_hash_control *hash_ctrl;
273         dma_addr_t hash_ctrl_dma_addr;
274         ena_mem_handle_t hash_ctrl_mem_handle;
275
276 };
277
278 struct ena_host_attribute {
279         /* Debug area */
280         u8 *debug_area_virt_addr;
281         dma_addr_t debug_area_dma_addr;
282         ena_mem_handle_t debug_area_dma_handle;
283         u32 debug_area_size;
284
285         /* Host information */
286         struct ena_admin_host_info *host_info;
287         dma_addr_t host_info_dma_addr;
288         ena_mem_handle_t host_info_dma_handle;
289 };
290
291 /* Each ena_dev is a PCI function. */
292 struct ena_com_dev {
293         struct ena_com_admin_queue admin_queue;
294         struct ena_com_aenq aenq;
295         struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES];
296         struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES];
297         u8 __iomem *reg_bar;
298         void __iomem *mem_bar;
299         void *dmadev;
300         void *bus;
301
302         enum ena_admin_placement_policy_type tx_mem_queue_type;
303         u32 tx_max_header_size;
304         u16 stats_func; /* Selected function for extended statistic dump */
305         u16 stats_queue; /* Selected queue for extended statistic dump */
306
307         struct ena_com_mmio_read mmio_read;
308
309         struct ena_rss rss;
310         u32 supported_features;
311         u32 dma_addr_bits;
312
313         struct ena_host_attribute host_attr;
314         bool adaptive_coalescing;
315         u16 intr_delay_resolution;
316
317         /* interrupt moderation intervals are in usec divided by
318          * intr_delay_resolution, which is supplied by the device.
319          */
320         u32 intr_moder_tx_interval;
321         u32 intr_moder_rx_interval;
322
323         struct ena_intr_moder_entry *intr_moder_tbl;
324
325         struct ena_com_llq_info llq_info;
326
327         u32 ena_min_poll_delay_us;
328 };
329
330 struct ena_com_dev_get_features_ctx {
331         struct ena_admin_queue_feature_desc max_queues;
332         struct ena_admin_queue_ext_feature_desc max_queue_ext;
333         struct ena_admin_device_attr_feature_desc dev_attr;
334         struct ena_admin_feature_aenq_desc aenq;
335         struct ena_admin_feature_offload_desc offload;
336         struct ena_admin_ena_hw_hints hw_hints;
337         struct ena_admin_feature_llq_desc llq;
338         struct ena_admin_feature_rss_ind_table ind_table;
339 };
340
341 struct ena_com_create_io_ctx {
342         enum ena_admin_placement_policy_type mem_queue_type;
343         enum queue_direction direction;
344         int numa_node;
345         u32 msix_vector;
346         u16 queue_size;
347         u16 qid;
348 };
349
350 typedef void (*ena_aenq_handler)(void *data,
351         struct ena_admin_aenq_entry *aenq_e);
352
353 /* Holds aenq handlers. Indexed by AENQ event group */
354 struct ena_aenq_handlers {
355         ena_aenq_handler handlers[ENA_MAX_HANDLERS];
356         ena_aenq_handler unimplemented_handler;
357 };
358
359 /*****************************************************************************/
360 /*****************************************************************************/
361 #if defined(__cplusplus)
362 extern "C" {
363 #endif
364
365 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism
366  * @ena_dev: ENA communication layer struct
367  *
368  * Initialize the register read mechanism.
369  *
370  * @note: This method must be the first stage in the initialization sequence.
371  *
372  * @return - 0 on success, negative value on failure.
373  */
374 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev);
375
376 /* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism
377  * @ena_dev: ENA communication layer struct
378  * @readless_supported: readless mode (enable/disable)
379  */
380 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev,
381                                 bool readless_supported);
382
383 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return
384  * value physical address.
385  * @ena_dev: ENA communication layer struct
386  */
387 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev);
388
389 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism
390  * @ena_dev: ENA communication layer struct
391  */
392 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev);
393
394 /* ena_com_admin_init - Init the admin and the async queues
395  * @ena_dev: ENA communication layer struct
396  * @aenq_handlers: Those handlers to be called upon event.
397  *
398  * Initialize the admin submission and completion queues.
399  * Initialize the asynchronous events notification queues.
400  *
401  * @return - 0 on success, negative value on failure.
402  */
403 int ena_com_admin_init(struct ena_com_dev *ena_dev,
404                        struct ena_aenq_handlers *aenq_handlers);
405
406 /* ena_com_admin_destroy - Destroy the admin and the async events queues.
407  * @ena_dev: ENA communication layer struct
408  *
409  * @note: Before calling this method, the caller must validate that the device
410  * won't send any additional admin completions/aenq.
411  * To achieve that, a FLR is recommended.
412  */
413 void ena_com_admin_destroy(struct ena_com_dev *ena_dev);
414
415 /* ena_com_dev_reset - Perform device FLR to the device.
416  * @ena_dev: ENA communication layer struct
417  * @reset_reason: Specify what is the trigger for the reset in case of an error.
418  *
419  * @return - 0 on success, negative value on failure.
420  */
421 int ena_com_dev_reset(struct ena_com_dev *ena_dev,
422                       enum ena_regs_reset_reason_types reset_reason);
423
424 /* ena_com_create_io_queue - Create io queue.
425  * @ena_dev: ENA communication layer struct
426  * @ctx - create context structure
427  *
428  * Create the submission and the completion queues.
429  *
430  * @return - 0 on success, negative value on failure.
431  */
432 int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
433                             struct ena_com_create_io_ctx *ctx);
434
435 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid.
436  * @ena_dev: ENA communication layer struct
437  * @qid - the caller virtual queue id.
438  */
439 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid);
440
441 /* ena_com_get_io_handlers - Return the io queue handlers
442  * @ena_dev: ENA communication layer struct
443  * @qid - the caller virtual queue id.
444  * @io_sq - IO submission queue handler
445  * @io_cq - IO completion queue handler.
446  *
447  * @return - 0 on success, negative value on failure.
448  */
449 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid,
450                             struct ena_com_io_sq **io_sq,
451                             struct ena_com_io_cq **io_cq);
452
453 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications
454  * @ena_dev: ENA communication layer struct
455  *
456  * After this method, aenq event can be received via AENQ.
457  */
458 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev);
459
460 /* ena_com_set_admin_running_state - Set the state of the admin queue
461  * @ena_dev: ENA communication layer struct
462  *
463  * Change the state of the admin queue (enable/disable)
464  */
465 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state);
466
467 /* ena_com_get_admin_running_state - Get the admin queue state
468  * @ena_dev: ENA communication layer struct
469  *
470  * Retrieve the state of the admin queue (enable/disable)
471  *
472  * @return - current polling mode (enable/disable)
473  */
474 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev);
475
476 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode
477  * @ena_dev: ENA communication layer struct
478  * @polling: ENAble/Disable polling mode
479  *
480  * Set the admin completion mode.
481  */
482 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling);
483
484 /* ena_com_get_admin_polling_mode - Get the admin completion queue polling mode
485  * @ena_dev: ENA communication layer struct
486  *
487  * Get the admin completion mode.
488  * If polling mode is on, ena_com_execute_admin_command will perform a
489  * polling on the admin completion queue for the commands completion,
490  * otherwise it will wait on wait event.
491  *
492  * @return state
493  */
494 bool ena_com_get_admin_polling_mode(struct ena_com_dev *ena_dev);
495
496 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode
497  * @ena_dev: ENA communication layer struct
498  * @polling: Enable/Disable polling mode
499  *
500  * Set the autopolling mode.
501  * If autopolling is on:
502  * In case of missing interrupt when data is available switch to polling.
503  */
504 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev,
505                                          bool polling);
506
507 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler
508  * @ena_dev: ENA communication layer struct
509  *
510  * This method goes over the admin completion queue and wakes up all the pending
511  * threads that wait on the commands wait event.
512  *
513  * @note: Should be called after MSI-X interrupt.
514  */
515 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev);
516
517 /* ena_com_aenq_intr_handler - AENQ interrupt handler
518  * @ena_dev: ENA communication layer struct
519  *
520  * This method goes over the async event notification queue and calls the proper
521  * aenq handler.
522  */
523 void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data);
524
525 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands.
526  * @ena_dev: ENA communication layer struct
527  *
528  * This method aborts all the outstanding admin commands.
529  * The caller should then call ena_com_wait_for_abort_completion to make sure
530  * all the commands were completed.
531  */
532 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev);
533
534 /* ena_com_wait_for_abort_completion - Wait for admin commands abort.
535  * @ena_dev: ENA communication layer struct
536  *
537  * This method waits until all the outstanding admin commands are completed.
538  */
539 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev);
540
541 /* ena_com_validate_version - Validate the device parameters
542  * @ena_dev: ENA communication layer struct
543  *
544  * This method verifies the device parameters are the same as the saved
545  * parameters in ena_dev.
546  * This method is useful after device reset, to validate the device mac address
547  * and the device offloads are the same as before the reset.
548  *
549  * @return - 0 on success negative value otherwise.
550  */
551 int ena_com_validate_version(struct ena_com_dev *ena_dev);
552
553 /* ena_com_get_link_params - Retrieve physical link parameters.
554  * @ena_dev: ENA communication layer struct
555  * @resp: Link parameters
556  *
557  * Retrieve the physical link parameters,
558  * like speed, auto-negotiation and full duplex support.
559  *
560  * @return - 0 on Success negative value otherwise.
561  */
562 int ena_com_get_link_params(struct ena_com_dev *ena_dev,
563                             struct ena_admin_get_feat_resp *resp);
564
565 /* ena_com_get_dma_width - Retrieve physical dma address width the device
566  * supports.
567  * @ena_dev: ENA communication layer struct
568  *
569  * Retrieve the maximum physical address bits the device can handle.
570  *
571  * @return: > 0 on Success and negative value otherwise.
572  */
573 int ena_com_get_dma_width(struct ena_com_dev *ena_dev);
574
575 /* ena_com_set_aenq_config - Set aenq groups configurations
576  * @ena_dev: ENA communication layer struct
577  * @groups flag: bit fields flags of enum ena_admin_aenq_group.
578  *
579  * Configure which aenq event group the driver would like to receive.
580  *
581  * @return: 0 on Success and negative value otherwise.
582  */
583 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag);
584
585 /* ena_com_get_dev_attr_feat - Get device features
586  * @ena_dev: ENA communication layer struct
587  * @get_feat_ctx: returned context that contain the get features.
588  *
589  * @return: 0 on Success and negative value otherwise.
590  */
591 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev,
592                               struct ena_com_dev_get_features_ctx *get_feat_ctx);
593
594 /* ena_com_get_dev_basic_stats - Get device basic statistics
595  * @ena_dev: ENA communication layer struct
596  * @stats: stats return value
597  *
598  * @return: 0 on Success and negative value otherwise.
599  */
600 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev,
601                                 struct ena_admin_basic_stats *stats);
602
603 /* ena_com_get_eni_stats - Get extended network interface statistics
604  * @ena_dev: ENA communication layer struct
605  * @stats: stats return value
606  *
607  * @return: 0 on Success and negative value otherwise.
608  */
609 int ena_com_get_eni_stats(struct ena_com_dev *ena_dev,
610                           struct ena_admin_eni_stats *stats);
611
612 /* ena_com_set_dev_mtu - Configure the device mtu.
613  * @ena_dev: ENA communication layer struct
614  * @mtu: mtu value
615  *
616  * @return: 0 on Success and negative value otherwise.
617  */
618 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu);
619
620 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities
621  * @ena_dev: ENA communication layer struct
622  * @offlad: offload return value
623  *
624  * @return: 0 on Success and negative value otherwise.
625  */
626 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev,
627                                  struct ena_admin_feature_offload_desc *offload);
628
629 /* ena_com_rss_init - Init RSS
630  * @ena_dev: ENA communication layer struct
631  * @log_size: indirection log size
632  *
633  * Allocate RSS/RFS resources.
634  * The caller then can configure rss using ena_com_set_hash_function,
635  * ena_com_set_hash_ctrl and ena_com_indirect_table_set.
636  *
637  * @return: 0 on Success and negative value otherwise.
638  */
639 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
640
641 /* ena_com_rss_destroy - Destroy rss
642  * @ena_dev: ENA communication layer struct
643  *
644  * Free all the RSS/RFS resources.
645  */
646 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
647
648 /* ena_com_fill_hash_function - Fill RSS hash function
649  * @ena_dev: ENA communication layer struct
650  * @func: The hash function (Toeplitz or crc)
651  * @key: Hash key (for toeplitz hash)
652  * @key_len: key length (max length 10 DW)
653  * @init_val: initial value for the hash function
654  *
655  * Fill the ena_dev resources with the desire hash function, hash key, key_len
656  * and key initial value (if needed by the hash function).
657  * To flush the key into the device the caller should call
658  * ena_com_set_hash_function.
659  *
660  * @return: 0 on Success and negative value otherwise.
661  */
662 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
663                                enum ena_admin_hash_functions func,
664                                const u8 *key, u16 key_len, u32 init_val);
665
666 /* ena_com_set_hash_function - Flush the hash function and it dependencies to
667  * the device.
668  * @ena_dev: ENA communication layer struct
669  *
670  * Flush the hash function and it dependencies (key, key length and
671  * initial value) if needed.
672  *
673  * @note: Prior to this method the caller should call ena_com_fill_hash_function
674  *
675  * @return: 0 on Success and negative value otherwise.
676  */
677 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
678
679 /* ena_com_get_hash_function - Retrieve the hash function and the hash key
680  * from the device.
681  * @ena_dev: ENA communication layer struct
682  * @func: hash function
683  * @key: hash key
684  *
685  * Retrieve the hash function and the hash key from the device.
686  *
687  * @note: If the caller called ena_com_fill_hash_function but didn't flash
688  * it to the device, the new configuration will be lost.
689  *
690  * @return: 0 on Success and negative value otherwise.
691  */
692 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
693                               enum ena_admin_hash_functions *func,
694                               u8 *key);
695
696 /* ena_com_fill_hash_ctrl - Fill RSS hash control
697  * @ena_dev: ENA communication layer struct.
698  * @proto: The protocol to configure.
699  * @hash_fields: bit mask of ena_admin_flow_hash_fields
700  *
701  * Fill the ena_dev resources with the desire hash control (the ethernet
702  * fields that take part of the hash) for a specific protocol.
703  * To flush the hash control to the device, the caller should call
704  * ena_com_set_hash_ctrl.
705  *
706  * @return: 0 on Success and negative value otherwise.
707  */
708 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev,
709                            enum ena_admin_flow_hash_proto proto,
710                            u16 hash_fields);
711
712 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device.
713  * @ena_dev: ENA communication layer struct
714  *
715  * Flush the hash control (the ethernet fields that take part of the hash)
716  *
717  * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl.
718  *
719  * @return: 0 on Success and negative value otherwise.
720  */
721 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev);
722
723 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device.
724  * @ena_dev: ENA communication layer struct
725  * @proto: The protocol to retrieve.
726  * @fields: bit mask of ena_admin_flow_hash_fields.
727  *
728  * Retrieve the hash control from the device.
729  *
730  * @note: If the caller called ena_com_fill_hash_ctrl but didn't flash
731  * it to the device, the new configuration will be lost.
732  *
733  * @return: 0 on Success and negative value otherwise.
734  */
735 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev,
736                           enum ena_admin_flow_hash_proto proto,
737                           u16 *fields);
738
739 /* ena_com_set_default_hash_ctrl - Set the hash control to a default
740  * configuration.
741  * @ena_dev: ENA communication layer struct
742  *
743  * Fill the ena_dev resources with the default hash control configuration.
744  * To flush the hash control to the device, the caller should call
745  * ena_com_set_hash_ctrl.
746  *
747  * @return: 0 on Success and negative value otherwise.
748  */
749 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev);
750
751 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS
752  * indirection table
753  * @ena_dev: ENA communication layer struct.
754  * @entry_idx - indirection table entry.
755  * @entry_value - redirection value
756  *
757  * Fill a single entry of the RSS indirection table in the ena_dev resources.
758  * To flush the indirection table to the device, the called should call
759  * ena_com_indirect_table_set.
760  *
761  * @return: 0 on Success and negative value otherwise.
762  */
763 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev,
764                                       u16 entry_idx, u16 entry_value);
765
766 /* ena_com_indirect_table_set - Flush the indirection table to the device.
767  * @ena_dev: ENA communication layer struct
768  *
769  * Flush the indirection hash control to the device.
770  * Prior to this method the caller should call ena_com_indirect_table_fill_entry
771  *
772  * @return: 0 on Success and negative value otherwise.
773  */
774 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev);
775
776 /* ena_com_indirect_table_get - Retrieve the indirection table from the device.
777  * @ena_dev: ENA communication layer struct
778  * @ind_tbl: indirection table
779  *
780  * Retrieve the RSS indirection table from the device.
781  *
782  * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush
783  * it to the device, the new configuration will be lost.
784  *
785  * @return: 0 on Success and negative value otherwise.
786  */
787 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl);
788
789 /* ena_com_allocate_host_info - Allocate host info resources.
790  * @ena_dev: ENA communication layer struct
791  *
792  * @return: 0 on Success and negative value otherwise.
793  */
794 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev);
795
796 /* ena_com_allocate_debug_area - Allocate debug area.
797  * @ena_dev: ENA communication layer struct
798  * @debug_area_size - debug area size.
799  *
800  * @return: 0 on Success and negative value otherwise.
801  */
802 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev,
803                                 u32 debug_area_size);
804
805 /* ena_com_delete_debug_area - Free the debug area resources.
806  * @ena_dev: ENA communication layer struct
807  *
808  * Free the allocated debug area.
809  */
810 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev);
811
812 /* ena_com_delete_host_info - Free the host info resources.
813  * @ena_dev: ENA communication layer struct
814  *
815  * Free the allocated host info.
816  */
817 void ena_com_delete_host_info(struct ena_com_dev *ena_dev);
818
819 /* ena_com_set_host_attributes - Update the device with the host
820  * attributes (debug area and host info) base address.
821  * @ena_dev: ENA communication layer struct
822  *
823  * @return: 0 on Success and negative value otherwise.
824  */
825 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev);
826
827 /* ena_com_create_io_cq - Create io completion queue.
828  * @ena_dev: ENA communication layer struct
829  * @io_cq - io completion queue handler
830
831  * Create IO completion queue.
832  *
833  * @return - 0 on success, negative value on failure.
834  */
835 int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
836                          struct ena_com_io_cq *io_cq);
837
838 /* ena_com_destroy_io_cq - Destroy io completion queue.
839  * @ena_dev: ENA communication layer struct
840  * @io_cq - io completion queue handler
841
842  * Destroy IO completion queue.
843  *
844  * @return - 0 on success, negative value on failure.
845  */
846 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
847                           struct ena_com_io_cq *io_cq);
848
849 /* ena_com_execute_admin_command - Execute admin command
850  * @admin_queue: admin queue.
851  * @cmd: the admin command to execute.
852  * @cmd_size: the command size.
853  * @cmd_completion: command completion return value.
854  * @cmd_comp_size: command completion size.
855
856  * Submit an admin command and then wait until the device returns a
857  * completion.
858  * The completion will be copied into cmd_comp.
859  *
860  * @return - 0 on success, negative value on failure.
861  */
862 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue,
863                                   struct ena_admin_aq_entry *cmd,
864                                   size_t cmd_size,
865                                   struct ena_admin_acq_entry *cmd_comp,
866                                   size_t cmd_comp_size);
867
868 /* ena_com_init_interrupt_moderation - Init interrupt moderation
869  * @ena_dev: ENA communication layer struct
870  *
871  * @return - 0 on success, negative value on failure.
872  */
873 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev);
874
875 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation
876  * capability is supported by the device.
877  *
878  * @return - supported or not.
879  */
880 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev);
881
882 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the
883  * non-adaptive interval in Tx direction.
884  * @ena_dev: ENA communication layer struct
885  * @tx_coalesce_usecs: Interval in usec.
886  *
887  * @return - 0 on success, negative value on failure.
888  */
889 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev,
890                                                       u32 tx_coalesce_usecs);
891
892 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the
893  * non-adaptive interval in Rx direction.
894  * @ena_dev: ENA communication layer struct
895  * @rx_coalesce_usecs: Interval in usec.
896  *
897  * @return - 0 on success, negative value on failure.
898  */
899 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev,
900                                                       u32 rx_coalesce_usecs);
901
902 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the
903  * non-adaptive interval in Tx direction.
904  * @ena_dev: ENA communication layer struct
905  *
906  * @return - interval in usec
907  */
908 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev);
909
910 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the
911  * non-adaptive interval in Rx direction.
912  * @ena_dev: ENA communication layer struct
913  *
914  * @return - interval in usec
915  */
916 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev);
917
918 /* ena_com_config_dev_mode - Configure the placement policy of the device.
919  * @ena_dev: ENA communication layer struct
920  * @llq_features: LLQ feature descriptor, retrieve via
921  *                 ena_com_get_dev_attr_feat.
922  * @ena_llq_config: The default driver LLQ parameters configurations
923  */
924 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev,
925                             struct ena_admin_feature_llq_desc *llq_features,
926                             struct ena_llq_configurations *llq_default_config);
927
928 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev)
929 {
930         return ena_dev->adaptive_coalescing;
931 }
932
933 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev)
934 {
935         ena_dev->adaptive_coalescing = true;
936 }
937
938 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev)
939 {
940         ena_dev->adaptive_coalescing = false;
941 }
942
943 /* ena_com_update_intr_reg - Prepare interrupt register
944  * @intr_reg: interrupt register to update.
945  * @rx_delay_interval: Rx interval in usecs
946  * @tx_delay_interval: Tx interval in usecs
947  * @unmask: unmask enable/disable
948  *
949  * Prepare interrupt update register with the supplied parameters.
950  */
951 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg,
952                                            u32 rx_delay_interval,
953                                            u32 tx_delay_interval,
954                                            bool unmask)
955 {
956         intr_reg->intr_control = 0;
957         intr_reg->intr_control |= rx_delay_interval &
958                 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK;
959
960         intr_reg->intr_control |=
961                 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT)
962                 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK;
963
964         if (unmask)
965                 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK;
966 }
967
968 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl)
969 {
970         u16 size, buffers_num;
971         u8 *buf;
972
973         size = bounce_buf_ctrl->buffer_size;
974         buffers_num = bounce_buf_ctrl->buffers_num;
975
976         buf = bounce_buf_ctrl->base_buffer +
977                 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size;
978
979         prefetchw(bounce_buf_ctrl->base_buffer +
980                 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size);
981
982         return buf;
983 }
984
985 #if defined(__cplusplus)
986 }
987 #endif /* __cplusplus */
988 #endif /* !(ENA_COM) */