linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count
@ 2020-02-07 10:00 Kai-Heng Feng
  2020-02-20  5:45 ` Kai-Heng Feng
  2020-04-07 22:07 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2020-02-07 10:00 UTC (permalink / raw)
  To: axboe
  Cc: anthony.wong, Kai-Heng Feng,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

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>
---
 drivers/ata/ahci.c | 28 ++++++++++++++++++++++++----
 drivers/ata/ahci.h |  1 +
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 11ea1aff40db..cdbd995a7a6b 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1488,7 +1488,7 @@ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
 static void ahci_remap_check(struct pci_dev *pdev, int bar,
 		struct ahci_host_priv *hpriv)
 {
-	int i, count = 0;
+	int i;
 	u32 cap;
 
 	/*
@@ -1509,13 +1509,14 @@ static void ahci_remap_check(struct pci_dev *pdev, int bar,
 			continue;
 
 		/* We've found a remapped device */
-		count++;
+		hpriv->remapped_nvme++;
 	}
 
-	if (!count)
+	if (!hpriv->remapped_nvme)
 		return;
 
-	dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count);
+	dev_warn(&pdev->dev, "Found %u remapped NVMe devices.\n",
+		 hpriv->remapped_nvme);
 	dev_warn(&pdev->dev,
 		 "Switch your BIOS from RAID to AHCI mode to use them.\n");
 
@@ -1635,6 +1636,18 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
 	}
 }
 
+static ssize_t remapped_nvme_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct ata_host *host = dev_get_drvdata(dev);
+	struct ahci_host_priv *hpriv = host->private_data;
+
+	return sprintf(buf, "%u\n", hpriv->remapped_nvme);
+}
+
+static DEVICE_ATTR_RO(remapped_nvme);
+
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	unsigned int board_id = ent->driver_data;
@@ -1735,6 +1748,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* detect remapped nvme devices */
 	ahci_remap_check(pdev, ahci_pci_bar, hpriv);
 
+	sysfs_add_file_to_group(&pdev->dev.kobj,
+				&dev_attr_remapped_nvme.attr,
+				NULL);
+
 	/* must set flag prior to save config in order to take effect */
 	if (ahci_broken_devslp(pdev))
 		hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
@@ -1886,6 +1903,9 @@ static void ahci_shutdown_one(struct pci_dev *pdev)
 
 static void ahci_remove_one(struct pci_dev *pdev)
 {
+	sysfs_remove_file_from_group(&pdev->dev.kobj,
+				     &dev_attr_remapped_nvme.attr,
+				     NULL);
 	pm_runtime_get_noresume(&pdev->dev);
 	ata_pci_remove_one(pdev);
 }
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 3dbf398c92ea..d991dd46e89c 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -336,6 +336,7 @@ struct ahci_host_priv {
 	u32 			em_loc; /* enclosure management location */
 	u32			em_buf_sz;	/* EM buffer size in byte */
 	u32			em_msg_type;	/* EM message type */
+	u32			remapped_nvme;	/* NVMe remapped device count */
 	bool			got_runtime_pm; /* Did we do pm_runtime_get? */
 	struct clk		*clks[AHCI_MAX_CLKS]; /* Optional */
 	struct reset_control	*rsts;		/* Optional */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count
  2020-02-07 10:00 [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count Kai-Heng Feng
@ 2020-02-20  5:45 ` Kai-Heng Feng
  2020-04-07  6:08   ` Kai-Heng Feng
  2020-04-07 22:07 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Kai-Heng Feng @ 2020-02-20  5:45 UTC (permalink / raw)
  To: Jens Axboe
  Cc: anthony.wong,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list


> On Feb 7, 2020, at 18:00, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
> 
> 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>

A gentle ping...

> ---
> drivers/ata/ahci.c | 28 ++++++++++++++++++++++++----
> drivers/ata/ahci.h |  1 +
> 2 files changed, 25 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
> index 11ea1aff40db..cdbd995a7a6b 100644
> --- a/drivers/ata/ahci.c
> +++ b/drivers/ata/ahci.c
> @@ -1488,7 +1488,7 @@ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
> static void ahci_remap_check(struct pci_dev *pdev, int bar,
> 		struct ahci_host_priv *hpriv)
> {
> -	int i, count = 0;
> +	int i;
> 	u32 cap;
> 
> 	/*
> @@ -1509,13 +1509,14 @@ static void ahci_remap_check(struct pci_dev *pdev, int bar,
> 			continue;
> 
> 		/* We've found a remapped device */
> -		count++;
> +		hpriv->remapped_nvme++;
> 	}
> 
> -	if (!count)
> +	if (!hpriv->remapped_nvme)
> 		return;
> 
> -	dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count);
> +	dev_warn(&pdev->dev, "Found %u remapped NVMe devices.\n",
> +		 hpriv->remapped_nvme);
> 	dev_warn(&pdev->dev,
> 		 "Switch your BIOS from RAID to AHCI mode to use them.\n");
> 
> @@ -1635,6 +1636,18 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
> 	}
> }
> 
> +static ssize_t remapped_nvme_show(struct device *dev,
> +				  struct device_attribute *attr,
> +				  char *buf)
> +{
> +	struct ata_host *host = dev_get_drvdata(dev);
> +	struct ahci_host_priv *hpriv = host->private_data;
> +
> +	return sprintf(buf, "%u\n", hpriv->remapped_nvme);
> +}
> +
> +static DEVICE_ATTR_RO(remapped_nvme);
> +
> static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
> {
> 	unsigned int board_id = ent->driver_data;
> @@ -1735,6 +1748,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
> 	/* detect remapped nvme devices */
> 	ahci_remap_check(pdev, ahci_pci_bar, hpriv);
> 
> +	sysfs_add_file_to_group(&pdev->dev.kobj,
> +				&dev_attr_remapped_nvme.attr,
> +				NULL);
> +
> 	/* must set flag prior to save config in order to take effect */
> 	if (ahci_broken_devslp(pdev))
> 		hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
> @@ -1886,6 +1903,9 @@ static void ahci_shutdown_one(struct pci_dev *pdev)
> 
> static void ahci_remove_one(struct pci_dev *pdev)
> {
> +	sysfs_remove_file_from_group(&pdev->dev.kobj,
> +				     &dev_attr_remapped_nvme.attr,
> +				     NULL);
> 	pm_runtime_get_noresume(&pdev->dev);
> 	ata_pci_remove_one(pdev);
> }
> diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
> index 3dbf398c92ea..d991dd46e89c 100644
> --- a/drivers/ata/ahci.h
> +++ b/drivers/ata/ahci.h
> @@ -336,6 +336,7 @@ struct ahci_host_priv {
> 	u32 			em_loc; /* enclosure management location */
> 	u32			em_buf_sz;	/* EM buffer size in byte */
> 	u32			em_msg_type;	/* EM message type */
> +	u32			remapped_nvme;	/* NVMe remapped device count */
> 	bool			got_runtime_pm; /* Did we do pm_runtime_get? */
> 	struct clk		*clks[AHCI_MAX_CLKS]; /* Optional */
> 	struct reset_control	*rsts;		/* Optional */
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count
  2020-02-20  5:45 ` Kai-Heng Feng
