hwmon (occ): Avoid polling OCC during probe
PATCH 1/1 hwmon (occ): Avoid polling OCC during probe
Instead of polling the OCC during the probe, use the "occ_active" sysfs file to control when the driver polls the OCC for sensor data. The reason for this change is that the SBE, which is the device by which the driver communicates with the OCC, cannot handle communications during certain system state transitions.
--- drivers/hwmon/occ/common.c | 100 +++++++++++++++++++-------- drivers/hwmon/occ/common.h | 5 +- drivers/hwmon/occ/p8_i2c.c | 2 +- drivers/hwmon/occ/p9_sbe.c | 2 +- drivers/hwmon/occ/sysfs.c | 137 ++++++++++++++++++++++--------------- 5 files changed, 156 insertions(+), 90 deletions(-)
drivers/hwmon/occ/common.c +70 -30
@@ -1149,44 +1149,75 @@ static void occ_parse_poll_response(struct occ *occ) sizeof(*header), size + sizeof(*header)); } -int occ_setup (struct occ *occ,const char *name) +int occ_active (struct occ *occ,bool active) { -int rc; - -mutex_init (&occ->lock); - occ->groups[0 ] = &occ->group; +int rc =mutex_lock_interruptible (&occ->lock); -/* no need to lock */ - rc =occ_poll (occ); -if (rc == -ESHUTDOWN ) { -dev_info (occ->bus_dev,"host is not ready\n" ); -return rc; - }else if (rc <0 ) { -dev_err (occ->bus_dev, -"failed to get OCC poll response=%02x: %d\n" , - occ->resp.return_status, rc); +if (rc)return rc; - } - occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; -occ_parse_poll_response (occ); +if (active) { +if (occ->active) { + rc = -EALREADY ; + goto unlock; + } - rc =occ_setup_sensor_attrs (occ); -if (rc) { -dev_err (occ->bus_dev,"failed to setup sensor attrs: %d\n" , - rc); -return rc; - } + occ->error_count =0 ; + occ->last_safe =0 ; - occ->hwmon =devm_hwmon_device_register_with_groups (occ->bus_dev, name, - occ, occ->groups); -if (IS_ERR (occ->hwmon)) { - rc =PTR_ERR (occ->hwmon); -dev_err (occ->bus_dev,"failed to register hwmon device: %d\n" , - rc); -return rc; + rc =occ_poll (occ); +if (rc <0 ) { +dev_err (occ->bus_dev, +"failed to get OCC poll response=%02x: %d\n" , + occ->resp.return_status, rc); + goto unlock; + } + + occ->active = true; + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; +occ_parse_poll_response (occ); + + rc =occ_setup_sensor_attrs (occ); +if (rc) { +dev_err (occ->bus_dev, +"failed to setup sensor attrs: %d\n" , rc); + goto unlock; + } + + occ->hwmon =hwmon_device_register_with_groups (occ->bus_dev, +"occ" , occ, + occ->groups); +if (IS_ERR (occ->hwmon)) { + rc =PTR_ERR (occ->hwmon); + occ->hwmon =NULL ; +dev_err (occ->bus_dev, +"failed to register hwmon device: %d\n" , rc); + goto unlock; + } + }else { +if (!occ->active) { + rc = -EALREADY ; + goto unlock; + } + +if (occ->hwmon) +hwmon_device_unregister (occ->hwmon); + occ->active = false; + occ->hwmon =NULL ; } +unlock: +mutex_unlock (&occ->lock); +return rc; +} + +int occ_setup (struct occ *occ) +{ +int rc; + +mutex_init (&occ->lock); + occ->groups[0 ] = &occ->group; + rc =occ_setup_sysfs (occ);if (rc)dev_err (occ->bus_dev,"failed to setup sysfs: %d\n" , rc);
@@ -1195,6 +1226,15 @@ int occ_setup(struct occ *occ, const char *name) }EXPORT_SYMBOL_GPL (occ_setup); +void occ_shutdown (struct occ *occ) +{ +occ_shutdown_sysfs (occ); + +if (occ->hwmon) +hwmon_device_unregister (occ->hwmon); +} +EXPORT_SYMBOL_GPL (occ_shutdown); +MODULE_AUTHOR ("Eddie James <[email protected]>" );MODULE_DESCRIPTION ("Common OCC hwmon code" );MODULE_LICENSE ("GPL" );
drivers/hwmon/occ/common.h +4 -1
@@ -106,6 +106,7 @@ struct occ {struct attribute_group group;const struct attribute_group *groups[2 ]; +bool active;int error;/* final transfer error after retry */ int last_error;/* latest transfer error */ unsigned int error_count;/* number of xfr errors observed */
@@ -123,9 +124,11 @@ struct occ {u8 prev_mode; }; -int occ_setup (struct occ *occ,const char *name); +int occ_active (struct occ *occ,bool active); +int occ_setup (struct occ *occ);int occ_setup_sysfs (struct occ *occ);void occ_shutdown (struct occ *occ); +void occ_shutdown_sysfs (struct occ *occ);void occ_sysfs_poll_done (struct occ *occ);int occ_update_response (struct occ *occ);
drivers/hwmon/occ/p8_i2c.c +1 -1
@@ -223,7 +223,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client) occ->poll_cmd_data =0x10 ;/* P8 OCC poll data */ occ->send_cmd = p8_i2c_occ_send_cmd; -return occ_setup (occ,"p8_occ" ); +return occ_setup (occ); }static int p8_i2c_occ_remove (struct i2c_client *client)
drivers/hwmon/occ/p9_sbe.c +1 -1
@@ -145,7 +145,7 @@ static int p9_sbe_occ_probe(struct platform_device *pdev) occ->poll_cmd_data =0x20 ;/* P9 OCC poll data */ occ->send_cmd = p9_sbe_occ_send_cmd; - rc =occ_setup (occ,"p9_occ" ); + rc =occ_setup (occ);if (rc == -ESHUTDOWN ) rc = -ENODEV ;/* Host is shutdown, don't spew errors */
drivers/hwmon/occ/sysfs.c +80 -57
187 lines not on this page · raw message
Signature · 1 line
2.27.0
Guenter Roeck
maintainerQuoted 6 lines · Eddie James
Instead of polling the OCC during the probe, use the "
occ_active" sysfs file to control when the driver polls the OCC for sensor data. The reason for this change is that the SBE, which is the device by which the driver communicates with the OCC, cannot handle communications during certain system state transitions.
This is hackish, to say the least. Why not just instantiate the driver manually instead if userspace interaction is indeed needed, and there is no means to auto-instantiate it only after the hardware is ready ?
On the other side, what means does userspace have to determine that the SBE/OCC is ready ? Can't that same mechanism not be used in the kernel to auto-instantiate the driver ?
Guenter
Quoted 384 lines
Signed-off-by Eddie James <[email protected]>--- drivers/hwmon/occ/common.c | 100 +++++++++++++++++++-------- drivers/hwmon/occ/common.h | 5 +- drivers/hwmon/occ/p8_i2c.c | 2 +- drivers/hwmon/occ/p9_sbe.c | 2 +- drivers/hwmon/occ/sysfs.c | 137 ++++++++++++++++++++++--------------- 5 files changed, 156 insertions(+), 90 deletions(-)drivers/hwmon/occ/common.c +70
-30@@ -1149,44 +1149,75 @@ static void occ_parse_poll_response(struct occ *occ) sizeof(*header), size + sizeof(*header)); } -int occ_setup (struct occ *occ,const char *name) +int occ_active (struct occ *occ,bool active) { -int rc; - -mutex_init (&occ->lock); - occ->groups[0 ] = &occ->group; +int rc =mutex_lock_interruptible (&occ->lock); -/* no need to lock */ - rc =occ_poll (occ); -if (rc == -ESHUTDOWN ) { -dev_info (occ->bus_dev,"host is not ready\n" ); -return rc; - }else if (rc <0 ) { -dev_err (occ->bus_dev, -"failed to get OCC poll response=%02x: %d\n" , - occ->resp.return_status, rc); +if (rc)return rc; - } - occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; -occ_parse_poll_response (occ); +if (active) { +if (occ->active) { + rc = -EALREADY ; + goto unlock; + } - rc =occ_setup_sensor_attrs (occ); -if (rc) { -dev_err (occ->bus_dev,"failed to setup sensor attrs: %d\n" , - rc); -return rc; - } + occ->error_count =0 ; + occ->last_safe =0 ; - occ->hwmon =devm_hwmon_device_register_with_groups (occ->bus_dev, name, - occ, occ->groups); -if (IS_ERR (occ->hwmon)) { - rc =PTR_ERR (occ->hwmon); -dev_err (occ->bus_dev,"failed to register hwmon device: %d\n" , - rc); -return rc; + rc =occ_poll (occ); +if (rc <0 ) { +dev_err (occ->bus_dev, +"failed to get OCC poll response=%02x: %d\n" , + occ->resp.return_status, rc); + goto unlock; + } + + occ->active = true; + occ->next_update = jiffies +OCC_UPDATE_FREQUENCY ; +occ_parse_poll_response (occ); + + rc =occ_setup_sensor_attrs (occ); +if (rc) { +dev_err (occ->bus_dev, +"failed to setup sensor attrs: %d\n" , rc); + goto unlock; + } + + occ->hwmon =hwmon_device_register_with_groups (occ->bus_dev, +"occ" , occ, + occ->groups); +if (IS_ERR (occ->hwmon)) { + rc =PTR_ERR (occ->hwmon); + occ->hwmon =NULL ; +dev_err (occ->bus_dev, +"failed to register hwmon device: %d\n" , rc); + goto unlock; + } + }else { +if (!occ->active) { + rc = -EALREADY ; + goto unlock; + } + +if (occ->hwmon) +hwmon_device_unregister (occ->hwmon); + occ->active = false; + occ->hwmon =NULL ; } +unlock: +mutex_unlock (&occ->lock); +return rc; +} + +int occ_setup (struct occ *occ) +{ +int rc; + +mutex_init (&occ->lock); + occ->groups[0 ] = &occ->group; + rc =occ_setup_sysfs (occ);if (rc)dev_err (occ->bus_dev,"failed to setup sysfs: %d\n" , rc);@@ -1195,6 +1226,15 @@ int occ_setup(struct occ *occ, const char *name) }EXPORT_SYMBOL_GPL (occ_setup); +void occ_shutdown (struct occ *occ) +{ +occ_shutdown_sysfs (occ); + +if (occ->hwmon) +hwmon_device_unregister (occ->hwmon); +} +EXPORT_SYMBOL_GPL (occ_shutdown); +MODULE_AUTHOR ("Eddie James <[email protected]>" );MODULE_DESCRIPTION ("Common OCC hwmon code" );MODULE_LICENSE ("GPL" );drivers/hwmon/occ/common.h +4
-1@@ -106,6 +106,7 @@ struct occ {struct attribute_group group;const struct attribute_group *groups[2 ]; +bool active;int error;/* final transfer error after retry */ int last_error;/* latest transfer error */ unsigned int error_count;/* number of xfr errors observed */ @@ -123,9 +124,11 @@ struct occ {u8 prev_mode; }; -int occ_setup (struct occ *occ,const char *name); +int occ_active (struct occ *occ,bool active); +int occ_setup (struct occ *occ);int occ_setup_sysfs (struct occ *occ);void occ_shutdown (struct occ *occ); +void occ_shutdown_sysfs (struct occ *occ);void occ_sysfs_poll_done (struct occ *occ);int occ_update_response (struct occ *occ);drivers/hwmon/occ/p8_i2c.c +1
-1@@ -223,7 +223,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client) occ->poll_cmd_data =0x10 ;/* P8 OCC poll data */ occ->send_cmd = p8_i2c_occ_send_cmd; -return occ_setup (occ,"p8_occ" ); +return occ_setup (occ); }static int p8_i2c_occ_remove (struct i2c_client *client)drivers/hwmon/occ/p9_sbe.c +1
-1@@ -145,7 +145,7 @@ static int p9_sbe_occ_probe(struct platform_device *pdev) occ->poll_cmd_data =0x20 ;/* P9 OCC poll data */ occ->send_cmd = p9_sbe_occ_send_cmd; - rc =occ_setup (occ,"p9_occ" ); + rc =occ_setup (occ);if (rc == -ESHUTDOWN ) rc = -ENODEV ;/* Host is shutdown, don't spew errors */ drivers/hwmon/occ/sysfs.c +80
-57@@ -6,13 +6,13 @@#include <linux/export.h> #include <linux/hwmon-sysfs.h> #include <linux/kernel.h> +#include <linux/kstrtox.h> #include <linux/sysfs.h> #include "common.h" /* OCC status register */ #define OCC_STAT_MASTER BIT(7) -#define OCC_STAT_ACTIVE BIT(0)/* OCC extended status register */ #define OCC_EXT_STAT_DVFS_OT BIT(7)@@ -22,6 +22,25 @@#define OCC_EXT_STAT_DVFS_VDD BIT(3)#define OCC_EXT_STAT_GPU_THROTTLE GENMASK(2, 0) +static ssize_t occ_active_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +int rc; +bool active; +struct occ *occ =dev_get_drvdata (dev); + + rc =kstrtobool (buf, &active); +if (rc) +return rc; + + rc =occ_active (occ, active); +if (rc) +return rc; + +return count; +} +static ssize_t occ_sysfs_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -31,54 +50,64 @@ static ssize_t occ_sysfs_show(struct device *dev,struct occ_poll_response_header *header;struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); - rc =occ_update_response (occ); -if (rc) -return rc; +if (occ->active) { + rc =occ_update_response (occ); +if (rc) +return rc; - header = (struct occ_poll_response_header *)occ->resp.data; - -switch (sattr->index) { -case 0 : - val = !!(header->status &OCC_STAT_MASTER ); -break ; -case 1 : - val = !!(header->status &OCC_STAT_ACTIVE ); -break ; -case 2 : - val = !!(header->ext_status &OCC_EXT_STAT_DVFS_OT ); -break ; -case 3 : - val = !!(header->ext_status &OCC_EXT_STAT_DVFS_POWER ); -break ; -case 4 : - val = !!(header->ext_status &OCC_EXT_STAT_MEM_THROTTLE ); -break ; -case 5 : - val = !!(header->ext_status &OCC_EXT_STAT_QUICK_DROP ); -break ; -case 6 : - val = header->occ_state; -break ; -case 7 : -if (header->status &OCC_STAT_MASTER ) - val =hweight8 (header->occs_present); -else + header = (struct occ_poll_response_header *)occ->resp.data; + +switch (sattr->index) { +case 0 : + val = !!(header->status &OCC_STAT_MASTER ); +break ; +case 1 : val =1 ; -break ; -case 8 : - val = header->ips_status; -break ; -case 9 : - val = header->mode; -break ; -case 10 : - val = !!(header->ext_status &OCC_EXT_STAT_DVFS_VDD ); -break ; -case 11 : - val = header->ext_status &OCC_EXT_STAT_GPU_THROTTLE ; -break ; -default : -return -EINVAL ; +break ; +case 2 : + val = !!(header->ext_status &OCC_EXT_STAT_DVFS_OT ); +break ; +case 3 : + val = !!(header->ext_status &OCC_EXT_STAT_DVFS_POWER ); +break ; +case 4 : + val = !!(header->ext_status & +OCC_EXT_STAT_MEM_THROTTLE ); +break ; +case 5 : + val = !!(header->ext_status &OCC_EXT_STAT_QUICK_DROP ); +break ; +case 6 : + val = header->occ_state; +break ; +case 7 : +if (header->status &OCC_STAT_MASTER ) + val =hweight8 (header->occs_present); +else + val =1 ; +break ; +case 8 : + val = header->ips_status; +break ; +case 9 : + val = header->mode; +break ; +case 10 : + val = !!(header->ext_status &OCC_EXT_STAT_DVFS_VDD ); +break ; +case 11 : + val = header->ext_status &OCC_EXT_STAT_GPU_THROTTLE ; +break ; +default : +return -EINVAL ; + } + }else { +if (sattr->index ==1 ) + val =0 ; +else if (sattr->index <=11 ) + val = -ENODATA ; +else +return -EINVAL ; }return sysfs_emit (buf,"%d\n" , val);@@ -95,7 +124,8 @@ static ssize_t occ_error_show(struct device *dev, } static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_sysfs_show, NULL, 0); -static SENSOR_DEVICE_ATTR(occ_active, 0444, occ_sysfs_show, NULL, 1); +static SENSOR_DEVICE_ATTR(occ_active, 0644, occ_sysfs_show, occ_active_store, + 1); static SENSOR_DEVICE_ATTR(occ_dvfs_overtemp, 0444, occ_sysfs_show, NULL, 2); static SENSOR_DEVICE_ATTR(occ_dvfs_power, 0444, occ_sysfs_show, NULL, 3); static SENSOR_DEVICE_ATTR(occ_mem_throttle, 0444, occ_sysfs_show, NULL, 4);@@ -139,7 +169,7 @@ void occ_sysfs_poll_done(struct occ *occ)* On the first poll response, we haven't yet created the sysfs * attributes, so don't make any notify calls. */ -if (!occ->hwmon) +if (!occ->active) goto done; if ((header->status & OCC_STAT_MASTER) !=@@ -148,12 +178,6 @@ void occ_sysfs_poll_done(struct occ *occ)sysfs_notify (&occ->bus_dev->kobj,NULL , name); } -if ((header->status &OCC_STAT_ACTIVE ) != - (occ->prev_stat &OCC_STAT_ACTIVE )) { - name = sensor_dev_attr_occ_active.dev_attr.attr.name; -sysfs_notify (&occ->bus_dev->kobj,NULL , name); - } -if ((header->ext_status &OCC_EXT_STAT_DVFS_OT ) != (occ->prev_ext_stat &OCC_EXT_STAT_DVFS_OT )) { name = sensor_dev_attr_occ_dvfs_overtemp.dev_attr.attr.name;@@ -227,8 +251,7 @@ int occ_setup_sysfs(struct occ *occ)return sysfs_create_group (&occ->bus_dev->kobj, &occ_sysfs); } -void occ_shutdown (struct occ *occ) +void occ_shutdown_sysfs (struct occ *occ) {sysfs_remove_group (&occ->bus_dev->kobj, &occ_sysfs); } -EXPORT_SYMBOL_GPL (occ_shutdown);
Quoted 11 lines · Guenter Roeck
Quoted 6 lines · Eddie James
Instead of polling the OCC during the probe, use the "
occ_active" sysfs file to control when the driver polls the OCC for sensor data. The reason for this change is that the SBE, which is the device by which the driver communicates with the OCC, cannot handle communications during certain system state transitions.This is hackish, to say the least. Why not just instantiate the driver manually instead if userspace interaction is indeed needed, and there is no means to auto-instantiate it only after the hardware is ready ?
Well, the occ-hwmon platform devices are currently created by the parent FSI occ device (that's a bit of a hack too). I poked through the platform/device/bus interfaces but couldn't work out how to create the device but not probe it, so that userspace could later bind the device to the driver. The current userspace does just that, but it relies on the the initial probe failing since SBE can't handle the communications yet. The error scenario is that the SBE can get into a bad state, so communications shouldn't even be attempted.
So to answer your question, there's no reason not to just instantiate the driver manually, but I don't actually know how to do so with these drivers.
Quoted 4 lines
On the other side, what means does userspace have to determine that the SBE/OCC is ready ? Can't that same mechanism not be used in the kernel to auto-instantiate the driver ?
No it's impossible, it's not just some bit we can check in HW unfortunately, the signal is PLDM (platform level data model) over the network.
Thanks for your quick response.
Eddie
Quoted 367 lines
Guenter
Quoted 363 lines
Signed-off-by Eddie James <[email protected]>---
drivers/hwmon/occ/common.c | 100 +++++++++++++++++++-------- drivers/hwmon/occ/common.h | 5 +- drivers/hwmon/occ/p8_i2c.c | 2 +- drivers/hwmon/occ/p9_sbe.c | 2 +- drivers/hwmon/occ/sysfs.c | 137 ++++++++++++++++++++++--------------- 5 files changed, 156 insertions(+), 90 deletions(-)drivers/hwmon/occ/common.c +2
-4@@ -1149,44 +1149,75 @@ static void occ_parse_poll_response(struct occ *occ) sizeof(*header), size + sizeof(*header)); } -int occ_setup(struct occ *occ, const char *name) +int occ_active(struct occ *occ, bool active) { - int rc; - - mutex_init(&occ->lock); - occ->groups[0] = &occ->group; + int rc = mutex_lock_interruptible(&occ->lock);- /* no need to lock */
- rc =occ_poll(occ);
- if (rc ==-ESHUTDOWN) {
-dev_info(occ->bus_dev, "host is not ready\n");
- return rc;
- } else if (rc < 0) {
- dev_err(occ->bus_dev,
- "failed to get OCC poll response=%02x: %d\n",
-occ->resp.return_status, rc);
+ if (rc)
return rc;
- }
-occ->next_update= jiffies +OCC_UPDATE_FREQUENCY;
-occ_parse_poll_response(occ);
+ if (active) {
+ if (occ->active) {
+ rc =-EALREADY;
+ goto unlock;
+ }
- rc =occ_setup_sensor_attrs(occ);
- if (rc) {
-dev_err(occ->bus_dev, "failed to setup sensor attrs: %d\n", - rc);
- return rc;
- }
+occ->error_count= 0;
+occ->last_safe= 0;
-occ->hwmon= devm_hwmon_device_register_with_groups(occ->bus_dev, name, - occ,occ->groups);
- if (IS_ERR(occ->hwmon)) {
- rc =PTR_ERR(occ->hwmon);
-dev_err(occ->bus_dev, "failed to register hwmon device: %d\n", - rc);
- return rc;
+ rc =occ_poll(occ);
+ if (rc < 0) {
+ dev_err(occ->bus_dev,
+ "failed to get OCC poll response=%02x: %d\n",
+occ->resp.return_status, rc);
+ goto unlock;
+ }drivers/hwmon/occ/common.c +32
-0+ + occ->active = true; + occ->next_update = jiffies + OCC_UPDATE_FREQUENCY; + occ_parse_poll_response(occ); + + rc = occ_setup_sensor_attrs(occ); + if (rc) { + dev_err(occ->bus_dev, + "failed to setup sensor attrs: %d\n", rc); + goto unlock; + } + + occ->hwmon = hwmon_device_register_with_groups(occ->bus_dev, + "occ", occ, + occ->groups); + if (IS_ERR(occ->hwmon)) { + rc = PTR_ERR(occ->hwmon); + occ->hwmon = NULL; + dev_err(occ->bus_dev, + "failed to register hwmon device: %d\n", rc); + goto unlock; + } + } else { + if (!occ->active) { + rc = -EALREADY; + goto unlock; + } + + if (occ->hwmon) + hwmon_device_unregister(occ->hwmon); + occ->active = false; + occ->hwmon = NULL;}
+unlock:
+mutex_unlock(&occ->lock);
+ return rc;drivers/hwmon/occ/common.c +9
-0+} + +int occ_setup (struct occ *occ) +{ + int rc; + + mutex_init(&occ->lock); + occ->groups[0] = &occ->group; +rc =
occ_setup_sysfs(occ);
if (rc)
dev_err(occ->bus_dev, "failed to setup sysfs: %d\n", rc);drivers/hwmon/occ/common.c +8
-0@@ -1195,6 +1226,15 @@ int occ_setup(struct occ *occ, const char *name) } EXPORT_SYMBOL_GPL(occ_setup); +void occ_shutdown(struct occ *occ) +{ + occ_shutdown_sysfs(occ); + + if (occ->hwmon) + hwmon_device_unregister(occ->hwmon); +} +EXPORT_SYMBOL_GPL (occ_shutdown); + MODULE_AUTHOR("Eddie James <[email protected]>"); MODULE_DESCRIPTION("Common OCC hwmon code"); MODULE_LICENSE("GPL");drivers/hwmon/occ/common.h +0
-0@@ -106,6 +106,7 @@ struct occ { struct attribute_group group; const struct attribute_group *groups[2]; + bool active;int error; /* final transfer error after retry */ int last_error; /* latest transfer error */ unsigned int error_count; /* number of xfr errors observed */
drivers/hwmon/occ/common.h +3
-0@@ -123,9 +124,11 @@ struct occ { u8 prev_mode; }; -int occ_setup(struct occ *occ, const char *name); +int occ_active (struct occ *occ,bool active); +int occ_setup (struct occ *occ); int occ_setup_sysfs(struct occ *occ); void occ_shutdown(struct occ *occ); +void occ_shutdown_sysfs (struct occ *occ); void occ_sysfs_poll_done(struct occ *occ); int occ_update_response(struct occ *occ);diff --git
a/drivers/hwmon/occ/p8_i2c.cb/drivers/hwmon/occ/p8_i2c.cindex9e61e1fb5142..da39ea28df31100644drivers/hwmon/occ/p8_i2c.c +0
-0@@ -223,7 +223,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client)
occ->poll_cmd_data= 0x10; /* P8 OCC poll data */occ->send_cmd=p8_i2c_occ_send_cmd;
- returnocc_setup(occ, "p8_occ");
+ returnocc_setup(occ);
}
static intp8_i2c_occ_remove(struct i2c_client *client)drivers/hwmon/occ/p9_sbe.c +0
-0@@ -145,7 +145,7 @@ static int p9_sbe_occ_probe(struct platform_device *pdev)
occ->poll_cmd_data= 0x20; /* P9 OCC poll data */occ->send_cmd=p9_sbe_occ_send_cmd;
- rc =occ_setup(occ, "p9_occ");
+ rc =occ_setup(occ);
if (rc ==-ESHUTDOWN)
rc = -ENODEV; /* Host is shutdown, don't spew errors */ diff --gita/drivers/hwmon/occ/sysfs.cb/drivers/hwmon/occ/sysfs.cindexb2f788a77746..2317301fc1e9100644drivers/hwmon/occ/sysfs.c +78
-47@@ -6,13 +6,13 @@ #include <linux/export.h> #include <linux/hwmon-sysfs.h> #include <linux/kernel.h> +#include <linux/kstrtox.h> #include <linux/sysfs.h> #include "common.h" /* OCC status register */ #define OCC_STAT_MASTER BIT(7) -#define OCC_STAT_ACTIVE BIT(0) /* OCC extended status register */ #define OCC_EXT_STAT_DVFS_OT BIT(7)@@ -22,6 +22,25 @@ #define OCC_EXT_STAT_DVFS_VDD BIT(3) #define OCC_EXT_STAT_GPU_THROTTLE GENMASK(2, 0) +static ssize_t occ_active_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int rc; + bool active; + struct occ *occ = dev_get_drvdata(dev); + + rc = kstrtobool(buf, &active); + if (rc) + return rc; + + rc = occ_active(occ, active); + if (rc) + return rc; + + return count; +} + static ssize_t occ_sysfs_show(struct device *dev, struct device_attribute *attr, char *buf) {@@ -31,54 +50,64 @@ static ssize_t occ_sysfs_show(struct device *dev, struct occ_poll_response_header *header; struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); - rc = occ_update_response(occ); - if (rc) - return rc; + if (occ->active) { + rc = occ_update_response(occ); + if (rc) + return rc; - header = (struct occ_poll_response_header *)occ->resp.data; - - switch (sattr->index) { - case 0: - val = !!(header->status & OCC_STAT_MASTER); - break; - case 1: - val = !!(header->status & OCC_STAT_ACTIVE); - break; - case 2: - val = !!(header->ext_status & OCC_EXT_STAT_DVFS_OT); - break; - case 3: - val = !!(header->ext_status & OCC_EXT_STAT_DVFS_POWER); - break; - case 4: - val = !!(header->ext_status & OCC_EXT_STAT_MEM_THROTTLE); - break; - case 5: - val = !!(header->ext_status & OCC_EXT_STAT_QUICK_DROP); - break; - case 6: - val = header->occ_state; - break; - case 7: - if (header->status & OCC_STAT_MASTER) - val = hweight8(header->occs_present); - else + header = (struct occ_poll_response_header *)occ->resp.data; + + switch (sattr->index) { + case 0: + val = !!(header->status & OCC_STAT_MASTER); + break; + case 1: val = 1; - break; - case 8: - val = header->ips_status; - break; - case 9: - val = header->mode; - break; - case 10: - val = !!(header->ext_status & OCC_EXT_STAT_DVFS_VDD); - break; - case 11: - val = header->ext_status & OCC_EXT_STAT_GPU_THROTTLE; - break; - default: - return -EINVAL; + break; + case 2: + val = !!(header->ext_status & OCC_EXT_STAT_DVFS_OT); + break; + case 3: + val = !!(header->ext_status & OCC_EXT_STAT_DVFS_POWER); + break; + case 4: + val = !!(header->ext_status & + OCC_EXT_STAT_MEM_THROTTLE); + break; + case 5: + val = !!(header->ext_status & OCC_EXT_STAT_QUICK_DROP); + break; + case 6: + val = header->occ_state; + break; + case 7: + if (header->status & OCC_STAT_MASTER) + val = hweight8(header->occs_present); + else + val = 1; + break; + case 8: + val = header->ips_status; + break; + case 9: + val = header->mode; + break; + case 10: + val = !!(header->ext_status & OCC_EXT_STAT_DVFS_VDD); + break; + case 11: + val = header->ext_status & OCC_EXT_STAT_GPU_THROTTLE; + break; + default: + return -EINVAL; + } + } else { + if (sattr->index == 1) + val = 0; + else if (sattr->index <= 11) + val = -ENODATA; + else + return -EINVAL; } return sysfs_emit(buf, "%d\n", val);@@ -95,7 +124,8 @@ static ssize_t occ_error_show(struct device *dev, } static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_sysfs_show, NULL, 0); -static SENSOR_DEVICE_ATTR(occ_active, 0444, occ_sysfs_show, NULL, 1); +static SENSOR_DEVICE_ATTR(occ_active, 0644, occ_sysfs_show, occ_active_store, + 1); static SENSOR_DEVICE_ATTR(occ_dvfs_overtemp, 0444, occ_sysfs_show, NULL, 2); static SENSOR_DEVICE_ATTR(occ_dvfs_power, 0444, occ_sysfs_show, NULL, 3); static SENSOR_DEVICE_ATTR(occ_mem_throttle, 0444, occ_sysfs_show, NULL, 4);@@ -139,7 +169,7 @@ void occ_sysfs_poll_done(struct occ *occ)* On the first poll response, we haven't yet created the sysfs * attributes, so don't make any notify calls. */ - if (!occ->hwmon) + if (!occ->active) goto done;if ((
header->status&OCC_STAT_MASTER) !=drivers/hwmon/occ/sysfs.c +0
-0@@ -148,12 +178,6 @@ void occ_sysfs_poll_done(struct occ *occ) sysfs_notify(&occ->bus_dev->kobj, NULL, name); }- if ((
header->status&OCC_STAT_ACTIVE) !=
- (occ->prev_stat&OCC_STAT_ACTIVE)) {
- name = sensor_dev_attr_occ_active.dev_attr.attr.name; -sysfs_notify(&occ->bus_dev->kobj, NULL, name);
- }
-
if ((header->ext_status&OCC_EXT_STAT_DVFS_OT) != (occ->prev_ext_stat&OCC_EXT_STAT_DVFS_OT)) { name = sensor_dev_attr_occ_dvfs_overtemp.dev_attr.attr.name;drivers/hwmon/occ/sysfs.c +1
-1@@ -227,8 +251,7 @@ int occ_setup_sysfs(struct occ *occ) return sysfs_create_group(&occ->bus_dev->kobj, &occ_sysfs); } -void occ_shutdown(struct occ *occ) +void occ_shutdown_sysfs(struct occ *occ) { sysfs_remove_group(&occ->bus_dev->kobj, &occ_sysfs); } -EXPORT_SYMBOL_GPL (occ_shutdown);
Guenter Roeck
maintainerQuoted 21 lines · Eddie James
Quoted 11 lines · Guenter Roeck
Quoted 6 lines · Eddie James
Instead of polling the OCC during the probe, use the "
occ_active" sysfs file to control when the driver polls the OCC for sensor data. The reason for this change is that the SBE, which is the device by which the driver communicates with the OCC, cannot handle communications during certain system state transitions.This is hackish, to say the least. Why not just instantiate the driver manually instead if userspace interaction is indeed needed, and there is no means to auto-instantiate it only after the hardware is ready ?
Well, the occ-hwmon platform devices are currently created by the parent FSI occ device (that's a bit of a hack too). I poked through the platform/device/bus interfaces but couldn't work out how to create the device but not probe it, so that userspace could later bind the device to the driver. The current userspace does just that, but it relies on the the initial probe failing since SBE can't handle the communications yet. The error scenario is that the SBE can get into a bad state, so communications shouldn't even be attempted.
So to answer your question, there's no reason not to just instantiate the driver manually, but I don't actually know how to do so with these drivers.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
On the other side, what means does userspace have to determine that the SBE/OCC is ready ? Can't that same mechanism not be used in the kernel to auto-instantiate the driver ?
No it's impossible, it's not just some bit we can check in HW unfortunately, the signal is PLDM (platform level data model) over the network.
What a mess.
The subject and description are misleading. The code doesn't "avoid polling during probe", it delays hwmon registration until directed to do it by writing into a new sysfs attribute. Please update accordingly.
Thanks,
Guenter
Quoted 27 lines · Guenter Roeck
Quoted 26 lines · Eddie James
Quoted 11 lines · Guenter Roeck
Quoted 6 lines · Eddie James
Instead of polling the OCC during the probe, use the "
occ_active" sysfs file to control when the driver polls the OCC for sensor data. The reason for this change is that the SBE, which is the device by which the driver communicates with the OCC, cannot handle communications during certain system state transitions.This is hackish, to say the least. Why not just instantiate the driver manually instead if userspace interaction is indeed needed, and there is no means to auto-instantiate it only after the hardware is ready ?
Well, the occ-hwmon platform devices are currently created by the parent FSI occ device (that's a bit of a hack too). I poked through the platform/device/bus interfaces but couldn't work out how to create the device but not probe it, so that userspace could later bind the device to the driver. The current userspace does just that, but it relies on the the initial probe failing since SBE can't handle the communications yet. The error scenario is that the SBE can get into a bad state, so communications shouldn't even be attempted.
So to answer your question, there's no reason not to just instantiate the driver manually, but I don't actually know how to do so with these drivers.
Quoted 4 lines
On the other side, what means does userspace have to determine that the SBE/OCC is ready ? Can't that same mechanism not be used in the kernel to auto-instantiate the driver ?
Quoted 4 lines
Quoted 2 lines
No it's impossible, it's not just some bit we can check in HW unfortunately, the signal is PLDM (platform level data model) over the network.
What a mess.
It is, yes. Just sent a v2. Thanks for taking a second look.
Eddie
Quoted 5 lines
The subject and description are misleading. The code doesn't "avoid polling during probe", it delays hwmon registration until directed to do it by writing into a new sysfs attribute. Please update accordingly.
It's actually an existing sysfs file, I've just made it writeable.
Quoted 3 lines
Thanks,
Guenter