From patchwork Tue Jan 14 13:59:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332341 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5A351398 for ; Tue, 14 Jan 2020 13:59:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 941E324679 for ; Tue, 14 Jan 2020 13:59:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EGE60Tz9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728918AbgANN7y (ORCPT ); Tue, 14 Jan 2020 08:59:54 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52876 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727289AbgANN7x (ORCPT ); Tue, 14 Jan 2020 08:59:53 -0500 Received: by mail-wm1-f66.google.com with SMTP id p9so13922533wmc.2; Tue, 14 Jan 2020 05:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CpAqaZx6JeHzamdabNXS/MeiqNHInVywNzBkpn7W7C4=; b=EGE60Tz9ZomQozYGZ/klz3rYuQFmxyX/3ipXjYNC2U1eKb5UWY4x3m/pWmsI9myf1r UpibKFW4DOAw/goE/hdwe8S4JkRJvWfA7bQR4zvQm10+mEvPFqQJThEeKdgs7JKeMIQG fiUgFXYCSS+7SlaTMVUD1Vys/I00NPBymU0+qrlXceClhkgNI+4lFy+rM+Ud36ROg/4c 1fHrX+5g9m9d1xROUHKCSLUz1+yeyQnke9P7l0rheXf6k4lTij/EkdAGpqoAm4FdY3/I fNBXEgHqARWslgm5hDKc4ORHALnr9CQIC2Y9RljKGyDgNy/mfxqYXGpw1GwiEAFjRx6A 4BwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CpAqaZx6JeHzamdabNXS/MeiqNHInVywNzBkpn7W7C4=; b=an7vPKzVa2ktIpEnzyj6rhVSQIKH4ZScm5R9ujQiHsVL3hnVIhIftW9ny5Pz7KUuey 1vzOEsgFin6a0y8LorcSeYRqZXca/ztH1NjKVFBOy8Aj44PUUBT8z6uJMYltthLqAz03 tIcimhZyNSCna5YxeslSJmeoYnAmKhktyWjM/niAXtG71i23ic3ABa74f2mOHkiUidQR E83CI3wISzVxgiE2TjyW2p3kSmoAiHIk/NHgbHmneb/FnWUDOBR6VAL4g0WFblAWuMkS sr5Q4A9JFO/zUGaYkMW4uLiJirg81IsPBhFm6ARwzX5jHm9AwIn4U54Ktex4daJKqNhf 3UQg== X-Gm-Message-State: APjAAAVCByFp3Y11IByXSEMJsOCSQ54sp8jqmpVVA5b3PpjAW8nC31pa pgPfsUV+w3jt50JxveG7qN0= X-Google-Smtp-Source: APXvYqw+ky2HWP39jMAlwguBjhRJJXXYNObsWOMbBN+eNALLt0hLuU+EgqRGX3WRMq+vYEMZZ16sGQ== X-Received: by 2002:a05:600c:1003:: with SMTP id c3mr27443453wmc.47.1579010391218; Tue, 14 Jan 2020 05:59:51 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:50 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 01/10] crypto: sun8i-ce: move iv data to request context Date: Tue, 14 Jan 2020 14:59:27 +0100 Message-Id: <20200114135936.32422-2-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of storing IV data in the channel context, store them in the request context. Storing them in the channel structure was conceptualy wrong since they are per request related. Signed-off-by: Corentin Labbe --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 27 +++++++++---------- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 10 ++++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 75e2bef2b363..6108cea0e0bd 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -91,7 +91,6 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) struct scatterlist *sg; unsigned int todo, len, offset, ivsize; dma_addr_t addr_iv = 0, addr_key = 0; - void *backup_iv = NULL; u32 common, sym; int flow, i; int nr_sgs = 0; @@ -154,24 +153,24 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) ivsize = crypto_skcipher_ivsize(tfm); if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) { - chan->ivlen = ivsize; - chan->bounce_iv = kzalloc(ivsize, GFP_KERNEL | GFP_DMA); - if (!chan->bounce_iv) { + rctx->ivlen = ivsize; + rctx->bounce_iv = kzalloc(ivsize, GFP_KERNEL | GFP_DMA); + if (!rctx->bounce_iv) { err = -ENOMEM; goto theend_key; } if (rctx->op_dir & CE_DECRYPTION) { - backup_iv = kzalloc(ivsize, GFP_KERNEL); - if (!backup_iv) { + rctx->backup_iv = kzalloc(ivsize, GFP_KERNEL); + if (!rctx->backup_iv) { err = -ENOMEM; goto theend_key; } offset = areq->cryptlen - ivsize; - scatterwalk_map_and_copy(backup_iv, areq->src, offset, - ivsize, 0); + scatterwalk_map_and_copy(rctx->backup_iv, areq->src, + offset, ivsize, 0); } - memcpy(chan->bounce_iv, areq->iv, ivsize); - addr_iv = dma_map_single(ce->dev, chan->bounce_iv, chan->ivlen, + memcpy(rctx->bounce_iv, areq->iv, ivsize); + addr_iv = dma_map_single(ce->dev, rctx->bounce_iv, rctx->ivlen, DMA_TO_DEVICE); cet->t_iv = cpu_to_le32(addr_iv); if (dma_mapping_error(ce->dev, addr_iv)) { @@ -252,17 +251,17 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) theend_iv: if (areq->iv && ivsize > 0) { if (addr_iv) - dma_unmap_single(ce->dev, addr_iv, chan->ivlen, + dma_unmap_single(ce->dev, addr_iv, rctx->ivlen, DMA_TO_DEVICE); offset = areq->cryptlen - ivsize; if (rctx->op_dir & CE_DECRYPTION) { - memcpy(areq->iv, backup_iv, ivsize); - kzfree(backup_iv); + memcpy(areq->iv, rctx->backup_iv, ivsize); + kzfree(rctx->backup_iv); } else { scatterwalk_map_and_copy(areq->iv, areq->dst, offset, ivsize, 0); } - kfree(chan->bounce_iv); + kfree(rctx->bounce_iv); } theend_key: diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 8f8404c84a4d..49507ef2ec63 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -129,8 +129,6 @@ struct ce_task { /* * struct sun8i_ce_flow - Information used by each flow * @engine: ptr to the crypto_engine for this flow - * @bounce_iv: buffer which contain the IV - * @ivlen: size of bounce_iv * @complete: completion for the current task on this flow * @status: set to 1 by interrupt if task is done * @t_phy: Physical address of task @@ -139,8 +137,6 @@ struct ce_task { */ struct sun8i_ce_flow { struct crypto_engine *engine; - void *bounce_iv; - unsigned int ivlen; struct completion complete; int status; dma_addr_t t_phy; @@ -183,10 +179,16 @@ struct sun8i_ce_dev { * struct sun8i_cipher_req_ctx - context for a skcipher request * @op_dir: direction (encrypt vs decrypt) for this request * @flow: the flow to use for this request + * @backup_iv: buffer which contain the next IV to store + * @bounce_iv: buffer which contain a copy of IV + * @ivlen: size of bounce_iv */ struct sun8i_cipher_req_ctx { u32 op_dir; int flow; + void *backup_iv; + void *bounce_iv; + unsigned int ivlen; }; /* From patchwork Tue Jan 14 13:59:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332363 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 995E01398 for ; Tue, 14 Jan 2020 14:00:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 760EC24680 for ; Tue, 14 Jan 2020 14:00:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vf0d1GFb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729145AbgANOAd (ORCPT ); Tue, 14 Jan 2020 09:00:33 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37401 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728909AbgANN7y (ORCPT ); Tue, 14 Jan 2020 08:59:54 -0500 Received: by mail-wr1-f65.google.com with SMTP id w15so12304724wru.4; Tue, 14 Jan 2020 05:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vXhhnXKXoxYSpa1+LXBS7VNs2uspXwnX5jIhIQmwFrM=; b=vf0d1GFbo08+NG6G7zxZJeTZMiLIJ81itsHNzneSbCkxlMw9PSK/5EefhFcFVz9UQt opn2DFmB99e8fxSV8zDeioxOunCEPA1JwLFUV1JZ7tohx4yS9VeIx8szZELtTSaUVi8e MpWVfqUzXzlqC8OzVcKJK0ejjOuekOA7kfio69OKQHzwuuBCoSSJilnH5swyZxmwDZJF tN3p1UTmeFTOKAHtBkIz5KeyE9Q4FZuzTOg9R23HG9C9cgjdnkGH0O/sF2p6DB0IkmgJ U5ZD/0/mbzXaXbqd6FkEoMNCPZqXCdUeNLQe5nz7k+II0heYxnrX1j0mMKgnkq6aGLYT cx4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vXhhnXKXoxYSpa1+LXBS7VNs2uspXwnX5jIhIQmwFrM=; b=Oy7B2bqjPKt3JraVLq+uRzyqxAQ+oq1+bZQRKVEb9acahUDnzYz6RYg0EahBGWJC54 XF70JortqoD97HwErlkrFyPa1MsByZvV/YiscIxclzu1wUBV7vgCOib0EmUlpB/lB+YC Rwlmjuad+RxWwJYv4RNQzWU1EVQqAaWDxN0YH1wrsQ3HdSERoOvFdW4wdNeF6pW+P4eQ geC62V7fs6qg4iJw0tgBG1n5YIwk16WrmKLmWFpJZ/V50sBTiUorDtUTLUoFvnVZvPqB 9WDwceEDDJiJB8CK6tVKKkKlfZDPARo0lYeJda4GinAEy1/rCKN62s8rzU7wcOFvyrsi ixsw== X-Gm-Message-State: APjAAAUCBWmJx19grPHAOvID7IXwC5JqNXR8kEznfFcMxAhcAB/nnNVo 3wnixloHzpZJLBDEDxIDD0c= X-Google-Smtp-Source: APXvYqzIL5QDAbPSLYL8aOpzAthE16eu5faMIOdeePz7IfOOcLviaBT2dTkTsFRl6NklQxS0c9Fjhw== X-Received: by 2002:a5d:6703:: with SMTP id o3mr26238015wru.235.1579010392992; Tue, 14 Jan 2020 05:59:52 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:52 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 02/10] crypto: sun8i-ce: increase task list size Date: Tue, 14 Jan 2020 14:59:28 +0100 Message-Id: <20200114135936.32422-3-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The CE can handle more than 1 task at once, so this patch increase the size of the task list up to 8. For the moment I did not see more gain beyong this value. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 4 ++-- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index f72346a44e69..e8bf7bf31061 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -321,7 +321,7 @@ static void sun8i_ce_free_chanlist(struct sun8i_ce_dev *ce, int i) while (i >= 0) { crypto_engine_exit(ce->chanlist[i].engine); if (ce->chanlist[i].tl) - dma_free_coherent(ce->dev, sizeof(struct ce_task), + dma_free_coherent(ce->dev, sizeof(struct ce_task) * MAXTASK, ce->chanlist[i].tl, ce->chanlist[i].t_phy); i--; @@ -356,7 +356,7 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) goto error_engine; } ce->chanlist[i].tl = dma_alloc_coherent(ce->dev, - sizeof(struct ce_task), + sizeof(struct ce_task) * MAXTASK, &ce->chanlist[i].t_phy, GFP_KERNEL); if (!ce->chanlist[i].tl) { diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 49507ef2ec63..049b3175d755 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -73,6 +73,7 @@ #define CE_MAX_CLOCKS 3 #define MAXFLOW 4 +#define MAXTASK 8 /* * struct ce_clock - Describe clocks used by sun8i-ce From patchwork Tue Jan 14 13:59:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332359 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C29B01398 for ; Tue, 14 Jan 2020 14:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 952A524685 for ; Tue, 14 Jan 2020 14:00:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oSFvsfR/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbgANN76 (ORCPT ); Tue, 14 Jan 2020 08:59:58 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40020 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbgANN75 (ORCPT ); Tue, 14 Jan 2020 08:59:57 -0500 Received: by mail-wr1-f67.google.com with SMTP id c14so12269688wrn.7; Tue, 14 Jan 2020 05:59:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t9FT5fa3SeoozrvYAEFmKmMXN/EPpMMGGoi0s6SDiyU=; b=oSFvsfR/LJOKaCs8d7wwS3haZMNmt9yVMFgpfRLn2shhRClhS1eumasQBeBg6P1WIf EWgofZKZ2JeBcfnsbgwg2NzMLRh51ivNtRUwOJW5KHOmEb5a1zY3ZLh7jB1lN/iQkEVH 8orzTRi/8f+jnRtzLhxEZ4LNftMcmaYCD/dS5lilG/OXNQTF/Y4HA/6SLS28Hm2wEkWj 6fCqEzadKadEgcFW04TPWTSsKtux74+cwwT871kCJy/rbMhsI9r25HBcMql4Kpuxwr7v 7r8ADb/enBtLFwrKWsyo7av1/mrgvaLqZgWDFUYTv21H25VfZyQYqmy8ykMObOCJtWpC Gysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t9FT5fa3SeoozrvYAEFmKmMXN/EPpMMGGoi0s6SDiyU=; b=Rcq0WHjquQ1hf+tcidjdXegnBGivq005jo0yGqWVGIH69cogNhM9PUnzIJfqIr4dON ueaWvth8kaGY8qnF69dAe2bOTu8iUwAODP7+UfXgFZY6jxAfsCYCMR/SL7fCfm/zAF9m 9ycmkzI2VU3J/TRQK/NcZI6OhdxJ85cXhLtEPtm0s1E7Bgt6EQTeYVU1j4pmzWKQXvWu XPM8svbMLk/CFYBavZL9WnKWItx0G/670JuQzrUZ9EFJ1G2mlI1copeonfsZRa8cXVr1 EeumgjKI0PZ+ay7Zs5aoY3uIWPmDMGTqWZokSk0dqRPxP+SECpS5tyv+B8shqZhGBFut 5hMQ== X-Gm-Message-State: APjAAAUDDSPMoUZwe/VKNBdfvIII8B6RYb2cdSs9FMCva+b0vK6n1isv 1DRQ5PO5DDaj2FMLynbu7yY= X-Google-Smtp-Source: APXvYqxeoPOewBzfM1WWeAN9PbUvz883FCNn39JDjsvf/kr7lRyYmTOjgl6pRX5IxaOrrboo+lb4yw== X-Received: by 2002:a5d:494f:: with SMTP id r15mr26124939wrs.143.1579010394666; Tue, 14 Jan 2020 05:59:54 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:54 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 03/10] crypto: sun8i-ce: split into prepare/run/unprepare Date: Tue, 14 Jan 2020 14:59:29 +0100 Message-Id: <20200114135936.32422-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch split the do_one_request into three. Prepare will handle all DMA mapping and initialisation of the task structure. Unprepare will clean all DMA mapping. And the do_one_request will be limited to just excuting the task. Signed-off-by: Corentin Labbe --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 70 ++++++++++++++++--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 4 ++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 6108cea0e0bd..401f39f144ea 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -78,8 +78,9 @@ static int sun8i_ce_cipher_fallback(struct skcipher_request *areq) return err; } -static int sun8i_ce_cipher(struct skcipher_request *areq) +static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req) { + struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct sun8i_ce_dev *ce = op->ce; @@ -237,7 +238,9 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) } chan->timeout = areq->cryptlen; - err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(areq->base.tfm)); + rctx->nr_sgs = nr_sgs; + rctx->nr_sgd = nr_sgd; + return 0; theend_sgs: if (areq->src == areq->dst) { @@ -271,13 +274,64 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) return err; } -static int sun8i_ce_handle_cipher_request(struct crypto_engine *engine, void *areq) +int sun8i_ce_cipher_run(struct crypto_engine *engine, void *areq) { - int err; struct skcipher_request *breq = container_of(areq, struct skcipher_request, base); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(breq); + struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct sun8i_ce_dev *ce = op->ce; + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(breq); + int flow, err; - err = sun8i_ce_cipher(breq); + flow = rctx->flow; + err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(breq->base.tfm)); crypto_finalize_skcipher_request(engine, breq, err); + return 0; +} + +static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_req) +{ + struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct sun8i_ce_dev *ce = op->ce; + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct sun8i_ce_flow *chan; + struct ce_task *cet; + unsigned int ivsize, offset; + int nr_sgs = rctx->nr_sgs; + int nr_sgd = rctx->nr_sgd; + int flow; + + flow = rctx->flow; + chan = &ce->chanlist[flow]; + cet = chan->tl; + ivsize = crypto_skcipher_ivsize(tfm); + + if (areq->src == areq->dst) { + dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL); + } else { + if (nr_sgs > 0) + dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); + dma_unmap_sg(ce->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE); + } + + if (areq->iv && ivsize > 0) { + if (cet->t_iv) + dma_unmap_single(ce->dev, cet->t_iv, rctx->ivlen, + DMA_TO_DEVICE); + offset = areq->cryptlen - ivsize; + if (rctx->op_dir & CE_DECRYPTION) { + memcpy(areq->iv, rctx->backup_iv, ivsize); + kzfree(rctx->backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, offset, + ivsize, 0); + } + kfree(rctx->bounce_iv); + } + + dma_unmap_single(ce->dev, cet->t_key, op->keylen, DMA_TO_DEVICE); return 0; } @@ -347,9 +401,9 @@ int sun8i_ce_cipher_init(struct crypto_tfm *tfm) crypto_tfm_alg_driver_name(&sktfm->base), crypto_tfm_alg_driver_name(crypto_skcipher_tfm(&op->fallback_tfm->base))); - op->enginectx.op.do_one_request = sun8i_ce_handle_cipher_request; - op->enginectx.op.prepare_request = NULL; - op->enginectx.op.unprepare_request = NULL; + op->enginectx.op.do_one_request = sun8i_ce_cipher_run; + op->enginectx.op.prepare_request = sun8i_ce_cipher_prepare; + op->enginectx.op.unprepare_request = sun8i_ce_cipher_unprepare; err = pm_runtime_get_sync(op->ce->dev); if (err < 0) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 049b3175d755..2d3325a13bf1 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -183,6 +183,8 @@ struct sun8i_ce_dev { * @backup_iv: buffer which contain the next IV to store * @bounce_iv: buffer which contain a copy of IV * @ivlen: size of bounce_iv + * @nr_sgs: The number of source SG (as given by dma_map_sg()) + * @nr_sgd: The number of destination SG (as given by dma_map_sg()) */ struct sun8i_cipher_req_ctx { u32 op_dir; @@ -190,6 +192,8 @@ struct sun8i_cipher_req_ctx { void *backup_iv; void *bounce_iv; unsigned int ivlen; + int nr_sgs; + int nr_sgd; }; /* From patchwork Tue Jan 14 13:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332361 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1869A1398 for ; Tue, 14 Jan 2020 14:00:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7F7524685 for ; Tue, 14 Jan 2020 14:00:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EUO5m76U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbgANOAX (ORCPT ); Tue, 14 Jan 2020 09:00:23 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34765 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728939AbgANN76 (ORCPT ); Tue, 14 Jan 2020 08:59:58 -0500 Received: by mail-wm1-f66.google.com with SMTP id w5so2378446wmi.1; Tue, 14 Jan 2020 05:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xjPV4Ha5BYE0MCX17Wl6xnLI6QAy5DnWASz8VTCVvYQ=; b=EUO5m76UvmdUwWtNzcIKhgu1b3wsytiLJXK+nCU8Jd+QLUFj3sjQ6tp4GDPLdz01Tk CqD2W85UbyrcCOMSjLf/dFpOusOr7BW9TGliVE1RP6bXsB8Sxe8ahdtC2GAFpvVWPHtu huctNx72GCsTAiGkF1SCKWPEXR1HgUR4pAxwdKl8372GYVvlcoKFEIjoubnexI0StKy6 x656qiDvIBYjjnHT10RUOQDzOjyDF4tIiOjDG3EtntrJNHGhnm/SU9hhc3qJmCNhKtuH mUG4dI9ncJ9bO9nTWh1qxkJkNIl9HucXdHS5WgPs9si0eKsDk+9KCo/JNtoxvjSE9hva LINg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xjPV4Ha5BYE0MCX17Wl6xnLI6QAy5DnWASz8VTCVvYQ=; b=ZBE7vZM9HVNLRuZmt9dln8hZtzG/Us4DLZr+UkHN7nm4HMJvN4Gqrl2wRu119GoQfl Eb9uRuejZQePAs8jFmSExHCdaC1xF+0h/NnubT9CY4tz+Vg/+CRtwOojC6ofk1Rh3Qpb gp+MwiT9p5gNYN5OTWZlSG+39b9Z82sEeL/E+Ol8wu8L3pm9ybxY0G0E882c/ckB3f8c WkMR5hRpDvFQT0n3QyrTKZ/joAK+VRre6nfAeHfGqVspHI3PcU5cDpZZJUUwOkppVJXN nkSaz/NGPu8B0ZkewieLw5gRkchdcStg28nnGTeh/zqZDt4m075m6iRIlnwyBpy4mQO+ h2zQ== X-Gm-Message-State: APjAAAWxKCwXYbGOKXbGWrRqd1S8ymmvzKMRPXtfLPd4pzq/0psrM+MQ MFPePSigY86y5dUpyx5ZBsY= X-Google-Smtp-Source: APXvYqzVCraPGaXbAoGqhP1ygDTY7R+QHVftrzEYOGKAwqSEbThaIsz0cQp5wFfFNd9DXBamDMmh5Q== X-Received: by 2002:a1c:62c1:: with SMTP id w184mr28138545wmb.150.1579010396021; Tue, 14 Jan 2020 05:59:56 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:55 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 04/10] crypto: sun8i-ce: introduce the slot number Date: Tue, 14 Jan 2020 14:59:30 +0100 Message-Id: <20200114135936.32422-5-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch adds the slot position, for choosing which task in the task list should be prepared/unprepared. The slot is for the moment is always 0 until the infrastructure will handle non 0 value. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 ++++-- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 401f39f144ea..9c1f6c9eaaf9 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -96,6 +96,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req int flow, i; int nr_sgs = 0; int nr_sgd = 0; + int slot = 0; int err = 0; algt = container_of(alg, struct sun8i_ce_alg_template, alg.skcipher); @@ -114,7 +115,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req chan = &ce->chanlist[flow]; - cet = chan->tl; + cet = &chan->tl[slot]; memset(cet, 0, sizeof(struct ce_task)); cet->t_id = cpu_to_le32(flow); @@ -301,11 +302,12 @@ static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_r unsigned int ivsize, offset; int nr_sgs = rctx->nr_sgs; int nr_sgd = rctx->nr_sgd; + int slot = 0; int flow; flow = rctx->flow; chan = &ce->chanlist[flow]; - cet = chan->tl; + cet = &chan->tl[slot]; ivsize = crypto_skcipher_ivsize(tfm); if (areq->src == areq->dst) { diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index e8bf7bf31061..bd355f4b95f3 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -120,7 +120,7 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) /* Be sure all data is written before enabling the task */ wmb(); - v = 1 | (ce->chanlist[flow].tl->t_common_ctl & 0x7F) << 8; + v = 1 | (ce->chanlist[flow].tl[0].t_common_ctl & 0x7F) << 8; writel(v, ce->base + CE_TLR); mutex_unlock(&ce->mlock); From patchwork Tue Jan 14 13:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332357 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0865614E3 for ; Tue, 14 Jan 2020 14:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D05E92468F for ; Tue, 14 Jan 2020 14:00:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="efXBmH3q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728978AbgANOAB (ORCPT ); Tue, 14 Jan 2020 09:00:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37866 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727289AbgANOAA (ORCPT ); Tue, 14 Jan 2020 09:00:00 -0500 Received: by mail-wm1-f68.google.com with SMTP id f129so13858985wmf.2; Tue, 14 Jan 2020 05:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QK7uW2JyHvV/1Sv2A8qlxlva+nc6onlWMSezJazY5hk=; b=efXBmH3q24U2Ufo+ifFyvvi/Yqw1RTmkeHkZXJeT9nLqdmsYllLF/q2N9FAhZlqGqu RBRE6imvHtTjPuAT6uSI0u8gEa/aPiV6fx5u9Qii+wAEjQj3bN75LYbj3UReGbmzuu/S +EzcxW3bE2JtTlpJKXIIUfixjAHAB/MQ0QBD0T6YKviQ0xcdASq9RQWCkCEqLyk9Yur1 wclEEH0H2U8Vb3gbbzVV57N6NPZcXUO0AMROkDiuduyRPXBEl4w51A/OdtHtlcbeBr/v 80KsdAyRRVrqwaBL/Cr8miC6ZA8T/MZhNVmkKio/bN9Ns/IdyFqzfoBa/JNmlZzDl1fz RpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QK7uW2JyHvV/1Sv2A8qlxlva+nc6onlWMSezJazY5hk=; b=UGzfRfT/MDVcHYwmJhFL06OMwiCi25XBroy00lFDlp35UxG2Lv44DfR2b1mVJwlQf3 pihc29BBGDeRhfZBwfFnv8T9RG6X/mwNO5b0eiPNFokWYV/4ss7oeaOb28rzTjeUNaID gouza+QP97Pprjyeu+JFhLcpBJc7O7fAqlQBCjcACWZjStIiqscwKnb9yBhQ4KRNLUdG vMIyiPMlrM/ijFsnI98osskOyLNPq7RJbJhyk0E4/2Mt4MNMkCF4CheN5pnp6vSqGmgR MzknDtLVXrfD1ETc6qbjOaQZyZZMOvc3RVozveWsoWO8a0Bq2Mf3inOVmeFcVWrop5TN m/mg== X-Gm-Message-State: APjAAAXonO638IBONKh0oRhaZhF7Og4cB0SmV8cL8cN3r0y3j+MuOkkh si2ST3vgp6czMKIRkHo3fm8= X-Google-Smtp-Source: APXvYqwah42w9ldVBz5YQTGbbxH1zgfKmZAqapYTzwVE0gSRGQr7ndjMeZOzQrZT2x49dlCWNGYM4g== X-Received: by 2002:a1c:1d16:: with SMTP id d22mr27986303wmd.158.1579010397577; Tue, 14 Jan 2020 05:59:57 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:57 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 05/10] crypto: engine: transform cur_req in an array Date: Tue, 14 Jan 2020 14:59:31 +0100 Message-Id: <20200114135936.32422-6-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org For having the ability of doing a batch of request in one do_one_request(), we should be able to store them in an array. (for unpreparing them later). This patch converts cur_req in an array of request, but for the moment hardcode the maximum to 1. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 32 ++++++++++++++++++-------------- include/crypto/engine.h | 19 +++++++++++++++---- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index eb029ff1e05a..b72873550587 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -30,26 +30,27 @@ static void crypto_finalize_request(struct crypto_engine *engine, struct crypto_engine_ctx *enginectx; spin_lock_irqsave(&engine->queue_lock, flags); - if (engine->cur_req == req) + if (engine->cur_reqs[0].req == req) finalize_cur_req = true; spin_unlock_irqrestore(&engine->queue_lock, flags); if (finalize_cur_req) { - enginectx = crypto_tfm_ctx(req->tfm); - if (engine->cur_req_prepared && + enginectx = crypto_tfm_ctx(engine->cur_reqs[0].req->tfm); + if (engine->cur_reqs[0].prepared && enginectx->op.unprepare_request) { - ret = enginectx->op.unprepare_request(engine, req); + ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[0].req); if (ret) dev_err(engine->dev, "failed to unprepare request\n"); } + engine->cur_reqs[0].req->complete(engine->cur_reqs[0].req, err); spin_lock_irqsave(&engine->queue_lock, flags); - engine->cur_req = NULL; - engine->cur_req_prepared = false; + engine->cur_reqs[0].prepared = false; + engine->cur_reqs[0].req = NULL; spin_unlock_irqrestore(&engine->queue_lock, flags); + } else { + req->complete(req, err); } - req->complete(req, err); - kthread_queue_work(engine->kworker, &engine->pump_requests); } @@ -74,7 +75,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, spin_lock_irqsave(&engine->queue_lock, flags); /* Make sure we are not already running a request */ - if (engine->cur_req) + if (engine->cur_reqs[0].req) goto out; /* If another context is idling then defer */ @@ -114,7 +115,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, if (!async_req) goto out; - engine->cur_req = async_req; + engine->cur_reqs[0].req = async_req; if (backlog) backlog->complete(backlog, -EINPROGRESS); @@ -143,14 +144,14 @@ static void crypto_pump_requests(struct crypto_engine *engine, ret); goto req_err; } - engine->cur_req_prepared = true; + engine->cur_reqs[0].prepared = true; } if (!enginectx->op.do_one_request) { dev_err(engine->dev, "failed to do request\n"); ret = -EINVAL; goto req_err; } - ret = enginectx->op.do_one_request(engine, async_req); + ret = enginectx->op.do_one_request(engine, engine->cur_reqs[0].req); if (ret) { dev_err(engine->dev, "Failed to do one request from queue: %d\n", ret); goto req_err; @@ -158,7 +159,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, return; req_err: - crypto_finalize_request(engine, async_req, ret); + crypto_finalize_request(engine, engine->cur_reqs[0].req, ret); return; out: @@ -411,10 +412,13 @@ struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt) engine->running = false; engine->busy = false; engine->idling = false; - engine->cur_req_prepared = false; engine->priv_data = dev; snprintf(engine->name, sizeof(engine->name), "%s-engine", dev_name(dev)); + engine->rmax = 1; + engine->cur_reqs = devm_kzalloc(dev, sizeof(struct cur_req) * engine->rmax, GFP_KERNEL); + if (!engine->cur_reqs) + return NULL; crypto_init_queue(&engine->queue, CRYPTO_ENGINE_MAX_QLEN); spin_lock_init(&engine->queue_lock); diff --git a/include/crypto/engine.h b/include/crypto/engine.h index e29cd67f93c7..362134e226f4 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -18,13 +18,23 @@ #include #define ENGINE_NAME_LEN 30 + +/* + * struct cur_req - Represent a request to be processed + * @prepared: Does the request was prepared + * @req: The request to be processed + */ +struct cur_req { + bool prepared; + struct crypto_async_request *req; +}; + /* * struct crypto_engine - crypto hardware engine * @name: the engine name * @idling: the engine is entering idle state * @busy: request pump is busy * @running: the engine is on working - * @cur_req_prepared: current request is prepared * @list: link with the global crypto engine list * @queue_lock: spinlock to syncronise access to request queue * @queue: the crypto queue of the engine @@ -38,14 +48,14 @@ * @kworker: kthread worker struct for request pump * @pump_requests: work struct for scheduling work to the request pump * @priv_data: the engine private data - * @cur_req: the current request which is on processing + * @rmax: The number of request which can be processed in one batch + * @cur_reqs: A list for requests to be processed */ struct crypto_engine { char name[ENGINE_NAME_LEN]; bool idling; bool busy; bool running; - bool cur_req_prepared; struct list_head list; spinlock_t queue_lock; @@ -61,7 +71,8 @@ struct crypto_engine { struct kthread_work pump_requests; void *priv_data; - struct crypto_async_request *cur_req; + int rmax; + struct cur_req *cur_reqs; }; /* From patchwork Tue Jan 14 13:59:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332355 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74EC892A for ; Tue, 14 Jan 2020 14:00:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 524382467A for ; Tue, 14 Jan 2020 14:00:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LRbl4YL7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728984AbgANOAB (ORCPT ); Tue, 14 Jan 2020 09:00:01 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50650 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbgANOAA (ORCPT ); Tue, 14 Jan 2020 09:00:00 -0500 Received: by mail-wm1-f65.google.com with SMTP id a5so13907447wmb.0; Tue, 14 Jan 2020 05:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vwz74GVw3RqN4zv8KJzc6WOhikJUNutjS1yfSHb85f4=; b=LRbl4YL7xfmzQ1ubfonhUq+riBVo7Eyg2CecNwz5sXvOhYgCzzU5f4KizEPmiziF4m D5jqMuwxJGXYuIgRLNfSlIMO+OvP0h0nyl6yQNA07t23ws19poi5JoP44FXZMMfT1blT T3g1hisBu9zecBZnslMBQqKKbPPRXL+YE/DWuBrcGUUkV79ew8rqEstIc7XJNGwgFxr4 3iIX6iHzJCNHtV57Fr2N1q7nvQvfgoyA65gMyrBolpyP0gZSZgu2GCp/UZhTJaZcRuV4 BIIJ1IGwfAmSGYq+Sz31qndyOjB9icWSWIwv2nO1LrhDw0SIB1FsPcGfwJW5AK9eqv2g ZHTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vwz74GVw3RqN4zv8KJzc6WOhikJUNutjS1yfSHb85f4=; b=FZmYRyq4dSOP4Pew2XLld+wIGyj8cupiT39jiPeni65BU4zB+dKOiVwbTO22ozJNoW X/ni2S3K2mLfD9UxqVGpnVrsNQgak3lOMbUvJ3w+XT0OY3w1Kvdqq6wyILt1dCEHbXd2 rkELsKTJr20XDFzQclJPXeyr6NxviRjlQAALX5JHYRAcJBMg3O3Se7YAqQ99AQjS9CJl 6NiCWueeN86MOyKomvBetadYtzPrHTl6PcrbAecevJE0FKebXi1QmLVhFhCNWaDOyf2l TWnRj2Qyb1sFeWtMDxCUwg04IfOY9SD5H1J54sCHcIlkJlO3uLdIfYrOFsN9bbc5z7NK rOtA== X-Gm-Message-State: APjAAAWZDXusv0+DTTiJ/nQjnNRyldca6FUSbqVCQ3IEIUvUfr8dz9ml 4gtBgk8GfOdS6v5T7RVOI24= X-Google-Smtp-Source: APXvYqy5IpziUXqSl8mzGqH49R4MKas13Mk/3/YX/GN9HtlxDzqVTADoOUc6wXiGyyxKvj7oJv29NA== X-Received: by 2002:a1c:9c87:: with SMTP id f129mr26421503wme.26.1579010399002; Tue, 14 Jan 2020 05:59:59 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:58 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 06/10] crypto: engine: introduce ct Date: Tue, 14 Jan 2020 14:59:32 +0100 Message-Id: <20200114135936.32422-7-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org We will store the number of request in a batch in engine->ct. This patch adds all loop to unprepare all requests of a batch. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 30 ++++++++++++++++++------------ include/crypto/engine.h | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index b72873550587..591dea5ddeec 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -28,6 +28,7 @@ static void crypto_finalize_request(struct crypto_engine *engine, bool finalize_cur_req = false; int ret; struct crypto_engine_ctx *enginectx; + int i = 0; spin_lock_irqsave(&engine->queue_lock, flags); if (engine->cur_reqs[0].req == req) @@ -35,17 +36,20 @@ static void crypto_finalize_request(struct crypto_engine *engine, spin_unlock_irqrestore(&engine->queue_lock, flags); if (finalize_cur_req) { - enginectx = crypto_tfm_ctx(engine->cur_reqs[0].req->tfm); - if (engine->cur_reqs[0].prepared && - enginectx->op.unprepare_request) { - ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[0].req); - if (ret) - dev_err(engine->dev, "failed to unprepare request\n"); - } - engine->cur_reqs[0].req->complete(engine->cur_reqs[0].req, err); + do { + enginectx = crypto_tfm_ctx(engine->cur_reqs[i].req->tfm); + if (engine->cur_reqs[i].prepared && + enginectx->op.unprepare_request) { + ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[i].req); + if (ret) + dev_err(engine->dev, "failed to unprepare request\n"); + } + engine->cur_reqs[i].prepared = false; + engine->cur_reqs[i].req->complete(engine->cur_reqs[i].req, err); + } while (++i < engine->ct); spin_lock_irqsave(&engine->queue_lock, flags); - engine->cur_reqs[0].prepared = false; - engine->cur_reqs[0].req = NULL; + while (engine->ct-- > 0) + engine->cur_reqs[engine->ct].req = NULL; spin_unlock_irqrestore(&engine->queue_lock, flags); } else { req->complete(req, err); @@ -109,13 +113,14 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto out; } + engine->ct = 0; /* Get the fist request from the engine queue to handle */ backlog = crypto_get_backlog(&engine->queue); async_req = crypto_dequeue_request(&engine->queue); if (!async_req) goto out; - engine->cur_reqs[0].req = async_req; + engine->cur_reqs[engine->ct].req = async_req; if (backlog) backlog->complete(backlog, -EINPROGRESS); @@ -144,8 +149,9 @@ static void crypto_pump_requests(struct crypto_engine *engine, ret); goto req_err; } - engine->cur_reqs[0].prepared = true; + engine->cur_reqs[engine->ct].prepared = true; } + engine->ct++; if (!enginectx->op.do_one_request) { dev_err(engine->dev, "failed to do request\n"); ret = -EINVAL; diff --git a/include/crypto/engine.h b/include/crypto/engine.h index 362134e226f4..021136a47b93 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -50,6 +50,7 @@ struct cur_req { * @priv_data: the engine private data * @rmax: The number of request which can be processed in one batch * @cur_reqs: A list for requests to be processed + * @ct: How many requests will be handled in one batch */ struct crypto_engine { char name[ENGINE_NAME_LEN]; @@ -73,6 +74,7 @@ struct crypto_engine { void *priv_data; int rmax; struct cur_req *cur_reqs; + int ct; }; /* From patchwork Tue Jan 14 13:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332343 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E2881398 for ; Tue, 14 Jan 2020 14:00:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E077524679 for ; Tue, 14 Jan 2020 14:00:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IZGzjrkK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729014AbgANOAD (ORCPT ); Tue, 14 Jan 2020 09:00:03 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39330 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728975AbgANOAC (ORCPT ); Tue, 14 Jan 2020 09:00:02 -0500 Received: by mail-wm1-f67.google.com with SMTP id 20so13832894wmj.4; Tue, 14 Jan 2020 06:00:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+qS8cmFG129sXx7XLwvT27GqZEqHpjOOs5rdHnFSHiU=; b=IZGzjrkKewPPH+1qPChWS+BhLPaglsstZcFbIFMqVrWlnEyYo4D//EwlO073t5dWRt wsEUkhhhPmT8ar86gm41TZiFZdKhJ2hH3xwEbn3ADew+ZParRG4n8k5o10jGL1LVRUU2 BrBFsb3E1LCR5wy9kjfteNYmsmUS3a6zFMW85ywB2QE/McqEpFsR6LhS7Q4jCZc/iMUv PlIJAqPajK75h7F0rRdhNWoe63r2OhG9YYn/0wMxi/hX/wkIBchGVH/aHmOKmpMenkfJ zmjXb4+u1GtLTbLFq3gs2YUvR/hG+0pZd1Z57g5j0ZHtScUCIuDBo32GjFTElntjiR5m nDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+qS8cmFG129sXx7XLwvT27GqZEqHpjOOs5rdHnFSHiU=; b=q11OWSEesovI4m+PrmHb30wvYAYC7nz1KzpRnOcRUZF9W1C9JDl+iXyHmW0WHxIwGu FXz0+2x4dJS6vAXqQ5aKfwaxO48MTKFw5fUceINWEHp0zX9/dZlopz/AorZLIPzAsGVY 108kCqdTt7S9jlFfDXkbikTpxHyDV4vCCi3avci8wEzWFyHVLrWR4UWNpMNlA9UWUcB8 N2kJmXTDqxNeiOQB41sAPtI6yeniLrjCZ4loK0N5IFtBRF1jV+De9Gc/vGAJOz4U1RJY eqnm6/DBmwwlwN645flm4wJKgspUtwyY4IPtRFgVGWZZQkjQ07AEg8XLWPDwBSBFOh8p NBtw== X-Gm-Message-State: APjAAAVFM5pMxiuHUGsiE8nOu/TQe7i+oMDmXnAqOCpPbr8+UK6dTw7j 25pQMgIwqsM6fgJJWpfOq4E= X-Google-Smtp-Source: APXvYqww13Rw2lNgkQnVrqZqhVvYRprXFy6sm0G6g1K6ZSDEAxdwdk/Iiwdc3bXXKo2jLD2F6nJdKg== X-Received: by 2002:a1c:a702:: with SMTP id q2mr27788126wme.6.1579010400417; Tue, 14 Jan 2020 06:00:00 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:59 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 07/10] crypto: sun8i-ce: handle slot > 0 Date: Tue, 14 Jan 2020 14:59:33 +0100 Message-Id: <20200114135936.32422-8-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Handle the fact a slot could be different than 0. This imply: - linking two task via next - set interrupt flag just before running the batch in the last task. Signed-off-by: Corentin Labbe --- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 8 +++++++- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 9c1f6c9eaaf9..d56c992fbf93 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -99,6 +99,9 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req int slot = 0; int err = 0; + if (slot < 0 || slot >= MAXTASK) + return -EINVAL; + algt = container_of(alg, struct sun8i_ce_alg_template, alg.skcipher); dev_dbg(ce->dev, "%s %s %u %x IV(%p %u) key=%u\n", __func__, @@ -120,8 +123,11 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req cet->t_id = cpu_to_le32(flow); common = ce->variant->alg_cipher[algt->ce_algo_id]; - common |= rctx->op_dir | CE_COMM_INT; + common |= rctx->op_dir; cet->t_common_ctl = cpu_to_le32(common); + if (slot > 0) + chan->tl[slot - 1].next = cpu_to_le32(chan->t_phy + 176 * slot); + /* CTS and recent CE (H6) need length in bytes, in word otherwise */ if (ce->variant->has_t_dlen_in_bytes) cet->t_dlen = cpu_to_le32(areq->cryptlen); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index bd355f4b95f3..39bf684c0ff5 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -106,6 +106,8 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG ce->chanlist[flow].stat_req++; #endif + /* mark last one */ + ce->chanlist[flow].tl[ce->chanlist[flow].engine->ct - 1].t_common_ctl |= cpu_to_le32(CE_COMM_INT); mutex_lock(&ce->mlock); From patchwork Tue Jan 14 13:59:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332351 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A78D21398 for ; Tue, 14 Jan 2020 14:00:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7187A24685 for ; Tue, 14 Jan 2020 14:00:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b9ZF2ddh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbgANOAQ (ORCPT ); Tue, 14 Jan 2020 09:00:16 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54620 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728831AbgANOAE (ORCPT ); Tue, 14 Jan 2020 09:00:04 -0500 Received: by mail-wm1-f65.google.com with SMTP id b19so13872648wmj.4; Tue, 14 Jan 2020 06:00:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AaGocOWYYqqxxVSnuFJaes6fIuVCOqjGVL46fuoWceA=; b=b9ZF2ddhd9zGkBUQfYFINe52pfdd1cQRB5F71PoXqYhsv0I8C5zSpPdxZldg1b50IX rRbXf0DOHBwabaizpHXOVgrzXx5h1pybWotTD745Mh2HMmCt3jeVIpDjfrBOLPWRn2hw sdpmhM8LJLIUpPTw60uqNDGVdrNhK5EgVjV/Sva1mfNFlROzQfwcX7Gkj9tTwPCLXPlI RZ5xfscNXx+zApX/Fy0SGHwyPKv7Vwcl/HsdZ1P4zFADNJyFc6Xuwpp6gatMrFaf15bK MlKgfS22UUABgUklrYWfOLgo9eaCJJ7QX/eXvzzcsumnQhuGTe7TfacEeL6CGr/7pTqK E8uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AaGocOWYYqqxxVSnuFJaes6fIuVCOqjGVL46fuoWceA=; b=mzx2uIVQntkHBvtKtFDdMkOsFngNjmPiaXG+wP8vo5bBuu2Ry88074LF6XK5YyBNT0 DvzsUEF7MogSeN5D3GPgqc3xRzYgF6t7NWpsgHe9rqbf57JGDkeTC0/lYa1/XhLl+Qdt 64tys/h+55dQ6HMUUWEh+qtkbnKR5kPAR1erF47LBFFm9iLbuYgw50wjAON6Zi5ILPah QV2d+IljGk/KmxLzpQgzfKDjR2k2Ovy/ptC0kha8Urb1rlKXf6chrcNkCDqyHCiHM/gQ K2LdGIQVjFV8h1O8pli2A2qY/UVsWYB6NPOvby6G1ex27eJkbnbQ8In3MNeD8gMkewAM 0+PA== X-Gm-Message-State: APjAAAVakV5MyfL8D5f9uRGBLm10f1eTGB/bm+h28l4YBkFxYW2ORuwT cJnC1Subfn7i1CzGg/kRh0A= X-Google-Smtp-Source: APXvYqx+OxKcWRqq8m9tk4fmOp55+mC1hDkwaWDzxu8S8kxilLu0l5ArdfWrRaXSdKdve/5st6FN/Q== X-Received: by 2002:a05:600c:2383:: with SMTP id m3mr28610665wma.32.1579010402204; Tue, 14 Jan 2020 06:00:02 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.06.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 06:00:01 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 08/10] crypto: engine: add slot parameter Date: Tue, 14 Jan 2020 14:59:34 +0100 Message-Id: <20200114135936.32422-9-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org prepare/unprepare functions should be able to know which slot in a batch should be used for preparing a request. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 4 ++-- drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 ++---- drivers/crypto/omap-aes-gcm.c | 2 +- drivers/crypto/omap-aes.c | 4 ++-- drivers/crypto/omap-des.c | 4 ++-- drivers/crypto/stm32/stm32-cryp.c | 8 ++++---- drivers/crypto/stm32/stm32-hash.c | 4 ++-- include/crypto/engine.h | 4 ++-- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 591dea5ddeec..e23a398ba330 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -40,7 +40,7 @@ static void crypto_finalize_request(struct crypto_engine *engine, enginectx = crypto_tfm_ctx(engine->cur_reqs[i].req->tfm); if (engine->cur_reqs[i].prepared && enginectx->op.unprepare_request) { - ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[i].req); + ret = enginectx->op.unprepare_request(engine, engine->cur_reqs[i].req, i); if (ret) dev_err(engine->dev, "failed to unprepare request\n"); } @@ -143,7 +143,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, enginectx = crypto_tfm_ctx(async_req->tfm); if (enginectx->op.prepare_request) { - ret = enginectx->op.prepare_request(engine, async_req); + ret = enginectx->op.prepare_request(engine, async_req, engine->ct); if (ret) { dev_err(engine->dev, "failed to prepare request: %d\n", ret); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index d56c992fbf93..41d18c18d1d1 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -78,7 +78,7 @@ static int sun8i_ce_cipher_fallback(struct skcipher_request *areq) return err; } -static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req) +static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req, int slot) { struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); @@ -96,7 +96,6 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req int flow, i; int nr_sgs = 0; int nr_sgd = 0; - int slot = 0; int err = 0; if (slot < 0 || slot >= MAXTASK) @@ -296,7 +295,7 @@ int sun8i_ce_cipher_run(struct crypto_engine *engine, void *areq) return 0; } -static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_req) +static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_req, int slot) { struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); @@ -308,7 +307,6 @@ static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_r unsigned int ivsize, offset; int nr_sgs = rctx->nr_sgs; int nr_sgd = rctx->nr_sgd; - int slot = 0; int flow; flow = rctx->flow; diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c index 32dc00dc570b..0fea3dd40378 100644 --- a/drivers/crypto/omap-aes-gcm.c +++ b/drivers/crypto/omap-aes-gcm.c @@ -213,7 +213,7 @@ static int omap_aes_gcm_handle_queue(struct omap_aes_dev *dd, return 0; } -static int omap_aes_gcm_prepare_req(struct crypto_engine *engine, void *areq) +static int omap_aes_gcm_prepare_req(struct crypto_engine *engine, void *areq, int slot) { struct aead_request *req = container_of(areq, struct aead_request, base); diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c index 824ddf2a66ff..4d9caa7ce8da 100644 --- a/drivers/crypto/omap-aes.c +++ b/drivers/crypto/omap-aes.c @@ -427,7 +427,7 @@ static int omap_aes_handle_queue(struct omap_aes_dev *dd, } static int omap_aes_prepare_req(struct crypto_engine *engine, - void *areq) + void *areq, int slot) { struct skcipher_request *req = container_of(areq, struct skcipher_request, base); struct omap_aes_ctx *ctx = crypto_skcipher_ctx( @@ -632,7 +632,7 @@ static int omap_aes_ctr_decrypt(struct skcipher_request *req) } static int omap_aes_prepare_req(struct crypto_engine *engine, - void *req); + void *req, int slot); static int omap_aes_crypt_req(struct crypto_engine *engine, void *req); diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c index 8eda43319204..92c5fb1d4b83 100644 --- a/drivers/crypto/omap-des.c +++ b/drivers/crypto/omap-des.c @@ -524,7 +524,7 @@ static int omap_des_handle_queue(struct omap_des_dev *dd, } static int omap_des_prepare_req(struct crypto_engine *engine, - void *areq) + void *areq, int slot) { struct skcipher_request *req = container_of(areq, struct skcipher_request, base); struct omap_des_ctx *ctx = crypto_skcipher_ctx( @@ -711,7 +711,7 @@ static int omap_des_cbc_decrypt(struct skcipher_request *req) } static int omap_des_prepare_req(struct crypto_engine *engine, - void *areq); + void *areq, int slot); static int omap_des_crypt_req(struct crypto_engine *engine, void *areq); diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index d347a1d6e351..7c65b526d20e 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -684,7 +684,7 @@ static int stm32_cryp_cpu_start(struct stm32_cryp *cryp) static int stm32_cryp_cipher_one_req(struct crypto_engine *engine, void *areq); static int stm32_cryp_prepare_cipher_req(struct crypto_engine *engine, - void *areq); + void *areq, int slot); static int stm32_cryp_init_tfm(struct crypto_skcipher *tfm) { @@ -700,7 +700,7 @@ static int stm32_cryp_init_tfm(struct crypto_skcipher *tfm) static int stm32_cryp_aead_one_req(struct crypto_engine *engine, void *areq); static int stm32_cryp_prepare_aead_req(struct crypto_engine *engine, - void *areq); + void *areq, int slot); static int stm32_cryp_aes_aead_init(struct crypto_aead *tfm) { @@ -1015,7 +1015,7 @@ static int stm32_cryp_prepare_req(struct skcipher_request *req, } static int stm32_cryp_prepare_cipher_req(struct crypto_engine *engine, - void *areq) + void *areq, int slot) { struct skcipher_request *req = container_of(areq, struct skcipher_request, @@ -1039,7 +1039,7 @@ static int stm32_cryp_cipher_one_req(struct crypto_engine *engine, void *areq) return stm32_cryp_cpu_start(cryp); } -static int stm32_cryp_prepare_aead_req(struct crypto_engine *engine, void *areq) +static int stm32_cryp_prepare_aead_req(struct crypto_engine *engine, void *areq, int slot) { struct aead_request *req = container_of(areq, struct aead_request, base); diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index 167b80eec437..4a696c48126c 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -824,7 +824,7 @@ static int stm32_hash_hw_init(struct stm32_hash_dev *hdev, } static int stm32_hash_one_request(struct crypto_engine *engine, void *areq); -static int stm32_hash_prepare_req(struct crypto_engine *engine, void *areq); +static int stm32_hash_prepare_req(struct crypto_engine *engine, void *areq, int slot); static int stm32_hash_handle_queue(struct stm32_hash_dev *hdev, struct ahash_request *req) @@ -832,7 +832,7 @@ static int stm32_hash_handle_queue(struct stm32_hash_dev *hdev, return crypto_transfer_hash_request_to_engine(hdev->engine, req); } -static int stm32_hash_prepare_req(struct crypto_engine *engine, void *areq) +static int stm32_hash_prepare_req(struct crypto_engine *engine, void *areq, int slot) { struct ahash_request *req = container_of(areq, struct ahash_request, base); diff --git a/include/crypto/engine.h b/include/crypto/engine.h index 021136a47b93..55d3dbc2498c 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -85,9 +85,9 @@ struct crypto_engine { */ struct crypto_engine_op { int (*prepare_request)(struct crypto_engine *engine, - void *areq); + void *areq, int slot); int (*unprepare_request)(struct crypto_engine *engine, - void *areq); + void *areq, int slot); int (*do_one_request)(struct crypto_engine *engine, void *areq); }; From patchwork Tue Jan 14 13:59:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332347 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99ADC1398 for ; Tue, 14 Jan 2020 14:00:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77E1A24679 for ; Tue, 14 Jan 2020 14:00:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CMlWfiRv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728975AbgANOAH (ORCPT ); Tue, 14 Jan 2020 09:00:07 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45867 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbgANOAG (ORCPT ); Tue, 14 Jan 2020 09:00:06 -0500 Received: by mail-wr1-f66.google.com with SMTP id j42so12230004wrj.12; Tue, 14 Jan 2020 06:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lxb7PN4lvjObtQ59KMU2hHjHYfZBsU9IrbvtHskV7n0=; b=CMlWfiRvaRRJU+hOQ4WPokjIT8GHSX3vkbMyfsBc8DCF2hmxmKbLRl3XuVhkhou0oY 8ildadcB1t+iC3etvIdUbg1E1UntznuFyodZFJWT/fKIama5xaeApXEASHJT7JgN2ozv QCnT8RndunnruzJfnh/71PB8HtxvyO7XJKZnUF7uB+UEQl7A2erDumW8cUH7LVKRRVSc clHmeeo+WxvTbERdluTb53uZ8A62/xxsCsI0ksjNmkSLPYzaqbl3ZsQ8rb2gQr+2OhwQ umwgvNEbrkvZ6ozlVfbhYTa8lSeqFFXS2E6ACT6PSnFlW92eK2gHkYubDtNs9tVVSPeA TMUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lxb7PN4lvjObtQ59KMU2hHjHYfZBsU9IrbvtHskV7n0=; b=NPDZkZkATGrsehWJwVpX5sTDm6l8I1aj7qeGxtJZjjeykbOpdnbKPnhyjesJcx2Oew pN8R1lX+vBzpSut7nvYdvV01NjVZZL12f0FDf2sqxEreIqq5Z+65rijtvmsG4DIRoYhm yGlgpCE9qxzs2afEpv17qxKI0GAzN/EWu2eZeqhMdNaKtOuqzsB5ehq9qPcJC1iOOsT2 G2otXiPvhnL7aSp+fjQ35tLy7YAJg2klS8ydfDmge0hPYCdjeqkKJ7oSgQQspPe7ZSl5 n0lo4gaXnVLE+SJMA87E8egqv11uvczehTjZ2IrL82MxBF64YiGBjM5nlSQUCkEDMmvQ EXSQ== X-Gm-Message-State: APjAAAW6/VJ8BePzN5/fgVlgDuxTUhFzSm3XXp8bAssIgEFaqGJU9B+u Wa9zxgEW6ZJRRkgPPsbY4+IORX1+ X-Google-Smtp-Source: APXvYqxq5XivXy1rjI7OaJJ+olOKx4Pgt9tO+9ND8MTyENMvSQ3szmCgKQXFPKTU/w3I7VW7kOqisA== X-Received: by 2002:a5d:4651:: with SMTP id j17mr26245596wrs.237.1579010403794; Tue, 14 Jan 2020 06:00:03 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.06.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 06:00:03 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 09/10] crypto: engine: permit to batch requests Date: Tue, 14 Jan 2020 14:59:35 +0100 Message-Id: <20200114135936.32422-10-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Now everything is ready, this patch permits to choose the number of request to batch. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 32 +++++++++++++++++++++++++++----- include/crypto/engine.h | 2 ++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index e23a398ba330..e9cd9ec9a732 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -114,6 +114,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, } engine->ct = 0; +retry: /* Get the fist request from the engine queue to handle */ backlog = crypto_get_backlog(&engine->queue); async_req = crypto_dequeue_request(&engine->queue); @@ -151,7 +152,10 @@ static void crypto_pump_requests(struct crypto_engine *engine, } engine->cur_reqs[engine->ct].prepared = true; } - engine->ct++; + if (++engine->ct < engine->rmax && engine->queue.qlen > 0) { + spin_lock_irqsave(&engine->queue_lock, flags); + goto retry; + } if (!enginectx->op.do_one_request) { dev_err(engine->dev, "failed to do request\n"); ret = -EINVAL; @@ -393,15 +397,18 @@ int crypto_engine_stop(struct crypto_engine *engine) EXPORT_SYMBOL_GPL(crypto_engine_stop); /** - * crypto_engine_alloc_init - allocate crypto hardware engine structure and + * crypto_engine_alloc_init2 - allocate crypto hardware engine structure and * initialize it. * @dev: the device attached with one hardware engine * @rt: whether this queue is set to run as a realtime task + * @rmax: The number of request that the engine can batch in one + * @qlen: The size of the crypto queue * * This must be called from context that can sleep. * Return: the crypto engine structure on success, else NULL. */ -struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt) +struct crypto_engine *crypto_engine_alloc_init2(struct device *dev, bool rt, + int rmax, int qlen) { struct sched_param param = { .sched_priority = MAX_RT_PRIO / 2 }; struct crypto_engine *engine; @@ -421,12 +428,12 @@ struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt) engine->priv_data = dev; snprintf(engine->name, sizeof(engine->name), "%s-engine", dev_name(dev)); - engine->rmax = 1; + engine->rmax = rmax; engine->cur_reqs = devm_kzalloc(dev, sizeof(struct cur_req) * engine->rmax, GFP_KERNEL); if (!engine->cur_reqs) return NULL; - crypto_init_queue(&engine->queue, CRYPTO_ENGINE_MAX_QLEN); + crypto_init_queue(&engine->queue, qlen); spin_lock_init(&engine->queue_lock); engine->kworker = kthread_create_worker(0, "%s", engine->name); @@ -443,6 +450,21 @@ struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt) return engine; } +EXPORT_SYMBOL_GPL(crypto_engine_alloc_init2); + +/** + * crypto_engine_alloc_init - allocate crypto hardware engine structure and + * initialize it. + * @dev: the device attached with one hardware engine + * @rt: whether this queue is set to run as a realtime task + * + * This must be called from context that can sleep. + * Return: the crypto engine structure on success, else NULL. + */ +struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt) +{ + return crypto_engine_alloc_init2(dev, rt, 1, CRYPTO_ENGINE_MAX_QLEN); +} EXPORT_SYMBOL_GPL(crypto_engine_alloc_init); /** diff --git a/include/crypto/engine.h b/include/crypto/engine.h index 55d3dbc2498c..fe0dfea8bf07 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -115,6 +115,8 @@ void crypto_finalize_skcipher_request(struct crypto_engine *engine, int crypto_engine_start(struct crypto_engine *engine); int crypto_engine_stop(struct crypto_engine *engine); struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); +struct crypto_engine *crypto_engine_alloc_init2(struct device *dev, bool rt, + int rmax, int qlen); int crypto_engine_exit(struct crypto_engine *engine); #endif /* _CRYPTO_ENGINE_H */ From patchwork Tue Jan 14 13:59:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 11332349 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6648392A for ; Tue, 14 Jan 2020 14:00:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4471F2467A for ; Tue, 14 Jan 2020 14:00:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YwKwklKF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727289AbgANOAM (ORCPT ); Tue, 14 Jan 2020 09:00:12 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54628 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbgANOAH (ORCPT ); Tue, 14 Jan 2020 09:00:07 -0500 Received: by mail-wm1-f65.google.com with SMTP id b19so13872899wmj.4; Tue, 14 Jan 2020 06:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mmCo0cmcYxTYUl0HTh9b5uPHQjBF+Ornrl4fpC6nIuw=; b=YwKwklKFwVrhQTbq9+emPqf95apR1314k05ofi1R4X4ecmLMYVeTbhUyQp8rc6JOOE 1OtSdz22N7qTe1XPnouOPYwL70jWyR9WzmlK2ZXg2p4vGpwHbn4BMRc+jo0MBgwO6T0l kwj1Qo0YWV0mSI6WuIA9JmgmgulgXFJC/X0mzv2VstuVM/XkmTbkjnaL13iIDmY92It8 5oNt9CMr3GzgOVZqxWqargG03QKjOuUSUMJbmcmPXGbcmT0gddtiaVxm7R4gWVDD353H OJ5ZNctjqERrdhzXqK1zFZdA3CDKpvZ79XSCt2HQ6upbF63gIHwk+/f4B7j0TroYbesC L5Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mmCo0cmcYxTYUl0HTh9b5uPHQjBF+Ornrl4fpC6nIuw=; b=rcIHleI73aIPMfFTkCUOdiB4s/Di6/J114pp92+lkbFvqF7JcYF2ekbKFO7xnLsp2l uywubl83JiupnTTu/BnxsB7UgGHEU//5PfYw1QMWiQTbEBauMABOI6HYz2VGb603VbKh 1EugfIiCNkzXwvxv6GQXSSLQCwU0PkOMslPkUPzl5LqDDJJzLXZed0ATVdqyNOAQcT0a pPwFNv27r/KUPXWLpY3xG54AhdoM3g364wYQIAbFrShC+LQ9Gph0N+E4emAa78p3oEyk NjD7LUZgEQJLGUebYh1rXIVtadh72+CE77MSzcuQMkB70j9iQ+RsqDufs/nTMlZZ0yTt TNMQ== X-Gm-Message-State: APjAAAV5xiXdxrUJsuCQg8SN5CD1Un/n4EUs+dp661ZOcabNI9lJoUqY GrINbq9f0mK6BIV8DHWuRNg= X-Google-Smtp-Source: APXvYqxIi99Bpxvcwct69pL122PlCYsc6pFqFmQLsPv1kKKkDRC+0KM4vq6kSF3tJBiUx5oECNcNKw== X-Received: by 2002:a7b:c389:: with SMTP id s9mr27249334wmj.7.1579010405396; Tue, 14 Jan 2020 06:00:05 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.06.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 06:00:04 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 10/10] crypto: sun8i-ce: use the new batch mechanism Date: Tue, 14 Jan 2020 14:59:36 +0100 Message-Id: <20200114135936.32422-11-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Now all infrastructure to batch request are in place, it is time to use it. Introduce some debug for it also. Signed-off-by: Corentin Labbe --- .../crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 14 ++++++++------ drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 9 ++++++--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 41d18c18d1d1..fe5374788304 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -103,20 +103,22 @@ static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req algt = container_of(alg, struct sun8i_ce_alg_template, alg.skcipher); - dev_dbg(ce->dev, "%s %s %u %x IV(%p %u) key=%u\n", __func__, + dev_dbg(ce->dev, "%s %s %u %x IV(%p %u) key=%u slot=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->cryptlen, rctx->op_dir, areq->iv, crypto_skcipher_ivsize(tfm), - op->keylen); - -#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG - algt->stat_req++; -#endif + op->keylen, slot); flow = rctx->flow; chan = &ce->chanlist[flow]; +#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG + algt->stat_req++; + if (chan->engine->ct + 1 > chan->tmax) + chan->tmax = chan->engine->ct + 1; +#endif + cet = &chan->tl[slot]; memset(cet, 0, sizeof(struct ce_task)); diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c index 39bf684c0ff5..7cd98c227357 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c @@ -104,7 +104,7 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name) int err = 0; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG - ce->chanlist[flow].stat_req++; + ce->chanlist[flow].stat_req += ce->chanlist[flow].engine->ct; #endif /* mark last one */ ce->chanlist[flow].tl[ce->chanlist[flow].engine->ct - 1].t_common_ctl |= cpu_to_le32(CE_COMM_INT); @@ -287,7 +287,10 @@ static int sun8i_ce_dbgfs_read(struct seq_file *seq, void *v) int i; for (i = 0; i < MAXFLOW; i++) - seq_printf(seq, "Channel %d: nreq %lu\n", i, ce->chanlist[i].stat_req); + seq_printf(seq, "Channel %d: nreq %lu tmax %d eqlen=%d/%d\n", i, + ce->chanlist[i].stat_req, ce->chanlist[i].tmax, + ce->chanlist[i].engine->queue.qlen, + ce->chanlist[i].engine->queue.max_qlen); for (i = 0; i < ARRAY_SIZE(ce_algs); i++) { if (!ce_algs[i].ce) @@ -345,7 +348,7 @@ static int sun8i_ce_allocate_chanlist(struct sun8i_ce_dev *ce) for (i = 0; i < MAXFLOW; i++) { init_completion(&ce->chanlist[i].complete); - ce->chanlist[i].engine = crypto_engine_alloc_init(ce->dev, true); + ce->chanlist[i].engine = crypto_engine_alloc_init2(ce->dev, true, MAXTASK, MAXTASK * 2); if (!ce->chanlist[i].engine) { dev_err(ce->dev, "Cannot allocate engine\n"); i--; diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 2d3325a13bf1..22bb15fea476 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -135,6 +135,7 @@ struct ce_task { * @t_phy: Physical address of task * @tl: pointer to the current ce_task for this flow * @stat_req: number of request done by this flow + * @tmax: The maximum number of tasks done in one batch */ struct sun8i_ce_flow { struct crypto_engine *engine; @@ -145,6 +146,7 @@ struct sun8i_ce_flow { struct ce_task *tl; #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG unsigned long stat_req; + int tmax; #endif };