Skip to content

Commit ddfb8b3

Browse files
maurizio-lombardikeithbusch
authored andcommitted
nvme: expose active quirks in sysfs
Currently, there is no straightforward way for a user to inspect which quirks are active for a given device from userspace. Add a new "quirks" sysfs attribute to the nvme controller device. Reading this file will display a human-readable list of all active quirks, with each quirk name on a new line. If no quirks are active, it will display "none". Tested-by: John Meneghini <jmeneghi@redhat.com> Reviewed-by: John Meneghini <jmeneghi@redhat.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent f947d9e commit ddfb8b3

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

drivers/nvme/host/nvme.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,60 @@ enum nvme_quirks {
180180
NVME_QUIRK_DMAPOOL_ALIGN_512 = (1 << 22),
181181
};
182182

183+
static inline char *nvme_quirk_name(enum nvme_quirks q)
184+
{
185+
switch (q) {
186+
case NVME_QUIRK_STRIPE_SIZE:
187+
return "stripe_size";
188+
case NVME_QUIRK_IDENTIFY_CNS:
189+
return "identify_cns";
190+
case NVME_QUIRK_DEALLOCATE_ZEROES:
191+
return "deallocate_zeroes";
192+
case NVME_QUIRK_DELAY_BEFORE_CHK_RDY:
193+
return "delay_before_chk_rdy";
194+
case NVME_QUIRK_NO_APST:
195+
return "no_apst";
196+
case NVME_QUIRK_NO_DEEPEST_PS:
197+
return "no_deepest_ps";
198+
case NVME_QUIRK_QDEPTH_ONE:
199+
return "qdepth_one";
200+
case NVME_QUIRK_MEDIUM_PRIO_SQ:
201+
return "medium_prio_sq";
202+
case NVME_QUIRK_IGNORE_DEV_SUBNQN:
203+
return "ignore_dev_subnqn";
204+
case NVME_QUIRK_DISABLE_WRITE_ZEROES:
205+
return "disable_write_zeroes";
206+
case NVME_QUIRK_SIMPLE_SUSPEND:
207+
return "simple_suspend";
208+
case NVME_QUIRK_SINGLE_VECTOR:
209+
return "single_vector";
210+
case NVME_QUIRK_128_BYTES_SQES:
211+
return "128_bytes_sqes";
212+
case NVME_QUIRK_SHARED_TAGS:
213+
return "shared_tags";
214+
case NVME_QUIRK_NO_TEMP_THRESH_CHANGE:
215+
return "no_temp_thresh_change";
216+
case NVME_QUIRK_NO_NS_DESC_LIST:
217+
return "no_ns_desc_list";
218+
case NVME_QUIRK_DMA_ADDRESS_BITS_48:
219+
return "dma_address_bits_48";
220+
case NVME_QUIRK_SKIP_CID_GEN:
221+
return "skip_cid_gen";
222+
case NVME_QUIRK_BOGUS_NID:
223+
return "bogus_nid";
224+
case NVME_QUIRK_NO_SECONDARY_TEMP_THRESH:
225+
return "no_secondary_temp_thresh";
226+
case NVME_QUIRK_FORCE_NO_SIMPLE_SUSPEND:
227+
return "force_no_simple_suspend";
228+
case NVME_QUIRK_BROKEN_MSI:
229+
return "broken_msi";
230+
case NVME_QUIRK_DMAPOOL_ALIGN_512:
231+
return "dmapool_align_512";
232+
}
233+
234+
return "unknown";
235+
}
236+
183237
/*
184238
* Common request structure for NVMe passthrough. All drivers must have
185239
* this structure as the first member of their request-private data.

drivers/nvme/host/sysfs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,28 @@ static ssize_t dctype_show(struct device *dev,
601601
}
602602
static DEVICE_ATTR_RO(dctype);
603603

604+
static ssize_t quirks_show(struct device *dev, struct device_attribute *attr,
605+
char *buf)
606+
{
607+
int count = 0, i;
608+
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
609+
unsigned long quirks = ctrl->quirks;
610+
611+
if (!quirks)
612+
return sysfs_emit(buf, "none\n");
613+
614+
for (i = 0; quirks; ++i) {
615+
if (quirks & 1) {
616+
count += sysfs_emit_at(buf, count, "%s\n",
617+
nvme_quirk_name(BIT(i)));
618+
}
619+
quirks >>= 1;
620+
}
621+
622+
return count;
623+
}
624+
static DEVICE_ATTR_RO(quirks);
625+
604626
#ifdef CONFIG_NVME_HOST_AUTH
605627
static ssize_t nvme_ctrl_dhchap_secret_show(struct device *dev,
606628
struct device_attribute *attr, char *buf)
@@ -742,6 +764,7 @@ static struct attribute *nvme_dev_attrs[] = {
742764
&dev_attr_kato.attr,
743765
&dev_attr_cntrltype.attr,
744766
&dev_attr_dctype.attr,
767+
&dev_attr_quirks.attr,
745768
#ifdef CONFIG_NVME_HOST_AUTH
746769
&dev_attr_dhchap_secret.attr,
747770
&dev_attr_dhchap_ctrl_secret.attr,

0 commit comments

Comments
 (0)