PCI/IB: add support for pci driver attribute groups
Subsystems (2)
From: Greg Kroah-Hartman <[email protected]>
Some drivers (specifically the nes IB driver), want to create a lot of sysfs driver attributes. Instead of open-coding the creation and removal of these files (and getting it wrong btw), it's a better idea to let the driver core handle all of this logic for us.
So add a new field to the pci driver structure, **groups, that allows pci drivers to specify an attribute group list it wishes to have created when it is registered with the driver core.
Big bonus is now the driver doesn't race with userspace when the sysfs files are created vs. when the kobject is announced, so any script/tool that actually wanted to use these files will not have to poll waiting for them to show up.
--- drivers/infiniband/hw/nes/nes.c | 69 +++++++++++++--------------------------- drivers/pci/pci-driver.c | 1 include/linux/pci.h | 1 3 files changed, 26 insertions(+), 45 deletions(-)
drivers/infiniband/hw/nes/nes.c +24 -45
@@ -808,13 +808,6 @@ static void nes_remove(struct pci_dev *p } -static struct pci_driver nes_pci_driver = { - .name =DRV_NAME , - .id_table = nes_pci_table, - .probe = nes_probe, - .remove = nes_remove, -}; -static ssize_t adapter_show (struct device_driver *ddp,char *buf) {unsigned int devfn =0xffffffff ;
@@ -1156,35 +1149,29 @@ static DRIVER_ATTR_RW(idx_addr);static DRIVER_ATTR_RW (idx_data);static DRIVER_ATTR_RW (wqm_quanta); -static int nes_create_driver_sysfs (struct pci_driver *drv) -{ -int error; - error =driver_create_file (&drv->driver, &driver_attr_adapter); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_data); - error |=driver_create_file (&drv->driver, &driver_attr_flash_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_flash_data); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_data); - error |=driver_create_file (&drv->driver, &driver_attr_idx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_idx_data); - error |=driver_create_file (&drv->driver, &driver_attr_wqm_quanta); -return error; -} - -static void nes_remove_driver_sysfs (struct pci_driver *drv) -{ -driver_remove_file (&drv->driver, &driver_attr_adapter); -driver_remove_file (&drv->driver, &driver_attr_eeprom_cmd); -driver_remove_file (&drv->driver, &driver_attr_eeprom_data); -driver_remove_file (&drv->driver, &driver_attr_flash_cmd); -driver_remove_file (&drv->driver, &driver_attr_flash_data); -driver_remove_file (&drv->driver, &driver_attr_nonidx_addr); -driver_remove_file (&drv->driver, &driver_attr_nonidx_data); -driver_remove_file (&drv->driver, &driver_attr_idx_addr); -driver_remove_file (&drv->driver, &driver_attr_idx_data); -driver_remove_file (&drv->driver, &driver_attr_wqm_quanta); -} +static struct attribute *nes_attrs[] = { + &driver_attr_adapter, + &driver_attr_eeprom_cmd, + &driver_attr_eeprom_data, + &driver_attr_flash_cmd, + &driver_attr_flash_data, + &driver_attr_nonidx_addr, + &driver_attr_nonidx_data, + &driver_attr_idx_addr, + &driver_attr_idx_data, + &driver_attr_wqm_quanta, +NULL , +}; +ATTRIBUTE_GROUPS (nes); + +static struct pci_driver nes_pci_driver = { + .name =DRV_NAME , + .id_table = nes_pci_table, + .probe = nes_probe, + .remove = nes_remove, + .groups = nes_groups, +}; +/** * nes_init_module - module initialization entry point
@@ -1192,20 +1179,13 @@ static void nes_remove_driver_sysfs(strustatic int __init nes_init_module (void ) {int retval; -int retval1; retval =nes_cm_start ();if (retval) { printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");return retval; } - retval =pci_register_driver (&nes_pci_driver); -if (retval >=0 ) { - retval1 =nes_create_driver_sysfs (&nes_pci_driver); -if (retval1 <0 ) - printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n"); - } -return retval; +return pci_register_driver (&nes_pci_driver); }
@@ -1215,7 +1195,6 @@ static int __init nes_init_module(void) static void __exit nes_exit_module(void) {nes_cm_stop (); -nes_remove_driver_sysfs (&nes_pci_driver);pci_unregister_driver (&nes_pci_driver); }
drivers/pci/pci-driver.c +1 -0
@@ -1307,6 +1307,7 @@ int __pci_register_driver(struct pci_dri drv->driver.bus = &pci_bus_type; drv->driver.owner = owner; drv->driver.mod_name = mod_name; + drv->driver.groups = drv->groups;spin_lock_init (&drv->dynids.lock);INIT_LIST_HEAD (&drv->dynids.list);
include/linux/pci.h +1 -0
@@ -729,6 +729,7 @@ struct pci_driver {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; +const struct attribute_group **groups;struct device_driver driver;struct pci_dynids dynids; };
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Thanks!
Faisal
Quoted 158 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Wednesday, July 19, 2017 8:01 AM
To: Latif, Faisal <[email protected]>; Doug Ledford <[email protected]>; Hefty, Sean <[email protected]>; Hal Rosenstock <[email protected]>; Bjorn Helgaas <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: PCI/IB: add support for pci driver attribute groupsFrom: Greg Kroah-Hartman <[email protected]>
Some drivers (specifically the nes IB driver), want to create a lot of sysfs driver attributes. Instead of open-coding the creation and removal of these files (and getting it wrong btw), it's a better idea to let the driver core handle all of this logic for us.
So add a new field to the pci driver structure, **groups, that allows pci drivers to specify an attribute group list it wishes to have created when it is registered with the driver core.
Big bonus is now the driver doesn't race with userspace when the sysfs files are created vs. when the kobject is announced, so any script/tool that actually wanted to use these files will not have to poll waiting for them to show up.
Cc Faisal Latif <[email protected]>Cc Doug Ledford <[email protected]>Cc Sean Hefty <[email protected]>Cc Hal Rosenstock <[email protected]>Cc Bjorn Helgaas <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>---
drivers/infiniband/hw/nes/nes.c | 69 +++++++++++++--------------------------- drivers/pci/pci-driver.c | 1 include/linux/pci.h | 1 3 files changed, 26 insertions(+), 45 deletions(-)drivers/infiniband/hw/nes/nes.c +23
-34@@ -808,13 +808,6 @@ static void nes_remove(struct pci_dev *p } -static struct pci_driver nes_pci_driver = { - .name =DRV_NAME , - .id_table = nes_pci_table, - .probe = nes_probe, - .remove = nes_remove, -}; -static ssize_t adapter_show (struct device_driver *ddp,char *buf) {unsigned int devfn =0xffffffff ;@@ -1156,35 +1149,29 @@ static DRIVER_ATTR_RW(idx_addr); staticDRIVER_ATTR_RW (idx_data);static DRIVER_ATTR_RW (wqm_quanta); -static int nes_create_driver_sysfs(struct pci_driver *drv) -{ -int error; - error =driver_create_file (&drv->driver, &driver_attr_adapter); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_data); - error |=driver_create_file (&drv->driver, &driver_attr_flash_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_flash_data); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_data); - error |=driver_create_file (&drv->driver, &driver_attr_idx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_idx_data); - error |=driver_create_file (&drv->driver, &driver_attr_wqm_quanta); -return error; -} - -static void nes_remove_driver_sysfs(struct pci_driver *drv) -{ -driver_remove_file (&drv->driver, &driver_attr_adapter); -driver_remove_file (&drv->driver, &driver_attr_eeprom_cmd); -driver_remove_file (&drv->driver, &driver_attr_eeprom_data); -driver_remove_file (&drv->driver, &driver_attr_flash_cmd); -driver_remove_file (&drv->driver, &driver_attr_flash_data); -driver_remove_file (&drv->driver, &driver_attr_nonidx_addr); -driver_remove_file (&drv->driver, &driver_attr_nonidx_data); -driver_remove_file (&drv->driver, &driver_attr_idx_addr); -driver_remove_file (&drv->driver, &driver_attr_idx_data); -driver_remove_file (&drv->driver, &driver_attr_wqm_quanta); -} +static struct attribute *nes_attrs[] = { + &driver_attr_adapter, + &driver_attr_eeprom_cmd, + &driver_attr_eeprom_data, + &driver_attr_flash_cmd, + &driver_attr_flash_data, + &driver_attr_nonidx_addr, + &driver_attr_nonidx_data, + &driver_attr_idx_addr, + &driver_attr_idx_data, + &driver_attr_wqm_quanta, +NULL , +}; +ATTRIBUTE_GROUPS (nes); + +static struct pci_driver nes_pci_driver = { + .name =DRV_NAME , + .id_table = nes_pci_table, + .probe = nes_probe, + .remove = nes_remove, + .groups = nes_groups, +}; +/** * nes_init_module - module initialization entry point @@ -1192,20 +1179,13 @@ static void nes_remove_driver_sysfs(stru static int
__initnes_init_module(void) { int retval;drivers/infiniband/hw/nes/nes.c +0
-1-int retval1;retval = nes_cm_start(); if (retval) { printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n"); return retval; }drivers/infiniband/hw/nes/nes.c +0
-5- retval =pci_register_driver (&nes_pci_driver); - if (retval >= 0) { - retval1 = nes_create_driver_sysfs(&nes_pci_driver); - if (retval1 < 0) - printk(KERN_ERR PFX "Unable to create NetEffect sysfiles.\n");
drivers/infiniband/hw/nes/nes.c +1
-2- } -return retval; +return pci_register_driver (&nes_pci_driver);}
drivers/infiniband/hw/nes/nes.c +0
-1@@ -1215,7 +1195,6 @@ static int __init nes_init_module(void) static void__exit nes_exit_module (void ) {nes_cm_stop (); -nes_remove_driver_sysfs (&nes_pci_driver);pci_unregister_driver (&nes_pci_driver); }drivers/pci/pci-driver.c +1
-0@@ -1307,6 +1307,7 @@ int __pci_register_driver(struct pci_dri drv->driver.bus = &pci_bus_type; drv->driver.owner = owner; drv->driver.mod_name = mod_name; + drv->driver.groups = drv->groups;spin_lock_init (&drv->dynids.lock);INIT_LIST_HEAD (&drv->dynids.list);include/linux/pci.h +1
-0@@ -729,6 +729,7 @@ struct pci_driver {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; +const struct attribute_group **groups;struct device_driver driver;struct pci_dynids dynids; };
Bjorn Helgaas
Acked-byQuoted 16 lines · Greg KH
From: Greg Kroah-Hartman <[email protected]>
Some drivers (specifically the nes IB driver), want to create a lot of sysfs driver attributes. Instead of open-coding the creation and removal of these files (and getting it wrong btw), it's a better idea to let the driver core handle all of this logic for us.
So add a new field to the pci driver structure, **groups, that allows pci drivers to specify an attribute group list it wishes to have created when it is registered with the driver core.
Big bonus is now the driver doesn't race with userspace when the sysfs files are created vs. when the kobject is announced, so any script/tool that actually wanted to use these files will not have to poll waiting for them to show up.
Quoted 6 lines
Cc Faisal Latif <[email protected]>Cc Doug Ledford <[email protected]>Cc Sean Hefty <[email protected]>Cc Hal Rosenstock <[email protected]>Cc Bjorn Helgaas <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
If you want me to take this let me know; otherwise I'll assume Doug will merge it.
Quoted 131 lines
--- drivers/infiniband/hw/nes/nes.c | 69 +++++++++++++--------------------------- drivers/pci/pci-driver.c | 1 include/linux/pci.h | 1 3 files changed, 26 insertions(+), 45 deletions(-)drivers/infiniband/hw/nes/nes.c +24
-45@@ -808,13 +808,6 @@ static void nes_remove(struct pci_dev *p } -static struct pci_driver nes_pci_driver = { - .name =DRV_NAME , - .id_table = nes_pci_table, - .probe = nes_probe, - .remove = nes_remove, -}; -static ssize_t adapter_show (struct device_driver *ddp,char *buf) {unsigned int devfn =0xffffffff ;@@ -1156,35 +1149,29 @@ static DRIVER_ATTR_RW(idx_addr);static DRIVER_ATTR_RW (idx_data);static DRIVER_ATTR_RW (wqm_quanta); -static int nes_create_driver_sysfs (struct pci_driver *drv) -{ -int error; - error =driver_create_file (&drv->driver, &driver_attr_adapter); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_eeprom_data); - error |=driver_create_file (&drv->driver, &driver_attr_flash_cmd); - error |=driver_create_file (&drv->driver, &driver_attr_flash_data); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_nonidx_data); - error |=driver_create_file (&drv->driver, &driver_attr_idx_addr); - error |=driver_create_file (&drv->driver, &driver_attr_idx_data); - error |=driver_create_file (&drv->driver, &driver_attr_wqm_quanta); -return error; -} - -static void nes_remove_driver_sysfs (struct pci_driver *drv) -{ -driver_remove_file (&drv->driver, &driver_attr_adapter); -driver_remove_file (&drv->driver, &driver_attr_eeprom_cmd); -driver_remove_file (&drv->driver, &driver_attr_eeprom_data); -driver_remove_file (&drv->driver, &driver_attr_flash_cmd); -driver_remove_file (&drv->driver, &driver_attr_flash_data); -driver_remove_file (&drv->driver, &driver_attr_nonidx_addr); -driver_remove_file (&drv->driver, &driver_attr_nonidx_data); -driver_remove_file (&drv->driver, &driver_attr_idx_addr); -driver_remove_file (&drv->driver, &driver_attr_idx_data); -driver_remove_file (&drv->driver, &driver_attr_wqm_quanta); -} +static struct attribute *nes_attrs[] = { + &driver_attr_adapter, + &driver_attr_eeprom_cmd, + &driver_attr_eeprom_data, + &driver_attr_flash_cmd, + &driver_attr_flash_data, + &driver_attr_nonidx_addr, + &driver_attr_nonidx_data, + &driver_attr_idx_addr, + &driver_attr_idx_data, + &driver_attr_wqm_quanta, +NULL , +}; +ATTRIBUTE_GROUPS (nes); + +static struct pci_driver nes_pci_driver = { + .name =DRV_NAME , + .id_table = nes_pci_table, + .probe = nes_probe, + .remove = nes_remove, + .groups = nes_groups, +}; +/** * nes_init_module - module initialization entry point @@ -1192,20 +1179,13 @@ static void nes_remove_driver_sysfs(strustatic int __init nes_init_module (void ) {int retval; -int retval1; retval =nes_cm_start ();if (retval) { printk(KERN_ERR PFX "Unable to start NetEffect iWARP CM.\n");return retval; } - retval =pci_register_driver (&nes_pci_driver); -if (retval >=0 ) { - retval1 =nes_create_driver_sysfs (&nes_pci_driver); -if (retval1 <0 ) - printk(KERN_ERR PFX "Unable to create NetEffect sys files.\n"); - } -return retval; +return pci_register_driver (&nes_pci_driver); }@@ -1215,7 +1195,6 @@ static int __init nes_init_module(void) static void __exit nes_exit_module(void) {nes_cm_stop (); -nes_remove_driver_sysfs (&nes_pci_driver);pci_unregister_driver (&nes_pci_driver); }drivers/pci/pci-driver.c +1
-0@@ -1307,6 +1307,7 @@ int __pci_register_driver(struct pci_dri drv->driver.bus = &pci_bus_type; drv->driver.owner = owner; drv->driver.mod_name = mod_name; + drv->driver.groups = drv->groups;spin_lock_init (&drv->dynids.lock);INIT_LIST_HEAD (&drv->dynids.list);include/linux/pci.h +1
-0@@ -729,6 +729,7 @@ struct pci_driver {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; +const struct attribute_group **groups;struct device_driver driver;struct pci_dynids dynids; };
Doug Ledford
AppliedQuoted 31 lines · Bjorn Helgaas
Quoted 23 lines · Greg KH
From: Greg Kroah-Hartman <[email protected]>
Some drivers (specifically the nes IB driver), want to create a lot of
sysfs driver attributes. Instead of open-coding the creation and removal of these files (and getting it wrong btw), it's a better idea to
let the driver core handle all of this logic for us.So add a new field to the pci driver structure, **groups, that allows
pci drivers to specify an attribute group list it wishes to have created
when it is registered with the driver core.Big bonus is now the driver doesn't race with userspace when the sysfs
files are created vs. when the kobject is announced, so any script/tool
that actually wanted to use these files will not have to poll waiting
for them to show up.Quoted 6 lines
Cc Faisal Latif <[email protected]>Cc Doug Ledford <[email protected]>Cc Sean Hefty <[email protected]>Cc Hal Rosenstock <[email protected]>Cc Bjorn Helgaas <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 5 lines
Acked-by Bjorn Helgaas <[email protected]>If you want me to take this let me know; otherwise I'll assume Doug will
merge it.
I've picked it up for for-next. Thanks.
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD