From patchwork Wed Jun 12 13:54:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695077 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45F64C27C77 for ; Wed, 12 Jun 2024 13:54:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 3237FC4AF1A; Wed, 12 Jun 2024 13:54:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A1D7C116B1; Wed, 12 Jun 2024 13:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200491; bh=qNQKeKVAjEgxOQBenmNAc0eVUtJC4/u8mbQTNzE9vLQ=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOwelx94P9Adhgg+DYwL/GL0POlSbZv4GyL/fMEQQ+BAIDhBMbc3F4RHJZAus2C9N QFvTvMguua9xmMsf9YOArP0e1ugD+9KdonA1hAFDYDl1GTjutjLZCL1o7hBSyEr+WJ 5K+sV80Ep7NWIu+Hcf4ab1uOrPxANCAhYWuniDzXsdgZkGKikGmwmrYcKK9ZlfLq3t 2doG6xBMuEaAACWPbU9GeE4JPeTqfLXYC2B0hWaDwlrD4F0Pj4VoQscHRv9RLDOFeL pJkGUrilF8a7S54p6IOPW2/A7Nnu3tjqcuoR7FNSqSyR6yFdxgQ36vP+drX8U/dtAF S/fB8XZuC6yAg== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 01/19] firmware: turris-mox-rwtm: Do not complete if there are no waiters Date: Wed, 12 Jun 2024 15:54:25 +0200 Message-ID: <20240612135443.30239-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Do not complete the command done completion if there are no waiters. This can happen if a wait_for_completion timed out or was interrupted. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 31d962cdd6eb..f1f9160c4195 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -2,7 +2,7 @@ /* * Turris Mox rWTM firmware driver * - * Copyright (C) 2019 Marek Behún + * Copyright (C) 2019, 2024 Marek Behún */ #include @@ -174,6 +174,9 @@ static void mox_rwtm_rx_callback(struct mbox_client *cl, void *data) struct mox_rwtm *rwtm = dev_get_drvdata(cl->dev); struct armada_37xx_rwtm_rx_msg *msg = data; + if (completion_done(&rwtm->cmd_done)) + return; + rwtm->reply = *msg; complete(&rwtm->cmd_done); } From patchwork Wed Jun 12 13:54:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695078 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEF0BC27C53 for ; Wed, 12 Jun 2024 13:54:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id A5E72C4AF49; Wed, 12 Jun 2024 13:54:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CC26C116B1; Wed, 12 Jun 2024 13:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200493; bh=UIFCQkzuurEPJQtM9wHNEh8UDAHIpMA2CMVShGlY+gI=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=DCXB8AXINlIVSZV9WINx7371GkkpFIEa6aBaoHVzsFvbyVcl77Tw+46W/7BHA8/w4 qADHBEUdutjQO3p/Y+QRTd/j/aa3ynTL8F0q76v2PHDKveeKtp7Q6tZ4J1zxrA2Az0 ySLSAKONxi41eXTPetRB/j8F7v8CxxScuJPvtClrzZkP0gp1bCpsuftY0WVWWBXkff Hv1gtjyKoPsphUFGMaupR4fSS4VijLFtxGJ2dsL0CJmrSsL1bLVjhqDXShBn48GMcW bTv9KRsZ+P+qDtFyo66zHfXchEHYGhaHVNJ2ZNzB1ySy0GoYwPYzcwx4mmq9b33k/8 OrHE8yLikTDHA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 02/19] firmware: turris-mox-rwtm: Fix checking return value of wait_for_completion_timeout() Date: Wed, 12 Jun 2024 15:54:26 +0200 Message-ID: <20240612135443.30239-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 The wait_for_completion_timeout() function returns 0 if timed out, and a positive value if completed. Fix the usage of this function. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Fixes: 2eab59cf0d20 ("firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng") Signed-off-by: Marek Behún Reviewed-by: Ilpo Järvinen --- drivers/firmware/turris-mox-rwtm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index f1f9160c4195..3f4758e03c81 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -202,9 +202,8 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); if (ret == -ENODATA) { @@ -238,9 +237,8 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); if (ret == -ENODATA) { @@ -277,9 +275,8 @@ static int check_get_random_support(struct mox_rwtm *rwtm) if (ret < 0) return ret; - ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2); - if (ret < 0) - return ret; + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval); } From patchwork Wed Jun 12 13:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695079 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3864EC27C53 for ; Wed, 12 Jun 2024 13:54:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 264EEC4AF48; Wed, 12 Jun 2024 13:54:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C647C116B1; Wed, 12 Jun 2024 13:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200496; bh=ZR/ZhtvNAnjkQJ27zWhiI+4NFBGnWk7aiuC44C9rRjQ=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=q83sJv7pplM0ZJ4BQtadWFO76tM7noly3ajrIMkfTiA8XyDzNDqxIDy1wD9GtRnpw I16uDiHjNLeRi86iNghX0Z8TvNtONo8Hg+MKZnNDPcKoWs+nLx2NS2ECOFxvgPRtZ1 9zTRF7yFnR3sACgMaJYsBi4OBPKAUtE4Vq5eNJ4EUTl6ggpxO1g8TMIg1VRyvWZrLD 6DQWNQkXxtToLu0ncoES/Sf2pGY4mptOGqoL0FhJzE5oHDW7U5KoZVgQ0YcsiSGZQb Cg+rg/6zAqLpfWmDimT3FK0BpZwkqZbM9i+ZkU3MkCsQV2t1XNU6mN1Po/5UzcnMRR WROsnLBV0VoKA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 03/19] firmware: turris-mox-rwtm: Use PAGE_SIZE instead of hardcoded 4096 Date: Wed, 12 Jun 2024 15:54:27 +0200 Message-ID: <20240612135443.30239-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 The 4096 bytes limit in mox_hwrng_read() is due to the DMA buffer being allocated to one PAGE_SIZE bytes. The PAGE_SIZE macro is used when allocating the buffer, use it in mox_hwrng_read() as well. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 3f4758e03c81..5acdde1bb6d9 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -287,8 +287,8 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) struct armada_37xx_rwtm_tx_msg msg; int ret; - if (max > 4096) - max = 4096; + if (max > PAGE_SIZE) + max = PAGE_SIZE; msg.command = MBOX_CMD_GET_RANDOM; msg.args[0] = 1; From patchwork Wed Jun 12 13:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695080 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6DC3C27C7B for ; Wed, 12 Jun 2024 13:54:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 98BA2C4AF1A; Wed, 12 Jun 2024 13:54:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8061AC116B1; Wed, 12 Jun 2024 13:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200498; bh=tgU8PCpcoAUSUZevpHCTHRC2Bimt3v7p8oXarkB55Xc=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=tuNb7KtvIGpoZzVxziBmgZkxBeoWo1ByaOVT2pvhe6kdwz3jvoKmRcAFxzwib15G8 8yNj4gqUqinoudk25WkS4p3/U1cf23ZjChaGVYd1y7hctYS2u3TxDCJMKcpLp70Ntv nmBOOl/jkK6SwQkA4aMO2Iy/GY4OYqkVwTvnbe6zKMuLtH5WThXRtSWoZ3/bgH9i+T sDIPobz3Ws8GYjBzBm7kpT5T5OTUCdmddDvDJZtyM4y1xGF+zACIdpa6xGy58tUvqo dzc5yz4GxE4bgsi6EGRYBbIgUJt0DVD0kqXbxrg61igG1D1gBXBFrkbJF5Pe6L4T9B bSLLRY+L50bIQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 04/19] firmware: turris-mox-rwtm: Use ETH_ALEN instead of hardcoded 6 Date: Wed, 12 Jun 2024 15:54:28 +0200 Message-ID: <20240612135443.30239-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use the ETH_ALEN macro instead of hardcoded 6 for MAC address length. Signed-off-by: Marek Behún Reviewed-by: Ilpo Järvinen --- drivers/firmware/turris-mox-rwtm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5acdde1bb6d9..1b708a0760e6 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ struct mox_rwtm { int has_board_info; u64 serial_number; int board_version, ram_size; - u8 mac_address1[6], mac_address2[6]; + u8 mac_address1[ETH_ALEN], mac_address2[ETH_ALEN]; /* public key burned in eFuse */ int has_pubkey; From patchwork Wed Jun 12 13:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695081 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DA41C27C53 for ; Wed, 12 Jun 2024 13:55:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 178C2C4AF4D; Wed, 12 Jun 2024 13:55:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F31A6C4AF1C; Wed, 12 Jun 2024 13:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200501; bh=UJKLQjeHEA1kG0tFDE2J4AMYNSgru3E+9THu5hnfly8=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=RFBO+XKB3KJveH36q1i5lqL1uCOMgbUced9qaKYGgigyFspEURegSnDZODKsshEcs NuZz+ge9dnDVrOmakC2re6gKwRKqjDpjTu34aiQsG+UyOO6YqequQ2lCK7jIHbEvJr pgrvxvB/2s28RM6pO/Xakh1qy0XzIQCooPnGCebUaCgAhq8qSLDBJY6Doopg+u388t oaSMnomKTiObzTA/nBKVr8xjbmGvtZ2ql3q0QceLI/tX/zQY9PYnjN4DaFTGAT3iWD 1pUUQfwHXhHNc7GpzSuHCHHbfxke3uCCHNUk0QxwkzpLRl9OkepnqxkqnCxzF1L0qf 4aO15shzdeNoA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 05/19] firmware: turris-mox-rwtm: Use the boolean type where appropriate Date: Wed, 12 Jun 2024 15:54:29 +0200 Message-ID: <20240612135443.30239-6-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use the boolean type for has_board_info, has_pubkey and last_sig_done members of the driver's private structure. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 1b708a0760e6..b7212bdc301d 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -17,6 +17,7 @@ #include #include #include +#include #define DRIVER_NAME "turris-mox-rwtm" @@ -63,13 +64,13 @@ struct mox_rwtm { struct completion cmd_done; /* board information */ - int has_board_info; + bool has_board_info; u64 serial_number; int board_version, ram_size; u8 mac_address1[ETH_ALEN], mac_address2[ETH_ALEN]; /* public key burned in eFuse */ - int has_pubkey; + bool has_pubkey; u8 pubkey[135]; #ifdef CONFIG_DEBUG_FS @@ -81,7 +82,7 @@ struct mox_rwtm { */ struct dentry *debugfs_root; u32 last_sig[34]; - int last_sig_done; + bool last_sig_done; #endif }; @@ -225,7 +226,7 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) reply->status[5]); reply_to_mac_addr(rwtm->mac_address2, reply->status[6], reply->status[7]); - rwtm->has_board_info = 1; + rwtm->has_board_info = true; pr_info("Turris Mox serial number %016llX\n", rwtm->serial_number); @@ -252,7 +253,7 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) } else { u32 *s = reply->status; - rwtm->has_pubkey = 1; + rwtm->has_pubkey = true; sprintf(rwtm->pubkey, "%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", ret, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], @@ -349,7 +350,7 @@ static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len, /* 2 arrays of 17 32-bit words are 136 bytes */ ret = simple_read_from_buffer(buf, len, ppos, rwtm->last_sig, 136); - rwtm->last_sig_done = 0; + rwtm->last_sig_done = false; return ret; } @@ -415,7 +416,7 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, */ memcpy(rwtm->last_sig, rwtm->buf + 68, 136); cpu_to_be32_array(rwtm->last_sig, rwtm->last_sig, 34); - rwtm->last_sig_done = 1; + rwtm->last_sig_done = true; mutex_unlock(&rwtm->busy); return len; From patchwork Wed Jun 12 13:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695082 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99915C27C77 for ; Wed, 12 Jun 2024 13:55:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 8D90FC4AF1C; Wed, 12 Jun 2024 13:55:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 756ACC4AF1A; Wed, 12 Jun 2024 13:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200503; bh=OtJMZCrUsbmNab955NgjcKdtWPN6mrFbBfHlEtFgF6c=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ho9DrH0GD7FVpt2NcpogoQzI/Ok5RimLilivij1Tx4ZCApERWjYx8nFvf9XQBQUBt C3dzBHJNQvPVjob/UYL/f0uLWzj9Zkayfp6s8FS/K7DIDU/fOWC3QPRrix2nNDvLZL RTivfyzVEqoXXEiAJcAtpdi2Znr7jcR8Xnli8wRUXuRcVPFBe/ZFtg92p0wNLli4+T nkB0OB9/JzyRFkb6DjmM4gvlFoGaKiqdA689ip5RRdKHUAk2Gk1P0LhvgpM0yDUwSw rt4FPmQpB/lDx/qtzZiXTwGy15pRhU2dTh+8mbc7Cydw1gmtbrc2xN9eA+L6r9+TRm F2qh5eRGRf6LQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 06/19] firmware: turris-mox-rwtm: Hide signature related constants behind macros Date: Wed, 12 Jun 2024 15:54:30 +0200 Message-ID: <20240612135443.30239-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Hide signature generation related constants behind macros instead of hardcoding the values. Use SHA512_DIGEST_SIZE from crypto/sha2.h instead of hardcoded 64 as the message size. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index b7212bdc301d..254629437f59 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -5,6 +5,7 @@ * Copyright (C) 2019, 2024 Marek Behún */ +#include #include #include #include @@ -27,6 +28,12 @@ * https://gitlab.labs.nic.cz/turris/mox-boot-builder/tree/master/wtmi. */ +#define MOX_ECC_NUMBER_WORDS 17 +#define MOX_ECC_NUMBER_LEN (MOX_ECC_NUMBER_WORDS * sizeof(u32)) + +#define MOX_ECC_SIGNATURE_WORDS (2 * MOX_ECC_NUMBER_WORDS) +#define MOX_ECC_SIGNATURE_LEN (MOX_ECC_NUMBER_WORDS * sizeof(u32)) + #define MBOX_STS_SUCCESS (0 << 30) #define MBOX_STS_FAIL (1 << 30) #define MBOX_STS_BADCMD (2 << 30) @@ -81,7 +88,7 @@ struct mox_rwtm { * from userspace. */ struct dentry *debugfs_root; - u32 last_sig[34]; + u32 last_sig[MOX_ECC_SIGNATURE_WORDS]; bool last_sig_done; #endif }; @@ -342,14 +349,15 @@ static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len, if (*ppos != 0) return 0; - if (len < 136) + if (len < MOX_ECC_SIGNATURE_LEN) return -EINVAL; if (!rwtm->last_sig_done) return -ENODATA; /* 2 arrays of 17 32-bit words are 136 bytes */ - ret = simple_read_from_buffer(buf, len, ppos, rwtm->last_sig, 136); + ret = simple_read_from_buffer(buf, len, ppos, rwtm->last_sig, + MOX_ECC_SIGNATURE_LEN); rwtm->last_sig_done = false; return ret; @@ -364,8 +372,7 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, loff_t dummy = 0; ssize_t ret; - /* the input is a SHA-512 hash, so exactly 64 bytes have to be read */ - if (len != 64) + if (len != SHA512_DIGEST_SIZE) return -EINVAL; /* if last result is not zero user has not read that information yet */ @@ -386,17 +393,18 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, * 3. Address of the buffer where ECDSA signature value S shall be * stored by the rWTM firmware. */ - memset(rwtm->buf, 0, 4); - ret = simple_write_to_buffer(rwtm->buf + 4, 64, &dummy, buf, len); + memset(rwtm->buf, 0, sizeof(u32)); + ret = simple_write_to_buffer(rwtm->buf + sizeof(u32), + SHA512_DIGEST_SIZE, &dummy, buf, len); if (ret < 0) goto unlock_mutex; - be32_to_cpu_array(rwtm->buf, rwtm->buf, 17); + be32_to_cpu_array(rwtm->buf, rwtm->buf, MOX_ECC_NUMBER_WORDS); msg.command = MBOX_CMD_SIGN; msg.args[0] = 1; msg.args[1] = rwtm->buf_phys; - msg.args[2] = rwtm->buf_phys + 68; - msg.args[3] = rwtm->buf_phys + 2 * 68; + msg.args[2] = rwtm->buf_phys + MOX_ECC_NUMBER_LEN; + msg.args[3] = rwtm->buf_phys + 2 * MOX_ECC_NUMBER_LEN; ret = mbox_send_message(rwtm->mbox, &msg); if (ret < 0) goto unlock_mutex; @@ -414,8 +422,10 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, * computed by the rWTM firmware and convert their words from * LE to BE. */ - memcpy(rwtm->last_sig, rwtm->buf + 68, 136); - cpu_to_be32_array(rwtm->last_sig, rwtm->last_sig, 34); + memcpy(rwtm->last_sig, rwtm->buf + MOX_ECC_NUMBER_LEN, + MOX_ECC_SIGNATURE_LEN); + cpu_to_be32_array(rwtm->last_sig, rwtm->last_sig, + MOX_ECC_SIGNATURE_WORDS); rwtm->last_sig_done = true; mutex_unlock(&rwtm->busy); From patchwork Wed Jun 12 13:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695083 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1AD78C27C53 for ; Wed, 12 Jun 2024 13:55:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 0DAE1C3277B; Wed, 12 Jun 2024 13:55:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8A65C4AF1A; Wed, 12 Jun 2024 13:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200506; bh=NCKHSWCnLa+FimG1uW1VNJqome5YSP5MoytzzxjTQC8=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=uEkRNjXqe8wXYul/9UeGaQbDF+mqYLsxC84YKNKvuiVoA6tjwujTHZNMAqw+4fHDB xc2g1RuGw0ILgLdzSui7xKpnMN56zbLTBtrUAp0Pc6/9AVGqbSgnSzA1YlR3qHd0MU WKBjnYrQy/mkGZup38v7Z65At+OJsZVuQdBjJqI8qNQFkh/UAJqSy0PbNdvnudxIQo l/FkdC3mWj0YGgnDYwqIS8nHFhxliDjZnZ5+x6G6Id3VOzstsrRP10ji13AAbS7eoy IsIJmBgJKJtXI+1RTtK+rDU25405rg2VsREmXuVVcBh8oIan+9kqF6x8eEh6KKiJYG MJF3mO4dwpWVQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 07/19] firmware: turris-mox-rwtm: Fix driver includes Date: Wed, 12 Jun 2024 15:54:31 +0200 Message-ID: <20240612135443.30239-8-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Drop including of.h, include several other headers that are used but not included directly. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 254629437f59..5675f94a3ff2 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -8,16 +8,21 @@ #include #include #include +#include #include +#include #include +#include +#include #include #include +#include #include #include #include -#include #include #include +#include #include #define DRIVER_NAME "turris-mox-rwtm" From patchwork Wed Jun 12 13:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695084 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95E1CC27C53 for ; Wed, 12 Jun 2024 13:55:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 84F7FC4AF49; Wed, 12 Jun 2024 13:55:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68188C4AF1C; Wed, 12 Jun 2024 13:55:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200508; bh=Bf9tRSAmEXenw45r/F8ave9yg8ECTSVDJu6/QnQTpN4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=bYmwmlXbzak/3S6E18d5kS3LGnhkBjV9M9pCiFE60gkrB16ehU0qHcGkJjD0WCt40 YQ3VyVE1cENPqXX1sXihu5ASU5zbIoimETOIY6RK3ZNNf9Vvg9AML1UXBWSCSmkOs7 O283nqmhKzbswNTYfF0LmCrGxwO5aZEwVyXhYfq/GxZu2cUT9MgXkbU7to4rlQg0vd V8uhMuky4q4TyPVrNzS/F1nCSkWIzKFch4yDcFOF5dHOV9bBKbdP5xeJXIiVcwbnvx 8JwHsyx8VkuFuZQ96Hi+3mXH4zpDqZrBFKaX4aBQnAbzhy6kNi5dJSTuP15GpSOiYg 7pyfNNbi4zFQw== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 08/19] firmware: turris-mox-rwtm: Use kobj_type's default_groups member for automatic sysfs files creation Date: Wed, 12 Jun 2024 15:54:32 +0200 Message-ID: <20240612135443.30239-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Put the turris-mox-rwtm attribute group into the .default_groups member of the underlying kobject type and drop the manual sysfs_create_files() / sysfs_remove_files(). The kobject library will take care of this in it's internal code. Signed-off-by: Marek Behún Reviewed-by: Ilpo Järvinen --- drivers/firmware/turris-mox-rwtm.c | 71 ++++++++++++++---------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5675f94a3ff2..441409fefc59 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -113,6 +113,36 @@ static inline struct mox_rwtm *to_rwtm(struct kobject *kobj) return container_of(kobj, struct mox_kobject, kobj)->rwtm; } +#define MOX_ATTR_RO(name, format, cat) \ +static ssize_t \ +name##_show(struct kobject *kobj, struct kobj_attribute *a, \ + char *buf) \ +{ \ + struct mox_rwtm *rwtm = to_rwtm(kobj); \ + if (!rwtm->has_##cat) \ + return -ENODATA; \ + return sprintf(buf, format, rwtm->name); \ +} \ +static struct kobj_attribute mox_attr_##name = __ATTR_RO(name) + +MOX_ATTR_RO(serial_number, "%016llX\n", board_info); +MOX_ATTR_RO(board_version, "%i\n", board_info); +MOX_ATTR_RO(ram_size, "%i\n", board_info); +MOX_ATTR_RO(mac_address1, "%pM\n", board_info); +MOX_ATTR_RO(mac_address2, "%pM\n", board_info); +MOX_ATTR_RO(pubkey, "%s\n", pubkey); + +static struct attribute *mox_rwtm_attrs[] = { + &mox_attr_serial_number.attr, + &mox_attr_board_version.attr, + &mox_attr_ram_size.attr, + &mox_attr_mac_address1.attr, + &mox_attr_mac_address2.attr, + &mox_attr_pubkey.attr, + NULL +}; +ATTRIBUTE_GROUPS(mox_rwtm); + static void mox_kobj_release(struct kobject *kobj) { kfree(to_rwtm(kobj)->kobj); @@ -121,6 +151,7 @@ static void mox_kobj_release(struct kobject *kobj) static const struct kobj_type mox_kobj_ktype = { .release = mox_kobj_release, .sysfs_ops = &kobj_sysfs_ops, + .default_groups = mox_rwtm_groups, }; static int mox_kobj_create(struct mox_rwtm *rwtm) @@ -140,25 +171,6 @@ static int mox_kobj_create(struct mox_rwtm *rwtm) return 0; } -#define MOX_ATTR_RO(name, format, cat) \ -static ssize_t \ -name##_show(struct kobject *kobj, struct kobj_attribute *a, \ - char *buf) \ -{ \ - struct mox_rwtm *rwtm = to_rwtm(kobj); \ - if (!rwtm->has_##cat) \ - return -ENODATA; \ - return sprintf(buf, format, rwtm->name); \ -} \ -static struct kobj_attribute mox_attr_##name = __ATTR_RO(name) - -MOX_ATTR_RO(serial_number, "%016llX\n", board_info); -MOX_ATTR_RO(board_version, "%i\n", board_info); -MOX_ATTR_RO(ram_size, "%i\n", board_info); -MOX_ATTR_RO(mac_address1, "%pM\n", board_info); -MOX_ATTR_RO(mac_address2, "%pM\n", board_info); -MOX_ATTR_RO(pubkey, "%s\n", pubkey); - static int mox_get_status(enum mbox_cmd cmd, u32 retval) { if (MBOX_STS_CMD(retval) != cmd) @@ -173,16 +185,6 @@ static int mox_get_status(enum mbox_cmd cmd, u32 retval) return MBOX_STS_VALUE(retval); } -static const struct attribute *mox_rwtm_attrs[] = { - &mox_attr_serial_number.attr, - &mox_attr_board_version.attr, - &mox_attr_ram_size.attr, - &mox_attr_mac_address1.attr, - &mox_attr_mac_address2.attr, - &mox_attr_pubkey.attr, - NULL -}; - static void mox_rwtm_rx_callback(struct mbox_client *cl, void *data) { struct mox_rwtm *rwtm = dev_get_drvdata(cl->dev); @@ -507,12 +509,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) return ret; } - ret = sysfs_create_files(rwtm_to_kobj(rwtm), mox_rwtm_attrs); - if (ret < 0) { - dev_err(dev, "Cannot create sysfs files!\n"); - goto put_kobj; - } - platform_set_drvdata(pdev, rwtm); mutex_init(&rwtm->busy); @@ -526,7 +522,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (ret != -EPROBE_DEFER) dev_err(dev, "Cannot request mailbox channel: %i\n", ret); - goto remove_files; + goto put_kobj; } init_completion(&rwtm->cmd_done); @@ -564,8 +560,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) free_channel: mbox_free_channel(rwtm->mbox); -remove_files: - sysfs_remove_files(rwtm_to_kobj(rwtm), mox_rwtm_attrs); put_kobj: kobject_put(rwtm_to_kobj(rwtm)); return ret; @@ -576,7 +570,6 @@ static void turris_mox_rwtm_remove(struct platform_device *pdev) struct mox_rwtm *rwtm = platform_get_drvdata(pdev); rwtm_unregister_debugfs(rwtm); - sysfs_remove_files(rwtm_to_kobj(rwtm), mox_rwtm_attrs); kobject_put(rwtm_to_kobj(rwtm)); mbox_free_channel(rwtm->mbox); } From patchwork Wed Jun 12 13:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695085 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16D21C27C7B for ; Wed, 12 Jun 2024 13:55:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 03703C116B1; Wed, 12 Jun 2024 13:55:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE273C4AF4D; Wed, 12 Jun 2024 13:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200510; bh=qdLkloo1//kkYo58+g2Kq+JROyy0900hRCsR5nrF8kg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=NchAFQecUqPIT7ueHC21YGAf5yMAF3vlX1q85s/8MmKOQH35keQlMVsp8KG2WojVd y7ueG3tFxZ13sMC6s5krEeYQ0oAnLj7ZJF05+kyuCNSx8ga/a9nOt+wyqozlE6bpUI +aJwrEU8VdSwHVt5hCtYlXoqx3jMdVz9aGh/OQwM3mqxy10WiMc7cfLcOMNkeOjEh+ TXTkjNuMW9M29pXj4cBvh+8hfTj9UgAJMBgWGGIQuUJ71JtI1hjwWI21BgCQrw59i7 F/U97efm3EB44T2+IwaBM+f80BwNNOlJZOyPUE3o4Il0+PjTo5x5Rgpw3hmHMhZ0Rk XBZEnXiS0OnlA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 09/19] firmware: turris-mox-rwtm: Simplify debugfs code Date: Wed, 12 Jun 2024 15:54:33 +0200 Message-ID: <20240612135443.30239-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Simplify debugfs code: do not check for errors, as debugfs errors should be ignored, and use devm action for dropping the debugfs directory. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 44 ++++++++---------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 441409fefc59..6d1e0b1dd2b4 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -92,7 +92,6 @@ struct mox_rwtm { * It should be rewritten via crypto API once akcipher API is available * from userspace. */ - struct dentry *debugfs_root; u32 last_sig[MOX_ECC_SIGNATURE_WORDS]; bool last_sig_done; #endif @@ -450,39 +449,23 @@ static const struct file_operations do_sign_fops = { .llseek = no_llseek, }; -static int rwtm_register_debugfs(struct mox_rwtm *rwtm) +static void rwtm_debugfs_release(void *root) { - struct dentry *root, *entry; - - root = debugfs_create_dir("turris-mox-rwtm", NULL); - - if (IS_ERR(root)) - return PTR_ERR(root); - - entry = debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, - &do_sign_fops); - if (IS_ERR(entry)) - goto err_remove; - - rwtm->debugfs_root = root; - - return 0; -err_remove: debugfs_remove_recursive(root); - return PTR_ERR(entry); } -static void rwtm_unregister_debugfs(struct mox_rwtm *rwtm) +static void rwtm_register_debugfs(struct mox_rwtm *rwtm) { - debugfs_remove_recursive(rwtm->debugfs_root); + struct dentry *root; + + root = debugfs_create_dir("turris-mox-rwtm", NULL); + + devm_add_action_or_reset(rwtm->dev, rwtm_debugfs_release, root); + + debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, &do_sign_fops); } #else -static inline int rwtm_register_debugfs(struct mox_rwtm *rwtm) -{ - return 0; -} - -static inline void rwtm_unregister_debugfs(struct mox_rwtm *rwtm) +static inline void rwtm_register_debugfs(struct mox_rwtm *rwtm) { } #endif @@ -548,11 +531,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) goto free_channel; } - ret = rwtm_register_debugfs(rwtm); - if (ret < 0) { - dev_err(dev, "Failed creating debugfs entries: %i\n", ret); - goto free_channel; - } + rwtm_register_debugfs(rwtm); dev_info(dev, "HWRNG successfully registered\n"); @@ -569,7 +548,6 @@ static void turris_mox_rwtm_remove(struct platform_device *pdev) { struct mox_rwtm *rwtm = platform_get_drvdata(pdev); - rwtm_unregister_debugfs(rwtm); kobject_put(rwtm_to_kobj(rwtm)); mbox_free_channel(rwtm->mbox); } From patchwork Wed Jun 12 13:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695086 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 831E1C27C53 for ; Wed, 12 Jun 2024 13:55:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 753D6C3277B; Wed, 12 Jun 2024 13:55:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CD08C116B1; Wed, 12 Jun 2024 13:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200513; bh=oH4c2b46Uxiua0aZV3BzNe9qtvV1Wp1s4VPDuk/wB9k=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2ADrSpz0J8PW2E6s4bj9kNNlTLFPWJ+jLznRN9/mlIJkMJPsqA1HwK7jdXuPmVaY dUGS2WTnFG9ybwvjVfuW4WkW7ErUW0vQjnrZMYZ84GwAs81x6RovG4GZ1ViyGEHYue QTfbZeNMU6w0XhXMom6zmQ8+U/2W7p/5GywG9rggZV3UOJ7oj604Z+HoZni/1Tl6Ez t5hmpp8mDe73e83RNMEKba8hFUW+YwQ5pVYRehzIoobx5ZmBLi/QEhwp4GheoJ/89l VlHC1CCJZm26ryIMpphAyz13fjf4EgFbwdbWd3XWCy4OUjgTuAgb1Y7hxcwBA1wZKI 7N4+hIRQ9dCHQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 10/19] firmware: turris-mox-rwtm: Simplify driver kobject code Date: Wed, 12 Jun 2024 15:54:34 +0200 Message-ID: <20240612135443.30239-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Drop the mox_kobject wrapper that needs to be allocated, instead put the kobject directly into the driver private structure. This allows us to drop one kzalloc() call. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 36 ++++++++---------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 6d1e0b1dd2b4..84ec72575c4d 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -58,13 +57,11 @@ enum mbox_cmd { MBOX_CMD_OTP_WRITE = 8, }; -struct mox_kobject; - struct mox_rwtm { struct device *dev; struct mbox_client mbox_client; struct mbox_chan *mbox; - struct mox_kobject *kobj; + struct kobject kobj; struct hwrng hwrng; struct armada_37xx_rwtm_rx_msg reply; @@ -97,19 +94,9 @@ struct mox_rwtm { #endif }; -struct mox_kobject { - struct kobject kobj; - struct mox_rwtm *rwtm; -}; - -static inline struct kobject *rwtm_to_kobj(struct mox_rwtm *rwtm) -{ - return &rwtm->kobj->kobj; -} - static inline struct mox_rwtm *to_rwtm(struct kobject *kobj) { - return container_of(kobj, struct mox_kobject, kobj)->rwtm; + return container_of(kobj, struct mox_rwtm, kobj); } #define MOX_ATTR_RO(name, format, cat) \ @@ -142,9 +129,8 @@ static struct attribute *mox_rwtm_attrs[] = { }; ATTRIBUTE_GROUPS(mox_rwtm); -static void mox_kobj_release(struct kobject *kobj) +static void mox_kobj_release(struct kobject *) { - kfree(to_rwtm(kobj)->kobj); } static const struct kobj_type mox_kobj_ktype = { @@ -155,18 +141,14 @@ static const struct kobj_type mox_kobj_ktype = { static int mox_kobj_create(struct mox_rwtm *rwtm) { - rwtm->kobj = kzalloc(sizeof(*rwtm->kobj), GFP_KERNEL); - if (!rwtm->kobj) - return -ENOMEM; + struct kobject *kobj = &rwtm->kobj; - kobject_init(rwtm_to_kobj(rwtm), &mox_kobj_ktype); - if (kobject_add(rwtm_to_kobj(rwtm), firmware_kobj, "turris-mox-rwtm")) { - kobject_put(rwtm_to_kobj(rwtm)); + kobject_init(kobj, &mox_kobj_ktype); + if (kobject_add(kobj, firmware_kobj, "turris-mox-rwtm")) { + kobject_put(kobj); return -ENXIO; } - rwtm->kobj->rwtm = rwtm; - return 0; } @@ -540,7 +522,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) free_channel: mbox_free_channel(rwtm->mbox); put_kobj: - kobject_put(rwtm_to_kobj(rwtm)); + kobject_put(&rwtm->kobj); return ret; } @@ -548,7 +530,7 @@ static void turris_mox_rwtm_remove(struct platform_device *pdev) { struct mox_rwtm *rwtm = platform_get_drvdata(pdev); - kobject_put(rwtm_to_kobj(rwtm)); + kobject_put(&rwtm->kobj); mbox_free_channel(rwtm->mbox); } From patchwork Wed Jun 12 13:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695087 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0522AC27C77 for ; Wed, 12 Jun 2024 13:55:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id E7E2EC3277B; Wed, 12 Jun 2024 13:55:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF8EDC4AF48; Wed, 12 Jun 2024 13:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200515; bh=OwbRGiEKG+M4Cmtg2E/rPrs8D2l6T0J6onStDDJ8v1U=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=dPx+OM4Er8oTy9rT+lkBza/nnXSY2PWBGTusDXEHtSIJi8vykdr9Bsxi81nQCaPdG jrSIpGN+adlsHqEor08Z0EcZ6b/CjYCCmd82cF/lBdvWDM1rsbYNvJXjc2S8en+7qz YYjMKPKbTw65qIdWq/LYBTGEpJxzXmiIudekLJd7ZM7QmwQV7HHB3ZuXhx9IeIGcIT pWOsiYz95thgk+rnAvyJXvGh4Q68cpo+kPbEcqV/tK7X5KMCTnxAyudQskYZAyAld7 nmI8CS9dAEsQ4q2SjyxdTPeJ7vlOEdItWEOa2F5T5PNyOPUWzewYv4p8STBGVzdB/U wTWINjGv2gvWA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 11/19] firmware: turris-mox-rwtm: Return true error code if kobject_add() fails Date: Wed, 12 Jun 2024 15:54:35 +0200 Message-ID: <20240612135443.30239-12-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Return the error code from kobject_add() if it fails, instead of -ENXIO. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 84ec72575c4d..cdbe244be694 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -142,14 +142,15 @@ static const struct kobj_type mox_kobj_ktype = { static int mox_kobj_create(struct mox_rwtm *rwtm) { struct kobject *kobj = &rwtm->kobj; + int ret; kobject_init(kobj, &mox_kobj_ktype); - if (kobject_add(kobj, firmware_kobj, "turris-mox-rwtm")) { + + ret = kobject_add(kobj, firmware_kobj, "turris-mox-rwtm"); + if (ret) kobject_put(kobj); - return -ENXIO; - } - return 0; + return ret; } static int mox_get_status(enum mbox_cmd cmd, u32 retval) From patchwork Wed Jun 12 13:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695088 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74673C27C53 for ; Wed, 12 Jun 2024 13:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 668FFC3277B; Wed, 12 Jun 2024 13:55:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E26DC4AF1A; Wed, 12 Jun 2024 13:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200518; bh=7x42hmfj08LWLsSjf15DKkCEuTD32sDaWvE5MzcKO2g=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3NhcknAknT8iFqmY+XAh8HPR1m1SA85Qb77aY0cwQCUCJ1LnZGMh4mqypLHr3lzC 3H61gcKhEyx8jBbIho+fRxd7dyNlWyHKv8pYGwB71T2kz1b3LSLPzV6GwY0k7+hRv4 ftD5Erb2s9mDf802BLQlLeTtmUbIxqMBxllwzf3scOWkrNs/wD0G7azcKsM65La7L+ zdHUVa68K+3wQiSDyhYf/lJ318fGFJPeEJ8h9t7qcsCWRlzDzk0fV65FiA61VVGgC1 CiX4/ixBAUEwlwqWBwqU7iQ4mOVlFGC7prdwHyzKr0sITOS37hF5mfuhPMU/Qbr8kG dmYZKOWOeTNfQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 12/19] firmware: turris-mox-rwtm: Convert rest to devm_* and get rid of driver .remove() Date: Wed, 12 Jun 2024 15:54:36 +0200 Message-ID: <20240612135443.30239-13-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use devm resource management for driver's kobject and mailbox. This allows us to get rid of driver's .remove() method and gotos in .probe(). Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 41 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index cdbe244be694..153772721901 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -139,6 +139,11 @@ static const struct kobj_type mox_kobj_ktype = { .default_groups = mox_rwtm_groups, }; +static void mox_devm_kobj_release(void *kobj) +{ + kobject_put(kobj); +} + static int mox_kobj_create(struct mox_rwtm *rwtm) { struct kobject *kobj = &rwtm->kobj; @@ -146,11 +151,11 @@ static int mox_kobj_create(struct mox_rwtm *rwtm) kobject_init(kobj, &mox_kobj_ktype); - ret = kobject_add(kobj, firmware_kobj, "turris-mox-rwtm"); + ret = devm_add_action_or_reset(rwtm->dev, mox_devm_kobj_release, kobj); if (ret) - kobject_put(kobj); + return ret; - return ret; + return kobject_add(kobj, firmware_kobj, "turris-mox-rwtm"); } static int mox_get_status(enum mbox_cmd cmd, u32 retval) @@ -453,6 +458,11 @@ static inline void rwtm_register_debugfs(struct mox_rwtm *rwtm) } #endif +static void rwtm_devm_mbox_release(void *mbox) +{ + mbox_free_channel(mbox); +} + static int turris_mox_rwtm_probe(struct platform_device *pdev) { struct mox_rwtm *rwtm; @@ -488,9 +498,13 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (ret != -EPROBE_DEFER) dev_err(dev, "Cannot request mailbox channel: %i\n", ret); - goto put_kobj; + return ret; } + ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox); + if (ret < 0) + return ret; + init_completion(&rwtm->cmd_done); ret = mox_get_board_info(rwtm); @@ -501,7 +515,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (ret < 0) { dev_notice(dev, "Firmware does not support the GET_RANDOM command\n"); - goto free_channel; + return ret; } rwtm->hwrng.name = DRIVER_NAME "_hwrng"; @@ -511,7 +525,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) ret = devm_hwrng_register(dev, &rwtm->hwrng); if (ret < 0) { dev_err(dev, "Cannot register HWRNG: %i\n", ret); - goto free_channel; + return ret; } rwtm_register_debugfs(rwtm); @@ -519,20 +533,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) dev_info(dev, "HWRNG successfully registered\n"); return 0; - -free_channel: - mbox_free_channel(rwtm->mbox); -put_kobj: - kobject_put(&rwtm->kobj); - return ret; -} - -static void turris_mox_rwtm_remove(struct platform_device *pdev) -{ - struct mox_rwtm *rwtm = platform_get_drvdata(pdev); - - kobject_put(&rwtm->kobj); - mbox_free_channel(rwtm->mbox); } static const struct of_device_id turris_mox_rwtm_match[] = { @@ -545,7 +545,6 @@ MODULE_DEVICE_TABLE(of, turris_mox_rwtm_match); static struct platform_driver turris_mox_rwtm_driver = { .probe = turris_mox_rwtm_probe, - .remove_new = turris_mox_rwtm_remove, .driver = { .name = DRIVER_NAME, .of_match_table = turris_mox_rwtm_match, From patchwork Wed Jun 12 13:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695089 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E79D4C27C77 for ; Wed, 12 Jun 2024 13:55:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id D90B0C3277B; Wed, 12 Jun 2024 13:55:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C11ABC4AF1C; Wed, 12 Jun 2024 13:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200520; bh=NB3+7yKH7jftdDy0/3uzHo2M1+UbHlrMh0HTTbTUVu8=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWlPeV5OPeq1N8OSJPtEhTWIrzG5plQO72Tf7OIMYx/bnUCOVhHcgQqkWJdXWT48g mFsNx6Pd/OYxcZ1cpS9BlVae/dujlzEr7ZEC+Jsj3174OCfeb6RBRYnF4NiRDgLGlu uKfsS+KJHKk+8fH6YUd03/4k2wGULD0ocgI3GXC+1xBxwOvzIWjRFhwnfYodXX6W1/ a7Xt3NPuU1zlB4JpdA/ZDDg0BElQaWq28Ofj4zb7lpDEOuSzs8OymISpT1ZE5fGy0Q /6rY0+mOcA5lV3ZwSVK6B39N0UdGC92dAxbZ1quTPdOv5oWZ5/NgEo18dXY/D9E36b cbi8IcDMosfjw== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 13/19] firmware: turris-mox-rwtm: Use dev_err_probe() where possible Date: Wed, 12 Jun 2024 15:54:37 +0200 Message-ID: <20240612135443.30239-14-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use dev_err_probe() where possible in the driver's .probe() method. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 153772721901..3c3f8ae23809 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -480,10 +480,9 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) return -ENOMEM; ret = mox_kobj_create(rwtm); - if (ret < 0) { - dev_err(dev, "Cannot create turris-mox-rwtm kobject!\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, + "Cannot create turris-mox-rwtm kobject!\n"); platform_set_drvdata(pdev, rwtm); @@ -495,10 +494,11 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) rwtm->mbox = mbox_request_channel(&rwtm->mbox_client, 0); if (IS_ERR(rwtm->mbox)) { ret = PTR_ERR(rwtm->mbox); - if (ret != -EPROBE_DEFER) - dev_err(dev, "Cannot request mailbox channel: %i\n", - ret); - return ret; + if (ret == -EPROBE_DEFER) + return ret; + + return dev_err_probe(dev, ret, + "Cannot request mailbox channel!\n"); } ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox); @@ -523,10 +523,8 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) rwtm->hwrng.priv = (unsigned long) rwtm; ret = devm_hwrng_register(dev, &rwtm->hwrng); - if (ret < 0) { - dev_err(dev, "Cannot register HWRNG: %i\n", ret); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "Cannot register HWRNG!\n"); rwtm_register_debugfs(rwtm); From patchwork Wed Jun 12 13:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695090 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92810C27C53 for ; Wed, 12 Jun 2024 13:55:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 60D5FC3277B; Wed, 12 Jun 2024 13:55:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F753C4AF1C; Wed, 12 Jun 2024 13:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200523; bh=1gQhXqOVGRWAUH0rPrpfISbwSYU7INaumxyrJJcurYg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=OfXr56dgn3TLJmFbt1/zWaKsl40Qbje2FrdQ6O1aQsJOffdB+907ASF60vvwMPrHD ky1DXh53Tno/Ui41v5ozWoms4fODIDWzFXPImHrD1zULPH5k3zL2YI7p4c4krzGwAE l5PVfoIqyQRXJllkR0ek2FltKWM83NEdgc00wyj7FmQNEYZlJbbSZayV1vsy0zS53r R1Ik6X+NsFe3KzrvIuf/jh2AJN+fc/oTYoitr/lur1mYH7jagytWABFfNkoCjucSPc WGlOIkuREvc5B6LOryfALBbIomDtCY9DgXsCNNmUzFYddnTKccJHwCQ5h9TyP0L49G U/xqxc4ADb7LQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 14/19] firmware: turris-mox-rwtm: Rearrange probe calls Date: Wed, 12 Jun 2024 15:54:38 +0200 Message-ID: <20240612135443.30239-15-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Rearrange probe calls: - create the kobject (and corresponding sysfs files) only after the mailbox is created and board info is read - initialize the completion before mailbox channel is requested Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 3c3f8ae23809..b9be3c806695 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -479,14 +479,10 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (!rwtm->buf) return -ENOMEM; - ret = mox_kobj_create(rwtm); - if (ret < 0) - return dev_err_probe(dev, ret, - "Cannot create turris-mox-rwtm kobject!\n"); - platform_set_drvdata(pdev, rwtm); mutex_init(&rwtm->busy); + init_completion(&rwtm->cmd_done); rwtm->mbox_client.dev = dev; rwtm->mbox_client.rx_callback = mox_rwtm_rx_callback; @@ -505,12 +501,15 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (ret < 0) return ret; - init_completion(&rwtm->cmd_done); - ret = mox_get_board_info(rwtm); if (ret < 0) dev_warn(dev, "Cannot read board information: %i\n", ret); + ret = mox_kobj_create(rwtm); + if (ret < 0) + return dev_err_probe(dev, ret, + "Cannot create turris-mox-rwtm kobject!\n"); + ret = check_get_random_support(rwtm); if (ret < 0) { dev_notice(dev, From patchwork Wed Jun 12 13:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695091 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E36BCC27C7B for ; Wed, 12 Jun 2024 13:55:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id D3A8BC3277B; Wed, 12 Jun 2024 13:55:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA924C116B1; Wed, 12 Jun 2024 13:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200525; bh=KBKGcGMHOE+vukZuKgYKLszyxK53WRdJFswjU3Adm0o=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=hnTp6RRs9DjaQ0qvJbI+YzIDiPW0kxIOVaO7qLKWTeJi1thO0ajd1CWZqsN97f1NA CgN7ZbU60obG1WgavrTousPBKQYYoSujEafw/WvBFc3FojOHzRlN3ABqK5pAM1JE7c e4VD3nEmbccvryp6tNH8h5JCY7ICc5oqQq+/M3G+MnGxqeYxBcDttC3S9MlKnNYjLn LdASDqjr/tCCA08HKpIn2MNMXFHsSzRvQCyoVEVHLzgh5yrmjvfIyPduwmrN/cxk/b j4hmV8P0Qt30Bq+F2iKyUgW7nfcJ6942P5aACsaZqrj1gmEkpfQOqeLTdE0HUR5X6c 2InEHbedLX4Ag== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 15/19] firmware: turris-mox-rwtm: Drop redundant device pointer Date: Wed, 12 Jun 2024 15:54:39 +0200 Message-ID: <20240612135443.30239-16-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Drop redundant device pointer from driver's private structure. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index b9be3c806695..5f4dd919ce2e 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -58,7 +58,6 @@ enum mbox_cmd { }; struct mox_rwtm { - struct device *dev; struct mbox_client mbox_client; struct mbox_chan *mbox; struct kobject kobj; @@ -94,6 +93,11 @@ struct mox_rwtm { #endif }; +static inline struct device *rwtm_dev(struct mox_rwtm *rwtm) +{ + return rwtm->mbox_client.dev; +} + static inline struct mox_rwtm *to_rwtm(struct kobject *kobj) { return container_of(kobj, struct mox_rwtm, kobj); @@ -151,7 +155,8 @@ static int mox_kobj_create(struct mox_rwtm *rwtm) kobject_init(kobj, &mox_kobj_ktype); - ret = devm_add_action_or_reset(rwtm->dev, mox_devm_kobj_release, kobj); + ret = devm_add_action_or_reset(rwtm_dev(rwtm), mox_devm_kobj_release, + kobj); if (ret) return ret; @@ -196,6 +201,7 @@ static void reply_to_mac_addr(u8 *mac, u32 t1, u32 t2) static int mox_get_board_info(struct mox_rwtm *rwtm) { + struct device *dev = rwtm_dev(rwtm); struct armada_37xx_rwtm_tx_msg msg; struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply; int ret; @@ -210,10 +216,10 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); if (ret == -ENODATA) { - dev_warn(rwtm->dev, + dev_warn(dev, "Board does not have manufacturing information burned!\n"); } else if (ret == -ENOSYS) { - dev_notice(rwtm->dev, + dev_notice(dev, "Firmware does not support the BOARD_INFO command\n"); } else if (ret < 0) { return ret; @@ -245,9 +251,9 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); if (ret == -ENODATA) { - dev_warn(rwtm->dev, "Board has no public key burned!\n"); + dev_warn(dev, "Board has no public key burned!\n"); } else if (ret == -ENOSYS) { - dev_notice(rwtm->dev, + dev_notice(dev, "Firmware does not support the ECDSA_PUB_KEY command\n"); } else if (ret < 0) { return ret; @@ -448,7 +454,7 @@ static void rwtm_register_debugfs(struct mox_rwtm *rwtm) root = debugfs_create_dir("turris-mox-rwtm", NULL); - devm_add_action_or_reset(rwtm->dev, rwtm_debugfs_release, root); + devm_add_action_or_reset(rwtm_dev(rwtm), rwtm_debugfs_release, root); debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, &do_sign_fops); } @@ -473,7 +479,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (!rwtm) return -ENOMEM; - rwtm->dev = dev; rwtm->buf = dmam_alloc_coherent(dev, PAGE_SIZE, &rwtm->buf_phys, GFP_KERNEL); if (!rwtm->buf) From patchwork Wed Jun 12 13:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695092 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 690F1C27C53 for ; Wed, 12 Jun 2024 13:55:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 5CF7FC116B1; Wed, 12 Jun 2024 13:55:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39F5BC3277B; Wed, 12 Jun 2024 13:55:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200528; bh=wbxgZ6XcWbRj7bTCWwbRQkszGJRhY+DPR1wPfvpHI+c=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=iNK9D4vY6HoLt4R0h9NuqRTTf74Rya7WjO54A7wJz7oVEVWP+fsLP9c+1qSBFyZxF c3S/dzFlM4B32Rxg5Loe/nt2xT6k9z1kULfglh4g8EYtY/l/tUw6+rfe3lNGRn6NJy +WeevrE7SWlQBAgpqPrghPxn2gSQ030zU4SOMZ+7wXkg3XzI/ouylaUd6zHDGBqYrr Nv6baxvcnzjMn+GLe4Hr10wWh5MdBzEFcL04mIVli2lkW1/w2rYUzgn2YZ4+A4RUg7 uWv4Ktouo555F4RQDzx8ZDsoftF3c23EjpXQtFZYkKamVikzfeu0ysahuWqxid2J56 uiFAbkuhc736Q== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 16/19] firmware: turris-mox-rwtm: Use devm_mutex_init() instead of mutex_init() Date: Wed, 12 Jun 2024 15:54:40 +0200 Message-ID: <20240612135443.30239-17-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use devm_mutex_init() instead of mutex_init(), to properly call mutex_destroy() on probe failure / driver unbind. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5f4dd919ce2e..f753e98f1ca7 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -486,7 +486,10 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rwtm); - mutex_init(&rwtm->busy); + ret = devm_mutex_init(dev, &rwtm->busy); + if (ret < 0) + return ret; + init_completion(&rwtm->cmd_done); rwtm->mbox_client.dev = dev; From patchwork Wed Jun 12 13:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695093 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9EFEC27C77 for ; Wed, 12 Jun 2024 13:55:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id CFCDDC4AF1A; Wed, 12 Jun 2024 13:55:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B71F9C116B1; Wed, 12 Jun 2024 13:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200530; bh=McfKg9k2MTP61RXrnOKchL8mdl0535mBGq+KGqtDx0U=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZhD32MtFGfLMo4NkUo1TWkijmaVNKyWehflqi0KYPmvDuxGNBm86fLUYgCcQXO0C 7Fpv1RqitZkOvG/zG51uZ5TH2lVtG31XjPOaRU63k+mRAqBwaS5Yw2/kmVxKeDt0zP Mk8FaR4BgXAGe9AYhFd0npalRXBHM9K2bpmwy7Geg5q08X+eGTiqUFXhP7uay4xgNH fFIdsK3fsgORKXT+Ga93jH/ZCfnFCB51uurJPYz+XafKrJtksRfvpoTJX3Nyi8DL81 eQjVt6+v/9RLyTVxi8oSBzEJauSdYTi5lfH2Y2XoT2Pi1YrRSzAFKaPHe8QpYsuSQT IfhxRZF5vt+DA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 17/19] firmware: turris-mox-rwtm: Use container_of() instead of hwrng .priv member Date: Wed, 12 Jun 2024 15:54:41 +0200 Message-ID: <20240612135443.30239-18-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Use container_of() to get driver private structure from hwnrg structure, instead of the hwrng's .priv member, as suggested by Herbert for another driver [1]. [1] https://lore.kernel.org/soc/ZmLhQBdmg613KdET@gondor.apana.org.au/ Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index f753e98f1ca7..5991434f62a3 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -292,7 +292,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm) static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) { - struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv; + struct mox_rwtm *rwtm = container_of(rng, struct mox_rwtm, hwrng); struct armada_37xx_rwtm_tx_msg msg; int ret; @@ -527,7 +527,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) rwtm->hwrng.name = DRIVER_NAME "_hwrng"; rwtm->hwrng.read = mox_hwrng_read; - rwtm->hwrng.priv = (unsigned long) rwtm; ret = devm_hwrng_register(dev, &rwtm->hwrng); if (ret < 0) From patchwork Wed Jun 12 13:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695094 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DD3FC27C7B for ; Wed, 12 Jun 2024 13:55:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 50323C4AF4D; Wed, 12 Jun 2024 13:55:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36D4CC3277B; Wed, 12 Jun 2024 13:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200533; bh=4nS0fhKoOolUMLDymijnF9ypMR5ROqOiUkUY6emIvT4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=PXjLdBF6rtRMkJg0qHgEbjj9KkLsoJEwEGH0kj4JlDSu4FuYee+DX+l/QSRJWclXu 2OSFUsQY9aC8PfWH2Wh++KG8pJIxvOBsfk/JPkEWCNMdN33TWIxAMuAFtZL8Alnyjx l6/4yN/mYpcYxKIh7SB3uXEAMLoDWmreggeCr4dM+jk8Qw7SrhZP3pk5za6KwMiI/O orpI5uBvd8YoPWmLRMX5xNTz+lWtnPMU+af3rMvITuS5Z6q7XxA/T9z/OjnMJsw42v zMQ+oUvA3Wjc2X+JCA9/F66NRo1n5NWy9ecSX/E2V6fNdjCCgdaIfNd0+1MTqVRzL5 xpOmOAMeupeLg== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 18/19] firmware: turris-mox-rwtm: Deduplicate command execution code Date: Wed, 12 Jun 2024 15:54:42 +0200 Message-ID: <20240612135443.30239-19-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Deduplicate rWTM command execution calls mbox_send_message() wait_for_completion() mox_get_status() to one function mox_rwtm_exec() Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 98 ++++++++++++------------------ 1 file changed, 39 insertions(+), 59 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5991434f62a3..ea5ff1827d08 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -189,6 +189,34 @@ static void mox_rwtm_rx_callback(struct mbox_client *cl, void *data) complete(&rwtm->cmd_done); } +static int mox_rwtm_exec(struct mox_rwtm *rwtm, enum mbox_cmd cmd, + struct armada_37xx_rwtm_tx_msg *msg, + bool interruptible) +{ + struct armada_37xx_rwtm_tx_msg _msg = {}; + int ret; + + if (!msg) + msg = &_msg; + + msg->command = cmd; + + ret = mbox_send_message(rwtm->mbox, msg); + if (ret < 0) + return ret; + + if (interruptible) { + ret = wait_for_completion_interruptible(&rwtm->cmd_done); + if (ret < 0) + return ret; + } else { + if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) + return -ETIMEDOUT; + } + + return mox_get_status(cmd, rwtm->reply.retval); +} + static void reply_to_mac_addr(u8 *mac, u32 t1, u32 t2) { mac[0] = t1 >> 8; @@ -202,19 +230,10 @@ static void reply_to_mac_addr(u8 *mac, u32 t1, u32 t2) static int mox_get_board_info(struct mox_rwtm *rwtm) { struct device *dev = rwtm_dev(rwtm); - struct armada_37xx_rwtm_tx_msg msg; struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply; int ret; - msg.command = MBOX_CMD_BOARD_INFO; - ret = mbox_send_message(rwtm->mbox, &msg); - if (ret < 0) - return ret; - - if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) - return -ETIMEDOUT; - - ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); + ret = mox_rwtm_exec(rwtm, MBOX_CMD_BOARD_INFO, NULL, false); if (ret == -ENODATA) { dev_warn(dev, "Board does not have manufacturing information burned!\n"); @@ -241,15 +260,7 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) pr_info(" burned RAM size %i MiB\n", rwtm->ram_size); } - msg.command = MBOX_CMD_ECDSA_PUB_KEY; - ret = mbox_send_message(rwtm->mbox, &msg); - if (ret < 0) - return ret; - - if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) - return -ETIMEDOUT; - - ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); + ret = mox_rwtm_exec(rwtm, MBOX_CMD_ECDSA_PUB_KEY, NULL, false); if (ret == -ENODATA) { dev_warn(dev, "Board has no public key burned!\n"); } else if (ret == -ENOSYS) { @@ -272,38 +283,24 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) static int check_get_random_support(struct mox_rwtm *rwtm) { - struct armada_37xx_rwtm_tx_msg msg; - int ret; - - msg.command = MBOX_CMD_GET_RANDOM; - msg.args[0] = 1; - msg.args[1] = rwtm->buf_phys; - msg.args[2] = 4; - - ret = mbox_send_message(rwtm->mbox, &msg); - if (ret < 0) - return ret; - - if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2)) - return -ETIMEDOUT; + struct armada_37xx_rwtm_tx_msg msg = { + .args = { 1, rwtm->buf_phys, 4 }, + }; - return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval); + return mox_rwtm_exec(rwtm, MBOX_CMD_GET_RANDOM, &msg, false); } static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) { struct mox_rwtm *rwtm = container_of(rng, struct mox_rwtm, hwrng); - struct armada_37xx_rwtm_tx_msg msg; + struct armada_37xx_rwtm_tx_msg msg = { + .args = { 1, rwtm->buf_phys, (max + 3) & ~3 }, + }; int ret; if (max > PAGE_SIZE) max = PAGE_SIZE; - msg.command = MBOX_CMD_GET_RANDOM; - msg.args[0] = 1; - msg.args[1] = rwtm->buf_phys; - msg.args[2] = (max + 3) & ~3; - if (!wait) { if (!mutex_trylock(&rwtm->busy)) return -EBUSY; @@ -311,15 +308,7 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) mutex_lock(&rwtm->busy); } - ret = mbox_send_message(rwtm->mbox, &msg); - if (ret < 0) - goto unlock_mutex; - - ret = wait_for_completion_interruptible(&rwtm->cmd_done); - if (ret < 0) - goto unlock_mutex; - - ret = mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval); + ret = mox_rwtm_exec(rwtm, MBOX_CMD_GET_RANDOM, &msg, true); if (ret < 0) goto unlock_mutex; @@ -367,7 +356,6 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, size_t len, loff_t *ppos) { struct mox_rwtm *rwtm = file->private_data; - struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply; struct armada_37xx_rwtm_tx_msg msg; loff_t dummy = 0; ssize_t ret; @@ -400,23 +388,15 @@ static ssize_t do_sign_write(struct file *file, const char __user *buf, goto unlock_mutex; be32_to_cpu_array(rwtm->buf, rwtm->buf, MOX_ECC_NUMBER_WORDS); - msg.command = MBOX_CMD_SIGN; msg.args[0] = 1; msg.args[1] = rwtm->buf_phys; msg.args[2] = rwtm->buf_phys + MOX_ECC_NUMBER_LEN; msg.args[3] = rwtm->buf_phys + 2 * MOX_ECC_NUMBER_LEN; - ret = mbox_send_message(rwtm->mbox, &msg); - if (ret < 0) - goto unlock_mutex; - ret = wait_for_completion_interruptible(&rwtm->cmd_done); + ret = mox_rwtm_exec(rwtm, MBOX_CMD_SIGN, &msg, true); if (ret < 0) goto unlock_mutex; - ret = MBOX_STS_VALUE(reply->retval); - if (MBOX_STS_ERROR(reply->retval) != MBOX_STS_SUCCESS) - goto unlock_mutex; - /* * Here we read the R and S values of the ECDSA signature * computed by the rWTM firmware and convert their words from From patchwork Wed Jun 12 13:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13695095 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFB5DC27C53 for ; Wed, 12 Jun 2024 13:55:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id C3372C3277B; Wed, 12 Jun 2024 13:55:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAACDC4AF1C; Wed, 12 Jun 2024 13:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718200535; bh=XwoWP6pEFsDmCWAubVOo61604qzI/mvr37a1NpuVFMM=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHHJ+YVz9QEijtJJcfytvQVNd3ZEiu4mkzKjuSj/K/HJIm/VTG50c8PHSibhYaRcW uHAn08lmDD4pEblxYa8Os/Upro5Xs92D1l2SZpHTi/G34FgnbOBYuoEkVZ21vnR2QG PEKmCk/beEbapgJW1yv9mkAHk0ldn25WG49WI3PWMSaOltgszIrwAaRocJRwCY7jJE es3fwMCC/CrZjiLTzRK7aP02U8m0rc4+8PRysIGp9wtFVX4+/9vB5Zb/v3opaH5HQc cg0VarXGtPjNaVASLhk37W4RR4BIgQDNnGnQfEreVKeSX7lJtEApEg9Qxn8wQ6I7tT 5BKtbELBaG9NA== From: =?utf-8?q?Marek_Beh=C3=BAn?= List-Id: To: Gregory CLEMENT , Andrew Lunn , Arnd Bergmann , soc@kernel.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 19/19] firmware: turris-mox-rwtm: Use EOPNOTSUPP instead of ENOSYS Date: Wed, 12 Jun 2024 15:54:43 +0200 Message-ID: <20240612135443.30239-20-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240612135443.30239-1-kabel@kernel.org> References: <20240612135443.30239-1-kabel@kernel.org> MIME-Version: 1.0 Checkpatch warns agains -ENOSYS: WARNING: ENOSYS means 'invalid syscall nr' and nothing else Use EOPNOTSUPP instead. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index ea5ff1827d08..d1e5ee37aca4 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -170,7 +170,7 @@ static int mox_get_status(enum mbox_cmd cmd, u32 retval) else if (MBOX_STS_ERROR(retval) == MBOX_STS_FAIL) return -(int)MBOX_STS_VALUE(retval); else if (MBOX_STS_ERROR(retval) == MBOX_STS_BADCMD) - return -ENOSYS; + return -EOPNOTSUPP; else if (MBOX_STS_ERROR(retval) != MBOX_STS_SUCCESS) return -EIO; else @@ -237,7 +237,7 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) if (ret == -ENODATA) { dev_warn(dev, "Board does not have manufacturing information burned!\n"); - } else if (ret == -ENOSYS) { + } else if (ret == -EOPNOTSUPP) { dev_notice(dev, "Firmware does not support the BOARD_INFO command\n"); } else if (ret < 0) { @@ -263,7 +263,7 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ret = mox_rwtm_exec(rwtm, MBOX_CMD_ECDSA_PUB_KEY, NULL, false); if (ret == -ENODATA) { dev_warn(dev, "Board has no public key burned!\n"); - } else if (ret == -ENOSYS) { + } else if (ret == -EOPNOTSUPP) { dev_notice(dev, "Firmware does not support the ECDSA_PUB_KEY command\n"); } else if (ret < 0) {