From patchwork Tue Nov 7 09:40:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 118134 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3758354qgn; Tue, 7 Nov 2017 01:42:15 -0800 (PST) X-Google-Smtp-Source: ABhQp+TkwcDNQq1If4SmNd9HudznckK22focf/Iow3ZmEliJkU0C0cmc2Z3AWf1RpQ/e8+YvqYI9 X-Received: by 10.101.68.69 with SMTP id e5mr17793499pgq.282.1510047735435; Tue, 07 Nov 2017 01:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510047735; cv=none; d=google.com; s=arc-20160816; b=GZxBzXqIX6k7fZa+4BrlRDI0Wl++rx5HcYGMUzwG7xX+0Am/x2CnRgXXb7M7LF/K39 TxZoU4Zt7EvbtnD+ewEEwMr+B0sr3rltjgFv1fWbRC8D0aUSi5zkmRz8vpXWcJU+qpz3 1BOe/aMImS9zUaKCcN7koud4mpXRqloA3LQEqOdnMioz3qFKqfQQTP5spCOZJl9tWz42 3XN8txDQwT7syd/4nyLAA3A+Z0tQhl8O1jqnCUlqgY5klPYTvQJOSt8WM0KLFdLHsQ51 lb2KJ9U+ijG1f6J6U9PZ55R6IuZH7KcRYlUuV7Z2qDhnlw3LTp0MKbJwnVwaXtPA/Vae Yqcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=FGZtlETkYd6n+xZg2tAXzzgjfG1AH/uWchS8vRH4fgI=; b=vZzz6NNMKGSKcTQaMTd+F49v5RW2CUn0MmOmuapqT59Uklvfs6fv+HUNZKQvDNFKqb 7xyRLE+eu6Xn0PdzNc7XZEBeqIMrSCySuW3NwIg/b6YJfLImaPj3pemJmjIUWuAao0Lg ZL0e1XkeyuF2eLi6C+MCBAFc4IXbdEhIfiDzik9KI/sPyWqwo3RGEswqOQBUUqtsN0N1 J3XFEFazjCzNe7owEb5/sCKWP4ibSDaOVx3Z5qgQoZimt+ABEa0IWF9mwRG99dEHgdhm UhhK+ldJgIK7eymqeWszsoDIAk0tQh1MuLlNva5GFP5qa0pEfLXLZMF0DPPo4MtDWo6z b8fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p72si807406pfa.376.2017.11.07.01.42.15; Tue, 07 Nov 2017 01:42:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756769AbdKGJmM (ORCPT + 26 others); Tue, 7 Nov 2017 04:42:12 -0500 Received: from foss.arm.com ([217.140.101.70]:46386 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756722AbdKGJkj (ORCPT ); Tue, 7 Nov 2017 04:40:39 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B3931435; Tue, 7 Nov 2017 01:40:39 -0800 (PST) Received: from sugar.kfn.arm.com (unknown [10.45.48.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E590E3F220; Tue, 7 Nov 2017 01:40:37 -0800 (PST) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] staging: ccree: fold common code into function Date: Tue, 7 Nov 2017 09:40:01 +0000 Message-Id: <1510047606-5589-6-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510047606-5589-1-git-send-email-gilad@benyossef.com> References: <1510047606-5589-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fold common code copying MAC to/from a temp. buffer into an inline function instead of keeping multiple open coded versions of same. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_buffer_mgr.c | 92 ++++++++++++++-------------------- 1 file changed, 38 insertions(+), 54 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c b/drivers/staging/ccree/ssi_buffer_mgr.c index b3ca249..f3076f3 100644 --- a/drivers/staging/ccree/ssi_buffer_mgr.c +++ b/drivers/staging/ccree/ssi_buffer_mgr.c @@ -65,6 +65,27 @@ struct buffer_array { }; /** + * cc_copy_mac() - Copy MAC to temporary location + * + * @dev: device object + * @req: aead request object + * @dir: [IN] copy from/to sgl + */ +static inline void cc_copy_mac(struct device *dev, struct aead_request *req, + enum ssi_sg_cpy_direct dir) +{ + struct aead_req_ctx *areq_ctx = aead_request_ctx(req); + struct crypto_aead *tfm = crypto_aead_reqtfm(req); + u32 skip = req->assoclen + req->cryptlen; + + if (areq_ctx->is_gcm4543) + skip += crypto_aead_ivsize(tfm); + + cc_copy_sg_portion(dev, areq_ctx->backup_mac, req->src, + (skip - areq_ctx->req_authsize), skip, dir); +} + +/** * cc_get_sgl_nents() - Get scatterlist number of entries. * * @sg_list: SG list @@ -669,21 +690,12 @@ void cc_unmap_aead_request(struct device *dev, struct aead_request *req) } if (drvdata->coherent && (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) && - likely(req->src == req->dst)) { - u32 size_to_skip = req->assoclen; - - if (areq_ctx->is_gcm4543) - size_to_skip += crypto_aead_ivsize(tfm); + likely(req->src == req->dst)) - /* copy mac to a temporary location to deal with possible + /* copy back mac from temporary location to deal with possible * data memory overriding that caused by cache coherence problem. */ - cc_copy_sg_portion(dev, areq_ctx->backup_mac, req->src, - (size_to_skip + req->cryptlen - - areq_ctx->req_authsize), - (size_to_skip + req->cryptlen), - SSI_SG_FROM_BUF); - } + cc_copy_mac(dev, req, SSI_SG_FROM_BUF); } static inline int cc_get_aead_icv_nents( @@ -918,7 +930,6 @@ static inline int cc_prepare_aead_data_mlli( enum drv_crypto_direction direct = areq_ctx->gen_ctx.op_type; unsigned int authsize = areq_ctx->req_authsize; int rc = 0, icv_nents; - struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct device *dev = drvdata_to_dev(drvdata); if (likely(req->src == req->dst)) { @@ -943,24 +954,14 @@ static inline int cc_prepare_aead_data_mlli( * MAC verification upon request completion */ if (direct == DRV_CRYPTO_DIRECTION_DECRYPT) { - if (!drvdata->coherent) { /* In coherent platforms (e.g. ACP) * already copying ICV for any * INPLACE-DECRYPT operation, hence * we must neglect this code. */ - u32 skip = req->assoclen; - - if (areq_ctx->is_gcm4543) - skip += crypto_aead_ivsize(tfm); - - cc_copy_sg_portion(dev, - areq_ctx->backup_mac, - req->src, - (skip + req->cryptlen - areq_ctx->req_authsize), - (skip + req->cryptlen), - SSI_SG_TO_BUF); - } + if (!drvdata->coherent) + cc_copy_mac(dev, req, SSI_SG_TO_BUF); + areq_ctx->icv_virt_addr = areq_ctx->backup_mac; } else { areq_ctx->icv_virt_addr = areq_ctx->mac_buf; @@ -996,22 +997,14 @@ static inline int cc_prepare_aead_data_mlli( goto prepare_data_mlli_exit; } + /* Backup happens only when ICV is fragmented, ICV + * verification is made by CPU compare in order to simplify + * MAC verification upon request completion + */ if (unlikely(areq_ctx->is_icv_fragmented)) { - /* Backup happens only when ICV is fragmented, ICV - * verification is made by CPU compare in order to simplify - * MAC verification upon request completion - */ - u32 size_to_skip = req->assoclen; - - if (areq_ctx->is_gcm4543) - size_to_skip += crypto_aead_ivsize(tfm); - - cc_copy_sg_portion(dev, areq_ctx->backup_mac, - req->src, - (size_to_skip + req->cryptlen - areq_ctx->req_authsize), - (size_to_skip + req->cryptlen), - SSI_SG_TO_BUF); + cc_copy_mac(dev, req, SSI_SG_TO_BUF); areq_ctx->icv_virt_addr = areq_ctx->backup_mac; + } else { /* Contig. ICV */ /*Should hanlde if the sg is not contig.*/ areq_ctx->icv_dma_addr = sg_dma_address( @@ -1249,22 +1242,13 @@ int cc_map_aead_request( mlli_params->curr_pool = NULL; sg_data.num_of_buffers = 0; + /* copy mac to a temporary location to deal with possible + * data memory overriding that caused by cache coherence problem. + */ if (drvdata->coherent && (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) && - likely(req->src == req->dst)) { - u32 size_to_skip = req->assoclen; - - if (is_gcm4543) - size_to_skip += crypto_aead_ivsize(tfm); - - /* copy mac to a temporary location to deal with possible - * data memory overriding that caused by cache coherence problem. - */ - cc_copy_sg_portion(dev, areq_ctx->backup_mac, req->src, - (size_to_skip + req->cryptlen - areq_ctx->req_authsize), - (size_to_skip + req->cryptlen), - SSI_SG_TO_BUF); - } + likely(req->src == req->dst)) + cc_copy_mac(dev, req, SSI_SG_TO_BUF); /* cacluate the size for cipher remove ICV in decrypt*/ areq_ctx->cryptlen = (areq_ctx->gen_ctx.op_type ==