All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/9] Add Ampere's Altra SMPro MFD and its child drivers
@ 2022-04-22  2:46 ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information. The SMPro MFD driver initializes the
register map and instantiates all sub-devices. All the specifics will
be handled in the child drivers.

This patch set includes support for Ampere SMpro hwmon, errmon, and
misc as the child drivers. The hwmon driver supports accessing various
CPU sensors provided by the SMpro co-processor including temperature,
power, voltages, and current found on Ampere Altra processor family.
The errmon driver supports monitoring and reporting RAS-related errors.
The misc driver is to support reporting boot progress and other
miscellaneous information.

Discussion for v7: https://lkml.org/lkml/2022/3/21/125

v8:
  + Insert 'break;' to avoid fall-through          [kernel test robot]
  + Avoid uninitialized variable use               [kernel test robot]
  + Remove unused #*_cells                                 [Krzysztof]
  + Switch to use sysfs_emit()                                  [Greg]
  + Sysfs to return single value only                           [Greg]
  + Fix KernelVerion field in Documentation/ABI/testing doc     [Greg]
  + Change errors_* sysfs to error_*                            [Quan]
  + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
  overflow status of each type of HW errors                     [Quan]
  + Update wording in Kconfig for smpro-errmon and smpro-misc   [Quan]
  + Masks reserved bit when read 10-bit power value             [Quan]
  + Add some minor refactor                                     [Quan]

v7:
  + Add docs to Documentation/ABI/testing                       [Greg]
  + Re-order patches to avoid compile dependency           [Lee Jones]
  + Remove regmap_acquire/release_lock()                        [Quan]
  + Install regmap bus->read/write() to handle multiple types of bus
    access                                                      [Quan]
  + Replace i2c block read by regmap_noinc_read()               [Quan]
  + Fix wrong return type of *show/store()         [kernel test robot]
  + Update GPL version                                          [Quan]
  + Add some others minor code refactor                         [Quan]

v6:
  + Introduced smpro-errmon, smpro-misc as smpro-mfd sub-device [Quan]

v5:
  + Introduced the smpro-mfd driver and drop the use of
  simple-mfd-i2c driver to avoid DT node with no resource in child
  device DT nodes [Rob]
  + Removed the use of reg DT property in child driver [Quan]
  + Validated ManufactureID when probing smpro-mfd drivers [Quan]
  + As child devices are instantiated by SMPro MFD driver, drop the
  ManufacturerID checking in child driver, ie: smpro-hwmon [Quan]
  + Revised commit messages [Quan]

v4:
  + Revised commit message [Quan]
  + Fixed build issue found by kernel test robot [Guenter]
  + Returned regmap_read() error code [Guenter]

v3:
  + Supported list of compatible string [Rob]
  + Introduced reg property in DT to specify reg offset [Rob]
  + Updated description and other minor changes in yaml file [Rob]
  + Handled negative temperature value [Guenter]
  + Returned -ENODEV if Manufacturer ID is wrong [Guenter]
  + Refactored smpro_read_string() and smpro_temp_read() [Guenter]
  + Removed smpro_write() function [Guenter]
  + Added minor refactor changes [Quan]

v2:
  + Used 'struct of_device_id's .data attribute [Lee Jones]
  + Removed "virtual" sensors [Guenter]
  + Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Clarified "highest" meaning in documentation [Guenter]
  + Corrected return error code when host is turn off [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed license info as SPDX-License-Identifier existed [Guenter]
  + Added is_visible() support [Guenter]
  + Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
  + Made is_valid_id() return boolean [Guenter]
  + Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
  + Removed unnecessary error message when dev register fail [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Changed "ampere,ac01-smpro" to "ampere,smpro" [Quan]
  + Included sensor type and channel in labels [Quan]
  + Refactorized code to fix checkpatch.pl --strict complaint [Quan]

Quan Nguyen (9):
  hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
  docs: hwmon: (smpro-hwmon) Add documentation
  misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  docs: misc-devices: (smpro-errmon) Add documentation
  misc: smpro-misc: Add Ampere's Altra SMpro misc driver
  docs: misc-devices: (smpro-misc) Add documentation
  dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
  mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  docs: ABI: testing: Document the Ampere Altra Family's SMpro sysfs
    interfaces

 .../sysfs-bus-platform-devices-ampere-smpro   | 157 ++++++
 .../devicetree/bindings/mfd/ampere,smpro.yaml |  42 ++
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/smpro-hwmon.rst           | 101 ++++
 Documentation/misc-devices/index.rst          |   2 +
 Documentation/misc-devices/smpro-errmon.rst   | 198 ++++++++
 Documentation/misc-devices/smpro-misc.rst     |  82 +++
 drivers/hwmon/Kconfig                         |   8 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/smpro-hwmon.c                   | 465 +++++++++++++++++
 drivers/mfd/Kconfig                           |  12 +
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/smpro-mfd.c                       | 134 +++++
 drivers/misc/Kconfig                          |  22 +
 drivers/misc/Makefile                         |   2 +
 drivers/misc/smpro-errmon.c                   | 477 ++++++++++++++++++
 drivers/misc/smpro-misc.c                     | 161 ++++++
 17 files changed, 1866 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
 create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
 create mode 100644 Documentation/hwmon/smpro-hwmon.rst
 create mode 100644 Documentation/misc-devices/smpro-errmon.rst
 create mode 100644 Documentation/misc-devices/smpro-misc.rst
 create mode 100644 drivers/hwmon/smpro-hwmon.c
 create mode 100644 drivers/mfd/smpro-mfd.c
 create mode 100644 drivers/misc/smpro-errmon.c
 create mode 100644 drivers/misc/smpro-misc.c

-- 
2.35.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v8 0/9] Add Ampere's Altra SMPro MFD and its child drivers
@ 2022-04-22  2:46 ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information. The SMPro MFD driver initializes the
register map and instantiates all sub-devices. All the specifics will
be handled in the child drivers.

This patch set includes support for Ampere SMpro hwmon, errmon, and
misc as the child drivers. The hwmon driver supports accessing various
CPU sensors provided by the SMpro co-processor including temperature,
power, voltages, and current found on Ampere Altra processor family.
The errmon driver supports monitoring and reporting RAS-related errors.
The misc driver is to support reporting boot progress and other
miscellaneous information.

Discussion for v7: https://lkml.org/lkml/2022/3/21/125

v8:
  + Insert 'break;' to avoid fall-through          [kernel test robot]
  + Avoid uninitialized variable use               [kernel test robot]
  + Remove unused #*_cells                                 [Krzysztof]
  + Switch to use sysfs_emit()                                  [Greg]
  + Sysfs to return single value only                           [Greg]
  + Fix KernelVerion field in Documentation/ABI/testing doc     [Greg]
  + Change errors_* sysfs to error_*                            [Quan]
  + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
  overflow status of each type of HW errors                     [Quan]
  + Update wording in Kconfig for smpro-errmon and smpro-misc   [Quan]
  + Masks reserved bit when read 10-bit power value             [Quan]
  + Add some minor refactor                                     [Quan]

v7:
  + Add docs to Documentation/ABI/testing                       [Greg]
  + Re-order patches to avoid compile dependency           [Lee Jones]
  + Remove regmap_acquire/release_lock()                        [Quan]
  + Install regmap bus->read/write() to handle multiple types of bus
    access                                                      [Quan]
  + Replace i2c block read by regmap_noinc_read()               [Quan]
  + Fix wrong return type of *show/store()         [kernel test robot]
  + Update GPL version                                          [Quan]
  + Add some others minor code refactor                         [Quan]

v6:
  + Introduced smpro-errmon, smpro-misc as smpro-mfd sub-device [Quan]

v5:
  + Introduced the smpro-mfd driver and drop the use of
  simple-mfd-i2c driver to avoid DT node with no resource in child
  device DT nodes [Rob]
  + Removed the use of reg DT property in child driver [Quan]
  + Validated ManufactureID when probing smpro-mfd drivers [Quan]
  + As child devices are instantiated by SMPro MFD driver, drop the
  ManufacturerID checking in child driver, ie: smpro-hwmon [Quan]
  + Revised commit messages [Quan]

v4:
  + Revised commit message [Quan]
  + Fixed build issue found by kernel test robot [Guenter]
  + Returned regmap_read() error code [Guenter]

v3:
  + Supported list of compatible string [Rob]
  + Introduced reg property in DT to specify reg offset [Rob]
  + Updated description and other minor changes in yaml file [Rob]
  + Handled negative temperature value [Guenter]
  + Returned -ENODEV if Manufacturer ID is wrong [Guenter]
  + Refactored smpro_read_string() and smpro_temp_read() [Guenter]
  + Removed smpro_write() function [Guenter]
  + Added minor refactor changes [Quan]

v2:
  + Used 'struct of_device_id's .data attribute [Lee Jones]
  + Removed "virtual" sensors [Guenter]
  + Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Clarified "highest" meaning in documentation [Guenter]
  + Corrected return error code when host is turn off [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed license info as SPDX-License-Identifier existed [Guenter]
  + Added is_visible() support [Guenter]
  + Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
  + Made is_valid_id() return boolean [Guenter]
  + Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
  + Removed unnecessary error message when dev register fail [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Changed "ampere,ac01-smpro" to "ampere,smpro" [Quan]
  + Included sensor type and channel in labels [Quan]
  + Refactorized code to fix checkpatch.pl --strict complaint [Quan]

Quan Nguyen (9):
  hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
  docs: hwmon: (smpro-hwmon) Add documentation
  misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  docs: misc-devices: (smpro-errmon) Add documentation
  misc: smpro-misc: Add Ampere's Altra SMpro misc driver
  docs: misc-devices: (smpro-misc) Add documentation
  dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
  mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  docs: ABI: testing: Document the Ampere Altra Family's SMpro sysfs
    interfaces

 .../sysfs-bus-platform-devices-ampere-smpro   | 157 ++++++
 .../devicetree/bindings/mfd/ampere,smpro.yaml |  42 ++
 Documentation/hwmon/index.rst                 |   1 +
 Documentation/hwmon/smpro-hwmon.rst           | 101 ++++
 Documentation/misc-devices/index.rst          |   2 +
 Documentation/misc-devices/smpro-errmon.rst   | 198 ++++++++
 Documentation/misc-devices/smpro-misc.rst     |  82 +++
 drivers/hwmon/Kconfig                         |   8 +
 drivers/hwmon/Makefile                        |   1 +
 drivers/hwmon/smpro-hwmon.c                   | 465 +++++++++++++++++
 drivers/mfd/Kconfig                           |  12 +
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/smpro-mfd.c                       | 134 +++++
 drivers/misc/Kconfig                          |  22 +
 drivers/misc/Makefile                         |   2 +
 drivers/misc/smpro-errmon.c                   | 477 ++++++++++++++++++
 drivers/misc/smpro-misc.c                     | 161 ++++++
 17 files changed, 1866 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
 create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
 create mode 100644 Documentation/hwmon/smpro-hwmon.rst
 create mode 100644 Documentation/misc-devices/smpro-errmon.rst
 create mode 100644 Documentation/misc-devices/smpro-misc.rst
 create mode 100644 drivers/hwmon/smpro-hwmon.c
 create mode 100644 drivers/mfd/smpro-mfd.c
 create mode 100644 drivers/misc/smpro-errmon.c
 create mode 100644 drivers/misc/smpro-misc.c

-- 
2.35.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* [PATCH v8 1/9] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

This commit adds support for Ampere SMpro hwmon driver. This driver
supports accessing various CPU sensors provided by the SMpro co-processor
including temperature, power, voltages, and current.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
Changes in v8:
  + Masks reserved bit when read 10-bit power value    [Quan]
  + Insert 'break;' to avoid fall-through [kernel test robot]
    Dear Guenter, I still keep your Reviewed-by here with these
  changes, expecting you are still OK with them. Please let me
  know if otherwise. Thanks.

Changes in v7:
  + Update GPL version [Quan]

Changes in v6:
  + None

Changes in v5:
  + Drop ManufacturerID checking when probe as it was checked during
  smpro-mfd probing [Quan]
  + Drop the use of register offset [Quan]
  + Removed the use of compatible string as it is instantiated by
  smpro-mfd driver [Quan]

Changes in v4:
  + Returned regmap_read() error code [Guenter]

Changes in v3:
  + Handled negative temperature value [Guenter]
  + Returned -ENODEV if Manufacturer ID is wrong [Guenter]
  + Refactored smpro_read_string() and smpro_temp_read() [Guenter]
  + Removed smpro_write() function [Guenter]
  + Added minor refactor changes [Quan]

Changes in v2:
  + Removed "virtual" sensors [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Corrected return error code when host is turn off [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed license info as SPDX-License-Identifier existed [Guenter]
  + Added is_visible() support [Guenter]
  + Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
  + Made is_valid_id() return boolean [Guenter]
  + Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
  + Removed unnecessary error message when dev register fail [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Included sensor type and channel in labels [Quan]
  + Refactorized code to fix checkpatch.pl --strict complaint [Quan]

 drivers/hwmon/Kconfig       |   8 +
 drivers/hwmon/Makefile      |   1 +
 drivers/hwmon/smpro-hwmon.c | 465 ++++++++++++++++++++++++++++++++++++
 3 files changed, 474 insertions(+)
 create mode 100644 drivers/hwmon/smpro-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 1f1bb4d858cb..64a46e545a23 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -67,6 +67,14 @@ config SENSORS_ABITUGURU3
 	  This driver can also be built as a module. If so, the module
 	  will be called abituguru3.
 
+config SENSORS_SMPRO
+	tristate "Ampere's Altra SMpro hardware monitoring driver"
+	depends on MFD_SMPRO
+	help
+	  If you say yes here you get support for the thermal, voltage,
+	  current and power sensors of Ampere's Altra processor family SoC
+	  with SMpro co-processor.
+
 config SENSORS_AD7314
 	tristate "Analog Devices AD7314 and compatibles"
 	depends on SPI
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 8a03289e2aa4..00e0b187675b 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -182,6 +182,7 @@ obj-$(CONFIG_SENSORS_SHT4x)	+= sht4x.o
 obj-$(CONFIG_SENSORS_SHTC1)	+= shtc1.o
 obj-$(CONFIG_SENSORS_SIS5595)	+= sis5595.o
 obj-$(CONFIG_SENSORS_SMM665)	+= smm665.o
+obj-$(CONFIG_SENSORS_SMPRO)	+= smpro-hwmon.o
 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
 obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
 obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
diff --git a/drivers/hwmon/smpro-hwmon.c b/drivers/hwmon/smpro-hwmon.c
new file mode 100644
index 000000000000..ccf660f74290
--- /dev/null
+++ b/drivers/hwmon/smpro-hwmon.c
@@ -0,0 +1,465 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMPro Hardware Monitoring Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ */
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+/* Logical Power Sensor Registers */
+#define SOC_TEMP		0x10
+#define SOC_VRD_TEMP		0x11
+#define DIMM_VRD_TEMP		0x12
+#define CORE_VRD_TEMP		0x13
+#define CH0_DIMM_TEMP		0x14
+#define CH1_DIMM_TEMP		0x15
+#define CH2_DIMM_TEMP		0x16
+#define CH3_DIMM_TEMP		0x17
+#define CH4_DIMM_TEMP		0x18
+#define CH5_DIMM_TEMP		0x19
+#define CH6_DIMM_TEMP		0x1A
+#define CH7_DIMM_TEMP		0x1B
+#define RCA_VRD_TEMP		0x1C
+
+#define CORE_VRD_PWR		0x20
+#define SOC_PWR			0x21
+#define DIMM_VRD1_PWR		0x22
+#define DIMM_VRD2_PWR		0x23
+#define CORE_VRD_PWR_MW		0x26
+#define SOC_PWR_MW		0x27
+#define DIMM_VRD1_PWR_MW	0x28
+#define DIMM_VRD2_PWR_MW	0x29
+#define RCA_VRD_PWR		0x2A
+#define RCA_VRD_PWR_MW		0x2B
+
+#define MEM_HOT_THRESHOLD	0x32
+#define SOC_VR_HOT_THRESHOLD	0x33
+#define CORE_VRD_VOLT		0x34
+#define SOC_VRD_VOLT		0x35
+#define DIMM_VRD1_VOLT		0x36
+#define DIMM_VRD2_VOLT		0x37
+#define RCA_VRD_VOLT		0x38
+
+#define CORE_VRD_CURR		0x39
+#define SOC_VRD_CURR		0x3A
+#define DIMM_VRD1_CURR		0x3B
+#define DIMM_VRD2_CURR		0x3C
+#define RCA_VRD_CURR		0x3D
+
+struct smpro_hwmon {
+	struct regmap *regmap;
+};
+
+struct smpro_sensor {
+	const u8 reg;
+	const u8 reg_ext;
+	const char *label;
+};
+
+static const struct smpro_sensor temperature[] = {
+	{
+		.reg = SOC_TEMP,
+		.label = "temp1 SoC"
+	},
+	{
+		.reg = SOC_VRD_TEMP,
+		.reg_ext = SOC_VR_HOT_THRESHOLD,
+		.label = "temp2 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD_TEMP,
+		.label = "temp3 DIMM VRD"
+	},
+	{
+		.reg = CORE_VRD_TEMP,
+		.label = "temp4 CORE VRD"
+	},
+	{
+		.reg = CH0_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp5 CH0 DIMM"
+	},
+	{
+		.reg = CH1_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp6 CH1 DIMM"
+	},
+	{
+		.reg = CH2_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp7 CH2 DIMM"
+	},
+	{
+		.reg = CH3_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp8 CH3 DIMM"
+	},
+	{
+		.reg = CH4_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp9 CH4 DIMM"
+	},
+	{
+		.reg = CH5_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp10 CH5 DIMM"
+	},
+	{
+		.reg = CH6_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp11 CH6 DIMM"
+	},
+	{
+		.reg = CH7_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp12 CH7 DIMM"
+	},
+	{
+		.reg = RCA_VRD_TEMP,
+		.label = "temp13 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor voltage[] = {
+	{
+		.reg = CORE_VRD_VOLT,
+		.label = "vout0 CORE VRD"
+	},
+	{
+		.reg = SOC_VRD_VOLT,
+		.label = "vout1 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD1_VOLT,
+		.label = "vout2 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_VOLT,
+		.label = "vout3 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_VOLT,
+		.label = "vout4 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor curr_sensor[] = {
+	{
+		.reg = CORE_VRD_CURR,
+		.label = "iout1 CORE VRD"
+	},
+	{
+		.reg = SOC_VRD_CURR,
+		.label = "iout2 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD1_CURR,
+		.label = "iout3 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_CURR,
+		.label = "iout4 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_CURR,
+		.label = "iout5 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor power[] = {
+	{
+		.reg = CORE_VRD_PWR,
+		.reg_ext = CORE_VRD_PWR_MW,
+		.label = "power1 CORE VRD"
+	},
+	{
+		.reg = SOC_PWR,
+		.reg_ext = SOC_PWR_MW,
+		.label = "power2 SoC"
+	},
+	{
+		.reg = DIMM_VRD1_PWR,
+		.reg_ext = DIMM_VRD1_PWR_MW,
+		.label = "power3 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_PWR,
+		.reg_ext = DIMM_VRD2_PWR_MW,
+		.label = "power4 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_PWR,
+		.reg_ext = RCA_VRD_PWR_MW,
+		.label = "power5 RCA VRD"
+	},
+};
+
+static int smpro_read_temp(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_temp_input:
+		ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+		if (ret)
+			return ret;
+		break;
+	case hwmon_temp_crit:
+		ret = regmap_read(hwmon->regmap, temperature[channel].reg_ext, &value);
+		if (ret)
+			return ret;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	*val = sign_extend32(value, 8) * 1000;
+	return 0;
+}
+
+static int smpro_read_in(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_in_input:
+		ret = regmap_read(hwmon->regmap, voltage[channel].reg, &value);
+		if (ret < 0)
+			return ret;
+		/* 15-bit value in 1mV */
+		*val = value & 0x7fff;
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_curr(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_curr_input:
+		ret = regmap_read(hwmon->regmap, curr_sensor[channel].reg, &value);
+		if (ret < 0)
+			return ret;
+		/* Scale reported by the hardware is 1mA */
+		*val = value & 0x7fff;
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_power(struct device *dev, u32 attr, int channel, long *val_pwr)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int val = 0, val_mw = 0;
+	int ret;
+
+	switch (attr) {
+	case hwmon_power_input:
+		ret = regmap_read(hwmon->regmap, power[channel].reg, &val);
+		if (ret)
+			return ret;
+
+		ret = regmap_read(hwmon->regmap, power[channel].reg_ext, &val_mw);
+		if (ret)
+			return ret;
+		/* 10-bit value */
+		*val_pwr = (val & 0x3ff) * 1000000 + (val_mw & 0x3ff) * 1000;
+		return 0;
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read(struct device *dev, enum hwmon_sensor_types type,
+		      u32 attr, int channel, long *val)
+{
+	switch (type) {
+	case hwmon_temp:
+		return smpro_read_temp(dev, attr, channel, val);
+	case hwmon_in:
+		return smpro_read_in(dev, attr, channel, val);
+	case hwmon_power:
+		return smpro_read_power(dev, attr, channel, val);
+	case hwmon_curr:
+		return smpro_read_curr(dev, attr, channel, val);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_string(struct device *dev, enum hwmon_sensor_types type,
+			     u32 attr, int channel, const char **str)
+{
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_label:
+			*str = temperature[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_label:
+			*str = voltage[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_curr:
+		switch (attr) {
+		case hwmon_curr_label:
+			*str = curr_sensor[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_power:
+		switch (attr) {
+		case hwmon_power_label:
+			*str = power[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static umode_t smpro_is_visible(const void *data, enum hwmon_sensor_types type,
+				u32 attr, int channel)
+{
+	const struct smpro_hwmon *hwmon = data;
+	unsigned int value;
+	int ret;
+
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_input:
+		case hwmon_temp_label:
+		case hwmon_temp_crit:
+			ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+			if (ret || value == 0xFFFF)
+				return 0;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+
+	return 0444;
+}
+
+static const struct hwmon_channel_info *smpro_info[] = {
+	HWMON_CHANNEL_INFO(temp,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL),
+	HWMON_CHANNEL_INFO(in,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL),
+	HWMON_CHANNEL_INFO(power,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL),
+	HWMON_CHANNEL_INFO(curr,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL),
+	NULL
+};
+
+static const struct hwmon_ops smpro_hwmon_ops = {
+	.is_visible = smpro_is_visible,
+	.read = smpro_read,
+	.read_string = smpro_read_string,
+};
+
+static const struct hwmon_chip_info smpro_chip_info = {
+	.ops = &smpro_hwmon_ops,
+	.info = smpro_info,
+};
+
+static int smpro_hwmon_probe(struct platform_device *pdev)
+{
+	struct smpro_hwmon *hwmon;
+	struct device *hwmon_dev;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_hwmon), GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	hwmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!hwmon->regmap)
+		return -ENODEV;
+
+	hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, "smpro_hwmon",
+							 hwmon, &smpro_chip_info, NULL);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static struct platform_driver smpro_hwmon_driver = {
+	.probe		= smpro_hwmon_probe,
+	.driver = {
+		.name	= "smpro-hwmon",
+	},
+};
+
+module_platform_driver(smpro_hwmon_driver);
+
+MODULE_AUTHOR("Thu Nguyen <thu@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMPro hwmon driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 1/9] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

This commit adds support for Ampere SMpro hwmon driver. This driver
supports accessing various CPU sensors provided by the SMpro co-processor
including temperature, power, voltages, and current.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
Changes in v8:
  + Masks reserved bit when read 10-bit power value    [Quan]
  + Insert 'break;' to avoid fall-through [kernel test robot]
    Dear Guenter, I still keep your Reviewed-by here with these
  changes, expecting you are still OK with them. Please let me
  know if otherwise. Thanks.

Changes in v7:
  + Update GPL version [Quan]

Changes in v6:
  + None

Changes in v5:
  + Drop ManufacturerID checking when probe as it was checked during
  smpro-mfd probing [Quan]
  + Drop the use of register offset [Quan]
  + Removed the use of compatible string as it is instantiated by
  smpro-mfd driver [Quan]

Changes in v4:
  + Returned regmap_read() error code [Guenter]

Changes in v3:
  + Handled negative temperature value [Guenter]
  + Returned -ENODEV if Manufacturer ID is wrong [Guenter]
  + Refactored smpro_read_string() and smpro_temp_read() [Guenter]
  + Removed smpro_write() function [Guenter]
  + Added minor refactor changes [Quan]

Changes in v2:
  + Removed "virtual" sensors [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Corrected return error code when host is turn off [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed license info as SPDX-License-Identifier existed [Guenter]
  + Added is_visible() support [Guenter]
  + Used HWMON_CHANNEL_INFO() macro and LABEL attributes [Guenter]
  + Made is_valid_id() return boolean [Guenter]
  + Returned -EPROBE_DEFER when smpro reg inaccessible [Guenter]
  + Removed unnecessary error message when dev register fail [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Included sensor type and channel in labels [Quan]
  + Refactorized code to fix checkpatch.pl --strict complaint [Quan]

 drivers/hwmon/Kconfig       |   8 +
 drivers/hwmon/Makefile      |   1 +
 drivers/hwmon/smpro-hwmon.c | 465 ++++++++++++++++++++++++++++++++++++
 3 files changed, 474 insertions(+)
 create mode 100644 drivers/hwmon/smpro-hwmon.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 1f1bb4d858cb..64a46e545a23 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -67,6 +67,14 @@ config SENSORS_ABITUGURU3
 	  This driver can also be built as a module. If so, the module
 	  will be called abituguru3.
 
+config SENSORS_SMPRO
+	tristate "Ampere's Altra SMpro hardware monitoring driver"
+	depends on MFD_SMPRO
+	help
+	  If you say yes here you get support for the thermal, voltage,
+	  current and power sensors of Ampere's Altra processor family SoC
+	  with SMpro co-processor.
+
 config SENSORS_AD7314
 	tristate "Analog Devices AD7314 and compatibles"
 	depends on SPI
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 8a03289e2aa4..00e0b187675b 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -182,6 +182,7 @@ obj-$(CONFIG_SENSORS_SHT4x)	+= sht4x.o
 obj-$(CONFIG_SENSORS_SHTC1)	+= shtc1.o
 obj-$(CONFIG_SENSORS_SIS5595)	+= sis5595.o
 obj-$(CONFIG_SENSORS_SMM665)	+= smm665.o
+obj-$(CONFIG_SENSORS_SMPRO)	+= smpro-hwmon.o
 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
 obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
 obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
diff --git a/drivers/hwmon/smpro-hwmon.c b/drivers/hwmon/smpro-hwmon.c
new file mode 100644
index 000000000000..ccf660f74290
--- /dev/null
+++ b/drivers/hwmon/smpro-hwmon.c
@@ -0,0 +1,465 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMPro Hardware Monitoring Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ */
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+/* Logical Power Sensor Registers */
+#define SOC_TEMP		0x10
+#define SOC_VRD_TEMP		0x11
+#define DIMM_VRD_TEMP		0x12
+#define CORE_VRD_TEMP		0x13
+#define CH0_DIMM_TEMP		0x14
+#define CH1_DIMM_TEMP		0x15
+#define CH2_DIMM_TEMP		0x16
+#define CH3_DIMM_TEMP		0x17
+#define CH4_DIMM_TEMP		0x18
+#define CH5_DIMM_TEMP		0x19
+#define CH6_DIMM_TEMP		0x1A
+#define CH7_DIMM_TEMP		0x1B
+#define RCA_VRD_TEMP		0x1C
+
+#define CORE_VRD_PWR		0x20
+#define SOC_PWR			0x21
+#define DIMM_VRD1_PWR		0x22
+#define DIMM_VRD2_PWR		0x23
+#define CORE_VRD_PWR_MW		0x26
+#define SOC_PWR_MW		0x27
+#define DIMM_VRD1_PWR_MW	0x28
+#define DIMM_VRD2_PWR_MW	0x29
+#define RCA_VRD_PWR		0x2A
+#define RCA_VRD_PWR_MW		0x2B
+
+#define MEM_HOT_THRESHOLD	0x32
+#define SOC_VR_HOT_THRESHOLD	0x33
+#define CORE_VRD_VOLT		0x34
+#define SOC_VRD_VOLT		0x35
+#define DIMM_VRD1_VOLT		0x36
+#define DIMM_VRD2_VOLT		0x37
+#define RCA_VRD_VOLT		0x38
+
+#define CORE_VRD_CURR		0x39
+#define SOC_VRD_CURR		0x3A
+#define DIMM_VRD1_CURR		0x3B
+#define DIMM_VRD2_CURR		0x3C
+#define RCA_VRD_CURR		0x3D
+
+struct smpro_hwmon {
+	struct regmap *regmap;
+};
+
+struct smpro_sensor {
+	const u8 reg;
+	const u8 reg_ext;
+	const char *label;
+};
+
+static const struct smpro_sensor temperature[] = {
+	{
+		.reg = SOC_TEMP,
+		.label = "temp1 SoC"
+	},
+	{
+		.reg = SOC_VRD_TEMP,
+		.reg_ext = SOC_VR_HOT_THRESHOLD,
+		.label = "temp2 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD_TEMP,
+		.label = "temp3 DIMM VRD"
+	},
+	{
+		.reg = CORE_VRD_TEMP,
+		.label = "temp4 CORE VRD"
+	},
+	{
+		.reg = CH0_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp5 CH0 DIMM"
+	},
+	{
+		.reg = CH1_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp6 CH1 DIMM"
+	},
+	{
+		.reg = CH2_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp7 CH2 DIMM"
+	},
+	{
+		.reg = CH3_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp8 CH3 DIMM"
+	},
+	{
+		.reg = CH4_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp9 CH4 DIMM"
+	},
+	{
+		.reg = CH5_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp10 CH5 DIMM"
+	},
+	{
+		.reg = CH6_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp11 CH6 DIMM"
+	},
+	{
+		.reg = CH7_DIMM_TEMP,
+		.reg_ext = MEM_HOT_THRESHOLD,
+		.label = "temp12 CH7 DIMM"
+	},
+	{
+		.reg = RCA_VRD_TEMP,
+		.label = "temp13 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor voltage[] = {
+	{
+		.reg = CORE_VRD_VOLT,
+		.label = "vout0 CORE VRD"
+	},
+	{
+		.reg = SOC_VRD_VOLT,
+		.label = "vout1 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD1_VOLT,
+		.label = "vout2 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_VOLT,
+		.label = "vout3 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_VOLT,
+		.label = "vout4 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor curr_sensor[] = {
+	{
+		.reg = CORE_VRD_CURR,
+		.label = "iout1 CORE VRD"
+	},
+	{
+		.reg = SOC_VRD_CURR,
+		.label = "iout2 SoC VRD"
+	},
+	{
+		.reg = DIMM_VRD1_CURR,
+		.label = "iout3 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_CURR,
+		.label = "iout4 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_CURR,
+		.label = "iout5 RCA VRD"
+	},
+};
+
+static const struct smpro_sensor power[] = {
+	{
+		.reg = CORE_VRD_PWR,
+		.reg_ext = CORE_VRD_PWR_MW,
+		.label = "power1 CORE VRD"
+	},
+	{
+		.reg = SOC_PWR,
+		.reg_ext = SOC_PWR_MW,
+		.label = "power2 SoC"
+	},
+	{
+		.reg = DIMM_VRD1_PWR,
+		.reg_ext = DIMM_VRD1_PWR_MW,
+		.label = "power3 DIMM VRD1"
+	},
+	{
+		.reg = DIMM_VRD2_PWR,
+		.reg_ext = DIMM_VRD2_PWR_MW,
+		.label = "power4 DIMM VRD2"
+	},
+	{
+		.reg = RCA_VRD_PWR,
+		.reg_ext = RCA_VRD_PWR_MW,
+		.label = "power5 RCA VRD"
+	},
+};
+
+static int smpro_read_temp(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_temp_input:
+		ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+		if (ret)
+			return ret;
+		break;
+	case hwmon_temp_crit:
+		ret = regmap_read(hwmon->regmap, temperature[channel].reg_ext, &value);
+		if (ret)
+			return ret;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	*val = sign_extend32(value, 8) * 1000;
+	return 0;
+}
+
+static int smpro_read_in(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_in_input:
+		ret = regmap_read(hwmon->regmap, voltage[channel].reg, &value);
+		if (ret < 0)
+			return ret;
+		/* 15-bit value in 1mV */
+		*val = value & 0x7fff;
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_curr(struct device *dev, u32 attr, int channel, long *val)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	switch (attr) {
+	case hwmon_curr_input:
+		ret = regmap_read(hwmon->regmap, curr_sensor[channel].reg, &value);
+		if (ret < 0)
+			return ret;
+		/* Scale reported by the hardware is 1mA */
+		*val = value & 0x7fff;
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_power(struct device *dev, u32 attr, int channel, long *val_pwr)
+{
+	struct smpro_hwmon *hwmon = dev_get_drvdata(dev);
+	unsigned int val = 0, val_mw = 0;
+	int ret;
+
+	switch (attr) {
+	case hwmon_power_input:
+		ret = regmap_read(hwmon->regmap, power[channel].reg, &val);
+		if (ret)
+			return ret;
+
+		ret = regmap_read(hwmon->regmap, power[channel].reg_ext, &val_mw);
+		if (ret)
+			return ret;
+		/* 10-bit value */
+		*val_pwr = (val & 0x3ff) * 1000000 + (val_mw & 0x3ff) * 1000;
+		return 0;
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read(struct device *dev, enum hwmon_sensor_types type,
+		      u32 attr, int channel, long *val)
+{
+	switch (type) {
+	case hwmon_temp:
+		return smpro_read_temp(dev, attr, channel, val);
+	case hwmon_in:
+		return smpro_read_in(dev, attr, channel, val);
+	case hwmon_power:
+		return smpro_read_power(dev, attr, channel, val);
+	case hwmon_curr:
+		return smpro_read_curr(dev, attr, channel, val);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int smpro_read_string(struct device *dev, enum hwmon_sensor_types type,
+			     u32 attr, int channel, const char **str)
+{
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_label:
+			*str = temperature[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_in:
+		switch (attr) {
+		case hwmon_in_label:
+			*str = voltage[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_curr:
+		switch (attr) {
+		case hwmon_curr_label:
+			*str = curr_sensor[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+
+	case hwmon_power:
+		switch (attr) {
+		case hwmon_power_label:
+			*str = power[channel].label;
+			return 0;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+
+	return -EOPNOTSUPP;
+}
+
+static umode_t smpro_is_visible(const void *data, enum hwmon_sensor_types type,
+				u32 attr, int channel)
+{
+	const struct smpro_hwmon *hwmon = data;
+	unsigned int value;
+	int ret;
+
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_input:
+		case hwmon_temp_label:
+		case hwmon_temp_crit:
+			ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
+			if (ret || value == 0xFFFF)
+				return 0;
+		default:
+			break;
+		}
+		break;
+	default:
+		break;
+	}
+
+	return 0444;
+}
+
+static const struct hwmon_channel_info *smpro_info[] = {
+	HWMON_CHANNEL_INFO(temp,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_CRIT,
+			   HWMON_T_INPUT | HWMON_T_LABEL),
+	HWMON_CHANNEL_INFO(in,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL,
+			   HWMON_I_INPUT | HWMON_I_LABEL),
+	HWMON_CHANNEL_INFO(power,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL,
+			   HWMON_P_INPUT | HWMON_P_LABEL),
+	HWMON_CHANNEL_INFO(curr,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL,
+			   HWMON_C_INPUT | HWMON_C_LABEL),
+	NULL
+};
+
+static const struct hwmon_ops smpro_hwmon_ops = {
+	.is_visible = smpro_is_visible,
+	.read = smpro_read,
+	.read_string = smpro_read_string,
+};
+
+static const struct hwmon_chip_info smpro_chip_info = {
+	.ops = &smpro_hwmon_ops,
+	.info = smpro_info,
+};
+
+static int smpro_hwmon_probe(struct platform_device *pdev)
+{
+	struct smpro_hwmon *hwmon;
+	struct device *hwmon_dev;
+
+	hwmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_hwmon), GFP_KERNEL);
+	if (!hwmon)
+		return -ENOMEM;
+
+	hwmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!hwmon->regmap)
+		return -ENODEV;
+
+	hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, "smpro_hwmon",
+							 hwmon, &smpro_chip_info, NULL);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static struct platform_driver smpro_hwmon_driver = {
+	.probe		= smpro_hwmon_probe,
+	.driver = {
+		.name	= "smpro-hwmon",
+	},
+};
+
+module_platform_driver(smpro_hwmon_driver);
+
+MODULE_AUTHOR("Thu Nguyen <thu@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMPro hwmon driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 2/9] docs: hwmon: (smpro-hwmon) Add documentation
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Add documentation for the Ampere(R)'s Altra(R) SMpro hwmon driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
Changes from v3=>v8:
  + None

Changes in v2:
  + Removed "virtual" sensors [Guenter]
  + Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Clarified "highest" meaning in documentation [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Included sensor type and channel in labels [Quan]

 Documentation/hwmon/index.rst       |   1 +
 Documentation/hwmon/smpro-hwmon.rst | 101 ++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/hwmon/smpro-hwmon.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 863b76289159..833dd38c93a6 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -184,6 +184,7 @@ Hardware Monitoring Kernel Drivers
    sis5595
    sl28cpld
    smm665
+   smpro-hwmon
    smsc47b397
    smsc47m192
    smsc47m1
diff --git a/Documentation/hwmon/smpro-hwmon.rst b/Documentation/hwmon/smpro-hwmon.rst
new file mode 100644
index 000000000000..f978b1370e16
--- /dev/null
+++ b/Documentation/hwmon/smpro-hwmon.rst
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro hwmon
+==============================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following sensor types are supported by the driver:
+
+  * temperature
+  * voltage
+  * current
+  * power
+
+The SMpro interface provides the registers to query the various sensors and
+their values which are then exported to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro hwmon driver creates at least two sysfs files for each sensor.
+
+* File ``<sensor_type><idx>_label`` reports the sensor label.
+* File ``<sensor_type><idx>_input`` returns the sensor value.
+
+The sysfs files are allocated in the SMpro root fs folder.
+There is one root folder for each SMpro instance.
+
+When the SoC is turned off, the driver will fail to read registers
+and return -ENXIO.
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+============    =============   ======  ===============================================
+Name            Unit            Perm    Description
+temp1_input     milli Celsius   RO      SoC temperature
+temp2_input     milli Celsius   RO      Max temperature reported among SoC VRDs
+temp2_crit      milli Celsius   RO      SoC VRD HOT Threshold temperature
+temp3_input     milli Celsius   RO      Max temperature reported among DIMM VRDs
+temp4_input     milli Celsius   RO      Max temperature reported among Core VRDs
+temp5_input     milli Celsius   RO      Temperature of DIMM0 on CH0
+temp5_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp6_input     milli Celsius   RO      Temperature of DIMM0 on CH1
+temp6_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp7_input     milli Celsius   RO      Temperature of DIMM0 on CH2
+temp7_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp8_input     milli Celsius   RO      Temperature of DIMM0 on CH3
+temp8_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp9_input     milli Celsius   RO      Temperature of DIMM0 on CH4
+temp9_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp10_input    milli Celsius   RO      Temperature of DIMM0 on CH5
+temp10_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp11_input    milli Celsius   RO      Temperature of DIMM0 on CH6
+temp11_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp12_input    milli Celsius   RO      Temperature of DIMM0 on CH7
+temp12_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp13_input    milli Celsius   RO      Max temperature reported among RCA VRDs
+in0_input       milli Volts     RO      Core voltage
+in1_input       milli Volts     RO      SoC voltage
+in2_input       milli Volts     RO      DIMM VRD1 voltage
+in3_input       milli Volts     RO      DIMM VRD2 voltage
+in4_input       milli Volts     RO      RCA VRD voltage
+cur1_input      milli Amperes   RO      Core VRD current
+cur2_input      milli Amperes   RO      SoC VRD current
+cur3_input      milli Amperes   RO      DIMM VRD1 current
+cur4_input      milli Amperes   RO      DIMM VRD2 current
+cur5_input      milli Amperes   RO      RCA VRD current
+power1_input    micro Watts     RO      Core VRD power
+power2_input    micro Watts     RO      SoC VRD power
+power3_input    micro Watts     RO      DIMM VRD1 power
+power4_input    micro Watts     RO      DIMM VRD2 power
+power5_input    micro Watts     RO      RCA VRD power
+============    =============   ======  ===============================================
+
+Example::
+
+    # cat in0_input
+    830
+    # cat temp1_input
+    37000
+    # cat curr1_input
+    9000
+    # cat power5_input
+    19500000
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 2/9] docs: hwmon: (smpro-hwmon) Add documentation
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Add documentation for the Ampere(R)'s Altra(R) SMpro hwmon driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
Changes from v3=>v8:
  + None

Changes in v2:
  + Removed "virtual" sensors [Guenter]
  + Fixed typo "mili" to "milli", "nanoWatt" to "microWatt" [Guenter]
  + Reported SOC_TDP as "Socket TDP" using max attributes [Guenter]
  + Clarified "highest" meaning in documentation [Guenter]
  + Reported MEM HOT Threshold for all DIMMs as temp*_crit [Guenter]
  + Removed Socket TDP sensor [Quan]
  + Included sensor type and channel in labels [Quan]

 Documentation/hwmon/index.rst       |   1 +
 Documentation/hwmon/smpro-hwmon.rst | 101 ++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/hwmon/smpro-hwmon.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 863b76289159..833dd38c93a6 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -184,6 +184,7 @@ Hardware Monitoring Kernel Drivers
    sis5595
    sl28cpld
    smm665
+   smpro-hwmon
    smsc47b397
    smsc47m192
    smsc47m1
diff --git a/Documentation/hwmon/smpro-hwmon.rst b/Documentation/hwmon/smpro-hwmon.rst
new file mode 100644
index 000000000000..f978b1370e16
--- /dev/null
+++ b/Documentation/hwmon/smpro-hwmon.rst
@@ -0,0 +1,101 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro hwmon
+==============================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following sensor types are supported by the driver:
+
+  * temperature
+  * voltage
+  * current
+  * power
+
+The SMpro interface provides the registers to query the various sensors and
+their values which are then exported to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro hwmon driver creates at least two sysfs files for each sensor.
+
+* File ``<sensor_type><idx>_label`` reports the sensor label.
+* File ``<sensor_type><idx>_input`` returns the sensor value.
+
+The sysfs files are allocated in the SMpro root fs folder.
+There is one root folder for each SMpro instance.
+
+When the SoC is turned off, the driver will fail to read registers
+and return -ENXIO.
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+============    =============   ======  ===============================================
+Name            Unit            Perm    Description
+temp1_input     milli Celsius   RO      SoC temperature
+temp2_input     milli Celsius   RO      Max temperature reported among SoC VRDs
+temp2_crit      milli Celsius   RO      SoC VRD HOT Threshold temperature
+temp3_input     milli Celsius   RO      Max temperature reported among DIMM VRDs
+temp4_input     milli Celsius   RO      Max temperature reported among Core VRDs
+temp5_input     milli Celsius   RO      Temperature of DIMM0 on CH0
+temp5_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp6_input     milli Celsius   RO      Temperature of DIMM0 on CH1
+temp6_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp7_input     milli Celsius   RO      Temperature of DIMM0 on CH2
+temp7_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp8_input     milli Celsius   RO      Temperature of DIMM0 on CH3
+temp8_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp9_input     milli Celsius   RO      Temperature of DIMM0 on CH4
+temp9_crit      milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp10_input    milli Celsius   RO      Temperature of DIMM0 on CH5
+temp10_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp11_input    milli Celsius   RO      Temperature of DIMM0 on CH6
+temp11_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp12_input    milli Celsius   RO      Temperature of DIMM0 on CH7
+temp12_crit     milli Celsius   RO      MEM HOT Threshold for all DIMMs
+temp13_input    milli Celsius   RO      Max temperature reported among RCA VRDs
+in0_input       milli Volts     RO      Core voltage
+in1_input       milli Volts     RO      SoC voltage
+in2_input       milli Volts     RO      DIMM VRD1 voltage
+in3_input       milli Volts     RO      DIMM VRD2 voltage
+in4_input       milli Volts     RO      RCA VRD voltage
+cur1_input      milli Amperes   RO      Core VRD current
+cur2_input      milli Amperes   RO      SoC VRD current
+cur3_input      milli Amperes   RO      DIMM VRD1 current
+cur4_input      milli Amperes   RO      DIMM VRD2 current
+cur5_input      milli Amperes   RO      RCA VRD current
+power1_input    micro Watts     RO      Core VRD power
+power2_input    micro Watts     RO      SoC VRD power
+power3_input    micro Watts     RO      DIMM VRD1 power
+power4_input    micro Watts     RO      DIMM VRD2 power
+power5_input    micro Watts     RO      RCA VRD power
+============    =============   ======  ===============================================
+
+Example::
+
+    # cat in0_input
+    830
+    # cat temp1_input
+    37000
+    # cat curr1_input
+    9000
+    # cat power5_input
+    19500000
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

This commit adds Ampere's SMpro error monitor driver for monitoring
and reporting RAS-related errors as reported by SMpro co-processor
found on Ampere's Altra processor family.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
  + Avoid uninitialized variable use               [kernel test robot]
  + Switch to use sysfs_emit()                                  [Greg]
  + Make sysfs to return single value                           [Greg]
  + Change errors_* sysfs to error_*                            [Quan]
  + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
  overflow status of each type of HW errors                     [Quan]
  + Add some minor refactor                                     [Quan]

Changes in v7:
  + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
  + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
  + Validate number of errors before read                       [Quan]
  + Fix wrong return type of *_show() function     [kernel test robot]
  + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
  + Use pointer instead of stack memory                         [Quan]

Changes in v6:
  + First introduced in v6 [Quan]

 drivers/misc/Kconfig        |  12 +
 drivers/misc/Makefile       |   1 +
 drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
 3 files changed, 490 insertions(+)
 create mode 100644 drivers/misc/smpro-errmon.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 41d2bb0ae23a..9fbe6797c440 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -176,6 +176,18 @@ config SGI_XP
 	  this feature will allow for direct communication between SSIs
 	  based on a network adapter and DMA messaging.
 
+config SMPRO_ERRMON
+	tristate "Ampere Computing SMPro error monitor driver"
+	depends on MFD_SMPRO || COMPILE_TEST
+	help
+	  Say Y here to get support for the SMpro error monitor function
+	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
+	  loading, the driver creates sysfs files which can be use to gather
+	  multiple HW error data reported via read and write system calls.
+
+	  To compile this driver as a module, say M here. The driver will be
+	  called smpro-errmon.
+
 config CS5535_MFGPT
 	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
 	depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 70e800e9127f..483308a6e113 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
 obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
 obj-$(CONFIG_SGI_XP)		+= sgi-xp/
 obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
+obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
 obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
 obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
 obj-$(CONFIG_HP_ILO)		+= hpilo.o
diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
new file mode 100644
index 000000000000..df7d8fc4ff3f
--- /dev/null
+++ b/drivers/misc/smpro-errmon.c
@@ -0,0 +1,477 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Error Monitoring Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ *
+ */
+
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* GPI RAS Error Registers */
+#define GPI_RAS_ERR		0x7E
+
+/* Core and L2C Error Registers */
+#define CORE_CE_ERR_CNT		0x80
+#define CORE_CE_ERR_LEN		0x81
+#define CORE_CE_ERR_DATA	0x82
+#define CORE_UE_ERR_CNT		0x83
+#define CORE_UE_ERR_LEN		0x84
+#define CORE_UE_ERR_DATA	0x85
+
+/* Memory Error Registers */
+#define MEM_CE_ERR_CNT		0x90
+#define MEM_CE_ERR_LEN		0x91
+#define MEM_CE_ERR_DATA		0x92
+#define MEM_UE_ERR_CNT		0x93
+#define MEM_UE_ERR_LEN		0x94
+#define MEM_UE_ERR_DATA		0x95
+
+/* RAS Error/Warning Registers */
+#define ERR_SMPRO_TYPE		0xA0
+#define ERR_PMPRO_TYPE		0xA1
+#define ERR_SMPRO_INFO_LO	0xA2
+#define ERR_SMPRO_INFO_HI	0xA3
+#define ERR_SMPRO_DATA_LO	0xA4
+#define ERR_SMPRO_DATA_HI	0xA5
+#define WARN_SMPRO_INFO_LO	0xAA
+#define WARN_SMPRO_INFO_HI	0xAB
+#define ERR_PMPRO_INFO_LO	0xA6
+#define ERR_PMPRO_INFO_HI	0xA7
+#define ERR_PMPRO_DATA_LO	0xA8
+#define ERR_PMPRO_DATA_HI	0xA9
+#define WARN_PMPRO_INFO_LO	0xAC
+#define WARN_PMPRO_INFO_HI	0xAD
+
+/* PCIE Error Registers */
+#define PCIE_CE_ERR_CNT		0xC0
+#define PCIE_CE_ERR_LEN		0xC1
+#define PCIE_CE_ERR_DATA	0xC2
+#define PCIE_UE_ERR_CNT		0xC3
+#define PCIE_UE_ERR_LEN		0xC4
+#define PCIE_UE_ERR_DATA	0xC5
+
+/* Other Error Registers */
+#define OTHER_CE_ERR_CNT	0xD0
+#define OTHER_CE_ERR_LEN	0xD1
+#define OTHER_CE_ERR_DATA	0xD2
+#define OTHER_UE_ERR_CNT	0xD8
+#define OTHER_UE_ERR_LEN	0xD9
+#define OTHER_UE_ERR_DATA	0xDA
+
+/* Event Data Registers */
+#define VRD_WARN_FAULT_EVENT_DATA	0x78
+#define VRD_HOT_EVENT_DATA		0x79
+#define DIMM_HOT_EVENT_DATA		0x7A
+#define DIMM_2X_REFRESH_EVENT_DATA	0x96
+
+#define MAX_READ_BLOCK_LENGTH	48
+#define NUM_I2C_MESSAGES	2
+#define MAX_MSG_LEN		128
+
+#define RAS_SMPRO_ERRS		0
+#define RAS_PMPRO_ERRS		1
+
+enum RAS_48BYTES_ERR_TYPES {
+	CORE_CE_ERRS,
+	CORE_UE_ERRS,
+	MEM_CE_ERRS,
+	MEM_UE_ERRS,
+	PCIE_CE_ERRS,
+	PCIE_UE_ERRS,
+	OTHER_CE_ERRS,
+	OTHER_UE_ERRS,
+	NUM_48BYTES_ERR_TYPE,
+};
+
+struct smpro_error_hdr {
+	u8 err_count;	/* Number of the RAS errors */
+	u8 err_len;	/* Number of data bytes */
+	u8 err_data;	/* Start of 48-byte data */
+	u8 max_err_cnt;	/* Max num of errors */
+};
+
+/*
+ * Included Address of registers to get Count, Length of data and Data
+ * of the 48 bytes error data
+ */
+static struct smpro_error_hdr smpro_error_table[NUM_48BYTES_ERR_TYPE] = {
+	{CORE_CE_ERR_CNT, CORE_CE_ERR_LEN, CORE_CE_ERR_DATA, 32},
+	{CORE_UE_ERR_CNT, CORE_UE_ERR_LEN, CORE_UE_ERR_DATA, 32},
+	{MEM_CE_ERR_CNT, MEM_CE_ERR_LEN, MEM_CE_ERR_DATA, 16},
+	{MEM_UE_ERR_CNT, MEM_UE_ERR_LEN, MEM_UE_ERR_DATA, 16},
+	{PCIE_CE_ERR_CNT, PCIE_CE_ERR_LEN, PCIE_CE_ERR_DATA, 96},
+	{PCIE_UE_ERR_CNT, PCIE_UE_ERR_LEN, PCIE_UE_ERR_DATA, 96},
+	{OTHER_CE_ERR_CNT, OTHER_CE_ERR_LEN, OTHER_CE_ERR_DATA, 8},
+	{OTHER_UE_ERR_CNT, OTHER_UE_ERR_LEN, OTHER_UE_ERR_DATA, 8},
+};
+
+/*
+ * List of SCP registers which are used to get
+ * one type of RAS Internal errors.
+ */
+struct smpro_int_error_hdr {
+	u8 err_type;
+	u8 err_info_low;
+	u8 err_info_high;
+	u8 err_data_high;
+	u8 err_data_low;
+	u8 warn_info_low;
+	u8 warn_info_high;
+};
+
+static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
+	{
+	 ERR_SMPRO_TYPE,
+	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
+	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
+	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
+	},
+	{
+	 ERR_PMPRO_TYPE,
+	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
+	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
+	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
+	},
+};
+
+struct smpro_errmon {
+	struct regmap *regmap;
+};
+
+enum EVENT_TYPES {
+	VRD_WARN_FAULT_EVENTS,
+	VRD_HOT_EVENTS,
+	DIMM_HOT_EVENTS,
+	NUM_EVENTS_TYPE,
+};
+
+/* Included Address of event source and data registers */
+static u8 smpro_event_table[NUM_EVENTS_TYPE] = {
+	VRD_WARN_FAULT_EVENT_DATA,
+	VRD_HOT_EVENT_DATA,
+	DIMM_HOT_EVENT_DATA,
+};
+
+static ssize_t smpro_event_data_read(struct device *dev,
+				     struct device_attribute *da, char *buf,
+				     int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	s32 event_data;
+	int ret;
+
+	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
+	if (ret)
+		goto done;
+
+	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
+	/* Clear event after read */
+	if (event_data != 0)
+		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
+done:
+	return ret;
+}
+
+static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
+					char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	struct smpro_error_hdr *err_info;
+	s32 err_count;
+	int ret;
+
+	err_info = &smpro_error_table[channel];
+
+	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
+	if (ret)
+		return ret;
+
+	/* Bit 8 indicates the overflow status */
+	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
+}
+
+static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
+				     char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
+	struct smpro_error_hdr *err_info;
+	s32 err_count, err_length;
+	int count = 0;
+	int ret;
+
+	err_info = &smpro_error_table[channel];
+
+	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
+	/* Error count is the low byte */
+	err_count &= 0xff;
+	if (ret || !err_count || err_count > err_info->max_err_cnt)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
+	if (ret || err_length <= 0)
+		goto done;
+
+	if (err_length > MAX_READ_BLOCK_LENGTH)
+		err_length = MAX_READ_BLOCK_LENGTH;
+
+	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
+	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
+	if (ret < 0)
+		goto done;
+
+	/*
+	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
+	 * <Error Type><Error SubType><Instance><Error Status>\
+	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
+	 * Where:
+	 *  + Error Type: The hardwares cause the errors. (1 byte)
+	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
+	 *  + Instance: Combination of the socket, channel,
+	 *    slot cause the error. (2 bytes)
+	 *  + Error Status: Encode of error status. (4 bytes)
+	 *  + Error Address: The address in device causes the errors. (8 bytes)
+	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
+	 * Reference Altra SOC BMC Interface specification.
+	 */
+	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
+			   err_data[0], err_data[1], *(u16 *)&err_data[2],
+			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
+			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
+			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
+
+	/* go to next error */
+	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
+done:
+	return ret ? ret : count;
+}
+
+/*
+ * Output format:
+ * <errType><image><dir><Location><errorCode><data>
+ * Where:
+ *   + errType: SCP Error Type (3 bits)
+ *      1: Warning
+ *      2: Error
+ *      4: Error with data
+ *   + image: SCP Image Code (8 bits)
+ *   + dir: Direction (1 bit)
+ *      0: Enter
+ *      1: Exit
+ *   + location: SCP Module Location Code (8 bits)
+ *   + errorCode: SCP Error Code (16 bits)
+ *   + data : Extensive data (32 bits)
+ *      All bits are 0 when errType is warning or error.
+ */
+static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
+				       char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	struct smpro_int_error_hdr *err_info;
+	unsigned int data_lo = 0, data_hi = 0;
+	unsigned int ret_hi, ret_lo;
+	unsigned int err_type;
+	unsigned int value;
+	int count = 0;
+	int ret;
+
+	/* read error status */
+	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
+	if (ret)
+		goto done;
+
+	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
+	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
+		goto done;
+
+	err_info = &list_smpro_int_error_hdr[channel];
+	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
+	if (ret)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
+	if (ret)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
+	if (ret)
+		goto done;
+
+	if (err_type & BIT(2)) {
+		/* Error with data type */
+		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
+		if (ret)
+			goto done;
+
+		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
+		if (ret)
+			goto done;
+
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
+
+	} else if (err_type & BIT(1)) {
+		/* Error type */
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
+
+	} else if (err_type & BIT(0)) {
+		/* Warning type */
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
+	}
+done:
+	return ret ? ret : count;
+}
+
+#define ERROR_OVERFLOW_RO(_error, _index) \
+	static ssize_t overflow_##_error##_show(struct device *dev,            \
+						struct device_attribute *da,   \
+						char *buf)                     \
+	{                                                                      \
+		return smpro_overflow_data_read(dev, da, buf, _index);         \
+	}                                                                      \
+	static DEVICE_ATTR_RO(overflow_##_error)
+
+ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
+ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
+ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
+ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
+ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
+ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
+ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
+ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
+
+#define ERROR_RO(_error, _index) \
+	static ssize_t error_##_error##_show(struct device *dev,            \
+					     struct device_attribute *da,   \
+					     char *buf)                     \
+	{                                                                   \
+		return smpro_error_data_read(dev, da, buf, _index);         \
+	}                                                                   \
+	static DEVICE_ATTR_RO(error_##_error)
+
+ERROR_RO(core_ce, CORE_CE_ERRS);
+ERROR_RO(core_ue, CORE_UE_ERRS);
+ERROR_RO(mem_ce, MEM_CE_ERRS);
+ERROR_RO(mem_ue, MEM_UE_ERRS);
+ERROR_RO(pcie_ce, PCIE_CE_ERRS);
+ERROR_RO(pcie_ue, PCIE_UE_ERRS);
+ERROR_RO(other_ce, OTHER_CE_ERRS);
+ERROR_RO(other_ue, OTHER_UE_ERRS);
+
+static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(error_smpro);
+
+static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(error_pmpro);
+
+#define EVENT_RO(_event, _index) \
+	static ssize_t event_##_event##_show(struct device *dev,            \
+					     struct device_attribute *da,   \
+					     char *buf)                     \
+	{                                                                   \
+		return smpro_event_data_read(dev, da, buf, _index);         \
+	}                                                                   \
+	static DEVICE_ATTR_RO(event_##_event)
+
+EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
+EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
+EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
+
+static struct attribute *smpro_errmon_attrs[] = {
+	&dev_attr_overflow_core_ce.attr,
+	&dev_attr_overflow_core_ue.attr,
+	&dev_attr_overflow_mem_ce.attr,
+	&dev_attr_overflow_mem_ue.attr,
+	&dev_attr_overflow_pcie_ce.attr,
+	&dev_attr_overflow_pcie_ue.attr,
+	&dev_attr_overflow_other_ce.attr,
+	&dev_attr_overflow_other_ue.attr,
+	&dev_attr_error_core_ce.attr,
+	&dev_attr_error_core_ue.attr,
+	&dev_attr_error_mem_ce.attr,
+	&dev_attr_error_mem_ue.attr,
+	&dev_attr_error_pcie_ce.attr,
+	&dev_attr_error_pcie_ue.attr,
+	&dev_attr_error_other_ce.attr,
+	&dev_attr_error_other_ue.attr,
+	&dev_attr_error_smpro.attr,
+	&dev_attr_error_pmpro.attr,
+	&dev_attr_event_vrd_warn_fault.attr,
+	&dev_attr_event_vrd_hot.attr,
+	&dev_attr_event_dimm_hot.attr,
+	NULL
+};
+
+static const struct attribute_group smpro_errmon_attr_group = {
+	.attrs = smpro_errmon_attrs
+};
+
+static int smpro_errmon_probe(struct platform_device *pdev)
+{
+	struct smpro_errmon *errmon;
+	int ret;
+
+	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
+	if (!errmon)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, errmon);
+
+	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!errmon->regmap)
+		return -ENODEV;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+	if (ret)
+		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
+
+	return 0;
+}
+
+static int smpro_errmon_remove(struct platform_device *pdev)
+{
+	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+	pr_info("SMPro errmon sysfs entries removed");
+
+	return 0;
+}
+
+static struct platform_driver smpro_errmon_driver = {
+	.probe          = smpro_errmon_probe,
+	.remove         = smpro_errmon_remove,
+	.driver = {
+		.name   = "smpro-errmon",
+	},
+};
+
+module_platform_driver(smpro_errmon_driver);
+
+MODULE_AUTHOR("Tung Nguyen <tung.nguyen@amperecomputing.com>");
+MODULE_AUTHOR("Thinh Pham <thinh.pham@amperecomputing.com>");
+MODULE_AUTHOR("Hoang Nguyen <hnguyen@amperecomputing.com>");
+MODULE_AUTHOR("Thu Nguyen <thu@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMpro driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

This commit adds Ampere's SMpro error monitor driver for monitoring
and reporting RAS-related errors as reported by SMpro co-processor
found on Ampere's Altra processor family.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
  + Avoid uninitialized variable use               [kernel test robot]
  + Switch to use sysfs_emit()                                  [Greg]
  + Make sysfs to return single value                           [Greg]
  + Change errors_* sysfs to error_*                            [Quan]
  + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
  overflow status of each type of HW errors                     [Quan]
  + Add some minor refactor                                     [Quan]

Changes in v7:
  + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
  + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
  + Validate number of errors before read                       [Quan]
  + Fix wrong return type of *_show() function     [kernel test robot]
  + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
  + Use pointer instead of stack memory                         [Quan]

Changes in v6:
  + First introduced in v6 [Quan]

 drivers/misc/Kconfig        |  12 +
 drivers/misc/Makefile       |   1 +
 drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
 3 files changed, 490 insertions(+)
 create mode 100644 drivers/misc/smpro-errmon.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 41d2bb0ae23a..9fbe6797c440 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -176,6 +176,18 @@ config SGI_XP
 	  this feature will allow for direct communication between SSIs
 	  based on a network adapter and DMA messaging.
 
+config SMPRO_ERRMON
+	tristate "Ampere Computing SMPro error monitor driver"
+	depends on MFD_SMPRO || COMPILE_TEST
+	help
+	  Say Y here to get support for the SMpro error monitor function
+	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
+	  loading, the driver creates sysfs files which can be use to gather
+	  multiple HW error data reported via read and write system calls.
+
+	  To compile this driver as a module, say M here. The driver will be
+	  called smpro-errmon.
+
 config CS5535_MFGPT
 	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
 	depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 70e800e9127f..483308a6e113 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
 obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
 obj-$(CONFIG_SGI_XP)		+= sgi-xp/
 obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
+obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
 obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
 obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
 obj-$(CONFIG_HP_ILO)		+= hpilo.o
diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
new file mode 100644
index 000000000000..df7d8fc4ff3f
--- /dev/null
+++ b/drivers/misc/smpro-errmon.c
@@ -0,0 +1,477 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Error Monitoring Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ *
+ */
+
+#include <linux/i2c.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* GPI RAS Error Registers */
+#define GPI_RAS_ERR		0x7E
+
+/* Core and L2C Error Registers */
+#define CORE_CE_ERR_CNT		0x80
+#define CORE_CE_ERR_LEN		0x81
+#define CORE_CE_ERR_DATA	0x82
+#define CORE_UE_ERR_CNT		0x83
+#define CORE_UE_ERR_LEN		0x84
+#define CORE_UE_ERR_DATA	0x85
+
+/* Memory Error Registers */
+#define MEM_CE_ERR_CNT		0x90
+#define MEM_CE_ERR_LEN		0x91
+#define MEM_CE_ERR_DATA		0x92
+#define MEM_UE_ERR_CNT		0x93
+#define MEM_UE_ERR_LEN		0x94
+#define MEM_UE_ERR_DATA		0x95
+
+/* RAS Error/Warning Registers */
+#define ERR_SMPRO_TYPE		0xA0
+#define ERR_PMPRO_TYPE		0xA1
+#define ERR_SMPRO_INFO_LO	0xA2
+#define ERR_SMPRO_INFO_HI	0xA3
+#define ERR_SMPRO_DATA_LO	0xA4
+#define ERR_SMPRO_DATA_HI	0xA5
+#define WARN_SMPRO_INFO_LO	0xAA
+#define WARN_SMPRO_INFO_HI	0xAB
+#define ERR_PMPRO_INFO_LO	0xA6
+#define ERR_PMPRO_INFO_HI	0xA7
+#define ERR_PMPRO_DATA_LO	0xA8
+#define ERR_PMPRO_DATA_HI	0xA9
+#define WARN_PMPRO_INFO_LO	0xAC
+#define WARN_PMPRO_INFO_HI	0xAD
+
+/* PCIE Error Registers */
+#define PCIE_CE_ERR_CNT		0xC0
+#define PCIE_CE_ERR_LEN		0xC1
+#define PCIE_CE_ERR_DATA	0xC2
+#define PCIE_UE_ERR_CNT		0xC3
+#define PCIE_UE_ERR_LEN		0xC4
+#define PCIE_UE_ERR_DATA	0xC5
+
+/* Other Error Registers */
+#define OTHER_CE_ERR_CNT	0xD0
+#define OTHER_CE_ERR_LEN	0xD1
+#define OTHER_CE_ERR_DATA	0xD2
+#define OTHER_UE_ERR_CNT	0xD8
+#define OTHER_UE_ERR_LEN	0xD9
+#define OTHER_UE_ERR_DATA	0xDA
+
+/* Event Data Registers */
+#define VRD_WARN_FAULT_EVENT_DATA	0x78
+#define VRD_HOT_EVENT_DATA		0x79
+#define DIMM_HOT_EVENT_DATA		0x7A
+#define DIMM_2X_REFRESH_EVENT_DATA	0x96
+
+#define MAX_READ_BLOCK_LENGTH	48
+#define NUM_I2C_MESSAGES	2
+#define MAX_MSG_LEN		128
+
+#define RAS_SMPRO_ERRS		0
+#define RAS_PMPRO_ERRS		1
+
+enum RAS_48BYTES_ERR_TYPES {
+	CORE_CE_ERRS,
+	CORE_UE_ERRS,
+	MEM_CE_ERRS,
+	MEM_UE_ERRS,
+	PCIE_CE_ERRS,
+	PCIE_UE_ERRS,
+	OTHER_CE_ERRS,
+	OTHER_UE_ERRS,
+	NUM_48BYTES_ERR_TYPE,
+};
+
+struct smpro_error_hdr {
+	u8 err_count;	/* Number of the RAS errors */
+	u8 err_len;	/* Number of data bytes */
+	u8 err_data;	/* Start of 48-byte data */
+	u8 max_err_cnt;	/* Max num of errors */
+};
+
+/*
+ * Included Address of registers to get Count, Length of data and Data
+ * of the 48 bytes error data
+ */
+static struct smpro_error_hdr smpro_error_table[NUM_48BYTES_ERR_TYPE] = {
+	{CORE_CE_ERR_CNT, CORE_CE_ERR_LEN, CORE_CE_ERR_DATA, 32},
+	{CORE_UE_ERR_CNT, CORE_UE_ERR_LEN, CORE_UE_ERR_DATA, 32},
+	{MEM_CE_ERR_CNT, MEM_CE_ERR_LEN, MEM_CE_ERR_DATA, 16},
+	{MEM_UE_ERR_CNT, MEM_UE_ERR_LEN, MEM_UE_ERR_DATA, 16},
+	{PCIE_CE_ERR_CNT, PCIE_CE_ERR_LEN, PCIE_CE_ERR_DATA, 96},
+	{PCIE_UE_ERR_CNT, PCIE_UE_ERR_LEN, PCIE_UE_ERR_DATA, 96},
+	{OTHER_CE_ERR_CNT, OTHER_CE_ERR_LEN, OTHER_CE_ERR_DATA, 8},
+	{OTHER_UE_ERR_CNT, OTHER_UE_ERR_LEN, OTHER_UE_ERR_DATA, 8},
+};
+
+/*
+ * List of SCP registers which are used to get
+ * one type of RAS Internal errors.
+ */
+struct smpro_int_error_hdr {
+	u8 err_type;
+	u8 err_info_low;
+	u8 err_info_high;
+	u8 err_data_high;
+	u8 err_data_low;
+	u8 warn_info_low;
+	u8 warn_info_high;
+};
+
+static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
+	{
+	 ERR_SMPRO_TYPE,
+	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
+	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
+	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
+	},
+	{
+	 ERR_PMPRO_TYPE,
+	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
+	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
+	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
+	},
+};
+
+struct smpro_errmon {
+	struct regmap *regmap;
+};
+
+enum EVENT_TYPES {
+	VRD_WARN_FAULT_EVENTS,
+	VRD_HOT_EVENTS,
+	DIMM_HOT_EVENTS,
+	NUM_EVENTS_TYPE,
+};
+
+/* Included Address of event source and data registers */
+static u8 smpro_event_table[NUM_EVENTS_TYPE] = {
+	VRD_WARN_FAULT_EVENT_DATA,
+	VRD_HOT_EVENT_DATA,
+	DIMM_HOT_EVENT_DATA,
+};
+
+static ssize_t smpro_event_data_read(struct device *dev,
+				     struct device_attribute *da, char *buf,
+				     int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	s32 event_data;
+	int ret;
+
+	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
+	if (ret)
+		goto done;
+
+	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
+	/* Clear event after read */
+	if (event_data != 0)
+		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
+done:
+	return ret;
+}
+
+static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
+					char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	struct smpro_error_hdr *err_info;
+	s32 err_count;
+	int ret;
+
+	err_info = &smpro_error_table[channel];
+
+	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
+	if (ret)
+		return ret;
+
+	/* Bit 8 indicates the overflow status */
+	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
+}
+
+static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
+				     char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
+	struct smpro_error_hdr *err_info;
+	s32 err_count, err_length;
+	int count = 0;
+	int ret;
+
+	err_info = &smpro_error_table[channel];
+
+	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
+	/* Error count is the low byte */
+	err_count &= 0xff;
+	if (ret || !err_count || err_count > err_info->max_err_cnt)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
+	if (ret || err_length <= 0)
+		goto done;
+
+	if (err_length > MAX_READ_BLOCK_LENGTH)
+		err_length = MAX_READ_BLOCK_LENGTH;
+
+	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
+	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
+	if (ret < 0)
+		goto done;
+
+	/*
+	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
+	 * <Error Type><Error SubType><Instance><Error Status>\
+	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
+	 * Where:
+	 *  + Error Type: The hardwares cause the errors. (1 byte)
+	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
+	 *  + Instance: Combination of the socket, channel,
+	 *    slot cause the error. (2 bytes)
+	 *  + Error Status: Encode of error status. (4 bytes)
+	 *  + Error Address: The address in device causes the errors. (8 bytes)
+	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
+	 * Reference Altra SOC BMC Interface specification.
+	 */
+	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
+			   err_data[0], err_data[1], *(u16 *)&err_data[2],
+			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
+			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
+			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
+
+	/* go to next error */
+	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
+done:
+	return ret ? ret : count;
+}
+
+/*
+ * Output format:
+ * <errType><image><dir><Location><errorCode><data>
+ * Where:
+ *   + errType: SCP Error Type (3 bits)
+ *      1: Warning
+ *      2: Error
+ *      4: Error with data
+ *   + image: SCP Image Code (8 bits)
+ *   + dir: Direction (1 bit)
+ *      0: Enter
+ *      1: Exit
+ *   + location: SCP Module Location Code (8 bits)
+ *   + errorCode: SCP Error Code (16 bits)
+ *   + data : Extensive data (32 bits)
+ *      All bits are 0 when errType is warning or error.
+ */
+static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
+				       char *buf, int channel)
+{
+	struct smpro_errmon *errmon = dev_get_drvdata(dev);
+	struct smpro_int_error_hdr *err_info;
+	unsigned int data_lo = 0, data_hi = 0;
+	unsigned int ret_hi, ret_lo;
+	unsigned int err_type;
+	unsigned int value;
+	int count = 0;
+	int ret;
+
+	/* read error status */
+	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
+	if (ret)
+		goto done;
+
+	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
+	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
+		goto done;
+
+	err_info = &list_smpro_int_error_hdr[channel];
+	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
+	if (ret)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
+	if (ret)
+		goto done;
+
+	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
+	if (ret)
+		goto done;
+
+	if (err_type & BIT(2)) {
+		/* Error with data type */
+		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
+		if (ret)
+			goto done;
+
+		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
+		if (ret)
+			goto done;
+
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
+
+	} else if (err_type & BIT(1)) {
+		/* Error type */
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
+
+	} else if (err_type & BIT(0)) {
+		/* Warning type */
+		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
+				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
+				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
+		/* clear the read errors */
+		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
+	}
+done:
+	return ret ? ret : count;
+}
+
+#define ERROR_OVERFLOW_RO(_error, _index) \
+	static ssize_t overflow_##_error##_show(struct device *dev,            \
+						struct device_attribute *da,   \
+						char *buf)                     \
+	{                                                                      \
+		return smpro_overflow_data_read(dev, da, buf, _index);         \
+	}                                                                      \
+	static DEVICE_ATTR_RO(overflow_##_error)
+
+ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
+ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
+ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
+ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
+ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
+ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
+ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
+ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
+
+#define ERROR_RO(_error, _index) \
+	static ssize_t error_##_error##_show(struct device *dev,            \
+					     struct device_attribute *da,   \
+					     char *buf)                     \
+	{                                                                   \
+		return smpro_error_data_read(dev, da, buf, _index);         \
+	}                                                                   \
+	static DEVICE_ATTR_RO(error_##_error)
+
+ERROR_RO(core_ce, CORE_CE_ERRS);
+ERROR_RO(core_ue, CORE_UE_ERRS);
+ERROR_RO(mem_ce, MEM_CE_ERRS);
+ERROR_RO(mem_ue, MEM_UE_ERRS);
+ERROR_RO(pcie_ce, PCIE_CE_ERRS);
+ERROR_RO(pcie_ue, PCIE_UE_ERRS);
+ERROR_RO(other_ce, OTHER_CE_ERRS);
+ERROR_RO(other_ue, OTHER_UE_ERRS);
+
+static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(error_smpro);
+
+static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
+}
+static DEVICE_ATTR_RO(error_pmpro);
+
+#define EVENT_RO(_event, _index) \
+	static ssize_t event_##_event##_show(struct device *dev,            \
+					     struct device_attribute *da,   \
+					     char *buf)                     \
+	{                                                                   \
+		return smpro_event_data_read(dev, da, buf, _index);         \
+	}                                                                   \
+	static DEVICE_ATTR_RO(event_##_event)
+
+EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
+EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
+EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
+
+static struct attribute *smpro_errmon_attrs[] = {
+	&dev_attr_overflow_core_ce.attr,
+	&dev_attr_overflow_core_ue.attr,
+	&dev_attr_overflow_mem_ce.attr,
+	&dev_attr_overflow_mem_ue.attr,
+	&dev_attr_overflow_pcie_ce.attr,
+	&dev_attr_overflow_pcie_ue.attr,
+	&dev_attr_overflow_other_ce.attr,
+	&dev_attr_overflow_other_ue.attr,
+	&dev_attr_error_core_ce.attr,
+	&dev_attr_error_core_ue.attr,
+	&dev_attr_error_mem_ce.attr,
+	&dev_attr_error_mem_ue.attr,
+	&dev_attr_error_pcie_ce.attr,
+	&dev_attr_error_pcie_ue.attr,
+	&dev_attr_error_other_ce.attr,
+	&dev_attr_error_other_ue.attr,
+	&dev_attr_error_smpro.attr,
+	&dev_attr_error_pmpro.attr,
+	&dev_attr_event_vrd_warn_fault.attr,
+	&dev_attr_event_vrd_hot.attr,
+	&dev_attr_event_dimm_hot.attr,
+	NULL
+};
+
+static const struct attribute_group smpro_errmon_attr_group = {
+	.attrs = smpro_errmon_attrs
+};
+
+static int smpro_errmon_probe(struct platform_device *pdev)
+{
+	struct smpro_errmon *errmon;
+	int ret;
+
+	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
+	if (!errmon)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, errmon);
+
+	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!errmon->regmap)
+		return -ENODEV;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+	if (ret)
+		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
+
+	return 0;
+}
+
+static int smpro_errmon_remove(struct platform_device *pdev)
+{
+	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
+	pr_info("SMPro errmon sysfs entries removed");
+
+	return 0;
+}
+
+static struct platform_driver smpro_errmon_driver = {
+	.probe          = smpro_errmon_probe,
+	.remove         = smpro_errmon_remove,
+	.driver = {
+		.name   = "smpro-errmon",
+	},
+};
+
+module_platform_driver(smpro_errmon_driver);
+
+MODULE_AUTHOR("Tung Nguyen <tung.nguyen@amperecomputing.com>");
+MODULE_AUTHOR("Thinh Pham <thinh.pham@amperecomputing.com>");
+MODULE_AUTHOR("Hoang Nguyen <hnguyen@amperecomputing.com>");
+MODULE_AUTHOR("Thu Nguyen <thu@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMpro driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 4/9] docs: misc-devices: (smpro-errmon) Add documentation
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Adds documentation for Ampere(R)'s Altra(R) SMpro errmon driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update to reflect single value per sysfs  [Quan]

Changes in v7:
  + None

Changes in v6:
  + First introduced in v6 [Quan]

 Documentation/misc-devices/index.rst        |   1 +
 Documentation/misc-devices/smpro-errmon.rst | 198 ++++++++++++++++++++
 2 files changed, 199 insertions(+)
 create mode 100644 Documentation/misc-devices/smpro-errmon.rst

diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 30ac58f81901..7a6a6263cbab 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -26,6 +26,7 @@ fit into other categories.
    lis3lv02d
    max6875
    pci-endpoint-test
+   smpro-errmon
    spear-pcie-gadget
    uacce
    xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-errmon.rst b/Documentation/misc-devices/smpro-errmon.rst
new file mode 100644
index 000000000000..53599904da70
--- /dev/null
+++ b/Documentation/misc-devices/smpro-errmon.rst
@@ -0,0 +1,198 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro errmon
+===============================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Preference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following SoC alert/event types are supported by the errmon driver:
+
+* Core CE/UE errors
+* Memory CE/UE errors
+* PCIe CE/UE errors
+* Other CE/UE errors
+* Internal SMpro/PMpro errors
+* VRD hot
+* VRD warn/fault
+* DIMM Hot
+
+The SMpro interface provides the registers to query the status of the SoC alerts/events
+and their data and export to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro errmon driver creates the sysfs files for each host alert/event type.
+Example: ``error_core_ce`` to get Core CE error type.
+
+To get a host alert/event type, the user will read the corresponding sysfs file.
+
+* If the alert/event is absented, the sysfs file returns empty.
+* If the alerts/events are presented, one each read to the sysfs, the oldest alert/event will be reported until all the errors are read out..
+
+The format of the error lines is defended on the alert/event type.
+
+1) Type 1 for Core/Memory/PCIe/Other CE/UE alert types::
+
+    <Error Type><Error SubType><Instance><Error Status><Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
+
+    Where:
+    * Error Type: The hardwares cause the errors in format of two hex characters.
+    * SubType: Sub type of error in the specified hardware error in format of two hex characters.
+    * Instance: Combination of the socket, channel, slot cause the error in format of four hex characters.
+    * Error Status: Encode of error status in format of eight hex characters.
+    * Error Address: The address in device causes the errors in format of sixteen hex characters.
+    * Error Misc 0/1/2/3: Addition info about the errors. Each field is in format of sixteen hex characters.
+
+    Example:
+    # cat error_other_ce
+    0a020000000030e400000000000000800000020000000000000000000000000000000000000000000000000000000000
+
+    The size of the alert buffer for this error type is 8 alerts.
+    When the buffer is overflowed, the read to overflow_other_ce will return 1, otherwise it returns 0.
+
+    Example:
+    # cat overflow_other_ce
+    1
+
+Below table defines the value of Error types, Sub Types, Sub component and instance:
+
+    ============   ==========    =========   ===============  ================
+    Error Group    Error Type    Sub type    Sub component    Instance
+    CPM            0             0           Snoop-Logic      CPM #
+    CPM            0             2           Armv8 Core 1     CPM #
+    MCU            1             1           ERR1             MCU # | SLOT << 11
+    MCU            1             2           ERR2             MCU # | SLOT << 11
+    MCU            1             3           ERR3             MCU #
+    MCU            1             4           ERR4             MCU #
+    MCU            1             5           ERR5             MCU #
+    MCU            1             6           ERR6             MCU #
+    MCU            1             7           Link Error       MCU #
+    Mesh           2             0           Cross Point      X | (Y << 5) | NS <<11
+    Mesh           2             1           Home Node(IO)    X | (Y << 5) | NS <<11
+    Mesh           2             2           Home Node(Mem)   X | (Y << 5) | NS <<11 | device<<12
+    Mesh           2             4           CCIX Node        X | (Y << 5) | NS <<11
+    2P Link        3             0           N/A              Altra 2P Link #
+    GIC            5             0           ERR0             0
+    GIC            5             1           ERR1             0
+    GIC            5             2           ERR2             0
+    GIC            5             3           ERR3             0
+    GIC            5             4           ERR4             0
+    GIC            5             5           ERR5             0
+    GIC            5             6           ERR6             0
+    GIC            5             7           ERR7             0
+    GIC            5             8           ERR8             0
+    GIC            5             9           ERR9             0
+    GIC            5             10          ERR10            0
+    GIC            5             11          ERR11            0
+    GIC            5             12          ERR12            0
+    GIC            5             13-21       ERR13            RC# + 1
+    SMMU           6             TCU         100              RC #
+    SMMU           6             TBU0        0                RC #
+    SMMU           6             TBU1        1                RC #
+    SMMU           6             TBU2        2                RC #
+    SMMU           6             TBU3        3                RC #
+    SMMU           6             TBU4        4                RC #
+    SMMU           6             TBU5        5                RC #
+    SMMU           6             TBU6        6                RC #
+    SMMU           6             TBU7        7                RC #
+    SMMU           6             TBU8        8                RC #
+    SMMU           6             TBU9        9                RC #
+    PCIe AER       7             Root        0                RC #
+    PCIe AER       7             Device      1                RC #
+    PCIe RC        8             RCA HB      0                RC #
+    PCIe RC        8             RCB HB      1                RC #
+    PCIe RC        8             RASDP       8                RC #
+    OCM            9             ERR0        0                0
+    OCM            9             ERR1        1                0
+    OCM            9             ERR2        2                0
+    SMpro          10            ERR0        0                0
+    SMpro          10            ERR1        1                0
+    SMpro          10            MPA_ERR     2                0
+    PMpro          11            ERR0        0                0
+    PMpro          11            ERR1        1                0
+    PMpro          11            MPA_ERR     2                0
+    =============  ==========    =========   ===============  ================
+
+
+2) Type 2 for the Internal SMpro/PMpro alert types::
+
+    <Error Type><Error SubType><Direction><Error Location><Error Code><Error Data>
+
+    Where:
+    * Error Type: SMpro/PMpro Error types in format of two hex characters.
+      + 1: Warning
+      + 2: Error
+      + 4: Error with data
+    * Error SubType: SMpro/PMpro Image Code in format of two hex characters.
+    * Direction: Direction in format of two hex characters.
+      + 0: Enter
+      + 1: Exit
+    * Error Location: SMpro/PMpro Module Location code in format of two hex characters.
+    * Error Code: SMpro/PMpro Error code in format of four hex characters.
+    * Error Data: Extensive datae in format of eight hex characters.
+      All bits are 0 when Error Type is warning or error.
+
+    Example:
+    # cat errors_smpro
+    01040108003500000000
+
+3) Type 3 for the VRD hot, VRD /warn/fault, DIMM Hot event::
+
+    <Event Channel><Event Data>
+
+    Where:
+    * Event channel:
+        00: VRD Warning Fault
+        01: VRD Hot
+        02: DIMM hot
+    * Event Data: Extensive data if have in format of four hex characters.
+
+    Example:
+    #cat event_vrd_hot
+    010000
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+Alert Types:
+
+    ================= =============== =========================================================== =======
+    Alert Type        Sysfs name      Description                                                 Format
+    Core CE Errors    errors_core_ce  Triggered by CPU when Core has an CE error                  1
+    Core UE Errors    errors_core_ue  Triggered by CPU when Core has an UE error                  1
+    Memory CE Errors  errors_mem_ce   Triggered by CPU when Memory has an CE error                1
+    Memory UE Errors  errors_mem_ue   Triggered by CPU when Memory has an UE error                1
+    PCIe CE Errors    errors_pcie_ce  Triggered by CPU when any PCIe controller has any CE error  1
+    PCIe UE Errors    errors_pcie_ue  Triggered by CPU when any PCIe controller has any UE error  1
+    Other CE Errors   errors_other_ce Triggered by CPU when any Others CE error                   1
+    Other UE Errors   errors_other_ue Triggered by CPU when any Others UE error                   1
+    SMpro Errors      errors_smpro    Triggered by CPU when system have SMpro error               2
+    PMpro Errors      errors_pmpro    Triggered by CPU when system have PMpro error               2
+    ================= =============== =========================================================== =======
+
+Event Type:
+
+    ============================ ========================== =========== ========================
+    Event Type                   Sysfs name                 Event Type  Sub Type
+    VRD HOT                      event_vrd_hot              0           0: SoC, 1: Core, 2: DIMM
+    VR Warn/Fault                event_vrd_warn_fault       1           0: SoC, 1: Core, 2: DIMM
+    DIMM Hot                     event_dimm_hot             2           NA (Default 0)
+    ============================ ========================== =========== ========================
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 4/9] docs: misc-devices: (smpro-errmon) Add documentation
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Adds documentation for Ampere(R)'s Altra(R) SMpro errmon driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update to reflect single value per sysfs  [Quan]

Changes in v7:
  + None

Changes in v6:
  + First introduced in v6 [Quan]

 Documentation/misc-devices/index.rst        |   1 +
 Documentation/misc-devices/smpro-errmon.rst | 198 ++++++++++++++++++++
 2 files changed, 199 insertions(+)
 create mode 100644 Documentation/misc-devices/smpro-errmon.rst

diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 30ac58f81901..7a6a6263cbab 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -26,6 +26,7 @@ fit into other categories.
    lis3lv02d
    max6875
    pci-endpoint-test
+   smpro-errmon
    spear-pcie-gadget
    uacce
    xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-errmon.rst b/Documentation/misc-devices/smpro-errmon.rst
new file mode 100644
index 000000000000..53599904da70
--- /dev/null
+++ b/Documentation/misc-devices/smpro-errmon.rst
@@ -0,0 +1,198 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R)'s Altra(R) SMpro errmon
+===============================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Preference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+
+This driver supports hardware monitoring for Ampere(R) Altra(R) SoC's based on the
+SMpro co-processor (SMpro).
+The following SoC alert/event types are supported by the errmon driver:
+
+* Core CE/UE errors
+* Memory CE/UE errors
+* PCIe CE/UE errors
+* Other CE/UE errors
+* Internal SMpro/PMpro errors
+* VRD hot
+* VRD warn/fault
+* DIMM Hot
+
+The SMpro interface provides the registers to query the status of the SoC alerts/events
+and their data and export to userspace by this driver.
+
+Usage Notes
+-----------
+
+SMpro errmon driver creates the sysfs files for each host alert/event type.
+Example: ``error_core_ce`` to get Core CE error type.
+
+To get a host alert/event type, the user will read the corresponding sysfs file.
+
+* If the alert/event is absented, the sysfs file returns empty.
+* If the alerts/events are presented, one each read to the sysfs, the oldest alert/event will be reported until all the errors are read out..
+
+The format of the error lines is defended on the alert/event type.
+
+1) Type 1 for Core/Memory/PCIe/Other CE/UE alert types::
+
+    <Error Type><Error SubType><Instance><Error Status><Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
+
+    Where:
+    * Error Type: The hardwares cause the errors in format of two hex characters.
+    * SubType: Sub type of error in the specified hardware error in format of two hex characters.
+    * Instance: Combination of the socket, channel, slot cause the error in format of four hex characters.
+    * Error Status: Encode of error status in format of eight hex characters.
+    * Error Address: The address in device causes the errors in format of sixteen hex characters.
+    * Error Misc 0/1/2/3: Addition info about the errors. Each field is in format of sixteen hex characters.
+
+    Example:
+    # cat error_other_ce
+    0a020000000030e400000000000000800000020000000000000000000000000000000000000000000000000000000000
+
+    The size of the alert buffer for this error type is 8 alerts.
+    When the buffer is overflowed, the read to overflow_other_ce will return 1, otherwise it returns 0.
+
+    Example:
+    # cat overflow_other_ce
+    1
+
+Below table defines the value of Error types, Sub Types, Sub component and instance:
+
+    ============   ==========    =========   ===============  ================
+    Error Group    Error Type    Sub type    Sub component    Instance
+    CPM            0             0           Snoop-Logic      CPM #
+    CPM            0             2           Armv8 Core 1     CPM #
+    MCU            1             1           ERR1             MCU # | SLOT << 11
+    MCU            1             2           ERR2             MCU # | SLOT << 11
+    MCU            1             3           ERR3             MCU #
+    MCU            1             4           ERR4             MCU #
+    MCU            1             5           ERR5             MCU #
+    MCU            1             6           ERR6             MCU #
+    MCU            1             7           Link Error       MCU #
+    Mesh           2             0           Cross Point      X | (Y << 5) | NS <<11
+    Mesh           2             1           Home Node(IO)    X | (Y << 5) | NS <<11
+    Mesh           2             2           Home Node(Mem)   X | (Y << 5) | NS <<11 | device<<12
+    Mesh           2             4           CCIX Node        X | (Y << 5) | NS <<11
+    2P Link        3             0           N/A              Altra 2P Link #
+    GIC            5             0           ERR0             0
+    GIC            5             1           ERR1             0
+    GIC            5             2           ERR2             0
+    GIC            5             3           ERR3             0
+    GIC            5             4           ERR4             0
+    GIC            5             5           ERR5             0
+    GIC            5             6           ERR6             0
+    GIC            5             7           ERR7             0
+    GIC            5             8           ERR8             0
+    GIC            5             9           ERR9             0
+    GIC            5             10          ERR10            0
+    GIC            5             11          ERR11            0
+    GIC            5             12          ERR12            0
+    GIC            5             13-21       ERR13            RC# + 1
+    SMMU           6             TCU         100              RC #
+    SMMU           6             TBU0        0                RC #
+    SMMU           6             TBU1        1                RC #
+    SMMU           6             TBU2        2                RC #
+    SMMU           6             TBU3        3                RC #
+    SMMU           6             TBU4        4                RC #
+    SMMU           6             TBU5        5                RC #
+    SMMU           6             TBU6        6                RC #
+    SMMU           6             TBU7        7                RC #
+    SMMU           6             TBU8        8                RC #
+    SMMU           6             TBU9        9                RC #
+    PCIe AER       7             Root        0                RC #
+    PCIe AER       7             Device      1                RC #
+    PCIe RC        8             RCA HB      0                RC #
+    PCIe RC        8             RCB HB      1                RC #
+    PCIe RC        8             RASDP       8                RC #
+    OCM            9             ERR0        0                0
+    OCM            9             ERR1        1                0
+    OCM            9             ERR2        2                0
+    SMpro          10            ERR0        0                0
+    SMpro          10            ERR1        1                0
+    SMpro          10            MPA_ERR     2                0
+    PMpro          11            ERR0        0                0
+    PMpro          11            ERR1        1                0
+    PMpro          11            MPA_ERR     2                0
+    =============  ==========    =========   ===============  ================
+
+
+2) Type 2 for the Internal SMpro/PMpro alert types::
+
+    <Error Type><Error SubType><Direction><Error Location><Error Code><Error Data>
+
+    Where:
+    * Error Type: SMpro/PMpro Error types in format of two hex characters.
+      + 1: Warning
+      + 2: Error
+      + 4: Error with data
+    * Error SubType: SMpro/PMpro Image Code in format of two hex characters.
+    * Direction: Direction in format of two hex characters.
+      + 0: Enter
+      + 1: Exit
+    * Error Location: SMpro/PMpro Module Location code in format of two hex characters.
+    * Error Code: SMpro/PMpro Error code in format of four hex characters.
+    * Error Data: Extensive datae in format of eight hex characters.
+      All bits are 0 when Error Type is warning or error.
+
+    Example:
+    # cat errors_smpro
+    01040108003500000000
+
+3) Type 3 for the VRD hot, VRD /warn/fault, DIMM Hot event::
+
+    <Event Channel><Event Data>
+
+    Where:
+    * Event channel:
+        00: VRD Warning Fault
+        01: VRD Hot
+        02: DIMM hot
+    * Event Data: Extensive data if have in format of four hex characters.
+
+    Example:
+    #cat event_vrd_hot
+    010000
+
+Sysfs entries
+-------------
+
+The following sysfs files are supported:
+
+* Ampere(R) Altra(R):
+
+Alert Types:
+
+    ================= =============== =========================================================== =======
+    Alert Type        Sysfs name      Description                                                 Format
+    Core CE Errors    errors_core_ce  Triggered by CPU when Core has an CE error                  1
+    Core UE Errors    errors_core_ue  Triggered by CPU when Core has an UE error                  1
+    Memory CE Errors  errors_mem_ce   Triggered by CPU when Memory has an CE error                1
+    Memory UE Errors  errors_mem_ue   Triggered by CPU when Memory has an UE error                1
+    PCIe CE Errors    errors_pcie_ce  Triggered by CPU when any PCIe controller has any CE error  1
+    PCIe UE Errors    errors_pcie_ue  Triggered by CPU when any PCIe controller has any UE error  1
+    Other CE Errors   errors_other_ce Triggered by CPU when any Others CE error                   1
+    Other UE Errors   errors_other_ue Triggered by CPU when any Others UE error                   1
+    SMpro Errors      errors_smpro    Triggered by CPU when system have SMpro error               2
+    PMpro Errors      errors_pmpro    Triggered by CPU when system have PMpro error               2
+    ================= =============== =========================================================== =======
+
+Event Type:
+
+    ============================ ========================== =========== ========================
+    Event Type                   Sysfs name                 Event Type  Sub Type
+    VRD HOT                      event_vrd_hot              0           0: SoC, 1: Core, 2: DIMM
+    VR Warn/Fault                event_vrd_warn_fault       1           0: SoC, 1: Core, 2: DIMM
+    DIMM Hot                     event_dimm_hot             2           NA (Default 0)
+    ============================ ========================== =========== ========================
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 5/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

This commit adds driver support for accessing various information
reported by Ampere's SMpro co-processor such as Boot Progress and
other miscellaneous data.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update wording for SMPRO_MISC in Kconfig file           [Quan]
  + Switch to use sysfs_emit()                              [Quan]

Changes in v7:
  + Fix wrong return type of *_show/store()
  functions                                    [kernel robot test]
  + Adjust patch order to remove dependence with
  smpro-mfd                                            [Lee Jones]

Changes in v6:
  + First introduced in v6 [Quan]

 drivers/misc/Kconfig      |  10 +++
 drivers/misc/Makefile     |   1 +
 drivers/misc/smpro-misc.c | 161 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 drivers/misc/smpro-misc.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 9fbe6797c440..368fbe73853e 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -188,6 +188,16 @@ config SMPRO_ERRMON
 	  To compile this driver as a module, say M here. The driver will be
 	  called smpro-errmon.
 
+config SMPRO_MISC
+	tristate "Ampere Computing SMPro miscellaneous driver"
+	depends on MFD_SMPRO || COMPILE_TEST
+	help
+	  Say Y here to get support for the SMpro error miscellalenous function
+	  provided by Ampere Computing's Altra and Altra Max SoCs.
+
+	  To compile this driver as a module, say M here. The driver will be
+	  called smpro-misc.
+
 config CS5535_MFGPT
 	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
 	depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 483308a6e113..e61e462924d0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
 obj-$(CONFIG_SGI_XP)		+= sgi-xp/
 obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
 obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
+obj-$(CONFIG_SMPRO_MISC)	+= smpro-misc.o
 obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
 obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
 obj-$(CONFIG_HP_ILO)		+= hpilo.o
diff --git a/drivers/misc/smpro-misc.c b/drivers/misc/smpro-misc.c
new file mode 100644
index 000000000000..4b98098ace8f
--- /dev/null
+++ b/drivers/misc/smpro-misc.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Misc Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ */
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* Boot Stage/Progress Registers */
+#define BOOTSTAGE_SELECT	0xB0
+#define BOOTSTAGE_STATUS_LO	0xB1
+#define BOOTSTAGE_CUR_STAGE	0xB2
+#define BOOTSTAGE_STATUS_HI	0xB3
+
+/* SOC State Registers */
+#define SOC_POWER_LIMIT		0xE5
+
+struct smpro_misc {
+	struct regmap *regmap;
+};
+
+static ssize_t boot_progress_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	u32 boot_progress;
+	u8 current_stage;
+	u8 boot_status;
+	u8 boot_stage;
+	u32 select;
+	u32 reg_lo;
+	u32 reg;
+	int ret;
+
+	/* Read current boot stage */
+	ret = regmap_read(misc->regmap, BOOTSTAGE_CUR_STAGE, &reg);
+	if (ret)
+		return ret;
+
+	current_stage = reg & 0xff;
+
+	/* Read the boot progress */
+	ret = regmap_read(misc->regmap, BOOTSTAGE_SELECT, &select);
+	if (ret)
+		return ret;
+
+	boot_stage = (select >> 8) & 0xff;
+	boot_status = select & 0xff;
+
+	if (boot_stage > current_stage)
+		return -EINVAL;
+
+	ret = regmap_read(misc->regmap,	BOOTSTAGE_STATUS_LO, &reg_lo);
+	if (!ret)
+		ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_HI, &reg);
+	if (ret)
+		return ret;
+
+	boot_progress = swab16(reg) << 16 | swab16(reg_lo);
+
+	/* Tell firmware to provide next boot stage next time */
+	if (boot_stage < current_stage) {
+		ret = regmap_write(misc->regmap, BOOTSTAGE_SELECT, ((select & 0xff00) | 0x1));
+		if (ret)
+			return ret;
+	}
+
+	return sysfs_emit(buf, "%02x%02x%08x\n", boot_stage, boot_status, boot_progress);
+}
+
+static DEVICE_ATTR_RO(boot_progress);
+
+static ssize_t soc_power_limit_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	ret = regmap_read(misc->regmap, SOC_POWER_LIMIT, &value);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%d\n", value);
+}
+
+static ssize_t soc_power_limit_store(struct device *dev, struct device_attribute *da,
+				     const char *buf, size_t count)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	unsigned long val;
+	s32 ret;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(misc->regmap, SOC_POWER_LIMIT, (unsigned int)val);
+	if (ret)
+		return -EPROTO;
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(soc_power_limit);
+
+static struct attribute *smpro_misc_attrs[] = {
+	&dev_attr_boot_progress.attr,
+	&dev_attr_soc_power_limit.attr,
+	NULL
+};
+
+static const struct attribute_group smpro_misc_attr_group = {
+	.attrs = smpro_misc_attrs
+};
+
+static int smpro_misc_probe(struct platform_device *pdev)
+{
+	struct smpro_misc *misc;
+	int ret;
+
+	misc = devm_kzalloc(&pdev->dev, sizeof(struct smpro_misc), GFP_KERNEL);
+	if (!misc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, misc);
+
+	misc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!misc->regmap)
+		return -ENODEV;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+	if (ret)
+		dev_err(&pdev->dev, "SMPro misc sysfs registration failed\n");
+
+	return 0;
+}
+
+static int smpro_misc_remove(struct platform_device *pdev)
+{
+	sysfs_remove_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+	pr_info("SMPro misc sysfs entries removed");
+
+	return 0;
+}
+
+static struct platform_driver smpro_misc_driver = {
+	.probe		= smpro_misc_probe,
+	.remove		= smpro_misc_remove,
+	.driver = {
+		.name	= "smpro-misc",
+	},
+};
+
+module_platform_driver(smpro_misc_driver);
+
+MODULE_AUTHOR("Tung Nguyen <tungnguyen@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMpro Misc driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 5/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

This commit adds driver support for accessing various information
reported by Ampere's SMpro co-processor such as Boot Progress and
other miscellaneous data.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update wording for SMPRO_MISC in Kconfig file           [Quan]
  + Switch to use sysfs_emit()                              [Quan]

Changes in v7:
  + Fix wrong return type of *_show/store()
  functions                                    [kernel robot test]
  + Adjust patch order to remove dependence with
  smpro-mfd                                            [Lee Jones]

Changes in v6:
  + First introduced in v6 [Quan]

 drivers/misc/Kconfig      |  10 +++
 drivers/misc/Makefile     |   1 +
 drivers/misc/smpro-misc.c | 161 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 drivers/misc/smpro-misc.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 9fbe6797c440..368fbe73853e 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -188,6 +188,16 @@ config SMPRO_ERRMON
 	  To compile this driver as a module, say M here. The driver will be
 	  called smpro-errmon.
 
+config SMPRO_MISC
+	tristate "Ampere Computing SMPro miscellaneous driver"
+	depends on MFD_SMPRO || COMPILE_TEST
+	help
+	  Say Y here to get support for the SMpro error miscellalenous function
+	  provided by Ampere Computing's Altra and Altra Max SoCs.
+
+	  To compile this driver as a module, say M here. The driver will be
+	  called smpro-misc.
+
 config CS5535_MFGPT
 	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
 	depends on MFD_CS5535
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 483308a6e113..e61e462924d0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
 obj-$(CONFIG_SGI_XP)		+= sgi-xp/
 obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
 obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
+obj-$(CONFIG_SMPRO_MISC)	+= smpro-misc.o
 obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
 obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
 obj-$(CONFIG_HP_ILO)		+= hpilo.o
diff --git a/drivers/misc/smpro-misc.c b/drivers/misc/smpro-misc.c
new file mode 100644
index 000000000000..4b98098ace8f
--- /dev/null
+++ b/drivers/misc/smpro-misc.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ampere Computing SoC's SMpro Misc Driver
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ */
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+/* Boot Stage/Progress Registers */
+#define BOOTSTAGE_SELECT	0xB0
+#define BOOTSTAGE_STATUS_LO	0xB1
+#define BOOTSTAGE_CUR_STAGE	0xB2
+#define BOOTSTAGE_STATUS_HI	0xB3
+
+/* SOC State Registers */
+#define SOC_POWER_LIMIT		0xE5
+
+struct smpro_misc {
+	struct regmap *regmap;
+};
+
+static ssize_t boot_progress_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	u32 boot_progress;
+	u8 current_stage;
+	u8 boot_status;
+	u8 boot_stage;
+	u32 select;
+	u32 reg_lo;
+	u32 reg;
+	int ret;
+
+	/* Read current boot stage */
+	ret = regmap_read(misc->regmap, BOOTSTAGE_CUR_STAGE, &reg);
+	if (ret)
+		return ret;
+
+	current_stage = reg & 0xff;
+
+	/* Read the boot progress */
+	ret = regmap_read(misc->regmap, BOOTSTAGE_SELECT, &select);
+	if (ret)
+		return ret;
+
+	boot_stage = (select >> 8) & 0xff;
+	boot_status = select & 0xff;
+
+	if (boot_stage > current_stage)
+		return -EINVAL;
+
+	ret = regmap_read(misc->regmap,	BOOTSTAGE_STATUS_LO, &reg_lo);
+	if (!ret)
+		ret = regmap_read(misc->regmap, BOOTSTAGE_STATUS_HI, &reg);
+	if (ret)
+		return ret;
+
+	boot_progress = swab16(reg) << 16 | swab16(reg_lo);
+
+	/* Tell firmware to provide next boot stage next time */
+	if (boot_stage < current_stage) {
+		ret = regmap_write(misc->regmap, BOOTSTAGE_SELECT, ((select & 0xff00) | 0x1));
+		if (ret)
+			return ret;
+	}
+
+	return sysfs_emit(buf, "%02x%02x%08x\n", boot_stage, boot_status, boot_progress);
+}
+
+static DEVICE_ATTR_RO(boot_progress);
+
+static ssize_t soc_power_limit_show(struct device *dev, struct device_attribute *da, char *buf)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	unsigned int value;
+	int ret;
+
+	ret = regmap_read(misc->regmap, SOC_POWER_LIMIT, &value);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%d\n", value);
+}
+
+static ssize_t soc_power_limit_store(struct device *dev, struct device_attribute *da,
+				     const char *buf, size_t count)
+{
+	struct smpro_misc *misc = dev_get_drvdata(dev);
+	unsigned long val;
+	s32 ret;
+
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(misc->regmap, SOC_POWER_LIMIT, (unsigned int)val);
+	if (ret)
+		return -EPROTO;
+
+	return count;
+}
+
+static DEVICE_ATTR_RW(soc_power_limit);
+
+static struct attribute *smpro_misc_attrs[] = {
+	&dev_attr_boot_progress.attr,
+	&dev_attr_soc_power_limit.attr,
+	NULL
+};
+
+static const struct attribute_group smpro_misc_attr_group = {
+	.attrs = smpro_misc_attrs
+};
+
+static int smpro_misc_probe(struct platform_device *pdev)
+{
+	struct smpro_misc *misc;
+	int ret;
+
+	misc = devm_kzalloc(&pdev->dev, sizeof(struct smpro_misc), GFP_KERNEL);
+	if (!misc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, misc);
+
+	misc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!misc->regmap)
+		return -ENODEV;
+
+	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+	if (ret)
+		dev_err(&pdev->dev, "SMPro misc sysfs registration failed\n");
+
+	return 0;
+}
+
+static int smpro_misc_remove(struct platform_device *pdev)
+{
+	sysfs_remove_group(&pdev->dev.kobj, &smpro_misc_attr_group);
+	pr_info("SMPro misc sysfs entries removed");
+
+	return 0;
+}
+
+static struct platform_driver smpro_misc_driver = {
+	.probe		= smpro_misc_probe,
+	.remove		= smpro_misc_remove,
+	.driver = {
+		.name	= "smpro-misc",
+	},
+};
+
+module_platform_driver(smpro_misc_driver);
+
+MODULE_AUTHOR("Tung Nguyen <tungnguyen@os.amperecomputing.com>");
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("Ampere Altra SMpro Misc driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 6/9] docs: misc-devices: (smpro-misc) Add documentation
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Adds documentation for the Ampere(R)'s Altra(R) SMpro misc driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update to reflect single value per sysfs     [Quan]

Changes in v7:
  + None

Changes in v6:
  + First introduced in v6 [Quan]

 Documentation/misc-devices/index.rst      |  1 +
 Documentation/misc-devices/smpro-misc.rst | 82 +++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/misc-devices/smpro-misc.rst

diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 7a6a6263cbab..284568eca747 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -27,6 +27,7 @@ fit into other categories.
    max6875
    pci-endpoint-test
    smpro-errmon
+   smpro-misc
    spear-pcie-gadget
    uacce
    xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-misc.rst b/Documentation/misc-devices/smpro-misc.rst
new file mode 100644
index 000000000000..7d4123991c5d
--- /dev/null
+++ b/Documentation/misc-devices/smpro-misc.rst
@@ -0,0 +1,82 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R) Altra(R) SMpro miscellaneous
+====================================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+
+This driver support the monitoring and configuration of various miscellaneous
+data provided by Ampere(R) Altra(R) SMpro processor.
+At this time, these include:
+
+  * Reading Boot Progress information
+  * Configuring SoC Power Limit
+
+Sysfs entries
+-------------
+
+1) Boot progress
+
+SMpro misc driver creates the sysfs files ``boot_progress``.
+The format of ``boot_progress`` file is as below::
+
+<boot stage><boot status><boot progress>
+
+Where:
+
+* Boot stage::
+
+    0: SMpro firmware booting.
+    1: PMpro firmware booting.
+    2: ATF BL1 firmware booting.
+    3: DDR initialization.
+    4: DDR training report status.
+    5: ATF BL2 firmware booting.
+    6: ATF BL31 firmware booting.
+    7: ATF BL32 firmware booting.
+    8: UEFI firmware booting.
+    9: OS booting.
+
+* Boot status::
+
+    0: Not started.
+    1: Started.
+    2: Complete without error.
+    3: Failure.
+
+* boot progress: 32 bits boot progress code
+
+The sysfs ``boot_progress`` only reports the boot state when the host is booting.
+If the host is already booted, it returns latest state.
+
+Example::
+
+    #cat boot_progress
+    0102808454A8
+
+2) SoC Power Limit
+
+SMpro misc driver creates the sysfs file ``soc_power_limit`` to get/set the SoC Power Limit.
+
+Reading this sysfs return the current setting of SoC Power Limit (W) in decimal string.
+Writing the desired value in decimal string to set the SoC Power Limit in Watt (W).
+The range of SoC Power Limit is 90-500(W) and will be ignored if out of range.
+
+Example::
+
+    #cat soc_power_limit
+    90
+    #echo 95 > soc_power_limit
+    #cat soc_power_limit
+    95
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 6/9] docs: misc-devices: (smpro-misc) Add documentation
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Adds documentation for the Ampere(R)'s Altra(R) SMpro misc driver.

Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Update to reflect single value per sysfs     [Quan]

Changes in v7:
  + None

Changes in v6:
  + First introduced in v6 [Quan]

 Documentation/misc-devices/index.rst      |  1 +
 Documentation/misc-devices/smpro-misc.rst | 82 +++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 Documentation/misc-devices/smpro-misc.rst

diff --git a/Documentation/misc-devices/index.rst b/Documentation/misc-devices/index.rst
index 7a6a6263cbab..284568eca747 100644
--- a/Documentation/misc-devices/index.rst
+++ b/Documentation/misc-devices/index.rst
@@ -27,6 +27,7 @@ fit into other categories.
    max6875
    pci-endpoint-test
    smpro-errmon
+   smpro-misc
    spear-pcie-gadget
    uacce
    xilinx_sdfec
diff --git a/Documentation/misc-devices/smpro-misc.rst b/Documentation/misc-devices/smpro-misc.rst
new file mode 100644
index 000000000000..7d4123991c5d
--- /dev/null
+++ b/Documentation/misc-devices/smpro-misc.rst
@@ -0,0 +1,82 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver Ampere(R) Altra(R) SMpro miscellaneous
+====================================================
+
+Supported chips:
+
+  * Ampere(R) Altra(R)
+
+    Prefix: 'smpro'
+
+    Reference: Altra SoC BMC Interface Specification
+
+Author: Thu Nguyen <thu@os.amperecomputing.com>
+
+Description
+-----------
+
+This driver support the monitoring and configuration of various miscellaneous
+data provided by Ampere(R) Altra(R) SMpro processor.
+At this time, these include:
+
+  * Reading Boot Progress information
+  * Configuring SoC Power Limit
+
+Sysfs entries
+-------------
+
+1) Boot progress
+
+SMpro misc driver creates the sysfs files ``boot_progress``.
+The format of ``boot_progress`` file is as below::
+
+<boot stage><boot status><boot progress>
+
+Where:
+
+* Boot stage::
+
+    0: SMpro firmware booting.
+    1: PMpro firmware booting.
+    2: ATF BL1 firmware booting.
+    3: DDR initialization.
+    4: DDR training report status.
+    5: ATF BL2 firmware booting.
+    6: ATF BL31 firmware booting.
+    7: ATF BL32 firmware booting.
+    8: UEFI firmware booting.
+    9: OS booting.
+
+* Boot status::
+
+    0: Not started.
+    1: Started.
+    2: Complete without error.
+    3: Failure.
+
+* boot progress: 32 bits boot progress code
+
+The sysfs ``boot_progress`` only reports the boot state when the host is booting.
+If the host is already booted, it returns latest state.
+
+Example::
+
+    #cat boot_progress
+    0102808454A8
+
+2) SoC Power Limit
+
+SMpro misc driver creates the sysfs file ``soc_power_limit`` to get/set the SoC Power Limit.
+
+Reading this sysfs return the current setting of SoC Power Limit (W) in decimal string.
+Writing the desired value in decimal string to set the SoC Power Limit in Watt (W).
+The range of SoC Power Limit is 90-500(W) and will be ignored if out of range.
+
+Example::
+
+    #cat soc_power_limit
+    90
+    #echo 95 > soc_power_limit
+    #cat soc_power_limit
+    95
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 7/9] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Adds device tree bindings for SMPro MFD driver found on the Mt.Jade
hardware reference platform with Ampere's Altra Processor family.

The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
Changes in v8:
  + Removed unused #*_cells                              [Krzysztof]

Changes in v7:
  + None

Changes in v6:
  + None

 .../devicetree/bindings/mfd/ampere,smpro.yaml | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
new file mode 100644
index 000000000000..c442c3cdffed
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ampere,smpro.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ampere Altra SMPro firmware driver
+
+maintainers:
+  - Quan Nguyen <quan@os.amperecomputing.com>
+
+description: |
+  Ampere Altra SMPro firmware may contain different blocks like hardware
+  monitoring, error monitoring and other miscellaneous features.
+
+properties:
+  compatible:
+    enum:
+      - ampere,smpro
+
+  reg:
+    description:
+      I2C device address.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        smpro@4f {
+            compatible = "ampere,smpro";
+            reg = <0x4f>;
+        };
+    };
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 7/9] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Adds device tree bindings for SMPro MFD driver found on the Mt.Jade
hardware reference platform with Ampere's Altra Processor family.

