1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4  *   Copyright 2016,2020-2021 NXP
5  *
6  */
7 
8 #ifndef _DPAA2_SEC_PMD_PRIVATE_H_
9 #define _DPAA2_SEC_PMD_PRIVATE_H_
10 
11 #ifdef RTE_LIB_SECURITY
12 #include <rte_security_driver.h>
13 #endif
14 
15 #define CRYPTODEV_NAME_DPAA2_SEC_PMD	crypto_dpaa2_sec
16 /**< NXP DPAA2 - SEC PMD device name */
17 
18 extern uint8_t cryptodev_driver_id;
19 
20 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
21 #define FLE_POOL_NUM_BUFS	32000
22 #define FLE_POOL_BUF_SIZE	256
23 #define FLE_POOL_CACHE_SIZE	512
24 #define FLE_SG_MEM_SIZE(num)	(FLE_POOL_BUF_SIZE + ((num) * 32))
25 #define SEC_FLC_DHR_OUTBOUND	-114
26 #define SEC_FLC_DHR_INBOUND	0
27 
28 #define MAX_QUEUES		64
29 #define MAX_DESC_SIZE		64
30 /** private data structure for each DPAA2_SEC device */
31 struct dpaa2_sec_dev_private {
32 	void *mc_portal; /**< MC Portal for configuring this device */
33 	void *hw; /**< Hardware handle for this device.Used by NADK framework */
34 	struct rte_mempool *fle_pool; /* per device memory pool for FLE */
35 	int32_t hw_id; /**< An unique ID of this device instance */
36 	int32_t vfio_fd; /**< File descriptor received via VFIO */
37 	uint16_t token; /**< Token required by DPxxx objects */
38 	unsigned int max_nb_queue_pairs;
39 	/**< Max number of queue pairs supported by device */
40 };
41 
42 struct dpaa2_sec_qp {
43 	struct dpaa2_queue rx_vq;
44 	struct dpaa2_queue tx_vq;
45 };
46 
47 enum shr_desc_type {
48 	DESC_UPDATE,
49 	DESC_FINAL,
50 	DESC_INITFINAL,
51 };
52 
53 #define DIR_ENC                 1
54 #define DIR_DEC                 0
55 
56 #define DPAA2_IPv6_DEFAULT_VTC_FLOW	0x60000000
57 
58 #define DPAA2_SET_FLC_EWS(flc)  (flc->word1_bits23_16 |= 0x1)
59 #define DPAA2_SET_FLC_RSC(flc)  (flc->word1_bits31_24 |= 0x1)
60 #define DPAA2_SET_FLC_REUSE_BS(flc) (flc->mode_bits |= 0x8000)
61 #define DPAA2_SET_FLC_REUSE_FF(flc) (flc->mode_bits |= 0x2000)
62 
63 /* SEC Flow Context Descriptor */
64 struct sec_flow_context {
65 	/* word 0 */
66 	uint16_t word0_sdid;		/* 11-0  SDID */
67 	uint16_t word0_res;		/* 31-12 reserved */
68 
69 	/* word 1 */
70 	uint8_t word1_sdl;		/* 5-0 SDL */
71 					/* 7-6 reserved */
72 
73 	uint8_t word1_bits_15_8;        /* 11-8 CRID */
74 					/* 14-12 reserved */
75 					/* 15 CRJD */
76 
77 	uint8_t word1_bits23_16;	/* 16  EWS */
78 					/* 17 DAC */
79 					/* 18,19,20 ? */
80 					/* 23-21 reserved */
81 
82 	uint8_t word1_bits31_24;	/* 24 RSC */
83 					/* 25 RBMT */
84 					/* 31-26 reserved */
85 
86 	/* word 2  RFLC[31-0] */
87 	uint32_t word2_rflc_31_0;
88 
89 	/* word 3  RFLC[63-32] */
90 	uint32_t word3_rflc_63_32;
91 
92 	/* word 4 */
93 	uint16_t word4_iicid;		/* 15-0  IICID */
94 	uint16_t word4_oicid;		/* 31-16 OICID */
95 
96 	/* word 5 */
97 	uint32_t word5_ofqid:24;		/* 23-0 OFQID */
98 	uint32_t word5_31_24:8;
99 					/* 24 OSC */
100 					/* 25 OBMT */
101 					/* 29-26 reserved */
102 					/* 31-30 ICR */
103 
104 	/* word 6 */
105 	uint32_t word6_oflc_31_0;
106 
107 	/* word 7 */
108 	uint32_t word7_oflc_63_32;
109 
110 	/* Word 8-15 storage profiles */
111 	uint16_t dl;			/**<  DataLength(correction) */
112 	uint16_t reserved;		/**< reserved */
113 	uint16_t dhr;			/**< DataHeadRoom(correction) */
114 	uint16_t mode_bits;		/**< mode bits */
115 	uint16_t bpv0;			/**< buffer pool0 valid */
116 	uint16_t bpid0;			/**< Bypass Memory Translation */
117 	uint16_t bpv1;			/**< buffer pool1 valid */
118 	uint16_t bpid1;			/**< Bypass Memory Translation */
119 	uint64_t word_12_15[2];		/**< word 12-15 are reserved */
120 };
121 
122 struct sec_flc_desc {
123 	struct sec_flow_context flc;
124 	uint32_t desc[MAX_DESC_SIZE];
125 };
126 
127 struct ctxt_priv {
128 	struct rte_mempool *fle_pool; /* per device memory pool for FLE */
129 	struct sec_flc_desc flc_desc[0];
130 };
131 
132 enum dpaa2_sec_op_type {
133 	DPAA2_SEC_NONE,  /*!< No Cipher operations*/
134 	DPAA2_SEC_CIPHER,/*!< CIPHER operations */
135 	DPAA2_SEC_AUTH,  /*!< Authentication Operations */
136 	DPAA2_SEC_AEAD,  /*!< AEAD (AES-GCM/CCM) type operations */
137 	DPAA2_SEC_CIPHER_HASH,  /*!< Authenticated Encryption with
138 				 * associated data
139 				 */
140 	DPAA2_SEC_HASH_CIPHER,  /*!< Encryption with Authenticated
141 				 * associated data
142 				 */
143 	DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
144 	DPAA2_SEC_PDCP,  /*!< PDCP protocol operations*/
145 	DPAA2_SEC_PKC,   /*!< Public Key Cryptographic Operations */
146 	DPAA2_SEC_MAX
147 };
148 
149 struct dpaa2_sec_aead_ctxt {
150 	uint16_t auth_only_len; /*!< Length of data for Auth only */
151 	uint8_t auth_cipher_text;       /**< Authenticate/cipher ordering */
152 };
153 
154 #ifdef RTE_LIB_SECURITY
155 /*
156  * The structure is to be filled by user for PDCP Protocol
157  */
158 struct dpaa2_pdcp_ctxt {
159 	enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
160 	int8_t bearer;	/*!< PDCP bearer ID */
161 	int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
162 	int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
163 	uint8_t sn_size;	/*!< Sequence number size, 5/7/12/15/18 */
164 	uint32_t hfn_ovd_offset;/*!< offset from rte_crypto_op at which
165 				 * per packet hfn is stored
166 				 */
167 	uint32_t hfn;	/*!< Hyper Frame Number */
168 	uint32_t hfn_threshold;	/*!< HFN Threashold for key renegotiation */
169 };
170 #endif
171 
172 typedef int (*dpaa2_sec_build_fd_t)(
173 	void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
174 	uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
175 	struct rte_crypto_va_iova_ptr *iv,
176 	struct rte_crypto_va_iova_ptr *digest,
177 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
178 	void *user_data);
179 
180 typedef int (*dpaa2_sec_build_raw_dp_fd_t)(uint8_t *drv_ctx,
181 		       struct rte_crypto_sgl *sgl,
182 		       struct rte_crypto_sgl *dest_sgl,
183 		       struct rte_crypto_va_iova_ptr *iv,
184 		       struct rte_crypto_va_iova_ptr *digest,
185 		       struct rte_crypto_va_iova_ptr *auth_iv,
186 		       union rte_crypto_sym_ofs ofs,
187 		       void *userdata,
188 		       struct qbman_fd *fd);
189 
190 typedef struct dpaa2_sec_session_entry {
191 	void *ctxt;
192 	uint8_t ctxt_type;
193 	uint8_t dir;         /*!< Operation Direction */
194 	enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
195 	enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
196 	enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
197 	dpaa2_sec_build_fd_t build_fd;
198 	dpaa2_sec_build_raw_dp_fd_t build_raw_dp_fd;
199 	union {
200 		struct {
201 			uint8_t *data;	/**< pointer to key data */
202 			size_t length;	/**< key length in bytes */
203 		} aead_key;
204 		struct {
205 			struct {
206 				uint8_t *data;	/**< pointer to key data */
207 				size_t length;	/**< key length in bytes */
208 			} cipher_key;
209 			struct {
210 				uint8_t *data;	/**< pointer to key data */
211 				size_t length;	/**< key length in bytes */
212 			} auth_key;
213 		};
214 	};
215 	union {
216 		struct {
217 			struct {
218 				uint16_t length; /**< IV length in bytes */
219 				uint16_t offset; /**< IV offset in bytes */
220 			} iv;
221 			uint16_t digest_length;
222 			uint8_t status;
223 			union {
224 				struct dpaa2_sec_aead_ctxt aead_ctxt;
225 			} ext_params;
226 		};
227 #ifdef RTE_LIB_SECURITY
228 		struct dpaa2_pdcp_ctxt pdcp;
229 #endif
230 	};
231 } dpaa2_sec_session;
232 
233 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
234 	/* Symmetric capabilities */
235 	{	/* MD5 */
236 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
237 		{.sym = {
238 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
239 			{.auth = {
240 				.algo = RTE_CRYPTO_AUTH_MD5,
241 				.block_size = 64,
242 				.key_size = {
243 					.min = 0,
244 					.max = 0,
245 					.increment = 0
246 				},
247 				.digest_size = {
248 					.min = 16,
249 					.max = 16,
250 					.increment = 0
251 				},
252 				.iv_size = { 0 }
253 			}, }
254 		}, }
255 	},
256 	{	/* MD5 HMAC */
257 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
258 		{.sym = {
259 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
260 			{.auth = {
261 				.algo = RTE_CRYPTO_AUTH_MD5_HMAC,
262 				.block_size = 64,
263 				.key_size = {
264 					.min = 1,
265 					.max = 64,
266 					.increment = 1
267 				},
268 				.digest_size = {
269 					.min = 1,
270 					.max = 16,
271 					.increment = 1
272 				},
273 				.iv_size = { 0 }
274 			}, }
275 		}, }
276 	},
277 	{	/* SHA1 */
278 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
279 		{.sym = {
280 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
281 			{.auth = {
282 				.algo = RTE_CRYPTO_AUTH_SHA1,
283 				.block_size = 64,
284 				.key_size = {
285 					.min = 0,
286 					.max = 0,
287 					.increment = 0
288 				},
289 				.digest_size = {
290 					.min = 20,
291 					.max = 20,
292 					.increment = 0
293 				},
294 				.iv_size = { 0 }
295 			}, }
296 		}, }
297 	},
298 	{	/* SHA1 HMAC */
299 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
300 		{.sym = {
301 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
302 			{.auth = {
303 				.algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
304 				.block_size = 64,
305 				.key_size = {
306 					.min = 1,
307 					.max = 64,
308 					.increment = 1
309 				},
310 				.digest_size = {
311 					.min = 1,
312 					.max = 20,
313 					.increment = 1
314 				},
315 				.iv_size = { 0 }
316 			}, }
317 		}, }
318 	},
319 	{	/* SHA224 */
320 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
321 		{.sym = {
322 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
323 			{.auth = {
324 				.algo = RTE_CRYPTO_AUTH_SHA224,
325 				.block_size = 64,
326 					.key_size = {
327 					.min = 0,
328 					.max = 0,
329 					.increment = 0
330 				},
331 				.digest_size = {
332 					.min = 28,
333 					.max = 28,
334 					.increment = 0
335 				},
336 				.iv_size = { 0 }
337 			}, }
338 		}, }
339 	},
340 	{	/* SHA224 HMAC */
341 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
342 		{.sym = {
343 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
344 			{.auth = {
345 				.algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
346 				.block_size = 64,
347 				.key_size = {
348 					.min = 1,
349 					.max = 64,
350 					.increment = 1
351 				},
352 				.digest_size = {
353 					.min = 1,
354 					.max = 28,
355 					.increment = 1
356 				},
357 				.iv_size = { 0 }
358 			}, }
359 		}, }
360 	},
361 	{	/* SHA256 */
362 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
363 		{.sym = {
364 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
365 			{.auth = {
366 				.algo = RTE_CRYPTO_AUTH_SHA256,
367 				.block_size = 64,
368 				.key_size = {
369 					.min = 0,
370 					.max = 0,
371 					.increment = 0
372 				},
373 				.digest_size = {
374 					.min = 32,
375 					.max = 32,
376 					.increment = 0
377 				},
378 				.iv_size = { 0 }
379 			}, }
380 		}, }
381 	},
382 	{	/* SHA256 HMAC */
383 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
384 		{.sym = {
385 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
386 			{.auth = {
387 				.algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
388 				.block_size = 64,
389 				.key_size = {
390 					.min = 1,
391 					.max = 64,
392 					.increment = 1
393 				},
394 				.digest_size = {
395 					.min = 1,
396 					.max = 32,
397 					.increment = 1
398 				},
399 				.iv_size = { 0 }
400 			}, }
401 		}, }
402 	},
403 	{	/* SHA384 */
404 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
405 		{.sym = {
406 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
407 			{.auth = {
408 				.algo = RTE_CRYPTO_AUTH_SHA384,
409 				.block_size = 64,
410 				.key_size = {
411 					.min = 0,
412 					.max = 0,
413 					.increment = 0
414 				},
415 				.digest_size = {
416 					.min = 48,
417 					.max = 48,
418 					.increment = 0
419 					},
420 				.iv_size = { 0 }
421 			}, }
422 		}, }
423 	},
424 	{	/* SHA384 HMAC */
425 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
426 		{.sym = {
427 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
428 			{.auth = {
429 				.algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
430 				.block_size = 128,
431 				.key_size = {
432 					.min = 1,
433 					.max = 128,
434 					.increment = 1
435 				},
436 				.digest_size = {
437 					.min = 1,
438 					.max = 48,
439 					.increment = 1
440 				},
441 				.iv_size = { 0 }
442 			}, }
443 		}, }
444 	},
445 	{	/* SHA512 */
446 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
447 		{.sym = {
448 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
449 			{.auth = {
450 				.algo = RTE_CRYPTO_AUTH_SHA512,
451 				.block_size = 128,
452 				.key_size = {
453 					.min = 0,
454 					.max = 0,
455 					.increment = 0
456 				},
457 				.digest_size = {
458 					.min = 64,
459 					.max = 64,
460 					.increment = 0
461 				},
462 				.iv_size = { 0 }
463 			}, }
464 		}, }
465 	},
466 	{	/* SHA512 HMAC */
467 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
468 		{.sym = {
469 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
470 			{.auth = {
471 				.algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
472 				.block_size = 128,
473 				.key_size = {
474 					.min = 1,
475 					.max = 128,
476 					.increment = 1
477 				},
478 				.digest_size = {
479 					.min = 1,
480 					.max = 64,
481 					.increment = 1
482 				},
483 				.iv_size = { 0 }
484 			}, }
485 		}, }
486 	},
487 	{	/* AES GCM */
488 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
489 		{.sym = {
490 			.xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
491 			{.aead = {
492 				.algo = RTE_CRYPTO_AEAD_AES_GCM,
493 				.block_size = 16,
494 				.key_size = {
495 					.min = 16,
496 					.max = 32,
497 					.increment = 8
498 				},
499 				.digest_size = {
500 					.min = 8,
501 					.max = 16,
502 					.increment = 4
503 				},
504 				.aad_size = {
505 					.min = 0,
506 					.max = 240,
507 					.increment = 1
508 				},
509 				.iv_size = {
510 					.min = 12,
511 					.max = 12,
512 					.increment = 0
513 				},
514 			}, }
515 		}, }
516 	},
517 	{	/* AES XCBC HMAC */
518 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
519 		{.sym = {
520 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
521 			{.auth = {
522 				.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
523 				.block_size = 16,
524 				.key_size = {
525 					.min = 1,
526 					.max = 16,
527 					.increment = 1
528 				},
529 				.digest_size = {
530 					.min = 12,
531 					.max = 16,
532 					.increment = 4
533 				},
534 				.aad_size = { 0 },
535 				.iv_size = { 0 }
536 			}, }
537 		}, }
538 	},
539 	{	/* AES CMAC */
540 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
541 		{.sym = {
542 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
543 			{.auth = {
544 				.algo = RTE_CRYPTO_AUTH_AES_CMAC,
545 				.block_size = 16,
546 				.key_size = {
547 					.min = 1,
548 					.max = 16,
549 					.increment = 1
550 				},
551 				.digest_size = {
552 					.min = 4,
553 					.max = 16,
554 					.increment = 4
555 				},
556 				.aad_size = { 0 }
557 			}, }
558 		}, }
559 	},
560 	{	/* AES CBC */
561 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
562 		{.sym = {
563 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
564 			{.cipher = {
565 				.algo = RTE_CRYPTO_CIPHER_AES_CBC,
566 				.block_size = 16,
567 				.key_size = {
568 					.min = 16,
569 					.max = 32,
570 					.increment = 8
571 				},
572 				.iv_size = {
573 					.min = 16,
574 					.max = 16,
575 					.increment = 0
576 				}
577 			}, }
578 		}, }
579 	},
580 	{	/* AES CTR */
581 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
582 		{.sym = {
583 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
584 			{.cipher = {
585 				.algo = RTE_CRYPTO_CIPHER_AES_CTR,
586 				.block_size = 16,
587 				.key_size = {
588 					.min = 16,
589 					.max = 32,
590 					.increment = 8
591 				},
592 				.iv_size = {
593 					.min = 16,
594 					.max = 16,
595 					.increment = 0
596 				},
597 			}, }
598 		}, }
599 	},
600 	{	/* DES CBC */
601 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
602 		{.sym = {
603 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
604 			{.cipher = {
605 				.algo = RTE_CRYPTO_CIPHER_DES_CBC,
606 				.block_size = 8,
607 				.key_size = {
608 					.min = 8,
609 					.max = 8,
610 					.increment = 0
611 				},
612 				.iv_size = {
613 					.min = 8,
614 					.max = 8,
615 					.increment = 0
616 				}
617 			}, }
618 		}, }
619 	},
620 	{	/* 3DES CBC */
621 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
622 		{.sym = {
623 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
624 			{.cipher = {
625 				.algo = RTE_CRYPTO_CIPHER_3DES_CBC,
626 				.block_size = 8,
627 				.key_size = {
628 					.min = 16,
629 					.max = 24,
630 					.increment = 8
631 				},
632 				.iv_size = {
633 					.min = 8,
634 					.max = 8,
635 					.increment = 0
636 				}
637 			}, }
638 		}, }
639 	},
640 	{	/* SNOW 3G (UIA2) */
641 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
642 		{.sym = {
643 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
644 			{.auth = {
645 				.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
646 				.block_size = 16,
647 				.key_size = {
648 					.min = 16,
649 					.max = 16,
650 					.increment = 0
651 				},
652 				.digest_size = {
653 					.min = 4,
654 					.max = 4,
655 					.increment = 0
656 				},
657 				.iv_size = {
658 					.min = 16,
659 					.max = 16,
660 					.increment = 0
661 				}
662 			}, }
663 		}, }
664 	},
665 	{	/* SNOW 3G (UEA2) */
666 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
667 		{.sym = {
668 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
669 			{.cipher = {
670 				.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
671 				.block_size = 16,
672 				.key_size = {
673 					.min = 16,
674 					.max = 16,
675 					.increment = 0
676 				},
677 				.iv_size = {
678 					.min = 16,
679 					.max = 16,
680 					.increment = 0
681 				}
682 			}, }
683 		}, }
684 	},
685 	{	/* ZUC (EEA3) */
686 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
687 		{.sym = {
688 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
689 			{.cipher = {
690 				.algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
691 				.block_size = 16,
692 				.key_size = {
693 					.min = 16,
694 					.max = 16,
695 					.increment = 0
696 				},
697 				.iv_size = {
698 					.min = 16,
699 					.max = 16,
700 					.increment = 0
701 				}
702 			}, }
703 		}, }
704 	},
705 	{	/* ZUC (EIA3) */
706 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
707 		{.sym = {
708 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
709 			{.auth = {
710 				.algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
711 				.block_size = 16,
712 				.key_size = {
713 					.min = 16,
714 					.max = 16,
715 					.increment = 0
716 				},
717 				.digest_size = {
718 					.min = 4,
719 					.max = 4,
720 					.increment = 0
721 				},
722 				.iv_size = {
723 					.min = 16,
724 					.max = 16,
725 					.increment = 0
726 				}
727 			}, }
728 		}, }
729 	},
730 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
731 };
732 
733 #ifdef RTE_LIB_SECURITY
734 
735 static const struct rte_cryptodev_capabilities dpaa2_pdcp_capabilities[] = {
736 	{	/* SNOW 3G (UIA2) */
737 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
738 		{.sym = {
739 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
740 			{.auth = {
741 				.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
742 				.block_size = 16,
743 				.key_size = {
744 					.min = 16,
745 					.max = 16,
746 					.increment = 0
747 				},
748 				.digest_size = {
749 					.min = 4,
750 					.max = 4,
751 					.increment = 0
752 				},
753 				.iv_size = {
754 					.min = 16,
755 					.max = 16,
756 					.increment = 0
757 				}
758 			}, }
759 		}, }
760 	},
761 	{	/* SNOW 3G (UEA2) */
762 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
763 		{.sym = {
764 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
765 			{.cipher = {
766 				.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
767 				.block_size = 16,
768 				.key_size = {
769 					.min = 16,
770 					.max = 16,
771 					.increment = 0
772 				},
773 				.iv_size = {
774 					.min = 16,
775 					.max = 16,
776 					.increment = 0
777 				}
778 			}, }
779 		}, }
780 	},
781 	{	/* AES CTR */
782 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
783 		{.sym = {
784 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
785 			{.cipher = {
786 				.algo = RTE_CRYPTO_CIPHER_AES_CTR,
787 				.block_size = 16,
788 				.key_size = {
789 					.min = 16,
790 					.max = 32,
791 					.increment = 8
792 				},
793 				.iv_size = {
794 					.min = 16,
795 					.max = 16,
796 					.increment = 0
797 				}
798 			}, }
799 		}, }
800 	},
801 	{	/* NULL (AUTH) */
802 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
803 		{.sym = {
804 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
805 			{.auth = {
806 				.algo = RTE_CRYPTO_AUTH_NULL,
807 				.block_size = 1,
808 				.key_size = {
809 					.min = 0,
810 					.max = 0,
811 					.increment = 0
812 				},
813 				.digest_size = {
814 					.min = 0,
815 					.max = 0,
816 					.increment = 0
817 				},
818 				.iv_size = { 0 }
819 			}, },
820 		}, },
821 	},
822 	{	/* NULL (CIPHER) */
823 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
824 		{.sym = {
825 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
826 			{.cipher = {
827 				.algo = RTE_CRYPTO_CIPHER_NULL,
828 				.block_size = 1,
829 				.key_size = {
830 					.min = 0,
831 					.max = 0,
832 					.increment = 0
833 				},
834 				.iv_size = {
835 					.min = 0,
836 					.max = 0,
837 					.increment = 0
838 				}
839 			}, },
840 		}, }
841 	},
842 	{	/* ZUC (EEA3) */
843 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
844 		{.sym = {
845 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
846 			{.cipher = {
847 				.algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
848 				.block_size = 16,
849 				.key_size = {
850 					.min = 16,
851 					.max = 16,
852 					.increment = 0
853 				},
854 				.iv_size = {
855 					.min = 16,
856 					.max = 16,
857 					.increment = 0
858 				}
859 			}, }
860 		}, }
861 	},
862 	{	/* ZUC (EIA3) */
863 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
864 		{.sym = {
865 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
866 			{.auth = {
867 				.algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
868 				.block_size = 16,
869 				.key_size = {
870 					.min = 16,
871 					.max = 16,
872 					.increment = 0
873 				},
874 				.digest_size = {
875 					.min = 4,
876 					.max = 4,
877 					.increment = 0
878 				},
879 				.iv_size = {
880 					.min = 16,
881 					.max = 16,
882 					.increment = 0
883 				}
884 			}, }
885 		}, }
886 	},
887 
888 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
889 };
890 
891 static const struct rte_security_capability dpaa2_sec_security_cap[] = {
892 	{ /* IPsec Lookaside Protocol offload ESP Transport Egress */
893 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
894 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
895 		.ipsec = {
896 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
897 			.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
898 			.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
899 			.options = { 0 },
900 			.replay_win_sz_max = 128
901 		},
902 		.crypto_capabilities = dpaa2_sec_capabilities
903 	},
904 	{ /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
905 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
906 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
907 		.ipsec = {
908 			.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
909 			.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
910 			.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
911 			.options = { 0 },
912 			.replay_win_sz_max = 128
913 		},
914 		.crypto_capabilities = dpaa2_sec_capabilities
915 	},
916 	{ /* PDCP Lookaside Protocol offload Data */
917 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
918 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
919 		.pdcp = {
920 			.domain = RTE_SECURITY_PDCP_MODE_DATA,
921 			.capa_flags = 0
922 		},
923 		.crypto_capabilities = dpaa2_pdcp_capabilities
924 	},
925 	{ /* PDCP Lookaside Protocol offload Control */
926 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
927 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
928 		.pdcp = {
929 			.domain = RTE_SECURITY_PDCP_MODE_CONTROL,
930 			.capa_flags = 0
931 		},
932 		.crypto_capabilities = dpaa2_pdcp_capabilities
933 	},
934 	{ /* PDCP Lookaside Protocol offload Short MAC */
935 		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
936 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
937 		.pdcp = {
938 			.domain = RTE_SECURITY_PDCP_MODE_SHORT_MAC,
939 			.capa_flags = 0
940 		},
941 		.crypto_capabilities = dpaa2_pdcp_capabilities
942 	},
943 	{
944 		.action = RTE_SECURITY_ACTION_TYPE_NONE
945 	}
946 };
947 #endif
948 /**
949  * Checksum
950  *
951  * @param buffer calculate chksum for buffer
952  * @param len    buffer length
953  *
954  * @return checksum value in host cpu order
955  */
956 static inline uint16_t
957 calc_chksum(void *buffer, int len)
958 {
959 	uint16_t *buf = (uint16_t *)buffer;
960 	uint32_t sum = 0;
961 	uint16_t result;
962 
963 	for (sum = 0; len > 1; len -= 2)
964 		sum += *buf++;
965 
966 	if (len == 1)
967 		sum += *(unsigned char *)buf;
968 
969 	sum = (sum >> 16) + (sum & 0xFFFF);
970 	sum += (sum >> 16);
971 	result = ~sum;
972 
973 	return  result;
974 }
975 
976 int
977 dpaa2_sec_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
978 	struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
979 	enum rte_crypto_op_sess_type sess_type,
980 	union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
981 
982 int
983 dpaa2_sec_get_dp_ctx_size(struct rte_cryptodev *dev);
984 
985 
986 #endif /* _DPAA2_SEC_PMD_PRIVATE_H_ */
987