Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4682985ybl; Wed, 22 Jan 2020 02:46:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyIOv8BYbJpw8OOSkmj4rteIuooRp+OzfwZUqOmjk43dO0LiQqjc0wigkZtwvQn7ABbaw+T X-Received: by 2002:a9d:3d0a:: with SMTP id a10mr6960625otc.327.1579690010038; Wed, 22 Jan 2020 02:46:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579690010; cv=none; d=google.com; s=arc-20160816; b=NLh+bE4B3/nGjIWm7xdx7ZWK+FjlAdMHW+lZmQEXmDPbvr/JgxBEuF16e20XSH9Y02 uSPDMTy1oUvS28MX1Qp4fS0nk0k4nWvsNtUCrRItm25CMhH6Wpo/cIC++hyp+QQueAyC F1DMwKC7KU8bBwOeBm19/x6XzyVQ+lJteJ6d4j+ADJbwDY5SMRlIWphmoNJobw5nM1iL +zLLZUYX2d84UrZCVnr8RuYG+rmrKQ9nRA/b5l/ygMVf4fF87JRyCmaxQrPB0/L9eY9s JyKSUezJHMURrk7754tBEZh1PP000fxNjvqi8xanux0OH2r1O0yGA/H1EphaKyXP9P7p +l2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4S+yn/Cw6FGkvqLirx1JEfwucBuYI5yAQeYyvQqpsxI=; b=u2yi3vAWmruQ6fsED0b41rjVA1av0Gxno+hgcI7RB9ZikNf5N4lvnvlblZuY9qL4y+ LhGjK0u2wgm0Kj+CKfDcDpOX2Dr7NW9B6itBdLiqASm0NPr0x+C2RYl6Vijh7JNtzr2t c4Fg6Z24frPlamUKNqZoXxMcUmoz0gZ526Pod/8RlsBgLf6Glp6Wu70qDwQMDwCPADRI 8BdMOAsDLBeogXKZMejl0nVskJInXpgGR6f8hmJ5JRIBDj3COeQTEg6YhCKHZhQBmr4W 72dPnVinEEyPa5wt6Ig9HLJeZX5d1mMN03M98EW0i5C2Rd5NxjVYMVBm8XUkVdJvc2Li rZOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ds2DOy1l; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si22539786oth.15.2020.01.22.02.46.38; Wed, 22 Jan 2020 02:46:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ds2DOy1l; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729679AbgAVKps (ORCPT + 99 others); Wed, 22 Jan 2020 05:45:48 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53332 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729643AbgAVKps (ORCPT ); Wed, 22 Jan 2020 05:45:48 -0500 Received: by mail-wm1-f68.google.com with SMTP id m24so6292885wmc.3; Wed, 22 Jan 2020 02:45:46 -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=4S+yn/Cw6FGkvqLirx1JEfwucBuYI5yAQeYyvQqpsxI=; b=ds2DOy1lyspOM14eZEZs2/17U7vnqFrKa7f9ZBdQhN3W9OxGpcntPuZZiS4Hsl6ioY r4D3P5iDPZSf3E90XC1Aow6iI6BUhadDjEJm9/ucW2Y0H37h0r+yiyeMlf0MZhMNTD11 fH3qWP+32nBsBvXOUSWj+uMPXUpB9LLHMgvRSEbLfbyRLiFhBaoJZnCjIx2a5gkcwPP+ aXO8SMILlAgDBw++VXJwFn7X/MUproKFpz7HMI/rJNEMkdv3vJ7ijVAgHB4zs6g3erol Kzi1VfRw2TEIFy6U8aurXO4lk4IR7j/SykPiA4WjQJ1hH0t/V3eRkJg/4nCnrWwDBl0e bHcQ== 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=4S+yn/Cw6FGkvqLirx1JEfwucBuYI5yAQeYyvQqpsxI=; b=sNdggCDbBhOyMVT0+NepbucIgdfihWFfDlVUWmoBYTnDCYDL+W9NVZJcY5GzuYZQAT n46LPJE2z+hH4b+znq94y7RDQxBArHPg7pVGn8Qc2p9kOStET4aQVYZT6X7fyWsOhhpa lyaorJeDFsyHawg18x5aSEs+gxu2w9fi473GaiiMx0yDX73S2vmQbETA1uvemQq10vyB NHWUacye1+LRGL3CDLQeaX+DKSgquR6DoM0RoJIXSQk15YuCj+cN5lx3KLzTBgr9oBoO xBdH2yNRonh1/2V2Zz//5/lxkrMTn1P1Byd7ZkkE+XXzRiuFtkrJgBLsrWVLk0ix2EE/ gSTQ== X-Gm-Message-State: APjAAAWm9jQA7DzwVKJ/GS9BLsT1TeBWsE4f5exXECujd6+L1Cb/qzDZ jZw9yQfd3pdnMP5W109WFD8= X-Received: by 2002:a1c:6308:: with SMTP id x8mr2357168wmb.80.1579689946278; Wed, 22 Jan 2020 02:45:46 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:3d5:a100:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id n3sm3443953wmc.27.2020.01.22.02.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 02:45:45 -0800 (PST) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH 5/9] crypto: engine: add enqueue_request/can_do_more Date: Wed, 22 Jan 2020 11:45:24 +0100 Message-Id: <20200122104528.30084-6-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122104528.30084-1-clabbe.montjoie@gmail.com> References: <20200122104528.30084-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patchs adds two new function wrapper in crypto_engine. - enqueue_request() for drivers enqueuing request to hardware. - can_queue_more() for letting drivers to tell if they can enqueue/prepare more. Since some drivers (like caam) only enqueue request without "doing" them, do_one_request() is now optional. Signed-off-by: Corentin Labbe --- crypto/crypto_engine.c | 25 ++++++++++++++++++++++--- include/crypto/engine.h | 14 ++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 5bcb1e740fd9..4a28548c49aa 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -83,6 +83,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto out; } +retry: /* Get the fist request from the engine queue to handle */ backlog = crypto_get_backlog(&engine->queue); async_req = crypto_dequeue_request(&engine->queue); @@ -118,10 +119,28 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto req_err2; } } + + if (enginectx->op.enqueue_request) { + ret = enginectx->op.enqueue_request(engine, async_req); + if (ret) { + dev_err(engine->dev, "failed to enqueue request: %d\n", + ret); + goto req_err; + } + } + if (enginectx->op.can_queue_more && engine->queue.qlen > 0) { + ret = enginectx->op.can_queue_more(engine, async_req); + if (ret > 0) { + spin_lock_irqsave(&engine->queue_lock, flags); + goto retry; + } + if (ret < 0) { + dev_err(engine->dev, "failed to call can_queue_more\n"); + /* TODO */ + } + } if (!enginectx->op.do_one_request) { - dev_err(engine->dev, "failed to do request\n"); - ret = -EINVAL; - goto req_err; + return; } ret = enginectx->op.do_one_request(engine, async_req); if (ret) { diff --git a/include/crypto/engine.h b/include/crypto/engine.h index 03d9f9ec1cea..8ab9d26e30fe 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -63,14 +63,16 @@ struct crypto_engine { * @prepare__request: do some prepare if need before handle the current request * @unprepare_request: undo any work done by prepare_request() * @do_one_request: do encryption for current request + * @enqueue_request: Enqueue the request in the hardware + * @can_queue_more: if this function return > 0, it will tell the crypto + * engine that more space are availlable for prepare/enqueue request */ struct crypto_engine_op { - int (*prepare_request)(struct crypto_engine *engine, - void *areq); - int (*unprepare_request)(struct crypto_engine *engine, - void *areq); - int (*do_one_request)(struct crypto_engine *engine, - void *areq); + int (*prepare_request)(struct crypto_engine *engine, void *areq); + int (*unprepare_request)(struct crypto_engine *engine, void *areq); + int (*do_one_request)(struct crypto_engine *engine, void *areq); + int (*enqueue_request)(struct crypto_engine *engine, void *areq); + int (*can_queue_more)(struct crypto_engine *engine, void *areq); }; struct crypto_engine_ctx { -- 2.24.1