[PATCH v2] nvme-sysfs: add 'format_***' attributes
Tokunori Ikegami
ikegami.t at gmail.com
Sun Sep 22 22:24:14 PDT 2024
The format_all_ns attriute is needed for the format NVM command.
Signed-off-by: Tokunori Ikegami <ikegami.t at gmail.com>
---
Changes since v1:
- Split the sysfs fna attiributes to format_*** attributes.
- Add NVME_CTRL_FNA attiributes definitions.
drivers/nvme/host/core.c | 1 +
drivers/nvme/host/nvme.h | 1 +
drivers/nvme/host/sysfs.c | 48 +++++++++++++++++++++++++++++++++++++++
include/linux/nvme.h | 4 ++++
4 files changed, 54 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2cc9876322e6..7aa291ca7d21 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3303,6 +3303,7 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
ctrl->cctemp = le16_to_cpu(id->cctemp);
atomic_set(&ctrl->abort_limit, id->acl + 1);
+ ctrl->fna = id->fna;
ctrl->vwc = id->vwc;
if (id->mdts)
max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index fb1d7c812135..2a3679ef1397 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -328,6 +328,7 @@ struct nvme_ctrl {
u16 sqsize;
u32 max_namespaces;
atomic_t abort_limit;
+ u8 fna;
u8 vwc;
u32 vs;
u32 sgls;
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 108b6eda07dc..499468c7cbd8 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -553,6 +553,50 @@ static ssize_t dctype_show(struct device *dev,
}
static DEVICE_ATTR_RO(dctype);
+static ssize_t format_all_ns_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+ if (ctrl->fna)
+ return sysfs_emit(buf, "%d\n", !!(ctrl->fna & NVME_CTRL_FNA_ALL_NS));
+
+ return 0;
+}
+static DEVICE_ATTR_RO(format_all_ns);
+
+static ssize_t format_se_all_ns_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+ if (ctrl->fna)
+ return sysfs_emit(buf, "%d\n", !!(ctrl->fna & NVME_CTRL_FNA_SE_ALL_NS));
+
+ return 0;
+}
+static DEVICE_ATTR_RO(format_se_all_ns);
+
+static ssize_t format_crypto_erase_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+ if (ctrl->fna)
+ return sysfs_emit(buf, "%d\n", !!(ctrl->fna & NVME_CTRL_FNA_CRYPTO_ERASE));
+
+ return 0;
+}
+static DEVICE_ATTR_RO(format_crypto_erase);
+
+static ssize_t format_nsid_all_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+ if (ctrl->fna)
+ return sysfs_emit(buf, "%d\n", !!(ctrl->fna & NVME_CTRL_FNA_NSID_ALL));
+
+ return 0;
+}
+static DEVICE_ATTR_RO(format_nsid_all);
+
#ifdef CONFIG_NVME_HOST_AUTH
static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -694,6 +738,10 @@ static struct attribute *nvme_dev_attrs[] = {
&dev_attr_kato.attr,
&dev_attr_cntrltype.attr,
&dev_attr_dctype.attr,
+ &dev_attr_format_all_ns.attr,
+ &dev_attr_format_se_all_ns.attr,
+ &dev_attr_format_crypto_erase.attr,
+ &dev_attr_format_nsid_all.attr,
#ifdef CONFIG_NVME_HOST_AUTH
&dev_attr_dhchap_secret.attr,
&dev_attr_dhchap_ctrl_secret.attr,
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index b58d9405d65e..3505454549e9 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -388,6 +388,10 @@ enum {
NVME_CTRL_CTRATT_PREDICTABLE_LAT = 1 << 5,
NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY = 1 << 7,
NVME_CTRL_CTRATT_UUID_LIST = 1 << 9,
+ NVME_CTRL_FNA_ALL_NS = 1 << 0,
+ NVME_CTRL_FNA_SE_ALL_NS = 1 << 1,
+ NVME_CTRL_FNA_CRYPTO_ERASE = 1 << 2,
+ NVME_CTRL_FNA_NSID_ALL = 1 << 3,
};
struct nvme_lbaf {
--
2.43.0
More information about the Linux-nvme
mailing list