diff mbox series

[3/3] hwmon: (occ) Check for device property for setting OCC active during probe

Message ID 20220802194656.240564-4-eajames@linux.ibm.com
State New
Headers show
Series occ: Restore default behavior of polling OCC during init | expand

Commit Message

Eddie James Aug. 2, 2022, 7:46 p.m. UTC
A previous commit changed the existing behavior of the driver to skip
attempting to communicate with the OCC during probe. Return to the
previous default behavior of automatically communicating with the OCC
and make it optional with a new device-tree property.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/hwmon/occ/common.c | 11 ++++++++++-
 drivers/hwmon/occ/p9_sbe.c |  9 +++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

kernel test robot Aug. 3, 2022, 12:21 p.m. UTC | #1
Hi Eddie,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20220728]
[also build test ERROR on v5.19]
[cannot apply to groeck-staging/hwmon-next linus/master v5.19 v5.19-rc8 v5.19-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Eddie-James/occ-Restore-default-behavior-of-polling-OCC-during-init/20220803-034854
base:    7c5e07b73ff3011c9b82d4a3286a3362b951ad2b
config: arm-randconfig-r021-20220803 (https://download.01.org/0day-ci/archive/20220803/202208032055.PEvfcqsc-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 495519e5f8232d144ed26e9c18dbcbac6a5f25eb)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/31dc5bad51ddf22f4e097c0c5862d14341708188
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eddie-James/occ-Restore-default-behavior-of-polling-OCC-during-init/20220803-034854
        git checkout 31dc5bad51ddf22f4e097c0c5862d14341708188
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/hwmon/occ/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/hwmon/occ/p9_sbe.c:188:25: error: use of undeclared identifier 'p8_i2c_occ_of_match'; did you mean 'p9_sbe_occ_of_match'?
   MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
                           ^~~~~~~~~~~~~~~~~~~
                           p9_sbe_occ_of_match
   include/linux/module.h:244:15: note: expanded from macro 'MODULE_DEVICE_TABLE'
   extern typeof(name) __mod_##type##__##name##_device_table               \
                 ^
   drivers/hwmon/occ/p9_sbe.c:183:34: note: 'p9_sbe_occ_of_match' declared here
   static const struct of_device_id p9_sbe_occ_of_match[] = {
                                    ^
   1 error generated.


vim +188 drivers/hwmon/occ/p9_sbe.c

   182	
   183	static const struct of_device_id p9_sbe_occ_of_match[] = {
   184		{ .compatible = "ibm,p9-occ-hwmon" },
   185		{ .compatible = "ibm,p10-occ-hwmon" },
   186		{}
   187	};
 > 188	MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
   189
kernel test robot Aug. 3, 2022, 2:44 p.m. UTC | #2
Hi Eddie,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20220728]
[also build test ERROR on v5.19]
[cannot apply to groeck-staging/hwmon-next linus/master v5.19 v5.19-rc8 v5.19-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Eddie-James/occ-Restore-default-behavior-of-polling-OCC-during-init/20220803-034854
base:    7c5e07b73ff3011c9b82d4a3286a3362b951ad2b
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20220803/202208032229.qba4UTzM-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/31dc5bad51ddf22f4e097c0c5862d14341708188
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eddie-James/occ-Restore-default-behavior-of-polling-OCC-during-init/20220803-034854
        git checkout 31dc5bad51ddf22f4e097c0c5862d14341708188
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/hwmon/occ/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/device/driver.h:21,
                    from include/linux/device.h:32,
                    from drivers/hwmon/occ/p9_sbe.c:4:
>> drivers/hwmon/occ/p9_sbe.c:188:25: error: 'p8_i2c_occ_of_match' undeclared here (not in a function); did you mean 'p9_sbe_occ_of_match'?
     188 | MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
         |                         ^~~~~~~~~~~~~~~~~~~
   include/linux/module.h:244:15: note: in definition of macro 'MODULE_DEVICE_TABLE'
     244 | extern typeof(name) __mod_##type##__##name##_device_table               \
         |               ^~~~
>> include/linux/module.h:244:21: error: '__mod_of__p8_i2c_occ_of_match_device_table' aliased to undefined symbol 'p8_i2c_occ_of_match'
     244 | extern typeof(name) __mod_##type##__##name##_device_table               \
         |                     ^~~~~~
   drivers/hwmon/occ/p9_sbe.c:188:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
     188 | MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
         | ^~~~~~~~~~~~~~~~~~~


vim +188 drivers/hwmon/occ/p9_sbe.c

     3	
   > 4	#include <linux/device.h>
     5	#include <linux/errno.h>
     6	#include <linux/slab.h>
     7	#include <linux/fsi-occ.h>
     8	#include <linux/mm.h>
     9	#include <linux/module.h>
    10	#include <linux/mod_devicetable.h>
    11	#include <linux/mutex.h>
    12	#include <linux/platform_device.h>
    13	#include <linux/string.h>
    14	#include <linux/sysfs.h>
    15	
    16	#include "common.h"
    17	
    18	#define OCC_CHECKSUM_RETRIES	3
    19	
    20	struct p9_sbe_occ {
    21		struct occ occ;
    22		bool sbe_error;
    23		void *ffdc;
    24		size_t ffdc_len;
    25		size_t ffdc_size;
    26		struct mutex sbe_error_lock;	/* lock access to ffdc data */
    27		struct device *sbe;
    28	};
    29	
    30	#define to_p9_sbe_occ(x)	container_of((x), struct p9_sbe_occ, occ)
    31	
    32	static ssize_t ffdc_read(struct file *filp, struct kobject *kobj,
    33				 struct bin_attribute *battr, char *buf, loff_t pos,
    34				 size_t count)
    35	{
    36		ssize_t rc = 0;
    37		struct occ *occ = dev_get_drvdata(kobj_to_dev(kobj));
    38		struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
    39	
    40		mutex_lock(&ctx->sbe_error_lock);
    41		if (ctx->sbe_error) {
    42			rc = memory_read_from_buffer(buf, count, &pos, ctx->ffdc,
    43						     ctx->ffdc_len);
    44			if (pos >= ctx->ffdc_len)
    45				ctx->sbe_error = false;
    46		}
    47		mutex_unlock(&ctx->sbe_error_lock);
    48	
    49		return rc;
    50	}
    51	static BIN_ATTR_RO(ffdc, OCC_MAX_RESP_WORDS * 4);
    52	
    53	static bool p9_sbe_occ_save_ffdc(struct p9_sbe_occ *ctx, const void *resp,
    54					 size_t resp_len)
    55	{
    56		bool notify = false;
    57	
    58		mutex_lock(&ctx->sbe_error_lock);
    59		if (!ctx->sbe_error) {
    60			if (resp_len > ctx->ffdc_size) {
    61				kvfree(ctx->ffdc);
    62				ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL);
    63				if (!ctx->ffdc) {
    64					ctx->ffdc_len = 0;
    65					ctx->ffdc_size = 0;
    66					goto done;
    67				}
    68	
    69				ctx->ffdc_size = resp_len;
    70			}
    71	
    72			notify = true;
    73			ctx->sbe_error = true;
    74			ctx->ffdc_len = resp_len;
    75			memcpy(ctx->ffdc, resp, resp_len);
    76		}
    77	
    78	done:
    79		mutex_unlock(&ctx->sbe_error_lock);
    80		return notify;
    81	}
    82	
    83	static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
    84				       void *resp, size_t resp_len)
    85	{
    86		struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
    87		int rc, i;
    88	
    89		for (i = 0; i < OCC_CHECKSUM_RETRIES; ++i) {
    90			rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
    91			if (rc >= 0)
    92				break;
    93			if (resp_len) {
    94				if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
    95					sysfs_notify(&occ->bus_dev->kobj, NULL,
    96						     bin_attr_ffdc.attr.name);
    97				return rc;
    98			}
    99			if (rc != -EBADE)
   100				return rc;
   101		}
   102	
   103		switch (((struct occ_response *)resp)->return_status) {
   104		case OCC_RESP_CMD_IN_PRG:
   105			rc = -ETIMEDOUT;
   106			break;
   107		case OCC_RESP_SUCCESS:
   108			rc = 0;
   109			break;
   110		case OCC_RESP_CMD_INVAL:
   111		case OCC_RESP_CMD_LEN_INVAL:
   112		case OCC_RESP_DATA_INVAL:
   113		case OCC_RESP_CHKSUM_ERR:
   114			rc = -EINVAL;
   115			break;
   116		case OCC_RESP_INT_ERR:
   117		case OCC_RESP_BAD_STATE:
   118		case OCC_RESP_CRIT_EXCEPT:
   119		case OCC_RESP_CRIT_INIT:
   120		case OCC_RESP_CRIT_WATCHDOG:
   121		case OCC_RESP_CRIT_OCB:
   122		case OCC_RESP_CRIT_HW:
   123			rc = -EREMOTEIO;
   124			break;
   125		default:
   126			rc = -EPROTO;
   127		}
   128	
   129		return rc;
   130	}
   131	
   132	static int p9_sbe_occ_probe(struct platform_device *pdev)
   133	{
   134		int rc;
   135		struct occ *occ;
   136		struct p9_sbe_occ *ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx),
   137						      GFP_KERNEL);
   138		if (!ctx)
   139			return -ENOMEM;
   140	
   141		mutex_init(&ctx->sbe_error_lock);
   142	
   143		ctx->sbe = pdev->dev.parent;
   144		occ = &ctx->occ;
   145		occ->bus_dev = &pdev->dev;
   146		platform_set_drvdata(pdev, occ);
   147	
   148		occ->powr_sample_time_us = 500;
   149		occ->poll_cmd_data = 0x20;		/* P9 OCC poll data */
   150		occ->send_cmd = p9_sbe_occ_send_cmd;
   151	
   152		rc = occ_setup(occ);
   153		if (rc == -ESHUTDOWN)
   154			rc = -ENODEV;	/* Host is shutdown, don't spew errors */
   155	
   156		if (!rc) {
   157			rc = device_create_bin_file(occ->bus_dev, &bin_attr_ffdc);
   158			if (rc) {
   159				dev_warn(occ->bus_dev,
   160					 "failed to create SBE error ffdc file\n");
   161				rc = 0;
   162			}
   163		}
   164	
   165		return rc;
   166	}
   167	
   168	static int p9_sbe_occ_remove(struct platform_device *pdev)
   169	{
   170		struct occ *occ = platform_get_drvdata(pdev);
   171		struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
   172	
   173		device_remove_bin_file(occ->bus_dev, &bin_attr_ffdc);
   174	
   175		ctx->sbe = NULL;
   176		occ_shutdown(occ);
   177	
   178		kvfree(ctx->ffdc);
   179	
   180		return 0;
   181	}
   182	
   183	static const struct of_device_id p9_sbe_occ_of_match[] = {
   184		{ .compatible = "ibm,p9-occ-hwmon" },
   185		{ .compatible = "ibm,p10-occ-hwmon" },
   186		{}
   187	};
 > 188	MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
   189
