2018-05-07 10:28:57

by Shilpasri G Bhat

[permalink] [raw]
Subject: [PATCH 0/3] Add support for energy sensors

This patch series provides support for adding energy sensors to
ibmpowernv-hwmon driver. This patch adds support to read 64bit
sensor values.

Shilpasri G Bhat (3):
powernv: opal-sensor: Add support to read 64bit sensor values
hwmon: (ibmpowernv): Add support to read 64 bit sensors
hwmon: (ibmpowernv) Add energy sensors

arch/powerpc/include/asm/opal-api.h | 1 +
arch/powerpc/include/asm/opal.h | 2 +
arch/powerpc/platforms/powernv/opal-sensor.c | 53 ++++++++++++++++++++++++++
arch/powerpc/platforms/powernv/opal-wrappers.S | 1 +
drivers/hwmon/ibmpowernv.c | 9 +++--
5 files changed, 63 insertions(+), 3 deletions(-)

--
1.8.3.1



2018-05-07 10:26:30

by Shilpasri G Bhat

[permalink] [raw]
Subject: [PATCH 1/3] powernv: opal-sensor: Add support to read 64bit sensor values

This patch adds support to read 64-bit sensor values. This method is
used to read energy sensors and counters which are of type u64.

Signed-off-by: Shilpasri G Bhat <[email protected]>
---
arch/powerpc/include/asm/opal-api.h | 1 +
arch/powerpc/include/asm/opal.h | 2 +
arch/powerpc/platforms/powernv/opal-sensor.c | 53 ++++++++++++++++++++++++++
arch/powerpc/platforms/powernv/opal-wrappers.S | 1 +
4 files changed, 57 insertions(+)

diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h
index d886a5b..f34d173 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -204,6 +204,7 @@
#define OPAL_NPU_SPA_SETUP 159
#define OPAL_NPU_SPA_CLEAR_CACHE 160
#define OPAL_NPU_TL_SET 161
+#define OPAL_SENSOR_READ_U64 162
#define OPAL_PCI_GET_PBCQ_TUNNEL_BAR 164
#define OPAL_PCI_SET_PBCQ_TUNNEL_BAR 165
#define OPAL_LAST 165
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 03e1a92..3960def 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -201,6 +201,7 @@ int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
uint64_t length);
int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
+int64_t opal_sensor_read_u64(u32 sensor_hndl, int token, __be64 *sensor_data);
int64_t opal_handle_hmi(void);
int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
int64_t opal_unregister_dump_region(uint32_t id);
@@ -323,6 +324,7 @@ extern int opal_message_notifier_unregister(enum opal_msg_type msg_type,
extern int opal_async_wait_response_interruptible(uint64_t token,
struct opal_msg *msg);
extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
+extern int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data);

struct rtc_time;
extern unsigned long opal_get_boot_time(void);
diff --git a/arch/powerpc/platforms/powernv/opal-sensor.c b/arch/powerpc/platforms/powernv/opal-sensor.c
index 0a7074b..35a5f4b 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -72,6 +72,59 @@ int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
}
EXPORT_SYMBOL_GPL(opal_get_sensor_data);

