From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0057.outbound.protection.outlook.com [104.47.32.57]) by dpdk.org (Postfix) with ESMTP id C11338CF6 for ; Tue, 15 Aug 2017 08:37:24 +0200 (CEST) Received: from BN3PR03CA0106.namprd03.prod.outlook.com (2603:10b6:400:4::24) by MWHSPR01MB180.namprd03.prod.outlook.com (2603:10b6:301:7b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1341.21; Tue, 15 Aug 2017 06:37:23 +0000 Received: from BN1AFFO11FD024.protection.gbl (2a01:111:f400:7c10::196) by BN3PR03CA0106.outlook.office365.com (2603:10b6:400:4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1341.21 via Frontend Transport; Tue, 15 Aug 2017 06:37:22 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11FD024.mail.protection.outlook.com (10.58.52.84) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1304.16 via Frontend Transport; Tue, 15 Aug 2017 06:37:21 +0000 Received: from netperf2.ap.freescale.net ([10.232.133.164]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id v7F6atQG015692; Mon, 14 Aug 2017 23:37:17 -0700 From: Akhil Goyal To: , , , , , , , CC: , , Akhil Goyal Date: Tue, 15 Aug 2017 12:05:04 +0530 Message-ID: <20170815063505.22032-4-akhil.goyal@nxp.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170815063505.22032-1-akhil.goyal@nxp.com> References: <20170725112153.29699-1-akhil.goyal@nxp.com> <20170815063505.22032-1-akhil.goyal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131472526422000659; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39860400002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(47776003)(6666003)(356003)(97736004)(8676002)(2950100002)(81156014)(81166006)(305945005)(48376002)(105606002)(8936002)(50226002)(85426001)(76176999)(50986999)(54906002)(7416002)(189998001)(5660300001)(2201001)(1076002)(104016004)(53936002)(68736007)(5003940100001)(575784001)(2906002)(86362001)(36756003)(77096006)(4326008)(69596002)(106466001)(50466002)(498600001)(33646002)(626005)(8656003)(217873001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHSPR01MB180; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1AFFO11FD024; 1:Y4qT9JdP49vLDzOXMj5QMqaFI+8rFOJYk9wHLgGJn?= =?us-ascii?Q?KXDFcvtWba/1Oft44MQfSgkrR09q9uAZLJnsNl7vtZOAj06YMdkQnJ43VWL+?= =?us-ascii?Q?gnpaypMwInHCW3CXuIvFBAZaJh/JksJkFzk5qsC2c3uHin7xNEgwomRafnEH?= =?us-ascii?Q?EKyJkNqhRtOJZ/5yuspTom+RwP4OhO/FkJTpXSwst2dZMaUezWQCOEybpHZf?= =?us-ascii?Q?GsB7kT2GlbNzDoACc5hPHuINT5L1fDzlUFc+zA9ar9bKA7iewnMiQ++yyISr?= =?us-ascii?Q?tYZBL4p1SG8rEeTFfF8Fu1WqAqszRXMd6RtM2XQgkIZEMMx0SbqsKRKofdxl?= =?us-ascii?Q?4V0MggFHCeNZ18W9XrY/qqlj2D/XeI3Ekul8Kzo88uhNp3ajgdQR64d6cIsK?= =?us-ascii?Q?jLqnyKap2C4bUUe9ZSKDsPyN1ev4Qd4d7gIemk5aGgdKbar532evUWgRVEIC?= =?us-ascii?Q?MeNQhpSuGvVYheDogv/8JMCwHpytdFVnlCNkZBZOvYdUvbeAMVg9Y2a0qEAn?= =?us-ascii?Q?zVWnP417N72ndN1Tlp7QXpfBBjLr35LksWgVHOAlbIsLhoBvOsAHYd6RBa1r?= =?us-ascii?Q?g8FpkfCI40DRl+zGUCeNskLCTNLqRymll81AN3DlCS3U2kitsUh6665TGHXx?= =?us-ascii?Q?vHoVZWDhRETa3VQ86axpxDiEM9ta984a4U+Ft3hmle8TaIQKkdWCed/MRMPA?= =?us-ascii?Q?2J1rfymTP80+18UsP+iLNk9An0G1CHqOzmhwirUOu2Kg80EfJuJ3eye7r3Xh?= =?us-ascii?Q?m6NYkGLqZxIcBjgklNR6Uwun+Qp2jY/UAkAaYSvzdSvf2jQIG6pI2KcmRcCU?= =?us-ascii?Q?ZA4l7lye5HI829m/9c+Ma4KBTA8yW2UC3v4JK2MOJfgJM2JM6uyULmMpht/3?= =?us-ascii?Q?l7tX9eavtfrOP/2bOe8S99rMbMn/OMLoOM4rhrHg3I7HMF/U3gjVHTi1xkN1?= =?us-ascii?Q?kx/Tvsbbwsoj8SpSppPEXQqs5zEcPbmCearxwNMkxhUF8aX8km0lSOPYjps9?= =?us-ascii?Q?HeHD5ImgcWYAo6UofILLCzO?= MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0972f364-1205-436b-e2b3-08d4e3a8158f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603031)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHSPR01MB180; X-Microsoft-Exchange-Diagnostics: 1; MWHSPR01MB180; 3:NAg8gQlakoOuX6+3njhk3SKMIPrMmg7MqzTP4KSpmUd0LD0UttFWnaQ4vxYkIoyvY/h9nUfqOAf7Fr3TjPSKRv21UP/Wz9JSVIKDkD8Xvnm7oS/BcCqn8DANbroQZG7iB/frb+Ra5TXfGztVjGcPfvDpJFpUKgmyV+Gr+G5mxgioQW9JWli0+9Fm8ABOXV45j9rq1ZgZrOjLXDdZZ1QFCfPwbklgOtwZdOgmwmX1F0u4mC9Qgvhy7ULhXqW6W5FwrV40QyXclntj1q0zdskVNhhyQioVali3Th3rN9eULltcvg3MwP5E5/cVZ1mVScEzyeaVYTL+vgHQwgEaCkOpOA==; 25:tPv38jB8+t0H+FLeTlhCwep48/nPRCHVv71SvibyG5xa1j8HyHoT9nxNcXQUePyPRXgZiJi7ZZ/LscD55GKC9QrtLThQd9fVlCDjgYxmipY3MXeopHVbPEZhRggsz1UQkdR84MKYLqx6RkhPRK2UuZjx1dIDDSZsB2bD/l9lT0D7FSwH3FS4TcA94vKexLXvWmuCKsAlWBsBz9qvt2tszadEBDLcDh82BX7po5BHHJbwVsTfjeSEuUlyLuAQrsMetikZBlNu/g2jxI9479XE4qWnPkVLj01Q/qs+JjewHVPT4MzERxOUVyfgbcQVQWyHX+jxZxYgbw6eCL830jbYjg==; 31:1EDZDpWHhDI3Iq1KSrycLcowcXA1tkO5iJ3Z7VBTby+H+Ob9Ah2IZ0masgRNZHl+Cs0y1zEdV7xKw9elCiLofGD69Mghe5j1Y+fR0KDQFzyBBpHD79uEeDGTbwrN2efNzqjxS281xFmXR9HfF3wsrkIgYtv/DX5i71zUyIJY6WqZ9pFNvzE/IKXpaMyKYpcttqbQ3j0JOVtM/g3kGPhFeH0PbrLQfMPoUEEyW/O8CBc= X-MS-TrafficTypeDiagnostic: MWHSPR01MB180: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(13016025)(13018025)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(6055026)(6096035)(201703131430075)(201703131448075)(201703131433075)(201703161259150)(201703151042153)(20161123559100)(20161123565025)(20161123561025)(20161123563025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHSPR01MB180; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHSPR01MB180; X-Microsoft-Exchange-Diagnostics: 1; MWHSPR01MB180; 4:JbD1qoq02eqdyKRSiumosdeYZq8WRvkTubzVnd0yqx9qdR5QZywdvuRaLGnG9x8xqpQzY4+TZBmwwWUfMo/MH0UpP7VpNYsTxz1y48MjSIUjoAnEeK6u/UDU+0470xO82vGgdkc+MDpZ0jIPBXmPqqgkEVMKml2s053U95CHDTsYhs9TT3L0ySB4/ZB0emsgqr9s1NNrJbWJaPTjRweyqqpaVGMr3YXQJP/hmAswqFjOERJXd1vUMoj2eUJM7vANTujagodpM9UlsRWaEJGuvTWglWwd7luRFQZ/3cHWjLjo1zEiDDTwL1uAqbLE4KlqeSjVLHcM6Rs7kpmzNq0XTQ== X-Forefront-PRVS: 04004D94E2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHSPR01MB180; 23:oXouGYDYQh4JMpoQ7hCyT4zv8gadGENF/yU0q9IKx?= =?us-ascii?Q?1JQ18fie94uWcUi5Po+dWIgMGC15i2XX1iu5BeCnD6CXsvy5LFaE3KMnODb+?= =?us-ascii?Q?pIEs1Bl5PmZ9UaHF6gM4Gi/OofIgENDLZL1groO/JBDM1oi74DgA2kHrrbwD?= =?us-ascii?Q?Qjhbn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S5NLVCskCL4zNeYYK+MgYURw94= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2017 06:37:21.9504 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHSPR01MB180 Subject: [dpdk-dev] [RFC PATCH 3/4] crypto/dpaa2_sec: add support for protocol offload ipsec X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Aug 2017 06:37:25 -0000 driver implementation to support rte_security APIs Signed-off-by: Akhil Goyal --- drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 368 +++++++++++++++++++++++++++- drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h | 33 +++ 2 files changed, 399 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c index e0f6cfc..45f41d5 100644 --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c @@ -73,12 +73,46 @@ #define FLE_POOL_NUM_BUFS 32000 #define FLE_POOL_BUF_SIZE 256 #define FLE_POOL_CACHE_SIZE 512 +#define SEC_FLC_DHR_OUTBOUND -114 +#define SEC_FLC_DHR_INBOUND 0 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8; static uint8_t cryptodev_driver_id; static inline int +build_proto_fd(dpaa2_sec_session *sess, + struct rte_crypto_op *op, + struct qbman_fd *fd, uint16_t bpid) +{ + struct rte_crypto_sym_op *sym_op = op->sym; + struct ctxt_priv *priv = sess->ctxt; + struct sec_flow_context *flc; + struct rte_mbuf *mbuf = sym_op->m_src; + + if (likely(bpid < MAX_BPID)) { + DPAA2_SET_FD_BPID(fd, bpid); + } else { + DPAA2_SET_FD_IVP(fd); + } + + /* Save the shared descriptor */ + flc = &priv->flc_desc[0].flc; + + DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src)); + DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off + sym_op->m_src->l2_len); + DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len - sym_op->m_src->l2_len); + DPAA2_SET_FD_FLC(fd, ((uint64_t)flc)); + + /* save physical address of mbuf */ + op->sym->aead.digest.phys_addr = mbuf->buf_physaddr; + mbuf->buf_physaddr = (uint64_t)op; + + return 0; +} + + +static inline int build_authenc_gcm_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op, struct qbman_fd *fd, uint16_t bpid) @@ -565,6 +599,9 @@ build_sec_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op, case DPAA2_SEC_CIPHER_HASH: ret = build_authenc_fd(sess, op, fd, bpid); break; + case DPAA2_SEC_IPSEC: + ret = build_proto_fd(sess, op, fd, bpid); + break; case DPAA2_SEC_HASH_CIPHER: default: RTE_LOG(ERR, PMD, "error: Unsupported session\n"); @@ -649,12 +686,44 @@ dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops, } static inline struct rte_crypto_op * -sec_fd_to_mbuf(const struct qbman_fd *fd) +sec_simple_fd_to_mbuf(const struct qbman_fd *fd, __rte_unused uint8_t id) +{ + struct rte_crypto_op *op; + uint16_t len = DPAA2_GET_FD_LEN(fd); + uint16_t diff = 0; + dpaa2_sec_session *sess_priv; + + struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF( + DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)), + rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size); + + op = (struct rte_crypto_op *)mbuf->buf_physaddr; + mbuf->buf_physaddr = op->sym->aead.digest.phys_addr; + op->sym->aead.digest.phys_addr = 0L; + + sess_priv = (dpaa2_sec_session *)get_sec_session_private_data( + op->sym->sec_session, id); + if (sess_priv->dir == DIR_ENC) + mbuf->data_off += SEC_FLC_DHR_OUTBOUND; + else + mbuf->data_off += SEC_FLC_DHR_INBOUND; + diff = len - mbuf->pkt_len; + mbuf->pkt_len += diff; + mbuf->data_len += diff; + + return op; +} + +static inline struct rte_crypto_op * +sec_fd_to_mbuf(const struct qbman_fd *fd, uint8_t driver_id) { struct qbman_fle *fle; struct rte_crypto_op *op; struct ctxt_priv *priv; + if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single) + return sec_simple_fd_to_mbuf(fd, driver_id); + fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)); PMD_RX_LOG(DEBUG, "FLE addr = %x - %x, offset = %x", @@ -701,6 +770,7 @@ dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops, { /* Function is responsible to receive frames for a given device and VQ*/ struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp; + struct rte_cryptodev *dev = (struct rte_cryptodev *)(dpaa2_qp->rx_vq.dev); struct qbman_result *dq_storage; uint32_t fqid = dpaa2_qp->rx_vq.fqid; int ret, num_rx = 0; @@ -770,7 +840,7 @@ dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops, } fd = qbman_result_DQ_fd(dq_storage); - ops[num_rx] = sec_fd_to_mbuf(fd); + ops[num_rx] = sec_fd_to_mbuf(fd, dev->driver_id); if (unlikely(fd->simple.frc)) { /* TODO Parse SEC errors */ @@ -1547,6 +1617,293 @@ dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev, } static int +dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev, + struct rte_security_ipsec_xform *xform, + void *sess) +{ + dpaa2_sec_session *session = (dpaa2_sec_session *)sess; + struct ctxt_priv *priv; + struct ipsec_encap_pdb encap_pdb; + struct ipsec_decap_pdb decap_pdb; + struct alginfo authdata, cipherdata; + unsigned int bufsize; +// unsigned int i; + struct sec_flow_context *flc; + + PMD_INIT_FUNC_TRACE(); + + priv = (struct ctxt_priv *)rte_zmalloc(NULL, + sizeof(struct ctxt_priv) + + sizeof(struct sec_flc_desc), + RTE_CACHE_LINE_SIZE); + + if (priv == NULL) { + RTE_LOG(ERR, PMD, "\nNo memory for priv CTXT"); + return -ENOMEM; + } + + flc = &priv->flc_desc[0].flc; + + session->ctxt_type = DPAA2_SEC_IPSEC; + session->cipher_key.data = rte_zmalloc(NULL, + xform->cipher_key.length, + RTE_CACHE_LINE_SIZE); + if (session->cipher_key.data == NULL && + xform->cipher_key.length > 0) { + RTE_LOG(ERR, PMD, "No Memory for cipher key\n"); + rte_free(priv); + return -ENOMEM; + } + + session->cipher_key.length = xform->cipher_key.length; + session->auth_key.data = rte_zmalloc(NULL, + xform->auth_key.length, + RTE_CACHE_LINE_SIZE); + if (session->auth_key.data == NULL && + xform->auth_key.length > 0) { + RTE_LOG(ERR, PMD, "No Memory for auth key\n"); + rte_free(session->cipher_key.data); + rte_free(priv); + return -ENOMEM; + } + session->auth_key.length = xform->auth_key.length; + memcpy(session->cipher_key.data, xform->cipher_key.data, + xform->cipher_key.length); + memcpy(session->auth_key.data, xform->auth_key.data, + xform->auth_key.length); + + authdata.key = (uint64_t)session->auth_key.data; + authdata.keylen = session->auth_key.length; + authdata.key_enc_flags = 0; + authdata.key_type = RTA_DATA_IMM; + switch (xform->auth_alg) { + case RTE_CRYPTO_AUTH_SHA1_HMAC: + authdata.algtype = OP_PCL_IPSEC_HMAC_SHA1_96; + authdata.algmode = OP_ALG_AAI_HMAC; + session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC; + break; + case RTE_CRYPTO_AUTH_MD5_HMAC: + authdata.algtype = OP_PCL_IPSEC_HMAC_MD5_96; + authdata.algmode = OP_ALG_AAI_HMAC; + session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA256_HMAC: + authdata.algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128; + authdata.algmode = OP_ALG_AAI_HMAC; + session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA384_HMAC: + authdata.algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192; + authdata.algmode = OP_ALG_AAI_HMAC; + session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA512_HMAC: + authdata.algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256; + authdata.algmode = OP_ALG_AAI_HMAC; + session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC; + break; + case RTE_CRYPTO_AUTH_AES_CMAC: + authdata.algtype = OP_PCL_IPSEC_AES_CMAC_96; + session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC; + break; + case RTE_CRYPTO_AUTH_NULL: + authdata.algtype = OP_PCL_IPSEC_HMAC_NULL; + session->auth_alg = RTE_CRYPTO_AUTH_NULL; + break; + case RTE_CRYPTO_AUTH_SHA224_HMAC: + case RTE_CRYPTO_AUTH_AES_XCBC_MAC: + case RTE_CRYPTO_AUTH_SNOW3G_UIA2: + case RTE_CRYPTO_AUTH_SHA1: + case RTE_CRYPTO_AUTH_SHA256: + case RTE_CRYPTO_AUTH_SHA512: + case RTE_CRYPTO_AUTH_SHA224: + case RTE_CRYPTO_AUTH_SHA384: + case RTE_CRYPTO_AUTH_MD5: + case RTE_CRYPTO_AUTH_AES_GMAC: + case RTE_CRYPTO_AUTH_KASUMI_F9: + case RTE_CRYPTO_AUTH_AES_CBC_MAC: + case RTE_CRYPTO_AUTH_ZUC_EIA3: + RTE_LOG(ERR, PMD, "Crypto: Unsupported auth alg %u\n", + xform->auth_alg); + goto out; + default: + RTE_LOG(ERR, PMD, "Crypto: Undefined Auth specified %u\n", + xform->auth_alg); + goto out; + } + cipherdata.key = (uint64_t)session->cipher_key.data; + cipherdata.keylen = session->cipher_key.length; + cipherdata.key_enc_flags = 0; + cipherdata.key_type = RTA_DATA_IMM; + + switch (xform->cipher_alg) { + case RTE_CRYPTO_CIPHER_AES_CBC: + cipherdata.algtype = OP_PCL_IPSEC_AES_CBC; + cipherdata.algmode = OP_ALG_AAI_CBC; + session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC; + break; + case RTE_CRYPTO_CIPHER_3DES_CBC: + cipherdata.algtype = OP_PCL_IPSEC_3DES; + cipherdata.algmode = OP_ALG_AAI_CBC; + session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC; + break; + case RTE_CRYPTO_CIPHER_AES_CTR: + cipherdata.algtype = OP_PCL_IPSEC_AES_CTR; + cipherdata.algmode = OP_ALG_AAI_CTR; + session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR; + break; + case RTE_CRYPTO_CIPHER_NULL: + cipherdata.algtype = OP_PCL_IPSEC_NULL; + break; + case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: + case RTE_CRYPTO_CIPHER_3DES_ECB: + case RTE_CRYPTO_CIPHER_AES_ECB: + case RTE_CRYPTO_CIPHER_KASUMI_F8: + RTE_LOG(ERR, PMD, "Crypto: Unsupported Cipher alg %u\n", + xform->cipher_alg); + goto out; + default: + RTE_LOG(ERR, PMD, "Crypto: Undefined Cipher specified %u\n", + xform->cipher_alg); + goto out; + } + + if (xform->op == RTE_SECURITY_IPSEC_OP_ENCAP) { + flc->dhr = SEC_FLC_DHR_OUTBOUND; + struct ip ip4_hdr; + ip4_hdr.ip_v = IPVERSION; + ip4_hdr.ip_hl = 5; + ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr)); + ip4_hdr.ip_tos = xform->tunnel.ipv4.dscp; + ip4_hdr.ip_id = 0; + ip4_hdr.ip_off = 0; + ip4_hdr.ip_ttl = xform->tunnel.ipv4.ttl; + ip4_hdr.ip_p = 0x32; + ip4_hdr.ip_sum = 0; + ip4_hdr.ip_src = xform->tunnel.ipv4.src_ip; + ip4_hdr.ip_dst = xform->tunnel.ipv4.dst_ip; + ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)&ip4_hdr, + sizeof(struct ip)); + + /* For Sec Proto only one descriptor is required. */ + memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb)); + encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) | + PDBOPTS_ESP_OIHI_PDB_INL | + PDBOPTS_ESP_IVSRC | + PDBHMO_ESP_ENCAP_DTTL; + encap_pdb.spi = xform->spi; + encap_pdb.ip_hdr_len = sizeof(struct ip); + + session->dir = DIR_ENC; + bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc, + 1, 0, &encap_pdb, + (uint8_t *)&ip4_hdr, + &cipherdata, &authdata); + } else if (xform->op == RTE_SECURITY_IPSEC_OP_DECAP) { + flc->dhr = SEC_FLC_DHR_INBOUND; + memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb)); + decap_pdb.options = sizeof(struct ip) << 16; + session->dir = DIR_DEC; + bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc, 1, 0, + &decap_pdb, &cipherdata, &authdata); + } else + goto out; + flc->word1_sdl = (uint8_t)bufsize; +//#if !defined(BUILD_LS2080) && !defined(BUILD_LS2085) + /*Enable the stashing control bit*/ + DPAA2_SET_FLC_RSC(flc); + flc->word2_rflc_31_0 = lower_32_bits( + (uint64_t)&(((struct dpaa2_sec_qp *) + dev->data->queue_pairs[0])->rx_vq) | 0x14); + flc->word3_rflc_63_32 = upper_32_bits( + (uint64_t)&(((struct dpaa2_sec_qp *) + dev->data->queue_pairs[0])->rx_vq)); +//#endif + /* Set EWS bit i.e. enable write-safe */ + DPAA2_SET_FLC_EWS(flc); + /* Set BS = 1 i.e reuse input buffers as output buffers */ + DPAA2_SET_FLC_REUSE_BS(flc); + /* Set FF = 10 (bit) + Reuse input buffers if they provide sufficient space */ + DPAA2_SET_FLC_REUSE_FF(flc); + +// for (i = 0;i < bufsize; i++) +// printf("\nDESC[%u]: %x",i,priv->flc_desc[0].desc[i]); +// for (i = 0;i < 16;i++) +// printf("\nFLC[%u]: %x",i,((uint32_t *)flc)[i]); + session->ctxt = priv; + return 0; +out: + rte_free(session->auth_key.data); + rte_free(session->cipher_key.data); + rte_free(priv); + return -1; +} + + +static int +dpaa2_sec_security_session_configure(struct rte_cryptodev *dev, + struct rte_security_sess_conf *conf, + struct rte_security_session *sess, + struct rte_mempool *mempool) +{ + void *sess_private_data; + int ret; + + if (rte_mempool_get(mempool, &sess_private_data)) { + CDEV_LOG_ERR( + "Couldn't get object from session mempool"); + return -ENOMEM; + } + + switch (conf->protocol) { + case RTE_SEC_CONF_IPSEC: + ret = dpaa2_sec_set_ipsec_session(dev, conf->ipsec_xform, + sess_private_data); + break; + case RTE_SEC_CONF_DTLS: + case RTE_SEC_CONF_MACSEC: + return -ENOTSUP; + default: + return -EINVAL; + } + if (ret != 0) { + PMD_DRV_LOG(ERR, "DPAA2 PMD: failed to configure " + "session parameters"); + + /* Return session to mempool */ + rte_mempool_put(mempool, sess_private_data); + return ret; + } + + set_sec_session_private_data(sess, dev->driver_id, + sess_private_data); + + return ret; +} + +/** Clear the memory of session so it doesn't leave key material behind */ +static void +dpaa2_sec_security_session_clear(struct rte_cryptodev *dev, + struct rte_security_session *sess) +{ + PMD_INIT_FUNC_TRACE(); + uint8_t index = dev->driver_id; + void *sess_priv = get_sec_session_private_data(sess, index); + dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv; + + if (sess_priv) { + rte_free(s->ctxt); + rte_free(s->cipher_key.data); + rte_free(s->auth_key.data); + memset(sess, 0, sizeof(dpaa2_sec_session)); + struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv); + set_sec_session_private_data(sess, index, NULL); + rte_mempool_put(sess_mp, sess_priv); + } +} + +static int dpaa2_sec_session_configure(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform, struct rte_cryptodev_sym_session *sess, @@ -1820,6 +2177,12 @@ static struct rte_cryptodev_ops crypto_ops = { .session_clear = dpaa2_sec_session_clear, }; +static struct rte_security_ops security_ops = { + .session_configure = dpaa2_sec_security_session_configure, + .session_clear = dpaa2_sec_security_session_clear, +}; + + static int dpaa2_sec_uninit(const struct rte_cryptodev *dev) { @@ -1855,6 +2218,7 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev) cryptodev->driver_id = cryptodev_driver_id; cryptodev->dev_ops = &crypto_ops; + cryptodev->sec_ops = &security_ops; cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst; cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst; diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h b/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h index 3849a05..99f20c9 100644 --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h @@ -67,6 +67,11 @@ enum shr_desc_type { #define DIR_ENC 1 #define DIR_DEC 0 +#define DPAA2_SET_FLC_EWS(flc) flc->word1_bits23_16 |= 0x1 +#define DPAA2_SET_FLC_RSC(flc) (flc->word1_bits31_24 |= 0x1) +#define DPAA2_SET_FLC_REUSE_BS(flc) flc->mode_bits |= 0x8000 +#define DPAA2_SET_FLC_REUSE_FF(flc) flc->mode_bits |= 0x2000 + /* SEC Flow Context Descriptor */ struct sec_flow_context { /* word 0 */ @@ -411,4 +416,32 @@ static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = { RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; +/** + * Checksum + * + * @param buffer calculate chksum for buffer + * @param len buffer length + * + * @return checksum value in host cpu order + */ +static inline uint16_t calc_chksum(void *buffer, int len) +{ + uint16_t *buf = (uint16_t *)buffer; + uint32_t sum = 0; + uint16_t result; + + for (sum = 0; len > 1; len -= 2) + sum += *buf++; + + if (len == 1) + sum += *(unsigned char *)buf; + + sum = (sum >> 16) + (sum & 0xFFFF); + sum += (sum >> 16); + result = ~sum; + + return result; +} + + #endif /* _RTE_DPAA2_SEC_PMD_PRIVATE_H_ */ -- 2.9.3