The SMpro co-processor on Ampere Altra processor family is to monitor
and report various data included hwmon-related info, RAS errors, and
other miscellaneous information.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
Reviewed-by: Rob Herring <robh@kernel.org>
---
Changes in v8:
  + Removed unused #*_cells                              [Krzysztof]

Changes in v7:
  + None

Changes in v6:
  + None

 .../devicetree/bindings/mfd/ampere,smpro.yaml | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ampere,smpro.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
new file mode 100644
index 000000000000..c442c3cdffed
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ampere,smpro.yaml
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ampere,smpro.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Ampere Altra SMPro firmware driver
+
+maintainers:
+  - Quan Nguyen <quan@os.amperecomputing.com>
+
+description: |
+  Ampere Altra SMPro firmware may contain different blocks like hardware
+  monitoring, error monitoring and other miscellaneous features.
+
+properties:
+  compatible:
+    enum:
+      - ampere,smpro
+
+  reg:
+    description:
+      I2C device address.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        smpro@4f {
+            compatible = "ampere,smpro";
+            reg = <0x4f>;
+        };
+    };
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Adds Multi-function devices driver for SMpro co-processor found on the
Mt.Jade hardware reference platform with Ampere's Altra processor family.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + None

Changes in v7:
  + Smpro-mfd now significant changes in compare with simple-mfd-i2c
    driver, remove the copyright note about simple-mfd-i2c    [Quan]
  + Install bus->read/write()  to handle multiple types of bus
    access.                                                   [Quan]
  + Update license to MODULE_LICENSE("GPL")                   [Quan]
  + Add others minor refactor the code                        [Quan]

