Message ID | 20091218013410.4510.40263.stgit@localhost.localdomain |
---|---|
State | RFC, archived |
Delegated to: | David Miller |
Headers | show |
On Thu, 2009-12-17 at 17:34 -0800, Jeff Kirsher wrote: > From: Williams, Mitch A <mitch.a.williams@intel.com> > > Add a convenience function to determine how many VF devices are associated > with a given PF network interface. If the device is not an SR-IOV physical > function device, the function returns 0. [...] > +/** > + * netif_num_vf - return number of SR-IOV VFs > + * @dev: network device > + * > + * Return the number of SR-IOV virtual function devices that are > + * associated with this physical function device. Returns 0 if > + * device is not a PF device, or if SR-IOV not enabled. > + */ > +static inline int netif_num_vf(const struct net_device *dev) > +{ > + struct pci_dev *pdev; > + int retval = 0; > + > + if (!dev) > + goto out; Why should this function allow dev == NULL? > + if (!dev->dev.parent) > + goto out; > + > + if (dev->dev.parent->bus == &pci_bus_type) { > + pdev = to_pci_dev(dev->dev.parent); > + retval = pci_num_vf(pdev); > + } > +out: > + return retval; [...] It would be much clearer to write: struct pci_dev *pdev; if (dev && dev->dev.parent && dev->dev.parent->bus == &pci_bus_type) { pdev = to_pci_dev(dev->dev.parent); return pci_num_vf(pdev); } else { return 0; } Ben.
Well, first of all this won't build without CONFIG_PCI defined. Second of all, we're not putting PCI crap into netdevice.h Create a generic device layer abstraction by which you can fetch these values. Thanks. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>Subject: Re: [RFC PATCH v2 2/6] net: Add netif_num_vf function > > >Well, first of all this won't build without CONFIG_PCI >defined. > >Second of all, we're not putting PCI crap into netdevice.h > >Create a generic device layer abstraction by which you can >fetch these values. > >Thanks. OK, I'll respin this and resubmit after the new year. -Mitch -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index a3fccc8..f6e521e 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -38,6 +38,7 @@ #include <asm/byteorder.h> #include <linux/device.h> +#include <linux/pci.h> #include <linux/percpu.h> #include <linux/rculist.h> #include <linux/dmaengine.h> @@ -1509,6 +1510,32 @@ static inline int netif_is_multiqueue(const struct net_device *dev) { return (dev->num_tx_queues > 1); } +/** + * netif_num_vf - return number of SR-IOV VFs + * @dev: network device + * + * Return the number of SR-IOV virtual function devices that are + * associated with this physical function device. Returns 0 if + * device is not a PF device, or if SR-IOV not enabled. + */ +static inline int netif_num_vf(const struct net_device *dev) +{ + struct pci_dev *pdev; + int retval = 0; + + if (!dev) + goto out; + + if (!dev->dev.parent) + goto out; + + if (dev->dev.parent->bus == &pci_bus_type) { + pdev = to_pci_dev(dev->dev.parent); + retval = pci_num_vf(pdev); + } +out: + return retval; +} /* Use this variant when it is known for sure that it * is executing from hardware interrupt context or with hardware interrupts