Skip to contentSkip to conversation

Use PCIe DSN to improve pciehp_resume

PATCH In review Yijing Wang 4 participants 23 messages Jul 11, 2013 – Jul 15, 2013 PCI

lore
Share & tools
lore
#0 lore raw

cover Use PCIe DSN to improve pciehp_resume

v1->v2: Modify pci_get_dsn to pci_device_serial_number,
power off slot before remove the old device during resume to avoid
old .remove() method to touch new hardware.
Fix other typo and fail check problems.
Split the list_empty() guard into new patch.

Yijing Wang (3):
PCI: introduce PCIe Device Serial Number Capability support PCI,pciehp: avoid add a device already exist before suspend during
resume
PCI,pciehp: use PCIe DSN to identify device change during suspend

 drivers/pci/hotplug/pciehp_core.c |   54 ++++++++++++++++++++++++++++++++++--
 drivers/pci/pci.c                 |   27 ++++++++++++++++++
 drivers/pci/probe.c               |    2 +
 include/linux/pci.h               |    3 ++
 4 files changed, 83 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/3 PCI: introduce PCIe Device Serial Number Capability support

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
 drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
 drivers/pci/probe.c |    2 ++
 include/linux/pci.h |    3 +++
 3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +27 -0
index e37fea6..2e855b5 100644
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
 }
 
 /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)
+{
+	int pos;
+	u64 sn;
+	u32 lo, hi;
+
+	if (!pci_is_pcie(dev))
+		return 0;
+
+	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+	if (!pos)
+		return 0;
+
+	pci_read_config_dword(dev, pos + 4, &lo);
+	pci_read_config_dword(dev, pos + 8, &hi);
+	sn = ((u64)hi << 32) | lo;
+	return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
  * pci_configure_ari - enable or disable ARI forwarding
  * @dev: the PCI device
  *
drivers/pci/probe.c +2 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev *dev)
 	/* Power Management */
 	pci_pm_init(dev);
 
+	dev->sn = pci_device_serial_number(dev);
+
 	/* Vital Product Data */
 	pci_vpd_pci22_init(dev);
 
include/linux/pci.h +3 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
 	struct list_head msi_list;
 	struct kset *msi_kset;
 #endif
+	u64 sn;		/* device serieal number, 0 if not support */
 	struct pci_vpd *vpd;
 #ifdef CONFIG_PCI_ATS
 	union {
@@ -995,6 +996,8 @@ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
 ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
 int pci_vpd_truncate(struct pci_dev *dev, size_t size);
 
+u64 pci_device_serial_number(struct pci_dev *dev);
+
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
 resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
 void pci_bus_assign_resources(const struct pci_bus *bus);
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 19 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
  drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
  drivers/pci/probe.c |    2 ++
  include/linux/pci.h |    3 +++
  3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index e37fea6..2e855b5 100644

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2057

Quoted 10 lines
drivers/pci/pci.c +7 -0
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
  }
 
  /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)

See comment below:
void pci_device_serial_number(struct pci_dev *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2065

Quoted 8 lines
drivers/pci/pci.c +8 -0
+{
+	int pos;
+	u64 sn;
+	u32 lo, hi;
+
+	if (!pci_is_pcie(dev))
+		return 0;
+

See comment below:

if (!pci_is_pcie(dev)) {
	dev->sn = 0;
	return;
}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 7 lines
drivers/pci/pci.c +7 -0
+	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+	if (!pos)
+		return 0;
+
+	pci_read_config_dword(dev, pos + 4,&lo);
+	pci_read_config_dword(dev, pos + 8,&hi);
+	sn = ((u64)hi<<  32) | lo;

See comment below:

	dev->sn = ((u64)hi<<  32) | lo;
	return;
Quoted 13 lines
drivers/pci/pci.c +5 -0
+	return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
   * pci_configure_ari - enable or disable ARI forwarding
   * @dev: the PCI device
   *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 5 lines
drivers/pci/probe.c +2 -0
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev *dev)
  	/* Power Management */
  	pci_pm_init(dev);
 
+	dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought
was an improvement, but why not do above assignment in pci_device_serial_number() ? See above....
- Don

Quoted 24 lines
drivers/pci/probe.c +0 -0
  	/* Vital Product Data */
  	pci_vpd_pci22_init(dev);
 
include/linux/pci.h +3 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
  	struct list_head msi_list;
  	struct kset *msi_kset;
  #endif
+	u64 sn;		/* device serieal number, 0 if not support */
  	struct pci_vpd *vpd;
  #ifdef CONFIG_PCI_ATS
  	union {
@@ -995,6 +996,8 @@ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
  int pci_vpd_truncate(struct pci_dev *dev, size_t size);
 
+u64 pci_device_serial_number(struct pci_dev *dev);
+
  /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
  resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
  void pci_bus_assign_resources(const struct pci_bus *bus);
maintainer
#3 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 81 lines · Don Dutile
Quoted 20 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
  drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
  drivers/pci/probe.c |    2 ++
  include/linux/pci.h |    3 +++
  3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index e37fea6..2e855b5 100644

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2057

Quoted 10 lines
drivers/pci/pci.c +7 -0
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
  }
 
  /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)

