diff mbox

[RFC,v2,2/6] net: Add netif_num_vf function

Message ID 20091218013410.4510.40263.stgit@localhost.localdomain
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Kirsher, Jeffrey T Dec. 18, 2009, 1:34 a.m. UTC
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.

Signed-off-by: Mitch Williams <mitch.a.williams@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---

 include/linux/netdevice.h |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)


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

Comments

Ben Hutchings Dec. 18, 2009, 5:37 p.m. UTC | #1
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.
David Miller Dec. 19, 2009, 4:05 a.m. UTC | #2
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
Mitch Williams Dec. 21, 2009, 6:34 p.m. UTC | #3
>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 mbox

Patch

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