PECI device driver introduction
Subsystems (6)
v10 cover PECI device driver introduction
Introduction of the Platform Environment Control Interface (PECI) bus device driver. PECI is a one-wire bus interface that provides a communication channel from Intel processors and chipset components to external monitoring or control devices. PECI is designed to support the following sideband functions:
* Processor and DRAM thermal management
- Processor fan speed control is managed by comparing Digital Thermal Sensor (DTS) thermal readings acquired via PECI against the processor-specific fan speed control reference point, or TCONTROL. Both TCONTROL and DTS thermal readings are accessible via the processor PECI client. These variables are referenced to a common temperature, the TCC activation point, and are both defined as negative offsets from that reference.
- PECI based access to the processor package configuration space provides a means for Baseboard Management Controllers (BMC) or other platform management devices to actively manage the processor and memory power and thermal features.
* Platform Manageability
- Platform manageability functions including thermal, power, and error monitoring. Note that platform 'power' management includes monitoring and control for both the processor and DRAM subsystem to assist with data center power limiting.
- PECI allows read access to certain error registers in the processor MSR space and status monitoring registers in the PCI configuration space within the processor and downstream devices.
- PECI permits writes to certain registers in the processor PCI configuration space.
* Processor Interface Tuning and Diagnostics
- Processor interface tuning and diagnostics capabilities (Intel Interconnect BIST). The processors Intel Interconnect Built In Self Test (Intel IBIST) allows for infield diagnostic capabilities in the Intel UPI and memory controller interfaces. PECI provides a port to execute these diagnostics via its PCI Configuration read and write capabilities.
* Failure Analysis
- Output the state of the processor after a failure for analysis via Crashdump.
PECI uses a single wire for self-clocking and data transfer. The bus requires no additional control lines. The physical layer is a self-clocked one-wire bus that begins each bit with a driven, rising edge from an idle level near zero volts. The duration of the signal driven high depends on whether the bit value is a logic '0' or logic '1'. PECI also includes variable data transfer rate established with every message. In this way, it is highly flexible even though underlying logic is simple.
The interface design was optimized for interfacing between an Intel processor and chipset components in both single processor and multiple processor environments. The single wire interface provides low board routing overhead for the multiple load connections in the congested routing area near the processor and chipset components. Bus speed, error checking, and low protocol overhead provides adequate link bandwidth and reliability to transfer critical device operating conditions and configuration information.
This implementation provides the basic framework to add PECI extensions to the Linux bus and device models. A hardware specific 'Adapter' driver can be attached to the PECI bus to provide sideband functions described above. It is also possible to access all devices on an adapter from userspace through the /dev interface. A device specific 'Client' driver also can be attached to the PECI bus so each processor client's features can be supported by the 'Client' driver through an adapter connection in the bus. This patch set includes Aspeed 24xx/25xx PECI driver and PECI cputemp/dimmtemp drivers as the first implementation for both adapter and client drivers on the PECI bus framework.
Please review.
Thanks,
Jae
Changes since v9:
- Updated license identifiers to incidate 2019.
- Removed unnecessary member variable and enum type from intel client driver.
- Removed 'type' argument from the access_ok() function call.
Changes since v8:
- Refined descriptions in PECI device tree documents.
- Fixed checking logic of supportable PECI commands using full revision number.
- Fixed DIB data size to u64 to make that can contain 8-bytes of information.
- Changed PECI cdev names from pecix to peci-x where x is bus number.
- Refined intel-peci-client driver and moved hwmon relating codes to peci-hwmon.h.
- Added missing core label strings into peci-cputemp driver.
- Added kerneldoc comments.
Changes since v7:
- Fixed a typo in the MFD_INTEL_PECI_CLIENT description.
- Made peci_unregister_device() NULL-aware.
- Converted to using %pOF instead of node full name in peci-core.
- Removed OF tables from peci-cputemp and peci-dimmtemp.
- Removed of_compatible strings from intel-peci-client.
- Added an access_ok() check into peci_ioctl in peci-core.
- Changed the DT node name of peci simple-bus from 'peci' to 'bus'.
Changes since v6:
- Dropped off unnecessary examples from dt-bindings document.
- Fixed a bug in DIMM index mask building logic.
- Modified DIMM temp label strings to match with the way in BIOS.
- Changed PECI ioctl base number from B6 to B7 to avoid conflict with fpga-dfl.
- Separated the PECI section in MAINTAINERS into two parts - PECI subsystem and ASPEED PECI driver.
Changes since v5:
- Added more detailed descriptions for PECI client MFD documents.
- Changed PECI client MFD souce file names.
- Fixed DT example of PECI client MFD.
- Removed unnecessary debug printings.
- Moved the asm/intel-family.h inclusion place.
Changes since v4:
- Fixed an incorrect endianness handling in peci-aspeed.
- Added a comment to explain about the asm/intel-family.h inclusion.
- Added an MFD module to support multi-function PECI client devices.
Changes since v3:
- Made code more simple and compact.
- Removed unused header file inclusion.
- Fixed incorrect error return values and messages.
- Removed DTS margin temperature from the peci-cputemp.
- Made some magic numbers use defines.
- Moved peci_get_cpu_id() into peci-core as a common function.
- Replaced the cancel_delayed_work() call with a cancel_delayed_work_sync().
- Replaced AST and Aspeed uses with ASPEED.
- Simplified peci command timeout checking logic using regmap_read_poll_timeout().
- Simplified endian swap codes using endian handling macros.
- Dropped regmap read/write error checking except for the first access.
- Added a PECI reset setting in the device tree node.
- Removed unnecessary sleep from the probe context.
- Removed IRQF_SHARED flag from irq request code in the ASPEED PECI driver.
- Fixed typos in documents.
- Combined peci-bus.txt, peci-adapter.txt and peci-client.txt into peci.txt.
- Fixed and swept documents to drop some incorrect or unnecessary descriptions.
- Fixed device tree to make unit-address format use reg contents.
- Simplified bit manipulations using <linux/bitfield.h>.
- Made client CPU model checking use <asm/intel-family.h> if available.
- Modified adapter heap allocation method to use kobject reference count based.
- Added the low-level PECI xfer IOCTL again to support the Redfish requirement.
- Added PM domain attach/detach code.
- Added logic for device instantiation through sysfs.
- Fix a bug of interrupt status checking code in peci-aspeed driver.
Changes since v2:
- Divided peci-hwmon driver into two drivers, peci-cputemp and peci-dimmtemp.
- Added generic dt binding documents for PECI bus, adapter and client.
- Removed in_atomic() call from the PECI core driver.
- Improved PECI commands masking logic.
- Added permission check logic for PECI ioctls.
- Removed unnecessary type casts.
- Fixed some invalid error return codes.
- Added the mark_updated() function to improve update interval checking logic.
- Fixed a bug in populated DIMM checking function.
- Fixed some typo, grammar and style issues in documents.
- Rewrote hwmon drivers to use devm_hwmon_device_register_with_info API.
- Made peci_match_id() function as a static.
- Replaced a deprecated create_singlethread_workqueue() call with an alloc_ordered_workqueue() call.
- Reordered local variable definitions in reversed xmas tree notation.
- Listed up client CPUs that can be supported by peci-cputemp and peci-dimmtemp hwmon drivers.
- Added CPU generation detection logic which checks CPUID signature through PECI connection.
- Improved interrupt handling logic in the Aspeed PECI adapter driver.
- Fixed SPDX license identifier style in header files.
- Changed some macros in peci.h to static inline functions.
- Dropped sleepable context checking code in peci-core.
- Adjusted rt_mutex protection scope in peci-core.
- Moved adapter->xfer() checking code into peci_register_adapter().
- Improved PECI command retry checking logic.
- Changed ioctl base from 'P' to 0xb6 to avoid confiliction and updated ioctl-number.txt to reflect the ioctl number of PECI subsystem.
- Added a comment to describe PECI retry action.
- Simplified return code handling of peci_ioctl_ping().
- Changed type of peci_ioctl_fn[] to static const.
- Fixed range checking code for valid PECI commands.
- Fixed the error return code on invalid PECI commands.
- Fixed incorrect definitions of PECI ioctl and its handling logic.
Changes since v1:
- Additionally implemented a core driver to support PECI linux bus driver model.
- Modified Aspeed PECI driver to make that to be an adapter driver in PECI bus.
- Modified PECI hwmon driver to make that to be a client driver in PECI bus.
- Simplified hwmon driver attribute labels and removed redundant strings.
- Removed core_nums from device tree setting of hwmon driver and modified core number detection logic to check the resolved_core register in client CPU's local PCI configuration area.
- Removed dimm_nums from device tree setting of hwmon driver and added populated DIMM detection logic to support dynamic creation.
- Removed indexing gap on core temperature and DIMM temperature attributes.
- Improved hwmon registration and dynamic attribute creation logic.
- Fixed structure definitions in PECI uapi header to make that use __u8, __u16 and etc.
- Modified wait_for_completion_interruptible_timeout error handling logic in Aspeed PECI driver to deliver errors correctly.
- Removed low-level xfer command from ioctl and kept only high-level PECI command suite as ioctls.
- Fixed I/O timeout logic in Aspeed PECI driver using ktime.
- Added a function into hwmon driver to simplify update delay checking.
- Added a function into hwmon driver to convert 10.6 to millidegree.
- Dropped non-standard attributes in hwmon driver.
- Fixed OF table for hwmon to make it indicate as a PECI client of Intel CPU target.
- Added a maintainer of PECI subsystem into MAINTAINERS document.
Jae Hyun Yoo (12):
dt-bindings: Add a document of PECI subsystem
Documentation: ioctl: Add ioctl numbers for PECI subsystem
peci: Add support for PECI bus driver core
dt-bindings: Add a document of PECI adapter driver for ASPEED
AST24xx/25xx SoCs
ARM: dts: aspeed: peci: Add PECI node
peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
dt-bindings: mfd: Add a document for PECI client driver
mfd: intel-peci-client: Add PECI client driver
Documentation: hwmon: Add documents for PECI hwmon client drivers
hwmon: Add PECI cputemp driver
hwmon: Add PECI dimmtemp driver
Add maintainers for the PECI subsystem
.../bindings/mfd/intel-peci-client.txt | 34 + .../devicetree/bindings/peci/peci-aspeed.txt | 55 + .../devicetree/bindings/peci/peci.txt | 43 + Documentation/hwmon/peci-cputemp | 78 + Documentation/hwmon/peci-dimmtemp | 50 + Documentation/ioctl/ioctl-number.txt | 2 + MAINTAINERS | 22 + arch/arm/boot/dts/aspeed-g4.dtsi | 26 + arch/arm/boot/dts/aspeed-g5.dtsi | 26 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/hwmon/Kconfig | 28 + drivers/hwmon/Makefile | 2 + drivers/hwmon/peci-cputemp.c | 394 +++++ drivers/hwmon/peci-dimmtemp.c | 284 +++ drivers/hwmon/peci-hwmon.h | 49 + drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 1 + drivers/mfd/intel-peci-client.c | 143 ++ drivers/peci/Kconfig | 39 + drivers/peci/Makefile | 9 + drivers/peci/peci-aspeed.c | 505 ++++++ drivers/peci/peci-core.c | 1527 +++++++++++++++++ include/linux/mfd/intel-peci-client.h | 108 ++ include/linux/peci.h | 142 ++ include/uapi/linux/peci-ioctl.h | 403 +++++ 26 files changed, 3987 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/intel-peci-client.txt create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.txt create mode 100644 Documentation/devicetree/bindings/peci/peci.txt create mode 100644 Documentation/hwmon/peci-cputemp create mode 100644 Documentation/hwmon/peci-dimmtemp create mode 100644 drivers/hwmon/peci-cputemp.c create mode 100644 drivers/hwmon/peci-dimmtemp.c create mode 100644 drivers/hwmon/peci-hwmon.h create mode 100644 drivers/mfd/intel-peci-client.c create mode 100644 drivers/peci/Kconfig create mode 100644 drivers/peci/Makefile create mode 100644 drivers/peci/peci-aspeed.c create mode 100644 drivers/peci/peci-core.c create mode 100644 include/linux/mfd/intel-peci-client.h create mode 100644 include/linux/peci.h create mode 100644 include/uapi/linux/peci-ioctl.h
Signature · 1 line
2.20.1
PATCH v10 1/12 dt-bindings: Add a document of PECI subsystem
This commit adds a document of generic PECI bus, adapter and client driver.
--- .../devicetree/bindings/peci/peci.txt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/peci/peci.txt
Documentation/devicetree/bindings/peci/peci.txt new file +43 -0
@@ -0,0 +1,43 @@ +Generic device tree configuration for PECI adapters +=================================================== + +Required properties: +- #address-cells : Should be <1>. Read more about client addresses below. +- #size-cells : Should be <0>. Read more about client addresses below. + +The cells properties above define that an address of CPU clients of a PECI bus +are described by a single value. + +Example: + peci0: peci-bus@0 { + compatible = "vendor,soc-peci"; + reg = <0x0 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + }; + +Generic device tree configuration for PECI clients +================================================== + +Required properties: +- compatible : Should contain name of PECI client. +- reg : Should contain address of a client CPU. According to the PECI + specification, client addresses start from 0x30. + +Example: + peci-bus@0 { + compatible = "vendor,soc-peci"; + reg = <0x0 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + + peci-client@30 { + compatible = "intel,peci-client"; + reg = <0x30>; + }; + + peci-client@31 { + compatible = "intel,peci-client"; + reg = <0x31>; + }; + };
Signature · 1 line
2.20.1
PATCH v10 2/12 Documentation: ioctl: Add ioctl numbers for PECI subsystem
In reply to Jae Hyun YooThis commit updates ioctl-number.txt to reflect ioctl numbers used by the PECI subsystem.
--- Documentation/ioctl/ioctl-number.txt | 2 ++ 1 file changed, 2 insertions(+)
Documentation/ioctl/ioctl-number.txt +2 -0
@@ -327,6 +327,8 @@ Code Seq#(hex) Include File Comments 0xB4 00-0F linux/gpio.h <mailto:[email protected]> 0xB5 00-0F uapi/linux/rpmsg.h <mailto:[email protected]> 0xB6 all linux/fpga-dfl.h +0xB7 00-0F uapi/linux/peci-ioctl.h PECI subsystem + <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.h
Signature · 1 line
2.20.1
PATCH v10 3/12 peci: Add support for PECI bus driver core
In reply to Jae Hyun YooThis commit adds driver implementation for PECI bus core into linux driver framework.
PECI (Platform Environment Control Interface) is a one-wire bus interface that provides a communication channel from Intel processors and chipset components to external monitoring or control devices. PECI is designed to support the following sideband functions:
* Processor and DRAM thermal management
- Processor fan speed control is managed by comparing Digital Thermal Sensor (DTS) thermal readings acquired via PECI against the processor-specific fan speed control reference point, or TCONTROL. Both TCONTROL and DTS thermal readings are accessible via the processor PECI client. These variables are referenced to a common temperature, the TCC activation point, and are both defined as negative offsets from that reference.
- PECI based access to the processor package configuration space provides a means for Baseboard Management Controllers (BMC) or other platform management devices to actively manage the processor and memory power and thermal features.
* Platform Manageability
- Platform manageability functions including thermal, power, and error monitoring. Note that platform 'power' management includes monitoring and control for both the processor and DRAM subsystem to assist with data center power limiting.
- PECI allows read access to certain error registers in the processor MSR space and status monitoring registers in the PCI configuration space within the processor and downstream devices.
- PECI permits writes to certain registers in the processor PCI configuration space.
* Processor Interface Tuning and Diagnostics
- Processor interface tuning and diagnostics capabilities (Intel Interconnect BIST). The processors Intel Interconnect Built In Self Test (Intel IBIST) allows for infield diagnostic capabilities in the Intel UPI and memory controller interfaces. PECI provides a port to execute these diagnostics via its PCI Configuration read and write capabilities.
* Failure Analysis
- Output the state of the processor after a failure for analysis via Crashdump.
PECI uses a single wire for self-clocking and data transfer. The bus requires no additional control lines. The physical layer is a self-clocked one-wire bus that begins each bit with a driven, rising edge from an idle level near zero volts. The duration of the signal driven high depends on whether the bit value is a logic '0' or logic '1'. PECI also includes variable data transfer rate established with every message. In this way, it is highly flexible even though underlying logic is simple.
The interface design was optimized for interfacing between an Intel processor and chipset components in both single processor and multiple processor environments. The single wire interface provides low board routing overhead for the multiple load connections in the congested routing area near the processor and chipset components. Bus speed, error checking, and low protocol overhead provides adequate link bandwidth and reliability to transfer critical device operating conditions and configuration information.
This implementation provides the basic framework to add PECI extensions to the Linux bus and device models. A hardware specific 'Adapter' driver can be attached to the PECI bus to provide sideband functions described above. It is also possible to access all devices on an adapter from userspace through the /dev interface. A device specific 'Client' driver also can be attached to the PECI bus so each processor client's features can be supported by the 'Client' driver through an adapter connection in the bus.
--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/peci/Kconfig | 12 + drivers/peci/Makefile | 6 + drivers/peci/peci-core.c | 1527 +++++++++++++++++++++++++++++++ include/linux/peci.h | 142 +++ include/uapi/linux/peci-ioctl.h | 403 ++++++++ 7 files changed, 2093 insertions(+) create mode 100644 drivers/peci/Kconfig create mode 100644 drivers/peci/Makefile create mode 100644 drivers/peci/peci-core.c create mode 100644 include/linux/peci.h create mode 100644 include/uapi/linux/peci-ioctl.h
drivers/Kconfig +2 -0
@@ -228,4 +228,6 @@ source "drivers/siox/Kconfig" source "drivers/slimbus/Kconfig" +source "drivers/peci/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -186,3 +186,4 @@ obj-$(CONFIG_MULTIPLEXER) += mux/ obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/ obj-$(CONFIG_SIOX) += siox/ obj-$(CONFIG_GNSS) += gnss/ +obj-$(CONFIG_PECI) += peci/
drivers/peci/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# +# Platform Environment Control Interface (PECI) subsystem configuration +# + +config PECI + bool "PECI support" + select RT_MUTEXES + select CRC8 + help + The Platform Environment Control Interface (PECI) is a one-wire bus + interface that provides a communication channel from Intel processors + and chipset components to external monitoring or control devices.
drivers/peci/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for the PECI core and bus drivers. +# + +# Core functionality +obj-$(CONFIG_PECI) += peci-core.o
drivers/peci/peci-core.c new file +1527 -0
1,527 lines not on this page · raw message
include/linux/peci.h new file +142 -0
142 lines not on this page · raw message
include/uapi/linux/peci-ioctl.h new file +403 -0
403 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 4/12 dt-bindings: Add a document of PECI adapter driver for ASPEED AST24xx/25xx SoCs
In reply to Jae Hyun YooThis commit adds a dt-bindings document of PECI adapter driver for ASPEED AST24xx/25xx SoCs.
--- .../devicetree/bindings/peci/peci-aspeed.txt | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.txt
Documentation/devicetree/bindings/peci/peci-aspeed.txt new file +55 -0
@@ -0,0 +1,55 @@ +Device tree configuration for PECI buses on the AST24XX and AST25XX SoCs. + +Required properties: +- compatible : Should be one of: + "aspeed,ast2400-peci" + "aspeed,ast2500-peci" +- reg : Should contain PECI controller registers location and + length. +- #address-cells : Should be <1> required to define a client address. +- #size-cells : Should be <0> required to define a client address. +- interrupts : Should contain PECI controller interrupt. +- clocks : Should contain clock source for PECI controller. Should + reference the external oscillator clock in the second + cell. +- resets : Should contain phandle to reset controller with the reset + number in the second cell. +- clock-frequency : Should contain the operation frequency of PECI controller + in units of Hz. + 187500 ~ 24000000 + +Optional properties: +- msg-timing : 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 : 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 the time frame in which the 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: + peci0: peci-bus@0 { + compatible = "aspeed,ast2500-peci"; + reg = <0x0 0x60>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <15>; + clocks = <&syscon ASPEED_CLK_GATE_REFCLK>; + resets = <&syscon ASPEED_RESET_PECI>; + clock-frequency = <24000000>; + msg-timing = <1>; + addr-timing = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + };
Signature · 1 line
2.20.1
PATCH v10 5/12 ARM: dts: aspeed: peci: Add PECI node
In reply to Jae Hyun YooThis commit adds PECI bus/adapter node of AST24xx/AST25xx into aspeed-g4 and aspeed-g5.
--- arch/arm/boot/dts/aspeed-g4.dtsi | 26 ++++++++++++++++++++++++++ arch/arm/boot/dts/aspeed-g5.dtsi | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
arch/arm/boot/dts/aspeed-g4.dtsi +26 -0
@@ -29,6 +29,7 @@ serial3 = &uart4; serial4 = &uart5; serial5 = &vuart; + peci0 = &peci0; }; cpus {
@@ -317,6 +318,13 @@ }; }; + peci: bus@1e78b000 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x1e78b000 0x60>; + }; + uart2: serial@1e78d000 { compatible = "ns16550a"; reg = <0x1e78d000 0x20>;
@@ -360,6 +368,24 @@ }; }; +&peci { + peci0: peci-bus@0 { + compatible = "aspeed,ast2400-peci"; + reg = <0x0 0x60>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <15>; + clocks = <&syscon ASPEED_CLK_GATE_REFCLK>; + resets = <&syscon ASPEED_RESET_PECI>; + clock-frequency = <24000000>; + msg-timing = <1>; + addr-timing = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + status = "disabled"; + }; +}; + &i2c { i2c_ic: interrupt-controller@0 { #interrupt-cells = <1>;
arch/arm/boot/dts/aspeed-g5.dtsi +26 -0
@@ -29,6 +29,7 @@ serial3 = &uart4; serial4 = &uart5; serial5 = &vuart; + peci0 = &peci0; }; cpus {
@@ -377,6 +378,13 @@ }; }; + peci: bus@1e78b000 { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x1e78b000 0x60>; + }; + uart2: serial@1e78d000 { compatible = "ns16550a"; reg = <0x1e78d000 0x20>;
@@ -420,6 +428,24 @@ }; }; +&peci { + peci0: peci-bus@0 { + compatible = "aspeed,ast2500-peci"; + reg = <0x0 0x60>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <15>; + clocks = <&syscon ASPEED_CLK_GATE_REFCLK>; + resets = <&syscon ASPEED_RESET_PECI>; + clock-frequency = <24000000>; + msg-timing = <1>; + addr-timing = <1>; + rd-sampling-point = <8>; + cmd-timeout-ms = <1000>; + status = "disabled"; + }; +}; + &i2c { i2c_ic: interrupt-controller@0 { #interrupt-cells = <1>;
Signature · 1 line
2.20.1
PATCH v10 6/12 peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
In reply to Jae Hyun YooThis commit adds PECI adapter driver implementation for Aspeed AST24xx/AST25xx SoCs.
--- drivers/peci/Kconfig | 27 ++ drivers/peci/Makefile | 3 + drivers/peci/peci-aspeed.c | 505 +++++++++++++++++++++++++++++++++++++ 3 files changed, 535 insertions(+) create mode 100644 drivers/peci/peci-aspeed.c
drivers/peci/Kconfig +27 -0
@@ -10,3 +10,30 @@ config PECI The Platform Environment Control Interface (PECI) is a one-wire bus interface that provides a communication channel from Intel processors and chipset components to external monitoring or control devices. + + If you want PECI support, you should say Y here and also to the + specific driver for your bus adapter(s) below. + +if PECI + +# +# PECI hardware bus configuration +# + +menu "PECI Hardware Bus support" + +config PECI_ASPEED + tristate "ASPEED PECI support" + select REGMAP_MMIO + depends on OF + depends on ARCH_ASPEED || COMPILE_TEST + help + Say Y here if you want support for the Platform Environment Control + Interface (PECI) bus adapter driver on the ASPEED SoCs. + + This support is also available as a module. If so, the module + will be called peci-aspeed. + +endmenu + +endif # PECI
drivers/peci/Makefile +3 -0
@@ -4,3 +4,6 @@ # Core functionality obj-$(CONFIG_PECI) += peci-core.o + +# Hardware specific bus drivers +obj-$(CONFIG_PECI_ASPEED) += peci-aspeed.o
drivers/peci/peci-aspeed.c new file +505 -0
505 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 7/12 dt-bindings: mfd: Add a document for PECI client driver
In reply to Jae Hyun YooThis commit adds a dt-bindings document for PECI client driver.
--- .../bindings/mfd/intel-peci-client.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/intel-peci-client.txt
Documentation/devicetree/bindings/mfd/intel-peci-client.txt new file +34 -0
@@ -0,0 +1,34 @@ +* Intel PECI client bindings + +PECI (Platform Environment Control Interface) is a one-wire bus interface that +provides a communication channel from PECI clients in Intel processors and +chipset components to external monitoring or control devices. PECI is designed +to support the following sideband functions: + +- Processor and DRAM thermal management +- Platform Manageability +- Processor Interface Tuning and Diagnostics +- Failure Analysis + +Required properties: +- compatible : Should be "intel,peci-client". +- reg : Should contain address of a client CPU. According to the PECI + specification, client addresses start from 0x30. + +Example: + peci-bus@0 { + compatible = "vendor,soc-peci"; + reg = <0x0 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + + peci-client@30 { + compatible = "intel,peci-client"; + reg = <0x30>; + }; + + peci-client@31 { + compatible = "intel,peci-client"; + reg = <0x31>; + }; + };
Signature · 1 line
2.20.1
PATCH v10 8/12 mfd: intel-peci-client: Add PECI client driver
In reply to Jae Hyun YooThis commit adds PECI client driver.
--- drivers/mfd/Kconfig | 14 +++ drivers/mfd/Makefile | 1 + drivers/mfd/intel-peci-client.c | 143 ++++++++++++++++++++++++++ include/linux/mfd/intel-peci-client.h | 108 +++++++++++++++++++ 4 files changed, 266 insertions(+) create mode 100644 drivers/mfd/intel-peci-client.c create mode 100644 include/linux/mfd/intel-peci-client.h
drivers/mfd/Kconfig +14 -0
@@ -604,6 +604,20 @@ config MFD_INTEL_MSIC Passage) chip. This chip embeds audio, battery, GPIO, etc. devices used in Intel Medfield platforms. +config MFD_INTEL_PECI_CLIENT + bool "Intel PECI client" + depends on (PECI || COMPILE_TEST) + select MFD_CORE + help + If you say yes to this option, support will be included for the + Intel PECI (Platform Environment Control Interface) client. PECI is a + one-wire bus interface that provides a communication channel from PECI + clients in Intel processors and chipset components to external + monitoring or control devices. + + Additional drivers must be enabled in order to use the functionality + of the device. + config MFD_IPAQ_MICRO bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support" depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
@@ -204,6 +204,7 @@ obj-$(CONFIG_MFD_INTEL_LPSS) += intel-lpss.o obj-$(CONFIG_MFD_INTEL_LPSS_PCI) += intel-lpss-pci.o obj-$(CONFIG_MFD_INTEL_LPSS_ACPI) += intel-lpss-acpi.o obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o +obj-$(CONFIG_MFD_INTEL_PECI_CLIENT) += intel-peci-client.o obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o
drivers/mfd/intel-peci-client.c new file +143 -0
143 lines not on this page · raw message
include/linux/mfd/intel-peci-client.h new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 9/12 Documentation: hwmon: Add documents for PECI hwmon client drivers
In reply to Jae Hyun YooThis commit adds hwmon documents for PECI cputemp and dimmtemp drivers.
--- Documentation/hwmon/peci-cputemp | 78 +++++++++++++++++++++++++++++++ Documentation/hwmon/peci-dimmtemp | 50 ++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 Documentation/hwmon/peci-cputemp create mode 100644 Documentation/hwmon/peci-dimmtemp
Documentation/hwmon/peci-cputemp new file +78 -0
@@ -0,0 +1,78 @@ +Kernel driver peci-cputemp +========================== + +Supported chips: + One of Intel server CPUs listed below which is connected to a PECI bus. + * Intel Xeon E5/E7 v3 server processors + Intel Xeon E5-14xx v3 family + Intel Xeon E5-24xx v3 family + Intel Xeon E5-16xx v3 family + Intel Xeon E5-26xx v3 family + Intel Xeon E5-46xx v3 family + Intel Xeon E7-48xx v3 family + Intel Xeon E7-88xx v3 family + * Intel Xeon E5/E7 v4 server processors + Intel Xeon E5-16xx v4 family + Intel Xeon E5-26xx v4 family + Intel Xeon E5-46xx v4 family + Intel Xeon E7-48xx v4 family + Intel Xeon E7-88xx v4 family + * Intel Xeon Scalable server processors + Intel Xeon Bronze family + Intel Xeon Silver family + Intel Xeon Gold family + Intel Xeon Platinum family + Addresses scanned: PECI client address 0x30 - 0x37 + Datasheet: Available from http://www.intel.com/design/literature.htm + +Author: + Jae Hyun Yoo <[email protected]> + +Description +----------- + +This driver implements a generic PECI hwmon feature which provides Digital +Thermal Sensor (DTS) thermal readings of the CPU package and CPU cores that are +accessible using the PECI Client Command Suite via the processor PECI client. + +All temperature values are given in millidegree Celsius and will be measurable +only when the target CPU is powered on. + +sysfs attributes +---------------- + +temp1_label "Die" +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_label "Tcontrol" +temp2_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. +temp2_crit Provides Tcontrol critical value of the CPU package + which is same to Tjmax. + +temp3_label "Tthrottle" +temp3_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. + +temp4_label "Tjmax" +temp4_input Provides the maximum junction temperature, Tjmax of the + CPU package. + +temp[5-*]_label Provides string "Core X", where X is resolved core + number. +temp[5-*]_input Provides current temperature of each core. +temp[5-*]_max Provides thermal control temperature of the core. +temp[5-*]_crit Provides shutdown temperature of the core. +temp[5-*]_crit_hyst Provides the hysteresis value from Tcontrol to Tjmax of + the core.
Documentation/hwmon/peci-dimmtemp new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 10/12 hwmon: Add PECI cputemp driver
In reply to Jae Hyun YooThis commit adds PECI cputemp hwmon driver.
--- drivers/hwmon/Kconfig | 14 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-cputemp.c | 394 +++++++++++++++++++++++++++++++++++ drivers/hwmon/peci-hwmon.h | 49 +++++ 4 files changed, 458 insertions(+) create mode 100644 drivers/hwmon/peci-cputemp.c create mode 100644 drivers/hwmon/peci-hwmon.h
drivers/hwmon/Kconfig +14 -0
@@ -1310,6 +1310,20 @@ config SENSORS_PCF8591 These devices are hard to detect and rarely found on mainstream hardware. If unsure, say N. +config SENSORS_PECI_CPUTEMP + tristate "PECI CPU temperature monitoring support" + depends on PECI + select MFD_INTEL_PECI_CLIENT + help + If you say yes here you get support for the generic Intel PECI + cputemp driver which provides Digital Thermal Sensor (DTS) thermal + readings of the CPU package and CPU cores that are accessible using + the PECI Client Command Suite via the processor PECI client. + Check Documentation/hwmon/peci-cputemp for details. + + This driver can also be built as a module. If so, the module + will be called peci-cputemp. + source "drivers/hwmon/pmbus/Kconfig" config SENSORS_PWM_FAN
drivers/hwmon/Makefile +1 -0
@@ -141,6 +141,7 @@ obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o +obj-$(CONFIG_SENSORS_PECI_CPUTEMP) += peci-cputemp.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o
drivers/hwmon/peci-cputemp.c new file +394 -0
394 lines not on this page · raw message
drivers/hwmon/peci-hwmon.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 11/12 hwmon: Add PECI dimmtemp driver
In reply to Jae Hyun YooThis commit adds PECI dimmtemp hwmon driver.
--- drivers/hwmon/Kconfig | 14 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/peci-dimmtemp.c | 284 ++++++++++++++++++++++++++++++++++ 3 files changed, 299 insertions(+) create mode 100644 drivers/hwmon/peci-dimmtemp.c
drivers/hwmon/Kconfig +14 -0
@@ -1324,6 +1324,20 @@ config SENSORS_PECI_CPUTEMP This driver can also be built as a module. If so, the module will be called peci-cputemp. +config SENSORS_PECI_DIMMTEMP + tristate "PECI DIMM temperature monitoring support" + depends on PECI + select MFD_INTEL_PECI_CLIENT + help + If you say yes here you get support for the generic Intel PECI hwmon + driver which provides Digital Thermal Sensor (DTS) thermal readings of + DIMM components that are accessible using the PECI Client Command + Suite via the processor PECI client. + Check Documentation/hwmon/peci-dimmtemp for details. + + This driver can also be built as a module. If so, the module + will be called peci-dimmtemp. + source "drivers/hwmon/pmbus/Kconfig" config SENSORS_PWM_FAN
drivers/hwmon/Makefile +1 -0
@@ -142,6 +142,7 @@ obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o obj-$(CONFIG_SENSORS_PECI_CPUTEMP) += peci-cputemp.o +obj-$(CONFIG_SENSORS_PECI_DIMMTEMP) += peci-dimmtemp.o obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o
drivers/hwmon/peci-dimmtemp.c new file +284 -0
284 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v10 12/12 Add maintainers for the PECI subsystem
In reply to Jae Hyun YooThis commit adds maintainer information for the PECI subsystem.
--- MAINTAINERS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
MAINTAINERS +22 -0
@@ -1372,6 +1372,14 @@ F: arch/arm/mach-aspeed/ F: arch/arm/boot/dts/aspeed-* N: aspeed +ARM/ASPEED PECI DRIVER +M: Jae Hyun Yoo <[email protected]> +M: Jason M Biils <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/peci/peci-aspeed.txt +F: drivers/peci/peci-aspeed.c + ARM/CALXEDA HIGHBANK ARCHITECTURE M: Rob Herring <[email protected]> L: [email protected] (moderated for non-subscribers)
@@ -11885,6 +11893,20 @@ L: [email protected] S: Maintained F: drivers/platform/x86/peaq-wmi.c +PECI SUBSYSTEM +M: Jae Hyun Yoo <[email protected]> +M: Jason M Biils <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/peci/ +F: drivers/mfd/intel-peci-client.c +F: drivers/peci/ +F: drivers/hwmon/peci-*.c +F: drivers/hwmon/peci-hwmon.h +F: include/linux/mfd/intel-peci-client.h +F: include/linux/peci.h +F: include/uapi/linux/peci-ioctl.h + PER-CPU MEMORY ALLOCATOR M: Dennis Zhou <[email protected]> M: Tejun Heo <[email protected]>
Signature · 1 line
2.20.1
Re: [PATCH v10 10/12] hwmon: Add PECI cputemp driver
In reply to Jae Hyun YooHi,
A few minor nitpicks that you may consider.
drivers/hwmon/peci-cputemp.c line 269
Quoted 6 lines · Jae Hyun Yoo
drivers/hwmon/peci-cputemp.c new file +5
-0+if (priv->temp_config[channel] &BIT (attr)) +if (channel <DEFAULT_CHANNEL_NUMS || + (channel >=DEFAULT_CHANNEL_NUMS && + (priv->core_mask &BIT (channel -DEFAULT_CHANNEL_NUMS )))) +return 0444 ;
Maybe if ((...) && (...)) instead of double if?
drivers/hwmon/peci-cputemp.c line 318
Quoted 5 lines
drivers/hwmon/peci-cputemp.c new file +5
-0+for (i =0 ; i < priv->gen_info->core_max; i++) +if (priv->core_mask &BIT (i)) +while (i +DEFAULT_CHANNEL_NUMS >= priv->config_idx) + priv->temp_config[priv->config_idx++] = + config_table[channel_core];
priv->config_idx <= i + DEFAULT_CHANNEL_NUMS seems more readable (i.e. the while-loop variable first).
drivers/hwmon/peci-hwmon.h line 37
Quoted 8 lines
drivers/hwmon/peci-hwmon.h new file +8
-0+static inline bool peci_temp_need_update (struct temp_data *temp) +{ +if (temp->valid && +time_before (jiffies, temp->last_updated +UPDATE_INTERVAL )) +return false; + +return true; +}
Simply return the condition result.
Cheers,
Miguel
Re: [PATCH v10 01/12] dt-bindings: Add a document of PECI subsystem
In reply to Jae Hyun YooQuoted 4 lines · Jae Hyun Yoo
This commit adds a document of generic PECI bus, adapter and client driver.
Quoted 9 lines
Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Joel Stanley <[email protected]>Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Haiyue Wang <[email protected]>Reviewed-by James Feist <[email protected]>Reviewed-by Vernon Mauery <[email protected]>Reviewed-by Rob Herring <[email protected]>
Re: [PATCH v10 04/12] dt-bindings: Add a document of PECI adapter driver for ASPEED AST24xx/25xx SoCs
In reply to Jae Hyun YooQuoted 4 lines · Jae Hyun Yoo
This commit adds a dt-bindings document of PECI adapter driver for ASPEED AST24xx/25xx SoCs.
Quoted 15 lines
Cc Mark Rutland <[email protected]>Cc Joel Stanley <[email protected]>Cc Andrew Jeffery <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Jason M Biils <[email protected]>Cc Milton Miller II <[email protected]>Cc Pavel Machek <[email protected]>Cc Robin Murphy <[email protected]>Cc Ryan Chen <[email protected]>Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Haiyue Wang <[email protected]>Reviewed-by James Feist <[email protected]>Reviewed-by Vernon Mauery <[email protected]>Reviewed-by Rob Herring <[email protected]>
Joel Stanley
maintainerRe: [PATCH v10 05/12] ARM: dts: aspeed: peci: Add PECI node
In reply to Jae Hyun YooHi Jae,
Quoted 3 lines · Jae Hyun Yoo
This commit adds PECI bus/adapter node of AST24xx/AST25xx into aspeed-g4 and aspeed-g5.
This looks good, aside from the alias.
It will go via my aspeed tree once the bindings are merged. Send them to [email protected] at that time.
In the future I suggest leaving the changes to arch/arm/boot/dts until after the bindings and driver patches have landed. They will rarely go in before hand as the bindings need to be agreed on.
Quoted 4 lines
serial3 = &uart4; serial4 = &uart5; serial5 = &vuart;+ peci0 = &peci0;
I don't think this is necessary. Can you explain why you think you need it?
Cheers,
Joel
Joel Stanley
maintainerRe: [PATCH v10 03/12] peci: Add support for PECI bus driver core
In reply to Jae Hyun YooHello Jae,
Quoted 3 lines · Jae Hyun Yoo
This commit adds driver implementation for PECI bus core into linux driver framework.
I would like to help you get this merged next release cycle, as we are now carrying it in OpenBMC. I suggest we ask Greg to queue it up if there are no objections after you've addressed my questions.
Quoted 1 line
+static u8
peci_aw_fcs(u8 *data, int len)
I was wondering what aw_fcs meant. I notice that later on you describe it as an Assure Write Frame Check Sequence byte. You could add a comment next to this function :)
Instead of casing to u8 every time you call this, you could have this take a struct peci_xfer_msg * and cast when calling crc8.
drivers/peci/peci-core.c line 118
Quoted 12 lines
drivers/peci/peci-core.c new file +12
-0+{ +return crc8 (peci_crc8_table, data, (size_t )len,0 ); +} + +static int __peci_xfer (struct peci_adapter *adapter,struct peci_xfer_msg *msg, +bool do_retry,bool has_aw_fcs) +{ +ktime_t start, end; +s64 elapsed_ms; +int rc =0 ; + +/**
These are for kerneldoc, and the comments aren't kerneldoc. Replace them with /* instead.
Quoted 23 lines
drivers/peci/peci-core.c new file +23
-0+* For some commands, the PECI originator may need to retry a command if +* the processor PECI client responds with a 0x8x completion code. In +* each instance, the processor PECI client may have started the +* operation but not completed it yet. When the 'retry' bit is set, the +* PECI client will ignore a new request if it exactly matches a +* previous valid request. +*/ + +if (do_retry) + start =ktime_get (); + + do { + rc = adapter->xfer(adapter, msg); + + if (!do_retry || rc) + break; + + if (msg->rx_buf[0] == DEV_PECI_CC_SUCCESS) + break; + + /* Retry is needed when completion code is 0x8x */ + if ((msg->rx_buf[0] & DEV_PECI_CC_RETRY_CHECK_MASK) != + DEV_PECI_CC_NEED_RETRY) {
drivers/peci/peci-core.c line 151
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ rc = -EIO ; +break ; + } + +/* Set the retry bit to indicate a retry attempt */ + msg->tx_buf[1 ] |=DEV_PECI_RETRY_BIT ; + +/* Recalculate the AW FCS if it has one */ +if (has_aw_fcs) + msg->tx_buf[msg->tx_len - 1] = 0x80 ^
Can we guarantee that msg->tx_len will be set to non-zero whenever has_aw_fcs?
I suggest checking before doing the assignment in case a new caller is added and they make a mistake.
drivers/peci/peci-core.c line 295
Quoted 12 lines
drivers/peci/peci-core.c new file +12
-0+static int peci_ioctl_get_dib (struct peci_adapter *adapter,void *vmsg) +{ +struct peci_get_dib_msg *umsg = vmsg; +struct peci_xfer_msg msg; +int rc; + + msg.addr = umsg->addr; + msg.tx_len =GET_DIB_WR_LEN ; + msg.rx_len =GET_DIB_RD_LEN ; + msg.tx_buf[0 ] =GET_DIB_PECI_CMD ; + + rc =peci_xfer (adapter, &msg);
Most of tx_buf is going to be uninitialised. I assume a well behaving adapter->xfer will check this and only send the correct number of bytes, but it might pay to zero out struct peci_xfer_msg in all of these functions?
Quoted 11 lines
drivers/peci/peci-core.c new file +10
-0+if (rc) +return rc; + + umsg->dib =le64_to_cpup ((__le64 *)msg.rx_buf); + +return 0 ; +} + +#if IS_ENABLED (CONFIG_OF ) +static struct peci_client *peci_of_register_device(struct peci_adapter *adapter,
drivers/peci/peci-core.c line 1072
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ struct device_node *node) +{ +struct peci_board_info info = {}; +struct peci_client *result; +const __be32 *addr_be; +int len; + +dev_dbg (&adapter->dev,"register %pOF\n" , node); + +if (of_modalias_node (node, info.type,sizeof (info.type)) <0 ) {
I don't understand why you're doing this. Won't this always be peci, as your binding requires?
drivers/peci/peci-core.c line 1078
Quoted 6 lines
drivers/peci/peci-core.c new file +6
-0+dev_err (&adapter->dev,"modalias failure on %pOF\n" , node); +return ERR_PTR (-EINVAL ); + } + + addr_be =of_get_property (node,"reg" , &len); +if (!addr_be || len <sizeof (*addr_be)) {
The second check looks suspicious.
You could fix it to check the expected length (4), or use of_property_read_u32.
drivers/peci/peci-core.c line 1087
Quoted 9 lines
drivers/peci/peci-core.c new file +9
-0+dev_err (&adapter->dev,"invalid reg on %pOF\n" , node); +return ERR_PTR (-EINVAL ); + } + + info.addr =be32_to_cpup (addr_be); + info.of_node =of_node_get (node); + + result =peci_new_device (adapter, &info); +if (!result)
Should you do an of_node_put here?
drivers/peci/peci-core.c line 1090
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+ result =ERR_PTR (-EINVAL ); + +of_node_put (node);
Why do you release the reference here?
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+return result; +} +
Joel Stanley
maintainerRe: [PATCH v10 06/12] peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
In reply to Jae Hyun Yoodrivers/peci/peci-aspeed.c line 335
Quoted 9 lines · Jae Hyun Yoo
drivers/peci/peci-aspeed.c new file +9
-0+ ret =of_property_read_u32 (priv->dev->of_node,"cmd-timeout-ms" , + &priv->cmd_timeout_ms); +if (ret || priv->cmd_timeout_ms >PECI_CMD_TIMEOUT_MS_MAX || + priv->cmd_timeout_ms ==0 ) { +if (!ret) +dev_warn (priv->dev, +"Invalid cmd-timeout-ms : %u. Use default : %u\n" , + priv->cmd_timeout_ms, +PECI_CMD_TIMEOUT_MS_DEFAULT );
As this property is documented as optional, I'd split out the checks so you only warn when the value provided is invalid.
drivers/peci/peci-aspeed.c line 343
Quoted 6 lines
drivers/peci/peci-aspeed.c new file +6
-0+ +regmap_write (priv->regmap,ASPEED_PECI_CTRL , +FIELD_PREP (PECI_CTRL_CLK_DIV_MASK ,PECI_CLK_DIV_DEFAULT ) | +PECI_CTRL_PECI_CLK_EN ); + +/**
Just the one *.
Quoted 4 lines
drivers/peci/peci-aspeed.c new file +4
-0+* Timing negotiation period setting. +* The unit of the programmed value is 4 times of PECI clock period. +*/ + regmap_write(priv->regmap, ASPEED_PECI_TIMING,
drivers/peci/peci-aspeed.c line 381
Quoted 10 lines
drivers/peci/peci-aspeed.c new file +9
-0+FIELD_PREP (PECI_TIMING_MESSAGE_MASK , msg_timing) | + FIELD_PREP(PECI_TIMING_ADDRESS_MASK, addr_timing)); +static int aspeed_peci_xfer (struct peci_adapter *adapter, +struct peci_xfer_msg *msg) +{ +struct aspeed_peci *priv =peci_get_adapdata (adapter); + +return aspeed_peci_xfer_native (priv, msg); +}
It looks like you could do the peci_get_adapdata in aspeed_peci_xfer_native and drop the need for this wrapper.
Quoted 14 lines
drivers/peci/peci-aspeed.c new file +12
-0+ +static int aspeed_peci_probe (struct platform_device *pdev) +{ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (base)) { + ret =PTR_ERR (base); + goto err_put_adapter_dev; + } + + priv->regmap =devm_regmap_init_mmio (&pdev->dev, base, + &aspeed_peci_regmap_config);
drivers/peci/peci-aspeed.c line 419
Quoted 10 lines
drivers/peci/peci-aspeed.c new file +10
-0+if (IS_ERR (priv->regmap)) { + ret =PTR_ERR (priv->regmap); + goto err_put_adapter_dev; + } + +/** +* We check that the regmap works on this very first access, +* but as this is an MMIO-backed regmap, subsequent regmap +* access is not going to fail and we skip error checks from +* this point.
Why do you use a regmap for this driver? AFAICT it has exclusive ownership over the register range it uses, which is sometimes a reason to use a regmap over a mmio region.
I'm not sure if you've ever disassembled drivers/base/regmap/regmap.o, but if you do you will find that a single mmio read turns into hundreds of instructions.
Cheers,
Joel
Re: [PATCH v10 07/12] dt-bindings: mfd: Add a document for PECI client driver
In reply to Jae Hyun YooQuoted 13 lines · Jae Hyun Yoo
This commit adds a dt-bindings document for PECI client driver.
Cc Lee Jones <[email protected]>Cc Rob Herring <[email protected]>Cc Mark Rutland <[email protected]>Cc Andrew Jeffery <[email protected]>Cc James Feist <[email protected]>Cc Jason M Biils <[email protected]>Cc Joel Stanley <[email protected]>Cc Vernon Mauery <[email protected]>Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Rob Herring <[email protected]>
Re: [PATCH v10 08/12] mfd: intel-peci-client: Add PECI client driver
In reply to Jae Hyun YooQuoted 2 lines · Jae Hyun Yoo
This commit adds PECI client driver.
It looks like it's a PECI driver for the three CPU families, and it implements cpu and dimm temp, with sideband functions deferred to the future. If you add that information with a few more words it would make for a nicer commit message.
Quoted 1 line
Signed-off-by Jae Hyun Yoo <[email protected]>
Re: [PATCH v10 09/12] Documentation: hwmon: Add documents for PECI hwmon client drivers
In reply to Jae Hyun YooQuoted 13 lines · Jae Hyun Yoo
This commit adds hwmon documents for PECI cputemp and dimmtemp drivers.
Cc Guenter Roeck <[email protected]>Cc Jean Delvare <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Jason M Biils <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Haiyue Wang <[email protected]>Reviewed-by James Feist <[email protected]>Reviewed-by Vernon Mauery <[email protected]>Acked-by Guenter Roeck <[email protected]>
Re: [PATCH v10 05/12] ARM: dts: aspeed: peci: Add PECI node
In reply to Joel StanleyHi Joel,
Quoted 7 lines · Joel Stanley
Hi Jae,
Quoted 3 lines · Jae Hyun Yoo
This commit adds PECI bus/adapter node of AST24xx/AST25xx into aspeed-g4 and aspeed-g5.
Quoted 9 lines
This looks good, aside from the alias.
It will go via my aspeed tree once the bindings are merged. Send them to [email protected] at that time.
In the future I suggest leaving the changes to
arch/arm/boot/dtsuntil after the bindings and driver patches have landed. They will rarely go in before hand as the bindings need to be agreed on.
I thought that it would be helpful if it shows an actual example in this series because it is trying to add a new subsystem. In the future, I'll submit a dts patch separately from bindings and drivers, but I'd like to keep this dts changes in this series because it has been already submitted. I'll CC linux-aspeed list from the next version. Thanks!
Quoted 8 lines
Quoted 5 lines
serial3 = &uart4; serial4 = &uart5; serial5 = &vuart;+ peci0 = &peci0;
I don't think this is necessary. Can you explain why you think you need it?
You are right. This alias is not necessary at all. Will drop it.
Thanks,
Jae
Quoted 4 lines
Cheers,
Joel
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
In reply to Joel StanleyHello Joel,
Quoted 11 lines · Joel Stanley
Hello Jae,
Quoted 3 lines · Jae Hyun Yoo
This commit adds driver implementation for PECI bus core into linux driver framework.
I would like to help you get this merged next release cycle, as we are now carrying it in OpenBMC. I suggest we ask Greg to queue it up if there are no objections after you've addressed my questions.
Thanks a lot for your help on reviewing this patch series. I'll submit v11 to address your comments. We could ask Greg to queue it then.
Quoted 6 lines
Quoted 1 line
+static u8
peci_aw_fcs(u8 *data, int len)I was wondering what
aw_fcsmeant. I notice that later on you describe it as an Assure Write Frame Check Sequence byte. You could add a comment next to this function :)
Agreed. I'll add a comment like you suggested.
Quoted 3 lines
Instead of casing to u8 every time you call this, you could have this take a struct
peci_xfer_msg* and cast when calling crc8.
Yes, that would be neater. Will fix it.
Quoted 7 lines
Quoted 7 lines
drivers/peci/peci-core.c new file +7
-0+{ +return crc8 (peci_crc8_table, data, (size_t )len,0 ); +} + +static int __peci_xfer (struct peci_adapter *adapter,struct peci_xfer_msg *msg, +bool do_retry,bool has_aw_fcs) +{
Quoted 9 lines
drivers/peci/peci-core.c line 118
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ktime_t start, end; +s64 elapsed_ms; +int rc =0 ; + +/** These are for kerneldoc, and the comments aren't kerneldoc. Replace them with /* instead.
Okay, I'll check all comments again in this series.
Quoted 36 lines
Quoted 23 lines
drivers/peci/peci-core.c new file +23
-0+* For some commands, the PECI originator may need to retry a command if +* the processor PECI client responds with a 0x8x completion code. In +* each instance, the processor PECI client may have started the +* operation but not completed it yet. When the 'retry' bit is set, the +* PECI client will ignore a new request if it exactly matches a +* previous valid request. +*/ + +if (do_retry) + start =ktime_get (); + + do { + rc = adapter->xfer(adapter, msg); + + if (!do_retry || rc) + break; + + if (msg->rx_buf[0] == DEV_PECI_CC_SUCCESS) + break; + + /* Retry is needed when completion code is 0x8x */ + if ((msg->rx_buf[0] & DEV_PECI_CC_RETRY_CHECK_MASK) != + DEV_PECI_CC_NEED_RETRY) {drivers/peci/peci-core.c line 151
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ rc = -EIO ; +break ; + } + +/* Set the retry bit to indicate a retry attempt */ + msg->tx_buf[1 ] |=DEV_PECI_RETRY_BIT ; + +/* Recalculate the AW FCS if it has one */ +if (has_aw_fcs) + msg->tx_buf[msg->tx_len - 1] = 0x80 ^Can we guarantee that
msg->tx_lenwill be set to non-zero wheneverhas_aw_fcs?
Quoted 3 lines
I suggest checking before doing the assignment in case a new caller is added and they make a mistake.
The msg->tx_len is already checked by callers - peci_ioctl_wr_pkg_cfg() and peci_ioctl_wr_pci_cfg_local() - so it's not needed to be checked again at here.
Quoted 9 lines
Quoted 9 lines
drivers/peci/peci-core.c new file +9
-0+static int peci_ioctl_get_dib (struct peci_adapter *adapter,void *vmsg) +{ +struct peci_get_dib_msg *umsg = vmsg; +struct peci_xfer_msg msg; +int rc; + + msg.addr = umsg->addr; + msg.tx_len =GET_DIB_WR_LEN ; + msg.rx_len =GET_DIB_RD_LEN ;
Quoted 9 lines
drivers/peci/peci-core.c line 207
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+ msg.tx_buf[0 ] =GET_DIB_PECI_CMD ; + + rc =peci_xfer (adapter, &msg);Most of
tx_bufis going to be uninitialised. I assume a well behavingadapter->xferwill check this and only send the correct number of bytes, but it might pay to zero out structpeci_xfer_msgin all of these functions?
The tx_buf will be initialized only amounts it needs to be in each command. The adapter->xfer is handling exactly up to msg->tx_len so it would be better keep the current code without using zeroing out the struct.
Quoted 8 lines
Quoted 7 lines
drivers/peci/peci-core.c new file +7
-0+if (rc) +return rc; + + umsg->dib =le64_to_cpup ((__le64 *)msg.rx_buf); + +return 0 ; +}
Quoted 17 lines
drivers/peci/peci-core.c line 1072
Quoted 13 lines
drivers/peci/peci-core.c new file +13
-0+ +#if IS_ENABLED (CONFIG_OF ) +static struct peci_client *peci_of_register_device (struct peci_adapter *adapter, +struct device_node *node) +{ +struct peci_board_info info = {}; +struct peci_client *result; +const __be32 *addr_be; +int len; + +dev_dbg (&adapter->dev,"register %pOF\n" , node); + +if (of_modalias_node (node, info.type,sizeof (info.type)) <0 ) {I don't understand why you're doing this. Won't this always be peci, as your binding requires?
Since it supports only 'intel,peci-client' for now, it's not needed actually. I'll drop it at this time. It would be added later if needed.
Quoted 11 lines
drivers/peci/peci-core.c line 1078
Quoted 6 lines
drivers/peci/peci-core.c new file +6
-0+dev_err (&adapter->dev,"modalias failure on %pOF\n" , node); +return ERR_PTR (-EINVAL ); + } + + addr_be =of_get_property (node,"reg" , &len); +if (!addr_be || len <sizeof (*addr_be)) {The second check looks suspicious.
You could fix it to check the expected length (4), or use
of_property_read_u32.
Right, I'll fix it using of_property_read_u32.
Quoted 12 lines
drivers/peci/peci-core.c line 1087
Quoted 9 lines
drivers/peci/peci-core.c new file +9
-0+dev_err (&adapter->dev,"invalid reg on %pOF\n" , node); +return ERR_PTR (-EINVAL ); + } + + info.addr =be32_to_cpup (addr_be); + info.of_node =of_node_get (node); + + result =peci_new_device (adapter, &info); +if (!result)Should you do an
of_node_puthere?
Oh, this code is definitely incorrect. I should to put the of_node reference at here if peci_new_device() fails and should keep the reference until peci_unregister_device() is called. Will fix it. Thank you for your pointing it out!
Quoted 6 lines
drivers/peci/peci-core.c line 1090
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+ result =ERR_PTR (-EINVAL ); + +of_node_put (node);Why do you release the reference here?
This is incorrect too. Will move the of_node_get/put code into peci_new_device() and peci_unregister_device() to avoid confusion. Thanks again for your pointing it out. :)
Quoted 4 lines
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+return result; +} +
Re: [PATCH v10 06/12] peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
In reply to Joel StanleyQuoted 11 lines · Joel Stanley
drivers/peci/peci-aspeed.c line 335
Quoted 9 lines · Jae Hyun Yoo
drivers/peci/peci-aspeed.c new file +9
-0+ ret =of_property_read_u32 (priv->dev->of_node,"cmd-timeout-ms" , + &priv->cmd_timeout_ms); +if (ret || priv->cmd_timeout_ms >PECI_CMD_TIMEOUT_MS_MAX || + priv->cmd_timeout_ms ==0 ) { +if (!ret) +dev_warn (priv->dev, +"Invalid cmd-timeout-ms : %u. Use default : %u\n" , + priv->cmd_timeout_ms, +PECI_CMD_TIMEOUT_MS_DEFAULT );
Quoted 3 lines
As this property is documented as optional, I'd split out the checks so you only warn when the value provided is invalid.
Please check the above 'if' statement too. It prints out warning only when the property is defined in device tree but the value is out of range.
Quoted 9 lines
drivers/peci/peci-aspeed.c line 343
Quoted 6 lines
drivers/peci/peci-aspeed.c new file +6
-0+ +regmap_write (priv->regmap,ASPEED_PECI_CTRL , +FIELD_PREP (PECI_CTRL_CLK_DIV_MASK ,PECI_CLK_DIV_DEFAULT ) | +PECI_CTRL_PECI_CLK_EN ); + +/** Just the one *.
Will fix it.
Quoted 7 lines
Quoted 6 lines
drivers/peci/peci-aspeed.c new file +6
-0+* Timing negotiation period setting. +* The unit of the programmed value is 4 times of PECI clock period. +*/ +regmap_write (priv->regmap,ASPEED_PECI_TIMING , +FIELD_PREP (PECI_TIMING_MESSAGE_MASK , msg_timing) | +FIELD_PREP (PECI_TIMING_ADDRESS_MASK , addr_timing));
Quoted 11 lines
drivers/peci/peci-aspeed.c line 381
Quoted 7 lines
drivers/peci/peci-aspeed.c new file +7
-0+static int aspeed_peci_xfer (struct peci_adapter *adapter, +struct peci_xfer_msg *msg) +{ +struct aspeed_peci *priv =peci_get_adapdata (adapter); + +return aspeed_peci_xfer_native (priv, msg); +}It looks like you could do the
peci_get_adapdatainaspeed_peci_xfer_nativeand drop the need for this wrapper.
Yes, that would be neater. Will remove this wrapper.
Quoted 29 lines
Quoted 14 lines
drivers/peci/peci-aspeed.c new file +12
-0+ +static int aspeed_peci_probe (struct platform_device *pdev) +{ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (base)) { + ret =PTR_ERR (base); + goto err_put_adapter_dev; + } + + priv->regmap =devm_regmap_init_mmio (&pdev->dev, base, + &aspeed_peci_regmap_config);drivers/peci/peci-aspeed.c line 419
Quoted 10 lines
drivers/peci/peci-aspeed.c new file +10
-0+if (IS_ERR (priv->regmap)) { + ret =PTR_ERR (priv->regmap); + goto err_put_adapter_dev; + } + +/** +* We check that the regmap works on this very first access, +* but as this is an MMIO-backed regmap, subsequent regmap +* access is not going to fail and we skip error checks from +* this point. Why do you use a regmap for this driver? AFAICT it has exclusive ownership over the register range it uses, which is sometimes a reason to use a regmap over a mmio region.
Quoted 4 lines
I'm not sure if you've ever disassembled
drivers/base/regmap/regmap.o, but if you do you will find that a single mmio read turns into hundreds of instructions.
No specific reason. regmap makes some overhead as you mentioned but it also provides some advantages on access simplification, endianness handling and register dump at run time. I would not insist using of regmap if you prefer using of raw readl and writel. Do you want replace regmap with readl and writel in this driver?
Thanks,
Jae
Quoted 4 lines
Cheers,
Joel
Re: [PATCH v10 09/12] Documentation: hwmon: Add documents for PECI hwmon client drivers
In reply to Joel StanleyQuoted 15 lines · Joel Stanley
Quoted 13 lines · Jae Hyun Yoo
This commit adds hwmon documents for PECI cputemp and dimmtemp drivers.
Cc Guenter Roeck <[email protected]>Cc Jean Delvare <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Jason M Biils <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Haiyue Wang <[email protected]>Reviewed-by James Feist <[email protected]>Reviewed-by Vernon Mauery <[email protected]>Acked-by Guenter Roeck <[email protected]>
Quoted 2 lines
Reviewed-by Joel Stanley <[email protected]>
Hi Joel,
Thank you so much for your careful review on this patch series. I'll submit v11 soon to address your review comments.
Regards,
Jae
Re: [PATCH v10 08/12] mfd: intel-peci-client: Add PECI client driver
In reply to Joel StanleyQuoted 9 lines · Joel Stanley
Quoted 2 lines · Jae Hyun Yoo
This commit adds PECI client driver.
It looks like it's a PECI driver for the three CPU families, and it implements cpu and dimm temp, with sideband functions deferred to the future. If you add that information with a few more words it would make for a nicer commit message.
Yes, that would be nicer. I'll add the description into the commit message.
Thanks for your review!
Regards,
Jae
Quoted 4 lines
Quoted 1 line
Signed-off-by Jae Hyun Yoo <[email protected]>Reviewed-by Joel Stanley <[email protected]>
Joel Stanley
maintainerRe: [PATCH v10 06/12] peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
In reply to Jae Hyun YooQuoted 15 lines · Jae Hyun Yoo
Quoted 6 lines
drivers/peci/peci-aspeed.c line 419
Quoted 5 lines
drivers/peci/peci-aspeed.c new file +5
-0+/** +* We check that the regmap works on this very first access, +* but as this is an MMIO-backed regmap, subsequent regmap +* access is not going to fail and we skip error checks from +* this point. Quoted 8 lines
Why do you use a regmap for this driver? AFAICT it has exclusive ownership over the register range it uses, which is sometimes a reason to use a regmap over a mmio region.
I'm not sure if you've ever disassembled
drivers/base/regmap/regmap.o, but if you do you will find that a single mmio read turns into hundreds of instructions.
Quoted 5 lines
No specific reason. regmap makes some overhead as you mentioned but it also provides some advantages on access simplification, endianness handling and register dump at run time. I would not insist using of regmap if you prefer using of raw readl and writel. Do you want replace regmap with readl and writel in this driver?
I think that would be best.
You raise some good points about the regmap API, and you're not alone in using it for these reasons. We should look in to providing a suitable API without the overhead, or making regmap more efficient for the mmio case.
Re: [PATCH v10 06/12] peci: Add a PECI adapter driver for Aspeed AST24xx/AST25xx
Quoted 22 lines · Joel Stanley
Quoted 15 lines · Jae Hyun Yoo
Quoted 6 lines
drivers/peci/peci-aspeed.c line 419
Quoted 5 lines
drivers/peci/peci-aspeed.c new file +5
-0+/** +* We check that the regmap works on this very first access, +* but as this is an MMIO-backed regmap, subsequent regmap +* access is not going to fail and we skip error checks from +* this point. Quoted 8 lines
Why do you use a regmap for this driver? AFAICT it has exclusive ownership over the register range it uses, which is sometimes a reason to use a regmap over a mmio region.
I'm not sure if you've ever disassembled
drivers/base/regmap/regmap.o, but if you do you will find that a single mmio read turns into hundreds of instructions.Quoted 5 lines
No specific reason. regmap makes some overhead as you mentioned but it also provides some advantages on access simplification, endianness handling and register dump at run time. I would not insist using of regmap if you prefer using of raw readl and writel. Do you want replace regmap with readl and writel in this driver?
Quoted 7 lines
I think that would be best.
You raise some good points about the regmap API, and you're not alone in using it for these reasons. We should look in to providing a suitable API without the overhead, or making regmap more efficient for the mmio case.
Okay. I'll rewrite this driver code using readl and writel instead of regmap mmio. Thanks again for your review!
Regards,
Jae
Re: [PATCH v10 10/12] hwmon: Add PECI cputemp driver
In reply to Miguel OjedaHi Miguel,
Quoted 7 lines · Miguel Ojeda
Hi,
A few minor nitpicks that you may consider.
Quoted 1 line · Jae Hyun Yoo
Quoted 8 lines
drivers/hwmon/peci-cputemp.c line 269
Quoted 5 lines
drivers/hwmon/peci-cputemp.c new file +5
-0+if (priv->temp_config[channel] &BIT (attr)) +if (channel <DEFAULT_CHANNEL_NUMS || + (channel >=DEFAULT_CHANNEL_NUMS && + (priv->core_mask &BIT (channel -DEFAULT_CHANNEL_NUMS )))) +return 0444 ;Maybe if ((...) && (...)) instead of double if?
Okay, that would be neater. Will change it.
Quoted 9 lines
drivers/hwmon/peci-cputemp.c line 318
Quoted 5 lines
drivers/hwmon/peci-cputemp.c new file +5
-0+for (i =0 ; i < priv->gen_info->core_max; i++) +if (priv->core_mask &BIT (i)) +while (i +DEFAULT_CHANNEL_NUMS >= priv->config_idx) + priv->temp_config[priv->config_idx++] = + config_table[channel_core];
priv->config_idx<= i +DEFAULT_CHANNEL_NUMSseems more readable (i.e. the while-loop variable first).
Yeah, that would be better for readability. Will change it too.
Quoted 11 lines
drivers/hwmon/peci-hwmon.h line 37
Quoted 8 lines
drivers/hwmon/peci-hwmon.h new file +8
-0+static inline bool peci_temp_need_update (struct temp_data *temp) +{ +if (temp->valid && +time_before (jiffies, temp->last_updated +UPDATE_INTERVAL )) +return false; + +return true; +}Simply return the condition result.
I'm assuming you meant:
return !(temp->valid && time_before(jiffies, temp->last_updated +
UPDATE_INTERVAL));
Will change it as well.
Thanks for your review!
Regards,
Jae
Re: [PATCH v10 10/12] hwmon: Add PECI cputemp driver
Hi Jae,
Quoted 5 lines · Jae Hyun Yoo
I'm assuming you meant:
return !(temp->valid && time_before(jiffies,
temp->last_updated+UPDATE_INTERVAL));
Yeah, or return !... || !..., whatever you feel is more comprehensible. :)
Quoted 1 line
Thanks for your review!
You're welcome! It is just nitpicking, but I thought sending the email wouldn't hurt too much (in case you do another version of the series, otherwise don't change it just for this! :-)
Cheers,
Miguel
Re: [PATCH v10 10/12] hwmon: Add PECI cputemp driver
Hi Miguel,
Quoted 5 lines · Miguel Ojeda
Hi Jae,
Quoted 1 line · Jae Hyun Yoo
Quoted 7 lines
Quoted 4 lines
I'm assuming you meant:
return !(temp->valid && time_before(jiffies,
temp->last_updated+UPDATE_INTERVAL));Yeah, or return !... || !..., whatever you feel is more comprehensible. :)
Okay, I'll change it like above.
Quoted 6 lines
Quoted 1 line
Thanks for your review!
You're welcome! It is just nitpicking, but I thought sending the email wouldn't hurt too much (in case you do another version of the series, otherwise don't change it just for this! :-)
Currently, I'm making v11 series. I'll address your comments when I submit the version. Thanks again for your review! :)
Regards,
Jae
Quoted 3 lines
Cheers,
Miguel
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
In reply to Jae Hyun Yoodrivers/peci/Kconfig line 12
Quoted 8 lines · Jae Hyun Yoo
drivers/peci/Kconfig new file +8
-0+config PECI + bool "PECI support" + select RT_MUTEXES + select CRC8 + help + The Platform Environment Control Interface (PECI) is a one-wire bus + interface that provides a communication channel from Intel processors + and chipset components to external monitoring or control devices.
Why can't this be built as a module?
And why do you rely on rt mutexes?
Anyway, the driver core interaction looks good, I have a few other minor comments on the ioctl handling:
Quoted 6 lines
drivers/peci/peci-core.c new file +6
-0+typedef int (*peci_ioctl_fn_type )(struct peci_adapter *,void *); + +static const peci_ioctl_fn_type peci_ioctl_fn[PECI_CMD_MAX ] = { + peci_ioctl_xfer, + peci_ioctl_ping, + peci_ioctl_get_dib,
drivers/peci/peci-core.c line 533
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ peci_ioctl_get_temp, + peci_ioctl_rd_pkg_cfg, + peci_ioctl_wr_pkg_cfg, + peci_ioctl_rd_ia_msr, +NULL ,/* Reserved */ + peci_ioctl_rd_pci_cfg, +NULL ,/* Reserved */ + peci_ioctl_rd_pci_cfg_local, + peci_ioctl_wr_pci_cfg_local, +};
That's "interesting", why not have a list that has the ioctl number, and the function pointer? That way no need for "reserved" entries, and you don't have to add a new item to your "is this a valid ioctl" check below:
drivers/peci/peci-core.c line 576
Quoted 7 lines
drivers/peci/peci-core.c new file +7
-0+static long peci_ioctl (struct file *file,unsigned int iocmd,unsigned long arg) +{ +struct peci_adapter *adapter = file->private_data; +void __user *argp = (void __user *)arg; +unsigned int msg_len; +enum peci_cmd cmd; +int rc =0 ;
No need to set rc here.
drivers/peci/peci-core.c line 580
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+u8 *msg; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ;
Really? Nice, you have userspace tools running as root, what could go wrong... :)
drivers/peci/peci-core.c line 582
Quoted 2 lines
drivers/peci/peci-core.c new file +2
-0+ +dev_dbg (&adapter->dev,"ioctl, cmd=0x%x, arg=0x%lx\n" , iocmd, arg);
I understand the need for this type of thing when debugging the code initially, but you can remove them all now, ftrace should provide what you need now, right?
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ +switch (iocmd) { +case PECI_IOC_XFER : +case PECI_IOC_PING : +case PECI_IOC_GET_DIB :
drivers/peci/peci-core.c line 597
Quoted 10 lines
drivers/peci/peci-core.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 : + cmd =_IOC_NR (iocmd); + msg_len =_IOC_SIZE (iocmd); +break ;
That check up there can be replaced with an iteration over the list of ioctl functions, right?
drivers/peci/peci-core.c line 609
Quoted 12 lines
drivers/peci/peci-core.c new file +12
-0+ +default : +dev_dbg (&adapter->dev,"Invalid ioctl cmd : 0x%x\n" , iocmd); +return -ENOTTY ; + } + +if (!access_ok (argp, msg_len)) +return -EFAULT ; + + msg =memdup_user (argp, msg_len); +if (IS_ERR (msg)) +return PTR_ERR (msg);
Why call access_ok() if you are going to copy the memory anyways? memdup_user should fail with -EFAULT if you can't copy the memory properly.
drivers/peci/peci-core.c line 611
Quoted 2 lines
drivers/peci/peci-core.c new file +2
-0+ + rc =peci_command (adapter, cmd, msg);
Are you _SURE_ you audited your ioctls to not do foolish things with userspace values? I sure didn't, so can you please have someone else do this and sign off on this patch that they did so?
drivers/peci/peci-core.c line 655
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+static int peci_detect (struct peci_adapter *adapter,u8 addr) +{ +struct peci_ping_msg msg; + + msg.addr = addr;
What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
Quoted 14 lines
drivers/peci/peci-core.c new file +14
-0+static ssize_t peci_sysfs_new_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_board_info info = {}; +struct peci_client *client; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"new_device" );
drivers/peci/peci-core.c line 946
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"new_device" ); +return -EINVAL ; + } +memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end);
Please do not tell me you are parsing a sysfs write to do some type of new configuration. That is not what sysfs is for, that is what configfs is for, please use that instead, this isn't ok.
Quoted 9 lines
drivers/peci/peci-core.c new file +9
-0+if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" ,"new_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"new_device" ); +return -EINVAL ; + } +
drivers/peci/peci-core.c line 965
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ client =peci_new_device (adapter, &info); +if (!client) +return -EINVAL ; + +/* Keep track of the added device */ +mutex_lock (&adapter->userspace_clients_lock); +list_add_tail (&client->detected, &adapter->userspace_clients); +mutex_unlock (&adapter->userspace_clients_lock); +dev_info (dev,"%s: Instantiated device %s at 0x%02hx\n" ,"new_device" , + info.type, info.addr);
Don't be noisy for things that are expected to happen.
drivers/peci/peci-core.c line 969
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+ +return count; +} +static DEVICE_ATTR(new_device, 0200, NULL, peci_sysfs_new_device);
Not that you should be doing this, but DEVICE_ATTR_RO() is what you want here, right?
Quoted 25 lines
drivers/peci/peci-core.c new file +25
-0+ +static ssize_t peci_sysfs_delete_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_client *client, *next; +struct peci_board_info info = {}; +struct peci_driver *driver; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"delete_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"delete_device" ); +return -EINVAL ; + } +memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */
drivers/peci/peci-core.c line 1004
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ rc =sscanf (++blank,"%hi%c" , &info.addr, &end); +if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" , +"delete_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"delete_device" ); +return -EINVAL ; + }
Same here, no parsing of configurations through sysfs, that is not ok. Again, use configfs.
Quoted 13 lines
drivers/peci/peci-core.c new file +13
-0+ +/* Make sure the device was added through sysfs */ + rc = -ENOENT ; +mutex_lock (&adapter->userspace_clients_lock); +list_for_each_entry_safe (client, next, &adapter->userspace_clients, + detected) { + driver =to_peci_driver (client->dev.driver); + +if (client->addr == info.addr && + !strncmp (client->name, info.type,PECI_NAME_SIZE )) { +dev_info (dev,"%s: Deleting device %s at 0x%02hx\n" , +"delete_device" , client->name, client->addr); +list_del (&client->detected);
drivers/peci/peci-core.c line 1027
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+peci_unregister_device (client); + rc = count; +break ; + } + } +mutex_unlock (&adapter->userspace_clients_lock); + +if (rc <0 ) +dev_err (dev,"%s: Can't find device in list\n" , +"delete_device" );
So you can just spam the syslog by writing odd values to the file? Not good.
drivers/peci/peci-core.c line 1032
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ +return rc; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + peci_sysfs_delete_device);
sysfs files that remove themselves are reserved for a specific circle in hell, you really don't want to mess with them :(
Quoted 11 lines
include/linux/peci.h new file +11
-0+/** +* struct peci_adapter - represent a PECI adapter +* @owner: owner module of the PECI adpater +* @bus_lock: mutex for exclusion of multiple callers +* @dev: device interface to this driver +* @cdev: character device object to create character device +* @nr: the bus number to map +* @name: name of the adapter +* @userspace_clients_lock: mutex for exclusion of clients handling +* @userspace_clients: list of registered clients +* @xfer: low-level transfer function pointer of the adapter
include/linux/peci.h line 40
Quoted 10 lines
include/linux/peci.h new file +10
-0+* @cmd_mask: mask for supportable PECI commands +* +* Each PECI adapter can communicate with one or more PECI client children. +* These make a small bus, sharing a single wired PECI connection. +*/ +struct peci_adapter { +struct module *owner; +struct rt_mutex bus_lock; +struct device dev; +struct cdev cdev;
Yeah, two differently reference counted variables in the same structure, what could go wrong! :(
Don't do this, make your cdev a pointer to be sure you get things right, otherwise this will never work properly.
And shouldn't the character device be a class device? Don't confuse devices in the driver model with the interaction of them to userspace in a specific manner, those should be separate things, right?
Review
Quoted 2 lines
(quoted diff) +2
-0+ int nr; + char name[PECI_NAME_SIZE];
What's wrong with the name in struct device?
include/linux/peci.h line 47
Quoted 5 lines
include/linux/peci.h new file +5
-0+struct mutex userspace_clients_lock;/* clients list mutex */ +struct list_head userspace_clients; +int (*xfer)(struct peci_adapter *adapter, +struct peci_xfer_msg *msg); +uint cmd_mask;
u32?
Quoted 8 lines
include/uapi/linux/peci-ioctl.h new file +5
-0@@ -0,0 +1,403 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2018-2019 Intel Corporation */ + +#ifndef __PECI_IOCTL_H +#define __PECI_IOCTL_H
include/uapi/linux/peci-ioctl.h line 15
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+ +#include <linux/ioctl.h> +#include <linux/types.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 */ +#define MAX_PCI_READ_LEN 24/* Number of bytes of the PCI Space read */
PCI? Or PECI? I'm confused now, what does PCI have to do with PECI?
include/uapi/linux/peci-ioctl.h line 24
Quoted 9 lines
include/uapi/linux/peci-ioctl.h new file +9
-0+ +#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
You just abused the PCI core namespace here, are you sure about that?
Quoted 103 lines
include/uapi/linux/peci-ioctl.h new file +103
-0+ +/* Package Identifier Read Parameter Value */ +#define PKG_ID_CPU_ID 0x0000/* CPUID Info */ +#define PKG_ID_PLATFORM_ID 0x0001/* Platform ID */ +#define PKG_ID_UNCORE_ID 0x0002/* Uncore Device ID */ +#define PKG_ID_MAX_THREAD_ID 0x0003/* Max Thread ID */ +#define PKG_ID_MICROCODE_REV 0x0004/* CPU Microcode Update Revision */ +#define PKG_ID_MACHINE_CHECK_STATUS 0x0005/* 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 */ +#define MBX_INDEX_PKG_RAPL_PERF 8/* Pkg RAPL Performance Status Read */ +#define MBX_INDEX_PER_CORE_DTS_TEMP 9/* Per Core DTS Temperature Read */ +#define MBX_INDEX_DTS_MARGIN 10/* DTS thermal margin */ +#define MBX_INDEX_SKT_PWR_THRTL_DUR 11/* Socket Power Throttled Duration */ +#define MBX_INDEX_CFG_TDP_CONTROL 12/* TDP Config Control */ +#define MBX_INDEX_CFG_TDP_LEVELS 13/* TDP Config Levels */ +#define MBX_INDEX_DDR_DIMM_TEMP 14/* DDR DIMM Temperature */ +#define MBX_INDEX_CFG_ICCMAX 15/* Configurable ICCMAX */ +#define MBX_INDEX_TEMP_TARGET 16/* Temperature Target Read */ +#define MBX_INDEX_CURR_CFG_LIMIT 17/* Current Config Limit */ +#define MBX_INDEX_DIMM_TEMP_READ 20/* Package Thermal Status Read */ +#define MBX_INDEX_DRAM_IMC_TMP_READ 22/* DRAM IMC Temperature Read */ +#define MBX_INDEX_DDR_CH_THERM_STAT 23/* DDR Channel Thermal Status */ +#define MBX_INDEX_PKG_POWER_LIMIT1 26/* Package Power Limit1 */ +#define MBX_INDEX_PKG_POWER_LIMIT2 27/* Package Power Limit2 */ +#define MBX_INDEX_TDP 28/* Thermal design power minimum */ +#define MBX_INDEX_TDP_HIGH 29/* Thermal design power maximum */ +#define MBX_INDEX_TDP_UNITS 30/* Units for power/energy registers */ +#define MBX_INDEX_RUN_TIME 31/* Accumulated Run Time */ +#define MBX_INDEX_CONSTRAINED_TIME 32/* Thermally Constrained Time Read */ +#define MBX_INDEX_TURBO_RATIO 33/* Turbo Activation Ratio */ +#define MBX_INDEX_DDR_RAPL_PL1 34/* DDR RAPL PL1 */ +#define MBX_INDEX_DDR_PWR_INFO_HIGH 35/* DRAM Power Info Read (high) */ +#define MBX_INDEX_DDR_PWR_INFO_LOW 36/* DRAM Power Info Read (low) */ +#define MBX_INDEX_DDR_RAPL_PL2 37/* DDR RAPL PL2 */ +#define MBX_INDEX_DDR_RAPL_STATUS 38/* DDR RAPL Performance Status */ +#define MBX_INDEX_DDR_HOT_ABSOLUTE 43/* DDR Hottest Dimm Absolute Temp */ +#define MBX_INDEX_DDR_HOT_RELATIVE 44/* DDR Hottest Dimm Relative Temp */ +#define MBX_INDEX_DDR_THROTTLE_TIME 45/* DDR Throttle Time */ +#define MBX_INDEX_DDR_THERM_STATUS 46/* DDR Thermal Status */ +#define MBX_INDEX_TIME_AVG_TEMP 47/* Package time-averaged temperature */ +#define MBX_INDEX_TURBO_RATIO_LIMIT 49/* Turbo Ratio Limit Read */ +#define MBX_INDEX_HWP_AUTO_OOB 53/* HWP Autonomous Out-of-band */ +#define MBX_INDEX_DDR_WARM_BUDGET 55/* DDR Warm Power Budget */ +#define MBX_INDEX_DDR_HOT_BUDGET 56/* DDR Hot Power Budget */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM3 57/* Package/Psys Power Limit3 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM1 58/* Package/Psys Power Limit1 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM2 59/* Package/Psys Power Limit2 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM4 60/* Package/Psys Power Limit4 */ +#define MBX_INDEX_PERF_LIMIT_REASON 65/* Performance Limit Reasons */ + +/* WrPkgConfig Index */ +#define MBX_INDEX_DIMM_AMBIENT 19 +#define MBX_INDEX_DIMM_TEMP 24 + +/* Device Specific Completion Code (CC) Definition */ +#define DEV_PECI_CC_SUCCESS 0x40 +#define DEV_PECI_CC_TIMEOUT 0x80 +#define DEV_PECI_CC_OUT_OF_RESOURCE 0x81 +#define DEV_PECI_CC_UNAVAIL_RESOURCE 0x82 +#define DEV_PECI_CC_INVALID_REQ 0x90 + +/* Completion Code mask to check retry needs */ +#define DEV_PECI_CC_RETRY_CHECK_MASK 0xf0 +#define DEV_PECI_CC_NEED_RETRY 0x80 + +/* Skylake EDS says to retry for 250ms */ +#define DEV_PECI_RETRY_TIME_MS 250 +#define DEV_PECI_RETRY_INTERVAL_USEC 10000 +#define DEV_PECI_RETRY_BIT 0x01 + +#define GET_TEMP_WR_LEN 1 +#define GET_TEMP_RD_LEN 2 +#define GET_TEMP_PECI_CMD 0x01 + +#define GET_DIB_WR_LEN 1 +#define GET_DIB_RD_LEN 8 +#define GET_DIB_PECI_CMD 0xf7 + +#define RDPKGCFG_WRITE_LEN 5 +#define RDPKGCFG_READ_LEN_BASE 1 +#define RDPKGCFG_PECI_CMD 0xa1 + +#define WRPKGCFG_WRITE_LEN_BASE 6 +#define WRPKGCFG_READ_LEN 1 +#define WRPKGCFG_PECI_CMD 0xa5 + +#define RDIAMSR_WRITE_LEN 5 +#define RDIAMSR_READ_LEN 9 +#define RDIAMSR_PECI_CMD 0xb1 + +#define WRIAMSR_PECI_CMD 0xb5 + +#define RDPCICFG_WRITE_LEN 6 +#define RDPCICFG_READ_LEN 5 +#define RDPCICFG_PECI_CMD 0x61
include/uapi/linux/peci-ioctl.h line 137
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+ +#define WRPCICFG_PECI_CMD 0x65 + +#define RDPCICFGLOCAL_WRITE_LEN 5 +#define RDPCICFGLOCAL_READ_LEN_BASE 1 +#define RDPCICFGLOCAL_PECI_CMD 0xe1 + +#define WRPCICFGLOCAL_WRITE_LEN_BASE 6 +#define WRPCICFGLOCAL_READ_LEN 1 +#define WRPCICFGLOCAL_PECI_CMD 0xe5
Alignment?
include/uapi/linux/peci-ioctl.h line 139
Quoted 2 lines
include/uapi/linux/peci-ioctl.h new file +2
-0+ +#define PECI_BUFFER_SIZE 32
Why don't all of these have PECI_ at the front of them?
Quoted 44 lines
include/uapi/linux/peci-ioctl.h new file +44
-0+/** +* enum peci_cmd - PECI client commands +* @PECI_CMD_XFER: raw PECI transfer +* @PECI_CMD_PING: ping, a required message for all PECI devices +* @PECI_CMD_GET_DIB: get DIB (Device Info Byte) +* @PECI_CMD_GET_TEMP: get maximum die temperature +* @PECI_CMD_RD_PKG_CFG: read access to the PCS (Package Configuration Space) +* @PECI_CMD_WR_PKG_CFG: write access to the PCS (Package Configuration Space) +* @PECI_CMD_RD_IA_MSR: read access to MSRs (Model Specific Registers) +* @PECI_CMD_WR_IA_MSR: write access to MSRs (Model Specific Registers) +* @PECI_CMD_RD_PCI_CFG: sideband read access to the PCI configuration space +* maintained in downstream devices external to the processor +* @PECI_CMD_WR_PCI_CFG: sideband write access to the PCI configuration space +* maintained in downstream devices external to the processor +* @PECI_CMD_RD_PCI_CFG_LOCAL: sideband read access to the PCI configuration +* space that resides within the processor +* @PECI_CMD_WR_PCI_CFG_LOCAL: sideband write access to the PCI configuration +* space that resides within the processor +* +* Available commands depend on client's PECI revision. +*/ +enum peci_cmd { +PECI_CMD_XFER =0 , +PECI_CMD_PING , +PECI_CMD_GET_DIB , +PECI_CMD_GET_TEMP , +PECI_CMD_RD_PKG_CFG , +PECI_CMD_WR_PKG_CFG , +PECI_CMD_RD_IA_MSR , +PECI_CMD_WR_IA_MSR , +PECI_CMD_RD_PCI_CFG , +PECI_CMD_WR_PCI_CFG , +PECI_CMD_RD_PCI_CFG_LOCAL , +PECI_CMD_WR_PCI_CFG_LOCAL , +PECI_CMD_MAX +}; + +/** +* struct peci_xfer_msg - raw PECI transfer command +* @addr; address of the client +* @tx_len: number of data to be written in bytes +* @rx_len: number of data to be read in bytes +* @tx_buf: data to be written, or NULL +* @rx_buf: data to be read, or NULL
include/uapi/linux/peci-ioctl.h line 194
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* +* raw PECI transfer +*/ +struct peci_xfer_msg { +__u8 addr; +__u8 tx_len; +__u8 rx_len; +__u8 tx_buf[PECI_BUFFER_SIZE ]; +__u8 rx_buf[PECI_BUFFER_SIZE ]; +} __attribute__((__packed__ ));
Go kick the hardware engineer who did not align things on a 32bit boundry. They should have known better :(
Quoted 17 lines
include/uapi/linux/peci-ioctl.h new file +17
-0+ +/** +* struct peci_ping_msg - ping command +* @addr: address of the client +* +* Ping() is a required message for all PECI devices. This message is used to +* enumerate devices or determine if a device has been removed, been +* powered-off, etc. +*/ +struct peci_ping_msg { +__u8 addr; +} __attribute__((__packed__ )); + +/** +* struct peci_get_dib_msg - GetDIB command +* @addr: address of the client +* @dib: DIB data to be read
include/uapi/linux/peci-ioctl.h line 221
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* +* The processor PECI client implementation of GetDIB() includes an 8-byte +* response and provides information regarding client revision number and the +* number of supported domains. All processor PECI clients support the GetDIB() +* command. +*/ +struct peci_get_dib_msg { +__u8 addr; +__u64 dib; +} __attribute__((__packed__ ));
Ick, really? That's horrible, again, go kick them hard!
Quoted 5 lines
include/uapi/linux/peci-ioctl.h new file +5
-0+/** +* struct peci_get_temp_msg - GetTemp command +* @addr: address of the client +* @temp_raw: raw temperature data to be read +*
include/uapi/linux/peci-ioctl.h line 237
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* The GetTemp() command is used to retrieve the maximum die temperature from a +* target PECI address. The temperature is used by the external thermal +* management system to regulate the temperature on the die. The data is +* returned as a negative value representing the number of degrees centigrade +* below the maximum processor junction temperature. +*/ +struct peci_get_temp_msg { +__u8 addr; +__s16 temp_raw; +} __attribute__((__packed__ ));
{kick kick kick}
Quoted 12 lines
include/uapi/linux/peci-ioctl.h new file +12
-0+ +/** +* struct peci_rd_pkg_cfg_msg - RdPkgConfig command +* @addr: address of the client +* @index: encoding index for the requested service +* @param: specific data being requested +* @rx_len: number of data to be read in bytes +* @pkg_config: package config data to be read +* +* The RdPkgConfig() command provides read access to the Package Configuration +* Space (PCS) within the processor, including various power and thermal +* management functions. Typical PCS read services supported by the processor
include/uapi/linux/peci-ioctl.h line 259
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* may include access to temperature data, energy status, run time information, +* DIMM temperatures and so on. +*/ +struct peci_rd_pkg_cfg_msg { +__u8 addr; +__u8 index; +__u16 param; +__u8 rx_len; +__u8 pkg_config[4 ]; +} __attribute__((__packed__ ));
Ok, that's better, someone finally wisened up.
Quoted 11 lines
include/uapi/linux/peci-ioctl.h new file +11
-0+ +/** +* struct peci_wr_pkg_cfg_msg - WrPkgConfig command +* @addr: address of the client +* @index: encoding index for the requested service +* @param: specific data being requested +* @tx_len: number of data to be written in bytes +* @value: package config data to be written +* +* The WrPkgConfig() command provides write access to the Package Configuration +* Space (PCS) within the processor, including various power and thermal
include/uapi/linux/peci-ioctl.h line 280
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* management functions. Typical PCS write services supported by the processor +* may include power limiting, thermal averaging constant programming and so on. +*/ +struct peci_wr_pkg_cfg_msg { +__u8 addr; +__u8 index; +__u16 param; +__u8 tx_len; +__u32 value; +} __attribute__((__packed__ ));
No they didn't, ick, no one cares about speed here I guess. Oh well :(
Quoted 7 lines
include/uapi/linux/peci-ioctl.h new file +7
-0+ +/** +* struct peci_rd_ia_msr_msg - RdIAMSR command +* @addr: address of the client +* @thread_id: ID of the specific logical processor +* @address: address of MSR to read from +* @value: data to be read
include/uapi/linux/peci-ioctl.h line 297
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* +* The RdIAMSR() PECI command provides read access to Model Specific Registers +* (MSRs) defined in the processor's Intel Architecture (IA). +*/ +struct peci_rd_ia_msr_msg { +__u8 addr; +__u8 thread_id; +__u16 address; +__u64 value; +} __attribute__((__packed__ ));
They got lucky!
oh well,
greg k-h
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Hi Greg,
Thanks for sharing your time on reviewing this patch. Please find my answers below.
Quoted 11 lines · Greg Kroah-Hartman
drivers/peci/Kconfig line 12
Quoted 8 lines · Jae Hyun Yoo
drivers/peci/Kconfig new file +8
-0+config PECI + bool "PECI support" + select RT_MUTEXES + select CRC8 + help + The Platform Environment Control Interface (PECI) is a one-wire bus + interface that provides a communication channel from Intel processors + and chipset components to external monitoring or control devices.Why can't this be built as a module?
This PECI core driver should be prepared ahead of any PECI adapter driver registration which can be called from 'kernel_init' if the adapter driver is built-in. So this driver uses 'postcore_initcall' and it's the reason why it can't be built as a module.
Quoted 1 line
And why do you rely on rt mutexes?
I intended to use that for giving priorities on each PECI sideband function. For an example, Crach Dump sideband function should have a higher priority than Temperature Monitoring sideband function. But, in this initial implementation, it doesn't have any priority adjustment code on the rt mutext yet so I'll remove this config dependency and will replace rt_mutex with mutex for now. It could be replaced back with rt_mutex later when it's actually needed.
Quoted 16 lines
Anyway, the driver core interaction looks good, I have a few other minor comments on the ioctl handling:
Quoted 13 lines
drivers/peci/peci-core.c new file +13
-0+typedef int (*peci_ioctl_fn_type )(struct peci_adapter *,void *); + +static const peci_ioctl_fn_type peci_ioctl_fn[PECI_CMD_MAX ] = { + peci_ioctl_xfer, + peci_ioctl_ping, + peci_ioctl_get_dib, + peci_ioctl_get_temp, + peci_ioctl_rd_pkg_cfg, + peci_ioctl_wr_pkg_cfg, + peci_ioctl_rd_ia_msr, +NULL ,/* Reserved */ + peci_ioctl_rd_pci_cfg, +NULL ,/* Reserved */
Quoted 8 lines
drivers/peci/peci-core.c line 533
Quoted 3 lines
drivers/peci/peci-core.c new file +3
-0+ peci_ioctl_rd_pci_cfg_local, + peci_ioctl_wr_pci_cfg_local, +};That's "interesting", why not have a list that has the ioctl number, and the function pointer? That way no need for "reserved" entries, and you don't have to add a new item to your "is this a valid ioctl" check below:
Yes, that would be nicer. Thanks for your pointing it out. I'll add the ioctl number and the function pointer for the reserved entries so that the handler function can report an error value to indicate that the command is not implemented yet.
Quoted 9 lines
drivers/peci/peci-core.c line 576
Quoted 7 lines
drivers/peci/peci-core.c new file +7
-0+static long peci_ioctl (struct file *file,unsigned int iocmd,unsigned long arg) +{ +struct peci_adapter *adapter = file->private_data; +void __user *argp = (void __user *)arg; +unsigned int msg_len; +enum peci_cmd cmd; +int rc =0 ;No need to set rc here.
You are right. Will fix it.
Quoted 7 lines
drivers/peci/peci-core.c line 580
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+u8 *msg; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ;Really? Nice, you have userspace tools running as root, what could go wrong... :)
I didn't catch your point. Should it be removed?
Quoted 6 lines
drivers/peci/peci-core.c line 582
Quoted 2 lines
drivers/peci/peci-core.c new file +2
-0+ +dev_dbg (&adapter->dev,"ioctl, cmd=0x%x, arg=0x%lx\n" , iocmd, arg);I understand the need for this type of thing when debugging the code initially, but you can remove them all now, ftrace should provide what you need now, right?
Right, this was just for early stage debugging. Will remove it.
Quoted 10 lines
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ +switch (iocmd) { +case PECI_IOC_XFER : +case PECI_IOC_PING : +case PECI_IOC_GET_DIB : +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 :
Quoted 8 lines
drivers/peci/peci-core.c line 597
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+case PECI_IOC_RD_PCI_CFG_LOCAL : +case PECI_IOC_WR_PCI_CFG_LOCAL : + cmd =_IOC_NR (iocmd); + msg_len =_IOC_SIZE (iocmd); +break ;That check up there can be replaced with an iteration over the list of ioctl functions, right?
Right. I'll simplify it.
Quoted 8 lines
Quoted 8 lines
drivers/peci/peci-core.c new file +8
-0+ +default : +dev_dbg (&adapter->dev,"Invalid ioctl cmd : 0x%x\n" , iocmd); +return -ENOTTY ; + } + +if (!access_ok (argp, msg_len)) +return -EFAULT ;
Quoted 8 lines
drivers/peci/peci-core.c line 609
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+ + msg =memdup_user (argp, msg_len); +if (IS_ERR (msg)) +return PTR_ERR (msg);Why call
access_ok()if you are going to copy the memory anyways?memdup_usershould fail with-EFAULTif you can't copy the memory properly.
I see. I'll remove the access_ok().
Quoted 6 lines
drivers/peci/peci-core.c line 611
Quoted 2 lines
drivers/peci/peci-core.c new file +2
-0+ + rc =peci_command (adapter, cmd, msg);Are you _SURE_ you audited your ioctls to not do foolish things with userspace values? I sure didn't, so can you please have someone else do this and sign off on this patch that they did so?
No I didn't. I'll ask someone to do ioctl io audit on this patch and adding a signed off tag too.
Quoted 8 lines
drivers/peci/peci-core.c line 655
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+static int peci_detect (struct peci_adapter *adapter,u8 addr) +{ +struct peci_ping_msg msg; + + msg.addr = addr;What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
It's fully initialized at here because the peci_ping_msg struct has only one member:
struct peci_ping_msg {
__u8 addr;
};Quoted 20 lines
Quoted 20 lines
drivers/peci/peci-core.c new file +20
-0+static ssize_t peci_sysfs_new_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_board_info info = {}; +struct peci_client *client; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"new_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"new_device" ); +return -EINVAL ; + }
Quoted 8 lines
drivers/peci/peci-core.c line 946
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end);Please do not tell me you are parsing a sysfs write to do some type of new configuration. That is not what sysfs is for, that is what configfs is for, please use that instead, this isn't ok.
This is for run-time registration of a PECI client which is connected to a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
Quoted 13 lines
Quoted 13 lines
drivers/peci/peci-core.c new file +13
-0+if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" ,"new_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"new_device" ); +return -EINVAL ; + } + + client =peci_new_device (adapter, &info); +if (!client) +return -EINVAL ; +
Quoted 8 lines
drivers/peci/peci-core.c line 965
Quoted 6 lines
drivers/peci/peci-core.c new file +6
-0+/* Keep track of the added device */ +mutex_lock (&adapter->userspace_clients_lock); +list_add_tail (&client->detected, &adapter->userspace_clients); +mutex_unlock (&adapter->userspace_clients_lock); +dev_info (dev,"%s: Instantiated device %s at 0x%02hx\n" ,"new_device" , + info.type, info.addr);Don't be noisy for things that are expected to happen.
I think it should print out a result on a userspace request for client module registration.
Quoted 7 lines
drivers/peci/peci-core.c line 969
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+ +return count; +} +static DEVICE_ATTR(new_device, 0200, NULL, peci_sysfs_new_device);Not that you should be doing this, but
DEVICE_ATTR_RO()is what you want here, right?
Actually, DEVICE_ATTR_WO() is what I can use here. The reason why I used DEVICE_ATTR() is for keeping the function naming pattern as 'peci_sysfs_new_device()' instead of 'new_device_store()'.
Quoted 30 lines
Quoted 30 lines
drivers/peci/peci-core.c new file +30
-0+ +static ssize_t peci_sysfs_delete_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_client *client, *next; +struct peci_board_info info = {}; +struct peci_driver *driver; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"delete_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"delete_device" ); +return -EINVAL ; + } +memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end); +if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" , +"delete_device" ); +return -EINVAL ;
Quoted 8 lines
drivers/peci/peci-core.c line 1004
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"delete_device" ); +return -EINVAL ; + }Same here, no parsing of configurations through sysfs, that is not ok. Again, use configfs.
Same as above. This is for run-time deregistration of a PECI client which is registered on a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
Quoted 18 lines
Quoted 18 lines
drivers/peci/peci-core.c new file +18
-0+ +/* Make sure the device was added through sysfs */ + rc = -ENOENT ; +mutex_lock (&adapter->userspace_clients_lock); +list_for_each_entry_safe (client, next, &adapter->userspace_clients, + detected) { + driver =to_peci_driver (client->dev.driver); + +if (client->addr == info.addr && + !strncmp (client->name, info.type,PECI_NAME_SIZE )) { +dev_info (dev,"%s: Deleting device %s at 0x%02hx\n" , +"delete_device" , client->name, client->addr); +list_del (&client->detected); +peci_unregister_device (client); + rc = count; +break ; + } + }
Quoted 8 lines
drivers/peci/peci-core.c line 1027
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+mutex_unlock (&adapter->userspace_clients_lock); + +if (rc <0 ) +dev_err (dev,"%s: Can't find device in list\n" , +"delete_device" );So you can just spam the syslog by writing odd values to the file? Not good.
Okay. I'll remove this printing out.
Quoted 8 lines
drivers/peci/peci-core.c line 1032
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ +return rc; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + peci_sysfs_delete_device);sysfs files that remove themselves are reserved for a specific circle in hell, you really don't want to mess with them :(
It cannot remove itself. The owner of the sysfs files is an adapter driver and only client devices can be added/removed by these sysfs files. An adapter can't be removed by accessing of this sysfs.
Quoted 25 lines
Quoted 11 lines
include/linux/peci.h new file +11
-0+/** +* struct peci_adapter - represent a PECI adapter +* @owner: owner module of the PECI adpater +* @bus_lock: mutex for exclusion of multiple callers +* @dev: device interface to this driver +* @cdev: character device object to create character device +* @nr: the bus number to map +* @name: name of the adapter +* @userspace_clients_lock: mutex for exclusion of clients handling +* @userspace_clients: list of registered clients +* @xfer: low-level transfer function pointer of the adapter include/linux/peci.h line 40
Quoted 10 lines
include/linux/peci.h new file +10
-0+* @cmd_mask: mask for supportable PECI commands +* +* Each PECI adapter can communicate with one or more PECI client children. +* These make a small bus, sharing a single wired PECI connection. +*/ +struct peci_adapter { +struct module *owner; +struct rt_mutex bus_lock; +struct device dev; +struct cdev cdev;Yeah, two differently reference counted variables in the same structure, what could go wrong! :(
Quoted 6 lines
Don't do this, make your cdev a pointer to be sure you get things right, otherwise this will never work properly.
And shouldn't the character device be a class device? Don't confuse devices in the driver model with the interaction of them to userspace in a specific manner, those should be separate things, right?
Okay, I got your point. I'll split out the character device part as a separated module and will make the module can be attached to a PECI bus.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ int nr; + char name[PECI_NAME_SIZE];What's wrong with the name in struct device?
The name in struct device is used for indicating generic PECI bus topology like below example:
Adapter devices: 'peci-0' where 0 means bus number.
Client devices: '0-30' where 0 means bus number, 30 means hexadecimal
address of the client device.
These devices can be found in /sys/bus/peci/devices folder.
The name at here will contain a name which is assigned by adapter driver. In case of Aspeed PECI adapter driver in this series, it shows '1e78b000.peci-bus'.
Quoted 7 lines
include/linux/peci.h line 47
Quoted 5 lines
include/linux/peci.h new file +5
-0+struct mutex userspace_clients_lock;/* clients list mutex */ +struct list_head userspace_clients; +int (*xfer)(struct peci_adapter *adapter, +struct peci_xfer_msg *msg); +uint cmd_mask;u32?
Yes. Will fix it.
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/peci-ioctl.h new file +9
-0@@ -0,0 +1,403 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2018-2019 Intel Corporation */ + +#ifndef __PECI_IOCTL_H +#define __PECI_IOCTL_H + +#include <linux/ioctl.h> +#include <linux/types.h> +
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 15
Quoted 6 lines
include/uapi/linux/peci-ioctl.h new file +6
-0+/* 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 */ +#define MAX_PCI_READ_LEN 24/* Number of bytes of the PCI Space read */ PCI? Or PECI? I'm confused now, what does PCI have to do with PECI?
It defines a constant for the PCI configuration space access through a PECI bus. I'll add 'PECI_' at the front.
Quoted 11 lines
include/uapi/linux/peci-ioctl.h line 24
Quoted 9 lines
include/uapi/linux/peci-ioctl.h new file +9
-0+ +#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 0xd4You just abused the PCI core namespace here, are you sure about that?
I'll add 'PECI_' at the front of them.
Quoted 107 lines
Quoted 107 lines
include/uapi/linux/peci-ioctl.h new file +107
-0+ +/* Package Identifier Read Parameter Value */ +#define PKG_ID_CPU_ID 0x0000/* CPUID Info */ +#define PKG_ID_PLATFORM_ID 0x0001/* Platform ID */ +#define PKG_ID_UNCORE_ID 0x0002/* Uncore Device ID */ +#define PKG_ID_MAX_THREAD_ID 0x0003/* Max Thread ID */ +#define PKG_ID_MICROCODE_REV 0x0004/* CPU Microcode Update Revision */ +#define PKG_ID_MACHINE_CHECK_STATUS 0x0005/* 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 */ +#define MBX_INDEX_PKG_RAPL_PERF 8/* Pkg RAPL Performance Status Read */ +#define MBX_INDEX_PER_CORE_DTS_TEMP 9/* Per Core DTS Temperature Read */ +#define MBX_INDEX_DTS_MARGIN 10/* DTS thermal margin */ +#define MBX_INDEX_SKT_PWR_THRTL_DUR 11/* Socket Power Throttled Duration */ +#define MBX_INDEX_CFG_TDP_CONTROL 12/* TDP Config Control */ +#define MBX_INDEX_CFG_TDP_LEVELS 13/* TDP Config Levels */ +#define MBX_INDEX_DDR_DIMM_TEMP 14/* DDR DIMM Temperature */ +#define MBX_INDEX_CFG_ICCMAX 15/* Configurable ICCMAX */ +#define MBX_INDEX_TEMP_TARGET 16/* Temperature Target Read */ +#define MBX_INDEX_CURR_CFG_LIMIT 17/* Current Config Limit */ +#define MBX_INDEX_DIMM_TEMP_READ 20/* Package Thermal Status Read */ +#define MBX_INDEX_DRAM_IMC_TMP_READ 22/* DRAM IMC Temperature Read */ +#define MBX_INDEX_DDR_CH_THERM_STAT 23/* DDR Channel Thermal Status */ +#define MBX_INDEX_PKG_POWER_LIMIT1 26/* Package Power Limit1 */ +#define MBX_INDEX_PKG_POWER_LIMIT2 27/* Package Power Limit2 */ +#define MBX_INDEX_TDP 28/* Thermal design power minimum */ +#define MBX_INDEX_TDP_HIGH 29/* Thermal design power maximum */ +#define MBX_INDEX_TDP_UNITS 30/* Units for power/energy registers */ +#define MBX_INDEX_RUN_TIME 31/* Accumulated Run Time */ +#define MBX_INDEX_CONSTRAINED_TIME 32/* Thermally Constrained Time Read */ +#define MBX_INDEX_TURBO_RATIO 33/* Turbo Activation Ratio */ +#define MBX_INDEX_DDR_RAPL_PL1 34/* DDR RAPL PL1 */ +#define MBX_INDEX_DDR_PWR_INFO_HIGH 35/* DRAM Power Info Read (high) */ +#define MBX_INDEX_DDR_PWR_INFO_LOW 36/* DRAM Power Info Read (low) */ +#define MBX_INDEX_DDR_RAPL_PL2 37/* DDR RAPL PL2 */ +#define MBX_INDEX_DDR_RAPL_STATUS 38/* DDR RAPL Performance Status */ +#define MBX_INDEX_DDR_HOT_ABSOLUTE 43/* DDR Hottest Dimm Absolute Temp */ +#define MBX_INDEX_DDR_HOT_RELATIVE 44/* DDR Hottest Dimm Relative Temp */ +#define MBX_INDEX_DDR_THROTTLE_TIME 45/* DDR Throttle Time */ +#define MBX_INDEX_DDR_THERM_STATUS 46/* DDR Thermal Status */ +#define MBX_INDEX_TIME_AVG_TEMP 47/* Package time-averaged temperature */ +#define MBX_INDEX_TURBO_RATIO_LIMIT 49/* Turbo Ratio Limit Read */ +#define MBX_INDEX_HWP_AUTO_OOB 53/* HWP Autonomous Out-of-band */ +#define MBX_INDEX_DDR_WARM_BUDGET 55/* DDR Warm Power Budget */ +#define MBX_INDEX_DDR_HOT_BUDGET 56/* DDR Hot Power Budget */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM3 57/* Package/Psys Power Limit3 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM1 58/* Package/Psys Power Limit1 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM2 59/* Package/Psys Power Limit2 */ +#define MBX_INDEX_PKG_PSYS_PWR_LIM4 60/* Package/Psys Power Limit4 */ +#define MBX_INDEX_PERF_LIMIT_REASON 65/* Performance Limit Reasons */ + +/* WrPkgConfig Index */ +#define MBX_INDEX_DIMM_AMBIENT 19 +#define MBX_INDEX_DIMM_TEMP 24 + +/* Device Specific Completion Code (CC) Definition */ +#define DEV_PECI_CC_SUCCESS 0x40 +#define DEV_PECI_CC_TIMEOUT 0x80 +#define DEV_PECI_CC_OUT_OF_RESOURCE 0x81 +#define DEV_PECI_CC_UNAVAIL_RESOURCE 0x82 +#define DEV_PECI_CC_INVALID_REQ 0x90 + +/* Completion Code mask to check retry needs */ +#define DEV_PECI_CC_RETRY_CHECK_MASK 0xf0 +#define DEV_PECI_CC_NEED_RETRY 0x80 + +/* Skylake EDS says to retry for 250ms */ +#define DEV_PECI_RETRY_TIME_MS 250 +#define DEV_PECI_RETRY_INTERVAL_USEC 10000 +#define DEV_PECI_RETRY_BIT 0x01 + +#define GET_TEMP_WR_LEN 1 +#define GET_TEMP_RD_LEN 2 +#define GET_TEMP_PECI_CMD 0x01 + +#define GET_DIB_WR_LEN 1 +#define GET_DIB_RD_LEN 8 +#define GET_DIB_PECI_CMD 0xf7 + +#define RDPKGCFG_WRITE_LEN 5 +#define RDPKGCFG_READ_LEN_BASE 1 +#define RDPKGCFG_PECI_CMD 0xa1 + +#define WRPKGCFG_WRITE_LEN_BASE 6 +#define WRPKGCFG_READ_LEN 1 +#define WRPKGCFG_PECI_CMD 0xa5 + +#define RDIAMSR_WRITE_LEN 5 +#define RDIAMSR_READ_LEN 9 +#define RDIAMSR_PECI_CMD 0xb1 + +#define WRIAMSR_PECI_CMD 0xb5 + +#define RDPCICFG_WRITE_LEN 6 +#define RDPCICFG_READ_LEN 5 +#define RDPCICFG_PECI_CMD 0x61 + +#define WRPCICFG_PECI_CMD 0x65 + +#define RDPCICFGLOCAL_WRITE_LEN 5
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 137
Quoted 6 lines
include/uapi/linux/peci-ioctl.h new file +6
-0+#define RDPCICFGLOCAL_READ_LEN_BASE 1 +#define RDPCICFGLOCAL_PECI_CMD 0xe1 + +#define WRPCICFGLOCAL_WRITE_LEN_BASE 6 +#define WRPCICFGLOCAL_READ_LEN 1 +#define WRPCICFGLOCAL_PECI_CMD 0xe5Alignment?
Will fix it.
Quoted 4 lines
include/uapi/linux/peci-ioctl.h line 139
Quoted 2 lines
include/uapi/linux/peci-ioctl.h new file +2
-0+ +#define PECI_BUFFER_SIZE 32Why don't all of these have
PECI_at the front of them?
Okay. I'll add 'PECI_' for all of these.
Quoted 49 lines
Quoted 49 lines
include/uapi/linux/peci-ioctl.h new file +49
-0+/** +* enum peci_cmd - PECI client commands +* @PECI_CMD_XFER: raw PECI transfer +* @PECI_CMD_PING: ping, a required message for all PECI devices +* @PECI_CMD_GET_DIB: get DIB (Device Info Byte) +* @PECI_CMD_GET_TEMP: get maximum die temperature +* @PECI_CMD_RD_PKG_CFG: read access to the PCS (Package Configuration Space) +* @PECI_CMD_WR_PKG_CFG: write access to the PCS (Package Configuration Space) +* @PECI_CMD_RD_IA_MSR: read access to MSRs (Model Specific Registers) +* @PECI_CMD_WR_IA_MSR: write access to MSRs (Model Specific Registers) +* @PECI_CMD_RD_PCI_CFG: sideband read access to the PCI configuration space +* maintained in downstream devices external to the processor +* @PECI_CMD_WR_PCI_CFG: sideband write access to the PCI configuration space +* maintained in downstream devices external to the processor +* @PECI_CMD_RD_PCI_CFG_LOCAL: sideband read access to the PCI configuration +* space that resides within the processor +* @PECI_CMD_WR_PCI_CFG_LOCAL: sideband write access to the PCI configuration +* space that resides within the processor +* +* Available commands depend on client's PECI revision. +*/ +enum peci_cmd { +PECI_CMD_XFER =0 , +PECI_CMD_PING , +PECI_CMD_GET_DIB , +PECI_CMD_GET_TEMP , +PECI_CMD_RD_PKG_CFG , +PECI_CMD_WR_PKG_CFG , +PECI_CMD_RD_IA_MSR , +PECI_CMD_WR_IA_MSR , +PECI_CMD_RD_PCI_CFG , +PECI_CMD_WR_PCI_CFG , +PECI_CMD_RD_PCI_CFG_LOCAL , +PECI_CMD_WR_PCI_CFG_LOCAL , +PECI_CMD_MAX +}; + +/** +* struct peci_xfer_msg - raw PECI transfer command +* @addr; address of the client +* @tx_len: number of data to be written in bytes +* @rx_len: number of data to be read in bytes +* @tx_buf: data to be written, or NULL +* @rx_buf: data to be read, or NULL +* +* raw PECI transfer +*/ +struct peci_xfer_msg { +__u8 addr;
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 194
Quoted 5 lines
include/uapi/linux/peci-ioctl.h new file +5
-0+__u8 tx_len; +__u8 rx_len; +__u8 tx_buf[PECI_BUFFER_SIZE ]; +__u8 rx_buf[PECI_BUFFER_SIZE ]; +} __attribute__((__packed__));Go kick the hardware engineer who did not align things on a 32bit boundry. They should have known better :(
I intended to make it as contiguous byte sequence in this order because some PECI commands need to caclulate CRC8 checksum using this as a byte array. I'll align these on a 32bit boundary and will use a temporary buffer instead while calcuating a CRC8 checksum.
Quoted 21 lines
Quoted 21 lines
include/uapi/linux/peci-ioctl.h new file +21
-0+ +/** +* struct peci_ping_msg - ping command +* @addr: address of the client +* +* Ping() is a required message for all PECI devices. This message is used to +* enumerate devices or determine if a device has been removed, been +* powered-off, etc. +*/ +struct peci_ping_msg { +__u8 addr; +} __attribute__((__packed__ )); + +/** +* struct peci_get_dib_msg - GetDIB command +* @addr: address of the client +* @dib: DIB data to be read +* +* The processor PECI client implementation of GetDIB() includes an 8-byte +* response and provides information regarding client revision number and the +* number of supported domains. All processor PECI clients support the GetDIB()
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 221
Quoted 6 lines
include/uapi/linux/peci-ioctl.h new file +6
-0+* command. +*/ +struct peci_get_dib_msg { +__u8 addr; +__u64 dib; +} __attribute__((__packed__ ));Ick, really? That's horrible, again, go kick them hard!
Okay, I kicked hard myself. Will align it.
Quoted 9 lines
Quoted 9 lines
include/uapi/linux/peci-ioctl.h new file +9
-0+/** +* struct peci_get_temp_msg - GetTemp command +* @addr: address of the client +* @temp_raw: raw temperature data to be read +* +* The GetTemp() command is used to retrieve the maximum die temperature from a +* target PECI address. The temperature is used by the external thermal +* management system to regulate the temperature on the die. The data is +* returned as a negative value representing the number of degrees centigrade
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 237
Quoted 6 lines
include/uapi/linux/peci-ioctl.h new file +6
-0+* below the maximum processor junction temperature. +*/ +struct peci_get_temp_msg { +__u8 addr; +__s16 temp_raw; +} __attribute__((__packed__ ));{kick kick kick}
Will fix it too.
Quoted 40 lines
Quoted 12 lines
include/uapi/linux/peci-ioctl.h new file +12
-0+ +/** +* struct peci_rd_pkg_cfg_msg - RdPkgConfig command +* @addr: address of the client +* @index: encoding index for the requested service +* @param: specific data being requested +* @rx_len: number of data to be read in bytes +* @pkg_config: package config data to be read +* +* The RdPkgConfig() command provides read access to the Package Configuration +* Space (PCS) within the processor, including various power and thermal +* management functions. Typical PCS read services supported by the processor include/uapi/linux/peci-ioctl.h line 259
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* may include access to temperature data, energy status, run time information, +* DIMM temperatures and so on. +*/ +struct peci_rd_pkg_cfg_msg { +__u8 addr; +__u8 index; +__u16 param; +__u8 rx_len; +__u8 pkg_config[4 ]; +} __attribute__((__packed__ ));Ok, that's better, someone finally wisened up.
Quoted 15 lines
include/uapi/linux/peci-ioctl.h new file +15
-0+ +/** +* struct peci_wr_pkg_cfg_msg - WrPkgConfig command +* @addr: address of the client +* @index: encoding index for the requested service +* @param: specific data being requested +* @tx_len: number of data to be written in bytes +* @value: package config data to be written +* +* The WrPkgConfig() command provides write access to the Package Configuration +* Space (PCS) within the processor, including various power and thermal +* management functions. Typical PCS write services supported by the processor +* may include power limiting, thermal averaging constant programming and so on. +*/ +struct peci_wr_pkg_cfg_msg {
Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 280
Quoted 6 lines
include/uapi/linux/peci-ioctl.h new file +6
-0+__u8 addr; +__u8 index; +__u16 param; +__u8 tx_len; +__u32 value; +} __attribute__((__packed__));No they didn't, ick, no one cares about speed here I guess. Oh well :(
Will fix it too.
Quoted 20 lines
Quoted 7 lines
include/uapi/linux/peci-ioctl.h new file +7
-0+ +/** +* struct peci_rd_ia_msr_msg - RdIAMSR command +* @addr: address of the client +* @thread_id: ID of the specific logical processor +* @address: address of MSR to read from +* @value: data to be read include/uapi/linux/peci-ioctl.h line 297
Quoted 10 lines
include/uapi/linux/peci-ioctl.h new file +10
-0+* +* The RdIAMSR() PECI command provides read access to Model Specific Registers +* (MSRs) defined in the processor's Intel Architecture (IA). +*/ +struct peci_rd_ia_msr_msg { +__u8 addr; +__u8 thread_id; +__u16 address; +__u64 value; +} __attribute__((__packed__ ));They got lucky!
Quoted 4 lines
oh well,
greg k-h
Thanks again for your comments. I'll submit a new version after addressing your comments.
Regards,
Jae
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Quoted 18 lines · Jae Hyun Yoo
Hi Greg,
Thanks for sharing your time on reviewing this patch. Please find my answers below.
Quoted 11 lines · Greg Kroah-Hartman
drivers/peci/Kconfig line 12
Quoted 8 lines · Jae Hyun Yoo
drivers/peci/Kconfig new file +8
-0+config PECI + bool "PECI support" + select RT_MUTEXES + select CRC8 + help + The Platform Environment Control Interface (PECI) is a one-wire bus + interface that provides a communication channel from Intel processors + and chipset components to external monitoring or control devices.Why can't this be built as a module?
Quoted 4 lines
This PECI core driver should be prepared ahead of any PECI adapter driver registration which can be called from '
kernel_init' if the adapter driver is built-in. So this driver uses 'postcore_initcall' and it's the reason why it can't be built as a module.
Then set up your dependancies correctly. As an example, you can have the USB core as a module, and you are not allowed to have USB drivers built into the kernel. It's not difficult to do this. Please make your core also be a module so that you do not burden the zillions of machines out there with code that they do not need, just because you forced the distro to choose "Y" or "N".
Quoted 9 lines
Quoted 1 line
And why do you rely on rt mutexes?
I intended to use that for giving priorities on each PECI sideband function. For an example, Crach Dump sideband function should have a higher priority than Temperature Monitoring sideband function. But, in this initial implementation, it doesn't have any priority adjustment code on the rt mutext yet so I'll remove this config dependency and will replace
rt_mutexwith mutex for now. It could be replaced back withrt_mutexlater when it's actually needed.
thank you.
Quoted 9 lines
Quoted 7 lines
drivers/peci/peci-core.c line 580
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+u8 *msg; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ;Really? Nice, you have userspace tools running as root, what could go wrong... :)
I didn't catch your point. Should it be removed?
You are forcing your userspace tools to have CAP_SYS_ADMIN in order to talk to your device. Why? What is wrong with the file permissions on the device node instead? Why can't userspace decide what user should be able to talk to your device?
Don't require special permissions for no good reason. This forces whatever userspace tool that handles this, to have enough permission to do anything it wants in the system. And I do not think you want that.
Quoted 9 lines
Quoted 8 lines
drivers/peci/peci-core.c line 655
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+static int peci_detect (struct peci_adapter *adapter,u8 addr) +{ +struct peci_ping_msg msg; + + msg.addr = addr;What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
Quoted 6 lines
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };
Ok. But my question about "can you do this off the stack" remains.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/peci/peci-core.c new file +20
-0+static ssize_t peci_sysfs_new_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_board_info info = {}; +struct peci_client *client; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"new_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"new_device" ); +return -EINVAL ; + }Quoted 8 lines
drivers/peci/peci-core.c line 946
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end);Please do not tell me you are parsing a sysfs write to do some type of new configuration. That is not what sysfs is for, that is what configfs is for, please use that instead, this isn't ok.
Quoted 4 lines
This is for run-time registration of a PECI client which is connected to a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
What i2c core driver parses configuration options in sysfs?
Ugh, I see that now. That's horrible. Please do not emulate that at all.
Again, use configfs, that is what it is there for, do not spread bad interfaces to new places in the kernel.
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/peci/peci-core.c new file +13
-0+if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" ,"new_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"new_device" ); +return -EINVAL ; + } + + client =peci_new_device (adapter, &info); +if (!client) +return -EINVAL ; +Quoted 8 lines
drivers/peci/peci-core.c line 965
Quoted 6 lines
drivers/peci/peci-core.c new file +6
-0+/* Keep track of the added device */ +mutex_lock (&adapter->userspace_clients_lock); +list_add_tail (&client->detected, &adapter->userspace_clients); +mutex_unlock (&adapter->userspace_clients_lock); +dev_info (dev,"%s: Instantiated device %s at 0x%02hx\n" ,"new_device" , + info.type, info.addr);Don't be noisy for things that are expected to happen.
Quoted 2 lines
I think it should print out a result on a userspace request for client module registration.
Why? Who is going to do anything with this? Userspace "knows" it worked because their function call returned success. It is not going to then parse a kernel log.
Quoted 11 lines
Quoted 7 lines
drivers/peci/peci-core.c line 969
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+ +return count; +} +static DEVICE_ATTR(new_device, 0200, NULL, peci_sysfs_new_device);Not that you should be doing this, but
DEVICE_ATTR_RO()is what you want here, right?Actually,
DEVICE_ATTR_WO()is what I can use here. The reason why I usedDEVICE_ATTR()is for keeping the function naming pattern as 'peci_sysfs_new_device()' instead of 'new_device_store()'.
Sorry, yes, WO is what you want. But anyway, this should be in configfs, not sysfs.
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
drivers/peci/peci-core.c new file +29
-0+static ssize_t peci_sysfs_delete_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_client *client, *next; +struct peci_board_info info = {}; +struct peci_driver *driver; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"delete_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"delete_device" ); +return -EINVAL ; + } +memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end); +if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" , +"delete_device" ); +return -EINVAL ;Quoted 8 lines
drivers/peci/peci-core.c line 1004
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"delete_device" ); +return -EINVAL ; + }Same here, no parsing of configurations through sysfs, that is not ok. Again, use configfs.
Quoted 4 lines
Same as above. This is for run-time deregistration of a PECI client which is registered on a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
Again, do not copy previous mistakes please.
Quoted 9 lines
Quoted 8 lines
drivers/peci/peci-core.c line 1032
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ +return rc; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + peci_sysfs_delete_device);sysfs files that remove themselves are reserved for a specific circle in hell, you really don't want to mess with them :(
Quoted 3 lines
It cannot remove itself. The owner of the sysfs files is an adapter driver and only client devices can be added/removed by these sysfs files. An adapter can't be removed by accessing of this sysfs.
They why the LOCKDEP notation?
Quoted 28 lines
Quoted 28 lines
Quoted 11 lines
include/linux/peci.h new file +11
-0+/** +* struct peci_adapter - represent a PECI adapter +* @owner: owner module of the PECI adpater +* @bus_lock: mutex for exclusion of multiple callers +* @dev: device interface to this driver +* @cdev: character device object to create character device +* @nr: the bus number to map +* @name: name of the adapter +* @userspace_clients_lock: mutex for exclusion of clients handling +* @userspace_clients: list of registered clients +* @xfer: low-level transfer function pointer of the adapter include/linux/peci.h line 40
Quoted 10 lines
include/linux/peci.h new file +10
-0+* @cmd_mask: mask for supportable PECI commands +* +* Each PECI adapter can communicate with one or more PECI client children. +* These make a small bus, sharing a single wired PECI connection. +*/ +struct peci_adapter { +struct module *owner; +struct rt_mutex bus_lock; +struct device dev; +struct cdev cdev;Yeah, two differently reference counted variables in the same structure, what could go wrong! :(
Don't do this, make your cdev a pointer to be sure you get things right, otherwise this will never work properly.
Quoted 7 lines
Quoted 3 lines
And shouldn't the character device be a class device? Don't confuse devices in the driver model with the interaction of them to userspace in a specific manner, those should be separate things, right?
Okay, I got your point. I'll split out the character device part as a separated module and will make the module can be attached to a PECI bus.
I'm not saying it has to be a whole separate module, at the least it needs to be a new structure. As it is, your code is not correct due to the dual-structures-trying-to-fight-it-out-for-lifecycle-rules
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/peci-ioctl.h new file +12
-0+/** +* struct peci_xfer_msg - raw PECI transfer command +* @addr; address of the client +* @tx_len: number of data to be written in bytes +* @rx_len: number of data to be read in bytes +* @tx_buf: data to be written, or NULL +* @rx_buf: data to be read, or NULL +* +* raw PECI transfer +*/ +struct peci_xfer_msg { +__u8 addr;Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 194
Quoted 5 lines
include/uapi/linux/peci-ioctl.h new file +5
-0+__u8 tx_len; +__u8 rx_len; +__u8 tx_buf[PECI_BUFFER_SIZE ]; +__u8 rx_buf[PECI_BUFFER_SIZE ]; +} __attribute__((__packed__));Go kick the hardware engineer who did not align things on a 32bit boundry. They should have known better :(
Quoted 4 lines
I intended to make it as contiguous byte sequence in this order because some PECI commands need to caclulate CRC8 checksum using this as a byte array. I'll align these on a 32bit boundary and will use a temporary buffer instead while calcuating a CRC8 checksum.
If this really is the way the structure needs to be on the wire, that's fine, it's just a complaint about the protocol and how bad accessing those fields are going to suck for some processors.
But if you can get away with not doing it like this, that would be nice.
thanks,
greg k-h
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Hi Greg,
Quoted 24 lines · Greg Kroah-Hartman
Quoted 18 lines · Jae Hyun Yoo
Hi Greg,
Thanks for sharing your time on reviewing this patch. Please find my answers below.
Quoted 11 lines · Greg Kroah-Hartman
drivers/peci/Kconfig line 12
Quoted 8 lines · Jae Hyun Yoo
drivers/peci/Kconfig new file +8
-0+config PECI + bool "PECI support" + select RT_MUTEXES + select CRC8 + help + The Platform Environment Control Interface (PECI) is a one-wire bus + interface that provides a communication channel from Intel processors + and chipset components to external monitoring or control devices.Why can't this be built as a module?
Quoted 4 lines
This PECI core driver should be prepared ahead of any PECI adapter driver registration which can be called from '
kernel_init' if the adapter driver is built-in. So this driver uses 'postcore_initcall' and it's the reason why it can't be built as a module.
Quoted 6 lines
Then set up your dependancies correctly. As an example, you can have the USB core as a module, and you are not allowed to have USB drivers built into the kernel. It's not difficult to do this. Please make your core also be a module so that you do not burden the zillions of machines out there with code that they do not need, just because you forced the distro to choose "Y" or "N".
Okay. I'll make this core config as a tristate.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
drivers/peci/peci-core.c line 580
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+u8 *msg; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ;Really? Nice, you have userspace tools running as root, what could go wrong... :)
I didn't catch your point. Should it be removed?
Quoted 8 lines
You are forcing your userspace tools to have
CAP_SYS_ADMINin order to talk to your device. Why? What is wrong with the file permissions on the device node instead? Why can't userspace decide what user should be able to talk to your device?Don't require special permissions for no good reason. This forces whatever userspace tool that handles this, to have enough permission to do anything it wants in the system. And I do not think you want that.
Okay, I got your point now. Thank you. I'll remove this permission check from here.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/peci/peci-core.c line 655
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+static int peci_detect (struct peci_adapter *adapter,u8 addr) +{ +struct peci_ping_msg msg; + + msg.addr = addr;What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
Quoted 8 lines
Quoted 6 lines
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };Ok. But my question about "can you do this off the stack" remains.
I'll add 3 bytes of dummy padding into this structure. Also, I'll check again u32 boundary alignment for all struct defines in peci_ioctl.h. Would it be okay to be on stack then?
Quoted 34 lines
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/peci/peci-core.c new file +20
-0+static ssize_t peci_sysfs_new_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_board_info info = {}; +struct peci_client *client; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"new_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"new_device" ); +return -EINVAL ; + }Quoted 8 lines
drivers/peci/peci-core.c line 946
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ + rc =sscanf (++blank,"%hi%c" , &info.addr, &end);Please do not tell me you are parsing a sysfs write to do some type of new configuration. That is not what sysfs is for, that is what configfs is for, please use that instead, this isn't ok.
Quoted 4 lines
This is for run-time registration of a PECI client which is connected to a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
Quoted 7 lines
What i2c core driver parses configuration options in sysfs?
Ugh, I see that now. That's horrible. Please do not emulate that at all.
Again, use configfs, that is what it is there for, do not spread bad interfaces to new places in the kernel.
Okay, I see. I'll rewrite this interface using configfs. Thanks!
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
drivers/peci/peci-core.c new file +9
-0+if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" ,"new_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"new_device" ); +return -EINVAL ; + } +drivers/peci/peci-core.c line 965
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ client =peci_new_device (adapter, &info); +if (!client) +return -EINVAL ; + +/* Keep track of the added device */ +mutex_lock (&adapter->userspace_clients_lock); +list_add_tail (&client->detected, &adapter->userspace_clients); +mutex_unlock (&adapter->userspace_clients_lock); +dev_info (dev,"%s: Instantiated device %s at 0x%02hx\n" ,"new_device" , + info.type, info.addr);Don't be noisy for things that are expected to happen.
Quoted 6 lines
Quoted 2 lines
I think it should print out a result on a userspace request for client module registration.
Why? Who is going to do anything with this? Userspace "knows" it worked because their function call returned success. It is not going to then parse a kernel log.
Agree. Will change it to dev_dbg().
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/peci/peci-core.c line 969
Quoted 4 lines
drivers/peci/peci-core.c new file +4
-0+ +return count; +} +static DEVICE_ATTR(new_device, 0200, NULL, peci_sysfs_new_device);Not that you should be doing this, but
DEVICE_ATTR_RO()is what you want here, right?
Quoted 6 lines
Quoted 3 lines
Actually,
DEVICE_ATTR_WO()is what I can use here. The reason why I usedDEVICE_ATTR()is for keeping the function naming pattern as 'peci_sysfs_new_device()' instead of 'new_device_store()'.Sorry, yes, WO is what you want. But anyway, this should be in configfs, not sysfs.
I'll rewrite this interface using configfs.
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 24 lines
drivers/peci/peci-core.c new file +24
-0+static ssize_t peci_sysfs_delete_device (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct peci_adapter *adapter =to_peci_adapter (dev); +struct peci_client *client, *next; +struct peci_board_info info = {}; +struct peci_driver *driver; +char *blank, end; +int rc; + +/* Parse device type */ + blank =strchr (buf,' ' ); +if (!blank) { +dev_err (dev,"%s: Missing parameters\n" ,"delete_device" ); +return -EINVAL ; + } +if (blank - buf >PECI_NAME_SIZE -1 ) { +dev_err (dev,"%s: Invalid device type\n" ,"delete_device" ); +return -EINVAL ; + } +memcpy (info.type, buf, blank - buf); + +/* Parse remaining parameters, reject extra parameters */ drivers/peci/peci-core.c line 1004
Quoted 10 lines
drivers/peci/peci-core.c new file +10
-0+ rc =sscanf (++blank,"%hi%c" , &info.addr, &end); +if (rc <1 ) { +dev_err (dev,"%s: Can't parse client address\n" , +"delete_device" ); +return -EINVAL ; + } +if (rc >1 && end !='\n' ) { +dev_err (dev,"%s: Extra parameters\n" ,"delete_device" ); +return -EINVAL ; + }Same here, no parsing of configurations through sysfs, that is not ok. Again, use configfs.
Quoted 6 lines
Quoted 4 lines
Same as above. This is for run-time deregistration of a PECI client which is registered on a PECI bus adapter. The life cycle of this sysfs interface will be synced with the adapter driver. Actually, it follows what I2C core driver currently does.
Again, do not copy previous mistakes please.
Agreed. Thanks!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/peci/peci-core.c line 1032
Quoted 5 lines
drivers/peci/peci-core.c new file +5
-0+ +return rc; +} +static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL, + peci_sysfs_delete_device);sysfs files that remove themselves are reserved for a specific circle in hell, you really don't want to mess with them :(
Quoted 5 lines
Quoted 3 lines
It cannot remove itself. The owner of the sysfs files is an adapter driver and only client devices can be added/removed by these sysfs files. An adapter can't be removed by accessing of this sysfs.
They why the LOCKDEP notation?
For a case of debugging. Anyway, I'll rewrite this part using configfs.
Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 11 lines
include/linux/peci.h new file +11
-0+/** +* struct peci_adapter - represent a PECI adapter +* @owner: owner module of the PECI adpater +* @bus_lock: mutex for exclusion of multiple callers +* @dev: device interface to this driver +* @cdev: character device object to create character device +* @nr: the bus number to map +* @name: name of the adapter +* @userspace_clients_lock: mutex for exclusion of clients handling +* @userspace_clients: list of registered clients +* @xfer: low-level transfer function pointer of the adapter include/linux/peci.h line 40
Quoted 10 lines
include/linux/peci.h new file +10
-0+* @cmd_mask: mask for supportable PECI commands +* +* Each PECI adapter can communicate with one or more PECI client children. +* These make a small bus, sharing a single wired PECI connection. +*/ +struct peci_adapter { +struct module *owner; +struct rt_mutex bus_lock; +struct device dev; +struct cdev cdev;Yeah, two differently reference counted variables in the same structure, what could go wrong! :(
Don't do this, make your cdev a pointer to be sure you get things right, otherwise this will never work properly.
And shouldn't the character device be a class device? Don't confuse devices in the driver model with the interaction of them to userspace in a specific manner, those should be separate things, right?
Quoted 7 lines
Quoted 3 lines
Okay, I got your point. I'll split out the character device part as a separated module and will make the module can be attached to a PECI bus.
I'm not saying it has to be a whole separate module, at the least it needs to be a new structure. As it is, your code is not correct due to the dual-structures-trying-to-fight-it-out-for-lifecycle-rules
I got you point clearly now. I'll use a separate structure for the character device.
Quoted 26 lines
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/peci-ioctl.h new file +12
-0+/** +* struct peci_xfer_msg - raw PECI transfer command +* @addr; address of the client +* @tx_len: number of data to be written in bytes +* @rx_len: number of data to be read in bytes +* @tx_buf: data to be written, or NULL +* @rx_buf: data to be read, or NULL +* +* raw PECI transfer +*/ +struct peci_xfer_msg { +__u8 addr;Quoted 8 lines
include/uapi/linux/peci-ioctl.h line 194
Quoted 5 lines
include/uapi/linux/peci-ioctl.h new file +5
-0+__u8 tx_len; +__u8 rx_len; +__u8 tx_buf[PECI_BUFFER_SIZE ]; +__u8 rx_buf[PECI_BUFFER_SIZE ]; +} __attribute__((__packed__));Go kick the hardware engineer who did not align things on a 32bit boundry. They should have known better :(
Quoted 4 lines
I intended to make it as contiguous byte sequence in this order because some PECI commands need to caclulate CRC8 checksum using this as a byte array. I'll align these on a 32bit boundary and will use a temporary buffer instead while calcuating a CRC8 checksum.
Quoted 5 lines
If this really is the way the structure needs to be on the wire, that's fine, it's just a complaint about the protocol and how bad accessing those fields are going to suck for some processors.
But if you can get away with not doing it like this, that would be nice.
OK. I'll align this on a 32bit boundary and align all remaining structures in this header file as well.
Thanks a lot for your comments.
Regards,
Jae
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Quoted 12 lines · Jae Hyun Yoo
Quoted 11 lines · Greg Kroah-Hartman
Quoted 9 lines · Jae Hyun Yoo
Quoted 2 lines
What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };
Quoted 5 lines
Quoted 1 line
Ok. But my question about "can you do this off the stack" remains.
I'll add 3 bytes of dummy padding into this structure. Also, I'll check again u32 boundary alignment for all struct defines in
peci_ioctl.h. Would it be okay to be on stack then?
The issue of being on the stack has nothing to do with alignment, and everything to do with, "can your controller handle data from the stack". Lots of busses and controllers can not (i.e. all USB devices), so you have to properly allocate all memory that is used for data transfers from areas that are able to do DMA properly (i.e. by using kmalloc).
That is why I asked here about that, if this is a USB driver, having the data you wish to send from a stack variable is not allowed. I don't know how your hardware works, which is why I was asking this.
Note, some architectures (like x86), hide this fact as their stack memory is able to be DMA, so you do not run into any errors. Other arches that Linux supports are not like that, which is why we have those types of restrictions.
Hope this helps,
greg k-h
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Hi Greg,
Quoted 25 lines · Greg Kroah-Hartman
Quoted 12 lines · Jae Hyun Yoo
Quoted 11 lines · Greg Kroah-Hartman
Quoted 9 lines · Jae Hyun Yoo
Quoted 2 lines
What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };Quoted 5 lines
Quoted 1 line
Ok. But my question about "can you do this off the stack" remains.
I'll add 3 bytes of dummy padding into this structure. Also, I'll check again u32 boundary alignment for all struct defines in
peci_ioctl.h. Would it be okay to be on stack then?The issue of being on the stack has nothing to do with alignment, and everything to do with, "can your controller handle data from the stack". Lots of busses and controllers can not (i.e. all USB devices), so you have to properly allocate all memory that is used for data transfers from areas that are able to do DMA properly (i.e. by using kmalloc).
Quoted 8 lines
That is why I asked here about that, if this is a USB driver, having the data you wish to send from a stack variable is not allowed. I don't know how your hardware works, which is why I was asking this.
Note, some architectures (like x86), hide this fact as their stack memory is able to be DMA, so you do not run into any errors. Other arches that Linux supports are not like that, which is why we have those types of restrictions.
Thanks for your detailed explanation.
In this core driver, all PECI command messages will be translated into the raw PECI message structure (peci_xfer_msg) and it is the actual data which will be delivered to an adapter driver through adapter->xfer().
I'll fix the translation logic to use heap instead of stack for handling the peci_xfer_msg structure.
Thanks,
Jae
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Quoted 39 lines · Jae Hyun Yoo
Hi Greg,
Quoted 25 lines · Greg Kroah-Hartman
Quoted 12 lines · Jae Hyun Yoo
Quoted 11 lines · Greg Kroah-Hartman
Quoted 9 lines · Jae Hyun Yoo
Quoted 2 lines
What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };Quoted 5 lines
Quoted 1 line
Ok. But my question about "can you do this off the stack" remains.
I'll add 3 bytes of dummy padding into this structure. Also, I'll check again u32 boundary alignment for all struct defines in
peci_ioctl.h. Would it be okay to be on stack then?The issue of being on the stack has nothing to do with alignment, and everything to do with, "can your controller handle data from the stack". Lots of busses and controllers can not (i.e. all USB devices), so you have to properly allocate all memory that is used for data transfers from areas that are able to do DMA properly (i.e. by using kmalloc).
Quoted 8 lines
That is why I asked here about that, if this is a USB driver, having the data you wish to send from a stack variable is not allowed. I don't know how your hardware works, which is why I was asking this.
Note, some architectures (like x86), hide this fact as their stack memory is able to be DMA, so you do not run into any errors. Other arches that Linux supports are not like that, which is why we have those types of restrictions.
Thanks for your detailed explanation.
Quoted 7 lines
In this core driver, all PECI command messages will be translated into the raw PECI message structure (
peci_xfer_msg) and it is the actual data which will be delivered to an adapter driver throughadapter->xfer().I'll fix the translation logic to use heap instead of stack for handling the
peci_xfer_msgstructure.
Great! You might want to add the checks that we have in the USB core for this type of thing to catch users who don't remember not to send stack-data. Look at usb_hcd_map_urb_for_dma() for specifics.
thanks,
greg k-h
Re: [PATCH v10 03/12] peci: Add support for PECI bus driver core
Hi Greg,
Quoted 45 lines · Greg Kroah-Hartman
Quoted 44 lines · Jae Hyun Yoo
Hi Greg,
Quoted 25 lines · Greg Kroah-Hartman
Quoted 12 lines · Jae Hyun Yoo
Quoted 11 lines · Greg Kroah-Hartman
Quoted 9 lines · Jae Hyun Yoo
Quoted 2 lines
What about the un-initialized fields in this structure? Can you properly handle that, and also, is this ok to be on the stack?
It's fully initialized at here because the
peci_ping_msgstruct has only one member:struct peci_ping_msg { __u8 addr; };Quoted 5 lines
Quoted 1 line
Ok. But my question about "can you do this off the stack" remains.
I'll add 3 bytes of dummy padding into this structure. Also, I'll check again u32 boundary alignment for all struct defines in
peci_ioctl.h. Would it be okay to be on stack then?The issue of being on the stack has nothing to do with alignment, and everything to do with, "can your controller handle data from the stack". Lots of busses and controllers can not (i.e. all USB devices), so you have to properly allocate all memory that is used for data transfers from areas that are able to do DMA properly (i.e. by using kmalloc).
Quoted 8 lines
That is why I asked here about that, if this is a USB driver, having the data you wish to send from a stack variable is not allowed. I don't know how your hardware works, which is why I was asking this.
Note, some architectures (like x86), hide this fact as their stack memory is able to be DMA, so you do not run into any errors. Other arches that Linux supports are not like that, which is why we have those types of restrictions.
Thanks for your detailed explanation.
In this core driver, all PECI command messages will be translated into the raw PECI message structure (
peci_xfer_msg) and it is the actual data which will be delivered to an adapter driver throughadapter->xfer().
Quoted 6 lines
Quoted 2 lines
I'll fix the translation logic to use heap instead of stack for handling the
peci_xfer_msgstructure.Great! You might want to add the checks that we have in the USB core for this type of thing to catch users who don't remember not to send stack-data. Look at
usb_hcd_map_urb_for_dma()for specifics.
Thanks for the additional information. I'll add the checks as well.
Regards,
Jae