[lkml]   [2010]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectAdd a helper function in PCI IOV to get VF device

The motivation is make VF device visible to PF driver. PF driver
may need this to access VF's PCI configuration.
Another use case is in sysfs symbolic linking. Some of VF's sysfs
entries are created by PF driver. For example, /sys/class/net/ethx/vfx
in Intel 82576 NIC driver. Makeing a symbolic link from VF's pci device
to this path also must be done in PF's driver.

Currently, there is no hint about VF's bus/devfn in PF's pci_dev.
The offset and stride entries(which are used to calculate bus/devfn
of VF devices) in VF's PCI configuration is also invisible in PF's
driver. So IMO this helper function is needed.

Any reply is appreciated, THX.

(ps: gmail will do line wrap/tab replace, use attachment instead to patch)

Frank Pan

Computer Science and Technology
Tsinghua University

Signed-off-by: Frank Pan <>
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index ce6a366..f15aa2a 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -722,6 +722,18 @@ int pci_num_vf(struct pci_dev *dev)

+ * pci_get_vf_dev - return the PCI device of a specific VF
+ * @dev: the PCI device
+ */
+struct pci_dev *pci_get_vf_dev(struct pci_dev *dev, int id)
+ return pci_get_bus_and_slot(
+ virtfn_bus(dev, id),
+ virtfn_devfn(dev, id));
static int ats_alloc_one(struct pci_dev *dev, int ps)
int pos;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a327322..fb6010b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1374,6 +1374,7 @@ extern int pci_enable_sriov(struct pci_dev *dev,
int nr_virtfn);
extern void pci_disable_sriov(struct pci_dev *dev);
extern irqreturn_t pci_sriov_migration(struct pci_dev *dev);
extern int pci_num_vf(struct pci_dev *dev);
+extern struct pci_dev *pci_get_vf_dev(struct pci_dev *dev, int id);
static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
@@ -1390,6 +1391,10 @@ static inline int pci_num_vf(struct pci_dev *dev)
return 0;
+static inline struct pci_dev *pci_get_vf_dev(struct pci_dev *dev, int id)
+ return NULL;

#if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)[unhandled content-type:application/octet-stream]
 \ /
  Last update: 2010-06-01 07:09    [W:0.046 / U:1.756 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site