Received: by 10.213.65.68 with SMTP id h4csp568931imn; Thu, 22 Mar 2018 03:57:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELua0Bt+bRSFiu/+8JybS6vjhrnfxnQeVuFZVwarN+8RWA8oALpREp5UmfAEi8DjcyI32s29 X-Received: by 10.101.65.195 with SMTP id b3mr15687981pgq.118.1521716235405; Thu, 22 Mar 2018 03:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521716235; cv=none; d=google.com; s=arc-20160816; b=oi267uGVwHId/l6TlpUflfncku68FMnvF4lP4F4qjSSb4LT1fkZMnyMbO85QHt1jXJ rqMoDh/djvX4EBjvmZX5Ud93kYqSG7IuuFFjW/IZcHLXy867774feI/g9zk/18iTgAJJ Anl//puRxDDR1mwErqWo3nmcUZE2OE/Dyj15/gmYk2n13ThMaI1YfMvyEVaUlOp63m/c ymHMmidks1I8uy73LSfkWraNonevPoN8fpVhkh1OGjaJ5RRTdrKGHx3d2cW6Gig+n9HR zlrkbrNnF+qBh2QPlhy9kpucM6PauXy9YtIiKwXSKZvsFkEzhaIvw100mWyN/33GUTW7 9wqA== 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=UO2cXFq2zKIhpNZmv2RsLoxi9XcU6L+Ux1qCHeb4NyI=; b=BYNlEbrFLuwbcFeKsQfpR70IcbkKyh9xBQ5Mwq9CSD16NG0rVQtFqXXJgLFLM05plW gXWVwoAilPrxeim+cH6YP6b358B/3fRgNVY9VwRRnQUmzK92AXNh/AgL/dSPA50EsrfX 1ONFRx92hpcPbkZstUGQ88tkuH6gDD76SvLf7iYA4B3Vs+LIpxsEq+rYGvWAgeN1QCNw vagr7V1+eUic25CMwQAeF5ReaAk19L2/eNa6CzP34kflOu4e8J43mF9ejxM/f+zmr5lU wMFQrrO7UZ1vhFSApe6+RvbsgHyoMpC4u8iQ+RH2DAjlBFTlR6UA/1GbPlWgKhcPnMpe H5/w== 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 e22-v6si5003733plj.494.2018.03.22.03.57.01; Thu, 22 Mar 2018 03:57:15 -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 S1754514AbeCVKzM (ORCPT + 99 others); Thu, 22 Mar 2018 06:55:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39124 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753653AbeCVKzC (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 w2MAsrGg005163 for ; Thu, 22 Mar 2018 06:55:02 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gva67ampu-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 22 Mar 2018 06:55:01 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Mar 2018 10:54:59 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 22 Mar 2018 10:54:57 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2MAsvOP56623180; Thu, 22 Mar 2018 10:54:57 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73E3C42049; Thu, 22 Mar 2018 10:47:03 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2870642047; Thu, 22 Mar 2018 10:47:02 +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:47:01 +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 3/3] powernv: opal-sensor-groups: Add attributes to disable/enable sensors Date: Thu, 22 Mar 2018 16:24:35 +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-0008-0000-0000-000004E11FAA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18032210-0009-0000-0000-00001E7446D4 Message-Id: <1521716075-807-4-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 This patch provides support to disable and enable plaform specific sensor groups like performance, utilization and frequency. Signed-off-by: Shilpasri G Bhat --- .../ABI/testing/sysfs-firmware-opal-sensor-groups | 34 +++++++++ .../powerpc/platforms/powernv/opal-sensor-groups.c | 80 +++++++++++++--------- 2 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-opal-sensor-groups diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-sensor-groups b/Documentation/ABI/testing/sysfs-firmware-opal-sensor-groups new file mode 100644 index 0000000..484ff1c --- /dev/null +++ b/Documentation/ABI/testing/sysfs-firmware-opal-sensor-groups @@ -0,0 +1,34 @@ +What: /sys/firmware/opal/sensor_groups +Date: March 2018 +Contact: Linux for PowerPC mailing list +Description: Sensor groups directory for POWER9 powernv servers + + Each folder in this directory contains a sensor group + which are classified based on type of the sensor + like power, temperature, frequency, current, etc. They + can also indicate the group of sensors belonging to + different owners like CSM, Profiler, Job-Scheduler + +What: /sys/firmware/opal/sensor_groups//clear +Date: March 2018 +Contact: Linux for PowerPC mailing list +Description: Sysfs file to clear the min-max of all the sensors + belonging to the group. + + Writing 1 to this file will clear the minimum and + maximum values of all the sensors in the group. The + min-max of a sensor is the historical minimum and + maximum value of the sensor cached by OCC. + +What: /sys/firmware/opal/sensor_groups//enable +Date: March 2018 +Contact: Linux for PowerPC mailing list +Description: Sysfs file to enable/disable the sensor-group + + Writing 0 value to this file will disable the copying + of the sensor-group to main memory by OCC. And writing + 1 to this file will enable the sensor-group copying. + By default all the sensor-groups are enabled and will + be copied to main memory. This file can be used to + increase the update frequency of selective + sensor-groups. diff --git a/arch/powerpc/platforms/powernv/opal-sensor-groups.c b/arch/powerpc/platforms/powernv/opal-sensor-groups.c index 5b53f58..67f28b2 100644 --- a/arch/powerpc/platforms/powernv/opal-sensor-groups.c +++ b/arch/powerpc/platforms/powernv/opal-sensor-groups.c @@ -24,6 +24,7 @@ struct sg_attr { u32 handle; struct kobj_attribute attr; + u32 opal_no; }; static struct sensor_group { @@ -60,34 +61,17 @@ int sensor_group_enable(u32 handle, bool enable) } EXPORT_SYMBOL_GPL(sensor_group_enable); -static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count) +static int sensor_group_clear(u32 handle) { - struct sg_attr *sattr = container_of(attr, struct sg_attr, attr); struct opal_msg msg; - u32 data; - int ret, token; - - ret = kstrtoint(buf, 0, &data); - if (ret) - return ret; - - if (data != 1) - return -EINVAL; + int token, ret; token = opal_async_get_token_interruptible(); - if (token < 0) { - pr_devel("Failed to get token\n"); + if (token < 0) return token; - } - ret = mutex_lock_interruptible(&sg_mutex); - if (ret) - goto out_token; - - ret = opal_sensor_group_clear(sattr->handle, token); - switch (ret) { - case OPAL_ASYNC_COMPLETION: + ret = opal_sensor_group_clear(handle, token); + if (ret == OPAL_ASYNC_COMPLETION) { ret = opal_async_wait_response(token, &msg); if (ret) { pr_devel("Failed to wait for the async response\n"); @@ -95,20 +79,48 @@ static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr, goto out; } ret = opal_error_code(opal_get_async_rc(msg)); - if (!ret) - ret = count; + } else { + ret = opal_error_code(ret); + } + +out: + opal_async_release_token(token); + return ret; +} + +static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct sg_attr *sattr = container_of(attr, struct sg_attr, attr); + u32 data; + int ret; + + ret = kstrtoint(buf, 0, &data); + if (ret) + return ret; + + ret = mutex_lock_interruptible(&sg_mutex); + if (ret) + return ret; + + ret = -EINVAL; + switch (sattr->opal_no) { + case OPAL_SENSOR_GROUP_CLEAR: + if (data == 1) + ret = sensor_group_clear(sattr->handle); break; - case OPAL_SUCCESS: - ret = count; + case OPAL_SENSOR_GROUP_ENABLE: + if (data == 0 || data == 1) + ret = sensor_group_enable(sattr->handle, data); break; default: - ret = opal_error_code(ret); + break; } -out: + if (!ret) + ret = count; + mutex_unlock(&sg_mutex); -out_token: - opal_async_release_token(token); return ret; } @@ -118,12 +130,14 @@ static ssize_t sg_store(struct kobject *kobj, struct kobj_attribute *attr, ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count); } ops_info[] = { - { OPAL_SENSOR_GROUP_CLEAR, "clear", sg_store }, + { OPAL_SENSOR_GROUP_CLEAR, "clear", sg_store}, + { OPAL_SENSOR_GROUP_ENABLE, "enable", sg_store}, }; static void add_attr(int handle, struct sg_attr *attr, int index) { attr->handle = handle; + attr->opal_no = ops_info[index].opal_no; sysfs_attr_init(&attr->attr.attr); attr->attr.attr.name = ops_info[index].attr_name; attr->attr.attr.mode = 0220; @@ -186,6 +200,10 @@ void __init opal_sensor_groups_init(void) const __be32 *ops; u32 sgid, len, nr_attrs, chipid; + /* Skip sensor groups that are handled in HWMON */ + if (of_device_is_compatible(node, "ibm,opal-sensor")) + continue; + ops = of_get_property(node, "ops", &len); if (!ops) continue; -- 1.8.3.1