From: aspeedyh <yh_chung@aspeedtech.com>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Joel Stanley <joel@jms.id.au>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
Ryan Chen <ryan_chen@aspeedtech.com>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: <devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-aspeed@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,
<openbmc@lists.ozlabs.org>, <maciej.lawniczak@intel.com>,
aspeedyh <yh_chung@aspeedtech.com>
Subject: [PATCH 6/7] soc: aspeed: Add sysfs controls for flash backend selection
Date: Fri, 13 Mar 2026 18:07:41 +0800 [thread overview]
Message-ID: <20260313-upstream_espi-v1-6-9504428e1f43@aspeedtech.com> (raw)
In-Reply-To: <20260313-upstream_espi-v1-0-9504428e1f43@aspeedtech.com>
add following attributes to select backend storage for eSPI TAFS LUN
interface:
- flash_lun_path: specify path of backend storage for eSPI TAFS to share
with host.
- flash_lun_readonly: set flash LUN to read-only or read-write mode to
block host write operations.
- flash_lun_enable: open storage according to flash_lun_path as file for
eSPI TAFS access.
Example usage:
- Select /dev/mtdblock8 as backend storage for eSPI TAFS LUN interface
echo /dev/mtdblock8 > \
/sys/bus/platform/devices/1e6ee000.espi/flash_lun_path
- Set LUN to read-only mode to block host write operations
echo 1 > /sys/bus/platform/devices/1e6ee000.espi/flash_lun_readonly
- Enable flash LUN for eSPI TAFS access
echo 1 > /sys/bus/platform/devices/1e6ee000.espi/flash_lun_enable
Signed-off-by: aspeedyh <yh_chung@aspeedtech.com>
---
drivers/soc/aspeed/espi/aspeed-espi.c | 218 ++++++++++++++++++++++++++++++++++
1 file changed, 218 insertions(+)
diff --git a/drivers/soc/aspeed/espi/aspeed-espi.c b/drivers/soc/aspeed/espi/aspeed-espi.c
index 7d58c78ed397..2c8f9641174d 100644
--- a/drivers/soc/aspeed/espi/aspeed-espi.c
+++ b/drivers/soc/aspeed/espi/aspeed-espi.c
@@ -12,12 +12,224 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
+#include <linux/kstrtox.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include "aspeed-espi.h"
#include "aspeed-espi-comm.h"
#include "ast2600-espi.h"
#include "espi_storage.h"
+static ssize_t flash_lun_path_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ ssize_t rc;
+
+ espi = dev_get_drvdata(dev);
+
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ mutex_lock(&flash->lun_mtx);
+ rc = scnprintf(buf, PAGE_SIZE, "%s\n", flash->lun_path);
+ mutex_unlock(&flash->lun_mtx);
+
+ return rc;
+}
+
+static ssize_t flash_lun_path_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ char tmp[ASPEED_ESPI_LUN_PATH_MAX];
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ size_t len;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ len = strnlen(buf, count);
+ if (len && buf[len - 1] == '\n')
+ len--;
+
+ if (len >= sizeof(tmp))
+ return -ENAMETOOLONG;
+
+ memcpy(tmp, buf, len);
+ tmp[len] = '\0';
+
+ mutex_lock(&flash->lun_mtx);
+ if (flash->lun && flash->lun->filp) {
+ mutex_unlock(&flash->lun_mtx);
+ return -EBUSY;
+ }
+
+ strscpy(flash->lun_path, tmp, sizeof(flash->lun_path));
+ dev_info(dev, "flash lun path set to %s\n", flash->lun_path);
+ mutex_unlock(&flash->lun_mtx);
+
+ return count;
+}
+
+static ssize_t flash_lun_readonly_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ ssize_t rc;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ mutex_lock(&flash->lun_mtx);
+ rc = scnprintf(buf, PAGE_SIZE, "%u\n", flash->lun_ro);
+ mutex_unlock(&flash->lun_mtx);
+
+ return rc;
+}
+
+static ssize_t flash_lun_readonly_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ bool ro;
+ int rc;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ rc = kstrtobool(buf, &ro);
+ if (rc)
+ return rc;
+
+ mutex_lock(&flash->lun_mtx);
+ if (flash->lun && flash->lun->filp) {
+ mutex_unlock(&flash->lun_mtx);
+ return -EBUSY;
+ }
+
+ flash->lun_ro = ro;
+ dev_info(dev, "flash lun readonly set to %u\n", flash->lun_ro);
+ mutex_unlock(&flash->lun_mtx);
+
+ return count;
+}
+
+static ssize_t flash_lun_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ bool enabled;
+ ssize_t rc;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ mutex_lock(&flash->lun_mtx);
+ enabled = flash->lun && flash->lun->filp;
+ mutex_unlock(&flash->lun_mtx);
+
+ rc = scnprintf(buf, PAGE_SIZE, "%u\n", enabled);
+ return rc;
+}
+
+static ssize_t flash_lun_enable_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct aspeed_espi_flash *flash;
+ struct aspeed_espi *espi;
+ bool enable;
+ int rc = 0;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ flash = &espi->flash;
+
+ rc = kstrtobool(buf, &enable);
+ if (rc)
+ return rc;
+
+ mutex_lock(&flash->lun_mtx);
+ if (!flash->lun) {
+ flash->lun = devm_kzalloc(dev, sizeof(*flash->lun), GFP_KERNEL);
+ if (!flash->lun) {
+ rc = -ENOMEM;
+ goto out_unlock;
+ }
+ }
+
+ if (enable) {
+ if (flash->lun->filp)
+ goto out_unlock;
+ if (!flash->lun_path[0]) {
+ rc = -EINVAL;
+ goto out_unlock;
+ }
+
+ dev_info(dev, "flash lun enable: path=%s ro=%u\n",
+ flash->lun_path, flash->lun_ro);
+ mutex_lock(&flash->tx_mtx);
+ rc = aspeed_espi_lun_open(flash->lun, flash->lun_path,
+ flash->lun_ro, false);
+ mutex_unlock(&flash->tx_mtx);
+ } else {
+ if (!flash->lun->filp)
+ goto out_unlock;
+
+ dev_info(dev, "flash lun disable\n");
+ mutex_lock(&flash->tx_mtx);
+ aspeed_espi_lun_close(flash->lun);
+ mutex_unlock(&flash->tx_mtx);
+ }
+
+out_unlock:
+ mutex_unlock(&flash->lun_mtx);
+ if (rc) {
+ dev_err(dev, "flash lun enable=%u failed: %d\n", enable, rc);
+ return rc;
+ }
+
+ return count;
+}
+
+static DEVICE_ATTR_RW(flash_lun_path);
+static DEVICE_ATTR_RW(flash_lun_readonly);
+static DEVICE_ATTR_RW(flash_lun_enable);
+
+static struct attribute *aspeed_espi_flash_attrs[] = {
+ &dev_attr_flash_lun_path.attr,
+ &dev_attr_flash_lun_readonly.attr,
+ &dev_attr_flash_lun_enable.attr,
+ NULL,
+};
+
+static const struct attribute_group aspeed_espi_flash_attr_group = {
+ .attrs = aspeed_espi_flash_attrs,
+};
struct aspeed_espi_ops {
void (*espi_pre_init)(struct aspeed_espi *espi);
@@ -336,6 +548,12 @@ static int aspeed_espi_probe(struct platform_device *pdev)
goto err_remove_perif;
}
+ rc = devm_device_add_group(dev, &aspeed_espi_flash_attr_group);
+ if (rc) {
+ dev_err(dev, "cannot add flash LUN sysfs group, rc=%d\n", rc);
+ goto err_remove_flash;
+ }
+
rc = devm_request_irq(dev, espi->irq, espi->ops->espi_isr, 0,
dev_name(dev), espi);
if (rc) {
--
2.34.1
next prev parent reply other threads:[~2026-03-13 10:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 10:07 [PATCH 0/7] soc: aspeed: Add AST2600 eSPI controller support aspeedyh
2026-03-13 10:07 ` [PATCH 1/7] dt-bindings: soc: aspeed: Add AST2600 eSPI controller aspeedyh
2026-03-16 7:07 ` Krzysztof Kozlowski
2026-03-16 8:17 ` YH Chung
2026-03-16 11:04 ` Conor Dooley
2026-03-17 8:43 ` YH Chung
2026-03-13 10:07 ` [PATCH 2/7] soc: aspeed: Introduce core eSPI controller support aspeedyh
2026-03-16 9:57 ` Philipp Zabel
2026-03-17 8:40 ` YH Chung
2026-03-13 10:07 ` [PATCH 3/7] soc: aspeed: Add AST2600 peripheral channel port I/O support aspeedyh
2026-03-13 10:07 ` [PATCH 4/7] soc: aspeed: Add eSPI TAFS backend support aspeedyh
2026-03-13 10:07 ` [PATCH 5/7] soc: aspeed: Add eSPI flash channel support aspeedyh
2026-03-19 23:53 ` kernel test robot
2026-03-20 1:17 ` kernel test robot
2026-03-20 4:19 ` kernel test robot
2026-03-13 10:07 ` aspeedyh [this message]
2026-03-13 10:07 ` [PATCH 7/7] arm: dts: aspeed: Add eSPI node for AST2600 aspeedyh
2026-03-13 16:24 ` [PATCH 0/7] soc: aspeed: Add AST2600 eSPI controller support Conor Dooley
2026-03-13 16:32 ` Mark Brown
2026-03-13 16:48 ` Mark Brown
2026-03-16 3:07 ` YH Chung
2026-03-13 21:36 ` Arnd Bergmann
2026-03-14 1:02 ` Mark Brown
2026-03-16 6:06 ` Ivan Mikhaylov
2026-03-16 6:34 ` Andrew Jeffery
2026-03-17 8:14 ` YH Chung
2026-03-17 9:50 ` Arnd Bergmann
2026-03-25 8:41 ` YH Chung
2026-03-25 10:30 ` Arnd Bergmann
2026-03-27 4:14 ` YH Chung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260313-upstream_espi-v1-6-9504428e1f43@aspeedtech.com \
--to=yh_chung@aspeedtech.com \
--cc=andrew@codeconstruct.com.au \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=joel@jms.id.au \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.lawniczak@intel.com \
--cc=openbmc@lists.ozlabs.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=ryan_chen@aspeedtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox