Skip to contentSkip to conversation

PECI device driver introduction

PATCH In review Jae Hyun Yoo 5 participants 37 messages Dec 11, 2019 – Dec 18, 2019

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

v11 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/26xx, NPCM7xx PECI drivers 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 v10:
- Split out peci-dev module from peci-core module.
- Changed device tree bindings documents format to DT schema.
- Changed hwmon documents format to rst.
- Added Skylake Xeon D support in PECI hwmon drivers.
- Added DTS temperature reading in peci-cputemp driver which is more thermal control friendlier than Die temperature.
- Added max and crit properties into peci-dimmtemp driver for temperature threshold checking.
- Refined kconfig dependencies in PECI subsystem.
- Added PECI 4.0 command set support.
- Refined 32-bit boundary alignment for all PECI ioctl command structs.
- Added DMA safe command buffer handling in peci-core.
- Added Nuvoton NPCM7xx PECI support.
- Added Aspeed AST26xx PECI support.
- Moved adapter drivers into 'drivers/peci/busses'.
- Fixed minor bugs and style issues.
- configfs support isn't added in this patch set. Will add that using a seperate patch set.

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 (11):
dt-bindings: Add PECI subsystem document
Documentation: ioctl: Add ioctl numbers for PECI subsystem
peci: Add support for PECI bus driver core
dt-bindings: Add bindings document of Aspeed PECI adapter
ARM: dts: aspeed: Add PECI node
peci: Add Aspeed PECI adapter driver
dt-bindings: mfd: Add Intel PECI client bindings document
mfd: intel-peci-client: Add Intel PECI client driver
Documentation: hwmon: Add documents for PECI hwmon drivers
hwmon: Add PECI cputemp driver
hwmon: Add PECI dimmtemp driver

Tomer Maimon (3):
dt-bindings: peci: add NPCM PECI documentation
ARM: dts: npcm7xx: Add PECI node
peci: npcm: add NPCM PECI driver

 .../bindings/mfd/intel,peci-client.yaml       |   67 +
 .../devicetree/bindings/peci/peci-aspeed.yaml |  124 +
 .../devicetree/bindings/peci/peci-bus.yaml    |  129 +
 .../devicetree/bindings/peci/peci-client.yaml |   54 +
 .../devicetree/bindings/peci/peci-npcm.yaml   |  102 +
 Documentation/hwmon/index.rst                 |    2 +
 Documentation/hwmon/peci-cputemp.rst          |   95 +
 Documentation/hwmon/peci-dimmtemp.rst         |   60 +
 .../userspace-api/ioctl/ioctl-number.rst      |    2 +
 arch/arm/boot/dts/aspeed-g4.dtsi              |   25 +
 arch/arm/boot/dts/aspeed-g5.dtsi              |   25 +
 arch/arm/boot/dts/aspeed-g6.dtsi              |   25 +
 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi |   19 +
 drivers/Kconfig                               |    2 +
 drivers/Makefile                              |    1 +
 drivers/hwmon/Kconfig                         |   28 +
 drivers/hwmon/Makefile                        |    2 +
 drivers/hwmon/peci-cputemp.c                  |  448 ++++
 drivers/hwmon/peci-dimmtemp.c                 |  393 ++++
 drivers/hwmon/peci-hwmon.h                    |   46 +
 drivers/mfd/Kconfig                           |   17 +
 drivers/mfd/Makefile                          |    1 +
 drivers/mfd/intel-peci-client.c               |  149 ++
 drivers/peci/Kconfig                          |   38 +
 drivers/peci/Makefile                         |   11 +
 drivers/peci/busses/Kconfig                   |   32 +
 drivers/peci/busses/Makefile                  |    7 +
 drivers/peci/busses/peci-aspeed.c             |  489 ++++
 drivers/peci/busses/peci-npcm.c               |  407 ++++
 drivers/peci/peci-core.c                      | 2086 +++++++++++++++++
 drivers/peci/peci-dev.c                       |  348 +++
 include/linux/mfd/intel-peci-client.h         |  117 +
 include/linux/peci.h                          |  150 ++
 include/uapi/linux/peci-ioctl.h               |  660 ++++++
 34 files changed, 6161 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/intel,peci-client.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-bus.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-client.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-npcm.yaml
 create mode 100644 Documentation/hwmon/peci-cputemp.rst
 create mode 100644 Documentation/hwmon/peci-dimmtemp.rst
 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/busses/Kconfig
 create mode 100644 drivers/peci/busses/Makefile
 create mode 100644 drivers/peci/busses/peci-aspeed.c
 create mode 100644 drivers/peci/busses/peci-npcm.c
 create mode 100644 drivers/peci/peci-core.c
 create mode 100644 drivers/peci/peci-dev.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.17.1
#1 lore raw

PATCH v11 1/14 dt-bindings: Add PECI subsystem document

This commit adds PECI subsystem document.

Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Joel Stanley <[email protected]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

 .../devicetree/bindings/peci/peci-bus.yaml    | 129 ++++++++++++++++++
 .../devicetree/bindings/peci/peci-client.yaml |  54 ++++++++
 2 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-bus.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-client.yaml
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +129 -0
new file mode 100644
index 000000000000..b085e67089cf
@@ -0,0 +1,129 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-bus.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Device Tree Bindings for PECI bus
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+description: |
+  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.
+
+  PECI subsystem provides single or multiple bus nodes support so each bus can
+  have one adapter node and multiple device specific client nodes that can be
+  attached to the PECI bus so each processor client's features can be supported
+  by the client node through an adapter connection in the bus.
+
+properties:
+  compatible:
+    const: simple-bus
+
+  "#address-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  "#size-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  ranges: true
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+  - ranges
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+
+        // Just an example. ast2600 doesn't have a second PECI module actually.
+        peci1: peci-bus@100 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x100 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+    };
+...
Documentation/devicetree/bindings/peci/peci-client.yaml new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH v11 01/14] dt-bindings: Add PECI subsystem document

Quoted 24 lines · Jae Hyun Yoo

This commit adds PECI subsystem document.

Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Joel Stanley <[email protected]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

 .../devicetree/bindings/peci/peci-bus.yaml    | 129 ++++++++++++++++++
 .../devicetree/bindings/peci/peci-client.yaml |  54 ++++++++
 2 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-bus.yaml
 create mode 100644 Documentation/devicetree/bindings/peci/peci-client.yaml
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +0 -0
new file mode 100644
index 000000000000..b085e67089cf

Documentation/devicetree/bindings/peci/peci-bus.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +1 -0
@@ -0,0 +1,129 @@
+# SPDX-License-Identifier: GPL-2.0

Dual license new bindings please:

(GPL-2.0-only OR BSD-2-Clause)

Quoted 67 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +67 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-bus.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Device Tree Bindings for PECI bus
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+description: |
+  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

Documentation/devicetree/bindings/peci/peci-bus.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +10 -0
+  information.
+
+  PECI subsystem provides single or multiple bus nodes support so each bus can
+  have one adapter node and multiple device specific client nodes that can be
+  attached to the PECI bus so each processor client's features can be supported
+  by the client node through an adapter connection in the bus.
+
+properties:
+  compatible:
+    const: simple-bus

This is wrong. We already have a schema for this.

What's needed is a peci-bus schema that defines the bus node structure and then schemas for the specific controllers and child devices. See i2c-controller.yaml for an example.

Quoted 67 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +51 -0
+
+  "#address-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  "#size-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  ranges: true
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+  - ranges
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+
+        // Just an example. ast2600 doesn't have a second PECI module actually.
+        peci1: peci-bus@100 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x100 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+    };
+...
Documentation/devicetree/bindings/peci/peci-client.yaml new file +10 -0
new file mode 100644
index 000000000000..fc7c4110e929
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-client.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Device Tree Bindings for PECI clients
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>

Documentation/devicetree/bindings/peci/peci-client.yaml line 20

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-client.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - intel,peci-client
+
+  reg:
+    description: |
+      Address of a client CPU. According to the PECI specification, client
+      addresses start from 0x30.

0x30 being the min should be a constraint in the bus schema.

Quoted 37 lines
Documentation/devicetree/bindings/peci/peci-client.yaml new file +34 -0
+    maxItems: 1
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+
+            peci-client@30 {
+                compatible = "intel,peci-client";
+                reg = <0x30>;
+            };
+
+            peci-client@31 {
+                compatible = "intel,peci-client";
+                reg = <0x31>;
+            };
+        };
+    };
+...
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v11 01/14] dt-bindings: Add PECI subsystem document

Hi Rob,

Quoted 29 lines · Rob Herring
Quoted 24 lines · Jae Hyun Yoo

This commit adds PECI subsystem document.

Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Joel Stanley <[email protected]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

  .../devicetree/bindings/peci/peci-bus.yaml    | 129 ++++++++++++++++++
  .../devicetree/bindings/peci/peci-client.yaml |  54 ++++++++
  2 files changed, 183 insertions(+)

create mode 100644 Documentation/devicetree/bindings/peci/peci-bus.yaml create mode 100644 Documentation/devicetree/bindings/peci/peci-client.yaml

Documentation/devicetree/bindings/peci/peci-bus.yaml new file +0 -0
new file mode 100644
index 000000000000..b085e67089cf

Documentation/devicetree/bindings/peci/peci-bus.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +1 -0
@@ -0,0 +1,129 @@
+# SPDX-License-Identifier: GPL-2.0

Dual license new bindings please:

Quoted 1 line

(GPL-2.0-only OR BSD-2-Clause)

I see. I'll replace that with it for all new bindings in this patch set.

Quoted 80 lines
Quoted 67 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +67 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-bus.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Device Tree Bindings for PECI bus
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+description: |
+  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

Documentation/devicetree/bindings/peci/peci-bus.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +10 -0
+  information.
+
+  PECI subsystem provides single or multiple bus nodes support so each bus can
+  have one adapter node and multiple device specific client nodes that can be
+  attached to the PECI bus so each processor client's features can be supported
+  by the client node through an adapter connection in the bus.
+
+properties:
+  compatible:
+    const: simple-bus

This is wrong. We already have a schema for this.

Quoted 3 lines

What's needed is a peci-bus schema that defines the bus node structure and then schemas for the specific controllers and child devices. See i2c-controller.yaml for an example.

Oh, I see. I'll fix and submit it as '/schema/peci-bus.yaml' into dt-schema tree.

Quoted 71 lines
Quoted 71 lines
Documentation/devicetree/bindings/peci/peci-bus.yaml new file +51 -0
+
+  "#address-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  "#size-cells":
+    # Required to define bus device control resource address.
+    const: 1
+
+  ranges: true
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+  - ranges
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+
+        // Just an example. ast2600 doesn't have a second PECI module actually.
+        peci1: peci-bus@100 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x100 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+        };
+    };
+...
Documentation/devicetree/bindings/peci/peci-client.yaml new file +14 -0
new file mode 100644
index 000000000000..fc7c4110e929
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-client.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic Device Tree Bindings for PECI clients
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+properties:
+  compatible:
+    enum:
Quoted 8 lines

Documentation/devicetree/bindings/peci/peci-client.yaml line 20

Quoted 6 lines
Documentation/devicetree/bindings/peci/peci-client.yaml new file +6 -0
+      - intel,peci-client
+
+  reg:
+    description: |
+      Address of a client CPU. According to the PECI specification, client
+      addresses start from 0x30.

0x30 being the min should be a constraint in the bus schema.

Right. Will add that.

Thanks a lot for your review!

-Jae

Quoted 38 lines
Quoted 37 lines
Documentation/devicetree/bindings/peci/peci-client.yaml new file +34 -0
+    maxItems: 1
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+
+            peci-client@30 {
+                compatible = "intel,peci-client";
+                reg = <0x30>;
+            };
+
+            peci-client@31 {
+                compatible = "intel,peci-client";
+                reg = <0x31>;
+            };
+        };
+    };
+...
Signature · 1 line
2.17.1
#4 lore raw

PATCH v11 2/14 Documentation: ioctl: Add ioctl numbers for PECI subsystem

In reply to Jae Hyun Yoo

This commit updates ioctl-number.rst to reflect ioctl numbers used by the PECI subsystem.

Cc Jonathan Corbet <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Kishon Vijay Abraham I <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Gustavo Pimentel <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc Tomohiro Kusumi <[email protected]>
Cc Eric Sandeen <[email protected]>
Cc Frederic Barrat <[email protected]>
Cc Bryant G. Ly <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc James Feist <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Vernon Mauery <[email protected]>

---
Changes since v10:
- Moved the change from 'Documentation/ioctl/ioctl-number.txt.

 Documentation/userspace-api/ioctl/ioctl-number.rst | 2 ++
 1 file changed, 2 insertions(+)
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
index 4ef86433bd67..ce99968032f7 100644
@@ -338,6 +338,8 @@ Code  Seq#    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  all    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.17.1
#5 lore raw

PATCH v11 3/14 peci: Add support for PECI bus driver core

In reply to Jae Hyun Yoo

This 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.

Cc Greg Kroah-Hartman <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Gavin Schenk <[email protected]>
Cc Vinod Koul <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Sagar Dharia <[email protected]>
Cc David Kershner <[email protected]>
Cc Johan Hovold <[email protected]>
Cc Uwe Kleine-Konig <[email protected]>
Cc Viresh Kumar <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Cyrille Pitchen <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Fengguang Wu <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Julia Cartwright <[email protected]>

---
Changes since v10:
- Split out peci-dev module from peci-core module.
- Added PECI 4.0 command set support.
- Refined 32-bit boundary alignment for all PECI ioctl command structs.
- Added DMA safe command buffer handling in peci-core.
- Refined kconfig dependencies in PECI subsystem.
- Fixed minor bugs and style issues.
- configfs support isn't added in this patch set. Will add that using a seperate patch set.

 drivers/Kconfig                 |    2 +
 drivers/Makefile                |    1 +
 drivers/peci/Kconfig            |   38 +
 drivers/peci/Makefile           |   11 +
 drivers/peci/busses/Kconfig     |    7 +
 drivers/peci/busses/Makefile    |    4 +
 drivers/peci/peci-core.c        | 2086 +++++++++++++++++++++++++++++++
 drivers/peci/peci-dev.c         |  348 ++++++
 include/linux/peci.h            |  150 +++
 include/uapi/linux/peci-ioctl.h |  660 ++++++++++
 10 files changed, 3307 insertions(+)
 create mode 100644 drivers/peci/Kconfig
 create mode 100644 drivers/peci/Makefile
 create mode 100644 drivers/peci/busses/Kconfig
 create mode 100644 drivers/peci/busses/Makefile
 create mode 100644 drivers/peci/peci-core.c
 create mode 100644 drivers/peci/peci-dev.c
 create mode 100644 include/linux/peci.h
 create mode 100644 include/uapi/linux/peci-ioctl.h
drivers/Kconfig +2 -0
index 8befa53f43be..4322efa37732 100644
@@ -228,4 +228,6 @@ source "drivers/interconnect/Kconfig"
 
 source "drivers/counter/Kconfig"
 
+source "drivers/peci/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index aaef17cc6512..82f78cfedf69 100644
@@ -186,3 +186,4 @@ obj-$(CONFIG_SIOX)		+= siox/
 obj-$(CONFIG_GNSS)		+= gnss/
 obj-$(CONFIG_INTERCONNECT)	+= interconnect/
 obj-$(CONFIG_COUNTER)		+= counter/
+obj-$(CONFIG_PECI)		+= peci/
drivers/peci/Kconfig new file +38 -0
new file mode 100644
index 000000000000..9752feee2454
@@ -0,0 +1,38 @@
+#
+# Platform Environment Control Interface (PECI) subsystem configuration
+#
+
+menu "PECI support"
+
+config PECI
+	tristate "PECI support"
+	select CRC8
+	default n
+	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.
+
+	  If you want PECI support, you should say Y here and also to the
+	  specific driver for your bus adapter(s) below.
+
+	  This support is also available as a module. If so, the module
+	  will be called peci-core.
+
+if PECI
+
+config PECI_CHARDEV
+	tristate "PECI device interface"
+	help
+	  Say Y here to use peci-* device files, usually found in the /dev
+	  directory on your system. They make it possible to have user-space
+	  programs use the PECI bus.
+
+	  This support is also available as a module. If so, the module
+	  will be called peci-dev.
+
+source "drivers/peci/busses/Kconfig"
+
+endif # PECI
+
+endmenu
drivers/peci/Makefile new file +11 -0
new file mode 100644
index 000000000000..da8b0a33fa42
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the PECI core drivers.
+#
+
+# Core functionality
+obj-$(CONFIG_PECI)		+= peci-core.o
+obj-$(CONFIG_PECI_CHARDEV)	+= peci-dev.o
+
+# Hardware specific bus drivers
+obj-y				+= busses/
drivers/peci/busses/Kconfig new file +7 -0
new file mode 100644
index 000000000000..d7e064f52a1c
@@ -0,0 +1,7 @@
+#
+# PECI hardware bus configuration
+#
+
+menu "PECI Hardware Bus support"
+
+endmenu
drivers/peci/busses/Makefile new file +4 -0
new file mode 100644
index 000000000000..9e9334fee297
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the PECI hardware bus drivers.
+#
drivers/peci/peci-core.c new file +2086 -0

2,086 lines not on this page · raw message

drivers/peci/peci-dev.c new file +348 -0

348 lines not on this page · raw message

include/linux/peci.h new file +150 -0

150 lines not on this page · raw message

include/uapi/linux/peci-ioctl.h new file +660 -0

346 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.17.1

Part of the diff is not shown here. View the raw message.

#6 lore raw

Re: [PATCH v11 03/14] peci: Add support for PECI bus driver core

Quoted 61 lines · Jae Hyun Yoo

This 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.

Quoted 7 lines

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.

Nice, we have some drivers under drivers/hwmon. Are they using PECI? How they will be integrated to this? Can this be part of drivers/hwmon?

Quoted 1 line

Changes since v10:

It's funny I don't remember previous version(s), but anyway I'll comment on this later on -- it has at least several style issues / inconveniences.

Quoted 9 lines

- Split out peci-dev module from peci-core module.
- Added PECI 4.0 command set support.
- Refined 32-bit boundary alignment for all PECI ioctl command structs.
- Added DMA safe command buffer handling in peci-core.
- Refined kconfig dependencies in PECI subsystem.
- Fixed minor bugs and style issues.
- configfs support isn't added in this patch set. Will add that using a seperate patch set.

drivers/peci/Kconfig line 10

Quoted 5 lines
drivers/peci/Kconfig new file +4 -0
+config PECI
+	tristate "PECI support"
+	select CRC8
 
+	default n

As for beginning, this one is redundant.
If you have more, drop them.

drivers/peci/peci-core.c line 9

Quoted 7 lines
drivers/peci/peci-core.c new file +6 -0
+#include <linux/bitfield.h>
+#include <linux/crc8.h>
+#include <linux/delay.h>
+#include <linux/mm.h>
+#include <linux/module.h>
 
+#include <linux/of_device.h>

What about ACPI? Can you use fwnode API?

Quoted 5 lines
drivers/peci/peci-core.c new file +5 -0
+#include <linux/peci.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
+#include <linux/sched/task_stack.h>
+#include <linux/slab.h>
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH v11 03/14] peci: Add support for PECI bus driver core

Hi Andy,

Quoted 3 lines · Andy Shevchenko

Nice, we have some drivers under drivers/hwmon. Are they using PECI? How they will be integrated to this? Can this be part of drivers/hwmon?

