Skip to content

Commit fa10f41

Browse files
abhijitG-xlnxgregkh
authored andcommitted
cdx: add sysfs for subsystem, class and revision
CDX 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. Co-developed-by: Puneet Gupta <puneet.gupta@amd.com> Signed-off-by: Puneet Gupta <puneet.gupta@amd.com> Co-developed-by: Nipun Gupta <nipun.gupta@amd.com> Signed-off-by: Nipun Gupta <nipun.gupta@amd.com> Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com> Reviewed-by: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com> Tested-by: Nikhil Agarwal <nikhil.agarwal@amd.com> Link: https://lore.kernel.org/r/20231017160505.10640-8-abhijit.gangurde@amd.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0174f58 commit fa10f41

File tree

8 files changed

+135
-3
lines changed

8 files changed

+135
-3
lines changed

Documentation/ABI/testing/sysfs-bus-cdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ Description:
2828
of a device manufacturer.
2929
Combination of Vendor ID and Device ID identifies a device.
3030

31+
What: /sys/bus/cdx/devices/.../subsystem_vendor
32+
Date: July 2023
33+
Contact: puneet.gupta@amd.com
34+
Description:
35+
Subsystem Vendor ID for this CDX device, in hexadecimal.
36+
Subsystem Vendor ID is 16 bit identifier specific to the
37+
card manufacturer.
38+
39+
What: /sys/bus/cdx/devices/.../subsystem_device
40+
Date: July 2023
41+
Contact: puneet.gupta@amd.com
42+
Description:
43+
Subsystem Device ID for this CDX device, in hexadecimal
44+
Subsystem Device ID is 16 bit identifier specific to the
45+
card manufacturer.
46+
47+
What: /sys/bus/cdx/devices/.../class
48+
Date: July 2023
49+
Contact: puneet.gupta@amd.com
50+
Description:
51+
This file contains the class of the CDX device, in hexadecimal.
52+
Class is 24 bit identifier specifies the functionality of the device.
53+
54+
What: /sys/bus/cdx/devices/.../revision
55+
Date: July 2023
56+
Contact: puneet.gupta@amd.com
57+
Description:
58+
This file contains the revision field of the CDX device, in hexadecimal.
59+
Revision is 8 bit revision identifier of the device.
60+
3161
What: /sys/bus/cdx/devices/.../enable
3262
Date: October 2023
3363
Contact: abhijit.gangurde@amd.com
@@ -67,3 +97,18 @@ Description:
6797
For example::
6898

6999
# echo 1 > /sys/bus/cdx/devices/.../remove
100+
101+
What: /sys/bus/cdx/devices/.../modalias
102+
Date: July 2023
103+
Contact: nipun.gupta@amd.com
104+
Description:
105+
This attribute indicates the CDX ID of the device.
106+
That is in the format:
107+
cdx:vXXXXdXXXXsvXXXXsdXXXXcXXXXXX,
108+
where:
109+
110+
- vXXXX contains the vendor ID;
111+
- dXXXX contains the device ID;
112+
- svXXXX contains the subsystem vendor ID;
113+
- sdXXXX contains the subsystem device ID;
114+
- cXXXXXX contains the device class.

