xref: /dpdk/drivers/common/cnxk/roc_ie_ot_tls.h (revision 7f82e9c89f3514715533feb34f46ff1ea95c6f98)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2024 Marvell.
3  */
4 
5 #ifndef __ROC_IE_OT_TLS_H__
6 #define __ROC_IE_OT_TLS_H__
7 
8 #include "roc_platform.h"
9 
10 #define ROC_IE_OT_TLS_CTX_ILEN		     1
11 #define ROC_IE_OT_TLS_CTX_HDR_SIZE	     1
12 #define ROC_IE_OT_TLS_AR_WIN_SIZE_MAX	     4096
13 #define ROC_IE_OT_TLS_LOG_MIN_AR_WIN_SIZE_M1 5
14 
15 /* u64 array size to fit anti replay window bits */
16 #define ROC_IE_OT_TLS_AR_WINBITS_SZ                                                                \
17 	(PLT_ALIGN_CEIL(ROC_IE_OT_TLS_AR_WIN_SIZE_MAX, BITS_PER_LONG_LONG) / BITS_PER_LONG_LONG)
18 
19 /* CN10K TLS opcodes */
20 #define ROC_IE_OT_TLS_MAJOR_OP_RECORD_ENC   0x16UL
21 #define ROC_IE_OT_TLS_MAJOR_OP_RECORD_DEC   0x17UL
22 #define ROC_IE_OT_TLS13_MAJOR_OP_RECORD_ENC 0x18UL
23 #define ROC_IE_OT_TLS13_MAJOR_OP_RECORD_DEC 0x19UL
24 
25 #define ROC_IE_OT_TLS_CTX_MAX_OPAD_IPAD_LEN 128
26 #define ROC_IE_OT_TLS_CTX_MAX_KEY_IV_LEN    48
27 #define ROC_IE_OT_TLS_CTX_MAX_IV_LEN	    16
28 
29 enum roc_ie_ot_tls_mac_type {
30 	ROC_IE_OT_TLS_MAC_MD5 = 1,
31 	ROC_IE_OT_TLS_MAC_SHA1 = 2,
32 	ROC_IE_OT_TLS_MAC_SHA2_256 = 4,
33 	ROC_IE_OT_TLS_MAC_SHA2_384 = 5,
34 	ROC_IE_OT_TLS_MAC_SHA2_512 = 6,
35 };
36 
37 enum roc_ie_ot_tls_cipher_type {
38 	ROC_IE_OT_TLS_CIPHER_3DES = 1,
39 	ROC_IE_OT_TLS_CIPHER_AES_CBC = 3,
40 	ROC_IE_OT_TLS_CIPHER_AES_GCM = 7,
41 	ROC_IE_OT_TLS_CIPHER_AES_CCM = 10,
42 	ROC_IE_OT_TLS_CIPHER_CHACHA_POLY = 9,
43 };
44 
45 enum roc_ie_ot_tls_ver {
46 	ROC_IE_OT_TLS_VERSION_TLS_12 = 1,
47 	ROC_IE_OT_TLS_VERSION_DTLS_12 = 2,
48 	ROC_IE_OT_TLS_VERSION_TLS_13 = 3,
49 };
50 
51 enum roc_ie_ot_tls_aes_key_len {
52 	ROC_IE_OT_TLS_AES_KEY_LEN_128 = 1,
53 	ROC_IE_OT_TLS_AES_KEY_LEN_256 = 3,
54 };
55 
56 enum {
57 	ROC_IE_OT_TLS_IV_SRC_DEFAULT = 0,
58 	ROC_IE_OT_TLS_IV_SRC_FROM_SA = 1,
59 };
60 
61 struct roc_ie_ot_tls_read_ctx_update_reg {
62 	uint64_t ar_base;
63 	uint64_t ar_valid_mask;
64 	uint64_t hard_life;
65 	uint64_t soft_life;
66 	uint64_t mib_octs;
67 	uint64_t mib_pkts;
68 	uint64_t ar_winbits[ROC_IE_OT_TLS_AR_WINBITS_SZ];
69 };
70 
71 struct roc_ie_ot_tls_1_3_read_ctx_update_reg {
72 	uint64_t rsvd0;
73 	uint64_t ar_valid_mask;
74 	uint64_t hard_life;
75 	uint64_t soft_life;
76 	uint64_t mib_octs;
77 	uint64_t mib_pkts;
78 	uint64_t rsvd1;
79 };
80 
81 union roc_ie_ot_tls_param2 {
82 	uint16_t u16;
83 	struct {
84 		uint8_t msg_type;
85 		uint8_t rsvd;
86 	} s;
87 };
88 
89 struct roc_ie_ot_tls_read_sa {
90 	/* Word0 */
91 	union {
92 		struct {
93 			uint64_t ar_win : 3;
94 			uint64_t hard_life_dec : 1;
95 			uint64_t soft_life_dec : 1;
96 			uint64_t count_glb_octets : 1;
97 			uint64_t count_glb_pkts : 1;
98 			uint64_t count_mib_bytes : 1;
99 
100 			uint64_t count_mib_pkts : 1;
101 			uint64_t hw_ctx_off : 7;
102 
103 			uint64_t ctx_id : 16;
104 
105 			uint64_t orig_pkt_fabs : 1;
106 			uint64_t orig_pkt_free : 1;
107 			uint64_t pkind : 6;
108 
109 			uint64_t rsvd0 : 1;
110 			uint64_t et_ovrwr : 1;
111 			uint64_t pkt_output : 2;
112 			uint64_t pkt_format : 1;
113 			uint64_t defrag_opt : 2;
114 			uint64_t x2p_dst : 1;
115 
116 			uint64_t ctx_push_size : 7;
117 			uint64_t rsvd1 : 1;
118 
119 			uint64_t ctx_hdr_size : 2;
120 			uint64_t aop_valid : 1;
121 			uint64_t rsvd2 : 1;
122 			uint64_t ctx_size : 4;
123 		} s;
124 		uint64_t u64;
125 	} w0;
126 
127 	/* Word1 */
128 	uint64_t w1_rsvd3;
129 
130 	/* Word2 */
131 	union {
132 		struct {
133 			uint64_t version_select : 4;
134 			uint64_t aes_key_len : 2;
135 			uint64_t cipher_select : 4;
136 			uint64_t mac_select : 4;
137 			uint64_t rsvd4 : 50;
138 		} s;
139 		uint64_t u64;
140 	} w2;
141 
142 	/* Word3 */
143 	uint64_t w3_rsvd5;
144 
145 	/* Word4 - Word9 */
146 	uint8_t cipher_key[ROC_IE_OT_TLS_CTX_MAX_KEY_IV_LEN];
147 
148 	union {
149 		struct {
150 			/* Word10 - Word16 */
151 			struct roc_ie_ot_tls_1_3_read_ctx_update_reg ctx;
152 		} tls_13;
153 
154 		struct {
155 			/* Word10 - Word25 */
156 			uint8_t opad_ipad[ROC_IE_OT_TLS_CTX_MAX_OPAD_IPAD_LEN];
157 
158 			/* Word26 - Word95 */
159 			struct roc_ie_ot_tls_read_ctx_update_reg ctx;
160 		} tls_12;
161 	};
162 };
163 
164 struct roc_ie_ot_tls_write_sa {
165 	/* Word0 */
166 	union {
167 		struct {
168 			uint64_t rsvd0 : 3;
169 			uint64_t hard_life_dec : 1;
170 			uint64_t soft_life_dec : 1;
171 			uint64_t count_glb_octets : 1;
172 			uint64_t count_glb_pkts : 1;
173 			uint64_t count_mib_bytes : 1;
174 
175 			uint64_t count_mib_pkts : 1;
176 			uint64_t hw_ctx_off : 7;
177 
178 			uint64_t rsvd1 : 32;
179 
180 			uint64_t ctx_push_size : 7;
181 			uint64_t rsvd2 : 1;
182 
183 			uint64_t ctx_hdr_size : 2;
184 			uint64_t aop_valid : 1;
185 			uint64_t rsvd3 : 1;
186 			uint64_t ctx_size : 4;
187 		} s;
188 		uint64_t u64;
189 	} w0;
190 
191 	/* Word1 */
192 	uint64_t w1_rsvd4;
193 
194 	/* Word2 */
195 	union {
196 		struct {
197 			uint64_t version_select : 4;
198 			uint64_t aes_key_len : 2;
199 			uint64_t cipher_select : 4;
200 			uint64_t mac_select : 4;
201 			uint64_t iv_at_cptr : 1;
202 			uint64_t rsvd5 : 49;
203 		} s;
204 		uint64_t u64;
205 	} w2;
206 
207 	/* Word3 */
208 	uint64_t w3_rsvd6;
209 
210 	/* Word4 - Word9 */
211 	uint8_t cipher_key[ROC_IE_OT_TLS_CTX_MAX_KEY_IV_LEN];
212 
213 	union {
214 		struct {
215 			/* Word10 */
216 			uint64_t w10_rsvd7;
217 
218 			uint64_t seq_num;
219 		} tls_13;
220 
221 		struct {
222 			/* Word10 - Word25 */
223 			uint8_t opad_ipad[ROC_IE_OT_TLS_CTX_MAX_OPAD_IPAD_LEN];
224 
225 			/* Word26 */
226 			uint64_t w26_rsvd7;
227 
228 			/* Word27 */
229 			uint64_t seq_num;
230 		} tls_12;
231 	};
232 };
233 #endif /* __ROC_IE_OT_TLS_H__ */
234