This is designed for SoCs have one-wire PECI hardware which can handle raw PECI protocol. Some drivers under 'drivers/hwmon' that use PECI-to-I2C translation hardware are out of scope from this patch. In case if an SoC supports both PECI-to-I2C translation mode and raw PECI mode, only raw PECI mode can be integrated to this. NPCM7xx is the case and peci-npcm driver in this patch set is an example of the raw PECI driver.

This patch includes peci-cputemp and peci-dimmtemp as raw PECI hwmon drivers.

Quoted 4 lines
Quoted 1 line

Changes since v10:

It's funny I don't remember previous version(s), but anyway I'll comment on this later on -- it has at least several style issues / inconveniences.

I CC'ed you in every submissions but you probably forgot that because I submitted v10 in January this year. Thanks for your review.

Quoted 9 lines
Quoted 8 lines

- Split out peci-dev module from peci-core module.
- Added PECI 4.0 command set support.
- Refined 32-bit boundary alignment for all PECI ioctl command structs.
- Added DMA safe command buffer handling in peci-core.
- Refined kconfig dependencies in PECI subsystem.
- Fixed minor bugs and style issues.
- configfs support isn't added in this patch set. Will add that using a seperate patch set.

Quoted 8 lines

drivers/peci/Kconfig line 10

Quoted 5 lines
drivers/peci/Kconfig new file +4 -0
+config PECI
+	tristate "PECI support"
+	select CRC8
 
+	default n

As for beginning, this one is redundant.
If you have more, drop them.

I see. I'll drop the default setting.

Quoted 9 lines

drivers/peci/peci-core.c line 9

Quoted 7 lines
drivers/peci/peci-core.c new file +6 -0
+#include <linux/bitfield.h>
+#include <linux/crc8.h>
+#include <linux/delay.h>
+#include <linux/mm.h>
+#include <linux/module.h>
 
+#include <linux/of_device.h>

What about ACPI? Can you use fwnode API?

Currently, it's targeting BMC (Baseboard Management Controller) SoCs that are running on ARM kernel. If any needs of ACPI support comes in the future, the ACPI support will be added.

Thanks a lot for your review!

-Jae

Quoted 6 lines
Quoted 5 lines
drivers/peci/peci-core.c new file +5 -0
+#include <linux/peci.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
+#include <linux/sched/task_stack.h>
+#include <linux/slab.h>
#8 lore raw

PATCH v11 4/14 dt-bindings: Add bindings document of Aspeed PECI adapter

In reply to Jae Hyun Yoo

This commit adds bindings document of Aspeed PECI adapter for ASPEED AST24xx/25xx/26xx SoCs.

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]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

 .../devicetree/bindings/peci/peci-aspeed.yaml | 124 ++++++++++++++++++
 1 file changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.yaml
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +124 -0
new file mode 100644
index 000000000000..0f5c2993fe9b
@@ -0,0 +1,124 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-aspeed.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Aspeed PECI Bus Device Tree Bindings
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - aspeed,ast2400-peci
+      - aspeed,ast2500-peci
+      - aspeed,ast2600-peci
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    description: |
+      Clock source for PECI controller. Should reference the external
+      oscillator clock.
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  clock-frequency:
+    # Operation frequency of PECI controller in units of Hz.
+    minimum: 187500
+    maximum: 24000000
+
+  msg-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  addr-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  rd-sampling-point:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 15
+        default: 8
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+  - resets
+  - clock-frequency
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            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.17.1
maintainer
#9 lore raw

Re: [PATCH v11 04/14] dt-bindings: Add bindings document of Aspeed PECI adapter

Quoted 48 lines · Jae Hyun Yoo

This commit adds bindings document of Aspeed PECI adapter for ASPEED AST24xx/25xx/26xx SoCs.

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]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

 .../devicetree/bindings/peci/peci-aspeed.yaml | 124 ++++++++++++++++++
 1 file changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.yaml
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +19 -0
new file mode 100644
index 000000000000..0f5c2993fe9b
@@ -0,0 +1,124 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-aspeed.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Aspeed PECI Bus Device Tree Bindings
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - aspeed,ast2400-peci
+      - aspeed,ast2500-peci
+      - aspeed,ast2600-peci
+
+  reg:

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +9 -0
+    maxItems: 1
+
 
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0

These 2 can be defined by the bus schema.

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 34

Quoted 6 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +6 -0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    description: |

You can drop the '|' if there's no formatting to preserve.

Quoted 63 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +63 -0
+      Clock source for PECI controller. Should reference the external
+      oscillator clock.
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  clock-frequency:
+    # Operation frequency of PECI controller in units of Hz.
+    minimum: 187500
+    maximum: 24000000
+
+  msg-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  addr-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  rd-sampling-point:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 15
+        default: 8
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+  - resets
+  - clock-frequency

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 107

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +10 -0
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;

You can drop this node in the examples.

Quoted 20 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +17 -0
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            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.17.1
#10 lore raw

Re: [PATCH v11 04/14] dt-bindings: Add bindings document of Aspeed PECI adapter

Hi Rob,

Quoted 60 lines · Rob Herring
Quoted 48 lines · Jae Hyun Yoo

This commit adds bindings document of Aspeed PECI adapter for ASPEED AST24xx/25xx/26xx SoCs.

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]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

  .../devicetree/bindings/peci/peci-aspeed.yaml | 124 ++++++++++++++++++
  1 file changed, 124 insertions(+)

create mode 100644 Documentation/devicetree/bindings/peci/peci-aspeed.yaml

Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +19 -0
new file mode 100644
index 000000000000..0f5c2993fe9b
@@ -0,0 +1,124 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-aspeed.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Aspeed PECI Bus Device Tree Bindings
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - aspeed,ast2400-peci
+      - aspeed,ast2500-peci
+      - aspeed,ast2600-peci
+
+  reg:

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +9 -0
+    maxItems: 1
+
 
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0
Quoted 1 line

These 2 can be defined by the bus schema.

I see. I'll add these to peci-bus schema.

Quoted 8 lines

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 34

Quoted 6 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +6 -0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    description: |

You can drop the '|' if there's no formatting to preserve.

Will check this for all bindings in this patch set.

Quoted 67 lines
Quoted 67 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +67 -0
+      Clock source for PECI controller. Should reference the external
+      oscillator clock.
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  clock-frequency:
+    # Operation frequency of PECI controller in units of Hz.
+    minimum: 187500
+    maximum: 24000000
+
+  msg-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  addr-timing:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 255
+        default: 1
+
+  rd-sampling-point:
+    description: |
+      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.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 15
+        default: 8
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+  - resets
+  - clock-frequency
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
Quoted 8 lines

Documentation/devicetree/bindings/peci/peci-aspeed.yaml line 107

Quoted 6 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +6 -0
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;

You can drop this node in the examples.

I see. Will drop the parent node in this example.

Thanks a lot for your review!

-Jae

Quoted 21 lines
Quoted 20 lines
Documentation/devicetree/bindings/peci/peci-aspeed.yaml new file +17 -0
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            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.17.1
#11 lore raw

PATCH v11 5/14 ARM: dts: aspeed: Add PECI node

In reply to Jae Hyun Yoo

This commit adds PECI bus/adapter node into aspeed-g4, aspeed-g5 and aspeed-g6.

---
Changes since v10:
- Added PECI node for Aspeed AST2600.

 arch/arm/boot/dts/aspeed-g4.dtsi | 25 +++++++++++++++++++++++++
 arch/arm/boot/dts/aspeed-g5.dtsi | 25 +++++++++++++++++++++++++
 arch/arm/boot/dts/aspeed-g6.dtsi | 25 +++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
arch/arm/boot/dts/aspeed-g4.dtsi +25 -0
index 46c0891aac5a..3b81aebed190 100644
@@ -378,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>;
@@ -421,6 +428,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 +25 -0
index a259c63fff06..41faf0ad8074 100644
@@ -492,6 +492,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>;
@@ -535,6 +542,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>;
arch/arm/boot/dts/aspeed-g6.dtsi +25 -0
index 5f6142d99eeb..1056c1538be5 100644
@@ -391,6 +391,13 @@
 				status = "disabled";
 			};
 
+			peci: bus@1e78b000 {
+				compatible = "simple-bus";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				ranges = <0x0 0x1e78b000 0x100>;
+			};
+
 			lpc: lpc@1e789000 {
 				compatible = "aspeed,ast2600-lpc", "simple-mfd";
 				reg = <0x1e789000 0x1000>;
@@ -601,6 +608,24 @@
 
 #include "aspeed-g6-pinctrl.dtsi"
 
+&peci {
+	peci0: peci-bus@0 {
+		compatible = "aspeed,ast2600-peci";
+		reg = <0x0 0x100>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+		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 {
 	i2c0: i2c-bus@80 {
 		#address-cells = <1>;
Signature · 1 line
2.17.1
#12 lore raw

PATCH v11 6/14 peci: Add Aspeed PECI adapter driver

In reply to Jae Hyun Yoo

This commit adds Aspeed PECI adapter driver for Aspeed AST24xx/25xx/26xx SoCs.

Cc Joel Stanley <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Ryan Chen <[email protected]>

---
Changes since v10:
- Moved driver into 'drivers/peci/busses'.
- Fixed minor bugs.

 drivers/peci/busses/Kconfig       |  12 +
 drivers/peci/busses/Makefile      |   2 +
 drivers/peci/busses/peci-aspeed.c | 492 ++++++++++++++++++++++++++++++
 3 files changed, 506 insertions(+)
 create mode 100644 drivers/peci/busses/peci-aspeed.c
drivers/peci/busses/Kconfig +12 -0
index d7e064f52a1c..2b2540221b36 100644
@@ -4,4 +4,16 @@
 
 menu "PECI Hardware Bus support"
 
+config PECI_ASPEED
+	tristate "ASPEED PECI support"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on OF
+	depends on PECI
+	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
drivers/peci/busses/Makefile +2 -0
index 9e9334fee297..69e31dfaca19 100644
@@ -2,3 +2,5 @@
 #
 # Makefile for the PECI hardware bus drivers.
 #
+
+obj-$(CONFIG_PECI_ASPEED)	+= peci-aspeed.o
drivers/peci/busses/peci-aspeed.c new file +492 -0

492 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v11 06/14] peci: Add Aspeed PECI adapter driver

Quoted 2 lines · Jae Hyun Yoo

This commit adds Aspeed PECI adapter driver for Aspeed AST24xx/25xx/26xx SoCs.

...

drivers/peci/busses/peci-aspeed.c line 42

Quoted 2 lines
drivers/peci/busses/peci-aspeed.c new file +2 -0
+#define   ASPEED_PECI_CMD_IDLE_MASK		(ASPEED_PECI_CMD_STS_MASK | \
+						 ASPEED_PECI_CMD_PIN_MON)

Better looking when the value completely occupies second line without touching the first.

...

drivers/peci/busses/peci-aspeed.c line 132

Quoted 4 lines
drivers/peci/busses/peci-aspeed.c new file +4 -0
+static int aspeed_peci_check_idle(struct aspeed_peci *priv)
+{
+	ulong timeout = jiffies + usecs_to_jiffies(ASPEED_PECI_IDLE_CHECK_TIMEOUT_USEC);
+	u32 cmd_sts;

Like in the previous patch this one has hard to read timeout loops with inefficient code.

drivers/peci/busses/peci-aspeed.c line 138

Quoted 6 lines
drivers/peci/busses/peci-aspeed.c new file +5 -0
+	for (;;) {
+		cmd_sts = readl(priv->base + ASPEED_PECI_CMD);
+		if (!(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK))
+			break;
 
+		if (time_after(jiffies, timeout)) {

This is actually main exit condition (vs. infinite loop).

Review

Quoted 1 line
(quoted diff) +1 -0
+			cmd_sts = readl(priv->base + ASPEED_PECI_CMD);

This make no sense. If you would like to have one more iteration, just spell it explicitly.

drivers/peci/busses/peci-aspeed.c line 146

Quoted 9 lines
drivers/peci/busses/peci-aspeed.c new file +7 -0
+			break;
+		}
 
+		usleep_range((ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC >> 2) + 1,
+			     ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC);
+	}
+
 
+	return !(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK) ? 0 : -ETIMEDOUT;

Ditto.

Quoted 1 line

+}

Now look at the other variant:

	do {
		...do something...
		if (success)
			return 0;
		usleep(...);
	} while (time_before(...));

	return -ETIMEDOUT;

* Easy
* less LOCs
* guaranteed always to be at least one iteration
* has explicitly spelled exit condition

BUT!

In this very case you may do even better if you read iopoll.h, i.e readl_poll_timeout() has this functionality embedded in the macro.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

Re: [PATCH v11 06/14] peci: Add Aspeed PECI adapter driver

Hi Andy,

Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Jae Hyun Yoo

This commit adds Aspeed PECI adapter driver for Aspeed AST24xx/25xx/26xx SoCs.

...

drivers/peci/busses/peci-aspeed.c line 42

Quoted 2 lines
drivers/peci/busses/peci-aspeed.c new file +2 -0
+#define   ASPEED_PECI_CMD_IDLE_MASK		(ASPEED_PECI_CMD_STS_MASK | \
+						 ASPEED_PECI_CMD_PIN_MON)

Better looking when the value completely occupies second line without touching the first.

Yes. Will change it.

Quoted 53 lines

...

drivers/peci/busses/peci-aspeed.c line 132

Quoted 4 lines
drivers/peci/busses/peci-aspeed.c new file +4 -0
+static int aspeed_peci_check_idle(struct aspeed_peci *priv)
+{
+	ulong timeout = jiffies + usecs_to_jiffies(ASPEED_PECI_IDLE_CHECK_TIMEOUT_USEC);
+	u32 cmd_sts;

Like in the previous patch this one has hard to read timeout loops with inefficient code.

drivers/peci/busses/peci-aspeed.c line 138

Quoted 6 lines
drivers/peci/busses/peci-aspeed.c new file +5 -0
+	for (;;) {
+		cmd_sts = readl(priv->base + ASPEED_PECI_CMD);
+		if (!(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK))
+			break;
 
+		if (time_after(jiffies, timeout)) {

This is actually main exit condition (vs. infinite loop).

Review

Quoted 1 line
(quoted diff) +1 -0
+			cmd_sts = readl(priv->base + ASPEED_PECI_CMD);

This make no sense. If you would like to have one more iteration, just spell it explicitly.

drivers/peci/busses/peci-aspeed.c line 146

Quoted 9 lines
drivers/peci/busses/peci-aspeed.c new file +7 -0
+			break;
+		}
 
+		usleep_range((ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC >> 2) + 1,
+			     ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC);
+	}
+
 
+	return !(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK) ? 0 : -ETIMEDOUT;

Ditto.

Quoted 1 line

+}

Now look at the other variant:

	do {
		...do something...
		if (success)
			return 0;
		usleep(...);
	} while (time_before(...));

	return -ETIMEDOUT;

* Easy
* less LOCs
* guaranteed always to be at least one iteration
* has explicitly spelled exit condition

Quoted 5 lines

BUT!

In this very case you may do even better if you read iopoll.h, i.e readl_poll_timeout() has this functionality embedded in the macro.

I see. I'll simplify this function like below:

#include <linux/iopoll.h>

static inline int aspeed_peci_check_idle(struct aspeed_peci *priv)

{
	u32 cmd_sts;

	return readl_poll_timeout(priv->base + ASPEED_PECI_CMD,
				  cmd_sts,
				  !(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK),
				  ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC,
				  ASPEED_PECI_IDLE_CHECK_TIMEOUT_USEC);
}

Thanks a lot for your review!

-Jae

#15 lore raw

Re: [PATCH v11 06/14] peci: Add Aspeed PECI adapter driver

Quoted 4 lines · Jae Hyun Yoo
Quoted 3 lines · Andy Shevchenko

On Wed, Dec 11, 2019 at 11:46:16AM -0800, Jae Hyun Yoo wrote:

Like in the previous patch...

(1)

Quoted 5 lines

I see. I'll simplify this function like below:

#include <linux/iopoll.h>

static inline int aspeed_peci_check_idle(struct aspeed_peci *priv)

Quoted 9 lines
{
	u32 cmd_sts;

	return readl_poll_timeout(priv->base + ASPEED_PECI_CMD,
				  cmd_sts,
				  !(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK),
				  ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC,
				  ASPEED_PECI_IDLE_CHECK_TIMEOUT_USEC);
}

Good for *this* case, but please fix all the rest accordingly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH v11 06/14] peci: Add Aspeed PECI adapter driver

Hi Andy,

Quoted 16 lines · Andy Shevchenko
Quoted 4 lines · Jae Hyun Yoo
Quoted 3 lines · Andy Shevchenko

On Wed, Dec 11, 2019 at 11:46:16AM -0800, Jae Hyun Yoo wrote:

Like in the previous patch...

(1)

Quoted 8 lines

I see. I'll simplify this function like below:

#include <linux/iopoll.h>

static inline int aspeed_peci_check_idle(struct aspeed_peci *priv)

{
	u32 cmd_sts;
Quoted 8 lines
Quoted 6 lines
	return readl_poll_timeout(priv->base + ASPEED_PECI_CMD,
				  cmd_sts,
				  !(cmd_sts & ASPEED_PECI_CMD_IDLE_MASK),
				  ASPEED_PECI_IDLE_CHECK_INTERVAL_USEC,
				  ASPEED_PECI_IDLE_CHECK_TIMEOUT_USEC);
}

Good for *this* case, but please fix all the rest accordingly.

Sure. Will do that.

Thanks,

Jae

#17 lore raw

PATCH v11 7/14 dt-bindings: peci: add NPCM PECI documentation

In reply to Jae Hyun Yoo

From: Tomer Maimon <[email protected]>

Added device tree binding documentation for Nuvoton BMC NPCM Platform Environment Control Interface(PECI).

---
Changes since v10:
- Newly added in v11.

 .../devicetree/bindings/peci/peci-npcm.yaml   | 102 ++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-npcm.yaml
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +102 -0
new file mode 100644
index 000000000000..bcd5626e68e7
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-npcm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton NPCM PECI Bus Device Tree Bindings
+
+maintainers:
+  - Tomer Maimon <[email protected]>
+
+properties:
+  compatible:
+    const: nuvoton,npcm750-peci # for the NPCM7XX BMC.
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    # PECI reference clock.
+    maxItems: 1
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+  pull-down:
+    description: |
+      Defines the PECI I/O internal pull down operation.
+        0: pull down always enable
+        1: pull down only during transactions.
+        2: pull down always disable.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 2
+        default: 0
+
+  host-neg-bit-rate:
+    description: |
+      Define host negotiation bit rate divider.
+      the host negotiation bit rate calculate with formula:
+      clock frequency[Hz] / [4 x {host-neg-bit-rate + 1}]
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 7
+        maximum: 31
+        default: 15
+
+  high-volt-range:
+    description: |
+      Adapts PECI I/O interface to voltage range.
+        0: PECI I/O interface voltage range of 0.8-1.06V (default)
+        1: PECI I/O interface voltage range of 0.95-1.26V
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h>
+    peci: bus@100000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x100000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "nuvoton,npcm750-peci";
+            reg = <0x0 0x200>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&clk NPCM7XX_CLK_APB3>;
+            cmd-timeout-ms = <1000>;
+            pull-down = <0>;
+            host-neg-bit-rate = <15>;
+        };
+    };
+...
Signature · 1 line
2.17.1
maintainer
#18 lore raw

Re: [PATCH v11 07/14] dt-bindings: peci: add NPCM PECI documentation

Quoted 48 lines · Jae Hyun Yoo

From: Tomer Maimon <[email protected]>

Added device tree binding documentation for Nuvoton BMC NPCM Platform Environment Control Interface(PECI).

