Skip to content

Commit 894fba7

Browse files
khfengaxboe
authored andcommitted
ata: ahci: Add sysfs attribute to show remapped NVMe device count
Add a new sysfs attribute to show how many NVMe devices are remapped. Userspace like distro installer can use this info to ask user to change the BIOS setting. Signed-off-by: Kai-Heng Feng <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3aadcf8 commit 894fba7

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

drivers/ata/ahci.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
14951495
static void ahci_remap_check(struct pci_dev *pdev, int bar,
14961496
struct ahci_host_priv *hpriv)
14971497
{
1498-
int i, count = 0;
1498+
int i;
14991499
u32 cap;
15001500

15011501
/*
@@ -1516,13 +1516,14 @@ static void ahci_remap_check(struct pci_dev *pdev, int bar,
15161516
continue;
15171517

15181518
/* We've found a remapped device */
1519-
count++;
1519+
hpriv->remapped_nvme++;
15201520
}
15211521

1522-
if (!count)
1522+
if (!hpriv->remapped_nvme)
15231523
return;
15241524

1525-
dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count);
1525+
dev_warn(&pdev->dev, "Found %u remapped NVMe devices.\n",
1526+
hpriv->remapped_nvme);
15261527
dev_warn(&pdev->dev,
15271528
"Switch your BIOS from RAID to AHCI mode to use them.\n");
15281529

@@ -1642,6 +1643,18 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
16421643
}
16431644
}
16441645

1646+
static ssize_t remapped_nvme_show(struct device *dev,
1647+
struct device_attribute *attr,
1648+
char *buf)
1649+
{
1650+
struct ata_host *host = dev_get_drvdata(dev);
1651+
struct ahci_host_priv *hpriv = host->private_data;
1652+
1653+
return sprintf(buf, "%u\n", hpriv->remapped_nvme);
1654+
}
1655+
1656+
static DEVICE_ATTR_RO(remapped_nvme);
1657+
16451658
static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
16461659
{
16471660
unsigned int board_id = ent->driver_data;
@@ -1745,6 +1758,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
17451758
/* detect remapped nvme devices */
17461759
ahci_remap_check(pdev, ahci_pci_bar, hpriv);
17471760

1761+
sysfs_add_file_to_group(&pdev->dev.kobj,
1762+
&dev_attr_remapped_nvme.attr,
1763+
NULL);
1764+
17481765
/* must set flag prior to save config in order to take effect */
17491766
if (ahci_broken_devslp(pdev))
17501767
hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
@@ -1896,6 +1913,9 @@ static void ahci_shutdown_one(struct pci_dev *pdev)
18961913

18971914
static void ahci_remove_one(struct pci_dev *pdev)
18981915
{
1916+
sysfs_remove_file_from_group(&pdev->dev.kobj,
1917+
&dev_attr_remapped_nvme.attr,
1918+
NULL);
18991919
pm_runtime_get_noresume(&pdev->dev);
19001920
ata_pci_remove_one(pdev);
19011921
}

drivers/ata/ahci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ struct ahci_host_priv {
336336
u32 em_loc; /* enclosure management location */
337337
u32 em_buf_sz; /* EM buffer size in byte */
338338
u32 em_msg_type; /* EM message type */
339+
u32 remapped_nvme; /* NVMe remapped device count */
339340
bool got_runtime_pm; /* Did we do pm_runtime_get? */
340341
struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
341342
struct reset_control *rsts; /* Optional */

0 commit comments

Comments
 (0)