From patchwork Mon Jul 25 14:04:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928084 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 033EFC43334 for ; Mon, 25 Jul 2022 14:07:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbiGYOHY (ORCPT ); Mon, 25 Jul 2022 10:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234405AbiGYOHX (ORCPT ); Mon, 25 Jul 2022 10:07:23 -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 7C03213CC4 for ; Mon, 25 Jul 2022 07:07:22 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id p10so10692523lfd.9 for ; Mon, 25 Jul 2022 07:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fD8+wIdL2kfiinqMnkslDfHHIOINpTieSbpxOuavPaA=; b=xNwZLDP8Gk3vb5BGkbchDjpzJr4kUCFXO4y1amkIvhwNiVNuvAji3+M+NxjfC4eMqo C6N2iW1WCQjtyrK17Wr8vkIU6Wok6B29RvVetnYJC5RtJm2H8gSs4TqZANbebKSwXz2U MT3AXdhX31RXf3jwuPgmVhocA0xZ12y3iHMqGKGca1uBPRdwMOvt+Vtfqn59BtZDCkIV zZUKtKyQCPMVr5ONPHBCNh+xxuCFoZwp9X9eM9jQWxEbd9S3Tj4Ds86xe7eEwmIVzD2u xyNOv1sEByae1deKglQVu7rpn9QH34R7Hzy+hy4cncDp2Hg5CzSCXwZRcZe3xDhfehKs rtxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fD8+wIdL2kfiinqMnkslDfHHIOINpTieSbpxOuavPaA=; b=v6VpExHbR0Z4jSe00qJG9TT/rjhwL8j71AzUcv0EJ9kIZLHkSgYNt+CkSHWNhpSrfN xrCqKJ47Zd4JW1PYYB9UuTiekHuueAVd5rpxH5O1QQDXXXAeCCN3b1ovuu6kmzWJEqXK TuzhG6hzMfiZ3SFKkGUDJohElTRQbVb4HH6ng7if7tnOfbO3ji4jW6de1BV52yC0DXsQ SYZADBXMgIG10zdOzqG4dUmNQ9AbYIrTlgoVarLvUudp42UF3yramIAT+OpnY5wTJoHt Cw12E4tDYRrvwOYeKk3rd7FZfEZ1QRQD9Wlgr37T9MP+WaXr96CKjj7mJXT8OXzjwxPj nYuw== X-Gm-Message-State: AJIora/9Tz4y7inHACqJyLHC74OMmzbKBFuG5h6zO8wI0nOj83DtjPmS TFri8UVcHrixJfRsDh7eecqtyP8kclQgNg== X-Google-Smtp-Source: AGRyM1sl2+MNAqlTlw8xq4c3MTz7OiJa6xNYiuQ6wgTFx2GQREdQml0uCLZR8tmP+Tu+QZ7JPTtcxg== X-Received: by 2002:ac2:456c:0:b0:48a:8c7f:e332 with SMTP id k12-20020ac2456c000000b0048a8c7fe332mr1981147lfm.410.1658758041636; Mon, 25 Jul 2022 07:07:21 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 01/15 v2] crypto: ux500/hash: Pass ctx to hash_setconfiguration() Date: Mon, 25 Jul 2022 16:04:50 +0200 Message-Id: <20220725140504.2398965-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 265ef3e96fdd..dfdf3e35d94f 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 Mon Jul 25 14:04:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928085 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 E5BDCC43334 for ; Mon, 25 Jul 2022 14:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235275AbiGYOHa (ORCPT ); Mon, 25 Jul 2022 10:07:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234945AbiGYOH1 (ORCPT ); Mon, 25 Jul 2022 10:07:27 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 044CF14087 for ; Mon, 25 Jul 2022 07:07:25 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id b16so5762637lfb.7 for ; Mon, 25 Jul 2022 07:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZBy4mH3tH/mKdYrWAHsE8vj+OWKXhvzJV2v2xxRnpkk=; b=BoZYnRmPSAfvA0ruBqvQ3onCm2I/HVp0JbBxyUZ0IlOj6pCAxsM1kcMvqd0Mc7JFsS Lqk4A6xPAxhCY9KBy2CjH3478VC2EovsVOPBvkNaPMSOOOY3M52DbfTNNg3Lz15YoYjE tAtmvbKHFpa6heq/jMSD2QLGxunld9FrWsIkEt5xVsdHiJNsrfLRF/zlE1j/Oejhy8Ly sZDq0As1Qi7UQ44B6jEMOp2jQ7KColdNUysi5rJJv5gPEB6YljU2LrIzZeJL13290TvD n9QUGo/UbSzOtbNHC9j53s79b7QRjLrpjOXKYb/ctvkhRI/5XeNhsSDM8zi60G4K1tl3 6rxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZBy4mH3tH/mKdYrWAHsE8vj+OWKXhvzJV2v2xxRnpkk=; b=BndH6sGz6ECJRNnvU6+9qdZ45lKkEgq/eAK2j0yOz6GiExcKBw4rDfFVWKk4+SkDU6 4PfG7vS+YiqdI1UK6M7E4ZgFPGtrWd4Dn6rxnbNOKYGVOCQxBT/jLGwAcI95HqBcDhOq pOLzz1mIsmcNYG2sg6U7yc6eC+Ure2+Dy6dW9dQaWKdGi7jk1whYLruv12ZCXmVYJtWk 5hQ6PbNDP57ZuYD4dMGJZEAbqJvPnO9oSQlUUoml6Z+EOn2kzO11zbzfCwtDhe84/Sbb 2BjqjjhL6WAfpKZO0pXlFFRq6zEVRaXUzJtlgKgfDAiAqjMHfWZ7vCJx3tJ1csSb5hhx DppQ== X-Gm-Message-State: AJIora86zLHsKeOKEgWP5liujAJXLG/l2HuWFeGCuV6nLeCsPUs1bcCZ cIRv+aPWXRJSCwB6lXt82vJCudqoXHz23w== X-Google-Smtp-Source: AGRyM1sYgcqD+1vlk+ePPVy+Hs9MZJ8Zce8GL7/S4pHY6bp+oaUSCtUHmQ3Lqw+ruf1ecI0QaGXK8Q== X-Received: by 2002:a05:6512:258b:b0:48a:83da:4f0a with SMTP id bf11-20020a056512258b00b0048a83da4f0amr3326060lfb.256.1658758042940; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:22 -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 02/15 v2] crypto: ux500/hash: Get rid of custom device list Date: Mon, 25 Jul 2022 16:04:51 +0200 Message-Id: <20220725140504.2398965-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 dfdf3e35d94f..fd7a862244ac 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 Mon Jul 25 14:04:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928086 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 69EABCCA473 for ; Mon, 25 Jul 2022 14:07:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235190AbiGYOHb (ORCPT ); Mon, 25 Jul 2022 10:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235261AbiGYOH2 (ORCPT ); Mon, 25 Jul 2022 10:07:28 -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 37B0814D3A for ; Mon, 25 Jul 2022 07:07:26 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id r14so13248040ljp.2 for ; Mon, 25 Jul 2022 07:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZWLYEfxygMjqNcWPZGRXzAM2CEyKrpm8S5gQVU/gLlY=; b=ZIJv2oWwotCmwAqMhW3UumXcWXz5Gf2FFNn99IZMcNXGKMEENS8ISwkLKbHtw+NNsU UxZvvFl5Cbow9Pg19p5jKwZP8QGQ01+v7yYbWDP2nwxfjOH9XqtJrfwUwGflH2IoAAGW hNMG7gvXa5V4OIiAL7jlIkpx58oCFV4rNcFXAgO4ZmZeDqfl+YcBfbdaAHUXZ6mJRo6i miAiz1LCG+y85CgLUgtTIbEaDXLAupMBoaV5Vv4Q9zR4jn9kJjKiEzafa4gqQJydMCfB kLTnqZLJEYfO427Pyy+AIZczkk5MRyPPDc/uK88AgFpuDZXxpRxthihwORbDwiP3JrKG nBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZWLYEfxygMjqNcWPZGRXzAM2CEyKrpm8S5gQVU/gLlY=; b=yPw4Er15ORoREP53Kj2vMA7VPyu1AP1j2e1Rn3VZTmlnkM0mlErGQC6W4OyjWZ+gTD FBjbbaqq3v2bebkfzbt3adQSPmVLe77zY+O/tPcxXqujXtGNBVUizljkw2PwVkjLj7TO J2w+aacyuFuw5h98cCR0ZpPJsm9e7/+0H+OeWmndYhiMNnQJC918iOBO8vcHoJYAx575 vHFHTgQ0djk1K0xraBjKfa35SFSjJL7Lk06+FW92wV/hekJFYiYJDC5qLpiVCeJ3Kvdf GV2A0IdnZUGubhyLKqEcRK6ehG0HazSX2EX0NWsu0CDtsnmTtC1cVAivQZYST23FRNQu NEPg== X-Gm-Message-State: AJIora8lVGgYh52n4K8uuwoV5TrGRcF30IYvny9zAL3aIOnpW4rSVwaY Nq0eWGBbwJ5O0rHzjh84cRJSmoJnPOQ4kw== X-Google-Smtp-Source: AGRyM1tQhbDtPEcMYb6kyTXB8hWFpZ0eFYmkrvzPyDeuZ0/r51E7PrQz0wwVQLzZYZnpNvpoDLq94Q== X-Received: by 2002:a2e:8ec7:0:b0:25e:92f:c330 with SMTP id e7-20020a2e8ec7000000b0025e092fc330mr1496341ljl.56.1658758044351; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 03/15 v2] crypto: ux500/hash: Pass context to zero message digest Date: Mon, 25 Jul 2022 16:04:52 +0200 Message-Id: <20220725140504.2398965-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 fd7a862244ac..884046e87262 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 Mon Jul 25 14:04:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928087 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 36081CCA48C for ; Mon, 25 Jul 2022 14:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235261AbiGYOHc (ORCPT ); Mon, 25 Jul 2022 10:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235272AbiGYOHa (ORCPT ); Mon, 25 Jul 2022 10:07:30 -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 73C8B165B6 for ; Mon, 25 Jul 2022 07:07:28 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id z13so12857887ljj.6 for ; Mon, 25 Jul 2022 07:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rN8jYOVehuu3dO+n+b32giGGSLgkWgby9u0JmweOpzI=; b=aU7gzGVDCfF1zbEJ+RRAnz6f6z/HIkXICO+9eTKQKaKaOtrhDz2OWq0aH1mrF3D9hm ztUaNrj/UfrGYhs1fd4BokFaJJEFzmSEGL9/0cim+LpA4yq3sg/mvDIB5g6Kw98VXiOw /TgLym8YI7m3W9z5VpG6jD2JahtCfm255zRpgAo91CeNHrreocmcNLdPHp2xzoRvRMyX xUY370lSolVSj1PJ1CPh2vF1n7SKEdixPPhChr74MY7MVq2N0ytVdrLYyw3vQ+TfrYKo FGIfR7YbBlyWzAbp9zQp3e0BEtZx+nAzfdyWbAwd5e/YFtTgIf5lj+/e4pfapY8rluAe 1D6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rN8jYOVehuu3dO+n+b32giGGSLgkWgby9u0JmweOpzI=; b=nRmba+A1lUYqfWjYGCiYw2LijYon6oJ3P+7f1a3P6R2ewerWVADssUArQgGFubAS73 RC1vbgz9qbBueS0TLJeH+M78yc8RPuNTRJQF+k8pHadX6xtfzoBn/wrZrXGOEbKCKq+P 5VkRTWjqDq/INNskV9TWYcRr0H0nSDQC2L6M9xFm5hYf0U/3tKHG8ZMuITBDXCsMCWZx M1eq5WLF7yju6+4TctbRC/XNSUHKvi92pg7Z6H6XKrwHvoxU9AYtDs6aIQwaHOJen0Z8 BfS3ZKPY0nAiNdixpgp+ZhwuO60IiREMG9LlMG4AQtH2cmv/xk/bqswRUjt29rPN5A8t WK5Q== X-Gm-Message-State: AJIora+EVkIguwn8dFwZxjqu6ISRlxZQz5k+CbR/dxHKjeCZKR7pcyXD LJU2yw9eeo+lbPdvTtQy5jr9HiZluxXStw== X-Google-Smtp-Source: AGRyM1ty7gR21SbKWRLehmT4mU90C7+mFpjstmZxS4W5nnmffRbQxvMRTHnOK5DYNIc2/A/5HFfmpw== X-Received: by 2002:a05:651c:32d:b0:25e:946:2740 with SMTP id b13-20020a05651c032d00b0025e09462740mr1429814ljp.378.1658758046151; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 04/15 v2] crypto: ux500/hash: Drop custom state save/restore Date: Mon, 25 Jul 2022 16:04:53 +0200 Message-Id: <20220725140504.2398965-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 884046e87262..e6e3a91ae795 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 Mon Jul 25 14:04:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928088 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 03A05CCA48F for ; Mon, 25 Jul 2022 14:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235281AbiGYOHc (ORCPT ); Mon, 25 Jul 2022 10:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235273AbiGYOHa (ORCPT ); Mon, 25 Jul 2022 10:07:30 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50987167C2 for ; Mon, 25 Jul 2022 07:07:29 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id t17so5956876lfk.0 for ; Mon, 25 Jul 2022 07:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uRvI4FZyi9EAerjPaenffG/YQ8jsdNde1v0863NG528=; b=CX2PeM/RmnUqqvtuDcLYfqpl6eTxSkeU9motVdpORR72Hem2+0iFD/TDH+LDKEEoRz jwVTAEmGFzI9iyMCCjsh1Q20nBfwVOBt3m3lpplUgfICLyiHtco1W+HQFrMAubWehyTP zuF+t08i5dnYkBSAhAxAB6gjxqdY/weY4iOclDPiCq2S/ckHh2kNqK4n4Gs3QqfPzex+ Wp67SbjfVeiAFtZ709ycS+uGnk/9CKQY9KjWgxRpGzrFvvMx2IyhX/lR7+8dtsJG+uD6 uy/8jE1mAaadZtIqfpnTYaq3QA1168+/pnyGWtFkOOYnSXVOa9C11cLIH7mpnfLB2bFa VCIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uRvI4FZyi9EAerjPaenffG/YQ8jsdNde1v0863NG528=; b=fl57kuCt9QPifuVqj1trPDInYe1ohfXIWV9GC1SgSegOEwbacRh6P6g/Nfqs41PFxs kibL7/ypKOFe8luWArEu99D0KuIwwLnG/PrcUNc149Wci84RSqM1SUWvcvWUjTXnei2D qxu+H9EL31UIs5wpMVm4zMF8bsGQ5/QEATxnt9oxwWeLhsaoQBPt6unIG1ABQVqPlSPD 8G38MOgX5zLjSPrZ+5q4FCeATf2HxIM3rFyGD4eDAPw+M6KLc3ic5yjayyrLM68SMQGB 2xF0cYXYuxUrzEYmixQmbCrElIgMMS+/e74oZ4CfWKf/k1jkaai0HYtpax4N8xsAYOtE x8xg== X-Gm-Message-State: AJIora9YXvU5NcrQruIjHh1k+mlVsLdeypV6D4qDN5IP2F2DsPQYkqIV N5nPlmzRtenrYYYUQ2yN7n61dkCqNINSfg== X-Google-Smtp-Source: AGRyM1utbeva6CvwbChtckcmDyHUNhJJhIIziA+US8OtNy6CMqzgFQD3KHkF6PepkgcFnSvqTAkiIg== X-Received: by 2002:ac2:5084:0:b0:48a:6e29:bf8 with SMTP id f4-20020ac25084000000b0048a6e290bf8mr4756854lfm.572.1658758047443; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 05/15 v2] crypto: ux500/hash: Drop bit index Date: Mon, 25 Jul 2022 16:04:54 +0200 Message-Id: <20220725140504.2398965-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 e6e3a91ae795..e9962c8a29bd 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 Mon Jul 25 14:04:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928089 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 C6884CCA473 for ; Mon, 25 Jul 2022 14:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235273AbiGYOHd (ORCPT ); Mon, 25 Jul 2022 10:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235222AbiGYOHb (ORCPT ); Mon, 25 Jul 2022 10:07:31 -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 83157167C9 for ; Mon, 25 Jul 2022 07:07:30 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id z13so12858048ljj.6 for ; Mon, 25 Jul 2022 07:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XhDve6JLJ3Kju6H4o7eHpk5rJCSDlgoSXIzWMLgqIdY=; b=BrQmM4z6wseWqWYrUpGMUcwzzFz459jFZoxL8QfLFrHozJDEqLZxKcA2crq9qmCSHi 1PrXTJu9w3s7nvBMGm4t7tJOaE0t3l0djy9NZAMnslMJXdCwtjgeeg7i8FB3emO6965t bi36OxcGi4JodTJMNsyen0iGY289Wh51BNkZ9qDOHEyBA/LuUvla/LTeQ1cyQp5Ci8h5 I/BluA8Z+vWhILMH6p2s+DW+M29YFuE/bMoJv0lEdCHxEAe7JzpydrXMsMsrS03DMm7l ixiMIfs7pjPm/YWiruw8JIF9eyFW9ePtoFJd6ro8fH0if0dciGmWcz3/1pGwFAb+kOjC es5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XhDve6JLJ3Kju6H4o7eHpk5rJCSDlgoSXIzWMLgqIdY=; b=EBI/WwuSqKthOGiaAvvK1utkipQd+ZWgQbXGydmbsBqqy70N8YYxciJFOOpv9+oijc 3/R6kMR1EOhkNfnNc4NaqBkrNEImpPsBABGB+8gG8LKxwkT8pT4H6WNgkkc2+4Ki3p5L y5JyXoS9HYBoL6Q+sFJkH0LGDm5bFsDdoeXyC3DS8xVMRQa5sv5MkiWcS1POETackEv9 0fy+hcmzSe3qgcYDH3M1i9I0C5Gfm2o/+UtJHsXmSASDzbsNfRJvYDTff8CkIpSv8zQM PxQQadypJRKFC72lx117AkqsHN1H80tKoaTj3Tqq1jjH7lMoxV81TbXwHhW54LIxFe+v D3mA== X-Gm-Message-State: AJIora/zuGw3yTT0126C6FRlyafQDM3ljnlKFLfR8oIPdjZ5BcL9sdWA sL3waVZkb3PFhEEtz1lwFakZ8popd1dF+Q== X-Google-Smtp-Source: AGRyM1vHMG4ei9iEs7o1abwOd/CPQsfJvXKmO7hj4znQHZHTukk3pyN/f7P0bAWe7I49adkyagEO0w== X-Received: by 2002:a05:651c:160a:b0:25a:62a4:9085 with SMTP id f10-20020a05651c160a00b0025a62a49085mr4575036ljq.214.1658758048757; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 06/15 v2] crypto: ux500/hash: Break while/do instead of if/else Date: Mon, 25 Jul 2022 16:04:55 +0200 Message-Id: <20220725140504.2398965-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 e9962c8a29bd..c9ceaa0b1778 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 Mon Jul 25 14:04:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928090 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 D75FACCA48C for ; Mon, 25 Jul 2022 14:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235342AbiGYOHf (ORCPT ); Mon, 25 Jul 2022 10:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235276AbiGYOHc (ORCPT ); Mon, 25 Jul 2022 10:07:32 -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 9C4A115FCC for ; Mon, 25 Jul 2022 07:07:30 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id by8so13234297ljb.13 for ; Mon, 25 Jul 2022 07:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V9qbu9pBS7+3W8ZYo1R9wg6Idr81jkbRlVfnq4Xdegw=; b=vcRKkgvDyoN9zjH5gsnY0vT7d2/dQODfvaY75B23jv/5Yq7u89OyepPanfnm/SNh1J 7oR8WBwPscK2aDXI8Xme3XmsDFahek5EozjdqCin+5luNi28zQn6WhKt5VstNq/XEDUC AyQoD57RP9/yOTqdpqX4SShnAT2IB4/FeKPgBvKL8xHFf3aFp0BCclIyghbGSJ5phJsn 3ALdUyw5sK78yk+LAI/ZJvTJWYdsoNvyoGqperpMKceBv5LfzVoXqavQNKjbnNj+9BXW /FKY/Q3uLV80pjxPswajCp4NuLtW5yOx517Mk5bFBo564lCR264WSdbTPq7XGx4c8daH q1yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V9qbu9pBS7+3W8ZYo1R9wg6Idr81jkbRlVfnq4Xdegw=; b=d2+l1YxdzMGnnoPtkF55dnNaHq+sCk3aw4P68B0r9wGbquPSJ6LdUE4GlqZ5tsmtcl uNqsCNIm5L+S1kIoti4FeKlAmJyWQJ4gTnxwkGkkkPu9533B6UCcVQ5tEf6i0uRPACCf 2k3n9+NdnO/bS/wWCEsFgqmE9Kn5ggn3clJ2iUw3wOvuJUc29SRk8kgH9g7rilLtOcnE stha9gT1bCD79BEpxKp/vfPBwUhrHTgpL1xYZgTiAjr/ULRDZElI7jecIWQMaHPFd4HW sIvudbJMR0s9VZkZiT9Q4KzFK8orLaJRHcvjhDILyB2RVD31J8QXKC/hHgnEYspKCShz M2jw== X-Gm-Message-State: AJIora8vKUuIFyEAaopwr4QMFuNdUPmhqSlCldoy3s5nu7obQcybrBzC RoFzcSZFLMvh16BZ0PA137EDs0HW3JFbtw== X-Google-Smtp-Source: AGRyM1uJcrN5AaY3eNHSIYIIu7YgnA1QC0+LcgDImVrnSpq+aBtQMWFzenZf0xxVwEhmPJon/wdVCg== X-Received: by 2002:a2e:938c:0:b0:25d:f714:52e8 with SMTP id g12-20020a2e938c000000b0025df71452e8mr4015661ljh.454.1658758050037; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 07/15 v2] crypto: ux500/hash: Rename and switch type of member Date: Mon, 25 Jul 2022 16:04:56 +0200 Message-Id: <20220725140504.2398965-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 c9ceaa0b1778..b3649e00184f 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 Mon Jul 25 14:04:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928091 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 8343CC433EF for ; Mon, 25 Jul 2022 14:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235329AbiGYOHr (ORCPT ); Mon, 25 Jul 2022 10:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235333AbiGYOHe (ORCPT ); Mon, 25 Jul 2022 10:07:34 -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 46A9414D35 for ; Mon, 25 Jul 2022 07:07:33 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id a13so13080820ljr.11 for ; Mon, 25 Jul 2022 07:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C6S3uKvTAP+Cp0+QHVaCOI5oR5HoGiw3zJjt6sISzSU=; b=yTVzpWenvwRkWoozJxMrX1G2Siyp5l8lHkNgDuuxKQTs0WDKiCSxJqCXzVRDMz+mwA 7Cbg2sfEMF5q9Nmz6q6yafvsoW5xXKgXWKnJ6fG90RHn7Kew1Y6ho5z7crhoHPadpjsL m2gjHyk8WZrOpgykW7W0s4kFhPhViFe+ADajhpDOomE6v0EnCoyYDR0TcrOgQVdsThvZ pnBCsl1r6MPKdTsGzYZcsLkB6o43iudjstrajruGG1dOBxnAUzfQFFcuqORdEEXw6Xuc NhlKHTahomNq2+eBF6kmiHgvijZy+OfFv5v6hXKY347t9n3wbmBtsbjgidTVyUY2lGe5 Wqrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C6S3uKvTAP+Cp0+QHVaCOI5oR5HoGiw3zJjt6sISzSU=; b=bQWtzYtotqu1z0jKi1lqa43DgwBqE6DDcXlOuHGvwHjYU9dpRRDw4mE5OnhyH6g0gz r/EREQUCSNoOSaKphQ5iF12KC18pr+Z9GoYeOO2OOyVyUAIaFX66VMHDa97RNCW1j6t7 jKl8aQQF/Fw2OX2IIQ1vLvMG/UJg/oOyXApQ3Cu/z8JDLifW7y5X8k6ZYsmgg5XprZbR aaLXyY9ZVCvkEfflODyccoifAffYR+Eq9CTJ9A21O5E/GDMPseVOG6u3cbzoLgHxpF5O /rLw0ztrFJM7++sHlb/+hVHkkf3E2hfrTVW8GWzmzPJ9PMnTNeEOmXbp0nLwxiJ8UTIV Ij1g== X-Gm-Message-State: AJIora/5RkiWTg4/gQxr6xvk9gfSP4UIXJtXk8yHQl9xx3n9oecw8njQ nPZGhTq5u7q8qphuIA75x7Eqfk9S8KeNWA== X-Google-Smtp-Source: AGRyM1v6m9uG8KrasSYT71mXP4rd8Zh4mfRM7XRxUrJXE/q+b9w2l5/yQxgs+EkYgpzxrZbJJuVFcg== X-Received: by 2002:a2e:5705:0:b0:25d:f295:c9d8 with SMTP id l5-20020a2e5705000000b0025df295c9d8mr4528319ljb.292.1658758051314; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 08/15 v2] crypto: ux500/hash: Stop saving/restoring compulsively Date: Mon, 25 Jul 2022 16:04:57 +0200 Message-Id: <20220725140504.2398965-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 b3649e00184f..c2e8bd977f57 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 Mon Jul 25 14:04:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928092 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 648F9CCA473 for ; Mon, 25 Jul 2022 14:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235332AbiGYOHr (ORCPT ); Mon, 25 Jul 2022 10:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235222AbiGYOHf (ORCPT ); Mon, 25 Jul 2022 10:07:35 -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 493E515FCC for ; Mon, 25 Jul 2022 07:07:33 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id by8so13234472ljb.13 for ; Mon, 25 Jul 2022 07:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iil7pyadLsiItt4fgSDUQOwrxRR3XJeZgGmkhWhYJ1U=; b=thnslM863r6FuCa9v9Br0joQjC7cWCgm1PzcUvIMxJQ7Lwxpi9yN72mFO2KGvEyIAy Fi/794HXNDyopVNIPsIiX/FlsD9X9n8w7ze1h14ki6i0rTphgL3PrmS0KPCVlJIMQ4+9 /g0g/ZubzGUptYmYgA9nClqaSPhiUkHZHuCYvyLPpwv6Tfp+/qWtupQcf9ZwIK3xn9dN zObGOldz1D1aj5FJc9XVEGN1xpbf9b7Twzcx/Q0M+zq+3tanyEXcshYRyIyC3aaWSh9T D72a77lZ+j9vDYMg7/UKZIPFBNQJZFHWbJKmUsTBJRro+rf7enYUxARPec5Qwn5UqsBK L/dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iil7pyadLsiItt4fgSDUQOwrxRR3XJeZgGmkhWhYJ1U=; b=hH7aifcixYL8zeQJgBTu0ODusSP13QmNbWFWp8p3K0d1lv4Ssc2EUTDgBQ/oLtTgfP 5jbPyItYzprdzCr5f0qVzfgvSXgu2nSoZh0I9B9x9UwsQWftGUOdCtb46p/A4IhSKP3e 8VjmUT7qui2v6iK2hxGyAuJJscDx2VTAc0s1bznVJ+QKsII0NSE+HAbqvoPeStMgwHTs LAzWSh0CNSX/h2Az84fBomkQiT3tU+Z+ism1n1iLJubBoOOYjcSU+1EwU8mMm0sh5HKy iyqhdggzZWDkKN8j25C1wUDN8RPmW+rEzJeQeh698nM5nCk2eUEb1oFcy3cNH50yetCF Z/fQ== X-Gm-Message-State: AJIora9NrDdjayqbkqiBsmT+ti3AOk6zaKiQ6iy1CLDxYm2jn/rq8GL4 nRA/Qj3qr06OE/YEz6hB+PIgEpCuE/FjJQ== X-Google-Smtp-Source: AGRyM1vo62ECTzQcXdVh1unBz9couZKALFbWVaGXMW4kQU3/3AvyCFPsUAe9z2YCj5BUWfC4BB0rZw== X-Received: by 2002:a2e:a990:0:b0:25d:5e37:1746 with SMTP id x16-20020a2ea990000000b0025d5e371746mr4492106ljq.34.1658758052636; Mon, 25 Jul 2022 07:07: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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07: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 09/15 v2] crypto: ux500/hash: Get rid of state from request context Date: Mon, 25 Jul 2022 16:04:58 +0200 Message-Id: <20220725140504.2398965-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 c2e8bd977f57..46dad128b6fe 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 Mon Jul 25 14:04:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928093 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 AEFE8C433EF for ; Mon, 25 Jul 2022 14:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235440AbiGYOIB (ORCPT ); Mon, 25 Jul 2022 10:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235269AbiGYOHk (ORCPT ); Mon, 25 Jul 2022 10:07:40 -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 E4E7F167C8 for ; Mon, 25 Jul 2022 07:07:34 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id p22so3443347lji.10 for ; Mon, 25 Jul 2022 07:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nYX7Y16K2holIUqsDpcgLU5VEJyjd2qVQe8bxbMCzME=; b=u6uEbEo4/mM3QNuCI9CL2W/16XGjQTXe9hBJraEsGqKQv0REc37KnjrgovR4OyxgRe 3wbRns4GJ8Rog5J+0suKcS6chgA4YUWFTSRaE/aaLbyiYUp+X3cynMtlyTiKOKfJQjDX eXBqcyruwMY/NX2LAK8H0jSAGCQ9YvihPSORH9j1qzj300wDUXs1rwuP8cXmSG6pmmSw v6Hn6DJWE/7U8/WNJ7ifYReVuNAYfz0XGuRu96tfwA4jZVXc4q7mKCz9uSl8hA2Q2bWW fBYzbU0ObvEUbZqPobZECYsPQdsp97MXGeNFacR/61SaHpslRdZ4+yhwiLEQLajx3AwG We7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nYX7Y16K2holIUqsDpcgLU5VEJyjd2qVQe8bxbMCzME=; b=og9kNl56rhvgNdkHXoOubwsNcLiowh+hLGuairXypdrm5X08i3pe7RdnffhZLtocPK 0Dd9AQJqEYZFW4e2Y4Z/VL7aOiTAZoL0j96xXlAW7fVunwf1V522FaZYD4xjFlPqT7ru gJXeil+OrWOgmL0LcLrpQPZ6FknjKT/XV8xuwH0+TUOuHMoDpfwZponxJfRx+VDaZvkd B16XmJiWFcJHJZl1In2Nt1aM30P8NZs0JT7uO1UdBJEsvzJ71VJQBXPvIHNaRaSYJMXb NjmsE/I8cx94NG1XGEx4sSZ4HV2XS06oD8aOENl9QmBBcOj4rPihqcbsbQxUYT7/UWh0 G2sw== X-Gm-Message-State: AJIora/7J22/2wP712N9CFfr+4Fb/AMIcpHVe2dgJeSiLlrud5YE9jaN aCql597j6v0fsTl6REKuGU2PWEVq/UDbfQ== X-Google-Smtp-Source: AGRyM1tZwOeQ2RKUG3Gnj0Mb03TYdDQSBMXGACg4+e/eM4YYUrZdP1tTzX6pgckOjTcCg9QADjXc1A== X-Received: by 2002:a2e:b88b:0:b0:25d:a15a:bba9 with SMTP id r11-20020a2eb88b000000b0025da15abba9mr4551031ljp.357.1658758054048; Mon, 25 Jul 2022 07:07:34 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:33 -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 10/15 v2] crypto: ux500/hash: Implement .export and .import Date: Mon, 25 Jul 2022 16:04:59 +0200 Message-Id: <20220725140504.2398965-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 46dad128b6fe..1edb11812c7d 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 Mon Jul 25 14:05:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928094 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 807ECCCA473 for ; Mon, 25 Jul 2022 14:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235358AbiGYOIC (ORCPT ); Mon, 25 Jul 2022 10:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235311AbiGYOHl (ORCPT ); Mon, 25 Jul 2022 10:07:41 -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 4040717054 for ; Mon, 25 Jul 2022 07:07:36 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id by8so13234614ljb.13 for ; Mon, 25 Jul 2022 07:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f/vbPkNKKbkjJjRwGJUOoxcfcoJSh1/50auwny6lijM=; b=ygR5yI4yLkEw91pK3Zuyntm9mWwzok7jYknAlg00Gb60IwA+HqI7ez7sn8KMEm2wbS vo1sFTF/qSsSJeH0yCDjsXxqoKFSizsVGR4pwYLpwrSe1NC7hxxPtnyKEuA5v1iThfxo t5/Aso14HYPsamjcem4xtmQGk/HsxVjGkb3LZM27s0Q+7B+3IFp92lwF51HgFzk3Y24v N5Gc/bm0RKekHRmyQfLgKcSEVJOwBefBx+c9CDaO3qPuaTC35m8BIENmRB4F8Ry6pX4M XknAT0PDVv/KaB/mg+E7uULlirB3qbh3fMo0v5g8q7KPkoqV84qTu8f6NVvWPPOuQQoG TiHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f/vbPkNKKbkjJjRwGJUOoxcfcoJSh1/50auwny6lijM=; b=aJFlSDNSJJQtbnN5ZkjFErHp3SpNyAuojUqg8kCRHuUu6r7hNpjshPbhX7FzdUg+e6 5N+jUFePpdayxeuUk0U4MO+zBxlgCLJVwIF+zzPivUYnScgVne0pQia/pJTTpbquE00D JGbsShsXiX4e79j6cg0RrVX07QdD6tOlZmpNJpZpm4/XmjQukioQNVXX+3TFkgzmzWXv Sz30aaHMyOMChMYs+X1CAgk0bsax1OcdQER4AedxAoK7yIny6IpilfX/so7VhWbNzYWb ZGYKQ5xcXIzFdUJeDrYYiDdrd9TVLlWoF/S7oSB7qmQvN9Y04GgmIPaA9iaZ9OE8nFRv 6JhA== X-Gm-Message-State: AJIora8zTr/tc2wEyP5RspgZpuHyEW2QQdXTbvx7g1NBz7lnUUQyRVeR nIGH6jlFg+F5Kwod/Mja0mdUI6eTkaVdqg== X-Google-Smtp-Source: AGRyM1tlVocaOXGBmAUJjTtSoTV1/vY6C+4qoaq0mflIUvRWTwEBbDnxfqq2kPY13ZWsVUTxYCZypg== X-Received: by 2002:a05:651c:178f:b0:25d:ba24:2e98 with SMTP id bn15-20020a05651c178f00b0025dba242e98mr4288019ljb.197.1658758055508; Mon, 25 Jul 2022 07:07:35 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:35 -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 11/15 v2] crypto: ux500/hash: Drop custom uint64 type Date: Mon, 25 Jul 2022 16:05:00 +0200 Message-Id: <20220725140504.2398965-12-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 1edb11812c7d..390e50b2b1d2 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 Mon Jul 25 14:05:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928095 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 7152DC43334 for ; Mon, 25 Jul 2022 14:08:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235321AbiGYOIF (ORCPT ); Mon, 25 Jul 2022 10:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232682AbiGYOH6 (ORCPT ); Mon, 25 Jul 2022 10:07:58 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B1D17A94 for ; Mon, 25 Jul 2022 07:07:38 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id u20so5466992ljk.0 for ; Mon, 25 Jul 2022 07:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yi2lvCepVGwm5m2nCvkz5wHi60hhFaZd2WavgA33JOY=; b=nV1yHgodszVgqTT0PRJYaE3rLNkXFMwuZc/Ahb8HqL0mY/KHLAcHSZ8JJlqt6YwnW0 QeLD5UJFti4ggBKJxaEV66nykmHrwfxFbhiHdSasBhRxHtbPHD5sVpp0x0S4LH1j6pkd tzDovRmoAIJ1l+2QLHTEKCzMk8lBbsWcHJ/Dr6q18jLUtSbV4giipH0LCWaIkECDnlfz fTpT8i+NWskM4ZebkuRxxjcMCmJA8a3t9FOWaDJpUZvH4sF1KQzQhKUzIYqPWA82+NPb /725E390S3N9gWCDIJ+VFvIkV0YFmWSvxNAzBwAGdoNquUK3bGk5Igi6j/gggiADhRRz 1QnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yi2lvCepVGwm5m2nCvkz5wHi60hhFaZd2WavgA33JOY=; b=YKttJfvfLu1KA9/Br860zEVRUgV13TycXa6Dw97VpD0e60w7CHPCXpG3doclYU/dfw DE5CA1HexqT0Cp1h3qB8xY/67wPOPEr1aBVwJ504A7CSRYGuypZNMLLOaA2AJ82g/u7D OWhF7mtiuBjZlQvG+xgF1XVtq6dAgSzONDcxEC2iWY6pw7eFsKVNHV/kfYvJMKrRkFf/ DxRDaKH6ZuGf7l3q9SysxVT+BI3R6G9KFIX+c82o2PD/ybOdia+c8BuVN+ulMXJyrsAv bJsic6ddxEv4c26v9vbctEZ9IcyNtSgqhPm/TY6LeDD6auvFQ/G5bq8/nBcpbC87fVzp u8VQ== X-Gm-Message-State: AJIora83bfW6Kc55BWVTyL1C//RP4L0dh04bgSrHfzoVzEuWbQq4fng1 fIad1EpBby93PmW1gpTq/Eq6CQWIEzWgKQ== X-Google-Smtp-Source: AGRyM1vqpWKxgUjA7sTYscL5OkgIL6QlfPeVDFZYgyIRf7MHZLt+8BRJyTOCKlQqWHRwv/7irOFx4Q== X-Received: by 2002:a2e:3109:0:b0:25a:8a0c:40e2 with SMTP id x9-20020a2e3109000000b0025a8a0c40e2mr4155142ljx.26.1658758056835; Mon, 25 Jul 2022 07:07:36 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:36 -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 12/15 v2] crypto: ux500/hash: Drop regulator handling Date: Mon, 25 Jul 2022 16:05:01 +0200 Message-Id: <20220725140504.2398965-13-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 390e50b2b1d2..3bd58b60aade 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 Mon Jul 25 14:05:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928098 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 5EED4CCA490 for ; Mon, 25 Jul 2022 14:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235181AbiGYOII (ORCPT ); Mon, 25 Jul 2022 10:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235276AbiGYOH7 (ORCPT ); Mon, 25 Jul 2022 10:07:59 -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 758A617AA4 for ; Mon, 25 Jul 2022 07:07:39 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id by8so13234803ljb.13 for ; Mon, 25 Jul 2022 07:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ml1TL5b3nOmQaPLroLg4kxj5s789f1Zgfues0z8+qI8=; b=ySM1hscslhS9n2h5XIfP779jb0wO4StWpACPPW9E28qZOHnuq0weoFpynLxWp7BgSj 6CliFGmU+0jsTZiWHoVJXcThAGmXwS1vvxTlWyLBgk6Zy31lQJV8r2wd9ZFYJsewbCcV EbLmhozZkIQdcCeeBeuumiXmTKrlK53PruUc4f/R3jRjTkk6WhGkkDWANZT27HyzBgDA 7sGU6l8mMeWxuilgC719rPpXLHuWG00txyPfEx4PBo9KAt/JJzS3G0HaYBPA2bZR67Hu GWRXGcteDIr8mmLsIgM1tOc71ojQ4KTMAAkxq4pXNcNn/zbEWsB+T/mi/CN66fx/b+yu T16g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ml1TL5b3nOmQaPLroLg4kxj5s789f1Zgfues0z8+qI8=; b=pK3XhcgLJIrW1h4Rh658gdMq3uoZEw0350rP/aFEmlLwDGHslAJCQn7TzIHTNS0f1v EJ1a8G8CEht4cbgo+b3+eGXbVkFI5mIL6nBcIonzcLZZn8bhlwKur8P/az8Tifb9Lk2u c76bPAxDBhNie/s/mlKtdSF4Wg5xWHws2pjUWEhBgm+2InVr2RMCX+l2n1pV5qJiACBM mryFMgcSlqY35b2SmQLLLaNXKKwEWl2guc58WLJYMbzYLnib0BJzY1y+PgajryfI8ZH1 3A7rWSsdB/J/1gIXHYEUPs0TAAbqjNSoHHnEx8snyezLbXUR8c1/R7HL4oW1Xu8nKwJF RaDw== X-Gm-Message-State: AJIora+8pymTjcjGKtMVE922aVhOFOxc7tBnJ8U7sIyUz3fIs0G2J/wc fr1IiMpImd41YISgq1hJt+36l3Mg35mzmg== X-Google-Smtp-Source: AGRyM1vXYrVP4XbagUGC4HsmNxMUh9pIUpISj8DlkUXoqRj85nbosbVqhF8wFPULjfQDCidLPvUd8g== X-Received: by 2002:a05:651c:151:b0:25d:e967:23e1 with SMTP id c17-20020a05651c015100b0025de96723e1mr4094163ljd.346.1658758058188; Mon, 25 Jul 2022 07:07:38 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:37 -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 13/15 v2] crypto: ux500/hash: Convert to regmap MMIO Date: Mon, 25 Jul 2022 16:05:02 +0200 Message-Id: <20220725140504.2398965-14-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 3bd58b60aade..914c35919570 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 Mon Jul 25 14:05:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928096 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 89486CCA48F for ; Mon, 25 Jul 2022 14:08:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232682AbiGYOIF (ORCPT ); Mon, 25 Jul 2022 10:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235413AbiGYOIA (ORCPT ); Mon, 25 Jul 2022 10:08:00 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5BF115FEA for ; Mon, 25 Jul 2022 07:07:41 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id m9so13218091ljp.9 for ; Mon, 25 Jul 2022 07:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SrdUO9p0SA0PsaHNzNaJfswGHU5WZE7FQ25wOEwgT+E=; b=r61hLiVUDqiYKvL0Rbcg5CGjg5OD61d4x2IyQT4cbcupYh+QBKe/3mDJWC6CiDX1WV 6jVUUDt0XG4QJRWb0RFZDrJDnl5EGFS18lNwnGBOWBtKUrbrErHgHuzyzb2b3QwG6XkW wnbBkcQbwlm3C8OQjDtMxhUK4HQrGK8PxLZFm2copghgLhK9FXIGQKtZq9f5yb81bVqZ b9GtiZnAIl1wU4ofw7gA2hQdIfcfhWDqYYETXeL7JAaNrb/ugG4KTDGFPfVpk8HxyFj8 MPSyUNW6Iw77O+E8Z1dwksg/ulzaBNEkh/6FvoDhveSqgJ6dsb0wLvfehu6vMIgleErP IApg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SrdUO9p0SA0PsaHNzNaJfswGHU5WZE7FQ25wOEwgT+E=; b=uv8JGhJzOlzqFfXhdgvv70vuXWZ04GeNRSJc4H+Kn0YRfIaKxuUYEjB6UVkirjYdBZ q4fCDi8W7xHhuYxRSKRXerT1kxPVd/Z0Le85PwMiENt0Pra8JBBkJwpSCZU7kQWF1Bq7 /BXNKTbL1x9liEHcr23NgflyMo0kYUu2Gi1MwbGqLgqVzugpOB4OP7HqbheXA1JCHcPc IDjjyTRUNAQpYv/nJ82mxrl9ctIjR5g60ZA6Ehj7wRmCEey8E/rwOA+/QtnmZDSEgATO wEoJ7TGbpnuND6SoX9VKv5Wb0RKK8jNJU7OVDIqUrBGBeTp4UMyy2DZbOw7Tp6OMXEqx Mh4g== X-Gm-Message-State: AJIora/jSRfaBY4ytVe6oXNq7kFclWpFqApZpgUESV0qwFx67LjPDbK8 MyZkEUpWy1Fevr9O//RvdiPpi/xjPENvHg== X-Google-Smtp-Source: AGRyM1u1CMCV1K4zo/EliOwZX9n0smF+kYBaNmbtWs//+n4miikHEfMb7d/tYjTqAu9+/kJ/vtJH4A== X-Received: by 2002:a05:651c:1615:b0:25e:7df:f7b4 with SMTP id f21-20020a05651c161500b0025e07dff7b4mr1598516ljq.188.1658758059689; Mon, 25 Jul 2022 07:07:39 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:39 -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 14/15 v2] crypto: ux500/hash: Use AMBA core primecell IDs Date: Mon, 25 Jul 2022 16:05:03 +0200 Message-Id: <20220725140504.2398965-15-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 914c35919570..71ed2a573714 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 Mon Jul 25 14:05:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12928097 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 079B8CCA473 for ; Mon, 25 Jul 2022 14:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235376AbiGYOIH (ORCPT ); Mon, 25 Jul 2022 10:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235420AbiGYOIA (ORCPT ); Mon, 25 Jul 2022 10:08:00 -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 4DA2217A89 for ; Mon, 25 Jul 2022 07:07:43 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id y11so18126059lfs.6 for ; Mon, 25 Jul 2022 07:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rzgP+fRPARWak06I6AOjFFbBJ87jnAoawXDDrQ7nXN8=; b=tktI2KG9Y/wcP8pehTIB2urKwCsFFMDPGe5uM3LPTsJDkFE9zix7ZNu6kHxFLL96d6 gJOlJU2+YIJv0+AdhRnxq8KrJlKBXaXTuJgWrlLw5oZOHugXo2QG8fRgKjofwVYWBVEo hIotTZkNhXn/RPSAxY7hZkHqWKnGKqmJk06QzHqKqRD0dNtQL1jOxyGScX0ifBKQj18T dE0BuOO77crNjFaFCa1LsWEx6UfpKxuxtiQaSkRxwrJODhODSZGNHeG0c2kSGI5FJSce tq/jEWZxc7TQYmrZ9sks65u8m+/bZjxLRaKvaA5mTR1DOvTJctuYeOiJiFKAgYy+vAqg wW7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rzgP+fRPARWak06I6AOjFFbBJ87jnAoawXDDrQ7nXN8=; b=qkOHzwApW47WB7xkXbld2pFY9Kv/1HE50pAKTqVq43xWP7FF7aFMdVfKEgKMZIB7Jc sgafeC4gfCxkQJC3ANuAXCk07FsY+DqR8ds5CXL2uw3qRuhD7ha9draV1t+9dwdaCDNk p1c+MGFXzRP2PH9bcuZWzP4yddVnEskf1LRqIco7Sh5EZkjiK0cKp7ziWrha5lmUhyc/ FPDsmDX/SeiFEB0Zk+tj1rmJFqy92Ek1uV/Dk6pnrZPwaoIMJZrnv4gxGg21dAPq4dbd /O0/uHzcBq4pa7yuWRC/VxC2amCD/3f1tKbXlkKrHkfV3bgezV2cUxaVSU/CruRQZqWy dZvg== X-Gm-Message-State: AJIora8V/KTp3MEiJTBjL2+re4csoJl/dBedcxEvGvqHdyTFcCiKdpcf 8I+h5NjMC4jYO+UxPjsbq4tLGwT17J0sTw== X-Google-Smtp-Source: AGRyM1tQQbFddQZ2mAD4qxR5UHI1LCl1fJEM3UPn4AUOXEnt8taIT5fyv7dxh6WFglSOcPfSwI4SjA== X-Received: by 2002:a05:6512:1681:b0:48a:2e71:e202 with SMTP id bu1-20020a056512168100b0048a2e71e202mr4797141lfb.378.1658758061274; Mon, 25 Jul 2022 07:07:41 -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 o7-20020a05651205c700b0047f7419de4asm901127lfo.180.2022.07.25.07.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:07:40 -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 15/15 v2] crypto: ux500/hash: Implement runtime PM Date: Mon, 25 Jul 2022 16:05:04 +0200 Message-Id: <20220725140504.2398965-16-linus.walleij@linaro.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220725140504.2398965-1-linus.walleij@linaro.org> References: <20220725140504.2398965-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 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 71ed2a573714..8a2da25f69ca 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);