---
Changes since v10:
- Newly added in v11.

 .../devicetree/bindings/peci/peci-npcm.yaml   | 102 ++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/peci/peci-npcm.yaml
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +27 -0
new file mode 100644
index 000000000000..bcd5626e68e7
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-npcm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton NPCM PECI Bus Device Tree Bindings
+
+maintainers:
+  - Tomer Maimon <[email protected]>
+
+properties:
+  compatible:
+    const: nuvoton,npcm750-peci # for the NPCM7XX BMC.
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0
+
+  interrupts:

Documentation/devicetree/bindings/peci/peci-npcm.yaml line 37

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +10 -0
+    maxItems: 1
+
+  clocks:
+    # PECI reference clock.
+    maxItems: 1
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32

You can drop this as standard units already have a type.

Quoted 23 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +23 -0
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+  pull-down:
+    description: |
+      Defines the PECI I/O internal pull down operation.
+        0: pull down always enable
+        1: pull down only during transactions.
+        2: pull down always disable.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 2
+        default: 0
+
+  host-neg-bit-rate:
+    description: |
+      Define host negotiation bit rate divider.
+      the host negotiation bit rate calculate with formula:
+      clock frequency[Hz] / [4 x {host-neg-bit-rate + 1}]
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32

Documentation/devicetree/bindings/peci/peci-npcm.yaml line 70

Quoted 10 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +10 -0
+      - minimum: 7
+        maximum: 31
+        default: 15
+
+  high-volt-range:
+    description: |
+      Adapts PECI I/O interface to voltage range.
+        0: PECI I/O interface voltage range of 0.8-1.06V (default)
+        1: PECI I/O interface voltage range of 0.95-1.26V
+    type: boolean

These last 4 properties are vendor specific or PECI common. For the former, needs a vendor prefix. For the latter, needs to be moved to common location.

Quoted 35 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +32 -0
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h>
+    peci: bus@100000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x100000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "nuvoton,npcm750-peci";
+            reg = <0x0 0x200>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&clk NPCM7XX_CLK_APB3>;
+            cmd-timeout-ms = <1000>;
+            pull-down = <0>;
+            host-neg-bit-rate = <15>;
+        };
+    };
+...
Signature · 1 line
2.17.1
#19 lore raw

Re: [PATCH v11 07/14] dt-bindings: peci: add NPCM PECI documentation

Hi Rob,

Quoted 53 lines · Rob Herring
Quoted 52 lines · Jae Hyun Yoo

From: Tomer Maimon <[email protected]>

Added device tree binding documentation for Nuvoton BMC NPCM Platform Environment Control Interface(PECI).

---
Changes since v10:
- Newly added in v11.

  .../devicetree/bindings/peci/peci-npcm.yaml   | 102 ++++++++++++++++++
  1 file changed, 102 insertions(+)

create mode 100644 Documentation/devicetree/bindings/peci/peci-npcm.yaml

Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +31 -0
new file mode 100644
index 000000000000..bcd5626e68e7
@@ -0,0 +1,102 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/peci/peci-npcm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton NPCM PECI Bus Device Tree Bindings
+
+maintainers:
+  - Tomer Maimon <[email protected]>
+
+properties:
+  compatible:
+    const: nuvoton,npcm750-peci # for the NPCM7XX BMC.
+
+  reg:
+    maxItems: 1
+
+  "#address-cells":
+    # Required to define a client address.
+    const: 1
+
+  "#size-cells":
+    # Required to define a client address.
+    const: 0
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    # PECI reference clock.
Quoted 8 lines

Documentation/devicetree/bindings/peci/peci-npcm.yaml line 37

Quoted 6 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +6 -0
+    maxItems: 1
+
+  cmd-timeout-ms:
+    # Command timeout in units of ms.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32

You can drop this as standard units already have a type.

I'm assuming you pointed the timeout-ms as one of standard units, right? I'll drop this ref.

Quoted 29 lines
Quoted 29 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +29 -0
+      - minimum: 1
+        maximum: 60000
+        default: 1000
+
+  pull-down:
+    description: |
+      Defines the PECI I/O internal pull down operation.
+        0: pull down always enable
+        1: pull down only during transactions.
+        2: pull down always disable.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 0
+        maximum: 2
+        default: 0
+
+  host-neg-bit-rate:
+    description: |
+      Define host negotiation bit rate divider.
+      the host negotiation bit rate calculate with formula:
+      clock frequency[Hz] / [4 x {host-neg-bit-rate + 1}]
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+      - minimum: 7
+        maximum: 31
+        default: 15
+
+  high-volt-range:
+    description: |
Quoted 8 lines

Documentation/devicetree/bindings/peci/peci-npcm.yaml line 70

Quoted 4 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +4 -0
+      Adapts PECI I/O interface to voltage range.
+        0: PECI I/O interface voltage range of 0.8-1.06V (default)
+        1: PECI I/O interface voltage range of 0.95-1.26V
+    type: boolean

These last 4 properties are vendor specific or PECI common. For the former, needs a vendor prefix. For the latter, needs to be moved to common location.

These are Nuvoton vendor specifics. I'll add prefix for them and will check Aspeed bindings too.

Thanks a lot for your review!

-Jae

Quoted 36 lines
Quoted 35 lines
Documentation/devicetree/bindings/peci/peci-npcm.yaml new file +32 -0
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+  - interrupts
+  - clocks
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h>
+    peci: bus@100000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x100000 0x200>;
+
+        peci0: peci-bus@0 {
+            compatible = "nuvoton,npcm750-peci";
+            reg = <0x0 0x200>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&clk NPCM7XX_CLK_APB3>;
+            cmd-timeout-ms = <1000>;
+            pull-down = <0>;
+            host-neg-bit-rate = <15>;
+        };
+    };
+...
Signature · 1 line
2.17.1
#20 lore raw

PATCH v11 8/14 ARM: dts: npcm7xx: Add PECI node

In reply to Jae Hyun Yoo

From: Tomer Maimon <[email protected]>

This commit adds PECI node for npcm7xx.

---
Changes since v10:
- Newly added in v11.

 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +19 -0
index d2d0761295a4..526c56770388 100644
@@ -116,6 +116,13 @@
 			interrupt-parent = <&gic>;
 			ranges = <0x0 0xf0000000 0x00300000>;
 
+			peci: bus@100000 {
+				compatible = "simple-bus";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				ranges = <0x0 0x100000 0x200>;
+			};
+
 			timer0: timer@8000 {
 				compatible = "nuvoton,npcm750-timer";
 				interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
@@ -185,3 +192,15 @@
 		};
 	};
 };
+
+&peci {
+	peci0: peci-bus@0 {
+		compatible = "nuvoton,npcm750-peci";
+		reg = <0x0 0x200>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&clk NPCM7XX_CLK_APB3>;
+		status = "disabled";
+	};
+};
Signature · 1 line
2.17.1
#21 lore raw

PATCH v11 9/14 peci: npcm: add NPCM PECI driver

In reply to Jae Hyun Yoo

From: Tomer Maimon <[email protected]>

Add support for the Nuvoton NPCM BMC hardware to the Platform Environment Control Interface (PECI) subsystem.

---
Changes since v10:
- Newly added in v11Split out peci-dev module from peci-core module.

 drivers/peci/busses/Kconfig     |  13 +
 drivers/peci/busses/Makefile    |   1 +
 drivers/peci/busses/peci-npcm.c | 407 ++++++++++++++++++++++++++++++++
 3 files changed, 421 insertions(+)
 create mode 100644 drivers/peci/busses/peci-npcm.c
drivers/peci/busses/Kconfig +13 -0
index 2b2540221b36..bfacafb7a7ba 100644
@@ -16,4 +16,17 @@ config PECI_ASPEED
 	  This support is also available as a module. If so, the module
 	  will be called peci-aspeed.
 
+config PECI_NPCM
+	tristate "Nuvoton NPCM PECI support"
+	select REGMAP_MMIO
+	depends on OF
+	depends on ARCH_NPCM || COMPILE_TEST
+	depends on PECI
+	help
+	  Say Y here if you want support for the Platform Environment Control
+	  Interface (PECI) bus adapter driver on the Nuvoton NPCM SoCs.
+
+	  This support is also available as a module. If so, the module
+	  will be called peci-npcm.
+
 endmenu
drivers/peci/busses/Makefile +1 -0
index 69e31dfaca19..aa8ce3ae5947 100644
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_PECI_ASPEED)	+= peci-aspeed.o
+obj-$(CONFIG_PECI_NPCM)		+= peci-npcm.o
drivers/peci/busses/peci-npcm.c new file +407 -0

407 lines not on this page · raw message

Signature · 1 line
2.17.1
#22 lore raw

PATCH v11 10/14 dt-bindings: mfd: Add Intel PECI client bindings document

In reply to Jae Hyun Yoo

This commit adds Intel PECI client bindings document.

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]>

---
Changes since v10:
- Changed documents format to DT schema format so I dropped all review tags. Please review it again.

 .../bindings/mfd/intel,peci-client.yaml       | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/intel,peci-client.yaml
Documentation/devicetree/bindings/mfd/intel,peci-client.yaml new file +67 -0
new file mode 100644
index 000000000000..7baddce0a92c
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/intel,peci-client.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Intel PECI Client Device Tree Bindings
+
+maintainers:
+  - Jae Hyun Yoo <[email protected]>
+
+description: |
+  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
+
+properties:
+  compatible:
+    const: intel,peci-client
+
+  reg:
+    description: |
+      Address of a client CPU. According to the PECI specification, client
+      addresses start from 0x30.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/ast2600-clock.h>
+    peci: bus@1e78b000 {
+        compatible = "simple-bus";
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0x0 0x1e78b000 0x60>;
+
+        peci0: peci-bus@0 {
+            compatible = "aspeed,ast2600-peci";
+            reg = <0x0 0x100>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+            interrupts = <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon ASPEED_CLK_GATE_REF0CLK>;
+            resets = <&syscon ASPEED_RESET_PECI>;
+            clock-frequency = <24000000>;
+
+            peci-client@30 {
+                compatible = "intel,peci-client";
+                reg = <0x30>;
+            };
+
+            peci-client@31 {
+                compatible = "intel,peci-client";
+                reg = <0x31>;
+            };
+        };
+    };
+...
Signature · 1 line
2.17.1
#23 lore raw

PATCH v11 11/14 mfd: intel-peci-client: Add Intel PECI client driver

In reply to Jae Hyun Yoo

This commit adds Intel PECI client driver.

Cc Lee Jones <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Rob Herring <[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]>

---
Changes since v10:
- Fixed minor style issues.

 drivers/mfd/Kconfig                   |  17 +++
 drivers/mfd/Makefile                  |   1 +
 drivers/mfd/intel-peci-client.c       | 149 ++++++++++++++++++++++++++
 include/linux/mfd/intel-peci-client.h | 117 ++++++++++++++++++++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/mfd/intel-peci-client.c
 create mode 100644 include/linux/mfd/intel-peci-client.h
drivers/mfd/Kconfig +17 -0
index 420900852166..7022e54a4703 100644
@@ -632,6 +632,23 @@ config MFD_INTEL_MSIC
 	  Passage) chip. This chip embeds audio, battery, GPIO, etc.
 	  devices used in Intel Medfield platforms.
 
+config MFD_INTEL_PECI_CLIENT
+	tristate "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.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called intel-peci-client.
+
 config MFD_IPAQ_MICRO
 	bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support"
 	depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
index aed99f08739f..91c6fda5cec6 100644
@@ -211,6 +211,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 +149 -0

149 lines not on this page · raw message

include/linux/mfd/intel-peci-client.h new file +117 -0

117 lines not on this page · raw message

Signature · 1 line
2.17.1
#24 lore raw

Re: [PATCH v11 11/14] mfd: intel-peci-client: Add Intel PECI client driver

Quoted 83 lines · Jae Hyun Yoo

This commit adds Intel PECI client driver.

Cc Lee Jones <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Rob Herring <[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]>

---
Changes since v10:
- Fixed minor style issues.

 drivers/mfd/Kconfig                   |  17 +++
 drivers/mfd/Makefile                  |   1 +
 drivers/mfd/intel-peci-client.c       | 149 ++++++++++++++++++++++++++
 include/linux/mfd/intel-peci-client.h | 117 ++++++++++++++++++++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/mfd/intel-peci-client.c
 create mode 100644 include/linux/mfd/intel-peci-client.h
drivers/mfd/Kconfig +17 -0
index 420900852166..7022e54a4703 100644
@@ -632,6 +632,23 @@ config MFD_INTEL_MSIC
 	  Passage) chip. This chip embeds audio, battery, GPIO, etc.
 	  devices used in Intel Medfield platforms.
 
+config MFD_INTEL_PECI_CLIENT
+	tristate "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.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called intel-peci-client.
+
 config MFD_IPAQ_MICRO
 	bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support"
 	depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
index aed99f08739f..91c6fda5cec6 100644
@@ -211,6 +211,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 +14 -0
new file mode 100644
index 000000000000..18bf0af0e09e
@@ -0,0 +1,149 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/bitfield.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/peci.h>
+
+#define CPU_ID_MODEL_MASK      GENMASK(7, 4)
+#define CPU_ID_FAMILY_MASK     GENMASK(11, 8)
+#define CPU_ID_EXT_MODEL_MASK  GENMASK(19, 16)
+#define CPU_ID_EXT_FAMILY_MASK GENMASK(27, 20)

drivers/mfd/intel-peci-client.c line 24

