From patchwork Thu Dec 17 16:48:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrille Pitchen X-Patchwork-Id: 7874421 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 35B84BEEE5 for ; Thu, 17 Dec 2015 16:50:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69EF120444 for ; Thu, 17 Dec 2015 16:50:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B6102042C for ; Thu, 17 Dec 2015 16:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966844AbbLQQui (ORCPT ); Thu, 17 Dec 2015 11:50:38 -0500 Received: from eusmtp01.atmel.com ([212.144.249.242]:56612 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbbLQQug (ORCPT ); Thu, 17 Dec 2015 11:50:36 -0500 Received: from tenerife.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server id 14.3.235.1; Thu, 17 Dec 2015 17:50:28 +0100 From: Cyrille Pitchen To: , , CC: , , , Cyrille Pitchen Subject: [PATCH 07/24] crypto: atmel-aes: change atmel_aes_write_ctrl() signature Date: Thu, 17 Dec 2015 17:48:38 +0100 Message-ID: <034ee506976eb9e9f766cae62ccacf56d848f947.1450366831.git.cyrille.pitchen@atmel.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch changes the signature of atmel_aes_write_ctrl() to make it more generic. This will be used by future patches when implementing new block cipher modes such as GCM. Especially atmel_aes_hw_init() is now called outside atmel_aes_write_ctrl(): this allows to call atmel_aes_write_ctrl() many times, still initializing the hardware only once. Indeed, the support of GCM will require to update the Mode Register and the IV when processing a single request. Signed-off-by: Cyrille Pitchen --- drivers/crypto/atmel-aes.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c index 9a9e1b88a384..ccb8a8322bf7 100644 --- a/drivers/crypto/atmel-aes.c +++ b/drivers/crypto/atmel-aes.c @@ -496,16 +496,11 @@ static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd) return err; } -static int atmel_aes_write_ctrl(struct atmel_aes_dev *dd) +static void atmel_aes_write_ctrl(struct atmel_aes_dev *dd, bool use_dma, + const u32 *iv) { - int err; u32 valcr = 0, valmr = 0; - err = atmel_aes_hw_init(dd); - - if (err) - return err; - /* MR register must be set before IV registers */ if (dd->ctx->keylen == AES_KEYSIZE_128) valmr |= AES_MR_KEYSIZE_128; @@ -539,7 +534,7 @@ static int atmel_aes_write_ctrl(struct atmel_aes_dev *dd) if (dd->flags & AES_FLAGS_ENCRYPT) valmr |= AES_MR_CYPHER_ENC; - if (dd->total > ATMEL_AES_DMA_THRESHOLD) { + if (use_dma) { valmr |= AES_MR_SMOD_IDATAR0; if (dd->caps.has_dualbuff) valmr |= AES_MR_DUALBUFF; @@ -555,11 +550,9 @@ static int atmel_aes_write_ctrl(struct atmel_aes_dev *dd) if (((dd->flags & AES_FLAGS_CBC) || (dd->flags & AES_FLAGS_CFB) || (dd->flags & AES_FLAGS_OFB) || (dd->flags & AES_FLAGS_CTR)) && - dd->req->info) { - atmel_aes_write_n(dd, AES_IVR(0), dd->req->info, 4); + iv) { + atmel_aes_write_n(dd, AES_IVR(0), iv, 4); } - - return 0; } static int atmel_aes_handle_queue(struct atmel_aes_dev *dd, @@ -570,6 +563,7 @@ static int atmel_aes_handle_queue(struct atmel_aes_dev *dd, struct atmel_aes_reqctx *rctx; unsigned long flags; int err, ret = 0; + bool use_dma; spin_lock_irqsave(&dd->lock, flags); if (req) @@ -607,9 +601,11 @@ static int atmel_aes_handle_queue(struct atmel_aes_dev *dd, dd->ctx = ctx; ctx->dd = dd; - err = atmel_aes_write_ctrl(dd); + err = atmel_aes_hw_init(dd); if (!err) { - if (dd->total > ATMEL_AES_DMA_THRESHOLD) + use_dma = (dd->total > ATMEL_AES_DMA_THRESHOLD); + atmel_aes_write_ctrl(dd, use_dma, req->info); + if (use_dma) err = atmel_aes_crypt_dma_start(dd); else err = atmel_aes_crypt_cpu_start(dd);