From patchwork Thu Dec 7 22:19:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 10101175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C90D60360 for ; Thu, 7 Dec 2017 22:20:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFDB7288DF for ; Thu, 7 Dec 2017 22:20:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD2732887F; Thu, 7 Dec 2017 22:20:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D86228879 for ; Thu, 7 Dec 2017 22:20:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752252AbdLGWT5 (ORCPT ); Thu, 7 Dec 2017 17:19:57 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39090 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752212AbdLGWTy (ORCPT ); Thu, 7 Dec 2017 17:19:54 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB7MJRGi117407 for ; Thu, 7 Dec 2017 17:19:54 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2eqb7j09ur-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 07 Dec 2017 17:19:53 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Dec 2017 17:19:49 -0500 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 7 Dec 2017 17:19:47 -0500 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB7MJkIh44892412; Thu, 7 Dec 2017 22:19:46 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E85FAE03C; Thu, 7 Dec 2017 17:20:45 -0500 (EST) Received: from oc3016140333.ibm.com (unknown [9.80.198.254]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 8E9D7AE03B; Thu, 7 Dec 2017 17:20:44 -0500 (EST) Subject: Re: [PATCH 2/2] hwmon (pmbus): cffps: Add debugfs entries To: Guenter Roeck Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, jdelvare@suse.com, mspinler@linux.vnet.ibm.com, joel@jms.id.au, "Edward A. James" References: <1512676238-8020-1-git-send-email-eajames@linux.vnet.ibm.com> <1512676238-8020-3-git-send-email-eajames@linux.vnet.ibm.com> <20171207205321.GB7736@roeck-us.net> From: Eddie James Date: Thu, 7 Dec 2017 16:19:45 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171207205321.GB7736@roeck-us.net> Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17120722-0036-0000-0000-000002984368 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008168; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00956919; UDB=6.00483766; IPR=6.00736951; BA=6.00005729; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018413; XFM=3.00000015; UTC=2017-12-07 22:19:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120722-0037-0000-0000-0000429A9EA5 Message-Id: <68d9f677-3dd7-24b3-141a-f1d49bd6bb5d@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-07_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712070326 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 12/07/2017 02:53 PM, Guenter Roeck wrote: > On Thu, Dec 07, 2017 at 01:50:38PM -0600, Eddie James wrote: >> From: "Edward A. James" >> >> Add debugfs entries for additional power supply data, including part >> number, serial number, FRU number, firmware revision, ccin, and the >> input history of the power supply. The input history is 10 minutes of >> input power data in the form of twenty 30-second packets. Each packet >> contains average and maximum power for that 30 second period. >> >> Signed-off-by: Edward A. James >> --- >> drivers/hwmon/pmbus/ibm-cffps.c | 199 +++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 198 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/hwmon/pmbus/ibm-cffps.c b/drivers/hwmon/pmbus/ibm-cffps.c >> index cb56da6..6d19399 100644 >> --- a/drivers/hwmon/pmbus/ibm-cffps.c >> +++ b/drivers/hwmon/pmbus/ibm-cffps.c >> @@ -8,12 +8,26 @@ >> */ >> >> #include >> +#include >> #include >> +#include >> #include >> +#include >> #include >> +#include >> >> #include "pmbus.h" >> >> +#define CFFPS_FRU_CMD 0x9A >> +#define CFFPS_PN_CMD 0x9B >> +#define CFFPS_SN_CMD 0x9E >> +#define CFFPS_CCIN_CMD 0xBD >> +#define CFFPS_FW_CMD_START 0xFA >> +#define CFFPS_FW_NUM_BYTES 4 >> + >> +#define CFFPS_INPUT_HISTORY_CMD 0xD6 >> +#define CFFPS_INPUT_HISTORY_SIZE 100 >> + >> /* STATUS_MFR_SPECIFIC bits */ >> #define CFFPS_MFR_FAN_FAULT BIT(0) >> #define CFFPS_MFR_THERMAL_FAULT BIT(1) >> @@ -24,6 +38,144 @@ >> #define CFFPS_MFR_VAUX_FAULT BIT(6) >> #define CFFPS_MFR_CURRENT_SHARE_WARNING BIT(7) >> >> +enum { >> + CFFPS_DEBUGFS_INPUT_HISTORY = 0, >> + CFFPS_DEBUGFS_FRU, >> + CFFPS_DEBUGFS_PN, >> + CFFPS_DEBUGFS_SN, >> + CFFPS_DEBUGFS_CCIN, >> + CFFPS_DEBUGFS_FW, >> + CFFPS_DEBUGFS_NUM_ENTRIES >> +}; >> + >> +struct ibm_cffps_input_history { >> + struct mutex update_lock; >> + unsigned long last_update; >> + >> + u8 byte_count; >> + u8 data[CFFPS_INPUT_HISTORY_SIZE]; >> +}; >> + >> +struct ibm_cffps { >> + struct i2c_client *client; >> + >> + struct ibm_cffps_input_history input_history; >> + >> + int debugfs_entries[CFFPS_DEBUGFS_NUM_ENTRIES]; >> +}; >> + >> +#define to_psu(x, y) container_of((x), struct ibm_cffps, debugfs_entries[(y)]) >> + >> +static ssize_t ibm_cffps_read_input_history(struct ibm_cffps *psu, >> + char __user *buf, size_t count, >> + loff_t *ppos) >> +{ >> + int rc; >> + u8 msgbuf0[1] = { CFFPS_INPUT_HISTORY_CMD }; >> + u8 msgbuf1[CFFPS_INPUT_HISTORY_SIZE + 1] = { 0 }; >> + struct i2c_msg msg[2] = { >> + { >> + .addr = psu->client->addr, >> + .flags = psu->client->flags, >> + .len = 1, >> + .buf = msgbuf0, >> + }, { >> + .addr = psu->client->addr, >> + .flags = psu->client->flags | I2C_M_RD, >> + .len = CFFPS_INPUT_HISTORY_SIZE + 1, >> + .buf = msgbuf1, >> + }, >> + }; >> + >> + if (!*ppos) { >> + mutex_lock(&psu->input_history.update_lock); >> + if (time_after(jiffies, psu->input_history.last_update + HZ)) { >> + /* >> + * Use a raw i2c transfer, since we need more bytes >> + * than Linux I2C supports through smbus xfr (only 32). >> + */ >> + rc = i2c_transfer(psu->client->adapter, msg, 2); >> + if (rc < 0) { >> + mutex_unlock(&psu->input_history.update_lock); >> + return rc; >> + } >> + >> + psu->input_history.byte_count = msgbuf1[0]; >> + memcpy(psu->input_history.data, &msgbuf1[1], >> + CFFPS_INPUT_HISTORY_SIZE); >> + psu->input_history.last_update = jiffies; >> + } >> + >> + mutex_unlock(&psu->input_history.update_lock); >> + } >> + >> + return simple_read_from_buffer(buf, count, ppos, >> + psu->input_history.data, >> + psu->input_history.byte_count); >> +} >> + >> +static ssize_t ibm_cffps_debugfs_op(struct file *file, char __user *buf, >> + size_t count, loff_t *ppos) >> +{ >> + u8 cmd; >> + int i, rc; >> + int *idxp = file->private_data; >> + int idx = *idxp; >> + struct ibm_cffps *psu = to_psu(idxp, idx); >> + char data[I2C_SMBUS_BLOCK_MAX] = { 0 }; >> + >> + switch (idx) { >> + case CFFPS_DEBUGFS_INPUT_HISTORY: >> + return ibm_cffps_read_input_history(psu, buf, count, ppos); >> + case CFFPS_DEBUGFS_FRU: >> + cmd = CFFPS_FRU_CMD; >> + break; >> + case CFFPS_DEBUGFS_PN: >> + cmd = CFFPS_PN_CMD; >> + break; >> + case CFFPS_DEBUGFS_SN: >> + cmd = CFFPS_SN_CMD; >> + break; >> + case CFFPS_DEBUGFS_CCIN: >> + rc = i2c_smbus_read_word_data(psu->client, CFFPS_CCIN_CMD); >> + if (rc < 0) >> + return rc; >> + >> + rc = snprintf(data, 5, "%04X", rc); >> + goto done; >> + case CFFPS_DEBUGFS_FW: >> + for (i = 0; i < CFFPS_FW_NUM_BYTES; ++i) { >> + rc = i2c_smbus_read_byte_data(psu->client, >> + CFFPS_FW_CMD_START + i); >> + if (rc < 0) >> + return rc; >> + >> + snprintf(&data[i * 2], 3, "%02X", rc); >> + } >> + >> + rc = i * 2; >> + goto done; >> + default: >> + return -EINVAL; >> + } >> + >> + rc = i2c_smbus_read_block_data(psu->client, cmd, data); >> + if (rc < 0) >> + return rc; >> + >> +done: >> + data[rc] = '\n'; >> + rc += 2; >> + >> + return simple_read_from_buffer(buf, count, ppos, data, rc); >> +} >> + >> +static const struct file_operations ibm_cffps_fops = { >> + .llseek = noop_llseek, >> + .read = ibm_cffps_debugfs_op, >> + .open = simple_open, >> +}; >> + >> static int ibm_cffps_read_byte_data(struct i2c_client *client, int page, >> int reg) >> { >> @@ -119,7 +271,52 @@ static int ibm_cffps_read_word_data(struct i2c_client *client, int page, >> static int ibm_cffps_probe(struct i2c_client *client, >> const struct i2c_device_id *id) >> { >> - return pmbus_do_probe(client, id, &ibm_cffps_info); >> + int i, rc; >> + struct dentry *debugfs; >> + struct ibm_cffps *psu; >> + >> + rc = pmbus_do_probe(client, id, &ibm_cffps_info); >> + if (rc) >> + return rc; >> + >> + /* Don't fail the probe if we can't create debugfs */ >> + psu = devm_kzalloc(&client->dev, sizeof(*psu), GFP_KERNEL); >> + if (!psu) >> + return 0; >> + >> + psu->client = client; >> + mutex_init(&psu->input_history.update_lock); >> + if (jiffies > HZ) >> + /* time_after wouldn't succeed with last_update = 0 in test */ > ... but you are setting it to 'jiffies' elsewhere, so it can still end up > being 0 at some point, especially since 'jiffies' starts with a large number > and wraps a few minutes after boot. Not sure I understand the problem, > actually. Can you elaborate ? Yea, not sure I understand it either, but basically, if we don't set last_update to jiffies - HZ or similar at start up, the check above for time_after(jiffies, last_upate + HZ) doesn't succeed soon after the boot. This doesn't make any sense to me, unless time_after is broken, but setting last_update to something relative to jiffies during probe fixes it. [  279.480000] failed time_after with jiffies[-2052] last_update[0] [  302.050000] succeeded time_after with jiffies[205] last_update[0] tested with this (should have used %u instead of %d, but you get the idea):               * Use a raw i2c transfer, since we need more bytes               * than Linux I2C supports through smbus xfr (only 32). @@ -105,6 +106,8 @@ static ssize_t ibm_cffps_read_input_history(struct ibm_cffps *psu,                     CFFPS_INPUT_HISTORY_SIZE);              psu->input_history.last_update = jiffies;          } +        else +printk("failed time_after with jiffies[%d] last_update[%d]\n", jiffies, psu->input_history.last_update);          mutex_unlock(&psu->input_history.update_lock);      } @@ -286,9 +289,6 @@ static int ibm_cffps_probe(struct i2c_client *client,      psu->client = client;      mutex_init(&psu->input_history.update_lock); -    if (jiffies > HZ) -        /* time_after wouldn't succeed with last_update = 0 in test */ -        psu->input_history.last_update = jiffies - HZ;      debugfs = pmbus_get_debugfs_dir(client);      if (!debugfs) diff --git a/drivers/hwmon/pmbus/ibm-cffps.c b/drivers/hwmon/pmbus/ibm-cffps.c index 6d19399..e5cb52a 100644 --- a/drivers/hwmon/pmbus/ibm-cffps.c +++ b/drivers/hwmon/pmbus/ibm-cffps.c @@ -90,6 +90,7 @@ static ssize_t ibm_cffps_read_input_history(struct ibm_cffps *psu,      if (!*ppos) {          mutex_lock(&psu->input_history.update_lock);          if (time_after(jiffies, psu->input_history.last_update + HZ)) { +printk("succeeded time_after with jiffies[%d] last_update[%d]\n", jiffies, psu->input_history.last_update);              /*