Quoted 10 lines
drivers/mfd/intel-peci-client.c new file +10 -0
+
+#define LOWER_NIBBLE_MASK      GENMASK(3, 0)
+#define UPPER_NIBBLE_MASK      GENMASK(7, 4)
+#define LOWER_BYTE_MASK        GENMASK(7, 0)
+#define UPPER_BYTE_MASK        GENMASK(16, 8)
+
+static struct mfd_cell peci_functions[] = {
+	{ .name = "peci-cputemp", },
+	{ .name = "peci-dimmtemp", },
+	/* TODO: Add additional PECI sideband functions into here */

No need for this comment. It's implied.

drivers/mfd/intel-peci-client.c line 29

Quoted 5 lines
drivers/mfd/intel-peci-client.c new file +5 -0
+};
+
+static const struct cpu_gen_info cpu_gen_info_table[] = {
+	{ /* Haswell Xeon */
+		.family        = 6, /* Family code */

Nit: Why don't you just define the number, instead of feeling the need to further clarify by providing a comment?

Quoted 84 lines
drivers/mfd/intel-peci-client.c new file +84 -0
+		.model         = INTEL_FAM6_HASWELL_X,
+		.core_max      = CORE_MAX_ON_HSX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_HSX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_HSX },
+	{ /* Broadwell Xeon */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_BROADWELL_X,
+		.core_max      = CORE_MAX_ON_BDX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_BDX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_BDX },
+	{ /* Skylake Xeon */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_SKYLAKE_X,
+		.core_max      = CORE_MAX_ON_SKX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_SKX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_SKX },
+	{ /* Skylake Xeon D */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_SKYLAKE_XD,
+		.core_max      = CORE_MAX_ON_SKXD,
+		.chan_rank_max = CHAN_RANK_MAX_ON_SKXD,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_SKXD },
+};
+
+static int peci_client_get_cpu_gen_info(struct peci_client_manager *priv)
+{
+	struct device *dev = &priv->client->dev;
+	u32 cpu_id;
+	u16 family;
+	u8 model;
+	int ret;
+	int i;
+
+	ret = peci_get_cpu_id(priv->client->adapter, priv->client->addr,
+			      &cpu_id);
+	if (ret)
+		return ret;
+
+	family = FIELD_PREP(LOWER_BYTE_MASK,
+			    FIELD_GET(CPU_ID_FAMILY_MASK, cpu_id)) |
+		 FIELD_PREP(UPPER_BYTE_MASK,
+			    FIELD_GET(CPU_ID_EXT_FAMILY_MASK, cpu_id));
+	model = FIELD_PREP(LOWER_NIBBLE_MASK,
+			   FIELD_GET(CPU_ID_MODEL_MASK, cpu_id)) |
+		FIELD_PREP(UPPER_NIBBLE_MASK,
+			   FIELD_GET(CPU_ID_EXT_MODEL_MASK, cpu_id));
+
+	for (i = 0; i < ARRAY_SIZE(cpu_gen_info_table); i++) {
+		const struct cpu_gen_info *cpu_info = &cpu_gen_info_table[i];
+
+		if (family == cpu_info->family && model == cpu_info->model) {
+			priv->gen_info = cpu_info;
+			break;
+		}
+	}
+
+	if (!priv->gen_info) {
+		dev_err(dev, "Can't support this CPU: 0x%x\n", cpu_id);
+		ret = -ENODEV;
+	}
+
+	return ret;
+}
+
+static int peci_client_probe(struct peci_client *client)
+{
+	struct device *dev = &client->dev;
+	struct peci_client_manager *priv;
+	uint cpu_no;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, priv);
+	priv->client = client;
+	cpu_no = client->addr - PECI_BASE_ADDR;
+
+	ret = peci_client_get_cpu_gen_info(priv);
+	if (ret)
+		return ret;
+
+	ret = devm_mfd_add_devices(dev, cpu_no, peci_functions,

drivers/mfd/intel-peci-client.c line 123

Quoted 10 lines
drivers/mfd/intel-peci-client.c new file +10 -0
+				   ARRAY_SIZE(peci_functions), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(dev, "Failed to register child devices: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_OF)

#ifdef CONFIG_OF

drivers/mfd/intel-peci-client.c line 129

Quoted 6 lines
drivers/mfd/intel-peci-client.c new file +6 -0
+static const struct of_device_id peci_client_of_table[] = {
+	{ .compatible = "intel,peci-client" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, peci_client_of_table);
+#endif /* CONFIG_OF */

Please remove this comment. It doesn't provide anything here.

drivers/mfd/intel-peci-client.c line 135

Quoted 5 lines
drivers/mfd/intel-peci-client.c new file +5 -0
+static const struct peci_device_id peci_client_ids[] = {
+	{ .name = "peci-client" },
+	{ }
+};
+MODULE_DEVICE_TABLE(peci, peci_client_ids);

Is this a requirement? If so, why?

We're trying to get rid of unnecessary tables.

Please grep for "probe_new".

Quoted 124 lines
drivers/mfd/intel-peci-client.c new file +13 -0
+static struct peci_driver peci_client_driver = {
+	.probe    = peci_client_probe,
+	.id_table = peci_client_ids,
+	.driver   = {
+		.name           = KBUILD_MODNAME,
+		.of_match_table = of_match_ptr(peci_client_of_table),
+	},
+};
+module_peci_driver(peci_client_driver);
+
+MODULE_AUTHOR("Jae Hyun Yoo <[email protected]>");
+MODULE_DESCRIPTION("PECI client driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/intel-peci-client.h new file +105 -0
new file mode 100644
index 000000000000..9854303bbc26
@@ -0,0 +1,117 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018-2019 Intel Corporation */
+
+#ifndef __LINUX_MFD_INTEL_PECI_CLIENT_H
+#define __LINUX_MFD_INTEL_PECI_CLIENT_H
+
+#include <linux/peci.h>
+
+#if IS_ENABLED(CONFIG_X86)
+#include <asm/intel-family.h>
+#else
+/*
+ * Architectures other than x86 cannot include the header file so define these
+ * at here. These are needed for detecting type of client x86 CPUs behind a PECI
+ * connection.
+ */
+#define INTEL_FAM6_HASWELL_X		0x3F
+#define INTEL_FAM6_BROADWELL_X		0x4F
+#define INTEL_FAM6_SKYLAKE_X		0x55
+#define INTEL_FAM6_SKYLAKE_XD		0x56
+#endif
+
+#define CORE_MAX_ON_HSX        18 /* Max number of cores on Haswell */
+#define CHAN_RANK_MAX_ON_HSX   8  /* Max number of channel ranks on Haswell */
+#define DIMM_IDX_MAX_ON_HSX    3  /* Max DIMM index per channel on Haswell */
+
+#define CORE_MAX_ON_BDX        24 /* Max number of cores on Broadwell */
+#define CHAN_RANK_MAX_ON_BDX   4  /* Max number of channel ranks on Broadwell */
+#define DIMM_IDX_MAX_ON_BDX    3  /* Max DIMM index per channel on Broadwell */
+
+#define CORE_MAX_ON_SKX        28 /* Max number of cores on Skylake */
+#define CHAN_RANK_MAX_ON_SKX   6  /* Max number of channel ranks on Skylake */
+#define DIMM_IDX_MAX_ON_SKX    2  /* Max DIMM index per channel on Skylake */
+
+#define CORE_MAX_ON_SKXD       16 /* Max number of cores on Skylake D */
+#define CHAN_RANK_MAX_ON_SKXD  2  /* Max number of channel ranks on Skylake D */
+#define DIMM_IDX_MAX_ON_SKXD   2  /* Max DIMM index per channel on Skylake D */
+
+#define CORE_NUMS_MAX          CORE_MAX_ON_SKX
+#define CHAN_RANK_MAX          CHAN_RANK_MAX_ON_HSX
+#define DIMM_IDX_MAX           DIMM_IDX_MAX_ON_HSX
+#define DIMM_NUMS_MAX          (CHAN_RANK_MAX * DIMM_IDX_MAX)
+
+/**
+ * struct cpu_gen_info - CPU generation specific information
+ * @family: CPU family ID
+ * @model: CPU model
+ * @core_max: max number of cores
+ * @chan_rank_max: max number of channel ranks
+ * @dimm_idx_max: max number of DIMM indices
+ *
+ * CPU generation specific information to identify maximum number of cores and
+ * DIMM slots.
+ */
+struct cpu_gen_info {
+	u16  family;
+	u8   model;
+	uint core_max;
+	uint chan_rank_max;
+	uint dimm_idx_max;
+};
+
+/**
+ * struct peci_client_manager - PECI client manager information
+ * @client; pointer to the PECI client
+ * @name: PECI client manager name
+ * @gen_info: CPU generation info of the detected CPU
+ *
+ * PECI client manager information for managing PECI sideband functions on a CPU
+ * client.
+ */
+struct peci_client_manager {
+	struct peci_client *client;
+	char name[PECI_NAME_SIZE];
+	const struct cpu_gen_info *gen_info;
+};
+
+/**
+ * peci_client_read_package_config - read from the Package Configuration Space
+ * @priv: driver private data structure
+ * @index: encoding index for the requested service
+ * @param: parameter to specify the exact data being requested
+ * @data: data buffer to store the result
+ * Context: can sleep
+ *
+ * A generic PECI command that provides read access to the
+ * "Package Configuration Space" that is maintained by the PCU, including
+ * various power and thermal management functions. Typical PCS read services
+ * supported by the processor may include access to temperature data, energy
+ * status, run time information, DIMM temperatures and so on.
+ *
+ * Return: zero on success, else a negative error code.
+ */
+static inline int
+peci_client_read_package_config(struct peci_client_manager *priv,
+				u8 index, u16 param, u8 *data)
+{
+	struct peci_rd_pkg_cfg_msg msg;
+	int ret;
+
+	msg.addr = priv->client->addr;
+	msg.index = index;
+	msg.param = param;
+	msg.rx_len = 4;
+

include/linux/mfd/intel-peci-client.h line 115

Quoted 10 lines
include/linux/mfd/intel-peci-client.h new file +10 -0
+	ret = peci_command(priv->client->adapter, PECI_CMD_RD_PKG_CFG, &msg);
+	if (msg.cc != PECI_DEV_CC_SUCCESS)
+		ret = -EAGAIN;
+	if (ret)
+		return ret;
+
+	memcpy(data, msg.pkg_config, 4);
+
+	return 0;
+}

Where is this function used?

Quoted 1 line
include/linux/mfd/intel-peci-client.h new file +1 -0
+#endif /* __LINUX_MFD_INTEL_PECI_CLIENT_H */
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#25 lore raw

Re: [PATCH v11 11/14] mfd: intel-peci-client: Add Intel PECI client driver

Hi Lee,

Quoted 89 lines · Lee Jones
Quoted 87 lines · Jae Hyun Yoo

This commit adds Intel PECI client driver.

Cc Lee Jones <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Rob Herring <[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]>

---
Changes since v10:
- Fixed minor style issues.

  drivers/mfd/Kconfig                   |  17 +++
  drivers/mfd/Makefile                  |   1 +
  drivers/mfd/intel-peci-client.c       | 149 ++++++++++++++++++++++++++
  include/linux/mfd/intel-peci-client.h | 117 ++++++++++++++++++++
  4 files changed, 284 insertions(+)

create mode 100644 drivers/mfd/intel-peci-client.c create mode 100644 include/linux/mfd/intel-peci-client.h

drivers/mfd/Kconfig +17 -0
index 420900852166..7022e54a4703 100644
@@ -632,6 +632,23 @@ config MFD_INTEL_MSIC
  	  Passage) chip. This chip embeds audio, battery, GPIO, etc.
  	  devices used in Intel Medfield platforms.
 
+config MFD_INTEL_PECI_CLIENT
+	tristate "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.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called intel-peci-client.
+
  config MFD_IPAQ_MICRO
  	bool "Atmel Micro ASIC (iPAQ h3100/h3600/h3700) Support"
  	depends on SA1100_H3100 || SA1100_H3600
drivers/mfd/Makefile +1 -0
index aed99f08739f..91c6fda5cec6 100644
@@ -211,6 +211,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 +18 -0
new file mode 100644
index 000000000000..18bf0af0e09e
@@ -0,0 +1,149 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/bitfield.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/peci.h>
+
+#define CPU_ID_MODEL_MASK      GENMASK(7, 4)
+#define CPU_ID_FAMILY_MASK     GENMASK(11, 8)
+#define CPU_ID_EXT_MODEL_MASK  GENMASK(19, 16)
+#define CPU_ID_EXT_FAMILY_MASK GENMASK(27, 20)
+
+#define LOWER_NIBBLE_MASK      GENMASK(3, 0)
+#define UPPER_NIBBLE_MASK      GENMASK(7, 4)
+#define LOWER_BYTE_MASK        GENMASK(7, 0)
Quoted 8 lines

drivers/mfd/intel-peci-client.c line 24

Quoted 6 lines
drivers/mfd/intel-peci-client.c new file +6 -0
+#define UPPER_BYTE_MASK        GENMASK(16, 8)
+
+static struct mfd_cell peci_functions[] = {
+	{ .name = "peci-cputemp", },
+	{ .name = "peci-dimmtemp", },
+	/* TODO: Add additional PECI sideband functions into here */

No need for this comment. It's implied.

I see. I'll remove this comment.

Quoted 8 lines

drivers/mfd/intel-peci-client.c line 29

Quoted 5 lines
drivers/mfd/intel-peci-client.c new file +5 -0
+};
+
+static const struct cpu_gen_info cpu_gen_info_table[] = {
+	{ /* Haswell Xeon */
+		.family        = 6, /* Family code */

Nit: Why don't you just define the number, instead of feeling the need to further clarify by providing a comment?

Makes sense. Will define the number.

Quoted 88 lines
Quoted 88 lines
drivers/mfd/intel-peci-client.c new file +88 -0
+		.model         = INTEL_FAM6_HASWELL_X,
+		.core_max      = CORE_MAX_ON_HSX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_HSX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_HSX },
+	{ /* Broadwell Xeon */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_BROADWELL_X,
+		.core_max      = CORE_MAX_ON_BDX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_BDX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_BDX },
+	{ /* Skylake Xeon */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_SKYLAKE_X,
+		.core_max      = CORE_MAX_ON_SKX,
+		.chan_rank_max = CHAN_RANK_MAX_ON_SKX,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_SKX },
+	{ /* Skylake Xeon D */
+		.family        = 6, /* Family code */
+		.model         = INTEL_FAM6_SKYLAKE_XD,
+		.core_max      = CORE_MAX_ON_SKXD,
+		.chan_rank_max = CHAN_RANK_MAX_ON_SKXD,
+		.dimm_idx_max  = DIMM_IDX_MAX_ON_SKXD },
+};
+
+static int peci_client_get_cpu_gen_info(struct peci_client_manager *priv)
+{
+	struct device *dev = &priv->client->dev;
+	u32 cpu_id;
+	u16 family;
+	u8 model;
+	int ret;
+	int i;
+
+	ret = peci_get_cpu_id(priv->client->adapter, priv->client->addr,
+			      &cpu_id);
+	if (ret)
+		return ret;
+
+	family = FIELD_PREP(LOWER_BYTE_MASK,
+			    FIELD_GET(CPU_ID_FAMILY_MASK, cpu_id)) |
+		 FIELD_PREP(UPPER_BYTE_MASK,
+			    FIELD_GET(CPU_ID_EXT_FAMILY_MASK, cpu_id));
+	model = FIELD_PREP(LOWER_NIBBLE_MASK,
+			   FIELD_GET(CPU_ID_MODEL_MASK, cpu_id)) |
+		FIELD_PREP(UPPER_NIBBLE_MASK,
+			   FIELD_GET(CPU_ID_EXT_MODEL_MASK, cpu_id));
+
+	for (i = 0; i < ARRAY_SIZE(cpu_gen_info_table); i++) {
+		const struct cpu_gen_info *cpu_info = &cpu_gen_info_table[i];
+
+		if (family == cpu_info->family && model == cpu_info->model) {
+			priv->gen_info = cpu_info;
+			break;
+		}
+	}
+
+	if (!priv->gen_info) {
+		dev_err(dev, "Can't support this CPU: 0x%x\n", cpu_id);
+		ret = -ENODEV;
+	}
+
+	return ret;
+}
+
+static int peci_client_probe(struct peci_client *client)
+{
+	struct device *dev = &client->dev;
+	struct peci_client_manager *priv;
+	uint cpu_no;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, priv);
+	priv->client = client;
+	cpu_no = client->addr - PECI_BASE_ADDR;
+
+	ret = peci_client_get_cpu_gen_info(priv);
+	if (ret)
+		return ret;
+
+	ret = devm_mfd_add_devices(dev, cpu_no, peci_functions,
+				   ARRAY_SIZE(peci_functions), NULL, 0, NULL);
+	if (ret < 0) {
+		dev_err(dev, "Failed to register child devices: %d\n", ret);
+		return ret;
Quoted 8 lines

drivers/mfd/intel-peci-client.c line 123

Quoted 6 lines
drivers/mfd/intel-peci-client.c new file +6 -0
+	}
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_OF)

#ifdef CONFIG_OF

Will fix it.

Quoted 8 lines

drivers/mfd/intel-peci-client.c line 129

Quoted 6 lines
drivers/mfd/intel-peci-client.c new file +6 -0
+static const struct of_device_id peci_client_of_table[] = {
+	{ .compatible = "intel,peci-client" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, peci_client_of_table);
+#endif /* CONFIG_OF */

Please remove this comment. It doesn't provide anything here.

I see. I'll remove this comment.

Quoted 11 lines

drivers/mfd/intel-peci-client.c line 135

Quoted 5 lines
drivers/mfd/intel-peci-client.c new file +5 -0
+static const struct peci_device_id peci_client_ids[] = {
+	{ .name = "peci-client" },
+	{ }
+};
+MODULE_DEVICE_TABLE(peci, peci_client_ids);

Is this a requirement? If so, why?

We're trying to get rid of unnecessary tables.

Please grep for "probe_new".

This is needed because peci-core.c provides sub tree searching while registering a peci bus using of_match_device, also it provides runtime registration through sysfs interface using ID match just like I2C subsystem does. The probe member in 'struct peci_driver' is defined as the new style like this:

struct peci_driver {
	int (*probe)(struct peci_client *client);
	[....]
}
Quoted 128 lines
Quoted 128 lines
drivers/mfd/intel-peci-client.c new file +13 -0
+static struct peci_driver peci_client_driver = {
+	.probe    = peci_client_probe,
+	.id_table = peci_client_ids,
+	.driver   = {
+		.name           = KBUILD_MODNAME,
+		.of_match_table = of_match_ptr(peci_client_of_table),
+	},
+};
+module_peci_driver(peci_client_driver);
+
+MODULE_AUTHOR("Jae Hyun Yoo <[email protected]>");
+MODULE_DESCRIPTION("PECI client driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/intel-peci-client.h new file +109 -0
new file mode 100644
index 000000000000..9854303bbc26
@@ -0,0 +1,117 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018-2019 Intel Corporation */
+
+#ifndef __LINUX_MFD_INTEL_PECI_CLIENT_H
+#define __LINUX_MFD_INTEL_PECI_CLIENT_H
+
+#include <linux/peci.h>
+
+#if IS_ENABLED(CONFIG_X86)
+#include <asm/intel-family.h>
+#else
+/*
+ * Architectures other than x86 cannot include the header file so define these
+ * at here. These are needed for detecting type of client x86 CPUs behind a PECI
+ * connection.
+ */
+#define INTEL_FAM6_HASWELL_X		0x3F
+#define INTEL_FAM6_BROADWELL_X		0x4F
+#define INTEL_FAM6_SKYLAKE_X		0x55
+#define INTEL_FAM6_SKYLAKE_XD		0x56
+#endif
+
+#define CORE_MAX_ON_HSX        18 /* Max number of cores on Haswell */
+#define CHAN_RANK_MAX_ON_HSX   8  /* Max number of channel ranks on Haswell */
+#define DIMM_IDX_MAX_ON_HSX    3  /* Max DIMM index per channel on Haswell */
+
+#define CORE_MAX_ON_BDX        24 /* Max number of cores on Broadwell */
+#define CHAN_RANK_MAX_ON_BDX   4  /* Max number of channel ranks on Broadwell */
+#define DIMM_IDX_MAX_ON_BDX    3  /* Max DIMM index per channel on Broadwell */
+
+#define CORE_MAX_ON_SKX        28 /* Max number of cores on Skylake */
+#define CHAN_RANK_MAX_ON_SKX   6  /* Max number of channel ranks on Skylake */
+#define DIMM_IDX_MAX_ON_SKX    2  /* Max DIMM index per channel on Skylake */
+
+#define CORE_MAX_ON_SKXD       16 /* Max number of cores on Skylake D */
+#define CHAN_RANK_MAX_ON_SKXD  2  /* Max number of channel ranks on Skylake D */
+#define DIMM_IDX_MAX_ON_SKXD   2  /* Max DIMM index per channel on Skylake D */
+
+#define CORE_NUMS_MAX          CORE_MAX_ON_SKX
+#define CHAN_RANK_MAX          CHAN_RANK_MAX_ON_HSX
+#define DIMM_IDX_MAX           DIMM_IDX_MAX_ON_HSX
+#define DIMM_NUMS_MAX          (CHAN_RANK_MAX * DIMM_IDX_MAX)
+
+/**
+ * struct cpu_gen_info - CPU generation specific information
+ * @family: CPU family ID
+ * @model: CPU model
+ * @core_max: max number of cores
+ * @chan_rank_max: max number of channel ranks
+ * @dimm_idx_max: max number of DIMM indices
+ *
+ * CPU generation specific information to identify maximum number of cores and
+ * DIMM slots.
+ */
+struct cpu_gen_info {
+	u16  family;
+	u8   model;
+	uint core_max;
+	uint chan_rank_max;
+	uint dimm_idx_max;
+};
+
+/**
+ * struct peci_client_manager - PECI client manager information
+ * @client; pointer to the PECI client
+ * @name: PECI client manager name
+ * @gen_info: CPU generation info of the detected CPU
+ *
+ * PECI client manager information for managing PECI sideband functions on a CPU
+ * client.
+ */
+struct peci_client_manager {
+	struct peci_client *client;
+	char name[PECI_NAME_SIZE];
+	const struct cpu_gen_info *gen_info;
+};
+
+/**
+ * peci_client_read_package_config - read from the Package Configuration Space
+ * @priv: driver private data structure
+ * @index: encoding index for the requested service
+ * @param: parameter to specify the exact data being requested
+ * @data: data buffer to store the result
+ * Context: can sleep
+ *
+ * A generic PECI command that provides read access to the
+ * "Package Configuration Space" that is maintained by the PCU, including
+ * various power and thermal management functions. Typical PCS read services
+ * supported by the processor may include access to temperature data, energy
+ * status, run time information, DIMM temperatures and so on.
+ *
+ * Return: zero on success, else a negative error code.
+ */
+static inline int
+peci_client_read_package_config(struct peci_client_manager *priv,
+				u8 index, u16 param, u8 *data)
+{
+	struct peci_rd_pkg_cfg_msg msg;
+	int ret;
+
+	msg.addr = priv->client->addr;
+	msg.index = index;
+	msg.param = param;
+	msg.rx_len = 4;
+
+	ret = peci_command(priv->client->adapter, PECI_CMD_RD_PKG_CFG, &msg);
+	if (msg.cc != PECI_DEV_CC_SUCCESS)
+		ret = -EAGAIN;
+	if (ret)
Quoted 8 lines

include/linux/mfd/intel-peci-client.h line 115

Quoted 6 lines
include/linux/mfd/intel-peci-client.h new file +6 -0
+		return ret;
+
+	memcpy(data, msg.pkg_config, 4);
+
+	return 0;
+}

Where is this function used?

This function is used in MFD cell drivers that are included in this patch set, peci-cputemp and peci-dimmtemp drivers. I moved it from intel-peci-client.c to this header file as you commented in the previous review spin. I also thought about moving it into peci-hwmon.h but this command macro is a generic thing for Intel CPUs so I moved into here.

Thanks a lot for your review!

-Jae

Quoted 2 lines
Quoted 1 line
include/linux/mfd/intel-peci-client.h new file +1 -0
+#endif /* __LINUX_MFD_INTEL_PECI_CLIENT_H */
#26 lore raw

PATCH v11 12/14 Documentation: hwmon: Add documents for PECI hwmon drivers

In reply to Jae Hyun Yoo

This commit adds hwmon documents for PECI cputemp and dimmtemp drivers.

---
Changes since v10:
- Changed documents format to rst.

 Documentation/hwmon/index.rst         |  2 +
 Documentation/hwmon/peci-cputemp.rst  | 95 +++++++++++++++++++++++++++
 Documentation/hwmon/peci-dimmtemp.rst | 60 +++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 Documentation/hwmon/peci-cputemp.rst
 create mode 100644 Documentation/hwmon/peci-dimmtemp.rst
Documentation/hwmon/index.rst +2 -0
index 43cc605741ea..8cb0265c8e9b 100644
@@ -131,6 +131,8 @@ Hardware Monitoring Kernel Drivers
    pc87360
    pc87427
    pcf8591
+   peci-cputemp
+   peci-dimmtemp
    pmbus
    powr1220
    pxe1610
Documentation/hwmon/peci-cputemp.rst new file +95 -0

96 lines not on this page · raw message

Documentation/hwmon/peci-dimmtemp.rst new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.17.1
#27 lore raw

PATCH v11 13/14 hwmon: Add PECI cputemp driver

In reply to Jae Hyun Yoo

This commit adds PECI cputemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added DTS temperature which is more thermal control friendlier than Die temperature.
- Fixed minor bugs and style issues.

 drivers/hwmon/Kconfig        |  14 ++
 drivers/hwmon/Makefile       |   1 +
 drivers/hwmon/peci-cputemp.c | 448 +++++++++++++++++++++++++++++++++++
 drivers/hwmon/peci-hwmon.h   |  46 ++++
 4 files changed, 509 insertions(+)
 create mode 100644 drivers/hwmon/peci-cputemp.c
 create mode 100644 drivers/hwmon/peci-hwmon.h
drivers/hwmon/Kconfig +14 -0
index 23dfe848979a..b6604759579c 100644
@@ -1349,6 +1349,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 client"
+	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 <file:Documentation/hwmon/peci-cputemp.rst> 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
index 6db5db9cdc29..d6fea48697af 100644
@@ -144,6 +144,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 +448 -0

448 lines not on this page · raw message

drivers/hwmon/peci-hwmon.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#28 lore raw

Re: [PATCH v11 13/14] hwmon: Add PECI cputemp driver

Quoted 79 lines · Jae Hyun Yoo

This commit adds PECI cputemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added DTS temperature which is more thermal control friendlier than Die temperature.
- Fixed minor bugs and style issues.

  drivers/hwmon/Kconfig        |  14 ++
  drivers/hwmon/Makefile       |   1 +
  drivers/hwmon/peci-cputemp.c | 448 +++++++++++++++++++++++++++++++++++
  drivers/hwmon/peci-hwmon.h   |  46 ++++
  4 files changed, 509 insertions(+)

create mode 100644 drivers/hwmon/peci-cputemp.c
create mode 100644 drivers/hwmon/peci-hwmon.h

drivers/hwmon/Kconfig +14 -0
index 23dfe848979a..b6604759579c 100644
@@ -1349,6 +1349,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 client"
+	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 <file:Documentation/hwmon/peci-cputemp.rst> 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
index 6db5db9cdc29..d6fea48697af 100644
@@ -144,6 +144,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 +3 -0
new file mode 100644
index 000000000000..70ced9f9299f
@@ -0,0 +1,448 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+

drivers/hwmon/peci-cputemp.c line 13

Quoted 10 lines
drivers/hwmon/peci-cputemp.c new file +10 -0
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include "peci-hwmon.h"
+
+#define DEFAULT_CHANNEL_NUMS   5
+#define CORETEMP_CHANNEL_NUMS  CORE_NUMS_MAX

Why not just use CORE_NUMS_MAX ?

Quoted 62 lines
drivers/hwmon/peci-cputemp.c new file +62 -0
+#define CPUTEMP_CHANNEL_NUMS   (DEFAULT_CHANNEL_NUMS + CORETEMP_CHANNEL_NUMS)
+
+struct temp_group {
+	struct peci_sensor_data die;
+	struct peci_sensor_data dts;
+	struct peci_sensor_data tcontrol;
+	struct peci_sensor_data tthrottle;
+	struct peci_sensor_data tjmax;
+	struct peci_sensor_data core[CORETEMP_CHANNEL_NUMS];
+};
+
+struct peci_cputemp {
+	struct peci_client_manager *mgr;
+	struct device *dev;
+	char name[PECI_NAME_SIZE];
+	const struct cpu_gen_info *gen_info;
+	struct temp_group temp;
+	u64 core_mask;
+	u32 temp_config[CPUTEMP_CHANNEL_NUMS + 1];
+	uint config_idx;
+	struct hwmon_channel_info temp_info;
+	const struct hwmon_channel_info *info[2];
+	struct hwmon_chip_info chip;
+};
+
+enum cputemp_channels {
+	channel_die,
+	channel_dts,
+	channel_tcontrol,
+	channel_tthrottle,
+	channel_tjmax,
+	channel_core,
+};
+
+static const u32 config_table[DEFAULT_CHANNEL_NUMS + 1] = {
+	/* Die temperature */
+	HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+	HWMON_T_CRIT_HYST,
+
+	/* DTS margin */
+	HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+	HWMON_T_CRIT_HYST,
+
+	/* Tcontrol temperature */
+	HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_CRIT,
+
+	/* Tthrottle temperature */
+	HWMON_T_LABEL | HWMON_T_INPUT,
+
+	/* Tjmax temperature */
+	HWMON_T_LABEL | HWMON_T_INPUT,
+
+	/* Core temperature - for all core channels */
+	HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+	HWMON_T_CRIT_HYST,
+};
+
+static const char *cputemp_label[CPUTEMP_CHANNEL_NUMS] = {
+	"Die",
+	"DTS",
+	"Tcontrol",
+	"Tthrottle",

drivers/hwmon/peci-cputemp.c line 85

Quoted 10 lines
drivers/hwmon/peci-cputemp.c new file +10 -0
+	"Tjmax",
+	"Core 0", "Core 1", "Core 2", "Core 3",
+	"Core 4", "Core 5", "Core 6", "Core 7",
+	"Core 8", "Core 9", "Core 10", "Core 11",
+	"Core 12", "Core 13", "Core 14", "Core 15",
+	"Core 16", "Core 17", "Core 18", "Core 19",
+	"Core 20", "Core 21", "Core 22", "Core 23",
+	"Core 24", "Core 25", "Core 26", "Core 27",
+};
+

What happens if CPUTEMP_CHANNEL_NUMS is increased in the future, and some of this array includes NULL pointers because this file doesn't track CORE_NUMS_MAX ?

drivers/hwmon/peci-cputemp.c line 88

Quoted 3 lines
drivers/hwmon/peci-cputemp.c new file +3 -0
+static s32 ten_dot_six_to_millidegree(s32 val)
+{
+	return ((val ^ 0x8000) - 0x8000) * 1000 / 64;

Normally I suggest to use DIV_ROUND_CLOSEST in situations like this to improve rounding, but ultimately that is your call.

Quoted 106 lines
drivers/hwmon/peci-cputemp.c new file +106 -0
+}
+
+static int get_temp_targets(struct peci_cputemp *priv)
+{
+	s32 tthrottle_offset;
+	s32 tcontrol_margin;
+	u8  pkg_cfg[4];
+	int ret;
+
+	/*
+	 * Just use only the tcontrol marker to determine if target values need
+	 * update.
+	 */
+	if (!peci_sensor_need_update(&priv->temp.tcontrol))
+		return 0;
+
+	ret = peci_client_read_package_config(priv->mgr,
+					      PECI_MBX_INDEX_TEMP_TARGET, 0,
+					      pkg_cfg);
+	if (ret)
+		return ret;
+
+	priv->temp.tjmax.value = pkg_cfg[2] * 1000;
+
+	tcontrol_margin = pkg_cfg[1];
+	tcontrol_margin = ((tcontrol_margin ^ 0x80) - 0x80) * 1000;
+	priv->temp.tcontrol.value = priv->temp.tjmax.value - tcontrol_margin;
+
+	tthrottle_offset = (pkg_cfg[3] & 0x2f) * 1000;
+	priv->temp.tthrottle.value = priv->temp.tjmax.value - tthrottle_offset;
+
+	peci_sensor_mark_updated(&priv->temp.tcontrol);
+
+	return 0;
+}
+
+static int get_die_temp(struct peci_cputemp *priv)
+{
+	struct peci_get_temp_msg msg;
+	int ret;
+
+	if (!peci_sensor_need_update(&priv->temp.die))
+		return 0;
+
+	msg.addr = priv->mgr->client->addr;
+
+	ret = peci_command(priv->mgr->client->adapter, PECI_CMD_GET_TEMP, &msg);
+	if (ret)
+		return ret;
+
+	/* Note that the tjmax should be available before calling it */
+	priv->temp.die.value = priv->temp.tjmax.value +
+			       (msg.temp_raw * 1000 / 64);
+
+	peci_sensor_mark_updated(&priv->temp.die);
+
+	return 0;
+}
+
+static int get_dts(struct peci_cputemp *priv)
+{
+	s32 dts_margin;
+	u8  pkg_cfg[4];
+	int ret;
+
+	if (!peci_sensor_need_update(&priv->temp.dts))
+		return 0;
+
+	ret = peci_client_read_package_config(priv->mgr,
+					      PECI_MBX_INDEX_DTS_MARGIN, 0,
+					      pkg_cfg);
+
+	if (ret)
+		return ret;
+
+	dts_margin = (pkg_cfg[1] << 8) | pkg_cfg[0];
+
+	/**
+	 * Processors return a value of DTS reading in 10.6 format
+	 * (10 bits signed decimal, 6 bits fractional).
+	 * Error codes:
+	 *   0x8000: General sensor error
+	 *   0x8001: Reserved
+	 *   0x8002: Underflow on reading value
+	 *   0x8003-0x81ff: Reserved
+	 */
+	if (dts_margin >= 0x8000 && dts_margin <= 0x81ff)
+		return -EIO;
+
+	dts_margin = ten_dot_six_to_millidegree(dts_margin);
+
+	/* Note that the tcontrol should be available before calling it */
+	priv->temp.dts.value = priv->temp.tcontrol.value - dts_margin;
+
+	peci_sensor_mark_updated(&priv->temp.dts);
+
+	return 0;
+}
+
+static int get_core_temp(struct peci_cputemp *priv, int core_index)
+{
+	s32 core_dts_margin;
+	u8  pkg_cfg[4];
+	int ret;
+
+	if (!peci_sensor_need_update(&priv->temp.core[core_index]))

drivers/hwmon/peci-cputemp.c line 204

Quoted 10 lines
drivers/hwmon/peci-cputemp.c new file +10 -0
+		return 0;
+
+	ret = peci_client_read_package_config(priv->mgr,
+					      PECI_MBX_INDEX_PER_CORE_DTS_TEMP,
+					      core_index, pkg_cfg);
+	if (ret)
+		return ret;
+
+	core_dts_margin = le16_to_cpup((__le16 *)pkg_cfg);
+

Any special readon for using the helper function here but not above ?

Quoted 297 lines
drivers/hwmon/peci-cputemp.c new file +244 -0
+	/*
+	 * Processors return a value of the core DTS reading in 10.6 format
+	 * (10 bits signed decimal, 6 bits fractional).
+	 * Error codes:
+	 *   0x8000: General sensor error
+	 *   0x8001: Reserved
+	 *   0x8002: Underflow on reading value
+	 *   0x8003-0x81ff: Reserved
+	 */
+	if (core_dts_margin >= 0x8000 && core_dts_margin <= 0x81ff)
+		return -EIO;
+
+	core_dts_margin = ten_dot_six_to_millidegree(core_dts_margin);
+
+	/* Note that the tjmax should be available before calling it */
+	priv->temp.core[core_index].value = priv->temp.tjmax.value +
+					    core_dts_margin;
+
+	peci_sensor_mark_updated(&priv->temp.core[core_index]);
+
+	return 0;
+}
+
+static int cputemp_read_string(struct device *dev,
+			       enum hwmon_sensor_types type,
+			       u32 attr, int channel, const char **str)
+{
+	if (attr != hwmon_temp_label)
+		return -EOPNOTSUPP;
+
+	*str = cputemp_label[channel];
+
+	return 0;
+}
+
+static int cputemp_read(struct device *dev,
+			enum hwmon_sensor_types type,
+			u32 attr, int channel, long *val)
+{
+	struct peci_cputemp *priv = dev_get_drvdata(dev);
+	int ret, core_index;
+
+	if (channel >= CPUTEMP_CHANNEL_NUMS ||
+	    !(priv->temp_config[channel] & BIT(attr)))
+		return -EOPNOTSUPP;
+
+	ret = get_temp_targets(priv);
+	if (ret)
+		return ret;
+
+	switch (attr) {
+	case hwmon_temp_input:
+		switch (channel) {
+		case channel_die:
+			ret = get_die_temp(priv);
+			if (ret)
+				break;
+
+			*val = priv->temp.die.value;
+			break;
+		case channel_dts:
+			ret = get_dts(priv);
+			if (ret)
+				break;
+
+			*val = priv->temp.dts.value;
+			break;
+		case channel_tcontrol:
+			*val = priv->temp.tcontrol.value;
+			break;
+		case channel_tthrottle:
+			*val = priv->temp.tthrottle.value;
+			break;
+		case channel_tjmax:
+			*val = priv->temp.tjmax.value;
+			break;
+		default:
+			core_index = channel - DEFAULT_CHANNEL_NUMS;
+			ret = get_core_temp(priv, core_index);
+			if (ret)
+				break;
+
+			*val = priv->temp.core[core_index].value;
+			break;
+		}
+		break;
+	case hwmon_temp_max:
+		*val = priv->temp.tcontrol.value;
+		break;
+	case hwmon_temp_crit:
+		*val = priv->temp.tjmax.value;
+		break;
+	case hwmon_temp_crit_hyst:
+		*val = priv->temp.tjmax.value - priv->temp.tcontrol.value;
+		break;
+	default:
+		ret = -EOPNOTSUPP;
+		break;
+	}
+
+	return ret;
+}
+
+static umode_t cputemp_is_visible(const void *data,
+				  enum hwmon_sensor_types type,
+				  u32 attr, int channel)
+{
+	const struct peci_cputemp *priv = data;
+
+	if (channel < ARRAY_SIZE(priv->temp_config) &&
+	    (priv->temp_config[channel] & BIT(attr)) &&
+	    (channel < DEFAULT_CHANNEL_NUMS ||
+	     (channel >= DEFAULT_CHANNEL_NUMS &&
+	      (priv->core_mask & BIT(channel - DEFAULT_CHANNEL_NUMS)))))
+		return 0444;
+
+	return 0;
+}
+
+static const struct hwmon_ops cputemp_ops = {
+	.is_visible = cputemp_is_visible,
+	.read_string = cputemp_read_string,
+	.read = cputemp_read,
+};
+
+static int check_resolved_cores(struct peci_cputemp *priv)
+{
+	struct peci_rd_pci_cfg_local_msg msg;
+	int ret;
+
+	/* Get the RESOLVED_CORES register value */
+	msg.addr = priv->mgr->client->addr;
+	msg.device = 30;
+	msg.function = 3;
+	msg.rx_len = 4;
+	msg.bus = 1;
+	msg.reg = 0xb4;
+
+	ret = peci_command(priv->mgr->client->adapter,
+			   PECI_CMD_RD_PCI_CFG_LOCAL, &msg);
+	if (msg.cc != PECI_DEV_CC_SUCCESS)
+		ret = -EAGAIN;
+	if (ret)
+		return ret;
+
+	priv->core_mask = le32_to_cpup((__le32 *)msg.pci_config);
+	if (!priv->core_mask)
+		return -EAGAIN;
+
+	dev_dbg(priv->dev, "Scanned resolved cores: 0x%llx\n", priv->core_mask);
+
+	return 0;
+}
+
+static int create_core_temp_info(struct peci_cputemp *priv)
+{
+	int ret, i;
+
+	ret = check_resolved_cores(priv);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < priv->gen_info->core_max; i++)
+		if (priv->core_mask & BIT(i))
+			while (priv->config_idx <= i + DEFAULT_CHANNEL_NUMS)
+				priv->temp_config[priv->config_idx++] =
+					config_table[channel_core];
+
+	return 0;
+}
+
+static int peci_cputemp_probe(struct platform_device *pdev)
+{
+	struct peci_client_manager *mgr = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct peci_cputemp *priv;
+	struct device *hwmon_dev;
+	int ret;
+
+	if ((mgr->client->adapter->cmd_mask &
+	    (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG))) !=
+	    (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG)))
+		return -ENODEV;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, priv);
+	priv->mgr = mgr;
+	priv->dev = dev;
+	priv->gen_info = mgr->gen_info;
+
+	snprintf(priv->name, PECI_NAME_SIZE, "peci_cputemp.cpu%d",
+		 mgr->client->addr - PECI_BASE_ADDR);
+
+	priv->temp_config[priv->config_idx++] = config_table[channel_die];
+	priv->temp_config[priv->config_idx++] = config_table[channel_dts];
+	priv->temp_config[priv->config_idx++] = config_table[channel_tcontrol];
+	priv->temp_config[priv->config_idx++] = config_table[channel_tthrottle];
+	priv->temp_config[priv->config_idx++] = config_table[channel_tjmax];
+
+	ret = create_core_temp_info(priv);
+	if (ret)
+		dev_dbg(dev, "Skipped creating core temp info\n");
+
+	priv->chip.ops = &cputemp_ops;
+	priv->chip.info = priv->info;
+
+	priv->info[0] = &priv->temp_info;
+
+	priv->temp_info.type = hwmon_temp;
+	priv->temp_info.config = priv->temp_config;
+
+	hwmon_dev = devm_hwmon_device_register_with_info(priv->dev,
+							 priv->name,
+							 priv,
+							 &priv->chip,
+							 NULL);
+
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	dev_dbg(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), priv->name);
+
+	return 0;
+}
+
+static const struct platform_device_id peci_cputemp_ids[] = {
+	{ .name = "peci-cputemp", .driver_data = 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, peci_cputemp_ids);
+
+static struct platform_driver peci_cputemp_driver = {
+	.probe    = peci_cputemp_probe,
+	.id_table = peci_cputemp_ids,
+	.driver   = { .name = KBUILD_MODNAME, },
+};
+module_platform_driver(peci_cputemp_driver);
+
+MODULE_AUTHOR("Jae Hyun Yoo <[email protected]>");
+MODULE_DESCRIPTION("PECI cputemp driver");
+MODULE_LICENSE("GPL v2");
drivers/hwmon/peci-hwmon.h new file +46 -0
new file mode 100644
index 000000000000..e0e3c901c6e4
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018-2019 Intel Corporation */
+
+#ifndef __PECI_HWMON_H
+#define __PECI_HWMON_H
+
+#include <linux/peci.h>
+
+#define TEMP_TYPE_PECI   6 /* Sensor type 6: Intel PECI */
+#define UPDATE_INTERVAL  HZ
+
+/**
+ * struct peci_sensor_data - PECI sensor information
+ * @valid: flag to indicate the sensor value is valid
+ * @value: sensor value in millidegree Celsius
+ * @last_updated: time of the last update in jiffies
+ */
+struct peci_sensor_data {
+	uint  valid;
+	s32   value;
+	ulong last_updated;
+};
+
+/**
+ * peci_sensor_need_update - check whether sensor update is needed or not
+ * @sensor: pointer to sensor data struct
+ *
+ * Return: true if update is needed, false if not.
+ */
+static inline bool peci_sensor_need_update(struct peci_sensor_data *sensor)
+{
+	return !sensor->valid ||
+	       time_after(jiffies, sensor->last_updated + UPDATE_INTERVAL);
+}
+
+/**
+ * peci_sensor_mark_updated - mark the sensor is updated
+ * @sensor: pointer to sensor data struct
+ */
+static inline void peci_sensor_mark_updated(struct peci_sensor_data *sensor)
+{
+	sensor->valid = 1;
+	sensor->last_updated = jiffies;
+}
+
+#endif /* __PECI_HWMON_H */
#29 lore raw

Re: [PATCH v11 13/14] hwmon: Add PECI cputemp driver

Hi Guenter,

Quoted 84 lines · Guenter Roeck
Quoted 83 lines · Jae Hyun Yoo

This commit adds PECI cputemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added DTS temperature which is more thermal control friendlier than Die temperature.
- Fixed minor bugs and style issues.

  drivers/hwmon/Kconfig        |  14 ++ drivers/hwmon/Makefile       |   1 + drivers/hwmon/peci-cputemp.c | 448 +++++++++++++++++++++++++++++++++++ drivers/hwmon/peci-hwmon.h   |  46 ++++

  4 files changed, 509 insertions(+)

  create mode 100644 drivers/hwmon/peci-cputemp.c
  create mode 100644 drivers/hwmon/peci-hwmon.h

drivers/hwmon/Kconfig +0 -0
index 23dfe848979a..b6604759579c 100644
@@ -1349,6 +1349,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 client"
+    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 <file:Documentation/hwmon/peci-cputemp.rst> for details.

drivers/hwmon/Kconfig +4 -0
+
+      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 +0 -0
index 6db5db9cdc29..d6fea48697af 100644
@@ -144,6 +144,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 +7 -0
new file mode 100644
index 000000000000..70ced9f9299f
@@ -0,0 +1,448 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
Quoted 8 lines

drivers/hwmon/peci-cputemp.c line 13

Quoted 6 lines
drivers/hwmon/peci-cputemp.c new file +6 -0
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include "peci-hwmon.h"
+
+#define DEFAULT_CHANNEL_NUMS   5
+#define CORETEMP_CHANNEL_NUMS  CORE_NUMS_MAX

Why not just use CORE_NUMS_MAX ?

For better readability in below code to represent max core numbers as core temp channel numbers. If you don't like it, I'll use CORE_NUMS_MAX as it is for the core temp channel numbers.

Quoted 69 lines
Quoted 69 lines
drivers/hwmon/peci-cputemp.c new file +1 -0
+#define CPUTEMP_CHANNEL_NUMS   (DEFAULT_CHANNEL_NUMS + 

CORETEMP_CHANNEL_NUMS)

