From patchwork Sat Aug 31 09:20:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785977 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 D9958CD1293 for ; Sat, 31 Aug 2024 09:21:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id B2F69C4CEC8; Sat, 31 Aug 2024 09:21:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA3CFC4CEC9; Sat, 31 Aug 2024 09:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096060; bh=Abfd6J238robHdsfA+mAo+HtZEUoV4Xe3/uHVf1Dd3U=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=nF7pMQ8BD3iplkCYTqQvrnL6VGdUT2QPtjVAzq9ShFZWUjbAuJaibYtKWoTsFvRdk qkTtBilEXtkKUiip1VkHeTQsmBc1AcEtK9qU37xPqhjh4x5FPhr/olKWxhQemTMfEC 2KpYz+/VY2Pl8FX6LxMyLf3jSHoV1B1zLLOj6Sfm6Fy3C2TvkVnh1v8l53InxbetLb irHpvjF1N+yWUTDyJEKls5tlB6JXkw3hf/RXbk/a62z0bLZIkAmFaHGRsk6y1NakiF KrJqwlotYfpYH8XwFGULInep973IUidtztUexbAWVyqC8j1thNnGhK2agX1LC3GNeQ STXGSnUaFdQAQ== 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 v5 01/16] firmware: turris-mox-rwtm: Use macro constant instead of hardcoded 4096 Date: Sat, 31 Aug 2024 11:20:35 +0200 Message-ID: <20240831092050.23093-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 3e7f186d239a..67d7b65da174 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 Sat Aug 31 09:20:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785978 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 30CE1CD1293 for ; Sat, 31 Aug 2024 09:21:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1ED83C4CEC9; Sat, 31 Aug 2024 09:21:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1668FC4CEC0; Sat, 31 Aug 2024 09:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096063; bh=1I034L4LLf9or8F0uskNWOW/awQZlwNsmaQxnhu9RK0=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=dIU0akJ/rw4csfbTNcG4OL7XcNbKsI73eKwi2TthWaaLGnyQ4UFYKZAOzjw+htgdN 263IT5FD9EiW0xKoKKT+xkB68rF4dWfNmoHqWOGIrVm+94JnxjZDYqcl2fJwgLqaJP pIc6MVihsRFr8fvWjK7gHuRze64XSicdUEHltxUWZW3B3DcrO+aBVex3HRKGmZI1BF mGuXjhB61Vdvy5kZgx3DK3ei2sAlwmjf5kh+0vMx2+yyb7IPrfAMe5Yvo8nhTISOqT pK6/GecHWzRDX/IU8o15djrD6M/op+RkRuUzwCwDCJW8y6pari75y5MZij7eTvaPk4 fQxxu3NT1yjRQ== 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 v5 02/16] firmware: turris-mox-rwtm: Use ETH_ALEN instead of hardcoded 6 Date: Sat, 31 Aug 2024 11:20:36 +0200 Message-ID: <20240831092050.23093-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 67d7b65da174..d3ce093d4835 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 Sat Aug 31 09:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785979 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 90923CA101D for ; Sat, 31 Aug 2024 09:21:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 7F46FC4CEC7; Sat, 31 Aug 2024 09:21:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7670CC4CECB; Sat, 31 Aug 2024 09:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096065; bh=iAZ6bIn+WN0rB7kQZOlw9v8V713pYkJzGxek3pkoSX4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ItIIsvmjyr9LKF5S9W295eiejNSDyOamHEMP3cicTOXJho4jQUgEy/8SNSS0z8JiW b1Rpu0jzDMdoNR8W6eQfiEwvMwiQxbj7oVQRKC/e713k3pSz8zALNIT5AuzPpV3Q5N LbWEj68PTIT1HOPGbe3WSAASknf+sS7mDPa98WzuXGH3lBFlQaNm+imyAT72lb9j/Z pdVa6bgWbFnq/iNYmuAZpp8M1LGhMukm7llssAMrN/P2QQs9/2wW8oboqdx1G1nbTG oALiSH5nHyqkEpgBbVOWOnkWkqEKCiGsg81CDoEHfXToK6fqX/EvNBNJasacgoNcof sB4qPLSRX3lRA== 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 v5 03/16] firmware: turris-mox-rwtm: Use the boolean type where appropriate Date: Sat, 31 Aug 2024 11:20:37 +0200 Message-ID: <20240831092050.23093-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 d3ce093d4835..8875c35f9b19 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 Sat Aug 31 09:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785980 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 03817CA101D for ; Sat, 31 Aug 2024 09:21:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id DFCB4C4CEC5; Sat, 31 Aug 2024 09:21:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7072C4CEC8; Sat, 31 Aug 2024 09:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096067; bh=AwT5qzxhp9vQo1GlsE1SlB7a3vvarFYBTj9yOuK6/iA=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8QZzeedWqfWgdPXplTYnwFIDjRI7dihxVXzRFRK5CZUKf9RsGuoq9NwbzXywJYL7 P1JSJ7sAsqeAMaY9kcF13n4k7oRYTORq62rOTUrkQCbMLT8AUYFDrSeYwVQJtvFkgO WKijPh516iIub1HwAJB/M4UdCI46Z9D4xdCZI9/XhdgYg0+XSV1cYDZv/Dpqw6+w4r +Or/yRK+jLkYfAqD7jmpv5niV5U7YXpIQSo7Ydv9DVd7oj8Etr1bACsqfhGKm5TwSB rkqWOV0tlWIo34D7L7fKRKpR/heKWpi1VrzBss7Fr8IxMvIMszY9x7tHOu5SObDBwq RftG3BjrSY13g== 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 v5 04/16] firmware: turris-mox-rwtm: Hide signature related constants behind macros Date: Sat, 31 Aug 2024 11:20:38 +0200 Message-ID: <20240831092050.23093-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 8875c35f9b19..cf8c605d99ef 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 Sat Aug 31 09:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785981 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 5A7CECD1293 for ; Sat, 31 Aug 2024 09:21:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 4C082C4CEC5; Sat, 31 Aug 2024 09:21:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 432B1C4CEC0; Sat, 31 Aug 2024 09:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096070; bh=SprDeKaKZM3BNc5A0mxv+mHWFnXhvCaYNzKPcz6ZuEU=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=bN42+lU7NzCf8gfHQaA+UphQ9iM1oW6tcJeg1IOf74lj8e0MOOUDbY6RgBAGxvGMb 1Y5KsLrVX35eHW8SxnZwfOAYlS5isfX/8w1A1t22qv3kbfkPWHts4jsx3oJlyt2MPx fQoAIXJW9dqRyDZSFp/SJys59mDg2o7axWae6v5fONJW/vXVin1RfuBewKwycc5BWf IlIoKqupEL60dF6Y5OO4x5rnWHHknKTADEtmt8lrw9HffBtOu+hsLlF2ojqlRJ45bd IkfOyKQdjdbC5j611Z+23TBDHkEeBkl6vFNYURRAUlim4rLU6WdYr/3UPkg3ElEC3r oWFCxgLElmjDQ== 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 v5 05/16] firmware: turris-mox-rwtm: Fix driver includes Date: Sat, 31 Aug 2024 11:20:39 +0200 Message-ID: <20240831092050.23093-6-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 cf8c605d99ef..ca1eb1687d44 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 Sat Aug 31 09:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785982 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 C3AEDCA101D for ; Sat, 31 Aug 2024 09:21:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id B724AC4CEC7; Sat, 31 Aug 2024 09:21:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A35B9C4CEC5; Sat, 31 Aug 2024 09:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096072; bh=QOYrXpy2pmCBbkyC+LvWvL/9josV+fUBW6pQ3TTjIMc=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=A6MZZUwrQW4aCVfpZS6DfnpheL2urClIWIMmqR2t9ORM+l2SgmssIPHldZlNWDDX3 gKUTgpEIAMS1ntO+E8iTFsN/jYWrFCCk7PKNwImZlkdlI4IsilRGcVcTjrjEHRKPZX SKpMy2J47dbGx/rGDI0KWGwYDBp/8wfBCklXLyczvcEu2C31A/CLGezBs5NjYJzktk abtOs09U5b8Jz79WKEjjBlAxGp7aZ1FcLgSikcdxyjhi3qvyQoWbZNcHnCnwuh1hAh d/ulQ3ufvXu9YUokpsqJpb1uJYLlCHvIILslmWwE2DdHDGSF9+8B7DeBGmp9yxi3/B eR65ZOTc7/5og== 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 v5 06/16] firmware: turris-mox-rwtm: Use sysfs_emit() instead of sprintf() Date: Sat, 31 Aug 2024 11:20:40 +0200 Message-ID: <20240831092050.23093-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 ca1eb1687d44..8923c4cabcd0 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 Sat Aug 31 09:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785983 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 32659CD1293 for ; Sat, 31 Aug 2024 09:21:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 22214C4CEC5; Sat, 31 Aug 2024 09:21:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19B17C4CEC8; Sat, 31 Aug 2024 09:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096075; bh=xauxMrGMnMgZUeN2QbW+ZSHvzAXrMw35f+LCYFoyFm8=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=FtBJqn7j3YsrWIyJEco2e6xuTtcZmVsInFmsHcZmXQQuW5BeEbD+sRUtOa12AN7p/ +NIBP/rLW87daGgw61pBNetweGNV5FAVfrx5H5eTGGz6g2tXhxmQmUUPqrPIgV9ciz GBo+SjFHVIsH+lloJFwrNUZhLWBk84xUjitJsZAXMAkevc1nCkrFRRioFM1yV32Wyy /nE9DV3HceAKPN/yLAa6eGyaDxCTlZM6pf8T/cSoWyJKaLqh6bFqJ28/2fSM15j/sq GmxG62lyIxm2Kn9YwII/vQGxB8+FPr7fJd2t71iOCQFLCEjN5SdTufWVUBNcgkUyms H4HEXeFHqellw== 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 v5 07/16] firmware: turris-mox-rwtm: Don't create own kobject type Date: Sat, 31 Aug 2024 11:20:41 +0200 Message-ID: <20240831092050.23093-8-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 8923c4cabcd0..97b40982a3e7 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); @@ -528,7 +476,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; } ret = mox_get_board_info(rwtm); @@ -560,14 +508,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; } @@ -576,8 +529,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); } @@ -595,6 +546,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 Sat Aug 31 09:20:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785984 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 985E8CD1293 for ; Sat, 31 Aug 2024 09:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 82EA9C4CEC5; Sat, 31 Aug 2024 09:21:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79FA5C4CEC7; Sat, 31 Aug 2024 09:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096077; bh=XY9/bsfo6LS1W4K5qQLLhTvcREhj+N6mql29QGQClgg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/vWnI7VznqDa1rwskHQmfkF90sFClAZ6P8rGfbS3CkJF1IFh11sNPGx806esTjat wBkvBF7bhhTya14BeMsd0re8esjrCHyIJlEGRxXfA8f3YdxpdktXg0Rnsh/BMb6n81 j1aGZO+LbzpF4xwiB6kZ7zaw71Xv/z4EOU0KKVj9wQIRlZkLGOJiHYw4wTXCARf6lB Wlroog8elJKB83TIHRiYhfW0YrbvFRjvo7pWWacQ4KcXTTfppe+dp02FAj+8wxb/Lh t1r9bVtVAWY8Y+uRT9vtBEGBSnggEj+RXTWcu6FsrLfB4K0OP9IIoVS2h8aHtUY11s uuhzZkmZG5rkA== 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 v5 08/16] firmware: turris-mox-rwtm: Simplify debugfs code Date: Sat, 31 Aug 2024 11:20:42 +0200 Message-ID: <20240831092050.23093-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 97b40982a3e7..0462c345778c 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 @@ -500,11 +483,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"); @@ -528,7 +507,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 Sat Aug 31 09:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13785985 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 EFFDDCA101D for ; Sat, 31 Aug 2024 09:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id E2D1BC4CEC7; Sat, 31 Aug 2024 09:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA8EDC4CEC0; Sat, 31 Aug 2024 09:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096079; bh=NQryTML5jdSBcx2G6HYZdjf8LG1gasfjM7xFkLaZRnE=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=F106tJvZpJ++0HD/HECBAjT9NcEMrUVIake43pJdPbd9z5y3LGWF8vUMw9bsYqDBu Kg6irowqG2Lbu/bImAJSQinXgMmEhFL+G7GISRi8tJEtSNjedVOoSDvFv/CDlbDVL6 32WIQS/dcNf9oYY6RQQn3naahA+RD7Sr7/OY7/I3KjY3jsv/iQ105LvEsmg8yQnrrb SqA3LL8fMT7ELZOOhNKEtLfuD3a+cqyPHQ3egBMbA4Istn/vtj/oa5/FIHglIaypSC G6BK75qTUUtbgqTqPQHQH2iPrd1uPU9oiTmSZfpsBNgrniQj1HnQcYeBbPXC0RfkDq lXexvuI8c2iSQ== 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 v5 09/16] firmware: turris-mox-rwtm: Convert rest to devm_* and get rid of driver .remove() Date: Sat, 31 Aug 2024 11:20:43 +0200 Message-ID: <20240831092050.23093-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 0462c345778c..dd0dbaa9de72 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); @@ -462,6 +467,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; + ret = mox_get_board_info(rwtm); if (ret < 0) dev_warn(dev, "Cannot read board information: %i\n", ret); @@ -470,7 +479,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"; @@ -480,7 +489,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); @@ -497,17 +506,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[] = { @@ -520,7 +518,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 Sat Aug 31 09:20:44 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: 13785986 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 5CC02CD1293 for ; Sat, 31 Aug 2024 09:21:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 4F7A8C4CEC5; Sat, 31 Aug 2024 09:21:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46734C4CEC7; Sat, 31 Aug 2024 09:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096082; bh=JR9ApgNuHbv2NGYPXh7+aUFxvoqTkluAm9nDSKFhru4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=eb6HCimZjUM9UkdpZAW1jwcn1GgVAjiubRJ2V6jhuBQlkNJUj2ybLswHi6F0hpdsj Xdu8BpubyLYXVvzOqe0xmz9Z8y+aHMYY2ji68tqGqmQf3JNcoA/BsSKALaqj08ahbi 5LjeMPXGTCHVkKSvp2wNq3CKT39stOv3zGw4xn4mX/7dDXlRVE2cjjL2PbINNQB+TZ /TAU/SFagtFzm+kdtDsvG8FWhtltRt/ib89fQlYEhJaODzEQzlqI9ksK6JXjr87ezt rF7XB/86uSEXSIVGiUyrDQ3pE8ucH31LkG2pL4Ulq5yLJ+3UVbuf1SAzr4dWUnRgzJ 1hoVCAlqjhG8g== 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 v5 10/16] firmware: turris-mox-rwtm: Use dev_err_probe() where possible Date: Sat, 31 Aug 2024 11:20:44 +0200 Message-ID: <20240831092050.23093-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 dd0dbaa9de72..f291df9a72ff 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -459,13 +459,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) @@ -487,10 +483,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 Sat Aug 31 09:20:45 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: 13785987 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 BE50FCA101D for ; Sat, 31 Aug 2024 09:21:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id AFEBCC4CEC5; Sat, 31 Aug 2024 09:21:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A72F5C4CEC7; Sat, 31 Aug 2024 09:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096084; bh=jbqAfRXeCbJK3CKZJ1Pv0ED1fDxWbljUDKYPCI6fzjg=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=cHNgLMWjwz0TpznoNLFlYkHa2qjCyh2ez29x3s/A+6ELwZDKhhLC9oO4cOnM1DZNR d7XjxLVwaoRLZBfBA5HK8h7XMFK7A5L9i7oOgFSNTNhI/z9uRpvQBZkf5ZLoiOdj43 0JYiNfCHDuVQIrqVtGSNDmmP/a8mfRgRJ2GjTMnrW9s0nSZZuxyPMcsjp/cAx6Ttd+ B+1odkGirtlzg6MKmYMdSMnWr32Eot1hyWebtt2eBNYKJ17W/JtgQZqnXzmTZh9on0 IOSxJO8dU57whEdXkomPvnWaink3h4a7rwsHOsOEfL5NcIikwByZzdLeYsi+wcwiXI ZsKCIWZ6y1lyg== 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 v5 11/16] firmware: turris-mox-rwtm: Drop redundant device pointer Date: Sat, 31 Aug 2024 11:20:45 +0200 Message-ID: <20240831092050.23093-12-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 Sat Aug 31 09:20:46 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: 13785988 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 29AC1CD1293 for ; Sat, 31 Aug 2024 09:21:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 1C4BBC4AF0C; Sat, 31 Aug 2024 09:21:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 134F5C4CEC9; Sat, 31 Aug 2024 09:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096087; bh=Z85ohY/TriR5MifQgfR1EPcpJLeH2R08PF6O395cHGw=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=OHGm+iFTWV/Fny3TiqAqZ8g87fEw0/wexXUQV3he3x4An/ftBou8XOO5YNwxaDs7w sI6oA/lx+XbvxMuffGgdW8Q0R9ExRqffJNOgg+PpUBnbauRMUJmaPrGR2W7uJ2tFgw +9QY3xcEHtBCAN7nU0gwY7RA9TDS7k339OkMP/7kkX8jRUVFrPfEe7dqyeXqEbYZzC MBIGhfR44vrFWgxhu2iIr/XoDJa+piO/gtBs3mVAGUSRfDDH5qA9PuYsWMEKBe6bmz Zz0xHT31kg+YZj3kg7jaRkNhSbif7lk+zkmtzwELlvCPIUYAH83OtDW6o3WMemW8rl 55GlXtGBAYqKg== 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 v5 12/16] firmware: turris-mox-rwtm: Use devm_mutex_init() instead of mutex_init() Date: Sat, 31 Aug 2024 11:20:46 +0200 Message-ID: <20240831092050.23093-13-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 Sat Aug 31 09:20:47 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: 13785989 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 92847CD1293 for ; Sat, 31 Aug 2024 09:21:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 7CC61C4AF0C; Sat, 31 Aug 2024 09:21:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 739EDC4CEC8; Sat, 31 Aug 2024 09:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096089; bh=kZlRiEZGYaAz7Vl2Ou2b/HAdFUAXeMbtadH/7tYtf1U=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=E9MYiQ5eDX4J9QWFVdxKI0aWZ8HqfZU0cIZzKIj738QnjDOOct2M7nCWkshLR7Y2N tVGE0uDOUfruVvBc9OLJChG6mOZD4dAF6GNpxOlG8t5GVqOaP0Mr3YJOAChmsr3Nbk U6eWgjTWmIiAOxBsjsH0vlZc2OJNIZDdB/ifyIf3NlP43whNcArxoxX8tyKSikdKuQ G1dYMyAYOK2Do8gu8XmfNplajAG4CRQu9FpYc4hT/8EupwBB/gmWFx8EVybrzHjg60 is1HazkOO6I8CZpHYnVa3HrH/7//W/iQsETX4dtjTQEF9dKKAWsXE6M5cpPAK1SttR l//vI5sU48wrQ== 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 v5 13/16] firmware: turris-mox-rwtm: Use container_of() instead of hwrng .priv member Date: Sat, 31 Aug 2024 11:20:47 +0200 Message-ID: <20240831092050.23093-14-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 Sat Aug 31 09:20:48 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: 13785990 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 E8661CA101D for ; Sat, 31 Aug 2024 09:21:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id DCCAEC4CEC0; Sat, 31 Aug 2024 09:21:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D45F9C4CEC7; Sat, 31 Aug 2024 09:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096091; bh=fZXp5znfN0w2WN+UlYs07thNJDMXh+5ZEjk8LG8Hru4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWCmo/SUPrjaQbDNNSRYHUKFu0qzqsXDRFULweViPBp/DxX+CymjsbDVnF8Ew/51g OVG8URY+mkpIdH+yEPCf3jSTGTtd3Da3Qbf5rVNUwc8H4/y/Eqnjf0f3ufaJLAeMf0 DzcNR+GD8M5y1FxMZZmXTytwstxKiXsGH+tZUEKv57EUVQud7moIby2Dnw7aYPPTqb x+bb6FihjFqCic3bB/qwbXj3Oiu9d3JIBqV+niZzUmjg3NgdtoXtzlIOltulvVLc9+ 1+LZCJWiOR2ZYmg/OR7xQrY8mVUTb4R96ST3GXWU5sjvTRiATjiAB1ifYWDtesFuQE bkoArSCsNZgmw== 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 v5 14/16] firmware: turris-mox-rwtm: Use EOPNOTSUPP instead of ENOSYS Date: Sat, 31 Aug 2024 11:20:48 +0200 Message-ID: <20240831092050.23093-15-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 Sat Aug 31 09:20:49 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: 13785991 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 57395CA101D for ; Sat, 31 Aug 2024 09:21:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 497E5C4CEC7; Sat, 31 Aug 2024 09:21:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40C70C4CEC0; Sat, 31 Aug 2024 09:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096094; bh=8BMIGuOiKNipiQV7zt2ZZvMZ3wYh4xdIWqHGjkxp12s=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=NpbCJmHQapth6GWzEEe7iOcLdIuC5NtXGVkNNbBin213ym+2cjnuSzQLvSGAM72MZ a4CmSxkZDkK5vJf+oRIV4ZrXxl/4TNRLSdumgfVJA2voO1YfD6jc6sTwvHDzmSR+OI pM/AszcBSo8ZR9jnRUcKPpJgoWQhu03WQVVezCm9aIhu9Omc+9kNGLVYHS/B8+VEhY JCxQITxtuUZzctLefd0+TqCiEl2YKMu+IANkBWwPM7+CZYJV8PjsR3fYm6dwZJVARl V3MQ1JwYn9EN54F99N6WTimjLrQLpusjl+ZitTMDIjPdY6WlWM1JDLnAe7bKGpAfVa WuAtWJ+7j4qtA== 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 v5 15/16] firmware: turris-mox-rwtm: Use ALIGN() instead of hardcoding Date: Sat, 31 Aug 2024 11:20:49 +0200 Message-ID: <20240831092050.23093-16-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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 Sat Aug 31 09:20:50 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: 13785992 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 B5615CD1293 for ; Sat, 31 Aug 2024 09:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id AA1F8C4CEC5; Sat, 31 Aug 2024 09:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A12FDC4CEC8; Sat, 31 Aug 2024 09:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725096096; bh=ra4UQDdEcA4b5Z3A9nyljWhOjo6TN9B8ZBY2ZwYX6gI=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=ryjCRdZX+CdOO5ijgk66V09Mc9Ad7zOh7m3sQXViB4UjoW7sKpR+lu+uj+FPNEWB7 FvkQzMdX3MlX7YgdNnuotquQfYPUDuE+Tcxp1LXPl49N5Y/JGG293WlNLEjaqY6Lo/ XMcfbxC3a30G0mvAblFkq+m+Lc5x/suOCDK0T3KpLSk1oGvqUuXHt0p+17KGeGfeMk lOky0trjvJ08eJEWdulugSeNbSKbtBWhZoiXnQOIEOT7ZVCeVp/Vzcy3OjuzKeepb8 7HBh/Z8wD4R4J4NeCyy2c3bSfzoR/ZLnhZs99yj1ccwd5r7H22LKdNn+gJ2ntTffB1 52wJZ3q8yUbGg== 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 v5 16/16] firmware: turris-mox-rwtm: Deduplicate command execution code Date: Sat, 31 Aug 2024 11:20:50 +0200 Message-ID: <20240831092050.23093-17-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240831092050.23093-1-kabel@kernel.org> References: <20240831092050.23093-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