See comment below:
void pci_device_serial_number(struct pci_dev *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2065

Quoted 8 lines
drivers/pci/pci.c +8 -0
+{
+       int pos;
+       u64 sn;
+       u32 lo, hi;
+
+       if (!pci_is_pcie(dev))
+               return 0;
+

See comment below:

if (!pci_is_pcie(dev)) {
        dev->sn = 0;
        return;

}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 8 lines
drivers/pci/pci.c +7 -0
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+       if (!pos)
+               return 0;
+
+       pci_read_config_dword(dev, pos + 4,&lo);
+       pci_read_config_dword(dev, pos + 8,&hi);
+       sn = ((u64)hi<<  32) | lo;

See comment below:

        dev->sn = ((u64)hi<<  32) | lo;
        return;
Quoted 17 lines
drivers/pci/pci.c +5 -0
+       return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
   * pci_configure_ari - enable or disable ARI forwarding
   * @dev: the PCI device
   *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev
 *dev)
        /* Power Management */
        pci_pm_init(dev);
 
Quoted 8 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+       dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought was an improvement, but why not do above assignment in pci_device_serial_number() ?
See above....

pci_device_serial_number() would then have the side-effect of saving the result somewhere, and callers would have to know where to look. Personally, I think it's simpler to return the serial number directly and avoid the side-effect, but maybe this is just bike-shedding.

As long as we are bike-shedding, I'd just drop "sn" and do:

    return ((u64)hi << 32) | lo;

And of course, you need spaces before "&hi" and "&lo" in the pci_read_config_dword() calls.

#4 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 91 lines · Bjorn Helgaas
Quoted 81 lines · Don Dutile
Quoted 20 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
   drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
   drivers/pci/probe.c |    2 ++
   include/linux/pci.h |    3 +++
   3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index e37fea6..2e855b5 100644

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2057

Quoted 10 lines
drivers/pci/pci.c +7 -0
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
   }
 
   /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)

See comment below:
void pci_device_serial_number(struct pci_dev *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2065

Quoted 8 lines
drivers/pci/pci.c +8 -0
+{
+       int pos;
+       u64 sn;
+       u32 lo, hi;
+
+       if (!pci_is_pcie(dev))
+               return 0;
+

See comment below:

if (!pci_is_pcie(dev)) {
         dev->sn = 0;
         return;

}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 8 lines
drivers/pci/pci.c +7 -0
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+       if (!pos)
+               return 0;
+
+       pci_read_config_dword(dev, pos + 4,&lo);
+       pci_read_config_dword(dev, pos + 8,&hi);
+       sn = ((u64)hi<<   32) | lo;

See comment below:

         dev->sn = ((u64)hi<<   32) | lo;
         return;
Quoted 17 lines
drivers/pci/pci.c +5 -0
+       return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
    * pci_configure_ari - enable or disable ARI forwarding
    * @dev: the PCI device
    *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev
 *dev)
         /* Power Management */
         pci_pm_init(dev);
 
Quoted 8 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+       dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought was an improvement, but why not do above assignment in pci_device_serial_number() ?
See above....

Quoted 2 lines

pci_device_serial_number() would then have the side-effect of saving the result somewhere, and callers would have to know where to look.

Ah, like so many other features of a PCI device? -- what are all those flags/status bits in pdev for ??? ;-)

Quoted 3 lines

Personally, I think it's simpler to return the serial number directly and avoid the side-effect, but maybe this is just bike-shedding.

What struck me about rtning a value is in pci_init_capabilities(),
it was the only function with a rtn value that had to be put into a pci_dev struct element, while all the others stored their related capabilities in the pdev, or other struct related to it.

So, maybe there should be a "pci_device_serial_number_init()" function which does the storage in the pdev struct, and another (wrapper, dare I shoot myself, inline) that is "pci_device_serial_number()" that returns the value of the pdev's sn element, if another module or other core component want to get it. .... and do that in a future patch... :-/

Quoted 6 lines

As long as we are bike-shedding, I'd just drop "sn" and do:

     return ((u64)hi<<  32) | lo;

And of course, you need spaces before "&hi" and "&lo" in the pci_read_config_dword() calls.

#5 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 100 lines · Don Dutile
Quoted 91 lines · Bjorn Helgaas
Quoted 81 lines · Don Dutile
Quoted 20 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
   drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
   drivers/pci/probe.c |    2 ++
   include/linux/pci.h |    3 +++
   3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index e37fea6..2e855b5 100644

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2057

Quoted 10 lines
drivers/pci/pci.c +7 -0
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
   }
 
   /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)

