Commit b1bd58e4 authored by Yijing Wang's avatar Yijing Wang Committed by Bjorn Helgaas

PCI: Consolidate "next-function" functions

There are several next_fn functions (no_next_fn, next_trad_fn,
next_ari_fn); consolidate them in next_fn() to simplify the code.

[bhelgaas: make next_fn() static, rework control flow]
Signed-off-by: default avatarYijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarJiang Liu <jiang.liu@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 31ab2476
...@@ -1349,31 +1349,31 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) ...@@ -1349,31 +1349,31 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
} }
EXPORT_SYMBOL(pci_scan_single_device); EXPORT_SYMBOL(pci_scan_single_device);
static unsigned next_ari_fn(struct pci_dev *dev, unsigned fn) static unsigned next_fn(struct pci_bus *bus, struct pci_dev *dev, unsigned fn)
{ {
u16 cap; int pos;
unsigned pos, next_fn; u16 cap = 0;
unsigned next_fn;
if (!dev) if (pci_ari_enabled(bus)) {
return 0; if (!dev)
return 0;
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
if (!pos)
return 0;
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap);
if (!pos) next_fn = PCI_ARI_CAP_NFN(cap);
return 0; if (next_fn <= fn)
pci_read_config_word(dev, pos + 4, &cap); return 0; /* protect against malformed list */
next_fn = cap >> 8;
if (next_fn <= fn)
return 0;
return next_fn;
}
static unsigned next_trad_fn(struct pci_dev *dev, unsigned fn) return next_fn;
{ }
return (fn + 1) % 8;
} /* dev may be NULL for non-contiguous multifunction devices */
if (!dev || dev->multifunction)
return (fn + 1) % 8;
static unsigned no_next_fn(struct pci_dev *dev, unsigned fn)
{
return 0; return 0;
} }
...@@ -1406,7 +1406,6 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) ...@@ -1406,7 +1406,6 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
{ {
unsigned fn, nr = 0; unsigned fn, nr = 0;
struct pci_dev *dev; struct pci_dev *dev;
unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn;
if (only_one_child(bus) && (devfn > 0)) if (only_one_child(bus) && (devfn > 0))
return 0; /* Already scanned the entire slot */ return 0; /* Already scanned the entire slot */
...@@ -1417,12 +1416,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) ...@@ -1417,12 +1416,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
if (!dev->is_added) if (!dev->is_added)
nr++; nr++;
if (pci_ari_enabled(bus)) for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) {
next_fn = next_ari_fn;
else if (dev->multifunction)
next_fn = next_trad_fn;
for (fn = next_fn(dev, 0); fn > 0; fn = next_fn(dev, fn)) {
dev = pci_scan_single_device(bus, devfn + fn); dev = pci_scan_single_device(bus, devfn + fn);
if (dev) { if (dev) {
if (!dev->is_added) if (!dev->is_added)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment