1 /* SPDX-License-Identifier: BSD-3-Clause
10 #define CRYPTODEV_NAME_DPAA_SEC_PMD crypto_dpaa_sec
11 /**< NXP DPAA - SEC PMD device name */
13 #define MAX_DPAA_CORES 4
14 #define NUM_POOL_CHANNELS 4
15 #define DPAA_SEC_BURST 7
16 #define DPAA_SEC_ALG_UNSUPPORT (-1)
17 #define TDES_CBC_IV_LEN 8
18 #define AES_CBC_IV_LEN 16
19 #define AES_CTR_IV_LEN 16
20 #define AES_GCM_IV_LEN 12
22 #define DPAA_IPv6_DEFAULT_VTC_FLOW 0x60000000
24 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
25 * a pointer to the shared descriptor.
27 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
28 /* CTX_POOL_NUM_BUFS is set as per the ipsec-secgw application */
29 #define CTX_POOL_NUM_BUFS 32000
30 #define CTX_POOL_BUF_SIZE sizeof(struct dpaa_sec_op_ctx)
31 #define CTX_POOL_CACHE_SIZE 512
32 #define RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS 1024
37 enum dpaa_sec_op_type {
38 DPAA_SEC_NONE, /*!< No Cipher operations*/
39 DPAA_SEC_CIPHER,/*!< CIPHER operations */
40 DPAA_SEC_AUTH, /*!< Authentication Operations */
41 DPAA_SEC_AEAD, /*!< AEAD (AES-GCM/CCM) type operations */
42 DPAA_SEC_CIPHER_HASH, /*!< Authenticated Encryption with
45 DPAA_SEC_HASH_CIPHER, /*!< Encryption with Authenticated
48 DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
49 DPAA_SEC_PDCP, /*!< PDCP protocol operations*/
50 DPAA_SEC_PKC, /*!< Public Key Cryptographic Operations */
54 #define DPAA_SEC_MAX_DESC_SIZE 64
55 /* code or cmd block to caam */
61 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
63 unsigned int rsvd47_39:9;
67 unsigned int rsvd47_39:9;
76 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
77 unsigned int rsvd31_30:2;
80 unsigned int offset:2;
82 unsigned int add_buf:1;
84 uint16_t pool_buffer_size;
86 uint16_t pool_buffer_size;
88 unsigned int add_buf:1;
90 unsigned int offset:2;
93 unsigned int rsvd31_30:2;
99 uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
101 #ifdef RTE_LIBRTE_SECURITY
103 * The structure is to be filled by user as a part of
104 * dpaa_sec_proto_ctxt for PDCP Protocol
106 struct sec_pdcp_ctxt {
107 enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
108 int8_t bearer; /*!< PDCP bearer ID */
109 int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
110 int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
111 uint8_t sn_size; /*!< Sequence number size, 5/7/12/15/18 */
112 uint32_t hfn_ovd_offset;/*!< offset from rte_crypto_op at which
113 * per packet hfn is stored
115 uint32_t hfn; /*!< Hyper Frame Number */
116 uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
119 typedef struct dpaa_sec_session_entry {
120 uint8_t dir; /*!< Operation Direction */
121 uint8_t ctxt; /*!< Session Context Type */
122 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
123 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
124 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
125 #ifdef RTE_LIBRTE_SECURITY
126 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
130 uint8_t *data; /**< pointer to key data */
131 size_t length; /**< key length in bytes */
137 uint8_t *data; /**< pointer to key data */
138 size_t length; /**< key length in bytes */
143 uint8_t *data; /**< pointer to key data */
144 size_t length; /**< key length in bytes */
155 } iv; /**< Initialisation vector parameters */
156 uint16_t auth_only_len;
157 /*!< Length of data for Auth only */
158 uint32_t digest_length;
159 struct ipsec_decap_pdb decap_pdb;
160 struct ipsec_encap_pdb encap_pdb;
163 struct rte_ipv6_hdr ip6_hdr;
165 uint8_t auth_cipher_text;
166 /**< Authenticate/cipher ordering */
168 #ifdef RTE_LIBRTE_SECURITY
169 struct sec_pdcp_ctxt pdcp;
172 struct dpaa_sec_qp *qp[MAX_DPAA_CORES];
173 struct qman_fq *inq[MAX_DPAA_CORES];
174 struct sec_cdb cdb; /**< cmd block associated with qp */
178 struct dpaa_sec_dev_private *internals;
179 struct rte_mempool *ctx_pool; /* mempool for dpaa_sec_op_ctx */
187 #define RTE_DPAA_MAX_NB_SEC_QPS 2
188 #define RTE_DPAA_MAX_RX_QUEUE (MAX_DPAA_CORES * RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS)
189 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
191 /* internal sec queue interface */
192 struct dpaa_sec_dev_private {
194 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
195 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
196 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
197 unsigned int max_nb_queue_pairs;
198 unsigned int max_nb_sessions;
202 #define MAX_SG_ENTRIES 16
203 #define MAX_JOB_SG_ENTRIES 36
205 struct dpaa_sec_job {
206 /* sg[0] output, sg[1] input, others are possible sub frames */
207 struct qm_sg_entry sg[MAX_JOB_SG_ENTRIES];
210 #define DPAA_MAX_NB_MAX_DIGEST 32
211 struct dpaa_sec_op_ctx {
212 struct dpaa_sec_job job;
213 struct rte_crypto_op *op;
214 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
217 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
220 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
222 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
224 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
226 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
243 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
245 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
247 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
264 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
266 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
268 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
285 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
287 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
289 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
306 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
308 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
310 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
327 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
329 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
331 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
348 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
350 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
352 .algo = RTE_CRYPTO_AEAD_AES_GCM,
378 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
380 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
382 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
398 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
400 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
402 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
418 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
420 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
422 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
437 { /* SNOW 3G (UIA2) */
438 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
440 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
442 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
462 { /* SNOW 3G (UEA2) */
463 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
465 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
467 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
483 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
485 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
487 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
503 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
505 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
507 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
527 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
530 #ifdef RTE_LIBRTE_SECURITY
531 static const struct rte_cryptodev_capabilities dpaa_pdcp_capabilities[] = {
532 { /* SNOW 3G (UIA2) */
533 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
535 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
537 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
557 { /* SNOW 3G (UEA2) */
558 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
560 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
562 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
578 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
580 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
582 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
598 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
600 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
602 .algo = RTE_CRYPTO_AUTH_NULL,
618 { /* NULL (CIPHER) */
619 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
621 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
623 .algo = RTE_CRYPTO_CIPHER_NULL,
639 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
641 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
643 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
659 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
661 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
663 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
684 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
687 static const struct rte_security_capability dpaa_sec_security_cap[] = {
688 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
689 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
690 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
692 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
693 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
694 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
697 .crypto_capabilities = dpaa_sec_capabilities
699 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
700 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
701 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
703 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
704 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
705 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
708 .crypto_capabilities = dpaa_sec_capabilities
710 { /* PDCP Lookaside Protocol offload Data */
711 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
712 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
714 .domain = RTE_SECURITY_PDCP_MODE_DATA,
716 .crypto_capabilities = dpaa_pdcp_capabilities
718 { /* PDCP Lookaside Protocol offload Control */
719 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
720 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
722 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
724 .crypto_capabilities = dpaa_pdcp_capabilities
727 .action = RTE_SECURITY_ACTION_TYPE_NONE
735 * @param buffer calculate chksum for buffer
736 * @param len buffer length
738 * @return checksum value in host cpu order
740 static inline uint16_t
741 calc_chksum(void *buffer, int len)
743 uint16_t *buf = (uint16_t *)buffer;
747 for (sum = 0; len > 1; len -= 2)
751 sum += *(unsigned char *)buf;
753 sum = (sum >> 16) + (sum & 0xFFFF);
760 #endif /* _DPAA_SEC_H_ */