Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <kai.heng.feng@canonical.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Kai-Heng Feng and committed by
Jens Axboe
894fba7f 3aadcf83

+25 -4
+24 -4
drivers/ata/ahci.c
··· 1495 1495 static void ahci_remap_check(struct pci_dev *pdev, int bar, 1496 1496 struct ahci_host_priv *hpriv) 1497 1497 { 1498 - int i, count = 0; 1498 + int i; 1499 1499 u32 cap; 1500 1500 1501 1501 /* ··· 1516 1516 continue; 1517 1517 1518 1518 /* We've found a remapped device */ 1519 - count++; 1519 + hpriv->remapped_nvme++; 1520 1520 } 1521 1521 1522 - if (!count) 1522 + if (!hpriv->remapped_nvme) 1523 1523 return; 1524 1524 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); 1526 1527 dev_warn(&pdev->dev, 1527 1528 "Switch your BIOS from RAID to AHCI mode to use them.\n"); 1528 1529 ··· 1643 1642 } 1644 1643 } 1645 1644 1645 + static ssize_t remapped_nvme_show(struct device *dev, 1646 + struct device_attribute *attr, 1647 + char *buf) 1648 + { 1649 + struct ata_host *host = dev_get_drvdata(dev); 1650 + struct ahci_host_priv *hpriv = host->private_data; 1651 + 1652 + return sprintf(buf, "%u\n", hpriv->remapped_nvme); 1653 + } 1654 + 1655 + static DEVICE_ATTR_RO(remapped_nvme); 1656 + 1646 1657 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1647 1658 { 1648 1659 unsigned int board_id = ent->driver_data; ··· 1757 1744 1758 1745 /* detect remapped nvme devices */ 1759 1746 ahci_remap_check(pdev, ahci_pci_bar, hpriv); 1747 + 1748 + sysfs_add_file_to_group(&pdev->dev.kobj, 1749 + &dev_attr_remapped_nvme.attr, 1750 + NULL); 1760 1751 1761 1752 /* must set flag prior to save config in order to take effect */ 1762 1753 if (ahci_broken_devslp(pdev)) ··· 1913 1896 1914 1897 static void ahci_remove_one(struct pci_dev *pdev) 1915 1898 { 1899 + sysfs_remove_file_from_group(&pdev->dev.kobj, 1900 + &dev_attr_remapped_nvme.attr, 1901 + NULL); 1916 1902 pm_runtime_get_noresume(&pdev->dev); 1917 1903 ata_pci_remove_one(pdev); 1918 1904 }
+1
drivers/ata/ahci.h
··· 336 336 u32 em_loc; /* enclosure management location */ 337 337 u32 em_buf_sz; /* EM buffer size in byte */ 338 338 u32 em_msg_type; /* EM message type */ 339 + u32 remapped_nvme; /* NVMe remapped device count */ 339 340 bool got_runtime_pm; /* Did we do pm_runtime_get? */ 340 341 struct clk *clks[AHCI_MAX_CLKS]; /* Optional */ 341 342 struct reset_control *rsts; /* Optional */