Skip to content

Commit 0760462

Browse files
committed
Merge branch 'bus-agnostic-num-vf'
Phil Sutter says: ==================== 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. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 6c59ebd + 9af15c3 commit 0760462

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

drivers/pci/pci-driver.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,11 @@ static int pci_uevent(struct device *dev, struct kobj_uevent_env *env)
14321432
return 0;
14331433
}
14341434

1435+
static int pci_bus_num_vf(struct device *dev)
1436+
{
1437+
return pci_num_vf(to_pci_dev(dev));
1438+
}
1439+
14351440
struct bus_type pci_bus_type = {
14361441
.name = "pci",
14371442
.match = pci_bus_match,
@@ -1443,6 +1448,7 @@ struct bus_type pci_bus_type = {
14431448
.bus_groups = pci_bus_groups,
14441449
.drv_groups = pci_drv_groups,
14451450
.pm = PCI_PM_OPS_PTR,
1451+
.num_vf = pci_bus_num_vf,
14461452
};
14471453
EXPORT_SYMBOL(pci_bus_type);
14481454

include/linux/device.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
8888
*
8989
* @suspend: Called when a device on this bus wants to go to sleep mode.
9090
* @resume: Called to bring a device on this bus out of sleep mode.
91+
* @num_vf: Called to find out how many virtual functions a device on this
92+
* bus supports.
9193
* @pm: Power management operations of this bus, callback the specific
9294
* device driver's pm-ops.
9395
* @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU
@@ -127,6 +129,8 @@ struct bus_type {
127129
int (*suspend)(struct device *dev, pm_message_t state);
128130
int (*resume)(struct device *dev);
129131

132+
int (*num_vf)(struct device *dev);
133+
130134
const struct dev_pm_ops *pm;
131135

132136
const struct iommu_ops *iommu_ops;
@@ -1140,6 +1144,13 @@ extern int device_online(struct device *dev);
11401144
extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
11411145
extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
11421146

1147+
static inline int dev_num_vf(struct device *dev)
1148+
{
1149+
if (dev->bus && dev->bus->num_vf)
1150+
return dev->bus->num_vf(dev);
1151+
return 0;
1152+
}
1153+
11431154
/*
11441155
* Root device objects for grouping under /sys/devices
11451156
*/

include/linux/pci.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type);
885885
void pci_sort_breadthfirst(void);
886886
#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
887887
#define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
888-
#define dev_num_vf(d) ((dev_is_pci(d) ? pci_num_vf(to_pci_dev(d)) : 0))
889888

890889
/* Generic PCI functions exported to card drivers */
891890

@@ -1630,7 +1629,6 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
16301629

16311630
#define dev_is_pci(d) (false)
16321631
#define dev_is_pf(d) (false)
1633-
#define dev_num_vf(d) (0)
16341632
#endif /* CONFIG_PCI */
16351633

16361634
/* Include architecture-dependent settings and functions */

net/core/rtnetlink.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,7 @@ static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
837837
static inline int rtnl_vfinfo_size(const struct net_device *dev,
838838
u32 ext_filter_mask)
839839
{
840-
if (dev->dev.parent && dev_is_pci(dev->dev.parent) &&
841-
(ext_filter_mask & RTEXT_FILTER_VF)) {
840+
if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF)) {
842841
int num_vfs = dev_num_vf(dev->dev.parent);
843842
size_t size = nla_total_size(0);
844843
size += num_vfs *

0 commit comments

Comments
 (0)