From: Frank Pan on
Greetings,

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 <frankpzh(a)gmail.com>
---
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)
}
EXPORT_SYMBOL_GPL(pci_num_vf);

+/**
+ * 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));
+}
+EXPORT_SYMBOL_GPL(pci_get_vf_dev);
+
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);
#else
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;
+}
#endif

#if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
From: Greg KH on
On Tue, Jun 01, 2010 at 01:05:25PM +0800, Frank Pan wrote:
> Greetings,
>
> The motivation is make VF device visible to PF driver. PF driver
> may need this to access VF's PCI configuration.

What is "VF" and "PF" here?

> 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.

No, the network core should create that symlink, not the driver, right?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Williams, Mitch A on
>-----Original Message-----
>From: Greg KH [mailto:greg(a)kroah.com]
>Sent: Tuesday, June 01, 2010 11:39 AM


>
>On Tue, Jun 01, 2010 at 01:05:25PM +0800, Frank Pan wrote:
>> Greetings,
>>
>> The motivation is make VF device visible to PF driver. PF driver
>> may need this to access VF's PCI configuration.
>
>What is "VF" and "PF" here?
>
>> 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.
>
>No, the network core should create that symlink, not the driver, right?
>
>thanks,
>
>greg k-h

Furthermore, the links are already there in sysfs, created by the PCI subsystem.

/sys/class/net/ethX/device links to the PCI device entry for the PF device, which itself has symlinks to each of the VF devices.

This patch just isn't necessary.

-Mitch
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Frank Pan on
> What is "VF" and "PF" here?
Virtual function/Physical function

> No, the network core should create that symlink, not the driver, right?
They are not network interfaces, so network core
won't link them. They are for VM uses. I may need
to explain this more clearly.

PF's interface in sysfs is /sys/class/net/ethx, while
VF has no interface. So 82576 driver makes directories
to provide interface-like sysfs entries: /sys/class/net/ethx/vf[1-7]
Make a link to this directory form VF's pci device is
almost impossible, because PF doesn't know VF's bdf.

Thanks for reply.

--
Frank Pan

Computer Science and Technology
Tsinghua University
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Frank Pan on
> Furthermore, the links are already there in sysfs, created by the PCI subsystem.
>
> /sys/class/net/ethX/device links to the PCI device entry for the PF device, which itself has symlinks to each of the VF devices.
>
> This patch just isn't necessary.

I'm not talking about PF's pci device, because PF
driver knows it. I'm talking about VF's.
The root cause is PF cannot get VF's bdf, so it has
no idea where VF is. IMO it's abnormal.

Make symlinks is just a use case. When a userspace
app only knows VF's bdf, it has no idea how to get
into the VF's interface-like directories.
(/sys/class/net/ethX/vf[1-7])
Because of:
1. Userspace app cannot get PF's bdf from VF's bdf
2. Userspace app cannot guess the interface name of
pf(ethX)
So a symlink from /sys/bus/pci/devices/xxxxx to
/sys/class/net/ethX/vf[1-7] is useful.
This is a real issue.

Thanks for reply.

--
Frank Pan

Computer Science and Technology
Tsinghua University
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/