1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
8 #ifndef _RTE_DPAA2_SEC_PMD_PRIVATE_H_
9 #define _RTE_DPAA2_SEC_PMD_PRIVATE_H_
11 #include <rte_security_driver.h>
13 #define CRYPTODEV_NAME_DPAA2_SEC_PMD crypto_dpaa2_sec
14 /**< NXP DPAA2 - SEC PMD device name */
17 #define MAX_DESC_SIZE 64
18 /** private data structure for each DPAA2_SEC device */
19 struct dpaa2_sec_dev_private {
20 void *mc_portal; /**< MC Portal for configuring this device */
21 void *hw; /**< Hardware handle for this device.Used by NADK framework */
22 struct rte_mempool *fle_pool; /* per device memory pool for FLE */
23 int32_t hw_id; /**< An unique ID of this device instance */
24 int32_t vfio_fd; /**< File descriptor received via VFIO */
25 uint16_t token; /**< Token required by DPxxx objects */
26 unsigned int max_nb_queue_pairs;
27 /**< Max number of queue pairs supported by device */
31 struct dpaa2_queue rx_vq;
32 struct dpaa2_queue tx_vq;
44 #define DPAA2_SET_FLC_EWS(flc) (flc->word1_bits23_16 |= 0x1)
45 #define DPAA2_SET_FLC_RSC(flc) (flc->word1_bits31_24 |= 0x1)
46 #define DPAA2_SET_FLC_REUSE_BS(flc) (flc->mode_bits |= 0x8000)
47 #define DPAA2_SET_FLC_REUSE_FF(flc) (flc->mode_bits |= 0x2000)
49 /* SEC Flow Context Descriptor */
50 struct sec_flow_context {
52 uint16_t word0_sdid; /* 11-0 SDID */
53 uint16_t word0_res; /* 31-12 reserved */
56 uint8_t word1_sdl; /* 5-0 SDL */
59 uint8_t word1_bits_15_8; /* 11-8 CRID */
63 uint8_t word1_bits23_16; /* 16 EWS */
68 uint8_t word1_bits31_24; /* 24 RSC */
72 /* word 2 RFLC[31-0] */
73 uint32_t word2_rflc_31_0;
75 /* word 3 RFLC[63-32] */
76 uint32_t word3_rflc_63_32;
79 uint16_t word4_iicid; /* 15-0 IICID */
80 uint16_t word4_oicid; /* 31-16 OICID */
83 uint32_t word5_ofqid:24; /* 23-0 OFQID */
84 uint32_t word5_31_24:8;
91 uint32_t word6_oflc_31_0;
94 uint32_t word7_oflc_63_32;
96 /* Word 8-15 storage profiles */
97 uint16_t dl; /**< DataLength(correction) */
98 uint16_t reserved; /**< reserved */
99 uint16_t dhr; /**< DataHeadRoom(correction) */
100 uint16_t mode_bits; /**< mode bits */
101 uint16_t bpv0; /**< buffer pool0 valid */
102 uint16_t bpid0; /**< Bypass Memory Translation */
103 uint16_t bpv1; /**< buffer pool1 valid */
104 uint16_t bpid1; /**< Bypass Memory Translation */
105 uint64_t word_12_15[2]; /**< word 12-15 are reserved */
108 struct sec_flc_desc {
109 struct sec_flow_context flc;
110 uint32_t desc[MAX_DESC_SIZE];
114 struct rte_mempool *fle_pool; /* per device memory pool for FLE */
115 struct sec_flc_desc flc_desc[0];
118 enum dpaa2_sec_op_type {
119 DPAA2_SEC_NONE, /*!< No Cipher operations*/
120 DPAA2_SEC_CIPHER,/*!< CIPHER operations */
121 DPAA2_SEC_AUTH, /*!< Authentication Operations */
122 DPAA2_SEC_AEAD, /*!< AEAD (AES-GCM/CCM) type operations */
123 DPAA2_SEC_CIPHER_HASH, /*!< Authenticated Encryption with
126 DPAA2_SEC_HASH_CIPHER, /*!< Encryption with Authenticated
129 DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
130 DPAA2_SEC_PDCP, /*!< PDCP protocol operations*/
131 DPAA2_SEC_PKC, /*!< Public Key Cryptographic Operations */
135 struct dpaa2_sec_aead_ctxt {
136 uint16_t auth_only_len; /*!< Length of data for Auth only */
137 uint8_t auth_cipher_text; /**< Authenticate/cipher ordering */
141 * The structure is to be filled by user for PDCP Protocol
143 struct dpaa2_pdcp_ctxt {
144 enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
145 int8_t bearer; /*!< PDCP bearer ID */
146 int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
147 int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
148 uint32_t hfn; /*!< Hyper Frame Number */
149 uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
150 uint8_t sn_size; /*!< Sequence number size, 7/12/15 */
153 typedef struct dpaa2_sec_session_entry {
156 uint8_t dir; /*!< Operation Direction */
157 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
158 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
159 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
162 uint8_t *data; /**< pointer to key data */
163 size_t length; /**< key length in bytes */
167 uint8_t *data; /**< pointer to key data */
168 size_t length; /**< key length in bytes */
171 uint8_t *data; /**< pointer to key data */
172 size_t length; /**< key length in bytes */
179 uint16_t length; /**< IV length in bytes */
180 uint16_t offset; /**< IV offset in bytes */
182 uint16_t digest_length;
185 struct dpaa2_sec_aead_ctxt aead_ctxt;
188 struct dpaa2_pdcp_ctxt pdcp;
192 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
194 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
196 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
198 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
215 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
217 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
219 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
236 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
238 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
240 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
257 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
259 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
261 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
278 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
280 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
282 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
299 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
301 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
303 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
320 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
322 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
324 .algo = RTE_CRYPTO_AEAD_AES_GCM,
350 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
352 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
354 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
370 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
372 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
374 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
390 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
392 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
394 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
410 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
413 static const struct rte_cryptodev_capabilities dpaa2_pdcp_capabilities[] = {
414 { /* SNOW 3G (UIA2) */
415 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
417 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
419 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
439 { /* SNOW 3G (UEA2) */
440 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
442 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
444 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
460 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
462 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
464 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
480 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
482 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
484 .algo = RTE_CRYPTO_AUTH_NULL,
500 { /* NULL (CIPHER) */
501 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
503 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
505 .algo = RTE_CRYPTO_CIPHER_NULL,
521 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
523 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
525 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
541 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
543 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
545 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
566 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
569 static const struct rte_security_capability dpaa2_sec_security_cap[] = {
570 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
571 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
572 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
574 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
575 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
576 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
579 .crypto_capabilities = dpaa2_sec_capabilities
581 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
582 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
583 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
585 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
586 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
587 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
590 .crypto_capabilities = dpaa2_sec_capabilities
592 { /* PDCP Lookaside Protocol offload Data */
593 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
594 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
596 .domain = RTE_SECURITY_PDCP_MODE_DATA,
599 .crypto_capabilities = dpaa2_pdcp_capabilities
601 { /* PDCP Lookaside Protocol offload Control */
602 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
603 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
605 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
608 .crypto_capabilities = dpaa2_pdcp_capabilities
611 .action = RTE_SECURITY_ACTION_TYPE_NONE
618 * @param buffer calculate chksum for buffer
619 * @param len buffer length
621 * @return checksum value in host cpu order
623 static inline uint16_t
624 calc_chksum(void *buffer, int len)
626 uint16_t *buf = (uint16_t *)buffer;
630 for (sum = 0; len > 1; len -= 2)
634 sum += *(unsigned char *)buf;
636 sum = (sum >> 16) + (sum & 0xFFFF);
643 #endif /* _RTE_DPAA2_SEC_PMD_PRIVATE_H_ */