From patchwork Thu Mar 22 10:54:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 10301239 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 A9B8660349 for ; Thu, 22 Mar 2018 10:56:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D9AF29B34 for ; Thu, 22 Mar 2018 10:56:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8765029B36; Thu, 22 Mar 2018 10:56:38 +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 D8DA929B34 for ; Thu, 22 Mar 2018 10:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754147AbeCVK4h (ORCPT ); Thu, 22 Mar 2018 06:56:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50100 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753690AbeCVKy7 (ORCPT ); Thu, 22 Mar 2018 06:54:59 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2MAsoMH061555 for ; Thu, 22 Mar 2018 06:54:59 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gvabat7ub-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 22 Mar 2018 06:54:59 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Mar 2018 10:54:56 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 22 Mar 2018 10:54:55 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2MAss8J40632424; Thu, 22 Mar 2018 10:54:54 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD0FA42045; Thu, 22 Mar 2018 10:47:00 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77E2942042; Thu, 22 Mar 2018 10:46:59 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.124.35.246]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 22 Mar 2018 10:46:59 +0000 (GMT) From: Shilpasri G Bhat To: mpe@ellerman.id.au, linux@roeck-us.net Cc: linuxppc-dev@lists.ozlabs.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, stewart@linux.vnet.ibm.com, Shilpasri G Bhat Subject: [PATCH 2/3] hwmon: ibmpowernv: Add attributes to enable/disable sensor groups Date: Thu, 22 Mar 2018 16:24:34 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1521716075-807-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1521716075-807-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18032210-0040-0000-0000-00000425C24D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032210-0041-0000-0000-00002628CA37 Message-Id: <1521716075-807-3-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-22_06:, , 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803220131 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-Chip-Controller(OCC) is an embedded micro-processor in POWER9 chip which measures various system and chip level sensors. These sensors comprises of environmental sensors (like power, temperature, current and voltage) and performance sensors (like utilization, frequency). All these sensors are copied to main memory at a regular interval of 100ms. OCC provides a way to select a group of sensors that is copied to the main memory to increase the update frequency of selected sensor groups. When a sensor-group is disabled, OCC will not copy it to main memory and those sensors read 0 values. This patch provides support for enabling/disabling the sensor groups like power, temperature, current and voltage. This patch adds new sysfs attributes to disable and enable them. Signed-off-by: Shilpasri G Bhat --- - Should the new attributes be added to hwmon_chip_attrs[]? Documentation/hwmon/ibmpowernv | 31 +++++++++- drivers/hwmon/ibmpowernv.c | 127 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 150 insertions(+), 8 deletions(-) diff --git a/Documentation/hwmon/ibmpowernv b/Documentation/hwmon/ibmpowernv index 8826ba2..5e510fd 100644 --- a/Documentation/hwmon/ibmpowernv +++ b/Documentation/hwmon/ibmpowernv @@ -38,4 +38,33 @@ tempX_max Threshold ambient temperature for alert generation. inX_input Measured power supply voltage inX_fault 0: No fail condition. 1: Failing power supply. -power1_input System power consumption (microWatt) +powerX_input Power consumption (microWatt) +currX_input Measured current + +Sysfs attributes in POWER9 +--------------------------- + +On-Chip-Controller(OCC) copies the sensors to main memory. The +environmental sensor groups can be dynamically configured by writing +to the below sysfs files. Writing to this file configures the sensor +group update for the all the OCC chips in the system. + +power_enable Disable/enable copying of power sensors + 0: Disable + 1: Enable + RO + +in_enable Disable/enable copying of voltage sensors + 0: Disable + 1: Enable + RO + +curr_enable Disable/enable copying of current sensors + 0: Disable + 1: Enable + RO + +temp_enable Disable/enable copying of temperature sensors + 0: Disable + 1: Enable + RO diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c index 5ccdd0b..696ccbc 100644 --- a/drivers/hwmon/ibmpowernv.c +++ b/drivers/hwmon/ibmpowernv.c @@ -90,6 +90,16 @@ struct sensor_data { struct device_attribute dev_attr; }; +struct sensor_group_data { + u32 nr_ids; + u32 *id; + char name[MAX_ATTR_LEN]; + struct device_attribute dev_attr; +}; + +DEFINE_MUTEX(sensor_groups_mutex); +static int nr_sg_attr_count; + struct platform_data { const struct attribute_group *attr_groups[MAX_SENSOR_TYPE + 1]; u32 sensors_count; /* Total count of sensors from each group */ @@ -117,6 +127,42 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr, return sprintf(buf, "%u\n", x); } +static ssize_t store_enable(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + struct sensor_group_data *sdata = container_of(devattr, + struct sensor_group_data, + dev_attr); + int ret; + u32 data; + int i; + + ret = kstrtoint(buf, 0, &data); + if (ret) + return ret; + + if (data != 0 && data != 1) + return -EIO; + + ret = mutex_lock_interruptible(&sensor_groups_mutex); + if (ret) + return ret; + + for (i = 0; i < sdata->nr_ids; i++) { + ret = sensor_group_enable(sdata->id[i], data); + if (ret) { + ret = -EIO; + goto out; + } + } + + ret = count; +out: + mutex_unlock(&sensor_groups_mutex); + return ret; +} + static ssize_t show_label(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -322,6 +368,21 @@ static int populate_attr_groups(struct platform_device *pdev) of_node_put(opal); + opal = of_find_node_by_path("/ibm,opal/sensor-groups"); + for (type = 0; type < MAX_SENSOR_TYPE; type++) + for_each_child_of_node(opal, np) { + enum sensors ctype; + + ctype = get_sensor_type(np); + if (ctype == type) { + sensor_groups[ctype].attr_count++; + nr_sg_attr_count++; + break; + } + } + + of_node_put(opal); + for (type = 0; type < MAX_SENSOR_TYPE; type++) { sensor_groups[type].group.attrs = devm_kzalloc(&pdev->dev, sizeof(struct attribute *) * @@ -400,19 +461,25 @@ static int create_device_attrs(struct platform_device *pdev) const struct attribute_group **pgroups = pdata->attr_groups; struct device_node *opal, *np; struct sensor_data *sdata; + struct sensor_group_data *sgdata; u32 sensor_id; enum sensors type; u32 count = 0; int err = 0; + int nr_id[MAX_SENSOR_TYPE] = {0}; - opal = of_find_node_by_path("/ibm,opal/sensors"); - sdata = devm_kzalloc(&pdev->dev, pdata->sensors_count * sizeof(*sdata), + sdata = devm_kzalloc(&pdev->dev, (pdata->sensors_count - + nr_sg_attr_count) * sizeof(*sdata), GFP_KERNEL); - if (!sdata) { - err = -ENOMEM; - goto exit_put_node; - } + if (!sdata) + return -ENOMEM; + + sgdata = devm_kzalloc(&pdev->dev, nr_sg_attr_count * sizeof(*sgdata), + GFP_KERNEL); + if (!sgdata) + return -ENOMEM; + opal = of_find_node_by_path("/ibm,opal/sensors"); for_each_child_of_node(opal, np) { const char *attr_name; u32 opal_index; @@ -496,7 +563,53 @@ static int create_device_attrs(struct platform_device *pdev) } } -exit_put_node: + of_node_put(opal); + + opal = of_find_node_by_path("/ibm,opal/sensor-groups"); + for_each_child_of_node(opal, np) { + type = get_sensor_type(np); + if (type == MAX_SENSOR_TYPE) + continue; + nr_id[type]++; + } + + count = 0; + for (type = 0; type < MAX_SENSOR_TYPE; type++) { + int c = 0; + + if (!nr_id[type]) + continue; + + sgdata[count].nr_ids = nr_id[type]; + sgdata[count].id = devm_kzalloc(&pdev->dev, nr_id[type] * + sizeof(u32), GFP_KERNEL); + if (!sgdata[count].id) + return -ENOMEM; + + for_each_child_of_node(opal, np) { + enum sensors ctype; + + ctype = get_sensor_type(np); + if (type != ctype) + continue; + + if (of_property_read_u32(np, "sensor-group-id", + &sensor_id)) + continue; + + sgdata[count].id[c++] = sensor_id; + } + snprintf(sgdata[count].name, MAX_ATTR_LEN, "%s_enable", + sensor_groups[type].name); + sysfs_attr_init(&sgdata[count].dev_attr.attr); + sgdata[count].dev_attr.attr.name = sgdata[count].name; + sgdata[count].dev_attr.attr.mode = 00220; + sgdata[count].dev_attr.store = store_enable; + pgroups[type]->attrs[sensor_groups[type].attr_count++] = + &sgdata[count].dev_attr.attr; + count++; + } + of_node_put(opal); return err; }