Retrieve number of VFs in a bus-agnostic way
Subsystems (4)
cover Retrieve number of VFs in a bus-agnostic way
Previously, it was assumed that only PCI NICs would be capable of having virtual functions - with my proposed enhancement of dummy NIC driver implementing (fake) ones for testing purposes, this is no longer true.
Discussion of said patch has led to the suggestion of implementing a bus-agnostic method for VF count retrieval so rtnetlink could work with both real VF-capable PCI NICs as well as my dummy modifications without introducing ugly hacks.
The following series tries to achieve just that by introducing a bus type callback to retrieve a device's number of VFs, implementing this callback for PCI bus and finally adjusting rtnetlink to make use of the generalized infrastructure.
Phil Sutter (3):
device: bus_type: Introduce num_vf callback
PCI: implement num_vf bus type callback
device: Implement a bus agnostic dev_num_vf routine
drivers/pci/pci-driver.c | 6 ++++++ include/linux/device.h | 11 +++++++++++ include/linux/pci.h | 2 -- net/core/rtnetlink.c | 3 +-- 4 files changed, 18 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/3 device: bus_type: Introduce num_vf callback
This allows for bus types to implement their own method of retrieving the number of virtual functions a NIC on that type of bus supports.
--- include/linux/device.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/device.h +4 -0
@@ -88,6 +88,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);* * @suspend: Called when a device on this bus wants to go to sleep mode. * @resume: Called to bring a device on this bus out of sleep mode. +* @num_vf: Called to find out how many virtual functions a device on this +* bus supports. * @pm: Power management operations of this bus, callback the specific * device driver's pm-ops. * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU
@@ -127,6 +129,8 @@ struct bus_type {int (*suspend)(struct device *dev,pm_message_t state);int (*resume)(struct device *dev); +int (*num_vf)(struct device *dev); +const struct dev_pm_ops *pm;const struct iommu_ops *iommu_ops;
Signature · 1 line
2.11.0
PATCH 2/3 PCI: implement num_vf bus type callback
In reply to Phil Sutter--- drivers/pci/pci-driver.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/pci/pci-driver.c +6 -0
@@ -1432,6 +1432,11 @@ static int pci_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static int pci_bus_num_vf (struct device *dev) +{ +return pci_num_vf (to_pci_dev (dev)); +} +struct bus_type pci_bus_type = { .name ="pci" , .match = pci_bus_match,
@@ -1443,6 +1448,7 @@ struct bus_type pci_bus_type = { .bus_groups = pci_bus_groups, .drv_groups = pci_drv_groups, .pm = PCI_PM_OPS_PTR, + .num_vf = pci_bus_num_vf, };EXPORT_SYMBOL (pci_bus_type);
Signature · 1 line
2.11.0
PATCH 3/3 device: Implement a bus agnostic dev_num_vf routine
In reply to Phil SutterNow that pci_bus_type has num_vf callback set, dev_num_vf can be implemented in a bus type independent way and the check for whether a PCI device is being handled in rtnetlink can be dropped.
--- include/linux/device.h | 7 +++++++ include/linux/pci.h | 2 -- net/core/rtnetlink.c | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-)
include/linux/device.h +7 -0
@@ -1144,6 +1144,13 @@ extern int device_online(struct device *dev);extern void set_primary_fwnode (struct device *dev,struct fwnode_handle *fwnode);extern void set_secondary_fwnode (struct device *dev,struct fwnode_handle *fwnode); +static inline int dev_num_vf (struct device *dev) +{ +if (dev->bus && dev->bus->num_vf) +return dev->bus->num_vf (dev); +return 0 ; +} +/* * Root device objects for grouping under /sys/devices */
include/linux/pci.h +0 -2
@@ -885,7 +885,6 @@ void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type);void pci_sort_breadthfirst (void );#define dev_is_pci (d) ((d)->bus == &pci_bus_type)#define dev_is_pf (d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false)) -#define dev_num_vf (d) ((dev_is_pci(d) ? pci_num_vf(to_pci_dev(d)) : 0))/* Generic PCI functions exported to card drivers */
@@ -1630,7 +1629,6 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }#define dev_is_pci (d) (false)#define dev_is_pf (d) (false) -#define dev_num_vf (d) (0)#endif /* CONFIG_PCI */ /* Include architecture-dependent settings and functions */
net/core/rtnetlink.c +1 -2
@@ -837,8 +837,7 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a,static inline int rtnl_vfinfo_size (const struct net_device *dev,u32 ext_filter_mask) { -if (dev->dev.parent &&dev_is_pci (dev->dev.parent) && - (ext_filter_mask &RTEXT_FILTER_VF )) { +if (dev->dev.parent && (ext_filter_mask &RTEXT_FILTER_VF )) {int num_vfs =dev_num_vf (dev->dev.parent);size_t size =nla_total_size (0 ); size += num_vfs *
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Phil Sutter <[email protected]>
Date: Wed, 18 Jan 2017 14:04:36 +0100
Quoted 9 lines
Previously, it was assumed that only PCI NICs would be capable of having virtual functions - with my proposed enhancement of dummy NIC driver implementing (fake) ones for testing purposes, this is no longer true.
Discussion of said patch has led to the suggestion of implementing a bus-agnostic method for VF count retrieval so rtnetlink could work with both real VF-capable PCI NICs as well as my dummy modifications without introducing ugly hacks.
Quoted 4 lines
The following series tries to achieve just that by introducing a bus type callback to retrieve a device's number of VFs, implementing this callback for PCI bus and finally adjusting rtnetlink to make use of the generalized infrastructure.
This is really nice and clean, compare it to your original approach :-)
Series applied, thanks!
Quoted 12 lines · David Miller
From: Phil Sutter <[email protected]>
Date: Wed, 18 Jan 2017 14:04:36 +0100Quoted 9 lines
Previously, it was assumed that only PCI NICs would be capable of having virtual functions - with my proposed enhancement of dummy NIC driver implementing (fake) ones for testing purposes, this is no longer true.
Discussion of said patch has led to the suggestion of implementing a bus-agnostic method for VF count retrieval so rtnetlink could work with both real VF-capable PCI NICs as well as my dummy modifications without introducing ugly hacks.
Quoted 6 lines
Quoted 4 lines
The following series tries to achieve just that by introducing a bus type callback to retrieve a device's number of VFs, implementing this callback for PCI bus and finally adjusting rtnetlink to make use of the generalized infrastructure.
This is really nice and clean, compare it to your original approach :-)
Yes, indeed! Thanks a lot for pointing me into the right direction. :)
Cheers, Phil