+int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data)
+{
+ int ret, token;
+ struct opal_msg msg;
+ __be64 data;
+
+ if (!opal_check_token(OPAL_SENSOR_READ_U64)) {
+ u32 sdata;
+
+ ret = opal_get_sensor_data(sensor_hndl, &sdata);
+ if (!ret)
+ *sensor_data = sdata;
+ return ret;
+ }
+
+ token = opal_async_get_token_interruptible();
+ if (token < 0)
+ return token;
+
+ ret = opal_sensor_read_u64(sensor_hndl, token, &data);
+ switch (ret) {
+ case OPAL_ASYNC_COMPLETION:
+ ret = opal_async_wait_response(token, &msg);
+ if (ret) {
+ pr_err("%s: Failed to wait for the async response, %d\n",
+ __func__, ret);
+ goto out_token;
+ }
+
+ ret = opal_error_code(opal_get_async_rc(msg));
+ *sensor_data = be64_to_cpu(data);
+ break;
+
+ case OPAL_SUCCESS:
+ ret = 0;
+ *sensor_data = be64_to_cpu(data);
+ break;
+
+ case OPAL_WRONG_STATE:
+ ret = -EIO;
+ break;
+
+ default:
+ ret = opal_error_code(ret);
+ break;
+ }
+
+out_token:
+ opal_async_release_token(token);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(opal_get_sensor_data_u64);
+
int __init opal_sensor_init(void)
{
struct platform_device *pdev;
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S
index 3da30c2..8482df2 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -325,3 +325,4 @@ OPAL_CALL(opal_npu_spa_clear_cache, OPAL_NPU_SPA_CLEAR_CACHE);
OPAL_CALL(opal_npu_tl_set, OPAL_NPU_TL_SET);
OPAL_CALL(opal_pci_get_pbcq_tunnel_bar, OPAL_PCI_GET_PBCQ_TUNNEL_BAR);
OPAL_CALL(opal_pci_set_pbcq_tunnel_bar, OPAL_PCI_SET_PBCQ_TUNNEL_BAR);
+OPAL_CALL(opal_sensor_read_u64, OPAL_SENSOR_READ_U64);
--
1.8.3.1


2018-05-07 10:26:31

by Shilpasri G Bhat

[permalink] [raw]
Subject: [PATCH 3/3] hwmon: (ibmpowernv) Add energy sensors

This patch exports the accumulated power numbers of each power
sensor maintained by OCC.

Signed-off-by: Shilpasri G Bhat <[email protected]>
---
drivers/hwmon/ibmpowernv.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index 74d9b5a..0298745 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -51,6 +51,7 @@ enum sensors {
POWER_SUPPLY,
POWER_INPUT,
CURRENT,
+ ENERGY,
MAX_SENSOR_TYPE,
};

@@ -78,6 +79,7 @@ enum sensors {
{ "in" },
{ "power" },
{ "curr" },
+ { "energy" },
};

struct sensor_data {
--
1.8.3.1


2018-05-07 10:27:28

by Shilpasri G Bhat

[permalink] [raw]
Subject: [PATCH 2/3] hwmon: (ibmpowernv): Add support to read 64 bit sensors

The firmware has supported for reading sensor values of size u32.
This patch adds support to use newer firmware functions which allows
to read the sensors of size u64.

Signed-off-by: Shilpasri G Bhat <[email protected]>
---
drivers/hwmon/ibmpowernv.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index 5ccdd0b..74d9b5a 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -101,9 +101,10 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
struct sensor_data *sdata = container_of(devattr, struct sensor_data,
dev_attr);
ssize_t ret;
- u32 x;
+ u64 x;
+
+ ret = opal_get_sensor_data_u64(sdata->id, &x);

- ret = opal_get_sensor_data(sdata->id, &x);
if (ret)
return ret;

@@ -114,7 +115,7 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
else if (sdata->type == POWER_INPUT)
x *= 1000000;

- return sprintf(buf, "%u\n", x);
+ return sprintf(buf, "%llu\n", x);
}

static ssize_t show_label(struct device *dev, struct device_attribute *devattr,
--
1.8.3.1


2018-05-09 17:32:19

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/3] hwmon: (ibmpowernv): Add support to read 64 bit sensors

On Mon, May 07, 2018 at 03:55:37PM +0530, Shilpasri G Bhat wrote:
> The firmware has supported for reading sensor values of size u32.
> This patch adds support to use newer firmware functions which allows
> to read the sensors of size u64.
>
> Signed-off-by: Shilpasri G Bhat <[email protected]>

Acked-by: Guenter Roeck <[email protected]>

I won't apply for the time being since it depends on patch 1/3 which is
outside hwmon.

> ---
> drivers/hwmon/ibmpowernv.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
> index 5ccdd0b..74d9b5a 100644
> --- a/drivers/hwmon/ibmpowernv.c
> +++ b/drivers/hwmon/ibmpowernv.c
> @@ -101,9 +101,10 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
> struct sensor_data *sdata = container_of(devattr, struct sensor_data,
> dev_attr);
> ssize_t ret;
> - u32 x;
> + u64 x;
> +
> + ret = opal_get_sensor_data_u64(sdata->id, &x);
>
> - ret = opal_get_sensor_data(sdata->id, &x);
> if (ret)
> return ret;
>
> @@ -114,7 +115,7 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
> else if (sdata->type == POWER_INPUT)
> x *= 1000000;
>
> - return sprintf(buf, "%u\n", x);
> + return sprintf(buf, "%llu\n", x);
> }
>
> static ssize_t show_label(struct device *dev, struct device_attribute *devattr,
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2018-05-09 17:33:44

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 3/3] hwmon: (ibmpowernv) Add energy sensors

On Mon, May 07, 2018 at 03:55:38PM +0530, Shilpasri G Bhat wrote:
> This patch exports the accumulated power numbers of each power
> sensor maintained by OCC.
>
> Signed-off-by: Shilpasri G Bhat <[email protected]>

Acked-by: Guenter Roeck <[email protected]>

> ---
> drivers/hwmon/ibmpowernv.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
> index 74d9b5a..0298745 100644
> --- a/drivers/hwmon/ibmpowernv.c
> +++ b/drivers/hwmon/ibmpowernv.c
> @@ -51,6 +51,7 @@ enum sensors {
> POWER_SUPPLY,
> POWER_INPUT,
> CURRENT,
> + ENERGY,
> MAX_SENSOR_TYPE,
> };
>
> @@ -78,6 +79,7 @@ enum sensors {
> { "in" },
> { "power" },
> { "curr" },
> + { "energy" },
> };
>
> struct sensor_data {
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2018-05-14 07:12:46

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH 2/3] hwmon: (ibmpowernv): Add support to read 64 bit sensors

Guenter Roeck <[email protected]> writes:

> On Mon, May 07, 2018 at 03:55:37PM +0530, Shilpasri G Bhat wrote:
>> The firmware has supported for reading sensor values of size u32.
>> This patch adds support to use newer firmware functions which allows
>> to read the sensors of size u64.
>>
>> Signed-off-by: Shilpasri G Bhat <[email protected]>
>
> Acked-by: Guenter Roeck <[email protected]>
>
> I won't apply for the time being since it depends on patch 1/3 which is
> outside hwmon.

Do you mind if I take the series via the powerpc tree?

cheers

2018-05-14 10:36:18

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/3] hwmon: (ibmpowernv): Add support to read 64 bit sensors

