ena: Amazon Elastic Network Adapter (ENA) native driver
[vpp.git] / src / plugins / dev_ena / ena_admin_defs.h
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright(c) 2023 Cisco Systems, Inc.
3  */
4
5 #ifndef _ENA_ADMIN_DEFS_H_
6 #define _ENA_ADMIN_DEFS_H_
7
8 #include <vppinfra/clib.h>
9 #include <vppinfra/error_bootstrap.h>
10
11 #define foreach_ena_aq_opcode                                                 \
12   _ (1, CREATE_SQ)                                                            \
13   _ (2, DESTROY_SQ)                                                           \
14   _ (3, CREATE_CQ)                                                            \
15   _ (4, DESTROY_CQ)                                                           \
16   _ (8, GET_FEATURE)                                                          \
17   _ (9, SET_FEATURE)                                                          \
18   _ (11, GET_STATS)
19
20 typedef enum
21 {
22 #define _(v, n) ENA_AQ_OPCODE_##n = (v),
23   foreach_ena_aq_opcode
24 #undef _
25 } __clib_packed ena_aq_opcode_t;
26
27 #define foreach_ena_aq_compl_status                                           \
28   _ (0, SUCCESS)                                                              \
29   _ (1, RESOURCE_ALLOCATION_FAILURE)                                          \
30   _ (2, BAD_OPCODE)                                                           \
31   _ (3, UNSUPPORTED_OPCODE)                                                   \
32   _ (4, MALFORMED_REQUEST)                                                    \
33   _ (5, ILLEGAL_PARAMETER)                                                    \
34   _ (6, UNKNOWN_ERROR)                                                        \
35   _ (7, RESOURCE_BUSY)
36
37 typedef enum
38 {
39 #define _(v, n) ENA_ADMIN_COMPL_STATUS_##n = (v),
40   foreach_ena_aq_compl_status
41 #undef _
42 } __clib_packed ena_aq_compl_status_t;
43
44 /* id, versiom, get, set, name, struct */
45 #define foreach_ena_aq_feature_id                                             \
46   _ (1, 0, 1, 0, DEVICE_ATTRIBUTES, ena_aq_feat_device_attr_t)                \
47   _ (2, 0, 1, 0, MAX_QUEUES_NUM, ena_aq_feat_max_queue_num_t)                 \
48   _ (3, 0, 1, 0, HW_HINTS, ena_aq_feat_hw_hints_t)                            \
49   _ (4, 0, 1, 1, LLQ, ena_aq_feat_llq_t)                                      \
50   _ (5, 0, 1, 0, EXTRA_PROPERTIES_STRINGS,                                    \
51      ena_aq_feat_extra_properties_strings_t)                                  \
52   _ (6, 0, 1, 0, EXTRA_PROPERTIES_FLAGS,                                      \
53      ena_aq_feat_extra_properties_flags_t)                                    \
54   _ (7, 1, 1, 0, MAX_QUEUES_EXT, ena_aq_feat_max_queue_ext_t)                 \
55   _ (10, 0, 1, 1, RSS_HASH_FUNCTION, ena_aq_feat_rss_hash_function_t)         \
56   _ (11, 0, 1, 0, STATELESS_OFFLOAD_CONFIG,                                   \
57      ena_aq_feat_stateless_offload_config_t)                                  \
58   _ (12, 0, 1, 1, RSS_INDIRECTION_TABLE_CONFIG,                               \
59      ena_aq_feat_rss_ind_table_config_t)                                      \
60   _ (14, 0, 0, 1, MTU, ena_aq_feat_mtu_t)                                     \
61   _ (18, 0, 1, 1, RSS_HASH_INPUT, ena_aq_feat_rss_hash_input_t)               \
62   _ (20, 0, 1, 0, INTERRUPT_MODERATION, ena_aq_feat_intr_moder_t)             \
63   _ (26, 0, 1, 1, AENQ_CONFIG, ena_aq_feat_aenq_config_t)                     \
64   _ (27, 0, 1, 0, LINK_CONFIG, ena_aq_feat_link_config_t)                     \
65   _ (28, 0, 0, 1, HOST_ATTR_CONFIG, ena_aq_feat_host_attr_config_t)           \
66   _ (29, 0, 1, 1, PHC_CONFIG, ena_aq_feat_phc_config_t)
67
68 typedef enum
69 {
70 #define _(v, ver, r, w, n, s) ENA_ADMIN_FEAT_ID_##n = (v),
71   foreach_ena_aq_feature_id
72 #undef _
73 } __clib_packed ena_aq_feature_id_t;
74
75 #define foreach_ena_aq_stats_type                                             \
76   _ (0, BASIC)                                                                \
77   _ (1, EXTENDED)                                                             \
78   _ (2, ENI)
79
80 #define foreach_ena_aq_stats_scope                                            \
81   _ (0, SPECIFIC_QUEUE)                                                       \
82   _ (1, ETH_TRAFFIC)
83
84 typedef enum
85 {
86 #define _(v, n) ENA_ADMIN_STATS_TYPE_##n = (v),
87   foreach_ena_aq_stats_type
88 #undef _
89 } __clib_packed ena_aq_stats_type_t;
90
91 typedef enum
92 {
93 #define _(v, n) ENA_ADMIN_STATS_SCOPE_##n = (v),
94   foreach_ena_aq_stats_scope
95 #undef _
96 } __clib_packed ena_aq_stats_scope_t;
97
98 typedef struct
99 {
100   u32 addr_lo;
101   u16 addr_hi;
102   u16 _reserved_16;
103 } ena_mem_addr_t;
104
105 #define foreach_ena_aq_aenq_groups                                            \
106   _ (link_change)                                                             \
107   _ (fatal_error)                                                             \
108   _ (warning)                                                                 \
109   _ (notification)                                                            \
110   _ (keep_alive)                                                              \
111   _ (refresh_capabilities)                                                    \
112   _ (conf_notifications)
113
114 typedef union
115 {
116   struct
117   {
118 #define _(g) u32 g : 1;
119     foreach_ena_aq_aenq_groups
120 #undef _
121   };
122   u32 as_u32;
123 } ena_aq_aenq_groups_t;
124
125 STATIC_ASSERT_SIZEOF (ena_aq_aenq_groups_t, 4);
126
127 typedef struct
128 {
129   u32 length;
130   ena_mem_addr_t addr;
131 } ena_aq_aq_ctrl_buff_info_t;
132
133 typedef struct
134 {
135   u32 impl_id;
136   u32 device_version;
137   u32 supported_features;
138   u32 _reserved3;
139   u32 phys_addr_width;
140   u32 virt_addr_width;
141   u8 mac_addr[6];
142   u8 _reserved7[2];
143   u32 max_mtu;
144 } ena_aq_feat_device_attr_t;
145
146 typedef struct
147 {
148   union
149   {
150     struct
151     {
152       u16 l3_sort : 1;
153       u16 l4_sort : 1;
154     };
155     u16 supported_input_sort;
156   };
157   union
158   {
159     struct
160     {
161       u16 enable_l3_sort : 1;
162       u16 enable_l4_sort : 1;
163     };
164     u16 enabled_input_sort;
165   };
166 } ena_aq_feat_rss_hash_input_t;
167
168 STATIC_ASSERT_SIZEOF (ena_aq_feat_rss_hash_input_t, 4);
169
170 typedef struct
171 {
172   u16 intr_delay_resolution;
173   u16 reserved;
174 } ena_aq_feat_intr_moder_t;
175
176 typedef struct
177 {
178   ena_aq_aenq_groups_t supported_groups;
179   ena_aq_aenq_groups_t enabled_groups;
180 } ena_aq_feat_aenq_config_t;
181
182 #define foreach_ena_aq_link_types                                             \
183   _ (0, 1000, 1G)                                                             \
184   _ (1, 2500, 2_5G)                                                           \
185   _ (2, 5000, 5G)                                                             \
186   _ (3, 10000, 10G)                                                           \
187   _ (4, 25000, 25G)                                                           \
188   _ (5, 40000, 40G)                                                           \
189   _ (6, 50000, 50G)                                                           \
190   _ (7, 100000, 100G)                                                         \
191   _ (8, 200000, 200G)                                                         \
192   _ (9, 400000, 400G)
193
194 typedef enum
195 {
196 #define _(b, v, n) ENA_ADMIN_LINK_TYPE_##n = (1U << b),
197   foreach_ena_aq_link_types
198 #undef _
199 } ena_aq_link_types_t;
200
201 typedef struct
202 {
203   u32 speed;
204   ena_aq_link_types_t supported;
205   u32 autoneg : 1;
206   u32 duplex : 1;
207 } ena_aq_feat_link_config_t;
208
209 STATIC_ASSERT_SIZEOF (ena_aq_feat_link_config_t, 12);
210
211 typedef struct
212 {
213   u32 tx;
214   u32 rx_supported;
215   u32 rx_enabled;
216 } ena_aq_feat_stateless_offload_config_t;
217
218 typedef struct
219 {
220   u16 cq_idx;
221   u16 reserved;
222 } ena_aq_feat_rss_ind_table_entry_t;
223
224 typedef struct
225 {
226   u16 min_size;
227   u16 max_size;
228   u16 size;
229   u8 one_entry_update : 1;
230   u8 reserved;
231   u32 inline_index;
232   ena_aq_feat_rss_ind_table_entry_t inline_entry;
233 } ena_aq_feat_rss_ind_table_config_t;
234
235 typedef struct
236 {
237   u32 mtu;
238 } ena_aq_feat_mtu_t;
239
240 typedef struct
241 {
242   u32 count;
243 } ena_aq_feat_extra_properties_strings_t;
244
245 typedef struct
246 {
247   u32 flags;
248 } ena_aq_feat_extra_properties_flags_t;
249
250 typedef struct
251 {
252   u32 max_sq_num;
253   u32 max_sq_depth;
254   u32 max_cq_num;
255   u32 max_cq_depth;
256   u32 max_legacy_llq_num;
257   u32 max_legacy_llq_depth;
258   u32 max_header_size;
259   u16 max_packet_tx_descs;
260   u16 max_packet_rx_descs;
261 } ena_aq_feat_max_queue_num_t;
262
263 typedef struct
264 {
265   u16 mmio_read_timeout;
266   u16 driver_watchdog_timeout;
267   u16 missing_tx_completion_timeout;
268   u16 missed_tx_completion_count_threshold_to_reset;
269   u16 admin_completion_tx_timeout;
270   u16 netdev_wd_timeout;
271   u16 max_tx_sgl_size;
272   u16 max_rx_sgl_size;
273   u16 reserved[8];
274 } ena_aq_feat_hw_hints_t;
275
276 typedef struct
277 {
278   u8 version;
279   u8 _reserved1[3];
280   u32 max_tx_sq_num;
281   u32 max_tx_cq_num;
282   u32 max_rx_sq_num;
283   u32 max_rx_cq_num;
284   u32 max_tx_sq_depth;
285   u32 max_tx_cq_depth;
286   u32 max_rx_sq_depth;
287   u32 max_rx_cq_depth;
288   u32 max_tx_header_size;
289   u16 max_per_packet_tx_descs;
290   u16 max_per_packet_rx_descs;
291 } ena_aq_feat_max_queue_ext_t;
292
293 typedef struct
294 {
295   u32 supported_func;
296   u32 selected_func;
297   u32 init_val;
298 } ena_aq_feat_rss_hash_function_t;
299
300 typedef struct
301 {
302   ena_mem_addr_t os_info_ba;
303   ena_mem_addr_t debug_ba;
304   u32 debug_area_size;
305 } ena_aq_feat_host_attr_config_t;
306
307 typedef struct
308 {
309   u8 type;
310   u8 reserved1[3];
311   u32 doorbell_offset;
312   u32 expire_timeout_usec;
313   u32 block_timeout_usec;
314   ena_mem_addr_t output_address;
315   u32 output_length;
316 } ena_aq_feat_phc_config_t;
317
318 typedef struct
319 {
320   u32 max_llq_num;
321   u32 max_llq_depth;
322   u16 header_location_ctrl_supported;
323   u16 header_location_ctrl_enabled;
324   u16 entry_size_ctrl_supported;
325   u16 entry_size_ctrl_enabled;
326   u16 desc_num_before_header_supported;
327   u16 desc_num_before_header_enabled;
328   u16 descriptors_stride_ctrl_supported;
329   u16 descriptors_stride_ctrl_enabled;
330   union
331   {
332     struct
333     {
334       u16 supported_flags;
335       u16 max_tx_burst_size;
336     } get;
337     struct
338     {
339       u16 enabled_flags;
340     } set;
341   } accel_mode;
342 } ena_aq_feat_llq_t;
343
344 typedef struct
345 {
346   /* feat common */
347   u8 flags;
348   ena_aq_feature_id_t feature_id;
349   u8 feature_version;
350   u8 _reserved;
351 } ena_aq_get_set_feature_common_desc_t;
352
353 STATIC_ASSERT_SIZEOF (ena_aq_get_set_feature_common_desc_t, 4);
354
355 typedef struct
356 {
357   ena_aq_aq_ctrl_buff_info_t control_buffer;
358   ena_aq_stats_type_t type;
359   ena_aq_stats_scope_t scope;
360   u16 _reserved3;
361   u16 queue_idx;
362   u16 device_id;
363 } ena_aq_get_stats_cmd_t;
364 STATIC_ASSERT_SIZEOF (ena_aq_get_stats_cmd_t, 20);
365
366 typedef enum
367 {
368   ENA_ADMIN_SQ_DIRECTION_TX = 1,
369   ENA_ADMIN_SQ_DIRECTION_RX = 2,
370 } ena_aq_sq_direction_t;
371
372 typedef enum
373 {
374   ENA_ADMIN_SQ_PLACEMENT_POLICY_HOST = 1,
375   ENA_ADMIN_SQ_PLACEMENT_POLICY_DEVICE = 3,
376 } ena_aq_sq_placement_policy_t;
377
378 typedef enum
379 {
380   ENA_ADMIN_SQ_COMPLETION_POLICY_DESC = 0,
381   ENA_ADMIN_SQ_COMPLETION_POLICY_DESC_ON_DEMAND = 1,
382   ENA_ADMIN_SQ_COMPLETION_POLICY_HEAD_ON_DEMAND = 2,
383   ENA_ADMIN_SQ_COMPLETION_POLICY_HEAD = 3,
384 } ena_aq_completion_policy_t;
385
386 typedef struct
387 {
388   union
389   {
390     struct
391     {
392       u8 _reserved0_0 : 5;
393       u8 sq_direction : 3; /* ena_aq_sq_direction_t */
394     };
395     u8 sq_identity;
396   };
397
398   u8 _reserved1;
399
400   union
401   {
402     struct
403     {
404       u8 placement_policy : 4;  /* ena_aq_sq_placement_policy_t */
405       u8 completion_policy : 3; /* ena_aq_completion_policy_t */
406       u8 _reserved2_7 : 1;
407     };
408     u8 sq_caps_2;
409   };
410
411   union
412   {
413     struct
414     {
415       u8 is_physically_contiguous : 1;
416       u8 _reserved3_1 : 7;
417     };
418     u8 sq_caps_3;
419   };
420
421   u16 cq_idx;
422   u16 sq_depth;
423   ena_mem_addr_t sq_ba;
424   ena_mem_addr_t sq_head_writeback; /* used if completion_policy is 2 or 3 */
425   u32 _reserved0_w7;
426   u32 _reserved0_w8;
427 } ena_aq_create_sq_cmd_t;
428
429 typedef struct
430 {
431   u16 sq_idx;
432   u16 _reserved;
433   u32 sq_doorbell_offset;     /* REG BAR offset of queue dorbell */
434   u32 llq_descriptors_offset; /* LLQ MEM BAR offset of descriptors */
435   u32 llq_headers_offset;     /* LLQ MEM BAR offset of headers mem */
436 } ena_aq_create_sq_resp_t;
437
438 typedef struct
439 {
440   union
441   {
442     struct
443     {
444       u8 _reserved0_0 : 5;
445       u8 interrupt_mode_enabled : 1;
446       u8 _reserved0_6 : 2;
447     };
448     u8 cq_caps_1;
449   };
450
451   union
452   {
453     struct
454     {
455       u8 cq_entry_size_words : 4;
456       u8 _reserved1_4 : 4;
457     };
458     u8 cq_caps_2;
459   };
460
461   u16 cq_depth;
462   u32 msix_vector;
463   ena_mem_addr_t cq_ba;
464 } ena_aq_create_cq_cmd_t;
465
466 typedef struct
467 {
468   u16 cq_idx;
469   u16 cq_actual_depth;
470   u32 numa_node_register_offset;
471   u32 cq_head_db_register_offset;
472   u32 cq_interrupt_unmask_register_offset;
473 } ena_aq_create_cq_resp_t;
474
475 typedef struct
476 {
477   u16 sq_idx;
478   union
479   {
480     struct
481     {
482       u8 _reserved : 5;
483       u8 sq_direction : 3; /* ena_aq_sq_direction_t */
484     };
485     u8 sq_identity;
486   };
487   u8 _reserved1;
488 } ena_aq_destroy_sq_cmd_t;
489
490 typedef struct
491 {
492   u16 cq_idx;
493   u16 _reserved1;
494 } ena_aq_destroy_cq_cmd_t;
495
496 STATIC_ASSERT_SIZEOF (ena_aq_create_sq_cmd_t, 32);
497 STATIC_ASSERT_SIZEOF (ena_aq_create_sq_resp_t, 16);
498 STATIC_ASSERT_SIZEOF (ena_aq_create_cq_cmd_t, 16);
499 STATIC_ASSERT_SIZEOF (ena_aq_create_cq_resp_t, 16);
500 STATIC_ASSERT_SIZEOF (ena_aq_destroy_sq_cmd_t, 4);
501 STATIC_ASSERT_SIZEOF (ena_aq_destroy_cq_cmd_t, 4);
502
503 typedef struct
504 {
505   /* common desc */
506   u16 command_id;
507   ena_aq_opcode_t opcode;
508
509   union
510   {
511     struct
512     {
513       u8 phase : 1;
514       u8 ctrl_data : 1;
515       u8 ctrl_data_indirect : 1;
516       u8 _reserved_3_3 : 5;
517     };
518     u8 flags;
519   };
520
521   u32 data[15];
522 } ena_aq_sq_entry_t;
523
524 STATIC_ASSERT_SIZEOF (ena_aq_sq_entry_t, 64);
525
526 typedef struct
527 {
528   u32 os_type;
529   u8 os_dist_str[128];
530   u32 os_dist;
531   u8 kernel_ver_str[32];
532   u32 kernel_ver;
533
534   struct
535   {
536     u8 major;
537     u8 minor;
538     u8 sub_minor;
539     u8 module_type;
540   } driver_version;
541
542   u32 supported_network_features[2];
543
544   struct
545   {
546     u16 minor : 8;
547     u16 major : 8;
548   } ena_spec_version;
549
550   struct
551   {
552     u16 function : 3;
553     u16 device : 5;
554     u16 bus : 8;
555   } bdf;
556
557   u16 num_cpus;
558   u16 _reserved;
559
560   union
561   {
562     struct
563     {
564       u32 _reserved0 : 1;
565       u32 rx_offset : 1;
566       u32 interrupt_moderation : 1;
567       u32 rx_buf_mirroring : 1;
568       u32 rss_configurable_function_key : 1;
569       u32 _reserved5 : 1;
570       u32 rx_page_reuse : 1;
571       u32 tx_ipv6_csum_offload : 1;
572       u32 _reserved8 : 24;
573     };
574     u32 as_u32;
575   } driver_supported_features;
576
577 } ena_aq_host_info_t;
578
579 STATIC_ASSERT_SIZEOF (ena_aq_host_info_t, 196);
580
581 typedef struct
582 {
583   union
584   {
585     u64 tx_bytes;
586     struct
587     {
588       u32 tx_bytes_low;
589       u32 tx_bytes_high;
590     };
591   };
592   union
593   {
594     u64 tx_pkts;
595     struct
596     {
597       u32 tx_pkts_low;
598       u32 tx_pkts_high;
599     };
600   };
601   union
602   {
603     u64 rx_bytes;
604     struct
605     {
606       u32 rx_bytes_low;
607       u32 rx_bytes_high;
608     };
609   };
610   union
611   {
612     u64 rx_pkts;
613     struct
614     {
615       u32 rx_pkts_low;
616       u32 rx_pkts_high;
617     };
618   };
619   union
620   {
621     u64 rx_drops;
622     struct
623     {
624       u32 rx_drops_low;
625       u32 rx_drops_high;
626     };
627   };
628   union
629   {
630     u64 tx_drops;
631     struct
632     {
633       u32 tx_drops_low;
634       u32 tx_drops_high;
635     };
636   };
637 } ena_aq_basic_stats_t;
638
639 #define foreach_ena_aq_basic_counter                                          \
640   _ (rx_pkts, "RX Packets")                                                   \
641   _ (tx_pkts, "TX Packets")                                                   \
642   _ (rx_bytes, "RX Bytes")                                                    \
643   _ (tx_bytes, "TX Bytes")                                                    \
644   _ (rx_drops, "RX Packet Drops")                                             \
645   _ (tx_drops, "TX Packet Drops")
646
647 typedef struct
648 {
649   u64 bw_in_allowance_exceeded;
650   u64 bw_out_allowance_exceeded;
651   u64 pps_allowance_exceeded;
652   u64 conntrack_allowance_exceeded;
653   u64 linklocal_allowance_exceeded;
654 } ena_aq_eni_stats_t;
655
656 #define foreach_ena_aq_eni_counter                                            \
657   _ (bw_in_allowance_exceeded, "Input BW Allowance Exceeded")                 \
658   _ (bw_out_allowance_exceeded, "Output BW Allowance Exceeded")               \
659   _ (pps_allowance_exceeded, "PPS Allowance Exceeded")                        \
660   _ (conntrack_allowance_exceeded, "ConnTrack Allowance Exceeded")            \
661   _ (linklocal_allowance_exceeded, "LinkLocal Allowance Exceeded")
662
663 typedef struct
664 {
665   /* common desc */
666   u16 command;
667   ena_aq_compl_status_t status;
668   union
669   {
670     struct
671     {
672       u8 phase : 1;
673       u8 _reserved3_1 : 7;
674     };
675     u8 flags;
676   };
677   u16 extended_status;
678   u16 sq_head_indx;
679
680   u32 data[14];
681 } ena_aq_cq_entry_t;
682
683 STATIC_ASSERT_SIZEOF (ena_aq_cq_entry_t, 64);
684
685 #endif /* _ENA_ADMIN_DEFS_H_ */