Received: by 10.213.65.68 with SMTP id h4csp568969imn; Thu, 22 Mar 2018 03:57:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELvlODwhhOcc/Ghey0GFbetRHaZtohrt+wng8GlHkbG/TvTXDKwTKCCfNOwrbETUf6K7b9E2 X-Received: by 2002:a17:902:6c4f:: with SMTP id h15-v6mr9535080pln.33.1521716240653; Thu, 22 Mar 2018 03:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521716240; cv=none; d=google.com; s=arc-20160816; b=S4OQLK6p4+ua79M3+P1RZgD1nJMEiajdzeWVUddjwuwMdXF0rR1NKznx8BaxItjJnx vNYAcnFp8/3Ekhq4ioHvVxfD3K5+eKwQdFsVO0YDHL2NwFNSM588hXBuMOSqQMBstheB z+rO/x01bELZW5WGWrSRCzB1qhIfv6QKZoWFyvnyUlyZHa4l9UGmxQJBOrM9A5a8Dnub jPqykVoVEMmfYPZNyUzBwd1gkOZD0FyPseXE+2fUM/pEFlYcabyzlQ87fQjRC3navNcC fbpfMiCVqs4amY+1a9UNmznvDA59+z/ma1iZHTdxabA3avTotQaMpCsHERh7xXxlv0Qw tWJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=2WX6IwHk/bNLyjWnZG2baeYhCe73JIVk8aR+zkHwtVg=; b=L54sRRBhWvIzVSo349i4CpSh13sdgZ2ImsNiLgU5NuGpIXIbKqHmC1C6SEGbD8Q0ZS C091KqXm8rw6RynP9rWer9qOayyGLDSTIiNNrxc3qwSkthDabc6xfs0vAdWIOOOQUV4u Hhb14zMPZej3NEPPpkRj4lTAXxvAKFD78SizIqr/t9RVEWoA9wfh3y/DncpMcGfVAMGH SkJOndmhn+CKsK/iXUw96RSHKg9z6A+bLu9aeG5jqTJSlsU42FYJ2zVu/tgLcnZ/7QK/ HU2RxDNMNBKQ9kDGqCO4uVDFsFxm7tRuyfuq7FO4Jg9ICyjFtJ09uFF9xXr+gm0ytgzq Xk0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si4187737pgp.438.2018.03.22.03.57.05; Thu, 22 Mar 2018 03:57:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754116AbeCVKzH (ORCPT + 99 others); Thu, 22 Mar 2018 06:55:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39100 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753649AbeCVKzC (ORCPT ); Thu, 22 Mar 2018 06:55:02 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2MAsqQk005090 for ; Thu, 22 Mar 2018 06:55:01 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gva67amn4-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 22 Mar 2018 06:55:01 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 1.8.3.1