From patchwork Mon Jul 15 10:47:05 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: 13733287 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 5527EC3DA59 for ; Mon, 15 Jul 2024 10:47:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 3F3F1C4AF0F; Mon, 15 Jul 2024 10:47:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2169AC4AF10; Mon, 15 Jul 2024 10:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040451; bh=O4uaxv7GHUzy/dI7jVG1XspnPohL9XyQ4MFsapoSjic=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ju2oU8BeB2CBHFs7oQomALT02Q8GtOsq/Kztk9cxyL33di+Isw79fre5bO4prVNRp u3aTXCj6Xv6SFm0DST5DlCT2ULsFW33XCyTdoZs7jmnwrWYw8a6TpS5ZqxmlIDiMxX 84dxzAYZvKjJOzfLk97QUU7V2BbX6c4/MWQ3ZW57qMD2Dmg3alf1FzovOHBGQncWiv w0tD5ucaHYNmmc+wdYF2gRl+tX16PaaRj3/4TCtct18IQxz74rCxx3rEvQgWzyeQzz wHMEISHQ5vyzsUpAvz/uuImZVnaPRLSZ0/WHUz7ewomsAShVtcfsCRS0FvALjEyICS MmBJqt2t3hxsg== 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 v4 01/19] firmware: turris-mox-rwtm: Do not complete if there are no waiters Date: Mon, 15 Jul 2024 12:47:05 +0200 Message-ID: <20240715104723.17751-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 Mon Jul 15 10:47:06 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: 13733288 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 CE6E6C3DA59 for ; Mon, 15 Jul 2024 10:47:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id AFA7FC4AF0E; Mon, 15 Jul 2024 10:47:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F50C32782; Mon, 15 Jul 2024 10:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040453; bh=b/RMi8pE1O8XodlWSP/qHTIDmSEE5TbkZW23gWQrxh4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMwcK9lHRDZgun1PnGGD2SRP856jj5USsF2RGZd3qqc0zdDTnlrBaD4yZKAyHaeuk Vm/nl6AQRL0LkY8DsDewBS1xAXxnVSE5PJN7gOr1mQrmgEZMOqthPHeMH3AW/Qfkpg WAITMSM4fOl7JPwpkJ45eY4rpn/tkm1cVDr3QfU95PVGd6I/G24S7b7bw2AShioTUU k60e00Aj5bFVbx5d8hOv3EZj5d49Q4Rda9NGPcdrgHUCkJsSAmxq8GdX4Ih711PQyU 2Z00aP+yr6G0+EadccP4kdsWdLGirbUE8JaAmkJ/OgFM5PTStLwuqUqTjkDK9ADlmd EsLM+wzf2xiRA== 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 v4 02/19] firmware: turris-mox-rwtm: Fix checking return value of wait_for_completion_timeout() Date: Mon, 15 Jul 2024 12:47:06 +0200 Message-ID: <20240715104723.17751-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 Mon Jul 15 10:47:07 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: 13733289 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 4AE06C3DA5D for ; Mon, 15 Jul 2024 10:47:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 316E0C4AF0F; Mon, 15 Jul 2024 10:47:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16270C4AF10; Mon, 15 Jul 2024 10:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040456; bh=A92y7rfHrXNvKJG+cqVuONweaDExbg3HeSLntRSQGps=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=essjcEZHiUjVW/C3qThucYXeSdfidVz2isNUw9dxaaHyHO8pa3fJfJ/z7nVcu6PWY mzH6sYEl31zaLua55d/XtPY+s4vWaiiDp0O2HUDWQ3Z/YBq/6FxN6GOdriaaZXmq+v 942N0WJV3XrHFar8s1dTMwfqZb7xbXuF+r1GEpf0A0wP2aZCr3DokLGmk1cfCnY5AB 8914X1nkhKbQ6v6pHc2SxHIjxomLo0F25ea89np4DCLX+1CGsmWm8wozjjnmpS4ZrR UcMPxcLgHLblbVbQgkVFsP5hcWrI70yS1m0rekPPgvsCHnH0jVgPuXCW9JQn83tIGr rEqsYL79hMoXg== 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 v4 03/19] firmware: turris-mox-rwtm: Use macro constant instead of hardcoded 4096 Date: Mon, 15 Jul 2024 12:47:07 +0200 Message-ID: <20240715104723.17751-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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. Use new local macro constant RWTM_DMA_BUFFER_SIZE at allocation time and when used in mox_hwrng_read(). Use SZ_4K instead of PAGE_SIZE. Although PAGE_SIZE is never set to a larger value on Armada 3720, it theoretically could, and this would be a waste of space. Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 3f4758e03c81..aafd747543f6 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -11,14 +11,18 @@ #include #include #include +#include #include #include #include #include +#include #include #define DRIVER_NAME "turris-mox-rwtm" +#define RWTM_DMA_BUFFER_SIZE SZ_4K + /* * The macros and constants below come from Turris Mox's rWTM firmware code. * This firmware is open source and it's sources can be found at @@ -287,8 +291,7 @@ 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; + max = min(max, RWTM_DMA_BUFFER_SIZE); msg.command = MBOX_CMD_GET_RANDOM; msg.args[0] = 1; @@ -479,8 +482,8 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) return -ENOMEM; rwtm->dev = dev; - rwtm->buf = dmam_alloc_coherent(dev, PAGE_SIZE, &rwtm->buf_phys, - GFP_KERNEL); + rwtm->buf = dmam_alloc_coherent(dev, RWTM_DMA_BUFFER_SIZE, + &rwtm->buf_phys, GFP_KERNEL); if (!rwtm->buf) return -ENOMEM; From patchwork Mon Jul 15 10:47:08 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: 13733290 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 BC469C3DA59 for ; Mon, 15 Jul 2024 10:47:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id A5477C4AF0B; Mon, 15 Jul 2024 10:47:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AA60C32782; Mon, 15 Jul 2024 10:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040458; bh=8Xa2UhyieKUsXGB16/F+i+QUPtzQHAeGEKxGEogPFVg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGLeT8oPTTH82IlWeJdZFow651ilGWUu3Y0YIn51ZbY6QlNA0q1wm+hsaZTrpWfmp fb3qWY9BNaaEx3ZOvWvqwBKmjzeDk6c1P30cMLwsK8BtEIFoInVdUAxrT0rq0fhgQv wZ1pG8kExq65yD/l7QMCgkWfbgVhTBzFg124AuqfpI3HRYeFyqODNhH2jMsRetBkNE H6pI0e86kshQ0UL+rAHj6Gg7YoJa6ybWItXINvzdgIjLe9gy9d0tu1A1XlawAX5co1 ti8VDs8igoJU5FtpZpd60OvLktqdQS/T5feYqVr4oohIZE6Caq2LNDwJPL9r7wP04M ATCgf1twkpJcg== 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 v4 04/19] firmware: turris-mox-rwtm: Use ETH_ALEN instead of hardcoded 6 Date: Mon, 15 Jul 2024 12:47:08 +0200 Message-ID: <20240715104723.17751-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 aafd747543f6..f7f9859b8f61 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 @@ -69,7 +70,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 Mon Jul 15 10:47:09 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: 13733291 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 45A8FC3DA5E for ; Mon, 15 Jul 2024 10:47:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 29378C4AF0F; Mon, 15 Jul 2024 10:47:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B644C4AF0A; Mon, 15 Jul 2024 10:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040461; bh=GD4zyNFAdyAK06VMAdVAjv3JUlGZ+p5Wzs9l7CZkbv0=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=eN/r6iN+ft1yvSoA7hQKMm6+evNT+FmxCt29ghOtAg5EUaWf3krEtwZZ+NK7e2Kpc YsxaCHicZYYQKjAfuFIgwM44kv06bFCxR2FXQfS9aeF401RkAuGloyvLTrQ469Y+2d zsAslXqujL2oSu5Mv034dd6K9NfWyjkV/GSrdJsyIAOTdzG1OlwMexzuOIn+Kq1M0e oFxtDU1iyBmOIiQoG1rFqpAXJkDGsU2mXBHKIfylRJYcCWdwUlaNCQCw6/mF0rIeA6 khtQp+uUSwz4i7ewaWy/UL6GhWiOr4j/mC4Ywp6ycu1Tgpm/F13DICfC9BQFowQv7W Ocb/DKto0KfhQ== 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 v4 05/19] firmware: turris-mox-rwtm: Use the boolean type where appropriate Date: Mon, 15 Jul 2024 12:47:09 +0200 Message-ID: <20240715104723.17751-6-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 f7f9859b8f61..5ed480ac5146 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -19,6 +19,7 @@ #include #include #include +#include #define DRIVER_NAME "turris-mox-rwtm" @@ -67,13 +68,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 @@ -85,7 +86,7 @@ struct mox_rwtm { */ struct dentry *debugfs_root; u32 last_sig[34]; - int last_sig_done; + bool last_sig_done; #endif }; @@ -229,7 +230,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); @@ -256,7 +257,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], @@ -352,7 +353,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; } @@ -418,7 +419,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 Mon Jul 15 10:47:10 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: 13733292 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 B6493C3DA5D for ; Mon, 15 Jul 2024 10:47:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 9FA96C4AF0E; Mon, 15 Jul 2024 10:47:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82475C32782; Mon, 15 Jul 2024 10:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040463; bh=TSF1yBGXH1ew7xzOViFF9FkVDA6qY9UcEeLLPG9fALA=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ukpu1OQi2FdzPMTQvzO7GyrPYQN8MU+6z7EAcd9ji1ut+ev+I/Gg1Ox8P9+5fjNFV hm7rdD01KJthWxpLKsoPpqEHTNjVvmqr0nv4vY3sX7qqPK25OdNuUZbGYJ2g6Hmrsw FiMB5w6tmGGd5EkA3VcjO1NingVP/LB7GqVZT+3zU1uV575f6n8bfxgC0jxFr6WNtW N0ZnLoA5nmBnAndBd60hmMGUsf1AYI7tYmkv3AfTxgAxG+oAOf0WiVE8kk6iaOtzZz 3voOUwNm2FM1snzxYyqY8XmtHhoXcFcCD7v4qZxQJOKBOSzQRszh6bYfRlL8ZBQtdv sVRnlxzHQiSPQ== 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 v4 06/19] firmware: turris-mox-rwtm: Hide signature related constants behind macros Date: Mon, 15 Jul 2024 12:47:10 +0200 Message-ID: <20240715104723.17751-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 36 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5ed480ac5146..0ae5b2086113 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 @@ -31,6 +32,11 @@ * 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 MBOX_STS_SUCCESS (0 << 30) #define MBOX_STS_FAIL (1 << 30) #define MBOX_STS_BADCMD (2 << 30) @@ -85,7 +91,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 }; @@ -341,18 +347,18 @@ static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len, struct mox_rwtm *rwtm = file->private_data; ssize_t ret; - /* only allow one read, of 136 bytes, from position 0 */ + /* only allow one read, of whole signature, from position 0 */ if (*ppos != 0) return 0; - if (len < 136) + if (len < sizeof(rwtm->last_sig)) 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, + sizeof(rwtm->last_sig)); rwtm->last_sig_done = false; return ret; @@ -367,8 +373,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 */ @@ -389,17 +394,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; @@ -417,8 +423,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, + sizeof(rwtm->last_sig)); + 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 Mon Jul 15 10:47:11 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: 13733293 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 351B8C3DA59 for ; Mon, 15 Jul 2024 10:47:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1F8A5C4AF0E; Mon, 15 Jul 2024 10:47:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05B2EC32782; Mon, 15 Jul 2024 10:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040466; bh=EWfl7Pzk2wgZExrt1XlXb7co9xshNocr3bGJAUWtFbg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWrQmgBVfsiSgnZqiHKQhcmDa4ag758VlUvthlVHGVaUiogjJuULTW7NatosVn8w7 wzw9H7AE8t6W6D4WFbR2VV+Ag4B2+q+Sq3EwQXy+0UcHW9Ow6vHSS7SJ2vnjiwxqxq ZLDB4kxyPJynAzAUKxXEvkJ7OY7f12t8VfGZzC/5brrLQjXUAyOquozbNxqZco0nY+ L5JzV6y8xh05AN5z1tgvnHxpZwdKFW6wgwsy3mSnIJL/ISq2xgW7ilMmY+YSkxNQhp s3IwFeZZ8u9EsXc0Q1qTJTwagLkiR5tKRu0Qy09JShQA+bjokAtLSiJg4lJPRmYMPL A6lVh3hA+qRzA== 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 v4 07/19] firmware: turris-mox-rwtm: Fix driver includes Date: Mon, 15 Jul 2024 12:47:11 +0200 Message-ID: <20240715104723.17751-8-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 0ae5b2086113..0da40f55c750 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -8,18 +8,23 @@ #include #include #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 Mon Jul 15 10:47:12 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: 13733294 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 B13A3C3DA59 for ; Mon, 15 Jul 2024 10:47:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 9D341C4AF0E; Mon, 15 Jul 2024 10:47:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A093C4AF0B; Mon, 15 Jul 2024 10:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040468; bh=XfNjdgEJaHYxp2TbZvn6td3wk5uKTKb8zqMIkFPSr6o=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ph9kmlYLuxHGLKrTwqnumcnixK+QcPJJMdvMxdW014LYzhp2AFjLCIVI4MElU0EQB KUA1O5cyTHvZe15kMRWgfBlNN3Pvj6P1mNcY9lNIZOYADhskuksoL4NB++sZvla9us 7vZj0VVq4gUq8qMx3Hm4B2+lfUoJOp7dhI0q1qisrLsAVYymA25mvAVkB42ly+XzKm JaZeioxRcxWtLxoDtiFen6u4txCiSFtpv+9RpVmZWfcgTTgWpLDJ11lv8b4MGGvaAn 7IhJ81OJrO3KO51gCv5kiaJIu2SPRyRqeduVxZQ+cmW4ToJL+L9QpzxBHAxIQ+zg6r W0hoGAOpWx2tA== 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 v4 08/19] firmware: turris-mox-rwtm: Use sysfs_emit() instead of sprintf() Date: Mon, 15 Jul 2024 12:47:12 +0200 Message-ID: <20240715104723.17751-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 Use sysfs_emit() instead of sprintf() in sysfs attribute .show() method. Signed-off-by: Marek Behún --- drivers/firmware/turris-mox-rwtm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 0da40f55c750..e3e209247e68 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -151,7 +151,7 @@ name##_show(struct kobject *kobj, struct kobj_attribute *a, \ struct mox_rwtm *rwtm = to_rwtm(kobj); \ if (!rwtm->has_##cat) \ return -ENODATA; \ - return sprintf(buf, format, rwtm->name); \ + return sysfs_emit(buf, format, rwtm->name); \ } \ static struct kobj_attribute mox_attr_##name = __ATTR_RO(name) From patchwork Mon Jul 15 10:47:13 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: 13733295 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 39EA8C3DA5D for ; Mon, 15 Jul 2024 10:47:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1D764C4AF0F; Mon, 15 Jul 2024 10:47:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03980C4AF0A; Mon, 15 Jul 2024 10:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040471; bh=5XVMq6Zj0fgRRybCQ1Ckyb89CTJwFtTCG3NWvPiSKEo=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=b0bI16G9SiApLHTZKf0xePgyX67mCTAJQl3fBHUDMsizHcgN60h98puzGXPC/a0y1 J3i2JFd4RuSBE+B20ZTSfLuG9OalJZRkValceNc0JyIao9cAbrHR+/69isbvC+02u5 f2WiB04ctOd9GKkeGxaQkrbCnQFFqKkTDmWLJhR7aGTv6+z7yCh7gTCvaarSzp92ji pdfLnOQPqMBYjTeWSmIkBICZ8BFjA/kUBmNjzJAfo9P/LzzcYlhuOxXdc2l9Xdj4EA brCzWTEutF30BflJ64TMxG2aEsAISkh22q8qbTqDuz7d4ncY+23RVNOuTskpuWxgpo xpqZ67zjioBsw== 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 v4 09/19] firmware: turris-mox-rwtm: Don't create own kobject type Date: Mon, 15 Jul 2024 12:47:13 +0200 Message-ID: <20240715104723.17751-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 In order to create attribute files in /sys/firmware/turris-mox-rwtm, this driver creates it's own kobject type. Simplify this by dropping this own kobject creation, and instead creating standard device attribute files. For backwards compatibility with sysfs ABI, create a symlink /sys/firmware/turris-mox-rwtm, pointing to this device's sysfs directory. Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 108 ++++++++--------------------- 1 file changed, 30 insertions(+), 78 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index e3e209247e68..ca70a07b4dee 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -61,13 +60,10 @@ 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 hwrng hwrng; struct armada_37xx_rwtm_rx_msg reply; @@ -101,59 +97,17 @@ 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; -} - -static void mox_kobj_release(struct kobject *kobj) -{ - kfree(to_rwtm(kobj)->kobj); -} - -static const struct kobj_type mox_kobj_ktype = { - .release = mox_kobj_release, - .sysfs_ops = &kobj_sysfs_ops, -}; - -static int mox_kobj_create(struct mox_rwtm *rwtm) -{ - rwtm->kobj = kzalloc(sizeof(*rwtm->kobj), GFP_KERNEL); - if (!rwtm->kobj) - return -ENOMEM; - - 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)); - return -ENXIO; - } - - rwtm->kobj->rwtm = rwtm; - - return 0; -} - #define MOX_ATTR_RO(name, format, cat) \ static ssize_t \ -name##_show(struct kobject *kobj, struct kobj_attribute *a, \ +name##_show(struct device *dev, struct device_attribute *a, \ char *buf) \ { \ - struct mox_rwtm *rwtm = to_rwtm(kobj); \ + struct mox_rwtm *rwtm = dev_get_drvdata(dev); \ if (!rwtm->has_##cat) \ return -ENODATA; \ return sysfs_emit(buf, format, rwtm->name); \ } \ -static struct kobj_attribute mox_attr_##name = __ATTR_RO(name) +static DEVICE_ATTR_RO(name) MOX_ATTR_RO(serial_number, "%016llX\n", board_info); MOX_ATTR_RO(board_version, "%i\n", board_info); @@ -162,6 +116,17 @@ 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 *turris_mox_rwtm_attrs[] = { + &dev_attr_serial_number.attr, + &dev_attr_board_version.attr, + &dev_attr_ram_size.attr, + &dev_attr_mac_address1.attr, + &dev_attr_mac_address2.attr, + &dev_attr_pubkey.attr, + NULL +}; +ATTRIBUTE_GROUPS(turris_mox_rwtm); + static int mox_get_status(enum mbox_cmd cmd, u32 retval) { if (MBOX_STS_CMD(retval) != cmd) @@ -176,16 +141,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); @@ -486,6 +441,11 @@ static inline void rwtm_unregister_debugfs(struct mox_rwtm *rwtm) } #endif +static void rwtm_firmware_symlink_drop(void *parent) +{ + sysfs_remove_link(parent, DRIVER_NAME); +} + static int turris_mox_rwtm_probe(struct platform_device *pdev) { struct mox_rwtm *rwtm; @@ -502,18 +462,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (!rwtm->buf) return -ENOMEM; - ret = mox_kobj_create(rwtm); - if (ret < 0) { - dev_err(dev, "Cannot create turris-mox-rwtm kobject!\n"); - 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); @@ -527,7 +475,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; + return ret; } init_completion(&rwtm->cmd_done); @@ -561,14 +509,19 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) dev_info(dev, "HWRNG successfully registered\n"); + /* + * For sysfs ABI compatibility, create symlink + * /sys/firmware/turris-mox-rwtm to this device's sysfs directory. + */ + ret = sysfs_create_link(firmware_kobj, &dev->kobj, DRIVER_NAME); + if (!ret) + devm_add_action_or_reset(dev, rwtm_firmware_symlink_drop, + firmware_kobj); + return 0; 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; } @@ -577,8 +530,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); } @@ -596,6 +547,7 @@ static struct platform_driver turris_mox_rwtm_driver = { .driver = { .name = DRIVER_NAME, .of_match_table = turris_mox_rwtm_match, + .dev_groups = turris_mox_rwtm_groups, }, }; module_platform_driver(turris_mox_rwtm_driver); From patchwork Mon Jul 15 10:47:14 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: 13733296 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 A955CC3DA59 for ; Mon, 15 Jul 2024 10:47:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 93712C4AF0B; Mon, 15 Jul 2024 10:47:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78256C4AF0E; Mon, 15 Jul 2024 10:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040473; bh=LZgNRo94yhadg1VKHJcimFfo/p4GTiM9/K11pkKEdIQ=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=p6x3aFlDygxwo4Wep7HT2qbYf2fsgCLTzEf89Zr6iH1hoaC37jXss/Qid7nv68o5m 3X0/zk5crP/DmTIIzKyFbv4HI3rtQXWxUsrzxpkWcg38VVQAln2DlD0/WUCqvTQcIJ 0yq3RpsnKTDma5qXbmYjmu6KeNSTk/YB3R1NgoZQlZXtcsba89VijY1wbSC6OGB+NR Adfi5YQR/a3J/e9ZD6Yrp4xba6G2Fv8H6SM2ADueqXccTU4zEBFN9KmozdPk+AJ92w d2gP0rdeWIXAkWUv7lRSjwR7YJLq5glvfEqR678gBH9MKrRMfmxgDCe442RBvnX4+h OqwPFXh6WQvZw== 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 v4 10/19] firmware: turris-mox-rwtm: Simplify debugfs code Date: Mon, 15 Jul 2024 12:47:14 +0200 Message-ID: <20240715104723.17751-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 ca70a07b4dee..f95e77cc4716 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -91,7 +91,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 @@ -404,39 +403,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); + + debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, &do_sign_fops); + + devm_add_action_or_reset(rwtm->dev, rwtm_debugfs_release, root); } #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 @@ -501,11 +484,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"); @@ -529,7 +508,6 @@ static void turris_mox_rwtm_remove(struct platform_device *pdev) { struct mox_rwtm *rwtm = platform_get_drvdata(pdev); - rwtm_unregister_debugfs(rwtm); mbox_free_channel(rwtm->mbox); } From patchwork Mon Jul 15 10:47:15 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: 13733297 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 2C854C3DA59 for ; Mon, 15 Jul 2024 10:47:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 159EDC4AF0E; Mon, 15 Jul 2024 10:47:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE919C32782; Mon, 15 Jul 2024 10:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040476; bh=SDdIezfetOjkv1Sjj9Ygh8uOOyA2sNzJKo9KfkvWUUs=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=MK4YvNvJ61QaPfmfAgz+1WIJDCQf36n0/CKxkMbm4j5KKyPIyZ18gINEFK0nX3cJc oIAjyD5SzM8GQ/7cu9fnNSsxoQSgBEXMLVOAgjhzk30Pyd2hgq16hCD1MuHQT9Lke9 Dyg3OxOjATihEFQicoPVVVA59SrZ19DxylgK9guJERtI0WG8Mg9ZEOPp4zDGr1cvkA euVb42I/eE+MCOb+D0m1r7ihECWCuh0tLuzWU8csP1cvU/Rz/IYKWVqoDNL3T9Pqrd r68Tt99sPSmTG1t7wHEK9CEntSK24D2NjEm2IXmTmO/kyc6tULWC1+y8DLLHgsxqBu m8qdGF+ERMmog== 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 v4 11/19] firmware: turris-mox-rwtm: Convert rest to devm_* and get rid of driver .remove() Date: Mon, 15 Jul 2024 12:47:15 +0200 Message-ID: <20240715104723.17751-12-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 Use devm resource management for driver's mailbox. This allows us to get rid of the driver's .remove() method and the gotos in .probe(). Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index f95e77cc4716..5f44fece33f2 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -424,6 +424,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 void rwtm_firmware_symlink_drop(void *parent) { sysfs_remove_link(parent, DRIVER_NAME); @@ -461,6 +466,10 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) return ret; } + ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox); + if (ret) + return ret; + init_completion(&rwtm->cmd_done); ret = mox_get_board_info(rwtm); @@ -471,7 +480,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"; @@ -481,7 +490,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); @@ -498,17 +507,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) firmware_kobj); return 0; - -free_channel: - mbox_free_channel(rwtm->mbox); - return ret; -} - -static void turris_mox_rwtm_remove(struct platform_device *pdev) -{ - struct mox_rwtm *rwtm = platform_get_drvdata(pdev); - - mbox_free_channel(rwtm->mbox); } static const struct of_device_id turris_mox_rwtm_match[] = { @@ -521,7 +519,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 Mon Jul 15 10:47:16 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: 13733298 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 A3565C3DA59 for ; Mon, 15 Jul 2024 10:47:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 8B4A0C4AF0B; Mon, 15 Jul 2024 10:47:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70558C4AF0E; Mon, 15 Jul 2024 10:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040478; bh=tefhaZTEF44wo+1+6IH3p/hjgSJjZbrphTxfFvM90YM=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dk1PQCrAPvSL6bt+Q+bQWwIOGQaoGw+fEfuoxfPDOIQCWlQvKemJRsXvNuMYzIE5h NBNxQ8363LII+9DIAMz3F5Rd26k57BF/5ljL+n1fG3W1CXD8lEAXHQYgWWG28LHRd8 pdoOboZicaFjP0bmIl9uw6mPEUfCgR3foLxPqT1PBAwF2eQNavUUXG5lYzKk96wIfj ljhEfce7vfaW3HXVM7S03vWEI1Lw+XL2DNODPRxSFdVUOaBXs5CmTksBXhRJuIBNxl Vp86Qk0YG2IoqHWonVxE41dh/5wvUYOy3q5jiYPp09oo6BVzd0T6yBB6OGJowebWvF pGqSpHbobKaPw== 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 v4 12/19] firmware: turris-mox-rwtm: Use dev_err_probe() where possible Date: Mon, 15 Jul 2024 12:47:16 +0200 Message-ID: <20240715104723.17751-13-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 5f44fece33f2..30c124e664d9 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -458,13 +458,9 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) rwtm->mbox_client.rx_callback = mox_rwtm_rx_callback; 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 (IS_ERR(rwtm->mbox)) + return dev_err_probe(dev, PTR_ERR(rwtm->mbox), + "Cannot request mailbox channel!\n"); ret = devm_add_action_or_reset(dev, rwtm_devm_mbox_release, rwtm->mbox); if (ret) @@ -488,10 +484,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) + return dev_err_probe(dev, ret, "Cannot register HWRNG!\n"); rwtm_register_debugfs(rwtm); From patchwork Mon Jul 15 10:47:17 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: 13733299 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 21CDBC3DA59 for ; Mon, 15 Jul 2024 10:48:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 0D1D3C4AF0F; Mon, 15 Jul 2024 10:48:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5DFAC32782; Mon, 15 Jul 2024 10:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040481; bh=hprSq5KeOGdNJ4ELz5Ky/YfL795RHKD06ANsIyf3DF4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=QJmK9sbJ7HcHBka7hfMmzPWUy1BAp7K42GSx6zSCkN6J80x7UpiQ0xqBTwjDB1Pwh aHcrPhJUO8gssNo2+8Wu+sh1sv65bi2ahHT6hRj0WRSFoDE3FluZA0IfhkELlc3E9k +iW0ccKzZ5D3hRs6nJC4UPtKUW/EYB/vZ4TgQSizEafh+y5Cn5BY0DAGm9rA4d46Wh M4EKNEgD1RWvg2m7VYXZd4bLGiUz34LXBpNI8xwDpSWrj8nipIPtRBsWOOTC8XWH+4 jIfJG7CU9N4MZbTp7sAc2tdto21QWwPLxQ5l5+iKI9k5RuXdGccl7C9XsX4KCLDj0f 8EXU7tIHyNM+g== 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 v4 13/19] firmware: turris-mox-rwtm: Initialize completion before mailbox Date: Mon, 15 Jul 2024 12:47:17 +0200 Message-ID: <20240715104723.17751-14-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 Initialize the completion before the mailbox channel is requested. Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver") Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- 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 30c124e664d9..f291df9a72ff 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -453,6 +453,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) 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; @@ -466,8 +467,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (ret) 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); From patchwork Mon Jul 15 10:47:18 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: 13733300 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 97926C3DA5E for ; Mon, 15 Jul 2024 10:48:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 82837C32782; Mon, 15 Jul 2024 10:48:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E04C4AF0B; Mon, 15 Jul 2024 10:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040483; bh=jbqAfRXeCbJK3CKZJ1Pv0ED1fDxWbljUDKYPCI6fzjg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=EB7tcxQQkV0gE/mpIktc6VOuIozLF5XS7hfonkIba3SwNgI+8CRBXfB1inMbFkPGY RIXs9BaNM8QrehKkmMlHNMtOlN1lZtja2nB/2ndcVodv99ink4vQjL1gPgXytPAFGp pPS5WFNyLSSl0WbZJrQZWo3UFaPMwPbp/b6nZKvuN4XXhWVHRlhbKwuyoLmqOw75G8 oqPhwKLCVKAcpWR4uCGrVf0HGLwBXk7seQUYGnV3T7pJKm1+SNT80GK5T9k4vrKm8d Xfe7H8WK7GELQy3IXzPRzDJ8wIw7nQAhL5aiNAQzTq62kYY6nSeO2YFpG6Pq8sG6y8 7Lk+kyvv47ikg== 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 v4 14/19] firmware: turris-mox-rwtm: Drop redundant device pointer Date: Mon, 15 Jul 2024 12:47:18 +0200 Message-ID: <20240715104723.17751-15-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 Drop redundant device pointer from driver's private structure. Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- drivers/firmware/turris-mox-rwtm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index f291df9a72ff..d12e29625022 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -61,7 +61,6 @@ enum mbox_cmd { }; struct mox_rwtm { - struct device *dev; struct mbox_client mbox_client; struct mbox_chan *mbox; struct hwrng hwrng; @@ -96,6 +95,11 @@ struct mox_rwtm { #endif }; +static inline struct device *rwtm_dev(struct mox_rwtm *rwtm) +{ + return rwtm->mbox_client.dev; +} + #define MOX_ATTR_RO(name, format, cat) \ static ssize_t \ name##_show(struct device *dev, struct device_attribute *a, \ @@ -164,6 +168,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; @@ -178,10 +183,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; @@ -213,9 +218,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; @@ -416,7 +421,7 @@ static void rwtm_register_debugfs(struct mox_rwtm *rwtm) debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, &do_sign_fops); - devm_add_action_or_reset(rwtm->dev, rwtm_debugfs_release, root); + devm_add_action_or_reset(rwtm_dev(rwtm), rwtm_debugfs_release, root); } #else static inline void rwtm_register_debugfs(struct mox_rwtm *rwtm) @@ -444,7 +449,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) if (!rwtm) return -ENOMEM; - rwtm->dev = dev; rwtm->buf = dmam_alloc_coherent(dev, RWTM_DMA_BUFFER_SIZE, &rwtm->buf_phys, GFP_KERNEL); if (!rwtm->buf) From patchwork Mon Jul 15 10:47:19 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: 13733301 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 1D00DC3DA5D for ; Mon, 15 Jul 2024 10:48:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 04FF4C4AF0E; Mon, 15 Jul 2024 10:48:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD489C32782; Mon, 15 Jul 2024 10:48:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040485; bh=Z85ohY/TriR5MifQgfR1EPcpJLeH2R08PF6O395cHGw=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=dU2XYDpZyPNHxKdofcVtv5p96shYyq6FuGvindmziMpq84a/zFyMNOA31Et54vUl7 P1zljvApeQe+Pk+RjF3DxstR/ZfKDQWQcDPv0BTbii4iRlcf7VMg6UNarb0h/wWOtx SS30gu6faYoWtd8v0OwsfX7z0xJDqgrHZfKQGmnJcNmLGsc3rCeityebMNXREL+RAK BCd5PWEacHmC4JTQHDLtf2aBzTygwCMEgqTegwJucjrr+zpixcPnWJM3x7edbXC/iv Eu2JRqTMljH81GbekXcqGSiH6JGWaA85+EkZMByMU0QOHvNK/kmp1b1Kv6bsKDBOTo Gl0vvyy8ABD1g== 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 v4 15/19] firmware: turris-mox-rwtm: Use devm_mutex_init() instead of mutex_init() Date: Mon, 15 Jul 2024 12:47:19 +0200 Message-ID: <20240715104723.17751-16-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 d12e29625022..9f6bda969943 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -456,7 +456,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) + return ret; + init_completion(&rwtm->cmd_done); rwtm->mbox_client.dev = dev; From patchwork Mon Jul 15 10:47:20 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: 13733302 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 8F5C2C3DA59 for ; Mon, 15 Jul 2024 10:48:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 7A7E2C4AF0E; Mon, 15 Jul 2024 10:48:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F59BC32782; Mon, 15 Jul 2024 10:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040488; bh=kZlRiEZGYaAz7Vl2Ou2b/HAdFUAXeMbtadH/7tYtf1U=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0fXWzyxMw//Ezl3kmpxG26tJtNpV5jVHVuH68f77HtoTmRTq0EwEnroTsG5jok/K 1iJ1d7x8yWJWrkraVhovO89WsKIeHk2FhcSBYrfOl9XgfH5DJQnqP0ZtrBhKifoKVA 7b5TZbtLqUKLpIMvoVzo+UMaphPhak3cKsIXsHnPerYfvLwfaZA1nBbPQ9nUa8DEYg tTmmZI6at1JgK+TFmpX1yHPbwrnZWQkBeQ70MNj2+jTh7P+dT+i7vWp0KFces+m3mZ diCmYBj8Nobaoecgykdcq2RdOBZOAPgtR1WYDVbu4HRyG1kN+nZw7b/VxAx71OuL5t Bqab3bngHcn4g== 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 v4 16/19] firmware: turris-mox-rwtm: Use container_of() instead of hwrng .priv member Date: Mon, 15 Jul 2024 12:47:20 +0200 Message-ID: <20240715104723.17751-17-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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. Link: https://lore.kernel.org/soc/ZmLhQBdmg613KdET@gondor.apana.org.au/ Signed-off-by: Marek Behún Reviewed-by: Andy Shevchenko --- 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 9f6bda969943..52f97235c3a6 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -259,7 +259,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; @@ -487,7 +487,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) From patchwork Mon Jul 15 10:47:21 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: 13733303 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 14F0CC3DA59 for ; Mon, 15 Jul 2024 10:48:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id F0AC7C32782; Mon, 15 Jul 2024 10:48:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53F8C4AF0A; Mon, 15 Jul 2024 10:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040490; bh=fZXp5znfN0w2WN+UlYs07thNJDMXh+5ZEjk8LG8Hru4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLbhAdyJc2NJgKcJRl48d9JXcqRg/F4t/kB1wgL8RwIs7JkOIB3PD6bRtBAB/7Q1A sytnkxnulsy0RlKHVB/Pzkry5uGKLbkdyeZC9mdc8iDorEea6qE0OEngANCjqRwRO+ 31lDhQBpdcaKTdWBuacrb2sRUcx5sA4/paFb1OFeNKYmOs2Rwkhlxz3pu1JrlpQIRi gYNLUr2EN3nhUgueeIz1ok+9GE6ucQDCQAZgz9cqkhc69yYMzKr7szwdS1P5I88TyI vtX4JYZ/oOmBsRaiBQGdy820at++gV8R03roion/lOR6D7ccQhwJwWkdCraNYvvOf9 X/MYS20U989Rg== 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 v4 17/19] firmware: turris-mox-rwtm: Use EOPNOTSUPP instead of ENOSYS Date: Mon, 15 Jul 2024 12:47:21 +0200 Message-ID: <20240715104723.17751-18-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 52f97235c3a6..a9391705f5b4 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -137,7 +137,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 @@ -185,7 +185,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) { @@ -219,7 +219,7 @@ 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(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) { From patchwork Mon Jul 15 10:47:22 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: 13733304 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 858A2C3DA59 for ; Mon, 15 Jul 2024 10:48:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 71C04C4AF0E; Mon, 15 Jul 2024 10:48:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 570C1C32782; Mon, 15 Jul 2024 10:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040493; bh=8BMIGuOiKNipiQV7zt2ZZvMZ3wYh4xdIWqHGjkxp12s=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=DzeayL92wPIY8AFCWkEapDoDHnuRz7Yv9x54kVcT6vfpvAGeFciUNrcwIDAMgo59K hfA/23uIBnPvakfvuJApfphqSvofGaytsbEb8hmeFPrxULcca6Qau3EZAhvp7CJWBF W9/OsrXcI/BN9rxdP5cS1h2Z7SqcJWYo5FfKKwJMbd0UCR8pTYlNPGa9T+WhiaAngu sz1Tbm2n2PxPlJp2lE7AEcKK/nCmW/ZRilvBOjmTXo/TtrM/oN7z7HNhC2L8ruzGTs 4+nwV1NHHwmQKzAu99B1jElzP4vU7xumEcU7WotIJiv5SvKV3vlPbjagX/xZgHQOvo E6DGoal5Gcjww== 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 v4 18/19] firmware: turris-mox-rwtm: Use ALIGN() instead of hardcoding Date: Mon, 15 Jul 2024 12:47:22 +0200 Message-ID: <20240715104723.17751-19-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-1-kabel@kernel.org> MIME-Version: 1.0 Use ALIGN(max, 4) instead of hardcoding ((max + 3) & ~3). Signed-off-by: Marek Behún --- 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 a9391705f5b4..0c7d8c96ea17 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -268,7 +269,7 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) msg.command = MBOX_CMD_GET_RANDOM; msg.args[0] = 1; msg.args[1] = rwtm->buf_phys; - msg.args[2] = (max + 3) & ~3; + msg.args[2] = ALIGN(max, 4); if (!wait) { if (!mutex_trylock(&rwtm->busy)) From patchwork Mon Jul 15 10:47:23 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: 13733305 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 08868C3DA59 for ; Mon, 15 Jul 2024 10:48:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id E7518C4AF0E; Mon, 15 Jul 2024 10:48:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC87AC4AF0A; Mon, 15 Jul 2024 10:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721040495; bh=ra4UQDdEcA4b5Z3A9nyljWhOjo6TN9B8ZBY2ZwYX6gI=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=MKjWaTclRAy0MEGW8/2aOWALLaRxTROYKwi2goJ14PKUkiP9owGfFSWuISPTOBWZD WOF+iveprDd/WOid5utMR0qfqg/+4J6EASVjgFTDlA0xPpPjP4eFZP+XV1rCvuN54c YawXxwh2FYaSvsc575C5DUdIUcrPnyNltqt65qbVDcCls090dRi2mqrKMTvl6i2vl4 NGaAkjtfWC/qPegDA+MqJ3/Gt4AzvCIyReIRB2zPPsQlXzkcwQluKEvxSZzu56UMFJ Q8zVzHi6gCkMvn2B1ahbTmG12JP9TCa0l93Tua0K48jMEY53y5xiFKGoblPN9OkGIe KfVW1yjfV/fig== 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 v4 19/19] firmware: turris-mox-rwtm: Deduplicate command execution code Date: Mon, 15 Jul 2024 12:47:23 +0200 Message-ID: <20240715104723.17751-20-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240715104723.17751-1-kabel@kernel.org> References: <20240715104723.17751-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 Reviewed-by: Andy Shevchenko --- 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 0c7d8c96ea17..525ebdc7ded5 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -157,6 +157,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; @@ -170,19 +198,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"); @@ -209,15 +228,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 == -EOPNOTSUPP) { @@ -240,37 +251,23 @@ 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, ALIGN(max, 4) }, + }; int ret; max = min(max, RWTM_DMA_BUFFER_SIZE); - msg.command = MBOX_CMD_GET_RANDOM; - msg.args[0] = 1; - msg.args[1] = rwtm->buf_phys; - msg.args[2] = ALIGN(max, 4); - if (!wait) { if (!mutex_trylock(&rwtm->busy)) return -EBUSY; @@ -278,15 +275,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; @@ -333,7 +322,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; @@ -366,23 +354,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