Changes in v6:
  + Update license part to reflect that this driver is clone from
  simple-mfd-i2c driver [Quan]

Changes in v5:
  + Dropped the use of simple-mfd-i2c driver [Quan]
  + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
  sub-devices. This is to avoid DT nodes without resource issue [Quan]
  + Revised commit message [Quan]

Changes in v4:
  + Add "depends on I2C" to fix build issue found by kernel test
  robot [Guenter]

Changes in v3:
  + None

Changes in v2:
  + Used 'struct of_device_id's .data attribute [Lee Jones]

 drivers/mfd/Kconfig     |  12 ++++
 drivers/mfd/Makefile    |   1 +
 drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 drivers/mfd/smpro-mfd.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3b59456f5545..383d0e6cfb91 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -77,6 +77,18 @@ config MFD_AS3711
 	help
 	  Support for the AS3711 PMIC from AMS
 
+config MFD_SMPRO
+	tristate "Ampere Computing MFD SMpro core driver"
+	depends on I2C
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Say yes here to enable SMpro driver support for Ampere's Altra
+	  processor family.
+
+	  Ampere's Altra SMpro exposes an I2C regmap interface that can
+	  be accessed by child devices.
+
 config MFD_AS3722
 	tristate "ams AS3722 Power Management IC"
 	select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 858cacf659d6..36f8981cc4fd 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
+obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
 
 obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
new file mode 100644
index 000000000000..485c4f89ebd9
--- /dev/null
+++ b/drivers/mfd/smpro-mfd.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Ampere Altra Family SMPro MFD - I2C
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ * Author: Quan Nguyen <quan@os.amperecomputing..com>
+ */
+
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+/* Identification Registers */
+#define MANUFACTURER_ID_REG     0x02
+#define AMPERE_MANUFACTURER_ID  0xCD3A
+
+static int smpro_mfd_write(void *context, const void *data, size_t count)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+	int ret;
+
+	ret = i2c_master_send(i2c, data, count);
+	if (ret == count)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;
+}
+
+static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
+			  void *val, size_t val_size)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+	struct i2c_msg xfer[2];
+	unsigned char buf[2];
+	int ret;
+
+	xfer[0].addr = i2c->addr;
+	xfer[0].flags = 0;
+
+	buf[0] = *(u8 *)reg;
+	buf[1] = val_size;
+	xfer[0].len = 2;
+	xfer[0].buf = buf;
+
+	xfer[1].addr = i2c->addr;
+	xfer[1].flags = I2C_M_RD;
+	xfer[1].len = val_size;
+	xfer[1].buf = val;
+
+	ret = i2c_transfer(i2c->adapter, xfer, 2);
+	if (ret == 2)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;
+}
+
+static const struct regmap_bus smpro_regmap_bus = {
+	.read = smpro_mfd_read,
+	.write = smpro_mfd_write,
+	.val_format_endian_default = REGMAP_ENDIAN_BIG,
+};
+
+static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
+{
+	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
+		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);
+}
+
+static const struct regmap_config smpro_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
+};
+
+static const struct mfd_cell smpro_devs[] = {
+	MFD_CELL_NAME("smpro-hwmon"),
+	MFD_CELL_NAME("smpro-errmon"),
+	MFD_CELL_NAME("smpro-misc"),
+};
+
+static int smpro_mfd_probe(struct i2c_client *i2c)
+{
+	const struct regmap_config *config;
+	struct regmap *regmap;
+	unsigned int val;
+	int ret;
+
+	config = device_get_match_data(&i2c->dev);
+	if (!config)
+		config = &smpro_regmap_config;
+
+	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	/* Check for valid ID */
+	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
+	if (ret)
+		return ret;
+
+	if (val != AMPERE_MANUFACTURER_ID)
+		return -ENODEV;
+
+	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
+				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
+}
+
+static const struct of_device_id smpro_mfd_of_match[] = {
+	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
+	{}
+};
+MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
+
+static struct i2c_driver smpro_mfd_driver = {
+	.probe_new = smpro_mfd_probe,
+	.driver = {
+		.name = "smpro-mfd-i2c",
+		.of_match_table = smpro_mfd_of_match,
+	},
+};
+module_i2c_driver(smpro_mfd_driver);
+
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Adds Multi-function devices driver for SMpro co-processor found on the
Mt.Jade hardware reference platform with Ampere's Altra processor family.

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + None

Changes in v7:
  + Smpro-mfd now significant changes in compare with simple-mfd-i2c
    driver, remove the copyright note about simple-mfd-i2c    [Quan]
  + Install bus->read/write()  to handle multiple types of bus
    access.                                                   [Quan]
  + Update license to MODULE_LICENSE("GPL")                   [Quan]
  + Add others minor refactor the code                        [Quan]

Changes in v6:
  + Update license part to reflect that this driver is clone from
  simple-mfd-i2c driver [Quan]

Changes in v5:
  + Dropped the use of simple-mfd-i2c driver [Quan]
  + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
  sub-devices. This is to avoid DT nodes without resource issue [Quan]
  + Revised commit message [Quan]

Changes in v4:
  + Add "depends on I2C" to fix build issue found by kernel test
  robot [Guenter]

Changes in v3:
  + None

Changes in v2:
  + Used 'struct of_device_id's .data attribute [Lee Jones]

 drivers/mfd/Kconfig     |  12 ++++
 drivers/mfd/Makefile    |   1 +
 drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 drivers/mfd/smpro-mfd.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3b59456f5545..383d0e6cfb91 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -77,6 +77,18 @@ config MFD_AS3711
 	help
 	  Support for the AS3711 PMIC from AMS
 
+config MFD_SMPRO
+	tristate "Ampere Computing MFD SMpro core driver"
+	depends on I2C
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Say yes here to enable SMpro driver support for Ampere's Altra
+	  processor family.
+
+	  Ampere's Altra SMpro exposes an I2C regmap interface that can
+	  be accessed by child devices.
+
 config MFD_AS3722
 	tristate "ams AS3722 Power Management IC"
 	select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 858cacf659d6..36f8981cc4fd 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
 
 obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
+obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
 
 obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
new file mode 100644
index 000000000000..485c4f89ebd9
--- /dev/null
+++ b/drivers/mfd/smpro-mfd.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Ampere Altra Family SMPro MFD - I2C
+ *
+ * Copyright (c) 2022, Ampere Computing LLC
+ * Author: Quan Nguyen <quan@os.amperecomputing..com>
+ */
+
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/mfd/core.h>
+#include <linux/regmap.h>
+
+/* Identification Registers */
+#define MANUFACTURER_ID_REG     0x02
+#define AMPERE_MANUFACTURER_ID  0xCD3A
+
+static int smpro_mfd_write(void *context, const void *data, size_t count)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+	int ret;
+
+	ret = i2c_master_send(i2c, data, count);
+	if (ret == count)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;
+}
+
+static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
+			  void *val, size_t val_size)
+{
+	struct device *dev = context;
+	struct i2c_client *i2c = to_i2c_client(dev);
+	struct i2c_msg xfer[2];
+	unsigned char buf[2];
+	int ret;
+
+	xfer[0].addr = i2c->addr;
+	xfer[0].flags = 0;
+
+	buf[0] = *(u8 *)reg;
+	buf[1] = val_size;
+	xfer[0].len = 2;
+	xfer[0].buf = buf;
+
+	xfer[1].addr = i2c->addr;
+	xfer[1].flags = I2C_M_RD;
+	xfer[1].len = val_size;
+	xfer[1].buf = val;
+
+	ret = i2c_transfer(i2c->adapter, xfer, 2);
+	if (ret == 2)
+		return 0;
+	else if (ret < 0)
+		return ret;
+	else
+		return -EIO;
+}
+
+static const struct regmap_bus smpro_regmap_bus = {
+	.read = smpro_mfd_read,
+	.write = smpro_mfd_write,
+	.val_format_endian_default = REGMAP_ENDIAN_BIG,
+};
+
+static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
+{
+	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
+		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);
+}
+
+static const struct regmap_config smpro_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 16,
+	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
+};
+
+static const struct mfd_cell smpro_devs[] = {
+	MFD_CELL_NAME("smpro-hwmon"),
+	MFD_CELL_NAME("smpro-errmon"),
+	MFD_CELL_NAME("smpro-misc"),
+};
+
+static int smpro_mfd_probe(struct i2c_client *i2c)
+{
+	const struct regmap_config *config;
+	struct regmap *regmap;
+	unsigned int val;
+	int ret;
+
+	config = device_get_match_data(&i2c->dev);
+	if (!config)
+		config = &smpro_regmap_config;
+
+	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	/* Check for valid ID */
+	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
+	if (ret)
+		return ret;
+
+	if (val != AMPERE_MANUFACTURER_ID)
+		return -ENODEV;
+
+	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
+				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
+}
+
+static const struct of_device_id smpro_mfd_of_match[] = {
+	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
+	{}
+};
+MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
+
+static struct i2c_driver smpro_mfd_driver = {
+	.probe_new = smpro_mfd_probe,
+	.driver = {
+		.name = "smpro-mfd-i2c",
+		.of_match_table = smpro_mfd_of_match,
+	},
+};
+module_i2c_driver(smpro_mfd_driver);
+
+MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
+MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 9/9] docs: ABI: testing: Document the Ampere Altra Family's SMpro sysfs interfaces
  2022-04-22  2:46 ` Quan Nguyen
@ 2022-04-22  2:46   ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

Add documentation for the Ampere(R)'s Altra(R) SMpro sysfs interfaces

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Sysfs to return single value in hex format              [Greg]
  + Fix KernelVersion info                                  [Greg]
  + Change errors_* to error_*                              [Quan]
  + Added overflow_[core|mem|pcie|other]_[ce|ue]            [Quan]

Changes in v7:
  + First introduce in v7                                   [Greg]

 .../sysfs-bus-platform-devices-ampere-smpro   | 157 ++++++++++++++++++
 1 file changed, 157 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro

diff --git a/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro b/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
new file mode 100644
index 000000000000..41edab6c3e28
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
@@ -0,0 +1,157 @@
+What:		/sys/bus/platform/devices/smpro-errmon.*/error_[core|mem|pcie|other]_[ce|ue]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the 48-byte Ampere (Vendor-Specific) Error Record, see [1],
+		printed in hex format as below:
+
+		AABBCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\
+		DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
+		Where:
+		  AA       : Error Type
+		  BB       : Subtype
+		  CCCC     : Instance
+		  DDD...DDD: 44-byte value similar to the Arm RAS standard error record
+
+		See [1] below for the format details.
+
+		The detail of each sysfs entries is as below:
+		+-------------+---------------------------------------------------------+
+		|   Error     |                   Sysfs entry                           |
+		+-------------+---------------------------------------------------------+
+		| Core's CE   | /sys/bus/platform/devices/smpro-errmon.*/error_core_ce |
+		| Core's UE   | /sys/bus/platform/devices/smpro-errmon.*/error_core_ue |
+		| Memory's CE | /sys/bus/platform/devices/smpro-errmon.*/error_mem_ce  |
+		| Memory's UE | /sys/bus/platform/devices/smpro-errmon.*/error_mem_ue  |
+		| PCIe's CE   | /sys/bus/platform/devices/smpro-errmon.*/error_pcie_ce |
+		| PCIe's UE   | /sys/bus/platform/devices/smpro-errmon.*/error_pcie_ue |
+		| Other's CE  | /sys/bus/platform/devices/smpro-errmon.*/error_other_ce|
+		| Other's UE  | /sys/bus/platform/devices/smpro-errmon.*/error_other_ue|
+		+-------------+---------------------------------------------------------+
+		UE: Uncorrect-able Error
+		CE: Correct-able Error
+
+		[1] Section 3.3 Ampere (Vendor-Specific) Error Record Formats,
+		    Altra Family RAS Supplement.
+
+
+What:		/sys/bus/platform/devices/smpro-errmon.*/overflow_[core|mem|pcie|other]_[ce|ue]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Return the overflow status of each type HW error reported:
+		  0      : No overflow
+		  1      : There is an overflow and the oldest HW errors are dropped
+
+		The detail of each sysfs entries is as below:
+		+-------------+-----------------------------------------------------------+
+		|   Overflow  |                   Sysfs entry                             |
+		+-------------+-----------------------------------------------------------+
+		| Core's CE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_core_ce |
+		| Core's UE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_core_ue |
+		| Memory's CE | /sys/bus/platform/devices/smpro-errmon.*/overflow_mem_ce  |
+		| Memory's UE | /sys/bus/platform/devices/smpro-errmon.*/overflow_mem_ue  |
+		| PCIe's CE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_pcie_ce |
+		| PCIe's UE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_pcie_ue |
+		| Other's CE  | /sys/bus/platform/devices/smpro-errmon.*/overflow_other_ce|
+		| Other's UE  | /sys/bus/platform/devices/smpro-errmon.*/overflow_other_ue|
+		+-------------+-----------------------------------------------------------+
+		UE: Uncorrect-able Error
+		CE: Correct-able Error
+
+What:           /sys/bus/platform/devices/smpro-errmon.*/error_[smpro|pmpro]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the internal firmware error record printed as hex format
+		as below:
+
+		ABBCDDEEEEFFFFFFFF
+		Where:
+		  A       : Firmware Error Type
+		              1: Warning
+		              2: Error
+			      4: Error with data
+		  BB      : Firmware Image Code (8-bit value)
+		  C       : Direction:
+		              0: Enter
+		              1: Exit
+		  DD      : Location, firmware module location code (8-bit value)
+		  EEEE    : Error Code, firmware Error Code (16-bit value)
+		  FFFFFFFF: Extensive data (32-bit value)
+
+		Example:
+		  root@mtjade:~# cat /sys/bus/platform/devices/smpro-errmon.1.auto/error_smpro
+		  109008000a00000000
+
+		The detail of each sysfs entries is as below:
+		+-------------+-------------------------------------------------------+
+		|   Error     |                   Sysfs entry                         |
+		+-------------+-------------------------------------------------------+
+		| SMpro error | /sys/bus/platform/devices/smpro-errmon.*/error_smpro  |
+		| PMpro error | /sys/bus/platform/devices/smpro-errmon.*/error_pmpro  |
+		+-------------+-------------------------------------------------------+
+		See more details in section 5.10 RAS Internal Error Register Definitions,
+		Altra Family Soc BMC Interface Specification.
+
+
+What:           /sys/bus/platform/devices/smpro-errmon.*/event_[vrd_warn_fault|vrd_hot|dimm_hot]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the detail information in case of VRD/DIMM warning/hot events
+		in hex format as below:
+
+		AABBBB
+		Where:
+		  AA  : The event channel
+		          00: VRD Warning Fault
+		          01: VRD Hot
+			  02: DIMM host
+		  BBBB: The event detail information data
+
+		See more details in section 5.7 GPI Status Registers,
+		Altra Family Soc BMC Interface Specification.
+
+
+What:		/sys/bus/platform/devices/smpro-misc.*/boot_progress
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the boot stages information in hex as format below:
+
+		AABBCCCCCCCC
+		Where:
+		  AA      : The boot stages
+		              00: SMpro firmware booting
+		              01: PMpro firmware booting
+		              02: ATF BL1 firmware booting
+		              03: DDR initialization
+		              04: DDR training report status
+		              05: ATF BL2 firmware booting
+		              06: ATF BL31 firmware booting
+		              07: ATF BL32 firmware booting
+		              08: UEFI firmware booting
+		              09: OS booting
+		  BB      : Boot status
+		              00: Not started
+		              01: Started
+		              02: Completed without error
+		              03: Failed.
+		  CCCCCCCC: Boot status information defined for each boot stages
+
+		See more details in section 5.11 Boot Stage Register Definitions,
+		and section 6. Processor Boot Progress Codes, Altra Family Soc BMC
+		Interface Specification.
+
+
+What:           /sys/bus/platform/devices/smpro-misc*/soc_power_limit
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RW) Contains the desired SoC power limit in Watt.
+		Writes to this sysfs set the desired SoC power limit (W).
+		Reads from this register return the current SoC power limit (W).
+		The value ranges:
+		  Minimum: 120 W
+		  Maximum: Socket TDP power
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v8 9/9] docs: ABI: testing: Document the Ampere Altra Family's SMpro sysfs interfaces
@ 2022-04-22  2:46   ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22  2:46 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Greg Kroah-Hartman, Quan Nguyen, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

Add documentation for the Ampere(R)'s Altra(R) SMpro sysfs interfaces

Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
---
Changes in v8:
  + Sysfs to return single value in hex format              [Greg]
  + Fix KernelVersion info                                  [Greg]
  + Change errors_* to error_*                              [Quan]
  + Added overflow_[core|mem|pcie|other]_[ce|ue]            [Quan]

Changes in v7:
  + First introduce in v7                                   [Greg]

 .../sysfs-bus-platform-devices-ampere-smpro   | 157 ++++++++++++++++++
 1 file changed, 157 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro

diff --git a/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro b/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
new file mode 100644
index 000000000000..41edab6c3e28
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-platform-devices-ampere-smpro
@@ -0,0 +1,157 @@
+What:		/sys/bus/platform/devices/smpro-errmon.*/error_[core|mem|pcie|other]_[ce|ue]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the 48-byte Ampere (Vendor-Specific) Error Record, see [1],
+		printed in hex format as below:
+
+		AABBCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\
+		DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
+		Where:
+		  AA       : Error Type
+		  BB       : Subtype
+		  CCCC     : Instance
+		  DDD...DDD: 44-byte value similar to the Arm RAS standard error record
+
+		See [1] below for the format details.
+
+		The detail of each sysfs entries is as below:
+		+-------------+---------------------------------------------------------+
+		|   Error     |                   Sysfs entry                           |
+		+-------------+---------------------------------------------------------+
+		| Core's CE   | /sys/bus/platform/devices/smpro-errmon.*/error_core_ce |
+		| Core's UE   | /sys/bus/platform/devices/smpro-errmon.*/error_core_ue |
+		| Memory's CE | /sys/bus/platform/devices/smpro-errmon.*/error_mem_ce  |
+		| Memory's UE | /sys/bus/platform/devices/smpro-errmon.*/error_mem_ue  |
+		| PCIe's CE   | /sys/bus/platform/devices/smpro-errmon.*/error_pcie_ce |
+		| PCIe's UE   | /sys/bus/platform/devices/smpro-errmon.*/error_pcie_ue |
+		| Other's CE  | /sys/bus/platform/devices/smpro-errmon.*/error_other_ce|
+		| Other's UE  | /sys/bus/platform/devices/smpro-errmon.*/error_other_ue|
+		+-------------+---------------------------------------------------------+
+		UE: Uncorrect-able Error
+		CE: Correct-able Error
+
+		[1] Section 3.3 Ampere (Vendor-Specific) Error Record Formats,
+		    Altra Family RAS Supplement.
+
+
+What:		/sys/bus/platform/devices/smpro-errmon.*/overflow_[core|mem|pcie|other]_[ce|ue]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Return the overflow status of each type HW error reported:
+		  0      : No overflow
+		  1      : There is an overflow and the oldest HW errors are dropped
+
+		The detail of each sysfs entries is as below:
+		+-------------+-----------------------------------------------------------+
+		|   Overflow  |                   Sysfs entry                             |
+		+-------------+-----------------------------------------------------------+
+		| Core's CE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_core_ce |
+		| Core's UE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_core_ue |
+		| Memory's CE | /sys/bus/platform/devices/smpro-errmon.*/overflow_mem_ce  |
+		| Memory's UE | /sys/bus/platform/devices/smpro-errmon.*/overflow_mem_ue  |
+		| PCIe's CE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_pcie_ce |
+		| PCIe's UE   | /sys/bus/platform/devices/smpro-errmon.*/overflow_pcie_ue |
+		| Other's CE  | /sys/bus/platform/devices/smpro-errmon.*/overflow_other_ce|
+		| Other's UE  | /sys/bus/platform/devices/smpro-errmon.*/overflow_other_ue|
+		+-------------+-----------------------------------------------------------+
+		UE: Uncorrect-able Error
+		CE: Correct-able Error
+
+What:           /sys/bus/platform/devices/smpro-errmon.*/error_[smpro|pmpro]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the internal firmware error record printed as hex format
+		as below:
+
+		ABBCDDEEEEFFFFFFFF
+		Where:
+		  A       : Firmware Error Type
+		              1: Warning
+		              2: Error
+			      4: Error with data
+		  BB      : Firmware Image Code (8-bit value)
+		  C       : Direction:
+		              0: Enter
+		              1: Exit
+		  DD      : Location, firmware module location code (8-bit value)
+		  EEEE    : Error Code, firmware Error Code (16-bit value)
+		  FFFFFFFF: Extensive data (32-bit value)
+
+		Example:
+		  root@mtjade:~# cat /sys/bus/platform/devices/smpro-errmon.1.auto/error_smpro
+		  109008000a00000000
+
+		The detail of each sysfs entries is as below:
+		+-------------+-------------------------------------------------------+
+		|   Error     |                   Sysfs entry                         |
+		+-------------+-------------------------------------------------------+
+		| SMpro error | /sys/bus/platform/devices/smpro-errmon.*/error_smpro  |
+		| PMpro error | /sys/bus/platform/devices/smpro-errmon.*/error_pmpro  |
+		+-------------+-------------------------------------------------------+
+		See more details in section 5.10 RAS Internal Error Register Definitions,
+		Altra Family Soc BMC Interface Specification.
+
+
+What:           /sys/bus/platform/devices/smpro-errmon.*/event_[vrd_warn_fault|vrd_hot|dimm_hot]
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the detail information in case of VRD/DIMM warning/hot events
+		in hex format as below:
+
+		AABBBB
+		Where:
+		  AA  : The event channel
+		          00: VRD Warning Fault
+		          01: VRD Hot
+			  02: DIMM host
+		  BBBB: The event detail information data
+
+		See more details in section 5.7 GPI Status Registers,
+		Altra Family Soc BMC Interface Specification.
+
+
+What:		/sys/bus/platform/devices/smpro-misc.*/boot_progress
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RO) Contains the boot stages information in hex as format below:
+
+		AABBCCCCCCCC
+		Where:
+		  AA      : The boot stages
+		              00: SMpro firmware booting
+		              01: PMpro firmware booting
+		              02: ATF BL1 firmware booting
+		              03: DDR initialization
+		              04: DDR training report status
+		              05: ATF BL2 firmware booting
+		              06: ATF BL31 firmware booting
+		              07: ATF BL32 firmware booting
+		              08: UEFI firmware booting
+		              09: OS booting
+		  BB      : Boot status
+		              00: Not started
+		              01: Started
+		              02: Completed without error
+		              03: Failed.
+		  CCCCCCCC: Boot status information defined for each boot stages
+
+		See more details in section 5.11 Boot Stage Register Definitions,
+		and section 6. Processor Boot Progress Codes, Altra Family Soc BMC
+		Interface Specification.
+
+
+What:           /sys/bus/platform/devices/smpro-misc*/soc_power_limit
+KernelVersion:	5.18
+Contact:	quan@os.amperecomputing.com
+Description:
+		(RW) Contains the desired SoC power limit in Watt.
+		Writes to this sysfs set the desired SoC power limit (W).
+		Reads from this register return the current SoC power limit (W).
+		The value ranges:
+		  Minimum: 120 W
+		  Maximum: Socket TDP power
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22  2:46   ` Quan Nguyen
@ 2022-04-22  6:20     ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-22  6:20 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> This commit adds Ampere's SMpro error monitor driver for monitoring
> and reporting RAS-related errors as reported by SMpro co-processor
> found on Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>   + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>   + Avoid uninitialized variable use               [kernel test robot]
>   + Switch to use sysfs_emit()                                  [Greg]
>   + Make sysfs to return single value                           [Greg]
>   + Change errors_* sysfs to error_*                            [Quan]
>   + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>   overflow status of each type of HW errors                     [Quan]
>   + Add some minor refactor                                     [Quan]
> 
> Changes in v7:
>   + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>   + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>   + Validate number of errors before read                       [Quan]
>   + Fix wrong return type of *_show() function     [kernel test robot]
>   + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>   + Use pointer instead of stack memory                         [Quan]
> 
> Changes in v6:
>   + First introduced in v6 [Quan]
> 
>  drivers/misc/Kconfig        |  12 +
>  drivers/misc/Makefile       |   1 +
>  drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 490 insertions(+)
>  create mode 100644 drivers/misc/smpro-errmon.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 41d2bb0ae23a..9fbe6797c440 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -176,6 +176,18 @@ config SGI_XP
>  	  this feature will allow for direct communication between SSIs
>  	  based on a network adapter and DMA messaging.
>  
> +config SMPRO_ERRMON
> +	tristate "Ampere Computing SMPro error monitor driver"
> +	depends on MFD_SMPRO || COMPILE_TEST
> +	help
> +	  Say Y here to get support for the SMpro error monitor function
> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> +	  loading, the driver creates sysfs files which can be use to gather
> +	  multiple HW error data reported via read and write system calls.
> +
> +	  To compile this driver as a module, say M here. The driver will be
> +	  called smpro-errmon.
> +
>  config CS5535_MFGPT
>  	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>  	depends on MFD_CS5535
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 70e800e9127f..483308a6e113 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>  obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>  obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>  obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>  obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>  obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>  obj-$(CONFIG_HP_ILO)		+= hpilo.o
> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> new file mode 100644
> index 000000000000..df7d8fc4ff3f
> --- /dev/null
> +++ b/drivers/misc/smpro-errmon.c
> @@ -0,0 +1,477 @@
> +// SPDX-License-Identifier: GPL-2.0+

Are you sure you mean "or any later version"?  I have to ask.

> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
> +	{
> +	 ERR_SMPRO_TYPE,
> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
> +	},
> +	{
> +	 ERR_PMPRO_TYPE,
> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
> +	},

Odd indentation, checkpatch did not complain?