drivers/hwmon/peci-cputemp.c new file +67 -0
+
+struct temp_group {
+    struct peci_sensor_data die;
+    struct peci_sensor_data dts;
+    struct peci_sensor_data tcontrol;
+    struct peci_sensor_data tthrottle;
+    struct peci_sensor_data tjmax;
+    struct peci_sensor_data core[CORETEMP_CHANNEL_NUMS];
+};
+
+struct peci_cputemp {
+    struct peci_client_manager *mgr;
+    struct device *dev;
+    char name[PECI_NAME_SIZE];
+    const struct cpu_gen_info *gen_info;
+    struct temp_group temp;
+    u64 core_mask;
+    u32 temp_config[CPUTEMP_CHANNEL_NUMS + 1];
+    uint config_idx;
+    struct hwmon_channel_info temp_info;
+    const struct hwmon_channel_info *info[2];
+    struct hwmon_chip_info chip;
+};
+
+enum cputemp_channels {
+    channel_die,
+    channel_dts,
+    channel_tcontrol,
+    channel_tthrottle,
+    channel_tjmax,
+    channel_core,
+};
+
+static const u32 config_table[DEFAULT_CHANNEL_NUMS + 1] = {
+    /* Die temperature */
+    HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+    HWMON_T_CRIT_HYST,
+
+    /* DTS margin */
+    HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+    HWMON_T_CRIT_HYST,
+
+    /* Tcontrol temperature */
+    HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_CRIT,
+
+    /* Tthrottle temperature */
+    HWMON_T_LABEL | HWMON_T_INPUT,
+
+    /* Tjmax temperature */
+    HWMON_T_LABEL | HWMON_T_INPUT,
+
+    /* Core temperature - for all core channels */
+    HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+    HWMON_T_CRIT_HYST,
+};
+
+static const char *cputemp_label[CPUTEMP_CHANNEL_NUMS] = {
+    "Die",
+    "DTS",
+    "Tcontrol",
+    "Tthrottle",
+    "Tjmax",
+    "Core 0", "Core 1", "Core 2", "Core 3",
+    "Core 4", "Core 5", "Core 6", "Core 7",
+    "Core 8", "Core 9", "Core 10", "Core 11",
+    "Core 12", "Core 13", "Core 14", "Core 15",
+    "Core 16", "Core 17", "Core 18", "Core 19",
Quoted 8 lines

drivers/hwmon/peci-cputemp.c

Quoted 4 lines

+    "Core 20", "Core 21", "Core 22", "Core 23",
+    "Core 24", "Core 25", "Core 26", "Core 27",

drivers/hwmon/peci-cputemp.c new file +2 -0
+};
+

