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 uint32_t hfn; /*!< Hyper Frame Number */
107 uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
108 uint8_t sn_size; /*!< Sequence number size, 7/12/15 */
111 typedef struct dpaa_sec_session_entry {
112 uint8_t dir; /*!< Operation Direction */
113 enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
114 enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
115 enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
116 enum rte_security_session_protocol proto_alg; /*!< Security Algorithm*/
119 uint8_t *data; /**< pointer to key data */
120 size_t length; /**< key length in bytes */
124 uint8_t *data; /**< pointer to key data */
125 size_t length; /**< key length in bytes */
128 uint8_t *data; /**< pointer to key data */
129 size_t length; /**< key length in bytes */
138 } iv; /**< Initialisation vector parameters */
139 uint16_t auth_only_len;
140 /*!< Length of data for Auth only */
141 uint32_t digest_length;
142 struct ipsec_decap_pdb decap_pdb;
143 struct ipsec_encap_pdb encap_pdb;
146 struct rte_ipv6_hdr ip6_hdr;
149 struct sec_pdcp_ctxt pdcp;
151 struct dpaa_sec_qp *qp[MAX_DPAA_CORES];
152 struct qman_fq *inq[MAX_DPAA_CORES];
153 struct sec_cdb cdb; /**< cmd block associated with qp */
154 struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
158 struct dpaa_sec_dev_private *internals;
166 #define RTE_DPAA_MAX_NB_SEC_QPS 2
167 #define RTE_DPAA_MAX_RX_QUEUE (MAX_DPAA_CORES * RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS)
168 #define DPAA_MAX_DEQUEUE_NUM_FRAMES 63
170 /* internal sec queue interface */
171 struct dpaa_sec_dev_private {
173 struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
174 struct dpaa_sec_qp qps[RTE_DPAA_MAX_NB_SEC_QPS]; /* i/o queue for sec */
175 struct qman_fq inq[RTE_DPAA_MAX_RX_QUEUE];
176 unsigned char inq_attach[RTE_DPAA_MAX_RX_QUEUE];
177 unsigned int max_nb_queue_pairs;
178 unsigned int max_nb_sessions;
182 #define MAX_SG_ENTRIES 16
183 #define SG_CACHELINE_0 0
184 #define SG_CACHELINE_1 4
185 #define SG_CACHELINE_2 8
186 #define SG_CACHELINE_3 12
187 struct dpaa_sec_job {
188 /* sg[0] output, sg[1] input, others are possible sub frames */
189 struct qm_sg_entry sg[MAX_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,
420 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
423 static const struct rte_cryptodev_capabilities dpaa_pdcp_capabilities[] = {
424 { /* SNOW 3G (UIA2) */
425 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
427 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
429 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
449 { /* SNOW 3G (UEA2) */
450 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
452 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
454 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
470 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
472 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
474 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
490 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
492 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
494 .algo = RTE_CRYPTO_AUTH_NULL,
510 { /* NULL (CIPHER) */
511 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
513 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
515 .algo = RTE_CRYPTO_CIPHER_NULL,
531 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
533 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
535 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
551 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
553 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
555 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
576 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
579 static const struct rte_security_capability dpaa_sec_security_cap[] = {
580 { /* IPsec Lookaside Protocol offload ESP Transport Egress */
581 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
582 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
584 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
585 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
586 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
589 .crypto_capabilities = dpaa_sec_capabilities
591 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
592 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
593 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
595 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
596 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
597 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
600 .crypto_capabilities = dpaa_sec_capabilities
602 { /* PDCP Lookaside Protocol offload Data */
603 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
604 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
606 .domain = RTE_SECURITY_PDCP_MODE_DATA,
608 .crypto_capabilities = dpaa_pdcp_capabilities
610 { /* PDCP Lookaside Protocol offload Control */
611 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
612 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
614 .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
616 .crypto_capabilities = dpaa_pdcp_capabilities
619 .action = RTE_SECURITY_ACTION_TYPE_NONE
626 * @param buffer calculate chksum for buffer
627 * @param len buffer length
629 * @return checksum value in host cpu order
631 static inline uint16_t
632 calc_chksum(void *buffer, int len)
634 uint16_t *buf = (uint16_t *)buffer;
638 for (sum = 0; len > 1; len -= 2)
642 sum += *(unsigned char *)buf;
644 sum = (sum >> 16) + (sum & 0xFFFF);
651 #endif /* _DPAA_SEC_H_ */