crypto/cnxk: support AES-CMAC
[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 key[16];
185                         uint8_t unused[32];
186                         struct roc_ie_on_ip_template template;
187                 } aes_xcbc;
188                 struct {
189                         uint8_t hmac_key[64];
190                         uint8_t hmac_iv[64];
191                         struct roc_ie_on_ip_template template;
192                 } sha2;
193         };
194 };
195
196 struct roc_ie_on_inb_sa {
197         /* w0 - w7 */
198         struct roc_ie_on_common_sa common_sa;
199
200         /* w8 */
201         uint8_t udp_encap[8];
202
203         /* w9-w33 */
204         union {
205                 struct {
206                         uint8_t hmac_key[48];
207                         struct roc_ie_on_traffic_selector selector;
208                 } sha1_or_gcm;
209                 struct {
210                         uint8_t key[16];
211                         uint8_t unused[32];
212                         struct roc_ie_on_traffic_selector selector;
213                 } aes_xcbc;
214                 struct {
215                         uint8_t hmac_key[64];
216                         uint8_t hmac_iv[64];
217                         struct roc_ie_on_traffic_selector selector;
218                 } sha2;
219         };
220 };
221
222 /* CN9K IPsec FP */
223
224 /* CN9K IPsec FP opcodes */
225 #define ROC_IE_ONF_MAJOR_OP_PROCESS_OUTBOUND_IPSEC 0x25UL
226 #define ROC_IE_ONF_MAJOR_OP_PROCESS_INBOUND_IPSEC  0x26UL
227
228 /* Ucode completion codes */
229 #define ROC_IE_ONF_UCC_SUCCESS 0
230
231 struct roc_ie_onf_sa_ctl {
232         uint32_t spi;
233         uint64_t exp_proto_inter_frag : 8;
234         uint64_t rsvd_41_40 : 2;
235         /* Disable SPI, SEQ data in RPTR for Inbound inline */
236         uint64_t spi_seq_dis : 1;
237         uint64_t esn_en : 1;
238         uint64_t rsvd_44_45 : 2;
239         uint64_t encap_type : 2;
240         uint64_t enc_type : 3;
241         uint64_t rsvd_48 : 1;
242         uint64_t auth_type : 4;
243         uint64_t valid : 1;
244         uint64_t direction : 1;
245         uint64_t outer_ip_ver : 1;
246         uint64_t inner_ip_ver : 1;
247         uint64_t ipsec_mode : 1;
248         uint64_t ipsec_proto : 1;
249         uint64_t aes_key_len : 2;
250 };
251
252 struct roc_onf_ipsec_outb_sa {
253         /* w0 */
254         struct roc_ie_onf_sa_ctl ctl;
255
256         /* w1 */
257         uint8_t nonce[4];
258         uint16_t udp_src;
259         uint16_t udp_dst;
260
261         /* w2 */
262         uint32_t ip_src;
263         uint32_t ip_dst;
264
265         /* w3-w6 */
266         uint8_t cipher_key[32];
267
268         /* w7-w12 */
269         uint8_t hmac_key[48];
270 };
271
272 struct roc_onf_ipsec_inb_sa {
273         /* w0 */
274         struct roc_ie_onf_sa_ctl ctl;
275
276         /* w1 */
277         uint8_t nonce[4]; /* Only for AES-GCM */
278         uint32_t unused;
279
280         /* w2 */
281         uint32_t esn_hi;
282         uint32_t esn_low;
283
284         /* w3-w6 */
285         uint8_t cipher_key[32];
286
287         /* w7-w12 */
288         uint8_t hmac_key[48];
289 };
290
291 #define ROC_ONF_IPSEC_INB_MAX_L2_SZ       32UL
292 #define ROC_ONF_IPSEC_OUTB_MAX_L2_SZ      30UL
293 #define ROC_ONF_IPSEC_OUTB_MAX_L2_INFO_SZ (ROC_ONF_IPSEC_OUTB_MAX_L2_SZ + 2)
294
295 #define ROC_ONF_IPSEC_INB_RES_OFF    80
296 #define ROC_ONF_IPSEC_INB_SPI_SEQ_SZ 16
297
298 struct roc_onf_ipsec_outb_hdr {
299         uint32_t ip_id;
300         uint32_t seq;
301         uint8_t iv[16];
302 };
303
304 #endif /* __ROC_IE_ON_H__ */