From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20051.outbound.protection.outlook.com [40.107.2.51]) by dpdk.org (Postfix) with ESMTP id 331101B3DA for ; Mon, 22 Oct 2018 16:57:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6Pa50VJ+J5K4EosDUD5xYNhFZzMSyzyGArwa3CBVbYY=; b=JHLVg7Y1+YY+Xh3lbptftRC2wUAyJbGLTG2jPmy4eHlgG9PqGNidDtOjeZT7CcH5Vmi+B0XFK6a+Jou0b9pT1fwdijV+oQuOkftsmNQb2zsT4qMwsubXMYiMCV4ZdSnjSb3jrwY2SyXr4sq7B/NNSI+Vp+Xkow9nVKrdfzTzwIY= Received: from HE1PR04MB1530.eurprd04.prod.outlook.com (10.164.48.20) by HE1PR04MB1305.eurprd04.prod.outlook.com (10.162.249.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.30; Mon, 22 Oct 2018 14:57:39 +0000 Received: from HE1PR04MB1530.eurprd04.prod.outlook.com ([fe80::95cd:198:d5c5:59a4]) by HE1PR04MB1530.eurprd04.prod.outlook.com ([fe80::95cd:198:d5c5:59a4%5]) with mapi id 15.20.1250.028; Mon, 22 Oct 2018 14:57:39 +0000 From: Gagandeep Singh To: "dev@dpdk.org" , Akhil Goyal CC: Gagandeep Singh , Hemant Agrawal Thread-Topic: [PATCH v5 08/15] crypto/caam_jr: add session configuration methods Thread-Index: AQHUaheTIpF62NEPYkiOkZNF1drjeQ== Date: Mon, 22 Oct 2018 14:57:39 +0000 Message-ID: <20181022145644.29277-9-g.singh@nxp.com> References: <20181022141657.4727-1-g.singh@nxp.com> <20181022145644.29277-1-g.singh@nxp.com> In-Reply-To: <20181022145644.29277-1-g.singh@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BM1PR0101CA0067.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:19::29) To HE1PR04MB1530.eurprd04.prod.outlook.com (2a01:111:e400:59a8::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [14.142.187.166] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR04MB1305; 6:4/qFFjdeeX/frG63MfiERKOh9hvmXVy8Jvky6kpJcMNOxDlE5FN+J/eG0EwLC+siIcQ2PRf5g3FjQYWB5Gc/8UWA6k73mwSUvSqHbDN8QphUKWho6Gs9SUo5D9/CnhUEoxKZD60HuuxdzNGzf86MUI551DnY1CnwVbq34HsLLC/XMawrFWqphlM7XbvDBuOAZG5vBwG29/IdCYvQxCwtThhVUNQMyRNhfBXexgmhp3+6XMq4kmBXJgaqSP7ti940mEXj9OdQa8X0scL+K8Eh/b2RQlNZEDkoT0VcW8V/SPEM4tWB0ymnBbwHoYA5UT/fiIDoRClWPfe01C8r2Y4ED+2WtylA88M3UJAlNEPKcuBpdyD9eLJ0DstU6zdVpMLO/9i0S4ZgmU9NgYkGvZ4BJSuGG8gtg1CC03Y+v95bObq1Ctw1rvjFkxc2/RV4+Krj6pJmKP9nDH2OMCwOnqLG2A==; 5:DUv2qF0/omcM7Lb+2Nvv747QMEz36lQkSrh3uy0QL6s0vXXazgdhMKMb3NSZT9/TndhM7CfcRQb+TU7bDi0mNgviWIq6AG/29OhtBDec5WUSecBLZ2NQ07C7EmfFDO+KsTx4Y+WyfO6E1OxHNIcTs78VAqvQ1+PI7a/slqJYqS8=; 7:fP1H/Bfc3og4UxU/Z8Wj0P6+WC9QpfhMyd4zKidwebCo/uoESBla+MREmk8QM9pv8F9liny4YT4KF1JzwyJUvbA72OViuqSkrB5tUbGW1gyyHsbukfkOgFS/v2gRbSw7GbHtHvfVWJ87mpYQi9vEE1OqMBxBE8X1xKIgchF4Q5QygRsElafJH6JCEKTLKEuJ/hHQEQ0QUBIewUBm5FFUueZUMa3WflPDJ2Qs2hQmNULKIvXPmLuFFHwJbStgLYqk x-ms-office365-filtering-correlation-id: dd3766ed-b3ea-4565-4fe9-08d6382eb591 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB1305; x-ms-traffictypediagnostic: HE1PR04MB1305: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(185117386973197); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:HE1PR04MB1305; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB1305; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(396003)(136003)(366004)(346002)(199004)(189003)(8676002)(256004)(81156014)(81166006)(11346002)(476003)(99286004)(446003)(316002)(52116002)(2616005)(486006)(106356001)(8936002)(105586002)(186003)(71200400001)(5250100002)(78486010)(3846002)(2501003)(71190400001)(25786009)(2900100001)(305945005)(7736002)(97736004)(478600001)(4326008)(2906002)(72206003)(6636002)(53936002)(14454004)(66066001)(6512007)(5660300001)(6116002)(1076002)(6436002)(6486002)(36756003)(14444005)(54906003)(6506007)(76176011)(55236004)(386003)(68736007)(26005)(86362001)(102836004)(110136005); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB1305; H:HE1PR04MB1530.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: zn85aN/YKkwWWU6gyMfXNxWBIpscHqthZU/RaNMJsa18e4WHXTgqtRIHBWGV4opTf+Irxz5mTgyo0jUmxGKaHd+r6bm96IR/fYwNn1ELCtGVoSzIVSLyVcFB9QgjebbniiZx3/X41jqR3vHtOijl8DBuk6zhOmmkwVIniU1C3oq0fdSQOBXJPovQaeqKNafX0g1CsQxKEHJxtE109yDDBCQTm0XcWcVl69O4cv565Bw8EK1Yyg5e2FuqzbphoWJIWmDmbe8b1iLnkg4fIWheRvEGMsaDd4awWQVvlrqPnaOlGCSbsA2n6UNLERZgyUlid3zYNYTT1wIUS/rnpFXgjqcPvrGFMCPV3jbdmLZ28Mc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd3766ed-b3ea-4565-4fe9-08d6382eb591 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 14:57:39.0418 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB1305 Subject: [dpdk-dev] [PATCH v5 08/15] crypto/caam_jr: add session configuration methods 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: Mon, 22 Oct 2018 14:57:42 -0000 This patch add support to create session configuration of various types i.e. cipher, auth and aead etc. Signed-off-by: Gagandeep Singh Signed-off-by: Hemant Agrawal Acked-by: Akhil Goyal --- drivers/crypto/caam_jr/caam_jr.c | 214 +++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam= _jr.c index 931070bef..aec033649 100644 --- a/drivers/crypto/caam_jr/caam_jr.c +++ b/drivers/crypto/caam_jr/caam_jr.c @@ -23,8 +23,11 @@ =20 /* RTA header files */ #include +#include +#include #include =20 +#define CAAM_JR_DBG 0 #define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr static uint8_t cryptodev_driver_id; int caam_jr_logtype; @@ -158,6 +161,214 @@ caam_jr_queue_pair_count(struct rte_cryptodev *dev) return dev->data->nb_queue_pairs; } =20 +/* Returns the size of the aesni gcm session structure */ +static unsigned int +caam_jr_sym_session_get_size(struct rte_cryptodev *dev __rte_unused) +{ + PMD_INIT_FUNC_TRACE(); + + return sizeof(struct caam_jr_session); +} + +static int +caam_jr_cipher_init(struct rte_cryptodev *dev __rte_unused, + struct rte_crypto_sym_xform *xform, + struct caam_jr_session *session) +{ + PMD_INIT_FUNC_TRACE(); + session->cipher_alg =3D xform->cipher.algo; + session->iv.length =3D xform->cipher.iv.length; + session->iv.offset =3D xform->cipher.iv.offset; + session->cipher_key.data =3D rte_zmalloc(NULL, xform->cipher.key.length, + RTE_CACHE_LINE_SIZE); + if (session->cipher_key.data =3D=3D NULL && xform->cipher.key.length > 0)= { + CAAM_JR_ERR("No Memory for cipher key\n"); + return -ENOMEM; + } + session->cipher_key.length =3D xform->cipher.key.length; + + memcpy(session->cipher_key.data, xform->cipher.key.data, + xform->cipher.key.length); + session->dir =3D (xform->cipher.op =3D=3D RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? + DIR_ENC : DIR_DEC; + + return 0; +} + +static int +caam_jr_auth_init(struct rte_cryptodev *dev __rte_unused, + struct rte_crypto_sym_xform *xform, + struct caam_jr_session *session) +{ + PMD_INIT_FUNC_TRACE(); + session->auth_alg =3D xform->auth.algo; + session->auth_key.data =3D rte_zmalloc(NULL, xform->auth.key.length, + RTE_CACHE_LINE_SIZE); + if (session->auth_key.data =3D=3D NULL && xform->auth.key.length > 0) { + CAAM_JR_ERR("No Memory for auth key\n"); + return -ENOMEM; + } + session->auth_key.length =3D xform->auth.key.length; + session->digest_length =3D xform->auth.digest_length; + + memcpy(session->auth_key.data, xform->auth.key.data, + xform->auth.key.length); + session->dir =3D (xform->auth.op =3D=3D RTE_CRYPTO_AUTH_OP_GENERATE) ? + DIR_ENC : DIR_DEC; + + return 0; +} + +static int +caam_jr_aead_init(struct rte_cryptodev *dev __rte_unused, + struct rte_crypto_sym_xform *xform, + struct caam_jr_session *session) +{ + PMD_INIT_FUNC_TRACE(); + session->aead_alg =3D xform->aead.algo; + session->iv.length =3D xform->aead.iv.length; + session->iv.offset =3D xform->aead.iv.offset; + session->auth_only_len =3D xform->aead.aad_length; + session->aead_key.data =3D rte_zmalloc(NULL, xform->aead.key.length, + RTE_CACHE_LINE_SIZE); + if (session->aead_key.data =3D=3D NULL && xform->aead.key.length > 0) { + CAAM_JR_ERR("No Memory for aead key\n"); + return -ENOMEM; + } + session->aead_key.length =3D xform->aead.key.length; + session->digest_length =3D xform->aead.digest_length; + + memcpy(session->aead_key.data, xform->aead.key.data, + xform->aead.key.length); + session->dir =3D (xform->aead.op =3D=3D RTE_CRYPTO_AEAD_OP_ENCRYPT) ? + DIR_ENC : DIR_DEC; + + return 0; +} + +static int +caam_jr_set_session_parameters(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, void *sess) +{ + struct sec_job_ring_t *internals =3D dev->data->dev_private; + struct caam_jr_session *session =3D sess; + + PMD_INIT_FUNC_TRACE(); + + if (unlikely(sess =3D=3D NULL)) { + CAAM_JR_ERR("invalid session struct"); + return -EINVAL; + } + + /* Default IV length =3D 0 */ + session->iv.length =3D 0; + + /* Cipher Only */ + if (xform->type =3D=3D RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next =3D=3D = NULL) { + session->auth_alg =3D RTE_CRYPTO_AUTH_NULL; + caam_jr_cipher_init(dev, xform, session); + + /* Authentication Only */ + } else if (xform->type =3D=3D RTE_CRYPTO_SYM_XFORM_AUTH && + xform->next =3D=3D NULL) { + session->cipher_alg =3D RTE_CRYPTO_CIPHER_NULL; + caam_jr_auth_init(dev, xform, session); + + /* Cipher then Authenticate */ + } else if (xform->type =3D=3D RTE_CRYPTO_SYM_XFORM_CIPHER && + xform->next->type =3D=3D RTE_CRYPTO_SYM_XFORM_AUTH) { + if (xform->cipher.op =3D=3D RTE_CRYPTO_CIPHER_OP_ENCRYPT) { + caam_jr_cipher_init(dev, xform, session); + caam_jr_auth_init(dev, xform->next, session); + } else { + CAAM_JR_ERR("Not supported: Auth then Cipher"); + goto err1; + } + + /* Authenticate then Cipher */ + } else if (xform->type =3D=3D RTE_CRYPTO_SYM_XFORM_AUTH && + xform->next->type =3D=3D RTE_CRYPTO_SYM_XFORM_CIPHER) { + if (xform->next->cipher.op =3D=3D RTE_CRYPTO_CIPHER_OP_DECRYPT) { + caam_jr_auth_init(dev, xform, session); + caam_jr_cipher_init(dev, xform->next, session); + } else { + CAAM_JR_ERR("Not supported: Auth then Cipher"); + goto err1; + } + + /* AEAD operation for AES-GCM kind of Algorithms */ + } else if (xform->type =3D=3D RTE_CRYPTO_SYM_XFORM_AEAD && + xform->next =3D=3D NULL) { + caam_jr_aead_init(dev, xform, session); + + } else { + CAAM_JR_ERR("Invalid crypto type"); + return -EINVAL; + } + session->ctx_pool =3D internals->ctx_pool; + + return 0; + +err1: + rte_free(session->cipher_key.data); + rte_free(session->auth_key.data); + memset(session, 0, sizeof(struct caam_jr_session)); + + return -EINVAL; +} + +static int +caam_jr_sym_session_configure(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *sess, + struct rte_mempool *mempool) +{ + void *sess_private_data; + int ret; + + PMD_INIT_FUNC_TRACE(); + + if (rte_mempool_get(mempool, &sess_private_data)) { + CAAM_JR_ERR("Couldn't get object from session mempool"); + return -ENOMEM; + } + + memset(sess_private_data, 0, sizeof(struct caam_jr_session)); + ret =3D caam_jr_set_session_parameters(dev, xform, sess_private_data); + if (ret !=3D 0) { + CAAM_JR_ERR("failed to configure session parameters"); + /* Return session to mempool */ + rte_mempool_put(mempool, sess_private_data); + return ret; + } + + set_sym_session_private_data(sess, dev->driver_id, sess_private_data); + + return 0; +} + +/* Clear the memory of session so it doesn't leave key material behind */ +static void +caam_jr_sym_session_clear(struct rte_cryptodev *dev, + struct rte_cryptodev_sym_session *sess) +{ + uint8_t index =3D dev->driver_id; + void *sess_priv =3D get_sym_session_private_data(sess, index); + struct caam_jr_session *s =3D (struct caam_jr_session *)sess_priv; + + PMD_INIT_FUNC_TRACE(); + + if (sess_priv) { + struct rte_mempool *sess_mp =3D rte_mempool_from_obj(sess_priv); + + rte_free(s->cipher_key.data); + rte_free(s->auth_key.data); + memset(s, 0, sizeof(struct caam_jr_session)); + set_sym_session_private_data(sess, index, NULL); + rte_mempool_put(sess_mp, sess_priv); + } +} + static int caam_jr_dev_configure(struct rte_cryptodev *dev, struct rte_cryptodev_config *config __rte_unused) @@ -241,6 +452,9 @@ static struct rte_cryptodev_ops caam_jr_ops =3D { .queue_pair_setup =3D caam_jr_queue_pair_setup, .queue_pair_release =3D caam_jr_queue_pair_release, .queue_pair_count =3D caam_jr_queue_pair_count, + .sym_session_get_size =3D caam_jr_sym_session_get_size, + .sym_session_configure =3D caam_jr_sym_session_configure, + .sym_session_clear =3D caam_jr_sym_session_clear }; =20 =20 --=20 2.17.1