All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Ben Hutchings <bhutchings@solarflare.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Greg Rose <gregory.v.rose@intel.com>,
	Yuval Mintz <yuvalmin@broadcom.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Ariel Elior <ariele@broadcom.com>,
	Eilon Greenstein <eilong@broadcom.com>,
	linux-pci <linux-pci@vger.kernel.org>
Subject: Re: New commands to configure IOV features
Date: Wed, 19 Sep 2012 17:19:47 -0700	[thread overview]
Message-ID: <CAE9FiQVk-uXgLK6dM8q5-Xsh8LO+c-Dd_cEpu2WzJ6Uzt6ztnA@mail.gmail.com> (raw)
In-Reply-To: <1348094773.2636.85.camel@bwh-desktop.uk.solarflarecom.com>

[-- Attachment #1: Type: text/plain, Size: 911 bytes --]

On Wed, Sep 19, 2012 at 3:46 PM, Ben Hutchings
<bhutchings@solarflare.com> wrote:
> On Wed, 2012-09-19 at 15:17 -0700, Yinghai Lu wrote:
>> +max_vfs_store(struct device *dev, struct device_attribute *attr,
>> +                const char *buf, size_t count)
>> +{
>> +       unsigned long val;
>> +       struct pci_dev *pdev = to_pci_dev(dev);
>> +
>> +       if (strict_strtoul(buf, 0, &val) < 0)
>> +               return -EINVAL;
>> +
>> +       pdev->max_vfs = val;
>> +
>> +       return count;
>> +}
> [...]
>
> Then what would actually trigger creation of the VFs?  There's no way we
> can assume that some sysfs attribute will be written before the PF
> driver is loaded (what if it's built-in?).  I thought the idea was to
> add a driver callback that would be called when the sysfs attribute was
> written.

could just stop the device and add it back again?

just like updated patch.

Thanks

Yinghai

[-- Attachment #2: sriov_xxx.patch --]
[-- Type: application/octet-stream, Size: 3664 bytes --]

Subject: [PATCH] PCI: Add max_vfs in sysfs per pci device where supports

driver later need to check dev->max_vfs in /sys

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 drivers/pci/pci-sysfs.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/remove.c    |    2 -
 include/linux/pci.h     |    2 +
 3 files changed, 60 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/pci/pci-sysfs.c
===================================================================
--- linux-2.6.orig/drivers/pci/pci-sysfs.c
+++ linux-2.6/drivers/pci/pci-sysfs.c
@@ -459,6 +459,58 @@ boot_vga_show(struct device *dev, struct
 }
 struct device_attribute vga_attr = __ATTR_RO(boot_vga);
 
+static ssize_t
+max_vfs_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	return sprintf(buf, "%u\n", pdev->max_vfs);
+}
+
+static void rebind_callback(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	int err;
+
+	mutex_lock(&pci_remove_rescan_mutex);
+	pci_stop_bus_device(pdev);
+	err = pci_bus_add_device(pdev);
+	if (!err) {
+		struct pci_bus *child = pdev->subordinate;
+
+		if (child) {
+			pci_bus_add_devices(child);
+			if (!child->is_added)
+				pci_bus_add_child(child);
+		}
+	}
+	mutex_unlock(&pci_remove_rescan_mutex);
+}
+static ssize_t
+max_vfs_store(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
+{
+	unsigned long val;
+	struct pci_dev *pdev = to_pci_dev(dev);
+
+	if (strict_strtoul(buf, 0, &val) < 0)
+		return -EINVAL;
+
+	pdev->max_vfs = val;
+
+	if (pdev->is_added) {
+		int err;
+		err = device_schedule_callback(dev, rebind_callback);
+
+		if (err)
+			return err;
+	}
+
+	return count;
+}
+struct device_attribute max_vfs_attr =
+	__ATTR(max_vfs, 0644, max_vfs_show, max_vfs_store);
+
 static void
 pci_config_pm_runtime_get(struct pci_dev *pdev)
 {
@@ -1406,6 +1458,7 @@ late_initcall(pci_sysfs_init);
 
 static struct attribute *pci_dev_dev_attrs[] = {
 	&vga_attr.attr,
+	&max_vfs_attr.attr,
 	NULL,
 };
 
@@ -1419,6 +1472,10 @@ static umode_t pci_dev_attrs_are_visible
 		if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
 			return 0;
 
+	if (a == &max_vfs_attr.attr)
+		if (!pdev->is_physfn)
+			return 0;
+
 	return a->mode;
 }
 
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -359,6 +359,7 @@ struct pci_dev {
 	unsigned int	broken_intx_masking:1;
 	unsigned int	io_window_1k:1;	/* Intel P2P bridge 1K I/O windows */
 	pci_dev_flags_t dev_flags;
+	unsigned int	max_vfs;
 	atomic_t	enable_cnt;	/* pci_enable_device has been called */
 
 	u32		saved_config_space[16]; /* config space saved at suspend time */
@@ -812,6 +813,7 @@ u8 pci_common_swizzle(struct pci_dev *de
 extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
 extern void pci_dev_put(struct pci_dev *dev);
 extern void pci_remove_bus(struct pci_bus *b);
+void pci_stop_bus_device(struct pci_dev *dev);
 extern void pci_stop_and_remove_bus_device(struct pci_dev *dev);
 void pci_stop_root_bus(struct pci_bus *bus);
 void pci_remove_root_bus(struct pci_bus *bus);
Index: linux-2.6/drivers/pci/remove.c
===================================================================
--- linux-2.6.orig/drivers/pci/remove.c
+++ linux-2.6/drivers/pci/remove.c
@@ -55,7 +55,7 @@ void pci_remove_bus(struct pci_bus *bus)
 }
 EXPORT_SYMBOL(pci_remove_bus);
 
-static void pci_stop_bus_device(struct pci_dev *dev)
+void pci_stop_bus_device(struct pci_dev *dev)
 {
 	struct pci_bus *bus = dev->subordinate;
 	struct pci_dev *child, *tmp;

  reply	other threads:[~2012-09-20  0:19 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 11:17 New commands to configure IOV features Yuval Mintz
2012-05-07 15:16 ` Greg Rose
2012-06-26 12:21   ` Yuval Mintz
2012-06-26 16:13     ` Alexander Duyck
2012-06-26 17:19     ` Greg Rose
2012-07-01 11:09       ` Yuval Mintz
2012-07-09 18:39       ` Ben Hutchings
2012-07-09 21:13         ` Chris Friesen
2012-07-16  9:19           ` Yuval Mintz
2012-07-17 19:29             ` Don Dutile
2012-07-17 21:08               ` Chris Friesen
2012-07-17 21:11                 ` David Miller
2012-07-20 15:27                   ` Chris Friesen
2012-07-20 15:56                     ` Don Dutile
2012-07-20 17:42                       ` Ben Hutchings
2012-07-20 19:29                         ` Chris Friesen
2012-07-20 20:01                           ` Ben Hutchings
2012-07-20 20:15                             ` Don Dutile
2012-07-20 23:42                             ` Chris Friesen
2012-07-21  0:52                               ` Rose, Gregory V
2012-07-23 14:03                               ` Don Dutile
2012-07-23 15:09                                 ` Chris Friesen
2012-07-23 17:06                                   ` Rose, Gregory V
2012-07-23 18:36                                   ` Stephen Hemminger
2012-07-23 18:40                                     ` Rose, Gregory V
2012-09-19 11:07                                       ` Yuval Mintz
2012-09-19 15:53                                         ` Greg Rose
2012-09-19 19:44                                           ` Ben Hutchings
2012-09-19 22:17                                             ` Yinghai Lu
2012-09-19 22:46                                               ` Ben Hutchings
2012-09-20  0:19                                                 ` Yinghai Lu [this message]
2012-09-20  1:23                                                   ` Ben Hutchings
2012-09-20  2:27                                                     ` Yinghai Lu
2012-09-20  3:08                                                       ` Subhendu Ghosh
2012-09-20 15:39                                                     ` Rose, Gregory V
2012-09-20 15:39                                                       ` Rose, Gregory V
2012-09-21  5:50                                                       ` Yinghai Lu
2012-09-21 17:35                                                         ` Ben Hutchings
2012-09-21 19:23                                                           ` Yinghai Lu
2012-09-21 18:06                                                         ` Don Dutile
2012-09-21 18:06                                                           ` Don Dutile
2012-09-21 19:49                                                           ` Yinghai Lu
2012-09-21 20:08                                                             ` Don Dutile
2012-09-21 20:08                                                               ` Don Dutile
2012-09-23 15:49                                                               ` Yuval Mintz
2012-09-24 17:37                                                                 ` Don Dutile
2012-09-24 17:37                                                                   ` Don Dutile
2012-09-30  6:39                                                               ` Yuval Mintz
2012-10-01 14:12                                                                 ` Don Dutile
2012-10-01 14:12                                                                   ` Don Dutile
2012-09-19 17:49                                         ` David Miller
2012-07-23 16:37                                 ` Rose, Gregory V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAE9FiQVk-uXgLK6dM8q5-Xsh8LO+c-Dd_cEpu2WzJ6Uzt6ztnA@mail.gmail.com \
    --to=yinghai@kernel.org \
    --cc=ariele@broadcom.com \
    --cc=bhelgaas@google.com \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=eilong@broadcom.com \
    --cc=gregory.v.rose@intel.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yuvalmin@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.