See comment below:
void pci_device_serial_number(struct pci_dev *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2065

Quoted 8 lines
drivers/pci/pci.c +8 -0
+{
+       int pos;
+       u64 sn;
+       u32 lo, hi;
+
+       if (!pci_is_pcie(dev))
+               return 0;
+

See comment below:

if (!pci_is_pcie(dev)) {
         dev->sn = 0;
         return;

}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 8 lines
drivers/pci/pci.c +7 -0
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+       if (!pos)
+               return 0;
+
+       pci_read_config_dword(dev, pos + 4,&lo);
+       pci_read_config_dword(dev, pos + 8,&hi);
+       sn = ((u64)hi<<   32) | lo;

See comment below:

         dev->sn = ((u64)hi<<   32) | lo;
         return;
Quoted 17 lines
drivers/pci/pci.c +5 -0
+       return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
    * pci_configure_ari - enable or disable ARI forwarding
    * @dev: the PCI device
    *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev
 *dev)
         /* Power Management */
         pci_pm_init(dev);
 
Quoted 8 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+       dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought was an improvement, but why not do above assignment in pci_device_serial_number() ?
See above....

Quoted 2 lines

pci_device_serial_number() would then have the side-effect of saving the result somewhere, and callers would have to know where to look.

Ah, like so many other features of a PCI device? -- what are all those flags/status bits in pdev for ??? ;-)

Quoted 3 lines

Personally, I think it's simpler to return the serial number directly and avoid the side-effect, but maybe this is just bike-shedding.

Quoted 8 lines

What struck me about rtning a value is in pci_init_capabilities(),
it was the only function with a rtn value that had to be put into a pci_dev struct element, while all the others stored their related capabilities in the pdev, or other struct related to it.

So, maybe there should be a "pci_device_serial_number_init()" function which does the storage in the pdev struct, and another (wrapper, dare I shoot myself, inline) that is "pci_device_serial_number()" that returns

add an wrapper function may be ok, as I mentioned in pre-reply, what about,

static void pci_init_capabilities(struct pci_dev *dev)

     ...............
     pci_dsn_init(dev);
     .................

void pci_dsn_init(dev)

{
     dev->sn = pci_device_serial_number(dev);
}
Quoted 13 lines

the value of the pdev's sn element, if another module or other core component want to get it. .... and do that in a future patch... :-/

Quoted 6 lines

As long as we are bike-shedding, I'd just drop "sn" and do:

     return ((u64)hi<<  32) | lo;

And of course, you need spaces before "&hi" and "&lo" in the pci_read_config_dword() calls.

.

Signature · 2 lines
Thanks!
Yijing
maintainer
#6 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

In reply to Don Dutile
Quoted 112 lines · Don Dutile
Quoted 101 lines · Bjorn Helgaas
Quoted 88 lines · Don Dutile
Quoted 22 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
   drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
   drivers/pci/probe.c |    2 ++
   include/linux/pci.h |    3 +++
   3 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/pci.c +0 -0
index e37fea6..2e855b5 100644
@@ -2048,6 +2048,33 @@ void pci_free_cap_save_buffers(struct pci_dev
 *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev · line 2058

Quoted 10 lines
drivers/pci/pci.c +7 -0
   }
 
   /**
+ * pci_device_serial_number - get device serial number
+ * @dev: the PCI device
+ *
+ * return the device serial number if device support,
+ * otherwise return 0.
+ */
+u64 pci_device_serial_number(struct pci_dev *dev)

See comment below:
void pci_device_serial_number(struct pci_dev *dev)

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev) · line 2065

Quoted 8 lines
drivers/pci/pci.c +8 -0
+{
+       int pos;
+       u64 sn;
+       u32 lo, hi;
+
+       if (!pci_is_pcie(dev))
+               return 0;
+

See comment below:

if (!pci_is_pcie(dev)) {
         dev->sn = 0;
         return;

}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 9 lines
drivers/pci/pci.c +7 -0
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+       if (!pos)
+               return 0;
+
+       pci_read_config_dword(dev, pos + 4,&lo);
+       pci_read_config_dword(dev, pos + 8,&hi);
+       sn = ((u64)hi<<   32) | lo;

See comment below:

         dev->sn = ((u64)hi<<   32) | lo;
         return;
Quoted 17 lines
drivers/pci/pci.c +5 -0
+       return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
    * pci_configure_ari - enable or disable ARI forwarding
    * @dev: the PCI device
    *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev
 *dev)
         /* Power Management */
         pci_pm_init(dev);
 
Quoted 9 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+       dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought was an improvement, but why not do above assignment in pci_device_serial_number() ?
See above....

Quoted 2 lines

pci_device_serial_number() would then have the side-effect of saving the result somewhere, and callers would have to know where to look.

Ah, like so many other features of a PCI device? -- what are all those flags/status bits in pdev for ??? ;-)

Quoted 3 lines

Personally, I think it's simpler to return the serial number directly and avoid the side-effect, but maybe this is just bike-shedding.

Quoted 6 lines

What struck me about rtning a value is in pci_init_capabilities(), it was the only function with a rtn value that had to be put into a pci_dev struct element,
while all the others stored their related capabilities in the pdev, or other struct
related to it.

Good point, BTW. I hadn't thought about it from that angle.

Quoted 7 lines

So, maybe there should be a "pci_device_serial_number_init()" function which does the storage in the pdev struct, and another (wrapper, dare I shoot myself, inline) that is "pci_device_serial_number()" that returns
the value of the pdev's sn element, if another module or other core component
want to get it. .... and do that in a future patch... :-/