What happens if CPUTEMP_CHANNEL_NUMS is increased in the future, and some of this array includes NULL pointers because this file doesn't track CORE_NUMS_MAX ?

Okay. It's reasonable concern. I'll fix it to make this driver generate the core temp label strings dynamically based on detected CPU generation information.

Quoted 6 lines

drivers/hwmon/peci-cputemp.c line 88

Quoted 3 lines
drivers/hwmon/peci-cputemp.c new file +3 -0
+static s32 ten_dot_six_to_millidegree(s32 val)
+{
+    return ((val ^ 0x8000) - 0x8000) * 1000 / 64;

Normally I suggest to use DIV_ROUND_CLOSEST in situations like this to improve rounding, but ultimately that is your call.

This is for conversion of 16-bit signed 10.6
(10 bits signed decimal, 6 bits fractional) format to 32-bits signed integer in millidegree units. It's right as it is.

Quoted 115 lines
Quoted 115 lines
drivers/hwmon/peci-cputemp.c new file +11 -0
+}
+
+static int get_temp_targets(struct peci_cputemp *priv)
+{
+    s32 tthrottle_offset;
+    s32 tcontrol_margin;
+    u8  pkg_cfg[4];
+    int ret;
+
+    /*
+     * Just use only the tcontrol marker to determine if target 

values need
+     * update.
+     */
+    if (!peci_sensor_need_update(&priv->temp.tcontrol)) +        return 0;

drivers/hwmon/peci-cputemp.c new file +12 -0
+
+    ret = peci_client_read_package_config(priv->mgr,
+                          PECI_MBX_INDEX_TEMP_TARGET, 0,
+                          pkg_cfg);
+    if (ret)
+        return ret;
+
+    priv->temp.tjmax.value = pkg_cfg[2] * 1000;
+
+    tcontrol_margin = pkg_cfg[1];
+    tcontrol_margin = ((tcontrol_margin ^ 0x80) - 0x80) * 1000;
+    priv->temp.tcontrol.value = priv->temp.tjmax.value - 

tcontrol_margin;
+
+    tthrottle_offset = (pkg_cfg[3] & 0x2f) * 1000; +    priv->temp.tthrottle.value = priv->temp.tjmax.value - tthrottle_offset;

drivers/hwmon/peci-cputemp.c new file +17 -0
+
+    peci_sensor_mark_updated(&priv->temp.tcontrol);
+
+    return 0;
+}
+
+static int get_die_temp(struct peci_cputemp *priv)
+{
+    struct peci_get_temp_msg msg;
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp.die))
+        return 0;
+
+    msg.addr = priv->mgr->client->addr;
+
+    ret = peci_command(priv->mgr->client->adapter, PECI_CMD_GET_TEMP, 

&msg);
+    if (ret)
+        return ret;

drivers/hwmon/peci-cputemp.c new file +62 -0
+
+    /* Note that the tjmax should be available before calling it */
+    priv->temp.die.value = priv->temp.tjmax.value +
+                   (msg.temp_raw * 1000 / 64);
+
+    peci_sensor_mark_updated(&priv->temp.die);
+
+    return 0;
+}
+
+static int get_dts(struct peci_cputemp *priv)
+{
+    s32 dts_margin;
+    u8  pkg_cfg[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp.dts))
+        return 0;
+
+    ret = peci_client_read_package_config(priv->mgr,
+                          PECI_MBX_INDEX_DTS_MARGIN, 0,
+                          pkg_cfg);
+
+    if (ret)
+        return ret;
+
+    dts_margin = (pkg_cfg[1] << 8) | pkg_cfg[0];
+
+    /**
+     * Processors return a value of DTS reading in 10.6 format
+     * (10 bits signed decimal, 6 bits fractional).
+     * Error codes:
+     *   0x8000: General sensor error
+     *   0x8001: Reserved
+     *   0x8002: Underflow on reading value
+     *   0x8003-0x81ff: Reserved
+     */
+    if (dts_margin >= 0x8000 && dts_margin <= 0x81ff)
+        return -EIO;
+
+    dts_margin = ten_dot_six_to_millidegree(dts_margin);
+
+    /* Note that the tcontrol should be available before calling it */
+    priv->temp.dts.value = priv->temp.tcontrol.value - dts_margin;
+
+    peci_sensor_mark_updated(&priv->temp.dts);
+
+    return 0;
+}
+
+static int get_core_temp(struct peci_cputemp *priv, int core_index)
+{
+    s32 core_dts_margin;
+    u8  pkg_cfg[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp.core[core_index]))
+        return 0;
+
+    ret = peci_client_read_package_config(priv->mgr,
+                          PECI_MBX_INDEX_PER_CORE_DTS_TEMP,
+                          core_index, pkg_cfg);
Quoted 8 lines

drivers/hwmon/peci-cputemp.c line 204

Quoted 5 lines

+    if (ret)
+        return ret;

drivers/hwmon/peci-cputemp.c new file +3 -0
+
+    core_dts_margin = le16_to_cpup((__le16 *)pkg_cfg);
+

Any special readon for using the helper function here but not above ?

Ah, I have to use le16_to_cpup for the above one too. Thanks!

Thanks a lot for your review!

-Jae

#30 lore raw

PATCH v11 14/14 hwmon: Add PECI dimmtemp driver

In reply to Jae Hyun Yoo

This commit adds PECI dimmtemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added max and crit properties for temperature threshold checking.
- Fixed minor bugs and style issues.

 drivers/hwmon/Kconfig         |  14 ++
 drivers/hwmon/Makefile        |   1 +
 drivers/hwmon/peci-dimmtemp.c | 393 ++++++++++++++++++++++++++++++++++
 3 files changed, 408 insertions(+)
 create mode 100644 drivers/hwmon/peci-dimmtemp.c
drivers/hwmon/Kconfig +14 -0
index b6604759579c..d3370fbab40c 100644
@@ -1363,6 +1363,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 client"
+	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 <file:Documentation/hwmon/peci-dimmtemp.rst> 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
index d6fea48697af..4015c4b60bf4 100644
@@ -145,6 +145,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 +393 -0

393 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#31 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

Quoted 216 lines · Jae Hyun Yoo

This commit adds PECI dimmtemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added max and crit properties for temperature threshold checking.
- Fixed minor bugs and style issues.

  drivers/hwmon/Kconfig         |  14 ++
  drivers/hwmon/Makefile        |   1 +
  drivers/hwmon/peci-dimmtemp.c | 393 ++++++++++++++++++++++++++++++++++
  3 files changed, 408 insertions(+)

create mode 100644 drivers/hwmon/peci-dimmtemp.c

