From patchwork Mon Jun 17 14:45: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: 13700858 X-Patchwork-Delegate: arnd@arndb.de 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 BC790C27C79 for ; Mon, 17 Jun 2024 14:45:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id A1BA9C4AF1D; Mon, 17 Jun 2024 14:45:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DF69C4AF4D; Mon, 17 Jun 2024 14:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635540; bh=qNQKeKVAjEgxOQBenmNAc0eVUtJC4/u8mbQTNzE9vLQ=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=qiQ7+pZN18F5rjHkAWsh1J+VHxZTChrF2Xeri/YbRrcNMr5gTRI+s+QNv3yJUbHGo qvY7W5vFiSl1c8++zG4hKW4SFZ0GOUd9PslFH3pILI6IfWnMCrRw3h7MxmrXOLJJeT IKCUATtvCiHeibSMi8iYbDzbnUYgxz/wP0p8pz1tvZll0tiTU4y9FOnjz9jtE4WJAS nsqmFPU5sWgu/ip3k+JNYyBps+lMrssnjBWJDsnYEZ7V0Oht8WeGrQVQT7rbiUfEX1 1SGada6kaEUagmfcskDDQ9CKl0pC9PyxfUI4J1nEMI8ZCCbLDGfxmFNfR7YoKh5mGt Ygj94UPNsLScQ== 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 v3 01/17] firmware: turris-mox-rwtm: Do not complete if there are no waiters Date: Mon, 17 Jun 2024 16:45:16 +0200 Message-ID: <20240617144532.17385-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 Mon Jun 17 14:45: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: 13700859 X-Patchwork-Delegate: arnd@arndb.de 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 51C92C27C79 for ; Mon, 17 Jun 2024 14:45:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1CBF2C2BD10; Mon, 17 Jun 2024 14:45:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A9FEC4AF48; Mon, 17 Jun 2024 14:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635543; bh=sc7EudhJ+/Cu2fPeZrbVPk1U0HTdb44HVHOPZKReBEY=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hj7K4hAZRyyA71WWIYuIWcvPbouXk5LJ1Ao4pqw3FalKxdlf5BsmKD3JLckyxGrDX Wtykcq6z2S2TYX7osZevo6kej9z2aZq2ZaPzt+BFfcmtwnOpF806IcBUqI5RUs8X5h xm4asUIjeiBGmGQIGr8FYy+hIBI7AgKnxTyqD5NhQdJiBU7M4Q7QS21LAQ7I0yjqZK xcbaYuPs6ifEax0M9SgbEdkPHvFSe59Q+72MAXF1a6eaGfL3OVCA/m4RlqoahzcyRn lSGeUhfBrROeCt+0L0hc+sKYBhPQ/Q8JIHXu5ab1S8mWKdO0X+Cc7EBH0X6GLJkPRl XCNU36b0zCOFA== 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 v3 02/17] firmware: turris-mox-rwtm: Fix checking return value of wait_for_completion_timeout() Date: Mon, 17 Jun 2024 16:45:17 +0200 Message-ID: <20240617144532.17385-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 Mon Jun 17 14:45: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: 13700860 X-Patchwork-Delegate: arnd@arndb.de 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 95C89C2BA18 for ; Mon, 17 Jun 2024 14:45:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 87D8FC4AF1C; Mon, 17 Jun 2024 14:45:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75DC5C2BD10; Mon, 17 Jun 2024 14:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635545; bh=P3L8zh+LINX0L/EVopvsKWgqUQ9/y+fl1zRqmHFXnAE=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVpci2ANSps2eeb2F8BBIgi/gp/QexsU37odf/jPXSc15/322MNt3vgSnstc49L97 sJGojkaxhNA8f9e0z6uKbyHCIvs5xUQBBS6C2hdRFnqhLSD74jkPIXhY6hhfiE/q/B LqA7+bVdgRHZTcuktcCCSoIHPsHgHGHuwE91GhSjPMqw6Ux7N9ekgNYyNy714b6FVc TNE26YOz8nhsxYIzVNd2MHgFFjUdD0HkZrtxyC/xzAd9TlXuzOJZGKIrofakxlYWW1 C2yVFChZD5Cqe5tJqb54EpxAjVEOUO/u3lLjzAZyd9J+4nE+GgMuv9XPRWNLMAn0Wc j24zwodbpMbYw== 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 v3 03/17] firmware: turris-mox-rwtm: Use macro constant instead of hardcoded 4096 Date: Mon, 17 Jun 2024 16:45:18 +0200 Message-ID: <20240617144532.17385-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 --- 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 Jun 17 14:45: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: 13700861 X-Patchwork-Delegate: arnd@arndb.de 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 18636C27C79 for ; Mon, 17 Jun 2024 14:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 03947C4DE03; Mon, 17 Jun 2024 14:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E13F0C4AF1C; Mon, 17 Jun 2024 14:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635547; bh=abCGVgPrm6/2lwzY06Zu5nJeF2cfxXJX2oWog4gA1Ns=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=T6NTOYSznVWnAafkYdHeGZQN2Pu+DNMc5Qds/xjGUeTn21k1W57qqlajY3i4lzA8X Hlw2AzrjVsc02FDys7EPh2PEnHmJW82wh6c0Edfz9ccgPkJ19+mCudQ59jMqYZNxl2 K/PyHJa23BMkS3Zb4MVfjsrIgJK8wifl6WP9sxivZQZoq0bwjnPpkCD5Sgz2Us0mw1 jOGxmISc2LXKgS2DD2yGAJnGw+OqTbp31SGMX8RX5a4jKqKKowt4ZxUy7LRx4SXJ00 s6NJ68ExTaW/omqhUs/wEnYSeZ4l5calzp8W4FCo+Q+qbn5K9Y6tSb+qXeRixoH4sM J+edAgtwcuyzA== 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 v3 04/17] firmware: turris-mox-rwtm: Use ETH_ALEN instead of hardcoded 6 Date: Mon, 17 Jun 2024 16:45:19 +0200 Message-ID: <20240617144532.17385-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 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 Jun 17 14:45: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: 13700862 X-Patchwork-Delegate: arnd@arndb.de 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 85600C2BA15 for ; Mon, 17 Jun 2024 14:45:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 7221EC4AF1D; Mon, 17 Jun 2024 14:45:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C71EC4E676; Mon, 17 Jun 2024 14:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635550; bh=RrUCpLbZ35rKlFT6PlN5knW+Mm2b8lbt4N316RRec7o=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=RkPFKGVOIh9YMXDNfXDf/U1NMqZoSkrofER2qT9Jz9bqq8nzsBeZAYUifYk0nNH11 zLuavkaMcfDzzUZcCkf9r5hpZ4MgPjALK4n8PZSzJIdRnsUbAx+YAeD9UBqTAqT28u HktIh0E+v0vMLIUCzGpo1k2rUcrJJn2e3d66ppg3/nY16hhrmqjgiQZbXeQpGioiaj +DHzGA8ZO2ohuD/wYMbm2pLBl2GGQ0fbPesy38Ujjn0w0OvYxIhO4Z+BTlPyUNHpkH jacgod+HAg4h9ZR/7qOiJj2DhmadHBeP833yPn6QR9o2zQb6jqD4NAXHpMnfsvUG2O fMaqSuL6Qg9rQ== 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 v3 05/17] firmware: turris-mox-rwtm: Use the boolean type where appropriate Date: Mon, 17 Jun 2024 16:45:20 +0200 Message-ID: <20240617144532.17385-6-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 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 Jun 17 14:45: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: 13700863 X-Patchwork-Delegate: arnd@arndb.de 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 ECF51C27C79 for ; Mon, 17 Jun 2024 14:45:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id DBFEFC4AF48; Mon, 17 Jun 2024 14:45:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CABB6C2BD10; Mon, 17 Jun 2024 14:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635552; bh=fvpW+Rp0jAo+vkO4GGTt1imbu3nKDZzSdK+Cvt0Hg+k=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q9KKMJ6vZxata64pj4GAZQZCEkNyMhzzh0uYz8Wcux+EDvUOXEa9cfrI3lGVScG/Q tbc83fK+Lj642QeZOROmMkwZMAX6f310jmMiD0jCxjVYjFswpHJC/tQbLUj4uWd/A7 z3J2cKwvS7OZom1bBej+9kO9LrVeAxJr9aYeJ4tycc9rFUSLj1+gpsiV0dsoUH7cBM qNW/UO1zuqLXfhRRN7Zf7PSWixkkLLiT9m6BtfF73Hw76XvYQacZMHkXFDDyn6G92H 5/JGSSBrW9kpzXCKMcJZXXzVN2FqNyhxCvjEAr6OyCA2i9yjTKIyPLzYYyjSIZc4bK SXqpNUyj57J0w== 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 v3 06/17] firmware: turris-mox-rwtm: Hide signature related constants behind macros Date: Mon, 17 Jun 2024 16:45:21 +0200 Message-ID: <20240617144532.17385-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 5ed480ac5146..59bb9245e04f 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,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) @@ -85,7 +92,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 }; @@ -345,14 +352,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; @@ -367,8 +375,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 +396,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 +425,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 Mon Jun 17 14:45: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: 13700864 X-Patchwork-Delegate: arnd@arndb.de 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 63D42C27C79 for ; Mon, 17 Jun 2024 14:45:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 531D7C4AF1D; Mon, 17 Jun 2024 14:45:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40A30C4AF51; Mon, 17 Jun 2024 14:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635555; bh=pz7+0i656dlp2cOr2pNHFfRCsQyVt9jrWZhX07rLn1g=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=HgrAH/cpLFRWyb42BMxe82PEBxFN1FcrytWsBv8y4kGQPz3CErV1PR/gXvlmeli5N jFSwmnHBoTcIRCG8jBZ+UYYgOQQrjDTFV3MU8O2Q031g1nzyFRv2MmFUgraI8uEtUp Fbxjq/OR24WdkmUb4Mz3WwO91f35+nxmFHDkivyVdUQIgCSD/4eIK0pBysqTmMdZh2 M5TCLejeevCFjlpzbVs0n1Bhi+TdCZmm8u9gfDYBO71nP8spAX8OnU5OlSoTisPMSz 07b1ekKPTMGCAoVAYOAggaiwf4Lg559vHNGfpg5Axkmq8dP/C0trCaU6oFz9Y/Vsj2 1yYNxtHCcMNCA== 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 v3 07/17] firmware: turris-mox-rwtm: Fix driver includes Date: Mon, 17 Jun 2024 16:45:22 +0200 Message-ID: <20240617144532.17385-8-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 59bb9245e04f..9c66bda2f976 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 Jun 17 14:45: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: 13700865 X-Patchwork-Delegate: arnd@arndb.de 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 D9AB2C2BA15 for ; Mon, 17 Jun 2024 14:45:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id C24EDC2BD10; Mon, 17 Jun 2024 14:45:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B176BC4AF50; Mon, 17 Jun 2024 14:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635557; bh=K78EqGh64UNDiGNafuP+nEyXE8eNjRdkL1Xp9FwdWJ4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=D5HX5pmaee+YgV3vRvxVxu0fqox3ErT8iSstfN5ekCfKBrsFl441umAS61ek8dklo +nCBw0l9yY7Q7TLwRUnhYfoKG9QKUvD1IWa3ahy1pX1/Jf27wUSmY7MbaQqljfynxM /ZBo8IOkMQ8tm8zjjlo/6RP/Blgzyrgz5rhg3r9BnjRB9mvnotb4UlpawIqwKr+3jz WeIS5XVQKaM97qFaQUZ4E3NAQDyOtnTLMwhSmBMjS/Te34k+qKagEjyhUY4ZpeY0wM SONbCjP+KLPi8KIDH+F3RizQlzgFH/IDXtWIm94Cl6cTIAOtFch6zCnrEwfDhbTlzT RHM0w+2DwyCSw== 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 v3 08/17] firmware: turris-mox-rwtm: Don't create own kobject type Date: Mon, 17 Jun 2024 16:45:23 +0200 Message-ID: <20240617144532.17385-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 --- 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 9c66bda2f976..9c857ba427d0 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 @@ -62,13 +61,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; @@ -102,59 +98,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 sprintf(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); @@ -163,6 +117,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) @@ -177,16 +142,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); @@ -488,6 +443,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; @@ -504,18 +464,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); @@ -529,7 +477,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); @@ -563,14 +511,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; } @@ -579,8 +532,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); } @@ -598,6 +549,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 Jun 17 14:45:24 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: 13700866 X-Patchwork-Delegate: arnd@arndb.de 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 4912EC27C79 for ; Mon, 17 Jun 2024 14:46:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 386AFC2BD10; Mon, 17 Jun 2024 14:46:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2739BC4AF51; Mon, 17 Jun 2024 14:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635560; bh=IPXVcrM6Jn5DU7UPCHjUl2g+3/XK1/wy949jq9Vky0w=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=iO/+fHrsY0gr38j6bRnaonNpwYTN05ko3uaBE3bybNn4kyPbP1HaJp2PlyjjqggP9 PJ9QHjvjPSXXIRbCL04cibv8FIeYItSqUmvxZliwOzOCZqrTCrmCg12vzB1+bnNAlv /OdLdquNrgDx2EfroaWJAb+h4sWKZYB0guQeJd+0F/pfNF6a3A6ymK8U6ISvRxTG3E bbCOhofFA3sS/No3x/J05a6OAB4KzlRXwoFu70fRIZlWcjNk8pJRLWno1CzDztNlYA 8vN2kGaJZOhADAAM5YCDCvB4rnx8m+pkz+Ta4b/G+VLFwV47WvDZC0c6PCSUj7mzH2 Ren8f4F1LyPCQ== 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 v3 09/17] firmware: turris-mox-rwtm: Simplify debugfs code Date: Mon, 17 Jun 2024 16:45:24 +0200 Message-ID: <20240617144532.17385-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 9c857ba427d0..77fdd5c66971 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 @@ -406,39 +405,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 @@ -503,11 +486,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"); @@ -531,7 +510,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 Jun 17 14:45: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: 13700867 X-Patchwork-Delegate: arnd@arndb.de 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 AF7C2C2BA15 for ; Mon, 17 Jun 2024 14:46:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id A20BFC4AF48; Mon, 17 Jun 2024 14:46:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91876C4AF1D; Mon, 17 Jun 2024 14:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635562; bh=XewggOxf0J4sZug5qVvIcqxtdUZ4VRaB7T8zPOqw4LY=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbNZoyjKydJvRMLiMCs5qlBlmdxnxyNNdVtoUzXjMyckMPTyshrpR+lmx8PVz9qax pCI8NZRbTZ1Z2g03pgYwxVg9z3e7ZTV/qL+S6qiHWnBCpB+7eSxV4Xhce7JmWubTQU yjnVIyjtqt4v8VO7lGQH8KrcAUrSk2lgGPoXt91OOAoUlXeqR8PgcU8rCyOrxYvOtG c6xt/y15PdQR60ZVm+JXrMzTC/ABem1nM3KAR45/xHXoOMmPrgu3vH6brF1M+5G/mK dk1pkOvbsvz7VeWXjUVok6vGGM+DRbsw92T498aicHIQS3X9PgjCCUX6pWcg0l6BVh kgtaJiktvSvyw== 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 v3 10/17] firmware: turris-mox-rwtm: Convert rest to devm_* and get rid of driver .remove() Date: Mon, 17 Jun 2024 16:45:25 +0200 Message-ID: <20240617144532.17385-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 --- 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 77fdd5c66971..9a68784a9619 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -426,6 +426,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); @@ -463,6 +468,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); @@ -473,7 +482,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"; @@ -483,7 +492,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); @@ -500,17 +509,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[] = { @@ -523,7 +521,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 Jun 17 14:45: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: 13700868 X-Patchwork-Delegate: arnd@arndb.de 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 29F16C27C79 for ; Mon, 17 Jun 2024 14:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 175B9C4AF48; Mon, 17 Jun 2024 14:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0716DC2BD10; Mon, 17 Jun 2024 14:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635565; bh=af5nHrY+O9vceRQiuHfUUbh4Q1ap+nLXCKNlbA24ZFA=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=IAyB3tpcUGzFHojgKZh3TdlKvLe0KSc2TU3I2NXRHLx0n2qSpr1umH3CxpEb7eBsO xcspl5nf4FHRtLaTuOW1Fb6Ey3aIPIXypiGI9/wxJSN5QdjEAycljzb4QoAB2JnWFa swL7nLfaVvpSa0eU9YDTo/uvaWqayuISNjEdwC58mqvHw+TiXmj7JPumbox04Jr8KN T9M7x/I3a55x2RLaAYHrz+KEakYXzPBjYpCrI0YkxfDQt5vk1EcZnKrXuhxsfsXD73 CFYCfAkbLm7cUFc73iOgcfF4JeI7PdwRCVK8YDA421vu97oDnRp8ikaO164nBgz9ar D/PteUcZRe44g== 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 v3 11/17] firmware: turris-mox-rwtm: Use dev_err_probe() where possible Date: Mon, 17 Jun 2024 16:45:26 +0200 Message-ID: <20240617144532.17385-12-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 | 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 9a68784a9619..397175fafbe0 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -460,13 +460,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) @@ -490,10 +486,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 Jun 17 14:45: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: 13700869 X-Patchwork-Delegate: arnd@arndb.de 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 97D86C2BA18 for ; Mon, 17 Jun 2024 14:46:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 807D6C4AF48; Mon, 17 Jun 2024 14:46:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70442C2BD10; Mon, 17 Jun 2024 14:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635567; bh=CQPS0TEQajBleFkxswdiW1wMbGSGeV3Womaa40tIEPw=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=XPYLRuUjr47xeyYH5YqS0S+6oxqP4mxXSfO0Yg1/YEvtyC+TaH36QhUWdSQ4XOZNM iodSbBYoszmevGV8d3Dat4FB98zNy21vydnZ6WdOPFl1tQh2kHnXNQtP1hayOeRrdR KjWtC/wcoYyClzVkR9EPYrh2mbvdWGr8dk73d2gXyLRHPCSBTF9Smvkqpiw23fcf0Q 0f09ZBGdMeC5HLxNUwmmwKDmIym0wrmDo6sZk4GqdI1WCrYfuBhiSlSMqImEXrm30E /Gyl8oiMESkURHnRbp5rEETUEMl3E6RkUUEkr1V1Yg+HYffTd+SR53pBBwA+Yv+M7Y XE42Mmlm/TkVg== 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 v3 12/17] firmware: turris-mox-rwtm: Initialize completion before mailbox Date: Mon, 17 Jun 2024 16:45:27 +0200 Message-ID: <20240617144532.17385-13-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 --- 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 397175fafbe0..2c43af69783c 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -455,6 +455,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; @@ -468,8 +469,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 Jun 17 14:45: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: 13700870 X-Patchwork-Delegate: arnd@arndb.de 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 07524C27C79 for ; Mon, 17 Jun 2024 14:46:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id EADFEC4AF48; Mon, 17 Jun 2024 14:46:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9D8AC4AF1D; Mon, 17 Jun 2024 14:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635569; bh=hp9iilqHl+n6FJlxywW0cGlXCBexEwsA60AfGXJEU+Q=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZzW8wwg7Qbd1YbNRzkmKf50as9cDQVIGN9CBCOQj+6JR8J/7x+lsjrKkML5ErW1dt 0Jnuye2K4vBi3EW30yD3DFe7fGV2c5dKcyWwxVOQADLIecnXVTSY+iMkRt+/T8MsBi xqEvTCnI3oV8yf2jYUXt3raogWPz5KNPYo8jcpjelJNfPffs6Qo11dcDbxuHQVDiIY 7Z91WLpKWjEMuogrxIvv7/V2rGb7LwjlBVYrZ6f93aP0smZrbML9dkimwL7ODeCyyN YorMbvXJ8yyLKeaCuo1985hdSb79WmNrhfCjRY8MZvgmmXm2E/6CillKy2evAXPToT ZvDqKQ0K+tvTQ== 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 v3 13/17] firmware: turris-mox-rwtm: Drop redundant device pointer Date: Mon, 17 Jun 2024 16:45:28 +0200 Message-ID: <20240617144532.17385-14-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 | 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 2c43af69783c..0b93040167b6 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -62,7 +62,6 @@ enum mbox_cmd { }; struct mox_rwtm { - struct device *dev; struct mbox_client mbox_client; struct mbox_chan *mbox; struct hwrng hwrng; @@ -97,6 +96,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, \ @@ -165,6 +169,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; @@ -179,10 +184,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; @@ -214,9 +219,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; @@ -418,7 +423,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) @@ -446,7 +451,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 Jun 17 14:45: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: 13700871 X-Patchwork-Delegate: arnd@arndb.de 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 79B47C27C79 for ; Mon, 17 Jun 2024 14:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 6A0EAC4AF49; Mon, 17 Jun 2024 14:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FE10C2BD10; Mon, 17 Jun 2024 14:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635572; bh=FYDQKufeAkmsjfLsNXBHdJptY6sZxFh8giyLiM5VDZo=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0SsZXL5Vee749VWcTkCTirEntyNqIIXX6xM9N46lZyfMVrPKP9kctScre9dtNtud pnNdLXOA7HKhJmIjieYo7oGlOd9vrXphB3NVHQol6+47CYz4ly371QP3mJDY7lvqSF baZzy1A+nTSUS3LJZ4N+cE8cgNVIf/UGFrVRlLYB3QNPUdiw/z0w2XaJxiXg7S2XDh /uyOO9Gxi7vpBFjfLCHjPG/2510N4es/EwadWJOc303DrszZwoh9Uz3D0m+61vKlXo pQTbcLdYhq9FYXBtM98rzlVzcIBeUYFdR/BM5BwBHRdB9gdu0qQwKow/rsdkXgWoNN GnEqT/ig4YZgw== 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 v3 14/17] firmware: turris-mox-rwtm: Use devm_mutex_init() instead of mutex_init() Date: Mon, 17 Jun 2024 16:45:29 +0200 Message-ID: <20240617144532.17385-15-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 0b93040167b6..5a850dc27fe3 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -458,7 +458,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 Jun 17 14:45: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: 13700872 X-Patchwork-Delegate: arnd@arndb.de 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 E527BC2BA18 for ; Mon, 17 Jun 2024 14:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id D36D5C4AF49; Mon, 17 Jun 2024 14:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3085C4AF1C; Mon, 17 Jun 2024 14:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635574; bh=CIb1ugDZLJlNiMHju0VNi48nJ7pg+VXzTe97P45Z3nM=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=iRPY4TRMztd55cuP4t8pMToW7pZdp9pw+Hxz4f61+//yUvGnETBB6aJPrJweFqhNm VLfE/wIJutcOGAQrz6Uhc5jch7jD3deuvNuTHeIVNVHofskoZJUGQDWEJgpZoY/OcD iwRPiOYFFPVy1BsWPlcBTGirMwfzrh4B5T3kvAqqkIPSRTnwvmLRoNem6gQk8eG4Sq JmyYk6s6FAjuoa7qGkHSciJs54dXapUZjLdIgEg1XG3M9AGNbzkdkveZzcLBI54DNC K2tXlcltShESTAYV+JgZ+cUvdi4S26wHIfMC9u56T4JPiidJnAd+rjuuS3WY0IebDA Xn1Z3Eypre78w== 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 v3 15/17] firmware: turris-mox-rwtm: Use container_of() instead of hwrng .priv member Date: Mon, 17 Jun 2024 16:45:30 +0200 Message-ID: <20240617144532.17385-16-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 5a850dc27fe3..135adfa9fb1f 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -260,7 +260,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; @@ -489,7 +489,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 Jun 17 14:45: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: 13700873 X-Patchwork-Delegate: arnd@arndb.de 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 66678C27C79 for ; Mon, 17 Jun 2024 14:46:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 4B1C8C4AF1C; Mon, 17 Jun 2024 14:46:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38714C4AF1D; Mon, 17 Jun 2024 14:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635577; bh=m9Ap4DRQXDlrhv05clTlujfZTHJ87jS+3h1ZSvaZPyw=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLDpKuuO5Dhqm7hMiYcy+lEEaMhQxXgYAilrhY7iAVBHEmEOXQ9tXLwitS9Q1gjmV jm0lUcMIa7NrhQyTERtyiYMFV44kerHiSX2h3n/mvuGJZHBZD+5DypmJedrnrIPDN4 5g4bfcLdqRPU2yHY1ZcFvOXyxTB+dT9LWKSMFi4QR+FVvo6OxnK8gFpXFaXPkgzlcN yo3WB/nMer9in5ppQeeq5oN07tDySnv9J6tJ5QCdgJz8eN44N3bwcR/4SF3JNAnSfg qHZM5Lgn8gTH5xlMts01CqW7ECj/usS9mvv8qVjz9gNaAgmhj/wLPotlKc/ekfuCjD MXfMgZxDvoJ2g== 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 v3 16/17] firmware: turris-mox-rwtm: Use EOPNOTSUPP instead of ENOSYS Date: Mon, 17 Jun 2024 16:45:31 +0200 Message-ID: <20240617144532.17385-17-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 135adfa9fb1f..9197e0549c6d 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -138,7 +138,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 @@ -186,7 +186,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) { @@ -220,7 +220,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 Jun 17 14:45: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: 13700874 X-Patchwork-Delegate: arnd@arndb.de 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 C9469C2BA18 for ; Mon, 17 Jun 2024 14:46:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id B54C7C4AF49; Mon, 17 Jun 2024 14:46:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A47DBC4AF1D; Mon, 17 Jun 2024 14:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718635579; bh=929W9SWRjwBkQhWkBoC5dIaM4uataYjRxnE8h3e+m3E=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=qEQmRjHwa3u5hDlejVPV/Xkwve4PMzTiHl27Sn25S6uOUK4+SvzFhIxDs2OMU+oX/ Ce3erP4nuG/x+bn0hoKb24Oue6clqPXNnX1R/l2j8LlV+WMzSsqtUCx9e49aX1fm8n um3f0yAmKjW+qdNu7lv8YMm88iY7RfqwGPVTWBw2KG3tEAY29FYK7ji9Z77wxyCco7 TAV5AHZTGER1oY0gfg+JY89nG9Q+8dWe0iKZd3IbNmyleo90KWH2weqz9i8RBcmKkr ZaIHMGczjet73i0xJAyfO1H0u3CJmJ1TQ+yC/U4mP/1cRbFdWiUkv2u6gYk8ZBXYNE DPKe4gFzd+iNA== 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 v3 17/17] firmware: turris-mox-rwtm: Deduplicate command execution code Date: Mon, 17 Jun 2024 16:45:32 +0200 Message-ID: <20240617144532.17385-18-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240617144532.17385-1-kabel@kernel.org> References: <20240617144532.17385-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 9197e0549c6d..52e5cc1cf48f 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, (max + 3) & ~3 }, + }; 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] = (max + 3) & ~3; - 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; @@ -334,7 +323,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; @@ -367,23 +355,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