1 /* SPDX-License-Identifier: BSD-3-Clause
10 #define NUM_POOL_CHANNELS 4
11 #define DPAA_SEC_BURST 7
12 #define DPAA_SEC_ALG_UNSUPPORT (-1)
13 #define TDES_CBC_IV_LEN 8
14 #define AES_CBC_IV_LEN 16
15 #define AES_CTR_IV_LEN 16
16 #define AES_GCM_IV_LEN 12
18 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
19 * a pointer to the shared descriptor.
21 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
22 /* CTX_POOL_NUM_BUFS is set as per the ipsec-secgw application */
23 #define CTX_POOL_NUM_BUFS 32000
24 #define CTX_POOL_BUF_SIZE sizeof(struct dpaa_sec_op_ctx)
25 #define CTX_POOL_CACHE_SIZE 512
30 enum dpaa_sec_op_type {
31 DPAA_SEC_NONE, /*!< No Cipher operations*/
32 DPAA_SEC_CIPHER,/*!< CIPHER operations */
33 DPAA_SEC_AUTH, /*!< Authentication Operations */
34 DPAA_SEC_AEAD, /*!< Authenticated Encryption with associated data */
35 DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
36 DPAA_SEC_PDCP, /*!< PDCP protocol operations*/
37 DPAA_SEC_PKC, /*!< Public Key Cryptographic Operations */
42 #define DPAA_SEC_MAX_DESC_SIZE 64
43 /* code or cmd block to caam */
49 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
51 unsigned int rsvd47_39:9;
55 unsigned int rsvd47_39:9;
64 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
65 unsigned int rsvd31_30:2;
68 unsigned int offset:2;
70 unsigned int add_buf:1;
72 uint16_t pool_buffer_size;
74 uint16_t pool_buffer_size;
76 unsigned int add_buf:1;
78 unsigned int offset:2;
81 unsigned int rsvd31_30:2;
87 uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
90 typedef struct dpaa_sec_session_entry {
91 uint8_t dir; /*!< Operation Direction */
92 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
93 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
94 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
95 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
98 uint8_t *data; /**< pointer to key data */
99 size_t length; /**< key length in bytes */
103 uint8_t *data; /**< pointer to key data */
104 size_t length; /**< key length in bytes */
107 uint8_t *data; /**< pointer to key data */
108 size_t length; /**< key length in bytes */
115 } iv; /**< Initialisation vector parameters */
116 uint16_t auth_only_len; /*!< Length of data for Auth only */
117 uint32_t digest_length;
118 struct ipsec_encap_pdb encap_pdb;
120 struct ipsec_decap_pdb decap_pdb;
121 struct dpaa_sec_qp *qp;
123 struct sec_cdb cdb; /**< cmd block associated with qp */
124 struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
128 struct dpaa_sec_dev_private *internals;
136 #define RTE_DPAA_MAX_NB_SEC_QPS 1
137 #define RTE_DPAA_MAX_RX_QUEUE RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS
138 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
140 /* internal sec queue interface */
141 struct dpaa_sec_dev_private {
143 struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
144 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
145 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
146 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
147 unsigned int max_nb_queue_pairs;
148 unsigned int max_nb_sessions;
151 #define MAX_SG_ENTRIES 16
152 #define SG_CACHELINE_0 0
153 #define SG_CACHELINE_1 4
154 #define SG_CACHELINE_2 8
155 #define SG_CACHELINE_3 12
156 struct dpaa_sec_job {
157 /* sg[0] output, sg[1] input, others are possible sub frames */
158 struct qm_sg_entry sg[MAX_SG_ENTRIES];
161 #define DPAA_MAX_NB_MAX_DIGEST 32
162 struct dpaa_sec_op_ctx {
163 struct dpaa_sec_job job;
164 struct rte_crypto_op *op;
165 struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
168 uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
171 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
173 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
175 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
177 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
193 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
195 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
197 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
213 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
215 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
217 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
233 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
235 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
237 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
253 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
255 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
257 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
273 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
275 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
277 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
293 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
295 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
297 .algo = RTE_CRYPTO_AEAD_AES_GCM,
323 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
325 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
327 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
343 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
345 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
347 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
363 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
365 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
367 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
383 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
386 static const struct rte_security_capability dpaa_sec_security_cap[] = {
387 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
388 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
389 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
391 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
392 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
393 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
396 .crypto_capabilities = dpaa_sec_capabilities
398 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
399 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
400 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
402 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
403 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
404 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
407 .crypto_capabilities = dpaa_sec_capabilities
410 .action = RTE_SECURITY_ACTION_TYPE_NONE
417 * @param buffer calculate chksum for buffer
418 * @param len buffer length
420 * @return checksum value in host cpu order
422 static inline uint16_t
423 calc_chksum(void *buffer, int len)
425 uint16_t *buf = (uint16_t *)buffer;
429 for (sum = 0; len > 1; len -= 2)
433 sum += *(unsigned char *)buf;
435 sum = (sum >> 16) + (sum & 0xFFFF);
442 #endif /* _DPAA_SEC_H_ */