drivers/hwmon/Kconfig +14 -0
index b6604759579c..d3370fbab40c 100644
@@ -1363,6 +1363,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 client"
+	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 <file:Documentation/hwmon/peci-dimmtemp.rst> 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
index d6fea48697af..4015c4b60bf4 100644
@@ -145,6 +145,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 +143 -0
new file mode 100644
index 000000000000..974f453f9366
@@ -0,0 +1,393 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+#include "peci-hwmon.h"
+
+#define DIMM_MASK_CHECK_DELAY_JIFFIES  msecs_to_jiffies(5000)
+#define DIMM_MASK_CHECK_RETRY_MAX      60 /* 60 x 5 secs = 5 minutes */
+
+struct peci_dimmtemp {
+	struct peci_client_manager *mgr;
+	struct device *dev;
+	char name[PECI_NAME_SIZE];
+	const struct cpu_gen_info *gen_info;
+	struct workqueue_struct *work_queue;
+	struct delayed_work work_handler;
+	struct peci_sensor_data temp[DIMM_NUMS_MAX];
+	long temp_max[DIMM_NUMS_MAX];
+	long temp_crit[DIMM_NUMS_MAX];
+	u32 dimm_mask;
+	int retry_count;
+	u32 temp_config[DIMM_NUMS_MAX + 1];
+	struct hwmon_channel_info temp_info;
+	const struct hwmon_channel_info *info[2];
+	struct hwmon_chip_info chip;
+};
+
+static const char *dimmtemp_label[CHAN_RANK_MAX][DIMM_IDX_MAX] = {
+	{ "DIMM A1", "DIMM A2", "DIMM A3" },
+	{ "DIMM B1", "DIMM B2", "DIMM B3" },
+	{ "DIMM C1", "DIMM C2", "DIMM C3" },
+	{ "DIMM D1", "DIMM D2", "DIMM D3" },
+	{ "DIMM E1", "DIMM E2", "DIMM E3" },
+	{ "DIMM F1", "DIMM F2", "DIMM F3" },
+	{ "DIMM G1", "DIMM G2", "DIMM G3" },
+	{ "DIMM H1", "DIMM H2", "DIMM H3" },
+};
+
+static inline int read_ddr_dimm_temp_config(struct peci_dimmtemp *priv,
+					    int chan_rank,
+					    u8 *cfg_data)
+{
+	return peci_client_read_package_config(priv->mgr,
+					       PECI_MBX_INDEX_DDR_DIMM_TEMP,
+					       chan_rank, cfg_data);
+}
+
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+	int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+	int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+	struct peci_rd_pci_cfg_local_msg rp_msg;
+	u8  cfg_data[4];
+	int ret;
+
+	if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+		return 0;
+
+	ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+	if (ret)
+		return ret;
+
+	priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+	switch (priv->gen_info->model) {
+	case INTEL_FAM6_SKYLAKE_X:
+		rp_msg.addr = priv->mgr->client->addr;
+		rp_msg.bus = 2;
+		/*
+		 * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+		 * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+		 * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+		 * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+		 * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+		 * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+		 */
+		rp_msg.device = 10 + chan_rank / 3 * 2 +
+			     (chan_rank % 3 == 2 ? 1 : 0);
+		rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+		rp_msg.reg = 0x120 + dimm_order * 4;
+		rp_msg.rx_len = 4;
+
+		ret = peci_command(priv->mgr->client->adapter,
+				   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+		if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+			ret = -EAGAIN;
+		if (ret)
+			return ret;
+
+		priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+		priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+		break;
+	case INTEL_FAM6_SKYLAKE_XD:
+		rp_msg.addr = priv->mgr->client->addr;
+		rp_msg.bus = 2;
+		/*
+		 * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+		 * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+		 * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+		 * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+		 */
+		rp_msg.device = 10 + chan_rank / 2 * 2;
+		rp_msg.function = (chan_rank % 2) ? 6 : 2;
+		rp_msg.reg = 0x120 + dimm_order * 4;
+		rp_msg.rx_len = 4;
+
+		ret = peci_command(priv->mgr->client->adapter,
+				   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+		if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+			ret = -EAGAIN;
+		if (ret)
+			return ret;
+
+		priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+		priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+		break;
+	case INTEL_FAM6_HASWELL_X:
+	case INTEL_FAM6_BROADWELL_X:
+		rp_msg.addr = priv->mgr->client->addr;
+		rp_msg.bus = 1;
+		/*
+		 * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+		 * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+		 * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+		 * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+		 * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+		 * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+		 * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+		 * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+		 */
+		rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+		rp_msg.function = chan_rank % 2;
+		rp_msg.reg = 0x120 + dimm_order * 4;
+		rp_msg.rx_len = 4;
+
+		ret = peci_command(priv->mgr->client->adapter,
+				   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+		if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+			ret = -EAGAIN;
+		if (ret)
+			return ret;
+
+		priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+		priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+		break;
+	default:
+		return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Quoted 11 lines
drivers/hwmon/peci-dimmtemp.c new file +11 -0
+	}
+
+	peci_sensor_mark_updated(&priv->temp[dimm_no]);
+
+	return 0;
+}
+
+static int dimmtemp_read_string(struct device *dev,
+				enum hwmon_sensor_types type,
+				u32 attr, int channel, const char **str)
+{

drivers/hwmon/peci-dimmtemp.c line 174

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+	struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+	u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+	int chan_rank, dimm_idx;
+
+	if (attr != hwmon_temp_label)
+		return -EOPNOTSUPP;
+
+	chan_rank = channel / dimm_idx_max;
+	dimm_idx = channel % dimm_idx_max;
+	*str = dimmtemp_label[chan_rank][dimm_idx];

Similar to the other patch, I am concerned that this can end up setting *str to NULL at some point in the future.

Quoted 124 lines
drivers/hwmon/peci-dimmtemp.c new file +124 -0
+
+	return 0;
+}
+
+static int dimmtemp_read(struct device *dev, enum hwmon_sensor_types type,
+			 u32 attr, int channel, long *val)
+{
+	struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+	int ret;
+
+	ret = get_dimm_temp(priv, channel);
+	if (ret)
+		return ret;
+
+	switch (attr) {
+	case hwmon_temp_input:
+		*val = priv->temp[channel].value;
+		break;
+	case hwmon_temp_max:
+		*val = priv->temp_max[channel];
+		break;
+	case hwmon_temp_crit:
+		*val = priv->temp_crit[channel];
+		break;
+	default:
+		ret = -EOPNOTSUPP;
+		break;
+	}
+
+	return ret;
+}
+
+static umode_t dimmtemp_is_visible(const void *data,
+				   enum hwmon_sensor_types type,
+				   u32 attr, int channel)
+{
+	const struct peci_dimmtemp *priv = data;
+
+	if (priv->temp_config[channel] & BIT(attr) &&
+	    priv->dimm_mask & BIT(channel))
+		return 0444;
+
+	return 0;
+}
+
+static const struct hwmon_ops dimmtemp_ops = {
+	.is_visible = dimmtemp_is_visible,
+	.read_string = dimmtemp_read_string,
+	.read = dimmtemp_read,
+};
+
+static int check_populated_dimms(struct peci_dimmtemp *priv)
+{
+	u32 chan_rank_max = priv->gen_info->chan_rank_max;
+	u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+	int chan_rank, dimm_idx;
+	u8  cfg_data[4];
+
+	for (chan_rank = 0; chan_rank < chan_rank_max; chan_rank++) {
+		int ret;
+
+		ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+		if (ret) {
+			priv->dimm_mask = 0;
+			return ret;
+		}
+
+		for (dimm_idx = 0; dimm_idx < dimm_idx_max; dimm_idx++)
+			if (cfg_data[dimm_idx])
+				priv->dimm_mask |= BIT(chan_rank *
+						       dimm_idx_max +
+						       dimm_idx);
+	}
+
+	if (!priv->dimm_mask)
+		return -EAGAIN;
+
+	dev_dbg(priv->dev, "Scanned populated DIMMs: 0x%x\n", priv->dimm_mask);
+
+	return 0;
+}
+
+static int create_dimm_temp_info(struct peci_dimmtemp *priv)
+{
+	int ret, i, config_idx, channels;
+	struct device *hwmon_dev;
+
+	ret = check_populated_dimms(priv);
+	if (ret) {
+		if (ret == -EAGAIN) {
+			if (priv->retry_count < DIMM_MASK_CHECK_RETRY_MAX) {
+				queue_delayed_work(priv->work_queue,
+						   &priv->work_handler,
+						 DIMM_MASK_CHECK_DELAY_JIFFIES);
+				priv->retry_count++;
+				dev_dbg(priv->dev,
+					"Deferred DIMM temp info creation\n");
+			} else {
+				dev_err(priv->dev,
+					"Timeout DIMM temp info creation\n");
+				ret = -ETIMEDOUT;
+			}
+		}
+
+		return ret;
+	}
+
+	channels = priv->gen_info->chan_rank_max *
+		   priv->gen_info->dimm_idx_max;
+	for (i = 0, config_idx = 0; i < channels; i++)
+		if (priv->dimm_mask & BIT(i))
+			while (i >= config_idx)
+				priv->temp_config[config_idx++] =
+					HWMON_T_LABEL | HWMON_T_INPUT |
+					HWMON_T_MAX | HWMON_T_CRIT;
+
+	priv->chip.ops = &dimmtemp_ops;
+	priv->chip.info = priv->info;
+
+	priv->info[0] = &priv->temp_info;
+
+	priv->temp_info.type = hwmon_temp;
+	priv->temp_info.config = priv->temp_config;
+

drivers/hwmon/peci-dimmtemp.c line 308

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+	hwmon_dev = devm_hwmon_device_register_with_info(priv->dev,
+							 priv->name,
+							 priv,
+							 &priv->chip,
+							 NULL);
+	ret = PTR_ERR_OR_ZERO(hwmon_dev);
+	if (!ret)
+		dev_dbg(priv->dev, "%s: sensor '%s'\n",
+			dev_name(hwmon_dev), priv->name);
+

Any chance to make this consistent with the other driver ?

Quoted 38 lines
drivers/hwmon/peci-dimmtemp.c new file +38 -0
+	return ret;
+}
+
+static void create_dimm_temp_info_delayed(struct work_struct *work)
+{
+	struct delayed_work *dwork = to_delayed_work(work);
+	struct peci_dimmtemp *priv = container_of(dwork, struct peci_dimmtemp,
+						  work_handler);
+	int ret;
+
+	ret = create_dimm_temp_info(priv);
+	if (ret && ret != -EAGAIN)
+		dev_dbg(priv->dev, "Failed to create DIMM temp info\n");
+}
+
+static int peci_dimmtemp_probe(struct platform_device *pdev)
+{
+	struct peci_client_manager *mgr = dev_get_drvdata(pdev->dev.parent);
+	struct device *dev = &pdev->dev;
+	struct peci_dimmtemp *priv;
+	int ret;
+
+	if ((mgr->client->adapter->cmd_mask &
+	    (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG))) !=
+	    (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG)))
+		return -ENODEV;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	dev_set_drvdata(dev, priv);
+	priv->mgr = mgr;
+	priv->dev = dev;
+	priv->gen_info = mgr->gen_info;
+
+	snprintf(priv->name, PECI_NAME_SIZE, "peci_dimmtemp.cpu%d",
+		 priv->mgr->client->addr - PECI_BASE_ADDR);

drivers/hwmon/peci-dimmtemp.c line 356

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+
+	priv->work_queue = alloc_ordered_workqueue(priv->name, 0);
+	if (!priv->work_queue)
+		return -ENOMEM;
+
+	INIT_DELAYED_WORK(&priv->work_handler, create_dimm_temp_info_delayed);
+
+	ret = create_dimm_temp_info(priv);
+	if (ret && ret != -EAGAIN) {
+		dev_err(dev, "Failed to create DIMM temp info\n");

Does this generate error messages if there are no DIMMS ?

Quoted 38 lines
drivers/hwmon/peci-dimmtemp.c new file +37 -0
+		goto err_free_wq;
+	}
+
+	return 0;
+
+err_free_wq:
+	destroy_workqueue(priv->work_queue);
+	return ret;
+}
+
+static int peci_dimmtemp_remove(struct platform_device *pdev)
+{
+	struct peci_dimmtemp *priv = dev_get_drvdata(&pdev->dev);
+
+	cancel_delayed_work_sync(&priv->work_handler);
+	destroy_workqueue(priv->work_queue);
+
+	return 0;
+}
+
+static const struct platform_device_id peci_dimmtemp_ids[] = {
+	{ .name = "peci-dimmtemp", .driver_data = 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, peci_dimmtemp_ids);
+
+static struct platform_driver peci_dimmtemp_driver = {
+	.probe    = peci_dimmtemp_probe,
+	.remove   = peci_dimmtemp_remove,
+	.id_table = peci_dimmtemp_ids,
+	.driver   = { .name = KBUILD_MODNAME, },
+};
+module_platform_driver(peci_dimmtemp_driver);
+
+MODULE_AUTHOR("Jae Hyun Yoo <[email protected]>");
+MODULE_DESCRIPTION("PECI dimmtemp driver");
+MODULE_LICENSE("GPL v2");
#32 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

Hi Guenter,

Quoted 232 lines · Guenter Roeck
Quoted 216 lines · Jae Hyun Yoo

This commit adds PECI dimmtemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added max and crit properties for temperature threshold checking.
- Fixed minor bugs and style issues.

  drivers/hwmon/Kconfig         |  14 ++ drivers/hwmon/Makefile        |   1 + drivers/hwmon/peci-dimmtemp.c | 393 ++++++++++++++++++++++++++++++++++

  3 files changed, 408 insertions(+)

  create mode 100644 drivers/hwmon/peci-dimmtemp.c

drivers/hwmon/Kconfig +0 -0
index b6604759579c..d3370fbab40c 100644
@@ -1363,6 +1363,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 client"
+    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 <file:Documentation/hwmon/peci-dimmtemp.rst> for details.

drivers/hwmon/Kconfig +4 -0
+
+      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 +0 -0
index d6fea48697af..4015c4b60bf4 100644
@@ -145,6 +145,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 +143 -0
new file mode 100644
index 000000000000..974f453f9366
@@ -0,0 +1,393 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+#include "peci-hwmon.h"
+
+#define DIMM_MASK_CHECK_DELAY_JIFFIES  msecs_to_jiffies(5000)
+#define DIMM_MASK_CHECK_RETRY_MAX      60 /* 60 x 5 secs = 5 minutes */
+
+struct peci_dimmtemp {
+    struct peci_client_manager *mgr;
+    struct device *dev;
+    char name[PECI_NAME_SIZE];
+    const struct cpu_gen_info *gen_info;
+    struct workqueue_struct *work_queue;
+    struct delayed_work work_handler;
+    struct peci_sensor_data temp[DIMM_NUMS_MAX];
+    long temp_max[DIMM_NUMS_MAX];
+    long temp_crit[DIMM_NUMS_MAX];
+    u32 dimm_mask;
+    int retry_count;
+    u32 temp_config[DIMM_NUMS_MAX + 1];
+    struct hwmon_channel_info temp_info;
+    const struct hwmon_channel_info *info[2];
+    struct hwmon_chip_info chip;
+};
+
+static const char *dimmtemp_label[CHAN_RANK_MAX][DIMM_IDX_MAX] = {
+    { "DIMM A1", "DIMM A2", "DIMM A3" },
+    { "DIMM B1", "DIMM B2", "DIMM B3" },
+    { "DIMM C1", "DIMM C2", "DIMM C3" },
+    { "DIMM D1", "DIMM D2", "DIMM D3" },
+    { "DIMM E1", "DIMM E2", "DIMM E3" },
+    { "DIMM F1", "DIMM F2", "DIMM F3" },
+    { "DIMM G1", "DIMM G2", "DIMM G3" },
+    { "DIMM H1", "DIMM H2", "DIMM H3" },
+};
+
+static inline int read_ddr_dimm_temp_config(struct peci_dimmtemp *priv,
+                        int chan_rank,
+                        u8 *cfg_data)
+{
+    return peci_client_read_package_config(priv->mgr,
+                           PECI_MBX_INDEX_DDR_DIMM_TEMP,
+                           chan_rank, cfg_data);
+}
+
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+    int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+    int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+    struct peci_rd_pci_cfg_local_msg rp_msg;
+    u8  cfg_data[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+        return 0;
+
+    ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+    if (ret)
+        return ret;
+
+    priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+    switch (priv->gen_info->model) {
+    case INTEL_FAM6_SKYLAKE_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+         * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+         */
+        rp_msg.device = 10 + chan_rank / 3 * 2 +
+                 (chan_rank % 3 == 2 ? 1 : 0);
+        rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_SKYLAKE_XD:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+         */
+        rp_msg.device = 10 + chan_rank / 2 * 2;
+        rp_msg.function = (chan_rank % 2) ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_HASWELL_X:
+    case INTEL_FAM6_BROADWELL_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 1;
+        /*
+         * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+         * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+         * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+         * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+         * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+         * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+         * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+         * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+         */
+        rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+        rp_msg.function = chan_rank % 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    default:
+        return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

Quoted 2 lines

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Actually, this 'default' case will not be happened because this driver will be registered only when the CPU model is supported. The CPU model checking code is in 'intel-peci-client.c' which is [11/14] of this patch set.

Quoted 16 lines
Quoted 16 lines
drivers/hwmon/peci-dimmtemp.c new file +16 -0
+    }
+
+    peci_sensor_mark_updated(&priv->temp[dimm_no]);
+
+    return 0;
+}
+
+static int dimmtemp_read_string(struct device *dev,
+                enum hwmon_sensor_types type,
+                u32 attr, int channel, const char **str)
+{
+    struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+    u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+    int chan_rank, dimm_idx;
+
+    if (attr != hwmon_temp_label)
Quoted 8 lines

drivers/hwmon/peci-dimmtemp.c line 174

Quoted 5 lines
drivers/hwmon/peci-dimmtemp.c new file +5 -0
+        return -EOPNOTSUPP;
+
+    chan_rank = channel / dimm_idx_max;
+    dimm_idx = channel % dimm_idx_max;
+    *str = dimmtemp_label[chan_rank][dimm_idx];

Similar to the other patch, I am concerned that this can end up setting *str to NULL at some point in the future.

Okay. I'll make dynamic label string table generation code for it as well.

Quoted 130 lines
Quoted 130 lines
drivers/hwmon/peci-dimmtemp.c new file +5 -0
+
+    return 0;
+}
+
+static int dimmtemp_read(struct device *dev, enum hwmon_sensor_types 

type,
+             u32 attr, int channel, long *val)

drivers/hwmon/peci-dimmtemp.c new file +72 -0
+{
+    struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+    int ret;
+
+    ret = get_dimm_temp(priv, channel);
+    if (ret)
+        return ret;
+
+    switch (attr) {
+    case hwmon_temp_input:
+        *val = priv->temp[channel].value;
+        break;
+    case hwmon_temp_max:
+        *val = priv->temp_max[channel];
+        break;
+    case hwmon_temp_crit:
+        *val = priv->temp_crit[channel];
+        break;
+    default:
+        ret = -EOPNOTSUPP;
+        break;
+    }
+
+    return ret;
+}
+
+static umode_t dimmtemp_is_visible(const void *data,
+                   enum hwmon_sensor_types type,
+                   u32 attr, int channel)
+{
+    const struct peci_dimmtemp *priv = data;
+
+    if (priv->temp_config[channel] & BIT(attr) &&
+        priv->dimm_mask & BIT(channel))
+        return 0444;
+
+    return 0;
+}
+
+static const struct hwmon_ops dimmtemp_ops = {
+    .is_visible = dimmtemp_is_visible,
+    .read_string = dimmtemp_read_string,
+    .read = dimmtemp_read,
+};
+
+static int check_populated_dimms(struct peci_dimmtemp *priv)
+{
+    u32 chan_rank_max = priv->gen_info->chan_rank_max;
+    u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+    int chan_rank, dimm_idx;
+    u8  cfg_data[4];
+
+    for (chan_rank = 0; chan_rank < chan_rank_max; chan_rank++) {
+        int ret;
+
+        ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+        if (ret) {
+            priv->dimm_mask = 0;
+            return ret;
+        }
+
+        for (dimm_idx = 0; dimm_idx < dimm_idx_max; dimm_idx++)
+            if (cfg_data[dimm_idx])
+                priv->dimm_mask |= BIT(chan_rank *
+                               dimm_idx_max +
+                               dimm_idx);
+    }
+
+    if (!priv->dimm_mask)
+        return -EAGAIN;
+
+    dev_dbg(priv->dev, "Scanned populated DIMMs: 0x%x\n", 

priv->dimm_mask);

drivers/hwmon/peci-dimmtemp.c new file +50 -0
+
+    return 0;
+}
+
+static int create_dimm_temp_info(struct peci_dimmtemp *priv)
+{
+    int ret, i, config_idx, channels;
+    struct device *hwmon_dev;
+
+    ret = check_populated_dimms(priv);
+    if (ret) {
+        if (ret == -EAGAIN) {
+            if (priv->retry_count < DIMM_MASK_CHECK_RETRY_MAX) {
+                queue_delayed_work(priv->work_queue,
+                           &priv->work_handler,
+                         DIMM_MASK_CHECK_DELAY_JIFFIES);
+                priv->retry_count++;
+                dev_dbg(priv->dev,
+                    "Deferred DIMM temp info creation\n");
+            } else {
+                dev_err(priv->dev,
+                    "Timeout DIMM temp info creation\n");
+                ret = -ETIMEDOUT;
+            }
+        }
+
+        return ret;
+    }
+
+    channels = priv->gen_info->chan_rank_max *
+           priv->gen_info->dimm_idx_max;
+    for (i = 0, config_idx = 0; i < channels; i++)
+        if (priv->dimm_mask & BIT(i))
+            while (i >= config_idx)
+                priv->temp_config[config_idx++] =
+                    HWMON_T_LABEL | HWMON_T_INPUT |
+                    HWMON_T_MAX | HWMON_T_CRIT;
+
+    priv->chip.ops = &dimmtemp_ops;
+    priv->chip.info = priv->info;
+
+    priv->info[0] = &priv->temp_info;
+
+    priv->temp_info.type = hwmon_temp;
+    priv->temp_info.config = priv->temp_config;
+
+    hwmon_dev = devm_hwmon_device_register_with_info(priv->dev,
+                             priv->name,
+                             priv,
+                             &priv->chip,
Quoted 8 lines
Quoted 6 lines

+                             NULL);
+    ret = PTR_ERR_OR_ZERO(hwmon_dev);
+    if (!ret)
+        dev_dbg(priv->dev, "%s: sensor '%s'\n",
+            dev_name(hwmon_dev), priv->name);
+

Any chance to make this consistent with the other driver ?

Will change this to:

if (IS_ERR(hwmon_dev)) {
	dev_err(&priv->dev, "Failed to register hwmon device\n");
	return PTR_ERR(hwmon_dev);
}
Quoted 44 lines
Quoted 44 lines

+    return ret;

drivers/hwmon/peci-dimmtemp.c new file +6 -0
+}
+
+static void create_dimm_temp_info_delayed(struct work_struct *work)
+{
+    struct delayed_work *dwork = to_delayed_work(work);
+    struct peci_dimmtemp *priv = container_of(dwork, struct 

peci_dimmtemp,
+                          work_handler);
+    int ret;

drivers/hwmon/peci-dimmtemp.c new file +34 -0
+
+    ret = create_dimm_temp_info(priv);
+    if (ret && ret != -EAGAIN)
+        dev_dbg(priv->dev, "Failed to create DIMM temp info\n");
+}
+
+static int peci_dimmtemp_probe(struct platform_device *pdev)
+{
+    struct peci_client_manager *mgr = dev_get_drvdata(pdev->dev.parent);
+    struct device *dev = &pdev->dev;
+    struct peci_dimmtemp *priv;
+    int ret;
+
+    if ((mgr->client->adapter->cmd_mask &
+        (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG))) !=
+        (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG)))
+        return -ENODEV;
+
+    priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+    if (!priv)
+        return -ENOMEM;
+
+    dev_set_drvdata(dev, priv);
+    priv->mgr = mgr;
+    priv->dev = dev;
+    priv->gen_info = mgr->gen_info;
+
+    snprintf(priv->name, PECI_NAME_SIZE, "peci_dimmtemp.cpu%d",
+         priv->mgr->client->addr - PECI_BASE_ADDR);
+
+    priv->work_queue = alloc_ordered_workqueue(priv->name, 0);
+    if (!priv->work_queue)
+        return -ENOMEM;
+
Quoted 8 lines
Quoted 6 lines

+    INIT_DELAYED_WORK(&priv->work_handler, create_dimm_temp_info_delayed);
+
+    ret = create_dimm_temp_info(priv);
+    if (ret && ret != -EAGAIN) {
+        dev_err(dev, "Failed to create DIMM temp info\n");

Does this generate error messages if there are no DIMMS ?

Yes, this error message will be printed out once if it meets a timeout in DIMM scanning when there is no DIMM.

Thanks a lot for your review!

-Jae

Quoted 40 lines
Quoted 38 lines

+        goto err_free_wq;
+    }

drivers/hwmon/peci-dimmtemp.c new file +35 -0
+
+    return 0;
+
+err_free_wq:
+    destroy_workqueue(priv->work_queue);
+    return ret;
+}
+
+static int peci_dimmtemp_remove(struct platform_device *pdev)
+{
+    struct peci_dimmtemp *priv = dev_get_drvdata(&pdev->dev);
+
+    cancel_delayed_work_sync(&priv->work_handler);
+    destroy_workqueue(priv->work_queue);
+
+    return 0;
+}
+
+static const struct platform_device_id peci_dimmtemp_ids[] = {
+    { .name = "peci-dimmtemp", .driver_data = 0 },
+    { }
+};
+MODULE_DEVICE_TABLE(platform, peci_dimmtemp_ids);
+
+static struct platform_driver peci_dimmtemp_driver = {
+    .probe    = peci_dimmtemp_probe,
+    .remove   = peci_dimmtemp_remove,
+    .id_table = peci_dimmtemp_ids,
+    .driver   = { .name = KBUILD_MODNAME, },
+};
+module_platform_driver(peci_dimmtemp_driver);
+
+MODULE_AUTHOR("Jae Hyun Yoo <[email protected]>");
+MODULE_DESCRIPTION("PECI dimmtemp driver");
+MODULE_LICENSE("GPL v2");
maintainer
#33 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

Quoted 236 lines · Jae Hyun Yoo

Hi Guenter,

Quoted 233 lines · Guenter Roeck
Quoted 217 lines · Jae Hyun Yoo

This commit adds PECI dimmtemp hwmon driver.

Cc Guenter Roeck <[email protected]>
Cc Jean Delvare <[email protected]>
Cc Alan Cox <[email protected]>
Cc Andrew Jeffery <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jason M Biils <[email protected]>
Cc Joel Stanley <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Stef van Os <[email protected]>

---
Changes since v10:
- Added Skylake Xeon D support.
- Added max and crit properties for temperature threshold checking.
- Fixed minor bugs and style issues.

  drivers/hwmon/Kconfig         |  14 ++ drivers/hwmon/Makefile        |   1 + drivers/hwmon/peci-dimmtemp.c | 393 ++++++++++++++++++++++++++++++++++

  3 files changed, 408 insertions(+)

  create mode 100644 drivers/hwmon/peci-dimmtemp.c

drivers/hwmon/Kconfig +0 -0
index b6604759579c..d3370fbab40c 100644
@@ -1363,6 +1363,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 client"
+    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 <file:Documentation/hwmon/peci-dimmtemp.rst> for details.

