From: Gagandeep Singh <g.singh@nxp.com>
To: dev@dpdk.org, akhil.goyal@nxp.com
Cc: Gagandeep Singh <g.singh@nxp.com>,
Hemant Agrawal <hemant.agrawal@nxp.com>
Subject: [dpdk-dev] [PATCH v2 09/14] crypto/caam_jr: add session configuration methods
Date: Fri, 12 Oct 2018 20:10:50 +0530 [thread overview]
Message-ID: <20181012144055.9461-10-g.singh@nxp.com> (raw)
In-Reply-To: <20181012144055.9461-1-g.singh@nxp.com>
This patch add support to create session configuration
of various types i.e. cipher, auth and aead etc.
Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
drivers/crypto/caam_jr/caam_jr.c | 215 +++++++++++++++++++++++++++++++
1 file changed, 215 insertions(+)
diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam_jr.c
index 78bc75f69..f6c2565cf 100644
--- a/drivers/crypto/caam_jr/caam_jr.c
+++ b/drivers/crypto/caam_jr/caam_jr.c
@@ -24,8 +24,11 @@
/* RTA header files */
#include <hw/desc/common.h>
+#include <hw/desc/algo.h>
+#include <hw/desc/ipsec.h>
#include <of.h>
+#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;
}
+/* 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 = xform->cipher.algo;
+ session->iv.length = xform->cipher.iv.length;
+ session->iv.offset = xform->cipher.iv.offset;
+ 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) {
+ CAAM_JR_ERR("No Memory for cipher key\n");
+ return -ENOMEM;
+ }
+ session->cipher_key.length = xform->cipher.key.length;
+
+ memcpy(session->cipher_key.data, xform->cipher.key.data,
+ xform->cipher.key.length);
+ session->dir = (xform->cipher.op == 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 = xform->auth.algo;
+ 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) {
+ CAAM_JR_ERR("No Memory for auth key\n");
+ return -ENOMEM;
+ }
+ session->auth_key.length = xform->auth.key.length;
+ session->digest_length = xform->auth.digest_length;
+
+ memcpy(session->auth_key.data, xform->auth.key.data,
+ xform->auth.key.length);
+ session->dir = (xform->auth.op == 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 = xform->aead.algo;
+ session->iv.length = xform->aead.iv.length;
+ session->iv.offset = xform->aead.iv.offset;
+ session->auth_only_len = xform->aead.aad_length;
+ session->aead_key.data = rte_zmalloc(NULL, xform->aead.key.length,
+ RTE_CACHE_LINE_SIZE);
+ if (session->aead_key.data == NULL && xform->aead.key.length > 0) {
+ CAAM_JR_ERR("No Memory for aead key\n");
+ return -ENOMEM;
+ }
+ session->aead_key.length = xform->aead.key.length;
+ session->digest_length = xform->aead.digest_length;
+
+ memcpy(session->aead_key.data, xform->aead.key.data,
+ xform->aead.key.length);
+ session->dir = (xform->aead.op == 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 = dev->data->dev_private;
+ struct caam_jr_session *session = sess;
+
+ PMD_INIT_FUNC_TRACE();
+
+ if (unlikely(sess == NULL)) {
+ CAAM_JR_ERR("invalid session struct");
+ return -EINVAL;
+ }
+
+ /* Default IV length = 0 */
+ session->iv.length = 0;
+
+ /* Cipher Only */
+ if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
+ session->auth_alg = RTE_CRYPTO_AUTH_NULL;
+ caam_jr_cipher_init(dev, xform, session);
+
+ /* Authentication Only */
+ } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
+ xform->next == NULL) {
+ session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
+ caam_jr_auth_init(dev, xform, session);
+
+ /* Cipher then Authenticate */
+ } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
+ xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
+ if (xform->cipher.op == 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 == RTE_CRYPTO_SYM_XFORM_AUTH &&
+ xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
+ if (xform->next->cipher.op == 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 == RTE_CRYPTO_SYM_XFORM_AEAD &&
+ xform->next == NULL) {
+ caam_jr_aead_init(dev, xform, session);
+
+ } else {
+ CAAM_JR_ERR("Invalid crypto type");
+ return -EINVAL;
+ }
+ session->ctx_pool = 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 = caam_jr_set_session_parameters(dev, xform, sess_private_data);
+ if (ret != 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 = dev->driver_id;
+ void *sess_priv = get_sym_session_private_data(sess, index);
+ struct caam_jr_session *s = (struct caam_jr_session *)sess_priv;
+
+ PMD_INIT_FUNC_TRACE();
+
+ if (sess_priv) {
+ struct rte_mempool *sess_mp = 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)
@@ -228,6 +439,7 @@ caam_jr_dev_infos_get(struct rte_cryptodev *dev,
if (info != NULL) {
info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
info->feature_flags = dev->feature_flags;
+ info->capabilities = caam_jr_get_cryptodev_capabilities();
info->sym.max_nb_sessions = internals->max_nb_sessions;
info->driver_id = cryptodev_driver_id;
}
@@ -242,6 +454,9 @@ static struct rte_cryptodev_ops caam_jr_ops = {
.queue_pair_setup = caam_jr_queue_pair_setup,
.queue_pair_release = caam_jr_queue_pair_release,
.queue_pair_count = caam_jr_queue_pair_count,
+ .sym_session_get_size = caam_jr_sym_session_get_size,
+ .sym_session_configure = caam_jr_sym_session_configure,
+ .sym_session_clear = caam_jr_sym_session_clear
};
--
2.17.1
next prev parent reply other threads:[~2018-10-12 14:41 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-13 6:08 [dpdk-dev] [PATCH 00/10] Introducing the NXP CAAM job ring driver Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 01/10] doc: add caam jr cryptodev details Gagandeep Singh
2018-09-18 12:27 ` Akhil Goyal
2018-10-12 13:29 ` Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 02/10] crypto/caam_jr: introduce basic driver Gagandeep Singh
2018-09-18 12:13 ` Akhil Goyal
2018-10-12 13:15 ` Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 03/10] crypto/caam_jr: add HW config for job rings Gagandeep Singh
2018-09-18 13:37 ` Akhil Goyal
2018-10-12 13:32 ` Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 04/10] crypto/caam_jr: add device configuration routines Gagandeep Singh
2018-09-18 13:59 ` Akhil Goyal
2018-10-12 13:38 ` Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 05/10] crypto/caam_jr: add queue config functions Gagandeep Singh
2018-09-18 14:04 ` Akhil Goyal
2018-10-12 13:39 ` Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 06/10] crypto/caam_jr: add basic session config routines Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 07/10] crypto/caam_jr: add enqueue and dequeue routines Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 08/10] crypto/caam_jr: add auth cipher and aead session support Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 09/10] crypto/caam_jr: add stats support Gagandeep Singh
2018-09-13 6:08 ` [dpdk-dev] [PATCH 10/10] crypto/caam_jr: add security offload support Gagandeep Singh
2018-09-18 14:21 ` [dpdk-dev] [PATCH 00/10] Introducing the NXP CAAM job ring driver Akhil Goyal
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 00/14] " Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 01/14] crypto/caam_jr: introduce basic driver Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 02/14] crypto/caam_jr: add HW tuning options Gagandeep Singh
2018-10-19 9:11 ` Thomas Monjalon
2018-10-22 12:31 ` Gagandeep Singh
2018-10-22 13:32 ` Ali Alnubani
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 03/14] crypto/caam_jr: add routines to configure HW Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 04/14] crypto/caam_jr: add UIO specific operations Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 05/14] crypto/caam_jr: add basic job ring routines Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 06/14] crypto/caam_jr: add device basic ops Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 07/14] crypto/caam_jr: add queue pair config ops Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 08/14] crypto/caam_jr: add device cababilities Gagandeep Singh
2018-10-12 14:40 ` Gagandeep Singh [this message]
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 10/14] crypto/caam_jr: add enqueue dequeue operations Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 11/14] crypto/caam_jr: add scatter gather Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 12/14] crypto/caam_jr: add statistics ops Gagandeep Singh
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 13/14] crypto/caam_jr: add security offload Gagandeep Singh
2018-10-19 2:17 ` Thomas Monjalon
2018-10-22 9:26 ` Thomas Monjalon
2018-10-22 10:31 ` Hemant Agrawal
2018-10-12 14:40 ` [dpdk-dev] [PATCH v2 14/14] doc: add caam jr cryptodev details Gagandeep Singh
2018-10-16 12:58 ` [dpdk-dev] [PATCH v2 00/14] Introducing the NXP CAAM job ring driver Akhil Goyal
2018-10-16 14:34 ` Akhil Goyal
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 00/15] " Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 01/15] crypto/caam_jr: introduce basic driver Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 02/15] crypto/caam_jr: add HW tuning options Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 03/15] crypto/caam_jr: add routines to configure HW Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 04/15] crypto/caam_jr: add UIO specific operations Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 05/15] crypto/caam_jr: add basic job ring routines Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 06/15] crypto/caam_jr: add device basic ops Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 07/15] crypto/caam_jr: add queue pair config ops Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 08/15] crypto/caam_jr: add session configuration methods Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 09/15] crypto/caam_jr: add device cababilities Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 10/15] crypto/caam_jr: add enqueue dequeue operations Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 11/15] crypto/caam_jr: add scatter gather Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 12/15] crypto/caam_jr: add statistics ops Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 13/15] crypto/caam_jr: add security offload Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 14/15] doc: add caam jr cryptodev details Gagandeep Singh
2018-10-22 13:31 ` [dpdk-dev] [PATCH v3 15/15] test/crypto: add CAAM JR driver validation test cases Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 00/15] Introducing the NXP CAAM job ring driver Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 01/15] crypto/caam_jr: introduce basic driver Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 02/15] crypto/caam_jr: add HW tuning options Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 03/15] crypto/caam_jr: add routines to configure HW Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 04/15] crypto/caam_jr: add UIO specific operations Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 05/15] crypto/caam_jr: add basic job ring routines Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 06/15] crypto/caam_jr: add device basic ops Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 07/15] crypto/caam_jr: add queue pair config ops Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 08/15] crypto/caam_jr: add session configuration methods Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 09/15] crypto/caam_jr: add device cababilities Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 10/15] crypto/caam_jr: add enqueue dequeue operations Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 11/15] crypto/caam_jr: add scatter gather Gagandeep Singh
2018-10-22 14:17 ` [dpdk-dev] [PATCH v4 12/15] crypto/caam_jr: add statistics ops Gagandeep Singh
2018-10-22 14:18 ` [dpdk-dev] [PATCH v4 13/15] crypto/caam_jr: add security offload Gagandeep Singh
2018-10-22 14:18 ` [dpdk-dev] [PATCH v4 14/15] doc: add caam jr cryptodev details Gagandeep Singh
2018-10-22 14:18 ` [dpdk-dev] [PATCH v4 15/15] test/crypto: add CAAM JR driver validation test cases Gagandeep Singh
2018-10-22 14:48 ` [dpdk-dev] [PATCH v4 00/15] Introducing the NXP CAAM job ring driver Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 " Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 01/15] crypto/caam_jr: introduce basic driver Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 02/15] crypto/caam_jr: add HW tuning options Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 03/15] crypto/caam_jr: add routines to configure HW Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 04/15] crypto/caam_jr: add UIO specific operations Gagandeep Singh
2018-10-28 0:35 ` Ferruh Yigit
2018-10-29 12:24 ` Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 05/15] crypto/caam_jr: add basic job ring routines Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 06/15] crypto/caam_jr: add device basic ops Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 07/15] crypto/caam_jr: add queue pair config ops Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 08/15] crypto/caam_jr: add session configuration methods Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 09/15] crypto/caam_jr: add device cababilities Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 10/15] crypto/caam_jr: add enqueue dequeue operations Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 11/15] crypto/caam_jr: add scatter gather Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 12/15] crypto/caam_jr: add statistics ops Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 13/15] crypto/caam_jr: add security offload Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 14/15] doc: add caam jr cryptodev details Gagandeep Singh
2018-10-22 14:57 ` [dpdk-dev] [PATCH v5 15/15] test/crypto: add CAAM JR driver validation test cases Gagandeep Singh
2018-10-22 20:30 ` [dpdk-dev] [PATCH v5 00/15] Introducing the NXP CAAM job ring driver Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181012144055.9461-10-g.singh@nxp.com \
--to=g.singh@nxp.com \
--cc=akhil.goyal@nxp.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).