> +static ssize_t smpro_event_data_read(struct device *dev,
> +				     struct device_attribute *da, char *buf,
> +				     int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	s32 event_data;
> +	int ret;
> +
> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
> +	if (ret)
> +		goto done;

Just return the error here.

> +
> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);

sysfs rules are one value per file.  You know this.

> +	/* Clear event after read */
> +	if (event_data != 0)

Why would it be 0?  Isn't 0 a valid value?


> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
> +done:
> +	return ret;
> +}
> +
> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
> +					char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	struct smpro_error_hdr *err_info;
> +	s32 err_count;
> +	int ret;
> +
> +	err_info = &smpro_error_table[channel];
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
> +	if (ret)
> +		return ret;
> +
> +	/* Bit 8 indicates the overflow status */
> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
> +}
> +
> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
> +				     char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
> +	struct smpro_error_hdr *err_info;
> +	s32 err_count, err_length;
> +	int count = 0;
> +	int ret;
> +
> +	err_info = &smpro_error_table[channel];
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
> +	/* Error count is the low byte */
> +	err_count &= 0xff;
> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
> +		goto done;

Just return the error.

> +
> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
> +	if (ret || err_length <= 0)
> +		goto done;

return the error.

Wait, you could return 0 here, are you sure about that?

> +
> +	if (err_length > MAX_READ_BLOCK_LENGTH)
> +		err_length = MAX_READ_BLOCK_LENGTH;
> +
> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
> +	if (ret < 0)
> +		goto done;

return the error, no need for a goto in this function.

> +
> +	/*
> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
> +	 * <Error Type><Error SubType><Instance><Error Status>\
> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
> +	 * Where:
> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
> +	 *  + Instance: Combination of the socket, channel,
> +	 *    slot cause the error. (2 bytes)
> +	 *  + Error Status: Encode of error status. (4 bytes)
> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
> +	 * Reference Altra SOC BMC Interface specification.
> +	 */
> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
> +
> +	/* go to next error */
> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
> +done:
> +	return ret ? ret : count;
> +}
> +
> +/*
> + * Output format:
> + * <errType><image><dir><Location><errorCode><data>
> + * Where:
> + *   + errType: SCP Error Type (3 bits)
> + *      1: Warning
> + *      2: Error
> + *      4: Error with data
> + *   + image: SCP Image Code (8 bits)
> + *   + dir: Direction (1 bit)
> + *      0: Enter
> + *      1: Exit
> + *   + location: SCP Module Location Code (8 bits)
> + *   + errorCode: SCP Error Code (16 bits)
> + *   + data : Extensive data (32 bits)
> + *      All bits are 0 when errType is warning or error.
> + */
> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
> +				       char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	struct smpro_int_error_hdr *err_info;
> +	unsigned int data_lo = 0, data_hi = 0;
> +	unsigned int ret_hi, ret_lo;
> +	unsigned int err_type;
> +	unsigned int value;
> +	int count = 0;
> +	int ret;
> +
> +	/* read error status */
> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
> +	if (ret)
> +		goto done;

Same mess here, just return the error.

> +
> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
> +		goto done;

No error?  Are you sure?

> +
> +	err_info = &list_smpro_int_error_hdr[channel];
> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
> +	if (ret)
> +		goto done;
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
> +	if (ret)
> +		goto done;
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
> +	if (ret)
> +		goto done;
> +
> +	if (err_type & BIT(2)) {
> +		/* Error with data type */
> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
> +		if (ret)
> +			goto done;
> +
> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
> +		if (ret)
> +			goto done;
> +
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
> +
> +	} else if (err_type & BIT(1)) {
> +		/* Error type */
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
> +
> +	} else if (err_type & BIT(0)) {
> +		/* Warning type */
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
> +	}
> +done:
> +	return ret ? ret : count;
> +}
> +
> +#define ERROR_OVERFLOW_RO(_error, _index) \
> +	static ssize_t overflow_##_error##_show(struct device *dev,            \
> +						struct device_attribute *da,   \
> +						char *buf)                     \
> +	{                                                                      \
> +		return smpro_overflow_data_read(dev, da, buf, _index);         \
> +	}                                                                      \
> +	static DEVICE_ATTR_RO(overflow_##_error)
> +
> +ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
> +ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
> +ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
> +ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
> +ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
> +ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
> +ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
> +ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
> +
> +#define ERROR_RO(_error, _index) \
> +	static ssize_t error_##_error##_show(struct device *dev,            \
> +					     struct device_attribute *da,   \
> +					     char *buf)                     \
> +	{                                                                   \
> +		return smpro_error_data_read(dev, da, buf, _index);         \
> +	}                                                                   \
> +	static DEVICE_ATTR_RO(error_##_error)
> +
> +ERROR_RO(core_ce, CORE_CE_ERRS);
> +ERROR_RO(core_ue, CORE_UE_ERRS);
> +ERROR_RO(mem_ce, MEM_CE_ERRS);
> +ERROR_RO(mem_ue, MEM_UE_ERRS);
> +ERROR_RO(pcie_ce, PCIE_CE_ERRS);
> +ERROR_RO(pcie_ue, PCIE_UE_ERRS);
> +ERROR_RO(other_ce, OTHER_CE_ERRS);
> +ERROR_RO(other_ue, OTHER_UE_ERRS);
> +
> +static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
> +{
> +	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
> +}
> +static DEVICE_ATTR_RO(error_smpro);
> +
> +static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
> +{
> +	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
> +}
> +static DEVICE_ATTR_RO(error_pmpro);
> +
> +#define EVENT_RO(_event, _index) \
> +	static ssize_t event_##_event##_show(struct device *dev,            \
> +					     struct device_attribute *da,   \
> +					     char *buf)                     \
> +	{                                                                   \
> +		return smpro_event_data_read(dev, da, buf, _index);         \
> +	}                                                                   \
> +	static DEVICE_ATTR_RO(event_##_event)
> +
> +EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
> +EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
> +EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
> +
> +static struct attribute *smpro_errmon_attrs[] = {
> +	&dev_attr_overflow_core_ce.attr,
> +	&dev_attr_overflow_core_ue.attr,
> +	&dev_attr_overflow_mem_ce.attr,
> +	&dev_attr_overflow_mem_ue.attr,
> +	&dev_attr_overflow_pcie_ce.attr,
> +	&dev_attr_overflow_pcie_ue.attr,
> +	&dev_attr_overflow_other_ce.attr,
> +	&dev_attr_overflow_other_ue.attr,
> +	&dev_attr_error_core_ce.attr,
> +	&dev_attr_error_core_ue.attr,
> +	&dev_attr_error_mem_ce.attr,
> +	&dev_attr_error_mem_ue.attr,
> +	&dev_attr_error_pcie_ce.attr,
> +	&dev_attr_error_pcie_ue.attr,
> +	&dev_attr_error_other_ce.attr,
> +	&dev_attr_error_other_ue.attr,
> +	&dev_attr_error_smpro.attr,
> +	&dev_attr_error_pmpro.attr,
> +	&dev_attr_event_vrd_warn_fault.attr,
> +	&dev_attr_event_vrd_hot.attr,
> +	&dev_attr_event_dimm_hot.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group smpro_errmon_attr_group = {
> +	.attrs = smpro_errmon_attrs
> +};

ATTRIBUTE_GROUPS()?


> +
> +static int smpro_errmon_probe(struct platform_device *pdev)
> +{
> +	struct smpro_errmon *errmon;
> +	int ret;
> +
> +	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
> +	if (!errmon)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, errmon);
> +
> +	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
> +	if (!errmon->regmap)
> +		return -ENODEV;
> +
> +	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);

You just raced with userspace and lost :(

Always use the default groups of the platform driver for this.  That way
you do not have to do anything special and your files will be created
properly.

> +	if (ret)
> +		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
> +
> +	return 0;
> +}
> +
> +static int smpro_errmon_remove(struct platform_device *pdev)
> +{
> +	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
> +	pr_info("SMPro errmon sysfs entries removed");

Drivers are quiet when all is working properly.

If you set the pointer properly as asked above, you do not have to
remove the group on your own.

Huge hint, if you ever call sysfs_* from a driver, something is probably
wrong.

Same goes for the other drivers in this series, please fix them all up
this way.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22  6:20     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-22  6:20 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> This commit adds Ampere's SMpro error monitor driver for monitoring
> and reporting RAS-related errors as reported by SMpro co-processor
> found on Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>   + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>   + Avoid uninitialized variable use               [kernel test robot]
>   + Switch to use sysfs_emit()                                  [Greg]
>   + Make sysfs to return single value                           [Greg]
>   + Change errors_* sysfs to error_*                            [Quan]
>   + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>   overflow status of each type of HW errors                     [Quan]
>   + Add some minor refactor                                     [Quan]
> 
> Changes in v7:
>   + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>   + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>   + Validate number of errors before read                       [Quan]
>   + Fix wrong return type of *_show() function     [kernel test robot]
>   + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>   + Use pointer instead of stack memory                         [Quan]
> 
> Changes in v6:
>   + First introduced in v6 [Quan]
> 
>  drivers/misc/Kconfig        |  12 +
>  drivers/misc/Makefile       |   1 +
>  drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 490 insertions(+)
>  create mode 100644 drivers/misc/smpro-errmon.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 41d2bb0ae23a..9fbe6797c440 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -176,6 +176,18 @@ config SGI_XP
>  	  this feature will allow for direct communication between SSIs
>  	  based on a network adapter and DMA messaging.
>  
> +config SMPRO_ERRMON
> +	tristate "Ampere Computing SMPro error monitor driver"
> +	depends on MFD_SMPRO || COMPILE_TEST
> +	help
> +	  Say Y here to get support for the SMpro error monitor function
> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> +	  loading, the driver creates sysfs files which can be use to gather
> +	  multiple HW error data reported via read and write system calls.
> +
> +	  To compile this driver as a module, say M here. The driver will be
> +	  called smpro-errmon.
> +
>  config CS5535_MFGPT
>  	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>  	depends on MFD_CS5535
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 70e800e9127f..483308a6e113 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>  obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>  obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>  obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>  obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>  obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>  obj-$(CONFIG_HP_ILO)		+= hpilo.o
> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> new file mode 100644
> index 000000000000..df7d8fc4ff3f
> --- /dev/null
> +++ b/drivers/misc/smpro-errmon.c
> @@ -0,0 +1,477 @@
> +// SPDX-License-Identifier: GPL-2.0+

Are you sure you mean "or any later version"?  I have to ask.

> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
> +	{
> +	 ERR_SMPRO_TYPE,
> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
> +	},
> +	{
> +	 ERR_PMPRO_TYPE,
> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
> +	},

Odd indentation, checkpatch did not complain?

> +static ssize_t smpro_event_data_read(struct device *dev,
> +				     struct device_attribute *da, char *buf,
> +				     int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	s32 event_data;
> +	int ret;
> +
> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
> +	if (ret)
> +		goto done;

Just return the error here.

> +
> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);

sysfs rules are one value per file.  You know this.

> +	/* Clear event after read */
> +	if (event_data != 0)

Why would it be 0?  Isn't 0 a valid value?


> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
> +done:
> +	return ret;
> +}
> +
> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
> +					char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	struct smpro_error_hdr *err_info;
> +	s32 err_count;
> +	int ret;
> +
> +	err_info = &smpro_error_table[channel];
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
> +	if (ret)
> +		return ret;
> +
> +	/* Bit 8 indicates the overflow status */
> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
> +}
> +
> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
> +				     char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
> +	struct smpro_error_hdr *err_info;
> +	s32 err_count, err_length;
> +	int count = 0;
> +	int ret;
> +
> +	err_info = &smpro_error_table[channel];
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
> +	/* Error count is the low byte */
> +	err_count &= 0xff;
> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
> +		goto done;

Just return the error.

> +
> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
> +	if (ret || err_length <= 0)
> +		goto done;

return the error.

Wait, you could return 0 here, are you sure about that?

> +
> +	if (err_length > MAX_READ_BLOCK_LENGTH)
> +		err_length = MAX_READ_BLOCK_LENGTH;
> +
> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
> +	if (ret < 0)
> +		goto done;

return the error, no need for a goto in this function.

> +
> +	/*
> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
> +	 * <Error Type><Error SubType><Instance><Error Status>\
> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
> +	 * Where:
> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
> +	 *  + Instance: Combination of the socket, channel,
> +	 *    slot cause the error. (2 bytes)
> +	 *  + Error Status: Encode of error status. (4 bytes)
> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
> +	 * Reference Altra SOC BMC Interface specification.
> +	 */
> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
> +
> +	/* go to next error */
> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
> +done:
> +	return ret ? ret : count;
> +}
> +
> +/*
> + * Output format:
> + * <errType><image><dir><Location><errorCode><data>
> + * Where:
> + *   + errType: SCP Error Type (3 bits)
> + *      1: Warning
> + *      2: Error
> + *      4: Error with data
> + *   + image: SCP Image Code (8 bits)
> + *   + dir: Direction (1 bit)
> + *      0: Enter
> + *      1: Exit
> + *   + location: SCP Module Location Code (8 bits)
> + *   + errorCode: SCP Error Code (16 bits)
> + *   + data : Extensive data (32 bits)
> + *      All bits are 0 when errType is warning or error.
> + */
> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
> +				       char *buf, int channel)
> +{
> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
> +	struct smpro_int_error_hdr *err_info;
> +	unsigned int data_lo = 0, data_hi = 0;
> +	unsigned int ret_hi, ret_lo;
> +	unsigned int err_type;
> +	unsigned int value;
> +	int count = 0;
> +	int ret;
> +
> +	/* read error status */
> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
> +	if (ret)
> +		goto done;

Same mess here, just return the error.

> +
> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
> +		goto done;

No error?  Are you sure?

> +
> +	err_info = &list_smpro_int_error_hdr[channel];
> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
> +	if (ret)
> +		goto done;
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
> +	if (ret)
> +		goto done;
> +
> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
> +	if (ret)
> +		goto done;
> +
> +	if (err_type & BIT(2)) {
> +		/* Error with data type */
> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
> +		if (ret)
> +			goto done;
> +
> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
> +		if (ret)
> +			goto done;
> +
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
> +
> +	} else if (err_type & BIT(1)) {
> +		/* Error type */
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
> +
> +	} else if (err_type & BIT(0)) {
> +		/* Warning type */
> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> +		/* clear the read errors */
> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
> +	}
> +done:
> +	return ret ? ret : count;
> +}
> +
> +#define ERROR_OVERFLOW_RO(_error, _index) \
> +	static ssize_t overflow_##_error##_show(struct device *dev,            \
> +						struct device_attribute *da,   \
> +						char *buf)                     \
> +	{                                                                      \
> +		return smpro_overflow_data_read(dev, da, buf, _index);         \
> +	}                                                                      \
> +	static DEVICE_ATTR_RO(overflow_##_error)
> +
> +ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
> +ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
> +ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
> +ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
> +ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
> +ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
> +ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
> +ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
> +
> +#define ERROR_RO(_error, _index) \
> +	static ssize_t error_##_error##_show(struct device *dev,            \
> +					     struct device_attribute *da,   \
> +					     char *buf)                     \
> +	{                                                                   \
> +		return smpro_error_data_read(dev, da, buf, _index);         \
> +	}                                                                   \
> +	static DEVICE_ATTR_RO(error_##_error)
> +
> +ERROR_RO(core_ce, CORE_CE_ERRS);
> +ERROR_RO(core_ue, CORE_UE_ERRS);
> +ERROR_RO(mem_ce, MEM_CE_ERRS);
> +ERROR_RO(mem_ue, MEM_UE_ERRS);
> +ERROR_RO(pcie_ce, PCIE_CE_ERRS);
> +ERROR_RO(pcie_ue, PCIE_UE_ERRS);
> +ERROR_RO(other_ce, OTHER_CE_ERRS);
> +ERROR_RO(other_ue, OTHER_UE_ERRS);
> +
> +static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
> +{
> +	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
> +}
> +static DEVICE_ATTR_RO(error_smpro);
> +
> +static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
> +{
> +	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
> +}
> +static DEVICE_ATTR_RO(error_pmpro);
> +
> +#define EVENT_RO(_event, _index) \
> +	static ssize_t event_##_event##_show(struct device *dev,            \
> +					     struct device_attribute *da,   \
> +					     char *buf)                     \
> +	{                                                                   \
> +		return smpro_event_data_read(dev, da, buf, _index);         \
> +	}                                                                   \
> +	static DEVICE_ATTR_RO(event_##_event)
> +
> +EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
> +EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
> +EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
> +
> +static struct attribute *smpro_errmon_attrs[] = {
> +	&dev_attr_overflow_core_ce.attr,
> +	&dev_attr_overflow_core_ue.attr,
> +	&dev_attr_overflow_mem_ce.attr,
> +	&dev_attr_overflow_mem_ue.attr,
> +	&dev_attr_overflow_pcie_ce.attr,
> +	&dev_attr_overflow_pcie_ue.attr,
> +	&dev_attr_overflow_other_ce.attr,
> +	&dev_attr_overflow_other_ue.attr,
> +	&dev_attr_error_core_ce.attr,
> +	&dev_attr_error_core_ue.attr,
> +	&dev_attr_error_mem_ce.attr,
> +	&dev_attr_error_mem_ue.attr,
> +	&dev_attr_error_pcie_ce.attr,
> +	&dev_attr_error_pcie_ue.attr,
> +	&dev_attr_error_other_ce.attr,
> +	&dev_attr_error_other_ue.attr,
> +	&dev_attr_error_smpro.attr,
> +	&dev_attr_error_pmpro.attr,
> +	&dev_attr_event_vrd_warn_fault.attr,
> +	&dev_attr_event_vrd_hot.attr,
> +	&dev_attr_event_dimm_hot.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group smpro_errmon_attr_group = {
> +	.attrs = smpro_errmon_attrs
> +};

ATTRIBUTE_GROUPS()?


> +
> +static int smpro_errmon_probe(struct platform_device *pdev)
> +{
> +	struct smpro_errmon *errmon;
> +	int ret;
> +
> +	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
> +	if (!errmon)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, errmon);
> +
> +	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
> +	if (!errmon->regmap)
> +		return -ENODEV;
> +
> +	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);

You just raced with userspace and lost :(

Always use the default groups of the platform driver for this.  That way
you do not have to do anything special and your files will be created
properly.

> +	if (ret)
> +		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
> +
> +	return 0;
> +}
> +
> +static int smpro_errmon_remove(struct platform_device *pdev)
> +{
> +	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
> +	pr_info("SMPro errmon sysfs entries removed");

Drivers are quiet when all is working properly.

If you set the pointer properly as asked above, you do not have to
remove the group on your own.

Huge hint, if you ever call sysfs_* from a driver, something is probably
wrong.

Same goes for the other drivers in this series, please fix them all up
this way.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 4/9] docs: misc-devices: (smpro-errmon) Add documentation
  2022-04-22  2:46   ` Quan Nguyen
@ 2022-04-22  6:27     ` Bagas Sanjaya
  -1 siblings, 0 replies; 44+ messages in thread
From: Bagas Sanjaya @ 2022-04-22  6:27 UTC (permalink / raw)
  To: Quan Nguyen, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Derek Kiernan,
	Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Phong Vo, Thang Q . Nguyen

On 4/22/22 09:46, Quan Nguyen wrote:
> Adds documentation for Ampere(R)'s Altra(R) SMpro errmon driver.
> 

Hi Quan,

Building htmldocs, I got this new warning:

/home/bagas/repo/linux-stable/Documentation/misc-devices/smpro-errmon.rst:128: WARNING: Malformed table.
Column span alignment problem in table line 56.

============   ==========    =========   ===============  ================
Error Group    Error Type    Sub type    Sub component    Instance
CPM            0             0           Snoop-Logic      CPM #
CPM            0             2           Armv8 Core 1     CPM #
MCU            1             1           ERR1             MCU # | SLOT << 11
MCU            1             2           ERR2             MCU # | SLOT << 11
MCU            1             3           ERR3             MCU #
MCU            1             4           ERR4             MCU #
MCU            1             5           ERR5             MCU #
MCU            1             6           ERR6             MCU #
MCU            1             7           Link Error       MCU #
Mesh           2             0           Cross Point      X | (Y << 5) | NS <<11
Mesh           2             1           Home Node(IO)    X | (Y << 5) | NS <<11
Mesh           2             2           Home Node(Mem)   X | (Y << 5) | NS <<11 | device<<12
Mesh           2             4           CCIX Node        X | (Y << 5) | NS <<11
2P Link        3             0           N/A              Altra 2P Link #
GIC            5             0           ERR0             0
GIC            5             1           ERR1             0
GIC            5             2           ERR2             0
GIC            5             3           ERR3             0
GIC            5             4           ERR4             0
GIC            5             5           ERR5             0
GIC            5             6           ERR6             0
GIC            5             7           ERR7             0
GIC            5             8           ERR8             0
GIC            5             9           ERR9             0
GIC            5             10          ERR10            0
GIC            5             11          ERR11            0
GIC            5             12          ERR12            0
GIC            5             13-21       ERR13            RC# + 1
SMMU           6             TCU         100              RC #
SMMU           6             TBU0        0                RC #
SMMU           6             TBU1        1                RC #
SMMU           6             TBU2        2                RC #
SMMU           6             TBU3        3                RC #
SMMU           6             TBU4        4                RC #
SMMU           6             TBU5        5                RC #
SMMU           6             TBU6        6                RC #
SMMU           6             TBU7        7                RC #
SMMU           6             TBU8        8                RC #
SMMU           6             TBU9        9                RC #
PCIe AER       7             Root        0                RC #
PCIe AER       7             Device      1                RC #
PCIe RC        8             RCA HB      0                RC #
PCIe RC        8             RCB HB      1                RC #
PCIe RC        8             RASDP       8                RC #
OCM            9             ERR0        0                0
OCM            9             ERR1        1                0
OCM            9             ERR2        2                0
SMpro          10            ERR0        0                0
SMpro          10            ERR1        1                0
SMpro          10            MPA_ERR     2                0
PMpro          11            ERR0        0                0
PMpro          11            ERR1        1                0
PMpro          11            MPA_ERR     2                0
=============  ==========    =========   ===============  ================

I have applied the following fixup:

From f16c63afa2064247507762ffcb623f575043f4a6 Mon Sep 17 00:00:00 2001
From: Bagas Sanjaya <bagasdotme@gmail.com>
Date: Fri, 22 Apr 2022 13:16:31 +0700
Subject: [PATCH] fixup for "docs: misc-devices: (smpro-errmon) Add
 documentation"

Fix table syntax warning

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 Documentation/misc-devices/smpro-errmon.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/misc-devices/smpro-errmon.rst b/Documentation/misc-devices/smpro-errmon.rst
index 53599904da7008..818f12bd8aca4d 100644
--- a/Documentation/misc-devices/smpro-errmon.rst
+++ b/Documentation/misc-devices/smpro-errmon.rst
@@ -70,8 +70,9 @@ The format of the error lines is defended on the alert/event type.
 
 Below table defines the value of Error types, Sub Types, Sub component and instance:
 
-    ============   ==========    =========   ===============  ================
+    ============   ==========    =========   ===============  ====================================
     Error Group    Error Type    Sub type    Sub component    Instance
+    ============   ==========    =========   ===============  ====================================
     CPM            0             0           Snoop-Logic      CPM #
     CPM            0             2           Armv8 Core 1     CPM #
     MCU            1             1           ERR1             MCU # | SLOT << 11
@@ -125,7 +126,7 @@ Below table defines the value of Error types, Sub Types, Sub component and insta
     PMpro          11            ERR0        0                0
     PMpro          11            ERR1        1                0
     PMpro          11            MPA_ERR     2                0
-    =============  ==========    =========   ===============  ================
+    ============   ==========    =========   ===============  ====================================
 
 
 2) Type 2 for the Internal SMpro/PMpro alert types::
-- 
An old man doll... just what I always wanted! - Clara

For consistency with the fixup, you need to format the tables so that
headings will be emphasized, by adding second ='s line before first
content row.

Thanks.

-- 
An old man doll... just what I always wanted! - Clara

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 4/9] docs: misc-devices: (smpro-errmon) Add documentation
@ 2022-04-22  6:27     ` Bagas Sanjaya
  0 siblings, 0 replies; 44+ messages in thread
From: Bagas Sanjaya @ 2022-04-22  6:27 UTC (permalink / raw)
  To: Quan Nguyen, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Derek Kiernan,
	Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, Thang Q . Nguyen, Phong Vo

On 4/22/22 09:46, Quan Nguyen wrote:
> Adds documentation for Ampere(R)'s Altra(R) SMpro errmon driver.
> 

Hi Quan,

Building htmldocs, I got this new warning:

/home/bagas/repo/linux-stable/Documentation/misc-devices/smpro-errmon.rst:128: WARNING: Malformed table.
Column span alignment problem in table line 56.

============   ==========    =========   ===============  ================
Error Group    Error Type    Sub type    Sub component    Instance
CPM            0             0           Snoop-Logic      CPM #
CPM            0             2           Armv8 Core 1     CPM #
MCU            1             1           ERR1             MCU # | SLOT << 11
MCU            1             2           ERR2             MCU # | SLOT << 11
MCU            1             3           ERR3             MCU #
MCU            1             4           ERR4             MCU #
MCU            1             5           ERR5             MCU #
MCU            1             6           ERR6             MCU #
MCU            1             7           Link Error       MCU #
Mesh           2             0           Cross Point      X | (Y << 5) | NS <<11
Mesh           2             1           Home Node(IO)    X | (Y << 5) | NS <<11
Mesh           2             2           Home Node(Mem)   X | (Y << 5) | NS <<11 | device<<12
Mesh           2             4           CCIX Node        X | (Y << 5) | NS <<11
2P Link        3             0           N/A              Altra 2P Link #
GIC            5             0           ERR0             0
GIC            5             1           ERR1             0
GIC            5             2           ERR2             0
GIC            5             3           ERR3             0
GIC            5             4           ERR4             0
GIC            5             5           ERR5             0
GIC            5             6           ERR6             0
GIC            5             7           ERR7             0
GIC            5             8           ERR8             0
GIC            5             9           ERR9             0
GIC            5             10          ERR10            0
GIC            5             11          ERR11            0
GIC            5             12          ERR12            0
GIC            5             13-21       ERR13            RC# + 1
SMMU           6             TCU         100              RC #
SMMU           6             TBU0        0                RC #
SMMU           6             TBU1        1                RC #
SMMU           6             TBU2        2                RC #
SMMU           6             TBU3        3                RC #
SMMU           6             TBU4        4                RC #
SMMU           6             TBU5        5                RC #
SMMU           6             TBU6        6                RC #
SMMU           6             TBU7        7                RC #
SMMU           6             TBU8        8                RC #
SMMU           6             TBU9        9                RC #
PCIe AER       7             Root        0                RC #
PCIe AER       7             Device      1                RC #
PCIe RC        8             RCA HB      0                RC #
PCIe RC        8             RCB HB      1                RC #
PCIe RC        8             RASDP       8                RC #
OCM            9             ERR0        0                0
OCM            9             ERR1        1                0
OCM            9             ERR2        2                0
SMpro          10            ERR0        0                0
SMpro          10            ERR1        1                0
SMpro          10            MPA_ERR     2                0
PMpro          11            ERR0        0                0
PMpro          11            ERR1        1                0
PMpro          11            MPA_ERR     2                0
=============  ==========    =========   ===============  ================

I have applied the following fixup:

From f16c63afa2064247507762ffcb623f575043f4a6 Mon Sep 17 00:00:00 2001
From: Bagas Sanjaya <bagasdotme@gmail.com>
Date: Fri, 22 Apr 2022 13:16:31 +0700
Subject: [PATCH] fixup for "docs: misc-devices: (smpro-errmon) Add
 documentation"

Fix table syntax warning

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 Documentation/misc-devices/smpro-errmon.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/misc-devices/smpro-errmon.rst b/Documentation/misc-devices/smpro-errmon.rst
index 53599904da7008..818f12bd8aca4d 100644
--- a/Documentation/misc-devices/smpro-errmon.rst
+++ b/Documentation/misc-devices/smpro-errmon.rst
@@ -70,8 +70,9 @@ The format of the error lines is defended on the alert/event type.
 
 Below table defines the value of Error types, Sub Types, Sub component and instance:
 
-    ============   ==========    =========   ===============  ================
+    ============   ==========    =========   ===============  ====================================
     Error Group    Error Type    Sub type    Sub component    Instance
+    ============   ==========    =========   ===============  ====================================
     CPM            0             0           Snoop-Logic      CPM #
     CPM            0             2           Armv8 Core 1     CPM #
     MCU            1             1           ERR1             MCU # | SLOT << 11
@@ -125,7 +126,7 @@ Below table defines the value of Error types, Sub Types, Sub component and insta
     PMpro          11            ERR0        0                0
     PMpro          11            ERR1        1                0
     PMpro          11            MPA_ERR     2                0
-    =============  ==========    =========   ===============  ================
+    ============   ==========    =========   ===============  ====================================
 
 
 2) Type 2 for the Internal SMpro/PMpro alert types::
-- 
An old man doll... just what I always wanted! - Clara

For consistency with the fixup, you need to format the tables so that
headings will be emphasized, by adding second ='s line before first
content row.

Thanks.

-- 
An old man doll... just what I always wanted! - Clara

^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22  6:20     ` Greg Kroah-Hartman
@ 2022-04-22 14:43       ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22 14:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>> This commit adds Ampere's SMpro error monitor driver for monitoring
>> and reporting RAS-related errors as reported by SMpro co-processor
>> found on Ampere's Altra processor family.
>>
>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>> ---
>> Changes in v8:
>>    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>    + Avoid uninitialized variable use               [kernel test robot]
>>    + Switch to use sysfs_emit()                                  [Greg]
>>    + Make sysfs to return single value                           [Greg]
>>    + Change errors_* sysfs to error_*                            [Quan]
>>    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>    overflow status of each type of HW errors                     [Quan]
>>    + Add some minor refactor                                     [Quan]
>>
>> Changes in v7:
>>    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>    + Validate number of errors before read                       [Quan]
>>    + Fix wrong return type of *_show() function     [kernel test robot]
>>    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>    + Use pointer instead of stack memory                         [Quan]
>>
>> Changes in v6:
>>    + First introduced in v6 [Quan]
>>
>>   drivers/misc/Kconfig        |  12 +
>>   drivers/misc/Makefile       |   1 +
>>   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>   3 files changed, 490 insertions(+)
>>   create mode 100644 drivers/misc/smpro-errmon.c
>>
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 41d2bb0ae23a..9fbe6797c440 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -176,6 +176,18 @@ config SGI_XP
>>   	  this feature will allow for direct communication between SSIs
>>   	  based on a network adapter and DMA messaging.
>>   
>> +config SMPRO_ERRMON
>> +	tristate "Ampere Computing SMPro error monitor driver"
>> +	depends on MFD_SMPRO || COMPILE_TEST
>> +	help
>> +	  Say Y here to get support for the SMpro error monitor function
>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>> +	  loading, the driver creates sysfs files which can be use to gather
>> +	  multiple HW error data reported via read and write system calls.
>> +
>> +	  To compile this driver as a module, say M here. The driver will be
>> +	  called smpro-errmon.
>> +
>>   config CS5535_MFGPT
>>   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>   	depends on MFD_CS5535
>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>> index 70e800e9127f..483308a6e113 100644
>> --- a/drivers/misc/Makefile
>> +++ b/drivers/misc/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>   obj-$(CONFIG_HP_ILO)		+= hpilo.o
>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>> new file mode 100644
>> index 000000000000..df7d8fc4ff3f
>> --- /dev/null
>> +++ b/drivers/misc/smpro-errmon.c
>> @@ -0,0 +1,477 @@
>> +// SPDX-License-Identifier: GPL-2.0+
> 
> Are you sure you mean "or any later version"?  I have to ask.
> 

Thank Greg for the review.

Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next 
version.

>> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
>> +	{
>> +	 ERR_SMPRO_TYPE,
>> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
>> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
>> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
>> +	},
>> +	{
>> +	 ERR_PMPRO_TYPE,
>> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
>> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
>> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
>> +	},
> 
> Odd indentation, checkpatch did not complain?
> 

No, checkpatch.pl did not complain. But let me check to see if there is 
better indentation.

>> +static ssize_t smpro_event_data_read(struct device *dev,
>> +				     struct device_attribute *da, char *buf,
>> +				     int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	s32 event_data;
>> +	int ret;
>> +
>> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
>> +	if (ret)
>> +		goto done;
> 
> Just return the error here.
> 
Will fix in next version

>> +
>> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
> 
> sysfs rules are one value per file.  You know this.
> 
Yes, I will address this in my next version. The "channel" could be 
removed as the sysfs file name itself is enough to identify the channel.

>> +	/* Clear event after read */
>> +	if (event_data != 0)
> 
> Why would it be 0?  Isn't 0 a valid value?
> 
> 

0 means it is good and there is no event, but if it is not 0, that mean 
there is an event and need to be written back to clear that event.

>> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
>> +done:
>> +	return ret;
>> +}
>> +
>> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
>> +					char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/* Bit 8 indicates the overflow status */
>> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
>> +}
>> +
>> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
>> +				     char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count, err_length;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	/* Error count is the low byte */
>> +	err_count &= 0xff;
>> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
>> +		goto done;
> 
> Just return the error.
> 
Will fix in next version.

>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
>> +	if (ret || err_length <= 0)
>> +		goto done;
> 
> return the error.
> 
> Wait, you could return 0 here, are you sure about that?
> 
Yes, that is our intention.
If ret != 0 then return the error
Otherwise, if ret == 0 then return 0 if there is no error and/or 
err_length invalid.

>> +
>> +	if (err_length > MAX_READ_BLOCK_LENGTH)
>> +		err_length = MAX_READ_BLOCK_LENGTH;
>> +
>> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
>> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
>> +	if (ret < 0)
>> +		goto done;
> 
> return the error, no need for a goto in this function.
> 
Agree, will fix this and any other places as well.

>> +
>> +	/*
>> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
>> +	 * <Error Type><Error SubType><Instance><Error Status>\
>> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
>> +	 * Where:
>> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
>> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
>> +	 *  + Instance: Combination of the socket, channel,
>> +	 *    slot cause the error. (2 bytes)
>> +	 *  + Error Status: Encode of error status. (4 bytes)
>> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
>> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
>> +	 * Reference Altra SOC BMC Interface specification.
>> +	 */
>> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
>> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
>> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
>> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
>> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
>> +
>> +	/* go to next error */
>> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +/*
>> + * Output format:
>> + * <errType><image><dir><Location><errorCode><data>
>> + * Where:
>> + *   + errType: SCP Error Type (3 bits)
>> + *      1: Warning
>> + *      2: Error
>> + *      4: Error with data
>> + *   + image: SCP Image Code (8 bits)
>> + *   + dir: Direction (1 bit)
>> + *      0: Enter
>> + *      1: Exit
>> + *   + location: SCP Module Location Code (8 bits)
>> + *   + errorCode: SCP Error Code (16 bits)
>> + *   + data : Extensive data (32 bits)
>> + *      All bits are 0 when errType is warning or error.
>> + */
>> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
>> +				       char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_int_error_hdr *err_info;
>> +	unsigned int data_lo = 0, data_hi = 0;
>> +	unsigned int ret_hi, ret_lo;
>> +	unsigned int err_type;
>> +	unsigned int value;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	/* read error status */
>> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
>> +	if (ret)
>> +		goto done;
> 
> Same mess here, just return the error.
> 
Yes. will do.
>> +
>> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
>> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
>> +		goto done;
> 
> No error?  Are you sure?
> 
Yes, no error, but let me try to make this a bit simpler in next version.

