xref: /freebsd/sys/dev/cxgbe/tom/t4_tls.h (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2017-2018 Chelsio Communications, Inc.
5  * All rights reserved.
6  * Written by: John Baldwin <jhb@FreeBSD.org>, Atul Gupta
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  *
31  */
32 
33 #ifndef __T4_TLS_H__
34 #define __T4_TLS_H__
35 
36 #define TLS1_VERSION                    0x0301
37 #define TLS1_1_VERSION                  0x0302
38 #define TLS1_2_VERSION                  0x0303
39 #define TLS_MAX_VERSION                 TLS1_2_VERSION
40 
41 #define DTLS1_VERSION                   0xFEFF
42 #define DTLS1_2_VERSION                 0xFEFD
43 #define DTLS_MAX_VERSION                DTLS1_2_VERSION
44 #define DTLS1_VERSION_MAJOR             0xFE
45 
46 /* Custom socket options for TLS+TOE. */
47 
48 #define MAX_MAC_KSZ		64	/*512 bits */
49 #define MAX_CIPHER_KSZ		32	/* 256 bits */
50 #define CIPHER_BLOCK_SZ		16
51 #define SALT_SIZE		4
52 
53 /* Can accomodate 16, 11-15 are reserved */
54 enum {
55     CHSSL_SHA_NOP,
56     CHSSL_SHA1,
57     CHSSL_SHA224,
58     CHSSL_SHA256,
59     CHSSL_GHASH,
60     CHSSL_SHA512_224,
61     CHSSL_SHA512_256,
62     CHSSL_SHA512_384,
63     CHSSL_SHA512_512,
64     CHSSL_CBCMAC,
65     CHSSL_CMAC,
66 };
67 
68 /* Can accomodate 16, 8-15 are reserved */
69 enum {
70     CHSSL_CIPH_NOP,
71     CHSSL_AES_CBC,
72     CHSSL_AES_GCM,
73     CHSSL_AES_CTR,
74     CHSSL_AES_GEN,
75     CHSSL_IPSEC_ESP,
76     CHSSL_AES_XTS,
77     CHSSL_AES_CCM,
78 };
79 
80 /* Key Context Programming Operation type */
81 #define KEY_WRITE_RX			0x1
82 #define KEY_WRITE_TX			0x2
83 #define KEY_DELETE_RX			0x4
84 #define KEY_DELETE_TX			0x8
85 
86 #define S_KEY_CLR_LOC		4
87 #define M_KEY_CLR_LOC		0xf
88 #define V_KEY_CLR_LOC(x)	((x) << S_KEY_CLR_LOC)
89 #define G_KEY_CLR_LOC(x)	(((x) >> S_KEY_CLR_LOC) & M_KEY_CLR_LOC)
90 #define F_KEY_CLR_LOC		V_KEY_CLR_LOC(1U)
91 
92 #define S_KEY_GET_LOC           0
93 #define M_KEY_GET_LOC           0xf
94 #define V_KEY_GET_LOC(x)        ((x) << S_KEY_GET_LOC)
95 #define G_KEY_GET_LOC(x)        (((x) >> S_KEY_GET_LOC) & M_KEY_GET_LOC)
96 
97 struct tls_ofld_state {
98     unsigned char enc_mode;
99     unsigned char mac_mode;
100     unsigned char key_loc;
101     unsigned char ofld_mode;
102     unsigned char auth_mode;
103     unsigned char resv[3];
104 };
105 
106 struct tls_tx_ctxt {
107     unsigned char   salt[SALT_SIZE];
108     unsigned char key[MAX_CIPHER_KSZ];
109     unsigned char ipad[MAX_MAC_KSZ];
110     unsigned char opad[MAX_MAC_KSZ];
111 };
112 
113 struct tls_rx_ctxt {
114     unsigned char   salt[SALT_SIZE];
115     unsigned char key[MAX_CIPHER_KSZ];
116     unsigned char ipad[MAX_MAC_KSZ];
117     unsigned char opad[MAX_MAC_KSZ];
118 };
119 
120 struct tls_key_context {
121     struct tls_tx_ctxt tx;
122     struct tls_rx_ctxt rx;
123 
124     unsigned char l_p_key;
125     unsigned char hmac_ctrl;
126     unsigned char mac_first;
127     unsigned char iv_size;
128     unsigned char iv_ctrl;
129     unsigned char iv_algo;
130     unsigned char tx_seq_no;
131     unsigned char rx_seq_no;
132 
133     struct tls_ofld_state state;
134 
135     unsigned int tx_key_info_size;
136     unsigned int rx_key_info_size;
137     unsigned int frag_size;
138     unsigned int mac_secret_size;
139     unsigned int cipher_secret_size;
140     int proto_ver;
141     unsigned int sock_fd;
142     unsigned short dtls_epoch;
143     unsigned short rsv;
144 };
145 
146 /* Set with 'struct tls_key_context'. */
147 #define	TCP_TLSOM_SET_TLS_CONTEXT	(TCP_VENDOR)
148 
149 /* Get returns int of enabled (1) / disabled (0). */
150 #define	TCP_TLSOM_GET_TLS_TOM		(TCP_VENDOR + 1)
151 
152 enum {
153 	TLS_TOM_NONE = 0,
154 	TLS_TOM_TXONLY,
155 	TLS_TOM_BOTH
156 };
157 
158 /* Set with no value. */
159 #define	TCP_TLSOM_CLR_TLS_TOM		(TCP_VENDOR + 2)
160 
161 /* Set with no value. */
162 #define	TCP_TLSOM_CLR_QUIES		(TCP_VENDOR + 3)
163 
164 #ifdef _KERNEL
165 /* Timeouts for handshake timer in seconds. */
166 #define TLS_SRV_HELLO_DONE		9
167 #define TLS_SRV_HELLO_RD_TM		5
168 #define TLS_SRV_HELLO_BKOFF_TM		15
169 
170 #define CONTENT_TYPE_CCS		20
171 #define CONTENT_TYPE_ALERT		21
172 #define CONTENT_TYPE_HANDSHAKE		22
173 #define CONTENT_TYPE_APP_DATA		23
174 #define CONTENT_TYPE_HEARTBEAT		24
175 #define CONTENT_TYPE_KEY_CONTEXT	32
176 #define CONTENT_TYPE_ERROR		127
177 
178 #define GCM_TAG_SIZE			16
179 #define AEAD_EXPLICIT_DATA_SIZE		8
180 #define TLS_HEADER_LENGTH		5
181 #define TP_TX_PG_SZ			65536
182 #define FC_TP_PLEN_MAX			17408
183 
184 #define IPAD_SIZE			64
185 #define OPAD_SIZE			64
186 #define KEY_SIZE			32
187 #define CIPHER_BLOCK_SIZE		16
188 #define HDR_KCTX_SIZE   (IPAD_SIZE + OPAD_SIZE + KEY_SIZE)
189 
190 #define KEY_IN_DDR_SIZE			16
191 #define	TLS_KEY_CONTEXT_SZ	roundup2(sizeof(struct tls_tx_ctxt), 32)
192 
193 /* MAC KEY SIZE */
194 #define SHA_NOP				0
195 #define SHA_GHASH			16
196 #define SHA_224				28
197 #define SHA_256				32
198 #define SHA_384				48
199 #define SHA_512				64
200 #define SHA1				20
201 
202 /* CIPHER KEY SIZE */
203 #define AES_NOP				0
204 #define AES_128				16
205 #define AES_192				24
206 #define AES_256				32
207 
208 enum {
209 	TLS_1_2_VERSION,
210 	TLS_1_1_VERSION,
211 	DTLS_1_2_VERSION,
212 	TLS_VERSION_MAX,
213 };
214 
215 enum {
216 	CH_EVP_CIPH_STREAM_CIPHER,
217 	CH_EVP_CIPH_CBC_MODE,
218 	CH_EVP_CIPH_GCM_MODE,
219 	CH_EVP_CIPH_CTR_MODE,
220 };
221 
222 enum {
223 	TLS_SFO_WR_CONTEXTLOC_DSGL,
224 	TLS_SFO_WR_CONTEXTLOC_IMMEDIATE,
225 	TLS_SFO_WR_CONTEXTLOC_DDR,
226 };
227 
228 enum {
229 	CPL_TX_TLS_SFO_TYPE_CCS,
230 	CPL_TX_TLS_SFO_TYPE_ALERT,
231 	CPL_TX_TLS_SFO_TYPE_HANDSHAKE,
232 	CPL_TX_TLS_SFO_TYPE_DATA,
233 	CPL_TX_TLS_SFO_TYPE_HEARTBEAT,	/* XXX: Shouldn't this be "CUSTOM"? */
234 };
235 
236 enum {
237 	CH_CK_SIZE_128,
238 	CH_CK_SIZE_192,
239 	CH_CK_SIZE_256,
240 	CH_CK_SIZE_NOP,
241 };
242 
243 enum {
244 	CH_MK_SIZE_128,
245 	CH_MK_SIZE_160,
246 	CH_MK_SIZE_192,
247 	CH_MK_SIZE_256,
248 	CH_MK_SIZE_512,
249 	CH_MK_SIZE_NOP,
250 };
251 
252 struct tls_scmd {
253 	__be32 seqno_numivs;
254 	__be32 ivgen_hdrlen;
255 };
256 
257 enum tls_mode {
258 	TLS_MODE_OFF,
259 	TLS_MODE_TLSOM,
260 	TLS_MODE_KTLS,
261 };
262 
263 struct tls_ofld_info {
264 	struct tls_key_context k_ctx;
265 	int key_location;
266 	int mac_length;
267 	int rx_key_addr;
268 	int tx_key_addr;
269 	uint64_t tx_seq_no;
270 	unsigned short fcplenmax;
271 	unsigned short adjusted_plen;
272 	unsigned short expn_per_ulp;
273 	unsigned short pdus_per_ulp;
274 	struct tls_scmd scmd0;
275 	u_int iv_len;
276 	enum tls_mode mode;
277 	struct callout handshake_timer;
278 	u_int sb_off;
279 };
280 
281 struct tls_key_req {
282 	__be32 wr_hi;
283 	__be32 wr_mid;
284         __be32 ftid;
285         __u8   reneg_to_write_rx;
286         __u8   protocol;
287         __be16 mfs;
288 	/* master command */
289 	__be32 cmd;
290 	__be32 len16;             /* command length */
291 	__be32 dlen;              /* data length in 32-byte units */
292 	__be32 kaddr;
293 	/* sub-command */
294 	__be32 sc_more;
295 	__be32 sc_len;
296 }__packed;
297 
298 struct tls_keyctx {
299         union key_ctx {
300                 struct tx_keyctx_hdr {
301                         __u8   ctxlen;
302                         __u8   r2;
303                         __be16 dualck_to_txvalid;
304                         __u8   txsalt[4];
305                         __be64 r5;
306                 } txhdr;
307                 struct rx_keyctx_hdr {
308                         __u8   flitcnt_hmacctrl;
309                         __u8   protover_ciphmode;
310                         __u8   authmode_to_rxvalid;
311                         __u8   ivpresent_to_rxmk_size;
312                         __u8   rxsalt[4];
313                         __be64 ivinsert_to_authinsrt;
314                 } rxhdr;
315         } u;
316         struct keys {
317                 __u8   edkey[32];
318                 __u8   ipad[64];
319                 __u8   opad[64];
320         } keys;
321 };
322 
323 #define S_TLS_KEYCTX_TX_WR_DUALCK    12
324 #define M_TLS_KEYCTX_TX_WR_DUALCK    0x1
325 #define V_TLS_KEYCTX_TX_WR_DUALCK(x) ((x) << S_TLS_KEYCTX_TX_WR_DUALCK)
326 #define G_TLS_KEYCTX_TX_WR_DUALCK(x) \
327     (((x) >> S_TLS_KEYCTX_TX_WR_DUALCK) & M_TLS_KEYCTX_TX_WR_DUALCK)
328 #define F_TLS_KEYCTX_TX_WR_DUALCK    V_TLS_KEYCTX_TX_WR_DUALCK(1U)
329 
330 #define S_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT 11
331 #define M_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT 0x1
332 #define V_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT(x) \
333     ((x) << S_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT)
334 #define G_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT(x) \
335     (((x) >> S_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT) & \
336      M_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT)
337 #define F_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT \
338     V_TLS_KEYCTX_TX_WR_TXOPAD_PRESENT(1U)
339 
340 #define S_TLS_KEYCTX_TX_WR_SALT_PRESENT 10
341 #define M_TLS_KEYCTX_TX_WR_SALT_PRESENT 0x1
342 #define V_TLS_KEYCTX_TX_WR_SALT_PRESENT(x) \
343     ((x) << S_TLS_KEYCTX_TX_WR_SALT_PRESENT)
344 #define G_TLS_KEYCTX_TX_WR_SALT_PRESENT(x) \
345     (((x) >> S_TLS_KEYCTX_TX_WR_SALT_PRESENT) & \
346      M_TLS_KEYCTX_TX_WR_SALT_PRESENT)
347 #define F_TLS_KEYCTX_TX_WR_SALT_PRESENT \
348     V_TLS_KEYCTX_TX_WR_SALT_PRESENT(1U)
349 
350 #define S_TLS_KEYCTX_TX_WR_TXCK_SIZE 6
351 #define M_TLS_KEYCTX_TX_WR_TXCK_SIZE 0xf
352 #define V_TLS_KEYCTX_TX_WR_TXCK_SIZE(x) \
353     ((x) << S_TLS_KEYCTX_TX_WR_TXCK_SIZE)
354 #define G_TLS_KEYCTX_TX_WR_TXCK_SIZE(x) \
355     (((x) >> S_TLS_KEYCTX_TX_WR_TXCK_SIZE) & \
356      M_TLS_KEYCTX_TX_WR_TXCK_SIZE)
357 
358 #define S_TLS_KEYCTX_TX_WR_TXMK_SIZE 2
359 #define M_TLS_KEYCTX_TX_WR_TXMK_SIZE 0xf
360 #define V_TLS_KEYCTX_TX_WR_TXMK_SIZE(x) \
361     ((x) << S_TLS_KEYCTX_TX_WR_TXMK_SIZE)
362 #define G_TLS_KEYCTX_TX_WR_TXMK_SIZE(x) \
363     (((x) >> S_TLS_KEYCTX_TX_WR_TXMK_SIZE) & \
364      M_TLS_KEYCTX_TX_WR_TXMK_SIZE)
365 
366 #define S_TLS_KEYCTX_TX_WR_TXVALID   0
367 #define M_TLS_KEYCTX_TX_WR_TXVALID   0x1
368 #define V_TLS_KEYCTX_TX_WR_TXVALID(x) \
369     ((x) << S_TLS_KEYCTX_TX_WR_TXVALID)
370 #define G_TLS_KEYCTX_TX_WR_TXVALID(x) \
371     (((x) >> S_TLS_KEYCTX_TX_WR_TXVALID) & M_TLS_KEYCTX_TX_WR_TXVALID)
372 #define F_TLS_KEYCTX_TX_WR_TXVALID   V_TLS_KEYCTX_TX_WR_TXVALID(1U)
373 
374 #define S_TLS_KEYCTX_TX_WR_FLITCNT   3
375 #define M_TLS_KEYCTX_TX_WR_FLITCNT   0x1f
376 #define V_TLS_KEYCTX_TX_WR_FLITCNT(x) \
377     ((x) << S_TLS_KEYCTX_TX_WR_FLITCNT)
378 #define G_TLS_KEYCTX_TX_WR_FLITCNT(x) \
379     (((x) >> S_TLS_KEYCTX_TX_WR_FLITCNT) & M_TLS_KEYCTX_TX_WR_FLITCNT)
380 
381 #define S_TLS_KEYCTX_TX_WR_HMACCTRL  0
382 #define M_TLS_KEYCTX_TX_WR_HMACCTRL  0x7
383 #define V_TLS_KEYCTX_TX_WR_HMACCTRL(x) \
384     ((x) << S_TLS_KEYCTX_TX_WR_HMACCTRL)
385 #define G_TLS_KEYCTX_TX_WR_HMACCTRL(x) \
386     (((x) >> S_TLS_KEYCTX_TX_WR_HMACCTRL) & M_TLS_KEYCTX_TX_WR_HMACCTRL)
387 
388 #define S_TLS_KEYCTX_TX_WR_PROTOVER  4
389 #define M_TLS_KEYCTX_TX_WR_PROTOVER  0xf
390 #define V_TLS_KEYCTX_TX_WR_PROTOVER(x) \
391     ((x) << S_TLS_KEYCTX_TX_WR_PROTOVER)
392 #define G_TLS_KEYCTX_TX_WR_PROTOVER(x) \
393     (((x) >> S_TLS_KEYCTX_TX_WR_PROTOVER) & M_TLS_KEYCTX_TX_WR_PROTOVER)
394 
395 #define S_TLS_KEYCTX_TX_WR_CIPHMODE  0
396 #define M_TLS_KEYCTX_TX_WR_CIPHMODE  0xf
397 #define V_TLS_KEYCTX_TX_WR_CIPHMODE(x) \
398     ((x) << S_TLS_KEYCTX_TX_WR_CIPHMODE)
399 #define G_TLS_KEYCTX_TX_WR_CIPHMODE(x) \
400     (((x) >> S_TLS_KEYCTX_TX_WR_CIPHMODE) & M_TLS_KEYCTX_TX_WR_CIPHMODE)
401 
402 #define S_TLS_KEYCTX_TX_WR_AUTHMODE  4
403 #define M_TLS_KEYCTX_TX_WR_AUTHMODE  0xf
404 #define V_TLS_KEYCTX_TX_WR_AUTHMODE(x) \
405     ((x) << S_TLS_KEYCTX_TX_WR_AUTHMODE)
406 #define G_TLS_KEYCTX_TX_WR_AUTHMODE(x) \
407     (((x) >> S_TLS_KEYCTX_TX_WR_AUTHMODE) & M_TLS_KEYCTX_TX_WR_AUTHMODE)
408 
409 #define S_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL 3
410 #define M_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL 0x1
411 #define V_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL(x) \
412     ((x) << S_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL)
413 #define G_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL(x) \
414     (((x) >> S_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL) & \
415      M_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL)
416 #define F_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL \
417     V_TLS_KEYCTX_TX_WR_CIPHAUTHSEQCTRL(1U)
418 
419 #define S_TLS_KEYCTX_TX_WR_SEQNUMCTRL 1
420 #define M_TLS_KEYCTX_TX_WR_SEQNUMCTRL 0x3
421 #define V_TLS_KEYCTX_TX_WR_SEQNUMCTRL(x) \
422     ((x) << S_TLS_KEYCTX_TX_WR_SEQNUMCTRL)
423 #define G_TLS_KEYCTX_TX_WR_SEQNUMCTRL(x) \
424     (((x) >> S_TLS_KEYCTX_TX_WR_SEQNUMCTRL) & \
425      M_TLS_KEYCTX_TX_WR_SEQNUMCTRL)
426 
427 #define S_TLS_KEYCTX_TX_WR_RXVALID   0
428 #define M_TLS_KEYCTX_TX_WR_RXVALID   0x1
429 #define V_TLS_KEYCTX_TX_WR_RXVALID(x) \
430     ((x) << S_TLS_KEYCTX_TX_WR_RXVALID)
431 #define G_TLS_KEYCTX_TX_WR_RXVALID(x) \
432     (((x) >> S_TLS_KEYCTX_TX_WR_RXVALID) & M_TLS_KEYCTX_TX_WR_RXVALID)
433 #define F_TLS_KEYCTX_TX_WR_RXVALID   V_TLS_KEYCTX_TX_WR_RXVALID(1U)
434 
435 #define S_TLS_KEYCTX_TX_WR_IVPRESENT 7
436 #define M_TLS_KEYCTX_TX_WR_IVPRESENT 0x1
437 #define V_TLS_KEYCTX_TX_WR_IVPRESENT(x) \
438     ((x) << S_TLS_KEYCTX_TX_WR_IVPRESENT)
439 #define G_TLS_KEYCTX_TX_WR_IVPRESENT(x) \
440     (((x) >> S_TLS_KEYCTX_TX_WR_IVPRESENT) & \
441      M_TLS_KEYCTX_TX_WR_IVPRESENT)
442 #define F_TLS_KEYCTX_TX_WR_IVPRESENT V_TLS_KEYCTX_TX_WR_IVPRESENT(1U)
443 
444 #define S_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT 6
445 #define M_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT 0x1
446 #define V_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT(x) \
447     ((x) << S_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT)
448 #define G_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT(x) \
449     (((x) >> S_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT) & \
450      M_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT)
451 #define F_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT \
452     V_TLS_KEYCTX_TX_WR_RXOPAD_PRESENT(1U)
453 
454 #define S_TLS_KEYCTX_TX_WR_RXCK_SIZE 3
455 #define M_TLS_KEYCTX_TX_WR_RXCK_SIZE 0x7
456 #define V_TLS_KEYCTX_TX_WR_RXCK_SIZE(x) \
457     ((x) << S_TLS_KEYCTX_TX_WR_RXCK_SIZE)
458 #define G_TLS_KEYCTX_TX_WR_RXCK_SIZE(x) \
459     (((x) >> S_TLS_KEYCTX_TX_WR_RXCK_SIZE) & \
460      M_TLS_KEYCTX_TX_WR_RXCK_SIZE)
461 
462 #define S_TLS_KEYCTX_TX_WR_RXMK_SIZE 0
463 #define M_TLS_KEYCTX_TX_WR_RXMK_SIZE 0x7
464 #define V_TLS_KEYCTX_TX_WR_RXMK_SIZE(x) \
465     ((x) << S_TLS_KEYCTX_TX_WR_RXMK_SIZE)
466 #define G_TLS_KEYCTX_TX_WR_RXMK_SIZE(x) \
467     (((x) >> S_TLS_KEYCTX_TX_WR_RXMK_SIZE) & \
468      M_TLS_KEYCTX_TX_WR_RXMK_SIZE)
469 
470 #define S_TLS_KEYCTX_TX_WR_IVINSERT  55
471 #define M_TLS_KEYCTX_TX_WR_IVINSERT  0x1ffULL
472 #define V_TLS_KEYCTX_TX_WR_IVINSERT(x) \
473     ((x) << S_TLS_KEYCTX_TX_WR_IVINSERT)
474 #define G_TLS_KEYCTX_TX_WR_IVINSERT(x) \
475     (((x) >> S_TLS_KEYCTX_TX_WR_IVINSERT) & M_TLS_KEYCTX_TX_WR_IVINSERT)
476 
477 #define S_TLS_KEYCTX_TX_WR_AADSTRTOFST 47
478 #define M_TLS_KEYCTX_TX_WR_AADSTRTOFST 0xffULL
479 #define V_TLS_KEYCTX_TX_WR_AADSTRTOFST(x) \
480     ((x) << S_TLS_KEYCTX_TX_WR_AADSTRTOFST)
481 #define G_TLS_KEYCTX_TX_WR_AADSTRTOFST(x) \
482     (((x) >> S_TLS_KEYCTX_TX_WR_AADSTRTOFST) & \
483      M_TLS_KEYCTX_TX_WR_AADSTRTOFST)
484 
485 #define S_TLS_KEYCTX_TX_WR_AADSTOPOFST 39
486 #define M_TLS_KEYCTX_TX_WR_AADSTOPOFST 0xffULL
487 #define V_TLS_KEYCTX_TX_WR_AADSTOPOFST(x) \
488     ((x) << S_TLS_KEYCTX_TX_WR_AADSTOPOFST)
489 #define G_TLS_KEYCTX_TX_WR_AADSTOPOFST(x) \
490     (((x) >> S_TLS_KEYCTX_TX_WR_AADSTOPOFST) & \
491      M_TLS_KEYCTX_TX_WR_AADSTOPOFST)
492 
493 #define S_TLS_KEYCTX_TX_WR_CIPHERSRTOFST 30
494 #define M_TLS_KEYCTX_TX_WR_CIPHERSRTOFST 0x1ffULL
495 #define V_TLS_KEYCTX_TX_WR_CIPHERSRTOFST(x) \
496     ((x) << S_TLS_KEYCTX_TX_WR_CIPHERSRTOFST)
497 #define G_TLS_KEYCTX_TX_WR_CIPHERSRTOFST(x) \
498     (((x) >> S_TLS_KEYCTX_TX_WR_CIPHERSRTOFST) & \
499      M_TLS_KEYCTX_TX_WR_CIPHERSRTOFST)
500 
501 #define S_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST 23
502 #define M_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST 0x7f
503 #define V_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST(x) \
504     ((x) << S_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST)
505 #define G_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST(x) \
506     (((x) >> S_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST) & \
507      M_TLS_KEYCTX_TX_WR_CIPHERSTOPOFST)
508 
509 #define S_TLS_KEYCTX_TX_WR_AUTHSRTOFST 14
510 #define M_TLS_KEYCTX_TX_WR_AUTHSRTOFST 0x1ff
511 #define V_TLS_KEYCTX_TX_WR_AUTHSRTOFST(x) \
512     ((x) << S_TLS_KEYCTX_TX_WR_AUTHSRTOFST)
513 #define G_TLS_KEYCTX_TX_WR_AUTHSRTOFST(x) \
514     (((x) >> S_TLS_KEYCTX_TX_WR_AUTHSRTOFST) & \
515      M_TLS_KEYCTX_TX_WR_AUTHSRTOFST)
516 
517 #define S_TLS_KEYCTX_TX_WR_AUTHSTOPOFST 7
518 #define M_TLS_KEYCTX_TX_WR_AUTHSTOPOFST 0x7f
519 #define V_TLS_KEYCTX_TX_WR_AUTHSTOPOFST(x) \
520     ((x) << S_TLS_KEYCTX_TX_WR_AUTHSTOPOFST)
521 #define G_TLS_KEYCTX_TX_WR_AUTHSTOPOFST(x) \
522     (((x) >> S_TLS_KEYCTX_TX_WR_AUTHSTOPOFST) & \
523      M_TLS_KEYCTX_TX_WR_AUTHSTOPOFST)
524 
525 #define S_TLS_KEYCTX_TX_WR_AUTHINSRT 0
526 #define M_TLS_KEYCTX_TX_WR_AUTHINSRT 0x7f
527 #define V_TLS_KEYCTX_TX_WR_AUTHINSRT(x) \
528     ((x) << S_TLS_KEYCTX_TX_WR_AUTHINSRT)
529 #define G_TLS_KEYCTX_TX_WR_AUTHINSRT(x) \
530     (((x) >> S_TLS_KEYCTX_TX_WR_AUTHINSRT) & \
531      M_TLS_KEYCTX_TX_WR_AUTHINSRT)
532 
533 struct tls_hdr {
534 	__u8   type;
535 	__be16 version;
536 	__be16 length;
537 } __packed;
538 
539 struct tlsrx_hdr_pkt {
540 	__u8   type;
541 	__be16 version;
542 	__be16 length;
543 
544 	__be64 tls_seq;
545 	__be16 reserved1;
546 	__u8   res_to_mac_error;
547 } __packed;
548 
549 /* res_to_mac_error fields */
550 #define S_TLSRX_HDR_PKT_INTERNAL_ERROR   4
551 #define M_TLSRX_HDR_PKT_INTERNAL_ERROR   0x1
552 #define V_TLSRX_HDR_PKT_INTERNAL_ERROR(x) \
553 	((x) << S_TLSRX_HDR_PKT_INTERNAL_ERROR)
554 #define G_TLSRX_HDR_PKT_INTERNAL_ERROR(x) \
555 (((x) >> S_TLSRX_HDR_PKT_INTERNAL_ERROR) & M_TLSRX_HDR_PKT_INTERNAL_ERROR)
556 #define F_TLSRX_HDR_PKT_INTERNAL_ERROR   V_TLSRX_HDR_PKT_INTERNAL_ERROR(1U)
557 
558 #define S_TLSRX_HDR_PKT_SPP_ERROR        3
559 #define M_TLSRX_HDR_PKT_SPP_ERROR        0x1
560 #define V_TLSRX_HDR_PKT_SPP_ERROR(x)     ((x) << S_TLSRX_HDR_PKT_SPP_ERROR)
561 #define G_TLSRX_HDR_PKT_SPP_ERROR(x)     \
562 (((x) >> S_TLSRX_HDR_PKT_SPP_ERROR) & M_TLSRX_HDR_PKT_SPP_ERROR)
563 #define F_TLSRX_HDR_PKT_SPP_ERROR        V_TLSRX_HDR_PKT_SPP_ERROR(1U)
564 
565 #define S_TLSRX_HDR_PKT_CCDX_ERROR       2
566 #define M_TLSRX_HDR_PKT_CCDX_ERROR       0x1
567 #define V_TLSRX_HDR_PKT_CCDX_ERROR(x)    ((x) << S_TLSRX_HDR_PKT_CCDX_ERROR)
568 #define G_TLSRX_HDR_PKT_CCDX_ERROR(x)    \
569 (((x) >> S_TLSRX_HDR_PKT_CCDX_ERROR) & M_TLSRX_HDR_PKT_CCDX_ERROR)
570 #define F_TLSRX_HDR_PKT_CCDX_ERROR       V_TLSRX_HDR_PKT_CCDX_ERROR(1U)
571 
572 #define S_TLSRX_HDR_PKT_PAD_ERROR        1
573 #define M_TLSRX_HDR_PKT_PAD_ERROR        0x1
574 #define V_TLSRX_HDR_PKT_PAD_ERROR(x)     ((x) << S_TLSRX_HDR_PKT_PAD_ERROR)
575 #define G_TLSRX_HDR_PKT_PAD_ERROR(x)     \
576 (((x) >> S_TLSRX_HDR_PKT_PAD_ERROR) & M_TLSRX_HDR_PKT_PAD_ERROR)
577 #define F_TLSRX_HDR_PKT_PAD_ERROR        V_TLSRX_HDR_PKT_PAD_ERROR(1U)
578 
579 #define S_TLSRX_HDR_PKT_MAC_ERROR        0
580 #define M_TLSRX_HDR_PKT_MAC_ERROR        0x1
581 #define V_TLSRX_HDR_PKT_MAC_ERROR(x)     ((x) << S_TLSRX_HDR_PKT_MAC_ERROR)
582 #define G_TLSRX_HDR_PKT_MAC_ERROR(x)     \
583 (((x) >> S_TLSRX_HDR_PKT_MAC_ERROR) & M_TLSRX_HDR_PKT_MAC_ERROR)
584 #define F_TLSRX_HDR_PKT_MAC_ERROR        V_TLSRX_HDR_PKT_MAC_ERROR(1U)
585 
586 #define M_TLSRX_HDR_PKT_ERROR		0x1F
587 
588 #endif /* _KERNEL */
589 
590 #endif /* !__T4_TLS_H__ */
591