Of course, for Yijing's use, it's important that we're able to get the *non-cached* serial number, because the cached one belongs to the old, pre-suspend device, and we want to look at the post-suspend device to see if it's the same.

Sigh. I dunno, I'll have to finish sorting through this in a week or so... (I'll be on vacation for the next few days.)

Bjorn

#7 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

In reply to Bjorn Helgaas
Quoted 45 lines
Quoted 31 lines

}

drivers/pci/pci.c void pci_free_cap_save_buffers(struct pci_dev *dev)

Quoted 8 lines
drivers/pci/pci.c +7 -0
+       pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+       if (!pos)
+               return 0;
+
+       pci_read_config_dword(dev, pos + 4,&lo);
+       pci_read_config_dword(dev, pos + 8,&hi);
+       sn = ((u64)hi<<  32) | lo;

See comment below:

        dev->sn = ((u64)hi<<  32) | lo;
        return;
Quoted 17 lines
drivers/pci/pci.c +5 -0
+       return sn;
+}
+EXPORT_SYMBOL(pci_device_serial_number);
+
+/**
   * pci_configure_ari - enable or disable ARI forwarding
   * @dev: the PCI device
   *
drivers/pci/probe.c +0 -0
index 46ada5c..c4c1a2b 100644
@@ -1322,6 +1322,8 @@ static void pci_init_capabilities(struct pci_dev
 *dev)
        /* Power Management */
        pci_pm_init(dev);
 
Quoted 8 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+       dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought was an improvement, but why not do above assignment in pci_device_serial_number() ?
See above....

pci_device_serial_number() would then have the side-effect of saving the result somewhere, and callers would have to know where to look. Personally, I think it's simpler to return the serial number directly and avoid the side-effect, but maybe this is just bike-shedding.

Quoted 6 lines

As long as we are bike-shedding, I'd just drop "sn" and do:

    return ((u64)hi << 32) | lo;

And of course, you need spaces before "&hi" and "&lo" in the pci_read_config_dword() calls.

OK, will drop "sn", strangely my original patch has spaces before "&hi" and "&lo", but in reply the spaces disappeared.

Thanks!
Yijing.

Quoted 6 lines

.

Signature · 2 lines
Thanks!
Yijing
#8 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

In reply to Don Dutile

Hi Don,
Thanks for your review and comments very much!

Quoted 5 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+    dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought
was an improvement, but why not do above assignment in pci_device_serial_number() ?

I don't do assignment in pci_device_serial_number() because pci_device_serial_number() is an EXPORT_SYMBOL, and will be used to get dsn for non-scaned device, for example:

1. we have pcie device in slot before suspend.
2. we removed the device during suspend.
3. we reinserted a new device during suspend.
4. we should check the device change during resume, so we try to use pcie device serial number to identify changes. But the pci_dev structure maybe the old stale data. So I prefer to get dsn by return.

what about this:

static void pci_init_capabilities(struct pci_dev *dev)

    ........
    pci_dsn_init(dev);
    ..........

void pci_dsn_init(dev)

{
    dev->sn = pci_device_serial_number(dev);
}
Quoted 31 lines

See above....
- Don

Quoted 16 lines
      /* Vital Product Data */
      pci_vpd_pci22_init(dev);
include/linux/pci.h +1 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
      struct list_head msi_list;
      struct kset *msi_kset;
  #endif
+    u64 sn;        /* device serieal number, 0 if not support */
      struct pci_vpd *vpd;
  #ifdef CONFIG_PCI_ATS
      union {

include/linux/pci.h ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf); · line 1003

Quoted 8 lines
include/linux/pci.h +2 -0
@@ -995,6 +996,8 @@ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
  int pci_vpd_truncate(struct pci_dev *dev, size_t size);
 
+u64 pci_device_serial_number(struct pci_dev *dev);
+
  /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
  resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
  void pci_bus_assign_resources(const struct pci_bus *bus);

.

Signature · 2 lines
Thanks!
Yijing
#9 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 28 lines · Yijing Wang

Hi Don,
Thanks for your review and comments very much!

Quoted 5 lines

drivers/pci/probe.c static void pci_init_capabilities(struct pci_dev *dev) · line 1326

Quoted 2 lines
drivers/pci/probe.c +2 -0
+    dev->sn = pci_device_serial_number(dev);
+

Finally, 'the comment below':
I know you were following Bjorn's suggestion, which I thought
was an improvement, but why not do above assignment in pci_device_serial_number() ?

I don't do assignment in pci_device_serial_number() because pci_device_serial_number() is an EXPORT_SYMBOL, and will be used to get dsn for non-scaned device, for example:

1. we have pcie device in slot before suspend.
2. we removed the device during suspend.
3. we reinserted a new device during suspend.
4. we should check the device change during resume, so we try to use pcie device serial number to identify changes. But the pci_dev structure maybe the old stale data. So I prefer to get dsn by return.

what about this:

static void pci_init_capabilities(struct pci_dev *dev)

     ........
     pci_dsn_init(dev);
     ..........
Quoted 7 lines

void pci_dsn_init(dev)