>> +
>> +	err_info = &list_smpro_int_error_hdr[channel];
>> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
>> +	if (ret)
>> +		goto done;
>> +
>> +	if (err_type & BIT(2)) {
>> +		/* Error with data type */
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>> +		if (ret)
>> +			goto done;
>> +
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>> +		if (ret)
>> +			goto done;
>> +
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>> +
>> +	} else if (err_type & BIT(1)) {
>> +		/* Error type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>> +
>> +	} else if (err_type & BIT(0)) {
>> +		/* Warning type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
>> +	}
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +#define ERROR_OVERFLOW_RO(_error, _index) \
>> +	static ssize_t overflow_##_error##_show(struct device *dev,            \
>> +						struct device_attribute *da,   \
>> +						char *buf)                     \
>> +	{                                                                      \
>> +		return smpro_overflow_data_read(dev, da, buf, _index);         \
>> +	}                                                                      \
>> +	static DEVICE_ATTR_RO(overflow_##_error)
>> +
>> +ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
>> +ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
>> +ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
>> +ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
>> +ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
>> +ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
>> +ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
>> +ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
>> +
>> +#define ERROR_RO(_error, _index) \
>> +	static ssize_t error_##_error##_show(struct device *dev,            \
>> +					     struct device_attribute *da,   \
>> +					     char *buf)                     \
>> +	{                                                                   \
>> +		return smpro_error_data_read(dev, da, buf, _index);         \
>> +	}                                                                   \
>> +	static DEVICE_ATTR_RO(error_##_error)
>> +
>> +ERROR_RO(core_ce, CORE_CE_ERRS);
>> +ERROR_RO(core_ue, CORE_UE_ERRS);
>> +ERROR_RO(mem_ce, MEM_CE_ERRS);
>> +ERROR_RO(mem_ue, MEM_UE_ERRS);
>> +ERROR_RO(pcie_ce, PCIE_CE_ERRS);
>> +ERROR_RO(pcie_ue, PCIE_UE_ERRS);
>> +ERROR_RO(other_ce, OTHER_CE_ERRS);
>> +ERROR_RO(other_ue, OTHER_UE_ERRS);
>> +
>> +static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
>> +{
>> +	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
>> +}
>> +static DEVICE_ATTR_RO(error_smpro);
>> +
>> +static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
>> +{
>> +	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
>> +}
>> +static DEVICE_ATTR_RO(error_pmpro);
>> +
>> +#define EVENT_RO(_event, _index) \
>> +	static ssize_t event_##_event##_show(struct device *dev,            \
>> +					     struct device_attribute *da,   \
>> +					     char *buf)                     \
>> +	{                                                                   \
>> +		return smpro_event_data_read(dev, da, buf, _index);         \
>> +	}                                                                   \
>> +	static DEVICE_ATTR_RO(event_##_event)
>> +
>> +EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
>> +EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
>> +EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
>> +
>> +static struct attribute *smpro_errmon_attrs[] = {
>> +	&dev_attr_overflow_core_ce.attr,
>> +	&dev_attr_overflow_core_ue.attr,
>> +	&dev_attr_overflow_mem_ce.attr,
>> +	&dev_attr_overflow_mem_ue.attr,
>> +	&dev_attr_overflow_pcie_ce.attr,
>> +	&dev_attr_overflow_pcie_ue.attr,
>> +	&dev_attr_overflow_other_ce.attr,
>> +	&dev_attr_overflow_other_ue.attr,
>> +	&dev_attr_error_core_ce.attr,
>> +	&dev_attr_error_core_ue.attr,
>> +	&dev_attr_error_mem_ce.attr,
>> +	&dev_attr_error_mem_ue.attr,
>> +	&dev_attr_error_pcie_ce.attr,
>> +	&dev_attr_error_pcie_ue.attr,
>> +	&dev_attr_error_other_ce.attr,
>> +	&dev_attr_error_other_ue.attr,
>> +	&dev_attr_error_smpro.attr,
>> +	&dev_attr_error_pmpro.attr,
>> +	&dev_attr_event_vrd_warn_fault.attr,
>> +	&dev_attr_event_vrd_hot.attr,
>> +	&dev_attr_event_dimm_hot.attr,
>> +	NULL
>> +};
>> +
>> +static const struct attribute_group smpro_errmon_attr_group = {
>> +	.attrs = smpro_errmon_attrs
>> +};
> 
> ATTRIBUTE_GROUPS()?
> 
> 
Will use this macro in next version.

>> +
>> +static int smpro_errmon_probe(struct platform_device *pdev)
>> +{
>> +	struct smpro_errmon *errmon;
>> +	int ret;
>> +
>> +	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
>> +	if (!errmon)
>> +		return -ENOMEM;
>> +
>> +	platform_set_drvdata(pdev, errmon);
>> +
>> +	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
>> +	if (!errmon->regmap)
>> +		return -ENODEV;
>> +
>> +	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
> 
> You just raced with userspace and lost :(
> 
> Always use the default groups of the platform driver for this.  That way
> you do not have to do anything special and your files will be created
> properly.
> 

And will switch to use .dev_groups follow your article at 
https://lwn.net/Articles/793061/

>> +	if (ret)
>> +		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
>> +
>> +	return 0;
>> +}
>> +
>> +static int smpro_errmon_remove(struct platform_device *pdev)
>> +{
>> +	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
>> +	pr_info("SMPro errmon sysfs entries removed");
> 
> Drivers are quiet when all is working properly.
> 
> If you set the pointer properly as asked above, you do not have to
> remove the group on your own.
> 
> Huge hint, if you ever call sysfs_* from a driver, something is probably
> wrong.
> 
> Same goes for the other drivers in this series, please fix them all up
> this way.
> 
Thanks for pointing out. Will apply all other places where applicable.

Thank you for the review,
-- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22 14:43       ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22 14:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>> This commit adds Ampere's SMpro error monitor driver for monitoring
>> and reporting RAS-related errors as reported by SMpro co-processor
>> found on Ampere's Altra processor family.
>>
>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>> ---
>> Changes in v8:
>>    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>    + Avoid uninitialized variable use               [kernel test robot]
>>    + Switch to use sysfs_emit()                                  [Greg]
>>    + Make sysfs to return single value                           [Greg]
>>    + Change errors_* sysfs to error_*                            [Quan]
>>    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>    overflow status of each type of HW errors                     [Quan]
>>    + Add some minor refactor                                     [Quan]
>>
>> Changes in v7:
>>    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>    + Validate number of errors before read                       [Quan]
>>    + Fix wrong return type of *_show() function     [kernel test robot]
>>    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>    + Use pointer instead of stack memory                         [Quan]
>>
>> Changes in v6:
>>    + First introduced in v6 [Quan]
>>
>>   drivers/misc/Kconfig        |  12 +
>>   drivers/misc/Makefile       |   1 +
>>   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>   3 files changed, 490 insertions(+)
>>   create mode 100644 drivers/misc/smpro-errmon.c
>>
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 41d2bb0ae23a..9fbe6797c440 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -176,6 +176,18 @@ config SGI_XP
>>   	  this feature will allow for direct communication between SSIs
>>   	  based on a network adapter and DMA messaging.
>>   
>> +config SMPRO_ERRMON
>> +	tristate "Ampere Computing SMPro error monitor driver"
>> +	depends on MFD_SMPRO || COMPILE_TEST
>> +	help
>> +	  Say Y here to get support for the SMpro error monitor function
>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>> +	  loading, the driver creates sysfs files which can be use to gather
>> +	  multiple HW error data reported via read and write system calls.
>> +
>> +	  To compile this driver as a module, say M here. The driver will be
>> +	  called smpro-errmon.
>> +
>>   config CS5535_MFGPT
>>   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>   	depends on MFD_CS5535
>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>> index 70e800e9127f..483308a6e113 100644
>> --- a/drivers/misc/Makefile
>> +++ b/drivers/misc/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>   obj-$(CONFIG_HP_ILO)		+= hpilo.o
>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>> new file mode 100644
>> index 000000000000..df7d8fc4ff3f
>> --- /dev/null
>> +++ b/drivers/misc/smpro-errmon.c
>> @@ -0,0 +1,477 @@
>> +// SPDX-License-Identifier: GPL-2.0+
> 
> Are you sure you mean "or any later version"?  I have to ask.
> 

Thank Greg for the review.

Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next 
version.

>> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
>> +	{
>> +	 ERR_SMPRO_TYPE,
>> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
>> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
>> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
>> +	},
>> +	{
>> +	 ERR_PMPRO_TYPE,
>> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
>> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
>> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
>> +	},
> 
> Odd indentation, checkpatch did not complain?
> 

No, checkpatch.pl did not complain. But let me check to see if there is 
better indentation.

>> +static ssize_t smpro_event_data_read(struct device *dev,
>> +				     struct device_attribute *da, char *buf,
>> +				     int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	s32 event_data;
>> +	int ret;
>> +
>> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
>> +	if (ret)
>> +		goto done;
> 
> Just return the error here.
> 
Will fix in next version

>> +
>> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
> 
> sysfs rules are one value per file.  You know this.
> 
Yes, I will address this in my next version. The "channel" could be 
removed as the sysfs file name itself is enough to identify the channel.

>> +	/* Clear event after read */
>> +	if (event_data != 0)
> 
> Why would it be 0?  Isn't 0 a valid value?
> 
> 

0 means it is good and there is no event, but if it is not 0, that mean 
there is an event and need to be written back to clear that event.

>> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
>> +done:
>> +	return ret;
>> +}
>> +
>> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
>> +					char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/* Bit 8 indicates the overflow status */
>> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
>> +}
>> +
>> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
>> +				     char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count, err_length;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	/* Error count is the low byte */
>> +	err_count &= 0xff;
>> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
>> +		goto done;
> 
> Just return the error.
> 
Will fix in next version.

>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
>> +	if (ret || err_length <= 0)
>> +		goto done;
> 
> return the error.
> 
> Wait, you could return 0 here, are you sure about that?
> 
Yes, that is our intention.
If ret != 0 then return the error
Otherwise, if ret == 0 then return 0 if there is no error and/or 
err_length invalid.

>> +
>> +	if (err_length > MAX_READ_BLOCK_LENGTH)
>> +		err_length = MAX_READ_BLOCK_LENGTH;
>> +
>> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
>> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
>> +	if (ret < 0)
>> +		goto done;
> 
> return the error, no need for a goto in this function.
> 
Agree, will fix this and any other places as well.

>> +
>> +	/*
>> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
>> +	 * <Error Type><Error SubType><Instance><Error Status>\
>> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
>> +	 * Where:
>> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
>> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
>> +	 *  + Instance: Combination of the socket, channel,
>> +	 *    slot cause the error. (2 bytes)
>> +	 *  + Error Status: Encode of error status. (4 bytes)
>> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
>> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
>> +	 * Reference Altra SOC BMC Interface specification.
>> +	 */
>> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
>> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
>> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
>> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
>> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
>> +
>> +	/* go to next error */
>> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +/*
>> + * Output format:
>> + * <errType><image><dir><Location><errorCode><data>
>> + * Where:
>> + *   + errType: SCP Error Type (3 bits)
>> + *      1: Warning
>> + *      2: Error
>> + *      4: Error with data
>> + *   + image: SCP Image Code (8 bits)
>> + *   + dir: Direction (1 bit)
>> + *      0: Enter
>> + *      1: Exit
>> + *   + location: SCP Module Location Code (8 bits)
>> + *   + errorCode: SCP Error Code (16 bits)
>> + *   + data : Extensive data (32 bits)
>> + *      All bits are 0 when errType is warning or error.
>> + */
>> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
>> +				       char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_int_error_hdr *err_info;
>> +	unsigned int data_lo = 0, data_hi = 0;
>> +	unsigned int ret_hi, ret_lo;
>> +	unsigned int err_type;
>> +	unsigned int value;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	/* read error status */
>> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
>> +	if (ret)
>> +		goto done;
> 
> Same mess here, just return the error.
> 
Yes. will do.
>> +
>> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
>> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
>> +		goto done;
> 
> No error?  Are you sure?
> 
Yes, no error, but let me try to make this a bit simpler in next version.