drivers/cdx/cdx.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ cdx_match_one_device(const struct cdx_device_id *id,
179179
{
180180
/* Use vendor ID and device ID for matching */
181181
if ((id->vendor == CDX_ANY_ID || id->vendor == dev->vendor) &&
182-
(id->device == CDX_ANY_ID || id->device == dev->device))
182+
(id->device == CDX_ANY_ID || id->device == dev->device) &&
183+
(id->subvendor == CDX_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
184+
(id->subdevice == CDX_ANY_ID || id->subdevice == dev->subsystem_device) &&
185+
!((id->class ^ dev->class) & id->class_mask))
183186
return id;
184187
return NULL;
185188
}
@@ -329,6 +332,10 @@ static DEVICE_ATTR_RO(field)
329332

330333
cdx_config_attr(vendor, "0x%04x\n");
331334
cdx_config_attr(device, "0x%04x\n");
335+
cdx_config_attr(subsystem_vendor, "0x%04x\n");
336+
cdx_config_attr(subsystem_device, "0x%04x\n");
337+
cdx_config_attr(revision, "0x%02x\n");
338+
cdx_config_attr(class, "0x%06x\n");
332339

333340
static ssize_t remove_store(struct device *dev,
334341
struct device_attribute *attr,
@@ -377,6 +384,17 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
377384
}
378385
static DEVICE_ATTR_WO(reset);
379386

387+
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
388+
char *buf)
389+
{
390+
struct cdx_device *cdx_dev = to_cdx_device(dev);
391+
392+
return sprintf(buf, "cdx:v%04Xd%04Xsv%04Xsd%04Xc%06X\n", cdx_dev->vendor,
393+
cdx_dev->device, cdx_dev->subsystem_vendor, cdx_dev->subsystem_device,
394+
cdx_dev->class);
395+
}
396+
static DEVICE_ATTR_RO(modalias);
397+
380398
static ssize_t driver_override_store(struct device *dev,
381399
struct device_attribute *attr,
382400
const char *buf, size_t count)
@@ -467,6 +485,11 @@ static struct attribute *cdx_dev_attrs[] = {
467485
&dev_attr_reset.attr,
468486
&dev_attr_vendor.attr,
469487
&dev_attr_device.attr,
488+
&dev_attr_subsystem_vendor.attr,
489+
&dev_attr_subsystem_device.attr,
490+
&dev_attr_class.attr,
491+
&dev_attr_revision.attr,
492+
&dev_attr_modalias.attr,
470493
&dev_attr_driver_override.attr,
471494
NULL,
472495
};
@@ -604,6 +627,10 @@ int cdx_device_add(struct cdx_dev_params *dev_params)
604627
cdx_dev->req_id = dev_params->req_id;
605628
cdx_dev->vendor = dev_params->vendor;
606629
cdx_dev->device = dev_params->device;
630+
cdx_dev->subsystem_vendor = dev_params->subsys_vendor;
631+
cdx_dev->subsystem_device = dev_params->subsys_device;
632+
cdx_dev->class = dev_params->class;
633+
cdx_dev->revision = dev_params->revision;
607634
cdx_dev->bus_num = dev_params->bus_num;
608635
cdx_dev->dev_num = dev_params->dev_num;
609636
cdx_dev->cdx = dev_params->cdx;

drivers/cdx/cdx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@
1616
* @parent: Associated CDX Bus device
1717
* @vendor: Vendor ID for CDX device
1818
* @device: Device ID for CDX device
19+
* @subsys_vendor: Sub vendor ID for CDX device
20+
* @subsys_device: Sub device ID for CDX device
1921
* @bus_num: Bus number for this CDX device
2022
* @dev_num: Device number for this device
2123
* @res: array of MMIO region entries
2224
* @res_count: number of valid MMIO regions
2325
* @req_id: Requestor ID associated with CDX device
26+
* @class: Class of the CDX Device
27+
* @revision: Revision of the CDX device
2428
*/
2529
struct cdx_dev_params {
2630
struct cdx_controller *cdx;
2731
struct device *parent;
2832
u16 vendor;
2933
u16 device;
34+
u16 subsys_vendor;
35+
u16 subsys_device;
3036
u8 bus_num;
3137
u8 dev_num;
3238
struct resource res[MAX_CDX_DEV_RESOURCES];
3339
u8 res_count;
3440
u32 req_id;
41+
u32 class;
42+
u8 revision;
3543
};
3644

3745
/**

drivers/cdx/controller/mcdi_functions.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx,
120120

121121
dev_params->vendor = MCDI_WORD(outbuf, CDX_BUS_GET_DEVICE_CONFIG_OUT_VENDOR_ID);
122122
dev_params->device = MCDI_WORD(outbuf, CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_ID);
123+
dev_params->subsys_vendor = MCDI_WORD(outbuf,
124+
CDX_BUS_GET_DEVICE_CONFIG_OUT_SUBSYS_VENDOR_ID);
125+
dev_params->subsys_device = MCDI_WORD(outbuf,
126+
CDX_BUS_GET_DEVICE_CONFIG_OUT_SUBSYS_DEVICE_ID);
127+
dev_params->class = MCDI_DWORD(outbuf,
128+
CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_CLASS) & 0xFFFFFF;
129+
dev_params->revision = MCDI_BYTE(outbuf, CDX_BUS_GET_DEVICE_CONFIG_OUT_DEVICE_REVISION);
123130

124131
return 0;
125132
}

include/linux/cdx/cdx_bus.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,
3838
u8 bus_num, u8 dev_num,
3939
struct cdx_device_config *dev_config);
4040

41+
/**
42+
* CDX_DEVICE - macro used to describe a specific CDX device
43+
* @vend: the 16 bit CDX Vendor ID
44+
* @dev: the 16 bit CDX Device ID
45+
*
46+
* This macro is used to create a struct cdx_device_id that matches a
47+
* specific device. The subvendor and subdevice fields will be set to
48+
* CDX_ANY_ID.
49+
*/
50+
#define CDX_DEVICE(vend, dev) \
51+
.vendor = (vend), .device = (dev), \
52+
.subvendor = CDX_ANY_ID, .subdevice = CDX_ANY_ID
53+
4154
/**
4255
* CDX_DEVICE_DRIVER_OVERRIDE - macro used to describe a CDX device with
4356
* override_only flags.
@@ -46,10 +59,12 @@ typedef int (*cdx_dev_configure_cb)(struct cdx_controller *cdx,
4659
* @driver_override: the 32 bit CDX Device override_only
4760
*
4861
* This macro is used to create a struct cdx_device_id that matches only a
49-
* driver_override device.
62+
* driver_override device. The subvendor and subdevice fields will be set to
63+
* CDX_ANY_ID.
5064
*/
5165
#define CDX_DEVICE_DRIVER_OVERRIDE(vend, dev, driver_override) \
52-
.vendor = (vend), .device = (dev), .override_only = (driver_override)
66+
.vendor = (vend), .device = (dev), .subvendor = CDX_ANY_ID,\
67+
.subdevice = CDX_ANY_ID, .override_only = (driver_override)
5368