{
     dev->sn = pci_device_serial_number(dev);
}

Looks good! I think that meets all the uses (use in init, post-suspend).
- Don

Quoted 33 lines
Quoted 31 lines

See above....
- Don

Quoted 16 lines
       /* Vital Product Data */
       pci_vpd_pci22_init(dev);
include/linux/pci.h +1 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
       struct list_head msi_list;
       struct kset *msi_kset;
   #endif
+    u64 sn;        /* device serieal number, 0 if not support */
       struct pci_vpd *vpd;
   #ifdef CONFIG_PCI_ATS
       union {

include/linux/pci.h ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf); · line 1003

Quoted 8 lines
include/linux/pci.h +2 -0
@@ -995,6 +996,8 @@ ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
   ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
   int pci_vpd_truncate(struct pci_dev *dev, size_t size);
 
+u64 pci_device_serial_number(struct pci_dev *dev);
+
   /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
   resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
   void pci_bus_assign_resources(const struct pci_bus *bus);

.

#10 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

In reply to Yijing Wang
Quoted 14 lines · Yijing Wang

Introduce PCIe Ext Capability Device Serial Number support, so we can use the unique device serial number to identify the physical device. During system suspend, if the PCIe device was removed and inserted a new same device, after system resume there is no good way to identify it, maybe Device Serial Number is a good choice if device support.

---
 drivers/pci/pci.c   |   27 +++++++++++++++++++++++++++
 drivers/pci/probe.c |    2 ++
 include/linux/pci.h |    3 +++
 3 files changed, 32 insertions(+), 0 deletions(-)

[...]