>> +
>> +	err_info = &list_smpro_int_error_hdr[channel];
>> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
>> +	if (ret)
>> +		goto done;
>> +
>> +	if (err_type & BIT(2)) {
>> +		/* Error with data type */
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>> +		if (ret)
>> +			goto done;
>> +
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>> +		if (ret)
>> +			goto done;
>> +
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>> +
>> +	} else if (err_type & BIT(1)) {
>> +		/* Error type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>> +
>> +	} else if (err_type & BIT(0)) {
>> +		/* Warning type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(0));
>> +	}
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +#define ERROR_OVERFLOW_RO(_error, _index) \
>> +	static ssize_t overflow_##_error##_show(struct device *dev,            \
>> +						struct device_attribute *da,   \
>> +						char *buf)                     \
>> +	{                                                                      \
>> +		return smpro_overflow_data_read(dev, da, buf, _index);         \
>> +	}                                                                      \
>> +	static DEVICE_ATTR_RO(overflow_##_error)
>> +
>> +ERROR_OVERFLOW_RO(core_ce, CORE_CE_ERRS);
>> +ERROR_OVERFLOW_RO(core_ue, CORE_UE_ERRS);
>> +ERROR_OVERFLOW_RO(mem_ce, MEM_CE_ERRS);
>> +ERROR_OVERFLOW_RO(mem_ue, MEM_UE_ERRS);
>> +ERROR_OVERFLOW_RO(pcie_ce, PCIE_CE_ERRS);
>> +ERROR_OVERFLOW_RO(pcie_ue, PCIE_UE_ERRS);
>> +ERROR_OVERFLOW_RO(other_ce, OTHER_CE_ERRS);
>> +ERROR_OVERFLOW_RO(other_ue, OTHER_UE_ERRS);
>> +
>> +#define ERROR_RO(_error, _index) \
>> +	static ssize_t error_##_error##_show(struct device *dev,            \
>> +					     struct device_attribute *da,   \
>> +					     char *buf)                     \
>> +	{                                                                   \
>> +		return smpro_error_data_read(dev, da, buf, _index);         \
>> +	}                                                                   \
>> +	static DEVICE_ATTR_RO(error_##_error)
>> +
>> +ERROR_RO(core_ce, CORE_CE_ERRS);
>> +ERROR_RO(core_ue, CORE_UE_ERRS);
>> +ERROR_RO(mem_ce, MEM_CE_ERRS);
>> +ERROR_RO(mem_ue, MEM_UE_ERRS);
>> +ERROR_RO(pcie_ce, PCIE_CE_ERRS);
>> +ERROR_RO(pcie_ue, PCIE_UE_ERRS);
>> +ERROR_RO(other_ce, OTHER_CE_ERRS);
>> +ERROR_RO(other_ue, OTHER_UE_ERRS);
>> +
>> +static ssize_t error_smpro_show(struct device *dev, struct device_attribute *da, char *buf)
>> +{
>> +	return smpro_internal_err_read(dev, da, buf, RAS_SMPRO_ERRS);
>> +}
>> +static DEVICE_ATTR_RO(error_smpro);
>> +
>> +static ssize_t error_pmpro_show(struct device *dev, struct device_attribute *da, char *buf)
>> +{
>> +	return smpro_internal_err_read(dev, da, buf, RAS_PMPRO_ERRS);
>> +}
>> +static DEVICE_ATTR_RO(error_pmpro);
>> +
>> +#define EVENT_RO(_event, _index) \
>> +	static ssize_t event_##_event##_show(struct device *dev,            \
>> +					     struct device_attribute *da,   \
>> +					     char *buf)                     \
>> +	{                                                                   \
>> +		return smpro_event_data_read(dev, da, buf, _index);         \
>> +	}                                                                   \
>> +	static DEVICE_ATTR_RO(event_##_event)
>> +
>> +EVENT_RO(vrd_warn_fault, VRD_WARN_FAULT_EVENTS);
>> +EVENT_RO(vrd_hot, VRD_HOT_EVENTS);
>> +EVENT_RO(dimm_hot, DIMM_HOT_EVENTS);
>> +
>> +static struct attribute *smpro_errmon_attrs[] = {
>> +	&dev_attr_overflow_core_ce.attr,
>> +	&dev_attr_overflow_core_ue.attr,
>> +	&dev_attr_overflow_mem_ce.attr,
>> +	&dev_attr_overflow_mem_ue.attr,
>> +	&dev_attr_overflow_pcie_ce.attr,
>> +	&dev_attr_overflow_pcie_ue.attr,
>> +	&dev_attr_overflow_other_ce.attr,
>> +	&dev_attr_overflow_other_ue.attr,
>> +	&dev_attr_error_core_ce.attr,
>> +	&dev_attr_error_core_ue.attr,
>> +	&dev_attr_error_mem_ce.attr,
>> +	&dev_attr_error_mem_ue.attr,
>> +	&dev_attr_error_pcie_ce.attr,
>> +	&dev_attr_error_pcie_ue.attr,
>> +	&dev_attr_error_other_ce.attr,
>> +	&dev_attr_error_other_ue.attr,
>> +	&dev_attr_error_smpro.attr,
>> +	&dev_attr_error_pmpro.attr,
>> +	&dev_attr_event_vrd_warn_fault.attr,
>> +	&dev_attr_event_vrd_hot.attr,
>> +	&dev_attr_event_dimm_hot.attr,
>> +	NULL
>> +};
>> +
>> +static const struct attribute_group smpro_errmon_attr_group = {
>> +	.attrs = smpro_errmon_attrs
>> +};
> 
> ATTRIBUTE_GROUPS()?
> 
> 
Will use this macro in next version.

>> +
>> +static int smpro_errmon_probe(struct platform_device *pdev)
>> +{
>> +	struct smpro_errmon *errmon;
>> +	int ret;
>> +
>> +	errmon = devm_kzalloc(&pdev->dev, sizeof(struct smpro_errmon), GFP_KERNEL);
>> +	if (!errmon)
>> +		return -ENOMEM;
>> +
>> +	platform_set_drvdata(pdev, errmon);
>> +
>> +	errmon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
>> +	if (!errmon->regmap)
>> +		return -ENODEV;
>> +
>> +	ret = sysfs_create_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
> 
> You just raced with userspace and lost :(
> 
> Always use the default groups of the platform driver for this.  That way
> you do not have to do anything special and your files will be created
> properly.
> 

And will switch to use .dev_groups follow your article at 
https://lwn.net/Articles/793061/

>> +	if (ret)
>> +		dev_err(&pdev->dev, "SMPro errmon sysfs registration failed\n");
>> +
>> +	return 0;
>> +}
>> +
>> +static int smpro_errmon_remove(struct platform_device *pdev)
>> +{
>> +	sysfs_remove_group(&pdev->dev.kobj, &smpro_errmon_attr_group);
>> +	pr_info("SMPro errmon sysfs entries removed");
> 
> Drivers are quiet when all is working properly.
> 
> If you set the pointer properly as asked above, you do not have to
> remove the group on your own.
> 
> Huge hint, if you ever call sysfs_* from a driver, something is probably
> wrong.
> 
> Same goes for the other drivers in this series, please fix them all up
> this way.
> 
Thanks for pointing out. Will apply all other places where applicable.

Thank you for the review,
-- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22 14:43       ` Quan Nguyen
@ 2022-04-22 14:57         ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-22 14:57 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
> On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> > On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> > > This commit adds Ampere's SMpro error monitor driver for monitoring
> > > and reporting RAS-related errors as reported by SMpro co-processor
> > > found on Ampere's Altra processor family.
> > > 
> > > Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> > > ---
> > > Changes in v8:
> > >    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
> > >    + Avoid uninitialized variable use               [kernel test robot]
> > >    + Switch to use sysfs_emit()                                  [Greg]
> > >    + Make sysfs to return single value                           [Greg]
> > >    + Change errors_* sysfs to error_*                            [Quan]
> > >    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
> > >    overflow status of each type of HW errors                     [Quan]
> > >    + Add some minor refactor                                     [Quan]
> > > 
> > > Changes in v7:
> > >    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
> > >    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
> > >    + Validate number of errors before read                       [Quan]
> > >    + Fix wrong return type of *_show() function     [kernel test robot]
> > >    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
> > >    + Use pointer instead of stack memory                         [Quan]
> > > 
> > > Changes in v6:
> > >    + First introduced in v6 [Quan]
> > > 
> > >   drivers/misc/Kconfig        |  12 +
> > >   drivers/misc/Makefile       |   1 +
> > >   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
> > >   3 files changed, 490 insertions(+)
> > >   create mode 100644 drivers/misc/smpro-errmon.c
> > > 
> > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > index 41d2bb0ae23a..9fbe6797c440 100644
> > > --- a/drivers/misc/Kconfig
> > > +++ b/drivers/misc/Kconfig
> > > @@ -176,6 +176,18 @@ config SGI_XP
> > >   	  this feature will allow for direct communication between SSIs
> > >   	  based on a network adapter and DMA messaging.
> > > +config SMPRO_ERRMON
> > > +	tristate "Ampere Computing SMPro error monitor driver"
> > > +	depends on MFD_SMPRO || COMPILE_TEST
> > > +	help
> > > +	  Say Y here to get support for the SMpro error monitor function
> > > +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> > > +	  loading, the driver creates sysfs files which can be use to gather
> > > +	  multiple HW error data reported via read and write system calls.
> > > +
> > > +	  To compile this driver as a module, say M here. The driver will be
> > > +	  called smpro-errmon.
> > > +
> > >   config CS5535_MFGPT
> > >   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
> > >   	depends on MFD_CS5535
> > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > index 70e800e9127f..483308a6e113 100644
> > > --- a/drivers/misc/Makefile
> > > +++ b/drivers/misc/Makefile
> > > @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
> > >   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
> > >   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
> > >   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> > > +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
> > >   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
> > >   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
> > >   obj-$(CONFIG_HP_ILO)		+= hpilo.o
> > > diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> > > new file mode 100644
> > > index 000000000000..df7d8fc4ff3f
> > > --- /dev/null
> > > +++ b/drivers/misc/smpro-errmon.c
> > > @@ -0,0 +1,477 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > 
> > Are you sure you mean "or any later version"?  I have to ask.
> > 
> 
> Thank Greg for the review.
> 
> Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
> version.

That is not what I am asking (the SPDX tag format).  I mean, do you
really mean "or later" for your license as that is not the license of
the kernel overall?  If so, wonderful, but I have to ask that as your
legal group needs to be aware of it, sorry.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22 14:57         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-22 14:57 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
> On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> > On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> > > This commit adds Ampere's SMpro error monitor driver for monitoring
> > > and reporting RAS-related errors as reported by SMpro co-processor
> > > found on Ampere's Altra processor family.
> > > 
> > > Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> > > ---
> > > Changes in v8:
> > >    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
> > >    + Avoid uninitialized variable use               [kernel test robot]
> > >    + Switch to use sysfs_emit()                                  [Greg]
> > >    + Make sysfs to return single value                           [Greg]
> > >    + Change errors_* sysfs to error_*                            [Quan]
> > >    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
> > >    overflow status of each type of HW errors                     [Quan]
> > >    + Add some minor refactor                                     [Quan]
> > > 
> > > Changes in v7:
> > >    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
> > >    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
> > >    + Validate number of errors before read                       [Quan]
> > >    + Fix wrong return type of *_show() function     [kernel test robot]
> > >    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
> > >    + Use pointer instead of stack memory                         [Quan]
> > > 
> > > Changes in v6:
> > >    + First introduced in v6 [Quan]
> > > 
> > >   drivers/misc/Kconfig        |  12 +
> > >   drivers/misc/Makefile       |   1 +
> > >   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
> > >   3 files changed, 490 insertions(+)
> > >   create mode 100644 drivers/misc/smpro-errmon.c
> > > 
> > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > index 41d2bb0ae23a..9fbe6797c440 100644
> > > --- a/drivers/misc/Kconfig
> > > +++ b/drivers/misc/Kconfig
> > > @@ -176,6 +176,18 @@ config SGI_XP
> > >   	  this feature will allow for direct communication between SSIs
> > >   	  based on a network adapter and DMA messaging.
> > > +config SMPRO_ERRMON
> > > +	tristate "Ampere Computing SMPro error monitor driver"
> > > +	depends on MFD_SMPRO || COMPILE_TEST
> > > +	help
> > > +	  Say Y here to get support for the SMpro error monitor function
> > > +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> > > +	  loading, the driver creates sysfs files which can be use to gather
> > > +	  multiple HW error data reported via read and write system calls.
> > > +
> > > +	  To compile this driver as a module, say M here. The driver will be
> > > +	  called smpro-errmon.
> > > +
> > >   config CS5535_MFGPT
> > >   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
> > >   	depends on MFD_CS5535
> > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > index 70e800e9127f..483308a6e113 100644
> > > --- a/drivers/misc/Makefile
> > > +++ b/drivers/misc/Makefile
> > > @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
> > >   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
> > >   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
> > >   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> > > +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
> > >   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
> > >   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
> > >   obj-$(CONFIG_HP_ILO)		+= hpilo.o
> > > diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> > > new file mode 100644
> > > index 000000000000..df7d8fc4ff3f
> > > --- /dev/null
> > > +++ b/drivers/misc/smpro-errmon.c
> > > @@ -0,0 +1,477 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > 
> > Are you sure you mean "or any later version"?  I have to ask.
> > 
> 
> Thank Greg for the review.
> 
> Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
> version.

That is not what I am asking (the SPDX tag format).  I mean, do you
really mean "or later" for your license as that is not the license of
the kernel overall?  If so, wonderful, but I have to ask that as your
legal group needs to be aware of it, sorry.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22 14:57         ` Greg Kroah-Hartman
@ 2022-04-22 17:07           ` Darren Hart
  -1 siblings, 0 replies; 44+ messages in thread
From: Darren Hart @ 2022-04-22 17:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Quan Nguyen, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Derek Kiernan,
	Dragan Cvetic, Arnd Bergmann, Thu Nguyen, linux-kernel,
	devicetree, linux-hwmon, linux-doc, OpenBMC Maillist,
	Open Source Submission, Phong Vo, Thang Q . Nguyen

On Fri, Apr 22, 2022 at 04:57:52PM +0200, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
> > On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> > > On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> > > > This commit adds Ampere's SMpro error monitor driver for monitoring
> > > > and reporting RAS-related errors as reported by SMpro co-processor
> > > > found on Ampere's Altra processor family.
> > > > 
> > > > Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> > > > ---
> > > > Changes in v8:
> > > >    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
> > > >    + Avoid uninitialized variable use               [kernel test robot]
> > > >    + Switch to use sysfs_emit()                                  [Greg]
> > > >    + Make sysfs to return single value                           [Greg]
> > > >    + Change errors_* sysfs to error_*                            [Quan]
> > > >    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
> > > >    overflow status of each type of HW errors                     [Quan]
> > > >    + Add some minor refactor                                     [Quan]
> > > > 
> > > > Changes in v7:
> > > >    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
> > > >    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
> > > >    + Validate number of errors before read                       [Quan]
> > > >    + Fix wrong return type of *_show() function     [kernel test robot]
> > > >    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
> > > >    + Use pointer instead of stack memory                         [Quan]
> > > > 
> > > > Changes in v6:
> > > >    + First introduced in v6 [Quan]
> > > > 
> > > >   drivers/misc/Kconfig        |  12 +
> > > >   drivers/misc/Makefile       |   1 +
> > > >   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
> > > >   3 files changed, 490 insertions(+)
> > > >   create mode 100644 drivers/misc/smpro-errmon.c
> > > > 
> > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > > index 41d2bb0ae23a..9fbe6797c440 100644
> > > > --- a/drivers/misc/Kconfig
> > > > +++ b/drivers/misc/Kconfig
> > > > @@ -176,6 +176,18 @@ config SGI_XP
> > > >   	  this feature will allow for direct communication between SSIs
> > > >   	  based on a network adapter and DMA messaging.
> > > > +config SMPRO_ERRMON
> > > > +	tristate "Ampere Computing SMPro error monitor driver"
> > > > +	depends on MFD_SMPRO || COMPILE_TEST
> > > > +	help
> > > > +	  Say Y here to get support for the SMpro error monitor function
> > > > +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> > > > +	  loading, the driver creates sysfs files which can be use to gather
> > > > +	  multiple HW error data reported via read and write system calls.
> > > > +
> > > > +	  To compile this driver as a module, say M here. The driver will be
> > > > +	  called smpro-errmon.
> > > > +
> > > >   config CS5535_MFGPT
> > > >   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
> > > >   	depends on MFD_CS5535
> > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > > index 70e800e9127f..483308a6e113 100644
> > > > --- a/drivers/misc/Makefile
> > > > +++ b/drivers/misc/Makefile
> > > > @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
> > > >   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
> > > >   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
> > > >   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> > > > +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
> > > >   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
> > > >   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
> > > >   obj-$(CONFIG_HP_ILO)		+= hpilo.o
> > > > diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> > > > new file mode 100644
> > > > index 000000000000..df7d8fc4ff3f
> > > > --- /dev/null
> > > > +++ b/drivers/misc/smpro-errmon.c
> > > > @@ -0,0 +1,477 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > 
> > > Are you sure you mean "or any later version"?  I have to ask.
> > > 
> > 
> > Thank Greg for the review.
> > 
> > Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
> > version.
> 
> That is not what I am asking (the SPDX tag format).  I mean, do you
> really mean "or later" for your license as that is not the license of
> the kernel overall?  If so, wonderful, but I have to ask that as your
> legal group needs to be aware of it, sorry.

Generally speaking we should be sticking with the standard license for projects
we engage with, in this case "GPL-2.0".

Quan, unless you have heard differently or have a specific reason to include the
"+", please drop from the next version. If you do feel the "+" is required,
let's have an internal conversation about that.

Apologies for missing that in earlier reviews.

Thanks,

-- 
Darren Hart
Ampere Computing / OS and Kernel

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22 17:07           ` Darren Hart
  0 siblings, 0 replies; 44+ messages in thread
From: Darren Hart @ 2022-04-22 17:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring, Quan Nguyen,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On Fri, Apr 22, 2022 at 04:57:52PM +0200, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
> > On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> > > On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
> > > > This commit adds Ampere's SMpro error monitor driver for monitoring
> > > > and reporting RAS-related errors as reported by SMpro co-processor
> > > > found on Ampere's Altra processor family.
> > > > 
> > > > Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> > > > ---
> > > > Changes in v8:
> > > >    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
> > > >    + Avoid uninitialized variable use               [kernel test robot]
> > > >    + Switch to use sysfs_emit()                                  [Greg]
> > > >    + Make sysfs to return single value                           [Greg]
> > > >    + Change errors_* sysfs to error_*                            [Quan]
> > > >    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
> > > >    overflow status of each type of HW errors                     [Quan]
> > > >    + Add some minor refactor                                     [Quan]
> > > > 
> > > > Changes in v7:
> > > >    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
> > > >    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
> > > >    + Validate number of errors before read                       [Quan]
> > > >    + Fix wrong return type of *_show() function     [kernel test robot]
> > > >    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
> > > >    + Use pointer instead of stack memory                         [Quan]
> > > > 
> > > > Changes in v6:
> > > >    + First introduced in v6 [Quan]
> > > > 
> > > >   drivers/misc/Kconfig        |  12 +
> > > >   drivers/misc/Makefile       |   1 +
> > > >   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
> > > >   3 files changed, 490 insertions(+)
> > > >   create mode 100644 drivers/misc/smpro-errmon.c
> > > > 
> > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > > index 41d2bb0ae23a..9fbe6797c440 100644
> > > > --- a/drivers/misc/Kconfig
> > > > +++ b/drivers/misc/Kconfig
> > > > @@ -176,6 +176,18 @@ config SGI_XP
> > > >   	  this feature will allow for direct communication between SSIs
> > > >   	  based on a network adapter and DMA messaging.
> > > > +config SMPRO_ERRMON
> > > > +	tristate "Ampere Computing SMPro error monitor driver"
> > > > +	depends on MFD_SMPRO || COMPILE_TEST
> > > > +	help
> > > > +	  Say Y here to get support for the SMpro error monitor function
> > > > +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
> > > > +	  loading, the driver creates sysfs files which can be use to gather
> > > > +	  multiple HW error data reported via read and write system calls.
> > > > +
> > > > +	  To compile this driver as a module, say M here. The driver will be
> > > > +	  called smpro-errmon.
> > > > +
> > > >   config CS5535_MFGPT
> > > >   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
> > > >   	depends on MFD_CS5535
> > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > > index 70e800e9127f..483308a6e113 100644
> > > > --- a/drivers/misc/Makefile
> > > > +++ b/drivers/misc/Makefile
> > > > @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
> > > >   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
> > > >   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
> > > >   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
> > > > +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
> > > >   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
> > > >   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
> > > >   obj-$(CONFIG_HP_ILO)		+= hpilo.o
> > > > diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
> > > > new file mode 100644
> > > > index 000000000000..df7d8fc4ff3f
> > > > --- /dev/null
> > > > +++ b/drivers/misc/smpro-errmon.c
> > > > @@ -0,0 +1,477 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > 
> > > Are you sure you mean "or any later version"?  I have to ask.
> > > 
> > 
> > Thank Greg for the review.
> > 
> > Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
> > version.
> 
> That is not what I am asking (the SPDX tag format).  I mean, do you
> really mean "or later" for your license as that is not the license of
> the kernel overall?  If so, wonderful, but I have to ask that as your
> legal group needs to be aware of it, sorry.

Generally speaking we should be sticking with the standard license for projects
we engage with, in this case "GPL-2.0".

Quan, unless you have heard differently or have a specific reason to include the
"+", please drop from the next version. If you do feel the "+" is required,
let's have an internal conversation about that.

Apologies for missing that in earlier reviews.

Thanks,

-- 
Darren Hart
Ampere Computing / OS and Kernel

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  2022-04-22  2:46   ` Quan Nguyen
@ 2022-04-22 21:19     ` kernel test robot
  -1 siblings, 0 replies; 44+ messages in thread
From: kernel test robot @ 2022-04-22 21:19 UTC (permalink / raw)
  To: Quan Nguyen, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Derek Kiernan,
	Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: llvm, kbuild-all, Open Source Submission, Phong Vo, Thang Q . Nguyen

Hi Quan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on groeck-staging/hwmon-next lee-mfd/for-mfd-next v5.18-rc3 next-20220422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Quan-Nguyen/Add-Ampere-s-Altra-SMPro-MFD-and-its-child-drivers/20220422-105732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git c50c29a806113614098efd8da9fd7b48d605ba45
config: arm-randconfig-r004-20220422 (https://download.01.org/0day-ci/archive/20220423/202204230554.4528TqPu-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5bd87350a5ae429baf8f373cb226a57b62f87280)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/09ec873f0dd4611cb2df0150923d8906b9c5b2d1
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Quan-Nguyen/Add-Ampere-s-Altra-SMPro-MFD-and-its-child-drivers/20220422-105732
        git checkout 09ec873f0dd4611cb2df0150923d8906b9c5b2d1
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash arch/arm/mach-at91/ drivers/hwmon/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/hwmon/smpro-hwmon.c:376:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
                   default:
                   ^
   drivers/hwmon/smpro-hwmon.c:376:3: note: insert 'break;' to avoid fall-through
                   default:
                   ^
                   break; 
   1 warning generated.


vim +376 drivers/hwmon/smpro-hwmon.c

e1354080fc83378 Quan Nguyen 2022-04-22  359  
e1354080fc83378 Quan Nguyen 2022-04-22  360  static umode_t smpro_is_visible(const void *data, enum hwmon_sensor_types type,
e1354080fc83378 Quan Nguyen 2022-04-22  361  				u32 attr, int channel)
e1354080fc83378 Quan Nguyen 2022-04-22  362  {
e1354080fc83378 Quan Nguyen 2022-04-22  363  	const struct smpro_hwmon *hwmon = data;
e1354080fc83378 Quan Nguyen 2022-04-22  364  	unsigned int value;
e1354080fc83378 Quan Nguyen 2022-04-22  365  	int ret;
e1354080fc83378 Quan Nguyen 2022-04-22  366  
e1354080fc83378 Quan Nguyen 2022-04-22  367  	switch (type) {
e1354080fc83378 Quan Nguyen 2022-04-22  368  	case hwmon_temp:
e1354080fc83378 Quan Nguyen 2022-04-22  369  		switch (attr) {
e1354080fc83378 Quan Nguyen 2022-04-22  370  		case hwmon_temp_input:
e1354080fc83378 Quan Nguyen 2022-04-22  371  		case hwmon_temp_label:
e1354080fc83378 Quan Nguyen 2022-04-22  372  		case hwmon_temp_crit:
e1354080fc83378 Quan Nguyen 2022-04-22  373  			ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
e1354080fc83378 Quan Nguyen 2022-04-22  374  			if (ret || value == 0xFFFF)
e1354080fc83378 Quan Nguyen 2022-04-22  375  				return 0;
e1354080fc83378 Quan Nguyen 2022-04-22 @376  		default:
e1354080fc83378 Quan Nguyen 2022-04-22  377  			break;
e1354080fc83378 Quan Nguyen 2022-04-22  378  		}
e1354080fc83378 Quan Nguyen 2022-04-22  379  		break;
e1354080fc83378 Quan Nguyen 2022-04-22  380  	default:
e1354080fc83378 Quan Nguyen 2022-04-22  381  		break;
e1354080fc83378 Quan Nguyen 2022-04-22  382  	}
e1354080fc83378 Quan Nguyen 2022-04-22  383  
e1354080fc83378 Quan Nguyen 2022-04-22  384  	return 0444;
e1354080fc83378 Quan Nguyen 2022-04-22  385  }
e1354080fc83378 Quan Nguyen 2022-04-22  386  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
@ 2022-04-22 21:19     ` kernel test robot
  0 siblings, 0 replies; 44+ messages in thread
From: kernel test robot @ 2022-04-22 21:19 UTC (permalink / raw)
  To: Quan Nguyen, Lee Jones, Rob Herring, Krzysztof Kozlowski,
	Jean Delvare, Guenter Roeck, Jonathan Corbet, Derek Kiernan,
	Dragan Cvetic, Arnd Bergmann, Greg Kroah-Hartman, Thu Nguyen,
	linux-kernel, devicetree, linux-hwmon, linux-doc,
	OpenBMC Maillist
  Cc: Open Source Submission, llvm, kbuild-all, Phong Vo, Thang Q . Nguyen

Hi Quan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on groeck-staging/hwmon-next lee-mfd/for-mfd-next v5.18-rc3 next-20220422]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Quan-Nguyen/Add-Ampere-s-Altra-SMPro-MFD-and-its-child-drivers/20220422-105732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git c50c29a806113614098efd8da9fd7b48d605ba45
config: arm-randconfig-r004-20220422 (https://download.01.org/0day-ci/archive/20220423/202204230554.4528TqPu-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5bd87350a5ae429baf8f373cb226a57b62f87280)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/09ec873f0dd4611cb2df0150923d8906b9c5b2d1
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Quan-Nguyen/Add-Ampere-s-Altra-SMPro-MFD-and-its-child-drivers/20220422-105732
        git checkout 09ec873f0dd4611cb2df0150923d8906b9c5b2d1
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash arch/arm/mach-at91/ drivers/hwmon/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/hwmon/smpro-hwmon.c:376:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
                   default:
                   ^
   drivers/hwmon/smpro-hwmon.c:376:3: note: insert 'break;' to avoid fall-through
                   default:
                   ^
                   break; 
   1 warning generated.


vim +376 drivers/hwmon/smpro-hwmon.c

e1354080fc83378 Quan Nguyen 2022-04-22  359  
e1354080fc83378 Quan Nguyen 2022-04-22  360  static umode_t smpro_is_visible(const void *data, enum hwmon_sensor_types type,
e1354080fc83378 Quan Nguyen 2022-04-22  361  				u32 attr, int channel)
e1354080fc83378 Quan Nguyen 2022-04-22  362  {
e1354080fc83378 Quan Nguyen 2022-04-22  363  	const struct smpro_hwmon *hwmon = data;
e1354080fc83378 Quan Nguyen 2022-04-22  364  	unsigned int value;
e1354080fc83378 Quan Nguyen 2022-04-22  365  	int ret;
e1354080fc83378 Quan Nguyen 2022-04-22  366  
e1354080fc83378 Quan Nguyen 2022-04-22  367  	switch (type) {
e1354080fc83378 Quan Nguyen 2022-04-22  368  	case hwmon_temp:
e1354080fc83378 Quan Nguyen 2022-04-22  369  		switch (attr) {
e1354080fc83378 Quan Nguyen 2022-04-22  370  		case hwmon_temp_input:
e1354080fc83378 Quan Nguyen 2022-04-22  371  		case hwmon_temp_label:
e1354080fc83378 Quan Nguyen 2022-04-22  372  		case hwmon_temp_crit:
e1354080fc83378 Quan Nguyen 2022-04-22  373  			ret = regmap_read(hwmon->regmap, temperature[channel].reg, &value);
e1354080fc83378 Quan Nguyen 2022-04-22  374  			if (ret || value == 0xFFFF)
e1354080fc83378 Quan Nguyen 2022-04-22  375  				return 0;
e1354080fc83378 Quan Nguyen 2022-04-22 @376  		default:
e1354080fc83378 Quan Nguyen 2022-04-22  377  			break;
e1354080fc83378 Quan Nguyen 2022-04-22  378  		}
e1354080fc83378 Quan Nguyen 2022-04-22  379  		break;
e1354080fc83378 Quan Nguyen 2022-04-22  380  	default:
e1354080fc83378 Quan Nguyen 2022-04-22  381  		break;
e1354080fc83378 Quan Nguyen 2022-04-22  382  	}
e1354080fc83378 Quan Nguyen 2022-04-22  383  
e1354080fc83378 Quan Nguyen 2022-04-22  384  	return 0444;
e1354080fc83378 Quan Nguyen 2022-04-22  385  }
e1354080fc83378 Quan Nguyen 2022-04-22  386  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22 14:57         ` Greg Kroah-Hartman
@ 2022-04-22 23:21           ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22 23:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck



On 22/04/2022 21:57, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
>> On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
>>> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>>>> This commit adds Ampere's SMpro error monitor driver for monitoring
>>>> and reporting RAS-related errors as reported by SMpro co-processor
>>>> found on Ampere's Altra processor family.
>>>>
>>>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>>>> ---
>>>> Changes in v8:
>>>>     + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>>>     + Avoid uninitialized variable use               [kernel test robot]
>>>>     + Switch to use sysfs_emit()                                  [Greg]
>>>>     + Make sysfs to return single value                           [Greg]
>>>>     + Change errors_* sysfs to error_*                            [Quan]
>>>>     + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>>>     overflow status of each type of HW errors                     [Quan]
>>>>     + Add some minor refactor                                     [Quan]
>>>>
>>>> Changes in v7:
>>>>     + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>>>     + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>>>     + Validate number of errors before read                       [Quan]
>>>>     + Fix wrong return type of *_show() function     [kernel test robot]
>>>>     + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>>>     + Use pointer instead of stack memory                         [Quan]
>>>>
>>>> Changes in v6:
>>>>     + First introduced in v6 [Quan]
>>>>
>>>>    drivers/misc/Kconfig        |  12 +
>>>>    drivers/misc/Makefile       |   1 +
>>>>    drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>>>    3 files changed, 490 insertions(+)
>>>>    create mode 100644 drivers/misc/smpro-errmon.c
>>>>
>>>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>>>> index 41d2bb0ae23a..9fbe6797c440 100644
>>>> --- a/drivers/misc/Kconfig
>>>> +++ b/drivers/misc/Kconfig
>>>> @@ -176,6 +176,18 @@ config SGI_XP
>>>>    	  this feature will allow for direct communication between SSIs
>>>>    	  based on a network adapter and DMA messaging.
>>>> +config SMPRO_ERRMON
>>>> +	tristate "Ampere Computing SMPro error monitor driver"
>>>> +	depends on MFD_SMPRO || COMPILE_TEST
>>>> +	help
>>>> +	  Say Y here to get support for the SMpro error monitor function
>>>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>>>> +	  loading, the driver creates sysfs files which can be use to gather
>>>> +	  multiple HW error data reported via read and write system calls.
>>>> +
>>>> +	  To compile this driver as a module, say M here. The driver will be
>>>> +	  called smpro-errmon.
>>>> +
>>>>    config CS5535_MFGPT
>>>>    	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>>>    	depends on MFD_CS5535
>>>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>>>> index 70e800e9127f..483308a6e113 100644
>>>> --- a/drivers/misc/Makefile
>>>> +++ b/drivers/misc/Makefile
>>>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>>>    obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>>>    obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>>>    obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>>>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>>>    obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>>>    obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>>>    obj-$(CONFIG_HP_ILO)		+= hpilo.o
>>>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>>>> new file mode 100644
>>>> index 000000000000..df7d8fc4ff3f
>>>> --- /dev/null
>>>> +++ b/drivers/misc/smpro-errmon.c
>>>> @@ -0,0 +1,477 @@
>>>> +// SPDX-License-Identifier: GPL-2.0+
>>>
>>> Are you sure you mean "or any later version"?  I have to ask.
>>>
>>
>> Thank Greg for the review.
>>
>> Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
>> version.
> 
> That is not what I am asking (the SPDX tag format).  I mean, do you
> really mean "or later" for your license as that is not the license of
> the kernel overall?  If so, wonderful, but I have to ask that as your
> legal group needs to be aware of it, sorry.
> 

Dear Greg,

My sincere thanks for bringing this up. This would need help from our 
legal team to recheck/review and will make appropriate change in my next 
version.

- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-04-22 23:21           ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-04-22 23:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen



On 22/04/2022 21:57, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:43:39PM +0700, Quan Nguyen wrote:
>> On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
>>> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>>>> This commit adds Ampere's SMpro error monitor driver for monitoring
>>>> and reporting RAS-related errors as reported by SMpro co-processor
>>>> found on Ampere's Altra processor family.
>>>>
>>>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>>>> ---
>>>> Changes in v8:
>>>>     + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>>>     + Avoid uninitialized variable use               [kernel test robot]
>>>>     + Switch to use sysfs_emit()                                  [Greg]
>>>>     + Make sysfs to return single value                           [Greg]
>>>>     + Change errors_* sysfs to error_*                            [Quan]
>>>>     + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>>>     overflow status of each type of HW errors                     [Quan]
>>>>     + Add some minor refactor                                     [Quan]
>>>>
>>>> Changes in v7:
>>>>     + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>>>     + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>>>     + Validate number of errors before read                       [Quan]
>>>>     + Fix wrong return type of *_show() function     [kernel test robot]
>>>>     + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>>>     + Use pointer instead of stack memory                         [Quan]
>>>>
>>>> Changes in v6:
>>>>     + First introduced in v6 [Quan]
>>>>
>>>>    drivers/misc/Kconfig        |  12 +
>>>>    drivers/misc/Makefile       |   1 +
>>>>    drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>>>    3 files changed, 490 insertions(+)
>>>>    create mode 100644 drivers/misc/smpro-errmon.c
>>>>
>>>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>>>> index 41d2bb0ae23a..9fbe6797c440 100644
>>>> --- a/drivers/misc/Kconfig
>>>> +++ b/drivers/misc/Kconfig
>>>> @@ -176,6 +176,18 @@ config SGI_XP
>>>>    	  this feature will allow for direct communication between SSIs
>>>>    	  based on a network adapter and DMA messaging.
>>>> +config SMPRO_ERRMON
>>>> +	tristate "Ampere Computing SMPro error monitor driver"
>>>> +	depends on MFD_SMPRO || COMPILE_TEST
>>>> +	help
>>>> +	  Say Y here to get support for the SMpro error monitor function
>>>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>>>> +	  loading, the driver creates sysfs files which can be use to gather
>>>> +	  multiple HW error data reported via read and write system calls.
>>>> +
>>>> +	  To compile this driver as a module, say M here. The driver will be
>>>> +	  called smpro-errmon.
>>>> +
>>>>    config CS5535_MFGPT
>>>>    	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>>>    	depends on MFD_CS5535
>>>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>>>> index 70e800e9127f..483308a6e113 100644
>>>> --- a/drivers/misc/Makefile
>>>> +++ b/drivers/misc/Makefile
>>>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>>>    obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>>>    obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>>>    obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>>>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>>>    obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>>>    obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>>>    obj-$(CONFIG_HP_ILO)		+= hpilo.o
>>>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>>>> new file mode 100644
>>>> index 000000000000..df7d8fc4ff3f
>>>> --- /dev/null
>>>> +++ b/drivers/misc/smpro-errmon.c
>>>> @@ -0,0 +1,477 @@
>>>> +// SPDX-License-Identifier: GPL-2.0+
>>>
>>> Are you sure you mean "or any later version"?  I have to ask.
>>>
>>
>> Thank Greg for the review.
>>
>> Will change all to SPDX-License-Identifier: GPL-2.0-or-later in next
>> version.
> 
> That is not what I am asking (the SPDX tag format).  I mean, do you
> really mean "or later" for your license as that is not the license of
> the kernel overall?  If so, wonderful, but I have to ask that as your
> legal group needs to be aware of it, sorry.
> 

Dear Greg,

My sincere thanks for bringing this up. This would need help from our 
legal team to recheck/review and will make appropriate change in my next 
version.

- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-04-22  6:20     ` Greg Kroah-Hartman
@ 2022-06-01  8:21       ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-01  8:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>> This commit adds Ampere's SMpro error monitor driver for monitoring
>> and reporting RAS-related errors as reported by SMpro co-processor
>> found on Ampere's Altra processor family.
>>
>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>> ---
>> Changes in v8:
>>    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>    + Avoid uninitialized variable use               [kernel test robot]
>>    + Switch to use sysfs_emit()                                  [Greg]
>>    + Make sysfs to return single value                           [Greg]
>>    + Change errors_* sysfs to error_*                            [Quan]
>>    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>    overflow status of each type of HW errors                     [Quan]
>>    + Add some minor refactor                                     [Quan]
>>
>> Changes in v7:
>>    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>    + Validate number of errors before read                       [Quan]
>>    + Fix wrong return type of *_show() function     [kernel test robot]
>>    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>    + Use pointer instead of stack memory                         [Quan]
>>
>> Changes in v6:
>>    + First introduced in v6 [Quan]
>>
>>   drivers/misc/Kconfig        |  12 +
>>   drivers/misc/Makefile       |   1 +
>>   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>   3 files changed, 490 insertions(+)
>>   create mode 100644 drivers/misc/smpro-errmon.c
>>
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 41d2bb0ae23a..9fbe6797c440 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -176,6 +176,18 @@ config SGI_XP
>>   	  this feature will allow for direct communication between SSIs
>>   	  based on a network adapter and DMA messaging.
>>   
>> +config SMPRO_ERRMON
>> +	tristate "Ampere Computing SMPro error monitor driver"
>> +	depends on MFD_SMPRO || COMPILE_TEST
>> +	help
>> +	  Say Y here to get support for the SMpro error monitor function
>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>> +	  loading, the driver creates sysfs files which can be use to gather
>> +	  multiple HW error data reported via read and write system calls.
>> +
>> +	  To compile this driver as a module, say M here. The driver will be
>> +	  called smpro-errmon.
>> +
>>   config CS5535_MFGPT
>>   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>   	depends on MFD_CS5535
>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>> index 70e800e9127f..483308a6e113 100644
>> --- a/drivers/misc/Makefile
>> +++ b/drivers/misc/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>   obj-$(CONFIG_HP_ILO)		+= hpilo.o
>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>> new file mode 100644
>> index 000000000000..df7d8fc4ff3f
>> --- /dev/null
>> +++ b/drivers/misc/smpro-errmon.c
>> @@ -0,0 +1,477 @@
>> +// SPDX-License-Identifier: GPL-2.0+
> 
> Are you sure you mean "or any later version"?  I have to ask.
> 
>> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
>> +	{
>> +	 ERR_SMPRO_TYPE,
>> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
>> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
>> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
>> +	},
>> +	{
>> +	 ERR_PMPRO_TYPE,
>> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
>> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
>> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
>> +	},
> 
> Odd indentation, checkpatch did not complain?
> 
>> +static ssize_t smpro_event_data_read(struct device *dev,
>> +				     struct device_attribute *da, char *buf,
>> +				     int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	s32 event_data;
>> +	int ret;
>> +
>> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
>> +	if (ret)
>> +		goto done;
> 
> Just return the error here.
> 
>> +
>> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
> 
> sysfs rules are one value per file.  You know this.
> 
>> +	/* Clear event after read */
>> +	if (event_data != 0)
> 
> Why would it be 0?  Isn't 0 a valid value?
> 
> 
>> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
>> +done:
>> +	return ret;
>> +}
>> +
>> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
>> +					char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/* Bit 8 indicates the overflow status */
>> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
>> +}
>> +
>> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
>> +				     char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count, err_length;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	/* Error count is the low byte */
>> +	err_count &= 0xff;
>> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
>> +		goto done;
> 
> Just return the error.
> 
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
>> +	if (ret || err_length <= 0)
>> +		goto done;
> 
> return the error.
> 
> Wait, you could return 0 here, are you sure about that?
> 
>> +
>> +	if (err_length > MAX_READ_BLOCK_LENGTH)
>> +		err_length = MAX_READ_BLOCK_LENGTH;
>> +
>> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
>> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
>> +	if (ret < 0)
>> +		goto done;
> 
> return the error, no need for a goto in this function.
> 
>> +
>> +	/*
>> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
>> +	 * <Error Type><Error SubType><Instance><Error Status>\
>> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
>> +	 * Where:
>> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
>> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
>> +	 *  + Instance: Combination of the socket, channel,
>> +	 *    slot cause the error. (2 bytes)
>> +	 *  + Error Status: Encode of error status. (4 bytes)
>> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
>> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
>> +	 * Reference Altra SOC BMC Interface specification.
>> +	 */
>> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
>> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
>> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
>> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
>> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
>> +
>> +	/* go to next error */
>> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +/*
>> + * Output format:
>> + * <errType><image><dir><Location><errorCode><data>
>> + * Where:
>> + *   + errType: SCP Error Type (3 bits)
>> + *      1: Warning
>> + *      2: Error
>> + *      4: Error with data
>> + *   + image: SCP Image Code (8 bits)
>> + *   + dir: Direction (1 bit)
>> + *      0: Enter
>> + *      1: Exit
>> + *   + location: SCP Module Location Code (8 bits)
>> + *   + errorCode: SCP Error Code (16 bits)
>> + *   + data : Extensive data (32 bits)
>> + *      All bits are 0 when errType is warning or error.
>> + */
>> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
>> +				       char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_int_error_hdr *err_info;
>> +	unsigned int data_lo = 0, data_hi = 0;
>> +	unsigned int ret_hi, ret_lo;
>> +	unsigned int err_type;
>> +	unsigned int value;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	/* read error status */
>> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
>> +	if (ret)
>> +		goto done;
> 
> Same mess here, just return the error.
> 
>> +
>> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
>> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
>> +		goto done;
> 
> No error?  Are you sure?
> 
>> +
>> +	err_info = &list_smpro_int_error_hdr[channel];
>> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
>> +	if (ret)
>> +		goto done;
>> +
>> +	if (err_type & BIT(2)) {
>> +		/* Error with data type */
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>> +		if (ret)
>> +			goto done;
>> +
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>> +		if (ret)
>> +			goto done;
>> +
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>> +
>> +	} else if (err_type & BIT(1)) {
>> +		/* Error type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>> +
>> +	} else if (err_type & BIT(0)) {
>> +		/* Warning type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);

Hi Greg,

Since the internal representation of the internal error is split into 
high low chunks of the info and data values which need to be 
communicated atomicly, I'm treating them as "one value" here. I could 
dump them in a temporary array and print that, but it seems like 
additional complexity for the same result. Can we consider this 
concatenated encoding as "an array of the same type" for the purposes of 
this driver?"

Thanks,
- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-06-01  8:21       ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-01  8:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On 22/04/2022 13:20, Greg Kroah-Hartman wrote:
> On Fri, Apr 22, 2022 at 09:46:47AM +0700, Quan Nguyen wrote:
>> This commit adds Ampere's SMpro error monitor driver for monitoring
>> and reporting RAS-related errors as reported by SMpro co-processor
>> found on Ampere's Altra processor family.
>>
>> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
>> ---
>> Changes in v8:
>>    + Update wording for SMPRO_ERRMON on Kconfig file             [Quan]
>>    + Avoid uninitialized variable use               [kernel test robot]
>>    + Switch to use sysfs_emit()                                  [Greg]
>>    + Make sysfs to return single value                           [Greg]
>>    + Change errors_* sysfs to error_*                            [Quan]
>>    + Add overflow_[core|mem|pcie|other]_[ce|ue] sysfs to report
>>    overflow status of each type of HW errors                     [Quan]
>>    + Add some minor refactor                                     [Quan]
>>
>> Changes in v7:
>>    + Remove regmap_acquire/release_lock(), read_i2c_block_data() [Quan]
>>    + Use regmap_noinc_read() instead of errmon_read_block()      [Quan]
>>    + Validate number of errors before read                       [Quan]
>>    + Fix wrong return type of *_show() function     [kernel test robot]
>>    + Adjust patch order to avoid dependence with smpro-mfd  [Lee Jones]
>>    + Use pointer instead of stack memory                         [Quan]
>>
>> Changes in v6:
>>    + First introduced in v6 [Quan]
>>
>>   drivers/misc/Kconfig        |  12 +
>>   drivers/misc/Makefile       |   1 +
>>   drivers/misc/smpro-errmon.c | 477 ++++++++++++++++++++++++++++++++++++
>>   3 files changed, 490 insertions(+)
>>   create mode 100644 drivers/misc/smpro-errmon.c
>>
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 41d2bb0ae23a..9fbe6797c440 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -176,6 +176,18 @@ config SGI_XP
>>   	  this feature will allow for direct communication between SSIs
>>   	  based on a network adapter and DMA messaging.
>>   
>> +config SMPRO_ERRMON
>> +	tristate "Ampere Computing SMPro error monitor driver"
>> +	depends on MFD_SMPRO || COMPILE_TEST
>> +	help
>> +	  Say Y here to get support for the SMpro error monitor function
>> +	  provided by Ampere Computing's Altra and Altra Max SoCs. Upon
>> +	  loading, the driver creates sysfs files which can be use to gather
>> +	  multiple HW error data reported via read and write system calls.
>> +
>> +	  To compile this driver as a module, say M here. The driver will be
>> +	  called smpro-errmon.
>> +
>>   config CS5535_MFGPT
>>   	tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support"
>>   	depends on MFD_CS5535
>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>> index 70e800e9127f..483308a6e113 100644
>> --- a/drivers/misc/Makefile
>> +++ b/drivers/misc/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
>>   obj-$(CONFIG_KGDB_TESTS)	+= kgdbts.o
>>   obj-$(CONFIG_SGI_XP)		+= sgi-xp/
>>   obj-$(CONFIG_SGI_GRU)		+= sgi-gru/
>> +obj-$(CONFIG_SMPRO_ERRMON)	+= smpro-errmon.o
>>   obj-$(CONFIG_CS5535_MFGPT)	+= cs5535-mfgpt.o
>>   obj-$(CONFIG_GEHC_ACHC)		+= gehc-achc.o
>>   obj-$(CONFIG_HP_ILO)		+= hpilo.o
>> diff --git a/drivers/misc/smpro-errmon.c b/drivers/misc/smpro-errmon.c
>> new file mode 100644
>> index 000000000000..df7d8fc4ff3f
>> --- /dev/null
>> +++ b/drivers/misc/smpro-errmon.c
>> @@ -0,0 +1,477 @@
>> +// SPDX-License-Identifier: GPL-2.0+
> 
> Are you sure you mean "or any later version"?  I have to ask.
> 
>> +static struct smpro_int_error_hdr list_smpro_int_error_hdr[2] = {
>> +	{
>> +	 ERR_SMPRO_TYPE,
>> +	 ERR_SMPRO_INFO_LO, ERR_SMPRO_INFO_HI,
>> +	 ERR_SMPRO_DATA_LO, ERR_SMPRO_DATA_HI,
>> +	 WARN_SMPRO_INFO_LO, WARN_SMPRO_INFO_HI
>> +	},
>> +	{
>> +	 ERR_PMPRO_TYPE,
>> +	 ERR_PMPRO_INFO_LO, ERR_PMPRO_INFO_HI,
>> +	 ERR_PMPRO_DATA_LO, ERR_PMPRO_DATA_HI,
>> +	 WARN_PMPRO_INFO_LO, WARN_PMPRO_INFO_HI
>> +	},
> 
> Odd indentation, checkpatch did not complain?
> 
>> +static ssize_t smpro_event_data_read(struct device *dev,
>> +				     struct device_attribute *da, char *buf,
>> +				     int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	s32 event_data;
>> +	int ret;
>> +
>> +	ret = regmap_read(errmon->regmap, smpro_event_table[channel], &event_data);
>> +	if (ret)
>> +		goto done;
> 
> Just return the error here.
> 
>> +
>> +	ret = sysfs_emit(buf, "%02x%04x\n", channel, event_data);
> 
> sysfs rules are one value per file.  You know this.
> 
>> +	/* Clear event after read */
>> +	if (event_data != 0)
> 
> Why would it be 0?  Isn't 0 a valid value?
> 
> 
>> +		regmap_write(errmon->regmap, smpro_event_table[channel], event_data);
>> +done:
>> +	return ret;
>> +}
>> +
>> +static ssize_t smpro_overflow_data_read(struct device *dev, struct device_attribute *da,
>> +					char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/* Bit 8 indicates the overflow status */
>> +	return sysfs_emit(buf, "%d\n", (err_count & BIT(8)) ? 1 : 0);
>> +}
>> +
>> +static ssize_t smpro_error_data_read(struct device *dev, struct device_attribute *da,
>> +				     char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	unsigned char err_data[MAX_READ_BLOCK_LENGTH];
>> +	struct smpro_error_hdr *err_info;
>> +	s32 err_count, err_length;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	err_info = &smpro_error_table[channel];
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_count, &err_count);
>> +	/* Error count is the low byte */
>> +	err_count &= 0xff;
>> +	if (ret || !err_count || err_count > err_info->max_err_cnt)
>> +		goto done;
> 
> Just return the error.
> 
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_len, &err_length);
>> +	if (ret || err_length <= 0)
>> +		goto done;
> 
> return the error.
> 
> Wait, you could return 0 here, are you sure about that?
> 
>> +
>> +	if (err_length > MAX_READ_BLOCK_LENGTH)
>> +		err_length = MAX_READ_BLOCK_LENGTH;
>> +
>> +	memset(err_data, 0x00, MAX_READ_BLOCK_LENGTH);
>> +	ret = regmap_noinc_read(errmon->regmap, err_info->err_data, err_data, err_length);
>> +	if (ret < 0)
>> +		goto done;
> 
> return the error, no need for a goto in this function.
> 
>> +
>> +	/*
>> +	 * The output of Core/Memory/PCIe/Others UE/CE errors follows below format:
>> +	 * <Error Type><Error SubType><Instance><Error Status>\
>> +	 * <Error Address><Error Misc 0><Error Misc 1><Error Misc2><Error Misc 3>
>> +	 * Where:
>> +	 *  + Error Type: The hardwares cause the errors. (1 byte)
>> +	 *  + SubType: Sub type of error in the specified hardware error. (1 byte)
>> +	 *  + Instance: Combination of the socket, channel,
>> +	 *    slot cause the error. (2 bytes)
>> +	 *  + Error Status: Encode of error status. (4 bytes)
>> +	 *  + Error Address: The address in device causes the errors. (8 bytes)
>> +	 *  + Error Misc 0/1/2/3: Addition info about the errors. (8 bytes for each)
>> +	 * Reference Altra SOC BMC Interface specification.
>> +	 */
>> +	count = sysfs_emit(buf, "%02x%02x%04x%08x%016llx%016llx%016llx%016llx%016llx\n",
>> +			   err_data[0], err_data[1], *(u16 *)&err_data[2],
>> +			   *(u32 *)&err_data[4], *(u64 *)&err_data[8],
>> +			   *(u64 *)&err_data[16], *(u64 *)&err_data[24],
>> +			   *(u64 *)&err_data[32], *(u64 *)&err_data[40]);
>> +
>> +	/* go to next error */
>> +	ret = regmap_write(errmon->regmap, err_info->err_count, 0x100);
>> +done:
>> +	return ret ? ret : count;
>> +}
>> +
>> +/*
>> + * Output format:
>> + * <errType><image><dir><Location><errorCode><data>
>> + * Where:
>> + *   + errType: SCP Error Type (3 bits)
>> + *      1: Warning
>> + *      2: Error
>> + *      4: Error with data
>> + *   + image: SCP Image Code (8 bits)
>> + *   + dir: Direction (1 bit)
>> + *      0: Enter
>> + *      1: Exit
>> + *   + location: SCP Module Location Code (8 bits)
>> + *   + errorCode: SCP Error Code (16 bits)
>> + *   + data : Extensive data (32 bits)
>> + *      All bits are 0 when errType is warning or error.
>> + */
>> +static ssize_t smpro_internal_err_read(struct device *dev, struct device_attribute *da,
>> +				       char *buf, int channel)
>> +{
>> +	struct smpro_errmon *errmon = dev_get_drvdata(dev);
>> +	struct smpro_int_error_hdr *err_info;
>> +	unsigned int data_lo = 0, data_hi = 0;
>> +	unsigned int ret_hi, ret_lo;
>> +	unsigned int err_type;
>> +	unsigned int value;
>> +	int count = 0;
>> +	int ret;
>> +
>> +	/* read error status */
>> +	ret = regmap_read(errmon->regmap, GPI_RAS_ERR, &value);
>> +	if (ret)
>> +		goto done;
> 
> Same mess here, just return the error.
> 
>> +
>> +	if (!((channel == RAS_SMPRO_ERRS && (value & BIT(0))) ||
>> +	      (channel == RAS_PMPRO_ERRS && (value & BIT(1)))))
>> +		goto done;
> 
> No error?  Are you sure?
> 
>> +
>> +	err_info = &list_smpro_int_error_hdr[channel];
>> +	ret = regmap_read(errmon->regmap, err_info->err_type, &err_type);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_low, &ret_lo);
>> +	if (ret)
>> +		goto done;
>> +
>> +	ret = regmap_read(errmon->regmap, err_info->err_info_high, &ret_hi);
>> +	if (ret)
>> +		goto done;
>> +
>> +	if (err_type & BIT(2)) {
>> +		/* Error with data type */
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>> +		if (ret)
>> +			goto done;
>> +
>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>> +		if (ret)
>> +			goto done;
>> +
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>> +
>> +	} else if (err_type & BIT(1)) {
>> +		/* Error type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>> +		/* clear the read errors */
>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>> +
>> +	} else if (err_type & BIT(0)) {
>> +		/* Warning type */
>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);

Hi Greg,

Since the internal representation of the internal error is split into 
high low chunks of the info and data values which need to be 
communicated atomicly, I'm treating them as "one value" here. I could 
dump them in a temporary array and print that, but it seems like 
additional complexity for the same result. Can we consider this 
concatenated encoding as "an array of the same type" for the purposes of 
this driver?"

Thanks,
- Quan

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-06-01  8:21       ` Quan Nguyen
@ 2022-06-01  9:33         ` Greg Kroah-Hartman
  -1 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-06-01  9:33 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On Wed, Jun 01, 2022 at 03:21:47PM +0700, Quan Nguyen wrote:
