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];
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 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
128 uint8_t *data; /**< pointer to key data */
129 size_t length; /**< key length in bytes */
135 uint8_t *data; /**< pointer to key data */
136 size_t length; /**< key length in bytes */
141 uint8_t *data; /**< pointer to key data */
142 size_t length; /**< key length in bytes */
153 } iv; /**< Initialisation vector parameters */
154 uint16_t auth_only_len;
155 /*!< Length of data for Auth only */
156 uint32_t digest_length;
157 struct ipsec_decap_pdb decap_pdb;
158 struct ipsec_encap_pdb encap_pdb;
161 struct rte_ipv6_hdr ip6_hdr;
163 uint8_t auth_cipher_text;
164 /**< Authenticate/cipher ordering */
166 struct sec_pdcp_ctxt pdcp;
168 struct dpaa_sec_qp *qp[MAX_DPAA_CORES];
169 struct qman_fq *inq[MAX_DPAA_CORES];
170 struct sec_cdb cdb; /**< cmd block associated with qp */
174 struct dpaa_sec_dev_private *internals;
175 struct rte_mempool *ctx_pool; /* mempool for dpaa_sec_op_ctx */
183 #define RTE_DPAA_MAX_NB_SEC_QPS 2
184 #define RTE_DPAA_MAX_RX_QUEUE (MAX_DPAA_CORES * RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS)
185 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
187 /* internal sec queue interface */
188 struct dpaa_sec_dev_private {
190 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
191 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
192 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
193 unsigned int max_nb_queue_pairs;
194 unsigned int max_nb_sessions;
198 #define MAX_SG_ENTRIES 16
199 #define MAX_JOB_SG_ENTRIES 36
201 struct dpaa_sec_job {
202 /* sg[0] output, sg[1] input, others are possible sub frames */
203 struct qm_sg_entry sg[MAX_JOB_SG_ENTRIES];
206 #define DPAA_MAX_NB_MAX_DIGEST 32
207 struct dpaa_sec_op_ctx {
208 struct dpaa_sec_job job;
209 struct rte_crypto_op *op;
210 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
213 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
216 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
218 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
220 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
222 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
239 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
241 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
243 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
260 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
262 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
264 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
281 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
283 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
285 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
302 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
304 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
306 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
323 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
325 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
327 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
344 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
346 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
348 .algo = RTE_CRYPTO_AEAD_AES_GCM,
374 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
376 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
378 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
394 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
396 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
398 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
414 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
416 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
418 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
433 { /* SNOW 3G (UIA2) */
434 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
436 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
438 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
458 { /* SNOW 3G (UEA2) */
459 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
461 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
463 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
479 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
481 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
483 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
499 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
501 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
503 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
523 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
526 static const struct rte_cryptodev_capabilities dpaa_pdcp_capabilities[] = {
527 { /* SNOW 3G (UIA2) */
528 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
530 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
532 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
552 { /* SNOW 3G (UEA2) */
553 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
555 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
557 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
573 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
575 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
577 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
593 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
595 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
597 .algo = RTE_CRYPTO_AUTH_NULL,
613 { /* NULL (CIPHER) */
614 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
616 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
618 .algo = RTE_CRYPTO_CIPHER_NULL,
634 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
636 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
638 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
654 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
656 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
658 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
679 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
682 static const struct rte_security_capability dpaa_sec_security_cap[] = {
683 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
684 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
685 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
687 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
688 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
689 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
692 .crypto_capabilities = dpaa_sec_capabilities
694 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
695 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
696 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
698 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
699 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
700 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
703 .crypto_capabilities = dpaa_sec_capabilities
705 { /* PDCP Lookaside Protocol offload Data */
706 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
707 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
709 .domain = RTE_SECURITY_PDCP_MODE_DATA,
711 .crypto_capabilities = dpaa_pdcp_capabilities
713 { /* PDCP Lookaside Protocol offload Control */
714 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
715 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
717 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
719 .crypto_capabilities = dpaa_pdcp_capabilities
722 .action = RTE_SECURITY_ACTION_TYPE_NONE
729 * @param buffer calculate chksum for buffer
730 * @param len buffer length
732 * @return checksum value in host cpu order
734 static inline uint16_t
735 calc_chksum(void *buffer, int len)
737 uint16_t *buf = (uint16_t *)buffer;
741 for (sum = 0; len > 1; len -= 2)
745 sum += *(unsigned char *)buf;
747 sum = (sum >> 16) + (sum & 0xFFFF);
754 #endif /* _DPAA_SEC_H_ */