Message ID | 20250122235159.2716036-6-dave.jiang@intel.com |
---|---|
State | New |
Headers | show |
Series | cxl: Add CXL feature commands support via fwctl | expand |
On Wed, 22 Jan 2025 16:50:36 -0700 Dave Jiang <dave.jiang@intel.com> wrote: > Enable sysfs attribute emission of the number of features supported by the > driver/device. This is useful for userspace to determine the number of features > to query for. > > Signed-off-by: Dave Jiang <dave.jiang@intel.com> Seems reasonable. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Dave Jiang wrote: > Enable sysfs attribute emission of the number of features supported by the > driver/device. This is useful for userspace to determine the number of features > to query for. > It would need Documentation in Documentation/ABI/ for userspace to even know it is there, but I am not convinced it's needed given we do not have a similar sysfs attribute for CXL commands. Is not the expectation for userspace to call Get Supported Features itself?
diff --git a/drivers/cxl/features.c b/drivers/cxl/features.c index a5949312a4ab..0d1fc3da9e35 100644 --- a/drivers/cxl/features.c +++ b/drivers/cxl/features.c @@ -173,11 +173,38 @@ static void cxl_features_remove(struct device *dev) kfree(cfs); } +static ssize_t features_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct cxl_features_state *cfs = dev_get_drvdata(dev); + + if (!cfs) + return -ENOENT; + + return sysfs_emit(buf, "%d\n", cfs->num_features); +} + +static DEVICE_ATTR_RO(features); + +static struct attribute *cxl_features_attrs[] = { + &dev_attr_features.attr, + NULL +}; + +static struct attribute_group cxl_features_group = { + .attrs = cxl_features_attrs, +}; + +__ATTRIBUTE_GROUPS(cxl_features); + static struct cxl_driver cxl_features_driver = { .name = "cxl_features", .probe = cxl_features_probe, .remove = cxl_features_remove, .id = CXL_DEVICE_FEATURES, + .drv = { + .dev_groups = cxl_features_groups, + }, }; module_cxl_driver(cxl_features_driver);
Enable sysfs attribute emission of the number of features supported by the driver/device. This is useful for userspace to determine the number of features to query for. Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- drivers/cxl/features.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)