From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700073.outbound.protection.outlook.com [40.107.70.73]) by dpdk.org (Postfix) with ESMTP id 0743E1BB82 for ; Fri, 8 Jun 2018 18:49:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e8N+gFqXyyKGgp4qhnQv4GcJBS7tnikqC3Nc0sJrDcw=; b=oKmLAy0LHQv7xDvupIt6PKyK3w0O1Cl11nyj1etH3tfwweIUMeuoXM+bjP4xY/o3Hr5rrsH+wCyW/iVS/b9gC3yKAifl9kcYiokCVSapu2O4DqVKfs51e1wtvZyR+N24VQDIKkfByXAxwvzqKoHBGzDeqDEop6fDV5yJtvuOLfg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from ajoseph83.caveonetworks.com.caveonetworks.com (115.113.156.2) by SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Fri, 8 Jun 2018 16:49:31 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara , Thomas Monjalon Cc: Ragothaman Jayaraman , Ankur Dwivedi , Jerin Jacob , Murthy NSSR , Narayana Prasad , Nithin Dabilpuram , Srisivasubramanian Srinivasan , dev@dpdk.org Date: Fri, 8 Jun 2018 22:15:22 +0530 Message-Id: <1528476325-15585-14-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BM1PR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::11) To SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB4911; X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 3:WpZh2kde49myHua7C23n4WuDH7L+rjYAgjTthqFvSa7SEJWIId+fgME1iyzguiksjFyFzBUBuA5JfYHfu6H7ddlJrlcJXr31lJ20nvNXj8jV1fIxu/sS/3i+XAY0tjboxu7c3EJ7zO/HGX1+3VxtZSLSS8tPDuMYk/hgQ/fH0/SZNzipNr4bg+GG2Bg+9R/ujL1bj9NiZTd56VLZTyKNGjPitpAvKGWzftGdGdiRi6BKgBYqMLfM7vwqGhmbmjew; 25:7wgFQjmFlSPcJn4mL7X30D6q2EIWzmnFnNS6bxQkWOUQWkZpE/r6khtGnUA53MCP9rW9/4OJYcxOkYKK1848KkgE9KZbjigjK6dOyqBKMgdi9UJXEqNNZRKkcm8hPz72a8fhrAdBwSDRchaCRzVZY7JN8vrCQBV6usaxy7fVNMKnN4K6/4h80a9NxPekT3YVkIKIMKR2wgoh97ulknQfkgpmz9Xz7ZrkzKNgaWSnOra9aAT1Gplft+fiBSlVyOEQ1L8/H46kdqeY4w94ydLqnjW8l3rYPx+Wl4+fO7ujUwqELpriDnmuFE4A9vlceo0dtaaFRNsvDo5dHnKGIalK4w==; 31:D9XmssKzr2VIExXXh22roFuACemYdERV9onwaY/2fZ9CSp/IM/9/9uBfoD4kCLElEZYgW3DB13DRWhYdiG2WjXsBczzxb73v8bvOd0VThA+LdWeVxdp+WDV6xrVs1GMkganbP7AxrrMRlDZmA1knVfJfTFPeGcLiiraXcq3qWgQZ3UwjmqEi375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oft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(131327999870524); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(3002001)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN6PR07MB4911; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4911; X-Forefront-PRVS: 06973FFAD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(39380400002)(366004)(39860400002)(189003)(199004)(26005)(52116002)(956004)(305945005)(8676002)(81156014)(50226002)(8936002)(81166006)(7736002)(68736007)(105586002)(106356001)(3846002)(6116002)(72206003)(478600001)(6486002)(97736004)(6506007)(16586007)(6512007)(53936002)(47776003)(486006)(25786009)(5660300001)(50466002)(48376002)(6666003)(4326008)(54906003)(76176011)(36756003)(110136005)(66066001)(8656006)(2906002)(316002)(55236004)(11346002)(16526019)(386003)(186003)(59450400001)(446003)(476003)(42882007)(44832011)(2616005)(51416003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4911; H:ajoseph83.caveonetworks.com.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR07MB4911; 23:7AaOa9f9uC+P1qsVsBE52R4zXiez/BVa5SjbC1Xrv?= =?us-ascii?Q?n5z+4vJoiUWDtRYODFl1jBD7dYYcmV33EQbOZDtTqS98HMTcaSm/sOvsZB1A?= =?us-ascii?Q?S9wcwI/K3TeDUrTRsI6n9fqb0KfxnqcGwo3F5IESPNpkq9mgo0C/s5qfa6Vo?= =?us-ascii?Q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==; 5:YkPPIDAYoIlZoF5cHf9eMC+b7jLQ72huJz9mczrMNYF7U5nUT+zgYb0l3oh7meEEBBMEVW+PKL5bMXkRXe+viaXB6XF5hhau4zxZMrQenoiWScn6bLgr8gyLVr2gS9/zq6FISJf8fKl76xj+V8jvWQ/s3dRHP1tCUhI6vAnk7dM=; 24:nMV/QLcx07+N4PLhDaUq3u/UvDd20P/VwVIIKeTxRAVdP3CG1gsBJT8wV6FWubObSFUxvCKwE6WQ1cYusWeXcDayf5bCvw+Vddzkz+HVmLw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 7:fbNfdeXco/GCayiA+YOWfaLzo+N88snHGMAIEroXdt1vdoCxF1vAJ8Rzn3ErtXjtWOIemJfsh7MiwsVvikF8+a75CXPsyyntsb0CLyjkP+45o3JKlq3UFnOBmxpXHx6nlc/KbOFN3muPgqEk8EeMxlRL2G93zp55W9bsCsTk56vUmEdap0+ZgQXUCuGqtKT0/DcWYhxudyh1deY0fnA0bJ5dsNVYdI5HWETFQ1H3Inh5lWgO0uIcMkSjI8GoLPeb X-MS-Office365-Filtering-Correlation-Id: 805dfa46-4a63-47c5-e46a-08d5cd5fd0db X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 16:49:31.6674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 805dfa46-4a63-47c5-e46a-08d5cd5fd0db X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4911 Subject: [dpdk-dev] [PATCH 13/16] crypto/cpt: adds the session related function callbacks 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: Fri, 08 Jun 2018 16:49:37 -0000 From: Ragothaman Jayaraman This patch adds the session callbacks functions. The cipher keys, auth keys and aead keys are set during the session configure. Signed-off-by: Ankur Dwivedi Signed-off-by: Murthy NSSR Signed-off-by: Nithin Dabilpuram Signed-off-by: Ragothaman Jayaraman Signed-off-by: Srisivasubramanian Srinivasan --- drivers/crypto/cpt/cpt_pmd_cryptodev.c | 6 +- drivers/crypto/cpt/cpt_pmd_ops.c | 470 +++++++++++++++++++++++++++++++++ drivers/crypto/cpt/cpt_pmd_ops.h | 11 + 3 files changed, 484 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/cpt/cpt_pmd_cryptodev.c b/drivers/crypto/cpt/cpt_pmd_cryptodev.c index 3961ec8..939f31b 100644 --- a/drivers/crypto/cpt/cpt_pmd_cryptodev.c +++ b/drivers/crypto/cpt/cpt_pmd_cryptodev.c @@ -62,9 +62,9 @@ .queue_pair_count = NULL, /* Crypto related operations */ - .session_get_size = NULL, - .session_configure = NULL, - .session_clear = NULL + .session_get_size = cpt_pmd_get_session_size, + .session_configure = cpt_pmd_session_cfg, + .session_clear = cpt_pmd_session_clear }; static int init_global_resources(void) diff --git a/drivers/crypto/cpt/cpt_pmd_ops.c b/drivers/crypto/cpt/cpt_pmd_ops.c index 1c60191..37808ce 100644 --- a/drivers/crypto/cpt/cpt_pmd_ops.c +++ b/drivers/crypto/cpt/cpt_pmd_ops.c @@ -605,3 +605,473 @@ void cpt_pmd_stats_reset(struct rte_cryptodev *dev __rte_unused) return 0; } + +unsigned int +cpt_pmd_get_session_size(struct rte_cryptodev *dev __rte_unused) +{ + return (sizeof(struct cpt_sess_misc) + + RTE_ALIGN_CEIL(cpt_fc_get_ctx_len(), 8)); +} + +static int +fill_sess_aead(cpt_instance_t *instance, struct rte_crypto_sym_xform *xform, + struct cpt_sess_misc *sess) +{ + struct rte_crypto_aead_xform *aead_form; + cipher_type_t enc_type = 0; /* NULL Cipher type */ + auth_type_t auth_type = 0; /* NULL Auth type */ + uint32_t cipher_key_len = 0; + uint8_t zsk_flag = 0, aes_gcm = 0; + aead_form = &xform->aead; + if (aead_form->op == RTE_CRYPTO_AEAD_OP_ENCRYPT && + aead_form->algo == RTE_CRYPTO_AEAD_AES_GCM) { + sess->cpt_op |= CSP_OP_CIPHER_ENCRYPT; + sess->cpt_op |= CSP_OP_AUTH_GENERATE; + } else if (aead_form->op == RTE_CRYPTO_AEAD_OP_DECRYPT && + aead_form->algo == RTE_CRYPTO_AEAD_AES_GCM) { + sess->cpt_op |= CSP_OP_CIPHER_DECRYPT; + sess->cpt_op |= CSP_OP_AUTH_VERIFY; + } else { + PMD_DRV_LOG(ERR, "Unknown cipher operation\n"); + return -1; + } + if (aead_form->key.length < cipher_key_len) { + PMD_DRV_LOG(ERR, "Invalid cipher params keylen %lu\n", + (unsigned int long)aead_form->key.length); + return -1; + } + switch (aead_form->algo) { + case RTE_CRYPTO_AEAD_AES_GCM: + enc_type = AES_GCM; + cipher_key_len = 16; + aes_gcm = 1; + break; + case RTE_CRYPTO_AEAD_AES_CCM: + PMD_DRV_LOG(ERR, "Crypto: Unsupported cipher alg %u", + aead_form->algo); + return -1; + default: + PMD_DRV_LOG(ERR, "Crypto: Undefined cipher algo %u specified", + aead_form->algo); + return -1; + } + sess->zsk_flag = zsk_flag; + sess->aes_gcm = aes_gcm; + sess->mac_len = aead_form->digest_length; + sess->iv_offset = aead_form->iv.offset; + sess->iv_length = aead_form->iv.length; + sess->aad_length = aead_form->aad_length; + cpt_fc_ciph_set_key(instance, + (void *)((uint8_t *)sess + sizeof(struct cpt_sess_misc)), + enc_type, + aead_form->key.data, + aead_form->key.length, + NULL); + + cpt_fc_auth_set_key(instance, + (void *)((uint8_t *)sess + sizeof(struct cpt_sess_misc)), + auth_type, + NULL, + 0, + aead_form->digest_length); + + return 0; +} +static int +fill_sess_cipher(cpt_instance_t *instance, struct rte_crypto_sym_xform *xform, + struct cpt_sess_misc *sess) +{ + struct rte_crypto_cipher_xform *c_form; + cipher_type_t enc_type = 0; /* NULL Cipher type */ + uint32_t cipher_key_len = 0; + uint8_t zsk_flag = 0, aes_gcm = 0, aes_ctr = 0; + + if (xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) + return -1; + + c_form = &xform->cipher; + + if (c_form->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) + sess->cpt_op |= CSP_OP_CIPHER_ENCRYPT; + else if (c_form->op == RTE_CRYPTO_CIPHER_OP_DECRYPT) + sess->cpt_op |= CSP_OP_CIPHER_DECRYPT; + else { + PMD_DRV_LOG(ERR, "Unknown cipher operation\n"); + return -1; + } + + switch (c_form->algo) { + case RTE_CRYPTO_CIPHER_AES_CBC: + enc_type = AES_CBC; + cipher_key_len = 16; + sess->dir_dma_supp |= CSP_DDMA_ENC; + break; + case RTE_CRYPTO_CIPHER_3DES_CBC: + enc_type = DES3_CBC; + cipher_key_len = 24; + break; + case RTE_CRYPTO_CIPHER_AES_CTR: + enc_type = AES_CTR; + cipher_key_len = 16; + aes_ctr = 1; + break; + case RTE_CRYPTO_CIPHER_NULL: + enc_type = 0; + break; + case RTE_CRYPTO_CIPHER_KASUMI_F8: + enc_type = KASUMI_F8_ECB; + cipher_key_len = 16; + zsk_flag = K_F8; + break; + case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: + enc_type = SNOW3G_UEA2; + cipher_key_len = 16; + zsk_flag = ZS_EA; + break; + case RTE_CRYPTO_CIPHER_ZUC_EEA3: + enc_type = ZUC_EEA3; + cipher_key_len = 16; + zsk_flag = ZS_EA; + break; + case RTE_CRYPTO_CIPHER_AES_XTS: + enc_type = AES_XTS; + cipher_key_len = 16; + break; + case RTE_CRYPTO_CIPHER_3DES_ECB: + enc_type = DES3_ECB; + cipher_key_len = 24; + break; + case RTE_CRYPTO_CIPHER_AES_ECB: + enc_type = AES_ECB; + cipher_key_len = 16; + break; + case RTE_CRYPTO_CIPHER_3DES_CTR: + case RTE_CRYPTO_CIPHER_AES_F8: + case RTE_CRYPTO_CIPHER_ARC4: + PMD_DRV_LOG(ERR, "Crypto: Unsupported cipher alg %u", + c_form->algo); + return -1; + default: + PMD_DRV_LOG(ERR, "Crypto: Undefined cipher algo %u specified", + c_form->algo); + return -1; + } + + if (c_form->key.length < cipher_key_len) { + PMD_DRV_LOG(ERR, "Invalid cipher params keylen %lu\n", + (unsigned long) c_form->key.length); + return -1; + } + + sess->zsk_flag = zsk_flag; + sess->aes_gcm = aes_gcm; + sess->aes_ctr = aes_ctr; + sess->iv_offset = c_form->iv.offset; + sess->iv_length = c_form->iv.length; + cpt_fc_ciph_set_key(instance, + SESS_PRIV(sess), + enc_type, + c_form->key.data, + c_form->key.length, + NULL); + + return 0; +} + +static int +fill_sess_auth(cpt_instance_t *instance, struct rte_crypto_sym_xform *xform, + struct cpt_sess_misc *sess) +{ + struct rte_crypto_auth_xform *a_form; + auth_type_t auth_type = 0; /* NULL Auth type */ + uint8_t zsk_flag = 0, aes_gcm = 0; + + if (xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) + goto error_out; + + a_form = &xform->auth; + + if (a_form->op == RTE_CRYPTO_AUTH_OP_VERIFY) + sess->cpt_op |= CSP_OP_AUTH_VERIFY; + else if (a_form->op == RTE_CRYPTO_AUTH_OP_GENERATE) + sess->cpt_op |= CSP_OP_AUTH_GENERATE; + else { + PMD_DRV_LOG(ERR, "Unknown auth operation\n"); + return -1; + } + + if (a_form->key.length > 64) { + PMD_DRV_LOG(ERR, "Auth key length is big\n"); + return -1; + } + + switch (a_form->algo) { + case RTE_CRYPTO_AUTH_SHA1_HMAC: + sess->dir_dma_supp |= CSP_DDMA_AUTH; + /* Fall through */ + case RTE_CRYPTO_AUTH_SHA1: + auth_type = SHA1_TYPE; + break; + case RTE_CRYPTO_AUTH_SHA256_HMAC: + case RTE_CRYPTO_AUTH_SHA256: + auth_type = SHA2_SHA256; + break; + case RTE_CRYPTO_AUTH_SHA512_HMAC: + case RTE_CRYPTO_AUTH_SHA512: + auth_type = SHA2_SHA512; + break; + case RTE_CRYPTO_AUTH_AES_GMAC: + auth_type = GMAC_TYPE; + aes_gcm = 1; + break; + case RTE_CRYPTO_AUTH_SHA224_HMAC: + case RTE_CRYPTO_AUTH_SHA224: + auth_type = SHA2_SHA224; + break; + case RTE_CRYPTO_AUTH_SHA384_HMAC: + case RTE_CRYPTO_AUTH_SHA384: + auth_type = SHA2_SHA384; + break; + case RTE_CRYPTO_AUTH_MD5_HMAC: + case RTE_CRYPTO_AUTH_MD5: + auth_type = MD5_TYPE; + break; + case RTE_CRYPTO_AUTH_KASUMI_F9: + auth_type = KASUMI_F9_ECB; + /* + * Indicate that direction needs to be taken out + * from end of src + */ + zsk_flag = K_F9; + break; + case RTE_CRYPTO_AUTH_SNOW3G_UIA2: + auth_type = SNOW3G_UIA2; + zsk_flag = ZS_IA; + break; + case RTE_CRYPTO_AUTH_ZUC_EIA3: + auth_type = ZUC_EIA3; + zsk_flag = ZS_IA; + break; + case RTE_CRYPTO_AUTH_AES_XCBC_MAC: + case RTE_CRYPTO_AUTH_AES_CMAC: + case RTE_CRYPTO_AUTH_AES_CBC_MAC: + case RTE_CRYPTO_AUTH_NULL: + PMD_DRV_LOG(ERR, "Crypto: Unsupported hash alg %u", + a_form->algo); + goto error_out; + default: + PMD_DRV_LOG(ERR, "Crypto: Undefined Hash algo %u specified", + a_form->algo); + goto error_out; + } + + sess->zsk_flag = zsk_flag; + sess->aes_gcm = aes_gcm; + sess->mac_len = a_form->digest_length; + if (zsk_flag) { + sess->auth_iv_offset = a_form->iv.offset; + sess->auth_iv_length = a_form->iv.length; + } + cpt_fc_auth_set_key(instance, + SESS_PRIV(sess), + auth_type, + a_form->key.data, + a_form->key.length, + a_form->digest_length); + + return 0; + +error_out: + return -1; +} +static int +fill_sess_gmac(cpt_instance_t *instance, struct rte_crypto_sym_xform *xform, + struct cpt_sess_misc *sess) +{ + struct rte_crypto_auth_xform *a_form; + cipher_type_t enc_type = 0; /* NULL Cipher type */ + auth_type_t auth_type = 0; /* NULL Auth type */ + uint8_t zsk_flag = 0, aes_gcm = 0; + + if (xform->type != RTE_CRYPTO_SYM_XFORM_AUTH) + return -1; + + a_form = &xform->auth; + + if (a_form->op == RTE_CRYPTO_AUTH_OP_GENERATE) + sess->cpt_op |= CSP_OP_ENCODE; + else if (a_form->op == RTE_CRYPTO_AUTH_OP_VERIFY) + sess->cpt_op |= CSP_OP_DECODE; + else { + PMD_DRV_LOG(ERR, "Unknown auth operation\n"); + return -1; + } + + switch (a_form->algo) { + case RTE_CRYPTO_AUTH_AES_GMAC: + enc_type = AES_GCM; + auth_type = GMAC_TYPE; + break; + default: + PMD_DRV_LOG(ERR, "Crypto: Undefined cipher algo %u specified", + a_form->algo); + return -1; + } + + sess->zsk_flag = zsk_flag; + sess->aes_gcm = aes_gcm; + sess->is_gmac = 1; + sess->iv_offset = a_form->iv.offset; + sess->iv_length = a_form->iv.length; + sess->mac_len = a_form->digest_length; + cpt_fc_ciph_set_key(instance, + (void *)((uint8_t *)sess + sizeof(struct cpt_sess_misc)), + enc_type, + a_form->key.data, + a_form->key.length, + NULL); + cpt_fc_auth_set_key(instance, + (void *)((uint8_t *)sess + sizeof(struct cpt_sess_misc)), + auth_type, + NULL, + 0, + a_form->digest_length); + + return 0; +} + +static void +cpt_pmd_session_init(struct rte_mempool *mp __rte_unused, void *sym_sess, + uint8_t driver_id) +{ + struct rte_cryptodev_sym_session *sess = sym_sess; + struct cpt_sess_misc *cpt_sess = + (struct cpt_sess_misc *) get_session_private_data(sess, driver_id); + + PMD_INIT_FUNC_TRACE(); + cpt_sess->ctx_dma_addr = rte_mempool_virt2iova(cpt_sess) + + sizeof(struct cpt_sess_misc); +} + + +int cpt_pmd_session_cfg(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *sess, + struct rte_mempool *mempool) +{ + struct rte_crypto_sym_xform *chain; + void *sess_private_data; + + PMD_INIT_FUNC_TRACE(); + + /* + * Microcode only supports the following combination. + * Encryption followed by authentication + * Authentication followed by decryption + * Also zuc, kasumi and snow3g are not supported in + * aead mode(ie. cipher+auth), but only cipher or auth. + */ + if (xform->next) { + if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) { + if ((xform->auth.algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2) || + (xform->auth.algo == RTE_CRYPTO_AUTH_ZUC_EIA3) || + (xform->auth.algo == RTE_CRYPTO_AUTH_KASUMI_F9)) { + PMD_DRV_LOG(ERR, "Requested auth algorithm in " + "combination with cipher unsupported\n"); + goto err; + } + if ((xform->next->type == + RTE_CRYPTO_SYM_XFORM_CIPHER) && + (xform->next->cipher.op == + RTE_CRYPTO_CIPHER_OP_ENCRYPT)) { + PMD_DRV_LOG(ERR, "Unsupported combination by " + "microcode\n"); + goto err; + /* Unsupported as of now by microcode */ + } + } + if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { + if ((xform->cipher.algo == + RTE_CRYPTO_CIPHER_SNOW3G_UEA2) || + (xform->cipher.algo == + RTE_CRYPTO_CIPHER_ZUC_EEA3) || + (xform->cipher.algo == + RTE_CRYPTO_CIPHER_KASUMI_F8)) { + PMD_DRV_LOG(ERR, "Requested cipher algorithm " + "in combination with auth unsupported\n"); + goto err; + } + if ((xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) && + (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT)) { + /* For GMAC auth there is no cipher operation */ + if ((xform->aead.algo != + RTE_CRYPTO_AEAD_AES_GCM) || + (xform->next->auth.algo != + RTE_CRYPTO_AUTH_AES_GMAC)) { + PMD_DRV_LOG(ERR, "Unsupported " + "combination by microcode\n"); + goto err; + /* Unsupported as of now by microcode */ + } + } + } + } + + if (unlikely(sess == NULL)) { + PMD_DRV_LOG(ERR, "invalid session struct"); + return -EINVAL; + } + + if (rte_mempool_get(mempool, &sess_private_data)) { + PMD_DRV_LOG(ERR, "Could not allocate sess_private_data\n"); + return -ENOMEM; + } + + chain = xform; + ((struct cpt_sess_misc *) sess_private_data)->dir_dma_supp = 0; + /* TODO: Need to restrict this loop to 2 chain elements? */ + while (chain) { + if (chain->type == RTE_CRYPTO_SYM_XFORM_AEAD) { + if (fill_sess_aead(NULL, chain, sess_private_data)) + goto err; + } else { + if (chain->type == RTE_CRYPTO_SYM_XFORM_CIPHER) { + if (fill_sess_cipher(NULL, chain, sess_private_data)) + goto err; + } else if (chain->type == RTE_CRYPTO_SYM_XFORM_AUTH) { + if (chain->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) { + if (fill_sess_gmac(NULL, chain, + sess_private_data)) + goto err; + } else { + if (fill_sess_auth(NULL, chain, sess_private_data)) + goto err; + } + } + } + chain = chain->next; + } + set_session_private_data(sess, dev->driver_id, sess_private_data); + cpt_pmd_session_init(NULL, sess, dev->driver_id); + return 0; + +err: + /* TODO: rte_mempool_put(); */ + return -EPERM; +} + +void +cpt_pmd_session_clear(struct rte_cryptodev *dev, + struct rte_cryptodev_sym_session *sess) +{ + void *session_private = get_session_private_data(sess, dev->driver_id); + + PMD_INIT_FUNC_TRACE(); + if (session_private) { + memset(session_private, 0, cpt_pmd_get_session_size(dev)); + struct rte_mempool *sess_mp = + rte_mempool_from_obj(session_private); + set_session_private_data(sess, dev->driver_id, NULL); + rte_mempool_put(sess_mp, session_private); + } +} diff --git a/drivers/crypto/cpt/cpt_pmd_ops.h b/drivers/crypto/cpt/cpt_pmd_ops.h index db2024b..314b2b1 100644 --- a/drivers/crypto/cpt/cpt_pmd_ops.h +++ b/drivers/crypto/cpt/cpt_pmd_ops.h @@ -72,4 +72,15 @@ void cpt_pmd_stats_get(struct rte_cryptodev *dev, void cpt_pmd_stats_reset(struct rte_cryptodev *dev); +unsigned int +cpt_pmd_get_session_size(struct rte_cryptodev *dev); + +int cpt_pmd_session_cfg(struct rte_cryptodev *dev, + struct rte_crypto_sym_xform *xform, + struct rte_cryptodev_sym_session *sess, + struct rte_mempool *mempool); + +void +cpt_pmd_session_clear(struct rte_cryptodev *dev, + struct rte_cryptodev_sym_session *sess); #endif -- 1.9.3