diff mbox series

Patch

diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index 45407b12db4b..95f16bb0e685 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -10,6 +10,7 @@ 
 #include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/property.h>
 #include <linux/sysfs.h>
 #include <asm/unaligned.h>
 
@@ -1216,8 +1217,16 @@  int occ_setup(struct occ *occ)
 	occ->groups[0] = &occ->group;
 
 	rc = occ_setup_sysfs(occ);
-	if (rc)
+	if (rc) {
 		dev_err(occ->bus_dev, "failed to setup sysfs: %d\n", rc);
+		return rc;
+	}
+
+	if (!device_property_read_bool(occ->bus_dev, "ibm,inactive-on-init")) {
+		rc = occ_active(occ, true);
+		if (rc)
+			occ_shutdown_sysfs(occ);
+	}
 
 	return rc;
 }
diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c
index 4a1fe4ee8e2c..bc0f190065aa 100644
--- a/drivers/hwmon/occ/p9_sbe.c
+++ b/drivers/hwmon/occ/p9_sbe.c
@@ -7,6 +7,7 @@ 
 #include <linux/fsi-occ.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/string.h>
@@ -179,9 +180,17 @@  static int p9_sbe_occ_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id p9_sbe_occ_of_match[] = {
+	{ .compatible = "ibm,p9-occ-hwmon" },
+	{ .compatible = "ibm,p10-occ-hwmon" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, p8_i2c_occ_of_match);
+
 static struct platform_driver p9_sbe_occ_driver = {
 	.driver = {
 		.name = "occ-hwmon",
+		.of_match_table = p9_sbe_occ_of_match,
 	},
 	.probe	= p9_sbe_occ_probe,
 	.remove = p9_sbe_occ_remove,