[PATCH part1 v6 6/7] PCI: Check pci device serial number when scan device

From: Yijing Wang
Date: Tue Feb 11 2014 - 21:53:32 EST


Sometimes pci device will be removed and reinsert
while suspended. In this case system can not identify
the device has been changed. Now PCIe support Device
Serial Number Capability which has the unique number.
So make system check pci device DSN during scanning
device if support.

Signed-off-by: Yijing Wang <wangyijing@xxxxxxxxxx>
---
drivers/pci/probe.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 27d3e6f..370b25c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1383,11 +1383,22 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
{
struct pci_dev *dev;
+ int rescan = 0;

dev = pci_get_slot(bus, devfn);
if (dev) {
+ /* only check func 0 device */
+ if (PCI_FUNC(devfn) == 0) {
+ if (pci_serial_number_changed(dev)) {
+ pci_bus_freeze_device(bus);
+ pci_stop_and_remove_bus_device(dev);
+ pci_bus_unfreeze_device(bus);
+ rescan = 1;
+ }
+ }
pci_dev_put(dev);
- return dev;
+ if (!rescan)
+ return dev;
}

dev = pci_scan_device(bus, devfn);
--
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/