5469
/**
5570
* struct cdx_ops - Callbacks supported by CDX controller.
@@ -88,6 +103,10 @@ struct cdx_controller {
88103
* @cdx: CDX controller associated with the device
89104
* @vendor: Vendor ID for CDX device
90105
* @device: Device ID for CDX device
106+
* @subsystem_vendor: Subsystem Vendor ID for CDX device
107+
* @subsystem_device: Subsystem Device ID for CDX device
108+
* @class: Class for the CDX device
109+
* @revision: Revision of the CDX device
91110
* @bus_num: Bus number for this CDX device
92111
* @dev_num: Device number for this device
93112
* @res: array of MMIO region entries
@@ -107,6 +126,10 @@ struct cdx_device {
107126
struct cdx_controller *cdx;
108127
u16 vendor;
109128
u16 device;
129+
u16 subsystem_vendor;
130+
u16 subsystem_device;
131+
u32 class;
132+
u8 revision;
110133
u8 bus_num;
111134
u8 dev_num;
112135
struct resource res[MAX_CDX_DEV_RESOURCES];

include/linux/mod_devicetable.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,12 @@ enum {
935935
* struct cdx_device_id - CDX device identifier
936936
* @vendor: Vendor ID
937937
* @device: Device ID
938+
* @subvendor: Subsystem vendor ID (or CDX_ANY_ID)
939+
* @subdevice: Subsystem device ID (or CDX_ANY_ID)
940+
* @class: Device class
941+
* Most drivers do not need to specify class/class_mask
942+
* as vendor/device is normally sufficient.
943+
* @class_mask: Limit which sub-fields of the class field are compared.
938944
* @override_only: Match only when dev->driver_override is this driver.
939945
*
940946
* Type of entries in the "device Id" table for CDX devices supported by
@@ -943,6 +949,10 @@ enum {
943949
struct cdx_device_id {
944950
__u16 vendor;
945951
__u16 device;
952+
__u16 subvendor;
953+
__u16 subdevice;
954+
__u32 class;
955+
__u32 class_mask;
946956
__u32 override_only;
947957
};
948958

scripts/mod/devicetable-offsets.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ int main(void)
265265
DEVID(cdx_device_id);
266266
DEVID_FIELD(cdx_device_id, vendor);
267267
DEVID_FIELD(cdx_device_id, device);
268+
DEVID_FIELD(cdx_device_id, subvendor);
269+
DEVID_FIELD(cdx_device_id, subdevice);
270+
DEVID_FIELD(cdx_device_id, class);
271+
DEVID_FIELD(cdx_device_id, class_mask);
268272
DEVID_FIELD(cdx_device_id, override_only);
269273

270274
return 0;

scripts/mod/file2alias.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,10 @@ static int do_cdx_entry(const char *filename, void *symval,
14581458
{
14591459
DEF_FIELD(symval, cdx_device_id, vendor);
14601460
DEF_FIELD(symval, cdx_device_id, device);
1461+
DEF_FIELD(symval, cdx_device_id, subvendor);
1462+
DEF_FIELD(symval, cdx_device_id, subdevice);
1463+
DEF_FIELD(symval, cdx_device_id, class);
1464+
DEF_FIELD(symval, cdx_device_id, class_mask);
14611465
DEF_FIELD(symval, cdx_device_id, override_only);
14621466

14631467
switch (override_only) {
@@ -1475,6 +1479,10 @@ static int do_cdx_entry(const char *filename, void *symval,
14751479

14761480
ADD(alias, "v", vendor != CDX_ANY_ID, vendor);
14771481
ADD(alias, "d", device != CDX_ANY_ID, device);
1482+
ADD(alias, "sv", subvendor != CDX_ANY_ID, subvendor);
1483+
ADD(alias, "sd", subdevice != CDX_ANY_ID, subdevice);
1484+
ADD(alias, "c", class_mask == 0xFFFFFF, class);
1485+
14781486
return 1;
14791487
}
14801488

0 commit comments

Comments
 (0)