drivers: hwmon: Add OCC driver
cover drivers: hwmon: Add OCC driver
From: "Edward A. James" <[email protected]>
This series adds a hwmon driver for the POWER9 OCC (haven't tested for P8 yet). The driver obtains the OCC poll response and exports all the sensor data as hwmon attributes. This driver is intended to operate on a service processor.
For the POWER9 application, the driver communicates with the OCC from a service processor using the SBE engine. The low-level transfer protocol details, however, are contained in the OCC "fifo" driver, in order to arbitrate accesses from different users on the service processor.
Edward A. James (3):
drivers: hwmon: Add P9 OCC driver
drivers: hwmon: OCC: Add common functionality and SBE access
drivers: hwmon: OCC: Add P9 sensors, hwmon attributes, and device
setup
drivers/hwmon/Kconfig | 2 + drivers/hwmon/Makefile | 1 + drivers/hwmon/occ/Kconfig | 24 ++++ drivers/hwmon/occ/Makefile | 7 + drivers/hwmon/occ/common.c | 110 ++++++++++++++ drivers/hwmon/occ/common.h | 124 ++++++++++++++++ drivers/hwmon/occ/p9.c | 350 +++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/p9.h | 17 +++ drivers/hwmon/occ/p9_sbe.c | 195 +++++++++++++++++++++++++ 9 files changed, 830 insertions(+) create mode 100644 drivers/hwmon/occ/Kconfig create mode 100644 drivers/hwmon/occ/Makefile create mode 100644 drivers/hwmon/occ/common.c create mode 100644 drivers/hwmon/occ/common.h create mode 100644 drivers/hwmon/occ/p9.c create mode 100644 drivers/hwmon/occ/p9.h create mode 100644 drivers/hwmon/occ/p9_sbe.c
Signature · 1 line
1.8.3.1
PATCH 2/3 drivers: hwmon: OCC: Add common functionality and SBE access
From: "Edward A. James" <[email protected]>
Add functions common to all POWER processors and bus transfer methods. Add the main function to actually fetch the OCC poll response via SBE.
--- drivers/hwmon/occ/common.c | 97 +++++++++++++++++++++++++++++++++++++++++++++- drivers/hwmon/occ/common.h | 10 +++++ drivers/hwmon/occ/p9_sbe.c | 82 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-)
drivers/hwmon/occ/common.c +96 -1
@@ -9,7 +9,102 @@#include "common.h" +void occ_parse_poll_response (struct occ *occ) +{ +unsigned int i, offset =0 , size =0 ; +struct occ_sensor *sensor; +struct occ_sensors *sensors = &occ->sensors; +struct occ_response *resp = &occ->resp; +struct occ_poll_response *poll = + (struct occ_poll_response *)&resp->data[0 ]; +struct occ_poll_response_header *header = &poll->header; +struct occ_sensor_data_block *block = &poll->block; + +for (i =0 ; i < header->num_sensor_data_blocks; ++i) { + block = (struct occ_sensor_data_block *)((u8 *)block + offset); + offset = (block->header.num_sensors * + block->header.sensor_length) +sizeof (block->header); + size += offset; + +/* validate all the length/size fields */ +if ((size +sizeof (*header)) >=OCC_RESP_DATA_BYTES ) { +dev_warn (occ->bus_dev,"exceeded response buffer\n" ); +return ; + } + +if (strncmp (block->header.eye_catcher,"TEMP" ,4 ) ==0 ) + sensor = &sensors->temp; +else if (strncmp (block->header.eye_catcher,"FREQ" ,4 ) ==0 ) + sensor = &sensors->freq; +else if (strncmp (block->header.eye_catcher,"POWR" ,4 ) ==0 ) + sensor = &sensors->power; +else if (strncmp (block->header.eye_catcher,"CAPS" ,4 ) ==0 ) + sensor = &sensors->caps; +else { +dev_warn (occ->bus_dev,"sensor not supported %.4s\n" , + block->header.eye_catcher); +continue ; + } + + sensor->num_sensors = block->header.num_sensors; + sensor->data = &block->data; + } +} +int occ_poll (struct occ *occ) { -return 0 ; +u16 checksum = occ->poll_cmd_data +1 ; +u8 cmd[8 ]; + + cmd[0 ] =0 ; + cmd[1 ] =0 ; + cmd[2 ] =0 ; + cmd[3 ] =1 ; + cmd[4 ] = occ->poll_cmd_data; + cmd[5 ] = checksum >>8 ; + cmd[6 ] = checksum &0xFF ; + cmd[7 ] =0 ; + +return occ->send_cmd (occ, cmd); +} + +int occ_set_user_power_cap (struct occ *occ,u16 user_power_cap) +{ +int rc; +u8 cmd[8 ]; +u16 checksum =0x24 ; + + user_power_cap =cpu_to_be16 (user_power_cap); + + cmd[0 ] =0 ; + cmd[1 ] =0x22 ; + cmd[2 ] =0 ; + cmd[3 ] =2 ; + +memcpy (&cmd[4 ], &user_power_cap,2 ); + + checksum += cmd[4 ] + cmd[5 ]; + cmd[6 ] = checksum >>8 ; + cmd[7 ] = checksum &0xFF ; + +mutex_lock (&occ->lock); + rc = occ->send_cmd (occ, cmd); +mutex_unlock (&occ->lock); + +return rc; +} + +int occ_update_response (struct occ *occ) +{ +int rc =0 ; + +mutex_lock (&occ->lock); + +if (time_after (jiffies, occ->last_update +OCC_UPDATE_FREQUENCY )) { + rc =occ_poll (occ); + occ->last_update = jiffies; + } + +mutex_unlock (&occ->lock); +return rc; }
drivers/hwmon/occ/common.h +10 -0
@@ -13,6 +13,7 @@#include <linux/hwmon-sysfs.h> #include <linux/sysfs.h> +#define OCC_UPDATE_FREQUENCY msecs_to_jiffies(1000)#define OCC_RESP_DATA_BYTES 4089struct occ_response {
@@ -75,10 +76,19 @@ struct occ_sensors {struct occ {struct device *bus_dev; +unsigned long last_update; +struct mutex lock; +struct occ_response resp;struct occ_sensors sensors; + +u8 poll_cmd_data; +int (*send_cmd)(struct occ *occ,u8 *cmd); }; +void occ_parse_poll_response (struct occ *occ);int occ_poll (struct occ *occ); +int occ_set_user_power_cap (struct occ *occ,u16 user_power_cap); +int occ_update_response (struct occ *occ);#endif /* __OCC_COMMON_H__ */
drivers/hwmon/occ/p9_sbe.c +82 -0
100 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 1/3 drivers: hwmon: Add P9 OCC driver
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Add initial probe function and common data structures. The occ-hmwon device is probed dynamically from the OCC "fifo" driver.
--- drivers/hwmon/Kconfig | 2 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/occ/Kconfig | 24 +++++++++++++ drivers/hwmon/occ/Makefile | 7 ++++ drivers/hwmon/occ/common.c | 15 +++++++++ drivers/hwmon/occ/common.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/p9_sbe.c | 60 +++++++++++++++++++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100644 drivers/hwmon/occ/Kconfig create mode 100644 drivers/hwmon/occ/Makefile create mode 100644 drivers/hwmon/occ/common.c create mode 100644 drivers/hwmon/occ/common.h create mode 100644 drivers/hwmon/occ/p9_sbe.c
drivers/hwmon/Kconfig +2 -0
@@ -1240,6 +1240,8 @@ config SENSORS_NSA320 This driver can also be built as a module. If so, the module will be called nsa320-hwmon. +source drivers/hwmon/occ/Kconfig + config SENSORS_PCF8591 tristate "Philips PCF8591 ADC/DAC" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -170,6 +170,7 @@ obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o obj-$(CONFIG_SENSORS_XGENE) += xgene-hwmon.o obj-$(CONFIG_PMBUS) += pmbus/ +obj-$(CONFIG_SENSORS_OCC) += occ/ ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
drivers/hwmon/occ/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +# +# On-Chip Controller configuration +# + +menuconfig SENSORS_OCC + tristate "POWER On-Chip Controller" + help + If you say yes here you get support for monitoring the IBM POWER + processor sensors via the On-Chip Controller (OCC). + + This driver can also be built as a module. If so, the module will be + called occ-hwmon. + +if SENSORS_OCC + +config SENSORS_OCC_P9_SBE + bool "POWER9 OCC via SBE" + depends on SBEFIFO_OCC + help + If you say yes here you get support for monitoring the POWER9 + processor sensors via the OCC, from a service processor, over SBE + engine on FSI bus. + +endif
drivers/hwmon/occ/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +occ-hwmon-objs := common.o + +ifeq ($(CONFIG_SENSORS_OCC_P9_SBE), y) +occ-hwmon-objs += p9_sbe.o +endif + +obj-$(CONFIG_SENSORS_OCC) += occ-hwmon.o
drivers/hwmon/occ/common.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright 2017 IBM Corp. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include "common.h" + +int occ_poll (struct occ *occ) +{ +return 0 ; +}
drivers/hwmon/occ/common.h new file +84 -0
84 lines not on this page · raw message
drivers/hwmon/occ/p9_sbe.c new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/3 drivers: hwmon: OCC: Add P9 sensors, hwmon attributes, and device setup
In reply to Eddie JamesFrom: "Edward A. James" <[email protected]>
Add P9 sysfs functions, sensor definitions, and hwmon attribute setup. Add device setup after probe. Use a delay to make sure SBE driver has finished setting up.
--- drivers/hwmon/occ/Makefile | 2 +- drivers/hwmon/occ/common.h | 30 ++++ drivers/hwmon/occ/p9.c | 350 +++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/p9.h | 17 +++ drivers/hwmon/occ/p9_sbe.c | 53 +++++++ 5 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 drivers/hwmon/occ/p9.c create mode 100644 drivers/hwmon/occ/p9.h
drivers/hwmon/occ/Makefile +1 -1
@@ -1,7 +1,7 @@ occ-hwmon-objs := common.o ifeq ($(CONFIG_SENSORS_OCC_P9_SBE), y) -occ-hwmon-objs += p9_sbe.o +occ-hwmon-objs += p9.o p9_sbe.o endif obj-$(CONFIG_SENSORS_OCC) += occ-hwmon.o
drivers/hwmon/occ/common.h +30 -0
@@ -73,8 +73,14 @@ struct occ_sensors {struct occ_sensor caps; }; +struct occ_attribute { +char name[32 ]; +struct sensor_device_attribute_2 sensor; +}; +struct occ {struct device *bus_dev; +struct device *hwmon;unsigned long last_update;struct mutex lock;
@@ -82,10 +88,34 @@ struct occ {struct occ_response resp;struct occ_sensors sensors; +unsigned int num_attrs; +struct occ_attribute *attrs; +struct attribute_group group; +const struct attribute_group *groups[2 ]; +u8 poll_cmd_data;int (*send_cmd)(struct occ *occ,u8 *cmd); }; +#define ATTR_OCC (_name, _mode, _show, _store) { \ + .attr = { \ + .name = _name, \ + .mode = VERIFY_OCTAL_PERMISSIONS(_mode), \ + }, \ + .show = _show, \ + .store = _store, \ +} + +#define SENSOR_ATTR_OCC (_name, _mode, _show, _store, _nr, _index) { \ + .dev_attr = ATTR_OCC(_name, _mode, _show, _store), \ + .index = _index, \ + .nr = _nr, \ +} + +#define OCC_INIT_ATTR (_name, _mode, _show, _store, _nr, _index) \ + ((struct sensor_device_attribute_2) \ + SENSOR_ATTR_OCC(_name, _mode, _show, _store, _nr, _index)) +void occ_parse_poll_response (struct occ *occ);int occ_poll (struct occ *occ);int occ_set_user_power_cap (struct occ *occ,u16 user_power_cap);
drivers/hwmon/occ/p9.c new file +350 -0
350 lines not on this page · raw message
drivers/hwmon/occ/p9.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Copyright 2017 IBM Corp. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __OCC_P9_H__ +#define __OCC_P9_H__ + +struct occ ; + +int p9_occ_setup_sensor_attrs (struct occ *occ); + +#endif /* __OCC_P9_H__ */
drivers/hwmon/occ/p9_sbe.c +53 -0
88 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 10 lines · Eddie James
From: "Edward A. James" <[email protected]>
This series adds a hwmon driver for the POWER9 OCC (haven't tested for P8 yet). The driver obtains the OCC poll response and exports all the sensor data as hwmon attributes. This driver is intended to operate on a service processor.
For the POWER9 application, the driver communicates with the OCC from a service processor using the SBE engine. The low-level transfer protocol details, however, are contained in the OCC "fifo" driver, in order to arbitrate accesses from different users on the service processor.
I have merged this series to dev-4.10. Do you have the relevant P8 bits too?
Lets sync up with Andrew on where we are at with the upstream review these drivers.
Cheers,
Joel
Quoted 28 lines
Edward A. James (3):
drivers: hwmon: Add P9 OCC driver
drivers: hwmon: OCC: Add common functionality and SBE access
drivers: hwmon: OCC: Add P9 sensors, hwmon attributes, and device
setupdrivers/hwmon/Kconfig | 2 + drivers/hwmon/Makefile | 1 + drivers/hwmon/occ/Kconfig | 24 ++++ drivers/hwmon/occ/Makefile | 7 + drivers/hwmon/occ/common.c | 110 ++++++++++++++ drivers/hwmon/occ/common.h | 124 ++++++++++++++++ drivers/hwmon/occ/p9.c | 350 +++++++++++++++++++++++++++++++++++++++++++++ drivers/hwmon/occ/p9.h | 17 +++ drivers/hwmon/occ/p9_sbe.c | 195 +++++++++++++++++++++++++ 9 files changed, 830 insertions(+) create mode 100644 drivers/hwmon/occ/Kconfig create mode 100644 drivers/hwmon/occ/Makefile create mode 100644 drivers/hwmon/occ/common.c create mode 100644 drivers/hwmon/occ/common.h create mode 100644 drivers/hwmon/occ/p9.c create mode 100644 drivers/hwmon/occ/p9.h create mode 100644 drivers/hwmon/occ/p9_sbe.c--
1.8.3.1
Quoted 12 lines · Joel Stanley
Quoted 10 lines · Eddie James
Quoted 1 line
Quoted 1 line
From: "Edward A. James" <[email protected]>
This series adds a hwmon driver for the POWER9 OCC (haven't tested for P8 yet). The driver obtains the OCC poll response and exports all the sensor data as hwmon attributes. This driver is intended to operate on a service processor.
For the POWER9 application, the driver communicates with the OCC from a service processor using the SBE engine. The low-level transfer protocol details, however, are contained in the OCC "fifo" driver, in order to arbitrate accesses from different users on the service processor.
Quoted 4 lines
I have merged this series to dev-4.10. Do you have the relevant P8 bits too?
Lets sync up with Andrew on where we are at with the upstream review these drivers.
My understanding was Eddie was going to do a wholesale rework to simplify the design now that we have the bits required for P9. It sounded like some of the abstractions could be removed.
Andrew