common/cnxk: make IPsec defines common
[dpdk.git] / drivers / common / cnxk / roc_ie_ot.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef __ROC_IE_OT_H__
6 #define __ROC_IE_OT_H__
7
8 /* PKIND to be used for CPT Meta parsing */
9 #define ROC_OT_CPT_META_PKIND 58
10
11 /* CN10K IPSEC opcodes */
12 #define ROC_IE_OT_MAJOR_OP_PROCESS_OUTBOUND_IPSEC 0x28UL
13 #define ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC  0x29UL
14
15 enum roc_ie_ot_ucc_ipsec {
16         ROC_IE_OT_UCC_SUCCESS = 0x00,
17         ROC_IE_OT_UCC_SUCCESS_PKT_IP_GOODCSUM = 0x02,
18         ROC_IE_OT_UCC_ERR_SA_INVAL = 0x03,
19         ROC_IE_OT_UCC_SUCCESS_PKT_IP_BADCSUM = 0x04,
20         ROC_IE_OT_UCC_ERR_SA_EXPIRED = 0x05,
21         ROC_IE_OT_UCC_SUCCESS_PKT_L4_GOODCSUM = 0x06,
22         ROC_IE_OT_UCC_ERR_SA_OVERFLOW = 0x07,
23         ROC_IE_OT_UCC_SUCCESS_PKT_L4_BADCSUM = 0x08,
24         ROC_IE_OT_UCC_ERR_SA_ESP_BAD_ALGO = 0x09,
25         ROC_IE_OT_UCC_SUCCESS_PKT_UDPESP_NZCSUM = 0x0a,
26         ROC_IE_OT_UCC_ERR_SA_ESP_BAD_KEYS = 0x0b,
27         ROC_IE_OT_UCC_SUCCESS_SA_SOFTEXP_FIRST = 0x0c,
28         ROC_IE_OT_UCC_ERR_SA_AH_BAD_ALGO = 0x0d,
29         ROC_IE_OT_UCC_SUCCESS_SA_SOFTEXP_AGAIN = 0x0e,
30         ROC_IE_OT_UCC_ERR_SA_AH_BAD_KEYS = 0x0f,
31         ROC_IE_OT_UCC_ERR_SA_BAD_IP = 0x11,
32         ROC_IE_OT_UCC_ERR_SA_BAD_CTX = 0x13,
33         ROC_IE_OT_UCC_ERR_AOP_IPSEC = 0x17,
34         ROC_IE_OT_UCC_ERR_PKT_IP = 0x23,
35         ROC_IE_OT_UCC_ERR_PKT_IP6_BAD_EXT = 0x25,
36         ROC_IE_OT_UCC_ERR_PKT_IP6_HBH = 0x27,
37         ROC_IE_OT_UCC_ERR_PKT_IP6_BIGEXT = 0x29,
38         ROC_IE_OT_UCC_ERR_PKT_IP_FRAG = 0x2b,
39         ROC_IE_OT_UCC_ERR_PKT_IP_ULP = 0x2d,
40         ROC_IE_OT_UCC_ERR_PKT_SA_MISMATCH = 0x2f,
41         ROC_IE_OT_UCC_ERR_PKT_SPI_MISMATCH = 0x31,
42         ROC_IE_OT_UCC_ERR_PKT_ESP_BADPAD = 0x33,
43         ROC_IE_OT_UCC_ERR_PKT_BADICV = 0x35,
44         ROC_IE_OT_UCC_ERR_PKT_REPLAY_SEQ = 0x37,
45         ROC_IE_OT_UCC_ERR_PKT_REPLAY_WINDOW = 0x39,
46         ROC_IE_OT_UCC_ERR_PKT_BADNH = 0x3b,
47         ROC_IE_OT_UCC_ERR_PKT_SA_PORT_MISMATCH = 0x3d,
48 };
49
50 enum {
51         ROC_IE_OT_SA_AR_WIN_DISABLED = 0,
52         ROC_IE_OT_SA_AR_WIN_64 = 1,
53         ROC_IE_OT_SA_AR_WIN_128 = 2,
54         ROC_IE_OT_SA_AR_WIN_256 = 3,
55         ROC_IE_OT_SA_AR_WIN_512 = 4,
56         ROC_IE_OT_SA_AR_WIN_1024 = 5,
57         ROC_IE_OT_SA_AR_WIN_2048 = 6,
58         ROC_IE_OT_SA_AR_WIN_4096 = 7,
59 };
60
61 enum {
62         ROC_IE_OT_SA_PKT_FMT_FULL = 0,
63         ROC_IE_OT_SA_PKT_FMT_META = 1,
64 };
65
66 enum {
67         ROC_IE_OT_SA_PKT_OUTPUT_DECRYPTED = 0,
68         ROC_IE_OT_SA_PKT_OUTPUT_NO_FRAG = 1,
69         ROC_IE_OT_SA_PKT_OUTPUT_HW_BASED_DEFRAG = 2,
70         ROC_IE_OT_SA_PKT_OUTPUT_UCODE_BASED_DEFRAG = 3,
71 };
72
73 enum {
74         ROC_IE_OT_SA_DEFRAG_ALL = 0,
75         ROC_IE_OT_SA_DEFRAG_IN_ORDER = 1,
76         ROC_IE_OT_SA_DEFRAG_IN_REV_ORDER = 2,
77 };
78
79 enum {
80         ROC_IE_OT_SA_IV_SRC_DEFAULT = 0,
81         ROC_IE_OT_SA_IV_SRC_ENC_CTR = 1,
82         ROC_IE_OT_SA_IV_SRC_FROM_SA = 2,
83 };
84
85 enum {
86         ROC_IE_OT_SA_COPY_FROM_SA = 0,
87         ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR = 1,
88 };
89
90 enum {
91         ROC_IE_OT_SA_INNER_PKT_IP_CSUM_ENABLE = 0,
92         ROC_IE_OT_SA_INNER_PKT_IP_CSUM_DISABLE = 1,
93 };
94
95 enum {
96         ROC_IE_OT_SA_INNER_PKT_L4_CSUM_ENABLE = 0,
97         ROC_IE_OT_SA_INNER_PKT_L4_CSUM_DISABLE = 1,
98 };
99
100 enum {
101         ROC_IE_OT_SA_ENC_NULL = 0,
102         ROC_IE_OT_SA_ENC_3DES_CBC = 2,
103         ROC_IE_OT_SA_ENC_AES_CBC = 3,
104         ROC_IE_OT_SA_ENC_AES_CTR = 4,
105         ROC_IE_OT_SA_ENC_AES_GCM = 5,
106         ROC_IE_OT_SA_ENC_AES_CCM = 6,
107 };
108
109 enum {
110         ROC_IE_OT_SA_AUTH_NULL = 0,
111         ROC_IE_OT_SA_AUTH_SHA1 = 2,
112         ROC_IE_OT_SA_AUTH_SHA2_256 = 4,
113         ROC_IE_OT_SA_AUTH_SHA2_384 = 5,
114         ROC_IE_OT_SA_AUTH_SHA2_512 = 6,
115         ROC_IE_OT_SA_AUTH_AES_GMAC = 7,
116         ROC_IE_OT_SA_AUTH_AES_XCBC_128 = 8,
117 };
118
119 enum {
120         ROC_IE_OT_SA_ENCAP_NONE = 0,
121         ROC_IE_OT_SA_ENCAP_UDP = 1,
122         ROC_IE_OT_SA_ENCAP_TCP = 2,
123 };
124
125 enum {
126         ROC_IE_OT_SA_LIFE_UNIT_OCTETS = 0,
127         ROC_IE_OT_SA_LIFE_UNIT_PKTS = 1,
128 };
129
130 enum {
131         ROC_IE_OT_SA_IP_HDR_VERIFY_DISABLED = 0,
132         ROC_IE_OT_SA_IP_HDR_VERIFY_DST_ADDR = 1,
133         ROC_IE_OT_SA_IP_HDR_VERIFY_SRC_DST_ADDR = 2,
134 };
135
136 enum {
137         ROC_IE_OT_REAS_STS_SUCCESS = 0,
138         ROC_IE_OT_REAS_STS_TIMEOUT = 1,
139         ROC_IE_OT_REAS_STS_EVICT = 2,
140         ROC_IE_OT_REAS_STS_BAD_ORDER = 3,
141         ROC_IE_OT_REAS_STS_TOO_MANY = 4,
142         ROC_IE_OT_REAS_STS_HSH_EVICT = 5,
143         ROC_IE_OT_REAS_STS_OVERLAP = 6,
144         ROC_IE_OT_REAS_STS_ZOMBIE = 7,
145         ROC_IE_OT_REAS_STS_L3P_ERR = 8,
146         ROC_IE_OT_REAS_STS_MAX = 9
147 };
148 /* Context units in bytes */
149 #define ROC_CTX_UNIT_8B           8
150 #define ROC_CTX_UNIT_128B         128
151 #define ROC_CTX_MAX_CKEY_LEN      32
152 #define ROC_CTX_MAX_OPAD_IPAD_LEN 128
153
154 /* Anti reply window size supported */
155 #define ROC_AR_WIN_SIZE_MIN        64
156 #define ROC_AR_WIN_SIZE_MAX        4096
157 #define ROC_LOG_MIN_AR_WIN_SIZE_M1 5
158
159 /* u64 array size to fit anti replay window bits */
160 #define ROC_AR_WINBITS_SZ                                                      \
161         (PLT_ALIGN_CEIL(ROC_AR_WIN_SIZE_MAX, BITS_PER_LONG_LONG) /             \
162          BITS_PER_LONG_LONG)
163
164 /* Common bit fields between inbound and outbound SA */
165 union roc_ot_ipsec_sa_word2 {
166         struct {
167                 uint64_t valid : 1;
168                 uint64_t dir : 1;
169                 uint64_t outer_ip_ver : 1;
170                 uint64_t rsvd0 : 1;
171                 uint64_t mode : 1;
172                 uint64_t protocol : 1;
173                 uint64_t aes_key_len : 2;
174
175                 uint64_t enc_type : 3;
176                 uint64_t life_unit : 1;
177                 uint64_t auth_type : 4;
178
179                 uint64_t encap_type : 2;
180                 uint64_t rsvd1 : 6;
181
182                 uint64_t rsvd2 : 7;
183                 uint64_t async_mode : 1;
184
185                 uint64_t spi : 32;
186         } s;
187         uint64_t u64;
188 };
189
190 PLT_STATIC_ASSERT(sizeof(union roc_ot_ipsec_sa_word2) == 1 * sizeof(uint64_t));
191
192 union roc_ot_ipsec_outer_ip_hdr {
193         struct {
194                 uint32_t dst_addr;
195                 uint32_t src_addr;
196         } ipv4;
197         struct {
198                 uint8_t src_addr[16];
199                 uint8_t dst_addr[16];
200         } ipv6;
201 };
202
203 struct roc_ot_ipsec_inb_ctx_update_reg {
204         uint64_t ar_base;
205         uint64_t ar_valid_mask;
206         uint64_t hard_life;
207         uint64_t soft_life;
208         uint64_t mib_octs;
209         uint64_t mib_pkts;
210         uint64_t ar_winbits[ROC_AR_WINBITS_SZ];
211 };
212
213 union roc_ot_ipsec_outb_iv {
214         uint64_t u64[2];
215         uint8_t iv_dbg[16];
216         struct {
217                 uint8_t iv_dbg1[4];
218                 uint8_t salt[4];
219
220                 uint32_t rsvd;
221                 uint8_t iv_dbg2[4];
222         } s;
223 };
224
225 struct roc_ot_ipsec_outb_ctx_update_reg {
226         uint64_t rsvd;
227         uint64_t esn_val;
228         uint64_t hard_life;
229         uint64_t soft_life;
230         uint64_t mib_octs;
231         uint64_t mib_pkts;
232 };
233
234 union roc_ot_ipsec_outb_param1 {
235         uint16_t u16;
236         struct {
237                 uint16_t l4_csum_disable : 1;
238                 uint16_t ip_csum_disable : 1;
239                 uint16_t ttl_or_hop_limit : 1;
240                 uint16_t dummy_pkt : 1;
241                 uint16_t rfc_or_override_mode : 1;
242                 uint16_t reserved_5_15 : 11;
243         } s;
244 };
245
246 union roc_ot_ipsec_inb_param1 {
247         uint16_t u16;
248         struct {
249                 uint16_t l4_csum_disable : 1;
250                 uint16_t ip_csum_disable : 1;
251                 uint16_t esp_trailer_disable : 1;
252                 uint16_t reserved_3_15 : 13;
253         } s;
254 };
255
256 struct roc_ot_ipsec_inb_sa {
257         /* Word0 */
258         union {
259                 struct {
260                         uint64_t ar_win : 3;
261                         uint64_t hard_life_dec : 1;
262                         uint64_t soft_life_dec : 1;
263                         uint64_t count_glb_octets : 1;
264                         uint64_t count_glb_pkts : 1;
265                         uint64_t count_mib_bytes : 1;
266
267                         uint64_t count_mib_pkts : 1;
268                         uint64_t hw_ctx_off : 7;
269
270                         uint64_t ctx_id : 16;
271
272                         uint64_t orig_pkt_fabs : 1;
273                         uint64_t orig_pkt_free : 1;
274                         uint64_t pkind : 6;
275
276                         uint64_t rsvd0 : 1;
277                         uint64_t et_ovrwr : 1;
278                         uint64_t pkt_output : 2;
279                         uint64_t pkt_format : 1;
280                         uint64_t defrag_opt : 2;
281                         uint64_t x2p_dst : 1;
282
283                         uint64_t ctx_push_size : 7;
284                         uint64_t rsvd1 : 1;
285
286                         uint64_t ctx_hdr_size : 2;
287                         uint64_t aop_valid : 1;
288                         uint64_t rsvd2 : 1;
289                         uint64_t ctx_size : 4;
290                 } s;
291                 uint64_t u64;
292         } w0;
293
294         /* Word1 */
295         union {
296                 struct {
297                         uint64_t orig_pkt_aura : 20;
298                         uint64_t rsvd3 : 4;
299                         uint64_t orig_pkt_foff : 8;
300                         uint64_t cookie : 32;
301                 } s;
302                 uint64_t u64;
303         } w1;
304
305         /* Word 2 */
306         union {
307                 struct {
308                         uint64_t valid : 1;
309                         uint64_t dir : 1;
310                         uint64_t outer_ip_ver : 1;
311                         uint64_t rsvd4 : 1;
312                         uint64_t ipsec_mode : 1;
313                         uint64_t ipsec_protocol : 1;
314                         uint64_t aes_key_len : 2;
315
316                         uint64_t enc_type : 3;
317                         uint64_t life_unit : 1;
318                         uint64_t auth_type : 4;
319
320                         uint64_t encap_type : 2;
321                         uint64_t et_ovrwr_ddr_en : 1;
322                         uint64_t esn_en : 1;
323                         uint64_t tport_l4_incr_csum : 1;
324                         uint64_t ip_hdr_verify : 2;
325                         uint64_t rsvd5 : 1;
326
327                         uint64_t rsvd6 : 7;
328                         uint64_t async_mode : 1;
329
330                         uint64_t spi : 32;
331                 } s;
332                 uint64_t u64;
333         } w2;
334
335         /* Word3 */
336         uint64_t rsvd7;
337
338         /* Word4 - Word7 */
339         uint8_t cipher_key[ROC_CTX_MAX_CKEY_LEN];
340
341         /* Word8 - Word9 */
342         union {
343                 struct {
344                         uint32_t rsvd8;
345                         uint8_t salt[4];
346                 } s;
347                 uint64_t u64;
348         } w8;
349         uint64_t rsvd9;
350
351         /* Word10 */
352         union {
353                 struct {
354                         uint64_t rsvd10 : 32;
355                         uint64_t udp_src_port : 16;
356                         uint64_t udp_dst_port : 16;
357                 } s;
358                 uint64_t u64;
359         } w10;
360
361         /* Word11 - Word14 */
362         union roc_ot_ipsec_outer_ip_hdr outer_hdr;
363
364         /* Word15 - Word30 */
365         uint8_t hmac_opad_ipad[ROC_CTX_MAX_OPAD_IPAD_LEN];
366
367         /* Word31 - Word100 */
368         struct roc_ot_ipsec_inb_ctx_update_reg ctx;
369 };
370
371 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, w1) ==
372                   1 * sizeof(uint64_t));
373 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, w2) ==
374                   2 * sizeof(uint64_t));
375 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, cipher_key) ==
376                   4 * sizeof(uint64_t));
377 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, w8) ==
378                   8 * sizeof(uint64_t));
379 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, w10) ==
380                   10 * sizeof(uint64_t));
381 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, outer_hdr) ==
382                   11 * sizeof(uint64_t));
383 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, hmac_opad_ipad) ==
384                   15 * sizeof(uint64_t));
385 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_inb_sa, ctx) ==
386                   31 * sizeof(uint64_t));
387
388 struct roc_ot_ipsec_outb_sa {
389         /* Word0 */
390         union {
391                 struct {
392                         uint64_t esn_en : 1;
393                         uint64_t ip_id : 1;
394                         uint64_t rsvd0 : 1;
395                         uint64_t hard_life_dec : 1;
396                         uint64_t soft_life_dec : 1;
397                         uint64_t count_glb_octets : 1;
398                         uint64_t count_glb_pkts : 1;
399                         uint64_t count_mib_bytes : 1;
400
401                         uint64_t count_mib_pkts : 1;
402                         uint64_t hw_ctx_off : 7;
403
404                         uint64_t rsvd1 : 32;
405
406                         uint64_t ctx_push_size : 7;
407                         uint64_t rsvd2 : 1;
408
409                         uint64_t ctx_hdr_size : 2;
410                         uint64_t aop_valid : 1;
411                         uint64_t rsvd3 : 1;
412                         uint64_t ctx_size : 4;
413                 } s;
414                 uint64_t u64;
415         } w0;
416
417         /* Word1 */
418         union {
419                 struct {
420                         uint64_t rsvd4 : 32;
421                         uint64_t cookie : 32;
422                 } s;
423                 uint64_t u64;
424         } w1;
425
426         /* Word 2 */
427         union {
428                 struct {
429                         uint64_t valid : 1;
430                         uint64_t dir : 1;
431                         uint64_t outer_ip_ver : 1;
432                         uint64_t rsvd5 : 1;
433                         uint64_t ipsec_mode : 1;
434                         uint64_t ipsec_protocol : 1;
435                         uint64_t aes_key_len : 2;
436
437                         uint64_t enc_type : 3;
438                         uint64_t life_unit : 1;
439                         uint64_t auth_type : 4;
440
441                         uint64_t encap_type : 2;
442                         uint64_t ipv4_df_src_or_ipv6_flw_lbl_src : 1;
443                         uint64_t dscp_src : 1;
444                         uint64_t iv_src : 2;
445                         uint64_t ipid_gen : 1;
446                         uint64_t rsvd6 : 1;
447
448                         uint64_t rsvd7 : 7;
449                         uint64_t async_mode : 1;
450
451                         uint64_t spi : 32;
452                 } s;
453                 uint64_t u64;
454         } w2;
455
456         /* Word3 */
457         uint64_t rsvd8;
458
459         /* Word4 - Word7 */
460         uint8_t cipher_key[ROC_CTX_MAX_CKEY_LEN];
461
462         /* Word8 - Word9 */
463         union roc_ot_ipsec_outb_iv iv;
464
465         /* Word10 */
466         union {
467                 struct {
468                         uint64_t rsvd9 : 4;
469                         uint64_t ipv4_df_or_ipv6_flw_lbl : 20;
470
471                         uint64_t dscp : 6;
472                         uint64_t rsvd10 : 2;
473
474                         uint64_t udp_dst_port : 16;
475
476                         uint64_t udp_src_port : 16;
477                 } s;
478                 uint64_t u64;
479         } w10;
480
481         /* Word11 - Word14 */
482         union roc_ot_ipsec_outer_ip_hdr outer_hdr;
483
484         /* Word15 - Word30 */
485         uint8_t hmac_opad_ipad[ROC_CTX_MAX_OPAD_IPAD_LEN];
486
487         /* Word31 - Word36 */
488         struct roc_ot_ipsec_outb_ctx_update_reg ctx;
489 };
490
491 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, w1) ==
492                   1 * sizeof(uint64_t));
493 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, w2) ==
494                   2 * sizeof(uint64_t));
495 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, cipher_key) ==
496                   4 * sizeof(uint64_t));
497 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, iv) ==
498                   8 * sizeof(uint64_t));
499 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, w10) ==
500                   10 * sizeof(uint64_t));
501 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, outer_hdr) ==
502                   11 * sizeof(uint64_t));
503 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, hmac_opad_ipad) ==
504                   15 * sizeof(uint64_t));
505 PLT_STATIC_ASSERT(offsetof(struct roc_ot_ipsec_outb_sa, ctx) ==
506                   31 * sizeof(uint64_t));
507
508 #endif /* __ROC_IE_OT_H__ */