SRIOV device enable and disable via sysfs
Subsystems (3)
PATCH 2/4 PCI,sys: Use is_visible() with boot_vga attribute for pci_dev
In reply to Donald DutileFrom: Don Dutile <[email protected]>
Should make pci_creae_sysfs_dev_files simpler.
Also fix possible memleak in remove path.
--- drivers/pci/pci-sysfs.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/pci/pci-sysfs.c +10 -11
@@ -1303,29 +1303,20 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev) pdev->rom_attr = attr; } -if ((pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ) { - retval =device_create_file (&pdev->dev, &vga_attr); -if (retval) - goto err_rom_file; - } -/* add platform-specific attributes */ retval =pcibios_add_platform_entries (pdev);if (retval) - goto err_vga_file; + goto err_rom_file;/* add sysfs entries for various capabilities */ retval =pci_create_capabilities_sysfs (pdev);if (retval) - goto err_vga_file; + goto err_rom_file;pci_create_firmware_label_files (pdev);return 0 ; -err_vga_file: -if ((pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ) -device_remove_file (&pdev->dev, &vga_attr); err_rom_file:if (rom_size) {sysfs_remove_bin_file (&pdev->dev.kobj, pdev->rom_attr);
@@ -1413,12 +1404,20 @@ static int __init pci_sysfs_init(void)late_initcall (pci_sysfs_init);static struct attribute *pci_dev_dev_attrs[] = { + &vga_attr.attr,NULL , };static umode_t pci_dev_attrs_are_visible (struct kobject *kobj,struct attribute *a,int n) { + struct device *dev = container_of(kobj, struct device, kobj); +struct pci_dev *pdev =to_pci_dev (dev); + +if (a == &vga_attr.attr) +if ((pdev->class >>8 ) !=PCI_CLASS_DISPLAY_VGA ) +return 0 ; +return a->mode; }
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 3/4 PCI,sys: SRIOV control and status via sysfs
In reply to Donald DutileProvide files under sysfs to determine the max number of vfs an SRIOV-capable PCIe device supports, and methods to enable and disable the vfs on a per device basis.
Currently, VF enablement by SRIOV-capable PCIe devices is done in driver-specific module parameters. If not setup in modprobe files, it requires admin to unload & reload PF drivers with number of desired VFs to enable. Additionally, the enablement is system wide: all devices controlled by the same driver have the same number of VFs enabled. Although the latter is probably desired, there are PCI configurations setup by system BIOS that may not enable that to occur.
Three files are created if a PCIe device has SRIOV support:sriov_totalvfs -- cat-ing this file returns the maximum number
of VFs a PCIe device supports as reported by the TotalVFs in the SRIOV ext cap structure.sriov_numvfs -- echo'ing a positive number to this file enables this
number of VFs for this given PCIe device.
-- echo'ing a 0 to this file disables
any previously enabled VFs for this PCIe device.
-- cat-ing this file will return the number of VFs
currently enabled on this PCIe device, i.e., the NumVFs field in SRIOV ext. cap structure.
VF enable and disablement is invoked much like other PCIe configuration functions -- via registered callbacks in the driver, i.e., probe, release, etc.
--- drivers/pci/pci-sysfs.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 136 insertions(+), 2 deletions(-)
drivers/pci/pci-sysfs.c +135 -2
@@ -14,7 +14,6 @@* */ -#include <linux/kernel.h> #include <linux/sched.h> #include <linux/pci.h>
@@ -404,6 +403,110 @@ static ssize_t d3cold_allowed_show(struct device *dev, }#endif +#ifdef CONFIG_PCI_IOV +static ssize_t sriov_totalvfs_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct pci_dev *pdev; +u16 total; + + pdev =to_pci_dev (dev); + total = pdev->sriov->total; +return sprintf (buf,"%u\n" , total); +} + + +static ssize_t sriov_numvfs_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct pci_dev *pdev; + + pdev =to_pci_dev (dev); + +return sprintf (buf,"%u\n" , pdev->sriov->nr_virtfn); +} + +/* +* num_vfs > 0; number of vfs to enable +* num_vfs = 0; disable all vfs +* +* Note: SRIOV spec doesn't allow partial VF +* disable, so its all or none. +*/ +static ssize_t sriov_numvfs_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev; +int num_vfs_enabled =0 ; +int num_vfs; +int ret =0 ; +u16 total; + + pdev =to_pci_dev (dev); + +if (kstrtoint (buf,0 , &num_vfs) <0 ) +return -EINVAL ; + +/* is PF driver loaded w/callback */ +if (!pdev->driver || !pdev->driver->sriov_configure) { +dev_info (&pdev->dev, +"Driver doesn't support SRIOV configuration via sysfs\n" ); +return -ENOSYS ; + } + +/* if enabling vf's ... */ + total = pdev->sriov->total; +/* Requested VFs to enable < totalvfs and none enabled already */ +if ((num_vfs >0 ) && (num_vfs <= total)) { +if (pdev->sriov->nr_virtfn ==0 ) { + num_vfs_enabled = + pdev->driver->sriov_configure (pdev, num_vfs); +if ((num_vfs_enabled >=0 ) && + (num_vfs_enabled != num_vfs)) +dev_warn (&pdev->dev, +"Only %d VFs enabled\n" , + num_vfs_enabled); +return count; + }else if (num_vfs == pdev->sriov->nr_virtfn) { +dev_warn (&pdev->dev, +"%d VFs already enabled; no enable action taken\n" , + num_vfs); +return count; + }else { +dev_warn (&pdev->dev, +"%d VFs already enabled. Disable before enabling %d VFs\n" , + pdev->sriov->nr_virtfn, num_vfs); +return -EINVAL ; + } + } + +/* disable vfs */ +if (num_vfs ==0 ) { +if (pdev->sriov->nr_virtfn !=0 ) { + ret = pdev->driver->sriov_configure (pdev,0 ); +return ret ? ret : count; + }else { +dev_warn (&pdev->dev, +"All VFs disabled; no disable action taken\n" ); +return count; + } + } + +dev_err (&pdev->dev, +"Invalid value for number of VFs to enable: %d\n" , num_vfs); + +return -EINVAL ; +} + +static struct device_attribute sriov_totalvfs_attr =__ATTR_RO (sriov_totalvfs); +static struct device_attribute sriov_numvfs_attr = +__ATTR (sriov_numvfs, (S_IRUGO |S_IWUSR |S_IWGRP ), + sriov_numvfs_show, sriov_numvfs_store); +#endif /* CONFIG_PCI_IOV */ +struct device_attribute pci_dev_attrs[] = {__ATTR_RO (resource),__ATTR_RO (vendor),
@@ -1409,7 +1512,7 @@ static struct attribute *pci_dev_dev_attrs[] = { };static umode_t pci_dev_attrs_are_visible (struct kobject *kobj, -struct attribute *a,int n) +struct attribute *a,int n) { struct device *dev = container_of(kobj, struct device, kobj);struct pci_dev *pdev =to_pci_dev (dev);
@@ -1421,6 +1524,33 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,return a->mode; } +#ifdef CONFIG_PCI_IOV +static struct attribute *sriov_dev_attrs[] = { + &sriov_totalvfs_attr.attr, + &sriov_numvfs_attr.attr, +NULL , +}; + +static umode_t sriov_attrs_are_visible (struct kobject *kobj, +struct attribute *a,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + +if ((a == &sriov_totalvfs_attr.attr) || + (a == &sriov_numvfs_attr.attr)) { +if (!dev_is_pf (dev)) +return 0 ; + } + +return a->mode; +} + +static struct attribute_group sriov_dev_attr_group = { + .attrs = sriov_dev_attrs, + .is_visible = sriov_attrs_are_visible, +}; +#endif /* CONFIG_PCI_IOV */ +static struct attribute_group pci_dev_attr_group = { .attrs = pci_dev_dev_attrs, .is_visible = pci_dev_attrs_are_visible,
@@ -1428,6 +1558,9 @@ static struct attribute_group pci_dev_attr_group = {static const struct attribute_group *pci_dev_attr_groups[] = { &pci_dev_attr_group, +#ifdef CONFIG_PCI_IOV + &sriov_dev_attr_group, +#endifNULL , };
include/linux/pci.h +1 -0
@@ -573,6 +573,7 @@ struct pci_driver {int (*resume_early) (struct pci_dev *dev);int (*resume) (struct pci_dev *dev);/* Device woken up */ void (*shutdown) (struct pci_dev *dev); +int (*sriov_configure) (struct pci_dev *dev,int num_vfs);/* PF pdev */ const struct pci_error_handlers *err_handler;struct device_driver driver;struct pci_dynids dynids;
Signature · 1 line
1.7.10.2.552.gaa3bb87
Provide files under sysfs to determine the max number of vfs an SRIOV-capable PCIe device supports, and methods to enable and disable the vfs on a per device basis.
Currently, VF enablement by SRIOV-capable PCIe devices is done in driver-specific module parameters. If not setup in modprobe files, it requires admin to unload & reload PF drivers with number of desired VFs to enable. Additionally, the enablement is system wide: all devices controlled by the same driver have the same number of VFs enabled. Although the latter is probably desired, there are PCI configurations setup by system BIOS that may not enable that to occur.
Two files are created if a PCIe device has SRIOV support:sriov_totalvfs -- cat-ing this file returns the maximum number
of VFs a PCIe device supports.sriov_numvfs -- echo'ing a positive number to this file enables
& configures this number of VFs for this given PCIe device.
-- echo'ing 0 to this file disables and deconfigures
all VFs for this given PCIe device.
-- cat-ing this file will return the number of VFs
currently enabled on this PCIe device.
VF enable and disablement is invoked much like other PCIe configuration functions -- via a registered callback in the driver, i.e., probe, release, etc. In this case, sriov_configure
RFC V3->PATCH:
-- incorporate feedback from Ben Hutchings.
-- clean up poor RFC patches & sanitize through checkpatch.pl
RFC v2->v3:
-- change the file names to reflect the names used in the SRIOV spec -- change to a single file for enable & disable;
change driver interface to a single interface.
-- add more informative messages on failures
-- add a core method that a driver can invoke to modify
the totalvfs reported & supported by a driver.
-- a set of patches for ixgbe provided by Greg Rose to use the
new interfaces; the last patch modified from the original two file, enable/disable interface to the current single file enable/disable. Greg will eventually post the final version of these patches via Intel's usual process for driver patches. Provided here as an example, and enable other SRIOV drivers to see how adoption of the interface can be added.
RFC v1->v2:
This patch is based on previous 2 patches by Yinghai Lu that cleaned up the vga attributes for PCI devices under sysfs, and uses visibility-checking group attributes as recommended by Greg K-H.
PATCH 1/4 PCI: add pci_device_type to pdev's device struct
From: Yinghai Lu <[email protected]>
Need type filled in device structure so it
can be used for visible attribute control in
syfsfs for pci_dev.
--- drivers/pci/pci-sysfs.c | 24 ++++++++++++++++++++++++ drivers/pci/pci.h | 1 + drivers/pci/probe.c | 1 + 3 files changed, 26 insertions(+)
drivers/pci/pci-sysfs.c +24 -0
@@ -1411,3 +1411,27 @@ static int __init pci_sysfs_init(void) }late_initcall (pci_sysfs_init); + +static struct attribute *pci_dev_dev_attrs[] = { +NULL , +}; + +static umode_t pci_dev_attrs_are_visible (struct kobject *kobj, +struct attribute *a,int n) +{ +return a->mode; +} + +static struct attribute_group pci_dev_attr_group = { + .attrs = pci_dev_dev_attrs, + .is_visible = pci_dev_attrs_are_visible, +}; + +static const struct attribute_group *pci_dev_attr_groups[] = { + &pci_dev_attr_group, +NULL , +}; + +struct device_type pci_dev_type = { + .groups = pci_dev_attr_groups, +};
drivers/pci/pci.h +1 -0
@@ -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
drivers/pci/probe.c +1 -0
@@ -975,6 +975,7 @@ int pci_setup_device(struct pci_dev *dev) dev->sysdata = dev->bus->sysdata; dev->dev.parent = dev->bus->bridge; dev->dev.bus = &pci_bus_type; + dev->dev.type = &pci_dev_type; dev->hdr_type = hdr_type &0x7f ; dev->multifunction = !!(hdr_type &0x80 ); dev->error_state = pci_channel_io_normal;
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 4/4 PCI,sriov: provide method to reduce the number of total VFs supported
In reply to Donald DutileSome 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.
--- drivers/pci/iov.c | 27 ++++++++++++++++++++++++++- drivers/pci/pci-sysfs.c | 10 ++++++++-- drivers/pci/pci.h | 1 + include/linux/pci.h | 5 +++++ 4 files changed, 40 insertions(+), 3 deletions(-)
drivers/pci/iov.c +26 -1
@@ -682,7 +682,6 @@ int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)if (!dev->is_physfn)return -ENODEV ; -return sriov_enable (dev, nr_virtfn); }EXPORT_SYMBOL_GPL (pci_enable_sriov);
@@ -735,3 +734,29 @@ 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, otherwise -EINVAL +*/ +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 -EIO ; +else + dev->sriov->drvttl = numvfs; + +return 0 ; +} +EXPORT_SYMBOL_GPL (pci_sriov_set_totalvfs);
drivers/pci/pci-sysfs.c +8 -2
@@ -412,7 +412,10 @@ static ssize_t sriov_totalvfs_show(struct device *dev,u16 total; pdev =to_pci_dev (dev); - total = pdev->sriov->total; +if (pdev->sriov->drvttl) + total = pdev->sriov->drvttl; +else + total = pdev->sriov->total;return sprintf (buf,"%u\n" , total); }
@@ -458,7 +461,10 @@ static ssize_t sriov_numvfs_store(struct device *dev, }/* if enabling vf's ... */ - total = pdev->sriov->total; +if (pdev->sriov->drvttl) + total = pdev->sriov->drvttl; +else + total = pdev->sriov->total;/* Requested VFs to enable < totalvfs and none enabled already */ if ((num_vfs >0 ) && (num_vfs <= total)) {if (pdev->sriov->nr_virtfn ==0 ) {
drivers/pci/pci.h +1 -0
@@ -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 */
include/linux/pci.h +5 -0
@@ -1611,6 +1611,7 @@ 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);#else static inline int pci_enable_sriov (struct pci_dev *dev,int nr_virtfn) {
@@ -1627,6 +1628,10 @@ 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 ; +}#endif #if defined(CONFIG_HOTPLUG_PCI ) || defined(CONFIG_HOTPLUG_PCI_MODULE )
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 5/8 ixgbe: refactor mailbox ops init
In reply to Donald DutileThere is no actual dependency on initialization of the mailbox ops on whether SR-IOV is enabled or not and it doesn't hurt to go ahead and initialize ops unconditionally. Move the initialization into the device probe so that the mailbox ops are initialized at the time we have the board info necessary to do it.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 ++++- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 9 +-------- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +4 -1
@@ -7249,7 +7249,10 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev, }#ifdef CONFIG_PCI_IOV -ixgbe_enable_sriov (adapter, ii); +/* Mailbox */ +ixgbe_init_mbx_params_pf (hw); +memcpy (&hw->mbx.ops, ii->mbx_ops,sizeof (hw->mbx.ops)); +ixgbe_enable_sriov (adapter);#endif netdev->features = NETIF_F_SG |
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +1 -8
@@ -44,8 +44,7 @@#include "ixgbe_sriov.h" #ifdef CONFIG_PCI_IOV -void ixgbe_enable_sriov (struct ixgbe_adapter *adapter, -const struct ixgbe_info *ii) +void ixgbe_enable_sriov (struct ixgbe_adapter *adapter); {struct ixgbe_hw *hw = &adapter->hw;int num_vf_macvlans, i;
@@ -124,12 +123,6 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,kcalloc (adapter->num_vfs,sizeof (struct vf_data_storage ),GFP_KERNEL );if (adapter->vfinfo) { -/* Now that we're sure SR-IOV is enabled -* and memory allocated set up the mailbox parameters -*/ -ixgbe_init_mbx_params_pf (hw); -memcpy (&hw->mbx.ops, ii->mbx_ops,sizeof (hw->mbx.ops)); -/* limit trafffic classes based on VFs enabled */ if ((adapter->hw.mac.type == ixgbe_mac_82599EB) && (adapter->num_vfs <16 )) {
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h +1 -2
@@ -43,8 +43,7 @@ int ixgbe_ndo_get_vf_config(struct net_device *netdev,void ixgbe_check_vf_rate_limit (struct ixgbe_adapter *adapter);void ixgbe_disable_sriov (struct ixgbe_adapter *adapter);#ifdef CONFIG_PCI_IOV -void ixgbe_enable_sriov (struct ixgbe_adapter *adapter, -const struct ixgbe_info *ii); +void ixgbe_enable_sriov (struct ixgbe_adapter *adapter);#endif
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 6/8 ixgbe: refactor SRIOV enable and disable for sysfs interface
In reply to Donald DutileIn preparation for enable/disable of SR-IOV via the pci sysfs interface move some core SR-IOV enablement code that would be common to module parameter usage or callback from the pci bus driver to a separate function so that it can be used by either method.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 98 +++++++++++++++----------- 1 file changed, 58 insertions(+), 40 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +58 -40
@@ -44,49 +44,11 @@#include "ixgbe_sriov.h" #ifdef CONFIG_PCI_IOV -void ixgbe_enable_sriov (struct ixgbe_adapter *adapter); +static int __ixgbe_enable_sriov (struct ixgbe_adapter *adapter) {struct ixgbe_hw *hw = &adapter->hw;int num_vf_macvlans, i;struct vf_macvlans *mv_list; -int pre_existing_vfs =0 ; - - pre_existing_vfs =pci_num_vf (adapter->pdev); -if (!pre_existing_vfs && !adapter->num_vfs) -return ; - -/* If there are pre-existing VFs then we have to force -* use of that many because they were not deleted the last -* time someone removed the PF driver. That would have -* been because they were allocated to guest VMs and can't -* be removed. Go ahead and just re-enable the old amount. -* If the user wants to change the number of VFs they can -* use ethtool while making sure no VFs are allocated to -* guest VMs... i.e. the right way. -*/ -if (pre_existing_vfs) { - adapter->num_vfs = pre_existing_vfs; -dev_warn (&adapter->pdev->dev,"Virtual Functions already " -"enabled for this device - Please reload all " -"VF drivers to avoid spoofed packet errors\n" ); - }else { -int err; -/* -* The 82599 supports up to 64 VFs per physical function -* but this implementation limits allocation to 63 so that -* basic networking resources are still available to the -* physical function. If the user requests greater thn -* 63 VFs then it is an error - reset to default of zero. -*/ - adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, 63); - - err =pci_enable_sriov (adapter->pdev, adapter->num_vfs); -if (err) { -e_err (probe,"Failed to enable PCI sriov: %d\n" , err); - adapter->num_vfs =0 ; -return ; - } - } adapter->flags |=IXGBE_FLAG_SRIOV_ENABLED ;e_info (probe,"SR-IOV enabled with %d VFs\n" , adapter->num_vfs);
@@ -156,10 +118,66 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter);/* enable spoof checking for all VFs */ for (i =0 ; i < adapter->num_vfs; i++) adapter->vfinfo[i].spoofchk_enabled = true; +return 0 ; + } + +return -ENOMEM ; +} + +/* +* Note this function is called when the user wants to enable SR-IOV +* VFs using the now deprecated module parameter +*/ +void ixgbe_enable_sriov (struct ixgbe_adapter *adapter) +{ +int pre_existing_vfs =0 ; + + pre_existing_vfs =pci_num_vf (adapter->pdev); +if (!pre_existing_vfs && !adapter->num_vfs)return ; + +if (!pre_existing_vfs) +dev_warn (&adapter->pdev->dev, +"Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n" ); + +/* +* If there are pre-existing VFs then we have to force +* use of that many - over ride any module parameter value. +* This may result from the user unloading the PF driver +* while VFs were assigned to guest VMs or because the VFs +* have been created via the new PCI SR-IOV sysfs interface. +*/ +if (pre_existing_vfs) { + adapter->num_vfs = pre_existing_vfs; +dev_warn (&adapter->pdev->dev,"Virtual Functions already " +"enabled for this device - Please reload all " +"VF drivers to avoid spoofed packet errors\n" ); + }else { +int err; +/* +* The 82599 supports up to 64 VFs per physical function +* but this implementation limits allocation to 63 so that +* basic networking resources are still available to the +* physical function. If the user requests greater thn +* 63 VFs then it is an error - reset to default of zero. +*/ + adapter->num_vfs = min_t(unsigned int, adapter->num_vfs, 63); + + err =pci_enable_sriov (adapter->pdev, adapter->num_vfs); +if (err) { +e_err (probe,"Failed to enable PCI sriov: %d\n" , err); + adapter->num_vfs =0 ; +return ; + } } -/* Oh oh */ +if (!__ixgbe_enable_sriov (adapter)) +return ; + +/* +* If we have gotten to this point then there is no memory available +* to manage the VF devices - print message and bail. +*/ e_err (probe,"Unable to allocate memory for VF Data Storage - " "SRIOV disabled\n" );ixgbe_disable_sriov (adapter);
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 7/8 ixgbe: sysfs sriov configuration callback support
In reply to Donald DutileImplement callbacks in the driver for the new PCI bus driver interface that allows the user to enable/disable SR-IOV VFs in a device via the sysfs interface.
--- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 3 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 28 +++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 89 +++++++++++++++++++++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h | 6 +- 4 files changed, 120 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +3 -0
@@ -753,5 +753,8 @@ extern int ixgbe_ptp_hwtstamp_ioctl(struct ixgbe_adapter *adapter,extern void ixgbe_ptp_start_cyclecounter (struct ixgbe_adapter *adapter);extern void ixgbe_ptp_check_pps_event (struct ixgbe_adapter *adapter,u32 eicr);#endif /* CONFIG_IXGBE_PTP */ +#ifdef CONFIG_PCI_IOV +void ixgbe_sriov_reinit (struct ixgbe_adapter *adapter); +#endif #endif /* _IXGBE_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +27 -1
@@ -6784,6 +6784,26 @@ int ixgbe_setup_tc(struct net_device *dev, u8 tc) }#endif /* CONFIG_IXGBE_DCB */ +#ifdef CONFIG_PCI_IOV +void ixgbe_sriov_reinit (struct ixgbe_adapter *adapter) +{ +struct net_device *netdev = adapter->netdev; + +rtnl_lock (); +#ifdef CONFIG_IXGBE_DCB +ixgbe_setup_tc (netdev,netdev_get_num_tc (netdev)); +#else +if (netif_running (netdev)) +ixgbe_close (netdev); +ixgbe_clear_interrupt_scheme (adapter); +ixgbe_init_interrupt_scheme (adapter); +if (netif_running (netdev)) +ixgbe_open (netdev); +#endif +rtnl_unlock (); +} + +#endif void ixgbe_do_reset (struct net_device *netdev) {struct ixgbe_adapter *adapter =netdev_priv (netdev);
@@ -7519,7 +7539,12 @@ static void __devexit ixgbe_remove(struct pci_dev *pdev)if (netdev->reg_state ==NETREG_REGISTERED )unregister_netdev (netdev); -ixgbe_disable_sriov (adapter); +/* +* Only disable SR-IOV on unload if the user specified the now +* deprecated max_vfs module parameter. +*/ +if (max_vfs) +ixgbe_disable_sriov (adapter);ixgbe_clear_interrupt_scheme (adapter);
@@ -7734,6 +7759,7 @@ static struct pci_driver ixgbe_driver = { .resume = ixgbe_resume, #endif .shutdown = ixgbe_shutdown, + .sriov_configure = ixgbe_pci_sriov_configure, .err_handler = &ixgbe_err_handler };
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +86 -3
121 lines not on this page · raw message
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h +4 -2
@@ -41,11 +41,13 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting);int ixgbe_ndo_get_vf_config (struct net_device *netdev,int vf,struct ifla_vf_info *ivi);void ixgbe_check_vf_rate_limit (struct ixgbe_adapter *adapter); -void ixgbe_disable_sriov (struct ixgbe_adapter *adapter); +int ixgbe_disable_sriov (struct ixgbe_adapter *adapter);#ifdef CONFIG_PCI_IOV void ixgbe_enable_sriov (struct ixgbe_adapter *adapter);#endif - +int ixgbe_pci_sriov_enable (struct pci_dev *dev,int num_vfs); +int ixgbe_pci_sriov_disable (struct pci_dev *dev); +int ixgbe_pci_sriov_configure (struct pci_dev *dev,int num_vfs);#endif /* _IXGBE_SRIOV_H_ */
Signature · 1 line
1.7.10.2.552.gaa3bb87
PATCH 8/8 ixgbe: change totalvfs to match support in driver
In reply to Donald Dutileixgbe claims it supports 64 VFs in its SRIOV capability structure, but the driver only supports 63. Adjust it so sysfs sriov configuration checking will check with the proper totalvf value.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -0
@@ -7273,6 +7273,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,ixgbe_init_mbx_params_pf (hw);memcpy (&hw->mbx.ops, ii->mbx_ops,sizeof (hw->mbx.ops));ixgbe_enable_sriov (adapter); +pci_sriov_set_totalvfs (pdev,63 );#endif netdev->features = NETIF_F_SG |
Signature · 1 line
1.7.10.2.552.gaa3bb87
Sorry, $Subject should be [PATCH] not [RFC] ... I don't know why it prefixed by [RFC] .... I blame it on Hurricane Sandy ! ;-)
Quoted 58 lines · Donald Dutile
Provide files under sysfs to determine the max number of vfs an SRIOV-capable PCIe device supports, and methods to enable and disable the vfs on a per device basis.
Currently, VF enablement by SRIOV-capable PCIe devices is done in driver-specific module parameters. If not setup in modprobe files, it requires admin to unload& reload PF drivers with number of desired VFs to enable. Additionally, the enablement is system wide: all devices controlled by the same driver have the same number of VFs enabled. Although the latter is probably desired, there are PCI configurations setup by system BIOS that may not enable that to occur.
Two files are created if a PCIe device has SRIOV support:
sriov_totalvfs-- cat-ing this file returns the maximum number
of VFs a PCIe device supports.sriov_numvfs-- echo'ing a positive number to this file enables
& configures this number of VFs for this given PCIe device.
-- echo'ing 0 to this file disables and deconfigures
all VFs for this given PCIe device.
-- cat-ing this file will return the number of VFs
currently enabled on this PCIe device.VF enable and disablement is invoked much like other PCIe configuration functions -- via a registered callback in the driver, i.e., probe, release, etc. In this case,
sriov_configureRFC
V3->PATCH:
-- incorporate feedback from Ben Hutchings.
-- clean up poor RFC patches& sanitize through checkpatch.plRFC
v2->v3:
-- change the file names to reflect the names used in the SRIOV spec -- change to a single file for enable& disable;
change driver interface to a single interface.
-- add more informative messages on failures
-- add a core method that a driver can invoke to modify
the totalvfs reported& supported by a driver.
-- a set of patches for ixgbe provided by Greg Rose to use the
new interfaces; the last patch modified from the original two file, enable/disable interface to the current single file enable/disable. Greg will eventually post the final version of these patches via Intel's usual process for driver patches. Provided here as an example, and enable other SRIOV drivers to see how adoption of the interface can be added.RFC
v1->v2:
This patch is based on previous 2 patches by Yinghai Lu that cleaned up the vga attributes for PCI devices under sysfs, and uses visibility-checking group attributes as recommended by Greg K-H.Signed-off-by Donald Dutile<[email protected]>--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] PCI,sys: Use is_visible() with boot_vga attribute for pci_dev
In reply to Donald DutileQuoted 1 line · Donald Dutile
From: Don Dutile <[email protected]>
should be
From: Yinghai Lu <[email protected]>
Quoted 5 lines
Should make
pci_creae_sysfs_dev_filessimpler.
Also fix possible memleak in remove path.Authored-by Yinghai Lu <[email protected]>
should be:
Quoted 1 line
Signed-off-by Donald Dutile <[email protected]>
patch 1 and 2 got acked-by from Greg KH
Re: [PATCH 2/4] PCI,sys: Use is_visible() with boot_vga attribute for pci_dev
Quoted 6 lines · Yinghai Lu
Quoted 1 line · Donald Dutile
From: Don Dutile<[email protected]>
should be
From: Yinghai Lu<[email protected]>
sorry. Tried to credit you for 1st two patches.
Quoted 9 lines
Quoted 5 lines
Should make
pci_creae_sysfs_dev_filessimpler.
Also fix possible memleak in remove path.Authored-by Yinghai Lu<[email protected]>should be:
Signed-off-by Yinghai Lu<[email protected]>
I didn't want to sign off for you b/c I reworded the log. I was trying to credit you for the patch by stating you Authored it. My apologies if that was incorrect.
Quoted 5 lines
Quoted 1 line
Signed-off-by Donald Dutile<[email protected]>patch 1 and 2 got acked-by from Greg KH
Yes, but didn't see it in Linus' git tree. Should I have used one of Bjorn's tree/branch with this patch in it as master of these patches ?
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] PCI,sys: Use is_visible() with boot_vga attribute for pci_dev
Quoted 20 lines · Don Dutile
Quoted 9 lines · Yinghai Lu
Quoted 2 lines · Donald Dutile
From: Don Dutile<[email protected]>
should be
From: Yinghai Lu<[email protected]>sorry. Tried to credit you for 1st two patches.
Quoted 7 lines
Quoted 5 lines
Should make
pci_creae_sysfs_dev_filessimpler.
Also fix possible memleak in remove path.Authored-by Yinghai Lu<[email protected]>
Quoted 9 lines
Quoted 3 lines
should be:
Signed-off-by Yinghai Lu<[email protected]>I didn't want to sign off for you b/c I reworded the log. I was trying to credit you for the patch by stating you Authored it. My apologies if that was incorrect.
if you change log, you still can keep my old Signed-off and add [ changelog updated.... Donald]
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
Signed-off-by Donald Dutile<[email protected]>patch 1 and 2 got acked-by from Greg KH
Yes, but didn't see it in Linus' git tree. Should I have used one of Bjorn's tree/branch with this patch in it as master of these patches ?
if bjorn could give Acked-by, those pci change patches go together with ixgbe changes via Dave's Net-next tree.
or bjorn add one branch in pci next tree to have the first 4 patches, and let Dave to pull it and use as base for ixgbe change.
or just first 4 patches go into 3.7 directly...
Re: [PATCH 3/4] PCI,sys: SRIOV control and status via sysfs
In reply to Donald DutileQuoted 38 lines · Donald Dutile
Provide files under sysfs to determine the max number of vfs an SRIOV-capable PCIe device supports, and methods to enable and disable the vfs on a per device basis.
Currently, VF enablement by SRIOV-capable PCIe devices is done in driver-specific module parameters. If not setup in modprobe files, it requires admin to unload & reload PF drivers with number of desired VFs to enable. Additionally, the enablement is system wide: all devices controlled by the same driver have the same number of VFs enabled. Although the latter is probably desired, there are PCI configurations setup by system BIOS that may not enable that to occur.
Three files are created if a PCIe device has SRIOV support:
sriov_totalvfs-- cat-ing this file returns the maximum number
of VFs a PCIe device supports as reported by the TotalVFs in the SRIOV ext cap structure.sriov_numvfs-- echo'ing a positive number to this file enables this
number of VFs for this given PCIe device.
-- echo'ing a 0 to this file disables
any previously enabled VFs for this PCIe device.
-- cat-ing this file will return the number of VFs
currently enabled on this PCIe device, i.e., the NumVFs field in SRIOV ext. cap structure.VF enable and disablement is invoked much like other PCIe configuration functions -- via registered callbacks in the driver, i.e., probe, release, etc.
Signed-off-by Donald Dutile <[email protected]>--- drivers/pci/pci-sysfs.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 136 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c +0
-0
[...]
Quoted 25 lines
drivers/pci/pci-sysfs.c +25
-0+static ssize_t sriov_numvfs_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev; +int num_vfs_enabled =0 ; +int num_vfs; +int ret =0 ; +u16 total; + + pdev =to_pci_dev (dev); + +if (kstrtoint (buf,0 , &num_vfs) <0 ) +return -EINVAL ; + +/* is PF driver loaded w/callback */ +if (!pdev->driver || !pdev->driver->sriov_configure) { +dev_info (&pdev->dev, +"Driver doesn't support SRIOV configuration via sysfs\n" ); +return -ENOSYS ; + } + +/* if enabling vf's ... */ + total = pdev->sriov->total; +/* Requested VFs to enable < totalvfs and none enabled already */
drivers/pci/pci-sysfs.c static ssize_t d3cold_allowed_show(struct device *dev, · line 472
Quoted 10 lines
drivers/pci/pci-sysfs.c +10
-0+if ((num_vfs >0 ) && (num_vfs <= total)) { +if (pdev->sriov->nr_virtfn ==0 ) { + num_vfs_enabled = + pdev->driver->sriov_configure (pdev, num_vfs); +if ((num_vfs_enabled >=0 ) && + (num_vfs_enabled != num_vfs)) +dev_warn (&pdev->dev, +"Only %d VFs enabled\n" , + num_vfs_enabled); +return count;
If num_vfs_enabled < 0 then it's an error value which should be returned instead of count.
[...]
drivers/pci/pci-sysfs.c static struct attribute *pci_dev_dev_attrs[] = { · line 1518
Quoted 9 lines
drivers/pci/pci-sysfs.c +1
-1@@ -1409,7 +1512,7 @@ static struct attribute *pci_dev_dev_attrs[] = { };static umode_t pci_dev_attrs_are_visible (struct kobject *kobj, -struct attribute *a,int n) +struct attribute *a,int n) { struct device *dev = container_of(kobj, struct device, kobj);struct pci_dev *pdev =to_pci_dev (dev);
This hunk should be folded into patch 1.
Quoted 11 lines
drivers/pci/pci-sysfs.c +7
-0@@ -1421,6 +1524,33 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,return a->mode; } +#ifdef CONFIG_PCI_IOV +static struct attribute *sriov_dev_attrs[] = { + &sriov_totalvfs_attr.attr, + &sriov_numvfs_attr.attr, +NULL , +}; +
drivers/pci/pci-sysfs.c static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, · line 1543
Quoted 10 lines
drivers/pci/pci-sysfs.c +10
-0+static umode_t sriov_attrs_are_visible (struct kobject *kobj, +struct attribute *a,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + +if ((a == &sriov_totalvfs_attr.attr) || + (a == &sriov_numvfs_attr.attr)) { +if (!dev_is_pf (dev)) +return 0 ; + }
Why do you check the attribute address? The whole group should be visible or invisible depending on dev_is_pf(). Any attributes that need another condition belong in another group.
Quoted 8 lines
drivers/pci/pci-sysfs.c +8
-0+ return a->mode; +} + +static struct attribute_group sriov_dev_attr_group = { + .attrs = sriov_dev_attrs, + .is_visible = sriov_attrs_are_visible, +}; +#endif /* CONFIG_PCI_IOV */
[...]
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH 4/4] PCI,sriov: provide method to reduce the number of total VFs supported
In reply to Donald DutileQuoted 22 lines · Donald Dutile
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 <[email protected]>--- drivers/pci/iov.c | 27 ++++++++++++++++++++++++++- drivers/pci/pci-sysfs.c | 10 ++++++++-- drivers/pci/pci.h | 1 + include/linux/pci.h | 5 +++++ 4 files changed, 40 insertions(+), 3 deletions(-)drivers/pci/iov.c +0
-0
drivers/pci/iov.c int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) · line 687
Quoted 7 lines
drivers/pci/iov.c +0
-1@@ -682,7 +682,6 @@ int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)if (!dev->is_physfn)return -ENODEV ; -return sriov_enable (dev, nr_virtfn); }EXPORT_SYMBOL_GPL (pci_enable_sriov);
This hunk doesn't belong in this patch.
Quoted 5 lines
drivers/pci/iov.c +1
-0@@ -735,3 +734,29 @@ int pci_num_vf(struct pci_dev *dev)return dev->sriov->nr_virtfn; }EXPORT_SYMBOL_GPL (pci_num_vf); +
drivers/pci/iov.c int pci_num_vf(struct pci_dev *dev) · line 747
Quoted 10 lines
drivers/pci/iov.c +10
-0+/** +* 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, otherwise -EINVAL
This says the only possible error is -EINVAL, but it can also return -EIO! And the already-enabled case might be one that some drivers will need to handle specially.
drivers/pci/iov.c int pci_num_vf(struct pci_dev *dev) · line 756
Quoted 9 lines
drivers/pci/iov.c +9
-0+*/ +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 -EIO ;
[...]
EBUSY seems a bit more appropriate.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [PATCH 3/4] PCI,sys: SRIOV control and status via sysfs
In reply to Ben HutchingsQuoted 79 lines · Ben Hutchings
Quoted 38 lines · Donald Dutile
Provide files under sysfs to determine the max number of vfs an SRIOV-capable PCIe device supports, and methods to enable and disable the vfs on a per device basis.
Currently, VF enablement by SRIOV-capable PCIe devices is done in driver-specific module parameters. If not setup in modprobe files, it requires admin to unload& reload PF drivers with number of desired VFs to enable. Additionally, the enablement is system wide: all devices controlled by the same driver have the same number of VFs enabled. Although the latter is probably desired, there are PCI configurations setup by system BIOS that may not enable that to occur.
Three files are created if a PCIe device has SRIOV support:
sriov_totalvfs-- cat-ing this file returns the maximum number
of VFs a PCIe device supports as reported by the TotalVFs in the SRIOV ext cap structure.sriov_numvfs-- echo'ing a positive number to this file enables this
number of VFs for this given PCIe device.
-- echo'ing a 0 to this file disables
any previously enabled VFs for this PCIe device.
-- cat-ing this file will return the number of VFs
currently enabled on this PCIe device, i.e., the NumVFs field in SRIOV ext. cap structure.VF enable and disablement is invoked much like other PCIe configuration functions -- via registered callbacks in the driver, i.e., probe, release, etc.
Signed-off-by Donald Dutile<[email protected]>--- drivers/pci/pci-sysfs.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 136 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c +0
-0[...]
Quoted 25 lines
drivers/pci/pci-sysfs.c +25
-0+static ssize_t sriov_numvfs_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct pci_dev *pdev; +int num_vfs_enabled =0 ; +int num_vfs; +int ret =0 ; +u16 total; + + pdev =to_pci_dev (dev); + +if (kstrtoint (buf,0 ,&num_vfs)<0 ) +return -EINVAL ; + +/* is PF driver loaded w/callback */ +if (!pdev->driver || !pdev->driver->sriov_configure) { +dev_info (&pdev->dev, +"Driver doesn't support SRIOV configuration via sysfs\n" ); +return -ENOSYS ; + } + +/* if enabling vf's ... */ + total = pdev->sriov->total; +/* Requested VFs to enable< totalvfs and none enabled already */ drivers/pci/pci-sysfs.c static ssize_t d3cold_allowed_show(struct device *dev, · line 472
Quoted 10 lines
drivers/pci/pci-sysfs.c +10
-0+if ((num_vfs>0 )&& (num_vfs<= total)) { +if (pdev->sriov->nr_virtfn ==0 ) { + num_vfs_enabled = + pdev->driver->sriov_configure (pdev, num_vfs); +if ((num_vfs_enabled>=0 )&& + (num_vfs_enabled != num_vfs)) +dev_warn (&pdev->dev, +"Only %d VFs enabled\n" , + num_vfs_enabled); +return count;If num_vfs_enabled< 0 then it's an error value which should be returned instead of count.
Quoted 1 line
[...]
agreed. will update.
Quoted 12 lines
drivers/pci/pci-sysfs.c static struct attribute *pci_dev_dev_attrs[] = { · line 1518
Quoted 9 lines
drivers/pci/pci-sysfs.c +1
-1@@ -1409,7 +1512,7 @@ static struct attribute *pci_dev_dev_attrs[] = { };static umode_t pci_dev_attrs_are_visible (struct kobject *kobj, -struct attribute *a,int n) +struct attribute *a,int n) { struct device *dev = container_of(kobj, struct device, kobj);struct pci_dev *pdev =to_pci_dev (dev);This hunk should be folded into patch 1.
i removed it. will do a cleanup of this file in another patch.
Quoted 17 lines
Quoted 17 lines
drivers/pci/pci-sysfs.c +13
-0@@ -1421,6 +1524,33 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,return a->mode; } +#ifdef CONFIG_PCI_IOV +static struct attribute *sriov_dev_attrs[] = { + &sriov_totalvfs_attr.attr, + &sriov_numvfs_attr.attr, +NULL , +}; + +static umode_t sriov_attrs_are_visible (struct kobject *kobj, +struct attribute *a,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + + if ((a ==&sriov_totalvfs_attr.attr) ||
Quoted 9 lines
drivers/pci/pci-sysfs.c static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, · line 1543
Quoted 4 lines
drivers/pci/pci-sysfs.c +4
-0+ (a ==&sriov_numvfs_attr.attr)) { +if (!dev_is_pf (dev)) +return 0 ; + }Why do you check the attribute address? The whole group should be visible or invisible depending on
dev_is_pf(). Any attributes that need another condition belong in another group.
agreed. it's a leftover design when it was part of the uber pci-dev attrs, but now that it's separate, dev_is_pf() is sufficient.
good cleanup.
Quoted 10 lines
Quoted 8 lines
drivers/pci/pci-sysfs.c +8
-0+ return a->mode; +} + +static struct attribute_group sriov_dev_attr_group = { + .attrs = sriov_dev_attrs, + .is_visible = sriov_attrs_are_visible, +}; +#endif /* CONFIG_PCI_IOV */ [...]
Re: [PATCH 4/4] PCI,sriov: provide method to reduce the number of total VFs supported
In reply to Ben HutchingsQuoted 24 lines · Ben Hutchings
Quoted 23 lines · Donald Dutile
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<[email protected]>--- drivers/pci/iov.c | 27 ++++++++++++++++++++++++++- drivers/pci/pci-sysfs.c | 10 ++++++++-- drivers/pci/pci.h | 1 + include/linux/pci.h | 5 +++++ 4 files changed, 40 insertions(+), 3 deletions(-)drivers/pci/iov.c +0
-0@@ -682,7 +682,6 @@ int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
Quoted 9 lines
drivers/pci/iov.c int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) · line 687
Quoted 6 lines
drivers/pci/iov.c +0
-1if (!dev->is_physfn)return -ENODEV ; -return sriov_enable (dev, nr_virtfn); }EXPORT_SYMBOL_GPL (pci_enable_sriov);This hunk doesn't belong in this patch.
gone in next rev.
Quoted 31 lines
Quoted 5 lines
drivers/pci/iov.c +1
-0@@ -735,3 +734,29 @@ int pci_num_vf(struct pci_dev *dev)return dev->sriov->nr_virtfn; }EXPORT_SYMBOL_GPL (pci_num_vf); +drivers/pci/iov.c int pci_num_vf(struct pci_dev *dev) · line 747
Quoted 10 lines
drivers/pci/iov.c +10
-0+/** +* 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, otherwise -EINVAL This says the only possible error is
-EINVAL, but it can also return-EIO! And the already-enabled case might be one that some drivers will need to handle specially.Quoted 9 lines
drivers/pci/iov.c +9
-0+*/ +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 -EIO ;[...]
Quoted 4 lines
EBUSY seems a bit more appropriate.
Ben.
ok. changed to -EBUSY & comment on return values.
After looking at this area more, I created a pci_sriov_get_totalvfs() as well, and now use that in the pci-sysfs.c file as well.... much cleaner; symmetric to set. Makes backporting to those crazy enterprise releases w/kabi rules easier too! ;-)