From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10075.outbound.protection.outlook.com [40.107.1.75]) by dpdk.org (Postfix) with ESMTP id 8A9245A6E for ; Mon, 22 Oct 2018 15:31:19 +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=TJUM47t1wMaW2XrvvCW09iuP2caLQ8WU7m/T6epL9So=; b=PQWgvB4zqsp9dcr4iEF6xAHbwmrvhRgw920f4CLF856DEXh/7H0TXmyTMDKk93+jaM4iLjiYUcXsPQQBJl0BvU52hxr5o8DJsJ7q/pbxtTTHrz21uPwO0ffm1RElSghsHof2R047juI4Q0p+6ytaIx7uL69GGIfHRVrMIWjp+/w= Received: from HE1PR04MB1530.eurprd04.prod.outlook.com (10.164.48.20) by HE1PR04MB3131.eurprd04.prod.outlook.com (10.171.196.142) 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 13:31:18 +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 13:31:18 +0000 From: Gagandeep Singh To: "dev@dpdk.org" , Akhil Goyal CC: Gagandeep Singh , Hemant Agrawal Thread-Topic: [PATCH v3 08/15] crypto/caam_jr: add session configuration methods Thread-Index: AQHUaguD/fHYI1SmKkeZPCrzofwWOA== Date: Mon, 22 Oct 2018 13:31:18 +0000 Message-ID: <20181022133021.11264-9-g.singh@nxp.com> References: <20181012144055.9461-1-g.singh@nxp.com> <20181022133021.11264-1-g.singh@nxp.com> In-Reply-To: <20181022133021.11264-1-g.singh@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BM1PR0101CA0016.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::26) 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; HE1PR04MB3131; 6:G6lJvA5qGC62Ze41yUdxxUsgC8Y+rZIxzMuXvQ47kW/o0DiCNk6mm8Kq/FtYbtd8Kp0osfAx3aI0EUWYrfRwXRzNPBjMvo1Mr1DbxfJUq5JWNFKuw8DREnjUBuES+WJwJW3EQvAemvOO6w8NFsMZD+maNkGg/IW1zpSfpJYdY089g0A9rCZbC9UTuRgSVbUPJ+KV5QeWMZH7PYIJA2r4ZlLZ/e+liYt7noZXSkeynFwVcdSZOjd7BJsHwJuHu6YhghbE7+vZHWBUr3d5FMgPi2g50Y/Sj2d3T2Vya2IytuSkvLhytv5eKdMONTEOMDNYa+aLJ1sfBZukkeSy8asoEGNzWXCc+0J497FtdQRGGhk/zDB7LDW8c/vozrkxvqh/rMXocDcXWfgzxOAcOY3w9EUHUyLJvBGnfylZb3kqZnPjMRKkOwjmvZSuJCc0hPzGS95Bf9urYS0JWDZ5NAYI6w==; 5:5IQPT/nndPGZSwn+548xfvyStmFqNQjNKs1D0ArICQwJjRKuvpx5/Cd/CSYcz+O2SJazrI+p+nLmNwKA4QRGOXXK2v8JIGMD8ixZ3xs9sYWnPevIOyJd5WYorUANzEXDvk7e6yRL1IsQnZxpNXISoHRuKalVr48WXMvTzwncA48=; 7:LlfvAXKrOW7FtGOsSc1+0G8bqnHkkmQjhGJ2hN13y58nwR4ZDupJIe+axQIbfD9ijMdoNKovAsQ9pwugw7z5+BwwAkG1bciEF7jQ0/6Xu4srN7JnWoBmX1NI7dZjH+4OpwrAeWgW2dztcCet3PmsE6fP41aFjYDci5enkwoFIRTs+5THgMEoSaD0oJAoLdPmWZjhRkkKYiCRm56ebHGzlSErObys5wDU4daJjlSKfetH5zXR8qQTaCLicpqzCIx/ x-ms-office365-filtering-correlation-id: 2f413434-f231-4d00-d161-08d63822a574 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB3131; x-ms-traffictypediagnostic: HE1PR04MB3131: 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:HE1PR04MB3131; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB3131; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(376002)(39860400002)(136003)(346002)(396003)(189003)(199004)(110136005)(99286004)(316002)(54906003)(81156014)(14454004)(25786009)(72206003)(81166006)(2900100001)(8936002)(106356001)(8676002)(6116002)(3846002)(86362001)(2616005)(476003)(6506007)(386003)(102836004)(1076002)(11346002)(446003)(26005)(186003)(305945005)(478600001)(4326008)(2906002)(76176011)(68736007)(7736002)(6636002)(97736004)(486006)(52116002)(36756003)(55236004)(105586002)(71190400001)(5660300001)(6436002)(6486002)(78486010)(53936002)(14444005)(2501003)(256004)(66066001)(71200400001)(5250100002)(6512007); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB3131; H:HE1PR04MB1530.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: liv9NnfmAYf2TqtFuEkDTyO96BAQ8JsmcEM/hbzQXxnuQVh4fxtjNoqpIjrIcj1B9WNL/qI9F6HS2rPuvxlSxriHdeQOYdHNIVh8kwckVTu56QA/LrdhhL/k9cCHwRsfSOeJiXim51oiXv1q6ffd44EkK7BWZsx5UCPFZjrdqI6ZpzMRui0kK8P9hYsvN9ukVgfugZWR/R/GLFgh0Sv82iRXrYMQvVgQicy4klmoDXthgZNcsWWD/+zcr6SQnL4ZtEo9f5oxJ3zl9R2YNLD52QZwoaY1QsXK0LH8oHC+L3+9VTRcVtQfnutl37OeBEHiqqpAaL5P2t+izbroAm3YIhaiJxRo0AqwRgijYOOfepc= 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: 2f413434-f231-4d00-d161-08d63822a574 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 13:31:18.1138 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB3131 Subject: [dpdk-dev] [PATCH v3 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 13:31:19 -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 78bc75f69..eedbeb731 100644 --- a/drivers/crypto/caam_jr/caam_jr.c +++ b/drivers/crypto/caam_jr/caam_jr.c @@ -24,8 +24,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; @@ -159,6 +162,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) @@ -242,6 +453,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