aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/probe.c
diff options
context:
space:
mode:
authorYijing Wang <wangyijing@huawei.com>2013-01-25 11:12:31 -0500
committerBjorn Helgaas <bhelgaas@google.com>2013-01-25 11:21:10 -0500
commitb1bd58e448f28531207124eea3fd43b81d6f8d06 (patch)
tree68406f79ead2f5bb488485ca190bf5a535712269 /drivers/pci/probe.c
parent31ab247623c541d56b39a0b792cdfe4e94dd2a45 (diff)
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: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r--drivers/pci/probe.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 7b9e691b95b1..2a9958c1556e 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1349,31 +1349,31 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
1349} 1349}
1350EXPORT_SYMBOL(pci_scan_single_device); 1350EXPORT_SYMBOL(pci_scan_single_device);
1351 1351
1352static unsigned next_ari_fn(struct pci_dev *dev, unsigned fn) 1352static unsigned next_fn(struct pci_bus *bus, struct pci_dev *dev, unsigned fn)
1353{ 1353{
1354 u16 cap; 1354 int pos;
1355 unsigned pos, next_fn; 1355 u16 cap = 0;
1356 unsigned next_fn;
1356 1357
1357 if (!dev) 1358 if (pci_ari_enabled(bus)) {
1358 return 0; 1359 if (!dev)
1360 return 0;
1361 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
1362 if (!pos)
1363 return 0;
1359 1364
1360 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 1365 pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap);
1361 if (!pos) 1366 next_fn = PCI_ARI_CAP_NFN(cap);
1362 return 0; 1367 if (next_fn <= fn)
1363 pci_read_config_word(dev, pos + 4, &cap); 1368 return 0; /* protect against malformed list */
1364 next_fn = cap >> 8;
1365 if (next_fn <= fn)
1366 return 0;
1367 return next_fn;
1368}
1369 1369
1370static unsigned next_trad_fn(struct pci_dev *dev, unsigned fn) 1370 return next_fn;
1371{ 1371 }
1372 return (fn + 1) % 8; 1372
1373} 1373 /* dev may be NULL for non-contiguous multifunction devices */
1374 if (!dev || dev->multifunction)
1375 return (fn + 1) % 8;
1374 1376
1375static unsigned no_next_fn(struct pci_dev *dev, unsigned fn)
1376{
1377 return 0; 1377 return 0;
1378} 1378}
1379 1379
@@ -1406,7 +1406,6 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
1406{ 1406{
1407 unsigned fn, nr = 0; 1407 unsigned fn, nr = 0;
1408 struct pci_dev *dev; 1408 struct pci_dev *dev;
1409 unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn;
1410 1409
1411 if (only_one_child(bus) && (devfn > 0)) 1410 if (only_one_child(bus) && (devfn > 0))
1412 return 0; /* Already scanned the entire slot */ 1411 return 0; /* Already scanned the entire slot */
@@ -1417,12 +1416,7 @@ int pci_scan_slot(struct pci_bus *bus, int devfn)
1417 if (!dev->is_added) 1416 if (!dev->is_added)
1418 nr++; 1417 nr++;
1419 1418
1420 if (pci_ari_enabled(bus)) 1419 for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) {
1421 next_fn = next_ari_fn;
1422 else if (dev->multifunction)
1423 next_fn = next_trad_fn;
1424
1425 for (fn = next_fn(dev, 0); fn > 0; fn = next_fn(dev, fn)) {
1426 dev = pci_scan_single_device(bus, devfn + fn); 1420 dev = pci_scan_single_device(bus, devfn + fn);
1427 if (dev) { 1421 if (dev) {
1428 if (!dev->is_added) 1422 if (!dev->is_added)