Add support PECI and PECI hwmon drivers
Subsystems (5)
cover Add support PECI and PECI hwmon drivers
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic peci.h and peci_ioctl.h headers to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.
The misc peci driver can be used as a multi-purpose PECI controller driver which serializes all PECI transactions that coming from user space and from other kernel modules. This misc peci driver could be replaced with other BMC chipsets' implementation if the implementation provide compatible 'peci_ioctl' inter-module call and ioctl scheme defined in peci.h and peci_ioctl.h files.
The hwmon peci driver implements a generic PECI hwmon feature which is running with a PECI misc driver supports compatible native PECI command suite for retrieving temperatures of the CPU package, CPU cores and DIMM components.
Please review.
-Jae
Jae Hyun Yoo (6):
Documentation: dt-bindings: Add Aspeed PECI
ARM: dts: aspeed: peci: Add Aspeed PECI
drivers/misc: Add driver for Aspeed PECI and generic PECI headers
Documentation: dt-bindings: Add a generic PECI hwmon
Documentation: hwmon: Add a generic PECI hwmon drivers/hwmon: Add a driver for a generic PECI hwmon
.../devicetree/bindings/hwmon/peci-hwmon.txt | 33 + .../devicetree/bindings/misc/aspeed-peci.txt | 55 + Documentation/hwmon/peci-hwmon | 74 ++ arch/arm/boot/dts/aspeed-g4.dtsi | 14 + arch/arm/boot/dts/aspeed-g5.dtsi | 14 + drivers/hwmon/Kconfig | 6 + drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-hwmon.c | 953 +++++++++++++++++ drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/aspeed-peci.c | 1130 ++++++++++++++++++++ include/misc/peci.h | 11 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/peci_ioctl.h | 270 +++++ 14 files changed, 2572 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/peci-hwmon.txt create mode 100644 Documentation/devicetree/bindings/misc/aspeed-peci.txt create mode 100644 Documentation/hwmon/peci-hwmon create mode 100644 drivers/hwmon/peci-hwmon.c create mode 100644 drivers/misc/aspeed-peci.c create mode 100644 include/misc/peci.h create mode 100644 include/uapi/linux/peci_ioctl.h
Signature · 1 line
2.7.4
PATCH 1/6 Documentation: dt-bindings: Add Aspeed PECI
This commit adds a dt-bindings document for Aspeed PECI.
--- .../devicetree/bindings/misc/aspeed-peci.txt | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/aspeed-peci.txt
Documentation/devicetree/bindings/misc/aspeed-peci.txt new file +55 -0
@@ -0,0 +1,55 @@ +* ASPEED PECI (Platform Environment Control Interface) misc driver. + +Hardware Interfaces: +- This driver implements support for the ASPEED AST2400/2500 PECI which has the + following features: + - Directly connected to APB bus + - Intel PECI 3.1 compliant (PECI 3.0 for AST2400) + - Maximum packet length is 256 bytes (Baseline transmission unit) + - Support up to 8 CPUs and 2 domains per CPU + - Integrate PECI compliant I/O buffers, can connect to PECI bus directly + - Transmit buffer 32 bytes and receive buffer 32 bytes + +Required properties: +- compatible: "aspeed,ast2400-peci" or "aspeed,ast2500-peci" + - aspeed,ast2400-peci: Aspeed AST2400 family PECI control interface + - aspeed,ast2500-peci: Aspeed AST2500 family PECI control interface +- reg: Should contain PECI registers location and length +- interrupts: Should contain PECI interrupt +- clocks: Should contain clock source. = <&clk_clkin>; +- clock_frequency: Should contain the operation frequency of PECI controller. + 187500 ~ 24000000 + +Optional properties: +- msg-timing-nego: Message timing negotiation period. + This value will determine the period of message timing negotiation to be + issued by PECI controller. The unit of the programmed value is four + times of PECI clock period. + 0 ~ 255 (default: 1) +- addr-timing-nego: Address timing negotiation period. + This value will determine the period of address timing negotiation to be + issued by PECI controller. The unit of the programmed value is four + times of PECI clock period. + 0 ~ 255 (default: 1) +- rd-sampling-point: Read sampling point selection. + The whole period of a bit time will be divided into 16 time frames. + This value will determine which time frame this controller will sample + PECI signal for data read back. Usually in the middle of a bit time is + the best. + 0 ~ 15 (default: 8) +- cmd_timeout_ms: Command timeout in units of ms + 1 ~ 60000 (default: 1000) + +Example: + peci: peci at 1e78b000 { + compatible = "aspeed,ast2500-peci"; + reg = <0x1e78b000 0x60>; + interrupt-controller; + interrupts = <15>; + clocks = <&clk_clkin>; + clock-frequency = <24000000>; + msg-timing-nego = <1>; + addr-timing-nego = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + };
Signature · 1 line
2.7.4
PATCH 2/6 ARM: dts: aspeed: peci: Add Aspeed PECI
In reply to Jae Hyun YooThis commit adds Aspeed PECI node into aspeed-g4 and aspeed-g5.
--- arch/arm/boot/dts/aspeed-g4.dtsi | 14 ++++++++++++++ arch/arm/boot/dts/aspeed-g5.dtsi | 14 ++++++++++++++ 2 files changed, 28 insertions(+)
arch/arm/boot/dts/aspeed-g4.dtsi +14 -0
@@ -238,6 +238,20 @@ clocks = <&clk_hpll>; }; + peci: peci at 1e78b000 { + compatible = "aspeed,ast2400-peci"; + reg = <0x1e78b000 0x60>; + interrupt-controller; + interrupts = <15>; + clocks = <&clk_clkin>; + clock-frequency = <24000000>; + msg-timing-nego = <1>; + addr-timing-nego = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + status = "disabled"; + }; + sgpio: gpio at 0x1e780200 { #gpio-cells = <2>; gpio-controller;
arch/arm/boot/dts/aspeed-g5.dtsi +14 -0
@@ -289,6 +289,20 @@ clocks = <&clk_hpll>; }; + peci: peci at 1e78b000 { + compatible = "aspeed,ast2500-peci"; + reg = <0x1e78b000 0x60>; + interrupt-controller; + interrupts = <15>; + clocks = <&clk_clkin>; + clock-frequency = <24000000>; + msg-timing-nego = <1>; + addr-timing-nego = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + status = "disabled"; + }; + timer: timer at 1e782000 { compatible = "aspeed,ast2400-timer"; reg = <0x1e782000 0x90>;
Signature · 1 line
2.7.4
PATCH 3/6 drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Jae Hyun YooThis commit adds driver implementation for Aspeed PECI. Also adds generic peci.h and peci_ioctl.h files to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.
--- drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/aspeed-peci.c | 1130 +++++++++++++++++++++++++++++++++++++++ include/misc/peci.h | 11 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/peci_ioctl.h | 270 ++++++++++ 6 files changed, 1422 insertions(+) create mode 100644 drivers/misc/aspeed-peci.c create mode 100644 include/misc/peci.h create mode 100644 include/uapi/linux/peci_ioctl.h
drivers/misc/Kconfig +9 -0
@@ -782,6 +782,15 @@ config ASPEED_LPC_SNOOP allows the BMC to listen on and save the data written by the host to an arbitrary LPC I/O port. +config ASPEED_PECI + tristate "Aspeed AST2400/AST2500 PECI support" + select CRC8 + select REGMAP_MMIO + depends on ARCH_ASPEED || COMPILE_TEST + help + Provides a driver for Platform Environment Control Interface (PECI) + controller on Aspeed AST2400/AST2500 SoC. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_CXL_BASE) += cxl/ obj-$(CONFIG_PANEL) += panel.o obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o +obj-$(CONFIG_ASPEED_PECI) += aspeed-peci.o lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
drivers/misc/aspeed-peci.c new file +1130 -0
1,130 lines not on this page · raw message
include/misc/peci.h new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#ifndef __PECI_H +#define __PECI_H + +#include <linux/peci_ioctl.h> + +long peci_ioctl (struct file *filp,unsigned int cmd,unsigned long arg); + +#endif /* __PECI_H */
include/uapi/linux/Kbuild +1 -0
@@ -327,6 +327,7 @@ header-y += packet_diag.h header-y += param.h header-y += parport.h header-y += patchkey.h +header-y += peci_ioctl.h header-y += pci.h header-y += pci_regs.h header-y += perf_event.h
include/uapi/linux/peci_ioctl.h new file +270 -0
270 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/6 Documentation: dt-bindings: Add a generic PECI hwmon
In reply to Jae Hyun YooThis commit add a dt-bindings document for a generic PECI hwmon driver.
--- .../devicetree/bindings/hwmon/peci-hwmon.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/peci-hwmon.txt
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +33 -0
@@ -0,0 +1,33 @@ +* Generic PECI (Platform Environment Control Interface) hwmon driver. + +Dependency: +- This driver uses a PECI misc driver as a controller interface so one of PECI + misc drivers which provides compatible ioctls has to be enabled. + +Required properties: +- compatible: "peci-hwmon" +- cpu-id: Should contain CPU socket ID + - 0 ~ 7 + +Optional properties: +- show-core: If this protperty is defined, core tmeperature attrubites will be + enumerated. +- dimm-nums: Should contain the number of DIMM slots that attached to each CPU + which is indicated by cpu-id. + 0 ~ 16 (default: 16) + In case of 0, DIMM temperature attrubites will not be enumerated. + +Example: + peci-hwmon0 { + compatible = "peci-hwmon"; + cpu-id = <0>; + show-core; + dimm-nums = <16>; + }; + + peci-hwmon1 { + compatible = "peci-hwmon"; + cpu-id = <1>; + show-core; + dimm-nums = <16>; + };
Signature · 1 line
2.7.4
PATCH 5/6 Documentation: hwmon: Add a generic PECI hwmon
In reply to Jae Hyun YooFrom: Jae Hyun Yoo <[email protected]>
This commit add a document for a generic PECI hwmon driver.
--- Documentation/hwmon/peci-hwmon | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/hwmon/peci-hwmon
Documentation/hwmon/peci-hwmon new file +74 -0
@@ -0,0 +1,74 @@ +Kernel driver peci-hwmon +=============================== + +Supported chips: + Generic BMC chips provide PECI controller + +Author: + Jae Hyun Yoo <[email protected]> + + +Hardware Interfaces +------------------- + +This driver uses a PECI misc driver as a controller interface so one of PECI +misc drivers which provides compatible ioctls has to be enabled. + + +Description +----------- + +This driver implements a generic PECI hwmon feature which is running with a PECI +controller driver supports native PECI Client Command Suite for retrieving +temperatures of the CPU package, CPU cores and DIMM components. + +All temperature values are given in millidegree Celsius and will be measurable +only when the target CPU is powered on. + + +sysfs files +----------- + +temp1_input Provides current die temperature of the CPU package. +temp1_max Provides thermal control temperature of the CPU package + which is also known as Tcontrol. +temp1_crit Provides shutdown temperature of the CPU package which + is also known as the maximum processor junction + temperature, Tjmax or Tprochot. +temp1_crit_hyst Provides the hysteresis value from Tcontrol to Tjmax of + the CPU package. + +temp2_input Provides current DTS thermal margin to Tcontrol of the + CPU package. Value 0 means it reaches to Tcontrol + temperature. Sub-zero value means the die temperature + goes across Tconrtol to Tjmax. +temp2_min Provides the minimum DTS thermal margin to Tcontrol of + the CPU package. +temp2_lcrit Provides the value when the CPU package temperature + reaches to Tjmax. + +temp3_input Provides current Tcontrol temperature of the CPU + package which is also known as Fan Temperature target. + Indicates the relative value from thermal monitor trip + temperature at which fans should be engaged. +temp3_crit Provides Tcontrol critical value of the CPU package + which is same to Tjmax. + +temp4_input Provides current Tthrottle temperature of the CPU + package. Used for throttling temperature. If this value + is allowed and lower than Tjmax - the throttle will + occur and reported at lower than Tjmax. + +temp[100-127]_input Provides current core temperature. +temp[100-127]_max Provides thermal control temperature of the core. +temp[100-127]_crit Provides shutdown temperature of the core. +temp[100-127]_crit_hyst Provides the hysteresis value from Tcontrol to Tjmax of + the core. + +Note: + Core temperature group will be appeared when probing the driver if CPU + is online or when the first reading on other attr happens because it + needs cpu info reading. The number of generated core attrs depends on + the number of cores of the cpu package. + +temp[200-215]_input Provides current temperature of the DDR DIMM.
Signature · 1 line
2.7.4
PATCH 6/6 drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Jae Hyun YooThis commit adds driver implementation for a generic PECI hwmon.
--- drivers/hwmon/Kconfig | 6 + drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-hwmon.c | 953 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 960 insertions(+) create mode 100644 drivers/hwmon/peci-hwmon.c
drivers/hwmon/Kconfig +6 -0
@@ -1234,6 +1234,12 @@ config SENSORS_NCT7904 This driver can also be built as a module. If so, the module will be called nct7904. +config SENSORS_PECI_HWMON + tristate "PECI hwmon support" + depends on ASPEED_PECI + help + If you say yes here you get support for the generic PECI hwmon driver. + config SENSORS_NSA320 tristate "ZyXEL NSA320 and compatible fan speed and temperature sensors" depends on GPIOLIB && OF
drivers/hwmon/Makefile +1 -0
@@ -131,6 +131,7 @@ obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o obj-$(CONFIG_SENSORS_NCT7904) += nct7904.o obj-$(CONFIG_SENSORS_NSA320) += nsa320-hwmon.o obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o +obj-$(CONFIG_SENSORS_PECI_HWMON) += peci-hwmon.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
drivers/hwmon/peci-hwmon.c new file +953 -0
953 lines not on this page · raw message
Signature · 1 line
2.7.4
Greg KH
maintainerQuoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.
What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Jae Hyun YooQuoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.
We don't add code that could be used "sometime in the future". Only include stuff that we use now.
Please fix up this series based on that and resubmit. There should not be any need for any uapi file then, right?
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Jae Hyun Yooinclude/uapi/linux/peci_ioctl.h line 160
Quoted 9 lines · Jae Hyun Yoo
include/uapi/linux/peci_ioctl.h new file +9
-0+#pragma pack(push, 1) +struct peci_xfer_msg { +unsigned char client_addr; +unsigned char tx_len; +unsigned char rx_len; +unsigned char tx_buf[MAX_BUFFER_SIZE ]; +unsigned char rx_buf[MAX_BUFFER_SIZE ]; +}; +#pragma pack(pop)
For any structure that crosses the user/kernel boundry, you _HAVE_ to use the "__" variant. So for here you would use __u8 instead of "unsigned char" in order for things to work properly.
I'm guessing you didn't test this all out on a mixed 32/64 bit system?
Please fix up and test to ensure that it all works properly before resubmitting.
thanks,
greg k-h
Arnd Bergmann
maintainerRe: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Jae Hyun YooQuoted 13 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.Signed-off-by Jae Hyun Yoo <[email protected]>drivers/misc/aspeed-peci.c new file +6
-0+#include <linux/clk.h> +#include <linux/crc8.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/jiffies.h>
drivers/misc/aspeed-peci.c line 20
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+#include <linux/mfd/syscon.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/peci_ioctl.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/semaphore.h> +#include <linux/types.h> +#include <linux/uaccess.h>
semaphore.h is not used here and can be dropped.
Quoted 1 line
+static struct
aspeed_peci*aspeed_peci_priv;
Try to avoid instance variables like this one. You should always be able to find that pointer from whatever structure you were called with.
Quoted 11 lines
drivers/misc/aspeed-peci.c new file +11
-0+ timeout =wait_for_completion_interruptible_timeout ( + &priv->xfer_complete, +msecs_to_jiffies (priv->cmd_timeout_ms)); + +dev_dbg (priv->dev,"INT_STS : 0x%08x\n" , priv->sts); +if (!regmap_read (priv->regmap,AST_PECI_CMD , &peci_state)) +dev_dbg (priv->dev,"PECI_STATE : 0x%lx\n" , +PECI_CMD_STS_GET (peci_state)); +else +dev_dbg (priv->dev,"PECI_STATE : read error\n" ); +
drivers/misc/aspeed-peci.c line 225
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+if (timeout <=0 || !(priv->sts &PECI_INT_CMD_DONE )) { +if (timeout <=0 ) { +dev_dbg (priv->dev,"Timeout waiting for a response!\n" ); + rc = -ETIME ; + }else { +dev_dbg (priv->dev,"No valid response!\n" ); + rc = -EFAULT ; + } +return rc; + }
You don't seem to handle -ERESTARTSYS correct here. Either do it right, or drop the _interruptible part above.
Quoted 27 lines
drivers/misc/aspeed-peci.c new file +27
-0+typedef int (*ioctl_fn )(struct aspeed_peci *,void *); + +static ioctl_fn peci_ioctl_fn[PECI_CMD_MAX ] = { + ioctl_xfer_msg, + ioctl_ping, + ioctl_get_dib, + ioctl_get_temp, + ioctl_rd_pkg_cfg, + ioctl_wr_pkg_cfg, + ioctl_rd_ia_msr, +NULL ,/* Reserved */ + ioctl_rd_pci_cfg, +NULL ,/* Reserved */ + ioctl_rd_pci_cfg_local, + ioctl_wr_pci_cfg_local, +}; + + +long peci_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct aspeed_peci *priv; +long ret =0 ; +void __user *argp = (void __user *)arg; +int timeout =PECI_IDLE_CHECK_TIMEOUT ; +u8 msg[sizeof (struct peci_xfer_msg )]; +unsigned int peci_cmd, msg_size; +u32 cmd_sts;
drivers/misc/aspeed-peci.c line 770
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+ +/* +* Treat it as an inter module call when filp is null but only in case +* the private data is initialized. +*/ +if (filp) + priv =container_of (filp->private_data, + struct aspeed_peci, miscdev); +else + priv = aspeed_peci_priv;
Drop this.
Quoted 7 lines
drivers/misc/aspeed-peci.c new file +7
-0+if (!priv) +return -ENXIO ; + +switch (cmd) { +case PECI_IOC_XFER : +case PECI_IOC_PING : +case PECI_IOC_GET_DIB :
drivers/misc/aspeed-peci.c line 788
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+case PECI_IOC_GET_TEMP : +case PECI_IOC_RD_PKG_CFG : +case PECI_IOC_WR_PKG_CFG : +case PECI_IOC_RD_IA_MSR : +case PECI_IOC_RD_PCI_CFG : +case PECI_IOC_RD_PCI_CFG_LOCAL : +case PECI_IOC_WR_PCI_CFG_LOCAL : + peci_cmd =_IOC_TYPE (cmd) -PECI_IOC_BASE ; + msg_size =_IOC_SIZE (cmd); +break ;
Having to keep the switch() statement and the array above seems a little fragile. Can you just do one or the other?
Regarding the command set, you have both a low-level PECI_IOC_XFER interface and a high-level interface. Can you explain why? I'd think that generally speaking it's better to have only one of the two.
drivers/misc/aspeed-peci.c line 812
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+/* Check command sts and bus idle state */ +while (!regmap_read (priv->regmap,AST_PECI_CMD , &cmd_sts) + && (cmd_sts & (PECI_CMD_STS_MASK |PECI_CMD_PIN_MON ))) { +if (timeout-- <0 ) { +dev_dbg (priv->dev,"Timeout waiting for idle state!\n" ); + ret = -ETIME ; + goto out; + } +usleep_range (10000 ,11000 ); + };
To implement timeout, it's better to replace the counter with a jiffies/time_before or ktime_get()/ktime_before() check, since usleep_range() is might sleep considerably longer than expected.
Quoted 1 line
+EXPORT_SYMBOL_GPL(peci_ioctl);
No user of this, so drop it.
Quoted 13 lines
drivers/misc/aspeed-peci.c new file +13
-0+static int aspeed_peci_open (struct inode *inode,struct file *filp) +{ +struct aspeed_peci *priv = + container_of(filp->private_data, struct aspeed_peci, miscdev); + +atomic_inc (&priv->ref_count); + +dev_dbg (priv->dev,"ref_count : %d\n" ,atomic_read (&priv->ref_count)); + +return 0 ; +} + +static int aspeed_peci_release (struct inode *inode,struct file *filp)
drivers/misc/aspeed-peci.c line 856
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+{ +struct aspeed_peci *priv = + container_of(filp->private_data, struct aspeed_peci, miscdev); + +atomic_dec (&priv->ref_count); + +dev_dbg (priv->dev,"ref_count : %d\n" ,atomic_read (&priv->ref_count)); + +return 0 ; +}
Nothing uses that reference count, drop it.
Quoted 6 lines
new file mode 100644
index 0000000..66322c6include/misc/peci.h new file +1
-0@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0
include/misc/peci.h line 11
Quoted 10 lines
include/misc/peci.h new file +10
-0+// Copyright (c) 2017 Intel Corporation + +#ifndef __PECI_H +#define __PECI_H + +#include <linux/peci_ioctl.h> + +long peci_ioctl (struct file *filp,unsigned int cmd,unsigned long arg); + +#endif /* __PECI_H */
Not used anywhere.
Quoted 19 lines
include/uapi/linux/peci_ioctl.h new file +13
-0@@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#ifndef __PECI_IOCTL_H +#define __PECI_IOCTL_H + +#include <linux/ioctl.h> + +/* Base Address of 48d */ +#define PECI_BASE_ADDR 0x30/* The PECI client's default address of 0x30 */ +#define PECI_OFFSET_MAX 8/* Max numver of CPU clients */ + +/* PCI Access */
include/uapi/linux/peci_ioctl.h line 23
Quoted 10 lines
include/uapi/linux/peci_ioctl.h new file +10
-0+#define MAX_PCI_READ_LEN 24/* Number of bytes of the PCI Space read */ + +#define PCI_BUS0_CPU0 0x00 +#define PCI_BUS0_CPU1 0x80 +#define PCI_CPUBUSNO_BUS 0x00 +#define PCI_CPUBUSNO_DEV 0x08 +#define PCI_CPUBUSNO_FUNC 0x02 +#define PCI_CPUBUSNO 0xcc +#define PCI_CPUBUSNO_1 0xd0 +#define PCI_CPUBUSNO_VALID 0xd4
I can't tell for sure, but this file seems to be mixing the kernel API with hardware specific macros that are not needed in user space. Can you move some of this file into the driver itself?
This might go back to the previous question about the high-level and low-level interfaces: if you can drop the low-level ioctl interface, more of this header can become private to the driver.
Quoted 6 lines
include/uapi/linux/peci_ioctl.h new file +6
-0+/* Package Identifier Read Parameter Value */ +#define PKG_ID_CPU_ID 0x0000/* 0 - CPUID Info */ +#define PKG_ID_PLATFORM_ID 0x0001/* 1 - Platform ID */ +#define PKG_ID_UNCORE_ID 0x0002/* 2 - Uncore Device ID */ +#define PKG_ID_MAX_THREAD_ID 0x0003/* 3 - Max Thread ID */ +#define PKG_ID_MICROCODE_REV 0x0004/* 4 - CPU Microcode Update Revision */
include/uapi/linux/peci_ioctl.h line 40
Quoted 10 lines
include/uapi/linux/peci_ioctl.h new file +10
-0+#define PKG_ID_MACHINE_CHECK_STATUS 0x0005/* 5 - Machine Check Status */ + +/* RdPkgConfig Index */ +#define MBX_INDEX_CPU_ID 0/* Package Identifier Read */ +#define MBX_INDEX_VR_DEBUG 1/* VR Debug */ +#define MBX_INDEX_PKG_TEMP_READ 2/* Package Temperature Read */ +#define MBX_INDEX_ENERGY_COUNTER 3/* Energy counter */ +#define MBX_INDEX_ENERGY_STATUS 4/* DDR Energy Status */ +#define MBX_INDEX_WAKE_MODE_BIT 5/* "Wake on PECI" Mode bit */ +#define MBX_INDEX_EPI 6/* Efficient Performance Indication */
Who defines these constants? Are they specific to the aspeed BMC, to the HECI protocol, or to a particular version of the remote endpoint?
Quoted 13 lines
include/uapi/linux/peci_ioctl.h new file +13
-0+#pragma pack(push, 1) +struct peci_xfer_msg { +unsigned char client_addr; +unsigned char tx_len; +unsigned char rx_len; +unsigned char tx_buf[MAX_BUFFER_SIZE ]; +unsigned char rx_buf[MAX_BUFFER_SIZE ]; +}; +#pragma pack(pop) + +struct peci_ping_msg { +unsigned char target; +};
include/uapi/linux/peci_ioctl.h line 174
Quoted 10 lines
include/uapi/linux/peci_ioctl.h new file +10
-0+ +struct peci_get_dib_msg { +unsigned char target; +unsigned int dib; +}; + +struct peci_get_temp_msg { +unsigned char target; +signed short temp_raw; +};
Aside from what Greg already said about the types, please be careful to also avoid implicit padding in the API data structures, including the end of the structure.
include/uapi/linux/peci_ioctl.h line 268
Quoted 11 lines
include/uapi/linux/peci_ioctl.h new file +11
-0+#define PECI_IOC_RD_PCI_CFG \ + _IOWR(PECI_IOC_BASE + PECI_CMD_RD_PCI_CFG, 0, \ + struct peci_rd_pci_cfg_msg) + +#define PECI_IOC_RD_PCI_CFG_LOCAL \ + _IOWR(PECI_IOC_BASE + PECI_CMD_RD_PCI_CFG_LOCAL, 0, \ + struct peci_rd_pci_cfg_local_msg) + +#define PECI_IOC_WR_PCI_CFG_LOCAL \ + _IOWR(PECI_IOC_BASE + PECI_CMD_WR_PCI_CFG_LOCAL, 0, \ + struct peci_wr_pci_cfg_local_msg)
Can you give some background on what these do? In particular, who is configuring whose PCI devices?
Arnd
Arnd Bergmann
maintainerRe: [PATCH linux dev-4.10 4/6] Documentation: dt-bindings: Add a generic PECI hwmon
In reply to Jae Hyun YooQuoted 15 lines · Jae Hyun Yoo
This commit add a dt-bindings document for a generic PECI hwmon driver.
Signed-off-by Jae Hyun Yoo <[email protected]>--- .../devicetree/bindings/hwmon/peci-hwmon.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/peci-hwmon.txtDocumentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +0
-0
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +5
-0@@ -0,0 +1,33 @@ +* Generic PECI (Platform Environment Control Interface) hwmon driver. + +Dependency: +- This driver uses a PECI misc driver as a controller interface so one of PECI + misc drivers which provides compatible ioctls has to be enabled.
The binding should only explain how we describe the hardware in an operating-system
independent way, but not talk about how an OS is supposed to implement those drivers.
Having multiple drivers each provide an exported function is not possible in Linux: it immediately breaks building an 'allyesconfig' kernel, and prevents you from running the same kernel across multiple implementations, so that has to be redesigned anyway.
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 13
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +7
-0+Required properties: +- compatible: "peci-hwmon" +- cpu-id: Should contain CPU socket ID + - 0 ~ 7 + +Optional properties: +- show-core: If this protperty is defined, core tmeperature attrubites will be
s/protperty/property/
s/tmeperature/temperature/
s/attrubites/attributes/
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +5
-0+ enumerated. +- dimm-nums: Should contain the number of DIMM slots that attached to each CPU + which is indicated by cpu-id. + 0 ~ 16 (default: 16) + In case of 0, DIMM temperature attrubites will not be enumerated.
Is this only an initial list that you expect to be extended in the future, or is this
a complete list of sensors that can ever be connected to PECI?
Should this be PECI version specific?
Arnd
Arnd Bergmann
maintainerRe: [PATCH linux dev-4.10 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Jae Hyun YooQuoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>
drivers/hwmon/peci-hwmon.c line 123
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +}
I said earlier that peci_ioctl() looked unused, that was obviously wrong, but what you have here
is not a proper way to abstract a bus.
Maybe this can be done more like an i2c bus: make the peci controller a bus device
and register all known target/index pairs as devices with the peci bus type, and have
them probed from DT. The driver can then bind to each of those individually. Not sure if that is getting to granular at that point, I'd have to understand better
how it is expected to get used, and what the variances are between implementations.
Arnd
Quoted 11 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.
Quoted 7 lines
What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
Thanks,
Jae
Greg KH
maintainerQuoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
What is "OpenBmc", and why are they using an obsolete and insecure kernel for their project? That seems like a very foolish thing to do...
thanks,
greg k-h
Quoted 24 lines · Greg KH
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
Quoted 7 lines
What is "OpenBmc", and why are they using an obsolete and insecure kernel for their project? That seems like a very foolish thing to do...
thanks,
greg k-h
OpenBmc is an open source project to create a highly extensible framework for BMC (Board Management Controller) software for data-center computer systems:
https://github.com/openbmc
Its current mainline is v4.10 but it is being kept upgrading so it will be upgraded to the latest stable or long-term version soon.
Thanks,
Jae
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Greg KHQuoted 9 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.We don't add code that could be used "sometime in the future". Only include stuff that we use now.
Quoted 7 lines
Please fix up this series based on that and resubmit. There should not be any need for any uapi file then, right?
thanks,
greg k-h
These header files are being used in this patch set as well. I meant, these files also can be used for the future implementation to provide compatibility. I will update the commit message.
Thanks,
Jae
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Greg KHQuoted 15 lines · Greg KH
include/uapi/linux/peci_ioctl.h line 160
Quoted 9 lines · Jae Hyun Yoo
include/uapi/linux/peci_ioctl.h new file +9
-0+#pragma pack(push, 1) +struct peci_xfer_msg { +unsigned char client_addr; +unsigned char tx_len; +unsigned char rx_len; +unsigned char tx_buf[MAX_BUFFER_SIZE ]; +unsigned char rx_buf[MAX_BUFFER_SIZE ]; +}; +#pragma pack(pop)For any structure that crosses the user/kernel boundry, you _HAVE_ to use the "__" variant. So for here you would use
__u8instead of "unsigned char" in order for things to work properly.
Quoted 9 lines
I'm guessing you didn't test this all out on a mixed 32/64 bit system?
Please fix up and test to ensure that it all works properly before resubmitting.
thanks,
greg k-h
Thanks for your pointing it out. I'll fix this.
Thanks a lot,
Jae
Greg KH
maintainerQuoted 33 lines · Jae Hyun Yoo
Quoted 24 lines · Greg KH
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
Quoted 7 lines
What is "OpenBmc", and why are they using an obsolete and insecure kernel for their project? That seems like a very foolish thing to do...
thanks,
greg k-h
Quoted 7 lines
OpenBmc is an open source project to create a highly extensible framework for BMC (Board Management Controller) software for data-center computer systems:
https://github.com/openbmcIts current mainline is v4.10 but it is being kept upgrading so it will be upgraded to the latest stable or long-term version soon.
Why hasn't it been updated in the year since 4.10 was released? That's a _very_ long time to be running on a totally insecure kernel, and no new development should ever be done on old kernels, that's even crazier (as we can't go back in time and accept patches for new features to old releases...)
It sounds like the openbmc project needs to learn how to manage their kernels a whole lot better, who do I need to go poke about this?
thanks,
greg k-h
Quoted 39 lines · Greg KH
Quoted 38 lines · Jae Hyun Yoo
Quoted 24 lines · Greg KH
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
Quoted 7 lines
What is "OpenBmc", and why are they using an obsolete and insecure kernel for their project? That seems like a very foolish thing to do...
thanks,
greg k-h
OpenBmc is an open source project to create a highly extensible framework for BMC (Board Management Controller) software for data-center computer systems:
https://github.com/openbmc
Quoted 9 lines
Quoted 2 lines
Its current mainline is v4.10 but it is being kept upgrading so it will be upgraded to the latest stable or long-term version soon.
Why hasn't it been updated in the year since 4.10 was released? That's a _very_ long time to be running on a totally insecure kernel, and no new development should ever be done on old kernels, that's even crazier (as we can't go back in time and accept patches for new features to old releases...)
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
Quoted 6 lines
It sounds like the openbmc project needs to learn how to manage their kernels a whole lot better, who do I need to go poke about this?
Quoted 1 line
thanks,
greg k-h
I've already cc'ed openbmc developers so they are also seeing this thread. Joel Stanley <[email protected]> is the openbmc kernel maintainer.
Thanks,
Jae
Guenter Roeck
maintainerRe: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Jae Hyun YooQuoted 49 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>--- drivers/hwmon/Kconfig | 6 + drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-hwmon.c | 953 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 960 insertions(+) create mode 100644 drivers/hwmon/peci-hwmon.cdrivers/hwmon/Kconfig +6
-0@@ -1234,6 +1234,12 @@ config SENSORS_NCT7904 This driver can also be built as a module. If so, the module will be called nct7904. +config SENSORS_PECI_HWMON + tristate "PECI hwmon support" + depends on ASPEED_PECI + help + If you say yes here you get support for the generic PECI hwmon driver. + config SENSORS_NSA320 tristate "ZyXEL NSA320 and compatible fan speed and temperature sensors" depends on GPIOLIB && OFdrivers/hwmon/Makefile +1
-0@@ -131,6 +131,7 @@ obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o obj-$(CONFIG_SENSORS_NCT7904) += nct7904.o obj-$(CONFIG_SENSORS_NSA320) += nsa320-hwmon.o obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o +obj-$(CONFIG_SENSORS_PECI_HWMON) += peci-hwmon.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.odrivers/hwmon/peci-hwmon.c new file +4
-0@@ -0,0 +1,953 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#include <linux/delay.h>
drivers/hwmon/peci-hwmon.c line 14
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/jiffies.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_platform.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/syscalls.h> +#include <misc/peci.h>
misc, not linux ? That seems wrong.
drivers/hwmon/peci-hwmon.c line 21
Quoted 7 lines
drivers/hwmon/peci-hwmon.c new file +7
-0+ +#define DEVICE_NAME "peci-hwmon" +#define HWMON_NAME "peci_hwmon" + +#define CPU_ID_MAX 8/* Max CPU number configured by socket ID */ +#define DIMM_NUMS_MAX 16/* Max DIMM numbers (channel ranks x 2) */ +#define CORE_NUMS_MAX 28/* Max core numbers (max on SKX Platinum) */
I won't insist, but it would be better if this were dynamic, otherwise we'll end up having to increase the defines in the future.
drivers/hwmon/peci-hwmon.c line 24
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+#define TEMP_TYPE_PECI 6/* Sensor type 6: Intel PECI */ +#define CORE_INDEX_OFFSET 100/* sysfs filename start offset for core temp */ +#define DIMM_INDEX_OFFSET 200/* sysfs filename start offset for DIMM temp */
Did you test with the "sensors" command to ensure that this works, with the large gaps in index values ?
Overall, I am not very happy with the indexing. Since each sensor as a label, it might be better to just make it dynamic.
Quoted 72 lines
drivers/hwmon/peci-hwmon.c new file +72
-0+#define TEMP_NAME_HEADER_LEN 4/* sysfs temp type header length */ +#define OF_DIMM_NUMS_DEFAULT 16/* default dimm-nums setting */ + +#define CORE_TEMP_ATTRS 5 +#define DIMM_TEMP_ATTRS 2 +#define ATTR_NAME_LEN 24 + +#define UPDATE_INTERVAL_MIN HZ + +enum sign_t { +POS , +NEG +}; + +struct cpuinfo_t { +bool valid; +u32 dib; +u8 cpuid; +u8 platform_id; +u32 microcode; +u8 logical_thread_nums; +}; + +struct temp_data_t { +bool valid; +s32 value; +unsigned long last_updated; +}; + +struct temp_group_t { +struct temp_data_t tjmax; +struct temp_data_t tcontrol; +struct temp_data_t tthrottle; +struct temp_data_t dts_margin; +struct temp_data_t die; +struct temp_data_t core[CORE_NUMS_MAX ]; +struct temp_data_t dimm[DIMM_NUMS_MAX ]; +}; + +struct core_temp_attr_group_t { +struct sensor_device_attribute sd_attrs[CORE_NUMS_MAX ][CORE_TEMP_ATTRS ]; +char attr_name[CORE_NUMS_MAX ][CORE_TEMP_ATTRS ][ATTR_NAME_LEN ]; +struct attribute *attrs[CORE_NUMS_MAX ][CORE_TEMP_ATTRS +1 ]; +struct attribute_group attr_group[CORE_NUMS_MAX ]; +}; + +struct dimm_temp_attr_group_t { +struct sensor_device_attribute sd_attrs[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS ]; +char attr_name[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS ][ATTR_NAME_LEN ]; +struct attribute *attrs[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS +1 ]; +struct attribute_group attr_group[DIMM_NUMS_MAX ]; +}; + +struct peci_hwmon { +struct device *dev; +struct device *hwmon_dev; +char name[NAME_MAX ]; +const struct attribute_group **groups; +struct cpuinfo_t cpuinfo; +struct temp_group_t temp; +u32 cpu_id; +bool show_core; +u32 core_nums; +u32 dimm_nums; +atomic_t core_group_created; +struct core_temp_attr_group_t core; +struct dimm_temp_attr_group_t dimm; +}; + +enum label_t { +L_DIE , +L_DTS ,
drivers/hwmon/peci-hwmon.c line 106
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+L_TCONTROL , +L_TTHROTTLE , +L_MAX +}; + +static const char *peci_label[L_MAX ] = { +"Die temperature\n" , +"DTS thermal margin to Tcontrol\n" , +"Tcontrol temperature\n" , + "Tthrottle temperature\n",
"temperature" is redundant for a temperature label.
drivers/hwmon/peci-hwmon.c line 111
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+}; + +static DEFINE_MUTEX (peci_hwmon_lock); + +static int create_core_temp_group (struct peci_hwmon *priv,int core_no);
Please avoid forward declarations.
drivers/hwmon/peci-hwmon.c line 113
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+ +
Please run your patches throuch checkpatch --strict and fix what it reports, or provide a reason why you don't.
Quoted 64 lines
drivers/hwmon/peci-hwmon.c new file +64
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +} + +static int get_cpuinfo (struct peci_hwmon *priv) +{ +struct peci_get_dib_msg dib_msg; +struct peci_rd_pkg_cfg_msg cfg_msg; +int rc, i; + +if (!priv->cpuinfo.valid) { + dib_msg.target =PECI_BASE_ADDR + priv->cpu_id; + + rc =xfer_peci_msg (PECI_IOC_GET_DIB , (void *)&dib_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.dib = dib_msg.dib; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =0 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.cpuid = cfg_msg.pkg_config[0 ]; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =1 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.platform_id = cfg_msg.pkg_config[0 ]; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =3 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.logical_thread_nums = cfg_msg.pkg_config[0 ] +1 ; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =4 ; + cfg_msg.rx_len =4 ; +
drivers/hwmon/peci-hwmon.c line 187
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+ rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.microcode = (cfg_msg.pkg_config[3 ] <<24 ) | + (cfg_msg.pkg_config[2 ] <<16 ) | + (cfg_msg.pkg_config[1 ] <<8 ) | + cfg_msg.pkg_config[0 ]; + + priv->core_nums = priv->cpuinfo.logical_thread_nums /2 ;
This seems to assume a 1:2 relationship between number of threads and number of CPUs, which is incorrect.
drivers/hwmon/peci-hwmon.c line 192
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+ +if (priv->show_core && +atomic_inc_return (&priv->core_group_created) ==1 ) { +for (i =0 ; i < priv->core_nums; i++) { + rc =create_core_temp_group (priv, i);
This is messy. Sensor groups should be created before or during hwmon registration, not at some arbitrary later time.
I don't know the logic behind this, but if it is supposed to track CPUs coming online and going offline it is the wrong approach.
Quoted 48 lines
drivers/hwmon/peci-hwmon.c new file +48
-0+if (rc !=0 ) { +dev_err (priv->dev, +"Failed to create core temp group\n" ); +for (--i; i >=0 ; i--) { +sysfs_remove_group ( + &priv->hwmon_dev->kobj, + &priv->core.attr_group[i]); + } +atomic_set (&priv->core_group_created, +0 ); +return rc; + } + } + } + + priv->cpuinfo.valid = true; + } + +return 0 ; +} + +static int get_tjmax (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +int rc; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + +if (!priv->temp.tjmax.valid) { + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.tjmax.value = (s32 )msg.pkg_config[2 ] *1000 ; + priv->temp.tjmax.valid = true; + } + +return 0 ; +} + +static int get_tcontrol (struct peci_hwmon *priv)
drivers/hwmon/peci-hwmon.c line 250
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+{ +struct peci_rd_pkg_cfg_msg msg; +s32 tcontrol_margin; +int rc; + +if (priv->temp.tcontrol.valid && +time_before (jiffies, priv->temp.tcontrol.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; +
Is the delay necessary ? Otherwise I would suggest to drop it. It adds a lot of complexity to the driver. Also, if the user polls values more often, that is presumably on purpose.
Quoted 99 lines
drivers/hwmon/peci-hwmon.c new file +99
-0+ rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + tcontrol_margin = msg.pkg_config[1 ]; + tcontrol_margin = ((tcontrol_margin ^0x80 ) -0x80 ) *1000 ; + + priv->temp.tcontrol.value = priv->temp.tjmax.value - tcontrol_margin; + +if (!priv->temp.tcontrol.valid) { + priv->temp.tcontrol.last_updated =INITIAL_JIFFIES ; + priv->temp.tcontrol.valid = true; + }else { + priv->temp.tcontrol.last_updated = jiffies; + } + +return 0 ; +} + +static int get_tthrottle (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 tthrottle_offset; +int rc; + +if (priv->temp.tthrottle.valid && +time_before (jiffies, priv->temp.tthrottle.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + tthrottle_offset = (msg.pkg_config[3 ] &0x2f ) *1000 ; + priv->temp.tthrottle.value = priv->temp.tjmax.value - tthrottle_offset; + +if (!priv->temp.tthrottle.valid) { + priv->temp.tthrottle.last_updated =INITIAL_JIFFIES ; + priv->temp.tthrottle.valid = true; + }else { + priv->temp.tthrottle.last_updated = jiffies; + } + +return 0 ; +} + +static int get_die_temp (struct peci_hwmon *priv) +{ +struct peci_get_temp_msg msg; +int rc; + +if (priv->temp.die.valid && +time_before (jiffies, priv->temp.die.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + + rc =xfer_peci_msg (PECI_IOC_GET_TEMP , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.die.value = priv->temp.tjmax.value + + ((s32 )msg.temp_raw *1000 /64 ); + +if (!priv->temp.die.valid) { + priv->temp.die.last_updated =INITIAL_JIFFIES ; + priv->temp.die.valid = true; + }else { + priv->temp.die.last_updated = jiffies; + } + +return 0 ; +} + +static int get_dts_margin (struct peci_hwmon *priv)
drivers/hwmon/peci-hwmon.c line 359
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+{ +struct peci_rd_pkg_cfg_msg msg; +s32 dts_margin; +int rc; + +if (priv->temp.dts_margin.valid && +time_before (jiffies, priv->temp.dts_margin.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; +
Are all those values expected to change dynamically, or are some static ? Static values do not have to be re-read repeatedly but can be cached permanently.
Quoted 19 lines
drivers/hwmon/peci-hwmon.c new file +19
-0+ rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_DTS_MARGIN ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + dts_margin = (msg.pkg_config[1 ] <<8 ) | msg.pkg_config[0 ]; + +/* +* Processors return a value of DTS reading in 10.6 format +* (10 bits signed decimal, 6 bits fractional). +* Error codes:
drivers/hwmon/peci-hwmon.c line 388
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+* 0x8000: General sensor error +* 0x8001: Reserved +* 0x8002: Underflow on reading value +* 0x8003-0x81ff: Reserved +*/ +if (dts_margin >=0x8000 && dts_margin <=0x81ff ) +return -1 ; + + dts_margin = ((dts_margin ^0x8000 ) -0x8000 ) *1000 /64 ; +
The above code is repeated several times. Please consider moving it into a function to reduce duplication.
Quoted 116 lines
drivers/hwmon/peci-hwmon.c new file +116
-0+ priv->temp.dts_margin.value = dts_margin; + +if (!priv->temp.dts_margin.valid) { + priv->temp.dts_margin.last_updated =INITIAL_JIFFIES ; + priv->temp.dts_margin.valid = true; + }else { + priv->temp.dts_margin.last_updated = jiffies; + } + +return 0 ; +} + +static int get_core_temp (struct peci_hwmon *priv,int core_index) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 core_dts_margin; +int rc; + +if (priv->temp.core[core_index].valid && +time_before (jiffies, priv->temp.core[core_index].last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_PER_CORE_DTS_TEMP ; + msg.param = core_index; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + core_dts_margin = (msg.pkg_config[1 ] <<8 ) | msg.pkg_config[0 ]; + +/* +* Processors return a value of the core DTS reading in 10.6 format +* (10 bits signed decimal, 6 bits fractional). +* Error codes: +* 0x8000: General sensor error +* 0x8001: Reserved +* 0x8002: Underflow on reading value +* 0x8003-0x81ff: Reserved +*/ +if (core_dts_margin >=0x8000 && core_dts_margin <=0x81ff ) +return -1 ; + + core_dts_margin = ((core_dts_margin ^0x8000 ) -0x8000 ) *1000 /64 ; + + priv->temp.core[core_index].value = priv->temp.tjmax.value + + core_dts_margin; + +if (!priv->temp.core[core_index].valid) { + priv->temp.core[core_index].last_updated =INITIAL_JIFFIES ; + priv->temp.core[core_index].valid = true; + }else { + priv->temp.core[core_index].last_updated = jiffies; + } + +return 0 ; +} + +static int get_dimm_temp (struct peci_hwmon *priv,int dimm_index) +{ +struct peci_rd_pkg_cfg_msg msg; +int channel_rank = dimm_index /2 ; +int dimm_order = dimm_index %2 ; +int rc; + +if (priv->temp.core[dimm_index].valid && +time_before (jiffies, priv->temp.core[dimm_index].last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_DDR_DIMM_TEMP ; + msg.param = channel_rank; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.dimm[dimm_index].value = msg.pkg_config[dimm_order] *1000 ; + +if (!priv->temp.dimm[dimm_index].valid) { + priv->temp.dimm[dimm_index].last_updated =INITIAL_JIFFIES ; + priv->temp.dimm[dimm_index].valid = true; + }else { + priv->temp.dimm[dimm_index].last_updated = jiffies; + } + +return 0 ; +} + +static ssize_t show_info (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"dib : 0x%08x\n" +"cpuid : 0x%x\n" + "platform id : %d\n"
drivers/hwmon/peci-hwmon.c line 514
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+"stepping : %d\n" +"microcode : 0x%08x\n" +"logical thread nums : %d\n" , + priv->cpuinfo.dib, + priv->cpuinfo.cpuid, + priv->cpuinfo.platform_id, + priv->cpuinfo.cpuid &0xf , + priv->cpuinfo.microcode, + priv->cpuinfo.logical_thread_nums); +}
Please no non-standard attributes, much less attributes not following sysfs attribute rules. If you want to display such information, consider using debugfs. Besides, this information specifically appears to duplicate the content of /proc/cpuid, which doesn't really add any value at all.
Quoted 138 lines
drivers/hwmon/peci-hwmon.c new file +138
-0+ +static ssize_t show_tcontrol (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tcontrol (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tcontrol.value); +} + +static ssize_t show_tcontrol_margin (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int rc; + + rc =get_tcontrol (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , sensor_attr->index ==POS ? + priv->temp.tjmax.value - + priv->temp.tcontrol.value : + priv->temp.tcontrol.value - + priv->temp.tjmax.value); +} + +static ssize_t show_tthrottle (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tthrottle (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tthrottle.value); +} + +static ssize_t show_tjmax (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tjmax.value); +} + +static ssize_t show_die_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_die_temp (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.die.value); +} + +static ssize_t show_dts_therm_margin (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_dts_margin (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.dts_margin.value); +} + +static ssize_t show_core_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int core_index = sensor_attr->index; +int rc; + + rc =get_core_temp (priv, core_index); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.core[core_index].value); +} + +static ssize_t show_dimm_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int dimm_index = sensor_attr->index; +int rc; + + rc =get_dimm_temp (priv, dimm_index); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.dimm[dimm_index].value); +} + +static ssize_t show_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf,"%d\n" , sensor_attr->index); +} + +static ssize_t show_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf, peci_label[sensor_attr->index]);
drivers/hwmon/peci-hwmon.c line 662
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+} + +static ssize_t show_core_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf,"Core #%d temperature\n" , sensor_attr->index); +}
Your label strings are quite long. How does that look like with the sensors command ?
Plus, again, "temperature" in a temperature label is redundant.
Quoted 188 lines
drivers/hwmon/peci-hwmon.c new file +188
-0+ +static ssize_t show_dimm_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +char channel ='A' + (sensor_attr->index /2 ); +int index = sensor_attr->index %2 ; + +return sprintf (buf,"Channel Rank %c DDR DIMM #%d temperature\n" , + channel, index); +} + +/* Die temperature */ +static SENSOR_DEVICE_ATTR(temp1_label, 0444, show_label, NULL, L_DIE); +static SENSOR_DEVICE_ATTR(temp1_input, 0444, show_die_temp, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_max, 0444, show_tcontrol, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_crit, 0444, show_tjmax, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, 0444, show_tcontrol_margin, NULL, + POS); + +static struct attribute *die_temp_attrs[] = { + &sensor_dev_attr_temp1_label.dev_attr.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_temp1_crit.dev_attr.attr, + &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, +NULL +}; + +static const struct attribute_group die_temp_attr_group = { + .attrs = die_temp_attrs, +}; + +/* DTS thermal margin temperature */ +static SENSOR_DEVICE_ATTR(temp2_label, 0444, show_label, NULL, L_DTS); +static SENSOR_DEVICE_ATTR(temp2_input, 0444, show_dts_therm_margin, NULL, 0); +static SENSOR_DEVICE_ATTR(temp2_min, 0444, show_value, NULL, 0); +static SENSOR_DEVICE_ATTR(temp2_lcrit, 0444, show_tcontrol_margin, NULL, NEG); + +static struct attribute *dts_margin_temp_attrs[] = { + &sensor_dev_attr_temp2_label.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp2_min.dev_attr.attr, + &sensor_dev_attr_temp2_lcrit.dev_attr.attr, +NULL +}; + +static const struct attribute_group dts_margin_temp_attr_group = { + .attrs = dts_margin_temp_attrs, +}; + +/* Tcontrol temperature */ +static SENSOR_DEVICE_ATTR(temp3_label, 0444, show_label, NULL, L_TCONTROL); +static SENSOR_DEVICE_ATTR(temp3_input, 0444, show_tcontrol, NULL, 0); +static SENSOR_DEVICE_ATTR(temp3_crit, 0444, show_tjmax, NULL, 0); + +static struct attribute *tcontrol_temp_attrs[] = { + &sensor_dev_attr_temp3_label.dev_attr.attr, + &sensor_dev_attr_temp3_input.dev_attr.attr, + &sensor_dev_attr_temp3_crit.dev_attr.attr, +NULL +}; + +static const struct attribute_group tcontrol_temp_attr_group = { + .attrs = tcontrol_temp_attrs, +}; + +/* Tthrottle temperature */ +static SENSOR_DEVICE_ATTR(temp4_label, 0444, show_label, NULL, L_TTHROTTLE); +static SENSOR_DEVICE_ATTR(temp4_input, 0444, show_tthrottle, NULL, 0); + +static struct attribute *tthrottle_temp_attrs[] = { + &sensor_dev_attr_temp4_label.dev_attr.attr, + &sensor_dev_attr_temp4_input.dev_attr.attr, +NULL +}; + +static const struct attribute_group tthrottle_temp_attr_group = { + .attrs = tthrottle_temp_attrs, +}; + +/* CPU info */ +static SENSOR_DEVICE_ATTR(info, 0444, show_info, NULL, 0); + +static struct attribute *info_attrs[] = { + &sensor_dev_attr_info.dev_attr.attr, +NULL +}; + +static const struct attribute_group info_attr_group = { + .attrs = info_attrs, +}; + +const struct attribute_group *peci_hwmon_attr_groups[] = { + &info_attr_group, + &die_temp_attr_group, + &dts_margin_temp_attr_group, + &tcontrol_temp_attr_group, + &tthrottle_temp_attr_group, +NULL +}; + +static ssize_t (*const core_show_fn[CORE_TEMP_ATTRS ]) (struct device *dev, +struct device_attribute *devattr,char *buf) = { + show_core_label, + show_core_temp, + show_tcontrol, + show_tjmax, + show_tcontrol_margin, +}; + +static const char *const core_suffix[CORE_TEMP_ATTRS ] = { +"label" , +"input" , +"max" , +"crit" , +"crit_hyst" , +}; + +static int create_core_temp_group (struct peci_hwmon *priv,int core_no) +{ +int i; + +for (i =0 ; i <CORE_TEMP_ATTRS ; i++) { +snprintf (priv->core.attr_name[core_no][i], +ATTR_NAME_LEN ,"temp%d_%s" , +CORE_INDEX_OFFSET + core_no, core_suffix[i]); +sysfs_attr_init ( + &priv->core.sd_attrs[core_no][i].dev_attr.attr); + priv->core.sd_attrs[core_no][i].dev_attr.attr.name = + priv->core.attr_name[core_no][i]; + priv->core.sd_attrs[core_no][i].dev_attr.attr.mode =0444 ; + priv->core.sd_attrs[core_no][i].dev_attr.show = core_show_fn[i]; +if (i ==0 || i ==1 )/* label or temp */ + priv->core.sd_attrs[core_no][i].index = core_no; + priv->core.attrs[core_no][i] = + &priv->core.sd_attrs[core_no][i].dev_attr.attr; + } + + priv->core.attr_group[core_no].attrs = priv->core.attrs[core_no]; + +return sysfs_create_group (&priv->hwmon_dev->kobj, + &priv->core.attr_group[core_no]); +} + +static ssize_t (*const dimm_show_fn[DIMM_TEMP_ATTRS ]) (struct device *dev, +struct device_attribute *devattr,char *buf) = { + show_dimm_label, + show_dimm_temp, +}; + +static const char *const dimm_suffix[DIMM_TEMP_ATTRS ] = { +"label" , +"input" , +}; + +static int create_dimm_temp_group (struct peci_hwmon *priv,int dimm_no) +{ +int i; + +for (i =0 ; i <DIMM_TEMP_ATTRS ; i++) { +snprintf (priv->dimm.attr_name[dimm_no][i], +ATTR_NAME_LEN ,"temp%d_%s" , +DIMM_INDEX_OFFSET + dimm_no, dimm_suffix[i]); +sysfs_attr_init (&priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr); + priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr.name = + priv->dimm.attr_name[dimm_no][i]; + priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr.mode =0444 ; + priv->dimm.sd_attrs[dimm_no][i].dev_attr.show = dimm_show_fn[i]; + priv->dimm.sd_attrs[dimm_no][i].index = dimm_no; + priv->dimm.attrs[dimm_no][i] = + &priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr; + } + + priv->dimm.attr_group[dimm_no].attrs = priv->dimm.attrs[dimm_no]; + +return sysfs_create_group (&priv->hwmon_dev->kobj, + &priv->dimm.attr_group[dimm_no]); +} + +static int peci_hwmon_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct peci_hwmon *priv; +struct device *hwmon;
drivers/hwmon/peci-hwmon.c line 860
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+int rc, i; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (dev, priv); + priv->dev = dev; + + rc =of_property_read_u32 (np,"cpu-id" , &priv->cpu_id);
What entity determines cpu-id ?
drivers/hwmon/peci-hwmon.c line 866
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+if (rc || priv->cpu_id >=CPU_ID_MAX ) { +dev_err (dev,"Invalid cpu-id configuration\n" ); +return rc; + } + + rc =of_property_read_u32 (np,"dimm-nums" , &priv->dimm_nums);
This is an odd devicetree attribute. Normally the number of DIMMs is dynamic. Isn't there a means to get all that information dynamically instead of having to set it through devicetree ? What if someone adds or removes a DIMM ? Who updates the devicetree ?
drivers/hwmon/peci-hwmon.c line 873
Quoted 7 lines
drivers/hwmon/peci-hwmon.c new file +7
-0+if (rc || priv->dimm_nums >DIMM_NUMS_MAX ) { +dev_warn (dev,"Invalid dimm-nums : %u. Use default : %u\n" , + priv->dimm_nums,OF_DIMM_NUMS_DEFAULT ); + priv->dimm_nums =OF_DIMM_NUMS_DEFAULT ; + } + + priv->show_core =of_property_read_bool (np,"show-core" );
This does not look like an appropriate devicetree attribute.
drivers/hwmon/peci-hwmon.c line 876
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ + priv->groups = peci_hwmon_attr_groups; +
This assignment (and the ->groups variable) is quite pointless.
drivers/hwmon/peci-hwmon.c line 881
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+snprintf (priv->name,NAME_MAX ,HWMON_NAME ".cpu%d" , priv->cpu_id); + + hwmon =devm_hwmon_device_register_with_groups (dev, + priv->name, + priv, priv->groups);
Please rewrite the driver to use devm_hwmon_device_register_with_info(), and avoid dynamic attributes.
drivers/hwmon/peci-hwmon.c line 889
Quoted 8 lines
drivers/hwmon/peci-hwmon.c new file +8
-0+ + rc =PTR_ERR_OR_ZERO (hwmon); +if (rc !=0 ) { +dev_err (dev,"Failed to register peci hwmon\n" ); +return rc; + } + + priv->hwmon_dev = hwmon;
Something is logically wrong if you need to store hwmon_dev in the private data structure. Specifically, creating attributes dynamically after hwmon registration is wrong.
drivers/hwmon/peci-hwmon.c line 892
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ +for (i =0 ; i < priv->dimm_nums; i++) { + rc =create_dimm_temp_group (priv, i);
No. See earlier comments. All attribute groups must be created during registration (or before, but I am not inclined to accept a new driver doing that).
Quoted 4 lines
drivers/hwmon/peci-hwmon.c new file +4
-0+if (rc !=0 ) { +dev_err (dev,"Failed to create dimm temp group\n" ); +for (--i; i >=0 ; i--) { + sysfs_remove_group(&priv->hwmon_dev->kobj,
drivers/hwmon/peci-hwmon.c line 906
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+ &priv->dimm.attr_group[i]); + } +return rc; + } + } + +/* +* Try to create core temp group now. It will be created if CPU is +* curretnly online or it will be created after the first reading of +* cpuinfo from the online CPU otherwise.
This is not how CPUs are supposed to be detected, and it does not handle CPUs taken offline. If the driver is instantiated as a CPU comes online, or as it goes offline, the driver should use the appropriate kernel interfaces to trigger that instantiation or removal. However, if so, it may be inappropriate to associate CPU temperatures with other system temperatures in the same instance of the driver; after all, those are all independent of each other.
Overall, I suspect that there should be a callback or some other mechanism in the peci core to trigger instantiation and removal of this driver, and I am not sure if any of the devicetree properties makes sense at all.
For example, if an instance of this driver is associated with a PECI agent (with assorted CPU/DIMM temperature reporting), the instantiation could be triggered as soon as the PECI core detects that the agent is available, and the PECI core could report what exactly that instance supports.
drivers/hwmon/peci-hwmon.c line 911
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+*/ +if (priv->show_core) + (void )get_cpuinfo (priv); + +dev_info (dev,"peci hwmon for CPU#%d registered\n" , priv->cpu_id);
Is this logging noise necessary ? Besides, some of it is redundant.
Quoted 9 lines
drivers/hwmon/peci-hwmon.c new file +9
-0+ +return rc; +} + +static int peci_hwmon_remove (struct platform_device *pdev) +{ +struct peci_hwmon *priv =dev_get_drvdata (&pdev->dev); +int i; +
drivers/hwmon/peci-hwmon.c line 930
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+if (atomic_read (&priv->core_group_created)) +for (i =0 ; i < priv->core_nums; i++) { +sysfs_remove_group (&priv->hwmon_dev->kobj, + &priv->core.attr_group[i]); + } + +for (i =0 ; i < priv->dimm_nums; i++) { +sysfs_remove_group (&priv->hwmon_dev->kobj, + &priv->dimm.attr_group[i]); + }
If you need to call sysfs_remove_group from here,
something is conceptually wrong in your driver.
drivers/hwmon/peci-hwmon.c line 936
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+ +return 0 ; +} + +static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },
This does not look like a reference to some piece of hardware.
Quoted 17 lines
drivers/hwmon/peci-hwmon.c new file +17
-0+ { } +}; +MODULE_DEVICE_TABLE (of, peci_of_table); + +static struct platform_driver peci_hwmon_driver = { + .probe = peci_hwmon_probe, + .remove = peci_hwmon_remove, + .driver = { + .name =DEVICE_NAME , + .of_match_table = peci_of_table, + }, +}; + +module_platform_driver (peci_hwmon_driver); +MODULE_AUTHOR ("Jae Hyun Yoo <[email protected]>" ); +MODULE_DESCRIPTION ("PECI hwmon driver" ); +MODULE_LICENSE ("GPL v2" );
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Arnd BergmannQuoted 19 lines · Arnd Bergmann
Quoted 17 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.Signed-off-by Jae Hyun Yoo <[email protected]>drivers/misc/aspeed-peci.c new file +10
-0+#include <linux/clk.h> +#include <linux/crc8.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/jiffies.h> +#include <linux/mfd/syscon.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/of.h>
Quoted 9 lines
drivers/misc/aspeed-peci.c line 20
Quoted 6 lines
drivers/misc/aspeed-peci.c new file +6
-0+#include <linux/peci_ioctl.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/semaphore.h> +#include <linux/types.h> +#include <linux/uaccess.h>
semaphore.his not used here and can be dropped.
You are right. Will drop it.
Quoted 6 lines
Quoted 1 line
+static struct
aspeed_peci*aspeed_peci_priv;Try to avoid instance variables like this one. You should always be able to find that pointer from whatever structure you were called with.
Okay. I will use driver_data instead.
Quoted 16 lines
Quoted 16 lines
drivers/misc/aspeed-peci.c new file +16
-0+ timeout =wait_for_completion_interruptible_timeout ( + &priv->xfer_complete, +msecs_to_jiffies (priv->cmd_timeout_ms)); + +dev_dbg (priv->dev,"INT_STS : 0x%08x\n" , priv->sts); +if (!regmap_read (priv->regmap,AST_PECI_CMD , &peci_state)) +dev_dbg (priv->dev,"PECI_STATE : 0x%lx\n" , +PECI_CMD_STS_GET (peci_state)); +else +dev_dbg (priv->dev,"PECI_STATE : read error\n" ); + +if (timeout <=0 || !(priv->sts &PECI_INT_CMD_DONE )) { +if (timeout <=0 ) { +dev_dbg (priv->dev,"Timeout waiting for a response!\n" ); + rc = -ETIME ; + }else {
Quoted 9 lines
drivers/misc/aspeed-peci.c line 225
Quoted 5 lines
drivers/misc/aspeed-peci.c new file +5
-0+dev_dbg (priv->dev,"No valid response!\n" ); + rc = -EFAULT ; + } +return rc; + }You don't seem to handle
-ERESTARTSYScorrect here. Either do it right, or drop the_interruptiblepart above.
Will add a handling logic for the -ERESTARTSYS.
Quoted 31 lines
Quoted 31 lines
drivers/misc/aspeed-peci.c new file +31
-0+typedef int (*ioctl_fn )(struct aspeed_peci *,void *); + +static ioctl_fn peci_ioctl_fn[PECI_CMD_MAX ] = { + ioctl_xfer_msg, + ioctl_ping, + ioctl_get_dib, + ioctl_get_temp, + ioctl_rd_pkg_cfg, + ioctl_wr_pkg_cfg, + ioctl_rd_ia_msr, +NULL ,/* Reserved */ + ioctl_rd_pci_cfg, +NULL ,/* Reserved */ + ioctl_rd_pci_cfg_local, + ioctl_wr_pci_cfg_local, +}; + + +long peci_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +struct aspeed_peci *priv; +long ret =0 ; +void __user *argp = (void __user *)arg; +int timeout =PECI_IDLE_CHECK_TIMEOUT ; +u8 msg[sizeof (struct peci_xfer_msg )]; +unsigned int peci_cmd, msg_size; +u32 cmd_sts; + +/* +* Treat it as an inter module call when filp is null but only in case +* the private data is initialized.
Quoted 9 lines
drivers/misc/aspeed-peci.c line 770
Quoted 6 lines
drivers/misc/aspeed-peci.c new file +6
-0+*/ +if (filp) + priv =container_of (filp->private_data, + struct aspeed_peci, miscdev); +else + priv = aspeed_peci_priv;Drop this.
peci_ioctl is being called from peci_hwmon as an inter-module call so it is needed, but as you suggested in the other patch, I'll consider redesign it with adding a peci device class.
Quoted 18 lines
Quoted 7 lines
drivers/misc/aspeed-peci.c new file +7
-0+if (!priv) +return -ENXIO ; + +switch (cmd) { +case PECI_IOC_XFER : +case PECI_IOC_PING : +case PECI_IOC_GET_DIB :drivers/misc/aspeed-peci.c line 788
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+case PECI_IOC_GET_TEMP : +case PECI_IOC_RD_PKG_CFG : +case PECI_IOC_WR_PKG_CFG : +case PECI_IOC_RD_IA_MSR : +case PECI_IOC_RD_PCI_CFG : +case PECI_IOC_RD_PCI_CFG_LOCAL : +case PECI_IOC_WR_PCI_CFG_LOCAL : + peci_cmd =_IOC_TYPE (cmd) -PECI_IOC_BASE ; + msg_size =_IOC_SIZE (cmd); +break ;
Quoted 7 lines
Having to keep the
switch()statement and the array above seems a little fragile. Can you just do one or the other?Regarding the command set, you have both a low-level
PECI_IOC_XFERinterface and a high-level interface. Can you explain why? I'd think that generally speaking it's better to have only one of the two.
I was intended to provide generic peci command set, also the low level PECI_IOC_XFER to provide flexibility for a case when compose a custom peci command which cannot be covered by the high-level command set. As you said, all other commands can be implemented in the upper layer but the benefit of when this driver has the implementation is, it's easy to manage retry logic since peci is retrial based protocol intends to do not disturb a CPU if the CPU is doing more important task.
However, your thought also makes sense. I'll check the spec again whether the high-level command set can cover all cases. If so, I'll remove the low-level command.
Quoted 11 lines
drivers/misc/aspeed-peci.c line 812
Quoted 10 lines
drivers/misc/aspeed-peci.c new file +10
-0+/* Check command sts and bus idle state */ +while (!regmap_read (priv->regmap,AST_PECI_CMD , &cmd_sts) + && (cmd_sts & (PECI_CMD_STS_MASK |PECI_CMD_PIN_MON ))) { +if (timeout-- <0 ) { +dev_dbg (priv->dev,"Timeout waiting for idle state!\n" ); + ret = -ETIME ; + goto out; + } +usleep_range (10000 ,11000 ); + };
Quoted 4 lines
To implement timeout, it's better to replace the counter with a jiffies/time_before or ktime_get()/ktime_before() check, since
usleep_range()is might sleep considerably longer than expected.
Thanks for the suggestion. Will rewrite it using ktime_get()/ktime_before().
Quoted 4 lines
Quoted 1 line
+EXPORT_SYMBOL_GPL(peci_ioctl);
No user of this, so drop it.
peci_hwmon is using it.
Quoted 17 lines
Quoted 17 lines
drivers/misc/aspeed-peci.c new file +17
-0+static int aspeed_peci_open (struct inode *inode,struct file *filp) +{ +struct aspeed_peci *priv = + container_of(filp->private_data, struct aspeed_peci, miscdev); + +atomic_inc (&priv->ref_count); + +dev_dbg (priv->dev,"ref_count : %d\n" ,atomic_read (&priv->ref_count)); + +return 0 ; +} + +static int aspeed_peci_release (struct inode *inode,struct file *filp) +{ +struct aspeed_peci *priv = + container_of(filp->private_data, struct aspeed_peci, miscdev); +
Quoted 9 lines
drivers/misc/aspeed-peci.c line 856
Quoted 6 lines
drivers/misc/aspeed-peci.c new file +6
-0+atomic_dec (&priv->ref_count); + +dev_dbg (priv->dev,"ref_count : %d\n" ,atomic_read (&priv->ref_count)); + +return 0 ; +}Nothing uses that reference count, drop it.
You are right. Will drop it.
Quoted 10 lines
Quoted 10 lines
new file mode 100644
index 0000000..66322c6include/misc/peci.h new file +5
-0@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#ifndef __PECI_H +#define __PECI_H
Quoted 9 lines
include/misc/peci.h line 11
Quoted 6 lines
include/misc/peci.h new file +6
-0+ +#include <linux/peci_ioctl.h> + +long peci_ioctl (struct file *filp,unsigned int cmd,unsigned long arg); + +#endif /* __PECI_H */ Not used anywhere.
peci_hwmon is using it.
Quoted 34 lines
Quoted 19 lines
include/uapi/linux/peci_ioctl.h new file +13
-0@@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#ifndef __PECI_IOCTL_H +#define __PECI_IOCTL_H + +#include <linux/ioctl.h> + +/* Base Address of 48d */ +#define PECI_BASE_ADDR 0x30/* The PECI client's default address of 0x30 */ +#define PECI_OFFSET_MAX 8/* Max numver of CPU clients */ + +/* PCI Access */ include/uapi/linux/peci_ioctl.h line 23
Quoted 10 lines
include/uapi/linux/peci_ioctl.h new file +10
-0+#define MAX_PCI_READ_LEN 24/* Number of bytes of the PCI Space read */ + +#define PCI_BUS0_CPU0 0x00 +#define PCI_BUS0_CPU1 0x80 +#define PCI_CPUBUSNO_BUS 0x00 +#define PCI_CPUBUSNO_DEV 0x08 +#define PCI_CPUBUSNO_FUNC 0x02 +#define PCI_CPUBUSNO 0xcc +#define PCI_CPUBUSNO_1 0xd0 +#define PCI_CPUBUSNO_VALID 0xd4I can't tell for sure, but this file seems to be mixing the kernel API with hardware specific macros that are not needed in user space. Can you move some of this file into the driver itself?
Quoted 4 lines
This might go back to the previous question about the high-level and low-level interfaces: if you can drop the low-level ioctl interface, more of this header can become private to the driver.
As I answered above, I'll check the spec again and remove the low-level command if the high-level command set covers all cases.
Quoted 11 lines
Quoted 11 lines
include/uapi/linux/peci_ioctl.h new file +11
-0+/* Package Identifier Read Parameter Value */ +#define PKG_ID_CPU_ID 0x0000/* 0 - CPUID Info */ +#define PKG_ID_PLATFORM_ID 0x0001/* 1 - Platform ID */ +#define PKG_ID_UNCORE_ID 0x0002/* 2 - Uncore Device ID */ +#define PKG_ID_MAX_THREAD_ID 0x0003/* 3 - Max Thread ID */ +#define PKG_ID_MICROCODE_REV 0x0004/* 4 - CPU Microcode Update Revision */ +#define PKG_ID_MACHINE_CHECK_STATUS 0x0005/* 5 - Machine Check Status */ + +/* RdPkgConfig Index */ +#define MBX_INDEX_CPU_ID 0/* Package Identifier Read */ +#define MBX_INDEX_VR_DEBUG 1/* VR Debug */
Quoted 9 lines
include/uapi/linux/peci_ioctl.h line 40
Quoted 5 lines
include/uapi/linux/peci_ioctl.h new file +5
-0+#define MBX_INDEX_PKG_TEMP_READ 2/* Package Temperature Read */ +#define MBX_INDEX_ENERGY_COUNTER 3/* Energy counter */ +#define MBX_INDEX_ENERGY_STATUS 4/* DDR Energy Status */ +#define MBX_INDEX_WAKE_MODE_BIT 5/* "Wake on PECI" Mode bit */ +#define MBX_INDEX_EPI 6/* Efficient Performance Indication */ Who defines these constants? Are they specific to the aspeed BMC, to the HECI protocol, or to a particular version of the remote endpoint?
These are common peci definitions, not the aspeed BMC specific.
Quoted 19 lines
Quoted 19 lines
include/uapi/linux/peci_ioctl.h new file +19
-0+#pragma pack(push, 1) +struct peci_xfer_msg { +unsigned char client_addr; +unsigned char tx_len; +unsigned char rx_len; +unsigned char tx_buf[MAX_BUFFER_SIZE ]; +unsigned char rx_buf[MAX_BUFFER_SIZE ]; +}; +#pragma pack(pop) + +struct peci_ping_msg { +unsigned char target; +}; + +struct peci_get_dib_msg { +unsigned char target; +unsigned int dib; +}; +
Quoted 9 lines
include/uapi/linux/peci_ioctl.h line 174
Quoted 4 lines
include/uapi/linux/peci_ioctl.h new file +4
-0+struct peci_get_temp_msg { +unsigned char target; +signed short temp_raw; +};Aside from what Greg already said about the types, please be careful to also avoid implicit padding in the API data structures, including the end of the structure.
Okay, I'll expand the pack() scope for all these definition.
Quoted 15 lines
include/uapi/linux/peci_ioctl.h line 268
Quoted 11 lines
include/uapi/linux/peci_ioctl.h new file +11
-0+#define PECI_IOC_RD_PCI_CFG \ + _IOWR(PECI_IOC_BASE + PECI_CMD_RD_PCI_CFG, 0, \ + struct peci_rd_pci_cfg_msg) + +#define PECI_IOC_RD_PCI_CFG_LOCAL \ + _IOWR(PECI_IOC_BASE + PECI_CMD_RD_PCI_CFG_LOCAL, 0, \ + struct peci_rd_pci_cfg_local_msg) + +#define PECI_IOC_WR_PCI_CFG_LOCAL \ + _IOWR(PECI_IOC_BASE + PECI_CMD_WR_PCI_CFG_LOCAL, 0, \ + struct peci_wr_pci_cfg_local_msg)Can you give some background on what these do? In particular, who is configuring whose PCI devices?
Quoted 2 lines
Arnd
These are commands to read/write a client CPU's PCI configuration which could be an end-point of the physical PECI interface connection. BMC controller will be a host and a CPU will be a client.
Thanks,
Jae
Re: [PATCH linux dev-4.10 4/6] Documentation: dt-bindings: Add a generic PECI hwmon
In reply to Arnd BergmannQuoted 28 lines · Arnd Bergmann
Quoted 15 lines · Jae Hyun Yoo
This commit add a dt-bindings document for a generic PECI hwmon driver.
Signed-off-by Jae Hyun Yoo <[email protected]>--- .../devicetree/bindings/hwmon/peci-hwmon.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+)create mode 100644
Documentation/devicetree/bindings/hwmon/peci-hwmon.txtDocumentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +0
-0Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +5
-0@@ -0,0 +1,33 @@ +* Generic PECI (Platform Environment Control Interface) hwmon driver. + +Dependency: +- This driver uses a PECI misc driver as a controller interface so one of PECI + misc drivers which provides compatible ioctls has to be enabled.The binding should only explain how we describe the hardware in an operating-system
independent way, but not talk about how an OS is supposed to implement those drivers.
Quoted 5 lines
Having multiple drivers each provide an exported function is not possible in Linux: it immediately breaks building an 'allyesconfig' kernel, and prevents you from running the same kernel across multiple implementations, so that has to be redesigned anyway.
Agreed, I'll consider redesigning of it.
Quoted 12 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 13
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +7
-0+Required properties: +- compatible: "peci-hwmon" +- cpu-id: Should contain CPU socket ID + - 0 ~ 7 + +Optional properties: +- show-core: If this protperty is defined, core tmeperature attrubites will bes/protperty/property/
s/tmeperature/temperature/
s/attrubites/attributes/
Oops! I made this many typos in this single line. Thanks for your pointing it out. Will fix these.
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/hwmon/peci-hwmon.txt new file +5
-0+ enumerated. +- dimm-nums: Should contain the number of DIMM slots that attached to each CPU + which is indicated by cpu-id. + 0 ~ 16 (default: 16) + In case of 0, DIMM temperature attrubites will not be enumerated.
Quoted 8 lines
Is this only an initial list that you expect to be extended in the future, or is this
a complete list of sensors that can ever be connected to PECI?Should this be PECI version specific?
Arnd
The maximum supportable number of dimm slots is not PECI version specific but depends on CPU architecture. Currently IA supports up to 16 slot as the maximum but it could vary in the future architecture.
Thanks,
Jae
Re: [PATCH linux dev-4.10 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Arnd BergmannQuoted 31 lines · Arnd Bergmann
Quoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>drivers/hwmon/peci-hwmon.c line 123
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +}I said earlier that
peci_ioctl()looked unused, that was obviously wrong, but what you have here
is not a proper way to abstract a bus.Maybe this can be done more like an i2c bus: make the peci controller a bus device
and register all known target/index pairs as devices with the peci bus type, and have
them probed from DT. The driver can then bind to each of those individually. Not sure if that is getting to granular at that point, I'd have to understand better
how it is expected to get used, and what the variances are between implementations.
Quoted 2 lines
Arnd
Thanks for sharing your opinion. In fact, this was also suggested by openbmc community so I should consider of redesigning it. I'm currently thinking about adding a new PECI device class as an abstract layer and any BMC chipset specific driver could be attached to the PECI class driver. Then, each CPU client could be registered as an individual device as you suggested. Will consider your suggestion.
Thanks a lot!
Jae
Greg KH
maintainerQuoted 50 lines · Jae Hyun Yoo
Quoted 39 lines · Greg KH
Quoted 38 lines · Jae Hyun Yoo
Quoted 24 lines · Greg KH
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Greg KH
Quoted 9 lines · Jae Hyun Yoo
From: Jae Hyun Yoo <[email protected]>
Hello,
This patch set provides support for PECI of AST2400/2500 which can give us PECI functionalities such as temperature monitoring, platform manageability, processor diagnostics and failure analysis. Also provides generic
peci.handpeci_ioctl.hheaders to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.What is the "dev-4.10" in the subject for? 4.10 is really old and obsolete :(
Quoted 7 lines
Quoted 4 lines
thanks,
greg k-h
I made this patch set on top of the v4.10 which OpenBmc project is currently using. I'll rebase this patch set onto the current kernel.org mainline.
Quoted 7 lines
What is "OpenBmc", and why are they using an obsolete and insecure kernel for their project? That seems like a very foolish thing to do...
thanks,
greg k-h
OpenBmc is an open source project to create a highly extensible framework for BMC (Board Management Controller) software for data-center computer systems:
https://github.com/openbmcQuoted 9 lines
Quoted 2 lines
Its current mainline is v4.10 but it is being kept upgrading so it will be upgraded to the latest stable or long-term version soon.
Why hasn't it been updated in the year since 4.10 was released? That's a _very_ long time to be running on a totally insecure kernel, and no new development should ever be done on old kernels, that's even crazier (as we can't go back in time and accept patches for new features to old releases...)
Quoted 4 lines
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
What keeps you all from just always tracking the latest tree from Linus? What is in your tree that is not upstream that requires you to have a kernel tree at all?
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
thanks,
greg k-h
Joel Stanley
maintainerQuoted 8 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
It contains support for our hardware that I have integrated from work in progress patches and upstream commits.
The OpenBMC project, with myself as the kernel maintainer, have intentions to regularly move to upstream releases. This takes time and effort. This time and effort is balanced with submitting our drivers upstream.
Quoted 1 line
What keeps you all from just always tracking the latest tree from Linus?
Linus' tree does not contain all of the drivers required to boot systems. Many of them are still under review on lkml, and others still require rewrite from the vendor tree.
Quoted 2 lines
What is in your tree that is not upstream that requires you to have a kernel tree at all?
We have PECI, video compression, crypto, USB CDC, DRM (graphics), serial GPIO, LPC mailbox for the ASPEED SoC.
Another silicon vendor has recently joined the project and that brings an entire SoC that is not upstream. We have patches on the ARM that are under review for this SoC, with more drivers undergoing cleanup in order to submit them to the relevant maintainers.
Quoted 5 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
We have a process that we've been developing under for the past few years. I find git to be a great tool for managing Linux kernel trees.
What would you recommend for managing kernel trees?
Cheers,
Joel
Greg KH
maintainerQuoted 10 lines · Joel Stanley
Quoted 8 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
Quoted 7 lines
It contains support for our hardware that I have integrated from work in progress patches and upstream commits.
The OpenBMC project, with myself as the kernel maintainer, have intentions to regularly move to upstream releases. This takes time and effort. This time and effort is balanced with submitting our drivers upstream.
Of course, but please do not have your "users" use a kernel that is known to have bugs and can not be supported. That would not be good at all, don't you think?
Quoted 5 lines
Quoted 1 line
What keeps you all from just always tracking the latest tree from Linus?
Linus' tree does not contain all of the drivers required to boot systems. Many of them are still under review on lkml, and others still require rewrite from the vendor tree.
Merging vendor trees into your tree has got to be a complicated mess. Why try to keep it all together in one place?
And who is responsible for getting the vendor code upstream? The individual drivers? Individual driver submissions should be quite easy, what is preventing them from getting merged?
Quoted 5 lines
Quoted 2 lines
What is in your tree that is not upstream that requires you to have a kernel tree at all?
We have PECI, video compression, crypto, USB CDC, DRM (graphics), serial GPIO, LPC mailbox for the ASPEED SoC.
What "USB CDC" do you have that is not upstream? I'll pick on this one specifically as I don't think I've seen any patches recently submitted for that driver at all. Am I just missing them?
The other ones should also all be easy to get merged, with maybe the exception of the drm stuff due to the speed that subsystem moves at. But even there, the community is very helpful in getting stuff upstream, have you asked for help?
Quoted 4 lines
Another silicon vendor has recently joined the project and that brings an entire SoC that is not upstream. We have patches on the ARM that are under review for this SoC, with more drivers undergoing cleanup in order to submit them to the relevant maintainers.
Why are you merging all SoC trees together into one place? That seems like a nightmare to manage, especially with git.
Quoted 9 lines
Quoted 4 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
We have a process that we've been developing under for the past few years. I find git to be a great tool for managing Linux kernel trees.
What would you recommend for managing kernel trees?
quilt is best for a tree that you can not rebase (i.e. a public git tree). Otherwise you end up getting patches all mushed together and hard to extract in any simple way.
Take a clue from the distros that have been managing kernels for decades and deal with an updated kernel all the time easily.
Good luck, it sounds like you will need it :)
thanks,
greg k-h
Quoted 2 lines · Greg KH
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
Haha, it's n-1. come on :-)
Quoted 3 lines
What keeps you all from just always tracking the latest tree from Linus? What is in your tree that is not upstream that requires you to have a kernel tree at all?
There are a couple of ARM based SoC families for which we are in the process of rewriting all the driver in upstreamable form. This takes time.
To respond to your other email about the USB CDC, it's mine, I haven't resubmited it yet because it had a dependency on some the aspeed clk driver to function properly (so is unusable without it) and it took 2 kernel versions to get that clk stuff upstream for a number of reasons.
So it's all getting upstream and eventually there will be (we hope) no "OpenBMC" kernel, it's just a way for us to get functional code with non-upstream-quality (read: vendor) drivers until we are one rewriting & upstreaming them all.
Quoted 4 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
Joel and I both find git perfectly fine for that. I've not touched quilt in eons and frankly don't regret it ;-)
That said, Jae should definitely submit a driver against upstream, not against some random OpenBMC tree.
Jae, for example when I submitted the original USB stuff back then, I did it from a local upstream based branch (with just a few hacks to work around the lack of the clk stuff).
I will rebase it in the next few days to upstream merged with Stephen's clk tree to get the finally merged clk stuff, verify it works, and submit patches against upstream.
There should be no mention of dev-4.10 or 4.13 on lkml or other upstream submission lists. Development work should happen upstream *first* and eventually be backported to our older kernels while they exist (hopefully I prefer if we are more aggressive at forward porting the crappy drivers so we can keep our tree more up to date but that's a different discussion).
Cheers,
Ben.
Quoted 3 lines
thanks,
greg k-h
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Greg KHQuoted 11 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.We don't add code that could be used "sometime in the future". Only include stuff that we use now.
Please fix up this series based on that and resubmit. There should not be any need for any uapi file then, right?
No Greg, I think you misunderstood (unless I misread myself).
What Jae means is that since PECI is a standard and other drivers implementing the same ioctl interface and messages will eventually go upstream, instead of having the ioctl definitions in a driver specific locations, they go in a generic spot, as they define a generic API for all PECI drivers, including the one that's getting merged now.
IE. This doesn't add unused stuff, it just puts the API parts of it into a generic location.
At least that's my understanding from a, granted cursory, look at the patch.
That said, I do have a problem with the structure definitions of the various packet types as they use "long" which has a variable size and unclear alignment. It should be using __u8, __u16 and __u32...
Cheers,
Ben.
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Jae Hyun Yooinclude/uapi/linux/peci_ioctl.h line 197
Quoted 6 lines · Jae Hyun Yoo
include/uapi/linux/peci_ioctl.h new file +6
-0+struct peci_rd_ia_msr_msg { +unsigned char target; +unsigned char thread_id; +unsigned short address; +unsigned long value; +};
Those types are representing messages on the wire ?
In that case those types aren't suitable. For example "long" will have a different size and alignment for 32 and 64-bit userspace. There are size-explicit userspace types available.
Also I didn't see any endianness annotations in there. Is that expected ? IE are those wire format packets ?
Cheers,
Ben.
Arnd Bergmann
maintainerQuoted 14 lines · Greg KH
Quoted 13 lines · Joel Stanley
Quoted 8 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
It contains support for our hardware that I have integrated from work in progress patches and upstream commits.
Quoted 8 lines
Quoted 4 lines
The OpenBMC project, with myself as the kernel maintainer, have intentions to regularly move to upstream releases. This takes time and effort. This time and effort is balanced with submitting our drivers upstream.
Of course, but please do not have your "users" use a kernel that is known to have bugs and can not be supported. That would not be good at all, don't you think?
I've been pretty happy with the progress in merging drivers upstream for OpenBMC. Of course things always take longer than planned, but they are getting there. Most servers today are probably running the aspeed vendor kernel based on linux-2.6.28.10, at least that's what my workstation runs (and no, I did not connect the BMC to my home network).
The particular choices of mainline versions (4.10 and 4.13) may be unfortunate as they are both one off from a longterm release, but not being stuck on 2.6 is the important first step in order to upstream stuff.
Quoted 7 lines
Quoted 4 lines
Another silicon vendor has recently joined the project and that brings an entire SoC that is not upstream. We have patches on the ARM that are under review for this SoC, with more drivers undergoing cleanup in order to submit them to the relevant maintainers.
Why are you merging all SoC trees together into one place? That seems like a nightmare to manage, especially with git.
Why would anyone want to have multiple kernel trees just to run things on different SoCs? ;-)
It's just a collection of device drivers in different stages of getting upstreamed.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
Quoted 8 lines
Quoted 4 lines
We have a process that we've been developing under for the past few years. I find git to be a great tool for managing Linux kernel trees.
What would you recommend for managing kernel trees?
quilt is best for a tree that you can not rebase (i.e. a public git tree). Otherwise you end up getting patches all mushed together and hard to extract in any simple way.
I'm ususally happy with having git with topic branches to make the rebasing easier. In many cases, you can just leave a topic branch for a particular subsystem unchanged between versions and just merge the latest version of those branches until the branch goes away after upstreaming.
Arnd
Quoted 14 lines · Greg KH
Quoted 13 lines · Joel Stanley
Quoted 8 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
Thanks for your pointing it out and I totally agree with you. Actually, we are preparing 4.13 update for now and an another update will be followed up. As I answered above, I'll rebase this patch set onto the latest kernel.org mainline. Sorry for my misunderstanding of upstream process.
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
It contains support for our hardware that I have integrated from work in progress patches and upstream commits.
Quoted 8 lines
Quoted 4 lines
The OpenBMC project, with myself as the kernel maintainer, have intentions to regularly move to upstream releases. This takes time and effort. This time and effort is balanced with submitting our drivers upstream.
Of course, but please do not have your "users" use a kernel that is known to have bugs and can not be supported. That would not be good at all, don't you think?
There is little choice, we don't have the manpower to rewrite/upstream all the drivers in a day, and rebasing to newer kernel takes time due to various dependencies, testing requirements etc.
That being said, 4.13 is N-1, not too bad.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What keeps you all from just always tracking the latest tree from Linus?
Linus' tree does not contain all of the drivers required to boot systems. Many of them are still under review on lkml, and others still require rewrite from the vendor tree.
Merging vendor trees into your tree has got to be a complicated mess. Why try to keep it all together in one place?
There are no vendor trees to speak of that we could merge. At least not yet. We've been teaching vendors about doing proper drivers that can work with upstream, device-tree based platforms etc... but it takes time for them to get up to speed.
So while we are rewriting the drivers (sometimes with the vendor's help), we keep a tree with the "sub-standard" ones hacked up to work on our DT based platform and with our other bits and pieces until we can ditch it.
Quoted 3 lines
And who is responsible for getting the vendor code upstream? The individual drivers? Individual driver submissions should be quite easy, what is preventing them from getting merged?
It just takes time Greg. The original vendor drivers are in no shape to get anywhere near upstream. They have to be mostly rewritten one by one. Sometimes we can teach the vendor and help them along, some times we do it ourselves, but it's a time consuming process. It took 2 or 3 kernel versions just to get the clk drivers that Joel had written upstream for example. It took me a long time as well to get ftgmac100 sorted.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
What is in your tree that is not upstream that requires you to have a kernel tree at all?
We have PECI, video compression, crypto, USB CDC, DRM (graphics), serial GPIO, LPC mailbox for the ASPEED SoC.
What "USB CDC" do you have that is not upstream?
See my other email :)
Quoted 8 lines
I'll pick on this one
specifically as I don't think I've seen any patches recently submitted for that driver at all. Am I just missing them?The other ones should also all be easy to get merged, with maybe the exception of the drm stuff due to the speed that subsystem moves at. But even there, the community is very helpful in getting stuff upstream, have you asked for help?
We can't expect the community to rewrite the drivers for us. Some of the clk and pinmux stuff is intrinsically very complex, and took time (and we did get valuable feedback).
Now that these basic pieces of infrastructure are in, it's a matter of tackling the remaining drivers one at a time.
Quoted 7 lines
Quoted 4 lines
Another silicon vendor has recently joined the project and that brings an entire SoC that is not upstream. We have patches on the ARM that are under review for this SoC, with more drivers undergoing cleanup in order to submit them to the relevant maintainers.
Why are you merging all SoC trees together into one place? That seems like a nightmare to manage, especially with git.
There are no SoC trees per-se.
There is the OpenBMC tree which has hand-hacked vendor drivers plugged into it, which are going away one at a time as we clean them up. There's really one SoC family only in use (aspeed) at the moment with one other coming around the corner (Nuvoton). For the latter, my understanding is that we are trying to get the vendor to get their stuff upstream directly.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
We have a process that we've been developing under for the past few years. I find git to be a great tool for managing Linux kernel trees.
What would you recommend for managing kernel trees?
Quoted 8 lines
quilt is best for a tree that you can not rebase (i.e. a public git tree). Otherwise you end up getting patches all mushed together and hard to extract in any simple way.
Take a clue from the distros that have been managing kernels for decades and deal with an updated kernel all the time easily.
Good luck, it sounds like you will need it :)
Nah, not luck, we just need to get those drivers done one at a time, it's not a matter of luck.
And I find git to be just fine :)
Cheers,
Ben.
Quoted 3 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 5 lines · Benjamin Herrenschmidt
Quoted 2 lines · Greg KH
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
Haha, it's n-1. come on :-)
And, if you use it in a device, it's still totally unsupported and insecure. Seriously, does no one actually pay attention to the patches I merge in the stable trees anymore?
Anyway, your other comments are good, glad to see work is progressing well, and yes it's better than a 2.6.y based kernel, but really, that's a low bar...
thanks,
greg k-h
Arnd Bergmann
maintainerRe: [PATCH linux dev-4.10 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Jae Hyun YooQuoted 38 lines · Jae Hyun Yoo
Quoted 25 lines · Arnd Bergmann
Quoted 6 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>drivers/hwmon/peci-hwmon.c line 123
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +}I said earlier that
peci_ioctl()looked unused, that was obviously wrong, but what you have here
is not a proper way to abstract a bus.Quoted 11 lines
Maybe this can be done more like an i2c bus: make the peci controller a bus device
and register all known target/index pairs as devices with the peci bus type, and have
them probed from DT. The driver can then bind to each of those individually.
Not sure if that is getting to granular at that point, I'd have to understand better
how it is expected to get used, and what the variances are between implementations.
Quoted 6 lines
Thanks for sharing your opinion. In fact, this was also suggested by openbmc community so I should consider of redesigning it. I'm currently thinking about adding a new PECI device class as an abstract layer and any BMC chipset specific driver could be attached to the PECI class driver. Then, each CPU client could be registered as an individual device as you suggested. Will consider your suggestion.
Another idea might be to pretend that PECI was I2C. We already have a few drivers for hardware that is not I2C but whose software interface looks similar enough that it just works. No idea if that is the case for PECI, but xfer_peci_msg might be close enough to i2c_xfer to make it work. If you are able to do that, then the PECI controller would just register itself as an i2c controller and it can be accessed using /dev/i2c from user space or a high-level i2c_driver.
Arnd
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Guenter RoeckQuoted 54 lines · Guenter Roeck
Quoted 53 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>--- drivers/hwmon/Kconfig | 6 + drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-hwmon.c | 953 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 960 insertions(+)create mode 100644
drivers/hwmon/peci-hwmon.cdrivers/hwmon/Kconfig +6
-0@@ -1234,6 +1234,12 @@ config SENSORS_NCT7904 This driver can also be built as a module. If so, the module will be called nct7904. +config SENSORS_PECI_HWMON + tristate "PECI hwmon support" + depends on ASPEED_PECI + help + If you say yes here you get support for the generic PECI hwmon driver. + config SENSORS_NSA320 tristate "ZyXEL NSA320 and compatible fan speed and temperature sensors" depends on GPIOLIB && OFdrivers/hwmon/Makefile +1
-0@@ -131,6 +131,7 @@ obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o obj-$(CONFIG_SENSORS_NCT7904) += nct7904.o obj-$(CONFIG_SENSORS_NSA320) += nsa320-hwmon.o obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o +obj-$(CONFIG_SENSORS_PECI_HWMON) += peci-hwmon.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.odrivers/hwmon/peci-hwmon.c new file +8
-0@@ -0,0 +1,953 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017 Intel Corporation + +#include <linux/delay.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> +#include <linux/jiffies.h> +#include <linux/module.h>
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 14
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+#include <linux/mutex.h> +#include <linux/of_platform.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/syscalls.h> +#include <misc/peci.h> misc, not linux ? That seems wrong.
You are right. I'll fix it.
Quoted 11 lines
drivers/hwmon/peci-hwmon.c line 21
Quoted 7 lines
drivers/hwmon/peci-hwmon.c new file +7
-0+ +#define DEVICE_NAME "peci-hwmon" +#define HWMON_NAME "peci_hwmon" + +#define CPU_ID_MAX 8/* Max CPU number configured by socket ID */ +#define DIMM_NUMS_MAX 16/* Max DIMM numbers (channel ranks x 2) */ +#define CORE_NUMS_MAX 28/* Max core numbers (max on SKX Platinum) */ I won't insist, but it would be better if this were dynamic, otherwise we'll end up having to increase the defines in the future.
Right. As you said, these values should be manually adjusted in the future if CPU architecture has been changed so better implement it as dynamic. I will check again a way of getting these values from client CPU thru PECI connection.
Quoted 10 lines
drivers/hwmon/peci-hwmon.c line 24
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+#define TEMP_TYPE_PECI 6/* Sensor type 6: Intel PECI */ +#define CORE_INDEX_OFFSET 100/* sysfs filename start offset for core temp */ +#define DIMM_INDEX_OFFSET 200/* sysfs filename start offset for DIMM temp */ Did you test with the "sensors" command to ensure that this works, with the large gaps in index values ?
Overall, I am not very happy with the indexing. Since each sensor as a label, it might be better to just make it dynamic.
Okay, that makes sense. Since all attributes has its own label, indexing gap wouldn't be needed even in case of CPU architecture change happens. I'll remove the indexing gap.
Quoted 76 lines
Quoted 76 lines
drivers/hwmon/peci-hwmon.c new file +76
-0+#define TEMP_NAME_HEADER_LEN 4/* sysfs temp type header length */ +#define OF_DIMM_NUMS_DEFAULT 16/* default dimm-nums setting */ + +#define CORE_TEMP_ATTRS 5 +#define DIMM_TEMP_ATTRS 2 +#define ATTR_NAME_LEN 24 + +#define UPDATE_INTERVAL_MIN HZ + +enum sign_t { +POS , +NEG +}; + +struct cpuinfo_t { +bool valid; +u32 dib; +u8 cpuid; +u8 platform_id; +u32 microcode; +u8 logical_thread_nums; +}; + +struct temp_data_t { +bool valid; +s32 value; +unsigned long last_updated; +}; + +struct temp_group_t { +struct temp_data_t tjmax; +struct temp_data_t tcontrol; +struct temp_data_t tthrottle; +struct temp_data_t dts_margin; +struct temp_data_t die; +struct temp_data_t core[CORE_NUMS_MAX ]; +struct temp_data_t dimm[DIMM_NUMS_MAX ]; +}; + +struct core_temp_attr_group_t { +struct sensor_device_attribute sd_attrs[CORE_NUMS_MAX ][CORE_TEMP_ATTRS ]; +char attr_name[CORE_NUMS_MAX ][CORE_TEMP_ATTRS ][ATTR_NAME_LEN ]; +struct attribute *attrs[CORE_NUMS_MAX ][CORE_TEMP_ATTRS +1 ]; +struct attribute_group attr_group[CORE_NUMS_MAX ]; +}; + +struct dimm_temp_attr_group_t { +struct sensor_device_attribute sd_attrs[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS ]; +char attr_name[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS ][ATTR_NAME_LEN ]; +struct attribute *attrs[DIMM_NUMS_MAX ][DIMM_TEMP_ATTRS +1 ]; +struct attribute_group attr_group[DIMM_NUMS_MAX ]; +}; + +struct peci_hwmon { +struct device *dev; +struct device *hwmon_dev; +char name[NAME_MAX ]; +const struct attribute_group **groups; +struct cpuinfo_t cpuinfo; +struct temp_group_t temp; +u32 cpu_id; +bool show_core; +u32 core_nums; +u32 dimm_nums; +atomic_t core_group_created; +struct core_temp_attr_group_t core; +struct dimm_temp_attr_group_t dimm; +}; + +enum label_t { +L_DIE , +L_DTS , +L_TCONTROL , +L_TTHROTTLE , +L_MAX +};
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 106
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+ +static const char *peci_label[L_MAX ] = { +"Die temperature\n" , +"DTS thermal margin to Tcontrol\n" , +"Tcontrol temperature\n" , +"Tthrottle temperature\n" ,"temperature" is redundant for a temperature label.
Agreed. Will remove the redundant string.
Quoted 8 lines
drivers/hwmon/peci-hwmon.c line 111
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+}; + +static DEFINE_MUTEX (peci_hwmon_lock); + +static int create_core_temp_group (struct peci_hwmon *priv,int core_no);Please avoid forward declarations.
Will fix it.
Quoted 6 lines
drivers/hwmon/peci-hwmon.c line 113
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+ +Please run your patches throuch checkpatch --strict and fix what it reports, or provide a reason why you don't.
Thanks for the tip. I didn't know about the --strict option before. Checked that the option reports more check points such as this multiple blank line case. I will run all patches again using --strict option.
Quoted 69 lines
Quoted 69 lines
drivers/hwmon/peci-hwmon.c new file +69
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +} + +static int get_cpuinfo (struct peci_hwmon *priv) +{ +struct peci_get_dib_msg dib_msg; +struct peci_rd_pkg_cfg_msg cfg_msg; +int rc, i; + +if (!priv->cpuinfo.valid) { + dib_msg.target =PECI_BASE_ADDR + priv->cpu_id; + + rc =xfer_peci_msg (PECI_IOC_GET_DIB , (void *)&dib_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.dib = dib_msg.dib; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =0 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.cpuid = cfg_msg.pkg_config[0 ]; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =1 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.platform_id = cfg_msg.pkg_config[0 ]; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =3 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.logical_thread_nums = cfg_msg.pkg_config[0 ] +1 ; + + cfg_msg.target =PECI_BASE_ADDR + priv->cpu_id; + cfg_msg.index =MBX_INDEX_CPU_ID ; + cfg_msg.param =4 ; + cfg_msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&cfg_msg); +if (rc <0 ) +return rc; + + priv->cpuinfo.microcode = (cfg_msg.pkg_config[3] << 24) |
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 187
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+ (cfg_msg.pkg_config[2 ] <<16 ) | + (cfg_msg.pkg_config[1 ] <<8 ) | + cfg_msg.pkg_config[0 ]; + + priv->core_nums = priv->cpuinfo.logical_thread_nums /2 ;This seems to assume a 1:2 relationship between number of threads and number of CPUs, which is incorrect.
You are right. This can't cover all CPUs. Will find a proper way.
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 192
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+ +if (priv->show_core && +atomic_inc_return (&priv->core_group_created) ==1 ) { +for (i =0 ; i < priv->core_nums; i++) { + rc =create_core_temp_group (priv, i);This is messy. Sensor groups should be created before or during hwmon registration, not at some arbitrary later time.
Quoted 3 lines
I don't know the logic behind this, but if it is supposed to track CPUs coming online and going offline it is the wrong approach.
Agreed. This driver wouldn't make communication with CPUs at all if CPUs are powered down so we don't need to leave this driver as inserted. As you commented below, if a agent does insert/remove this driver module while tracking CPU power state, this delayed creation logic wouldn't be needed. I will rewrite it.
Quoted 54 lines
Quoted 54 lines
drivers/hwmon/peci-hwmon.c new file +54
-0+if (rc !=0 ) { +dev_err (priv->dev, +"Failed to create core temp group\n" ); +for (--i; i >=0 ; i--) { +sysfs_remove_group ( + &priv->hwmon_dev->kobj, + &priv->core.attr_group[i]); + } +atomic_set (&priv->core_group_created, +0 ); +return rc; + } + } + } + + priv->cpuinfo.valid = true; + } + +return 0 ; +} + +static int get_tjmax (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +int rc; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + +if (!priv->temp.tjmax.valid) { + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.tjmax.value = (s32 )msg.pkg_config[2 ] *1000 ; + priv->temp.tjmax.valid = true; + } + +return 0 ; +} + +static int get_tcontrol (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 tcontrol_margin; +int rc; + + if (priv->temp.tcontrol.valid &&
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 250
Quoted 4 lines
drivers/hwmon/peci-hwmon.c new file +4
-0+ time_before(jiffies, priv->temp.tcontrol.last_updated + + UPDATE_INTERVAL_MIN)) +return 0 ; +Is the delay necessary ? Otherwise I would suggest to drop it. It adds a lot of complexity to the driver. Also, if the user polls values more often, that is presumably on purpose.
I was intended to reduce traffic on PECI bus because it's low speed single wired bus, and temperature values don't change frequently because the value is sampled and averaged in CPU itself. I'll keep this.
Quoted 104 lines
Quoted 104 lines
drivers/hwmon/peci-hwmon.c new file +104
-0+ rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + tcontrol_margin = msg.pkg_config[1 ]; + tcontrol_margin = ((tcontrol_margin ^0x80 ) -0x80 ) *1000 ; + + priv->temp.tcontrol.value = priv->temp.tjmax.value - tcontrol_margin; + +if (!priv->temp.tcontrol.valid) { + priv->temp.tcontrol.last_updated =INITIAL_JIFFIES ; + priv->temp.tcontrol.valid = true; + }else { + priv->temp.tcontrol.last_updated = jiffies; + } + +return 0 ; +} + +static int get_tthrottle (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 tthrottle_offset; +int rc; + +if (priv->temp.tthrottle.valid && +time_before (jiffies, priv->temp.tthrottle.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_TEMP_TARGET ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + tthrottle_offset = (msg.pkg_config[3 ] &0x2f ) *1000 ; + priv->temp.tthrottle.value = priv->temp.tjmax.value - tthrottle_offset; + +if (!priv->temp.tthrottle.valid) { + priv->temp.tthrottle.last_updated =INITIAL_JIFFIES ; + priv->temp.tthrottle.valid = true; + }else { + priv->temp.tthrottle.last_updated = jiffies; + } + +return 0 ; +} + +static int get_die_temp (struct peci_hwmon *priv) +{ +struct peci_get_temp_msg msg; +int rc; + +if (priv->temp.die.valid && +time_before (jiffies, priv->temp.die.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + + rc =xfer_peci_msg (PECI_IOC_GET_TEMP , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.die.value = priv->temp.tjmax.value + + ((s32 )msg.temp_raw *1000 /64 ); + +if (!priv->temp.die.valid) { + priv->temp.die.last_updated =INITIAL_JIFFIES ; + priv->temp.die.valid = true; + }else { + priv->temp.die.last_updated = jiffies; + } + +return 0 ; +} + +static int get_dts_margin (struct peci_hwmon *priv) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 dts_margin; +int rc; +
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 359
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+if (priv->temp.dts_margin.valid && +time_before (jiffies, priv->temp.dts_margin.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; +Are all those values expected to change dynamically, or are some static ? Static values do not have to be re-read repeatedly but can be cached permanently.
All values expected to change dynamically except the Tjmax value which is fused in CPU package, but the Tjmax varies on each CPU package so we need to read the Tjmax at least once. Current implementation uses cached Tjmax value after the first reading on the value.
Quoted 23 lines
Quoted 23 lines
drivers/hwmon/peci-hwmon.c new file +23
-0+ rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_DTS_MARGIN ; + msg.param =0 ; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + dts_margin = (msg.pkg_config[1 ] <<8 ) | msg.pkg_config[0 ]; + +/* +* Processors return a value of DTS reading in 10.6 format +* (10 bits signed decimal, 6 bits fractional). +* Error codes: +* 0x8000: General sensor error +* 0x8001: Reserved +* 0x8002: Underflow on reading value +* 0x8003-0x81ff: Reserved
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 388
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+*/ +if (dts_margin >=0x8000 && dts_margin <=0x81ff ) +return -1 ; + + dts_margin = ((dts_margin ^0x8000 ) -0x8000 ) *1000 /64 ; +The above code is repeated several times. Please consider moving it into a function to reduce duplication.
Okay. I will move it to a function.
Quoted 123 lines
Quoted 123 lines
drivers/hwmon/peci-hwmon.c new file +123
-0+ priv->temp.dts_margin.value = dts_margin; + +if (!priv->temp.dts_margin.valid) { + priv->temp.dts_margin.last_updated =INITIAL_JIFFIES ; + priv->temp.dts_margin.valid = true; + }else { + priv->temp.dts_margin.last_updated = jiffies; + } + +return 0 ; +} + +static int get_core_temp (struct peci_hwmon *priv,int core_index) +{ +struct peci_rd_pkg_cfg_msg msg; +s32 core_dts_margin; +int rc; + +if (priv->temp.core[core_index].valid && +time_before (jiffies, priv->temp.core[core_index].last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_PER_CORE_DTS_TEMP ; + msg.param = core_index; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + core_dts_margin = (msg.pkg_config[1 ] <<8 ) | msg.pkg_config[0 ]; + +/* +* Processors return a value of the core DTS reading in 10.6 format +* (10 bits signed decimal, 6 bits fractional). +* Error codes: +* 0x8000: General sensor error +* 0x8001: Reserved +* 0x8002: Underflow on reading value +* 0x8003-0x81ff: Reserved +*/ +if (core_dts_margin >=0x8000 && core_dts_margin <=0x81ff ) +return -1 ; + + core_dts_margin = ((core_dts_margin ^0x8000 ) -0x8000 ) *1000 /64 ; + + priv->temp.core[core_index].value = priv->temp.tjmax.value + + core_dts_margin; + +if (!priv->temp.core[core_index].valid) { + priv->temp.core[core_index].last_updated =INITIAL_JIFFIES ; + priv->temp.core[core_index].valid = true; + }else { + priv->temp.core[core_index].last_updated = jiffies; + } + +return 0 ; +} + +static int get_dimm_temp (struct peci_hwmon *priv,int dimm_index) +{ +struct peci_rd_pkg_cfg_msg msg; +int channel_rank = dimm_index /2 ; +int dimm_order = dimm_index %2 ; +int rc; + +if (priv->temp.core[dimm_index].valid && +time_before (jiffies, priv->temp.core[dimm_index].last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + + msg.target =PECI_BASE_ADDR + priv->cpu_id; + msg.index =MBX_INDEX_DDR_DIMM_TEMP ; + msg.param = channel_rank; + msg.rx_len =4 ; + + rc =xfer_peci_msg (PECI_IOC_RD_PKG_CFG , (void *)&msg); +if (rc <0 ) +return rc; + + priv->temp.dimm[dimm_index].value = msg.pkg_config[dimm_order] *1000 ; + +if (!priv->temp.dimm[dimm_index].valid) { + priv->temp.dimm[dimm_index].last_updated =INITIAL_JIFFIES ; + priv->temp.dimm[dimm_index].valid = true; + }else { + priv->temp.dimm[dimm_index].last_updated = jiffies; + } + +return 0 ; +} + +static ssize_t show_info (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_cpuinfo (priv); +if (rc <0 ) +return rc; + + return sprintf(buf, "dib : 0x%08x\n" + "cpuid : 0x%x\n" + "platform id : %d\n" + "stepping : %d\n" + "microcode : 0x%08x\n" + "logical thread nums : %d\n", + priv->cpuinfo.dib, + priv->cpuinfo.cpuid, + priv->cpuinfo.platform_id, + priv->cpuinfo.cpuid & 0xf,
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 514
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ priv->cpuinfo.microcode, + priv->cpuinfo.logical_thread_nums); +}Please no non-standard attributes, much less attributes not following sysfs attribute rules. If you want to display such information, consider using debugfs. Besides, this information specifically appears to duplicate the content of
/proc/cpuid, which doesn't really add any value at all.
Got it. Will drop this non-standard attribute.
Quoted 152 lines
Quoted 138 lines
drivers/hwmon/peci-hwmon.c new file +138
-0+ +static ssize_t show_tcontrol (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tcontrol (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tcontrol.value); +} + +static ssize_t show_tcontrol_margin (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int rc; + + rc =get_tcontrol (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , sensor_attr->index ==POS ? + priv->temp.tjmax.value - + priv->temp.tcontrol.value : + priv->temp.tcontrol.value - + priv->temp.tjmax.value); +} + +static ssize_t show_tthrottle (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tthrottle (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tthrottle.value); +} + +static ssize_t show_tjmax (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_tjmax (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.tjmax.value); +} + +static ssize_t show_die_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_die_temp (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.die.value); +} + +static ssize_t show_dts_therm_margin (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +int rc; + + rc =get_dts_margin (priv); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.dts_margin.value); +} + +static ssize_t show_core_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int core_index = sensor_attr->index; +int rc; + + rc =get_core_temp (priv, core_index); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.core[core_index].value); +} + +static ssize_t show_dimm_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct peci_hwmon *priv =dev_get_drvdata (dev); +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); +int dimm_index = sensor_attr->index; +int rc; + + rc =get_dimm_temp (priv, dimm_index); +if (rc <0 ) +return rc; + +return sprintf (buf,"%d\n" , priv->temp.dimm[dimm_index].value); +} + +static ssize_t show_value (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf,"%d\n" , sensor_attr->index); +} + +static ssize_t show_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf, peci_label[sensor_attr->index]);drivers/hwmon/peci-hwmon.c line 662
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+} + +static ssize_t show_core_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +return sprintf (buf,"Core #%d temperature\n" , sensor_attr->index); +}Your label strings are quite long. How does that look like with the sensors command ?
Quoted 2 lines
Plus, again, "temperature" in a temperature label is redundant.
Agreed. Will remove the redundant string.
Quoted 192 lines
Quoted 192 lines
drivers/hwmon/peci-hwmon.c new file +192
-0+ +static ssize_t show_dimm_label (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr); + +char channel ='A' + (sensor_attr->index /2 ); +int index = sensor_attr->index %2 ; + +return sprintf (buf,"Channel Rank %c DDR DIMM #%d temperature\n" , + channel, index); +} + +/* Die temperature */ +static SENSOR_DEVICE_ATTR(temp1_label, 0444, show_label, NULL, L_DIE); +static SENSOR_DEVICE_ATTR(temp1_input, 0444, show_die_temp, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_max, 0444, show_tcontrol, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_crit, 0444, show_tjmax, NULL, 0); +static SENSOR_DEVICE_ATTR(temp1_crit_hyst, 0444, show_tcontrol_margin, NULL, + POS); + +static struct attribute *die_temp_attrs[] = { + &sensor_dev_attr_temp1_label.dev_attr.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp1_max.dev_attr.attr, + &sensor_dev_attr_temp1_crit.dev_attr.attr, + &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, +NULL +}; + +static const struct attribute_group die_temp_attr_group = { + .attrs = die_temp_attrs, +}; + +/* DTS thermal margin temperature */ +static SENSOR_DEVICE_ATTR(temp2_label, 0444, show_label, NULL, L_DTS); +static SENSOR_DEVICE_ATTR(temp2_input, 0444, show_dts_therm_margin, NULL, 0); +static SENSOR_DEVICE_ATTR(temp2_min, 0444, show_value, NULL, 0); +static SENSOR_DEVICE_ATTR(temp2_lcrit, 0444, show_tcontrol_margin, NULL, NEG); + +static struct attribute *dts_margin_temp_attrs[] = { + &sensor_dev_attr_temp2_label.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp2_min.dev_attr.attr, + &sensor_dev_attr_temp2_lcrit.dev_attr.attr, +NULL +}; + +static const struct attribute_group dts_margin_temp_attr_group = { + .attrs = dts_margin_temp_attrs, +}; + +/* Tcontrol temperature */ +static SENSOR_DEVICE_ATTR(temp3_label, 0444, show_label, NULL, L_TCONTROL); +static SENSOR_DEVICE_ATTR(temp3_input, 0444, show_tcontrol, NULL, 0); +static SENSOR_DEVICE_ATTR(temp3_crit, 0444, show_tjmax, NULL, 0); + +static struct attribute *tcontrol_temp_attrs[] = { + &sensor_dev_attr_temp3_label.dev_attr.attr, + &sensor_dev_attr_temp3_input.dev_attr.attr, + &sensor_dev_attr_temp3_crit.dev_attr.attr, +NULL +}; + +static const struct attribute_group tcontrol_temp_attr_group = { + .attrs = tcontrol_temp_attrs, +}; + +/* Tthrottle temperature */ +static SENSOR_DEVICE_ATTR(temp4_label, 0444, show_label, NULL, L_TTHROTTLE); +static SENSOR_DEVICE_ATTR(temp4_input, 0444, show_tthrottle, NULL, 0); + +static struct attribute *tthrottle_temp_attrs[] = { + &sensor_dev_attr_temp4_label.dev_attr.attr, + &sensor_dev_attr_temp4_input.dev_attr.attr, +NULL +}; + +static const struct attribute_group tthrottle_temp_attr_group = { + .attrs = tthrottle_temp_attrs, +}; + +/* CPU info */ +static SENSOR_DEVICE_ATTR(info, 0444, show_info, NULL, 0); + +static struct attribute *info_attrs[] = { + &sensor_dev_attr_info.dev_attr.attr, +NULL +}; + +static const struct attribute_group info_attr_group = { + .attrs = info_attrs, +}; + +const struct attribute_group *peci_hwmon_attr_groups[] = { + &info_attr_group, + &die_temp_attr_group, + &dts_margin_temp_attr_group, + &tcontrol_temp_attr_group, + &tthrottle_temp_attr_group, +NULL +}; + +static ssize_t (*const core_show_fn[CORE_TEMP_ATTRS ]) (struct device *dev, +struct device_attribute *devattr,char *buf) = { + show_core_label, + show_core_temp, + show_tcontrol, + show_tjmax, + show_tcontrol_margin, +}; + +static const char *const core_suffix[CORE_TEMP_ATTRS ] = { +"label" , +"input" , +"max" , +"crit" , +"crit_hyst" , +}; + +static int create_core_temp_group (struct peci_hwmon *priv,int core_no) +{ +int i; + +for (i =0 ; i <CORE_TEMP_ATTRS ; i++) { +snprintf (priv->core.attr_name[core_no][i], +ATTR_NAME_LEN ,"temp%d_%s" , +CORE_INDEX_OFFSET + core_no, core_suffix[i]); +sysfs_attr_init ( + &priv->core.sd_attrs[core_no][i].dev_attr.attr); + priv->core.sd_attrs[core_no][i].dev_attr.attr.name = + priv->core.attr_name[core_no][i]; + priv->core.sd_attrs[core_no][i].dev_attr.attr.mode =0444 ; + priv->core.sd_attrs[core_no][i].dev_attr.show = core_show_fn[i]; +if (i ==0 || i ==1 )/* label or temp */ + priv->core.sd_attrs[core_no][i].index = core_no; + priv->core.attrs[core_no][i] = + &priv->core.sd_attrs[core_no][i].dev_attr.attr; + } + + priv->core.attr_group[core_no].attrs = priv->core.attrs[core_no]; + +return sysfs_create_group (&priv->hwmon_dev->kobj, + &priv->core.attr_group[core_no]); +} + +static ssize_t (*const dimm_show_fn[DIMM_TEMP_ATTRS ]) (struct device *dev, +struct device_attribute *devattr,char *buf) = { + show_dimm_label, + show_dimm_temp, +}; + +static const char *const dimm_suffix[DIMM_TEMP_ATTRS ] = { +"label" , +"input" , +}; + +static int create_dimm_temp_group (struct peci_hwmon *priv,int dimm_no) +{ +int i; + +for (i =0 ; i <DIMM_TEMP_ATTRS ; i++) { +snprintf (priv->dimm.attr_name[dimm_no][i], +ATTR_NAME_LEN ,"temp%d_%s" , +DIMM_INDEX_OFFSET + dimm_no, dimm_suffix[i]); +sysfs_attr_init (&priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr); + priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr.name = + priv->dimm.attr_name[dimm_no][i]; + priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr.mode =0444 ; + priv->dimm.sd_attrs[dimm_no][i].dev_attr.show = dimm_show_fn[i]; + priv->dimm.sd_attrs[dimm_no][i].index = dimm_no; + priv->dimm.attrs[dimm_no][i] = + &priv->dimm.sd_attrs[dimm_no][i].dev_attr.attr; + } + + priv->dimm.attr_group[dimm_no].attrs = priv->dimm.attrs[dimm_no]; + +return sysfs_create_group (&priv->hwmon_dev->kobj, + &priv->dimm.attr_group[dimm_no]); +} + +static int peci_hwmon_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct peci_hwmon *priv; +struct device *hwmon; +int rc, i; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv)
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 860
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+return -ENOMEM ; + +dev_set_drvdata (dev, priv); + priv->dev = dev; + + rc =of_property_read_u32 (np,"cpu-id" , &priv->cpu_id);What entity determines cpu-id ?
CPU ID numbering is determined by hardware SOCKET_ID strap pins. In this driver implementation, cpu-id is being used as CPU client indexing.
Quoted 12 lines
drivers/hwmon/peci-hwmon.c line 866
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+if (rc || priv->cpu_id >=CPU_ID_MAX ) { +dev_err (dev,"Invalid cpu-id configuration\n" ); +return rc; + } + + rc =of_property_read_u32 (np,"dimm-nums" , &priv->dimm_nums);This is an odd devicetree attribute. Normally the number of DIMMs is dynamic. Isn't there a means to get all that information dynamically instead of having to set it through devicetree ? What if someone adds or removes a DIMM ? Who updates the devicetree ?
It means the number of DIMM slots each CPU has, doesn't mean the number of currently installed DIMM components. If a DIMM is inserted a slot, CPU reports its actual temperature but on empty slot, CPU reports 0 instead of reporting an error so it is the reason why this driver enumerates all DIMM slots' attribute.
Quoted 10 lines
drivers/hwmon/peci-hwmon.c line 873
Quoted 7 lines
drivers/hwmon/peci-hwmon.c new file +7
-0+if (rc || priv->dimm_nums >DIMM_NUMS_MAX ) { +dev_warn (dev,"Invalid dimm-nums : %u. Use default : %u\n" , + priv->dimm_nums,OF_DIMM_NUMS_DEFAULT ); + priv->dimm_nums =OF_DIMM_NUMS_DEFAULT ; + } + + priv->show_core =of_property_read_bool (np,"show-core" );This does not look like an appropriate devicetree attribute.
Okay. I will remove this devicetree attribute and make this driver enable core temperature attributes always.
Quoted 6 lines
drivers/hwmon/peci-hwmon.c line 876
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ + priv->groups = peci_hwmon_attr_groups; +This assignment (and the ->groups variable) is quite pointless.
Will fix it.
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 881
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+snprintf (priv->name,NAME_MAX ,HWMON_NAME ".cpu%d" , priv->cpu_id); + + hwmon =devm_hwmon_device_register_with_groups (dev, + priv->name, + priv, priv->groups);Please rewrite the driver to use
devm_hwmon_device_register_with_info(), and avoid dynamic attributes.
I will rewrite it.
Quoted 47 lines
drivers/hwmon/peci-hwmon.c line 889
Quoted 8 lines
drivers/hwmon/peci-hwmon.c new file +8
-0+ + rc =PTR_ERR_OR_ZERO (hwmon); +if (rc !=0 ) { +dev_err (dev,"Failed to register peci hwmon\n" ); +return rc; + } + + priv->hwmon_dev = hwmon;Something is logically wrong if you need to store
hwmon_devin the private data structure. Specifically, creating attributes dynamically after hwmon registration is wrong.drivers/hwmon/peci-hwmon.c line 892
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ +for (i =0 ; i < priv->dimm_nums; i++) { + rc =create_dimm_temp_group (priv, i);No. See earlier comments. All attribute groups must be created during registration (or before, but I am not inclined to accept a new driver doing that).
Quoted 4 lines
drivers/hwmon/peci-hwmon.c new file +4
-0+if (rc !=0 ) { +dev_err (dev,"Failed to create dimm temp group\n" ); +for (--i; i >=0 ; i--) { + sysfs_remove_group(&priv->hwmon_dev->kobj,drivers/hwmon/peci-hwmon.c line 906
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+ &priv->dimm.attr_group[i]); + } +return rc; + } + } + +/* +* Try to create core temp group now. It will be created if CPU is +* curretnly online or it will be created after the first reading of +* cpuinfo from the online CPU otherwise. This is not how CPUs are supposed to be detected, and it does not handle CPUs taken offline. If the driver is instantiated as a CPU comes online, or as it goes offline, the driver should use the appropriate kernel interfaces to trigger that instantiation or removal. However, if so, it may be inappropriate to associate CPU temperatures with other system temperatures in the same instance of the driver; after all, those are all independent of each other.
Overall, I suspect that there should be a callback or some other mechanism in the peci core to trigger instantiation and removal of this driver, and I am not sure if any of the devicetree properties makes sense at all.
Quoted 6 lines
For example, if an instance of this driver is associated with a PECI agent (with assorted CPU/DIMM temperature reporting), the instantiation could be triggered as soon as the PECI core detects that the agent is available, and the PECI core could report what exactly that instance supports.
Thanks for sharing your detailed comment. In fact, PECI doesn't have any mechanism to get a callback for checking whether CPU is online or not. The only way PECI can do is, polling a CPU using the Ping PECI command. Also, a BMC controller can't make any PECI communication with offline CPU so this implementation uses delayed creation for some attributes which is messy as you said.
Like you suggested, a PECI agent could check CPU power state using some other mechanism and this driver module could be dynamically inserted/removed by the agent according to the CPU power state. This way could make all attributes creation possible at probing time so no need to use the delayed creation.
Also, I'll check feasibility of dynamic checking for maximum supportable numbers on each component type so that we can dynamically set the values as you suggested above.
Quoted 8 lines
drivers/hwmon/peci-hwmon.c line 911
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+*/ +if (priv->show_core) + (void )get_cpuinfo (priv); + +dev_info (dev,"peci hwmon for CPU#%d registered\n" , priv->cpu_id);Is this logging noise necessary ? Besides, some of it is redundant.
No, it isn't necessary. I will remove it.
Quoted 14 lines
Quoted 14 lines
drivers/hwmon/peci-hwmon.c new file +14
-0+ +return rc; +} + +static int peci_hwmon_remove (struct platform_device *pdev) +{ +struct peci_hwmon *priv =dev_get_drvdata (&pdev->dev); +int i; + +if (atomic_read (&priv->core_group_created)) +for (i =0 ; i < priv->core_nums; i++) { +sysfs_remove_group (&priv->hwmon_dev->kobj, + &priv->core.attr_group[i]); + }
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 898
Quoted 5 lines
drivers/hwmon/peci-hwmon.c new file +5
-0+ +for (i =0 ; i < priv->dimm_nums; i++) { +sysfs_remove_group (&priv->hwmon_dev->kobj, + &priv->dimm.attr_group[i]); + }If you need to call
sysfs_remove_groupfrom here,
something is conceptually wrong in your driver.
I'll remove it while rewriting the driver.
Quoted 9 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+ +return 0 ; +} + +static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
Quoted 17 lines
Quoted 17 lines
drivers/hwmon/peci-hwmon.c new file +17
-0+ { } +}; +MODULE_DEVICE_TABLE (of, peci_of_table); + +static struct platform_driver peci_hwmon_driver = { + .probe = peci_hwmon_probe, + .remove = peci_hwmon_remove, + .driver = { + .name =DEVICE_NAME , + .of_match_table = peci_of_table, + }, +}; + +module_platform_driver (peci_hwmon_driver); +MODULE_AUTHOR ("Jae Hyun Yoo <[email protected]>" ); +MODULE_DESCRIPTION ("PECI hwmon driver" ); +MODULE_LICENSE ("GPL v2" );
Quoted 51 lines · Benjamin Herrenschmidt
Quoted 2 lines · Greg KH
4.13? Why that kernel? It too is obsolete and insecure and unsupported.
Haha, it's n-1. come on :-)
Quoted 3 lines
What keeps you all from just always tracking the latest tree from Linus? What is in your tree that is not upstream that requires you to have a kernel tree at all?
There are a couple of ARM based SoC families for which we are in the process of rewriting all the driver in upstreamable form. This takes time.
To respond to your other email about the USB CDC, it's mine, I haven't resubmited it yet because it had a dependency on some the aspeed clk driver to function properly (so is unusable without it) and it took 2 kernel versions to get that clk stuff upstream for a number of reasons.
So it's all getting upstream and eventually there will be (we hope) no "OpenBMC" kernel, it's just a way for us to get functional code with non-upstream-quality (read: vendor) drivers until we are one rewriting & upstreaming them all.
Quoted 4 lines
And if you do have out-of-tree code, why not use a process that makes it trivial to update the base kernel version so that you can keep up to date very easily? (hint, just using 'git' is not a good way to do this...)
Joel and I both find git perfectly fine for that. I've not touched quilt in eons and frankly don't regret it ;-)
That said, Jae should definitely submit a driver against upstream, not against some random OpenBMC tree.
Jae, for example when I submitted the original USB stuff back then, I did it from a local upstream based branch (with just a few hacks to work around the lack of the clk stuff).
I will rebase it in the next few days to upstream merged with Stephen's clk tree to get the finally merged clk stuff, verify it works, and submit patches against upstream.
There should be no mention of dev-4.10 or 4.13 on lkml or other upstream submission lists. Development work should happen upstream *first* and eventually be backported to our older kernels while they exist (hopefully I prefer if we are more aggressive at forward porting the crappy drivers so we can keep our tree more up to date but that's a different discussion).
Quoted 3 lines
Cheers,
Ben.
Thanks for your reminding me the upstream process. I'll do like you said afterwards.
Thanks,
Jae
Quoted 4 lines
Quoted 3 lines
thanks,
greg k-h
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Benjamin HerrenschmidtQuoted 27 lines · Benjamin Herrenschmidt
Quoted 11 lines · Greg KH
Quoted 4 lines · Jae Hyun Yoo
This commit adds driver implementation for Aspeed PECI. Also adds generic
peci.handpeci_ioctl.hfiles to provide compatibility to peci drivers that can be implemented later e.g. Nuvoton's BMC SoC family.We don't add code that could be used "sometime in the future". Only include stuff that we use now.
Please fix up this series based on that and resubmit. There should not be any need for any uapi file then, right?
No Greg, I think you misunderstood (unless I misread myself).
What Jae means is that since PECI is a standard and other drivers implementing the same ioctl interface and messages will eventually go upstream, instead of having the ioctl definitions in a driver specific locations, they go in a generic spot, as they define a generic API for all PECI drivers, including the one that's getting merged now.
IE. This doesn't add unused stuff, it just puts the API parts of it into a generic location.
At least that's my understanding from a, granted cursory, look at the patch.
Quoted 7 lines
That said, I do have a problem with the structure definitions of the various packet types as they use "long" which has a variable size and unclear alignment. It should be using
__u8,__u16and__u32...Cheers,
Ben.
Thanks for your clear explanation. That is what I actually intended to. However, the structure definitions you and Greg pointed out need to be corrected. I will fix it.
Thanks,
Jae
Re: [PATCH linux dev-4.10 3/6] drivers/misc: Add driver for Aspeed PECI and generic PECI headers
In reply to Benjamin HerrenschmidtQuoted 14 lines · Benjamin Herrenschmidt
include/uapi/linux/peci_ioctl.h line 197
Quoted 6 lines · Jae Hyun Yoo
include/uapi/linux/peci_ioctl.h new file +6
-0+struct peci_rd_ia_msr_msg { +unsigned char target; +unsigned char thread_id; +unsigned short address; +unsigned long value; +};Those types are representing messages on the wire ?
In that case those types aren't suitable. For example "long" will have a different size and alignment for 32 and 64-bit userspace. There are size-explicit userspace types available.
Quoted 6 lines
Also I didn't see any endianness annotations in there. Is that expected ? IE are those wire format packets ?
Cheers,
Ben.
Only the 'peci_xfer_msg' struct is representing messages on the wire. All userspace messages which is using other struct definitions will be copied into the 'peci_xfer_msg' for each member variable in driver, but anyway, type definitions of each member variable should be fixed as you said. Will fix it.
Thanks,
Jae
Re: [PATCH linux dev-4.10 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Arnd BergmannQuoted 55 lines · Arnd Bergmann
Quoted 38 lines · Jae Hyun Yoo
Quoted 25 lines · Arnd Bergmann
Quoted 6 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>drivers/hwmon/peci-hwmon.c line 123
Quoted 10 lines
drivers/hwmon/peci-hwmon.c new file +10
-0+static int xfer_peci_msg (int cmd,void *pmsg) +{ +int rc; + +mutex_lock (&peci_hwmon_lock); + rc =peci_ioctl (NULL , cmd, (unsigned long )pmsg); +mutex_unlock (&peci_hwmon_lock); + +return rc; +}I said earlier that
peci_ioctl()looked unused, that was obviously wrong, but what you have here
is not a proper way to abstract a bus.Quoted 11 lines
Maybe this can be done more like an i2c bus: make the peci controller a bus device
and register all known target/index pairs as devices with the peci bus type, and have
them probed from DT. The driver can then bind to each of those individually.
Not sure if that is getting to granular at that point, I'd have to understand better
how it is expected to get used, and what the variances are between implementations.Quoted 6 lines
Thanks for sharing your opinion. In fact, this was also suggested by openbmc community so I should consider of redesigning it. I'm currently thinking about adding a new PECI device class as an abstract layer and any BMC chipset specific driver could be attached to the PECI class driver. Then, each CPU client could be registered as an individual device as you suggested. Will consider your suggestion.
Another idea might be to pretend that PECI was I2C. We already have a few drivers for hardware that is not I2C but whose software interface looks similar enough that it just works. No idea if that is the case for PECI, but
xfer_peci_msgmight be close enough toi2c_xferto make it work. If you are able to do that, then the PECI controller would just register itself as an i2c controller and it can be accessed using/dev/i2cfrom user space or a high-leveli2c_driver.
Quoted 2 lines
Arnd
Thanks for the good idea. It looks like one of possible options. I'll check this idea as well. :)
Thanks,
Jae
Quoted 3 lines · Greg KH
And, if you use it in a device, it's still totally unsupported and insecure. Seriously, does no one actually pay attention to the patches I merge in the stable trees anymore?
Yeah not sure why we aren't picking an LTC here, it could be that it's just a dev branch, not release, Joel, what's the process in that case ?
For anything going into products, if we're going to maintain a non- upstream branch, we should definitely stick it to an LTS release or we'll be missing a ton of security fixes.
Cheers,
Ben.
Guenter Roeck
maintainerRe: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Jae Hyun YooQuoted 5 lines · Jae Hyun Yoo
Quoted 4 lines · Guenter Roeck
Quoted 3 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>
[ ... ]
Quoted 12 lines
Quoted 11 lines
drivers/hwmon/peci-hwmon.c line 250
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+ +if (priv->temp.tcontrol.valid && +time_before (jiffies, priv->temp.tcontrol.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; +Is the delay necessary ? Otherwise I would suggest to drop it. It adds a lot of complexity to the driver. Also, if the user polls values more often, that is presumably on purpose.
Quoted 4 lines
I was intended to reduce traffic on PECI bus because it's low speed single wired bus, and temperature values don't change frequently because the value is sampled and averaged in CPU itself. I'll keep this.
Then please try to move the common code into a single function.
[ ... ]
Quoted 9 lines
Quoted 5 lines
drivers/hwmon/peci-hwmon.c line 860
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+ + rc =of_property_read_u32 (np,"cpu-id" , &priv->cpu_id);What entity determines cpu-id ?
CPU ID numbering is determined by hardware
SOCKET_IDstrap pins. In this driver implementation, cpu-id is being used as CPU client indexing.
Seems to me the necessary information to identify a given CPU should be provided by the PECI core. Also, there are already "cpu" nodes in devicetree which, if I recall correctly, may include information such as CPU Ids.
Quoted 13 lines
Quoted 12 lines
drivers/hwmon/peci-hwmon.c line 866
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+if (rc || priv->cpu_id >=CPU_ID_MAX ) { +dev_err (dev,"Invalid cpu-id configuration\n" ); +return rc; + } + + rc =of_property_read_u32 (np,"dimm-nums" , &priv->dimm_nums);This is an odd devicetree attribute. Normally the number of DIMMs is dynamic. Isn't there a means to get all that information dynamically instead of having to set it through devicetree ? What if someone adds or removes a DIMM ? Who updates the devicetree ?
Quoted 6 lines
It means the number of DIMM slots each CPU has, doesn't mean the number of currently installed DIMM components. If a DIMM is inserted a slot, CPU reports its actual temperature but on empty slot, CPU reports 0 instead of reporting an error so it is the reason why this driver enumerates all DIMM slots' attribute.
And there is no other means to get the number of DIMM slots per CPU ? It just seems to be that this is the wrong location to provide such information.
[ ... ]
Quoted 11 lines
Quoted 6 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ +static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
I don't really know enough about the system to make a recommendation. It seems to me that the PECI core should identify which functionality it supports and instantiate the necessary driver(s). Maybe there should be sub-nodes to the peci node with relevant information. Those sub-nodes should specify the supported functionality in more detail, though - such as indicating the supported CPU and/or DIMM sensors.
Guenter
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
PECI seems to be an Intel thing. So at least it should be
{ .compatible = "intel,peci-hwmon", }
assuming it is actually compatible with the Intel specification.
Andrew
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Guenter RoeckQuoted 21 lines · Guenter Roeck
Quoted 5 lines · Jae Hyun Yoo
Quoted 4 lines · Guenter Roeck
Quoted 3 lines · Jae Hyun Yoo
This commit adds driver implementation for a generic PECI hwmon.
Signed-off-by Jae Hyun Yoo <[email protected]>[ ... ]
Quoted 12 lines
Quoted 11 lines
drivers/hwmon/peci-hwmon.c line 250
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+ +if (priv->temp.tcontrol.valid && +time_before (jiffies, priv->temp.tcontrol.last_updated + +UPDATE_INTERVAL_MIN )) +return 0 ; +Is the delay necessary ? Otherwise I would suggest to drop it. It adds a lot of complexity to the driver. Also, if the user polls values more often, that is presumably on purpose.
Quoted 6 lines
Quoted 4 lines
I was intended to reduce traffic on PECI bus because it's low speed single wired bus, and temperature values don't change frequently because the value is sampled and averaged in CPU itself. I'll keep this.
Then please try to move the common code into a single function.
That makes sense. I'll move the common code into a single function.
Quoted 8 lines
[ ... ]
Quoted 6 lines
Quoted 5 lines
drivers/hwmon/peci-hwmon.c line 860
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+ + rc =of_property_read_u32 (np,"cpu-id" , &priv->cpu_id);What entity determines cpu-id ?
Quoted 8 lines
Quoted 3 lines
CPU ID numbering is determined by hardware
SOCKET_IDstrap pins. In this driver implementation, cpu-id is being used as CPU client indexing.Seems to me the necessary information to identify a given CPU should be provided by the PECI core. Also, there are already "cpu" nodes in devicetree which, if I recall correctly, may include information such as CPU Ids.
This driver is implemented to support only BMC (Baseboard Management Controllers) chipset which is running on a separated linux kernel from a host server system. Through a PECI connection between them, this driver collects the host server system's CPU and DIMM temperature information which is running on a separated OS. That could be a linux, a Windows OS or any other OSes. I mean, there is no shared devicetree data between them so it is why the 'cpu_id' was added into dt configuration of this driver.
Using quite limited hardware connections such as PECI, KSC, eSPI and SMBus, the BMC manages the host server and this hwmon is one of features of BMC.
Quoted 19 lines
Quoted 13 lines
Quoted 12 lines
drivers/hwmon/peci-hwmon.c line 866
Quoted 6 lines
drivers/hwmon/peci-hwmon.c new file +6
-0+if (rc || priv->cpu_id >=CPU_ID_MAX ) { +dev_err (dev,"Invalid cpu-id configuration\n" ); +return rc; + } + + rc =of_property_read_u32 (np,"dimm-nums" , &priv->dimm_nums);This is an odd devicetree attribute. Normally the number of DIMMs is dynamic. Isn't there a means to get all that information dynamically instead of having to set it through devicetree ? What if someone adds or removes a DIMM ? Who updates the devicetree ?
Quoted 6 lines
It means the number of DIMM slots each CPU has, doesn't mean the number of currently installed DIMM components. If a DIMM is inserted a slot, CPU reports its actual temperature but on empty slot, CPU reports 0 instead of reporting an error so it is the reason why this driver enumerates all DIMM slots' attribute.
Quoted 4 lines
And there is no other means to get the number of DIMM slots per CPU ? It just seems to be that this is the wrong location to provide such information.
This devicetree attribute will be configured at runtime using dt overlay based on the host server's hardware configuration which will be parsed and managed by a userspace BMC service.
Quoted 14 lines
[ ... ]
Quoted 11 lines
Quoted 6 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 3 lines
drivers/hwmon/peci-hwmon.c new file +3
-0+ +static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
Quoted 9 lines
I don't really know enough about the system to make a recommendation. It seems to me that the PECI core should identify which functionality it supports and instantiate the necessary driver(s). Maybe there should be sub-nodes to the peci node with relevant information. Those sub-nodes should specify the supported functionality in more detail, though - such as indicating the supported CPU and/or DIMM sensors.
Guenter
As I explained above, BMC and host server are running on separated OSes so this driver cannot be (actually, doesn't need to be) directly associated with other kernel modules in the BMC side OS for identifying the host server system's functionality. My thought is, this driver will use PECI only for identifying the host server's CPU and DIMM information and the userspace BMC service could deliver any additional host server information thru dt overlay if needed before the BMC service initiates this driver at runtime.
Thanks a lot,
Jae
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
In reply to Andrew LunnQuoted 10 lines · Andrew Lunn
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
Quoted 8 lines
PECI seems to be an Intel thing. So at least it should be
{ .compatible = "intel,peci-hwmon", }
assuming it is actually compatible with the Intel specification.
Andrew
Yes, PECI is an Intel thing but this driver is running on an ARM kernel on Aspeed or Nuvoton chipsets for now. This driver will be monitoring a host server's Intel CPU and DIMM which is running on a separated OS.
Thanks,
Jae
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Andrew Lunn
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
drivers/hwmon/peci-hwmon.c line 936
Quoted 2 lines
drivers/hwmon/peci-hwmon.c new file +2
-0+static const struct of_device_id peci_of_table[] = { + { .compatible ="peci-hwmon" , },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
PECI seems to be an Intel thing. So at least it should be
{ .compatible = "intel,peci-hwmon", }
Quoted 8 lines
Quoted 4 lines
assuming it is actually compatible with the Intel specification.
Andrew
Yes, PECI is an Intel thing but this driver is running on an ARM kernel on Aspeed or Nuvoton chipsets for now. This driver will be monitoring a host server's Intel CPU and DIMM which is running on a separated OS.
Hi Jae
You need to be careful with the name then. You should not claim the name 'peci' in case somebody actually implements a PECI driver which is compatible with Intel PECI.
However, looking at other comments, it seems like this part is going away, if you turn your code into a bus driver.
Andrew
Re: [linux, dev-4.10, 6/6] drivers/hwmon: Add a driver for a generic PECI hwmon
Quoted 27 lines · Andrew Lunn
Quoted 15 lines · Jae Hyun Yoo
Quoted 14 lines · Andrew Lunn
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static const struct of_device_id peci_of_table[] = { + { .compatible = "peci-hwmon", },This does not look like a reference to some piece of hardware.
This driver provides generic PECI hwmon function to which controller has PECI HW such as Aspeed or Nuvoton BMC chip so it's not dependant on a specific hardware. Should I remove this or any suggestion?
PECI seems to be an Intel thing. So at least it should be
{ .compatible = "intel,peci-hwmon", }
Quoted 8 lines
Quoted 4 lines
assuming it is actually compatible with the Intel specification.
Andrew
Yes, PECI is an Intel thing but this driver is running on an ARM kernel on Aspeed or Nuvoton chipsets for now. This driver will be monitoring a host server's Intel CPU and DIMM which is running on a separated OS.
Hi Jae
Quoted 9 lines
You need to be careful with the name then. You should not claim the name 'peci' in case somebody actually implements a PECI driver which is compatible with Intel PECI.
However, looking at other comments, it seems like this part is going away, if you turn your code into a bus driver.
Andrew
Hi Andrew,
I see. I'll keep that in mind and will keep finding if there is any better way. Thanks for sharing your thought.
Jae