drivers/hwmon/Kconfig +4 -0
+
+      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 +0 -0
index d6fea48697af..4015c4b60bf4 100644
@@ -145,6 +145,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 +143 -0
new file mode 100644
index 000000000000..974f453f9366
@@ -0,0 +1,393 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018-2019 Intel Corporation
+
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/mfd/intel-peci-client.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+#include "peci-hwmon.h"
+
+#define DIMM_MASK_CHECK_DELAY_JIFFIES  msecs_to_jiffies(5000)
+#define DIMM_MASK_CHECK_RETRY_MAX      60 /* 60 x 5 secs = 5 minutes */
+
+struct peci_dimmtemp {
+    struct peci_client_manager *mgr;
+    struct device *dev;
+    char name[PECI_NAME_SIZE];
+    const struct cpu_gen_info *gen_info;
+    struct workqueue_struct *work_queue;
+    struct delayed_work work_handler;
+    struct peci_sensor_data temp[DIMM_NUMS_MAX];
+    long temp_max[DIMM_NUMS_MAX];
+    long temp_crit[DIMM_NUMS_MAX];
+    u32 dimm_mask;
+    int retry_count;
+    u32 temp_config[DIMM_NUMS_MAX + 1];
+    struct hwmon_channel_info temp_info;
+    const struct hwmon_channel_info *info[2];
+    struct hwmon_chip_info chip;
+};
+
+static const char *dimmtemp_label[CHAN_RANK_MAX][DIMM_IDX_MAX] = {
+    { "DIMM A1", "DIMM A2", "DIMM A3" },
+    { "DIMM B1", "DIMM B2", "DIMM B3" },
+    { "DIMM C1", "DIMM C2", "DIMM C3" },
+    { "DIMM D1", "DIMM D2", "DIMM D3" },
+    { "DIMM E1", "DIMM E2", "DIMM E3" },
+    { "DIMM F1", "DIMM F2", "DIMM F3" },
+    { "DIMM G1", "DIMM G2", "DIMM G3" },
+    { "DIMM H1", "DIMM H2", "DIMM H3" },
+};
+
+static inline int read_ddr_dimm_temp_config(struct peci_dimmtemp *priv,
+                        int chan_rank,
+                        u8 *cfg_data)
+{
+    return peci_client_read_package_config(priv->mgr,
+                           PECI_MBX_INDEX_DDR_DIMM_TEMP,
+                           chan_rank, cfg_data);
+}
+
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+    int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+    int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+    struct peci_rd_pci_cfg_local_msg rp_msg;
+    u8  cfg_data[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+        return 0;
+
+    ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+    if (ret)
+        return ret;
+
+    priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+    switch (priv->gen_info->model) {
+    case INTEL_FAM6_SKYLAKE_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+         * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+         */
+        rp_msg.device = 10 + chan_rank / 3 * 2 +
+                 (chan_rank % 3 == 2 ? 1 : 0);
+        rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_SKYLAKE_XD:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+         */
+        rp_msg.device = 10 + chan_rank / 2 * 2;
+        rp_msg.function = (chan_rank % 2) ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_HASWELL_X:
+    case INTEL_FAM6_BROADWELL_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 1;
+        /*
+         * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+         * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+         * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+         * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+         * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+         * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+         * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+         * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+         */
+        rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+        rp_msg.function = chan_rank % 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    default:
+        return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

Quoted 8 lines
Quoted 2 lines

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Actually, this 'default' case will not be happened because this driver will be registered only when the CPU model is supported. The CPU model checking code is in 'intel-peci-client.c' which is [11/14] of this patch set.

That again assumes that both drivers will be modified in sync in the future. We can not make that assumption.

Quoted 228 lines
Quoted 17 lines
Quoted 17 lines
drivers/hwmon/peci-dimmtemp.c new file +17 -0
+    }
+
+    peci_sensor_mark_updated(&priv->temp[dimm_no]);
+
+    return 0;
+}
+
+static int dimmtemp_read_string(struct device *dev,
+                enum hwmon_sensor_types type,
+                u32 attr, int channel, const char **str)
+{
+    struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+    u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+    int chan_rank, dimm_idx;
+
+    if (attr != hwmon_temp_label)
+        return -EOPNOTSUPP;
Quoted 8 lines

drivers/hwmon/peci-dimmtemp.c line 174

Quoted 4 lines
drivers/hwmon/peci-dimmtemp.c new file +4 -0
+
+    chan_rank = channel / dimm_idx_max;
+    dimm_idx = channel % dimm_idx_max;
+    *str = dimmtemp_label[chan_rank][dimm_idx];

Similar to the other patch, I am concerned that this can end up setting *str
to NULL at some point in the future.

Okay. I'll make dynamic label string table generation code for it as well.

Quoted 130 lines
Quoted 130 lines
drivers/hwmon/peci-dimmtemp.c new file +5 -0
+
+    return 0;
+}
+
+static int dimmtemp_read(struct device *dev, enum

hwmon_sensor_types type,
+             u32 attr, int channel, long *val)

drivers/hwmon/peci-dimmtemp.c new file +72 -0
+{
+    struct peci_dimmtemp *priv = dev_get_drvdata(dev);
+    int ret;
+
+    ret = get_dimm_temp(priv, channel);
+    if (ret)
+        return ret;
+
+    switch (attr) {
+    case hwmon_temp_input:
+        *val = priv->temp[channel].value;
+        break;
+    case hwmon_temp_max:
+        *val = priv->temp_max[channel];
+        break;
+    case hwmon_temp_crit:
+        *val = priv->temp_crit[channel];
+        break;
+    default:
+        ret = -EOPNOTSUPP;
+        break;
+    }
+
+    return ret;
+}
+
+static umode_t dimmtemp_is_visible(const void *data,
+                   enum hwmon_sensor_types type,
+                   u32 attr, int channel)
+{
+    const struct peci_dimmtemp *priv = data;
+
+    if (priv->temp_config[channel] & BIT(attr) &&
+        priv->dimm_mask & BIT(channel))
+        return 0444;
+
+    return 0;
+}
+
+static const struct hwmon_ops dimmtemp_ops = {
+    .is_visible = dimmtemp_is_visible,
+    .read_string = dimmtemp_read_string,
+    .read = dimmtemp_read,
+};
+
+static int check_populated_dimms(struct peci_dimmtemp *priv)
+{
+    u32 chan_rank_max = priv->gen_info->chan_rank_max;
+    u32 dimm_idx_max = priv->gen_info->dimm_idx_max;
+    int chan_rank, dimm_idx;
+    u8  cfg_data[4];
+
+    for (chan_rank = 0; chan_rank < chan_rank_max; chan_rank++) {
+        int ret;
+
+        ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+        if (ret) {
+            priv->dimm_mask = 0;
+            return ret;
+        }
+
+        for (dimm_idx = 0; dimm_idx < dimm_idx_max; dimm_idx++)
+            if (cfg_data[dimm_idx])
+                priv->dimm_mask |= BIT(chan_rank *
+                               dimm_idx_max +
+                               dimm_idx);
+    }
+
+    if (!priv->dimm_mask)
+        return -EAGAIN;
+
+    dev_dbg(priv->dev, "Scanned populated DIMMs: 0x%x\n",

priv->dimm_mask);

drivers/hwmon/peci-dimmtemp.c new file +50 -0
+
+    return 0;
+}
+
+static int create_dimm_temp_info(struct peci_dimmtemp *priv)
+{
+    int ret, i, config_idx, channels;
+    struct device *hwmon_dev;
+
+    ret = check_populated_dimms(priv);
+    if (ret) {
+        if (ret == -EAGAIN) {
+            if (priv->retry_count < DIMM_MASK_CHECK_RETRY_MAX) {
+                queue_delayed_work(priv->work_queue,
+                           &priv->work_handler,
+                         DIMM_MASK_CHECK_DELAY_JIFFIES);
+                priv->retry_count++;
+                dev_dbg(priv->dev,
+                    "Deferred DIMM temp info creation\n");
+            } else {
+                dev_err(priv->dev,
+                    "Timeout DIMM temp info creation\n");
+                ret = -ETIMEDOUT;
+            }
+        }
+
+        return ret;
+    }
+
+    channels = priv->gen_info->chan_rank_max *
+           priv->gen_info->dimm_idx_max;
+    for (i = 0, config_idx = 0; i < channels; i++)
+        if (priv->dimm_mask & BIT(i))
+            while (i >= config_idx)
+                priv->temp_config[config_idx++] =
+                    HWMON_T_LABEL | HWMON_T_INPUT |
+                    HWMON_T_MAX | HWMON_T_CRIT;
+
+    priv->chip.ops = &dimmtemp_ops;
+    priv->chip.info = priv->info;
+
+    priv->info[0] = &priv->temp_info;
+
+    priv->temp_info.type = hwmon_temp;
+    priv->temp_info.config = priv->temp_config;
+
+    hwmon_dev = devm_hwmon_device_register_with_info(priv->dev,
+                             priv->name,
+                             priv,
+                             &priv->chip,
Quoted 8 lines
Quoted 6 lines

+                             NULL);
+    ret = PTR_ERR_OR_ZERO(hwmon_dev);
+    if (!ret)
+        dev_dbg(priv->dev, "%s: sensor '%s'\n",
+            dev_name(hwmon_dev), priv->name);
+

Any chance to make this consistent with the other driver ?

Will change this to:

if (IS_ERR(hwmon_dev)) {
	dev_err(&priv->dev, "Failed to register hwmon device\n");
	return PTR_ERR(hwmon_dev);
}
Quoted 44 lines
Quoted 44 lines

+    return ret;

drivers/hwmon/peci-dimmtemp.c new file +6 -0
+}
+
+static void create_dimm_temp_info_delayed(struct work_struct *work)
+{
+    struct delayed_work *dwork = to_delayed_work(work);
+    struct peci_dimmtemp *priv = container_of(dwork, struct

peci_dimmtemp,
+                          work_handler);
+    int ret;

drivers/hwmon/peci-dimmtemp.c new file +34 -0
+
+    ret = create_dimm_temp_info(priv);
+    if (ret && ret != -EAGAIN)
+        dev_dbg(priv->dev, "Failed to create DIMM temp info\n");
+}
+
+static int peci_dimmtemp_probe(struct platform_device *pdev)
+{
+    struct peci_client_manager *mgr = dev_get_drvdata(pdev->dev.parent);
+    struct device *dev = &pdev->dev;
+    struct peci_dimmtemp *priv;
+    int ret;
+
+    if ((mgr->client->adapter->cmd_mask &
+        (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG))) !=
+        (BIT(PECI_CMD_GET_TEMP) | BIT(PECI_CMD_RD_PKG_CFG)))
+        return -ENODEV;
+
+    priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+    if (!priv)
+        return -ENOMEM;
+
+    dev_set_drvdata(dev, priv);
+    priv->mgr = mgr;
+    priv->dev = dev;
+    priv->gen_info = mgr->gen_info;
+
+    snprintf(priv->name, PECI_NAME_SIZE, "peci_dimmtemp.cpu%d",
+         priv->mgr->client->addr - PECI_BASE_ADDR);
+
+    priv->work_queue = alloc_ordered_workqueue(priv->name, 0);
+    if (!priv->work_queue)
+        return -ENOMEM;
+
Quoted 8 lines
Quoted 6 lines

+    INIT_DELAYED_WORK(&priv->work_handler, create_dimm_temp_info_delayed);
+
+    ret = create_dimm_temp_info(priv);
+    if (ret && ret != -EAGAIN) {
+        dev_err(dev, "Failed to create DIMM temp info\n");

Does this generate error messages if there are no DIMMS ?

Quoted 3 lines

Yes, this error message will be printed out once if it meets a timeout in DIMM scanning when there is no DIMM.

Is that indeed an error, or are there situations where no DIMMs are detected and that is a perfectly valid situation ? An error message is only acceptable if this is indeed an error in all situations.

Guenter

#34 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

[...]

Quoted 108 lines
Quoted 108 lines
Quoted 107 lines
Quoted 90 lines
drivers/hwmon/peci-dimmtemp.c new file +90 -0
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+    int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+    int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+    struct peci_rd_pci_cfg_local_msg rp_msg;
+    u8  cfg_data[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+        return 0;
+
+    ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+    if (ret)
+        return ret;
+
+    priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+    switch (priv->gen_info->model) {
+    case INTEL_FAM6_SKYLAKE_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+         * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+         */
+        rp_msg.device = 10 + chan_rank / 3 * 2 +
+                 (chan_rank % 3 == 2 ? 1 : 0);
+        rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_SKYLAKE_XD:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+         */
+        rp_msg.device = 10 + chan_rank / 2 * 2;
+        rp_msg.function = (chan_rank % 2) ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_HASWELL_X:
+    case INTEL_FAM6_BROADWELL_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 1;
+        /*
+         * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+         * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+         * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+         * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+         * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+         * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+         * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+         * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+         */
+        rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+        rp_msg.function = chan_rank % 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    default:
+        return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Quoted 8 lines
Quoted 5 lines

Actually, this 'default' case will not be happened because this driver will be registered only when the CPU model is supported. The CPU model checking code is in 'intel-peci-client.c' which is [11/14] of this patch set.

That again assumes that both drivers will be modified in sync in the future. We can not make that assumption.

As you said, both drivers must be modified in sync in the future because each Intel CPU family uses different way of reading DIMM temperature. In case if supported CPU checking code updated without making sync with it, this driver will return the error.

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

+    ret = create_dimm_temp_info(priv);
+    if (ret && ret != -EAGAIN) {
+        dev_err(dev, "Failed to create DIMM temp info\n");

Does this generate error messages if there are no DIMMS ?

Quoted 7 lines
Quoted 3 lines

Yes, this error message will be printed out once if it meets a timeout in DIMM scanning when there is no DIMM.

Is that indeed an error, or are there situations where no DIMMs are detected and that is a perfectly valid situation ? An error message is only acceptable if this is indeed an error in all situations.

If a machine under monitoring has two Intel CPUs installed but only one CPU has a DIMM, it's also an working configuration although it's an unusual H/W configuration. I'll fix that to dbg printing.

Thanks,

Jae

maintainer
#35 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

Quoted 116 lines · Jae Hyun Yoo

[...]

Quoted 114 lines
Quoted 113 lines
Quoted 105 lines
Quoted 90 lines
drivers/hwmon/peci-dimmtemp.c new file +90 -0
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+    int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+    int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+    struct peci_rd_pci_cfg_local_msg rp_msg;
+    u8  cfg_data[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+        return 0;
+
+    ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+    if (ret)
+        return ret;
+
+    priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+    switch (priv->gen_info->model) {
+    case INTEL_FAM6_SKYLAKE_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+         * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+         */
+        rp_msg.device = 10 + chan_rank / 3 * 2 +
+                 (chan_rank % 3 == 2 ? 1 : 0);
+        rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_SKYLAKE_XD:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+         */
+        rp_msg.device = 10 + chan_rank / 2 * 2;
+        rp_msg.function = (chan_rank % 2) ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_HASWELL_X:
+    case INTEL_FAM6_BROADWELL_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 1;
+        /*
+         * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+         * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+         * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+         * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+         * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+         * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+         * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+         * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+         */
+        rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+        rp_msg.function = chan_rank % 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    default:
+        return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

Quoted 2 lines

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Actually, this 'default' case will not be happened because this driver will be registered only when the CPU model is supported. The CPU model checking code is in 'intel-peci-client.c' which is [11/14] of this patch set.

Quoted 8 lines
Quoted 2 lines

That again assumes that both drivers will be modified in sync in the future. We can not make that assumption.

As you said, both drivers must be modified in sync in the future because each Intel CPU family uses different way of reading DIMM temperature. In case if supported CPU checking code updated without making sync with it, this driver will return the error.

... and in that situation the driver should not instantiate in the first place. Its probe function should return -ENODEV.

Guenter

#36 lore raw

Re: [PATCH v11 14/14] hwmon: Add PECI dimmtemp driver

Quoted 120 lines · Guenter Roeck
Quoted 119 lines · Jae Hyun Yoo

[...]

Quoted 116 lines
Quoted 105 lines
Quoted 105 lines
Quoted 90 lines
drivers/hwmon/peci-dimmtemp.c new file +90 -0
+static int get_dimm_temp(struct peci_dimmtemp *priv, int dimm_no)
+{
+    int dimm_order = dimm_no % priv->gen_info->dimm_idx_max;
+    int chan_rank = dimm_no / priv->gen_info->dimm_idx_max;
+    struct peci_rd_pci_cfg_local_msg rp_msg;
+    u8  cfg_data[4];
+    int ret;
+
+    if (!peci_sensor_need_update(&priv->temp[dimm_no]))
+        return 0;
+
+    ret = read_ddr_dimm_temp_config(priv, chan_rank, cfg_data);
+    if (ret)
+        return ret;
+
+    priv->temp[dimm_no].value = cfg_data[dimm_order] * 1000;
+
+    switch (priv->gen_info->model) {
+    case INTEL_FAM6_SKYLAKE_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 11, Function 2: IMC 0 channel 2 -> rank 2
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 3
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 4
+         * Device 13, Function 2: IMC 1 channel 2 -> rank 5
+         */
+        rp_msg.device = 10 + chan_rank / 3 * 2 +
+                 (chan_rank % 3 == 2 ? 1 : 0);
+        rp_msg.function = chan_rank % 3 == 1 ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_SKYLAKE_XD:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 2;
+        /*
+         * Device 10, Function 2: IMC 0 channel 0 -> rank 0
+         * Device 10, Function 6: IMC 0 channel 1 -> rank 1
+         * Device 12, Function 2: IMC 1 channel 0 -> rank 2
+         * Device 12, Function 6: IMC 1 channel 1 -> rank 3
+         */
+        rp_msg.device = 10 + chan_rank / 2 * 2;
+        rp_msg.function = (chan_rank % 2) ? 6 : 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    case INTEL_FAM6_HASWELL_X:
+    case INTEL_FAM6_BROADWELL_X:
+        rp_msg.addr = priv->mgr->client->addr;
+        rp_msg.bus = 1;
+        /*
+         * Device 20, Function 0: IMC 0 channel 0 -> rank 0
+         * Device 20, Function 1: IMC 0 channel 1 -> rank 1
+         * Device 21, Function 0: IMC 0 channel 2 -> rank 2
+         * Device 21, Function 1: IMC 0 channel 3 -> rank 3
+         * Device 23, Function 0: IMC 1 channel 0 -> rank 4
+         * Device 23, Function 1: IMC 1 channel 1 -> rank 5
+         * Device 24, Function 0: IMC 1 channel 2 -> rank 6
+         * Device 24, Function 1: IMC 1 channel 3 -> rank 7
+         */
+        rp_msg.device = 20 + chan_rank / 2 + chan_rank / 4;
+        rp_msg.function = chan_rank % 2;
+        rp_msg.reg = 0x120 + dimm_order * 4;
+        rp_msg.rx_len = 4;
+
+        ret = peci_command(priv->mgr->client->adapter,
+                   PECI_CMD_RD_PCI_CFG_LOCAL, &rp_msg);

drivers/hwmon/peci-dimmtemp.c line 153

Quoted 10 lines
drivers/hwmon/peci-dimmtemp.c new file +10 -0
+        if (rp_msg.cc != PECI_DEV_CC_SUCCESS)
+            ret = -EAGAIN;
+        if (ret)
+            return ret;
+
+        priv->temp_max[dimm_no] = rp_msg.pci_config[1] * 1000;
+        priv->temp_crit[dimm_no] = rp_msg.pci_config[2] * 1000;
+        break;
+    default:
+        return -EOPNOTSUPP;

It looks like the sensors are created even on unsupported platforms, which would generate error messages whenever someone tries to read the attributes.

Quoted 8 lines
Quoted 2 lines

There should be some code early on checking this, and the driver should not even instantiate if the CPU model is not supported.

Actually, this 'default' case will not be happened because this driver will be registered only when the CPU model is supported. The CPU model checking code is in 'intel-peci-client.c' which is [11/14] of this patch set.

That again assumes that both drivers will be modified in sync in the future. We can not make that assumption.

Quoted 8 lines
Quoted 5 lines

As you said, both drivers must be modified in sync in the future because each Intel CPU family uses different way of reading DIMM temperature. In case if supported CPU checking code updated without making sync with it, this driver will return the error.

... and in that situation the driver should not instantiate in the first place. Its probe function should return -ENODEV.

Got the point. I'll add the checking code even in this driver module too.

Thanks a lot!

-Jae