common/cnxk: add bit fields for params
[dpdk.git] / drivers / common / cnxk / roc_ie_on.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef __ROC_IE_ON_H__
6 #define __ROC_IE_ON_H__
7
8 /* CN9K IPsec LA */
9
10 /* CN9K IPsec LA opcodes */
11 #define ROC_IE_ON_MAJOR_OP_WRITE_IPSEC_OUTBOUND   0x20
12 #define ROC_IE_ON_MAJOR_OP_WRITE_IPSEC_INBOUND    0x21
13 #define ROC_IE_ON_MAJOR_OP_PROCESS_OUTBOUND_IPSEC 0x23
14 #define ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC  0x24
15
16 /* Ucode completion codes */
17 enum roc_ie_on_ucc_ipsec {
18         ROC_IE_ON_UCC_SUCCESS = 0,
19         ROC_IE_ON_AUTH_UNSUPPORTED = 0xB0,
20         ROC_IE_ON_ENCRYPT_UNSUPPORTED = 0xB1,
21 };
22
23 /* Helper macros */
24 #define ROC_IE_ON_INB_RPTR_HDR 0x8
25
26 enum {
27         ROC_IE_ON_SA_ENC_NULL = 0,
28         ROC_IE_ON_SA_ENC_DES_CBC = 1,
29         ROC_IE_ON_SA_ENC_3DES_CBC = 2,
30         ROC_IE_ON_SA_ENC_AES_CBC = 3,
31         ROC_IE_ON_SA_ENC_AES_CTR = 4,
32         ROC_IE_ON_SA_ENC_AES_GCM = 5,
33         ROC_IE_ON_SA_ENC_AES_CCM = 6,
34 };
35
36 enum {
37         ROC_IE_ON_SA_AUTH_NULL = 0,
38         ROC_IE_ON_SA_AUTH_MD5 = 1,
39         ROC_IE_ON_SA_AUTH_SHA1 = 2,
40         ROC_IE_ON_SA_AUTH_SHA2_224 = 3,
41         ROC_IE_ON_SA_AUTH_SHA2_256 = 4,
42         ROC_IE_ON_SA_AUTH_SHA2_384 = 5,
43         ROC_IE_ON_SA_AUTH_SHA2_512 = 6,
44         ROC_IE_ON_SA_AUTH_AES_GMAC = 7,
45         ROC_IE_ON_SA_AUTH_AES_XCBC_128 = 8,
46 };
47
48 enum {
49         ROC_IE_ON_SA_FRAG_POST = 0,
50         ROC_IE_ON_SA_FRAG_PRE = 1,
51 };
52
53 enum {
54         ROC_IE_ON_SA_ENCAP_NONE = 0,
55         ROC_IE_ON_SA_ENCAP_UDP = 1,
56 };
57
58 struct roc_ie_on_outb_hdr {
59         uint32_t ip_id;
60         uint32_t seq;
61         uint8_t iv[16];
62 };
63
64 union roc_ie_on_bit_perfect_iv {
65         uint8_t aes_iv[16];
66         uint8_t des_iv[8];
67         struct {
68                 uint8_t nonce[4];
69                 uint8_t iv[8];
70                 uint8_t counter[4];
71         } gcm;
72 };
73
74 struct roc_ie_on_traffic_selector {
75         uint16_t src_port[2];
76         uint16_t dst_port[2];
77         union {
78                 struct {
79                         uint32_t src_addr[2];
80                         uint32_t dst_addr[2];
81                 } ipv4;
82                 struct {
83                         uint8_t src_addr[32];
84                         uint8_t dst_addr[32];
85                 } ipv6;
86         };
87 };
88
89 struct roc_ie_on_ip_template {
90         union {
91                 struct {
92                         uint8_t ipv4_hdr[20];
93                         uint16_t udp_src;
94                         uint16_t udp_dst;
95                 } ip4;
96                 struct {
97                         uint8_t ipv6_hdr[40];
98                         uint16_t udp_src;
99                         uint16_t udp_dst;
100                 } ip6;
101         };
102 };
103
104 union roc_on_ipsec_outb_param1 {
105         uint16_t u16;
106         struct {
107                 uint16_t frag_num : 4;
108                 uint16_t rsvd_4_6 : 3;
109                 uint16_t gre_select : 1;
110                 uint16_t dsiv : 1;
111                 uint16_t ikev2 : 1;
112                 uint16_t min_frag_size : 1;
113                 uint16_t per_pkt_iv : 1;
114                 uint16_t tfc_pad_enable : 1;
115                 uint16_t tfc_dummy_pkt : 1;
116                 uint16_t rfc_or_override_mode : 1;
117                 uint16_t custom_hdr_or_p99 : 1;
118         } s;
119 };
120
121 union roc_on_ipsec_inb_param2 {
122         uint16_t u16;
123         struct {
124                 uint16_t rsvd_0_10 : 11;
125                 uint16_t gre_select : 1;
126                 uint16_t ikev2 : 1;
127                 uint16_t udp_cksum : 1;
128                 uint16_t ctx_addr_sel : 1;
129                 uint16_t custom_hdr_or_p99 : 1;
130         } s;
131 };
132
133 struct roc_ie_on_sa_ctl {
134         uint64_t spi : 32;
135         uint64_t exp_proto_inter_frag : 8;
136         uint64_t copy_df : 1;
137         uint64_t frag_type : 1;
138         uint64_t explicit_iv_en : 1;
139         uint64_t esn_en : 1;
140         uint64_t rsvd_45_44 : 2;
141         uint64_t encap_type : 2;
142         uint64_t enc_type : 3;
143         uint64_t rsvd_48 : 1;
144         uint64_t auth_type : 4;
145         uint64_t valid : 1;
146         uint64_t direction : 1;
147         uint64_t outer_ip_ver : 1;
148         uint64_t inner_ip_ver : 1;
149         uint64_t ipsec_mode : 1;
150         uint64_t ipsec_proto : 1;
151         uint64_t aes_key_len : 2;
152 };
153
154 struct roc_ie_on_common_sa {
155         /* w0 */
156         struct roc_ie_on_sa_ctl ctl;
157
158         /* w1-w4 */
159         uint8_t cipher_key[32];
160
161         /* w5-w6 */
162         union roc_ie_on_bit_perfect_iv iv;
163
164         /* w7 */
165         uint32_t esn_hi;
166         uint32_t esn_low;
167 };
168
169 struct roc_ie_on_outb_sa {
170         /* w0 - w7 */
171         struct roc_ie_on_common_sa common_sa;
172
173         /* w8-w55 */
174         union {
175                 struct {
176                         struct roc_ie_on_ip_template template;
177                 } aes_gcm;
178                 struct {
179                         uint8_t hmac_key[24];
180                         uint8_t unused[24];
181                         struct roc_ie_on_ip_template template;
182                 } sha1;
183                 struct {
184                         uint8_t hmac_key[64];
185                         uint8_t hmac_iv[64];
186                         struct roc_ie_on_ip_template template;
187                 } sha2;
188         };
189 };
190
191 struct roc_ie_on_inb_sa {
192         /* w0 - w7 */
193         struct roc_ie_on_common_sa common_sa;
194
195         /* w8 */
196         uint8_t udp_encap[8];
197
198         /* w9-w33 */
199         union {
200                 struct {
201                         uint8_t hmac_key[48];
202                         struct roc_ie_on_traffic_selector selector;
203                 } sha1_or_gcm;
204                 struct {
205                         uint8_t hmac_key[64];
206                         uint8_t hmac_iv[64];
207                         struct roc_ie_on_traffic_selector selector;
208                 } sha2;
209         };
210 };
211
212 /* CN9K IPsec FP */
213
214 /* CN9K IPsec FP opcodes */
215 #define ROC_IE_ONF_MAJOR_OP_PROCESS_OUTBOUND_IPSEC 0x25UL
216 #define ROC_IE_ONF_MAJOR_OP_PROCESS_INBOUND_IPSEC  0x26UL
217
218 /* Ucode completion codes */
219 #define ROC_IE_ONF_UCC_SUCCESS 0
220
221 struct roc_ie_onf_sa_ctl {
222         uint32_t spi;
223         uint64_t exp_proto_inter_frag : 8;
224         uint64_t rsvd_41_40 : 2;
225         /* Disable SPI, SEQ data in RPTR for Inbound inline */
226         uint64_t spi_seq_dis : 1;
227         uint64_t esn_en : 1;
228         uint64_t rsvd_44_45 : 2;
229         uint64_t encap_type : 2;
230         uint64_t enc_type : 3;
231         uint64_t rsvd_48 : 1;
232         uint64_t auth_type : 4;
233         uint64_t valid : 1;
234         uint64_t direction : 1;
235         uint64_t outer_ip_ver : 1;
236         uint64_t inner_ip_ver : 1;
237         uint64_t ipsec_mode : 1;
238         uint64_t ipsec_proto : 1;
239         uint64_t aes_key_len : 2;
240 };
241
242 struct roc_onf_ipsec_outb_sa {
243         /* w0 */
244         struct roc_ie_onf_sa_ctl ctl;
245
246         /* w1 */
247         uint8_t nonce[4];
248         uint16_t udp_src;
249         uint16_t udp_dst;
250
251         /* w2 */
252         uint32_t ip_src;
253         uint32_t ip_dst;
254
255         /* w3-w6 */
256         uint8_t cipher_key[32];
257
258         /* w7-w12 */
259         uint8_t hmac_key[48];
260 };
261
262 struct roc_onf_ipsec_inb_sa {
263         /* w0 */
264         struct roc_ie_onf_sa_ctl ctl;
265
266         /* w1 */
267         uint8_t nonce[4]; /* Only for AES-GCM */
268         uint32_t unused;
269
270         /* w2 */
271         uint32_t esn_hi;
272         uint32_t esn_low;
273
274         /* w3-w6 */
275         uint8_t cipher_key[32];
276
277         /* w7-w12 */
278         uint8_t hmac_key[48];
279 };
280
281 #define ROC_ONF_IPSEC_INB_MAX_L2_SZ       32UL
282 #define ROC_ONF_IPSEC_OUTB_MAX_L2_SZ      30UL
283 #define ROC_ONF_IPSEC_OUTB_MAX_L2_INFO_SZ (ROC_ONF_IPSEC_OUTB_MAX_L2_SZ + 2)
284
285 #define ROC_ONF_IPSEC_INB_RES_OFF    80
286 #define ROC_ONF_IPSEC_INB_SPI_SEQ_SZ 16
287
288 struct roc_onf_ipsec_outb_hdr {
289         uint32_t ip_id;
290         uint32_t seq;
291         uint8_t iv[16];
292 };
293
294 #endif /* __ROC_IE_ON_H__ */