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