include/linux/pci.h struct pci_dev { · line 345

Quoted 9 lines
include/linux/pci.h +1 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
 	struct list_head msi_list;
 	struct kset *msi_kset;
 #endif
+	u64 sn;		/* device serieal number, 0 if not support */

Typo: serieal

include/linux/pci.h struct pci_dev { · line 348

Quoted 3 lines
include/linux/pci.h +0 -0
 	struct pci_vpd *vpd;
 #ifdef CONFIG_PCI_ATS
 	union {

[...]

Paul Bolle

#11 lore raw

Re: [PATCH -v2 1/3] PCI: introduce PCIe Device Serial Number Capability support

Quoted 14 lines
Quoted 2 lines

[...]

include/linux/pci.h struct pci_dev { · line 345

Quoted 9 lines
include/linux/pci.h +1 -0
index 0fd1f15..10d190b 100644
@@ -342,6 +342,7 @@ struct pci_dev {
 	struct list_head msi_list;
 	struct kset *msi_kset;
 #endif
+	u64 sn;		/* device serieal number, 0 if not support */

Typo: serieal

Thanks very much! Will update.

Quoted 13 lines

include/linux/pci.h struct pci_dev { · line 348

Quoted 4 lines
include/linux/pci.h +0 -0
 	struct pci_vpd *vpd;
 #ifdef CONFIG_PCI_ATS
 	union {

[...]

Paul Bolle

.

Signature · 2 lines
Thanks!
Yijing
#12 lore raw

PATCH 2/3 PCI,pciehp: avoid add a device already exist before suspend during resume

In reply to Yijing Wang

Currently, pciehp_resume() try to hot add device if the slot adapter status return true. But if there are already some devices exist, namely list_empty(bus->devices) return false. We should not add the device again, because the device add action will fail. Also print some uncomfortable messages like this:

	pciehp 0000:00:1c.1:pcie04: Device 0000:03:00.0 already exists at 0000:03:00, cannot hot-add
	pciehp 0000:00:1c.1:pcie04: Cannot add device at 0000:03:00
Cc Paul Bolle <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Gu Zheng <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/pci/hotplug/pciehp_core.c +6 -3
index 7d72c5e..1542735 100644
@@ -300,6 +300,7 @@ static int pciehp_resume (struct pcie_device *dev)
 {
 	struct controller *ctrl;
 	struct slot *slot;
+	struct pci_bus *pbus = dev->port->subordinate;
 	u8 status;
 
 	ctrl = get_service_data(dev);
@@ -311,10 +312,12 @@ static int pciehp_resume (struct pcie_device *dev)
 
 	/* Check if slot is occupied */
 	pciehp_get_adapter_status(slot, &status);
-	if (status)
-		pciehp_enable_slot(slot);
-	else
+	if (status) {
+		if (list_empty(&pbus->devices))
+			pciehp_enable_slot(slot);
+	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
+
 	return 0;
 }
 #endif /* PM */
Signature · 1 line
1.7.1
#13 lore raw

Re: [PATCH -v2 2/3] PCI,pciehp: avoid add a device already exist before suspend during resume

Quoted 22 lines · Yijing Wang

Currently, pciehp_resume() try to hot add device if the slot adapter status return true. But if there are already some devices exist, namely list_empty(bus->devices) return false. We should not add the device again, because the device add action will fail. Also print some uncomfortable messages like this:

	pciehp 0000:00:1c.1:pcie04: Device 0000:03:00.0 already exists at 0000:03:00, cannot hot-add
	pciehp 0000:00:1c.1:pcie04: Cannot add device at 0000:03:00
Cc Paul Bolle <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Gu Zheng <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/pci/hotplug/pciehp_core.c +0 -0
index 7d72c5e..1542735 100644

[...]

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 320

Quoted 13 lines
drivers/pci/hotplug/pciehp_core.c +5 -3
@@ -311,10 +312,12 @@ static int pciehp_resume (struct pcie_device *dev)
 
 	/* Check if slot is occupied */
 	pciehp_get_adapter_status(slot, &status);
-	if (status)
-		pciehp_enable_slot(slot);
-	else
+	if (status) {
+		if (list_empty(&pbus->devices))
+			pciehp_enable_slot(slot);
+	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
+

Coding style: braces for the "else if" branch too? Or change the first test to "if (status && list_empty([...]))" and drop the braces?

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 323

Quoted 3 lines
drivers/pci/hotplug/pciehp_core.c +0 -0
 	return 0;
 }
 #endif /* PM */

Paul Bolle

#14 lore raw

Re: [PATCH -v2 2/3] PCI,pciehp: avoid add a device already exist before suspend during resume

Quoted 11 lines
Quoted 8 lines
---
 drivers/pci/hotplug/pciehp_core.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/pci/hotplug/pciehp_core.c +0 -0
index 7d72c5e..1542735 100644

[...]

Quoted 2 lines
drivers/pci/hotplug/pciehp_core.c +0 -0
@@ -311,10 +312,12 @@ static int pciehp_resume (struct pcie_device *dev)
 
Quoted 14 lines

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 320

Quoted 11 lines
drivers/pci/hotplug/pciehp_core.c +5 -3
 	/* Check if slot is occupied */
 	pciehp_get_adapter_status(slot, &status);
-	if (status)
-		pciehp_enable_slot(slot);
-	else
+	if (status) {
+		if (list_empty(&pbus->devices))
+			pciehp_enable_slot(slot);
+	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
+

Coding style: braces for the "else if" branch too? Or change the first test to "if (status && list_empty([...]))" and drop the braces?

Hmmm, I will add the braces for "else if "

Change the first test "if (status && list_empty([...]))" is not a good idea, because this change will modify the code logic, for example
if a device was present before suspend and still there during resume, we should do nothing, but after the logic change, we may disable it.

Quoted 11 lines

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 323

Quoted 4 lines
drivers/pci/hotplug/pciehp_core.c +0 -0
 	return 0;
 }
 #endif /* PM */

Paul Bolle

.

Signature · 2 lines
Thanks!
Yijing
#15 lore raw

PATCH 3/3 PCI,pciehp: use PCIe DSN to identify device change during suspend

In reply to Yijing Wang

If device was removed from slot and reinsert a new device during suspend, pciehp can not identify the physical device change now. So the old driver .resume() method will be called for the new device, this is bad. If device support device serial number capability, we can identify this by DSN. So the reasonable way is first remove the old device, then enable the new device.

Cc Paul Bolle <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Gu Zheng <[email protected]>
---
 drivers/pci/hotplug/pciehp_core.c |   45 +++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
drivers/pci/hotplug/pciehp_core.c +45 -0
index 1542735..f2eb214 100644
@@ -296,11 +296,38 @@ static int pciehp_suspend (struct pcie_device *dev)
 	return 0;
 }
 
+/*
+ * check the func 0 device serial number is changed,
+ * if device does not support device serial number,
+ * return false.
+ */
+static bool device_serial_number_changed(struct pci_bus *pbus)
+{
+	u64 old_dsn, new_dsn;
+	struct pci_dev *pdev;
+
+	pdev = pci_get_slot(pbus, PCI_DEVFN(0, 0));
+	if (!pdev)
+		return false;
+
+	old_dsn = pdev->sn;
+
+	/* get func 0 device serial number */
+	new_dsn = pci_device_serial_number(pdev);
+	pci_dev_put(pdev);
+
+	if (old_dsn != new_dsn)
+		return true;
+
+	return false;
+}
+
 static int pciehp_resume (struct pcie_device *dev)
 {
 	struct controller *ctrl;
 	struct slot *slot;
 	struct pci_bus *pbus = dev->port->subordinate;
+	int retval = 0;
 	u8 status;
 
 	ctrl = get_service_data(dev);
@@ -315,6 +342,24 @@ static int pciehp_resume (struct pcie_device *dev)
 	if (status) {
 		if (list_empty(&pbus->devices))
 			pciehp_enable_slot(slot);
+
+		if (device_serial_number_changed(pbus)) {
+			/*
+			 * first power off slot, avoid the old driver
+			 * .remove() method touch the new hardware
+			 */
+			if (POWER_CTRL(ctrl)) {
+				retval = pciehp_power_off_slot(slot);
+				if (retval) {
+					ctrl_err(ctrl,
+						"Issue of Slot Disable command failed\n");
+					return 0;
+				}
+				msleep(1000);
+				pciehp_unconfigure_device(slot);
+				pciehp_enable_slot(slot);
+			}
+		}
 	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
 	
Signature · 1 line
1.7.1
#16 lore raw

Re: [PATCH -v2 3/3] PCI,pciehp: use PCIe DSN to identify device change during suspend

Sorry, did a 'reply' instead of 'reply all' on first reply to this patch... excuse any repeat...
- Don

Quoted 33 lines · Yijing Wang

If device was removed from slot and reinsert a new device during suspend, pciehp can not identify the physical device change now. So the old driver .resume() method will be called for the new device, this is bad. If device support device serial number capability, we can identify this by DSN. So the reasonable way is first remove the old device, then enable the new device.

Cc Paul Bolle<[email protected]>
Cc "Rafael J. Wysocki"<[email protected]>
Cc Oliver Neukum<[email protected]>
Cc Gu Zheng<[email protected]>
---
  drivers/pci/hotplug/pciehp_core.c |   45 +++++++++++++++++++++++++++++++++++++
  1 files changed, 45 insertions(+), 0 deletions(-)
drivers/pci/hotplug/pciehp_core.c +8 -0
index 1542735..f2eb214 100644
@@ -296,11 +296,38 @@ static int pciehp_suspend (struct pcie_device *dev)
  	return 0;
  }
 
+/*
+ * check the func 0 device serial number is changed,
+ * if device does not support device serial number,
+ * return false.
+ */
+static bool device_serial_number_changed(struct pci_bus *pbus)
+{
+	u64 old_dsn, new_dsn;

drivers/pci/hotplug/pciehp_core.c static int pciehp_suspend (struct pcie_device *dev) · line 316

Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +10 -0
+	struct pci_dev *pdev;
+
+	pdev = pci_get_slot(pbus, PCI_DEVFN(0, 0));
+	if (!pdev)
+		return false;
+
+	old_dsn = pdev->sn;
+
+	/* get func 0 device serial number */
+	new_dsn = pci_device_serial_number(pdev);

Due to previous recommended change to 1/3 patch, above would be:

    pci_device_serial_number(pdev);

drivers/pci/hotplug/pciehp_core.c static int pciehp_suspend (struct pcie_device *dev) · line 321

Quoted 5 lines
drivers/pci/hotplug/pciehp_core.c +5 -0
+	pci_dev_put(pdev);
+
+	if (old_dsn != new_dsn)
+		return true;
+

and above would be:

    new_dsn = pdev->dsn;
    pci_dev_put(pdev);
    if(pdev->dsn != old_dsn)
        return true;
Quoted 37 lines
drivers/pci/hotplug/pciehp_core.c +22 -0
+	return false;
+}
+
  static int pciehp_resume (struct pcie_device *dev)
  {
  	struct controller *ctrl;
  	struct slot *slot;
  	struct pci_bus *pbus = dev->port->subordinate;
+	int retval = 0;
  	u8 status;
 
  	ctrl = get_service_data(dev);
@@ -315,6 +342,24 @@ static int pciehp_resume (struct pcie_device *dev)
  	if (status) {
  		if (list_empty(&pbus->devices))
  			pciehp_enable_slot(slot);
+
+		if (device_serial_number_changed(pbus)) {
+			/*
+			 * first power off slot, avoid the old driver
+			 * .remove() method touch the new hardware
+			 */
+			if (POWER_CTRL(ctrl)) {
+				retval = pciehp_power_off_slot(slot);
+				if (retval) {
+					ctrl_err(ctrl,
+						"Issue of Slot Disable command failed\n");
+					return 0;
+				}
+				msleep(1000);
+				pciehp_unconfigure_device(slot);
+				pciehp_enable_slot(slot);
+			}
+		}
  	} else if (!list_empty(&pbus->devices))
  		pciehp_disable_slot(slot);
 
#17 lore raw

Re: [PATCH -v2 3/3] PCI,pciehp: use PCIe DSN to identify device change during suspend

In reply to Yijing Wang

On Thu, 2013-07-11 at 17:43 +0800, Yijing Wang wrote:
[...]

Quoted 4 lines
drivers/pci/hotplug/pciehp_core.c +0 -0
index 1542735..f2eb214 100644

[...]

Quoted 15 lines
drivers/pci/hotplug/pciehp_core.c +11 -0
@@ -315,6 +342,24 @@ static int pciehp_resume (struct pcie_device *dev)
 	if (status) {
 		if (list_empty(&pbus->devices))
 			pciehp_enable_slot(slot);
+
+		if (device_serial_number_changed(pbus)) {
+			/*
+			 * first power off slot, avoid the old driver
+			 * .remove() method touch the new hardware
+			 */
+			if (POWER_CTRL(ctrl)) {
+				retval = pciehp_power_off_slot(slot);
+				if (retval) {
+					ctrl_err(ctrl,
+						"Issue of Slot Disable command failed\n");

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 365

Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +7 -0
+					return 0;
+				}
+				msleep(1000);
+				pciehp_unconfigure_device(slot);
+				pciehp_enable_slot(slot);
+			}
+		}
 	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
 

It was surprisingly hard to see why the patch wouldn't apply to v3.10. It turns out the very last line of context is a line consisting of just a single tab. And in v3.10 it is an empty line.

Is that lone tab perhaps an editing mistake on your side?

Paul Bolle

#18 lore raw

Re: [PATCH -v2 3/3] PCI,pciehp: use PCIe DSN to identify device change during suspend

Quoted 37 lines · Paul Bolle

On Thu, 2013-07-11 at 17:43 +0800, Yijing Wang wrote:
[...]

Quoted 4 lines
drivers/pci/hotplug/pciehp_core.c +0 -0
index 1542735..f2eb214 100644

[...]

Quoted 15 lines
drivers/pci/hotplug/pciehp_core.c +11 -0
@@ -315,6 +342,24 @@ static int pciehp_resume (struct pcie_device *dev)
 	if (status) {
 		if (list_empty(&pbus->devices))
 			pciehp_enable_slot(slot);
+
+		if (device_serial_number_changed(pbus)) {
+			/*
+			 * first power off slot, avoid the old driver
+			 * .remove() method touch the new hardware
+			 */
+			if (POWER_CTRL(ctrl)) {
+				retval = pciehp_power_off_slot(slot);
+				if (retval) {
+					ctrl_err(ctrl,
+						"Issue of Slot Disable command failed\n");

drivers/pci/hotplug/pciehp_core.c static int pciehp_resume (struct pcie_device *dev) · line 365

Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +7 -0
+					return 0;
+				}
+				msleep(1000);
+				pciehp_unconfigure_device(slot);
+				pciehp_enable_slot(slot);
+			}
+		}
 	} else if (!list_empty(&pbus->devices))
 		pciehp_disable_slot(slot);
 

It was surprisingly hard to see why the patch wouldn't apply to v3.10. It turns out the very last line of context is a line consisting of just a single tab. And in v3.10 it is an empty line.

Quoted 1 line

Is that lone tab perhaps an editing mistake on your side?

I will check this, thanks!

Quoted 7 lines

Paul Bolle

.

Signature · 2 lines
Thanks!
Yijing
#19 lore raw
In reply to Yijing Wang
Quoted 13 lines · Yijing Wang

v1->v2: Modify pci_get_dsn to pci_device_serial_number,
power off slot before remove the old device during resume to avoid
old .remove() method to touch new hardware.
Fix other typo and fail check problems.
Split the list_empty() guard into new patch.

Yijing Wang (3):
PCI: introduce PCIe Device Serial Number Capability support PCI,pciehp: avoid add a device already exist before suspend during
resume
PCI,pciehp: use PCIe DSN to identify device change during suspend

Quoted 5 lines
 drivers/pci/hotplug/pciehp_core.c |   54 ++++++++++++++++++++++++++++++++++--
 drivers/pci/pci.c                 |   27 ++++++++++++++++++
 drivers/pci/probe.c               |    2 +
 include/linux/pci.h               |    3 ++
 4 files changed, 83 insertions(+), 3 deletions(-)

Series applies cleanly to v3.10 (but there was a small problem with 3/3, which I'll mention in a reply to that patch). Compiles without warning. Those two errors on every resume are now gone!

Thanks.

Paul Bolle

#20 lore raw
Quoted 20 lines · Paul Bolle
Quoted 13 lines · Yijing Wang

v1->v2: Modify pci_get_dsn to pci_device_serial_number,
power off slot before remove the old device during resume to avoid
old .remove() method to touch new hardware.
Fix other typo and fail check problems.
Split the list_empty() guard into new patch.

Yijing Wang (3):
PCI: introduce PCIe Device Serial Number Capability support PCI,pciehp: avoid add a device already exist before suspend during
resume
PCI,pciehp: use PCIe DSN to identify device change during suspend

Quoted 5 lines
 drivers/pci/hotplug/pciehp_core.c |   54 ++++++++++++++++++++++++++++++++++--
 drivers/pci/pci.c                 |   27 ++++++++++++++++++
 drivers/pci/probe.c               |    2 +
 include/linux/pci.h               |    3 ++
 4 files changed, 83 insertions(+), 3 deletions(-)
Quoted 3 lines

Series applies cleanly to v3.10 (but there was a small problem with 3/3, which I'll mention in a reply to that patch). Compiles without warning. Those two errors on every resume are now gone!

I will check patch 3/3, Paul, Do you wireless card support Device Serial Number ? You can confirm it by lspci -vvv.

Quoted 9 lines

Thanks.

Paul Bolle

.

Signature · 2 lines
Thanks!
Yijing
#21 lore raw

Yijing,

Quoted 2 lines · Yijing Wang

Do you wireless card support Device Serial Number ? You can confirm it by lspci -vvv.

Yes, it does:
lspci -vvv -s 03:00 | grep Serial
Capabilities: [140 v1] Device Serial Number [...]

Paul Bolle

#22 lore raw
Quoted 10 lines · Paul Bolle

Yijing,

Quoted 2 lines · Yijing Wang

Do you wireless card support Device Serial Number ? You can confirm it by lspci -vvv.

Yes, it does:
lspci -vvv -s 03:00 | grep Serial
Capabilities: [140 v1] Device Serial Number [...]

OK, I got it, thanks!

Quoted 5 lines

Paul Bolle

Signature · 2 lines
Thanks!
Yijing