ena: Amazon Elastic Network Adapter (ENA) native driver
[vpp.git] / src / plugins / dev_ena / ena_io_defs.h
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright(c) 2023 Cisco Systems, Inc.
3  */
4
5 #ifndef _ENA_IO_DEFS_H_
6 #define _ENA_IO_DEFS_H_
7
8 #include <vppinfra/clib.h>
9 #include <vppinfra/error_bootstrap.h>
10 #include <vppinfra/vector.h>
11
12 typedef struct
13 {
14   u16 length; /* 0 = 64K */
15   u8 reserved2;
16   union
17   {
18     struct
19     {
20       u8 phase : 1;
21       u8 reserved1 : 1;
22       u8 first : 1;    /* first descriptor in transaction */
23       u8 last : 1;     /* last descriptor in transaction */
24       u8 comp_req : 1; /* should completion be posted? */
25       u8 reserved5 : 1;
26       u8 reserved67 : 2;
27     };
28     u8 ctrl;
29   };
30   u16 req_id;
31   u16 reserved6;
32 } ena_rx_desc_lo_t;
33
34 STATIC_ASSERT_SIZEOF (ena_rx_desc_lo_t, 8);
35
36 typedef struct
37 {
38   union
39   {
40     struct
41     {
42       ena_rx_desc_lo_t lo;
43       u32 buff_addr_lo;
44       u16 buff_addr_hi;
45       u16 reserved16_w3;
46     };
47     u64x2 as_u64x2;
48   };
49 } ena_rx_desc_t;
50
51 STATIC_ASSERT_SIZEOF (ena_rx_desc_t, 16);
52
53 #define foreach_ena_rx_cdesc_status                                           \
54   _ (5, l3_proto_idx)                                                         \
55   _ (2, src_vlan_cnt)                                                         \
56   _ (1, _reserved7)                                                           \
57   _ (5, l4_proto_idx)                                                         \
58   _ (1, l3_csum_err)                                                          \
59   _ (1, l4_csum_err)                                                          \
60   _ (1, ipv4_frag)                                                            \
61   _ (1, l4_csum_checked)                                                      \
62   _ (7, _reserved17)                                                          \
63   _ (1, phase)                                                                \
64   _ (1, l3_csum2)                                                             \
65   _ (1, first)                                                                \
66   _ (1, last)                                                                 \
67   _ (2, _reserved28)                                                          \
68   _ (1, buffer)                                                               \
69   _ (1, _reserved31)
70
71 typedef struct
72 {
73   union
74   {
75     struct
76     {
77 #define _(b, n) u32 n : (b);
78       foreach_ena_rx_cdesc_status
79 #undef _
80     };
81     u32 as_u32;
82   };
83 } ena_rx_cdesc_status_t;
84
85 typedef struct
86 {
87   ena_rx_cdesc_status_t status;
88   u16 length;
89   u16 req_id;
90   u32 hash;
91   u16 sub_qid;
92   u8 offset;
93   u8 reserved;
94 } ena_rx_cdesc_t;
95
96 STATIC_ASSERT_SIZEOF (ena_rx_cdesc_t, 16);
97
98 #define foreach_ena_tx_desc                                                   \
99   /* len_ctrl */                                                              \
100   _ (16, length)                                                              \
101   _ (6, req_id_hi)                                                            \
102   _ (1, _reserved0_22)                                                        \
103   _ (1, meta_desc)                                                            \
104   _ (1, phase)                                                                \
105   _ (1, _reserved0_25)                                                        \
106   _ (1, first)                                                                \
107   _ (1, last)                                                                 \
108   _ (1, comp_req)                                                             \
109   _ (2, _reserved0_29)                                                        \
110   _ (1, _reserved0_31)                                                        \
111   /* meta_ctrl */                                                             \
112   _ (4, l3_proto_idx)                                                         \
113   _ (1, df)                                                                   \
114   _ (2, _reserved1_5)                                                         \
115   _ (1, tso_en)                                                               \
116   _ (5, l4_proto_idx)                                                         \
117   _ (1, l3_csum_en)                                                           \
118   _ (1, l4_csum_en)                                                           \
119   _ (1, ethernet_fcs_dis)                                                     \
120   _ (1, _reserved1_16)                                                        \
121   _ (1, l4_csum_partial)                                                      \
122   _ (3, _reserved_1_18)                                                       \
123   _ (1, _reserved_1_21)                                                       \
124   _ (10, req_id_lo)
125
126 typedef struct
127 {
128   union
129   {
130     struct
131     {
132 #define _(b, n) u32 n : (b);
133       foreach_ena_tx_desc
134 #undef _
135         u32 buff_addr_lo;
136       u16 buff_addr_hi;
137       u8 _reserved3_16;
138       u8 header_length;
139     };
140
141     u16x8 as_u16x8;
142     u32x4 as_u32x4;
143     u64x2 as_u64x2;
144   };
145 } ena_tx_desc_t;
146
147 STATIC_ASSERT_SIZEOF (ena_tx_desc_t, 16);
148
149 typedef struct
150 {
151   ena_tx_desc_t desc[2];
152   u8 data[96];
153 } __clib_aligned (128)
154 ena_tx_llq_desc128_t;
155 STATIC_ASSERT_SIZEOF (ena_tx_llq_desc128_t, 128);
156
157 typedef union
158 {
159   struct
160   {
161     u16 req_id;
162     u8 status;
163     union
164     {
165       struct
166       {
167         u8 phase : 1;
168       };
169       u8 flags;
170     };
171     u16 sub_qid;
172     u16 sq_head_idx;
173   };
174   u64 as_u64;
175 } ena_tx_cdesc_t;
176
177 STATIC_ASSERT_SIZEOF (ena_tx_cdesc_t, 8);
178
179 #endif /* _ENA_IO_DEFS_H_ */