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 NUM_POOL_CHANNELS 4
14 #define DPAA_SEC_BURST 7
15 #define DPAA_SEC_ALG_UNSUPPORT (-1)
16 #define TDES_CBC_IV_LEN 8
17 #define AES_CBC_IV_LEN 16
18 #define AES_CTR_IV_LEN 16
19 #define AES_GCM_IV_LEN 12
21 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
22 * a pointer to the shared descriptor.
24 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
25 /* CTX_POOL_NUM_BUFS is set as per the ipsec-secgw application */
26 #define CTX_POOL_NUM_BUFS 32000
27 #define CTX_POOL_BUF_SIZE sizeof(struct dpaa_sec_op_ctx)
28 #define CTX_POOL_CACHE_SIZE 512
29 #define RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS 2048
34 enum dpaa_sec_op_type {
35 DPAA_SEC_NONE, /*!< No Cipher operations*/
36 DPAA_SEC_CIPHER,/*!< CIPHER operations */
37 DPAA_SEC_AUTH, /*!< Authentication Operations */
38 DPAA_SEC_AEAD, /*!< Authenticated Encryption with associated data */
39 DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
40 DPAA_SEC_PDCP, /*!< PDCP protocol operations*/
41 DPAA_SEC_PKC, /*!< Public Key Cryptographic Operations */
46 #define DPAA_SEC_MAX_DESC_SIZE 64
47 /* code or cmd block to caam */
53 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
55 unsigned int rsvd47_39:9;
59 unsigned int rsvd47_39:9;
68 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
69 unsigned int rsvd31_30:2;
72 unsigned int offset:2;
74 unsigned int add_buf:1;
76 uint16_t pool_buffer_size;
78 uint16_t pool_buffer_size;
80 unsigned int add_buf:1;
82 unsigned int offset:2;
85 unsigned int rsvd31_30:2;
91 uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
95 * The structure is to be filled by user as a part of
96 * dpaa_sec_proto_ctxt for PDCP Protocol
98 struct sec_pdcp_ctxt {
99 enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
100 int8_t bearer; /*!< PDCP bearer ID */
101 int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
102 int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
103 uint32_t hfn; /*!< Hyper Frame Number */
104 uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
105 uint8_t sn_size; /*!< Sequence number size, 7/12/15 */
108 typedef struct dpaa_sec_session_entry {
109 uint8_t dir; /*!< Operation Direction */
110 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
111 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
112 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
113 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
116 uint8_t *data; /**< pointer to key data */
117 size_t length; /**< key length in bytes */
121 uint8_t *data; /**< pointer to key data */
122 size_t length; /**< key length in bytes */
125 uint8_t *data; /**< pointer to key data */
126 size_t length; /**< key length in bytes */
135 } iv; /**< Initialisation vector parameters */
136 uint16_t auth_only_len;
137 /*!< Length of data for Auth only */
138 uint32_t digest_length;
139 struct ipsec_decap_pdb decap_pdb;
140 struct ipsec_encap_pdb encap_pdb;
143 struct sec_pdcp_ctxt pdcp;
145 struct dpaa_sec_qp *qp;
147 struct sec_cdb cdb; /**< cmd block associated with qp */
148 struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
152 struct dpaa_sec_dev_private *internals;
160 #define RTE_DPAA_MAX_NB_SEC_QPS 2
161 #define RTE_DPAA_MAX_RX_QUEUE RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS
162 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
164 /* internal sec queue interface */
165 struct dpaa_sec_dev_private {
167 struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
168 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
169 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
170 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
171 unsigned int max_nb_queue_pairs;
172 unsigned int max_nb_sessions;
176 #define MAX_SG_ENTRIES 16
177 #define SG_CACHELINE_0 0
178 #define SG_CACHELINE_1 4
179 #define SG_CACHELINE_2 8
180 #define SG_CACHELINE_3 12
181 struct dpaa_sec_job {
182 /* sg[0] output, sg[1] input, others are possible sub frames */
183 struct qm_sg_entry sg[MAX_SG_ENTRIES];
186 #define DPAA_MAX_NB_MAX_DIGEST 32
187 struct dpaa_sec_op_ctx {
188 struct dpaa_sec_job job;
189 struct rte_crypto_op *op;
190 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
193 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
196 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
198 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
200 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
202 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
219 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
221 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
223 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
240 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
242 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
244 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
261 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
263 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
265 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
282 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
284 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
286 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
303 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
305 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
307 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
324 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
326 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
328 .algo = RTE_CRYPTO_AEAD_AES_GCM,
354 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
356 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
358 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
374 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
376 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
378 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
394 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
396 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
398 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
414 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
417 static const struct rte_cryptodev_capabilities dpaa_pdcp_capabilities[] = {
418 { /* SNOW 3G (UIA2) */
419 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
421 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
423 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
443 { /* SNOW 3G (UEA2) */
444 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
446 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
448 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
464 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
466 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
468 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
484 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
486 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
488 .algo = RTE_CRYPTO_AUTH_NULL,
504 { /* NULL (CIPHER) */
505 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
507 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
509 .algo = RTE_CRYPTO_CIPHER_NULL,
525 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
527 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
529 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
545 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
547 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
549 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
570 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
573 static const struct rte_security_capability dpaa_sec_security_cap[] = {
574 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
575 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
576 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
578 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
579 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
580 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
583 .crypto_capabilities = dpaa_sec_capabilities
585 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
586 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
587 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
589 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
590 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
591 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
594 .crypto_capabilities = dpaa_sec_capabilities
596 { /* PDCP Lookaside Protocol offload Data */
597 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
598 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
600 .domain = RTE_SECURITY_PDCP_MODE_DATA,
602 .crypto_capabilities = dpaa_pdcp_capabilities
604 { /* PDCP Lookaside Protocol offload Control */
605 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
606 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
608 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
610 .crypto_capabilities = dpaa_pdcp_capabilities
613 .action = RTE_SECURITY_ACTION_TYPE_NONE
620 * @param buffer calculate chksum for buffer
621 * @param len buffer length
623 * @return checksum value in host cpu order
625 static inline uint16_t
626 calc_chksum(void *buffer, int len)
628 uint16_t *buf = (uint16_t *)buffer;
632 for (sum = 0; len > 1; len -= 2)
636 sum += *(unsigned char *)buf;
638 sum = (sum >> 16) + (sum & 0xFFFF);
645 #endif /* _DPAA_SEC_H_ */