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, /*!< Authenticated Encryption with associated data */
42 DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
43 DPAA_SEC_PDCP, /*!< PDCP protocol operations*/
44 DPAA_SEC_PKC, /*!< Public Key Cryptographic Operations */
49 #define DPAA_SEC_MAX_DESC_SIZE 64
50 /* code or cmd block to caam */
56 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
58 unsigned int rsvd47_39:9;
62 unsigned int rsvd47_39:9;
71 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
72 unsigned int rsvd31_30:2;
75 unsigned int offset:2;
77 unsigned int add_buf:1;
79 uint16_t pool_buffer_size;
81 uint16_t pool_buffer_size;
83 unsigned int add_buf:1;
85 unsigned int offset:2;
88 unsigned int rsvd31_30:2;
94 uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
98 * The structure is to be filled by user as a part of
99 * dpaa_sec_proto_ctxt for PDCP Protocol
101 struct sec_pdcp_ctxt {
102 enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
103 int8_t bearer; /*!< PDCP bearer ID */
104 int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
105 int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
106 uint8_t sn_size; /*!< Sequence number size, 5/7/12/15/18 */
107 uint32_t hfn_ovd_offset;/*!< offset from rte_crypto_op at which
108 * per packet hfn is stored
110 uint32_t hfn; /*!< Hyper Frame Number */
111 uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
114 typedef struct dpaa_sec_session_entry {
115 uint8_t dir; /*!< Operation Direction */
116 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
117 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
118 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
119 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
122 uint8_t *data; /**< pointer to key data */
123 size_t length; /**< key length in bytes */
127 uint8_t *data; /**< pointer to key data */
128 size_t length; /**< key length in bytes */
131 uint8_t *data; /**< pointer to key data */
132 size_t length; /**< key length in bytes */
141 } iv; /**< Initialisation vector parameters */
142 uint16_t auth_only_len;
143 /*!< Length of data for Auth only */
144 uint32_t digest_length;
145 struct ipsec_decap_pdb decap_pdb;
146 struct ipsec_encap_pdb encap_pdb;
149 struct rte_ipv6_hdr ip6_hdr;
152 struct sec_pdcp_ctxt pdcp;
154 struct dpaa_sec_qp *qp[MAX_DPAA_CORES];
155 struct qman_fq *inq[MAX_DPAA_CORES];
156 struct sec_cdb cdb; /**< cmd block associated with qp */
160 struct dpaa_sec_dev_private *internals;
161 struct rte_mempool *ctx_pool; /* mempool for dpaa_sec_op_ctx */
169 #define RTE_DPAA_MAX_NB_SEC_QPS 2
170 #define RTE_DPAA_MAX_RX_QUEUE (MAX_DPAA_CORES * RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS)
171 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
173 /* internal sec queue interface */
174 struct dpaa_sec_dev_private {
176 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
177 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
178 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
179 unsigned int max_nb_queue_pairs;
180 unsigned int max_nb_sessions;
184 #define MAX_SG_ENTRIES 16
185 #define MAX_JOB_SG_ENTRIES 36
187 struct dpaa_sec_job {
188 /* sg[0] output, sg[1] input, others are possible sub frames */
189 struct qm_sg_entry sg[MAX_JOB_SG_ENTRIES];
192 #define DPAA_MAX_NB_MAX_DIGEST 32
193 struct dpaa_sec_op_ctx {
194 struct dpaa_sec_job job;
195 struct rte_crypto_op *op;
196 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
199 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
202 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
204 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
206 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
208 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
225 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
227 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
229 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
246 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
248 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
250 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
267 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
269 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
271 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
288 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
290 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
292 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
309 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
311 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
313 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
330 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
332 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
334 .algo = RTE_CRYPTO_AEAD_AES_GCM,
360 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
362 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
364 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
380 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
382 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
384 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
400 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
402 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
404 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
419 { /* SNOW 3G (UIA2) */
420 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
422 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
424 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
444 { /* SNOW 3G (UEA2) */
445 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
447 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
449 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
465 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
467 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
469 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
485 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
487 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
489 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
509 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
512 static const struct rte_cryptodev_capabilities dpaa_pdcp_capabilities[] = {
513 { /* SNOW 3G (UIA2) */
514 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
516 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
518 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
538 { /* SNOW 3G (UEA2) */
539 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
541 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
543 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
559 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
561 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
563 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
579 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
581 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
583 .algo = RTE_CRYPTO_AUTH_NULL,
599 { /* NULL (CIPHER) */
600 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
602 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
604 .algo = RTE_CRYPTO_CIPHER_NULL,
620 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
622 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
624 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
640 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
642 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
644 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
665 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
668 static const struct rte_security_capability dpaa_sec_security_cap[] = {
669 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
670 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
671 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
673 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
674 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
675 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
678 .crypto_capabilities = dpaa_sec_capabilities
680 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
681 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
682 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
684 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
685 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
686 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
689 .crypto_capabilities = dpaa_sec_capabilities
691 { /* PDCP Lookaside Protocol offload Data */
692 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
693 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
695 .domain = RTE_SECURITY_PDCP_MODE_DATA,
697 .crypto_capabilities = dpaa_pdcp_capabilities
699 { /* PDCP Lookaside Protocol offload Control */
700 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
701 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
703 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
705 .crypto_capabilities = dpaa_pdcp_capabilities
708 .action = RTE_SECURITY_ACTION_TYPE_NONE
715 * @param buffer calculate chksum for buffer
716 * @param len buffer length
718 * @return checksum value in host cpu order
720 static inline uint16_t
721 calc_chksum(void *buffer, int len)
723 uint16_t *buf = (uint16_t *)buffer;
727 for (sum = 0; len > 1; len -= 2)
731 sum += *(unsigned char *)buf;
733 sum = (sum >> 16) + (sum & 0xFFFF);
740 #endif /* _DPAA_SEC_H_ */