crypto/cnxk: move IPsec SA creation to common
[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         /* Software defined completion code for anti-replay failed packets */
22         ROC_IE_ON_SWCC_ANTI_REPLAY = 0xE7,
23 };
24
25 /* Helper macros */
26 #define ROC_IE_ON_INB_RPTR_HDR 16
27 #define ROC_IE_ON_MAX_IV_LEN   16
28 #define ROC_IE_ON_PER_PKT_IV   BIT(43)
29
30 enum {
31         ROC_IE_ON_SA_ENC_NULL = 0,
32         ROC_IE_ON_SA_ENC_DES_CBC = 1,
33         ROC_IE_ON_SA_ENC_3DES_CBC = 2,
34         ROC_IE_ON_SA_ENC_AES_CBC = 3,
35         ROC_IE_ON_SA_ENC_AES_CTR = 4,
36         ROC_IE_ON_SA_ENC_AES_GCM = 5,
37         ROC_IE_ON_SA_ENC_AES_CCM = 6,
38 };
39
40 enum {
41         ROC_IE_ON_SA_AUTH_NULL = 0,
42         ROC_IE_ON_SA_AUTH_MD5 = 1,
43         ROC_IE_ON_SA_AUTH_SHA1 = 2,
44         ROC_IE_ON_SA_AUTH_SHA2_224 = 3,
45         ROC_IE_ON_SA_AUTH_SHA2_256 = 4,
46         ROC_IE_ON_SA_AUTH_SHA2_384 = 5,
47         ROC_IE_ON_SA_AUTH_SHA2_512 = 6,
48         ROC_IE_ON_SA_AUTH_AES_GMAC = 7,
49         ROC_IE_ON_SA_AUTH_AES_XCBC_128 = 8,
50 };
51
52 enum {
53         ROC_IE_ON_SA_FRAG_POST = 0,
54         ROC_IE_ON_SA_FRAG_PRE = 1,
55 };
56
57 enum {
58         ROC_IE_ON_SA_ENCAP_NONE = 0,
59         ROC_IE_ON_SA_ENCAP_UDP = 1,
60 };
61
62 enum {
63         ROC_IE_ON_IV_SRC_HW_GEN_DEFAULT = 0,
64         ROC_IE_ON_IV_SRC_FROM_DPTR = 1,
65 };
66
67 struct roc_ie_on_outb_hdr {
68         uint32_t ip_id;
69         uint32_t seq;
70         uint32_t esn;
71         uint32_t df_tos;
72         uint8_t iv[16];
73 };
74
75 struct roc_ie_on_inb_hdr {
76         uint32_t sa_index;
77         uint64_t seq;
78         uint32_t pad;
79 };
80
81 union roc_ie_on_bit_perfect_iv {
82         uint8_t aes_iv[16];
83         uint8_t des_iv[8];
84         struct {
85                 uint8_t nonce[4];
86                 uint8_t iv[8];
87                 uint8_t counter[4];
88         } gcm;
89 };
90
91 struct roc_ie_on_traffic_selector {
92         uint16_t src_port[2];
93         uint16_t dst_port[2];
94         union {
95                 struct {
96                         uint32_t src_addr[2];
97                         uint32_t dst_addr[2];
98                 } ipv4;
99                 struct {
100                         uint8_t src_addr[32];
101                         uint8_t dst_addr[32];
102                 } ipv6;
103         };
104 };
105
106 struct roc_ie_on_ip_template {
107         union {
108                 struct {
109                         uint8_t ipv4_hdr[20];
110                         uint16_t udp_src;
111                         uint16_t udp_dst;
112                 } ip4;
113                 struct {
114                         uint8_t ipv6_hdr[40];
115                         uint16_t udp_src;
116                         uint16_t udp_dst;
117                 } ip6;
118         };
119 };
120
121 union roc_on_ipsec_outb_param1 {
122         uint16_t u16;
123         struct {
124                 uint16_t l2hdr_len : 4;
125                 uint16_t rsvd_4_6 : 3;
126                 uint16_t gre_select : 1;
127                 uint16_t dsiv : 1;
128                 uint16_t ikev2 : 1;
129                 uint16_t min_frag_size : 1;
130                 uint16_t per_pkt_iv : 1;
131                 uint16_t tfc_pad_enable : 1;
132                 uint16_t tfc_dummy_pkt : 1;
133                 uint16_t rfc_or_override_mode : 1;
134                 uint16_t custom_hdr_or_p99 : 1;
135         } s;
136 };
137
138 union roc_on_ipsec_inb_param2 {
139         uint16_t u16;
140         struct {
141                 uint16_t rsvd_0_10 : 11;
142                 uint16_t gre_select : 1;
143                 uint16_t ikev2 : 1;
144                 uint16_t udp_cksum : 1;
145                 uint16_t ctx_addr_sel : 1;
146                 uint16_t custom_hdr_or_p99 : 1;
147         } s;
148 };
149
150 struct roc_ie_on_sa_ctl {
151         uint64_t spi : 32;
152         uint64_t exp_proto_inter_frag : 8;
153         uint64_t copy_df : 1;
154         uint64_t frag_type : 1;
155         uint64_t explicit_iv_en : 1;
156         uint64_t esn_en : 1;
157         uint64_t rsvd_45_44 : 2;
158         uint64_t encap_type : 2;
159         uint64_t enc_type : 3;
160         uint64_t rsvd_48 : 1;
161         uint64_t auth_type : 4;
162         uint64_t valid : 1;
163         uint64_t direction : 1;
164         uint64_t outer_ip_ver : 1;
165         uint64_t inner_ip_ver : 1;
166         uint64_t ipsec_mode : 1;
167         uint64_t ipsec_proto : 1;
168         uint64_t aes_key_len : 2;
169 };
170
171 struct roc_ie_on_common_sa {
172         /* w0 */
173         struct roc_ie_on_sa_ctl ctl;
174
175         /* w1-w4 */
176         uint8_t cipher_key[32];
177
178         /* w5-w6 */
179         union roc_ie_on_bit_perfect_iv iv;
180
181         /* w7 */
182         union {
183                 uint64_t u64;
184                 struct {
185                         uint32_t th;
186                         uint32_t tl;
187                 };
188         } seq_t;
189 };
190
191 struct roc_ie_on_outb_sa {
192         /* w0 - w7 */
193         struct roc_ie_on_common_sa common_sa;
194
195         /* w8-w55 */
196         union {
197                 struct {
198                         struct roc_ie_on_ip_template template;
199                 } aes_gcm;
200                 struct {
201                         uint8_t hmac_key[24];
202                         uint8_t unused[24];
203                         struct roc_ie_on_ip_template template;
204                 } sha1;
205                 struct {
206                         uint8_t key[16];
207                         uint8_t unused[32];
208                         struct roc_ie_on_ip_template template;
209                 } aes_xcbc;
210                 struct {
211                         uint8_t hmac_key[64];
212                         uint8_t hmac_iv[64];
213                         struct roc_ie_on_ip_template template;
214                 } sha2;
215         };
216 };
217
218 struct roc_ie_on_inb_sa {
219         /* w0 - w7 */
220         struct roc_ie_on_common_sa common_sa;
221
222         /* w8 */
223         uint8_t udp_encap[8];
224
225         /* w9-w33 */
226         union {
227                 struct {
228                         uint8_t hmac_key[48];
229                         struct roc_ie_on_traffic_selector selector;
230                 } sha1_or_gcm;
231                 struct {
232                         uint8_t key[16];
233                         uint8_t unused[32];
234                         struct roc_ie_on_traffic_selector selector;
235                 } aes_xcbc;
236                 struct {
237                         uint8_t hmac_key[64];
238                         uint8_t hmac_iv[64];
239                         struct roc_ie_on_traffic_selector selector;
240                 } sha2;
241         };
242 };
243
244 /* CN9K IPsec FP */
245
246 /* CN9K IPsec FP opcodes */
247 #define ROC_IE_ONF_MAJOR_OP_PROCESS_OUTBOUND_IPSEC 0x25UL
248 #define ROC_IE_ONF_MAJOR_OP_PROCESS_INBOUND_IPSEC  0x26UL
249
250 /* Ucode completion codes */
251 #define ROC_IE_ON_UCC_SUCCESS             0
252 #define ROC_IE_ON_UCC_ENC_TYPE_ERR        0xB1
253 #define ROC_IE_ON_UCC_IP_VER_ERR          0xB2
254 #define ROC_IE_ON_UCC_PROTO_ERR           0xB3
255 #define ROC_IE_ON_UCC_CTX_INVALID         0xB4
256 #define ROC_IE_ON_UCC_CTX_DIR_MISMATCH    0xB5
257 #define ROC_IE_ON_UCC_IP_PAYLOAD_TYPE_ERR 0xB6
258 #define ROC_IE_ON_UCC_CTX_FLAG_MISMATCH   0xB7
259 #define ROC_IE_ON_UCC_SPI_MISMATCH        0xBE
260 #define ROC_IE_ON_UCC_IP_CHKSUM_ERR       0xBF
261 #define ROC_IE_ON_UCC_AUTH_ERR            0xC3
262 #define ROC_IE_ON_UCC_PADDING_INVALID     0xC4
263 #define ROC_IE_ON_UCC_SA_MISMATCH         0xCC
264 #define ROC_IE_ON_UCC_L2_HDR_INFO_ERR     0xCF
265 #define ROC_IE_ON_UCC_L2_HDR_LEN_ERR      0xE0
266
267 struct roc_ie_onf_sa_ctl {
268         uint32_t spi;
269         uint64_t exp_proto_inter_frag : 8;
270         uint64_t rsvd_41_40 : 2;
271         /* Disable SPI, SEQ data in RPTR for Inbound inline */
272         uint64_t spi_seq_dis : 1;
273         uint64_t esn_en : 1;
274         uint64_t rsvd_44_45 : 2;
275         uint64_t encap_type : 2;
276         uint64_t enc_type : 3;
277         uint64_t rsvd_48 : 1;
278         uint64_t auth_type : 4;
279         uint64_t valid : 1;
280         uint64_t direction : 1;
281         uint64_t outer_ip_ver : 1;
282         uint64_t inner_ip_ver : 1;
283         uint64_t ipsec_mode : 1;
284         uint64_t ipsec_proto : 1;
285         uint64_t aes_key_len : 2;
286 };
287
288 struct roc_onf_ipsec_outb_sa {
289         /* w0 */
290         struct roc_ie_onf_sa_ctl ctl;
291
292         /* w1 */
293         uint8_t nonce[4];
294         uint16_t udp_src;
295         uint16_t udp_dst;
296
297         /* w2 */
298         uint32_t ip_src;
299         uint32_t ip_dst;
300
301         /* w3-w6 */
302         uint8_t cipher_key[32];
303
304         /* w7-w12 */
305         uint8_t hmac_key[48];
306 };
307
308 struct roc_onf_ipsec_inb_sa {
309         /* w0 */
310         struct roc_ie_onf_sa_ctl ctl;
311
312         /* w1 */
313         uint8_t nonce[4]; /* Only for AES-GCM */
314         uint32_t unused;
315
316         /* w2 */
317         uint32_t esn_hi;
318         uint32_t esn_low;
319
320         /* w3-w6 */
321         uint8_t cipher_key[32];
322
323         /* w7-w12 */
324         uint8_t hmac_key[48];
325 };
326
327 #define ROC_ONF_IPSEC_INB_MAX_L2_SZ       32UL
328 #define ROC_ONF_IPSEC_OUTB_MAX_L2_SZ      30UL
329 #define ROC_ONF_IPSEC_OUTB_MAX_L2_INFO_SZ (ROC_ONF_IPSEC_OUTB_MAX_L2_SZ + 2)
330
331 #define ROC_ONF_IPSEC_INB_RES_OFF    80
332 #define ROC_ONF_IPSEC_INB_SPI_SEQ_SZ 16
333
334 struct roc_onf_ipsec_outb_hdr {
335         uint32_t ip_id;
336         uint32_t seq;
337         uint8_t iv[16];
338 };
339
340 #endif /* __ROC_IE_ON_H__ */