From 4e15c46bdc4d5ea0e7991a05edbd807328d38a2c Mon Sep 17 00:00:00 2001 From: Yinghai Lu Date: Mon, 5 Nov 2012 15:20:34 -0500 Subject: PCI: Add pci_device_type to pdev's device struct Need type filled in device structure so it can be used for visible attribute control in sysfs for pci_dev. Signed-off-by: Yinghai Lu Signed-off-by: Bjorn Helgaas --- drivers/pci/pci.h | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/pci/pci.h') diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index bacbcba69cf3..6f6cd145bb7e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -157,6 +157,7 @@ static inline int pci_no_d1d2(struct pci_dev *dev) } extern struct device_attribute pci_dev_attrs[]; extern struct device_attribute pcibus_dev_attrs[]; +extern struct device_type pci_dev_type; #ifdef CONFIG_HOTPLUG extern struct bus_attribute pci_bus_attrs[]; #else -- cgit v1.2.3-55-g7522 From bff73156d3ad661655e6d9ef04c2284cf3abb0f1 Mon Sep 17 00:00:00 2001 From: Donald Dutile Date: Mon, 5 Nov 2012 15:20:37 -0500 Subject: PCI: Provide method to reduce the number of total VFs supported Some implementations of SRIOV provide a capability structure value of TotalVFs that is greater than what the software can support. Provide a method to reduce the capability structure reported value to the value the driver can support. This ensures sysfs reports the current capability of the system, hardware and software. Example for its use: igb & ixgbe -- report 8 & 64 as TotalVFs, but drivers only support 7 & 63 maximum. Signed-off-by: Donald Dutile Signed-off-by: Bjorn Helgaas --- drivers/pci/iov.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 4 ++-- drivers/pci/pci.h | 1 + include/linux/pci.h | 10 ++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) (limited to 'drivers/pci/pci.h') diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index aeccc911abb8..f6781e42d00d 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -735,3 +735,50 @@ int pci_num_vf(struct pci_dev *dev) return dev->sriov->nr_virtfn; } EXPORT_SYMBOL_GPL(pci_num_vf); + +/** + * pci_sriov_set_totalvfs -- reduce the TotalVFs available + * @dev: the PCI PF device + * numvfs: number that should be used for TotalVFs supported + * + * Should be called from PF driver's probe routine with + * device's mutex held. + * + * Returns 0 if PF is an SRIOV-capable device and + * value of numvfs valid. If not a PF with VFS, return -EINVAL; + * if VFs already enabled, return -EBUSY. + */ +int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs) +{ + if (!dev || !dev->is_physfn || (numvfs > dev->sriov->total)) + return -EINVAL; + + /* Shouldn't change if VFs already enabled */ + if (dev->sriov->ctrl & PCI_SRIOV_CTRL_VFE) + return -EBUSY; + else + dev->sriov->drvttl = numvfs; + + return 0; +} +EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs); + +/** + * pci_sriov_get_totalvfs -- get total VFs supported on this devic3 + * @dev: the PCI PF device + * + * For a PCIe device with SRIOV support, return the PCIe + * SRIOV capability value of TotalVFs or the value of drvttl + * if the driver reduced it. Otherwise, -EINVAL. + */ +int pci_sriov_get_totalvfs(struct pci_dev *dev) +{ + if (!dev || !dev->is_physfn) + return -EINVAL; + + if (dev->sriov->drvttl) + return dev->sriov->drvttl; + else + return dev->sriov->total; +} +EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs); diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 74508c63bd47..99b5f83d2468 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -411,7 +411,7 @@ static ssize_t sriov_totalvfs_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->total); + return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); } @@ -452,7 +452,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, } /* if enabling vf's ... */ - total = pdev->sriov->total; + total = pci_sriov_get_totalvfs(pdev); /* Requested VFs to enable < totalvfs and none enabled already */ if ((num_vfs > 0) && (num_vfs <= total)) { if (pdev->sriov->nr_virtfn == 0) { diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 6f6cd145bb7e..553bbba76eec 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -240,6 +240,7 @@ struct pci_sriov { u16 stride; /* following VF stride */ u32 pgsz; /* page size for BAR alignment */ u8 link; /* Function Dependency Link */ + u16 drvttl; /* max num VFs driver supports */ struct pci_dev *dev; /* lowest numbered PF */ struct pci_dev *self; /* this PF */ struct mutex lock; /* lock for VF bus */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 7ef8fba319da..1ad824966e64 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1611,6 +1611,8 @@ extern int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn); extern void pci_disable_sriov(struct pci_dev *dev); extern irqreturn_t pci_sriov_migration(struct pci_dev *dev); extern int pci_num_vf(struct pci_dev *dev); +extern int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); +extern int pci_sriov_get_totalvfs(struct pci_dev *dev); #else static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) { @@ -1627,6 +1629,14 @@ static inline int pci_num_vf(struct pci_dev *dev) { return 0; } +static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs) +{ + return 0; +} +static inline int pci_sriov_get_totalvfs(struct pci_dev *dev) +{ + return 0; +} #endif #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE) -- cgit v1.2.3-55-g7522 From 6b136724691a6f247ada0c6a5f02370ed46de9f4 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Fri, 9 Nov 2012 20:27:53 -0700 Subject: PCI: Use spec names for SR-IOV capability fields Use the same names (almost) as the spec for TotalVFs, InitialVFs, NumVFs. Signed-off-by: Bjorn Helgaas --- drivers/pci/iov.c | 48 ++++++++++++++++++++++++------------------------ drivers/pci/pci-sysfs.c | 10 +++++----- drivers/pci/pci.h | 8 ++++---- 3 files changed, 33 insertions(+), 33 deletions(-) (limited to 'drivers/pci/pci.h') diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index f6781e42d00d..a32bd9ad0931 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -106,7 +106,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) virtfn->resource[i].name = pci_name(virtfn); virtfn->resource[i].flags = res->flags; size = resource_size(res); - do_div(size, iov->total); + do_div(size, iov->total_VFs); virtfn->resource[i].start = res->start + size * id; virtfn->resource[i].end = virtfn->resource[i].start + size - 1; rc = request_resource(res, &virtfn->resource[i]); @@ -194,7 +194,7 @@ static int sriov_migration(struct pci_dev *dev) u16 status; struct pci_sriov *iov = dev->sriov; - if (!iov->nr_virtfn) + if (!iov->num_VFs) return 0; if (!(iov->cap & PCI_SRIOV_CAP_VFM)) @@ -216,7 +216,7 @@ static void sriov_migration_task(struct work_struct *work) u16 status; struct pci_sriov *iov = container_of(work, struct pci_sriov, mtask); - for (i = iov->initial; i < iov->nr_virtfn; i++) { + for (i = iov->initial_VFs; i < iov->num_VFs; i++) { state = readb(iov->mstate + i); if (state == PCI_SRIOV_VFM_MI) { writeb(PCI_SRIOV_VFM_AV, iov->mstate + i); @@ -244,7 +244,7 @@ static int sriov_enable_migration(struct pci_dev *dev, int nr_virtfn) resource_size_t pa; struct pci_sriov *iov = dev->sriov; - if (nr_virtfn <= iov->initial) + if (nr_virtfn <= iov->initial_VFs) return 0; pci_read_config_dword(dev, iov->pos + PCI_SRIOV_VFM, &table); @@ -294,15 +294,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) if (!nr_virtfn) return 0; - if (iov->nr_virtfn) + if (iov->num_VFs) return -EINVAL; pci_read_config_word(dev, iov->pos + PCI_SRIOV_INITIAL_VF, &initial); - if (initial > iov->total || - (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial != iov->total))) + if (initial > iov->total_VFs || + (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial != iov->total_VFs))) return -EIO; - if (nr_virtfn < 0 || nr_virtfn > iov->total || + if (nr_virtfn < 0 || nr_virtfn > iov->total_VFs || (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial))) return -EINVAL; @@ -359,7 +359,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) msleep(100); pci_cfg_access_unlock(dev); - iov->initial = initial; + iov->initial_VFs = initial; if (nr_virtfn < initial) initial = nr_virtfn; @@ -376,7 +376,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) } kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE); - iov->nr_virtfn = nr_virtfn; + iov->num_VFs = nr_virtfn; return 0; @@ -401,13 +401,13 @@ static void sriov_disable(struct pci_dev *dev) int i; struct pci_sriov *iov = dev->sriov; - if (!iov->nr_virtfn) + if (!iov->num_VFs) return; if (iov->cap & PCI_SRIOV_CAP_VFM) sriov_disable_migration(dev); - for (i = 0; i < iov->nr_virtfn; i++) + for (i = 0; i < iov->num_VFs; i++) virtfn_remove(dev, i, 0); iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); @@ -419,7 +419,7 @@ static void sriov_disable(struct pci_dev *dev) if (iov->link != dev->devfn) sysfs_remove_link(&dev->dev.kobj, "dep_link"); - iov->nr_virtfn = 0; + iov->num_VFs = 0; } static int sriov_init(struct pci_dev *dev, int pos) @@ -496,7 +496,7 @@ found: iov->pos = pos; iov->nres = nres; iov->ctrl = ctrl; - iov->total = total; + iov->total_VFs = total; iov->offset = offset; iov->stride = stride; iov->pgsz = pgsz; @@ -529,7 +529,7 @@ failed: static void sriov_release(struct pci_dev *dev) { - BUG_ON(dev->sriov->nr_virtfn); + BUG_ON(dev->sriov->num_VFs); if (dev != dev->sriov->dev) pci_dev_put(dev->sriov->dev); @@ -554,7 +554,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_update_resource(dev, i); pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); - pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, iov->nr_virtfn); + pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, iov->num_VFs); pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); if (iov->ctrl & PCI_SRIOV_CTRL_VFE) msleep(100); @@ -661,7 +661,7 @@ int pci_iov_bus_range(struct pci_bus *bus) list_for_each_entry(dev, &bus->devices, bus_list) { if (!dev->is_physfn) continue; - busnr = virtfn_bus(dev, dev->sriov->total - 1); + busnr = virtfn_bus(dev, dev->sriov->total_VFs - 1); if (busnr > max) max = busnr; } @@ -732,7 +732,7 @@ int pci_num_vf(struct pci_dev *dev) if (!dev || !dev->is_physfn) return 0; else - return dev->sriov->nr_virtfn; + return dev->sriov->num_VFs; } EXPORT_SYMBOL_GPL(pci_num_vf); @@ -750,14 +750,14 @@ EXPORT_SYMBOL_GPL(pci_num_vf); */ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs) { - if (!dev || !dev->is_physfn || (numvfs > dev->sriov->total)) + if (!dev || !dev->is_physfn || (numvfs > dev->sriov->total_VFs)) return -EINVAL; /* Shouldn't change if VFs already enabled */ if (dev->sriov->ctrl & PCI_SRIOV_CTRL_VFE) return -EBUSY; else - dev->sriov->drvttl = numvfs; + dev->sriov->driver_max_VFs = numvfs; return 0; } @@ -768,7 +768,7 @@ EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs); * @dev: the PCI PF device * * For a PCIe device with SRIOV support, return the PCIe - * SRIOV capability value of TotalVFs or the value of drvttl + * SRIOV capability value of TotalVFs or the value of driver_max_VFs * if the driver reduced it. Otherwise, -EINVAL. */ int pci_sriov_get_totalvfs(struct pci_dev *dev) @@ -776,9 +776,9 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev) if (!dev || !dev->is_physfn) return -EINVAL; - if (dev->sriov->drvttl) - return dev->sriov->drvttl; + if (dev->sriov->driver_max_VFs) + return dev->sriov->driver_max_VFs; else - return dev->sriov->total; + return dev->sriov->total_VFs; } EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs); diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 99b5f83d2468..2f21991b8bcd 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -421,7 +421,7 @@ static ssize_t sriov_numvfs_show(struct device *dev, { struct pci_dev *pdev = to_pci_dev(dev); - return sprintf(buf, "%u\n", pdev->sriov->nr_virtfn); + return sprintf(buf, "%u\n", pdev->sriov->num_VFs); } /* @@ -455,7 +455,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, total = pci_sriov_get_totalvfs(pdev); /* Requested VFs to enable < totalvfs and none enabled already */ if ((num_vfs > 0) && (num_vfs <= total)) { - if (pdev->sriov->nr_virtfn == 0) { + if (pdev->sriov->num_VFs == 0) { num_vfs_enabled = pdev->driver->sriov_configure(pdev, num_vfs); if ((num_vfs_enabled >= 0) && @@ -467,7 +467,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, } else if (num_vfs_enabled < 0) /* error code from driver callback */ return num_vfs_enabled; - } else if (num_vfs == pdev->sriov->nr_virtfn) { + } else if (num_vfs == pdev->sriov->num_VFs) { dev_warn(&pdev->dev, "%d VFs already enabled; no enable action taken\n", num_vfs); @@ -475,14 +475,14 @@ static ssize_t sriov_numvfs_store(struct device *dev, } else { dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n", - pdev->sriov->nr_virtfn, num_vfs); + pdev->sriov->num_VFs, num_vfs); return -EINVAL; } } /* disable vfs */ if (num_vfs == 0) { - if (pdev->sriov->nr_virtfn != 0) { + if (pdev->sriov->num_VFs != 0) { ret = pdev->driver->sriov_configure(pdev, 0); return ret ? ret : count; } else { diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 553bbba76eec..3c9443ee00e6 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -233,14 +233,14 @@ struct pci_sriov { int nres; /* number of resources */ u32 cap; /* SR-IOV Capabilities */ u16 ctrl; /* SR-IOV Control */ - u16 total; /* total VFs associated with the PF */ - u16 initial; /* initial VFs associated with the PF */ - u16 nr_virtfn; /* number of VFs available */ + u16 total_VFs; /* total VFs associated with the PF */ + u16 initial_VFs; /* initial VFs associated with the PF */ + u16 num_VFs; /* number of VFs available */ u16 offset; /* first VF Routing ID offset */ u16 stride; /* following VF stride */ u32 pgsz; /* page size for BAR alignment */ u8 link; /* Function Dependency Link */ - u16 drvttl; /* max num VFs driver supports */ + u16 driver_max_VFs; /* max num VFs driver supports */ struct pci_dev *dev; /* lowest numbered PF */ struct pci_dev *self; /* this PF */ struct mutex lock; /* lock for VF bus */ -- cgit v1.2.3-55-g7522