From patchwork Tue Aug 16 14:00:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944985 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCEF3C28B2B for ; Tue, 16 Aug 2022 14:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235843AbiHPODZ (ORCPT ); Tue, 16 Aug 2022 10:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235853AbiHPODW (ORCPT ); Tue, 16 Aug 2022 10:03:22 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9BA711C0E for ; Tue, 16 Aug 2022 07:03:14 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id x9so10604201ljj.13 for ; Tue, 16 Aug 2022 07:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=BucOQJ+RxRyfe7V8KdF0CMOvkh9OJz+op1Vzn2l8TaI=; b=plyvCoCTKbp1iyvBxIByGkPq5XPf5JjPoxHi4wrLtRK9PYzCxxnnWnuiEYPDqnEqvv Dp0cYFrLBM+gWuIyw+guAFcS5oovVqhvX9et6tiXlbta5Y7LQVHeSdmsJQzFZKPXb3PJ VklCXn+d/8KNkOvxQF3+kw++eTm/j0qZ3QROQtPUFutRb4f9Ly6Q8BTCs8DNU/X0e4rH peUrEjGD7NgWHYU8OZ0S7LRGrpKoehVlLOtpX9cBKJqBKb4LZG91lX0tRbP7gNwSIfGP yGfMY+4D4IdOy1CBdlSUhdlaysr7Zx04JMWfYd2Tvd9ev0QfmGl2KnCoaGPHV9pcs0R3 7GiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=BucOQJ+RxRyfe7V8KdF0CMOvkh9OJz+op1Vzn2l8TaI=; b=KDgbTqzg4iaqkpmf+8r/hOERRu2LAQ3ejxItVlzZpOJfUMZd4C3/3vTsknyy/3Vl1M 1on3QnaxgC4I4x23th0oTb4Kjv5yhYQjtuoOqTaUViMV+APGYVCn/t0f591AhdWuHjnd 0pTgO7gPmsG0FMKQ13qX7Oymg5skMjcTW8duP9rYQbuSxhMq7VSByoAJNLxJkcdjZAlS sNkkdXOh5zvk7YYnpWIXb+kq5pCQkUkJsQeTQ4Oo0NlmxnrbxeZGWgSlImROwJTEhVDu DH9UVcbn8Gvd+vuzAkJd7rL5DmnaA1AApbsSxEbb+tIvyE+STSIyQvR4UB9AfD4beoPx f5Kg== X-Gm-Message-State: ACgBeo2gJDCK8Wswwdmt5tCu2rGgd7MM6tOyOIGgXjRXfs/GIyhahNVA OSUYaxPh6Xoosde4FqeJVA5XYhf2zN/DWg== X-Google-Smtp-Source: AA6agR5tsORCszE2ajIvLeglxtR4bch+K6I9q91kE3TfHjvCaAQWfaaMQc27gfzJsxkmkPUHoWMbcw== X-Received: by 2002:a2e:9dd0:0:b0:261:71bc:d3ef with SMTP id x16-20020a2e9dd0000000b0026171bcd3efmr6635246ljj.190.1660658592664; Tue, 16 Aug 2022 07:03:12 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:12 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 01/16] crypto: ux500/hash: Pass ctx to hash_setconfiguration() Date: Tue, 16 Aug 2022 16:00:34 +0200 Message-Id: <20220816140049.102306-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This function was dereferencing device_data->current_ctx to get the context. This is not a good idea, the device_data is serialized with an awkward semaphore construction and fragile. Also fix a checkpatch warning about putting compared constants to the right in an expression. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 2 +- drivers/crypto/ux500/hash/hash_core.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 7c9bcc15125f..26e8b7949d7c 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -380,7 +380,7 @@ struct hash_device_data { int hash_check_hw(struct hash_device_data *device_data); int hash_setconfiguration(struct hash_device_data *device_data, - struct hash_config *config); + struct hash_ctx *ctx); void hash_begin(struct hash_device_data *device_data, struct hash_ctx *ctx); diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index f104e8a43036..1662e176de44 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -473,7 +473,7 @@ static int init_hash_hw(struct hash_device_data *device_data, { int ret = 0; - ret = hash_setconfiguration(device_data, &ctx->config); + ret = hash_setconfiguration(device_data, ctx); if (ret) { dev_err(device_data->dev, "%s: hash_setconfiguration() failed!\n", __func__); @@ -672,11 +672,12 @@ static void hash_incrementlength(struct hash_req_ctx *ctx, u32 incr) * hash_setconfiguration - Sets the required configuration for the hash * hardware. * @device_data: Structure for the hash device. - * @config: Pointer to a configuration structure. + * @ctx: Current context */ int hash_setconfiguration(struct hash_device_data *device_data, - struct hash_config *config) + struct hash_ctx *ctx) { + struct hash_config *config = &ctx->config; int ret = 0; if (config->algorithm != HASH_ALGO_SHA1 && @@ -711,12 +712,12 @@ int hash_setconfiguration(struct hash_device_data *device_data, * MODE bit. This bit selects between HASH or HMAC mode for the * selected algorithm. 0b0 = HASH and 0b1 = HMAC. */ - if (HASH_OPER_MODE_HASH == config->oper_mode) + if (config->oper_mode == HASH_OPER_MODE_HASH) { HASH_CLEAR_BITS(&device_data->base->cr, HASH_CR_MODE_MASK); - else if (HASH_OPER_MODE_HMAC == config->oper_mode) { + } else if (config->oper_mode == HASH_OPER_MODE_HMAC) { HASH_SET_BITS(&device_data->base->cr, HASH_CR_MODE_MASK); - if (device_data->current_ctx->keylen > HASH_BLOCK_SIZE) { + if (ctx->keylen > HASH_BLOCK_SIZE) { /* Truncate key to blocksize */ dev_dbg(device_data->dev, "%s: LKEY set\n", __func__); HASH_SET_BITS(&device_data->base->cr, @@ -878,7 +879,7 @@ static int hash_dma_final(struct ahash_request *req) goto out; } } else { - ret = hash_setconfiguration(device_data, &ctx->config); + ret = hash_setconfiguration(device_data, ctx); if (ret) { dev_err(device_data->dev, "%s: hash_setconfiguration() failed!\n", From patchwork Tue Aug 16 14:00:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944987 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCC02C2BB41 for ; Tue, 16 Aug 2022 14:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235853AbiHPOD1 (ORCPT ); Tue, 16 Aug 2022 10:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235744AbiHPODW (ORCPT ); Tue, 16 Aug 2022 10:03:22 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3714137FB2 for ; Tue, 16 Aug 2022 07:03:17 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id j3so10664893ljo.0 for ; Tue, 16 Aug 2022 07:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=zIgIQNH9egSlrVYC+AMp4lopK69544ScTJ4QfR0a69c=; b=oRWv3XNAulsRxWqEojLjrniEQIvQx0LzTNMJfjUDvFOeDHsdzyJxaFYb5cRXMyKppC /+rNwxjlzSmGGJ4Pv4+W803UfWT0DvcNewRB6hnz/m0gx+Du3mDLCrAjtjrl88kM74qE Cp5mFE15Wvhh3f1s27ZSqXkEu5OF+lfGor5Wrfj0l5O3pxi9S1EL7mp4o7Oe/HeiKM9F LCpGNA6hlNTzY4yjQMhvU6nc35As2XQMnrf1XX4/15okUeAhhcMCa1Gnmm2K9WIvgmvR zl3m+6JwMfnt6h9U4ZHnSdq7urK43SrMEou/+b5uPJ2UacoTG//+bzcX5Daadaw4uXYx OCHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=zIgIQNH9egSlrVYC+AMp4lopK69544ScTJ4QfR0a69c=; b=D7d1ibYweehymZuqr48UOol0EiExiQr2oqqq549ZPM8EuHbp895I0dluKtJFPOC8OG fzD4zJLcpqqdR9bMLnn8sjlLlg+6brawzku9b3MByq4Ujct34e6OLfr6sD2oo+AJJJ1C lIypUKeVqqJqiPaDY+fcNcb1MZYau2nHzCVGIk6+upAZ25hKBvHg204g6ysBe8LAG21Z kUOQeonxQXPJTjfSbxHEFwWIRxrAzr8JWJBjFBmHo7ocPqWivta6bjozUFCv+cqfMxXj HDfE4bUDHU2aw9EFELmLsF5wXQa/+8+FnxkCOOlwtg98cSiMLuA9TWevJArpfMFmVeFU QROg== X-Gm-Message-State: ACgBeo0OQPfXEQKYlwwds5Be+baTu7mQv6KpozdxKTs9XFBaejt34ZGR i/rT6H9OZk05JyHeNsGSs+V9yXFakFX3xg== X-Google-Smtp-Source: AA6agR5uk6TUYZk9L+excfFGHmpc/AaXOvaka5lWnHGNqZ5L415Ll7yw0UTECfVKJMq5fnbr1HYM2g== X-Received: by 2002:a2e:97cd:0:b0:261:9bfc:3941 with SMTP id m13-20020a2e97cd000000b002619bfc3941mr531462ljj.110.1660658594241; Tue, 16 Aug 2022 07:03:14 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:13 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 02/16] crypto: ux500/hash: Get rid of custom device list Date: Tue, 16 Aug 2022 16:00:35 +0200 Message-Id: <20220816140049.102306-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The Ux500 hash driver builds a list with one (1) hash engine as it is all it has, then goes to great lengths to lock the one device using a semaphore. Instead do what other drivers do: trust the core to do the right thing, add the device state to the algorithm template, fill it in when registering the algorithms and assign the device state to the context when intializing each context. This saves us from a lot of complex code. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_core.c | 194 +++----------------------- 1 file changed, 17 insertions(+), 177 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 1662e176de44..5c2da6d42121 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -59,19 +58,6 @@ static const u8 zero_message_hmac_sha256[SHA256_DIGEST_SIZE] = { 0xc6, 0xc7, 0x12, 0x14, 0x42, 0x92, 0xc5, 0xad }; -/** - * struct hash_driver_data - data specific to the driver. - * - * @device_list: A list of registered devices to choose from. - * @device_allocation: A semaphore initialized with number of devices. - */ -struct hash_driver_data { - struct klist device_list; - struct semaphore device_allocation; -}; - -static struct hash_driver_data driver_data; - /* Declaration of functions */ /** * hash_messagepad - Pads a message and write the nblw bits. @@ -86,24 +72,6 @@ static struct hash_driver_data driver_data; static void hash_messagepad(struct hash_device_data *device_data, const u32 *message, u8 index_bytes); -/** - * release_hash_device - Releases a previously allocated hash device. - * @device_data: Structure for the hash device. - * - */ -static void release_hash_device(struct hash_device_data *device_data) -{ - spin_lock(&device_data->ctx_lock); - device_data->current_ctx->device = NULL; - device_data->current_ctx = NULL; - spin_unlock(&device_data->ctx_lock); - - /* - * The down_interruptible part for this semaphore is called in - * cryp_get_device_data. - */ - up(&driver_data.device_allocation); -} static void hash_dma_setup_channel(struct hash_device_data *device_data, struct device *dev) @@ -354,65 +322,6 @@ static int hash_enable_power(struct hash_device_data *device_data, return ret; } -/** - * hash_get_device_data - Checks for an available hash device and return it. - * @ctx: Structure for the hash context. - * @device_data: Structure for the hash device. - * - * This function check for an available hash device and return it to - * the caller. - * Note! Caller need to release the device, calling up(). - */ -static int hash_get_device_data(struct hash_ctx *ctx, - struct hash_device_data **device_data) -{ - int ret; - struct klist_iter device_iterator; - struct klist_node *device_node; - struct hash_device_data *local_device_data = NULL; - - /* Wait until a device is available */ - ret = down_interruptible(&driver_data.device_allocation); - if (ret) - return ret; /* Interrupted */ - - /* Select a device */ - klist_iter_init(&driver_data.device_list, &device_iterator); - device_node = klist_next(&device_iterator); - while (device_node) { - local_device_data = container_of(device_node, - struct hash_device_data, list_node); - spin_lock(&local_device_data->ctx_lock); - /* current_ctx allocates a device, NULL = unallocated */ - if (local_device_data->current_ctx) { - device_node = klist_next(&device_iterator); - } else { - local_device_data->current_ctx = ctx; - ctx->device = local_device_data; - spin_unlock(&local_device_data->ctx_lock); - break; - } - spin_unlock(&local_device_data->ctx_lock); - } - klist_iter_exit(&device_iterator); - - if (!device_node) { - /** - * No free device found. - * Since we allocated a device with down_interruptible, this - * should not be able to happen. - * Number of available devices, which are contained in - * device_allocation, is therefore decremented by not doing - * an up(device_allocation). - */ - return -EBUSY; - } - - *device_data = local_device_data; - - return 0; -} - /** * hash_hw_write_key - Writes the key to the hardware registries. * @@ -859,14 +768,10 @@ static int hash_dma_final(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); struct hash_req_ctx *req_ctx = ahash_request_ctx(req); - struct hash_device_data *device_data; + struct hash_device_data *device_data = ctx->device; u8 digest[SHA256_DIGEST_SIZE]; int bytes_written = 0; - ret = hash_get_device_data(ctx, &device_data); - if (ret) - return ret; - dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, (unsigned long)ctx); @@ -944,8 +849,6 @@ static int hash_dma_final(struct ahash_request *req) memcpy(req->result, digest, ctx->digestsize); out: - release_hash_device(device_data); - /** * Allocated in setkey, and only used in HMAC. */ @@ -964,13 +867,9 @@ static int hash_hw_final(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); struct hash_req_ctx *req_ctx = ahash_request_ctx(req); - struct hash_device_data *device_data; + struct hash_device_data *device_data = ctx->device; u8 digest[SHA256_DIGEST_SIZE]; - ret = hash_get_device_data(ctx, &device_data); - if (ret) - return ret; - dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, (unsigned long)ctx); @@ -1047,7 +946,6 @@ static int hash_hw_final(struct ahash_request *req) memcpy(req->result, digest, ctx->digestsize); out: - release_hash_device(device_data); /** * Allocated in setkey, and only used in HMAC. @@ -1068,36 +966,29 @@ int hash_hw_update(struct ahash_request *req) int ret = 0; u8 index = 0; u8 *buffer; - struct hash_device_data *device_data; u8 *data_buffer; struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); struct hash_req_ctx *req_ctx = ahash_request_ctx(req); + struct hash_device_data *device_data = ctx->device; struct crypto_hash_walk walk; int msg_length; index = req_ctx->state.index; buffer = (u8 *)req_ctx->state.buffer; - ret = hash_get_device_data(ctx, &device_data); - if (ret) - return ret; - msg_length = crypto_hash_walk_first(req, &walk); /* Empty message ("") is correct indata */ - if (msg_length == 0) { - ret = 0; - goto release_dev; - } + if (msg_length == 0) + return 0; /* Check if ctx->state.length + msg_length overflows */ if (msg_length > (req_ctx->state.length.low_word + msg_length) && HASH_HIGH_WORD_MAX_VAL == req_ctx->state.length.high_word) { pr_err("%s: HASH_MSG_LENGTH_OVERFLOW!\n", __func__); - ret = crypto_hash_walk_done(&walk, -EPERM); - goto release_dev; + return crypto_hash_walk_done(&walk, -EPERM); } /* Main loop */ @@ -1110,7 +1001,7 @@ int hash_hw_update(struct ahash_request *req) dev_err(device_data->dev, "%s: hash_internal_hw_update() failed!\n", __func__); crypto_hash_walk_done(&walk, ret); - goto release_dev; + return ret; } msg_length = crypto_hash_walk_done(&walk, 0); @@ -1120,10 +1011,7 @@ int hash_hw_update(struct ahash_request *req) dev_dbg(device_data->dev, "%s: indata length=%d, bin=%d\n", __func__, req_ctx->state.index, req_ctx->state.bit_index); -release_dev: - release_hash_device(device_data); - - return ret; + return 0; } /** @@ -1495,6 +1383,7 @@ static int hmac_sha256_setkey(struct crypto_ahash *tfm, struct hash_algo_template { struct hash_config conf; struct ahash_alg hash; + struct hash_device_data *device; }; static int hash_cra_init(struct crypto_tfm *tfm) @@ -1507,6 +1396,8 @@ static int hash_cra_init(struct crypto_tfm *tfm) struct hash_algo_template, hash); + ctx->device = hash_alg->device; + crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), sizeof(struct hash_req_ctx)); @@ -1623,6 +1514,7 @@ static int ahash_algs_register_all(struct hash_device_data *device_data) int count; for (i = 0; i < ARRAY_SIZE(hash_algs); i++) { + hash_algs[i].device = device_data; ret = crypto_register_ahash(&hash_algs[i].hash); if (ret) { count = i; @@ -1723,11 +1615,6 @@ static int ux500_hash_probe(struct platform_device *pdev) platform_set_drvdata(pdev, device_data); - /* Put the new device into the device list... */ - klist_add_tail(&device_data->list_node, &driver_data.device_list); - /* ... and signal that a new device is available. */ - up(&driver_data.device_allocation); - ret = ahash_algs_register_all(device_data); if (ret) { dev_err(dev, "%s: ahash_algs_register_all() failed!\n", @@ -1766,10 +1653,6 @@ static int ux500_hash_remove(struct platform_device *pdev) return -ENOMEM; } - /* Try to decrease the number of available devices. */ - if (down_trylock(&driver_data.device_allocation)) - return -EBUSY; - /* Check that the device is free */ spin_lock(&device_data->ctx_lock); /* current_ctx allocates a device, NULL = unallocated */ @@ -1777,19 +1660,12 @@ static int ux500_hash_remove(struct platform_device *pdev) /* The device is busy */ spin_unlock(&device_data->ctx_lock); /* Return the device to the pool. */ - up(&driver_data.device_allocation); return -EBUSY; } spin_unlock(&device_data->ctx_lock); - /* Remove the device from the list */ - if (klist_node_attached(&device_data->list_node)) - klist_remove(&device_data->list_node); - - /* If this was the last device, remove the services */ - if (list_empty(&driver_data.device_list.k_list)) - ahash_algs_unregister_all(device_data); + ahash_algs_unregister_all(device_data); if (hash_disable_power(device_data, false)) dev_err(dev, "%s: hash_disable_power() failed\n", @@ -1820,9 +1696,6 @@ static void ux500_hash_shutdown(struct platform_device *pdev) spin_lock(&device_data->ctx_lock); /* current_ctx allocates a device, NULL = unallocated */ if (!device_data->current_ctx) { - if (down_trylock(&driver_data.device_allocation)) - dev_dbg(&pdev->dev, "%s: Cryp still in use! Shutting down anyway...\n", - __func__); /** * (Allocate the device) * Need to set this to non-null (dummy) value, @@ -1832,13 +1705,7 @@ static void ux500_hash_shutdown(struct platform_device *pdev) } spin_unlock(&device_data->ctx_lock); - /* Remove the device from the list */ - if (klist_node_attached(&device_data->list_node)) - klist_remove(&device_data->list_node); - - /* If this was the last device, remove the services */ - if (list_empty(&driver_data.device_list.k_list)) - ahash_algs_unregister_all(device_data); + ahash_algs_unregister_all(device_data); if (hash_disable_power(device_data, false)) dev_err(&pdev->dev, "%s: hash_disable_power() failed\n", @@ -1868,9 +1735,6 @@ static int ux500_hash_suspend(struct device *dev) spin_unlock(&device_data->ctx_lock); if (device_data->current_ctx == ++temp_ctx) { - if (down_interruptible(&driver_data.device_allocation)) - dev_dbg(dev, "%s: down_interruptible() failed\n", - __func__); ret = hash_disable_power(device_data, false); } else { @@ -1904,9 +1768,7 @@ static int ux500_hash_resume(struct device *dev) device_data->current_ctx = NULL; spin_unlock(&device_data->ctx_lock); - if (!device_data->current_ctx) - up(&driver_data.device_allocation); - else + if (device_data->current_ctx) ret = hash_enable_power(device_data, true); if (ret) @@ -1924,7 +1786,7 @@ static const struct of_device_id ux500_hash_match[] = { }; MODULE_DEVICE_TABLE(of, ux500_hash_match); -static struct platform_driver hash_driver = { +static struct platform_driver ux500_hash_driver = { .probe = ux500_hash_probe, .remove = ux500_hash_remove, .shutdown = ux500_hash_shutdown, @@ -1934,29 +1796,7 @@ static struct platform_driver hash_driver = { .pm = &ux500_hash_pm, } }; - -/** - * ux500_hash_mod_init - The kernel module init function. - */ -static int __init ux500_hash_mod_init(void) -{ - klist_init(&driver_data.device_list, NULL, NULL); - /* Initialize the semaphore to 0 devices (locked state) */ - sema_init(&driver_data.device_allocation, 0); - - return platform_driver_register(&hash_driver); -} - -/** - * ux500_hash_mod_fini - The kernel module exit function. - */ -static void __exit ux500_hash_mod_fini(void) -{ - platform_driver_unregister(&hash_driver); -} - -module_init(ux500_hash_mod_init); -module_exit(ux500_hash_mod_fini); +module_platform_driver(ux500_hash_driver); MODULE_DESCRIPTION("Driver for ST-Ericsson UX500 HASH engine."); MODULE_LICENSE("GPL"); From patchwork Tue Aug 16 14:00:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944986 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BDFFC3F6B0 for ; Tue, 16 Aug 2022 14:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235744AbiHPOD2 (ORCPT ); Tue, 16 Aug 2022 10:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235844AbiHPODW (ORCPT ); Tue, 16 Aug 2022 10:03:22 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3742A3ECDF for ; Tue, 16 Aug 2022 07:03:17 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id z25so15067561lfr.2 for ; Tue, 16 Aug 2022 07:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=nAlowoVFY0LcXDiOUlU807XVFbbZNi0DFVp+JS034i0=; b=ykNHTA7elg26WsKl+wkQtE1lPFJbx0ZIxDFD/Vn+L0LWG3K0P5rECp0f4ZmSrLWazp /2id6tjVZVx8zv2SOJpZ3vc3+kMlHdWvEvtEWv/CMcGttuiL+FXR9mpwJyOO+glP5D2p /Ngv8LzramGa6QdcDkC/uG69MCjw6bmtcPOl+4azMQlhD8foywMrNilYTklXEnx6te0/ OzdHVpm2UkPo7IrMBY4hq5MC7xS0SJqz+77BaQpSNMnD0oJJ2c5ElyUYZxVRP0aZ3Y85 ldzC4cS1OTAlXUnJc6OjyzfKHuxtZuWuPFpnJXAu0PBOloG1ELjHpG0kkfdSIlQtVnXp ihnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=nAlowoVFY0LcXDiOUlU807XVFbbZNi0DFVp+JS034i0=; b=G1GWq455F6DL5+OlL/aTdXR7v+C9hTq4u5C5swLThm/rhRS54YPvyVnW8c0RAQoQoO kYzlnDdXUzPYpeRG11xwjyGh10IPTGmj+nNCFSq6i1ORDAFfPH5HnWaJvOy1dIWbXQxW d4BSHxSdTkvf9QQLN+7/gMHgNa1pifLhQi4s/BdxuFfdHHokINxiWxQm6TpPJ+IohSrW c0pF5mLnz16lvbssTfIhAZtb99uE7UdPJRFIIvWu7IdzoUUJ8PkLs0gdZTEL7DsY7Upz hu6Cp+xW2eP3raLvTJ5GSo0U1juG6Rt/mS8shklW0xntcpPPtW0sNdMTqVAEd8D13Law 96KA== X-Gm-Message-State: ACgBeo2B7h/+bNF+CZ9QQL2TTlMfrrc0gK/6XLSMd01U+P23Y5DU9DwX 2MKM5gLVlZO6FGoLOH/sRCiIh1SDHyuJhg== X-Google-Smtp-Source: AA6agR7KwaC5Otr26WZl/PeY9RCVB23kXI3MI1GQ3pp8ux4dKz9wK/PPQSp3+5IoThcFatUi/L2JpA== X-Received: by 2002:a05:6512:230a:b0:48c:2e06:6c74 with SMTP id o10-20020a056512230a00b0048c2e066c74mr7497057lfu.358.1660658595434; Tue, 16 Aug 2022 07:03:15 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:15 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 03/16] crypto: ux500/hash: Pass context to zero message digest Date: Tue, 16 Aug 2022 16:00:36 +0200 Message-Id: <20220816140049.102306-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This function obtains the current context from the device state pointer, which is fragile. Pass the context explicitly instead. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 5c2da6d42121..aa6bbae107cd 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -183,11 +183,10 @@ static int hash_dma_write(struct hash_ctx *ctx, * @zero_digest: True if zero_digest returned. */ static int get_empty_message_digest( - struct hash_device_data *device_data, + struct hash_device_data *device_data, struct hash_ctx *ctx, u8 *zero_hash, u32 *zero_hash_size, bool *zero_digest) { int ret = 0; - struct hash_ctx *ctx = device_data->current_ctx; *zero_digest = false; /** @@ -889,7 +888,7 @@ static int hash_hw_final(struct ahash_request *req) * Use a pre-calculated empty message digest * (workaround since hw return zeroes, hw bug!?) */ - ret = get_empty_message_digest(device_data, &zero_hash[0], + ret = get_empty_message_digest(device_data, ctx, &zero_hash[0], &zero_hash_size, &zero_digest); if (!ret && likely(zero_hash_size == ctx->digestsize) && zero_digest) { From patchwork Tue Aug 16 14:00:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944988 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A525C2BB41 for ; Tue, 16 Aug 2022 14:03:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235845AbiHPODa (ORCPT ); Tue, 16 Aug 2022 10:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235850AbiHPODY (ORCPT ); Tue, 16 Aug 2022 10:03:24 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F05A4F64B for ; Tue, 16 Aug 2022 07:03:18 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id u3so15048382lfk.8 for ; Tue, 16 Aug 2022 07:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=3hdGrIQ299lWEia0LRNRsH0WiIkUXzcfHJxdjTksbeY=; b=aDb6oRbTUav887/pixDHR2STjGNB7SH6U3SiRfOgf51fHKYFsirOyX31PcM9bao8ou sXROU2ZUvor/CGrgjUELCeN/Wo4zI8vkmCQAZAgipVLuJDCeUWxbb24hnq7HvUxaOe84 epvMo3NNYFMIKeHha0M4SgKIkJxfcCLYgzIve5z2w3kWTVFX9yncHNI4OUI+G/L17eEy a3yCKnPCjqUmtHMM10LVgJcOcCznfVimGo/Qj6UMCAsEYuSTi4VtRjdUMec5WHdM2Ten b+1N1n/swhwGBDiD4T+VzPia5K9BOTQYV1g/yjQMNbgW3/QiQrfhXXg2sSlIHpHm2H7W ffhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=3hdGrIQ299lWEia0LRNRsH0WiIkUXzcfHJxdjTksbeY=; b=AZdJCA7OyY8XnZJ1zbX3HsrUKJLhx5ErPFTWugoYAJfpcSw/Dscg3USgtIhcCeJzXl tHqActcSLMYxPEp9fTTxwK7m4rRrCA3Pimr62KC1McvXswl75HAd6NllHxfpF9EDPVUa //XtVqY3/XARYZC8qfz2u/pQYASPQHR5qhe58ckOebEivQlqM0whcVzftBptjqgzZduY AbLRgjBsnZgZUtT+pG8I+o/9Bt0ZMtOPK+9kjO+LQ0wdS73MICPUn9XX3J/FzIsRflOZ kZfjHJXtJR+laesQWrgqxxGMum8N6ooko1pG3BxRALNAdO9tMezlOJyyLUIMFnF2tCRk haEw== X-Gm-Message-State: ACgBeo0FTBBvO8560Lu3wB6xHoxKAMOe91HOs8bRFYuR4/eU2gCf+IhR ENrKysZkSQU00WGZJTk0nyKTzXWMjJJ1xg== X-Google-Smtp-Source: AA6agR5pX4QOud24aTiuXTToEkBKj5LLVsmQBYveANhSWYtmdmsba+yHZBXgJ/qp9qWgiOWJVkJXdg== X-Received: by 2002:ac2:44af:0:b0:48a:f361:fe1d with SMTP id c15-20020ac244af000000b0048af361fe1dmr7601083lfm.190.1660658596764; Tue, 16 Aug 2022 07:03:16 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:16 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 04/16] crypto: ux500/hash: Drop custom state save/restore Date: Tue, 16 Aug 2022 16:00:37 +0200 Message-Id: <20220816140049.102306-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Drop the code that is saving and restoring the device state as part of the PM operations: this is the job of .import and .export, do not try to work around the framework. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_core.c | 52 +++++---------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index aa6bbae107cd..fbd6335f142b 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -243,13 +243,11 @@ static int get_empty_message_digest( /** * hash_disable_power - Request to disable power and clock. * @device_data: Structure for the hash device. - * @save_device_state: If true, saves the current hw state. * * This function request for disabling power (regulator) and clock, * and could also save current hw state. */ -static int hash_disable_power(struct hash_device_data *device_data, - bool save_device_state) +static int hash_disable_power(struct hash_device_data *device_data) { int ret = 0; struct device *dev = device_data->dev; @@ -258,12 +256,6 @@ static int hash_disable_power(struct hash_device_data *device_data, if (!device_data->power_state) goto out; - if (save_device_state) { - hash_save_state(device_data, - &device_data->state); - device_data->restore_dev_state = true; - } - clk_disable(device_data->clk); ret = regulator_disable(device_data->regulator); if (ret) @@ -280,13 +272,11 @@ static int hash_disable_power(struct hash_device_data *device_data, /** * hash_enable_power - Request to enable power and clock. * @device_data: Structure for the hash device. - * @restore_device_state: If true, restores a previous saved hw state. * * This function request for enabling power (regulator) and clock, * and could also restore a previously saved hw state. */ -static int hash_enable_power(struct hash_device_data *device_data, - bool restore_device_state) +static int hash_enable_power(struct hash_device_data *device_data) { int ret = 0; struct device *dev = device_data->dev; @@ -309,12 +299,6 @@ static int hash_enable_power(struct hash_device_data *device_data, device_data->power_state = true; } - if (device_data->restore_dev_state) { - if (restore_device_state) { - device_data->restore_dev_state = false; - hash_resume_state(device_data, &device_data->state); - } - } out: spin_unlock(&device_data->power_state_lock); @@ -1597,7 +1581,7 @@ static int ux500_hash_probe(struct platform_device *pdev) } /* Enable device power (and clock) */ - ret = hash_enable_power(device_data, false); + ret = hash_enable_power(device_data); if (ret) { dev_err(dev, "%s: hash_enable_power() failed!\n", __func__); goto out_clk_unprepare; @@ -1625,7 +1609,7 @@ static int ux500_hash_probe(struct platform_device *pdev) return 0; out_power: - hash_disable_power(device_data, false); + hash_disable_power(device_data); out_clk_unprepare: clk_unprepare(device_data->clk); @@ -1666,7 +1650,7 @@ static int ux500_hash_remove(struct platform_device *pdev) ahash_algs_unregister_all(device_data); - if (hash_disable_power(device_data, false)) + if (hash_disable_power(device_data)) dev_err(dev, "%s: hash_disable_power() failed\n", __func__); @@ -1706,7 +1690,7 @@ static void ux500_hash_shutdown(struct platform_device *pdev) ahash_algs_unregister_all(device_data); - if (hash_disable_power(device_data, false)) + if (hash_disable_power(device_data)) dev_err(&pdev->dev, "%s: hash_disable_power() failed\n", __func__); } @@ -1720,7 +1704,6 @@ static int ux500_hash_suspend(struct device *dev) { int ret; struct hash_device_data *device_data; - struct hash_ctx *temp_ctx = NULL; device_data = dev_get_drvdata(dev); if (!device_data) { @@ -1728,18 +1711,7 @@ static int ux500_hash_suspend(struct device *dev) return -ENOMEM; } - spin_lock(&device_data->ctx_lock); - if (!device_data->current_ctx) - device_data->current_ctx++; - spin_unlock(&device_data->ctx_lock); - - if (device_data->current_ctx == ++temp_ctx) { - ret = hash_disable_power(device_data, false); - - } else { - ret = hash_disable_power(device_data, true); - } - + ret = hash_disable_power(device_data); if (ret) dev_err(dev, "%s: hash_disable_power()\n", __func__); @@ -1754,7 +1726,6 @@ static int ux500_hash_resume(struct device *dev) { int ret = 0; struct hash_device_data *device_data; - struct hash_ctx *temp_ctx = NULL; device_data = dev_get_drvdata(dev); if (!device_data) { @@ -1762,14 +1733,7 @@ static int ux500_hash_resume(struct device *dev) return -ENOMEM; } - spin_lock(&device_data->ctx_lock); - if (device_data->current_ctx == ++temp_ctx) - device_data->current_ctx = NULL; - spin_unlock(&device_data->ctx_lock); - - if (device_data->current_ctx) - ret = hash_enable_power(device_data, true); - + ret = hash_enable_power(device_data); if (ret) dev_err(dev, "%s: hash_enable_power() failed!\n", __func__); From patchwork Tue Aug 16 14:00:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944992 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1384C28B2B for ; Tue, 16 Aug 2022 14:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235851AbiHPODo (ORCPT ); Tue, 16 Aug 2022 10:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235864AbiHPOD0 (ORCPT ); Tue, 16 Aug 2022 10:03:26 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDCB57896 for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id l10so10618357lje.7 for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=sctki4nak4ZBSfbhd2II7H8or4YuNVPYzsqrowWkZ4E=; b=f5JUTuZhfEMvSB6ln1mYJLWrWHK3VNXsVun6B98tIgrH2UdZzjUi+CRmw9p5jq6zc/ mFvIn+abPhojCqvHi32zTMH0KPm3JmGkawcWmysalrSIO1hbTnhNuH/P4miE8KRVSssL f3hxkeqUeuWO3Z88cNwG8dNoijjoBO/1KDWuMLSQaI8rvTJMaToyJTu9i8aEXofym1CN eBXg3N+DocOztz6ZN0xxnRV9K2xjgeDtiVLFxUd87hiGdmjnvqfGexlZPoNWUzrMD9MO 6apqIHn/W8HIZzZU0ta4bqMPfeRq68RJtWoniERoNtkL4ah8wO3cVGlXZyj7zn8k267P 1g8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=sctki4nak4ZBSfbhd2II7H8or4YuNVPYzsqrowWkZ4E=; b=5Qbpt1arkK99Ea0mz6DfJrAns5nLw1cvFPhc3PFY3DPpC7vEm542FsiujP1cIRonXd 7bs3vRFY3JylMwCnakBL3qmziDhvh+2BfLB0Zx9B31dncE1+AHuK47o3z9QjhdPIgt5i a67lGMbSPy1w+5JTr0FkY5HvVK5cchqfyklBCY17oDeku9SPFindiSKCXZi8wWv4lXrU x77R/mPEtB4JLiHtxNIBM97J9WbaPJciBC/PCR6IDti3nnPNdOA6YUfsIgag1n6TpFH7 yeYnAxRPxdJPK+4x9KMQleGpihgrtSD+86ql1QOP/6nq3FDC0Nb5cQLBR6M1F5aydX+x u9bA== X-Gm-Message-State: ACgBeo1H/Jhw3hCgfskv7i74cF+vDIXZbIPmyk9Qe0QzbCQGcxrK91No XRSQuEwl/0rLTP8CPEPIt03IXoFRXWjcVA== X-Google-Smtp-Source: AA6agR6o6w78tVBFUXeTZtdyBttUTprdNcoKY82rKt9uZTzM29vRMHra8jrDdhOnG2W8B51RL9YmlA== X-Received: by 2002:a2e:9147:0:b0:25e:5764:9c9f with SMTP id q7-20020a2e9147000000b0025e57649c9fmr6714667ljg.278.1660658598029; Tue, 16 Aug 2022 07:03:18 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:17 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 05/16] crypto: ux500/hash: Drop bit index Date: Tue, 16 Aug 2022 16:00:38 +0200 Message-Id: <20220816140049.102306-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This is some leftover code because the field is only referenced in a debug print and never assigned. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 4 ---- drivers/crypto/ux500/hash/hash_core.c | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 26e8b7949d7c..00730c0090ae 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -217,7 +217,6 @@ struct hash_register { * @buffer: Working buffer for messages going to the hardware. * @length: Length of the part of message hashed so far (floor(N/64) * 64). * @index: Valid number of bytes in buffer (N % 64). - * @bit_index: Valid number of bits in buffer (N % 8). * * This structure is used between context switches, i.e. when ongoing jobs are * interupted with new jobs. When this happens we need to store intermediate @@ -237,7 +236,6 @@ struct hash_state { u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; struct uint64 length; u8 index; - u8 bit_index; }; /** @@ -358,7 +356,6 @@ struct hash_req_ctx { * @power_state_lock: Spinlock for power_state. * @regulator: Pointer to the device's power control. * @clk: Pointer to the device's clock control. - * @restore_dev_state: TRUE = saved state, FALSE = no saved state. * @dma: Structure used for dma. */ struct hash_device_data { @@ -372,7 +369,6 @@ struct hash_device_data { spinlock_t power_state_lock; struct regulator *regulator; struct clk *clk; - bool restore_dev_state; struct hash_state state; /* Used for saving and resuming state */ struct hash_dma dma; }; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index fbd6335f142b..65d328d438d2 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -991,8 +991,8 @@ int hash_hw_update(struct ahash_request *req) } req_ctx->state.index = index; - dev_dbg(device_data->dev, "%s: indata length=%d, bin=%d\n", - __func__, req_ctx->state.index, req_ctx->state.bit_index); + dev_dbg(device_data->dev, "%s: indata length=%d\n", + __func__, req_ctx->state.index); return 0; } From patchwork Tue Aug 16 14:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944989 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF907C25B0E for ; Tue, 16 Aug 2022 14:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235885AbiHPODm (ORCPT ); Tue, 16 Aug 2022 10:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235852AbiHPOD0 (ORCPT ); Tue, 16 Aug 2022 10:03:26 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDD2E2ED7A for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id x10so10628290ljq.4 for ; Tue, 16 Aug 2022 07:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=bNKl0WqaDu3QbRj292AtPq5phFFaJ1mJK+ISPGQQtjg=; b=NWxN02FM48jW+daL9f2AZliag0Jn6d1w+rXbGPDPXcwvM1cXkH7dVdqPiMHQ8Og/tm EFX9SBKfPv3OhSvG9gBy3a+VfSbZeorLUX7I3n5ToARHj56DWJ3lhBNqAEwqT7XJgKyF Rvxy51yWlTBMB3R9Ey+nqKGqzof/01x+iXss8pGkIG0UdHgVE7V0eh4zMo1HMEVQoEVD YB2fyOx22dbPK2eCTEqZB1iD9NO2R3K5ptkwDw1PqEONYPlXR/6uLghYfoAmiiZX09BS OwEDEmB2FXQT/wSFlCOPXTHQEfjzICZJWyyRmOzH6pkExWnXBJoXgMNAQF18nXu13UPL lP8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bNKl0WqaDu3QbRj292AtPq5phFFaJ1mJK+ISPGQQtjg=; b=3A0cVBHQWdpbjqwL21HM0ZbO73u8Rryy+Hzs+ga3ybnybfKNBSmM3QnWFwwSEwbofe 1Mep7+0Js4OhnN/FzBOf2t4SZbeMOWY9WWvKWvpiB/gUAmzAAFlSa6ql2HtGDnlYFqgC 0cgwaf4ezpY2YpAuMZevxYbuxLZdkRDArgVaQ+FPHFkUx23W9l9ZP8scEnL74B6LsJWK 3Fkakw3Ugao3RvbjUcIqce9oLxGnFRqVW3vLKOOHqcFp/ih3PIzg1tVTn6nODp4Wm856 fzWO7JzY7tyS/LMQ9kDH31DaYa+qrUqSZ7pv6QdwJ9E+9s/iPQRK6xuFkORaPP8QGQju Hu6g== X-Gm-Message-State: ACgBeo3FknCt0cRa68LQrV7ikApT5IVRbzmwceORLcuvmx5qoIZuS9jK h9eWHgXUMf96z4a4LBIWd1ZGsb5fPqxVIA== X-Google-Smtp-Source: AA6agR7XT4TMfhW9QRr8BZRSDjpQjQZXMR5qB9I0CYLSIsxKaSQUwPV7DIP9leLWIiEZRHNulNlixw== X-Received: by 2002:a2e:a236:0:b0:260:8ac:9182 with SMTP id i22-20020a2ea236000000b0026008ac9182mr6429203ljm.71.1660658599337; Tue, 16 Aug 2022 07:03:19 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:18 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 06/16] crypto: ux500/hash: Break while/do instead of if/else Date: Tue, 16 Aug 2022 16:00:39 +0200 Message-Id: <20220816140049.102306-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Instead of a deeply nested if/else inside the while/do loop, just break the loop as we know the termination requirement was just established (msg_length == 0). Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_core.c | 115 +++++++++++++------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 65d328d438d2..b559c53dc703 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -671,69 +671,70 @@ static int hash_process_data(struct hash_device_data *device_data, } *index += msg_length; msg_length = 0; - } else { - if (req_ctx->updated) { - ret = hash_resume_state(device_data, - &device_data->state); - memmove(req_ctx->state.buffer, - device_data->state.buffer, - HASH_BLOCK_SIZE); - if (ret) { - dev_err(device_data->dev, - "%s: hash_resume_state() failed!\n", - __func__); - goto out; - } - } else { - ret = init_hash_hw(device_data, ctx); - if (ret) { - dev_err(device_data->dev, - "%s: init_hash_hw() failed!\n", - __func__); - goto out; - } - req_ctx->updated = 1; - } - /* - * If 'data_buffer' is four byte aligned and - * local buffer does not have any data, we can - * write data directly from 'data_buffer' to - * HW peripheral, otherwise we first copy data - * to a local buffer - */ - if (IS_ALIGNED((unsigned long)data_buffer, 4) && - (0 == *index)) - hash_processblock(device_data, - (const u32 *)data_buffer, - HASH_BLOCK_SIZE); - else { - for (count = 0; - count < (u32)(HASH_BLOCK_SIZE - *index); - count++) { - buffer[*index + count] = - *(data_buffer + count); - } - hash_processblock(device_data, - (const u32 *)buffer, - HASH_BLOCK_SIZE); - } - hash_incrementlength(req_ctx, HASH_BLOCK_SIZE); - data_buffer += (HASH_BLOCK_SIZE - *index); - - msg_length -= (HASH_BLOCK_SIZE - *index); - *index = 0; - - ret = hash_save_state(device_data, - &device_data->state); + break; + } - memmove(device_data->state.buffer, - req_ctx->state.buffer, + if (req_ctx->updated) { + ret = hash_resume_state(device_data, + &device_data->state); + memmove(req_ctx->state.buffer, + device_data->state.buffer, HASH_BLOCK_SIZE); if (ret) { - dev_err(device_data->dev, "%s: hash_save_state() failed!\n", + dev_err(device_data->dev, + "%s: hash_resume_state() failed!\n", __func__); goto out; } + } else { + ret = init_hash_hw(device_data, ctx); + if (ret) { + dev_err(device_data->dev, + "%s: init_hash_hw() failed!\n", + __func__); + goto out; + } + req_ctx->updated = 1; + } + /* + * If 'data_buffer' is four byte aligned and + * local buffer does not have any data, we can + * write data directly from 'data_buffer' to + * HW peripheral, otherwise we first copy data + * to a local buffer + */ + if (IS_ALIGNED((unsigned long)data_buffer, 4) && + (*index == 0)) + hash_processblock(device_data, + (const u32 *)data_buffer, + HASH_BLOCK_SIZE); + else { + for (count = 0; + count < (u32)(HASH_BLOCK_SIZE - *index); + count++) { + buffer[*index + count] = + *(data_buffer + count); + } + hash_processblock(device_data, + (const u32 *)buffer, + HASH_BLOCK_SIZE); + } + hash_incrementlength(req_ctx, HASH_BLOCK_SIZE); + data_buffer += (HASH_BLOCK_SIZE - *index); + + msg_length -= (HASH_BLOCK_SIZE - *index); + *index = 0; + + ret = hash_save_state(device_data, + &device_data->state); + + memmove(device_data->state.buffer, + req_ctx->state.buffer, + HASH_BLOCK_SIZE); + if (ret) { + dev_err(device_data->dev, "%s: hash_save_state() failed!\n", + __func__); + goto out; } } while (msg_length != 0); out: From patchwork Tue Aug 16 14:00:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944991 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4106C2BB41 for ; Tue, 16 Aug 2022 14:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235892AbiHPODq (ORCPT ); Tue, 16 Aug 2022 10:03:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235855AbiHPOD1 (ORCPT ); Tue, 16 Aug 2022 10:03:27 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B641BE for ; Tue, 16 Aug 2022 07:03:23 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id x19so15059473lfq.7 for ; Tue, 16 Aug 2022 07:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=A70WX7DY4qkBKLEGBBQrXfzLaOJByga2AhTnjtGkloI=; b=ILxP7Y/jnoFu+RfOL3EGGDkSxVXMMS2ROa8dyVxCGlzk9BqX6QVdu/KGNigwWjtqE9 x27h0f0CysmHYhXbVg38KsMjGUjhL7F97DYGzq6a5lwH1NvcyIe77Ico+AZOoJEuXj8k Texj9AajA5RlzquoSi5GKZQIAArelAd99nJX7QMU6J38iVE+e5RBi/eT5tq0GXcJjsqe vYlh7BDhcGKzFtSzSZVIdrJNpFfT4mz3HwWOGTvIQVEItUUlALYlzKw5XqSQqS9gSeOp 6dknfEcDdr2w+XZ/L3vuyPr1pFt+xdo5N0MDAOrE/dW8Ez8vZ43UrCztCv8ZEFubcuhx OkOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=A70WX7DY4qkBKLEGBBQrXfzLaOJByga2AhTnjtGkloI=; b=AgVKRQsV0Au7zqxlH+bG6bbI+7l+RBMtqUy0ppIQYrFcXm4GaArlvSWskBlv6+qG3b rNnztOeIzS1+6XEGswDfgzSDA9qXAfjWkrU/emu/JfpGqRehwzmW636IVBl/x8XV2rnL 14x2gB2URaUry0cF4LCnzOBHkR0PCpg32CA+nONiMFIo+B34ORInIZEWW9immm3NsPps 0OoHpN1iAWnZrvxcdXWsh5eNutO21oVa6HokxQzM+9OCp55at+/PKWaIaqnZKHz7n1ge iPeZuz2Sa5ojxR+XERYpilE9hZQgzPVqA+M9LYe6bOnNvHzwklOJ6e1777wz4MxR21VC DwFQ== X-Gm-Message-State: ACgBeo1aC9EHrWgZsv/pCvb3RyBleSW82SGztAfueVyZqy6FbYbmRopZ uYo2HiHwItBWIkZIqR0EiWdkYfIyWAiSLA== X-Google-Smtp-Source: AA6agR4ECdixOwtqyQP3h7+yA6qBge6uWF2XSamZbE9VfMLZOEtIOwtoRKUtOOJuGfxalqOidLKkEA== X-Received: by 2002:a05:6512:68e:b0:491:8971:9efa with SMTP id t14-20020a056512068e00b0049189719efamr5235069lfe.514.1660658600741; Tue, 16 Aug 2022 07:03:20 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:20 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 07/16] crypto: ux500/hash: Rename and switch type of member Date: Tue, 16 Aug 2022 16:00:40 +0200 Message-Id: <20220816140049.102306-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The "updated" member of the context is very confusing, it actually means "hw_intialized" so rename it to this and switch it to a bool so it is clear how this is used. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 4 ++-- drivers/crypto/ux500/hash/hash_core.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 00730c0090ae..d124fd17519f 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -336,12 +336,12 @@ struct hash_ctx { * @state: The state of the current calculations. * @dma_mode: Used in special cases (workaround), e.g. need to change to * cpu mode, if not supported/working in dma mode. - * @updated: Indicates if hardware is initialized for new operations. + * @hw_initialized: Indicates if hardware is initialized for new operations. */ struct hash_req_ctx { struct hash_state state; bool dma_mode; - u8 updated; + bool hw_initialized; }; /** diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index b559c53dc703..c5cd9a5f7e5c 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -449,7 +449,7 @@ static int ux500_hash_init(struct ahash_request *req) ctx->keylen = 0; memset(&req_ctx->state, 0, sizeof(struct hash_state)); - req_ctx->updated = 0; + req_ctx->hw_initialized = false; if (hash_mode == HASH_MODE_DMA) { if (req->nbytes < HASH_DMA_ALIGN_SIZE) { req_ctx->dma_mode = false; /* Don't use DMA */ @@ -674,7 +674,7 @@ static int hash_process_data(struct hash_device_data *device_data, break; } - if (req_ctx->updated) { + if (req_ctx->hw_initialized) { ret = hash_resume_state(device_data, &device_data->state); memmove(req_ctx->state.buffer, @@ -694,7 +694,7 @@ static int hash_process_data(struct hash_device_data *device_data, __func__); goto out; } - req_ctx->updated = 1; + req_ctx->hw_initialized = true; } /* * If 'data_buffer' is four byte aligned and @@ -759,7 +759,7 @@ static int hash_dma_final(struct ahash_request *req) dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, (unsigned long)ctx); - if (req_ctx->updated) { + if (req_ctx->hw_initialized) { ret = hash_resume_state(device_data, &device_data->state); if (ret) { @@ -794,7 +794,7 @@ static int hash_dma_final(struct ahash_request *req) /* Number of bits in last word = (nbytes * 8) % 32 */ HASH_SET_NBLW((req->nbytes * 8) % 32); - req_ctx->updated = 1; + req_ctx->hw_initialized = true; } /* Store the nents in the dma struct. */ @@ -857,7 +857,7 @@ static int hash_hw_final(struct ahash_request *req) dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, (unsigned long)ctx); - if (req_ctx->updated) { + if (req_ctx->hw_initialized) { ret = hash_resume_state(device_data, &device_data->state); if (ret) { @@ -899,7 +899,7 @@ static int hash_hw_final(struct ahash_request *req) goto out; } - if (!req_ctx->updated) { + if (!req_ctx->hw_initialized) { ret = init_hash_hw(device_data, ctx); if (ret) { dev_err(device_data->dev, From patchwork Tue Aug 16 14:00:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944990 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3485BC2BB41 for ; Tue, 16 Aug 2022 14:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235852AbiHPODn (ORCPT ); Tue, 16 Aug 2022 10:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235851AbiHPOD0 (ORCPT ); Tue, 16 Aug 2022 10:03:26 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFEB1B9 for ; Tue, 16 Aug 2022 07:03:22 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id y23so10602778ljh.12 for ; Tue, 16 Aug 2022 07:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=vE+aW0nyiBU1fJkWezdCMzH7B9Qn6/AKvNwg7L28u/U=; b=axPyiZ0bm5BhK8rVP2fWFI6tyueVMbMoQryKim0gXmddKeN3IkzpqTzcP8z7z5mFQH N8Vkg2hoDCMQTRW3IRmf1vmhwO+aon0ayqYFHnjLHKtCoqePAdW1SRjcDSgXo//co24W z0zGwZynTreXv+mUlfdr9o9wd/m6v4El7LhVh4vnAZor6dHtrPJI545nruJcMLoP2Z5K I5XviAwCeUksPSJH8xb+ArlPEX04idtZoITuDwOBj/BdMzn3UEi3egbubC3N0MQqnQuK PERbKjtLkT8WRF8Uy1ovm1tf1a+HTP7PYWR3ujImX68PKFlLnYO1Ra3DILE33o+cTWVz eiNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=vE+aW0nyiBU1fJkWezdCMzH7B9Qn6/AKvNwg7L28u/U=; b=28uNLYx0jMJrTS184N7TesK5wTPyGIKfpiSLbdCSguYaL97TEnVx8LyydnTpFwAsf6 DIBvekIeqCWBdlLk/o95KKnE2A8z/cMb8x61jPWtkO17v/p22yby1DBVoexgKT7lha6f 7UTwszmMLBRCke4lnltAowREBPwHnh6Crm7UgA9NEHqdsinbUyT8tQg1/+NO8rbCtMBP e+/L22D8wN/zrKe/5l1wKjQOj2bZEiFbTNbWdL4oFEA0TStXrA3OaN64mjKi4mWlr4uD th/ysPB48s8VkBDocU7uN7bIwQVKT+Uxm04YHNM3ky5VmZjTBD3MGOfJRTRhcE9LtoU6 jvpA== X-Gm-Message-State: ACgBeo3s0t1dUgrF4pjBtvR2X1qfR3bxGGpNOpYRxRLXK0QPm6d8kSok 6r3BEVHje2sq/qMmZFjYSSNMijUV3kO3iA== X-Google-Smtp-Source: AA6agR7bykuYD9HHvkyQiRgpFBqN6f8Jv3eezb1aU7GXT/eOBOWJ7GJNC9nzWdXwUN8416J16/cKXQ== X-Received: by 2002:a2e:a7c8:0:b0:25e:792a:6fa8 with SMTP id x8-20020a2ea7c8000000b0025e792a6fa8mr6594019ljp.398.1660658602053; Tue, 16 Aug 2022 07:03:22 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:21 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 08/16] crypto: ux500/hash: Stop saving/restoring compulsively Date: Tue, 16 Aug 2022 16:00:41 +0200 Message-Id: <20220816140049.102306-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The driver is saving/restoring state very intensively, because of assumptions that suspend/resume can be called at any time. (Android behaviours.) We removed the state save/restore from the PM hooks and will use runtime PM for this instead so get rid of this. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 1 - drivers/crypto/ux500/hash/hash_core.c | 44 +++------------------------ 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index d124fd17519f..d9d59dba6e6e 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -369,7 +369,6 @@ struct hash_device_data { spinlock_t power_state_lock; struct regulator *regulator; struct clk *clk; - struct hash_state state; /* Used for saving and resuming state */ struct hash_dma dma; }; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index c5cd9a5f7e5c..844ef70301d5 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -674,19 +674,7 @@ static int hash_process_data(struct hash_device_data *device_data, break; } - if (req_ctx->hw_initialized) { - ret = hash_resume_state(device_data, - &device_data->state); - memmove(req_ctx->state.buffer, - device_data->state.buffer, - HASH_BLOCK_SIZE); - if (ret) { - dev_err(device_data->dev, - "%s: hash_resume_state() failed!\n", - __func__); - goto out; - } - } else { + if (!req_ctx->hw_initialized) { ret = init_hash_hw(device_data, ctx); if (ret) { dev_err(device_data->dev, @@ -725,17 +713,6 @@ static int hash_process_data(struct hash_device_data *device_data, msg_length -= (HASH_BLOCK_SIZE - *index); *index = 0; - ret = hash_save_state(device_data, - &device_data->state); - - memmove(device_data->state.buffer, - req_ctx->state.buffer, - HASH_BLOCK_SIZE); - if (ret) { - dev_err(device_data->dev, "%s: hash_save_state() failed!\n", - __func__); - goto out; - } } while (msg_length != 0); out: @@ -759,15 +736,7 @@ static int hash_dma_final(struct ahash_request *req) dev_dbg(device_data->dev, "%s: (ctx=0x%lx)!\n", __func__, (unsigned long)ctx); - if (req_ctx->hw_initialized) { - ret = hash_resume_state(device_data, &device_data->state); - - if (ret) { - dev_err(device_data->dev, "%s: hash_resume_state() failed!\n", - __func__); - goto out; - } - } else { + if (!req_ctx->hw_initialized) { ret = hash_setconfiguration(device_data, ctx); if (ret) { dev_err(device_data->dev, @@ -858,13 +827,8 @@ static int hash_hw_final(struct ahash_request *req) (unsigned long)ctx); if (req_ctx->hw_initialized) { - ret = hash_resume_state(device_data, &device_data->state); - - if (ret) { - dev_err(device_data->dev, - "%s: hash_resume_state() failed!\n", __func__); - goto out; - } + /* That's fine, result is in HW */ + dev_dbg(device_data->dev, "%s hw initialized\n", __func__); } else if (req->nbytes == 0 && ctx->keylen == 0) { u8 zero_hash[SHA256_DIGEST_SIZE]; u32 zero_hash_size = 0; From patchwork Tue Aug 16 14:00:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944993 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B150C3F6B0 for ; Tue, 16 Aug 2022 14:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235842AbiHPOEC (ORCPT ); Tue, 16 Aug 2022 10:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235874AbiHPOD3 (ORCPT ); Tue, 16 Aug 2022 10:03:29 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95AB34E61E for ; Tue, 16 Aug 2022 07:03:25 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id v10so10614671ljh.9 for ; Tue, 16 Aug 2022 07:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=f68TJS9tWewQng2Ircr9iqi3OUtPf1sdFQxnP/ggvg0=; b=Jv+zyXB9Btp4l8yOnrbTFTXtyWE0UgiP0VeEphicL6m79Xt6YlXHzzjg1R5dPZlzbq 4tPRIe7Jx1xKARZjoQr8mV+07uRKo93YUVAfB6rzfvCKcslG3jsAV9Dao2pYp4+pWTN4 MDxNYh+t1o7Ljpe2lEiv4tvy5R3pPC/MUv0W48d1zZSGXEtzDZOkG11DgktCgZ8onj2f k/FOPUTQHg8rz8uZALohZVL74ymbvoo20ZPIkb3i1cvUdkVqoAIAdJkKO5/vq4F8SSJr pyoY8UWIrN+wkWsEiFBIcraZt+i2vyCTCUosG5sDZS7ykLsR5g7tr8XHzVeB61brTZsc G4wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=f68TJS9tWewQng2Ircr9iqi3OUtPf1sdFQxnP/ggvg0=; b=U6mnX2c52K2b3sZ5h1YIoq0VBR3A97IYgVdrIwimAyO8mUvzhmbDZ3+MhoEF7AFHmA 3XdPYrkCrCgQfVaUFkf9J4ShDHqo3M/9BdFwN94G1oBbbEJIPQ8jSnvdyDCbK3hcysu5 Vrq2qXdaKJzmW0cF8IQgY/Guj8nlEGXRVbk360MBBhYUdzPveXkjL8d2hRz/4wnrq6uw S5UmUize8s3Uskqwbvvs0WPtyMPEt8DVKezJZUw6EOQaM/UYteyRqNIvEKEfOqbM/izK eNpNPiwgStgkHXGwpD/Q4XEKZPp4AzsCSd8ZkRO6KsgSzk5CzgpenD72v83H3dFI3xe8 39qQ== X-Gm-Message-State: ACgBeo2KYu0p8HXFgxeyYifp/W/qk5lx2aCeq7kfn+hhodowArVSHS5p DD2XVKB2m+enAQrk0Sc9M9Yyvi5I/2GuUA== X-Google-Smtp-Source: AA6agR4iyi8FdDgdIoLxUH9IWcb5UhAzz9r9NE6oygK59fMXBpEElClGOssGNm9S704WDVQK0AO0/A== X-Received: by 2002:a2e:9254:0:b0:25e:4f20:8d3a with SMTP id v20-20020a2e9254000000b0025e4f208d3amr6932991ljg.233.1660658603339; Tue, 16 Aug 2022 07:03:23 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:23 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 09/16] crypto: ux500/hash: Get rid of state from request context Date: Tue, 16 Aug 2022 16:00:42 +0200 Message-Id: <20220816140049.102306-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The request context is exactly for that: context state related to the request. The code was (ab)using the state used to store the hardware state for this. Move out the three variables from the hardware state to the request context and clean up the mess left behind. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 21 +++++++-------- drivers/crypto/ux500/hash/hash_core.c | 38 +++++++++++---------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index d9d59dba6e6e..5aa86c4855f5 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -214,17 +214,10 @@ struct hash_register { * @csr[52]: HASH Context Swap Registers 0-39. * @csfull: HASH Context Swap Registers 40 ie Status flags. * @csdatain: HASH Context Swap Registers 41 ie Input data. - * @buffer: Working buffer for messages going to the hardware. - * @length: Length of the part of message hashed so far (floor(N/64) * 64). - * @index: Valid number of bytes in buffer (N % 64). * * This structure is used between context switches, i.e. when ongoing jobs are * interupted with new jobs. When this happens we need to store intermediate * results in software. - * - * WARNING: "index" is the member of the structure, to be sure that "buffer" - * is aligned on a 4-bytes boundary. This is highly implementation dependent - * and MUST be checked whenever this code is ported on new platforms. */ struct hash_state { u32 temp_cr; @@ -233,9 +226,6 @@ struct hash_state { u32 csr[52]; u32 csfull; u32 csdatain; - u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; - struct uint64 length; - u8 index; }; /** @@ -333,13 +323,22 @@ struct hash_ctx { /** * struct hash_ctx - The request context used for hash calculations. + * @buffer: Working buffer for messages going to the hardware. + * @length: Length of the part of message hashed so far (floor(N/64) * 64). + * @index: Valid number of bytes in buffer (N % 64). * @state: The state of the current calculations. * @dma_mode: Used in special cases (workaround), e.g. need to change to * cpu mode, if not supported/working in dma mode. * @hw_initialized: Indicates if hardware is initialized for new operations. + * + * WARNING: "index" is the member of the structure, to be sure that "buffer" + * is aligned on a 4-bytes boundary. This is highly implementation dependent + * and MUST be checked whenever this code is ported on new platforms. */ struct hash_req_ctx { - struct hash_state state; + u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; + struct uint64 length; + u8 index; bool dma_mode; bool hw_initialized; }; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 844ef70301d5..c55f35b366be 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -448,7 +448,9 @@ static int ux500_hash_init(struct ahash_request *req) if (!ctx->key) ctx->keylen = 0; - memset(&req_ctx->state, 0, sizeof(struct hash_state)); + req_ctx->index = 0; + req_ctx->length.low_word = 0; + req_ctx->length.high_word = 0; req_ctx->hw_initialized = false; if (hash_mode == HASH_MODE_DMA) { if (req->nbytes < HASH_DMA_ALIGN_SIZE) { @@ -553,11 +555,11 @@ static void hash_messagepad(struct hash_device_data *device_data, */ static void hash_incrementlength(struct hash_req_ctx *ctx, u32 incr) { - ctx->state.length.low_word += incr; + ctx->length.low_word += incr; /* Check for wrap-around */ - if (ctx->state.length.low_word < incr) - ctx->state.length.high_word++; + if (ctx->length.low_word < incr) + ctx->length.high_word++; } /** @@ -872,9 +874,9 @@ static int hash_hw_final(struct ahash_request *req) } } - if (req_ctx->state.index) { - hash_messagepad(device_data, req_ctx->state.buffer, - req_ctx->state.index); + if (req_ctx->index) { + hash_messagepad(device_data, req_ctx->buffer, + req_ctx->index); } else { HASH_SET_DCAL; while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) @@ -922,8 +924,8 @@ int hash_hw_update(struct ahash_request *req) struct crypto_hash_walk walk; int msg_length; - index = req_ctx->state.index; - buffer = (u8 *)req_ctx->state.buffer; + index = req_ctx->index; + buffer = (u8 *)req_ctx->buffer; msg_length = crypto_hash_walk_first(req, &walk); @@ -931,10 +933,10 @@ int hash_hw_update(struct ahash_request *req) if (msg_length == 0) return 0; - /* Check if ctx->state.length + msg_length + /* Check if ctx->length + msg_length overflows */ - if (msg_length > (req_ctx->state.length.low_word + msg_length) && - HASH_HIGH_WORD_MAX_VAL == req_ctx->state.length.high_word) { + if (msg_length > (req_ctx->length.low_word + msg_length) && + req_ctx->length.high_word == HASH_HIGH_WORD_VAL_MAX) { pr_err("%s: HASH_MSG_LENGTH_OVERFLOW!\n", __func__); return crypto_hash_walk_done(&walk, -EPERM); } @@ -955,9 +957,9 @@ int hash_hw_update(struct ahash_request *req) msg_length = crypto_hash_walk_done(&walk, 0); } - req_ctx->state.index = index; + req_ctx->index = index; dev_dbg(device_data->dev, "%s: indata length=%d\n", - __func__, req_ctx->state.index); + __func__, req_ctx->index); return 0; } @@ -980,14 +982,6 @@ int hash_resume_state(struct hash_device_data *device_data, return -EPERM; } - /* Check correctness of index and length members */ - if (device_state->index > HASH_BLOCK_SIZE || - (device_state->length.low_word % HASH_BLOCK_SIZE) != 0) { - dev_err(device_data->dev, "%s: HASH_INVALID_PARAMETER!\n", - __func__); - return -EPERM; - } - /* * INIT bit. Set this bit to 0b1 to reset the HASH processor core and * prepare the initialize the HASH accelerator to compute the message From patchwork Tue Aug 16 14:00:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944994 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 722FBC3F6B0 for ; Tue, 16 Aug 2022 14:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235931AbiHPOEJ (ORCPT ); Tue, 16 Aug 2022 10:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235848AbiHPODl (ORCPT ); Tue, 16 Aug 2022 10:03:41 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B11849B44 for ; Tue, 16 Aug 2022 07:03:27 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id w15so10645824ljw.1 for ; Tue, 16 Aug 2022 07:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Fx7EF1XT4Xp0iRpazAxdlKrn3GmL1oB14hrqyzOxgx0=; b=jk91keprIpxbGJ83Z9PoWPZqw728sYdnBKcyoa+8qzBh4TadwM7VPvhgw3bakuNyO6 kSmHiNlHhFRY1OUNOJ5S0D29QfYa4GtNzsv35zbxNXtfEm5QtLBGNqFO/xQOjymr0teM ohP24lcFky6lPLifSdQ3ByUDkThlriHbdTNWWl2D2ISs4JBB8+UVhvZhWojbYSrS+1Wt g/MrTTKaovcPBDRiqy+xBF0Yr0dwWxjejI3QY1nfh5EF9LimY0AwDLAWQaIO2UojlKSo obFiGHfZnivM6kx73z01rdu74RqeS2OdkpyXP5tKX2L3446APthpWFktkRIYOsbheG39 mG8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Fx7EF1XT4Xp0iRpazAxdlKrn3GmL1oB14hrqyzOxgx0=; b=JOuslvIPFEoSrPn/9a5x1f1O+k03EWV7OoNteStwaNUc0v1xMTpgAD5xsbApHKQiaG jezYoIbaEacEO9y58BP0PYyb7uEcOs8LTUy2zh/NcwrWYtU8Fy5TNAY6MmrBeiaIVWMc M/+kNYqcNP5q+7ddGCDT08oUAtxJJ5aPTBAf06vChIgKNBaFgGH89HCVeMqMQURFzwOO jZVGlWLCZSKLM3L26T5WXbPsF7jMaSxegE5PZrsdI6+CIk9KE7+aehnnSlpbEj/yTacu RvUhLCXoxWad3mZiw+tCpzG80JYi0BeN5BTDoeh9aII01ra/Rtg4hg1YE+Ylt5ysP9US MeLw== X-Gm-Message-State: ACgBeo1tPxN9KYaW7HnJIQYdfqw1dpD5iqDQ/i4dehkoibO8+k2FV8Cl GagfwDr7EdRV+zWA4Jrh8+3UdBKyrszOfQ== X-Google-Smtp-Source: AA6agR60pm6rWg2Ihzi+l/GeBemmFNHIBKtkiAzbW686tLoNjZBPJVdal40VZJ77QMVVz/FU7Rn5qw== X-Received: by 2002:a2e:b0c9:0:b0:25e:71e3:8441 with SMTP id g9-20020a2eb0c9000000b0025e71e38441mr6914022ljl.156.1660658604639; Tue, 16 Aug 2022 07:03:24 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:24 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 10/16] crypto: ux500/hash: Implement .export and .import Date: Tue, 16 Aug 2022 16:00:43 +0200 Message-Id: <20220816140049.102306-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The .export and .import callbacks are just implemented as stubs which makes the tests fail: alg: ahash: hmac-sha256-ux500 export() failed with err -38 on test vector 0, cfg="import/export" ------------[ cut here ]------------ WARNING: CPU: 1 PID: 92 at crypto/testmgr.c:5777 alg_test.part.0+0x160/0x3ec alg: self-tests for hmac-sha256-ux500 (hmac(sha256)) failed (rc=-38) The driver already has code for saving and restoring the hardware state, which is now unused. Pass the tests by simply implementing the callbacks properly, extending the state with the length, index and buffer from the ongoing request context. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 5 + drivers/crypto/ux500/hash/hash_core.c | 227 +++++++++++++------------- 2 files changed, 114 insertions(+), 118 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 5aa86c4855f5..05f0b0221a13 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -226,6 +226,11 @@ struct hash_state { u32 csr[52]; u32 csfull; u32 csdatain; + u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; + struct uint64 length; + u8 index; + bool dma_mode; + bool hw_initialized; }; /** diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index c55f35b366be..c8771839ec8e 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -964,108 +964,6 @@ int hash_hw_update(struct ahash_request *req) return 0; } -/** - * hash_resume_state - Function that resumes the state of an calculation. - * @device_data: Pointer to the device structure. - * @device_state: The state to be restored in the hash hardware - */ -int hash_resume_state(struct hash_device_data *device_data, - const struct hash_state *device_state) -{ - u32 temp_cr; - s32 count; - int hash_mode = HASH_OPER_MODE_HASH; - - if (NULL == device_state) { - dev_err(device_data->dev, "%s: HASH_INVALID_PARAMETER!\n", - __func__); - return -EPERM; - } - - /* - * INIT bit. Set this bit to 0b1 to reset the HASH processor core and - * prepare the initialize the HASH accelerator to compute the message - * digest of a new message. - */ - HASH_INITIALIZE; - - temp_cr = device_state->temp_cr; - writel_relaxed(temp_cr & HASH_CR_RESUME_MASK, &device_data->base->cr); - - if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) - hash_mode = HASH_OPER_MODE_HMAC; - else - hash_mode = HASH_OPER_MODE_HASH; - - for (count = 0; count < HASH_CSR_COUNT; count++) { - if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) - break; - - writel_relaxed(device_state->csr[count], - &device_data->base->csrx[count]); - } - - writel_relaxed(device_state->csfull, &device_data->base->csfull); - writel_relaxed(device_state->csdatain, &device_data->base->csdatain); - - writel_relaxed(device_state->str_reg, &device_data->base->str); - writel_relaxed(temp_cr, &device_data->base->cr); - - return 0; -} - -/** - * hash_save_state - Function that saves the state of hardware. - * @device_data: Pointer to the device structure. - * @device_state: The strucure where the hardware state should be saved. - */ -int hash_save_state(struct hash_device_data *device_data, - struct hash_state *device_state) -{ - u32 temp_cr; - u32 count; - int hash_mode = HASH_OPER_MODE_HASH; - - if (NULL == device_state) { - dev_err(device_data->dev, "%s: HASH_INVALID_PARAMETER!\n", - __func__); - return -ENOTSUPP; - } - - /* Write dummy value to force digest intermediate calculation. This - * actually makes sure that there isn't any ongoing calculation in the - * hardware. - */ - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); - - temp_cr = readl_relaxed(&device_data->base->cr); - - device_state->str_reg = readl_relaxed(&device_data->base->str); - - device_state->din_reg = readl_relaxed(&device_data->base->din); - - if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) - hash_mode = HASH_OPER_MODE_HMAC; - else - hash_mode = HASH_OPER_MODE_HASH; - - for (count = 0; count < HASH_CSR_COUNT; count++) { - if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) - break; - - device_state->csr[count] = - readl_relaxed(&device_data->base->csrx[count]); - } - - device_state->csfull = readl_relaxed(&device_data->base->csfull); - device_state->csdatain = readl_relaxed(&device_data->base->csdatain); - - device_state->temp_cr = temp_cr; - - return 0; -} - /** * hash_check_hw - This routine checks for peripheral Ids and PCell Ids. * @device_data: @@ -1244,14 +1142,107 @@ static int ahash_sha256_digest(struct ahash_request *req) return ret1 ? ret1 : ret2; } -static int ahash_noimport(struct ahash_request *req, const void *in) +static int ahash_import(struct ahash_request *req, const void *in) { - return -ENOSYS; + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct hash_ctx *ctx = crypto_ahash_ctx(tfm); + struct hash_device_data *device_data = ctx->device; + struct hash_req_ctx *req_ctx = ahash_request_ctx(req); + const struct hash_state *hstate = in; + int hash_mode = HASH_OPER_MODE_HASH; + u32 cr; + s32 count; + + /* Restore software state */ + req_ctx->length = hstate->length; + req_ctx->index = hstate->index; + req_ctx->dma_mode = hstate->dma_mode; + req_ctx->hw_initialized = hstate->hw_initialized; + memcpy(req_ctx->buffer, hstate->buffer, HASH_BLOCK_SIZE); + + /* + * Restore hardware state + * INIT bit. Set this bit to 0b1 to reset the HASH processor core and + * prepare the initialize the HASH accelerator to compute the message + * digest of a new message. + */ + HASH_INITIALIZE; + + cr = hstate->temp_cr; + writel_relaxed(cr & HASH_CR_RESUME_MASK, &device_data->base->cr); + + if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) + hash_mode = HASH_OPER_MODE_HMAC; + else + hash_mode = HASH_OPER_MODE_HASH; + + for (count = 0; count < HASH_CSR_COUNT; count++) { + if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) + break; + writel_relaxed(hstate->csr[count], + &device_data->base->csrx[count]); + } + + writel_relaxed(hstate->csfull, &device_data->base->csfull); + writel_relaxed(hstate->csdatain, &device_data->base->csdatain); + writel_relaxed(hstate->str_reg, &device_data->base->str); + writel_relaxed(cr, &device_data->base->cr); + + return 0; } -static int ahash_noexport(struct ahash_request *req, void *out) +static int ahash_export(struct ahash_request *req, void *out) { - return -ENOSYS; + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct hash_ctx *ctx = crypto_ahash_ctx(tfm); + struct hash_device_data *device_data = ctx->device; + struct hash_req_ctx *req_ctx = ahash_request_ctx(req); + struct hash_state *hstate = out; + int hash_mode = HASH_OPER_MODE_HASH; + u32 cr; + u32 count; + + /* + * Save hardware state: + * Write dummy value to force digest intermediate calculation. This + * actually makes sure that there isn't any ongoing calculation in the + * hardware. + */ + while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) + cpu_relax(); + + cr = readl_relaxed(&device_data->base->cr); + + hstate->str_reg = readl_relaxed(&device_data->base->str); + + hstate->din_reg = readl_relaxed(&device_data->base->din); + + if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) + hash_mode = HASH_OPER_MODE_HMAC; + else + hash_mode = HASH_OPER_MODE_HASH; + + for (count = 0; count < HASH_CSR_COUNT; count++) { + if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) + break; + + hstate->csr[count] = + readl_relaxed(&device_data->base->csrx[count]); + } + + hstate->csfull = readl_relaxed(&device_data->base->csfull); + hstate->csdatain = readl_relaxed(&device_data->base->csdatain); + + hstate->temp_cr = cr; + + /* Save software state */ + hstate->length = req_ctx->length; + hstate->index = req_ctx->index; + hstate->dma_mode = req_ctx->dma_mode; + hstate->hw_initialized = req_ctx->hw_initialized; + memcpy(hstate->buffer, req_ctx->buffer, HASH_BLOCK_SIZE); + + return 0; } static int hmac_sha1_init(struct ahash_request *req) @@ -1361,10 +1352,10 @@ static struct hash_algo_template hash_algs[] = { .update = ahash_update, .final = ahash_final, .digest = ahash_sha1_digest, - .export = ahash_noexport, - .import = ahash_noimport, + .export = ahash_export, + .import = ahash_import, .halg.digestsize = SHA1_DIGEST_SIZE, - .halg.statesize = sizeof(struct hash_ctx), + .halg.statesize = sizeof(struct hash_state), .halg.base = { .cra_name = "sha1", .cra_driver_name = "sha1-ux500", @@ -1384,10 +1375,10 @@ static struct hash_algo_template hash_algs[] = { .update = ahash_update, .final = ahash_final, .digest = ahash_sha256_digest, - .export = ahash_noexport, - .import = ahash_noimport, + .export = ahash_export, + .import = ahash_import, .halg.digestsize = SHA256_DIGEST_SIZE, - .halg.statesize = sizeof(struct hash_ctx), + .halg.statesize = sizeof(struct hash_state), .halg.base = { .cra_name = "sha256", .cra_driver_name = "sha256-ux500", @@ -1408,10 +1399,10 @@ static struct hash_algo_template hash_algs[] = { .final = ahash_final, .digest = hmac_sha1_digest, .setkey = hmac_sha1_setkey, - .export = ahash_noexport, - .import = ahash_noimport, + .export = ahash_export, + .import = ahash_import, .halg.digestsize = SHA1_DIGEST_SIZE, - .halg.statesize = sizeof(struct hash_ctx), + .halg.statesize = sizeof(struct hash_state), .halg.base = { .cra_name = "hmac(sha1)", .cra_driver_name = "hmac-sha1-ux500", @@ -1432,10 +1423,10 @@ static struct hash_algo_template hash_algs[] = { .final = ahash_final, .digest = hmac_sha256_digest, .setkey = hmac_sha256_setkey, - .export = ahash_noexport, - .import = ahash_noimport, + .export = ahash_export, + .import = ahash_import, .halg.digestsize = SHA256_DIGEST_SIZE, - .halg.statesize = sizeof(struct hash_ctx), + .halg.statesize = sizeof(struct hash_state), .halg.base = { .cra_name = "hmac(sha256)", .cra_driver_name = "hmac-sha256-ux500", From patchwork Tue Aug 16 14:00:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944995 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCA68C25B0E for ; Tue, 16 Aug 2022 14:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235926AbiHPOEI (ORCPT ); Tue, 16 Aug 2022 10:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235879AbiHPOD3 (ORCPT ); Tue, 16 Aug 2022 10:03:29 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 203296B141 for ; Tue, 16 Aug 2022 07:03:27 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id f20so15051961lfc.10 for ; Tue, 16 Aug 2022 07:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0bbDdce5gaqck7gjD3V4/vgwIpyzTmf0xP/GcVB/qg0=; b=iXRPGFTUiQ7SA/TpFgZM6Y8lAjxpMUrpFPLQj/KN9Oi16VdpPoju7+7wn7zhs9ZGZ0 qKX5hGFFLay6nHNizBHoTuJ4ak50xxbpWQjZK6lzUbiK1rRRg1hbm3YSFnws91PlKAnj 1QARn9Xmm9dFgd/wYIfu8+HcJ5PTU834Qyz9HzhdNiIzhDoKem0I+5fcW5DOMXDVC05x p8uNeTetjE/gv1/7aEahT2VHzKYpGouygruykvjQApvjwERuReoVn1qsbauot6p806gz /ytSm6NLeIYTyy8NnW5u8lhECE1KECxXfQMH2u2njNZAhNAv8Xli08NN95B8rXzRAvKa Htog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0bbDdce5gaqck7gjD3V4/vgwIpyzTmf0xP/GcVB/qg0=; b=Sob+3sRhvHumc1kjfRzMX7NCRq4v1gthdccpRUhAVwOs/wJEdYdOpt+e3E8kb+7kum ROg3vjB1lor8L8L0DsrmV4zzCQO9VEJHbQP0sPN4Yn3dr8jHjy8p58DLONN9vn9/wZ29 ORZRUyE0oJZOtOV2psHzKS6NzQljRJWrdFZaFTNQCdyfLq197RFTVIOWMufWyB1ADUJj 7oyN+lK4PBLoX5cfVFM4PNDGUCqQ2Y1Mw7fjzKK4f2+hrjMD+ByndhYXwBu9vSFN768S 7bs++Qgap2Ya0LWYg4arRIaT5hGlvOpCl4OuLcjXLiADGNicUW+b0I+R5rRup3Bx/oz5 N9Ew== X-Gm-Message-State: ACgBeo2FX6ifLxZkoijiJJkTzqJdqNE7wbMei9bTKRJbz7JjqIKIp+t5 H7HYn44Py6K7UQolYA2zI8SwTl+HGDmFdQ== X-Google-Smtp-Source: AA6agR5IknY7XRE8Tl46q9vwQWFwpcY9hN4EEToXrBpaURtE3nmrw/NjhWf9/CRu6OnNKCBaIqXOLA== X-Received: by 2002:a05:6512:3d18:b0:48d:244d:2120 with SMTP id d24-20020a0565123d1800b0048d244d2120mr7040062lfv.387.1660658606127; Tue, 16 Aug 2022 07:03:26 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:25 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 11/16] crypto: ux500/hash: Drop custom uint64 type Date: Tue, 16 Aug 2022 16:00:44 +0200 Message-Id: <20220816140049.102306-12-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Drop the homebrewn uint64 support, the kernel has a u64 type that works just fine so we use that instead. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - No changes --- drivers/crypto/ux500/hash/hash_alg.h | 19 ++---------------- drivers/crypto/ux500/hash/hash_core.c | 28 ++++----------------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 05f0b0221a13..6a610c83e63d 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -16,9 +16,6 @@ #define HASH_DMA_PERFORMANCE_MIN_SIZE 1024 #define HASH_BYTES_PER_WORD 4 -/* Maximum value of the length's high word */ -#define HASH_HIGH_WORD_MAX_VAL 0xFFFFFFFFUL - /* Power on Reset values HASH registers */ #define HASH_RESET_CR_VALUE 0x0 #define HASH_RESET_STR_VALUE 0x0 @@ -135,18 +132,6 @@ enum hash_mode { HASH_MODE_DMA }; -/** - * struct uint64 - Structure to handle 64 bits integers. - * @high_word: Most significant bits. - * @low_word: Least significant bits. - * - * Used to handle 64 bits integers. - */ -struct uint64 { - u32 high_word; - u32 low_word; -}; - /** * struct hash_register - Contains all registers in ux500 hash hardware. * @cr: HASH control register (0x000). @@ -227,7 +212,7 @@ struct hash_state { u32 csfull; u32 csdatain; u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; - struct uint64 length; + u64 length; u8 index; bool dma_mode; bool hw_initialized; @@ -342,7 +327,7 @@ struct hash_ctx { */ struct hash_req_ctx { u32 buffer[HASH_BLOCK_SIZE / sizeof(u32)]; - struct uint64 length; + u64 length; u8 index; bool dma_mode; bool hw_initialized; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index c8771839ec8e..5fe0720cb1f5 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -449,8 +449,7 @@ static int ux500_hash_init(struct ahash_request *req) ctx->keylen = 0; req_ctx->index = 0; - req_ctx->length.low_word = 0; - req_ctx->length.high_word = 0; + req_ctx->length = 0; req_ctx->hw_initialized = false; if (hash_mode == HASH_MODE_DMA) { if (req->nbytes < HASH_DMA_ALIGN_SIZE) { @@ -545,23 +544,6 @@ static void hash_messagepad(struct hash_device_data *device_data, cpu_relax(); } -/** - * hash_incrementlength - Increments the length of the current message. - * @ctx: Hash context - * @incr: Length of message processed already - * - * Overflow cannot occur, because conditions for overflow are checked in - * hash_hw_update. - */ -static void hash_incrementlength(struct hash_req_ctx *ctx, u32 incr) -{ - ctx->length.low_word += incr; - - /* Check for wrap-around */ - if (ctx->length.low_word < incr) - ctx->length.high_word++; -} - /** * hash_setconfiguration - Sets the required configuration for the hash * hardware. @@ -709,7 +691,7 @@ static int hash_process_data(struct hash_device_data *device_data, (const u32 *)buffer, HASH_BLOCK_SIZE); } - hash_incrementlength(req_ctx, HASH_BLOCK_SIZE); + req_ctx->length += HASH_BLOCK_SIZE; data_buffer += (HASH_BLOCK_SIZE - *index); msg_length -= (HASH_BLOCK_SIZE - *index); @@ -933,10 +915,8 @@ int hash_hw_update(struct ahash_request *req) if (msg_length == 0) return 0; - /* Check if ctx->length + msg_length - overflows */ - if (msg_length > (req_ctx->length.low_word + msg_length) && - req_ctx->length.high_word == HASH_HIGH_WORD_VAL_MAX) { + /* Check if ctx->length + msg_length overflows */ + if ((req_ctx->length + msg_length) < msg_length) { pr_err("%s: HASH_MSG_LENGTH_OVERFLOW!\n", __func__); return crypto_hash_walk_done(&walk, -EPERM); } From patchwork Tue Aug 16 14:00:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944996 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 356BAC25B0E for ; Tue, 16 Aug 2022 14:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235628AbiHPOEU (ORCPT ); Tue, 16 Aug 2022 10:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235883AbiHPODm (ORCPT ); Tue, 16 Aug 2022 10:03:42 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C4EC6319 for ; Tue, 16 Aug 2022 07:03:30 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id u6so10628672ljk.8 for ; Tue, 16 Aug 2022 07:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=rF3jH/rtUdR2dYrOhKBuwcHbVAqHrocZAK7mo3xPYCg=; b=B2CsJZONYIaydYyrfgBAc5tNXRqvnP8wRNofzwSTblaB0HKbrSKlJ/opaGOBOtOSqb ycApkrv1zHrKl03A3GMRDFWUI5GfaW/SkXalZziGGqkC2rbC0wQ/oWX6+rrU/CkkM+0R 9jadcMW/PrZWXFIRm/hzC2+F6+iPqfo7/4x4Hp9vrmvZW78/cQGdc5cSEAiiL9Gdv2YU VrTPH+gcnPSxwLXzFvmi7T5s/AHh0IPHeHFyAHSBFs5CzjjiXrUfuGR77UK7LuNAm9Q7 humMhtcgyU/lpCrOwbSQ4pr1A2ryxk79OILL9dUhM3dxtlnSRqGGivAvHfD5MksuCdmI 71bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=rF3jH/rtUdR2dYrOhKBuwcHbVAqHrocZAK7mo3xPYCg=; b=LMeZ6VyqHLd70mtHGWv79BvW0ZgTr+u3RyucBA7+aua83nYaVrqmgCjnojb3CXm0gj I3RUyD2Tk6nQnijnykIWqgCKepty01KPz5fqht57C0QVzbBUNbUoOAyv50NIcJeggxEO mvIBcMJkMgcINBQsY/S0FrNNISoaZy+sDRPWUMq0FKW+k/RL62u96rQemU/4VVPXTSfr rqRpQ0R15PAN55zGeixh+ykK27I15TcOtUGW/EaBWHh76z2RJwnnBYXIGj7qAzDiirVi fy1rvGrDVWvHlWvwq75t9160O7lt3hnzpS++OfRtLN52dkRr/nW561UkzYnOylXwGdcw Sk7w== X-Gm-Message-State: ACgBeo0Cujm66SPalt/By9IHE4IADbarrNgzLGJlbWd1b7Lxz/edNtFE qIr1tefuSYxEnW3hpjf5DqkIY/IzSNvBdQ== X-Google-Smtp-Source: AA6agR7eJJ40nSspx3DYNPIKyxE12DsiM4iS6VE4Hl3zQEtS+Ed4hx5GU3HMkc92wcwZdhzXiPVFKw== X-Received: by 2002:a2e:8e71:0:b0:261:74ad:ab5f with SMTP id t17-20020a2e8e71000000b0026174adab5fmr5829083ljk.387.1660658607541; Tue, 16 Aug 2022 07:03:27 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:27 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 12/16] crypto: ux500/hash: Drop regulator handling Date: Tue, 16 Aug 2022 16:00:45 +0200 Message-Id: <20220816140049.102306-13-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This "APE" voltage is not handled by a regulator but by the power domain, drop it. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - New patch after noticing the power domain is handling this voltage. --- drivers/crypto/ux500/hash/hash_core.c | 38 +++------------------------ 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 5fe0720cb1f5..21657c9c79a7 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -24,8 +24,6 @@ #include #include #include - -#include #include #include @@ -244,22 +242,17 @@ static int get_empty_message_digest( * hash_disable_power - Request to disable power and clock. * @device_data: Structure for the hash device. * - * This function request for disabling power (regulator) and clock, - * and could also save current hw state. + * This function request for disabling the clock. */ static int hash_disable_power(struct hash_device_data *device_data) { int ret = 0; - struct device *dev = device_data->dev; spin_lock(&device_data->power_state_lock); if (!device_data->power_state) goto out; clk_disable(device_data->clk); - ret = regulator_disable(device_data->regulator); - if (ret) - dev_err(dev, "%s: regulator_disable() failed!\n", __func__); device_data->power_state = false; @@ -273,8 +266,7 @@ static int hash_disable_power(struct hash_device_data *device_data) * hash_enable_power - Request to enable power and clock. * @device_data: Structure for the hash device. * - * This function request for enabling power (regulator) and clock, - * and could also restore a previously saved hw state. + * This function request for enabling the clock. */ static int hash_enable_power(struct hash_device_data *device_data) { @@ -283,17 +275,9 @@ static int hash_enable_power(struct hash_device_data *device_data) spin_lock(&device_data->power_state_lock); if (!device_data->power_state) { - ret = regulator_enable(device_data->regulator); - if (ret) { - dev_err(dev, "%s: regulator_enable() failed!\n", - __func__); - goto out; - } ret = clk_enable(device_data->clk); if (ret) { dev_err(dev, "%s: clk_enable() failed!\n", __func__); - ret = regulator_disable( - device_data->regulator); goto out; } device_data->power_state = true; @@ -1487,27 +1471,17 @@ static int ux500_hash_probe(struct platform_device *pdev) spin_lock_init(&device_data->ctx_lock); spin_lock_init(&device_data->power_state_lock); - /* Enable power for HASH1 hardware block */ - device_data->regulator = regulator_get(dev, "v-ape"); - if (IS_ERR(device_data->regulator)) { - dev_err(dev, "%s: regulator_get() failed!\n", __func__); - ret = PTR_ERR(device_data->regulator); - device_data->regulator = NULL; - goto out; - } - - /* Enable the clock for HASH1 hardware block */ device_data->clk = devm_clk_get(dev, NULL); if (IS_ERR(device_data->clk)) { dev_err(dev, "%s: clk_get() failed!\n", __func__); ret = PTR_ERR(device_data->clk); - goto out_regulator; + goto out; } ret = clk_prepare(device_data->clk); if (ret) { dev_err(dev, "%s: clk_prepare() failed!\n", __func__); - goto out_regulator; + goto out; } /* Enable device power (and clock) */ @@ -1544,9 +1518,6 @@ static int ux500_hash_probe(struct platform_device *pdev) out_clk_unprepare: clk_unprepare(device_data->clk); -out_regulator: - regulator_put(device_data->regulator); - out: return ret; } @@ -1585,7 +1556,6 @@ static int ux500_hash_remove(struct platform_device *pdev) __func__); clk_unprepare(device_data->clk); - regulator_put(device_data->regulator); return 0; } From patchwork Tue Aug 16 14:00:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944997 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 989E9C3F6B0 for ; Tue, 16 Aug 2022 14:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234357AbiHPOEV (ORCPT ); Tue, 16 Aug 2022 10:04:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235884AbiHPODm (ORCPT ); Tue, 16 Aug 2022 10:03:42 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5F125C63 for ; Tue, 16 Aug 2022 07:03:31 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id e15so15114828lfs.0 for ; Tue, 16 Aug 2022 07:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=p+6hbJuzTfoCdoe9aWPSXaliBzd4ByI0bHJTkg1Dlbc=; b=j1aIS9w3TbsLQHz/OFlElS+7czgnScrpa0xNrSE3iNGIpi31QjfFe/eIdE4u592Sz8 9y9y0a1uWYRPVLQTYYBlqZ0vj4KpgwV59fP9bFRK2P3p454jdzIFuMBZq5FiKhXniyRW BhqgXpiNdNu+aIlmGm8lMUMdIUPcdkLXJojdq72+JXJh04kaJVqr+Llddl5RvQjQewxG /SXU2TF/fARCNH9cBZT7Nb0aW0XBkOcVpgEP4ebXY5sUPivmsEczWmyeT2FVDE7FU6O7 3TQ+XPNmcHlm00IbhAb2MNVCXQZqXMvcWYh02MoGJb6+JkOQabiYL4jKOFtN7O8+ZmOD M1wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=p+6hbJuzTfoCdoe9aWPSXaliBzd4ByI0bHJTkg1Dlbc=; b=jCMErDDU9V3mWNvpuHVdUkldRhf4LWJqQO72FsTPZXVnrQziv3RbB84ce555HNcIc7 6oO0aUKdFd22p/Y3fNDcAQ07wmRg14XpwPqjBPKAjgHsqzf4Gz5OpYOFV2k8BjiGDLfx H6MYPasiCpbw3hLznrQ4bpxsnSbJCZfvwo1aasVH/Go2qKSZ7oQnA3dUuTXHYupRgq/A cwW/dDb+XkyquWTjD4kHdmfBPVaDvHHrA61NWHe8L/wPiU8sV2y55tYHlApDWD3nT8se vYRFWrVz0yNi6L31/MND0RHpjBPYxY2UMprUBUD5Z/j/ehDBJ4LQwqGxeMU6wUZkkPS6 aqQg== X-Gm-Message-State: ACgBeo392Oo/KohYOKcY9Kv6nI3bH694TJdqcpVcyt0LmKokHw51k9bI 6S1MA2u+jAD6toJ5Y/Mkmb/1cFeP+VSpIw== X-Google-Smtp-Source: AA6agR4fsuWlu1HE4yCanCZ0n9eoBUow9lKA5urXIzQmKDBeP8h9RdC19QomYbzF6bT5ZFZRNN7klw== X-Received: by 2002:a05:6512:110d:b0:492:8c61:48f9 with SMTP id l13-20020a056512110d00b004928c6148f9mr2994162lfg.224.1660658608853; Tue, 16 Aug 2022 07:03:28 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:28 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 13/16] crypto: ux500/hash: Convert to regmap MMIO Date: Tue, 16 Aug 2022 16:00:46 +0200 Message-Id: <20220816140049.102306-14-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The driver goes to extents to map a struct over all the registers and access the registers and macros to access certain fields and bits in a way equivalent but inferior to the existing Linux regmap. The driver predates the introduction of regmap MMIO, so this is understandable. Convert the driver to use regmap MMIO instead. Break out two helper functions to wait for an STR flag and to fill the data in (DIN) FIFO to avoid repetitive code. Disable the regcache: this drives sends a LOT of data into a single register (DIN), which is pointless to cache and only takes extra execution time. Any other accesses are stray and few. Checkpatch complains about -ENOTSUPP so use -ENODEV instead. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - Mark PrimeCell ID registers volatile as they have interesting power-on defaults. - Avoid using noinc calls, they don't work with regmap MMIO right now. (Working on a solution.) --- drivers/crypto/ux500/Kconfig | 1 + drivers/crypto/ux500/hash/hash_alg.h | 200 +++---------- drivers/crypto/ux500/hash/hash_core.c | 415 ++++++++++++++++---------- 3 files changed, 302 insertions(+), 314 deletions(-) diff --git a/drivers/crypto/ux500/Kconfig b/drivers/crypto/ux500/Kconfig index f56d65c56ccf..5d70f5965d06 100644 --- a/drivers/crypto/ux500/Kconfig +++ b/drivers/crypto/ux500/Kconfig @@ -20,6 +20,7 @@ config CRYPTO_DEV_UX500_HASH select CRYPTO_HASH select CRYPTO_SHA1 select CRYPTO_SHA256 + select REGMAP_MMIO help This selects the hash driver for the UX500_HASH hardware. Depends on UX500/STM DMA if running in DMA mode. diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 6a610c83e63d..cc44d3cb21ac 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -8,6 +8,7 @@ #ifndef _HASH_ALG_H #define _HASH_ALG_H +#include #include #define HASH_BLOCK_SIZE 64 @@ -16,70 +17,50 @@ #define HASH_DMA_PERFORMANCE_MIN_SIZE 1024 #define HASH_BYTES_PER_WORD 4 -/* Power on Reset values HASH registers */ -#define HASH_RESET_CR_VALUE 0x0 -#define HASH_RESET_STR_VALUE 0x0 - /* Number of context swap registers */ #define HASH_CSR_COUNT 52 -#define HASH_RESET_CSRX_REG_VALUE 0x0 -#define HASH_RESET_CSFULL_REG_VALUE 0x0 -#define HASH_RESET_CSDATAIN_REG_VALUE 0x0 - -#define HASH_RESET_INDEX_VAL 0x0 -#define HASH_RESET_BIT_INDEX_VAL 0x0 -#define HASH_RESET_BUFFER_VAL 0x0 -#define HASH_RESET_LEN_HIGH_VAL 0x0 -#define HASH_RESET_LEN_LOW_VAL 0x0 +#define UX500_HASH_CR 0x00 +#define UX500_HASH_DIN 0x04 +#define UX500_HASH_STR 0x08 +#define UX500_HASH_H(x) (0x0C + ((x) * 0x04)) +#define UX500_HASH_ITCR 0x80 +#define UX500_HASH_ITIP 0x84 +#define UX500_HASH_ITOP 0x88 +#define UX500_HASH_CSFULL 0xF8 +#define UX500_HASH_CSDATAIN 0xFC +#define UX500_HASH_CSR(x) (0x100 + ((x) * 0x04)) +#define UX500_HASH_PERIPHID0 0xFE0 +#define UX500_HASH_PERIPHID1 0xFE4 +#define UX500_HASH_PERIPHID2 0xFE8 +#define UX500_HASH_PERIPHID3 0xFEC +#define UX500_HASH_CELLID0 0xFF0 +#define UX500_HASH_CELLID1 0xFF4 +#define UX500_HASH_CELLID2 0xFF8 +#define UX500_HASH_CELLID3 0xFFC /* Control register bitfields */ #define HASH_CR_RESUME_MASK 0x11FCF - -#define HASH_CR_SWITCHON_POS 31 -#define HASH_CR_SWITCHON_MASK BIT(31) - -#define HASH_CR_EMPTYMSG_POS 20 -#define HASH_CR_EMPTYMSG_MASK BIT(20) - -#define HASH_CR_DINF_POS 12 -#define HASH_CR_DINF_MASK BIT(12) - -#define HASH_CR_NBW_POS 8 +#define HASH_CR_SWITCHON BIT(31) +#define HASH_CR_EMPTYMSG BIT(20) +#define HASH_CR_DINF BIT(12) #define HASH_CR_NBW_MASK 0x00000F00UL - -#define HASH_CR_LKEY_POS 16 -#define HASH_CR_LKEY_MASK BIT(16) - -#define HASH_CR_ALGO_POS 7 -#define HASH_CR_ALGO_MASK BIT(7) - -#define HASH_CR_MODE_POS 6 -#define HASH_CR_MODE_MASK BIT(6) - -#define HASH_CR_DATAFORM_POS 4 +#define HASH_CR_LKEY BIT(16) +#define HASH_CR_ALGO BIT(7) +#define HASH_CR_MODE BIT(6) #define HASH_CR_DATAFORM_MASK (BIT(4) | BIT(5)) - -#define HASH_CR_DMAE_POS 3 -#define HASH_CR_DMAE_MASK BIT(3) - -#define HASH_CR_INIT_POS 2 -#define HASH_CR_INIT_MASK BIT(2) - -#define HASH_CR_PRIVN_POS 1 -#define HASH_CR_PRIVN_MASK BIT(1) - -#define HASH_CR_SECN_POS 0 -#define HASH_CR_SECN_MASK BIT(0) +#define HASH_CR_DATAFORM_32BIT 0 +#define HASH_CR_DATAFORM_16BIT BIT(4) +#define HASH_CR_DATAFORM_8BIT BIT(5) +#define HASH_CR_DATAFORM_1BIT (BIT(4) | BIT(5)) +#define HASH_CR_DMAE BIT(3) +#define HASH_CR_INIT BIT(2) +#define HASH_CR_PRIVN BIT(1) +#define HASH_CR_SECN BIT(0) /* Start register bitfields */ -#define HASH_STR_DCAL_POS 8 -#define HASH_STR_DCAL_MASK BIT(8) -#define HASH_STR_DEFAULT 0x0 - -#define HASH_STR_NBLW_POS 0 +#define HASH_STR_DCAL BIT(8) #define HASH_STR_NBLW_MASK 0x0000001FUL - #define HASH_NBLW_MAX_VAL 0x1F /* PrimeCell IDs */ @@ -92,105 +73,12 @@ #define HASH_CELL_ID2 0x05 #define HASH_CELL_ID3 0xB1 -#define HASH_SET_BITS(reg_name, mask) \ - writel_relaxed((readl_relaxed(reg_name) | mask), reg_name) - -#define HASH_CLEAR_BITS(reg_name, mask) \ - writel_relaxed((readl_relaxed(reg_name) & ~mask), reg_name) - -#define HASH_PUT_BITS(reg, val, shift, mask) \ - writel_relaxed(((readl(reg) & ~(mask)) | \ - (((u32)val << shift) & (mask))), reg) - -#define HASH_SET_DIN(val, len) writesl(&device_data->base->din, (val), (len)) - -#define HASH_INITIALIZE \ - HASH_PUT_BITS( \ - &device_data->base->cr, \ - 0x01, HASH_CR_INIT_POS, \ - HASH_CR_INIT_MASK) - -#define HASH_SET_DATA_FORMAT(data_format) \ - HASH_PUT_BITS( \ - &device_data->base->cr, \ - (u32) (data_format), HASH_CR_DATAFORM_POS, \ - HASH_CR_DATAFORM_MASK) -#define HASH_SET_NBLW(val) \ - HASH_PUT_BITS( \ - &device_data->base->str, \ - (u32) (val), HASH_STR_NBLW_POS, \ - HASH_STR_NBLW_MASK) -#define HASH_SET_DCAL \ - HASH_PUT_BITS( \ - &device_data->base->str, \ - 0x01, HASH_STR_DCAL_POS, \ - HASH_STR_DCAL_MASK) - /* Hardware access method */ enum hash_mode { HASH_MODE_CPU, HASH_MODE_DMA }; -/** - * struct hash_register - Contains all registers in ux500 hash hardware. - * @cr: HASH control register (0x000). - * @din: HASH data input register (0x004). - * @str: HASH start register (0x008). - * @hx: HASH digest register 0..7 (0x00c-0x01C). - * @padding0: Reserved (0x02C). - * @itcr: Integration test control register (0x080). - * @itip: Integration test input register (0x084). - * @itop: Integration test output register (0x088). - * @padding1: Reserved (0x08C). - * @csfull: HASH context full register (0x0F8). - * @csdatain: HASH context swap data input register (0x0FC). - * @csrx: HASH context swap register 0..51 (0x100-0x1CC). - * @padding2: Reserved (0x1D0). - * @periphid0: HASH peripheral identification register 0 (0xFE0). - * @periphid1: HASH peripheral identification register 1 (0xFE4). - * @periphid2: HASH peripheral identification register 2 (0xFE8). - * @periphid3: HASH peripheral identification register 3 (0xFEC). - * @cellid0: HASH PCell identification register 0 (0xFF0). - * @cellid1: HASH PCell identification register 1 (0xFF4). - * @cellid2: HASH PCell identification register 2 (0xFF8). - * @cellid3: HASH PCell identification register 3 (0xFFC). - * - * The device communicates to the HASH via 32-bit-wide control registers - * accessible via the 32-bit width AMBA rev. 2.0 AHB Bus. Below is a structure - * with the registers used. - */ -struct hash_register { - u32 cr; - u32 din; - u32 str; - u32 hx[8]; - - u32 padding0[(0x080 - 0x02C) / sizeof(u32)]; - - u32 itcr; - u32 itip; - u32 itop; - - u32 padding1[(0x0F8 - 0x08C) / sizeof(u32)]; - - u32 csfull; - u32 csdatain; - u32 csrx[HASH_CSR_COUNT]; - - u32 padding2[(0xFE0 - 0x1D0) / sizeof(u32)]; - - u32 periphid0; - u32 periphid1; - u32 periphid2; - u32 periphid3; - - u32 cellid0; - u32 cellid1; - u32 cellid2; - u32 cellid3; -}; - /** * struct hash_state - Hash context state. * @temp_cr: Temporary HASH Control Register. @@ -228,20 +116,6 @@ enum hash_device_id { HASH_DEVICE_ID_1 = 1 }; -/** - * enum hash_data_format - HASH data format. - * @HASH_DATA_32_BITS: 32 bits data format - * @HASH_DATA_16_BITS: 16 bits data format - * @HASH_DATA_8_BITS: 8 bits data format. - * @HASH_DATA_1_BITS: 1 bit data format. - */ -enum hash_data_format { - HASH_DATA_32_BITS = 0x0, - HASH_DATA_16_BITS = 0x1, - HASH_DATA_8_BITS = 0x2, - HASH_DATA_1_BIT = 0x3 -}; - /** * enum hash_algo - Enumeration for selecting between SHA1 or SHA2 algorithm. * @HASH_ALGO_SHA1: Indicates that SHA1 is used. @@ -269,7 +143,7 @@ enum hash_op { * @oper_mode: Operating mode selection bit. */ struct hash_config { - int data_format; + unsigned int data_format; int algorithm; int oper_mode; }; @@ -335,7 +209,7 @@ struct hash_req_ctx { /** * struct hash_device_data - structure for a hash device. - * @base: Pointer to virtual base address of the hash device. + * @map: Regmap for the MMIO for the device * @phybase: Pointer to physical memory location of the hash device. * @list_node: For inclusion in klist. * @dev: Pointer to the device dev structure. @@ -348,7 +222,7 @@ struct hash_req_ctx { * @dma: Structure used for dma. */ struct hash_device_data { - struct hash_register __iomem *base; + struct regmap *map; phys_addr_t phybase; struct klist_node list_node; struct device *dev; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 21657c9c79a7..ed54e71efbb2 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -289,6 +290,45 @@ static int hash_enable_power(struct hash_device_data *device_data) return ret; } +static void hash_wait_for_dcal(struct hash_device_data *device_data) +{ + unsigned int val; + + regmap_read(device_data->map, UX500_HASH_STR, &val); + while (val & HASH_STR_DCAL) { + cpu_relax(); + regmap_read(device_data->map, UX500_HASH_STR, &val); + } +} + +static void hash_fill_din(struct hash_device_data *device_data, + const void *data, unsigned int len) +{ + const u8 *datap = data; + u32 val; + + /* + * We cannot use regmap_write_noinc() because regmap MMIO does + * not support the noinc operations (requires .write() callback). + * TODO: revisit when regmap MMIO supports regmap_write_noinc(). + */ + while (len > 4) { + val = *((u32 *)datap); + regmap_write(device_data->map, UX500_HASH_DIN, val); + datap += 4; + len -= 4; + } + + if (len) { + val = 0; + while (len) { + val |= (datap[len - 1] << (8 * (len - 1))); + len--; + } + regmap_write(device_data->map, UX500_HASH_DIN, val); + } +} + /** * hash_hw_write_key - Writes the key to the hardware registries. * @@ -303,37 +343,17 @@ static int hash_enable_power(struct hash_device_data *device_data) static void hash_hw_write_key(struct hash_device_data *device_data, const u8 *key, unsigned int keylen) { - u32 word = 0; - int nwords = 1; - - HASH_CLEAR_BITS(&device_data->base->str, HASH_STR_NBLW_MASK); - - while (keylen >= 4) { - u32 *key_word = (u32 *)key; - - HASH_SET_DIN(key_word, nwords); - keylen -= 4; - key += 4; - } - - /* Take care of the remaining bytes in the last word */ - if (keylen) { - word = 0; - while (keylen) { - word |= (key[keylen - 1] << (8 * (keylen - 1))); - keylen--; - } + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, 0); - HASH_SET_DIN(&word, nwords); - } + hash_fill_din(device_data, key, keylen); - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + hash_wait_for_dcal(device_data); - HASH_SET_DCAL; + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_DCAL, HASH_STR_DCAL); - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + hash_wait_for_dcal(device_data); } /** @@ -468,16 +488,16 @@ static int ux500_hash_init(struct ahash_request *req) static void hash_processblock(struct hash_device_data *device_data, const u32 *message, int length) { - int len = length / HASH_BYTES_PER_WORD; /* * NBLW bits. Reset the number of bits in last word (NBLW). */ - HASH_CLEAR_BITS(&device_data->base->str, HASH_STR_NBLW_MASK); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, 0); /* * Write message data to the HASH_DIN register. */ - HASH_SET_DIN(message, len); + hash_fill_din(device_data, message, length); } /** @@ -493,39 +513,24 @@ static void hash_processblock(struct hash_device_data *device_data, static void hash_messagepad(struct hash_device_data *device_data, const u32 *message, u8 index_bytes) { - int nwords = 1; - /* * Clear hash str register, only clear NBLW * since DCAL will be reset by hardware. */ - HASH_CLEAR_BITS(&device_data->base->str, HASH_STR_NBLW_MASK); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, 0); - /* Main loop */ - while (index_bytes >= 4) { - HASH_SET_DIN(message, nwords); - index_bytes -= 4; - message++; - } - - if (index_bytes) - HASH_SET_DIN(message, nwords); + hash_fill_din(device_data, message, index_bytes); - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + hash_wait_for_dcal(device_data); /* num_of_bytes == 0 => NBLW <- 0 (32 bits valid in DATAIN) */ - HASH_SET_NBLW(index_bytes * 8); - dev_dbg(device_data->dev, "%s: DIN=0x%08x NBLW=%lu\n", - __func__, readl_relaxed(&device_data->base->din), - readl_relaxed(&device_data->base->str) & HASH_STR_NBLW_MASK); - HASH_SET_DCAL; - dev_dbg(device_data->dev, "%s: after dcal -> DIN=0x%08x NBLW=%lu\n", - __func__, readl_relaxed(&device_data->base->din), - readl_relaxed(&device_data->base->str) & HASH_STR_NBLW_MASK); - - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, index_bytes * 8); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_DCAL, HASH_STR_DCAL); + + hash_wait_for_dcal(device_data); } /** @@ -548,18 +553,21 @@ int hash_setconfiguration(struct hash_device_data *device_data, * DATAFORM bits. Set the DATAFORM bits to 0b11, which means the data * to be written to HASH_DIN is considered as 32 bits. */ - HASH_SET_DATA_FORMAT(config->data_format); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_DATAFORM_MASK, config->data_format); /* * ALGO bit. Set to 0b1 for SHA-1 and 0b0 for SHA-256 */ switch (config->algorithm) { case HASH_ALGO_SHA1: - HASH_SET_BITS(&device_data->base->cr, HASH_CR_ALGO_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_ALGO, HASH_CR_ALGO); break; case HASH_ALGO_SHA256: - HASH_CLEAR_BITS(&device_data->base->cr, HASH_CR_ALGO_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_ALGO, 0); break; default: @@ -573,20 +581,21 @@ int hash_setconfiguration(struct hash_device_data *device_data, * selected algorithm. 0b0 = HASH and 0b1 = HMAC. */ if (config->oper_mode == HASH_OPER_MODE_HASH) { - HASH_CLEAR_BITS(&device_data->base->cr, - HASH_CR_MODE_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_MODE, 0); } else if (config->oper_mode == HASH_OPER_MODE_HMAC) { - HASH_SET_BITS(&device_data->base->cr, HASH_CR_MODE_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_MODE, HASH_CR_MODE); if (ctx->keylen > HASH_BLOCK_SIZE) { /* Truncate key to blocksize */ dev_dbg(device_data->dev, "%s: LKEY set\n", __func__); - HASH_SET_BITS(&device_data->base->cr, - HASH_CR_LKEY_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_LKEY, HASH_CR_LKEY); } else { dev_dbg(device_data->dev, "%s: LKEY cleared\n", __func__); - HASH_CLEAR_BITS(&device_data->base->cr, - HASH_CR_LKEY_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_LKEY, 0); } } else { /* Wrong hash mode */ ret = -EPERM; @@ -607,20 +616,21 @@ void hash_begin(struct hash_device_data *device_data, struct hash_ctx *ctx) /* HW and SW initializations */ /* Note: there is no need to initialize buffer and digest members */ - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + hash_wait_for_dcal(device_data); /* * INIT bit. Set this bit to 0b1 to reset the HASH processor core and * prepare the initialize the HASH accelerator to compute the message * digest of a new message. */ - HASH_INITIALIZE; + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_INIT, HASH_CR_INIT); /* * NBLW bits. Reset the number of bits in last word (NBLW). */ - HASH_CLEAR_BITS(&device_data->base->str, HASH_STR_NBLW_MASK); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, 0); } static int hash_process_data(struct hash_device_data *device_data, @@ -715,22 +725,24 @@ static int hash_dma_final(struct ahash_request *req) /* Enable DMA input */ if (hash_mode != HASH_MODE_DMA || !req_ctx->dma_mode) { - HASH_CLEAR_BITS(&device_data->base->cr, - HASH_CR_DMAE_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_DMAE, 0); } else { - HASH_SET_BITS(&device_data->base->cr, - HASH_CR_DMAE_MASK); - HASH_SET_BITS(&device_data->base->cr, - HASH_CR_PRIVN_MASK); + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_DMAE | HASH_CR_PRIVN, + HASH_CR_DMAE | HASH_CR_PRIVN); } - HASH_INITIALIZE; + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_INIT, HASH_CR_INIT); if (ctx->config.oper_mode == HASH_OPER_MODE_HMAC) hash_hw_write_key(device_data, ctx->key, ctx->keylen); /* Number of bits in last word = (nbytes * 8) % 32 */ - HASH_SET_NBLW((req->nbytes * 8) % 32); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_NBLW_MASK, (req->nbytes * 8) % 32); + req_ctx->hw_initialized = true; } @@ -754,8 +766,7 @@ static int hash_dma_final(struct ahash_request *req) wait_for_completion(&ctx->device->dma.complete); hash_dma_done(ctx); - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + hash_wait_for_dcal(device_data); if (ctx->config.oper_mode == HASH_OPER_MODE_HMAC && ctx->key) { unsigned int keylen = ctx->keylen; @@ -844,9 +855,9 @@ static int hash_hw_final(struct ahash_request *req) hash_messagepad(device_data, req_ctx->buffer, req_ctx->index); } else { - HASH_SET_DCAL; - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); + regmap_update_bits(device_data->map, UX500_HASH_STR, + HASH_STR_DCAL, HASH_STR_DCAL); + hash_wait_for_dcal(device_data); } if (ctx->config.oper_mode == HASH_OPER_MODE_HMAC && ctx->key) { @@ -935,20 +946,24 @@ int hash_hw_update(struct ahash_request *req) */ int hash_check_hw(struct hash_device_data *device_data) { - /* Checking Peripheral Ids */ - if (HASH_P_ID0 == readl_relaxed(&device_data->base->periphid0) && - HASH_P_ID1 == readl_relaxed(&device_data->base->periphid1) && - HASH_P_ID2 == readl_relaxed(&device_data->base->periphid2) && - HASH_P_ID3 == readl_relaxed(&device_data->base->periphid3) && - HASH_CELL_ID0 == readl_relaxed(&device_data->base->cellid0) && - HASH_CELL_ID1 == readl_relaxed(&device_data->base->cellid1) && - HASH_CELL_ID2 == readl_relaxed(&device_data->base->cellid2) && - HASH_CELL_ID3 == readl_relaxed(&device_data->base->cellid3)) { - return 0; + unsigned int regs[] = { UX500_HASH_PERIPHID0, UX500_HASH_PERIPHID1, + UX500_HASH_PERIPHID2, UX500_HASH_PERIPHID3, UX500_HASH_CELLID0, + UX500_HASH_CELLID1, UX500_HASH_CELLID2, UX500_HASH_CELLID3 }; + unsigned int expected[] = { HASH_P_ID0, HASH_P_ID1, HASH_P_ID2, HASH_P_ID3, + HASH_CELL_ID0, HASH_CELL_ID1, HASH_CELL_ID2, HASH_CELL_ID3 }; + unsigned int val; + int i; + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + regmap_read(device_data->map, regs[i], &val); + if (val != expected[i]) { + dev_err(device_data->dev, "ID word %d was %08x expected %08x\n", + i, val, expected[i]); + return -ENODEV; + } } - dev_err(device_data->dev, "%s: HASH_UNSUPPORTED_HW!\n", __func__); - return -ENOTSUPP; + return 0; } /** @@ -960,8 +975,9 @@ int hash_check_hw(struct hash_device_data *device_data) void hash_get_digest(struct hash_device_data *device_data, u8 *digest, int algorithm) { - u32 temp_hx_val, count; int loop_ctr; + u32 val; + int i; if (algorithm != HASH_ALGO_SHA1 && algorithm != HASH_ALGO_SHA256) { dev_err(device_data->dev, "%s: Incorrect algorithm %d\n", @@ -977,13 +993,13 @@ void hash_get_digest(struct hash_device_data *device_data, dev_dbg(device_data->dev, "%s: digest array:(0x%lx)\n", __func__, (unsigned long)digest); - /* Copy result into digest array */ - for (count = 0; count < loop_ctr; count++) { - temp_hx_val = readl_relaxed(&device_data->base->hx[count]); - digest[count * 4] = (u8) ((temp_hx_val >> 24) & 0xFF); - digest[count * 4 + 1] = (u8) ((temp_hx_val >> 16) & 0xFF); - digest[count * 4 + 2] = (u8) ((temp_hx_val >> 8) & 0xFF); - digest[count * 4 + 3] = (u8) ((temp_hx_val >> 0) & 0xFF); + for (i = 0; i < loop_ctr; i++) { + regmap_read(device_data->map, UX500_HASH_H(i), + &val); + digest[i * 4] = (u8) ((val >> 24) & 0xFF); + digest[i * 4 + 1] = (u8) ((val >> 16) & 0xFF); + digest[i * 4 + 2] = (u8) ((val >> 8) & 0xFF); + digest[i * 4 + 3] = (u8) ((val >> 0) & 0xFF); } } @@ -1055,7 +1071,7 @@ static int ahash_sha1_init(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); - ctx->config.data_format = HASH_DATA_8_BITS; + ctx->config.data_format = HASH_CR_DATAFORM_8BIT; ctx->config.algorithm = HASH_ALGO_SHA1; ctx->config.oper_mode = HASH_OPER_MODE_HASH; ctx->digestsize = SHA1_DIGEST_SIZE; @@ -1068,7 +1084,7 @@ static int ahash_sha256_init(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); - ctx->config.data_format = HASH_DATA_8_BITS; + ctx->config.data_format = HASH_CR_DATAFORM_8BIT; ctx->config.algorithm = HASH_ALGO_SHA256; ctx->config.oper_mode = HASH_OPER_MODE_HASH; ctx->digestsize = SHA256_DIGEST_SIZE; @@ -1113,9 +1129,8 @@ static int ahash_import(struct ahash_request *req, const void *in) struct hash_device_data *device_data = ctx->device; struct hash_req_ctx *req_ctx = ahash_request_ctx(req); const struct hash_state *hstate = in; - int hash_mode = HASH_OPER_MODE_HASH; + unsigned int val; u32 cr; - s32 count; /* Restore software state */ req_ctx->length = hstate->length; @@ -1130,27 +1145,24 @@ static int ahash_import(struct ahash_request *req, const void *in) * prepare the initialize the HASH accelerator to compute the message * digest of a new message. */ - HASH_INITIALIZE; + regmap_update_bits(device_data->map, UX500_HASH_CR, + HASH_CR_INIT, HASH_CR_INIT); cr = hstate->temp_cr; - writel_relaxed(cr & HASH_CR_RESUME_MASK, &device_data->base->cr); + regmap_write(device_data->map, UX500_HASH_CR, cr & HASH_CR_RESUME_MASK); - if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) - hash_mode = HASH_OPER_MODE_HMAC; + regmap_read(device_data->map, UX500_HASH_CR, &val); + if (val & HASH_CR_MODE) + regmap_bulk_write(device_data->map, UX500_HASH_CSR(0), + hstate->csr, HASH_CSR_COUNT); else - hash_mode = HASH_OPER_MODE_HASH; - - for (count = 0; count < HASH_CSR_COUNT; count++) { - if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) - break; - writel_relaxed(hstate->csr[count], - &device_data->base->csrx[count]); - } + regmap_bulk_write(device_data->map, UX500_HASH_CSR(0), + hstate->csr, 36); - writel_relaxed(hstate->csfull, &device_data->base->csfull); - writel_relaxed(hstate->csdatain, &device_data->base->csdatain); - writel_relaxed(hstate->str_reg, &device_data->base->str); - writel_relaxed(cr, &device_data->base->cr); + regmap_write(device_data->map, UX500_HASH_CSFULL, hstate->csfull); + regmap_write(device_data->map, UX500_HASH_CSDATAIN, hstate->csdatain); + regmap_write(device_data->map, UX500_HASH_STR, hstate->str_reg); + regmap_write(device_data->map, UX500_HASH_CR, cr); return 0; } @@ -1162,9 +1174,7 @@ static int ahash_export(struct ahash_request *req, void *out) struct hash_device_data *device_data = ctx->device; struct hash_req_ctx *req_ctx = ahash_request_ctx(req); struct hash_state *hstate = out; - int hash_mode = HASH_OPER_MODE_HASH; u32 cr; - u32 count; /* * Save hardware state: @@ -1172,31 +1182,21 @@ static int ahash_export(struct ahash_request *req, void *out) * actually makes sure that there isn't any ongoing calculation in the * hardware. */ - while (readl(&device_data->base->str) & HASH_STR_DCAL_MASK) - cpu_relax(); - - cr = readl_relaxed(&device_data->base->cr); - - hstate->str_reg = readl_relaxed(&device_data->base->str); + hash_wait_for_dcal(device_data); - hstate->din_reg = readl_relaxed(&device_data->base->din); + regmap_read(device_data->map, UX500_HASH_CR, &cr); + regmap_read(device_data->map, UX500_HASH_STR, &hstate->str_reg); + regmap_read(device_data->map, UX500_HASH_DIN, &hstate->din_reg); - if (readl(&device_data->base->cr) & HASH_CR_MODE_MASK) - hash_mode = HASH_OPER_MODE_HMAC; + if (cr & HASH_CR_MODE) + regmap_bulk_read(device_data->map, UX500_HASH_CSR(0), + hstate->csr, HASH_CSR_COUNT); else - hash_mode = HASH_OPER_MODE_HASH; - - for (count = 0; count < HASH_CSR_COUNT; count++) { - if ((count >= 36) && (hash_mode == HASH_OPER_MODE_HASH)) - break; - - hstate->csr[count] = - readl_relaxed(&device_data->base->csrx[count]); - } - - hstate->csfull = readl_relaxed(&device_data->base->csfull); - hstate->csdatain = readl_relaxed(&device_data->base->csdatain); + regmap_bulk_read(device_data->map, UX500_HASH_CSR(0), + hstate->csr, 36); + regmap_read(device_data->map, UX500_HASH_CSFULL, &hstate->csfull); + regmap_read(device_data->map, UX500_HASH_CSDATAIN, &hstate->csdatain); hstate->temp_cr = cr; /* Save software state */ @@ -1214,7 +1214,7 @@ static int hmac_sha1_init(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); - ctx->config.data_format = HASH_DATA_8_BITS; + ctx->config.data_format = HASH_CR_DATAFORM_8BIT; ctx->config.algorithm = HASH_ALGO_SHA1; ctx->config.oper_mode = HASH_OPER_MODE_HMAC; ctx->digestsize = SHA1_DIGEST_SIZE; @@ -1227,7 +1227,7 @@ static int hmac_sha256_init(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); - ctx->config.data_format = HASH_DATA_8_BITS; + ctx->config.data_format = HASH_CR_DATAFORM_8BIT; ctx->config.algorithm = HASH_ALGO_SHA256; ctx->config.oper_mode = HASH_OPER_MODE_HMAC; ctx->digestsize = SHA256_DIGEST_SIZE; @@ -1298,7 +1298,7 @@ static int hash_cra_init(struct crypto_tfm *tfm) crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), sizeof(struct hash_req_ctx)); - ctx->config.data_format = HASH_DATA_8_BITS; + ctx->config.data_format = HASH_CR_DATAFORM_8BIT; ctx->config.algorithm = hash_alg->conf.algorithm; ctx->config.oper_mode = hash_alg->conf.oper_mode; @@ -1435,6 +1435,107 @@ static void ahash_algs_unregister_all(struct hash_device_data *device_data) crypto_unregister_ahash(&hash_algs[i].hash); } +static bool ux500_hash_reg_readable(struct device *dev, unsigned int reg) +{ + switch (reg) { + case UX500_HASH_CR: + case UX500_HASH_DIN: + case UX500_HASH_STR: + case UX500_HASH_H(0) ... UX500_HASH_H(7): + case UX500_HASH_ITCR: + case UX500_HASH_ITIP: + case UX500_HASH_ITOP: + case UX500_HASH_CSFULL: + case UX500_HASH_CSDATAIN: + case UX500_HASH_CSR(0) ... UX500_HASH_CSR(51): + case UX500_HASH_PERIPHID0: + case UX500_HASH_PERIPHID1: + case UX500_HASH_PERIPHID2: + case UX500_HASH_PERIPHID3: + case UX500_HASH_CELLID0: + case UX500_HASH_CELLID1: + case UX500_HASH_CELLID2: + case UX500_HASH_CELLID3: + return true; + default: + return false; + } +} + +static bool ux500_hash_reg_writeable(struct device *dev, unsigned int reg) +{ + switch (reg) { + case UX500_HASH_CR: + case UX500_HASH_DIN: + case UX500_HASH_STR: + case UX500_HASH_ITCR: + case UX500_HASH_ITIP: + case UX500_HASH_ITOP: + case UX500_HASH_CSFULL: + case UX500_HASH_CSDATAIN: + case UX500_HASH_CSR(0) ... UX500_HASH_CSR(51): + return true; + default: + return false; + } +} + +static bool ux500_hash_reg_writeable_noinc(struct device *dev, unsigned int reg) +{ + if (reg == UX500_HASH_DIN) + return true; + return false; +} + +static bool ux500_hash_reg_volatile(struct device *dev, unsigned int reg) +{ + switch (reg) { + case UX500_HASH_CR: + case UX500_HASH_STR: + case UX500_HASH_H(0) ... UX500_HASH_H(7): + case UX500_HASH_ITCR: + case UX500_HASH_ITIP: + case UX500_HASH_ITOP: + case UX500_HASH_CSFULL: + case UX500_HASH_CSDATAIN: + case UX500_HASH_CSR(0) ... UX500_HASH_CSR(51): + /* + * The following IDs are read-only, but to the reg cache they are + * volatile, since they have values there at startup. + */ + case UX500_HASH_PERIPHID0: + case UX500_HASH_PERIPHID1: + case UX500_HASH_PERIPHID2: + case UX500_HASH_PERIPHID3: + case UX500_HASH_CELLID0: + case UX500_HASH_CELLID1: + case UX500_HASH_CELLID2: + case UX500_HASH_CELLID3: + return true; + default: + return false; + } +} + +static const struct regmap_config ux500_hash_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + /* + * Regcache is not helpful since we shoehorn tons of random data + * into the hash engine, the few register reads outside of that + * are not worth it. Disable the cache. + */ + .cache_type = REGCACHE_NONE, + .fast_io = true, + .max_register = 0xFFC, + .use_relaxed_mmio = true, + .readable_reg = ux500_hash_reg_readable, + .writeable_reg = ux500_hash_reg_writeable, + .volatile_reg = ux500_hash_reg_volatile, + .writeable_noinc_reg = ux500_hash_reg_writeable_noinc, +}; + /** * ux500_hash_probe - Function that probes the hash hardware. * @pdev: The platform device. @@ -1445,6 +1546,7 @@ static int ux500_hash_probe(struct platform_device *pdev) struct resource *res = NULL; struct hash_device_data *device_data; struct device *dev = &pdev->dev; + void __iomem *base; device_data = devm_kzalloc(dev, sizeof(*device_data), GFP_KERNEL); if (!device_data) { @@ -1463,11 +1565,22 @@ static int ux500_hash_probe(struct platform_device *pdev) } device_data->phybase = res->start; - device_data->base = devm_ioremap_resource(dev, res); - if (IS_ERR(device_data->base)) { - ret = PTR_ERR(device_data->base); + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) { + ret = PTR_ERR(base); + goto out; + } + device_data->map = devm_regmap_init_mmio(dev, base, + &ux500_hash_regmap_config); + if (IS_ERR(device_data->map)) { + ret = PTR_ERR(device_data->map); goto out; } + /* + * We use REGCACHE_NONE, so also bypass any calls not stubbed + * by that. + */ + regcache_cache_bypass(device_data->map, true); spin_lock_init(&device_data->ctx_lock); spin_lock_init(&device_data->power_state_lock); From patchwork Tue Aug 16 14:00:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944999 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85BC3C2BB41 for ; Tue, 16 Aug 2022 14:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235938AbiHPOE0 (ORCPT ); Tue, 16 Aug 2022 10:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235886AbiHPODp (ORCPT ); Tue, 16 Aug 2022 10:03:45 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CA13275CC for ; Tue, 16 Aug 2022 07:03:31 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id s9so10622955ljs.6 for ; Tue, 16 Aug 2022 07:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=iGU/vTvY2BX/8BFNJIo0Zi6+OPq5P/GCaKsV9MKmlIE=; b=JUvySrLf8AfkfDQXHferjf2b/51+EzSOdbTnPUEB5odg4h0YfoYDvpwoUGBv8hhI0C 2H2kaUpK62JhEgD1Gr63xBymd/uLs9wD89+1AmFU9AGmJonAR6pEooAnGG3/fPXJk2qc W0he0f74qilfaQ3PvRZ2I0cIMfevvR67rmT+SjLVhAjoi6ZzKNJcdRf81jxECZQDvgDz PlUbIIQJAs+2zFyNj9XEc9s7BUQbxCsXX0w4JOIKUxk6IyDtxPqd4Z2+1DvqjWMoJde0 bOtjad0ZfvlFdArBTeGs9aU9abuSpPHiDz2k4gAyy0DPjV4pizqc+383zwoPvLeZziwR cq2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=iGU/vTvY2BX/8BFNJIo0Zi6+OPq5P/GCaKsV9MKmlIE=; b=rgIXZsVmxluqwtvaVVMwqbVGQ4SdqOTrDlTVNcp/VVLCmOrJ0cKOFM/qMtjf1fMX3e 3jn6XvKCzwhl0Yh/VZgwsy/dxqAP3T8PjMeb2qTU0Lbbnjd1GG4BDztN7LnahlAekDPr 0o+zliImrp/UY0eoIG/0JIg24v7LMWtXUfP4EgYUPw26vsjIGtuuV2czuD7mnnXOInnW EjrG3LCuerDeWKbV6aO1JkzhPWDCeur4c/BpGxNLSsh4P6StFu/EzSu5q9TFLwE6FRjS idNwKkygV57GxZP8QA/LBi2QTS66gtnCZRXMooFQo5Fn2NChfic+o7crRRaJaXkFa0DS 1Ysw== X-Gm-Message-State: ACgBeo0b86HRHjEqDK8dc/MHSvUjTlhOZmKvNZnsJWSqDGgXZxCHHWSn oaJhquRkj9ScZcPeCM10Fjglz3ZajyEb+A== X-Google-Smtp-Source: AA6agR5iHJzwOOs05iNGV4oO74C0ClSsUfVFWA3J3GuRgen6PQ/F4ejV8LZ9LHj/xErIwU82K2sWVw== X-Received: by 2002:a2e:9791:0:b0:261:6d82:7a6c with SMTP id y17-20020a2e9791000000b002616d827a6cmr6320638lji.224.1660658610158; Tue, 16 Aug 2022 07:03:30 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:29 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 14/16] crypto: ux500/hash: Use AMBA core primecell IDs Date: Tue, 16 Aug 2022 16:00:47 +0200 Message-Id: <20220816140049.102306-15-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use the AMBA (PrimeCell) bus core define and read 32bit CID and PID from the peripheral, then check those. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - Initialized both CID and PID to 0 appropriately. --- drivers/crypto/ux500/hash/hash_alg.h | 11 ++--------- drivers/crypto/ux500/hash/hash_core.c | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index cc44d3cb21ac..96c614444fa2 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -63,15 +63,8 @@ #define HASH_STR_NBLW_MASK 0x0000001FUL #define HASH_NBLW_MAX_VAL 0x1F -/* PrimeCell IDs */ -#define HASH_P_ID0 0xE0 -#define HASH_P_ID1 0x05 -#define HASH_P_ID2 0x38 -#define HASH_P_ID3 0x00 -#define HASH_CELL_ID0 0x0D -#define HASH_CELL_ID1 0xF0 -#define HASH_CELL_ID2 0x05 -#define HASH_CELL_ID3 0xB1 +/* PrimeCell ID */ +#define UX500_HASH_PID 0x003805E0U /* Hardware access method */ enum hash_mode { diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index ed54e71efbb2..188e309406b2 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) "hashX hashX: " fmt +#include #include #include #include @@ -949,18 +950,28 @@ int hash_check_hw(struct hash_device_data *device_data) unsigned int regs[] = { UX500_HASH_PERIPHID0, UX500_HASH_PERIPHID1, UX500_HASH_PERIPHID2, UX500_HASH_PERIPHID3, UX500_HASH_CELLID0, UX500_HASH_CELLID1, UX500_HASH_CELLID2, UX500_HASH_CELLID3 }; - unsigned int expected[] = { HASH_P_ID0, HASH_P_ID1, HASH_P_ID2, HASH_P_ID3, - HASH_CELL_ID0, HASH_CELL_ID1, HASH_CELL_ID2, HASH_CELL_ID3 }; unsigned int val; + u32 pid = 0; + u32 cid = 0; int i; for (i = 0; i < ARRAY_SIZE(regs); i++) { regmap_read(device_data->map, regs[i], &val); - if (val != expected[i]) { - dev_err(device_data->dev, "ID word %d was %08x expected %08x\n", - i, val, expected[i]); - return -ENODEV; - } + if (i < 4) + pid |= (val & 255) << (i * 8); + else + cid |= (val & 255) << ((i - 4) * 8); + } + + if (cid != AMBA_CID) { + dev_err(device_data->dev, "AMBA CID was %08x expected %08x\n", + cid, AMBA_CID); + return -ENODEV; + } + if (pid != UX500_HASH_PID) { + dev_err(device_data->dev, "PID was %08x expected %08x\n", + pid, UX500_HASH_PID); + return -ENODEV; } return 0; From patchwork Tue Aug 16 14:00:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12944998 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF321C28B2B for ; Tue, 16 Aug 2022 14:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235888AbiHPOE1 (ORCPT ); Tue, 16 Aug 2022 10:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235887AbiHPODq (ORCPT ); Tue, 16 Aug 2022 10:03:46 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CAF02C135 for ; Tue, 16 Aug 2022 07:03:32 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id o2so15087953lfb.1 for ; Tue, 16 Aug 2022 07:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=tcxO47ygEsHC0iu9hAyWTaXnRiHqq4d+JFjoMEvLaVk=; b=I7Jie9Kg8eCs+8zKf4I6NnTalBPaSnt7OdI3w9AJCVCtUKJGXD1x1eohAJ6cepkuFy aiLRrLxGAofV7Mb2Cp9xC53w8DI4MugwcPWzU/zWVPCHAhfTbuAynCmmlKIBUYQpLUno HUgG+4JiI5/ADKKbVmOq1h4p/U+Q1uOUE3AwHtRxA3WG04aglO81QZq0erwdw9Be2I3m IxSqjv3+I/vD/BG5rLJ/Lee32aeBKe+m8xpWkgiBoQZfEV8FVsanR4MGRjS6Alb8GdYS NeCbzL4dxb7AnMheV843unejVpb10vKvBm82xtlW0PaNuEFQG+6YbKt1Ms3pBEN9jfed 0gPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=tcxO47ygEsHC0iu9hAyWTaXnRiHqq4d+JFjoMEvLaVk=; b=SbyZPimTcA2ZnzHdXlIicMUNYoJJJJ2ovXIUmnFVDZnMWbUduyeXlm1CvIuAhQsgfN rFWv3FxHqq7ZZe2SQ/BtPTckJa9BTrUx70DlY3peGnV9qZQU9UhfFQMsZb6uX//WxVuj xomaRwcE5WjoiKdcZPulWlzMpXwqnONoykejIroQ8hGWta1RyGcKPHGJhkWdNZGfkb7D U+hnOU3vBKaq6uW5fGVWGfxgE0y/VYpMQrTOKEkVUIl4fRRz3+LnjQu9QEDPtj5o1+FN frQlMjTmqx2PevueJHF3XWgAVmNb7S51RScTS2in7VcWY/ooPJAMmL/PNqFsQ9itWunp 2+8A== X-Gm-Message-State: ACgBeo2dc2VrZqTKVgG/JsCtp5ORKlXAygs0FnaljOYurYCtvlaJx6TO HDwqsRQ2iNwdC6LTfUF0j/pql/Mo8jC/MQ== X-Google-Smtp-Source: AA6agR4Q9L3NZYtBSA9gZA8H7YFNUHhj95pn2oCaYdy45v5bd+zyE/hh4GJAAs6YWij4fo20xxXZSg== X-Received: by 2002:a19:4f56:0:b0:48b:205f:91a9 with SMTP id a22-20020a194f56000000b0048b205f91a9mr7081096lfk.543.1660658611358; Tue, 16 Aug 2022 07:03:31 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:31 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 15/16] crypto: ux500/hash: Implement runtime PM Date: Tue, 16 Aug 2022 16:00:48 +0200 Message-Id: <20220816140049.102306-16-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This implements runtime PM to gate the clock and regulator when the hash block is unused. Drop the own-invented "power state" and its associated lock: we don't need that when we have runtime PM. Delete the specific power functions and just enable/disable the clock in the runtime PM functions. Use the full *_prepare_enable() and *disable_unprepare() calls for really making sure the clock is off. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased on v6.0-rc1 ChangeLog v1->v2: - New patch to clean up also the custom PM. --- drivers/crypto/ux500/hash/hash_alg.h | 3 +- drivers/crypto/ux500/hash/hash_core.c | 164 +++++++++++--------------- 2 files changed, 71 insertions(+), 96 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_alg.h b/drivers/crypto/ux500/hash/hash_alg.h index 96c614444fa2..344f2294a938 100644 --- a/drivers/crypto/ux500/hash/hash_alg.h +++ b/drivers/crypto/ux500/hash/hash_alg.h @@ -16,6 +16,7 @@ #define HASH_DMA_ALIGN_SIZE 4 #define HASH_DMA_PERFORMANCE_MIN_SIZE 1024 #define HASH_BYTES_PER_WORD 4 +#define UX500_HASH_AUTOSUSPEND_DELAY_MS 50 /* Number of context swap registers */ #define HASH_CSR_COUNT 52 @@ -221,8 +222,6 @@ struct hash_device_data { struct device *dev; spinlock_t ctx_lock; struct hash_ctx *current_ctx; - bool power_state; - spinlock_t power_state_lock; struct regulator *regulator; struct clk *clk; struct hash_dma dma; diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index 188e309406b2..be703fe4d0ec 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -240,57 +241,6 @@ static int get_empty_message_digest( return ret; } -/** - * hash_disable_power - Request to disable power and clock. - * @device_data: Structure for the hash device. - * - * This function request for disabling the clock. - */ -static int hash_disable_power(struct hash_device_data *device_data) -{ - int ret = 0; - - spin_lock(&device_data->power_state_lock); - if (!device_data->power_state) - goto out; - - clk_disable(device_data->clk); - - device_data->power_state = false; - -out: - spin_unlock(&device_data->power_state_lock); - - return ret; -} - -/** - * hash_enable_power - Request to enable power and clock. - * @device_data: Structure for the hash device. - * - * This function request for enabling the clock. - */ -static int hash_enable_power(struct hash_device_data *device_data) -{ - int ret = 0; - struct device *dev = device_data->dev; - - spin_lock(&device_data->power_state_lock); - if (!device_data->power_state) { - ret = clk_enable(device_data->clk); - if (ret) { - dev_err(dev, "%s: clk_enable() failed!\n", __func__); - goto out; - } - device_data->power_state = true; - } - -out: - spin_unlock(&device_data->power_state_lock); - - return ret; -} - static void hash_wait_for_dcal(struct hash_device_data *device_data) { unsigned int val; @@ -449,6 +399,10 @@ static int ux500_hash_init(struct ahash_request *req) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); struct hash_ctx *ctx = crypto_ahash_ctx(tfm); struct hash_req_ctx *req_ctx = ahash_request_ctx(req); + struct hash_device_data *device_data = ctx->device; + + /* Power up on init() power down on final() */ + pm_runtime_get_sync(device_data->dev); if (!ctx->key) ctx->keylen = 0; @@ -474,6 +428,7 @@ static int ux500_hash_init(struct ahash_request *req) } } } + return 0; } @@ -782,6 +737,8 @@ static int hash_dma_final(struct ahash_request *req) memcpy(req->result, digest, ctx->digestsize); out: + pm_runtime_mark_last_busy(device_data->dev); + pm_runtime_put_autosuspend(device_data->dev); /** * Allocated in setkey, and only used in HMAC. */ @@ -1040,8 +997,11 @@ static int ahash_update(struct ahash_request *req) */ static int ahash_final(struct ahash_request *req) { - int ret = 0; + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct hash_ctx *ctx = crypto_ahash_ctx(tfm); + struct hash_device_data *device_data = ctx->device; struct hash_req_ctx *req_ctx = ahash_request_ctx(req); + int ret = 0; pr_debug("%s: data size: %d\n", __func__, req->nbytes); @@ -1050,6 +1010,9 @@ static int ahash_final(struct ahash_request *req) else ret = hash_hw_final(req); + pm_runtime_mark_last_busy(device_data->dev); + pm_runtime_put_autosuspend(device_data->dev); + if (ret) { pr_err("%s: hash_hw/dma_final() failed\n", __func__); } @@ -1150,6 +1113,9 @@ static int ahash_import(struct ahash_request *req, const void *in) req_ctx->hw_initialized = hstate->hw_initialized; memcpy(req_ctx->buffer, hstate->buffer, HASH_BLOCK_SIZE); + /* Power up as we may have lost power being exported */ + pm_runtime_get_sync(device_data->dev); + /* * Restore hardware state * INIT bit. Set this bit to 0b1 to reset the HASH processor core and @@ -1217,6 +1183,10 @@ static int ahash_export(struct ahash_request *req, void *out) hstate->hw_initialized = req_ctx->hw_initialized; memcpy(hstate->buffer, req_ctx->buffer, HASH_BLOCK_SIZE); + /* We can power down while exported */ + pm_runtime_mark_last_busy(device_data->dev); + pm_runtime_put_autosuspend(device_data->dev); + return 0; } @@ -1593,7 +1563,6 @@ static int ux500_hash_probe(struct platform_device *pdev) */ regcache_cache_bypass(device_data->map, true); spin_lock_init(&device_data->ctx_lock); - spin_lock_init(&device_data->power_state_lock); device_data->clk = devm_clk_get(dev, NULL); if (IS_ERR(device_data->clk)) { @@ -1602,25 +1571,24 @@ static int ux500_hash_probe(struct platform_device *pdev) goto out; } - ret = clk_prepare(device_data->clk); + ret = clk_prepare_enable(device_data->clk); if (ret) { - dev_err(dev, "%s: clk_prepare() failed!\n", __func__); + dev_err(dev, "%s: clk_prepare_enable() failed!\n", __func__); goto out; } - /* Enable device power (and clock) */ - ret = hash_enable_power(device_data); - if (ret) { - dev_err(dev, "%s: hash_enable_power() failed!\n", __func__); - goto out_clk_unprepare; - } - ret = hash_check_hw(device_data); if (ret) { dev_err(dev, "%s: hash_check_hw() failed!\n", __func__); - goto out_power; + goto out_clk; } + pm_runtime_set_autosuspend_delay(dev, UX500_HASH_AUTOSUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + if (hash_mode == HASH_MODE_DMA) hash_dma_setup_channel(device_data, dev); @@ -1630,18 +1598,20 @@ static int ux500_hash_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "%s: ahash_algs_register_all() failed!\n", __func__); - goto out_power; + goto out_pm_disable; } + pm_runtime_put_sync(dev); dev_info(dev, "successfully registered\n"); - return 0; - -out_power: - hash_disable_power(device_data); -out_clk_unprepare: - clk_unprepare(device_data->clk); + return 0; +out_pm_disable: + pm_runtime_get_sync(device_data->dev); + pm_runtime_put_noidle(device_data->dev); + pm_runtime_disable(device_data->dev); +out_clk: + clk_disable_unprepare(device_data->clk); out: return ret; } @@ -1675,11 +1645,10 @@ static int ux500_hash_remove(struct platform_device *pdev) ahash_algs_unregister_all(device_data); - if (hash_disable_power(device_data)) - dev_err(dev, "%s: hash_disable_power() failed\n", - __func__); - - clk_unprepare(device_data->clk); + pm_runtime_get_sync(device_data->dev); + pm_runtime_put_noidle(device_data->dev); + pm_runtime_disable(device_data->dev); + clk_disable_unprepare(device_data->clk); return 0; } @@ -1714,17 +1683,17 @@ static void ux500_hash_shutdown(struct platform_device *pdev) ahash_algs_unregister_all(device_data); - if (hash_disable_power(device_data)) - dev_err(&pdev->dev, "%s: hash_disable_power() failed\n", - __func__); + pm_runtime_get_sync(device_data->dev); + pm_runtime_put_noidle(device_data->dev); + pm_runtime_disable(device_data->dev); + clk_disable_unprepare(device_data->clk); } -#ifdef CONFIG_PM_SLEEP /** - * ux500_hash_suspend - Function that suspends the hash device. + * ux500_hash_runtime_suspend - Function that suspends the hash device. * @dev: Device to suspend. */ -static int ux500_hash_suspend(struct device *dev) +static int __maybe_unused ux500_hash_runtime_suspend(struct device *dev) { int ret; struct hash_device_data *device_data; @@ -1735,21 +1704,20 @@ static int ux500_hash_suspend(struct device *dev) return -ENOMEM; } - ret = hash_disable_power(device_data); - if (ret) - dev_err(dev, "%s: hash_disable_power()\n", __func__); + clk_disable_unprepare(device_data->clk); + dev_info(dev, "runtime suspended\n"); return ret; } /** - * ux500_hash_resume - Function that resume the hash device. + * ux500_hash_runtime_resume - Function that resume the hash device. * @dev: Device to resume. */ -static int ux500_hash_resume(struct device *dev) +static int __maybe_unused ux500_hash_runtime_resume(struct device *dev) { - int ret = 0; struct hash_device_data *device_data; + int ret; device_data = dev_get_drvdata(dev); if (!device_data) { @@ -1757,15 +1725,23 @@ static int ux500_hash_resume(struct device *dev) return -ENOMEM; } - ret = hash_enable_power(device_data); - if (ret) - dev_err(dev, "%s: hash_enable_power() failed!\n", __func__); + ret = clk_prepare_enable(device_data->clk); + if (ret) { + dev_err(dev, "%s: clk_enable() failed!\n", __func__); + return ret; + } - return ret; + dev_info(dev, "runtime resumed\n"); + + return 0; } -#endif -static SIMPLE_DEV_PM_OPS(ux500_hash_pm, ux500_hash_suspend, ux500_hash_resume); +static const struct dev_pm_ops ux500_hash_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(ux500_hash_runtime_suspend, + ux500_hash_runtime_resume, NULL) +}; static const struct of_device_id ux500_hash_match[] = { { .compatible = "stericsson,ux500-hash" }, @@ -1780,7 +1756,7 @@ static struct platform_driver ux500_hash_driver = { .driver = { .name = "hash1", .of_match_table = ux500_hash_match, - .pm = &ux500_hash_pm, + .pm = &ux500_hash_pm_ops, } }; module_platform_driver(ux500_hash_driver); From patchwork Tue Aug 16 14:00:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12945000 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E951C25B0E for ; Tue, 16 Aug 2022 14:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235887AbiHPOE2 (ORCPT ); Tue, 16 Aug 2022 10:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235889AbiHPODq (ORCPT ); Tue, 16 Aug 2022 10:03:46 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F31348EAA for ; Tue, 16 Aug 2022 07:03:33 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id v2so15063856lfi.6 for ; Tue, 16 Aug 2022 07:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Ivipl+R3KaUVhvm6+/uc6buRF+V3GiyHLaPQIyOLyJY=; b=Ku1K8okvTsqZWSrom1nyEPa7LmVHnQw789D3bH6894IPwQtY+0d2dodISIkXHyeaeH E8n8wJxFOkUX/r0rFiIgDkvibh5Yd8Fh+7lJB1A0tb2M+dew+gIV2JXtmwyz/xMc5f3Z a3cZDinMYLRUHNhMAukJupNxPEzKF5l6XKdjbADByRRik4xEq8WRhoaM1xJDkSh2C/Kq LwTPQ8FYf3rIfMQjHxkIbp+wXuFQYeHtCG8CwvXimPjjVEsoCVyfS8RAEOwIHv+JuYDD wIcelH0p5cgFlROcDJTOhKnRH3QpruaVhueEvNoFCXE+sV+Yl5XpCAnqEESAgkPIMMIo Vhxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Ivipl+R3KaUVhvm6+/uc6buRF+V3GiyHLaPQIyOLyJY=; b=jFS5vqFpoaDLU03pJkLGnuM2f6KLqwHa2i08GlnsmPr2rzHUmP8o8olfN6K5Fo5T3X 1hdX+TkfA1EzgTGm2YvCINsYyJdvYNpoer9heoDbVwYpjIKj2C/QgPDPnARLMgz/vOv8 woClIfNUZ+/wtJq3ZRQgcwUh0B0hML7Ub5dRIzlEm0U4VxM0ZQRdQg0/5tsUjdU3AVSq JrYkeLt9grr7iwIIcNxrIGieo5NT6jR/w2uRVCY6QqwdGc9hI2vE8rDGg3rOnx40J3uO tEKVKzteAMaFn1qAQky+dFwQWIyy22605LW3SQXBaRM5Dibb6gV45NQpcX2dtYbbd+U2 oCYg== X-Gm-Message-State: ACgBeo1Hj6Ik6adrTCPVN37qeK8ajcOZecSFsVYwDXmiE9r4dSFpeCC5 L66rRAmgj/Ep8kF82iJf5OT1hwNNjzl9wQ== X-Google-Smtp-Source: AA6agR5zEyGUE1TDC7NRh/f0M+uxNMd9TqVSjpi8cB6WPiMB+kEZel1mzRADhq01cn8D4hMOSBpcRw== X-Received: by 2002:a05:6512:a82:b0:48b:1241:f4cc with SMTP id m2-20020a0565120a8200b0048b1241f4ccmr6929877lfu.141.1660658612646; Tue, 16 Aug 2022 07:03:32 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id r27-20020a2eb61b000000b0025e739cd9a7sm1747902ljn.101.2022.08.16.07.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:03:32 -0700 (PDT) From: Linus Walleij To: linux-crypto@vger.kernel.org, Herbert Xu , "David S . Miller" Cc: phone-devel@vger.kernel.org, Stefan Hansson , Linus Walleij Subject: [PATCH v3 16/16] crypto: ux500/hash: Use accelerated noinc MMIO Date: Tue, 16 Aug 2022 16:00:49 +0200 Message-Id: <20220816140049.102306-17-linus.walleij@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220816140049.102306-1-linus.walleij@linaro.org> References: <20220816140049.102306-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org After fixes to regmap we can use accelerated MMIO access to quickly fill up the hash with new data. Signed-off-by: Linus Walleij --- ChangeLog v1->v3: - New patch based on v6.0-rc1 --- drivers/crypto/ux500/hash/hash_core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c index be703fe4d0ec..aa91bfecba15 100644 --- a/drivers/crypto/ux500/hash/hash_core.c +++ b/drivers/crypto/ux500/hash/hash_core.c @@ -256,18 +256,13 @@ static void hash_fill_din(struct hash_device_data *device_data, const void *data, unsigned int len) { const u8 *datap = data; + int evenbytes = (len / 4) * 4; u32 val; - /* - * We cannot use regmap_write_noinc() because regmap MMIO does - * not support the noinc operations (requires .write() callback). - * TODO: revisit when regmap MMIO supports regmap_write_noinc(). - */ - while (len > 4) { - val = *((u32 *)datap); - regmap_write(device_data->map, UX500_HASH_DIN, val); - datap += 4; - len -= 4; + if (evenbytes) { + regmap_noinc_write(device_data->map, UX500_HASH_DIN, + data, evenbytes); + len -= evenbytes; } if (len) { @@ -1472,6 +1467,7 @@ static bool ux500_hash_reg_volatile(struct device *dev, unsigned int reg) { switch (reg) { case UX500_HASH_CR: + case UX500_HASH_DIN: case UX500_HASH_STR: case UX500_HASH_H(0) ... UX500_HASH_H(7): case UX500_HASH_ITCR: