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];
94 typedef struct dpaa_sec_session_entry {
95 uint8_t dir; /*!< Operation Direction */
96 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
97 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
98 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
99 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
102 uint8_t *data; /**< pointer to key data */
103 size_t length; /**< key length in bytes */
107 uint8_t *data; /**< pointer to key data */
108 size_t length; /**< key length in bytes */
111 uint8_t *data; /**< pointer to key data */
112 size_t length; /**< key length in bytes */
119 } iv; /**< Initialisation vector parameters */
120 uint16_t auth_only_len; /*!< Length of data for Auth only */
121 uint32_t digest_length;
122 struct ipsec_encap_pdb encap_pdb;
124 struct ipsec_decap_pdb decap_pdb;
125 struct dpaa_sec_qp *qp;
127 struct sec_cdb cdb; /**< cmd block associated with qp */
128 struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
132 struct dpaa_sec_dev_private *internals;
140 #define RTE_DPAA_MAX_NB_SEC_QPS 8
141 #define RTE_DPAA_MAX_RX_QUEUE RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS
142 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
144 /* internal sec queue interface */
145 struct dpaa_sec_dev_private {
147 struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
148 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
149 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
150 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
151 unsigned int max_nb_queue_pairs;
152 unsigned int max_nb_sessions;
155 #define MAX_SG_ENTRIES 16
156 #define SG_CACHELINE_0 0
157 #define SG_CACHELINE_1 4
158 #define SG_CACHELINE_2 8
159 #define SG_CACHELINE_3 12
160 struct dpaa_sec_job {
161 /* sg[0] output, sg[1] input, others are possible sub frames */
162 struct qm_sg_entry sg[MAX_SG_ENTRIES];
165 #define DPAA_MAX_NB_MAX_DIGEST 32
166 struct dpaa_sec_op_ctx {
167 struct dpaa_sec_job job;
168 struct rte_crypto_op *op;
169 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
172 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
175 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
177 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
179 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
181 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
198 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
200 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
202 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
219 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
221 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
223 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
240 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
242 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
244 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
261 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
263 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
265 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
282 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
284 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
286 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
303 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
305 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
307 .algo = RTE_CRYPTO_AEAD_AES_GCM,
333 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
335 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
337 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
353 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
355 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
357 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
373 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
375 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
377 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
393 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
396 static const struct rte_security_capability dpaa_sec_security_cap[] = {
397 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
398 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
399 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
401 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
402 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
403 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
406 .crypto_capabilities = dpaa_sec_capabilities
408 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
409 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
410 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
412 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
413 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
414 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
417 .crypto_capabilities = dpaa_sec_capabilities
420 .action = RTE_SECURITY_ACTION_TYPE_NONE
427 * @param buffer calculate chksum for buffer
428 * @param len buffer length
430 * @return checksum value in host cpu order
432 static inline uint16_t
433 calc_chksum(void *buffer, int len)
435 uint16_t *buf = (uint16_t *)buffer;
439 for (sum = 0; len > 1; len -= 2)
443 sum += *(unsigned char *)buf;
445 sum = (sum >> 16) + (sum & 0xFFFF);
452 #endif /* _DPAA_SEC_H_ */