> > > +	if (err_type & BIT(2)) {
> > > +		/* Error with data type */
> > > +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
> > > +		if (ret)
> > > +			goto done;
> > > +
> > > +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
> > > +		if (ret)
> > > +			goto done;
> > > +
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> > > +		/* clear the read errors */
> > > +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
> > > +
> > > +	} else if (err_type & BIT(1)) {
> > > +		/* Error type */
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> > > +		/* clear the read errors */
> > > +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
> > > +
> > > +	} else if (err_type & BIT(0)) {
> > > +		/* Warning type */
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> 
> Hi Greg,
> 
> Since the internal representation of the internal error is split into high
> low chunks of the info and data values which need to be communicated
> atomicly, I'm treating them as "one value" here.

That is a huge "one value", that's not what this really is, it needs to
be parsed by userspace, right?

And why does this have to be atomic?  What happens if the values change
right after you read them?  What is userspace going to do with them?

> I could dump them in a
> temporary array and print that, but it seems like additional complexity for
> the same result. Can we consider this concatenated encoding as "an array of
> the same type" for the purposes of this driver?"

That's really not a good idea as sysfs files should never need to be
"parsed" like this.

Again, what are you trying to do here, and why does it have to be
atomic?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-06-01  9:33         ` Greg Kroah-Hartman
  0 siblings, 0 replies; 44+ messages in thread
From: Greg Kroah-Hartman @ 2022-06-01  9:33 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On Wed, Jun 01, 2022 at 03:21:47PM +0700, Quan Nguyen wrote:
> > > +	if (err_type & BIT(2)) {
> > > +		/* Error with data type */
> > > +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
> > > +		if (ret)
> > > +			goto done;
> > > +
> > > +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
> > > +		if (ret)
> > > +			goto done;
> > > +
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> > > +		/* clear the read errors */
> > > +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
> > > +
> > > +	} else if (err_type & BIT(1)) {
> > > +		/* Error type */
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> > > +		/* clear the read errors */
> > > +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
> > > +
> > > +	} else if (err_type & BIT(0)) {
> > > +		/* Warning type */
> > > +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
> > > +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
> > > +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
> 
> Hi Greg,
> 
> Since the internal representation of the internal error is split into high
> low chunks of the info and data values which need to be communicated
> atomicly, I'm treating them as "one value" here.

That is a huge "one value", that's not what this really is, it needs to
be parsed by userspace, right?

And why does this have to be atomic?  What happens if the values change
right after you read them?  What is userspace going to do with them?

> I could dump them in a
> temporary array and print that, but it seems like additional complexity for
> the same result. Can we consider this concatenated encoding as "an array of
> the same type" for the purposes of this driver?"

That's really not a good idea as sysfs files should never need to be
"parsed" like this.

Again, what are you trying to do here, and why does it have to be
atomic?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
  2022-06-01  9:33         ` Greg Kroah-Hartman
@ 2022-06-02  9:36           ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-02  9:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Jean Delvare,
	Guenter Roeck, Jonathan Corbet, Derek Kiernan, Dragan Cvetic,
	Arnd Bergmann, Thu Nguyen, linux-kernel, devicetree, linux-hwmon,
	linux-doc, OpenBMC Maillist, Open Source Submission, Phong Vo,
	Thang Q . Nguyen

On 01/06/2022 16:33, Greg Kroah-Hartman wrote:
> On Wed, Jun 01, 2022 at 03:21:47PM +0700, Quan Nguyen wrote:
>>>> +	if (err_type & BIT(2)) {
>>>> +		/* Error with data type */
>>>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>>>> +		if (ret)
>>>> +			goto done;
>>>> +
>>>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>>>> +		if (ret)
>>>> +			goto done;
>>>> +
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>>> +		/* clear the read errors */
>>>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>>>> +
>>>> +	} else if (err_type & BIT(1)) {
>>>> +		/* Error type */
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>>> +		/* clear the read errors */
>>>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>>>> +
>>>> +	} else if (err_type & BIT(0)) {
>>>> +		/* Warning type */
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>
>> Hi Greg,
>>
>> Since the internal representation of the internal error is split into high
>> low chunks of the info and data values which need to be communicated
>> atomicly, I'm treating them as "one value" here.
> 
> That is a huge "one value", that's not what this really is, it needs to
> be parsed by userspace, right?
> 
Thanks Greg for the review,

User space needs all of this "one value" to know what exactly is the error.

In our latest version, we remove all the if...else and simplify the code 
as below:
/*
  * The internal representation of the internal error is split into high
  * low chunks of the info and data values. Rather than temporarily
  * dumping these into an array and printing that, skip the intermediate
  * step and print them using a concatenation encoding.
  */
count = sysfs_emit(buf, "%04x%04x%04x%04x\n", info_h, info_l, data_h, 
data_l);

/* clear the read error */
ret = regmap_write(errmon->regmap, err_info->type, err_type);
return ret ? ret : count;

> And why does this have to be atomic?  What happens if the values change
> right after you read them?  What is userspace going to do with them?
> 
Because the error is bigger than single register can hold so it is split 
into small chunks to report via multiple separate registers.

Firmware stores each error in a queue. As the error's chunks are stored 
in separate registers. All of these registers will need to be read out 
before the error is clear so that the next error in the queue can be 
reported. That is why we say those chunks must be read out atomically.

User space will need to parse these information themself.

>> I could dump them in a
>> temporary array and print that, but it seems like additional complexity for
>> the same result. Can we consider this concatenated encoding as "an array of
>> the same type" for the purposes of this driver?"
> 
> That's really not a good idea as sysfs files should never need to be
> "parsed" like this.
> > Again, what are you trying to do here, and why does it have to be
> atomic?
> 
> thanks,
> 
> greg k-h


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver
@ 2022-06-02  9:36           ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-02  9:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Dragan Cvetic, linux-doc, linux-kernel,
	Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Lee Jones, Thu Nguyen, Guenter Roeck

On 01/06/2022 16:33, Greg Kroah-Hartman wrote:
> On Wed, Jun 01, 2022 at 03:21:47PM +0700, Quan Nguyen wrote:
>>>> +	if (err_type & BIT(2)) {
>>>> +		/* Error with data type */
>>>> +		ret = regmap_read(errmon->regmap, err_info->err_data_low, &data_lo);
>>>> +		if (ret)
>>>> +			goto done;
>>>> +
>>>> +		ret = regmap_read(errmon->regmap, err_info->err_data_high, &data_hi);
>>>> +		if (ret)
>>>> +			goto done;
>>>> +
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   4, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>>> +		/* clear the read errors */
>>>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(2));
>>>> +
>>>> +	} else if (err_type & BIT(1)) {
>>>> +		/* Error type */
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   2, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>>> +		/* clear the read errors */
>>>> +		ret = regmap_write(errmon->regmap, err_info->err_type, BIT(1));
>>>> +
>>>> +	} else if (err_type & BIT(0)) {
>>>> +		/* Warning type */
>>>> +		count = sysfs_emit(buf, "%01x%02x%01x%02x%04x%04x%04x\n",
>>>> +				   1, (ret_hi & 0xf000) >> 12, (ret_hi & 0x0800) >> 11,
>>>> +				   ret_hi & 0xff, ret_lo, data_hi, data_lo);
>>
>> Hi Greg,
>>
>> Since the internal representation of the internal error is split into high
>> low chunks of the info and data values which need to be communicated
>> atomicly, I'm treating them as "one value" here.
> 
> That is a huge "one value", that's not what this really is, it needs to
> be parsed by userspace, right?
> 
Thanks Greg for the review,

User space needs all of this "one value" to know what exactly is the error.

In our latest version, we remove all the if...else and simplify the code 
as below:
/*
  * The internal representation of the internal error is split into high
  * low chunks of the info and data values. Rather than temporarily
  * dumping these into an array and printing that, skip the intermediate
  * step and print them using a concatenation encoding.
  */
count = sysfs_emit(buf, "%04x%04x%04x%04x\n", info_h, info_l, data_h, 
data_l);

/* clear the read error */
ret = regmap_write(errmon->regmap, err_info->type, err_type);
return ret ? ret : count;

> And why does this have to be atomic?  What happens if the values change
> right after you read them?  What is userspace going to do with them?
> 
Because the error is bigger than single register can hold so it is split 
into small chunks to report via multiple separate registers.

Firmware stores each error in a queue. As the error's chunks are stored 
in separate registers. All of these registers will need to be read out 
before the error is clear so that the next error in the queue can be 
reported. That is why we say those chunks must be read out atomically.

User space will need to parse these information themself.

>> I could dump them in a
>> temporary array and print that, but it seems like additional complexity for
>> the same result. Can we consider this concatenated encoding as "an array of
>> the same type" for the purposes of this driver?"
> 
> That's really not a good idea as sysfs files should never need to be
> "parsed" like this.
> > Again, what are you trying to do here, and why does it have to be
> atomic?
> 
> thanks,
> 
> greg k-h


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  2022-04-22  2:46   ` Quan Nguyen
@ 2022-06-15 22:14     ` Lee Jones
  -1 siblings, 0 replies; 44+ messages in thread
From: Lee Jones @ 2022-06-15 22:14 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: Rob Herring, Krzysztof Kozlowski, Jean Delvare, Guenter Roeck,
	Jonathan Corbet, Derek Kiernan, Dragan Cvetic, Arnd Bergmann,
	Greg Kroah-Hartman, Thu Nguyen, linux-kernel, devicetree,
	linux-hwmon, linux-doc, OpenBMC Maillist, Open Source Submission,
	Phong Vo, Thang Q . Nguyen

On Fri, 22 Apr 2022, Quan Nguyen wrote:

> Adds Multi-function devices driver for SMpro co-processor found on the

Please drop the term MFD and describe the device instead.

> Mt.Jade hardware reference platform with Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>   + None
> 
> Changes in v7:
>   + Smpro-mfd now significant changes in compare with simple-mfd-i2c
>     driver, remove the copyright note about simple-mfd-i2c    [Quan]
>   + Install bus->read/write()  to handle multiple types of bus
>     access.                                                   [Quan]
>   + Update license to MODULE_LICENSE("GPL")                   [Quan]
>   + Add others minor refactor the code                        [Quan]
> 
> Changes in v6:
>   + Update license part to reflect that this driver is clone from
>   simple-mfd-i2c driver [Quan]
> 
> Changes in v5:
>   + Dropped the use of simple-mfd-i2c driver [Quan]
>   + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
>   sub-devices. This is to avoid DT nodes without resource issue [Quan]
>   + Revised commit message [Quan]
> 
> Changes in v4:
>   + Add "depends on I2C" to fix build issue found by kernel test
>   robot [Guenter]
> 
> Changes in v3:
>   + None
> 
> Changes in v2:
>   + Used 'struct of_device_id's .data attribute [Lee Jones]
> 
>  drivers/mfd/Kconfig     |  12 ++++
>  drivers/mfd/Makefile    |   1 +
>  drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++

Please drop the 'mfd' part.  Does 'core' work instead?

>  3 files changed, 147 insertions(+)
>  create mode 100644 drivers/mfd/smpro-mfd.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 3b59456f5545..383d0e6cfb91 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
>  	help
>  	  Support for the AS3711 PMIC from AMS
>  
> +config MFD_SMPRO
> +	tristate "Ampere Computing MFD SMpro core driver"

Drop 'MFD'.

> +	depends on I2C
> +	select MFD_CORE
> +	select REGMAP_I2C
> +	help
> +	  Say yes here to enable SMpro driver support for Ampere's Altra
> +	  processor family.
> +
> +	  Ampere's Altra SMpro exposes an I2C regmap interface that can
> +	  be accessed by child devices.
> +
>  config MFD_AS3722
>  	tristate "ams AS3722 Power Management IC"
>  	select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 858cacf659d6..36f8981cc4fd 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
>  
>  obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
>  obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
>  obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
>  
>  obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..485c4f89ebd9
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C

Drop 'MFD' throughout.

> + * Copyright (c) 2022, Ampere Computing LLC
> + * Author: Quan Nguyen <quan@os.amperecomputing..com>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>

Alphabetical.

> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG     0x02
> +#define AMPERE_MANUFACTURER_ID  0xCD3A
> +
> +static int smpro_mfd_write(void *context, const void *data, size_t count)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	int ret;
> +
> +	ret = i2c_master_send(i2c, data, count);
> +	if (ret == count)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
> +static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
> +			  void *val, size_t val_size)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	struct i2c_msg xfer[2];
> +	unsigned char buf[2];
> +	int ret;
> +
> +	xfer[0].addr = i2c->addr;
> +	xfer[0].flags = 0;
> +
> +	buf[0] = *(u8 *)reg;
> +	buf[1] = val_size;
> +	xfer[0].len = 2;
> +	xfer[0].buf = buf;
> +
> +	xfer[1].addr = i2c->addr;
> +	xfer[1].flags = I2C_M_RD;
> +	xfer[1].len = val_size;
> +	xfer[1].buf = val;
> +
> +	ret = i2c_transfer(i2c->adapter, xfer, 2);
> +	if (ret == 2)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}

This looks all too familiar.

I wonder how generic these i2c call-backs actually are.

> +static const struct regmap_bus smpro_regmap_bus = {
> +	.read = smpro_mfd_read,
> +	.write = smpro_mfd_write,
> +	.val_format_endian_default = REGMAP_ENDIAN_BIG,
> +};
> +
> +static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
> +{
> +	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
> +		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);

No magic numbers.  Please define these registers.

> +}
> +
> +static const struct regmap_config smpro_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 16,
> +	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> +	MFD_CELL_NAME("smpro-hwmon"),
> +	MFD_CELL_NAME("smpro-errmon"),
> +	MFD_CELL_NAME("smpro-misc"),
> +};
> +
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> +	const struct regmap_config *config;
> +	struct regmap *regmap;
> +	unsigned int val;
> +	int ret;
> +
> +	config = device_get_match_data(&i2c->dev);
> +	if (!config)
> +		config = &smpro_regmap_config;

This use-case is not currently supported.

Please return an error instead.

> +	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
> +	/* Check for valid ID */

Decent #define nomenclature should render this comment superfluous.

> +	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> +	if (ret)
> +		return ret;
> +
> +	if (val != AMPERE_MANUFACTURER_ID)
> +		return -ENODEV;
> +
> +	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> +				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> +	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> +	.probe_new = smpro_mfd_probe,
> +	.driver = {
> +		.name = "smpro-mfd-i2c",

"smpro-core"

> +		.of_match_table = smpro_mfd_of_match,
> +	},
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL");

-- 
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
@ 2022-06-15 22:14     ` Lee Jones
  0 siblings, 0 replies; 44+ messages in thread
From: Lee Jones @ 2022-06-15 22:14 UTC (permalink / raw)
  To: Quan Nguyen
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Greg Kroah-Hartman, Dragan Cvetic, linux-doc,
	linux-kernel, Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Thu Nguyen, Guenter Roeck

On Fri, 22 Apr 2022, Quan Nguyen wrote:

> Adds Multi-function devices driver for SMpro co-processor found on the

Please drop the term MFD and describe the device instead.

> Mt.Jade hardware reference platform with Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>   + None
> 
> Changes in v7:
>   + Smpro-mfd now significant changes in compare with simple-mfd-i2c
>     driver, remove the copyright note about simple-mfd-i2c    [Quan]
>   + Install bus->read/write()  to handle multiple types of bus
>     access.                                                   [Quan]
>   + Update license to MODULE_LICENSE("GPL")                   [Quan]
>   + Add others minor refactor the code                        [Quan]
> 
> Changes in v6:
>   + Update license part to reflect that this driver is clone from
>   simple-mfd-i2c driver [Quan]
> 
> Changes in v5:
>   + Dropped the use of simple-mfd-i2c driver [Quan]
>   + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
>   sub-devices. This is to avoid DT nodes without resource issue [Quan]
>   + Revised commit message [Quan]
> 
> Changes in v4:
>   + Add "depends on I2C" to fix build issue found by kernel test
>   robot [Guenter]
> 
> Changes in v3:
>   + None
> 
> Changes in v2:
>   + Used 'struct of_device_id's .data attribute [Lee Jones]
> 
>  drivers/mfd/Kconfig     |  12 ++++
>  drivers/mfd/Makefile    |   1 +
>  drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++

Please drop the 'mfd' part.  Does 'core' work instead?

>  3 files changed, 147 insertions(+)
>  create mode 100644 drivers/mfd/smpro-mfd.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 3b59456f5545..383d0e6cfb91 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
>  	help
>  	  Support for the AS3711 PMIC from AMS
>  
> +config MFD_SMPRO
> +	tristate "Ampere Computing MFD SMpro core driver"

Drop 'MFD'.

> +	depends on I2C
> +	select MFD_CORE
> +	select REGMAP_I2C
> +	help
> +	  Say yes here to enable SMpro driver support for Ampere's Altra
> +	  processor family.
> +
> +	  Ampere's Altra SMpro exposes an I2C regmap interface that can
> +	  be accessed by child devices.
> +
>  config MFD_AS3722
>  	tristate "ams AS3722 Power Management IC"
>  	select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 858cacf659d6..36f8981cc4fd 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
>  
>  obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
>  obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
>  obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
>  
>  obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..485c4f89ebd9
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C

Drop 'MFD' throughout.

> + * Copyright (c) 2022, Ampere Computing LLC
> + * Author: Quan Nguyen <quan@os.amperecomputing..com>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>

Alphabetical.

> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG     0x02
> +#define AMPERE_MANUFACTURER_ID  0xCD3A
> +
> +static int smpro_mfd_write(void *context, const void *data, size_t count)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	int ret;
> +
> +	ret = i2c_master_send(i2c, data, count);
> +	if (ret == count)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
> +static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
> +			  void *val, size_t val_size)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	struct i2c_msg xfer[2];
> +	unsigned char buf[2];
> +	int ret;
> +
> +	xfer[0].addr = i2c->addr;
> +	xfer[0].flags = 0;
> +
> +	buf[0] = *(u8 *)reg;
> +	buf[1] = val_size;
> +	xfer[0].len = 2;
> +	xfer[0].buf = buf;
> +
> +	xfer[1].addr = i2c->addr;
> +	xfer[1].flags = I2C_M_RD;
> +	xfer[1].len = val_size;
> +	xfer[1].buf = val;
> +
> +	ret = i2c_transfer(i2c->adapter, xfer, 2);
> +	if (ret == 2)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}

This looks all too familiar.

I wonder how generic these i2c call-backs actually are.

> +static const struct regmap_bus smpro_regmap_bus = {
> +	.read = smpro_mfd_read,
> +	.write = smpro_mfd_write,
> +	.val_format_endian_default = REGMAP_ENDIAN_BIG,
> +};
> +
> +static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
> +{
> +	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
> +		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);

No magic numbers.  Please define these registers.

> +}
> +
> +static const struct regmap_config smpro_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 16,
> +	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> +	MFD_CELL_NAME("smpro-hwmon"),
> +	MFD_CELL_NAME("smpro-errmon"),
> +	MFD_CELL_NAME("smpro-misc"),
> +};
> +
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> +	const struct regmap_config *config;
> +	struct regmap *regmap;
> +	unsigned int val;
> +	int ret;
> +
> +	config = device_get_match_data(&i2c->dev);
> +	if (!config)
> +		config = &smpro_regmap_config;

This use-case is not currently supported.

Please return an error instead.

> +	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
> +	/* Check for valid ID */

Decent #define nomenclature should render this comment superfluous.

> +	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> +	if (ret)
> +		return ret;
> +
> +	if (val != AMPERE_MANUFACTURER_ID)
> +		return -ENODEV;
> +
> +	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> +				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> +	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> +	.probe_new = smpro_mfd_probe,
> +	.driver = {
> +		.name = "smpro-mfd-i2c",

"smpro-core"

> +		.of_match_table = smpro_mfd_of_match,
> +	},
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL");

-- 
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
  2022-04-22  2:46   ` Quan Nguyen
@ 2022-06-29  9:23     ` Quan Nguyen
  -1 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-29  9:23 UTC (permalink / raw)
  To: Lee Jones
  Cc: Rob Herring, Krzysztof Kozlowski, Jean Delvare, Guenter Roeck,
	Jonathan Corbet, Derek Kiernan, Dragan Cvetic, Arnd Bergmann,
	Greg Kroah-Hartman, Thu Nguyen, linux-kernel, devicetree,
	linux-hwmon, linux-doc, OpenBMC Maillist, Open Source Submission,
	Phong Vo, Thang Q . Nguyen

Dear Lee Jones,

Thank you for the comment as on the link: 
https://lore.kernel.org/lkml/202204230554.4528TqPu-lkp@intel.com/T/#m476dce286d806bb3713f689663fa631f5a1f0909

I'm not sure what happen (maybe due to my bad junk filter) but I could 
only see your email when checking the link mentioned above.

I will try to response on each of your comment inline.

Thank you very much for the comment.
- Quan

On 22/04/2022 09:46, Quan Nguyen wrote:
> Adds Multi-function devices driver for SMpro co-processor found on the
[Lee] Please drop the term MFD and describe the device instead.

[Quan] Will replace MFD with "core" as your suggestion.

> Mt.Jade hardware reference platform with Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>    + None
> 
> Changes in v7:
>    + Smpro-mfd now significant changes in compare with simple-mfd-i2c
>      driver, remove the copyright note about simple-mfd-i2c    [Quan]
>    + Install bus->read/write()  to handle multiple types of bus
>      access.                                                   [Quan]
>    + Update license to MODULE_LICENSE("GPL")                   [Quan]
>    + Add others minor refactor the code                        [Quan]
> 
> Changes in v6:
>    + Update license part to reflect that this driver is clone from
>    simple-mfd-i2c driver [Quan]
> 
> Changes in v5:
>    + Dropped the use of simple-mfd-i2c driver [Quan]
>    + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
>    sub-devices. This is to avoid DT nodes without resource issue [Quan]
>    + Revised commit message [Quan]
> 
> Changes in v4:
>    + Add "depends on I2C" to fix build issue found by kernel test
>    robot [Guenter]
> 
> Changes in v3:
>    + None
> 
> Changes in v2:
>    + Used 'struct of_device_id's .data attribute [Lee Jones]
> 
>   drivers/mfd/Kconfig     |  12 ++++
>   drivers/mfd/Makefile    |   1 +
>   drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++
[Lee] Please drop the 'mfd' part.  Does 'core' work instead?

[Quan] Will drop the MFD thoroughly in next version.

>   3 files changed, 147 insertions(+)
>   create mode 100644 drivers/mfd/smpro-mfd.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 3b59456f5545..383d0e6cfb91 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
>   	help
>   	  Support for the AS3711 PMIC from AMS
>   
> +config MFD_SMPRO
> +	tristate "Ampere Computing MFD SMpro core driver"
> +	depends on I2C
> +	select MFD_CORE
> +	select REGMAP_I2C
> +	help
> +	  Say yes here to enable SMpro driver support for Ampere's Altra
> +	  processor family.
> +
> +	  Ampere's Altra SMpro exposes an I2C regmap interface that can
> +	  be accessed by child devices.
> +
>   config MFD_AS3722
>   	tristate "ams AS3722 Power Management IC"
>   	select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 858cacf659d6..36f8981cc4fd 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
>   
>   obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
>   obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
>   obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
>   
>   obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..485c4f89ebd9
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C
> + *
> + * Copyright (c) 2022, Ampere Computing LLC
> + * Author: Quan Nguyen <quan@os.amperecomputing..com>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>
> +
[Lee] Alphabetical.

[Quan] Will sort the included files follow alphbetical order in next 
version.

> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG     0x02
> +#define AMPERE_MANUFACTURER_ID  0xCD3A
> +
> +static int smpro_mfd_write(void *context, const void *data, size_t count)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	int ret;
> +
> +	ret = i2c_master_send(i2c, data, count);
> +	if (ret == count)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
> +static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
> +			  void *val, size_t val_size)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	struct i2c_msg xfer[2];
> +	unsigned char buf[2];
> +	int ret;
> +
> +	xfer[0].addr = i2c->addr;
> +	xfer[0].flags = 0;
> +
> +	buf[0] = *(u8 *)reg;
> +	buf[1] = val_size;
> +	xfer[0].len = 2;
> +	xfer[0].buf = buf;
> +
> +	xfer[1].addr = i2c->addr;
> +	xfer[1].flags = I2C_M_RD;
> +	xfer[1].len = val_size;
> +	xfer[1].buf = val;
> +
> +	ret = i2c_transfer(i2c->adapter, xfer, 2);
> +	if (ret == 2)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
[Lee] This looks all too familiar.

I wonder how generic these i2c call-backs actually are.

[Quan] yes, this is similar with regmap_i2c_read() but with reg_size is 
force to 2.
We can reuse regmap_i2c_read() but it needs to be exported from 
drivers/base/regmap/regmap-i2c.c

> +static const struct regmap_bus smpro_regmap_bus = {
> +	.read = smpro_mfd_read,
> +	.write = smpro_mfd_write,
> +	.val_format_endian_default = REGMAP_ENDIAN_BIG,
> +};
> +
> +static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
> +{
> +	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
> +		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);
> +}
[Lee] No magic numbers.  Please define these registers.

[Quan] Will fix this in next version.

> +
> +static const struct regmap_config smpro_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 16,
> +	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> +	MFD_CELL_NAME("smpro-hwmon"),
> +	MFD_CELL_NAME("smpro-errmon"),
> +	MFD_CELL_NAME("smpro-misc"),
> +};
> +
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> +	const struct regmap_config *config;
> +	struct regmap *regmap;
> +	unsigned int val;
> +	int ret;
> +
> +	config = device_get_match_data(&i2c->dev);
> +	if (!config)
> +		config = &smpro_regmap_config;
> +
[Lee] This use-case is not currently supported.

Please return an error instead.

[Quan] Will update in next version.

> +	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
> +	/* Check for valid ID */
[Lee] Decent #define nomenclature should render this comment superfluous.

[Quan] Thanks, will remove in next version.

> +	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> +	if (ret)
> +		return ret;
> +
> +	if (val != AMPERE_MANUFACTURER_ID)
> +		return -ENODEV;
> +
> +	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> +				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> +	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> +	.probe_new = smpro_mfd_probe,
> +	.driver = {
> +		.name = "smpro-mfd-i2c",
[Lee] "smpro-core"

[Quan] Will change mfd to "core" thoroughly.
Thanks for the review.

> +		.of_match_table = smpro_mfd_of_match,
> +	},
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro MFD driver
@ 2022-06-29  9:23     ` Quan Nguyen
  0 siblings, 0 replies; 44+ messages in thread
From: Quan Nguyen @ 2022-06-29  9:23 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-hwmon, devicetree, Jean Delvare, Phong Vo, Arnd Bergmann,
	Jonathan Corbet, Greg Kroah-Hartman, Dragan Cvetic, linux-doc,
	linux-kernel, Thang Q . Nguyen, OpenBMC Maillist, Rob Herring,
	Krzysztof Kozlowski, Derek Kiernan, Open Source Submission,
	Thu Nguyen, Guenter Roeck

Dear Lee Jones,

Thank you for the comment as on the link: 
https://lore.kernel.org/lkml/202204230554.4528TqPu-lkp@intel.com/T/#m476dce286d806bb3713f689663fa631f5a1f0909

I'm not sure what happen (maybe due to my bad junk filter) but I could 
only see your email when checking the link mentioned above.

I will try to response on each of your comment inline.

Thank you very much for the comment.
- Quan

On 22/04/2022 09:46, Quan Nguyen wrote:
> Adds Multi-function devices driver for SMpro co-processor found on the
[Lee] Please drop the term MFD and describe the device instead.

[Quan] Will replace MFD with "core" as your suggestion.

> Mt.Jade hardware reference platform with Ampere's Altra processor family.
> 
> Signed-off-by: Quan Nguyen <quan@os.amperecomputing.com>
> ---
> Changes in v8:
>    + None
> 
> Changes in v7:
>    + Smpro-mfd now significant changes in compare with simple-mfd-i2c
>      driver, remove the copyright note about simple-mfd-i2c    [Quan]
>    + Install bus->read/write()  to handle multiple types of bus
>      access.                                                   [Quan]
>    + Update license to MODULE_LICENSE("GPL")                   [Quan]
>    + Add others minor refactor the code                        [Quan]
> 
> Changes in v6:
>    + Update license part to reflect that this driver is clone from
>    simple-mfd-i2c driver [Quan]
> 
> Changes in v5:
>    + Dropped the use of simple-mfd-i2c driver [Quan]
>    + Introduced drivers/mfd/smpro-mfd.c driver to instantiate
>    sub-devices. This is to avoid DT nodes without resource issue [Quan]
>    + Revised commit message [Quan]
> 
> Changes in v4:
>    + Add "depends on I2C" to fix build issue found by kernel test
>    robot [Guenter]
> 
> Changes in v3:
>    + None
> 
> Changes in v2:
>    + Used 'struct of_device_id's .data attribute [Lee Jones]
> 
>   drivers/mfd/Kconfig     |  12 ++++
>   drivers/mfd/Makefile    |   1 +
>   drivers/mfd/smpro-mfd.c | 134 ++++++++++++++++++++++++++++++++++++++++
[Lee] Please drop the 'mfd' part.  Does 'core' work instead?

[Quan] Will drop the MFD thoroughly in next version.

>   3 files changed, 147 insertions(+)
>   create mode 100644 drivers/mfd/smpro-mfd.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 3b59456f5545..383d0e6cfb91 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -77,6 +77,18 @@ config MFD_AS3711
>   	help
>   	  Support for the AS3711 PMIC from AMS
>   
> +config MFD_SMPRO
> +	tristate "Ampere Computing MFD SMpro core driver"
> +	depends on I2C
> +	select MFD_CORE
> +	select REGMAP_I2C
> +	help
> +	  Say yes here to enable SMpro driver support for Ampere's Altra
> +	  processor family.
> +
> +	  Ampere's Altra SMpro exposes an I2C regmap interface that can
> +	  be accessed by child devices.
> +
>   config MFD_AS3722
>   	tristate "ams AS3722 Power Management IC"
>   	select MFD_CORE
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 858cacf659d6..36f8981cc4fd 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_QCOM_PM8008)	+= qcom-pm8008.o
>   
>   obj-$(CONFIG_SGI_MFD_IOC3)	+= ioc3.o
>   obj-$(CONFIG_MFD_SIMPLE_MFD_I2C)	+= simple-mfd-i2c.o
> +obj-$(CONFIG_MFD_SMPRO)		+= smpro-mfd.o
>   obj-$(CONFIG_MFD_INTEL_M10_BMC)   += intel-m10-bmc.o
>   
>   obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
> diff --git a/drivers/mfd/smpro-mfd.c b/drivers/mfd/smpro-mfd.c
> new file mode 100644
> index 000000000000..485c4f89ebd9
> --- /dev/null
> +++ b/drivers/mfd/smpro-mfd.c
> @@ -0,0 +1,134 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Ampere Altra Family SMPro MFD - I2C
> + *
> + * Copyright (c) 2022, Ampere Computing LLC
> + * Author: Quan Nguyen <quan@os.amperecomputing..com>
> + */
> +
> +#include <linux/i2c.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/mfd/core.h>
> +#include <linux/regmap.h>
> +
[Lee] Alphabetical.

[Quan] Will sort the included files follow alphbetical order in next 
version.

> +/* Identification Registers */
> +#define MANUFACTURER_ID_REG     0x02
> +#define AMPERE_MANUFACTURER_ID  0xCD3A
> +
> +static int smpro_mfd_write(void *context, const void *data, size_t count)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	int ret;
> +
> +	ret = i2c_master_send(i2c, data, count);
> +	if (ret == count)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
> +static int smpro_mfd_read(void *context, const void *reg, size_t reg_size,
> +			  void *val, size_t val_size)
> +{
> +	struct device *dev = context;
> +	struct i2c_client *i2c = to_i2c_client(dev);
> +	struct i2c_msg xfer[2];
> +	unsigned char buf[2];
> +	int ret;
> +
> +	xfer[0].addr = i2c->addr;
> +	xfer[0].flags = 0;
> +
> +	buf[0] = *(u8 *)reg;
> +	buf[1] = val_size;
> +	xfer[0].len = 2;
> +	xfer[0].buf = buf;
> +
> +	xfer[1].addr = i2c->addr;
> +	xfer[1].flags = I2C_M_RD;
> +	xfer[1].len = val_size;
> +	xfer[1].buf = val;
> +
> +	ret = i2c_transfer(i2c->adapter, xfer, 2);
> +	if (ret == 2)
> +		return 0;
> +	else if (ret < 0)
> +		return ret;
> +	else
> +		return -EIO;
> +}
> +
[Lee] This looks all too familiar.

I wonder how generic these i2c call-backs actually are.

[Quan] yes, this is similar with regmap_i2c_read() but with reg_size is 
force to 2.
We can reuse regmap_i2c_read() but it needs to be exported from 
drivers/base/regmap/regmap-i2c.c

> +static const struct regmap_bus smpro_regmap_bus = {
> +	.read = smpro_mfd_read,
> +	.write = smpro_mfd_write,
> +	.val_format_endian_default = REGMAP_ENDIAN_BIG,
> +};
> +
> +static bool smpro_mfd_readable_noinc_reg(struct device *dev, unsigned int reg)
> +{
> +	return  (reg == 0x82 || reg == 0x85 || reg == 0x92 || reg == 0x95 ||
> +		 reg == 0xC2 || reg == 0xC5 || reg == 0xD2 || reg == 0xDA);
> +}
[Lee] No magic numbers.  Please define these registers.

[Quan] Will fix this in next version.

> +
> +static const struct regmap_config smpro_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 16,
> +	.readable_noinc_reg = smpro_mfd_readable_noinc_reg,
> +};
> +
> +static const struct mfd_cell smpro_devs[] = {
> +	MFD_CELL_NAME("smpro-hwmon"),
> +	MFD_CELL_NAME("smpro-errmon"),
> +	MFD_CELL_NAME("smpro-misc"),
> +};
> +
> +static int smpro_mfd_probe(struct i2c_client *i2c)
> +{
> +	const struct regmap_config *config;
> +	struct regmap *regmap;
> +	unsigned int val;
> +	int ret;
> +
> +	config = device_get_match_data(&i2c->dev);
> +	if (!config)
> +		config = &smpro_regmap_config;
> +
[Lee] This use-case is not currently supported.

Please return an error instead.

[Quan] Will update in next version.

> +	regmap = devm_regmap_init(&i2c->dev, &smpro_regmap_bus, &i2c->dev, config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
> +	/* Check for valid ID */
[Lee] Decent #define nomenclature should render this comment superfluous.

[Quan] Thanks, will remove in next version.

> +	ret = regmap_read(regmap, MANUFACTURER_ID_REG, &val);
> +	if (ret)
> +		return ret;
> +
> +	if (val != AMPERE_MANUFACTURER_ID)
> +		return -ENODEV;
> +
> +	return devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> +				    smpro_devs, ARRAY_SIZE(smpro_devs), NULL, 0, NULL);
> +}
> +
> +static const struct of_device_id smpro_mfd_of_match[] = {
> +	{ .compatible = "ampere,smpro", .data = &smpro_regmap_config },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, smpro_mfd_of_match);
> +
> +static struct i2c_driver smpro_mfd_driver = {
> +	.probe_new = smpro_mfd_probe,
> +	.driver = {
> +		.name = "smpro-mfd-i2c",
[Lee] "smpro-core"

[Quan] Will change mfd to "core" thoroughly.
Thanks for the review.

> +		.of_match_table = smpro_mfd_of_match,
> +	},
> +};
> +module_i2c_driver(smpro_mfd_driver);
> +
> +MODULE_AUTHOR("Quan Nguyen <quan@os.amperecomputing.com>");
> +MODULE_DESCRIPTION("SMPRO MFD - I2C driver");
> +MODULE_LICENSE("GPL");

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2022-06-29  9:25 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22  2:46 [PATCH v8 0/9] Add Ampere's Altra SMPro MFD and its child drivers Quan Nguyen
2022-04-22  2:46 ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 1/9] hwmon: smpro: Add Ampere's Altra smpro-hwmon driver Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 2/9] docs: hwmon: (smpro-hwmon) Add documentation Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 3/9] misc: smpro-errmon: Add Ampere's SMpro error monitor driver Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  6:20   ` Greg Kroah-Hartman
2022-04-22  6:20     ` Greg Kroah-Hartman
2022-04-22 14:43     ` Quan Nguyen
2022-04-22 14:43       ` Quan Nguyen
2022-04-22 14:57       ` Greg Kroah-Hartman
2022-04-22 14:57         ` Greg Kroah-Hartman
2022-04-22 17:07         ` Darren Hart
2022-04-22 17:07           ` Darren Hart
2022-04-22 23:21         ` Quan Nguyen
2022-04-22 23:21           ` Quan Nguyen
2022-06-01  8:21     ` Quan Nguyen
2022-06-01  8:21       ` Quan Nguyen
2022-06-01  9:33       ` Greg Kroah-Hartman
2022-06-01  9:33         ` Greg Kroah-Hartman
2022-06-02  9:36         ` Quan Nguyen
2022-06-02  9:36           ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 4/9] docs: misc-devices: (smpro-errmon) Add documentation Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  6:27   ` Bagas Sanjaya
2022-04-22  6:27     ` Bagas Sanjaya
2022-04-22  2:46 ` [PATCH v8 5/9] misc: smpro-misc: Add Ampere's Altra SMpro misc driver Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 6/9] docs: misc-devices: (smpro-misc) Add documentation Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 7/9] dt-bindings: mfd: Add bindings for Ampere Altra SMPro MFD driver Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 8/9] mfd: smpro-mfd: Adds Ampere's Altra SMpro " Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen
2022-04-22 21:19   ` kernel test robot
2022-04-22 21:19     ` kernel test robot
2022-06-15 22:14   ` Lee Jones
2022-06-15 22:14     ` Lee Jones
2022-06-29  9:23   ` Quan Nguyen
2022-06-29  9:23     ` Quan Nguyen
2022-04-22  2:46 ` [PATCH v8 9/9] docs: ABI: testing: Document the Ampere Altra Family's SMpro sysfs interfaces Quan Nguyen
2022-04-22  2:46   ` Quan Nguyen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.