From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40053.outbound.protection.outlook.com [40.107.4.53]) by dpdk.org (Postfix) with ESMTP id 054FD1B11A for ; Mon, 22 Oct 2018 16:17:50 +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=GV0FnDlIlu+IY6QERZdPAstpiRnqtNrV7ufO9OgaNUQ/+xRhOhc14nVoKKwuoPA9ddZ7tjMIctKRLs7K3CJ1RY4iMDhzqLzzZYANzieI4HKnbd2Dyj+dKMXat9NnfumfHctBKbY6DM01DKs9G7+CMFtUfqiB0eGpIkcGY4DTSAc= Received: from HE1PR04MB1530.eurprd04.prod.outlook.com (10.164.48.20) by HE1PR04MB3242.eurprd04.prod.outlook.com (10.170.251.154) 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:17:50 +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:17:50 +0000 From: Gagandeep Singh To: "dev@dpdk.org" , Akhil Goyal CC: Gagandeep Singh , Hemant Agrawal Thread-Topic: [PATCH v4 08/15] crypto/caam_jr: add session configuration methods Thread-Index: AQHUahIDpbmk7X2x0U+ezyRujhUKxg== Date: Mon, 22 Oct 2018 14:17:49 +0000 Message-ID: <20181022141657.4727-9-g.singh@nxp.com> References: <20181022133021.11264-1-g.singh@nxp.com> <20181022141657.4727-1-g.singh@nxp.com> In-Reply-To: <20181022141657.4727-1-g.singh@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BM1PR0101CA0025.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::11) To HE1PR04MB1530.eurprd04.prod.outlook.com (2a01:111:e400:59a8::20) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [14.142.187.166] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR04MB3242; 6:c5S5nRba3PhKFXkYhwAu30NAEFZcREW9Pf9pEBv5k5wyBBZqZk+yTQ6sxoz+EwZqX+GzNCAHmtWJnfGmWOIYF4WZ/TOwQyi2z9Gf7HoOJH/gQRncxgIkcM84PlyD/F6FUajgNMaxuJwupIxN8S57nersZUmGUodR0dj/175PjQspiFb/vw55uu90cX/UiHN6jXn2tQZ3J4mgSuEfjxepFlIyPzUJiffP5mfC2t+lqorbdSQjIWQjgVnbaxx42lQzqA1MncAmjw6TzqNzRM+dPCPyNt2Yk6EinwXXrHyrzOMuxmrPUE5QU/WJH1GZtB7/4DRpdac1MTs9jnQZ4/59ovvjW9duu0Dwl6RNbsQPUWjNWuJP90z9chPDD1d3LcUAi7voFy/UR9cMHLsHMw/0jamC1F75bhrSnRgUlfegaoDPhRcrgs3LcTeIyJrvzCavGrGpHTlRMHVozOn/Vl1i6A==; 5:ny6nrwXlWWFwXaRA0vuSWY8NNrDhHS28uWqENG6bUUAtrnWeP+BwqMreSY5vxUwZmtVHiBu24ax6L4IBKA7ynSoDyLFpMQdoakQ1QOeBjFze0Fcq1SzPMq0PlY9TdppigmblDXeJVJUcFGgL0yHeaDTJjKcO3BZOmFxIMUADsGc=; 7:f0Q6uZxfzbjpt4/o6zPDk/2V7/umRmvU4WCyjjnHRxpJV0ftl9aD2VfR0Q48u8VMW/kjuplbiBmS0Rmdi4NVUvypVK8RAlBKWmmeet4eWvK12c8eedA6QZopWYah0v/t+vBdHXmmNZDxTF0NcBAXOc9M5bhyDIvAPi9W+UykC7wwOtXtNMyOQ7O9zzQiBQM+Axt07mLpxQFiaEv9We4W6+qUiRxT1m5+w5E3QmpqlyH6pHxi1z13Fs71TpNAu4v0 x-ms-office365-filtering-correlation-id: fb08a338-2ca6-4efa-df0d-08d638292579 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB3242; x-ms-traffictypediagnostic: HE1PR04MB3242: 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)(8121501046)(5005006)(3002001)(3231355)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:HE1PR04MB3242; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB3242; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(136003)(396003)(376002)(346002)(39860400002)(199004)(189003)(86362001)(68736007)(72206003)(1076002)(3846002)(6116002)(5660300001)(71200400001)(71190400001)(110136005)(54906003)(105586002)(78486010)(106356001)(6636002)(2906002)(7736002)(8936002)(305945005)(478600001)(81166006)(316002)(81156014)(8676002)(4326008)(25786009)(2900100001)(476003)(53936002)(66066001)(6486002)(14444005)(446003)(6436002)(6512007)(99286004)(52116002)(76176011)(36756003)(14454004)(256004)(6346003)(97736004)(2616005)(11346002)(486006)(186003)(26005)(2501003)(5250100002)(55236004)(102836004)(6506007)(386003); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB3242; 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) authentication-results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; x-microsoft-antispam-message-info: +n1PJ/RkXGEHyRO+eEXkC04U9VhapGD3WzaWDT2DwrGvVJlDCwFAW5ohoMi8Y/Si+oZPXVgY4X2GOe7TVgsQwRzGH/VfYTI7hhBTZ2Ciy8iLBKApxHEbuvUdYlbpUazP/Jt0q4wMNYibrMEcD2RoHEo9HDg4fvTQr8tXnc+P8LUTtL0xRW5tYhoJ/5FgVgcDASUeBjcI+EZmrZn1qLVXZMP9wkDAaAjHmPhthY0XT3bMr8h1oOmGaNiRdn/CjVcH8t25/hXg6fgNfqbZROIcCGK7c5q0lagmgYal0aX6VQWn1bM1PUa2oA1yEInnuwAdkt3134ljb8YcNMZmig/OgqL+vZpP65kZ38lEK13LmQU= 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: fb08a338-2ca6-4efa-df0d-08d638292579 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 14:17:49.9217 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB3242 Subject: [dpdk-dev] [PATCH v4 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:17:51 -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