@ 2020-04-07  6:08   ` Kai-Heng Feng
  0 siblings, 0 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2020-04-07  6:08 UTC (permalink / raw)
  To: Jens Axboe
  Cc: anthony.wong,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

Hi Jens,

> On Feb 20, 2020, at 13:45, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
> 
> 
>> On Feb 7, 2020, at 18:00, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
>> 
>> 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>
> 
> A gentle ping...

Any improvement I can make for this patch?

Kai-Heng

> 
>> ---
>> drivers/ata/ahci.c | 28 ++++++++++++++++++++++++----
>> drivers/ata/ahci.h |  1 +
>> 2 files changed, 25 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
>> index 11ea1aff40db..cdbd995a7a6b 100644
>> --- a/drivers/ata/ahci.c
>> +++ b/drivers/ata/ahci.c
>> @@ -1488,7 +1488,7 @@ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
>> static void ahci_remap_check(struct pci_dev *pdev, int bar,
>> 		struct ahci_host_priv *hpriv)
>> {
>> -	int i, count = 0;
>> +	int i;
>> 	u32 cap;
>> 
>> 	/*
>> @@ -1509,13 +1509,14 @@ static void ahci_remap_check(struct pci_dev *pdev, int bar,
>> 			continue;
>> 
>> 		/* We've found a remapped device */
>> -		count++;
>> +		hpriv->remapped_nvme++;
>> 	}
>> 
>> -	if (!count)
>> +	if (!hpriv->remapped_nvme)
>> 		return;
>> 
>> -	dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count);
>> +	dev_warn(&pdev->dev, "Found %u remapped NVMe devices.\n",
>> +		 hpriv->remapped_nvme);
>> 	dev_warn(&pdev->dev,
>> 		 "Switch your BIOS from RAID to AHCI mode to use them.\n");
>> 
>> @@ -1635,6 +1636,18 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
>> 	}
>> }
>> 
>> +static ssize_t remapped_nvme_show(struct device *dev,
>> +				  struct device_attribute *attr,
>> +				  char *buf)
>> +{
>> +	struct ata_host *host = dev_get_drvdata(dev);
>> +	struct ahci_host_priv *hpriv = host->private_data;
>> +
>> +	return sprintf(buf, "%u\n", hpriv->remapped_nvme);
>> +}
>> +
>> +static DEVICE_ATTR_RO(remapped_nvme);
>> +
>> static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>> {
>> 	unsigned int board_id = ent->driver_data;
>> @@ -1735,6 +1748,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>> 	/* detect remapped nvme devices */
>> 	ahci_remap_check(pdev, ahci_pci_bar, hpriv);
>> 
>> +	sysfs_add_file_to_group(&pdev->dev.kobj,
>> +				&dev_attr_remapped_nvme.attr,
>> +				NULL);
>> +
>> 	/* must set flag prior to save config in order to take effect */
>> 	if (ahci_broken_devslp(pdev))
>> 		hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
>> @@ -1886,6 +1903,9 @@ static void ahci_shutdown_one(struct pci_dev *pdev)
>> 
>> static void ahci_remove_one(struct pci_dev *pdev)
>> {
>> +	sysfs_remove_file_from_group(&pdev->dev.kobj,
>> +				     &dev_attr_remapped_nvme.attr,
>> +				     NULL);
>> 	pm_runtime_get_noresume(&pdev->dev);
>> 	ata_pci_remove_one(pdev);
>> }
>> diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
>> index 3dbf398c92ea..d991dd46e89c 100644
>> --- a/drivers/ata/ahci.h
>> +++ b/drivers/ata/ahci.h
>> @@ -336,6 +336,7 @@ struct ahci_host_priv {
>> 	u32 			em_loc; /* enclosure management location */
>> 	u32			em_buf_sz;	/* EM buffer size in byte */
>> 	u32			em_msg_type;	/* EM message type */
>> +	u32			remapped_nvme;	/* NVMe remapped device count */
>> 	bool			got_runtime_pm; /* Did we do pm_runtime_get? */
>> 	struct clk		*clks[AHCI_MAX_CLKS]; /* Optional */
>> 	struct reset_control	*rsts;		/* Optional */
>> -- 
>> 2.17.1
>> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count
  2020-02-07 10:00 [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count Kai-Heng Feng
  2020-02-20  5:45 ` Kai-Heng Feng
@ 2020-04-07 22:07 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-04-07 22:07 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: anthony.wong,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

On 2/7/20 2:00 AM, Kai-Heng Feng wrote:
> 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.

Sorry for the delay, looks good to me. Applied.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-07 22:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 10:00 [PATCH] ata: ahci: Add sysfs attribute to show remapped NVMe device count Kai-Heng Feng
2020-02-20  5:45 ` Kai-Heng Feng
2020-04-07  6:08   ` Kai-Heng Feng
2020-04-07 22:07 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).