From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0083.outbound.protection.outlook.com [104.47.34.83]) by dpdk.org (Postfix) with ESMTP id 5B44DAABF for ; Fri, 9 Mar 2018 09:35:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=inyWYOBER3e6+qtPnmL5/2ZIlpMI7QQ12FJdMiltrJU=; b=eZGXe0sFSYEoToDKB5SvBckU63YJ638JmCAEZvMiGTBBe6hI8uHufKPBpMNuQGeWeO9276I+Fl5SC9P2idixE5iga/RxXVuHSsqrx558E5TsmHCnzvB1Bd0vDbU4pIO/cegWLkmo/5I/VHFS5uuemUjdwBu9wsWTR200UUX1uUU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ravi1.Kumar@amd.com; Received: from wallaby-smavila.amd.com (202.56.249.162) by MWHPR12MB1518.namprd12.prod.outlook.com (2603:10b6:301:b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.14; Fri, 9 Mar 2018 08:35:54 +0000 From: Ravi Kumar To: dev@dpdk.org Cc: pablo.de.lara.guarch@intel.com Date: Fri, 9 Mar 2018 03:35:10 -0500 Message-Id: <1520584520-130522-10-git-send-email-Ravi1.kumar@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520584520-130522-1-git-send-email-Ravi1.kumar@amd.com> References: <1515577379-18453-1-git-send-email-Ravi1.kumar@amd.com> <1520584520-130522-1-git-send-email-Ravi1.kumar@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [202.56.249.162] X-ClientProxiedBy: MA1PR0101CA0050.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:20::12) To MWHPR12MB1518.namprd12.prod.outlook.com (2603:10b6:301:b::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 49efba5b-5e16-47da-1da3-08d58598c693 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MWHPR12MB1518; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1518; 3:gHLu4hG/IHEgrfXiieyws15iQ5O04c0dB2jsa7nxc/qTsjZXePLKWqFwC2UL0uC+eezN2RuhZ9J7Dn+ZBK4bHRf/eU4g0G2urL8e+xpay1vWVCWUYOJSuuIYALaWBeX46XAgQpUFnMat2/t8JIkRiO18YieWCl+SivvNS4iCPSOcS+t2vvX8cGWytDclUAMoht/9PxjlVZf+QkxdZkC1x/Se5qtzO8NpTPplQkI2bBEP4IGwkC83oK/9JXhNGJdP; 25:QIQs52EREywZvG5sAWK8bmw+1hdiJKZ+bJKD8sBq4VVjKsSTcSeno8zuJ6ZPLDyoW8Z4iRDfwrrC6oAazbJ8QvIYJChZJ/kQg+NWvzIDmWkNrFqp/4Y2sonavJPF7ANRXAmTjzBTxMuozcJtmkMWsvwPAmmhxY7azxZpPb+An7YYtTTbcNoJhosgpr9Nxq0rhpsnSKKgETS7W+d/r0vij3MAx3vHLS1AP1Gcxac1WO9X0N5npvVsDudVj9ooGnAKrMz0jJbWE6ftpPP9uurOnKXf0Kfh+Saf26NxULmZe5MEJqnrUhFJO4CYQdk/F4H8srDcDaTNbkzTX/qpe01sVw==; 31:mz7RPxZ46XWGaEcDcrjD/ovfq+zkwAX79Mbso2VnJGUqSVmNZ0BCu2B/QR9AJaBki/nV9m8B9WV89M/glFw9BRbiAUImfVHFAjDoE4CTxyULXibN2A/WDmem1VUxcxxhOw6WP+n766WfQLRd8JXXjPyYhvHzhbJ/5tvC+4a8Cdv1VTHLEsTlei+webPtGG8r8Yu3VAEEyiKQDmpTG09+kd55L9rCpfVl7RGb0YpMNPQ= X-MS-TrafficTypeDiagnostic: MWHPR12MB1518: X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1518; 20:hLy3uvMYs68ft/XoymjL0Slq0B1sJRA9S1PInVKysLzVxoTuMwJJb4gqD45D/hk4L07Qyqc+7NBVWv0Z698CFeYmVbZ7WMEWzz3kXZAjlB3FYscpPj3HDpBr01qCKsUoppiby1vG5360UvmtIww6acIpm0f8JRwKtPSTdXOrEumqBCdKHPS0fUeC9LL14DaVpm0PKx6aI7oCeDzaxy3WRqd2pJZwbLOH824EqBsLBpWTy9jQ8k0iMoELsjQbnIgwjcZCZYEwN3PjwwBMDcx3GU3wPwpqPLR/2SpuJIx+0FeCsRpgUblblNOBsktaVlWmBWiu8XiovFMzlGVWW6ZJ+q3S1+0VuGRIGliGluj37s9ZzSGy7ac14nmiWQonlf5n+uAG/99DV/2N+V8GHz96aEYzCjWIt4QdM48Y3ZWPg7JxmRdIMU759iSxV6AS7mIbbdzSGR+AhCfMV4TZwDTwzmz9hKVaYotqLD99Jd7Ju/BQdmJgBv70MDwzLpqPUaff; 4:Hn6xFIXm5kZvtfNhDVQClkXwByLM8BnXjjYB8pqTtQOvpvBKoJ7VzZqfwyov0a3PndSqe6doYuKq2WyYNZMGaieU+1wuKlEsecTEC1zPTzK++VAmBOuR0fdkYRVU+0JvqHV3i7f3yNIjEpd653zy8+h5QQFhH/poMeyNw5jgTK0k/aOwvx/E8XsdMX4rcsp7qgqYcdzdoAQr6PobJHbGSRP8e6ugT8HNPcnkaXuCW+VZJTwnrWjFxaQP3BlYvz11j+MS5hyE5Jv+sPI2CP6Kc2YsCxLugH5qj4tYoimYF2cLfOFgx7l7Q9R4/0QYieMg X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231220)(944501244)(52105095)(10201501046)(93006095)(93001095)(6055026)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MWHPR12MB1518; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1518; X-Forefront-PRVS: 0606BBEB39 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(366004)(376002)(346002)(199004)(189003)(16586007)(26005)(81156014)(16526019)(8676002)(186003)(81166006)(25786009)(7736002)(3846002)(386003)(305945005)(4326008)(6116002)(6666003)(316002)(86362001)(76176011)(52116002)(8936002)(51416003)(50226002)(5660300001)(2906002)(2950100002)(6916009)(59450400001)(7696005)(36756003)(106356001)(105586002)(6486002)(68736007)(48376002)(97736004)(53416004)(2361001)(2351001)(53936002)(50466002)(478600001)(47776003)(66066001)(72206003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1518; H:wallaby-smavila.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1518; 23:mLzptacvGAbry2+rvPEFZz01ECL1GjTxNlk/mNtBS?= =?us-ascii?Q?ylEoM7W6un3DzlhHFKDu3l2xh6yWcKx1si32u7frDBOQqI1HlQHhUDYV27iz?= =?us-ascii?Q?izVzSROoCsgS16w32EicqL7hLXZTC8O2MFduuRKsNq5WtP+811AJeO3Uji3V?= =?us-ascii?Q?5680qiPH7wGQfp3if9nPf2e1Gtmnr3nEwIa1CCeO/vD2zA3DhrmoYv9QBrWi?= =?us-ascii?Q?LHWZb3sjNa3vpngImfOdTON4iM4QJ4idYeA1wjMQThVmjQMWznqxbiJcFGPy?= =?us-ascii?Q?V5Ytr9Ggk+6p3YBqyQIbU9EmxhnhYJz5hlu+/1zt1xiIkNKxP3YVWeu1ykeB?= =?us-ascii?Q?ewomx4Xf8F0F9xqBtDdraHaj2mQXAyz1fgiiTqGyDRQ+ymoQ/1hUXfO+E1Cn?= =?us-ascii?Q?4Zca8KR6Vhg+sky0c5JLJkiM5iLZ/pnwB7MLV1JZed47OPVpRfVYKaknkySl?= =?us-ascii?Q?dyDfitM5pywYOsmJjnStUaf18ZMKnruh0jC1D/CwAcHKrnlSWG7l216Ec6hU?= =?us-ascii?Q?24g9n7tLBxzvS9PvG+3lHheXVehnOxPd5isRZi2zvyCk9JtcqdIbi7QsIJ0v?= =?us-ascii?Q?0aGEhMewZ4CHmftBt9WtlBPgh5IsfNHg48oBLHmbFk60MTkVdz/5QSAItgmW?= =?us-ascii?Q?eITxAYHbtqxhukVK2f4aMDmtbaQe5h4pO5x8WHp0R2UzkKrCdC3yEdP6O86G?= =?us-ascii?Q?P4rK1+onbiKcyhwSMXoRKD8cj//onqa1bB74Fp4DK3eUGceDAEphhzem2IvU?= =?us-ascii?Q?M7c3bxstQXj5s2oDepLT1Ut9mxv2QcHNqiQU9bqPkiVFNilpb+2GfHB1tHeQ?= =?us-ascii?Q?gXkoZEkEBFQaiLoq5SvakKw35HaZZT1sGK1M0X7abpppKUm8P5WYPn1oKib7?= =?us-ascii?Q?gu6887UqW0EzC6+uOyua9zA1DxNUAEgW5gNGNwCAU/u2/WD2MiGtdy+CB0DV?= =?us-ascii?Q?xpeMELwcmD5TRB6wU18xm0qNAAkA3hE0aKKbCd6v6efyncP7fBvTGJqQY3jX?= =?us-ascii?Q?t8aR7gwXc5gPq+os1AzPYGETfVqkR8GiZNK09NFvDBesNu38EId4ZqteBKtO?= =?us-ascii?Q?2eoutJBagu7qxo8e/i1Ez2byG8J40jL8IqW29VY1U6OZHLAXuy8u/6zEHx6J?= =?us-ascii?Q?17MgQp0TB9xWxKthbbMNcaxUnWudMpcL3dGeX89F2RlvI1382fnYE3kwgZpF?= =?us-ascii?Q?1ZP4BE0gm+pZIM=3D?= X-Microsoft-Antispam-Message-Info: rgx86CdbS02ggL/6Vo3tAPJf59/m9u5d8EoLu7wivuDgO9Kg9OgopKUQc6o4mLHmUxvcogtZAJyd6wv+foyMz7Ylz43hgUSH9P0HBot+C0yN0/GYpeN0aA05ZqcfWTULAqd1l72bVyWiTQzOsz6Qkm3hxIRAVbAekLfI8JxnENw4QHGKHFrtojOHgrvWcn2l X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1518; 6:JfY3ItTbOnSWWPWHuFJ5SFL4xX3vEX1aZfIqOErg+RgHTFLcZz4EvdkPt/VOStX936KWhbp/vrZvco/ntf9hM6aHxS4KqeO6E28i6kyk9jo+deSn0NcnW3Z/viemi5Pd8o9pUfRfOonzORNzwFMHEEICG5kcMTRyu2iCtZ1c+lFss7fTbj2E3T/NbjrnqWIdry6t6qWsMIq3W4mWQXqTietvxzueH+VzcNqp3rscgcUbqpnxKIYU5ls7pBl7FCoisOfoEsPniOLcbqr9sKb+RdGghKbwZVKYB8AtTH8PETyFM8058/RO/3xne+HqmCRMkf8cEXBpeMUbc3CJ6zFwXvpS76Tr2GVjSiGwfamLouI=; 5:lTIMgFFDUivHFovdMNGBTVLZzLOmbEUjmZ8sCoq687kCfPCZ3yIgVlOhH4usfsJyG60Url2+UBrszs6ELfehKHtdX2eHv7qZTvxLTtAy9pHo5w33Dfw/MZOx/sbjjoK8cRc1x6bJrJIpzjVb6GuUU7cexZ3yZ4hRwToXTv3Nqmk=; 24:NYSLzcLIaYtSOoNnMaLXBKPLXQidNyE0a+OrraMurh8D70M9UzMbvVV80bNAklyLIUf1bhVkafLs3HXoVWCYLM5M1fKoQ+JU49hJbwpxm1Q=; 7:xjsamP6UMIrbPo7FBuJEr35aWHasyYqevvQeyF+HvlawHJCQ5ZRG6L0RH5M527hMDtEOrJ8+vLtUwkAJBFIjmqA8W0w9vOLIXmRSpCez2Z/HCRW+megCeiij1owblxfbNKXFeNZiR9/6BdB0a3X2lz09rj0zEOxn2jPqlOCSkQEawaLgjoE8EyWsipiTotTEESFoJDt/EZMe14L4WUCkLlzxvU9Hv1hFwqwHKwh6vCBQgGImAXGmxH1eM7eeExAf SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1518; 20:0MlXOfoBIPFTDAztZqjIDB62tRsPm9AIeWTemESajntffanxxS8QuRnjYkPfH0ayPhO7hVN6weFAB0PB/yHKyUmntoFB8y1uYu/zw81rDx1A1+WkGRk1QC78mOZi4JjeT8JtV31Ig11JRTgJWf8p0jqIywwW/fKpmCYLNAV5+zBeQ1OLURsxwsizwu0Z/1Vc+jW1XHrGKEMOKMJOiWdwZ1LrZs/vDr3S/pSCJ6kjJTSPy1yE/htTek/XEKgF1UFV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2018 08:35:54.7565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 49efba5b-5e16-47da-1da3-08d58598c693 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1518 Subject: [dpdk-dev] [PATCH v4 10/20] crypto/ccp: support aes cipher algo 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, 09 Mar 2018 08:35:58 -0000 Signed-off-by: Ravi Kumar --- drivers/crypto/ccp/ccp_crypto.c | 197 ++++++++++++++++++++++++++++++++++++++- drivers/crypto/ccp/ccp_crypto.h | 13 +++ drivers/crypto/ccp/ccp_dev.h | 53 +++++++++++ drivers/crypto/ccp/ccp_pmd_ops.c | 60 ++++++++++++ 4 files changed, 321 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/ccp_crypto.c b/drivers/crypto/ccp/ccp_crypto.c index c17e84f..b097355 100644 --- a/drivers/crypto/ccp/ccp_crypto.c +++ b/drivers/crypto/ccp/ccp_crypto.c @@ -80,6 +80,7 @@ ccp_configure_session_cipher(struct ccp_session *sess, const struct rte_crypto_sym_xform *xform) { const struct rte_crypto_cipher_xform *cipher_xform = NULL; + size_t i; cipher_xform = &xform->cipher; @@ -99,6 +100,21 @@ ccp_configure_session_cipher(struct ccp_session *sess, sess->iv.length = cipher_xform->iv.length; switch (cipher_xform->algo) { + case RTE_CRYPTO_CIPHER_AES_CTR: + sess->cipher.algo = CCP_CIPHER_ALGO_AES_CTR; + sess->cipher.um.aes_mode = CCP_AES_MODE_CTR; + sess->cipher.engine = CCP_ENGINE_AES; + break; + case RTE_CRYPTO_CIPHER_AES_ECB: + sess->cipher.algo = CCP_CIPHER_ALGO_AES_CBC; + sess->cipher.um.aes_mode = CCP_AES_MODE_ECB; + sess->cipher.engine = CCP_ENGINE_AES; + break; + case RTE_CRYPTO_CIPHER_AES_CBC: + sess->cipher.algo = CCP_CIPHER_ALGO_AES_CBC; + sess->cipher.um.aes_mode = CCP_AES_MODE_CBC; + sess->cipher.engine = CCP_ENGINE_AES; + break; default: CCP_LOG_ERR("Unsupported cipher algo"); return -1; @@ -106,10 +122,27 @@ ccp_configure_session_cipher(struct ccp_session *sess, switch (sess->cipher.engine) { + case CCP_ENGINE_AES: + if (sess->cipher.key_length == 16) + sess->cipher.ut.aes_type = CCP_AES_TYPE_128; + else if (sess->cipher.key_length == 24) + sess->cipher.ut.aes_type = CCP_AES_TYPE_192; + else if (sess->cipher.key_length == 32) + sess->cipher.ut.aes_type = CCP_AES_TYPE_256; + else { + CCP_LOG_ERR("Invalid cipher key length"); + return -1; + } + for (i = 0; i < sess->cipher.key_length ; i++) + sess->cipher.key_ccp[sess->cipher.key_length - i - 1] = + sess->cipher.key[i]; + break; default: CCP_LOG_ERR("Invalid CCP Engine"); return -ENOTSUP; } + sess->cipher.nonce_phys = rte_mem_virt2phy(sess->cipher.nonce); + sess->cipher.key_phys = rte_mem_virt2phy(sess->cipher.key_ccp); return 0; } @@ -235,6 +268,18 @@ ccp_cipher_slot(struct ccp_session *session) int count = 0; switch (session->cipher.algo) { + case CCP_CIPHER_ALGO_AES_CBC: + count = 2; + /**< op + passthrough for iv */ + break; + case CCP_CIPHER_ALGO_AES_ECB: + count = 1; + /**cipher.algo); @@ -297,10 +342,146 @@ ccp_compute_slot_count(struct ccp_session *session) return count; } +static void +ccp_perform_passthru(struct ccp_passthru *pst, + struct ccp_queue *cmd_q) +{ + struct ccp_desc *desc; + union ccp_function function; + + desc = &cmd_q->qbase_desc[cmd_q->qidx]; + + CCP_CMD_ENGINE(desc) = CCP_ENGINE_PASSTHRU; + + CCP_CMD_SOC(desc) = 0; + CCP_CMD_IOC(desc) = 0; + CCP_CMD_INIT(desc) = 0; + CCP_CMD_EOM(desc) = 0; + CCP_CMD_PROT(desc) = 0; + + function.raw = 0; + CCP_PT_BYTESWAP(&function) = pst->byte_swap; + CCP_PT_BITWISE(&function) = pst->bit_mod; + CCP_CMD_FUNCTION(desc) = function.raw; + + CCP_CMD_LEN(desc) = pst->len; + + if (pst->dir) { + CCP_CMD_SRC_LO(desc) = (uint32_t)(pst->src_addr); + CCP_CMD_SRC_HI(desc) = high32_value(pst->src_addr); + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_DST_LO(desc) = (uint32_t)(pst->dest_addr); + CCP_CMD_DST_HI(desc) = 0; + CCP_CMD_DST_MEM(desc) = CCP_MEMTYPE_SB; + + if (pst->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) + CCP_CMD_LSB_ID(desc) = cmd_q->sb_key; + } else { + + CCP_CMD_SRC_LO(desc) = (uint32_t)(pst->src_addr); + CCP_CMD_SRC_HI(desc) = 0; + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SB; + + CCP_CMD_DST_LO(desc) = (uint32_t)(pst->dest_addr); + CCP_CMD_DST_HI(desc) = high32_value(pst->dest_addr); + CCP_CMD_DST_MEM(desc) = CCP_MEMTYPE_SYSTEM; + } + + cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE; +} + +static int +ccp_perform_aes(struct rte_crypto_op *op, + struct ccp_queue *cmd_q, + struct ccp_batch_info *b_info) +{ + struct ccp_session *session; + union ccp_function function; + uint8_t *lsb_buf; + struct ccp_passthru pst = {0}; + struct ccp_desc *desc; + phys_addr_t src_addr, dest_addr, key_addr; + uint8_t *iv; + + session = (struct ccp_session *)get_session_private_data( + op->sym->session, + ccp_cryptodev_driver_id); + function.raw = 0; + + iv = rte_crypto_op_ctod_offset(op, uint8_t *, session->iv.offset); + if (session->cipher.um.aes_mode != CCP_AES_MODE_ECB) { + if (session->cipher.um.aes_mode == CCP_AES_MODE_CTR) { + rte_memcpy(session->cipher.nonce + AES_BLOCK_SIZE, + iv, session->iv.length); + pst.src_addr = (phys_addr_t)session->cipher.nonce_phys; + CCP_AES_SIZE(&function) = 0x1F; + } else { + lsb_buf = + &(b_info->lsb_buf[b_info->lsb_buf_idx*CCP_SB_BYTES]); + rte_memcpy(lsb_buf + + (CCP_SB_BYTES - session->iv.length), + iv, session->iv.length); + pst.src_addr = b_info->lsb_buf_phys + + (b_info->lsb_buf_idx * CCP_SB_BYTES); + b_info->lsb_buf_idx++; + } + + pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); + pst.len = CCP_SB_BYTES; + pst.dir = 1; + pst.bit_mod = CCP_PASSTHRU_BITWISE_NOOP; + pst.byte_swap = CCP_PASSTHRU_BYTESWAP_256BIT; + ccp_perform_passthru(&pst, cmd_q); + } + + desc = &cmd_q->qbase_desc[cmd_q->qidx]; + + src_addr = rte_pktmbuf_mtophys_offset(op->sym->m_src, + op->sym->cipher.data.offset); + if (likely(op->sym->m_dst != NULL)) + dest_addr = rte_pktmbuf_mtophys_offset(op->sym->m_dst, + op->sym->cipher.data.offset); + else + dest_addr = src_addr; + key_addr = session->cipher.key_phys; + + /* prepare desc for aes command */ + CCP_CMD_ENGINE(desc) = CCP_ENGINE_AES; + CCP_CMD_INIT(desc) = 1; + CCP_CMD_EOM(desc) = 1; + + CCP_AES_ENCRYPT(&function) = session->cipher.dir; + CCP_AES_MODE(&function) = session->cipher.um.aes_mode; + CCP_AES_TYPE(&function) = session->cipher.ut.aes_type; + CCP_CMD_FUNCTION(desc) = function.raw; + + CCP_CMD_LEN(desc) = op->sym->cipher.data.length; + + CCP_CMD_SRC_LO(desc) = ((uint32_t)src_addr); + CCP_CMD_SRC_HI(desc) = high32_value(src_addr); + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_DST_LO(desc) = ((uint32_t)dest_addr); + CCP_CMD_DST_HI(desc) = high32_value(dest_addr); + CCP_CMD_DST_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_KEY_LO(desc) = ((uint32_t)key_addr); + CCP_CMD_KEY_HI(desc) = high32_value(key_addr); + CCP_CMD_KEY_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + if (session->cipher.um.aes_mode != CCP_AES_MODE_ECB) + CCP_CMD_LSB_ID(desc) = cmd_q->sb_iv; + + cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE; + op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + return 0; +} + static inline int ccp_crypto_cipher(struct rte_crypto_op *op, - struct ccp_queue *cmd_q __rte_unused, - struct ccp_batch_info *b_info __rte_unused) + struct ccp_queue *cmd_q, + struct ccp_batch_info *b_info) { int result = 0; struct ccp_session *session; @@ -310,6 +491,18 @@ ccp_crypto_cipher(struct rte_crypto_op *op, ccp_cryptodev_driver_id); switch (session->cipher.algo) { + case CCP_CIPHER_ALGO_AES_CBC: + result = ccp_perform_aes(op, cmd_q, b_info); + b_info->desccnt += 2; + break; + case CCP_CIPHER_ALGO_AES_CTR: + result = ccp_perform_aes(op, cmd_q, b_info); + b_info->desccnt += 2; + break; + case CCP_CIPHER_ALGO_AES_ECB: + result = ccp_perform_aes(op, cmd_q, b_info); + b_info->desccnt += 1; + break; default: CCP_LOG_ERR("Unsupported cipher algo %d", session->cipher.algo); diff --git a/drivers/crypto/ccp/ccp_crypto.h b/drivers/crypto/ccp/ccp_crypto.h index 4455497..614cd47 100644 --- a/drivers/crypto/ccp/ccp_crypto.h +++ b/drivers/crypto/ccp/ccp_crypto.h @@ -46,7 +46,20 @@ #include "ccp_dev.h" +#define AES_BLOCK_SIZE 16 +#define CMAC_PAD_VALUE 0x80 +#define CTR_NONCE_SIZE 4 +#define CTR_IV_SIZE 8 #define CCP_SHA3_CTX_SIZE 200 + +/**Macro helpers for CCP command creation*/ +#define CCP_AES_SIZE(p) ((p)->aes.size) +#define CCP_AES_ENCRYPT(p) ((p)->aes.encrypt) +#define CCP_AES_MODE(p) ((p)->aes.mode) +#define CCP_AES_TYPE(p) ((p)->aes.type) +#define CCP_PT_BYTESWAP(p) ((p)->pt.byteswap) +#define CCP_PT_BITWISE(p) ((p)->pt.bitwise) + /** * CCP supported AES modes */ diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h index a5c9ef3..759afc1 100644 --- a/drivers/crypto/ccp/ccp_dev.h +++ b/drivers/crypto/ccp/ccp_dev.h @@ -48,6 +48,7 @@ /**< CCP sspecific */ #define MAX_HW_QUEUES 5 #define CCP_MAX_TRNG_RETRIES 10 +#define CCP_ALIGN(x, y) ((((x) + (y - 1)) / y) * y) /**< CCP Register Mappings */ #define Q_MASK_REG 0x000 @@ -104,10 +105,52 @@ #define LSB_SIZE 16 #define LSB_ITEM_SIZE 32 #define SLSB_MAP_SIZE (MAX_LSB_CNT * LSB_SIZE) +#define LSB_ENTRY_NUMBER(LSB_ADDR) (LSB_ADDR / LSB_ITEM_SIZE) /* General CCP Defines */ #define CCP_SB_BYTES 32 +/* Word 0 */ +#define CCP_CMD_DW0(p) ((p)->dw0) +#define CCP_CMD_SOC(p) (CCP_CMD_DW0(p).soc) +#define CCP_CMD_IOC(p) (CCP_CMD_DW0(p).ioc) +#define CCP_CMD_INIT(p) (CCP_CMD_DW0(p).init) +#define CCP_CMD_EOM(p) (CCP_CMD_DW0(p).eom) +#define CCP_CMD_FUNCTION(p) (CCP_CMD_DW0(p).function) +#define CCP_CMD_ENGINE(p) (CCP_CMD_DW0(p).engine) +#define CCP_CMD_PROT(p) (CCP_CMD_DW0(p).prot) + +/* Word 1 */ +#define CCP_CMD_DW1(p) ((p)->length) +#define CCP_CMD_LEN(p) (CCP_CMD_DW1(p)) + +/* Word 2 */ +#define CCP_CMD_DW2(p) ((p)->src_lo) +#define CCP_CMD_SRC_LO(p) (CCP_CMD_DW2(p)) + +/* Word 3 */ +#define CCP_CMD_DW3(p) ((p)->dw3) +#define CCP_CMD_SRC_MEM(p) ((p)->dw3.src_mem) +#define CCP_CMD_SRC_HI(p) ((p)->dw3.src_hi) +#define CCP_CMD_LSB_ID(p) ((p)->dw3.lsb_cxt_id) +#define CCP_CMD_FIX_SRC(p) ((p)->dw3.fixed) + +/* Words 4/5 */ +#define CCP_CMD_DW4(p) ((p)->dw4) +#define CCP_CMD_DST_LO(p) (CCP_CMD_DW4(p).dst_lo) +#define CCP_CMD_DW5(p) ((p)->dw5.fields.dst_hi) +#define CCP_CMD_DST_HI(p) (CCP_CMD_DW5(p)) +#define CCP_CMD_DST_MEM(p) ((p)->dw5.fields.dst_mem) +#define CCP_CMD_FIX_DST(p) ((p)->dw5.fields.fixed) +#define CCP_CMD_SHA_LO(p) ((p)->dw4.sha_len_lo) +#define CCP_CMD_SHA_HI(p) ((p)->dw5.sha_len_hi) + +/* Word 6/7 */ +#define CCP_CMD_DW6(p) ((p)->key_lo) +#define CCP_CMD_KEY_LO(p) (CCP_CMD_DW6(p)) +#define CCP_CMD_DW7(p) ((p)->dw7) +#define CCP_CMD_KEY_HI(p) ((p)->dw7.key_hi) +#define CCP_CMD_KEY_MEM(p) ((p)->dw7.key_mem) /* bitmap */ enum { @@ -412,6 +455,16 @@ struct ccp_desc { }; /** + * ccp memory type + */ +enum ccp_memtype { + CCP_MEMTYPE_SYSTEM = 0, + CCP_MEMTYPE_SB, + CCP_MEMTYPE_LOCAL, + CCP_MEMTYPE_LAST, +}; + +/** * cmd id to follow order */ enum ccp_cmd_order { diff --git a/drivers/crypto/ccp/ccp_pmd_ops.c b/drivers/crypto/ccp/ccp_pmd_ops.c index d483a74..5f56242 100644 --- a/drivers/crypto/ccp/ccp_pmd_ops.c +++ b/drivers/crypto/ccp/ccp_pmd_ops.c @@ -39,6 +39,66 @@ #include "ccp_crypto.h" static const struct rte_cryptodev_capabilities ccp_pmd_capabilities[] = { + { /* AES ECB */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_ECB, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .iv_size = { + .min = 0, + .max = 0, + .increment = 0 + } + }, } + }, } + }, + { /* AES CBC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_CBC, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .iv_size = { + .min = 16, + .max = 16, + .increment = 0 + } + }, } + }, } + }, + { /* AES CTR */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, + {.cipher = { + .algo = RTE_CRYPTO_CIPHER_AES_CTR, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .iv_size = { + .min = 16, + .max = 16, + .increment = 0 + } + }, } + }, } + }, RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; -- 2.7.4