On 05/14/2018 12:11 AM, Michael Ellerman wrote:
> Guenter Roeck <[email protected]> writes:
>
>> On Mon, May 07, 2018 at 03:55:37PM +0530, Shilpasri G Bhat wrote:
>>> The firmware has supported for reading sensor values of size u32.
>>> This patch adds support to use newer firmware functions which allows
>>> to read the sensors of size u64.
>>>
>>> Signed-off-by: Shilpasri G Bhat <[email protected]>
>>
>> Acked-by: Guenter Roeck <[email protected]>
>>
>> I won't apply for the time being since it depends on patch 1/3 which is
>> outside hwmon.
>
> Do you mind if I take the series via the powerpc tree?
>

Fine with me.

Guenter


2018-05-25 11:42:50

by Michael Ellerman

[permalink] [raw]
Subject: Re: [3/3] hwmon: (ibmpowernv) Add energy sensors

On Mon, 2018-05-07 at 10:25:38 UTC, Shilpasri G Bhat wrote:
> This patch exports the accumulated power numbers of each power
> sensor maintained by OCC.
>
> Signed-off-by: Shilpasri G Bhat <[email protected]>
> Acked-by: Guenter Roeck <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/43d2974b66d916a6df16e536da542e

cheers

2018-05-25 11:43:46

by Michael Ellerman

[permalink] [raw]
Subject: Re: [1/3] powernv: opal-sensor: Add support to read 64bit sensor values

On Mon, 2018-05-07 at 10:25:36 UTC, Shilpasri G Bhat wrote:
> This patch adds support to read 64-bit sensor values. This method is
> used to read energy sensors and counters which are of type u64.
>
> Signed-off-by: Shilpasri G Bhat <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/5cdcb01e0af5a709c9bebe0e0450dc

cheers

2018-05-25 11:43:58

by Michael Ellerman

[permalink] [raw]
Subject: Re: [2/3] hwmon: (ibmpowernv): Add support to read 64 bit sensors

On Mon, 2018-05-07 at 10:25:37 UTC, Shilpasri G Bhat wrote:
> The firmware has supported for reading sensor values of size u32.
> This patch adds support to use newer firmware functions which allows
> to read the sensors of size u64.
>
> Signed-off-by: Shilpasri G Bhat <[email protected]>
> Acked-by: Guenter Roeck <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/3c8c049aa7bdffaab2e53401fd5270

cheers