* [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support [not found] <20261113034213.158390-1-prasanth.padarthi10@gmail.com> @ 2026-11-20 17:44 ` Prasanth Kumar Padarthi 2026-11-20 17:44 ` [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider Prasanth Kumar Padarthi ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Prasanth Kumar Padarthi @ 2026-11-20 17:44 UTC (permalink / raw) To: srini Cc: robh, krzk+dt, conor+dt, joel, andrew, ryan_chen, billy_tsai, neal_liu, tan.siewert, devicetree, linux-arm-kernel, linux-aspeed, linux-kernel, Prasanth Kumar Padarthi Hi, This series exposes permitted AST2600 OTP data through root-only NVMEM for userspace diagnostics using raw offsets. It adds the SBC NVMEM binding and a read-only driver adapted from ASPEED's downstream driver. Changes since v1: - Add the separate binding patch and rename the driver nvmem-aspeed-otp. - Poll once after a 1-us delay; retain the 100-ms timeout and log failures. - Initialize read mode once at probe and stop commands after a timeout. - Use a fixed secure-prefix keepout and check the live SEC54 range on reads. - Simplify copying, locking, configuration and Kconfig help. Tested on B650D4U (AST2600 A3), OpenBMC Linux 6.18.24 and upstream-based Linux 7.4-rc1: repeated reads, cross-pair reads and 40 reads from four concurrent readers passed. A 12-byte range matched the saved ASPEED-derived reference fingerprint. The 7.4-rc1 RAM boot used the working OpenBMC DTB and initramfs and also passed the final-pair comparison. ARM zImage built successfully. AI assisted with driver revisions, validation tooling and patch text, using the downstream code, review comments and Neal's hardware guidance. Hardware tests were run by the submitter. Prasanth Kumar Padarthi (2): dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider nvmem: aspeed: Add read-only AST2600 OTP support base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider 2026-11-20 17:44 ` [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi @ 2026-11-20 17:44 ` Prasanth Kumar Padarthi 2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi 2026-11-20 18:58 ` [PATCH v2 0/2] " Tan Siewert 2 siblings, 0 replies; 6+ messages in thread From: Prasanth Kumar Padarthi @ 2026-11-20 17:44 UTC (permalink / raw) To: srini Cc: robh, krzk+dt, conor+dt, joel, andrew, ryan_chen, billy_tsai, neal_liu, tan.siewert, devicetree, linux-arm-kernel, linux-aspeed, linux-kernel, Prasanth Kumar Padarthi The AST2600 secure boot controller also provides access to its OTP data region. Reference the NVMEM provider schema and use unevaluatedProperties so common NVMEM properties are accepted while unknown properties remain rejected. Describe the cell offset address space and extend the example with the read-only property. Signed-off-by: Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com> --- diff --git a/Documentation/devicetree/bindings/arm/aspeed/aspeed,sbc.yaml b/Documentation/devicetree/bindings/arm/aspeed/aspeed,sbc.yaml index b8c5cacb0..d8e19c224 100644 --- a/Documentation/devicetree/bindings/arm/aspeed/aspeed,sbc.yaml +++ b/Documentation/devicetree/bindings/arm/aspeed/aspeed,sbc.yaml @@ -13,7 +13,12 @@ maintainers: description: | The ASPEED SoCs have a register bank for interacting with the secure boot - controller. + controller. The controller also provides access to the OTP data region + through NVMEM. NVMEM cell offsets are byte offsets within the OTP data + region, not offsets within the controller register bank. + +allOf: + - $ref: /schemas/nvmem/nvmem.yaml# properties: compatible: @@ -27,11 +32,12 @@ required: - compatible - reg -additionalProperties: false +unevaluatedProperties: false examples: - | sbc: secure-boot-controller@1e6f2000 { compatible = "aspeed,ast2600-sbc"; reg = <0x1e6f2000 0x1000>; + read-only; }; ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support 2026-11-20 17:44 ` [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi 2026-11-20 17:44 ` [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider Prasanth Kumar Padarthi @ 2026-11-20 17:44 ` Prasanth Kumar Padarthi 2026-11-20 17:57 ` sashiko-bot 2026-11-20 19:05 ` Tan Siewert 2026-11-20 18:58 ` [PATCH v2 0/2] " Tan Siewert 2 siblings, 2 replies; 6+ messages in thread From: Prasanth Kumar Padarthi @ 2026-11-20 17:44 UTC (permalink / raw) To: srini Cc: robh, krzk+dt, conor+dt, joel, andrew, ryan_chen, billy_tsai, neal_liu, tan.siewert, devicetree, linux-arm-kernel, linux-aspeed, linux-kernel, Prasanth Kumar Padarthi Provide root-only NVMEM access for userspace diagnostics comparing OTP ranges with vendor-derived reference data during BMC bring-up. The consumer uses raw offsets rather than named cells or a private ioctl. Initialize read mode once at probe and mask the fixed secure prefix using an NVMEM keepout. Recheck SEC54 on each controller read and reject requests into an extended protected prefix. Programming protection does not block reads. Serialize transactions and stop issuing commands after a timeout. Use a 1-us initial polling delay and a generous 100-ms timeout. Adapt the read sequence from ASPEED's downstream driver, preserving its attribution, and add the driver to the ASPEED MAINTAINERS entry. Tested on ASRock Rack B650D4U (AST2600 A3) with Linux 7.4-rc1 and OpenBMC Linux 6.18.24. Repeated reads, cross-pair reads and four concurrent readers (40 reads) passed. The selected 12-byte range matched a saved ASPEED-derived reference. The 7.4-rc1 run used a RAM-booted kernel with the working OpenBMC board DTB and initramfs; its final-pair check also passed. Link: https://github.com/AspeedTech-BMC/linux/blob/769f62b7baa84d6998723b0ea60280e380183553/drivers/soc/aspeed/ast2600-otp.c Link: https://lore.kernel.org/linux-aspeed/KL1PR0601MB3986A356BD06F98D0FF9AD5E80792@KL1PR0601MB3986.apcprd06.prod.outlook.com/ Co-developed-by: Neal Liu <neal_liu@aspeedtech.com> Signed-off-by: Neal Liu <neal_liu@aspeedtech.com> Signed-off-by: Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com> --- MAINTAINERS | 1 drivers/nvmem/Kconfig | 13 ++ drivers/nvmem/Makefile | 1 drivers/nvmem/nvmem-aspeed-otp.c | 297 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 312 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 93abbb315..5415e2be4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2813,6 +2813,7 @@ F: Documentation/devicetree/bindings/arm/aspeed/ F: arch/arm/boot/dts/aspeed/ F: arch/arm/mach-aspeed/ F: arch/arm64/boot/dts/aspeed/ +F: drivers/nvmem/nvmem-aspeed-otp.c N: aspeed ARM/AXIADO ARCHITECTURE diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index d2f5bb236..e6445262b 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -164,6 +164,19 @@ config NVMEM_APPLE_SPMI This driver can also be built as a module. If so, the module will be called apple-nvmem-spmi. +config NVMEM_ASPEED_AST2600_OTP + tristate "ASPEED AST2600 OTP support" + depends on ARCH_ASPEED || COMPILE_TEST + depends on HAS_IOMEM + help + Say Y here to enable read-only access to the OTP data region + on ASPEED AST2600 BMCs through the NVMEM interface. + + This driver can also be built as a module. If so, the module + will be called nvmem-aspeed-otp. + + If unsure, say N. + config NVMEM_BCM_OCOTP tristate "Broadcom On-Chip OTP Controller support" depends on ARCH_BCM_IPROC || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 5e70bad9f..f09b7a8a5 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -23,6 +23,7 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o nvmem-apple-efuses-y := apple-efuses.o obj-$(CONFIG_NVMEM_APPLE_SPMI) += apple_nvmem_spmi.o apple_nvmem_spmi-y := apple-spmi-nvmem.o +obj-$(CONFIG_NVMEM_ASPEED_AST2600_OTP) += nvmem-aspeed-otp.o obj-$(CONFIG_NVMEM_BCM_OCOTP) += nvmem-bcm-ocotp.o nvmem-bcm-ocotp-y := bcm-ocotp.o obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o diff --git a/drivers/nvmem/nvmem-aspeed-otp.c b/drivers/nvmem/nvmem-aspeed-otp.c new file mode 100644 --- /dev/null +++ b/drivers/nvmem/nvmem-aspeed-otp.c @@ -0,0 +1,297 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) ASPEED Technology Inc. + * + * ASPEED AST2600 OTP Controller driver + */ + +#include <linux/bitfield.h> +#include <linux/cleanup.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/nvmem-provider.h> +#include <linux/platform_device.h> +#include <linux/unaligned.h> + +#define AST2600_OTP_PROTECT_KEY 0x00 +#define AST2600_OTP_CMD 0x04 +#define AST2600_OTP_ADDR 0x10 +#define AST2600_OTP_STATUS 0x14 +#define AST2600_OTP_COMPARE_1 0x20 +#define AST2600_OTP_COMPARE_2 0x24 +#define AST2600_OTP_EXTRA_READ_PROTECT 0x54 +#define AST2600_OTP_EXTRA_READ_RANGE GENMASK(5, 0) + +#define AST2600_OTP_CMD_READ 0x23b1e361 +#define AST2600_OTP_CMD_WRITE_MODE 0x23b1e362 +#define AST2600_OTP_UNLOCK_KEY 0x349fe38a +#define AST2600_OTP_STATUS_DONE GENMASK(2, 1) +/* Normal reads take less than 1 us; allow a generous bounded wait. */ +#define AST2600_OTP_TIMEOUT_US 100000 + +#define AST2600_OTP_DATA_WORDS 0x800 +#define AST2600_OTP_SIZE (AST2600_OTP_DATA_WORDS * sizeof(u32)) +#define AST2600_OTP_CONF0_ADDR 0x800 +#define AST2600_OTP_CONF0_SEC_SIZE GENMASK(21, 16) +#define AST2600_OTP_SEC_SIZE_UNIT (32 * sizeof(u32)) + +struct ast2600_otp { + struct device *dev; + void __iomem *base; + /* Serialize the complete unlock, read and relock sequence. */ + struct mutex lock; + struct nvmem_keepout secure_keepout; + bool failed; +}; + +static int ast2600_otp_wait_complete(struct ast2600_otp *priv) +{ + u32 status; + int ret; + + /* Wait at least 1 us before the first sample of both idle flags. */ + ret = read_poll_timeout(readl, status, + (status & AST2600_OTP_STATUS_DONE) == + AST2600_OTP_STATUS_DONE, + 1, AST2600_OTP_TIMEOUT_US, true, + priv->base + AST2600_OTP_STATUS); + if (ret) { + /* Relocking SEC00 does not abort an outstanding command. */ + priv->failed = true; + dev_err(priv->dev, + "OTP completion timed out (status=%#x); further reads blocked\n", + status); + } + + return ret; +} + +static int ast2600_otp_init_read_mode(struct ast2600_otp *priv) +{ + static const u32 mode_addresses[] = { 0x3000, 0x5000, 0x1000 }; + int i, ret; + + ret = ast2600_otp_wait_complete(priv); + if (ret) + return ret; + + /* + * Restore read mode once at probe; this driver never programs fuses. + * These writes target volatile mode registers, not OTP fuse cells. + * No fuse programming command or programming timing is used. + */ + for (i = 0; i < ARRAY_SIZE(mode_addresses); i++) { + writel(mode_addresses[i], priv->base + AST2600_OTP_ADDR); + writel(0, priv->base + AST2600_OTP_COMPARE_1); + writel(AST2600_OTP_CMD_WRITE_MODE, priv->base + AST2600_OTP_CMD); + ret = ast2600_otp_wait_complete(priv); + if (ret) + return ret; + } + + return 0; +} + +static int ast2600_otp_read_pair(struct ast2600_otp *priv, + unsigned int aligned_word, + u32 *word0, u32 *word1) +{ + int ret; + + /* The hardware reads two words starting at an even word index. */ + writel(aligned_word, priv->base + AST2600_OTP_ADDR); + + writel(AST2600_OTP_CMD_READ, + priv->base + AST2600_OTP_CMD); + + ret = ast2600_otp_wait_complete(priv); + if (ret) + return ret; + + *word0 = readl(priv->base + AST2600_OTP_COMPARE_1); + *word1 = readl(priv->base + AST2600_OTP_COMPARE_2); + + return 0; +} + +static int ast2600_otp_init_keepout(struct ast2600_otp *priv) +{ + u32 conf0, unused; + int ret; + + guard(mutex)(&priv->lock); + + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { + ret = -EACCES; + goto out_lock; + } + + ret = ast2600_otp_init_read_mode(priv); + if (ret) + goto out_lock; + + ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR, + &conf0, &unused); + if (ret) + goto out_lock; + + priv->secure_keepout.start = 0; + priv->secure_keepout.end = + FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) * + AST2600_OTP_SEC_SIZE_UNIT; + priv->secure_keepout.value = 0; + +out_lock: + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); + /* Complete the lock write before returning and releasing the mutex. */ + readl(priv->base + AST2600_OTP_PROTECT_KEY); + return ret; +} + +static int ast2600_otp_read(void *context, unsigned int offset, + void *val, size_t bytes) +{ + struct ast2600_otp *priv = context; + u8 *buf = val; + unsigned int word_index; + unsigned int aligned_word; + unsigned int secure_size; + u32 extra_read; + u32 word0, word1; + int ret; + + if (!bytes) + return 0; + + if (offset % sizeof(u32) || bytes % sizeof(u32)) + return -EINVAL; + + if (offset >= AST2600_OTP_SIZE || + bytes > AST2600_OTP_SIZE - offset) + return -EINVAL; + + guard(mutex)(&priv->lock); + + if (priv->failed) + return -EIO; + + /* SEC54 can grow after probe; keep the registered keepout immutable. */ + extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT); + secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) * + AST2600_OTP_SEC_SIZE_UNIT; + secure_size = max(priv->secure_keepout.end, secure_size); + if (offset < secure_size) + return -EACCES; + + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { + ret = -EACCES; + goto out_lock; + } + + ret = ast2600_otp_wait_complete(priv); + if (ret) + goto out_lock; + + word_index = offset / sizeof(u32); + while (bytes) { + aligned_word = word_index & ~1U; + + ret = ast2600_otp_read_pair(priv, aligned_word, + &word0, &word1); + if (ret) + goto out_lock; + + if (!(word_index & 1)) { + put_unaligned_le32(word0, buf); + buf += sizeof(u32); + bytes -= sizeof(u32); + word_index++; + } + if (bytes) { + put_unaligned_le32(word1, buf); + buf += sizeof(u32); + bytes -= sizeof(u32); + word_index++; + } + } + + ret = 0; + +out_lock: + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); + /* Complete the lock write before returning and releasing the mutex. */ + readl(priv->base + AST2600_OTP_PROTECT_KEY); + return ret; +} + +static int ast2600_otp_probe(struct platform_device *pdev) +{ + struct nvmem_config config = { + .name = "ast2600-otp", + .id = NVMEM_DEVID_AUTO, + .owner = THIS_MODULE, + .type = NVMEM_TYPE_OTP, + .read_only = true, + .root_only = true, + .word_size = sizeof(u32), + .stride = sizeof(u32), + .size = AST2600_OTP_SIZE, + .reg_read = ast2600_otp_read, + }; + struct nvmem_device *nvmem; + struct ast2600_otp *priv; + struct device *dev = &pdev->dev; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->dev = dev; + priv->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + ret = devm_mutex_init(dev, &priv->lock); + if (ret) + return ret; + + ret = ast2600_otp_init_keepout(priv); + if (ret) + return dev_err_probe(dev, ret, + "Failed to initialize OTP read mode and secure prefix\n"); + + config.dev = dev; + config.priv = priv; + if (priv->secure_keepout.end) { + config.keepout = &priv->secure_keepout; + config.nkeepout = 1; + } + nvmem = devm_nvmem_register(dev, &config); + return PTR_ERR_OR_ZERO(nvmem); +} + +static const struct of_device_id ast2600_otp_of_match[] = { + { .compatible = "aspeed,ast2600-sbc" }, + { } +}; +MODULE_DEVICE_TABLE(of, ast2600_otp_of_match); + +static struct platform_driver ast2600_otp_driver = { + .probe = ast2600_otp_probe, + .driver = { + .name = "ast2600-otp", + .of_match_table = ast2600_otp_of_match, + }, +}; +module_platform_driver(ast2600_otp_driver); + +MODULE_AUTHOR("Neal Liu <neal_liu@aspeedtech.com>"); +MODULE_AUTHOR("Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com>"); +MODULE_DESCRIPTION("ASPEED AST2600 read-only OTP NVMEM driver"); +MODULE_LICENSE("GPL"); ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support 2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi @ 2026-11-20 17:57 ` sashiko-bot 2026-11-20 19:05 ` Tan Siewert 1 sibling, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-11-20 17:57 UTC (permalink / raw) To: Prasanth Kumar Padarthi; +Cc: devicetree, robh, conor+dt Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] nvmem: aspeed: mix of guard(mutex) and goto cleanup in OTP helpers -- commit 34b51f06ae272e72e9e379fc1f5bbb493333d824 Author: Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com> nvmem: aspeed: Add read-only AST2600 OTP support This commit adds a read-only NVMEM provider driver for the ASPEED AST2600 OTP controller, masking the secure prefix with an NVMEM keepout and serializing hardware unlock, read, and relock transactions. Link: https://github.com/AspeedTech-BMC/linux/blob/769f62b7baa84d6998723b0ea60280e380183553/drivers/soc/aspeed/ast2600-otp.c Link: https://lore.kernel.org/linux-aspeed/KL1PR0601MB3986A356BD06F98D0FF9AD5E80792@KL1PR0601MB3986.apcprd06.prod.outlook.com/ > diff --git a/drivers/nvmem/nvmem-aspeed-otp.c b/drivers/nvmem/nvmem-aspeed-otp.c > new file mode 100644 > index 0000000000000..8a433dccaaaf0 > --- /dev/null > +++ b/drivers/nvmem/nvmem-aspeed-otp.c > @@ -0,0 +1,297 @@ [ ... ] > +static int ast2600_otp_init_keepout(struct ast2600_otp *priv) > +{ > + u32 conf0, unused; > + int ret; > + > + guard(mutex)(&priv->lock); > + > + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); > + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { > + ret = -EACCES; > + goto out_lock; > + } > + > + ret = ast2600_otp_init_read_mode(priv); > + if (ret) > + goto out_lock; > + > + ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR, > + &conf0, &unused); > + if (ret) > + goto out_lock; > + > + priv->secure_keepout.start = 0; > + priv->secure_keepout.end = > + FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) * > + AST2600_OTP_SEC_SIZE_UNIT; > + priv->secure_keepout.value = 0; > + > +out_lock: > + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); > + /* Complete the lock write before returning and releasing the mutex. */ > + readl(priv->base + AST2600_OTP_PROTECT_KEY); > + return ret; > +} > + > +static int ast2600_otp_read(void *context, unsigned int offset, > + void *val, size_t bytes) > +{ > + struct ast2600_otp *priv = context; > + u8 *buf = val; > + unsigned int word_index; > + unsigned int aligned_word; > + unsigned int secure_size; > + u32 extra_read; > + u32 word0, word1; > + int ret; > + > + if (!bytes) > + return 0; > + > + if (offset % sizeof(u32) || bytes % sizeof(u32)) > + return -EINVAL; > + > + if (offset >= AST2600_OTP_SIZE || > + bytes > AST2600_OTP_SIZE - offset) > + return -EINVAL; > + > + guard(mutex)(&priv->lock); > + > + if (priv->failed) > + return -EIO; > + > + /* SEC54 can grow after probe; keep the registered keepout immutable. */ > + extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT); > + secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) * > + AST2600_OTP_SEC_SIZE_UNIT; > + secure_size = max(priv->secure_keepout.end, secure_size); > + if (offset < secure_size) > + return -EACCES; > + > + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); > + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { > + ret = -EACCES; > + goto out_lock; > + } > + > + ret = ast2600_otp_wait_complete(priv); > + if (ret) > + goto out_lock; > + > + word_index = offset / sizeof(u32); > + while (bytes) { > + aligned_word = word_index & ~1U; > + > + ret = ast2600_otp_read_pair(priv, aligned_word, > + &word0, &word1); > + if (ret) > + goto out_lock; > + > + if (!(word_index & 1)) { > + put_unaligned_le32(word0, buf); > + buf += sizeof(u32); > + bytes -= sizeof(u32); > + word_index++; > + } > + if (bytes) { > + put_unaligned_le32(word1, buf); > + buf += sizeof(u32); > + bytes -= sizeof(u32); > + word_index++; > + } > + } > + > + ret = 0; > + > +out_lock: > + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); > + /* Complete the lock write before returning and releasing the mutex. */ > + readl(priv->base + AST2600_OTP_PROTECT_KEY); > + return ret; > +} [Severity: Low] This isn't a bug, but both ast2600_otp_init_keepout() and ast2600_otp_read() mix guard(mutex) with goto out_lock cleanup within the same function, contrary to the Cleanup API convention in include/linux/cleanup.h. Moving the work performed while AST2600_OTP_PROTECT_KEY is unlocked into inner helpers (or using consistent cleanup) would avoid mixing guard() with goto labels and also share the duplicated unlock/relock sequence. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261120174440.123487-1-prasanth.padarthi10@gmail.com?part=2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support 2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi 2026-11-20 17:57 ` sashiko-bot @ 2026-11-20 19:05 ` Tan Siewert 1 sibling, 0 replies; 6+ messages in thread From: Tan Siewert @ 2026-11-20 19:05 UTC (permalink / raw) To: Prasanth Kumar Padarthi, srini Cc: robh, krzk+dt, conor+dt, joel, andrew, ryan_chen, billy_tsai, neal_liu, devicetree, linux-arm-kernel, linux-aspeed, linux-kernel On 11/20/26 6:44 PM, Prasanth Kumar Padarthi wrote: > Provide root-only NVMEM access for userspace diagnostics comparing OTP > ranges with vendor-derived reference data during BMC bring-up. The > consumer uses raw offsets rather than named cells or a private ioctl. > > Initialize read mode once at probe and mask the fixed secure prefix using > an NVMEM keepout. Recheck SEC54 on each controller read and reject requests > into an extended protected prefix. Programming protection does not block > reads. Serialize transactions and stop issuing commands after a timeout. > Use a 1-us initial polling delay and a generous 100-ms timeout. > This is describing the code... Most of it belongs in the cover letter or below the --- line. Please explain what the *hardware* does and *why* the driver is designed this way, not what the code is doing! > Adapt the read sequence from ASPEED's downstream driver, preserving its > attribution, and add the driver to the ASPEED MAINTAINERS entry. > > Tested on ASRock Rack B650D4U (AST2600 A3) with Linux 7.4-rc1 and > OpenBMC Linux 6.18.24. Repeated reads, cross-pair reads and four concurrent > readers (40 reads) passed. The selected 12-byte range matched a saved > ASPEED-derived reference. The 7.4-rc1 run used a RAM-booted kernel with > the working OpenBMC board DTB and initramfs; its final-pair check also > passed. This part should be outside of the commit message, like I explained earlier. > > Link: https://github.com/AspeedTech-BMC/linux/blob/769f62b7baa84d6998723b0ea60280e380183553/drivers/soc/aspeed/ast2600-otp.c > Link: https://lore.kernel.org/linux-aspeed/KL1PR0601MB3986A356BD06F98D0FF9AD5E80792@KL1PR0601MB3986.apcprd06.prod.outlook.com/ > Co-developed-by: Neal Liu <neal_liu@aspeedtech.com> > Signed-off-by: Neal Liu <neal_liu@aspeedtech.com> > Signed-off-by: Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com> > > --- > MAINTAINERS | 1 > drivers/nvmem/Kconfig | 13 ++ > drivers/nvmem/Makefile | 1 > drivers/nvmem/nvmem-aspeed-otp.c | 297 ++++++++++++++++++++++++++++++++++++++ > 4 files changed, 312 insertions(+) > > diff --git a/MAINTAINERS b/MAINTAINERS > index 93abbb315..5415e2be4 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -2813,6 +2813,7 @@ F: Documentation/devicetree/bindings/arm/aspeed/ > F: arch/arm/boot/dts/aspeed/ > F: arch/arm/mach-aspeed/ > F: arch/arm64/boot/dts/aspeed/ > +F: drivers/nvmem/nvmem-aspeed-otp.c The matcher here *may* be unnecessary given that we have `N`. > N: aspeed > > ARM/AXIADO ARCHITECTURE > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig > index d2f5bb236..e6445262b 100644 > --- a/drivers/nvmem/Kconfig > +++ b/drivers/nvmem/Kconfig > @@ -164,6 +164,19 @@ config NVMEM_APPLE_SPMI > This driver can also be built as a module. If so, the module > will be called apple-nvmem-spmi. > > +config NVMEM_ASPEED_AST2600_OTP > + tristate "ASPEED AST2600 OTP support" The file is now named generic. Please name the kconfig "NVMEM_ASPEED_OTP" so it doesn't need to be renamed once AST2700 support is implemented. > + depends on ARCH_ASPEED || COMPILE_TEST > + depends on HAS_IOMEM > + help > + Say Y here to enable read-only access to the OTP data region > + on ASPEED AST2600 BMCs through the NVMEM interface. > + > + This driver can also be built as a module. If so, the module > + will be called nvmem-aspeed-otp. > + > + If unsure, say N. > + > config NVMEM_BCM_OCOTP > tristate "Broadcom On-Chip OTP Controller support" > depends on ARCH_BCM_IPROC || COMPILE_TEST *snip* > diff --git a/drivers/nvmem/nvmem-aspeed-otp.c b/drivers/nvmem/nvmem-aspeed-otp.c > new file mode 100644 > --- /dev/null > +++ b/drivers/nvmem/nvmem-aspeed-otp.c > @@ -0,0 +1,297 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) ASPEED Technology Inc. > + * > + * ASPEED AST2600 OTP Controller driver > + */ > + > +#include <linux/bitfield.h> > +#include <linux/cleanup.h> > +#include <linux/io.h> > +#include <linux/iopoll.h> > +#include <linux/mod_devicetable.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/nvmem-provider.h> > +#include <linux/platform_device.h> > +#include <linux/unaligned.h> > + > +#define AST2600_OTP_PROTECT_KEY 0x00 > +#define AST2600_OTP_CMD 0x04 > +#define AST2600_OTP_ADDR 0x10 > +#define AST2600_OTP_STATUS 0x14 > +#define AST2600_OTP_COMPARE_1 0x20 > +#define AST2600_OTP_COMPARE_2 0x24 > +#define AST2600_OTP_EXTRA_READ_PROTECT 0x54 > +#define AST2600_OTP_EXTRA_READ_RANGE GENMASK(5, 0) Please keep register offsets and field masks visually separate. Usually you put the fields directly below their register, indented with an extra space. For example: #define AST2600_OTP_EXTRA_READ_PROTECT 0x54 #define AST2600_OTP_EXTRA_READ_RANGE GENMASK(5, 0) > + > +#define AST2600_OTP_CMD_READ 0x23b1e361 > +#define AST2600_OTP_CMD_WRITE_MODE 0x23b1e362 > +#define AST2600_OTP_UNLOCK_KEY 0x349fe38a > +#define AST2600_OTP_STATUS_DONE GENMASK(2, 1) > +/* Normal reads take less than 1 us; allow a generous bounded wait. */ > +#define AST2600_OTP_TIMEOUT_US 100000 > + > +#define AST2600_OTP_DATA_WORDS 0x800 > +#define AST2600_OTP_SIZE (AST2600_OTP_DATA_WORDS * sizeof(u32)) > +#define AST2600_OTP_CONF0_ADDR 0x800 > +#define AST2600_OTP_CONF0_SEC_SIZE GENMASK(21, 16) > +#define AST2600_OTP_SEC_SIZE_UNIT (32 * sizeof(u32)) The alignment is somewhat inconsistent. > + > +struct ast2600_otp { > + struct device *dev; > + void __iomem *base; > + /* Serialize the complete unlock, read and relock sequence. */ > + struct mutex lock; > + struct nvmem_keepout secure_keepout; > + bool failed; > +}; > + *snip* > +static int ast2600_otp_init_read_mode(struct ast2600_otp *priv) > +{ > + static const u32 mode_addresses[] = { 0x3000, 0x5000, 0x1000 }; Please give these registers names instead of using an anonymous array. > + int i, ret; > + > + ret = ast2600_otp_wait_complete(priv); > + if (ret) > + return ret; > + > + /* > + * Restore read mode once at probe; this driver never programs fuses. > + * These writes target volatile mode registers, not OTP fuse cells. > + * No fuse programming command or programming timing is used. > + */ All the sentences say the same in slightly different ways, but none of them says *why* the step is needed. Maybe: "Linux never programs the OTP, but it might be left in it before, so restore the read mode once"? > + for (i = 0; i < ARRAY_SIZE(mode_addresses); i++) { > + writel(mode_addresses[i], priv->base + AST2600_OTP_ADDR); > + writel(0, priv->base + AST2600_OTP_COMPARE_1); > + writel(AST2600_OTP_CMD_WRITE_MODE, priv->base + AST2600_OTP_CMD); > + ret = ast2600_otp_wait_complete(priv); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > +static int ast2600_otp_read_pair(struct ast2600_otp *priv, > + unsigned int aligned_word, > + u32 *word0, u32 *word1) > +{ > + int ret; > + > + /* The hardware reads two words starting at an even word index. */ > + writel(aligned_word, priv->base + AST2600_OTP_ADDR); > + > + writel(AST2600_OTP_CMD_READ, > + priv->base + AST2600_OTP_CMD); > + > + ret = ast2600_otp_wait_complete(priv); > + if (ret) > + return ret; > + > + *word0 = readl(priv->base + AST2600_OTP_COMPARE_1); > + *word1 = readl(priv->base + AST2600_OTP_COMPARE_2); > + > + return 0; > +} > + > +static int ast2600_otp_init_keepout(struct ast2600_otp *priv) The is misleading, because it also restores read mode. > +{ > + u32 conf0, unused; > + int ret; > + > + guard(mutex)(&priv->lock); > + > + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); > + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { > + ret = -EACCES; > + goto out_lock; > + } Mixing goto and scope-based cleanup in the same function isn't allowed (see the big comment in include/linux/cleanup.h). The same applies to ast2600_otp_read(). The unlock/relock sequence is also duplicated between both functions. Please move this into helpers (or a DEFINE_GUARD()) so it doesn't need labels. Also, -EIO might be better here given that it's a hardware problem, and not a permission problem. > + > + ret = ast2600_otp_init_read_mode(priv); > + if (ret) > + goto out_lock; > + > + ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR, > + &conf0, &unused); > + if (ret) > + goto out_lock; > + > + priv->secure_keepout.start = 0; > + priv->secure_keepout.end = > + FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) * > + AST2600_OTP_SEC_SIZE_UNIT; > + priv->secure_keepout.value = 0; priv comes from devm_kzalloc(), so they're are already zero. > + > +out_lock: > + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); > + /* Complete the lock write before returning and releasing the mutex. */ > + readl(priv->base + AST2600_OTP_PROTECT_KEY); Again (as in v1), nothing else accesses the device during probe. This read is useless. > + return ret; > +} > + > +static int ast2600_otp_read(void *context, unsigned int offset, > + void *val, size_t bytes) > +{ > + struct ast2600_otp *priv = context; > + u8 *buf = val; > + unsigned int word_index; > + unsigned int aligned_word; > + unsigned int secure_size; > + u32 extra_read; > + u32 word0, word1; > + int ret; > + > + if (!bytes) > + return 0; > + > + if (offset % sizeof(u32) || bytes % sizeof(u32)) > + return -EINVAL; > + > + if (offset >= AST2600_OTP_SIZE || > + bytes > AST2600_OTP_SIZE - offset) > + return -EINVAL; > + > + guard(mutex)(&priv->lock); > + > + if (priv->failed) > + return -EIO; > + > + /* SEC54 can grow after probe; keep the registered keepout immutable. */ Please describe the hardware behaviour instead, e.g. "SEC54[5:0] can only grow until the ARM cores reset." > + extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT); > + secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) * > + AST2600_OTP_SEC_SIZE_UNIT; > + secure_size = max(priv->secure_keepout.end, secure_size); > + if (offset < secure_size) > + return -EACCES; > + > + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY); > + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) { > + ret = -EACCES; > + goto out_lock; > + } > + > + ret = ast2600_otp_wait_complete(priv); > + if (ret) > + goto out_lock; > + > + word_index = offset / sizeof(u32); > + while (bytes) { > + aligned_word = word_index & ~1U; > + > + ret = ast2600_otp_read_pair(priv, aligned_word, > + &word0, &word1); > + if (ret) > + goto out_lock; > + > + if (!(word_index & 1)) { > + put_unaligned_le32(word0, buf); > + buf += sizeof(u32); > + bytes -= sizeof(u32); > + word_index++; > + } > + if (bytes) { > + put_unaligned_le32(word1, buf); > + buf += sizeof(u32); > + bytes -= sizeof(u32); > + word_index++; > + } Why not reading the pair into an array? That'd remove the duplicates. > + } > + > + ret = 0; > + > +out_lock: > + writel(0, priv->base + AST2600_OTP_PROTECT_KEY); > + /* Complete the lock write before returning and releasing the mutex. */ > + readl(priv->base + AST2600_OTP_PROTECT_KEY); > + return ret; > +} > + > +static int ast2600_otp_probe(struct platform_device *pdev) > +{ > + struct nvmem_config config = { > + .name = "ast2600-otp", > + .id = NVMEM_DEVID_AUTO, > + .owner = THIS_MODULE, > + .type = NVMEM_TYPE_OTP, > + .read_only = true, > + .root_only = true, > + .word_size = sizeof(u32), > + .stride = sizeof(u32), > + .size = AST2600_OTP_SIZE, > + .reg_read = ast2600_otp_read, > + }; > + struct nvmem_device *nvmem; > + struct ast2600_otp *priv; > + struct device *dev = &pdev->dev; > + int ret; > + > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + priv->dev = dev; > + priv->base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(priv->base)) > + return PTR_ERR(priv->base); > + > + ret = devm_mutex_init(dev, &priv->lock); > + if (ret) > + return ret; > + > + ret = ast2600_otp_init_keepout(priv); > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to initialize OTP read mode and secure prefix\n"); > + > + config.dev = dev; > + config.priv = priv; > + if (priv->secure_keepout.end) { > + config.keepout = &priv->secure_keepout; > + config.nkeepout = 1; > + } > + nvmem = devm_nvmem_register(dev, &config); > + return PTR_ERR_OR_ZERO(nvmem); nit: return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); > +} > + > +static const struct of_device_id ast2600_otp_of_match[] = { > + { .compatible = "aspeed,ast2600-sbc" }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, ast2600_otp_of_match); > + > +static struct platform_driver ast2600_otp_driver = { > + .probe = ast2600_otp_probe, > + .driver = { > + .name = "ast2600-otp", If the plan is to add AST2700 later, then please use "aspeed-otp" and aspeed_otp_* names. Last: Please run your next build with W=1 and do checkpatch.pl + dt_binding_check... Tan ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support 2026-11-20 17:44 ` [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi 2026-11-20 17:44 ` [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider Prasanth Kumar Padarthi 2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi @ 2026-11-20 18:58 ` Tan Siewert 2 siblings, 0 replies; 6+ messages in thread From: Tan Siewert @ 2026-11-20 18:58 UTC (permalink / raw) To: Prasanth Kumar Padarthi Cc: robh, krzk+dt, conor+dt, joel, andrew, ryan_chen, billy_tsai, neal_liu, devicetree, linux-arm-kernel, linux-aspeed, linux-kernel, srini On 11/20/26 6:44 PM, Prasanth Kumar Padarthi wrote: > Hi, > > This series exposes permitted AST2600 OTP data through root-only NVMEM > for userspace diagnostics using raw offsets. It adds the SBC NVMEM > binding and a read-only driver adapted from ASPEED's downstream driver. > > Changes since v1: > - Add the separate binding patch and rename the driver nvmem-aspeed-otp. > - Poll once after a 1-us delay; retain the 100-ms timeout and log failures. > - Initialize read mode once at probe and stop commands after a timeout. > - Use a fixed secure-prefix keepout and check the live SEC54 range on reads. > - Simplify copying, locking, configuration and Kconfig help. > > Tested on B650D4U (AST2600 A3), OpenBMC Linux 6.18.24 and upstream-based > Linux 7.4-rc1: repeated reads, cross-pair reads and 40 reads from four > concurrent readers passed. A 12-byte range matched the saved ASPEED-derived > reference fingerprint. The 7.4-rc1 RAM boot used the working OpenBMC DTB > and initramfs and also passed the final-pair comparison. ARM zImage built > successfully. > > AI assisted with driver revisions, validation tooling and patch text, > using the downstream code, review comments and Neal's hardware guidance. > Hardware tests were run by the submitter. > > Prasanth Kumar Padarthi (2): > dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider > nvmem: aspeed: Add read-only AST2600 OTP support > > base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 Again, please fix your threading... Other maintainers and reviewers already told you in other threads that sending a new revision must not be "In-reply-to" to the previous revision. See the "Explicit In-Reply-To headers" section of the submission documentation [1]. Consider the use of b4 [2], which can handle it more consistently. Tan [1] https://docs.kernel.org/process/submitting-patches.html#explicit-in-reply-to-headers [2] https://b4.docs.kernel.org/en/latest/ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-20 19:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261113034213.158390-1-prasanth.padarthi10@gmail.com>
2026-11-20 17:44 ` [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi
2026-11-20 17:44 ` [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider Prasanth Kumar Padarthi
2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi
2026-11-20 17:57 ` sashiko-bot
2026-11-20 19:05 ` Tan Siewert
2026-11-20 18:58 ` [PATCH v2 0/2] " Tan Siewert
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox