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