cdx: provide sysfs interface for cdx device resources
Subsystems (2)
v2 cover cdx: provide sysfs interface for cdx device resources
This patch series provides sysfs interface to
- enable and disable of cdx bus
- reset for all the devices on cdx bus
- subsystem, class and revision for cdx device
Changes in v2:
- Introduce lock to protect controller ops and controller list
- Split sysfs entry enable to enable and disable
- sysfs entry enable and disable take bus number as an argument
- sysfs entry reset takes bus number as an argument
Abhijit Gangurde (4):
cdx: Introduce lock to protect controller ops and controller list
cdx: add support for bus enable and disable
cdx: add sysfs for bus reset
cdx: add sysfs for subsystem, class and revision
Documentation/ABI/testing/sysfs-bus-cdx | 87 +++++++++++++ drivers/cdx/cdx.c | 156 +++++++++++++++++++++++- drivers/cdx/cdx.h | 8 ++ drivers/cdx/controller/cdx_controller.c | 50 ++++++++ drivers/cdx/controller/mc_cdx_pcol.h | 54 ++++++++ drivers/cdx/controller/mcdi_functions.c | 31 +++++ drivers/cdx/controller/mcdi_functions.h | 18 +++ include/linux/cdx/cdx_bus.h | 39 +++++- include/linux/mod_devicetable.h | 10 ++ scripts/mod/devicetable-offsets.c | 4 + scripts/mod/file2alias.c | 8 ++ 11 files changed, 462 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/4 cdx: Introduce lock to protect controller ops and controller list
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/cdx/cdx.c +14 -0
@@ -72,6 +72,8 @@/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);/** * cdx_dev_reset - Reset a CDX device
@@ -393,6 +395,8 @@ static ssize_t rescan_store(const struct bus_type *bus,if (!val)return -EINVAL ; +mutex_lock (&cdx_controller_lock); +/* Unregister all the devices on the bus */ cdx_unregister_devices (&cdx_bus_type);
@@ -405,6 +409,8 @@ static ssize_t rescan_store(const struct bus_type *bus,dev_err (cdx->dev,"cdx bus scanning failed\n" ); } +mutex_unlock (&cdx_controller_lock); +return count; }static BUS_ATTR_WO (rescan);
@@ -520,9 +526,12 @@ int cdx_register_controller(struct cdx_controller *cdx) {int ret; +mutex_lock (&cdx_controller_lock); + ret =xa_alloc (&cdx_controllers, &cdx->id, cdx,XA_LIMIT (0 ,MAX_CDX_CONTROLLERS -1 ),GFP_KERNEL );if (ret) { +mutex_unlock (&cdx_controller_lock);dev_err (cdx->dev,"No free index available. Maximum controllers already registered\n" ); cdx->id = (u8 )MAX_CDX_CONTROLLERS ;
@@ -531,6 +540,7 @@ int cdx_register_controller(struct cdx_controller *cdx)/* Scan all the devices */ cdx->ops->scan (cdx); +mutex_unlock (&cdx_controller_lock);return 0 ; }
@@ -541,8 +551,12 @@ void cdx_unregister_controller(struct cdx_controller *cdx)if (cdx->id >=MAX_CDX_CONTROLLERS )return ; +mutex_lock (&cdx_controller_lock); +device_for_each_child (cdx->dev,NULL , cdx_unregister_device);xa_erase (&cdx_controllers, cdx->id); + +mutex_unlock (&cdx_controller_lock); }EXPORT_SYMBOL_GPL (cdx_unregister_controller);
Signature · 1 line
2.25.1
Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 13 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0
drivers/cdx/cdx.c line 76
Quoted 5 lines
drivers/cdx/cdx.c +2
-0@@ -72,6 +72,8 @@/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);
Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
thanks,
greg k-h
RE: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 24 lines
From: Greg KH <[email protected]>
Sent: Monday, July 31, 2023 5:55 PM
To: Gangurde, Abhijit <[email protected]>
Cc: [email protected]; [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Agarwal, Nikhil <[email protected]>; Gupta, Nipun <[email protected]>
Subject: Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller listQuoted 14 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0@@ -72,6 +72,8 @@
Quoted 9 lines
drivers/cdx/cdx.c line 76
Quoted 4 lines
drivers/cdx/cdx.c +2
-0/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
cdx_controllers list is holding just the controllers registered on the cdx bus system. CDX devices are still maintained by driver core list. Controller list is used by rescan which triggers rescan on all the controllers.
Thanks,
Abhijit
Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 34 lines · Abhijit
Quoted 24 lines
From: Greg KH <[email protected]>
Sent: Monday, July 31, 2023 5:55 PM
To: Gangurde, Abhijit <[email protected]>
Cc: [email protected]; [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Agarwal, Nikhil <[email protected]>; Gupta, Nipun <[email protected]>
Subject: Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller listQuoted 14 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0@@ -72,6 +72,8 @@Quoted 9 lines
drivers/cdx/cdx.c line 76
Quoted 4 lines
drivers/cdx/cdx.c +2
-0/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
Quoted 1 line
cdx_controllerslist is holding just the controllers registered on the cdx bus system.
Which are devices on the bus, so why do you need a separate list?
Quoted 2 lines
CDX devices are still maintained by driver core list. Controller list is used by rescan which triggers rescan on all the controllers.
Again, why a separate list? The driver core already tracks these, right?
thanks,
greg k-h
RE: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 39 lines
Quoted 5 lines
Quoted 5 lines
From: Greg KH <[email protected]>
Sent: Monday, July 31, 2023 5:55 PM
To: Gangurde, Abhijit <[email protected]>
Cc: [email protected]; [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Agarwal,Nikhil
Quoted 2 lines
Quoted 2 lines
<[email protected]>; Gupta, Nipun <[email protected]>
Subject: Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller opsand
Quoted 27 lines
Quoted 17 lines
controller list
Quoted 14 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0@@ -72,6 +72,8 @@Quoted 9 lines
drivers/cdx/cdx.c line 76
Quoted 4 lines
drivers/cdx/cdx.c +2
-0/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
Quoted 1 line
cdx_controllerslist is holding just the controllers registered on the cdx bussystem.
Quoted 8 lines
Which are devices on the bus, so why do you need a separate list?
Quoted 1 line
CDX devices are still maintained by driver core list. Controller list is used by
rescan
Quoted 1 line
which triggers rescan on all the controllers.
Again, why a separate list? The driver core already tracks these, right?
As of now, cdx controllers are platform devices and maintained on cdx_controllers list. CDX controller devices are not added on cdx bus. IIUC, you mean to use driver core list to find out different cdx controllers, in that case cdx bus would need to scan platform bus and access the private data of platform device to get a cdx_controller ops. IMHO, that would not be a right approach.
Or as an alternative cdx controller could be added on cdx bus as well. And we can then get these controllers from driver core list.
Thanks,
Abhijit
Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 41 lines · Abhijit
Quoted 41 lines
Quoted 5 lines
Quoted 5 lines
From: Greg KH <[email protected]>
Sent: Monday, July 31, 2023 5:55 PM
To: Gangurde, Abhijit <[email protected]>
Cc: [email protected]; [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Agarwal,Nikhil
Quoted 2 lines
Quoted 2 lines
<[email protected]>; Gupta, Nipun <[email protected]>
Subject: Re: [PATCH v2 1/4] cdx: Introduce lock to protect controller opsand
Quoted 27 lines
Quoted 17 lines
controller list
Quoted 14 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0@@ -72,6 +72,8 @@Quoted 9 lines
drivers/cdx/cdx.c line 76
Quoted 4 lines
drivers/cdx/cdx.c +2
-0/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
Quoted 1 line
cdx_controllerslist is holding just the controllers registered on the cdx bussystem.
Which are devices on the bus, so why do you need a separate list?
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
CDX devices are still maintained by driver core list. Controller list is used by
rescan
Quoted 1 line
which triggers rescan on all the controllers.
Again, why a separate list? The driver core already tracks these, right?
As of now, cdx controllers are platform devices and maintained on
cdx_controllerslist.
Oh, that's not ok. Please do NOT abuse platform devices for things that are not actually platform devices. Make them real devices on a real bus.
Quoted 4 lines
CDX controller devices are not added on cdx bus. IIUC, you mean to use driver core list to find out different cdx controllers, in that case cdx bus would need to scan platform bus and access the private data of platform device to get a
cdx_controllerops. IMHO, that would not be a right approach.
If these are actually real patform devices, then yes, that's the correct thing to do.
Or you can create a cdx controller device and add that to the device tree, that's usually the way "controller" devices work (look at USB host controllers as one example.)
Quoted 2 lines
Or as an alternative cdx controller could be added on cdx bus as well. And we can then get these controllers from driver core list.
Yes, that can work too, but don't keep them outside of the driver model, that will not work well over time, as you can see here already.
thanks,
greg k-h
RE: [PATCH v2 1/4] cdx: Introduce lock to protect controller ops and controller list
Quoted 64 lines · Abhijit
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
From: Greg KH <[email protected]>
Sent: Monday, July 31, 2023 5:55 PM
To: Gangurde, Abhijit <[email protected]>
Cc: [email protected]; [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Agarwal,Nikhil
Quoted 2 lines
Quoted 2 lines
<[email protected]>; Gupta, Nipun <[email protected]>
Subject: Re: [PATCH v2 1/4] cdx: Introduce lock to protect controllerops
Quoted 28 lines
Quoted 28 lines
and
Quoted 27 lines
Quoted 26 lines
controller list
Quoted 13 lines · Abhijit Gangurde
Add a mutex lock to prevent race between controller ops initiated by the bus subsystem and the controller registration/unregistration.
Signed-off-by Abhijit Gangurde <[email protected]>--- drivers/cdx/cdx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/cdx/cdx.c +0
-0drivers/cdx/cdx.c line 76
Quoted 5 lines
drivers/cdx/cdx.c +2
-0@@ -72,6 +72,8 @@/* CDX controllers registered with the CDX bus */ static DEFINE_XARRAY_ALLOC (cdx_controllers); +/* Lock to protect controller ops and controller list */ +static DEFINE_MUTEX (cdx_controller_lock);Wait, why do you have a local list and not just rely on the list the driver core has for you already? Isn't this a duplicate list where you have objects on two different lists with a lifespan controlled only by one of them?
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
cdx_controllerslist is holding just the controllers registered on the cdx bussystem.
Which are devices on the bus, so why do you need a separate list?
Quoted 1 line
CDX devices are still maintained by driver core list. Controller list is used
by
Quoted 7 lines
Quoted 5 lines
rescan
Quoted 1 line
which triggers rescan on all the controllers.
Again, why a separate list? The driver core already tracks these, right?
As of now, cdx controllers are platform devices and maintained on
cdx_controllerslist.Oh, that's not ok. Please do NOT abuse platform devices for things that are not actually platform devices. Make them real devices on a real bus.
Quoted 1 line
CDX controller devices are not added on cdx bus. IIUC, you mean to use
driver core
Quoted 1 line
list to find out different cdx controllers, in that case cdx bus would need to
scan
Quoted 1 line
platform bus and access the private data of platform device to get a
cdx_controllerops.
Quoted 8 lines
Quoted 1 line
IMHO, that would not be a right approach.
If these are actually real patform devices, then yes, that's the correct thing to do.
Or you can create a cdx controller device and add that to the device tree, that's usually the way "controller" devices work (look at USB host controllers as one example.)
Thank you for the suggestion. CDX controller is already in the device tree as a platform device. We are weighing both the options right now and would send the changes accordingly in next spin.
Thanks,
Abhijit
Quoted 11 lines
Quoted 2 lines
Or as an alternative cdx controller could be added on cdx bus as well. And we
can then
Quoted 1 line
get these controllers from driver core list.
Yes, that can work too, but don't keep them outside of the driver model, that will not work well over time, as you can see here already.
thanks,
greg k-h
PATCH v2 2/4 cdx: add support for bus enable and disable
In reply to Abhijit GangurdeCDX bus needs to be disabled before updating/writing devices in the FPGA. Once the devices are written, the bus shall be rescanned. This change provides sysfs entry to enable/disable the CDX bus.
--- Documentation/ABI/testing/sysfs-bus-cdx | 27 ++++++++++ drivers/cdx/cdx.c | 72 +++++++++++++++++++++++++ drivers/cdx/controller/cdx_controller.c | 50 +++++++++++++++++ drivers/cdx/controller/mc_cdx_pcol.h | 54 +++++++++++++++++++ drivers/cdx/controller/mcdi_functions.c | 24 +++++++++ drivers/cdx/controller/mcdi_functions.h | 18 +++++++ include/linux/cdx/cdx_bus.h | 12 +++++ 7 files changed, 257 insertions(+)
Documentation/ABI/testing/sysfs-bus-cdx +27 -0
@@ -11,6 +11,33 @@ Description: # echo 1 > /sys/bus/cdx/rescan +What: /sys/bus/cdx/enable +Date: July 2023 +Contact: [email protected] +Description: + Writing bus number in hex to this file will attempt to enable + the CDX bus. The bus number for the cdx devices can be found + at /sys/bus/cdx/devices/cdx-BB:DD, where BB denotes the bus + number for the respective device. + + For example :: + + # echo 00 > /sys/bus/cdx/enable + +What: /sys/bus/cdx/disable +Date: July 2023 +Contact: [email protected] +Description: + Writing bus number in hex to this file will attempt to disable + the CDX bus. CDX bus should be disabled before updating the + devices in FPGA. The bus number for the cdx devices can be + found at /sys/bus/cdx/devices/cdx-BB:DD, where BB denotes the + bus number for the respective device. + + For example :: + + # echo 00 > /sys/bus/cdx/disable + What: /sys/bus/cdx/devices/.../vendor Date: March 2023 Contact: [email protected]
drivers/cdx/cdx.c +72 -0
90 lines not on this page · raw message
drivers/cdx/controller/cdx_controller.c +50 -0
79 lines not on this page · raw message
drivers/cdx/controller/mc_cdx_pcol.h +54 -0
60 lines not on this page · raw message
drivers/cdx/controller/mcdi_functions.c +24 -0
@@ -124,6 +124,30 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx,return 0 ; } +int cdx_mcdi_bus_enable (struct cdx_mcdi *cdx,u8 bus_num) +{ +MCDI_DECLARE_BUF (inbuf,MC_CMD_CDX_BUS_UP_IN_LEN ); +int ret; + +MCDI_SET_DWORD (inbuf,CDX_BUS_UP_IN_BUS , bus_num); + ret =cdx_mcdi_rpc (cdx,MC_CMD_CDX_BUS_UP , inbuf,sizeof (inbuf), +NULL ,0 ,NULL ); + +return ret; +} + +int cdx_mcdi_bus_disable (struct cdx_mcdi *cdx,u8 bus_num) +{ +MCDI_DECLARE_BUF (inbuf,MC_CMD_CDX_BUS_DOWN_IN_LEN ); +int ret; + +MCDI_SET_DWORD (inbuf,CDX_BUS_DOWN_IN_BUS , bus_num); + ret =cdx_mcdi_rpc (cdx,MC_CMD_CDX_BUS_DOWN , inbuf,sizeof (inbuf), +NULL ,0 ,NULL ); + +return ret; +} +int cdx_mcdi_reset_device (struct cdx_mcdi *cdx,u8 bus_num,u8 dev_num) {MCDI_DECLARE_BUF (inbuf,MC_CMD_CDX_DEVICE_RESET_IN_LEN );
drivers/cdx/controller/mcdi_functions.h +18 -0
@@ -47,6 +47,24 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx, u8 bus_num, u8 dev_num, struct cdx_dev_params *dev_params); +/** +* cdx_mcdi_bus_enable - Enable CDX bus represented by bus_num +* @cdx: pointer to MCDI interface. +* @bus_num: Bus number. +* +* Return: 0 on success, <0 on failure +*/ +int cdx_mcdi_bus_enable (struct cdx_mcdi *cdx,u8 bus_num); + +/** +* cdx_mcdi_bus_disable - Disable CDX bus represented by bus_num +* @cdx: pointer to MCDI interface. +* @bus_num: Bus number. +* +* Return: 0 on success, <0 on failure +*/ +int cdx_mcdi_bus_disable (struct cdx_mcdi *cdx,u8 bus_num); +/** * cdx_mcdi_reset_device - Reset cdx device represented by bus_num:dev_num * @cdx: pointer to MCDI interface.
include/linux/cdx/cdx_bus.h +12 -0
@@ -16,6 +16,8 @@#define MAX_CDX_DEV_RESOURCES 4#define CDX_CONTROLLER_ID_SHIFT 4#define CDX_BUS_NUM_MASK 0xF +#define CDX_CONTROLLER_ID_MASK 0xF0 +#define MAX_CDX_BUSES (CDX_BUS_NUM_MASK + 1)/* Forward declaration for CDX controller */ struct cdx_controller ;
@@ -28,6 +30,10 @@ struct cdx_device_config {u8 type; }; +typedef int (*cdx_bus_enable_cb )(struct cdx_controller *cdx,u8 bus_num); + +typedef int (*cdx_bus_disable_cb )(struct cdx_controller *cdx,u8 bus_num); +typedef int (*cdx_scan_cb )(struct cdx_controller *cdx); typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,
@@ -49,11 +55,15 @@ typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,/** * struct cdx_ops - Callbacks supported by CDX controller. +* @bus_enable: enable bus on the controller +* @bus_disable: disable bus on the controller * @scan: scan the devices on the controller * @dev_configure: configuration like reset, master_enable, * msi_config etc for a CDX device */ struct cdx_ops { +cdx_bus_enable_cb bus_enable; +cdx_bus_disable_cb bus_disable;cdx_scan_cb scan;cdx_dev_configure_cb dev_configure; };
@@ -63,12 +73,14 @@ struct cdx_ops {* @dev: Linux device associated with the CDX controller. * @priv: private data * @id: Controller ID +* @bus_state: state of the buses(enabled/disabled) * @ops: CDX controller ops */ struct cdx_controller {struct device *dev;void *priv;u32 id; + DECLARE_BITMAP(bus_state, MAX_CDX_BUSES);struct cdx_ops *ops; };
Signature · 1 line
2.25.1
PATCH v2 3/4 cdx: add sysfs for bus reset
In reply to Abhijit GangurdeAdd sysfs interface reset to reset all the devices on the CDX bus.
--- Documentation/ABI/testing/sysfs-bus-cdx | 15 +++++++++ drivers/cdx/cdx.c | 41 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
Documentation/ABI/testing/sysfs-bus-cdx +15 -0
@@ -38,6 +38,21 @@ Description: # echo 00 > /sys/bus/cdx/disable +What: /sys/bus/cdx/reset +Date: July 2023 +Contact: [email protected] +Description: + Writing bus number in hex to this file will attempt to reset + all the devices present on the bus. Resetting a device would + clear all existing configuration of the device and put the + device in default state. The bus number for the cdx devices can + be found at /sys/bus/cdx/devices/cdx-BB:DD, where BB denotes + the bus number for the respective device. + + For example :: + + # echo 00 > /sys/bus/cdx/reset + What: /sys/bus/cdx/devices/.../vendor Date: March 2023 Contact: [email protected]
drivers/cdx/cdx.c +41 -0
57 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 4/4 cdx: add sysfs for subsystem, class and revision
In reply to Abhijit GangurdeCDX controller provides subsystem vendor, subsystem device, class and revision info of the device along with vendor and device ID in native endian format. CDX Bus system uses this information to bind the cdx device to the cdx device driver.
--- Documentation/ABI/testing/sysfs-bus-cdx | 45 +++++++++++++++++++++++++ drivers/cdx/cdx.c | 29 +++++++++++++++- drivers/cdx/cdx.h | 8 +++++ drivers/cdx/controller/mcdi_functions.c | 7 ++++ include/linux/cdx/cdx_bus.h | 27 +++++++++++++-- include/linux/mod_devicetable.h | 10 ++++++ scripts/mod/devicetable-offsets.c | 4 +++ scripts/mod/file2alias.c | 8 +++++ 8 files changed, 135 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-bus-cdx +45 -0
@@ -70,6 +70,36 @@ Description: of a device manufacturer. Combination of Vendor ID and Device ID identifies a device. +What: /sys/bus/cdx/devices/.../subsystem_vendor +Date: July 2023 +Contact: [email protected] +Description: + Subsystem Vendor ID for this CDX device, in hexadecimal. + Subsystem Vendor ID is 16 bit identifier specific to the + card manufacturer. + +What: /sys/bus/cdx/devices/.../subsystem_device +Date: July 2023 +Contact: [email protected] +Description: + Subsystem Device ID for this CDX device, in hexadecimal + Subsystem Device ID is 16 bit identifier specific to the + card manufacturer. + +What: /sys/bus/cdx/devices/.../class +Date: July 2023 +Contact: [email protected] +Description: + This file contains the class of the CDX device, in hexadecimal. + Class is 24 bit identifier specifies the functionality of the device. + +What: /sys/bus/cdx/devices/.../revision +Date: July 2023 +Contact: [email protected] +Description: + This file contains the revision field of the CDX device, in hexadecimal. + Revision is 8 bit revision identifier of the device. + What: /sys/bus/cdx/devices/.../reset Date: March 2023 Contact: [email protected]
@@ -96,3 +126,18 @@ Description: For example:: # echo 1 > /sys/bus/cdx/devices/.../remove + +What: /sys/bus/cdx/devices/.../modalias +Date: July 2023 +Contact: [email protected] +Description: + This attribute indicates the CDX ID of the device. + That is in the format: + cdx:vXXXXdXXXXsvXXXXsdXXXXcXXXXXX, + where: + + - vXXXX contains the vendor ID; + - dXXXX contains the device ID; + - svXXXX contains the subsystem vendor ID; + - sdXXXX contains the subsystem device ID; + - cXXXXXX contains the device class.
drivers/cdx/cdx.c +28 -1
@@ -179,7 +179,10 @@ cdx_match_one_device(const struct cdx_device_id *id, {/* Use vendor ID and device ID for matching */ if ((id->vendor ==CDX_ANY_ID || id->vendor == dev->vendor) && - (id->device ==CDX_ANY_ID || id->device == dev->device)) + (id->device ==CDX_ANY_ID || id->device == dev->device) && + (id->subvendor ==CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) && + (id->subdevice ==CDX_ANY_ID || id->subdevice == dev->subsystem_device) && + !((id->class ^ dev->class) & id->class_mask))return id;return NULL ; }
@@ -325,6 +328,10 @@ static DEVICE_ATTR_RO(field)cdx_config_attr (vendor,"0x%04x\n" );cdx_config_attr (device,"0x%04x\n" ); +cdx_config_attr (subsystem_vendor,"0x%04x\n" ); +cdx_config_attr (subsystem_device,"0x%04x\n" ); +cdx_config_attr (revision,"0x%02x\n" ); +cdx_config_attr (class,"0x%06x\n" ); static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
@@ -370,6 +377,17 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_WO (reset); +static ssize_t modalias_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct cdx_device *cdx_dev =to_cdx_device (dev); + +return sprintf (buf,"cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n" , cdx_dev->vendor, + cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device, + cdx_dev->class); +} +static DEVICE_ATTR_RO (modalias); +static ssize_t driver_override_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -401,6 +419,11 @@ static struct attribute *cdx_dev_attrs[] = { &dev_attr_reset.attr, &dev_attr_vendor.attr, &dev_attr_device.attr, + &dev_attr_subsystem_vendor.attr, + &dev_attr_subsystem_device.attr, + &dev_attr_class.attr, + &dev_attr_revision.attr, + &dev_attr_modalias.attr, &dev_attr_driver_override.attr, NULL, };
@@ -599,6 +622,10 @@ int cdx_device_add(struct cdx_dev_params *dev_params) cdx_dev->req_id = dev_params->req_id; cdx_dev->vendor = dev_params->vendor; cdx_dev->device = dev_params->device; + cdx_dev->subsystem_vendor = dev_params->subsys_vendor; + cdx_dev->subsystem_device = dev_params->subsys_device; + cdx_dev->class = dev_params->class; + cdx_dev->revision = dev_params->revision; cdx_dev->bus_num = dev_params->bus_num; cdx_dev->dev_num = dev_params->dev_num; cdx_dev->cdx = dev_params->cdx;
drivers/cdx/cdx.h +8 -0
@@ -16,21 +16,29 @@* @parent: Associated CDX controller * @vendor: Vendor ID for CDX device * @device: Device ID for CDX device +* @subsys_vendor: Sub vendor ID for CDX device +* @subsys_device: Sub device ID for CDX device * @bus_num: Bus number for this CDX device * @dev_num: Device number for this device * @res: array of MMIO region entries * @res_count: number of valid MMIO regions * @req_id: Requestor ID associated with CDX device +* @class: Class of the CDX Device +* @revision: Revision of the CDX device */ struct cdx_dev_params {struct cdx_controller *cdx;u16 vendor;u16 device; +u16 subsys_vendor; +u16 subsys_device;u8 bus_num;u8 dev_num;struct resource res[MAX_CDX_DEV_RESOURCES ];u8 res_count;u32 req_id; +u32 class; +u8 revision; };/**
drivers/cdx/controller/mcdi_functions.c +7 -0
@@ -120,6 +120,13 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx, dev_params->vendor =MCDI_WORD (outbuf,CDX_BUS_GET_DEVICE_CONFIG_OUT_VENDOR_ID ); dev_params->device =MCDI_WORD (outbuf,CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_ID ); + dev_params->subsys_vendor =MCDI_WORD (outbuf, +CDX_BUS_GET_DEVICE_CONFIG_OUT_SUBSYS_VENDOR_ID ); + dev_params->subsys_device =MCDI_WORD (outbuf, +CDX_BUS_GET_DEVICE_CONFIG_OUT_SUBSYS_DEVICE_ID ); + dev_params->class =MCDI_DWORD (outbuf, +CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_CLASS ) &0xFFFFFF ; + dev_params->revision =MCDI_BYTE (outbuf,CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_REVISION );return 0 ; }
include/linux/cdx/cdx_bus.h +25 -2
@@ -40,6 +40,19 @@ typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx, u8 bus_num, u8 dev_num, struct cdx_device_config *dev_config); +/** +* CDX_DEVICE - macro used to describe a specific CDX device +* @vend: the 16 bit CDX Vendor ID +* @dev: the 16 bit CDX Device ID +* +* This macro is used to create a struct cdx_device_id that matches a +* specific device. The subvendor and subdevice fields will be set to +* CDX_ANY_ID. +*/ +#define CDX_DEVICE (vend, dev) \ + .vendor = (vend), .device = (dev), \ + .subvendor = CDX_ANY_ID, .subdevice = CDX_ANY_ID +/** * CDX_DEVICE_DRIVER_OVERRIDE - macro used to describe a CDX device with * override_only flags.
@@ -48,10 +61,12 @@ typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,* @driver_override: the 32 bit CDX Device override_only * * This macro is used to create a struct cdx_device_id that matches only a -* driver_override device. +* driver_override device. The subvendor and subdevice fields will be set to +* CDX_ANY_ID. */ #define CDX_DEVICE_DRIVER_OVERRIDE (vend, dev, driver_override) \ - .vendor = (vend), .device = (dev), .override_only = (driver_override) + .vendor = (vend), .device = (dev), .subvendor = CDX_ANY_ID,\ + .subdevice = CDX_ANY_ID, .override_only = (driver_override)/** * struct cdx_ops - Callbacks supported by CDX controller.
@@ -90,6 +105,10 @@ struct cdx_controller {* @cdx: CDX controller associated with the device * @vendor: Vendor ID for CDX device * @device: Device ID for CDX device +* @subsystem_vendor: Subsystem Vendor ID for CDX device +* @subsystem_device: Subsystem Device ID for CDX device +* @class: Class for the CDX device +* @revision: Revision of the CDX device * @bus_num: Bus number for this CDX device * @dev_num: Device number for this device * @res: array of MMIO region entries
@@ -107,6 +126,10 @@ struct cdx_device {struct cdx_controller *cdx;u16 vendor;u16 device; +u16 subsystem_vendor; +u16 subsystem_device; +u32 class; +u8 revision;u8 bus_num;u8 dev_num;struct resource res[MAX_CDX_DEV_RESOURCES ];
include/linux/mod_devicetable.h +10 -0
@@ -935,6 +935,12 @@ enum {* struct cdx_device_id - CDX device identifier * @vendor: Vendor ID * @device: Device ID +* @subvendor: Subsystem vendor ID (or CDX_ANY_ID) +* @subdevice: Subsystem device ID (or CDX_ANY_ID) +* @class: Device class +* Most drivers do not need to specify class/class_mask +* as vendor/device is normally sufficient. +* @class_mask: Limit which sub-fields of the class field are compared. * @override_only: Match only when dev->driver_override is this driver. * * Type of entries in the "device Id" table for CDX devices supported by
@@ -943,6 +949,10 @@ enum {struct cdx_device_id {__u16 vendor;__u16 device; +__u16 subvendor; +__u16 subdevice; +__u32 class; +__u32 class_mask;__u32 override_only; };
scripts/mod/devicetable-offsets.c +4 -0
@@ -265,6 +265,10 @@ int main(void)DEVID (cdx_device_id);DEVID_FIELD (cdx_device_id, vendor);DEVID_FIELD (cdx_device_id, device); +DEVID_FIELD (cdx_device_id, subvendor); +DEVID_FIELD (cdx_device_id, subdevice); +DEVID_FIELD (cdx_device_id, class); +DEVID_FIELD (cdx_device_id, class_mask);DEVID_FIELD (cdx_device_id, override_only);return 0 ;
scripts/mod/file2alias.c +8 -0
@@ -1458,6 +1458,10 @@ static int do_cdx_entry(const char *filename, void *symval, {DEF_FIELD (symval, cdx_device_id, vendor);DEF_FIELD (symval, cdx_device_id, device); +DEF_FIELD (symval, cdx_device_id, subvendor); +DEF_FIELD (symval, cdx_device_id, subdevice); +DEF_FIELD (symval, cdx_device_id, class); +DEF_FIELD (symval, cdx_device_id, class_mask);DEF_FIELD (symval, cdx_device_id, override_only);switch (override_only) {
@@ -1475,6 +1479,10 @@ static int do_cdx_entry(const char *filename, void *symval,ADD (alias,"v" , vendor !=CDX_ANY_ID , vendor);ADD (alias,"d" , device !=CDX_ANY_ID , device); +ADD (alias,"sv" , subvendor !=CDX_ANY_ID , subvendor); +ADD (alias,"sd" , subdevice !=CDX_ANY_ID , subdevice); +ADD (alias,"c" , class_mask ==0xFFFFFF , class); +return 1 ; }
Signature · 1 line
2.25.1