mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/7] alpha: marvel: environmental sensors
@ 2026-11-17  2:59 Matt Turner
  2026-11-17  2:59 ` [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout Matt Turner
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

The service processors of the Marvel AlphaServers (GS1280, ES80, ES47)
monitor temperatures, fans, voltages and power supplies. Linux can't read
these sensors, and the events the firmware raises when one changes state
are printed only with CONFIG_VERBOSE_MCHECK, and then decoded wrongly.

Patches 1 and 2 fix the event reporting. Patch 3 adds the SRM callback
that refreshes the readings of one config tree node, patch 4 passes the
firmware's events to a notifier chain, and patch 5 registers a platform
device. Patch 6 is the hwmon driver, which polls, and patch 7 makes it
reread the sensors and notify userspace when the firmware reports an
event.

The hwmon patches depend on the alpha ones, so I'd suggest the whole
series go through the alpha tree with an ack from Guenter.

Tested on an ES47, where sensors(1) shows the temperatures, fans,
voltages and power supply status. Disconnecting AC from one of its two
power supplies raised a system event that set the supply's in_fault and
woke poll() and udev, and reconnecting it cleared the fault the same
way. No voltage is out of range, so the voltage alarms were checked by
forcing the warning and failure states in the console's packets.

I used Claude Code to help write this series: working out the packet
layout, drafting the code and changelogs, and checking the firmware
documentation. I reviewed and tested the result.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
Changes in v2:
- hwmon: report the firmware's states by their documented meaning: a
  sensor's warning and failure states are its reading reaching the
  warning and failure limits, not a broken sensor (Guenter)
- hwmon: report power supplies as in channels with only a fault
  attribute instead of power alarms (Guenter)
- hwmon: depend on !ALPHA_LEGACY_START_ADDRESS for generic kernels,
  which leave out core_marvel.o (Sashiko)
- hwmon: drop the private mutex, rely on the hwmon core lock and take
  hwmon_lock() in the event work (Sashiko)
- hwmon: notify each alarm attribute whose value changed, and only those
  (Sashiko, Magnus)
- hwmon: report a voltage outside its limits as in_min_alarm and
  in_lcrit_alarm or in_max_alarm and in_crit_alarm, by comparing it with
  the nominal voltage in the console's packet (Guenter, Magnus)
- alpha: define CCB_CFGTREE in asm/console.h instead of the uapi header,
  since it is a Marvel console extension, and say it comes from Tru64
  (Magnus)
- hwmon: return -ENODATA from every alarm of a sensor that became unknown
- alpha: drop the unreachable SRM check from
  marvel_cfgtree_partial_update(), and move the GCT node type and
  subtype the driver uses to asm/gct.h
- Reorder: fix the event layout before printing it unconditionally, and
  put the alpha patches first
- Drop the Assisted-by trailers, describe tool use here instead (Guenter)
- Link to v1: https://patch.msgid.link/20261114-marvel-env-v1-0-890328e4b7e5@gmail.com

---
Matt Turner (7):
      alpha: marvel: fix the environmental subpacket layout
      alpha: marvel: report environmental events without VERBOSE_MCHECK
      alpha: marvel: refresh environmental readings through the console
      alpha: marvel: notify environmental events
      alpha: marvel: register a platform device for the environmental sensors
      hwmon: Add driver for Marvel AlphaServer environmental sensors
      hwmon: (marvel-env) Notify userspace of environmental events

 Documentation/hwmon/index.rst       |   1 +
 Documentation/hwmon/marvel-env.rst  |  76 ++++
 MAINTAINERS                         |   8 +
 arch/alpha/include/asm/console.h    |   5 +
 arch/alpha/include/asm/err_ev7.h    |  16 +-
 arch/alpha/include/asm/gct.h        |   2 +
 arch/alpha/include/asm/marvel_env.h |  17 +
 arch/alpha/kernel/core_marvel.c     |  56 +++
 arch/alpha/kernel/err_marvel.c      |  39 +-
 arch/alpha/kernel/proto.h           |   1 +
 arch/alpha/kernel/srmcons.c         |   3 +-
 arch/alpha/lib/callback_srm.S       |   1 +
 drivers/hwmon/Kconfig               |  12 +
 drivers/hwmon/Makefile              |   1 +
 drivers/hwmon/marvel-env.c          | 690 ++++++++++++++++++++++++++++++++++++
 15 files changed, 909 insertions(+), 19 deletions(-)
---
base-commit: 0b4cadbe7c39d830dec35c4a2655483de0dae568
change-id: 20261114-marvel-env-d0289c736ba3

Best regards,
--  
Matt Turner <mattst88@gmail.com>


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

* [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:08   ` Magnus Lindholm
  2026-11-17  2:59 ` [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK Matt Turner
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

struct ev7_pal_environmental_subpacket does not match what the MBM and
CMM firmware (V2.7) put in system event frames, which is:

  +0   cabinet
  +2   drawer
  +8   PE (the power and environment node holding the sensor)
  +10  sensor index
  +14  state: 0 ok, 1 warning, 2 fault, 0xfffe unknown, 0xffff removed

So the byte printed as "Condition" was half of the sensor index, and the
state was never printed. Use the firmware's layout and print the state
along with the sensor's key. This matches the frames in the error log of
an ES47.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/include/asm/err_ev7.h | 16 ++++++++++++----
 arch/alpha/kernel/err_marvel.c   | 28 +++++++++++++++++-----------
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/arch/alpha/include/asm/err_ev7.h b/arch/alpha/include/asm/err_ev7.h
index ab17e6333764..5d30af0221fb 100644
--- a/arch/alpha/include/asm/err_ev7.h
+++ b/arch/alpha/include/asm/err_ev7.h
@@ -147,17 +147,25 @@ struct ev7_pal_io_subpacket {
  *	   class PAL (14), type POWER_SUPPLY (14)
  *	   class PAL (14), type LAN (15)
  *	   class PAL (14), type HOT_PLUG (16)
+ *
+ * Cabinet, drawer, PE and sensor are the keys of the sensor's GCT packet.
  */
 struct ev7_pal_environmental_subpacket {
 	u16 cabinet;
 	u16 drawer;
 	u16 reserved1[2];
-	u8 module_type;
-	u8 unit_id;		/* unit reporting condition */
-	u8 reserved2;
-	u8 condition;		/* condition reported       */
+	u16 pe;
+	u16 sensor;
+	u16 reserved2;
+	u16 state;		/* EV7_ENV_STATE_* */
 };
 
+#define EV7_ENV_STATE_OK	0
+#define EV7_ENV_STATE_WARNING	1
+#define EV7_ENV_STATE_FAULT	2
+#define EV7_ENV_STATE_UNKNOWN	0xfffe
+#define EV7_ENV_STATE_REMOVED	0xffff
+
 /*
  * Convert environmental type to index
  */
diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
index c0c0ccefc467..85f7a56816ce 100644
--- a/arch/alpha/kernel/err_marvel.c
+++ b/arch/alpha/kernel/err_marvel.c
@@ -21,6 +21,19 @@
 #include "err_impl.h"
 #include "proto.h"
 
+static const char *
+marvel_env_state(u16 state)
+{
+	switch (state) {
+	case EV7_ENV_STATE_OK:		return "ok";
+	case EV7_ENV_STATE_WARNING:	return "warning";
+	case EV7_ENV_STATE_FAULT:	return "fault";
+	case EV7_ENV_STATE_UNKNOWN:	return "unknown";
+	case EV7_ENV_STATE_REMOVED:	return "removed";
+	default:			return "unrecognized";
+	}
+}
+
 static void
 marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
 {
@@ -50,17 +63,10 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
 		if (!env)
 			continue;
 
-		printk("%s**%s event (cabinet %d, drawer %d)\n",
-		       err_print_prefix,
-		       ev_packets[i].name,
-		       env->cabinet,
-		       env->drawer);
-		printk("%s   Module Type: 0x%x - Unit ID 0x%x - "
-		       "Condition 0x%x\n",
-		       err_print_prefix,
-		       env->module_type,
-		       env->unit_id,
-		       env->condition);
+		printk("%s**%s %s (cabinet %u, drawer %u, PE %u, sensor %u, state %#x)\n",
+		       err_print_prefix, ev_packets[i].name,
+		       marvel_env_state(env->state), env->cabinet,
+		       env->drawer, env->pe, env->sensor, env->state);
 	}
 #endif /* CONFIG_VERBOSE_MCHECK */
 }

-- 
2.56.1


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

* [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
  2026-11-17  2:59 ` [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:10   ` Magnus Lindholm
  2026-11-17  2:59 ` [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console Matt Turner
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

The service processors report temperature, fan, voltage and power supply
alarms as system event (0x680) logout frames. The frame is already
classified as reportable, but without CONFIG_VERBOSE_MCHECK only the
header line reaches the log, which does not say which sensor or what
happened. Print the subpackets unconditionally.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/kernel/err_marvel.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
index 85f7a56816ce..46c521cea9a0 100644
--- a/arch/alpha/kernel/err_marvel.c
+++ b/arch/alpha/kernel/err_marvel.c
@@ -37,7 +37,6 @@ marvel_env_state(u16 state)
 static void
 marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
 {
-#ifdef CONFIG_VERBOSE_MCHECK
 	struct ev7_pal_environmental_subpacket *env;
 	struct { int type; char *name; } ev_packets[] = {
 		{ EL_TYPE__PAL__ENV__AMBIENT_TEMPERATURE,
@@ -68,7 +67,6 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
 		       marvel_env_state(env->state), env->cabinet,
 		       env->drawer, env->pe, env->sensor, env->state);
 	}
-#endif /* CONFIG_VERBOSE_MCHECK */
 }
 
 static int

-- 
2.56.1


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

* [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
  2026-11-17  2:59 ` [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout Matt Turner
  2026-11-17  2:59 ` [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:17   ` Magnus Lindholm
  2026-11-17  2:59 ` [PATCH v2 4/7] alpha: marvel: notify environmental events Matt Turner
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

The SRM console keeps the readings of the temperature, fan, voltage and
power supply sensors in the power and environment (P&E) nodes of the
config tree (GCT), and refreshes those of one node when asked through
config tree callback 0x28, function 0x1f. The Alpha Architecture
Reference Manual reserves every callback code it does not list, so this
is a Marvel console extension; its code and function number come from
Tru64 UNIX. Define CCB_CFGTREE in asm/console.h, and add the callback
and marvel_cfgtree_partial_update() for a sensor driver to use,
retrying, as Tru64 UNIX does, while the console reports busy.

On an ES47 the callback takes 13 to 300 ms per node with interrupts
disabled. The console callbacks are not reentrant: a refresh on one CPU
while another printed to the SRM console killed the second CPU, and the
service processor reset the partition. So export the srmcons callback
lock and hold it around the call.

Tru64 UNIX makes this and its other runtime config tree callbacks only on
the master CPU, and the Marvel PAL TOY calls are already known to work
only on the boot CPU, so make the call there as well.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/include/asm/console.h    |  5 +++++
 arch/alpha/include/asm/marvel_env.h | 12 ++++++++++
 arch/alpha/kernel/core_marvel.c     | 45 +++++++++++++++++++++++++++++++++++++
 arch/alpha/kernel/proto.h           |  1 +
 arch/alpha/kernel/srmcons.c         |  3 ++-
 arch/alpha/lib/callback_srm.S       |  1 +
 6 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/include/asm/console.h b/arch/alpha/include/asm/console.h
index 1cabdb6064bb..4f5cf589aff7 100644
--- a/arch/alpha/include/asm/console.h
+++ b/arch/alpha/include/asm/console.h
@@ -4,6 +4,9 @@
 
 #include <uapi/asm/console.h>
 
+/* Not architected: a Marvel console extension, as used by Tru64 UNIX. */
+#define CCB_CFGTREE		0x28
+
 #ifndef __ASSEMBLER__
 extern long callback_puts(long unit, const char *s, long length);
 extern long callback_getc(long unit);
@@ -15,6 +18,8 @@ extern long callback_read(long channel, long count, const char *buf, long lbn);
 extern long callback_getenv(long id, const char *buf, unsigned long buf_size);
 extern long callback_setenv(long id, const char *buf, unsigned long buf_size);
 extern long callback_save_env(void);
+extern long callback_cfgtree(long func, unsigned long arg1, unsigned long arg2,
+			     unsigned long arg3, unsigned long arg4);
 
 extern int srm_fixup(unsigned long new_callback_addr,
 		     unsigned long new_hwrpb_addr);
diff --git a/arch/alpha/include/asm/marvel_env.h b/arch/alpha/include/asm/marvel_env.h
new file mode 100644
index 000000000000..16ccd2002a11
--- /dev/null
+++ b/arch/alpha/include/asm/marvel_env.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ALPHA_MARVEL_ENV_H
+#define __ALPHA_MARVEL_ENV_H
+
+/*
+ * Ask the console to refresh the environmental readings of the GCT node at
+ * @offset from the start of the GCT. Returns the console status, which is 1
+ * or -0x4a on success.
+ */
+long marvel_cfgtree_partial_update(unsigned long offset);
+
+#endif /* __ALPHA_MARVEL_ENV_H */
diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
index 92e3312e786e..7525f3ed6b62 100644
--- a/arch/alpha/kernel/core_marvel.c
+++ b/arch/alpha/kernel/core_marvel.c
@@ -20,10 +20,13 @@
 #include <linux/string.h>
 #include <linux/module.h>
 #include <linux/memblock.h>
+#include <linux/workqueue.h>
 
 #include <asm/ptrace.h>
 #include <asm/smp.h>
 #include <asm/gct.h>
+#include <asm/console.h>
+#include <asm/marvel_env.h>
 #include <asm/tlbflush.h>
 #include <asm/vga.h>
 
@@ -1094,3 +1097,45 @@ marvel_agp_info(void)
 
 	return agp;
 }
+
+/*
+ * The console refreshes the environmental packets of a GCT node through
+ * config tree callback function 0x1f, returning -26 while it is busy. The
+ * callback runs for up to 300 ms with interrupts disabled. Hold the console
+ * callback lock: a concurrent callback from another CPU, such as SRM console
+ * output, kills that CPU. Make the call on the boot CPU, as Tru64 UNIX does
+ * for its config tree callbacks; the PAL TOY calls also work only there.
+ */
+#define CFGTREE_PARTIAL_UPDATE	0x1f
+#define CFGTREE_BUSY		(-26)
+
+static long marvel_cfgtree_partial_update_local(void *arg)
+{
+	unsigned long flags;
+	long status;
+
+	spin_lock_irqsave(&srmcons_callback_lock, flags);
+	status = callback_cfgtree(CFGTREE_PARTIAL_UPDATE, (unsigned long)arg,
+				  0, 0, 0);
+	spin_unlock_irqrestore(&srmcons_callback_lock, flags);
+
+	return status;
+}
+
+long marvel_cfgtree_partial_update(unsigned long offset)
+{
+	long status;
+	int tries;
+
+	for (tries = 0; tries < 100; tries++) {
+		status = work_on_cpu(boot_cpuid,
+				     marvel_cfgtree_partial_update_local,
+				     (void *)offset);
+		if (status != CFGTREE_BUSY)
+			break;
+		usleep_range(10000, 20000);
+	}
+
+	return status;
+}
+EXPORT_SYMBOL_GPL(marvel_cfgtree_partial_update);
diff --git a/arch/alpha/kernel/proto.h b/arch/alpha/kernel/proto.h
index c418333d0b89..b54f4fd69a0f 100644
--- a/arch/alpha/kernel/proto.h
+++ b/arch/alpha/kernel/proto.h
@@ -112,6 +112,7 @@ extern struct screen_info vgacon_screen_info;
 
 /* srmcons.c */
 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
+extern spinlock_t srmcons_callback_lock;
 extern void register_srm_console(void);
 extern void unregister_srm_console(void);
 #else
diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index d19e51ec711d..45a10d539f19 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -24,7 +24,8 @@
 #include "proto.h"
 
 
-static DEFINE_SPINLOCK(srmcons_callback_lock);
+/* The console callbacks are not reentrant. */
+DEFINE_SPINLOCK(srmcons_callback_lock);
 static int srm_is_registered_console = 0;
 
 /* 
diff --git a/arch/alpha/lib/callback_srm.S b/arch/alpha/lib/callback_srm.S
index 36b63f295170..6d3c9ce6b815 100644
--- a/arch/alpha/lib/callback_srm.S
+++ b/arch/alpha/lib/callback_srm.S
@@ -94,6 +94,7 @@ CALLBACK(reset_env, CCB_RESET_ENV, 4)
 CALLBACK(save_env, CCB_SAVE_ENV, 1)
 CALLBACK(pswitch, CCB_PSWITCH, 3)
 CALLBACK(bios_emul, CCB_BIOS_EMUL, 5)
+CALLBACK(cfgtree, CCB_CFGTREE, 6)
 
 EXPORT_SYMBOL(callback_getenv)
 EXPORT_SYMBOL(callback_setenv)

-- 
2.56.1


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

* [PATCH v2 4/7] alpha: marvel: notify environmental events
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
                   ` (2 preceding siblings ...)
  2026-11-17  2:59 ` [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:10   ` Magnus Lindholm
  2026-11-17  2:59 ` [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors Matt Turner
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

A change in the state of a sensor arrives as a system event logout
frame. Call an atomic notifier chain on each one, so that a sensor
driver can reread its sensors and tell userspace without polling.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/include/asm/marvel_env.h | 5 +++++
 arch/alpha/kernel/err_marvel.c      | 9 ++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/include/asm/marvel_env.h b/arch/alpha/include/asm/marvel_env.h
index 16ccd2002a11..dbbf827a18ad 100644
--- a/arch/alpha/include/asm/marvel_env.h
+++ b/arch/alpha/include/asm/marvel_env.h
@@ -2,6 +2,8 @@
 #ifndef __ALPHA_MARVEL_ENV_H
 #define __ALPHA_MARVEL_ENV_H
 
+#include <linux/notifier.h>
+
 /*
  * Ask the console to refresh the environmental readings of the GCT node at
  * @offset from the start of the GCT. Returns the console status, which is 1
@@ -9,4 +11,7 @@
  */
 long marvel_cfgtree_partial_update(unsigned long offset);
 
+/* Called from machine check context on each environmental system event. */
+extern struct atomic_notifier_head marvel_env_notifier;
+
 #endif /* __ALPHA_MARVEL_ENV_H */
diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
index 46c521cea9a0..6e0b0aabdaca 100644
--- a/arch/alpha/kernel/err_marvel.c
+++ b/arch/alpha/kernel/err_marvel.c
@@ -17,10 +17,14 @@
 #include <asm/smp.h>
 #include <asm/err_common.h>
 #include <asm/err_ev7.h>
+#include <asm/marvel_env.h>
 
 #include "err_impl.h"
 #include "proto.h"
 
+ATOMIC_NOTIFIER_HEAD(marvel_env_notifier);
+EXPORT_SYMBOL_GPL(marvel_env_notifier);
+
 static const char *
 marvel_env_state(u16 state)
 {
@@ -82,8 +86,11 @@ marvel_process_680_frame(struct ev7_lf_subpackets *lf_subpackets, int print)
 			status = MCHK_DISPOSITION_REPORT;
 	}
 
-	if (print)
+	/* The frame is processed twice; notify on the printing pass only. */
+	if (print) {
 		marvel_print_680_frame(lf_subpackets);
+		atomic_notifier_call_chain(&marvel_env_notifier, 0, NULL);
+	}
 
 	return status;
 }

-- 
2.56.1


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

* [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
                   ` (3 preceding siblings ...)
  2026-11-17  2:59 ` [PATCH v2 4/7] alpha: marvel: notify environmental events Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:11   ` Magnus Lindholm
  2026-11-17  2:59 ` [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer " Matt Turner
  2026-11-17  2:59 ` [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events Matt Turner
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

Register a "marvel_env" platform device on Marvel systems booted from
SRM, for the hwmon driver to bind to.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 arch/alpha/kernel/core_marvel.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
index 7525f3ed6b62..169a1df6adb2 100644
--- a/arch/alpha/kernel/core_marvel.c
+++ b/arch/alpha/kernel/core_marvel.c
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/memblock.h>
 #include <linux/workqueue.h>
+#include <linux/platform_device.h>
 
 #include <asm/ptrace.h>
 #include <asm/smp.h>
@@ -1139,3 +1140,13 @@ long marvel_cfgtree_partial_update(unsigned long offset)
 	return status;
 }
 EXPORT_SYMBOL_GPL(marvel_cfgtree_partial_update);
+
+static int __init marvel_env_init(void)
+{
+	if (alpha_mv.init_arch != marvel_init_arch || !alpha_using_srm)
+		return 0;
+
+	return PTR_ERR_OR_ZERO(platform_device_register_simple("marvel_env",
+							       -1, NULL, 0));
+}
+device_initcall(marvel_env_init);

-- 
2.56.1


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

* [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
                   ` (4 preceding siblings ...)
  2026-11-17  2:59 ` [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:27   ` Magnus Lindholm
  2026-11-17 16:13   ` Guenter Roeck
  2026-11-17  2:59 ` [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events Matt Turner
  6 siblings, 2 replies; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

The management firmware of the Marvel (EV7) AlphaServers, the GS1280,
ES80 and ES47, monitors temperatures, fans, voltages and power supplies.
The SRM console describes each sensor as a packet in a power and
environment node of its config tree (GCT), and fills in the readings
when asked to refresh the node. The packet layout was taken from Tru64
UNIX.

The firmware gives each temperature, fan and voltage sensor a warning
limit and a failure limit, and reports the sensor in the warning or
failure state once its reading reaches one. Neither state means that the
sensor is broken: a temperature past its failure limit is too high, not
faulty. Power supplies are either working or failed, with the cause
(AC, POK, overtemperature, fan) logged by the firmware.

Export the sensors through hwmon. A temperature's warning and failure
limits become max and crit, with max_alarm set in either state and
crit_alarm in the failure state. A fan's warning limit becomes min, with
min_alarm set in either state and fault in the failure state, which is
when the firmware counts the fan as failed. A voltage exports its
reading, with min_alarm or max_alarm set in either state and lcrit_alarm
or crit_alarm in the failure state, depending on which side of its
nominal voltage it reads. The console gives the nominal voltage and only
one other limit, so the voltage limits are not exported. A power supply
is a voltage channel with only a fault attribute.

A refresh keeps the boot CPU in the console with interrupts disabled for
up to 300 ms per node, so refresh a node at most once per
update_interval. The hwmon core serializes the callbacks, which also
serializes the refreshes.

The console callback lives in core_marvel.o, which generic kernels
built with ALPHA_LEGACY_START_ADDRESS leave out.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 Documentation/hwmon/index.rst      |   1 +
 Documentation/hwmon/marvel-env.rst |  72 +++++
 MAINTAINERS                        |   8 +
 arch/alpha/include/asm/gct.h       |   2 +
 drivers/hwmon/Kconfig              |  11 +
 drivers/hwmon/Makefile             |   1 +
 drivers/hwmon/marvel-env.c         | 609 +++++++++++++++++++++++++++++++++++++
 7 files changed, 704 insertions(+)

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 199ca79621e9..b062ad1ff53f 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers
    ltc4286
    lx1308
    macsmc-hwmon
+   marvel-env
    max127
    max15301
    max16064
diff --git a/Documentation/hwmon/marvel-env.rst b/Documentation/hwmon/marvel-env.rst
new file mode 100644
index 000000000000..7e0457a60094
--- /dev/null
+++ b/Documentation/hwmon/marvel-env.rst
@@ -0,0 +1,72 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver marvel-env
+========================
+
+Supported systems:
+
+  * Marvel (EV7) AlphaServers: the GS1280, ES80 and ES47 families,
+    booted from the SRM console
+
+Author: Matt Turner <mattst88@gmail.com>
+
+Description
+-----------
+
+The management firmware of these machines monitors temperatures, fans,
+voltages and power supplies, and the SRM console describes each sensor in
+its configuration tree (GCT). This driver asks the console to refresh the
+readings and exports them.
+
+The console has no sensor names, so the labels are built from the reporting
+unit (such as ``CMM0`` or ``MBM/PBM``) and the sensor's position in that
+unit. On systems with more than one drawer the label starts with the
+cabinet and drawer numbers.
+
+A refresh keeps the boot CPU in the console with interrupts disabled for up
+to 300 ms per unit, so a unit is refreshed at most once every
+``update_interval`` milliseconds (10000 by default).
+
+Sysfs entries
+-------------
+
+The management firmware gives each temperature, fan and voltage sensor a
+warning limit and a failure limit, and reports the sensor in the warning or
+failure state when its reading reaches the limit. Neither state means that
+the sensor is broken. Power supplies have no warning state and are reported
+as voltage channels that only have a fault attribute.
+
+=========================== =================================================
+``update_interval``         Minimum time between refreshes of a unit, in ms
+
+``temp[1-*]_input``         Temperature
+``temp[1-*]_max``           Warning limit
+``temp[1-*]_crit``          Failure limit
+``temp[1-*]_max_alarm``     Temperature reached the warning limit
+``temp[1-*]_crit_alarm``    Temperature reached the failure limit
+``temp[1-*]_label``         Sensor label
+
+``fan[1-*]_input``          Fan speed
+``fan[1-*]_min``            Warning limit
+``fan[1-*]_min_alarm``      Fan speed dropped to the warning limit
+``fan[1-*]_fault``          Fan speed dropped to the failure limit, and the
+                            firmware counts the fan as failed
+``fan[1-*]_label``          Fan label
+
+``in[0-*]_input``           Voltage
+``in[0-*]_min_alarm``       Voltage is below the warning limit
+``in[0-*]_max_alarm``       Voltage is above the warning limit
+``in[0-*]_lcrit_alarm``     Voltage is below the failure limit
+``in[0-*]_crit_alarm``      Voltage is above the failure limit
+``in[0-*]_fault``           Power supply has failed
+``in[0-*]_label``           Sensor or power supply label
+=========================== =================================================
+
+The firmware checks a voltage against limits on both sides of the nominal
+voltage, but the console only describes the nominal voltage and one other
+limit, so the voltage limits are not exported. Whether a voltage is too low
+or too high comes from comparing it with the nominal voltage.
+
+Sensors that the console reports as unknown or not present when the driver
+loads are not exported. If a sensor becomes unknown later, reading its input,
+alarm or fault attribute fails with ``-ENODATA``.
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..09dee8fab9ec 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16100,6 +16100,14 @@ L:	linux-mips@vger.kernel.org
 S:	Maintained
 F:	arch/mips/boot/dts/img/pistachio*
 
+MARVEL ALPHASERVER ENVIRONMENTAL SENSOR DRIVER
+M:	Matt Turner <mattst88@gmail.com>
+L:	linux-hwmon@vger.kernel.org
+L:	linux-alpha@vger.kernel.org
+S:	Maintained
+F:	Documentation/hwmon/marvel-env.rst
+F:	drivers/hwmon/marvel-env.c
+
 MARVELL 88E6XXX ETHERNET SWITCH FABRIC DRIVER
 M:	Andrew Lunn <andrew@lunn.ch>
 L:	netdev@vger.kernel.org
diff --git a/arch/alpha/include/asm/gct.h b/arch/alpha/include/asm/gct.h
index 2847449fb168..afa7ed870bd1 100644
--- a/arch/alpha/include/asm/gct.h
+++ b/arch/alpha/include/asm/gct.h
@@ -43,11 +43,13 @@ typedef struct {
  * node types 
  */
 #define GCT_TYPE_HOSE			0x0E
+#define GCT_TYPE_PE			0x13	/* power and environment */
 
 /*
  * node subtypes
  */
 #define GCT_SUBTYPE_IO_PORT_MODULE	0x2C
+#define GCT_SUBTYPE_PE_CABINET		0x3D	/* id holds an 8-bit cabinet */
 
 #define GCT_NODE_PTR(off) ((gct6_node *)((char *)hwrpb + 		\
 					 hwrpb->frut_offset + 		\
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 18c682e1a475..c0ce5591c82d 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1255,6 +1255,17 @@ config SENSORS_MACSMC_HWMON
 	  This driver can also be built as a module. If so, the module will
 	  be called macsmc-hwmon.
 
+config SENSORS_MARVEL_ENV
+	tristate "Marvel (EV7) AlphaServer environmental sensors"
+	depends on ALPHA_MARVEL || (ALPHA_GENERIC && !ALPHA_LEGACY_START_ADDRESS)
+	help
+	  If you say yes here you get support for the temperature, fan,
+	  voltage and power supply sensors of Marvel AlphaServers (the
+	  GS1280, ES80 and ES47), as described by the SRM console.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called marvel-env.
+
 config SENSORS_MAX1111
 	tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
 	depends on SPI_MASTER
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index d4c345ed7261..2b1b1850d641 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -157,6 +157,7 @@ obj-$(CONFIG_SENSORS_LTC4282)	+= ltc4282.o
 obj-$(CONFIG_SENSORS_LTC4283)	+= ltc4283.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MACSMC_HWMON)	+= macsmc-hwmon.o
+obj-$(CONFIG_SENSORS_MARVEL_ENV)	+= marvel-env.o
 obj-$(CONFIG_SENSORS_MAX1111)	+= max1111.o
 obj-$(CONFIG_SENSORS_MAX127)	+= max127.o
 obj-$(CONFIG_SENSORS_MAX16065)	+= max16065.o
diff --git a/drivers/hwmon/marvel-env.c b/drivers/hwmon/marvel-env.c
new file mode 100644
index 000000000000..e501e049d702
--- /dev/null
+++ b/drivers/hwmon/marvel-env.c
@@ -0,0 +1,609 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Environmental sensors of Marvel (EV7) AlphaServers: the GS1280, ES80 and
+ * ES47 families.
+ *
+ * The SRM console describes every sensor in the config tree (GCT). Each power
+ * and environment (P&E) node may carry a list of environmental packets:
+ * temperature and voltage sensors, fans and power supplies. The console fills
+ * in the readings when asked to refresh the node. The packet layout was
+ * taken from Tru64 UNIX.
+ *
+ * The management firmware gives each temperature, voltage and fan sensor a
+ * warning limit and a failure limit, and puts the sensor in the warning or
+ * failure state when its reading reaches the limit. Neither state means that
+ * the sensor itself is broken. A power supply has no warning state; it is
+ * either working or failed.
+ */
+
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include <asm/gct.h>
+#include <asm/marvel_env.h>
+
+#define DRVNAME "marvel_env"
+
+#define GCT_FLAGS_REQUIRED	BIT(9)
+#define GCT_FLAGS_EXCLUDED	(BIT(2) | BIT(7) | BIT(12) | BIT(14))
+
+/* Header of a P&E node's packet list, at hd_extension. */
+#define ENV_HDR_COUNT		0x10
+#define ENV_HDR_FIRST		0x14
+#define ENV_HDR_SIZE		0x18
+
+/* Packet types. */
+#define ENV_PKT_POWER_SUPPLY	0x08
+#define ENV_PKT_FAN		0x09
+#define ENV_PKT_SENSOR		0x2a
+
+/*
+ * Sensor packet: kind, status, reading, and two limits. Temperatures are in
+ * tenths of a degree Celsius, voltages in millivolts. For a temperature the
+ * two values are the warning and failure limits. For a voltage they are the
+ * nominal voltage and an upper limit; the firmware checks a voltage against
+ * a window on both sides of the nominal voltage, so neither is exported.
+ */
+#define SENSOR_KIND		0x28
+#define SENSOR_STATUS		0x2c
+#define SENSOR_VALUE		0x30
+#define SENSOR_WARN		0x34
+#define SENSOR_FAIL		0x38
+#define SENSOR_NOMINAL		SENSOR_WARN	/* of a voltage */
+#define SENSOR_SIZE		0x3c
+
+#define SENSOR_KIND_THERMAL	2
+#define SENSOR_KIND_VOLT_FIRST	3
+#define SENSOR_KIND_VOLT_LAST	5
+
+/* Fan packet: status, rpm, low warning limit, low failure limit. */
+#define FAN_STATUS		0x24
+#define FAN_VALUE		0x28
+#define FAN_WARN		0x2c
+#define FAN_SIZE		0x34
+
+/* Power supply packet: status. */
+#define PS_STATUS		0x24
+#define PS_SIZE			0x28
+
+/* Status values, in the low byte of the status word. */
+#define ENV_OK			0
+#define ENV_WARNING		1	/* reading reached the warning limit */
+#define ENV_FAILURE		2	/* reading reached the failure limit */
+#define ENV_UNKNOWN		0xfe
+#define ENV_NOT_PRESENT		0xff
+
+/* Console status of a refresh that Tru64 also treats as success. */
+#define CFGTREE_STATUS_OK2	(-0x4a)
+
+struct marvel_env_node {
+	gct6_node *node;
+	unsigned long offset;		/* from the start of the GCT */
+	unsigned long last_refresh;
+	bool valid;
+	unsigned int cabinet, drawer, pe;
+};
+
+struct marvel_env_chan {
+	struct marvel_env_node *node;
+	unsigned int pkt;		/* packet offset in the node */
+	bool ps;			/* power supply, as an in channel */
+	bool present;			/* known when the driver loaded */
+	char label[32];
+};
+
+struct marvel_env_data {
+	struct device *dev;
+	unsigned int update_interval;	/* ms */
+	struct marvel_env_node *nodes;
+	unsigned int nr_nodes;
+	struct marvel_env_chan *chans[hwmon_max];
+	unsigned int nr_chans[hwmon_max];
+};
+
+static const char * const pe_names[] = {
+	[0x09] = "MBM",
+	[0x0a] = "MBM/PBM",
+	[0x0c] = "PS",
+	[0x0d] = "FAN",
+	[0x0f] = "CMM0", [0x10] = "CMM1", [0x11] = "CMM2", [0x12] = "CMM3",
+	[0x14] = "VRM0", [0x15] = "VRM1", [0x16] = "VRM2", [0x17] = "VRM3",
+	[0x19] = "PBM",
+	[0x1a] = "XSHELF",
+	[0x1b] = "PCIPS",
+	[0x1c] = "PCIFANS",
+};
+
+/* The sensor types the driver exports. */
+static const enum hwmon_sensor_types marvel_env_types[] = {
+	hwmon_temp, hwmon_fan, hwmon_in,
+};
+
+/* The attributes that report the state of a channel. */
+static const u32 marvel_env_alarm_attrs[hwmon_max] = {
+	[hwmon_temp] = HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM,
+	[hwmon_fan] = HWMON_F_MIN_ALARM | HWMON_F_FAULT,
+	[hwmon_in] = HWMON_I_MIN_ALARM | HWMON_I_MAX_ALARM |
+		     HWMON_I_LCRIT_ALARM | HWMON_I_CRIT_ALARM | HWMON_I_FAULT,
+};
+
+static inline u32 env_rd(struct marvel_env_node *n, unsigned int off)
+{
+	return *(u32 *)((char *)n->node + off);
+}
+
+static bool env_status_valid(u8 status)
+{
+	return status != ENV_UNKNOWN && status != ENV_NOT_PRESENT;
+}
+
+static u8 marvel_env_status(enum hwmon_sensor_types type,
+			    const struct marvel_env_chan *c)
+{
+	unsigned int off;
+
+	if (type == hwmon_fan)
+		off = FAN_STATUS;
+	else if (c->ps)
+		off = PS_STATUS;
+	else
+		off = SENSOR_STATUS;
+	return env_rd(c->node, c->pkt + off) & 0xff;
+}
+
+/*
+ * The alarm attributes that are set in @status. A reading past the failure
+ * limit is also past the warning limit, so it sets both alarms. A fan below
+ * its failure limit is one the firmware counts as failed. A voltage outside
+ * its limits is too low or too high depending on which side of the nominal
+ * voltage it reads.
+ */
+static u32 marvel_env_alarms(enum hwmon_sensor_types type,
+			     const struct marvel_env_chan *c, u8 status)
+{
+	switch (type) {
+	case hwmon_temp:
+		if (status == ENV_FAILURE)
+			return HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM;
+		if (status == ENV_WARNING)
+			return HWMON_T_MAX_ALARM;
+		break;
+	case hwmon_fan:
+		if (status == ENV_FAILURE)
+			return HWMON_F_MIN_ALARM | HWMON_F_FAULT;
+		if (status == ENV_WARNING)
+			return HWMON_F_MIN_ALARM;
+		break;
+	case hwmon_in:
+		if (c->ps)
+			return status == ENV_FAILURE ? HWMON_I_FAULT : 0;
+		if (status != ENV_WARNING && status != ENV_FAILURE)
+			break;
+		if ((s32)env_rd(c->node, c->pkt + SENSOR_VALUE) <
+		    (s32)env_rd(c->node, c->pkt + SENSOR_NOMINAL)) {
+			if (status == ENV_FAILURE)
+				return HWMON_I_MIN_ALARM | HWMON_I_LCRIT_ALARM;
+			return HWMON_I_MIN_ALARM;
+		}
+		if (status == ENV_FAILURE)
+			return HWMON_I_MAX_ALARM | HWMON_I_CRIT_ALARM;
+		return HWMON_I_MAX_ALARM;
+	default:
+		break;
+	}
+	return 0;
+}
+
+static inline gct6_node *gct_node(gct6_handle h)
+{
+	return GCT_NODE_PTR(h);
+}
+
+/* Cabinet and drawer come from the P&E node's parent. */
+static void marvel_env_keys(struct marvel_env_node *n)
+{
+	gct6_node *parent = n->node->parent ? gct_node(n->node->parent) : NULL;
+
+	n->pe = n->node->id & 0xff;
+	if (!parent)
+		return;
+	if (parent->type == GCT_TYPE_PE && parent->subtype == GCT_SUBTYPE_PE_CABINET)
+		n->cabinet = (parent->id >> 48) & 0xff;
+	else
+		n->cabinet = (parent->id >> 48) & 0x3f;
+	n->drawer = (parent->id >> 32) & 0xff;
+}
+
+static int marvel_env_refresh(struct marvel_env_data *data,
+			      struct marvel_env_node *n)
+{
+	long status;
+
+	if (n->valid && time_before(jiffies, n->last_refresh +
+				    msecs_to_jiffies(data->update_interval)))
+		return 0;
+
+	status = marvel_cfgtree_partial_update(n->offset);
+	if (status != 1 && status != CFGTREE_STATUS_OK2) {
+		dev_warn_ratelimited(data->dev,
+				     "refresh of GCT node %#lx failed: %ld\n",
+				     n->offset, status);
+		return -EIO;
+	}
+	n->last_refresh = jiffies;
+	n->valid = true;
+	return 0;
+}
+
+/* The hwmon type of a packet, or hwmon_max to skip it. */
+static enum hwmon_sensor_types marvel_env_pkt_type(struct marvel_env_node *n,
+						   unsigned int pkt,
+						   unsigned int type)
+{
+	unsigned int len = env_rd(n, pkt) & 0xffff;
+	u32 kind;
+
+	switch (type) {
+	case ENV_PKT_SENSOR:
+		if (len < SENSOR_SIZE)
+			break;
+		kind = env_rd(n, pkt + SENSOR_KIND);
+		if (kind == SENSOR_KIND_THERMAL)
+			return hwmon_temp;
+		if (kind >= SENSOR_KIND_VOLT_FIRST && kind <= SENSOR_KIND_VOLT_LAST)
+			return hwmon_in;
+		break;
+	case ENV_PKT_FAN:
+		if (len >= FAN_SIZE)
+			return hwmon_fan;
+		break;
+	case ENV_PKT_POWER_SUPPLY:
+		if (len >= PS_SIZE)
+			return hwmon_in;
+		break;
+	}
+	return hwmon_max;
+}
+
+static void marvel_env_add_chan(struct marvel_env_data *data,
+				struct marvel_env_node *n, unsigned int pkt,
+				enum hwmon_sensor_types type, bool ps,
+				unsigned int index)
+{
+	static const char * const names[hwmon_max] = {
+		[hwmon_temp] = "Temp", [hwmon_fan] = "Fan", [hwmon_in] = "Volt",
+	};
+	const char *what = ps ? "PS" : names[type];
+	struct marvel_env_chan *c;
+	const char *pe = NULL;
+	size_t len = 0;
+	u8 status;
+
+	c = &data->chans[type][data->nr_chans[type]++];
+	c->node = n;
+	c->pkt = pkt;
+	c->ps = ps;
+	status = marvel_env_status(type, c);
+	c->present = env_status_valid(status);
+
+	if (n->cabinet || n->drawer)
+		len = scnprintf(c->label, sizeof(c->label), "Cab%u Dra%u ",
+				n->cabinet, n->drawer);
+
+	if (n->pe < ARRAY_SIZE(pe_names))
+		pe = pe_names[n->pe];
+	if (pe && !strncasecmp(pe, what, strlen(what)))
+		scnprintf(c->label + len, sizeof(c->label) - len, "%s %u",
+			  pe, index);
+	else if (pe)
+		scnprintf(c->label + len, sizeof(c->label) - len, "%s %s %u",
+			  pe, what, index);
+	else
+		scnprintf(c->label + len, sizeof(c->label) - len, "PE%u %s %u",
+			  n->pe, what, index);
+}
+
+/*
+ * Walk a P&E node's packets, counting them, or adding them when @add. As
+ * Tru64 does, visit count + 1 packets and number sensors from their
+ * position minus one.
+ */
+static void marvel_env_walk(struct marvel_env_data *data,
+			    struct marvel_env_node *n, bool add)
+{
+	unsigned int size = n->node->size;
+	unsigned int hdr = n->node->hd_extension;
+	unsigned int count, pkt, i;
+
+	if (!hdr || hdr + ENV_HDR_SIZE > size)
+		return;
+	count = env_rd(n, hdr + ENV_HDR_COUNT);
+	pkt = env_rd(n, hdr + ENV_HDR_FIRST);
+
+	for (i = 0; i <= count; i++) {
+		enum hwmon_sensor_types type;
+		unsigned int len, pkt_type;
+
+		if (pkt < 8 || pkt + 8 > size)
+			break;
+		len = env_rd(n, pkt) & 0xffff;
+		pkt_type = env_rd(n, pkt + 4) & 0xffff;
+		if (len < 8 || pkt + len > size)
+			break;
+
+		type = marvel_env_pkt_type(n, pkt, pkt_type);
+		if (type != hwmon_max && add)
+			marvel_env_add_chan(data, n, pkt, type,
+					    pkt_type == ENV_PKT_POWER_SUPPLY,
+					    pkt_type == ENV_PKT_SENSOR && i ?
+					    i - 1 : i);
+		else if (type != hwmon_max)
+			data->nr_chans[type]++;
+		pkt += len;
+	}
+}
+
+/* Collect the P&E nodes with an environmental packet list. */
+static void marvel_env_find_nodes(struct marvel_env_data *data,
+				  gct6_node *node, bool record)
+{
+	for (; node; node = node->next ? gct_node(node->next) : NULL) {
+		if (node->magic != GCT_NODE_MAGIC)
+			return;
+		if (node->type == GCT_TYPE_PE && node->hd_extension &&
+		    (node->flags & GCT_FLAGS_REQUIRED) &&
+		    !(node->flags & GCT_FLAGS_EXCLUDED)) {
+			if (record) {
+				struct marvel_env_node *n =
+					&data->nodes[data->nr_nodes];
+
+				n->node = node;
+				n->offset = (char *)node - (char *)gct_node(0);
+				marvel_env_keys(n);
+			}
+			data->nr_nodes++;
+		}
+		if (node->child)
+			marvel_env_find_nodes(data, gct_node(node->child),
+					      record);
+	}
+}
+
+static umode_t marvel_env_is_visible(const void *drvdata,
+				     enum hwmon_sensor_types type,
+				     u32 attr, int channel)
+{
+	const struct marvel_env_data *data = drvdata;
+
+	if (type == hwmon_chip)
+		return 0644;
+
+	/* Hide sensors that are absent when the driver loads. */
+	return data->chans[type][channel].present ? 0444 : 0;
+}
+
+/* Called with the hwmon device lock held, which serializes refreshes. */
+static int marvel_env_read(struct device *dev, enum hwmon_sensor_types type,
+			   u32 attr, int channel, long *val)
+{
+	struct marvel_env_data *data = dev_get_drvdata(dev);
+	struct marvel_env_chan *c;
+	struct marvel_env_node *n;
+	unsigned int pkt;
+	u8 status;
+	int ret;
+
+	if (type == hwmon_chip) {
+		*val = data->update_interval;
+		return 0;
+	}
+
+	c = &data->chans[type][channel];
+	n = c->node;
+	pkt = c->pkt;
+
+	ret = marvel_env_refresh(data, n);
+	if (ret)
+		return ret;
+	status = marvel_env_status(type, c);
+
+	switch (type) {
+	case hwmon_temp:
+		switch (attr) {
+		case hwmon_temp_max:
+			*val = (s32)env_rd(n, pkt + SENSOR_WARN) * 100L;
+			return 0;
+		case hwmon_temp_crit:
+			*val = (s32)env_rd(n, pkt + SENSOR_FAIL) * 100L;
+			return 0;
+		}
+		break;
+	case hwmon_fan:
+		if (attr == hwmon_fan_min) {
+			*val = env_rd(n, pkt + FAN_WARN);
+			return 0;
+		}
+		break;
+	default:
+		break;
+	}
+
+	if (!env_status_valid(status))
+		return -ENODATA;
+
+	if (marvel_env_alarm_attrs[type] & BIT(attr)) {
+		*val = !!(marvel_env_alarms(type, c, status) & BIT(attr));
+		return 0;
+	}
+
+	switch (type) {
+	case hwmon_temp:
+		if (attr != hwmon_temp_input)
+			break;
+		*val = (s32)env_rd(n, pkt + SENSOR_VALUE) * 100L;
+		return 0;
+	case hwmon_fan:
+		if (attr != hwmon_fan_input)
+			break;
+		*val = env_rd(n, pkt + FAN_VALUE);
+		return 0;
+	case hwmon_in:
+		if (attr != hwmon_in_input)
+			break;
+		*val = (s32)env_rd(n, pkt + SENSOR_VALUE);
+		return 0;
+	default:
+		break;
+	}
+	return -EOPNOTSUPP;
+}
+
+static int marvel_env_write(struct device *dev, enum hwmon_sensor_types type,
+			    u32 attr, int channel, long val)
+{
+	struct marvel_env_data *data = dev_get_drvdata(dev);
+
+	if (type != hwmon_chip || attr != hwmon_chip_update_interval)
+		return -EOPNOTSUPP;
+
+	data->update_interval = clamp_val(val, 0, 3600 * MSEC_PER_SEC);
+	return 0;
+}
+
+static int marvel_env_read_string(struct device *dev,
+				  enum hwmon_sensor_types type, u32 attr,
+				  int channel, const char **str)
+{
+	struct marvel_env_data *data = dev_get_drvdata(dev);
+
+	*str = data->chans[type][channel].label;
+	return 0;
+}
+
+static const struct hwmon_ops marvel_env_ops = {
+	.is_visible = marvel_env_is_visible,
+	.read = marvel_env_read,
+	.write = marvel_env_write,
+	.read_string = marvel_env_read_string,
+};
+
+static u32 marvel_env_config(enum hwmon_sensor_types type,
+			     const struct marvel_env_chan *c)
+{
+	switch (type) {
+	case hwmon_temp:
+		return HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
+		       HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_LABEL;
+	case hwmon_fan:
+		return HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_MIN_ALARM |
+		       HWMON_F_FAULT | HWMON_F_LABEL;
+	case hwmon_in:
+		if (c->ps)
+			return HWMON_I_FAULT | HWMON_I_LABEL;
+		return HWMON_I_INPUT | HWMON_I_MIN_ALARM | HWMON_I_MAX_ALARM |
+		       HWMON_I_LCRIT_ALARM | HWMON_I_CRIT_ALARM | HWMON_I_LABEL;
+	default:
+		return 0;
+	}
+}
+
+static const struct hwmon_channel_info * const marvel_env_chip_info =
+	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL);
+
+static int marvel_env_probe(struct platform_device *pdev)
+{
+	u32 *config[hwmon_max] = { };
+	struct device *dev = &pdev->dev;
+	const struct hwmon_channel_info **info;
+	struct marvel_env_data *data;
+	struct hwmon_chip_info *chip;
+	struct device *hwmon;
+	unsigned int i, k, nr_info = 0;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	data->dev = dev;
+	data->update_interval = 10 * MSEC_PER_SEC;
+
+	marvel_env_find_nodes(data, gct_node(0), false);
+	if (!data->nr_nodes)
+		return -ENODEV;
+	data->nodes = devm_kcalloc(dev, data->nr_nodes, sizeof(*data->nodes),
+				   GFP_KERNEL);
+	if (!data->nodes)
+		return -ENOMEM;
+	data->nr_nodes = 0;
+	marvel_env_find_nodes(data, gct_node(0), true);
+
+	for (i = 0; i < data->nr_nodes; i++) {
+		marvel_env_refresh(data, &data->nodes[i]);
+		marvel_env_walk(data, &data->nodes[i], false);
+	}
+
+	info = devm_kcalloc(dev, ARRAY_SIZE(marvel_env_types) + 2,
+			    sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+	info[nr_info++] = marvel_env_chip_info;
+
+	for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
+		enum hwmon_sensor_types type = marvel_env_types[k];
+		struct hwmon_channel_info *ci;
+
+		if (!data->nr_chans[type])
+			continue;
+		data->chans[type] = devm_kcalloc(dev, data->nr_chans[type],
+						 sizeof(*data->chans[type]),
+						 GFP_KERNEL);
+		ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
+		config[type] = devm_kcalloc(dev, data->nr_chans[type] + 1,
+					    sizeof(*config[type]), GFP_KERNEL);
+		if (!data->chans[type] || !ci || !config[type])
+			return -ENOMEM;
+		ci->type = type;
+		ci->config = config[type];
+		info[nr_info++] = ci;
+		data->nr_chans[type] = 0;
+	}
+	if (nr_info == 1)
+		return -ENODEV;
+
+	for (i = 0; i < data->nr_nodes; i++)
+		marvel_env_walk(data, &data->nodes[i], true);
+
+	for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
+		enum hwmon_sensor_types type = marvel_env_types[k];
+
+		for (i = 0; i < data->nr_chans[type]; i++)
+			config[type][i] = marvel_env_config(type,
+							    &data->chans[type][i]);
+	}
+
+	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+	chip->ops = &marvel_env_ops;
+	chip->info = info;
+
+	hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data, chip,
+						     NULL);
+	return PTR_ERR_OR_ZERO(hwmon);
+}
+
+static struct platform_driver marvel_env_driver = {
+	.driver = {
+		.name = DRVNAME,
+	},
+	.probe = marvel_env_probe,
+};
+module_platform_driver(marvel_env_driver);
+
+MODULE_ALIAS("platform:" DRVNAME);
+MODULE_DESCRIPTION("Marvel (EV7) AlphaServer environmental sensors");
+MODULE_LICENSE("GPL");

-- 
2.56.1


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

* [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events
  2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
                   ` (5 preceding siblings ...)
  2026-11-17  2:59 ` [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer " Matt Turner
@ 2026-11-17  2:59 ` Matt Turner
  2026-11-17 11:30   ` Magnus Lindholm
  6 siblings, 1 reply; 16+ messages in thread
From: Matt Turner @ 2026-11-17  2:59 UTC (permalink / raw)
  To: Richard Henderson, Magnus Lindholm, Guenter Roeck
  Cc: linux-alpha, linux-kernel, linux-hwmon, linux-doc, Matt Turner

The firmware reports each change of a sensor's state as a system event
machine check. On one, reread every node from a workqueue and notify
userspace of each alarm attribute whose value changed. The notifier runs
in machine check context, so it only queues an irq_work, which queues
the work. The work takes the hwmon device lock to serialize the refresh
with the sysfs callbacks.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 Documentation/hwmon/marvel-env.rst |  4 ++
 drivers/hwmon/Kconfig              |  1 +
 drivers/hwmon/marvel-env.c         | 89 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/Documentation/hwmon/marvel-env.rst b/Documentation/hwmon/marvel-env.rst
index 7e0457a60094..ae3edda557ab 100644
--- a/Documentation/hwmon/marvel-env.rst
+++ b/Documentation/hwmon/marvel-env.rst
@@ -27,6 +27,10 @@ A refresh keeps the boot CPU in the console with interrupts disabled for up
 to 300 ms per unit, so a unit is refreshed at most once every
 ``update_interval`` milliseconds (10000 by default).
 
+The firmware also reports every change of state as a system event machine
+check. When one arrives, the driver refreshes all units and notifies
+userspace through the alarm attributes.
+
 Sysfs entries
 -------------
 
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index c0ce5591c82d..99c5d84c8752 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1258,6 +1258,7 @@ config SENSORS_MACSMC_HWMON
 config SENSORS_MARVEL_ENV
 	tristate "Marvel (EV7) AlphaServer environmental sensors"
 	depends on ALPHA_MARVEL || (ALPHA_GENERIC && !ALPHA_LEGACY_START_ADDRESS)
+	select IRQ_WORK
 	help
 	  If you say yes here you get support for the temperature, fan,
 	  voltage and power supply sensors of Marvel AlphaServers (the
diff --git a/drivers/hwmon/marvel-env.c b/drivers/hwmon/marvel-env.c
index e501e049d702..d319556929e3 100644
--- a/drivers/hwmon/marvel-env.c
+++ b/drivers/hwmon/marvel-env.c
@@ -17,12 +17,15 @@
  */
 
 #include <linux/hwmon.h>
+#include <linux/irq_work.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/workqueue.h>
 
 #include <asm/gct.h>
 #include <asm/marvel_env.h>
@@ -94,16 +97,21 @@ struct marvel_env_chan {
 	unsigned int pkt;		/* packet offset in the node */
 	bool ps;			/* power supply, as an in channel */
 	bool present;			/* known when the driver loaded */
+	u32 alarms;			/* alarm attributes last reported */
 	char label[32];
 };
 
 struct marvel_env_data {
 	struct device *dev;
+	struct device *hwmon;
 	unsigned int update_interval;	/* ms */
 	struct marvel_env_node *nodes;
 	unsigned int nr_nodes;
 	struct marvel_env_chan *chans[hwmon_max];
 	unsigned int nr_chans[hwmon_max];
+	struct irq_work irq_work;
+	struct work_struct work;
+	struct notifier_block nb;
 };
 
 static const char * const pe_names[] = {
@@ -290,6 +298,7 @@ static void marvel_env_add_chan(struct marvel_env_data *data,
 	c->ps = ps;
 	status = marvel_env_status(type, c);
 	c->present = env_status_valid(status);
+	c->alarms = marvel_env_alarms(type, c, status);
 
 	if (n->cabinet || n->drawer)
 		len = scnprintf(c->label, sizeof(c->label), "Cab%u Dra%u ",
@@ -512,6 +521,72 @@ static u32 marvel_env_config(enum hwmon_sensor_types type,
 	}
 }
 
+/* Reread everything after a system event and report changed alarms. */
+static void marvel_env_event_work(struct work_struct *work)
+{
+	struct marvel_env_data *data =
+		container_of(work, struct marvel_env_data, work);
+	unsigned int i, k;
+
+	guard(hwmon_lock)(data->hwmon);
+
+	for (i = 0; i < data->nr_nodes; i++) {
+		data->nodes[i].valid = false;
+		marvel_env_refresh(data, &data->nodes[i]);
+	}
+
+	for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
+		enum hwmon_sensor_types type = marvel_env_types[k];
+
+		for (i = 0; i < data->nr_chans[type]; i++) {
+			struct marvel_env_chan *c = &data->chans[type][i];
+			unsigned long changed;
+			unsigned int attr;
+			u8 status;
+			u32 alarms;
+
+			if (!c->present)
+				continue;
+			status = marvel_env_status(type, c);
+			if (!env_status_valid(status))
+				continue;
+			alarms = marvel_env_alarms(type, c, status);
+			changed = alarms ^ c->alarms;
+			c->alarms = alarms;
+			for_each_set_bit(attr, &changed, 32)
+				hwmon_notify_event(data->hwmon, type, attr, i);
+		}
+	}
+}
+
+static void marvel_env_irq_work(struct irq_work *irq_work)
+{
+	struct marvel_env_data *data =
+		container_of(irq_work, struct marvel_env_data, irq_work);
+
+	schedule_work(&data->work);
+}
+
+/* Runs in machine check context, so only queue the irq_work. */
+static int marvel_env_event(struct notifier_block *nb, unsigned long action,
+			    void *unused)
+{
+	struct marvel_env_data *data =
+		container_of(nb, struct marvel_env_data, nb);
+
+	irq_work_queue(&data->irq_work);
+	return NOTIFY_OK;
+}
+
+static void marvel_env_unregister(void *arg)
+{
+	struct marvel_env_data *data = arg;
+
+	atomic_notifier_chain_unregister(&marvel_env_notifier, &data->nb);
+	irq_work_sync(&data->irq_work);
+	cancel_work_sync(&data->work);
+}
+
 static const struct hwmon_channel_info * const marvel_env_chip_info =
 	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL);
 
@@ -522,7 +597,6 @@ static int marvel_env_probe(struct platform_device *pdev)
 	const struct hwmon_channel_info **info;
 	struct marvel_env_data *data;
 	struct hwmon_chip_info *chip;
-	struct device *hwmon;
 	unsigned int i, k, nr_info = 0;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
@@ -591,9 +665,16 @@ static int marvel_env_probe(struct platform_device *pdev)
 	chip->ops = &marvel_env_ops;
 	chip->info = info;
 
-	hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data, chip,
-						     NULL);
-	return PTR_ERR_OR_ZERO(hwmon);
+	data->hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data,
+							   chip, NULL);
+	if (IS_ERR(data->hwmon))
+		return PTR_ERR(data->hwmon);
+
+	init_irq_work(&data->irq_work, marvel_env_irq_work);
+	INIT_WORK(&data->work, marvel_env_event_work);
+	data->nb.notifier_call = marvel_env_event;
+	atomic_notifier_chain_register(&marvel_env_notifier, &data->nb);
+	return devm_add_action_or_reset(dev, marvel_env_unregister, data);
 }
 
 static struct platform_driver marvel_env_driver = {

-- 
2.56.1


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

* Re: [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout
  2026-11-17  2:59 ` [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout Matt Turner
@ 2026-11-17 11:08   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:08 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> struct ev7_pal_environmental_subpacket does not match what the MBM and
> CMM firmware (V2.7) put in system event frames, which is:
>
>   +0   cabinet
>   +2   drawer
>   +8   PE (the power and environment node holding the sensor)
>   +10  sensor index
>   +14  state: 0 ok, 1 warning, 2 fault, 0xfffe unknown, 0xffff removed
>
> So the byte printed as "Condition" was half of the sensor index, and the
> state was never printed. Use the firmware's layout and print the state
> along with the sensor's key. This matches the frames in the error log of
> an ES47.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/alpha/include/asm/err_ev7.h | 16 ++++++++++++----
>  arch/alpha/kernel/err_marvel.c   | 28 +++++++++++++++++-----------
>  2 files changed, 29 insertions(+), 15 deletions(-)
>
> diff --git a/arch/alpha/include/asm/err_ev7.h b/arch/alpha/include/asm/err_ev7.h
> index ab17e6333764..5d30af0221fb 100644
> --- a/arch/alpha/include/asm/err_ev7.h
> +++ b/arch/alpha/include/asm/err_ev7.h
> @@ -147,17 +147,25 @@ struct ev7_pal_io_subpacket {
>   *        class PAL (14), type POWER_SUPPLY (14)
>   *        class PAL (14), type LAN (15)
>   *        class PAL (14), type HOT_PLUG (16)
> + *
> + * Cabinet, drawer, PE and sensor are the keys of the sensor's GCT packet.
>   */
>  struct ev7_pal_environmental_subpacket {
>         u16 cabinet;
>         u16 drawer;
>         u16 reserved1[2];
> -       u8 module_type;
> -       u8 unit_id;             /* unit reporting condition */
> -       u8 reserved2;
> -       u8 condition;           /* condition reported       */
> +       u16 pe;
> +       u16 sensor;
> +       u16 reserved2;
> +       u16 state;              /* EV7_ENV_STATE_* */
>  };
>
> +#define EV7_ENV_STATE_OK       0
> +#define EV7_ENV_STATE_WARNING  1
> +#define EV7_ENV_STATE_FAULT    2
> +#define EV7_ENV_STATE_UNKNOWN  0xfffe
> +#define EV7_ENV_STATE_REMOVED  0xffff
> +
>  /*
>   * Convert environmental type to index
>   */
> diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
> index c0c0ccefc467..85f7a56816ce 100644
> --- a/arch/alpha/kernel/err_marvel.c
> +++ b/arch/alpha/kernel/err_marvel.c
> @@ -21,6 +21,19 @@
>  #include "err_impl.h"
>  #include "proto.h"
>
> +static const char *
> +marvel_env_state(u16 state)
> +{
> +       switch (state) {
> +       case EV7_ENV_STATE_OK:          return "ok";
> +       case EV7_ENV_STATE_WARNING:     return "warning";
> +       case EV7_ENV_STATE_FAULT:       return "fault";
> +       case EV7_ENV_STATE_UNKNOWN:     return "unknown";
> +       case EV7_ENV_STATE_REMOVED:     return "removed";
> +       default:                        return "unrecognized";
> +       }
> +}
> +

After the reorder this sits outside the CONFIG_VERBOSE_MCHECK block but
is only used inside it until 2/7, so this patch alone warns with
VERBOSE_MCHECK=n (and fails with CONFIG_WERROR):

  arch/alpha/kernel/err_marvel.c:25:1: warning: 'marvel_env_state'
defined but not used [-Wunused-function]

Wrapping it in #ifdef CONFIG_VERBOSE_MCHECK here and dropping that in
2/7 with the other one fixes it.

Growing the struct to 16 bytes is safe, since
ev7_collect_logout_frame_subpackets() steps by each subpacket's own
length (err_ev7.c).

>  static void
>  marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
>  {
> @@ -50,17 +63,10 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
>                 if (!env)
>                         continue;
>
> -               printk("%s**%s event (cabinet %d, drawer %d)\n",
> -                      err_print_prefix,
> -                      ev_packets[i].name,
> -                      env->cabinet,
> -                      env->drawer);
> -               printk("%s   Module Type: 0x%x - Unit ID 0x%x - "
> -                      "Condition 0x%x\n",
> -                      err_print_prefix,
> -                      env->module_type,
> -                      env->unit_id,
> -                      env->condition);
> +               printk("%s**%s %s (cabinet %u, drawer %u, PE %u, sensor %u, state %#x)\n",
> +                      err_print_prefix, ev_packets[i].name,
> +                      marvel_env_state(env->state), env->cabinet,
> +                      env->drawer, env->pe, env->sensor, env->state);
>         }
>  #endif /* CONFIG_VERBOSE_MCHECK */
>  }
>
> --
> 2.56.1
>


Magnus

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

* Re: [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK
  2026-11-17  2:59 ` [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK Matt Turner
@ 2026-11-17 11:10   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:10 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> The service processors report temperature, fan, voltage and power supply
> alarms as system event (0x680) logout frames. The frame is already
> classified as reportable, but without CONFIG_VERBOSE_MCHECK only the
> header line reaches the log, which does not say which sensor or what
> happened. Print the subpackets unconditionally.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/alpha/kernel/err_marvel.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
> index 85f7a56816ce..46c521cea9a0 100644
> --- a/arch/alpha/kernel/err_marvel.c
> +++ b/arch/alpha/kernel/err_marvel.c
> @@ -37,7 +37,6 @@ marvel_env_state(u16 state)
>  static void
>  marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
>  {
> -#ifdef CONFIG_VERBOSE_MCHECK
>         struct ev7_pal_environmental_subpacket *env;
>         struct { int type; char *name; } ev_packets[] = {
>                 { EL_TYPE__PAL__ENV__AMBIENT_TEMPERATURE,
> @@ -68,7 +67,6 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets)
>                        marvel_env_state(env->state), env->cabinet,
>                        env->drawer, env->pe, env->sensor, env->state);
>         }
> -#endif /* CONFIG_VERBOSE_MCHECK */
>  }
>
>  static int
>
> --
> 2.56.1
>

Looks good to me:

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>

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

* Re: [PATCH v2 4/7] alpha: marvel: notify environmental events
  2026-11-17  2:59 ` [PATCH v2 4/7] alpha: marvel: notify environmental events Matt Turner
@ 2026-11-17 11:10   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:10 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> A change in the state of a sensor arrives as a system event logout
> frame. Call an atomic notifier chain on each one, so that a sensor
> driver can reread its sensors and tell userspace without polling.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/alpha/include/asm/marvel_env.h | 5 +++++
>  arch/alpha/kernel/err_marvel.c      | 9 ++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/include/asm/marvel_env.h b/arch/alpha/include/asm/marvel_env.h
> index 16ccd2002a11..dbbf827a18ad 100644
> --- a/arch/alpha/include/asm/marvel_env.h
> +++ b/arch/alpha/include/asm/marvel_env.h
> @@ -2,6 +2,8 @@
>  #ifndef __ALPHA_MARVEL_ENV_H
>  #define __ALPHA_MARVEL_ENV_H
>
> +#include <linux/notifier.h>
> +
>  /*
>   * Ask the console to refresh the environmental readings of the GCT node at
>   * @offset from the start of the GCT. Returns the console status, which is 1
> @@ -9,4 +11,7 @@
>   */
>  long marvel_cfgtree_partial_update(unsigned long offset);
>Reviewed-by: Magnus Lindholm <linmag7@gmail.com>Reviewed-by: Magnus Lindholm <linmag7@gmail.com>
> +/* Called from machine check context on each environmental system event. */
> +extern struct atomic_notifier_head marvel_env_notifier;
> +
>  #endif /* __ALPHA_MARVEL_ENV_H */
> diff --git a/arch/alpha/kernel/err_marvel.c b/arch/alpha/kernel/err_marvel.c
> index 46c521cea9a0..6e0b0aabdaca 100644
> --- a/arch/alpha/kernel/err_marvel.c
> +++ b/arch/alpha/kernel/err_marvel.c
> @@ -17,10 +17,14 @@
>  #include <asm/smp.h>
>  #include <asm/err_common.h>
>  #include <asm/err_ev7.h>
> +#include <asm/marvel_env.h>
>
>  #include "err_impl.h"
>  #include "proto.h"
>
> +ATOMIC_NOTIFIER_HEAD(marvel_env_notifier);
> +EXPORT_SYMBOL_GPL(marvel_env_notifier);
> +
>  static const char *
>  marvel_env_state(u16 state)
>  {
> @@ -82,8 +86,11 @@ marvel_process_680_frame(struct ev7_lf_subpackets *lf_subpackets, int print)
>                         status = MCHK_DISPOSITION_REPORT;
>         }
>
> -       if (print)
> +       /* The frame is processed twice; notify on the printing pass only. */
> +       if (print) {
>                 marvel_print_680_frame(lf_subpackets);
> +               atomic_notifier_call_chain(&marvel_env_notifier, 0, NULL);
> +       }
>
>         return status;
>  }
>
> --
> 2.56.1
>

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>

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

* Re: [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors
  2026-11-17  2:59 ` [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors Matt Turner
@ 2026-11-17 11:11   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:11 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> Register a "marvel_env" platform device on Marvel systems booted from
> SRM, for the hwmon driver to bind to.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/alpha/kernel/core_marvel.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
> index 7525f3ed6b62..169a1df6adb2 100644
> --- a/arch/alpha/kernel/core_marvel.c
> +++ b/arch/alpha/kernel/core_marvel.c
> @@ -21,6 +21,7 @@
>  #include <linux/module.h>
>  #include <linux/memblock.h>
>  #include <linux/workqueue.h>
> +#include <linux/platform_device.h>
>
>  #include <asm/ptrace.h>
>  #include <asm/smp.h>
> @@ -1139,3 +1140,13 @@ long marvel_cfgtree_partial_update(unsigned long offset)
>         return status;
>  }
>  EXPORT_SYMBOL_GPL(marvel_cfgtree_partial_update);
> +
> +static int __init marvel_env_init(void)
> +{
> +       if (alpha_mv.init_arch != marvel_init_arch || !alpha_using_srm)
> +               return 0;
> +
> +       return PTR_ERR_OR_ZERO(platform_device_register_simple("marvel_env",
> +                                                              -1, NULL, 0));
> +}
> +device_initcall(marvel_env_init);
>
> --
> 2.56.1
>

Looks good!

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>

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

* Re: [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console
  2026-11-17  2:59 ` [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console Matt Turner
@ 2026-11-17 11:17   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:17 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> The SRM console keeps the readings of the temperature, fan, voltage and
> power supply sensors in the power and environment (P&E) nodes of the
> config tree (GCT), and refreshes those of one node when asked through
> config tree callback 0x28, function 0x1f. The Alpha Architecture
> Reference Manual reserves every callback code it does not list, so this
> is a Marvel console extension; its code and function number come from
> Tru64 UNIX. Define CCB_CFGTREE in asm/console.h, and add the callback
> and marvel_cfgtree_partial_update() for a sensor driver to use,
> retrying, as Tru64 UNIX does, while the console reports busy.
>
> On an ES47 the callback takes 13 to 300 ms per node with interrupts
> disabled. The console callbacks are not reentrant: a refresh on one CPU
> while another printed to the SRM console killed the second CPU, and the
> service processor reset the partition. So export the srmcons callback
> lock and hold it around the call.
>
> Tru64 UNIX makes this and its other runtime config tree callbacks only on
> the master CPU, and the Marvel PAL TOY calls are already known to work
> only on the boot CPU, so make the call there as well.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/alpha/include/asm/console.h    |  5 +++++
>  arch/alpha/include/asm/marvel_env.h | 12 ++++++++++
>  arch/alpha/kernel/core_marvel.c     | 45 +++++++++++++++++++++++++++++++++++++
>  arch/alpha/kernel/proto.h           |  1 +
>  arch/alpha/kernel/srmcons.c         |  3 ++-
>  arch/alpha/lib/callback_srm.S       |  1 +
>  6 files changed, 66 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/include/asm/console.h b/arch/alpha/include/asm/console.h
> index 1cabdb6064bb..4f5cf589aff7 100644
> --- a/arch/alpha/include/asm/console.h
> +++ b/arch/alpha/include/asm/console.h
> @@ -4,6 +4,9 @@
>
>  #include <uapi/asm/console.h>
>
> +/* Not architected: a Marvel console extension, as used by Tru64 UNIX. */
> +#define CCB_CFGTREE            0x28
> +
>  #ifndef __ASSEMBLER__
>  extern long callback_puts(long unit, const char *s, long length);
>  extern long callback_getc(long unit);
> @@ -15,6 +18,8 @@ extern long callback_read(long channel, long count, const char *buf, long lbn);
>  extern long callback_getenv(long id, const char *buf, unsigned long buf_size);
>  extern long callback_setenv(long id, const char *buf, unsigned long buf_size);
>  extern long callback_save_env(void);
> +extern long callback_cfgtree(long func, unsigned long arg1, unsigned long arg2,
> +                            unsigned long arg3, unsigned long arg4);
>
>  extern int srm_fixup(unsigned long new_callback_addr,
>                      unsigned long new_hwrpb_addr);
> diff --git a/arch/alpha/include/asm/marvel_env.h b/arch/alpha/include/asm/marvel_env.h
> new file mode 100644
> index 000000000000..16ccd2002a11
> --- /dev/null
> +++ b/arch/alpha/include/asm/marvel_env.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __ALPHA_MARVEL_ENV_H
> +#define __ALPHA_MARVEL_ENV_H
> +
> +/*
> + * Ask the console to refresh the environmental readings of the GCT node at
> + * @offset from the start of the GCT. Returns the console status, which is 1
> + * or -0x4a on success.
> + */
> +long marvel_cfgtree_partial_update(unsigned long offset);
> +
> +#endif /* __ALPHA_MARVEL_ENV_H */
> diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marvel.c
> index 92e3312e786e..7525f3ed6b62 100644
> --- a/arch/alpha/kernel/core_marvel.c
> +++ b/arch/alpha/kernel/core_marvel.c
> @@ -20,10 +20,13 @@
>  #include <linux/string.h>
>  #include <linux/module.h>
>  #include <linux/memblock.h>
> +#include <linux/workqueue.h>
>
>  #include <asm/ptrace.h>
>  #include <asm/smp.h>
>  #include <asm/gct.h>
> +#include <asm/console.h>
> +#include <asm/marvel_env.h>
>  #include <asm/tlbflush.h>
>  #include <asm/vga.h>
>
> @@ -1094,3 +1097,45 @@ marvel_agp_info(void)
>
>         return agp;
>  }
> +
> +/*
> + * The console refreshes the environmental packets of a GCT node through
> + * config tree callback function 0x1f, returning -26 while it is busy. The
> + * callback runs for up to 300 ms with interrupts disabled. Hold the console
> + * callback lock: a concurrent callback from another CPU, such as SRM console
> + * output, kills that CPU. Make the call on the boot CPU, as Tru64 UNIX does
> + * for its config tree callbacks; the PAL TOY calls also work only there.
> + */
> +#define CFGTREE_PARTIAL_UPDATE 0x1f
> +#define CFGTREE_BUSY           (-26)
> +
> +static long marvel_cfgtree_partial_update_local(void *arg)
> +{
> +       unsigned long flags;
> +       long status;
> +
> +       spin_lock_irqsave(&srmcons_callback_lock, flags);
> +       status = callback_cfgtree(CFGTREE_PARTIAL_UPDATE, (unsigned long)arg,
> +                                 0, 0, 0);
> +       spin_unlock_irqrestore(&srmcons_callback_lock, flags);
> +
> +       return status;
> +}
> +
> +long marvel_cfgtree_partial_update(unsigned long offset)
> +{
> +       long status;
> +       int tries;
> +
> +       for (tries = 0; tries < 100; tries++) {
> +               status = work_on_cpu(boot_cpuid,
> +                                    marvel_cfgtree_partial_update_local,
> +                                    (void *)offset);
> +               if (status != CFGTREE_BUSY)
> +                       break;
> +               usleep_range(10000, 20000);
> +       }
> +
> +       return status;
> +}
> +EXPORT_SYMBOL_GPL(marvel_cfgtree_partial_update);
> diff --git a/arch/alpha/kernel/proto.h b/arch/alpha/kernel/proto.h
> index c418333d0b89..b54f4fd69a0f 100644
> --- a/arch/alpha/kernel/proto.h
> +++ b/arch/alpha/kernel/proto.h
> @@ -112,6 +112,7 @@ extern struct screen_info vgacon_screen_info;
>
>  /* srmcons.c */
>  #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
> +extern spinlock_t srmcons_callback_lock;

This breaks a Marvel kernel without SRM:

  arch/alpha/kernel/core_marvel.c:1118:28: error:
'srmcons_callback_lock' undeclared

That config needs EXPERT=y and TTY=n (ALPHA_SRM has no prompt on Marvel
and depends on TTY), so only randconfig will hit it, but the bots do
build those. You're right that the call is unreachable at run time;
the alpha_using_srm check is what let the compiler drop it, since it is
the constant 0 there (asm/machvec.h). Putting it back, with the extern
before the #if as in v1, builds for me with and without SRM.

Magnus

>  extern void register_srm_console(void);
>  extern void unregister_srm_console(void);
>  #else
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index d19e51ec711d..45a10d539f19 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -24,7 +24,8 @@
>  #include "proto.h"
>
>
> -static DEFINE_SPINLOCK(srmcons_callback_lock);
> +/* The console callbacks are not reentrant. */
> +DEFINE_SPINLOCK(srmcons_callback_lock);
>  static int srm_is_registered_console = 0;
>
>  /*
> diff --git a/arch/alpha/lib/callback_srm.S b/arch/alpha/lib/callback_srm.S
> index 36b63f295170..6d3c9ce6b815 100644
> --- a/arch/alpha/lib/callback_srm.S
> +++ b/arch/alpha/lib/callback_srm.S
> @@ -94,6 +94,7 @@ CALLBACK(reset_env, CCB_RESET_ENV, 4)
>  CALLBACK(save_env, CCB_SAVE_ENV, 1)
>  CALLBACK(pswitch, CCB_PSWITCH, 3)
>  CALLBACK(bios_emul, CCB_BIOS_EMUL, 5)
> +CALLBACK(cfgtree, CCB_CFGTREE, 6)
>
>  EXPORT_SYMBOL(callback_getenv)
>  EXPORT_SYMBOL(callback_setenv)
>
> --
> 2.56.1
>

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

* Re: [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
  2026-11-17  2:59 ` [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer " Matt Turner
@ 2026-11-17 11:27   ` Magnus Lindholm
  2026-11-17 16:13   ` Guenter Roeck
  1 sibling, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:27 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,


On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> The management firmware of the Marvel (EV7) AlphaServers, the GS1280,
> ES80 and ES47, monitors temperatures, fans, voltages and power supplies.
> The SRM console describes each sensor as a packet in a power and
> environment node of its config tree (GCT), and fills in the readings
> when asked to refresh the node. The packet layout was taken from Tru64
> UNIX.
>
> The firmware gives each temperature, fan and voltage sensor a warning
> limit and a failure limit, and reports the sensor in the warning or
> failure state once its reading reaches one. Neither state means that the
> sensor is broken: a temperature past its failure limit is too high, not
> faulty. Power supplies are either working or failed, with the cause
> (AC, POK, overtemperature, fan) logged by the firmware.
>
> Export the sensors through hwmon. A temperature's warning and failure
> limits become max and crit, with max_alarm set in either state and
> crit_alarm in the failure state. A fan's warning limit becomes min, with
> min_alarm set in either state and fault in the failure state, which is
> when the firmware counts the fan as failed. A voltage exports its
> reading, with min_alarm or max_alarm set in either state and lcrit_alarm
> or crit_alarm in the failure state, depending on which side of its
> nominal voltage it reads. The console gives the nominal voltage and only
> one other limit, so the voltage limits are not exported. A power supply
> is a voltage channel with only a fault attribute.
>
> A refresh keeps the boot CPU in the console with interrupts disabled for
> up to 300 ms per node, so refresh a node at most once per
> update_interval. The hwmon core serializes the callbacks, which also
> serializes the refreshes.
>
> The console callback lives in core_marvel.o, which generic kernels
> built with ALPHA_LEGACY_START_ADDRESS leave out.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  Documentation/hwmon/index.rst      |   1 +
>  Documentation/hwmon/marvel-env.rst |  72 +++++
>  MAINTAINERS                        |   8 +
>  arch/alpha/include/asm/gct.h       |   2 +
>  drivers/hwmon/Kconfig              |  11 +
>  drivers/hwmon/Makefile             |   1 +
>  drivers/hwmon/marvel-env.c         | 609 +++++++++++++++++++++++++++++++++++++
>  7 files changed, 704 insertions(+)
>
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 199ca79621e9..b062ad1ff53f 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers
>     ltc4286
>     lx1308
>     macsmc-hwmon
> +   marvel-env
>     max127
>     max15301
>     max16064
> diff --git a/Documentation/hwmon/marvel-env.rst b/Documentation/hwmon/marvel-env.rst
> new file mode 100644
> index 000000000000..7e0457a60094
> --- /dev/null
> +++ b/Documentation/hwmon/marvel-env.rst
> @@ -0,0 +1,72 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver marvel-env
> +========================
> +
> +Supported systems:
> +
> +  * Marvel (EV7) AlphaServers: the GS1280, ES80 and ES47 families,
> +    booted from the SRM console
> +
> +Author: Matt Turner <mattst88@gmail.com>
> +
> +Description
> +-----------
> +
> +The management firmware of these machines monitors temperatures, fans,
> +voltages and power supplies, and the SRM console describes each sensor in
> +its configuration tree (GCT). This driver asks the console to refresh the
> +readings and exports them.
> +
> +The console has no sensor names, so the labels are built from the reporting
> +unit (such as ``CMM0`` or ``MBM/PBM``) and the sensor's position in that
> +unit. On systems with more than one drawer the label starts with the
> +cabinet and drawer numbers.
> +
> +A refresh keeps the boot CPU in the console with interrupts disabled for up
> +to 300 ms per unit, so a unit is refreshed at most once every
> +``update_interval`` milliseconds (10000 by default).
> +
> +Sysfs entries
> +-------------
> +
> +The management firmware gives each temperature, fan and voltage sensor a
> +warning limit and a failure limit, and reports the sensor in the warning or
> +failure state when its reading reaches the limit. Neither state means that
> +the sensor is broken. Power supplies have no warning state and are reported
> +as voltage channels that only have a fault attribute.
> +
> +=========================== =================================================
> +``update_interval``         Minimum time between refreshes of a unit, in ms
> +
> +``temp[1-*]_input``         Temperature
> +``temp[1-*]_max``           Warning limit
> +``temp[1-*]_crit``          Failure limit
> +``temp[1-*]_max_alarm``     Temperature reached the warning limit
> +``temp[1-*]_crit_alarm``    Temperature reached the failure limit
> +``temp[1-*]_label``         Sensor label
> +
> +``fan[1-*]_input``          Fan speed
> +``fan[1-*]_min``            Warning limit
> +``fan[1-*]_min_alarm``      Fan speed dropped to the warning limit
> +``fan[1-*]_fault``          Fan speed dropped to the failure limit, and the
> +                            firmware counts the fan as failed
> +``fan[1-*]_label``          Fan label
> +
> +``in[0-*]_input``           Voltage
> +``in[0-*]_min_alarm``       Voltage is below the warning limit
> +``in[0-*]_max_alarm``       Voltage is above the warning limit
> +``in[0-*]_lcrit_alarm``     Voltage is below the failure limit
> +``in[0-*]_crit_alarm``      Voltage is above the failure limit
> +``in[0-*]_fault``           Power supply has failed
> +``in[0-*]_label``           Sensor or power supply label
> +=========================== =================================================
> +
> +The firmware checks a voltage against limits on both sides of the nominal
> +voltage, but the console only describes the nominal voltage and one other
> +limit, so the voltage limits are not exported. Whether a voltage is too low
> +or too high comes from comparing it with the nominal voltage.
> +
> +Sensors that the console reports as unknown or not present when the driver
> +loads are not exported. If a sensor becomes unknown later, reading its input,
> +alarm or fault attribute fails with ``-ENODATA``.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 93abbb315065..09dee8fab9ec 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -16100,6 +16100,14 @@ L:     linux-mips@vger.kernel.org
>  S:     Maintained
>  F:     arch/mips/boot/dts/img/pistachio*
>
> +MARVEL ALPHASERVER ENVIRONMENTAL SENSOR DRIVER
> +M:     Matt Turner <mattst88@gmail.com>
> +L:     linux-hwmon@vger.kernel.org
> +L:     linux-alpha@vger.kernel.org
> +S:     Maintained
> +F:     Documentation/hwmon/marvel-env.rst
> +F:     drivers/hwmon/marvel-env.c
> +
>  MARVELL 88E6XXX ETHERNET SWITCH FABRIC DRIVER
>  M:     Andrew Lunn <andrew@lunn.ch>
>  L:     netdev@vger.kernel.org
> diff --git a/arch/alpha/include/asm/gct.h b/arch/alpha/include/asm/gct.h
> index 2847449fb168..afa7ed870bd1 100644
> --- a/arch/alpha/include/asm/gct.h
> +++ b/arch/alpha/include/asm/gct.h
> @@ -43,11 +43,13 @@ typedef struct {
>   * node types
>   */
>  #define GCT_TYPE_HOSE                  0x0E
> +#define GCT_TYPE_PE                    0x13    /* power and environment */
>
>  /*
>   * node subtypes
>   */
>  #define GCT_SUBTYPE_IO_PORT_MODULE     0x2C
> +#define GCT_SUBTYPE_PE_CABINET         0x3D    /* id holds an 8-bit cabinet */
>
>  #define GCT_NODE_PTR(off) ((gct6_node *)((char *)hwrpb +               \
>                                          hwrpb->frut_offset +           \
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 18c682e1a475..c0ce5591c82d 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1255,6 +1255,17 @@ config SENSORS_MACSMC_HWMON
>           This driver can also be built as a module. If so, the module will
>           be called macsmc-hwmon.
>
> +config SENSORS_MARVEL_ENV
> +       tristate "Marvel (EV7) AlphaServer environmental sensors"
> +       depends on ALPHA_MARVEL || (ALPHA_GENERIC && !ALPHA_LEGACY_START_ADDRESS)
> +       help
> +         If you say yes here you get support for the temperature, fan,
> +         voltage and power supply sensors of Marvel AlphaServers (the
> +         GS1280, ES80 and ES47), as described by the SRM console.
> +
> +         This driver can also be built as a module. If so, the module
> +         will be called marvel-env.
> +
>  config SENSORS_MAX1111
>         tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
>         depends on SPI_MASTER
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index d4c345ed7261..2b1b1850d641 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -157,6 +157,7 @@ obj-$(CONFIG_SENSORS_LTC4282)       += ltc4282.o
>  obj-$(CONFIG_SENSORS_LTC4283)  += ltc4283.o
>  obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
>  obj-$(CONFIG_SENSORS_MACSMC_HWMON)     += macsmc-hwmon.o
> +obj-$(CONFIG_SENSORS_MARVEL_ENV)       += marvel-env.o
>  obj-$(CONFIG_SENSORS_MAX1111)  += max1111.o
>  obj-$(CONFIG_SENSORS_MAX127)   += max127.o
>  obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
> diff --git a/drivers/hwmon/marvel-env.c b/drivers/hwmon/marvel-env.c
> new file mode 100644
> index 000000000000..e501e049d702
> --- /dev/null
> +++ b/drivers/hwmon/marvel-env.c
> @@ -0,0 +1,609 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Environmental sensors of Marvel (EV7) AlphaServers: the GS1280, ES80 and
> + * ES47 families.
> + *
> + * The SRM console describes every sensor in the config tree (GCT). Each power
> + * and environment (P&E) node may carry a list of environmental packets:
> + * temperature and voltage sensors, fans and power supplies. The console fills
> + * in the readings when asked to refresh the node. The packet layout was
> + * taken from Tru64 UNIX.
> + *
> + * The management firmware gives each temperature, voltage and fan sensor a
> + * warning limit and a failure limit, and puts the sensor in the warning or
> + * failure state when its reading reaches the limit. Neither state means that
> + * the sensor itself is broken. A power supply has no warning state; it is
> + * either working or failed.
> + */
> +
> +#include <linux/hwmon.h>
> +#include <linux/jiffies.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +
> +#include <asm/gct.h>
> +#include <asm/marvel_env.h>
> +
> +#define DRVNAME "marvel_env"
> +
> +#define GCT_FLAGS_REQUIRED     BIT(9)
> +#define GCT_FLAGS_EXCLUDED     (BIT(2) | BIT(7) | BIT(12) | BIT(14))
> +
> +/* Header of a P&E node's packet list, at hd_extension. */
> +#define ENV_HDR_COUNT          0x10
> +#define ENV_HDR_FIRST          0x14
> +#define ENV_HDR_SIZE           0x18
> +
> +/* Packet types. */
> +#define ENV_PKT_POWER_SUPPLY   0x08
> +#define ENV_PKT_FAN            0x09
> +#define ENV_PKT_SENSOR         0x2a
> +
> +/*
> + * Sensor packet: kind, status, reading, and two limits. Temperatures are in
> + * tenths of a degree Celsius, voltages in millivolts. For a temperature the
> + * two values are the warning and failure limits. For a voltage they are the
> + * nominal voltage and an upper limit; the firmware checks a voltage against
> + * a window on both sides of the nominal voltage, so neither is exported.
> + */
> +#define SENSOR_KIND            0x28
> +#define SENSOR_STATUS          0x2c
> +#define SENSOR_VALUE           0x30
> +#define SENSOR_WARN            0x34
> +#define SENSOR_FAIL            0x38
> +#define SENSOR_NOMINAL         SENSOR_WARN     /* of a voltage */
> +#define SENSOR_SIZE            0x3c
> +
> +#define SENSOR_KIND_THERMAL    2
> +#define SENSOR_KIND_VOLT_FIRST 3
> +#define SENSOR_KIND_VOLT_LAST  5
> +
> +/* Fan packet: status, rpm, low warning limit, low failure limit. */
> +#define FAN_STATUS             0x24
> +#define FAN_VALUE              0x28
> +#define FAN_WARN               0x2c
> +#define FAN_SIZE               0x34
> +
> +/* Power supply packet: status. */
> +#define PS_STATUS              0x24
> +#define PS_SIZE                        0x28
> +
> +/* Status values, in the low byte of the status word. */
> +#define ENV_OK                 0
> +#define ENV_WARNING            1       /* reading reached the warning limit */
> +#define ENV_FAILURE            2       /* reading reached the failure limit */
> +#define ENV_UNKNOWN            0xfe
> +#define ENV_NOT_PRESENT                0xff
> +
> +/* Console status of a refresh that Tru64 also treats as success. */
> +#define CFGTREE_STATUS_OK2     (-0x4a)
> +
> +struct marvel_env_node {
> +       gct6_node *node;
> +       unsigned long offset;           /* from the start of the GCT */
> +       unsigned long last_refresh;
> +       bool valid;
> +       unsigned int cabinet, drawer, pe;
> +};
> +
> +struct marvel_env_chan {
> +       struct marvel_env_node *node;
> +       unsigned int pkt;               /* packet offset in the node */
> +       bool ps;                        /* power supply, as an in channel */
> +       bool present;                   /* known when the driver loaded */
> +       char label[32];
> +};
> +
> +struct marvel_env_data {
> +       struct device *dev;
> +       unsigned int update_interval;   /* ms */
> +       struct marvel_env_node *nodes;
> +       unsigned int nr_nodes;
> +       struct marvel_env_chan *chans[hwmon_max];
> +       unsigned int nr_chans[hwmon_max];
> +};
> +
> +static const char * const pe_names[] = {
> +       [0x09] = "MBM",
> +       [0x0a] = "MBM/PBM",
> +       [0x0c] = "PS",
> +       [0x0d] = "FAN",
> +       [0x0f] = "CMM0", [0x10] = "CMM1", [0x11] = "CMM2", [0x12] = "CMM3",
> +       [0x14] = "VRM0", [0x15] = "VRM1", [0x16] = "VRM2", [0x17] = "VRM3",
> +       [0x19] = "PBM",
> +       [0x1a] = "XSHELF",
> +       [0x1b] = "PCIPS",
> +       [0x1c] = "PCIFANS",
> +};
> +
> +/* The sensor types the driver exports. */
> +static const enum hwmon_sensor_types marvel_env_types[] = {
> +       hwmon_temp, hwmon_fan, hwmon_in,
> +};
> +
> +/* The attributes that report the state of a channel. */
> +static const u32 marvel_env_alarm_attrs[hwmon_max] = {
> +       [hwmon_temp] = HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM,
> +       [hwmon_fan] = HWMON_F_MIN_ALARM | HWMON_F_FAULT,
> +       [hwmon_in] = HWMON_I_MIN_ALARM | HWMON_I_MAX_ALARM |
> +                    HWMON_I_LCRIT_ALARM | HWMON_I_CRIT_ALARM | HWMON_I_FAULT,
> +};
> +
> +static inline u32 env_rd(struct marvel_env_node *n, unsigned int off)
> +{
> +       return *(u32 *)((char *)n->node + off);
> +}
> +
> +static bool env_status_valid(u8 status)
> +{
> +       return status != ENV_UNKNOWN && status != ENV_NOT_PRESENT;
> +}
> +
> +static u8 marvel_env_status(enum hwmon_sensor_types type,
> +                           const struct marvel_env_chan *c)
> +{
> +       unsigned int off;
> +
> +       if (type == hwmon_fan)
> +               off = FAN_STATUS;
> +       else if (c->ps)
> +               off = PS_STATUS;
> +       else
> +               off = SENSOR_STATUS;
> +       return env_rd(c->node, c->pkt + off) & 0xff;
> +}
> +
> +/*
> + * The alarm attributes that are set in @status. A reading past the failure
> + * limit is also past the warning limit, so it sets both alarms. A fan below
> + * its failure limit is one the firmware counts as failed. A voltage outside
> + * its limits is too low or too high depending on which side of the nominal
> + * voltage it reads.
> + */
> +static u32 marvel_env_alarms(enum hwmon_sensor_types type,
> +                            const struct marvel_env_chan *c, u8 status)
> +{
> +       switch (type) {
> +       case hwmon_temp:
> +               if (status == ENV_FAILURE)
> +                       return HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM;
> +               if (status == ENV_WARNING)
> +                       return HWMON_T_MAX_ALARM;
> +               break;
> +       case hwmon_fan:
> +               if (status == ENV_FAILURE)
> +                       return HWMON_F_MIN_ALARM | HWMON_F_FAULT;
> +               if (status == ENV_WARNING)
> +                       return HWMON_F_MIN_ALARM;
> +               break;
> +       case hwmon_in:
> +               if (c->ps)
> +                       return status == ENV_FAILURE ? HWMON_I_FAULT : 0;
> +               if (status != ENV_WARNING && status != ENV_FAILURE)
> +                       break;
> +               if ((s32)env_rd(c->node, c->pkt + SENSOR_VALUE) <
> +                   (s32)env_rd(c->node, c->pkt + SENSOR_NOMINAL)) {
> +                       if (status == ENV_FAILURE)
> +                               return HWMON_I_MIN_ALARM | HWMON_I_LCRIT_ALARM;
> +                       return HWMON_I_MIN_ALARM;
> +               }
> +               if (status == ENV_FAILURE)
> +                       return HWMON_I_MAX_ALARM | HWMON_I_CRIT_ALARM;
> +               return HWMON_I_MAX_ALARM;
> +       default:
> +               break;
> +       }
> +       return 0;
> +}
> +
> +static inline gct6_node *gct_node(gct6_handle h)
> +{
> +       return GCT_NODE_PTR(h);
> +}
> +
> +/* Cabinet and drawer come from the P&E node's parent. */
> +static void marvel_env_keys(struct marvel_env_node *n)
> +{
> +       gct6_node *parent = n->node->parent ? gct_node(n->node->parent) : NULL;
> +
> +       n->pe = n->node->id & 0xff;
> +       if (!parent)
> +               return;
> +       if (parent->type == GCT_TYPE_PE && parent->subtype == GCT_SUBTYPE_PE_CABINET)
> +               n->cabinet = (parent->id >> 48) & 0xff;
> +       else
> +               n->cabinet = (parent->id >> 48) & 0x3f;
> +       n->drawer = (parent->id >> 32) & 0xff;
> +}
> +
> +static int marvel_env_refresh(struct marvel_env_data *data,
> +                             struct marvel_env_node *n)
> +{
> +       long status;
> +
> +       if (n->valid && time_before(jiffies, n->last_refresh +
> +                                   msecs_to_jiffies(data->update_interval)))
> +               return 0;
> +
> +       status = marvel_cfgtree_partial_update(n->offset);
> +       if (status != 1 && status != CFGTREE_STATUS_OK2) {
> +               dev_warn_ratelimited(data->dev,
> +                                    "refresh of GCT node %#lx failed: %ld\n",
> +                                    n->offset, status);
> +               return -EIO;
> +       }
> +       n->last_refresh = jiffies;
> +       n->valid = true;
> +       return 0;
> +}
> +
> +/* The hwmon type of a packet, or hwmon_max to skip it. */
> +static enum hwmon_sensor_types marvel_env_pkt_type(struct marvel_env_node *n,
> +                                                  unsigned int pkt,
> +                                                  unsigned int type)
> +{
> +       unsigned int len = env_rd(n, pkt) & 0xffff;
> +       u32 kind;
> +
> +       switch (type) {
> +       case ENV_PKT_SENSOR:
> +               if (len < SENSOR_SIZE)
> +                       break;
> +               kind = env_rd(n, pkt + SENSOR_KIND);
> +               if (kind == SENSOR_KIND_THERMAL)
> +                       return hwmon_temp;
> +               if (kind >= SENSOR_KIND_VOLT_FIRST && kind <= SENSOR_KIND_VOLT_LAST)
> +                       return hwmon_in;
> +               break;
> +       case ENV_PKT_FAN:
> +               if (len >= FAN_SIZE)
> +                       return hwmon_fan;
> +               break;
> +       case ENV_PKT_POWER_SUPPLY:
> +               if (len >= PS_SIZE)
> +                       return hwmon_in;
> +               break;
> +       }
> +       return hwmon_max;
> +}
> +
> +static void marvel_env_add_chan(struct marvel_env_data *data,
> +                               struct marvel_env_node *n, unsigned int pkt,
> +                               enum hwmon_sensor_types type, bool ps,
> +                               unsigned int index)
> +{
> +       static const char * const names[hwmon_max] = {
> +               [hwmon_temp] = "Temp", [hwmon_fan] = "Fan", [hwmon_in] = "Volt",
> +       };
> +       const char *what = ps ? "PS" : names[type];
> +       struct marvel_env_chan *c;
> +       const char *pe = NULL;
> +       size_t len = 0;
> +       u8 status;
> +
> +       c = &data->chans[type][data->nr_chans[type]++];

Minor: nothing checks this against the first pass's count. Both walks
read the same GCT, but a bounds check is cheap.

> +       c->node = n;
> +       c->pkt = pkt;
> +       c->ps = ps;
> +       status = marvel_env_status(type, c);
> +       c->present = env_status_valid(status);
> +
> +       if (n->cabinet || n->drawer)

This tests the node's own position, so on a multi-drawer system the
cabinet 0, drawer 0 units get no prefix. Either decide once in probe
whether any node is outside cabinet 0, drawer 0, or reword the doc.

> +               len = scnprintf(c->label, sizeof(c->label), "Cab%u Dra%u ",
> +                               n->cabinet, n->drawer);
> +
> +       if (n->pe < ARRAY_SIZE(pe_names))
> +               pe = pe_names[n->pe];
> +       if (pe && !strncasecmp(pe, what, strlen(what)))
> +               scnprintf(c->label + len, sizeof(c->label) - len, "%s %u",
> +                         pe, index);
> +       else if (pe)
> +               scnprintf(c->label + len, sizeof(c->label) - len, "%s %s %u",
> +                         pe, what, index);
> +       else
> +               scnprintf(c->label + len, sizeof(c->label) - len, "PE%u %s %u",
> +                         n->pe, what, index);
> +}
> +
> +/*
> + * Walk a P&E node's packets, counting them, or adding them when @add. As
> + * Tru64 does, visit count + 1 packets and number sensors from their
> + * position minus one.
> + */
> +static void marvel_env_walk(struct marvel_env_data *data,
> +                           struct marvel_env_node *n, bool add)
> +{
> +       unsigned int size = n->node->size;
> +       unsigned int hdr = n->node->hd_extension;
> +       unsigned int count, pkt, i;
> +
> +       if (!hdr || hdr + ENV_HDR_SIZE > size)
> +               return;
> +       count = env_rd(n, hdr + ENV_HDR_COUNT);
> +       pkt = env_rd(n, hdr + ENV_HDR_FIRST);
> +
> +       for (i = 0; i <= count; i++) {
> +               enum hwmon_sensor_types type;
> +               unsigned int len, pkt_type;
> +
> +               if (pkt < 8 || pkt + 8 > size)
> +                       break;
> +               len = env_rd(n, pkt) & 0xffff;
> +               pkt_type = env_rd(n, pkt + 4) & 0xffff;
> +               if (len < 8 || pkt + len > size)
> +                       break;
> +
> +               type = marvel_env_pkt_type(n, pkt, pkt_type);
> +               if (type != hwmon_max && add)
> +                       marvel_env_add_chan(data, n, pkt, type,
> +                                           pkt_type == ENV_PKT_POWER_SUPPLY,
> +                                           pkt_type == ENV_PKT_SENSOR && i ?
> +                                           i - 1 : i);
> +               else if (type != hwmon_max)
> +                       data->nr_chans[type]++;
> +               pkt += len;
> +       }
> +}
> +
> +/* Collect the P&E nodes with an environmental packet list. */
> +static void marvel_env_find_nodes(struct marvel_env_data *data,
> +                                 gct6_node *node, bool record)
> +{
> +       for (; node; node = node->next ? gct_node(node->next) : NULL) {
> +               if (node->magic != GCT_NODE_MAGIC)
> +                       return;
> +               if (node->type == GCT_TYPE_PE && node->hd_extension &&
> +                   (node->flags & GCT_FLAGS_REQUIRED) &&
> +                   !(node->flags & GCT_FLAGS_EXCLUDED)) {
> +                       if (record) {
> +                               struct marvel_env_node *n =
> +                                       &data->nodes[data->nr_nodes];
> +
> +                               n->node = node;
> +                               n->offset = (char *)node - (char *)gct_node(0);
> +                               marvel_env_keys(n);
> +                       }
> +                       data->nr_nodes++;
> +               }
> +               if (node->child)
> +                       marvel_env_find_nodes(data, gct_node(node->child),
> +                                             record);
> +       }
> +}
> +
> +static umode_t marvel_env_is_visible(const void *drvdata,
> +                                    enum hwmon_sensor_types type,
> +                                    u32 attr, int channel)
> +{
> +       const struct marvel_env_data *data = drvdata;
> +
> +       if (type == hwmon_chip)
> +               return 0644;
> +
> +       /* Hide sensors that are absent when the driver loads. */
> +       return data->chans[type][channel].present ? 0444 : 0;
> +}
> +
> +/* Called with the hwmon device lock held, which serializes refreshes. */
> +static int marvel_env_read(struct device *dev, enum hwmon_sensor_types type,
> +                          u32 attr, int channel, long *val)
> +{
> +       struct marvel_env_data *data = dev_get_drvdata(dev);
> +       struct marvel_env_chan *c;
> +       struct marvel_env_node *n;
> +       unsigned int pkt;
> +       u8 status;
> +       int ret;
> +
> +       if (type == hwmon_chip) {
> +               *val = data->update_interval;
> +               return 0;
> +       }
> +
> +       c = &data->chans[type][channel];
> +       n = c->node;
> +       pkt = c->pkt;
> +
> +       ret = marvel_env_refresh(data, n);
> +       if (ret)
> +               return ret;
> +       status = marvel_env_status(type, c);
> +
> +       switch (type) {
> +       case hwmon_temp:
> +               switch (attr) {
> +               case hwmon_temp_max:
> +                       *val = (s32)env_rd(n, pkt + SENSOR_WARN) * 100L;
> +                       return 0;
> +               case hwmon_temp_crit:
> +                       *val = (s32)env_rd(n, pkt + SENSOR_FAIL) * 100L;
> +                       return 0;
> +               }
> +               break;
> +       case hwmon_fan:
> +               if (attr == hwmon_fan_min) {
> +                       *val = env_rd(n, pkt + FAN_WARN);
> +                       return 0;
> +               }
> +               break;
> +       default:
> +               break;
> +       }
> +
> +       if (!env_status_valid(status))
> +               return -ENODATA;
> +
> +       if (marvel_env_alarm_attrs[type] & BIT(attr)) {
> +               *val = !!(marvel_env_alarms(type, c, status) & BIT(attr));
> +               return 0;
> +       }
> +
> +       switch (type) {
> +       case hwmon_temp:
> +               if (attr != hwmon_temp_input)
> +                       break;
> +               *val = (s32)env_rd(n, pkt + SENSOR_VALUE) * 100L;
> +               return 0;
> +       case hwmon_fan:
> +               if (attr != hwmon_fan_input)
> +                       break;
> +               *val = env_rd(n, pkt + FAN_VALUE);
> +               return 0;
> +       case hwmon_in:
> +               if (attr != hwmon_in_input)
> +                       break;
> +               *val = (s32)env_rd(n, pkt + SENSOR_VALUE);
> +               return 0;
> +       default:
> +               break;
> +       }
> +       return -EOPNOTSUPP;
> +}
> +
> +static int marvel_env_write(struct device *dev, enum hwmon_sensor_types type,
> +                           u32 attr, int channel, long val)
> +{
> +       struct marvel_env_data *data = dev_get_drvdata(dev);
> +
> +       if (type != hwmon_chip || attr != hwmon_chip_update_interval)
> +               return -EOPNOTSUPP;
> +
> +       data->update_interval = clamp_val(val, 0, 3600 * MSEC_PER_SEC);
> +       return 0;
> +}

At 0 every attribute read refreshes its node, which is up to 300 ms
with interrupts off on the boot CPU, so a single "sensors" run can take
seconds. A floor of, say, 1000 ms would prevent that.

> +
> +static int marvel_env_read_string(struct device *dev,
> +                                 enum hwmon_sensor_types type, u32 attr,
> +                                 int channel, const char **str)
> +{
> +       struct marvel_env_data *data = dev_get_drvdata(dev);
> +
> +       *str = data->chans[type][channel].label;
> +       return 0;
> +}
> +
> +static const struct hwmon_ops marvel_env_ops = {
> +       .is_visible = marvel_env_is_visible,
> +       .read = marvel_env_read,
> +       .write = marvel_env_write,
> +       .read_string = marvel_env_read_string,
> +};
> +
> +static u32 marvel_env_config(enum hwmon_sensor_types type,
> +                            const struct marvel_env_chan *c)
> +{
> +       switch (type) {
> +       case hwmon_temp:
> +               return HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
> +                      HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_LABEL;
> +       case hwmon_fan:
> +               return HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_MIN_ALARM |
> +                      HWMON_F_FAULT | HWMON_F_LABEL;
> +       case hwmon_in:
> +               if (c->ps)
> +                       return HWMON_I_FAULT | HWMON_I_LABEL;
> +               return HWMON_I_INPUT | HWMON_I_MIN_ALARM | HWMON_I_MAX_ALARM |
> +                      HWMON_I_LCRIT_ALARM | HWMON_I_CRIT_ALARM | HWMON_I_LABEL;
> +       default:
> +               return 0;
> +       }
> +}
> +
> +static const struct hwmon_channel_info * const marvel_env_chip_info =
> +       HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL);
> +
> +static int marvel_env_probe(struct platform_device *pdev)
> +{
> +       u32 *config[hwmon_max] = { };
> +       struct device *dev = &pdev->dev;
> +       const struct hwmon_channel_info **info;
> +       struct marvel_env_data *data;
> +       struct hwmon_chip_info *chip;
> +       struct device *hwmon;
> +       unsigned int i, k, nr_info = 0;
> +
> +       data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> +       if (!data)
> +               return -ENOMEM;
> +       data->dev = dev;
> +       data->update_interval = 10 * MSEC_PER_SEC;
> +
> +       marvel_env_find_nodes(data, gct_node(0), false);
> +       if (!data->nr_nodes)
> +               return -ENODEV;
> +       data->nodes = devm_kcalloc(dev, data->nr_nodes, sizeof(*data->nodes),
> +                                  GFP_KERNEL);
> +       if (!data->nodes)
> +               return -ENOMEM;
> +       data->nr_nodes = 0;
> +       marvel_env_find_nodes(data, gct_node(0), true);
> +
> +       for (i = 0; i < data->nr_nodes; i++) {
> +               marvel_env_refresh(data, &data->nodes[i]);
> +               marvel_env_walk(data, &data->nodes[i], false);
> +       }
> +
> +       info = devm_kcalloc(dev, ARRAY_SIZE(marvel_env_types) + 2,
> +                           sizeof(*info), GFP_KERNEL);
> +       if (!info)
> +               return -ENOMEM;
> +       info[nr_info++] = marvel_env_chip_info;
> +
> +       for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
> +               enum hwmon_sensor_types type = marvel_env_types[k];
> +               struct hwmon_channel_info *ci;
> +
> +               if (!data->nr_chans[type])
> +                       continue;
> +               data->chans[type] = devm_kcalloc(dev, data->nr_chans[type],
> +                                                sizeof(*data->chans[type]),
> +                                                GFP_KERNEL);
> +               ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
> +               config[type] = devm_kcalloc(dev, data->nr_chans[type] + 1,
> +                                           sizeof(*config[type]), GFP_KERNEL);
> +               if (!data->chans[type] || !ci || !config[type])
> +                       return -ENOMEM;
> +               ci->type = type;
> +               ci->config = config[type];
> +               info[nr_info++] = ci;
> +               data->nr_chans[type] = 0;
> +       }
> +       if (nr_info == 1)
> +               return -ENODEV;
> +
> +       for (i = 0; i < data->nr_nodes; i++)
> +               marvel_env_walk(data, &data->nodes[i], true);
> +
> +       for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
> +               enum hwmon_sensor_types type = marvel_env_types[k];
> +
> +               for (i = 0; i < data->nr_chans[type]; i++)
> +                       config[type][i] = marvel_env_config(type,
> +                                                           &data->chans[type][i]);
> +       }
> +
> +       chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
> +       if (!chip)
> +               return -ENOMEM;
> +       chip->ops = &marvel_env_ops;
> +       chip->info = info;
> +
> +       hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data, chip,
> +                                                    NULL);
> +       return PTR_ERR_OR_ZERO(hwmon);
> +}
> +
> +static struct platform_driver marvel_env_driver = {
> +       .driver = {
> +               .name = DRVNAME,
> +       },
> +       .probe = marvel_env_probe,
> +};
> +module_platform_driver(marvel_env_driver);
> +
> +MODULE_ALIAS("platform:" DRVNAME);
> +MODULE_DESCRIPTION("Marvel (EV7) AlphaServer environmental sensors");
> +MODULE_LICENSE("GPL");
>
> --
> 2.56.1
>

Magnus

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

* Re: [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events
  2026-11-17  2:59 ` [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events Matt Turner
@ 2026-11-17 11:30   ` Magnus Lindholm
  0 siblings, 0 replies; 16+ messages in thread
From: Magnus Lindholm @ 2026-11-17 11:30 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Guenter Roeck, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

Hi Matt,

On Tue, Nov 17, 2026 at 3:59 AM Matt Turner <mattst88@gmail.com> wrote:
>
> The firmware reports each change of a sensor's state as a system event
> machine check. On one, reread every node from a workqueue and notify
> userspace of each alarm attribute whose value changed. The notifier runs
> in machine check context, so it only queues an irq_work, which queues
> the work. The work takes the hwmon device lock to serialize the refresh
> with the sysfs callbacks.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  Documentation/hwmon/marvel-env.rst |  4 ++
>  drivers/hwmon/Kconfig              |  1 +
>  drivers/hwmon/marvel-env.c         | 89 ++++++++++++++++++++++++++++++++++++--
>  3 files changed, 90 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/hwmon/marvel-env.rst b/Documentation/hwmon/marvel-env.rst
> index 7e0457a60094..ae3edda557ab 100644
> --- a/Documentation/hwmon/marvel-env.rst
> +++ b/Documentation/hwmon/marvel-env.rst
> @@ -27,6 +27,10 @@ A refresh keeps the boot CPU in the console with interrupts disabled for up
>  to 300 ms per unit, so a unit is refreshed at most once every
>  ``update_interval`` milliseconds (10000 by default).
>
> +The firmware also reports every change of state as a system event machine
> +check. When one arrives, the driver refreshes all units and notifies
> +userspace through the alarm attributes.
> +
>  Sysfs entries
>  -------------
>
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index c0ce5591c82d..99c5d84c8752 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1258,6 +1258,7 @@ config SENSORS_MACSMC_HWMON
>  config SENSORS_MARVEL_ENV
>         tristate "Marvel (EV7) AlphaServer environmental sensors"
>         depends on ALPHA_MARVEL || (ALPHA_GENERIC && !ALPHA_LEGACY_START_ADDRESS)
> +       select IRQ_WORK
>         help
>           If you say yes here you get support for the temperature, fan,
>           voltage and power supply sensors of Marvel AlphaServers (the
> diff --git a/drivers/hwmon/marvel-env.c b/drivers/hwmon/marvel-env.c
> index e501e049d702..d319556929e3 100644
> --- a/drivers/hwmon/marvel-env.c
> +++ b/drivers/hwmon/marvel-env.c
> @@ -17,12 +17,15 @@
>   */
>
>  #include <linux/hwmon.h>
> +#include <linux/irq_work.h>
>  #include <linux/jiffies.h>
>  #include <linux/kernel.h>
>  #include <linux/module.h>
> +#include <linux/notifier.h>
>  #include <linux/platform_device.h>
>  #include <linux/slab.h>
>  #include <linux/string.h>
> +#include <linux/workqueue.h>
>
>  #include <asm/gct.h>
>  #include <asm/marvel_env.h>
> @@ -94,16 +97,21 @@ struct marvel_env_chan {
>         unsigned int pkt;               /* packet offset in the node */
>         bool ps;                        /* power supply, as an in channel */
>         bool present;                   /* known when the driver loaded */
> +       u32 alarms;                     /* alarm attributes last reported */
>         char label[32];
>  };
>
>  struct marvel_env_data {
>         struct device *dev;
> +       struct device *hwmon;
>         unsigned int update_interval;   /* ms */
>         struct marvel_env_node *nodes;
>         unsigned int nr_nodes;
>         struct marvel_env_chan *chans[hwmon_max];
>         unsigned int nr_chans[hwmon_max];
> +       struct irq_work irq_work;
> +       struct work_struct work;
> +       struct notifier_block nb;
>  };
>
>  static const char * const pe_names[] = {
> @@ -290,6 +298,7 @@ static void marvel_env_add_chan(struct marvel_env_data *data,
>         c->ps = ps;
>         status = marvel_env_status(type, c);
>         c->present = env_status_valid(status);
> +       c->alarms = marvel_env_alarms(type, c, status);
>
>         if (n->cabinet || n->drawer)
>                 len = scnprintf(c->label, sizeof(c->label), "Cab%u Dra%u ",
> @@ -512,6 +521,72 @@ static u32 marvel_env_config(enum hwmon_sensor_types type,
>         }
>  }
>
> +/* Reread everything after a system event and report changed alarms. */
> +static void marvel_env_event_work(struct work_struct *work)
> +{
> +       struct marvel_env_data *data =
> +               container_of(work, struct marvel_env_data, work);
> +       unsigned int i, k;
> +
> +       guard(hwmon_lock)(data->hwmon);
> +
> +       for (i = 0; i < data->nr_nodes; i++) {
> +               data->nodes[i].valid = false;
> +               marvel_env_refresh(data, &data->nodes[i]);
> +       }
> +
> +       for (k = 0; k < ARRAY_SIZE(marvel_env_types); k++) {
> +               enum hwmon_sensor_types type = marvel_env_types[k];
> +
> +               for (i = 0; i < data->nr_chans[type]; i++) {
> +                       struct marvel_env_chan *c = &data->chans[type][i];
> +                       unsigned long changed;
> +                       unsigned int attr;
> +                       u8 status;
> +                       u32 alarms;
> +
> +                       if (!c->present)
> +                               continue;
> +                       status = marvel_env_status(type, c);
> +                       if (!env_status_valid(status))
> +                               continue;
> +                       alarms = marvel_env_alarms(type, c, status);
> +                       changed = alarms ^ c->alarms;
> +                       c->alarms = alarms;
> +                       for_each_set_bit(attr, &changed, 32)
> +                               hwmon_notify_event(data->hwmon, type, attr, i);
> +               }
> +       }
> +}
> +

This covers crit_alarm, fan_fault and the supplies' in_fault, and the
supply test on the ES47 exercises it end to end. Thanks.

> +static void marvel_env_irq_work(struct irq_work *irq_work)
> +{
> +       struct marvel_env_data *data =
> +               container_of(irq_work, struct marvel_env_data, irq_work);
> +
> +       schedule_work(&data->work);
> +}
> +
> +/* Runs in machine check context, so only queue the irq_work. */
> +static int marvel_env_event(struct notifier_block *nb, unsigned long action,
> +                           void *unused)
> +{
> +       struct marvel_env_data *data =
> +               container_of(nb, struct marvel_env_data, nb);
> +
> +       irq_work_queue(&data->irq_work);
> +       return NOTIFY_OK;
> +}
> +
> +static void marvel_env_unregister(void *arg)
> +{
> +       struct marvel_env_data *data = arg;
> +
> +       atomic_notifier_chain_unregister(&marvel_env_notifier, &data->nb);
> +       irq_work_sync(&data->irq_work);
> +       cancel_work_sync(&data->work);
> +}
> +
>  static const struct hwmon_channel_info * const marvel_env_chip_info =
>         HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL);
>
> @@ -522,7 +597,6 @@ static int marvel_env_probe(struct platform_device *pdev)
>         const struct hwmon_channel_info **info;
>         struct marvel_env_data *data;
>         struct hwmon_chip_info *chip;
> -       struct device *hwmon;
>         unsigned int i, k, nr_info = 0;
>
>         data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> @@ -591,9 +665,16 @@ static int marvel_env_probe(struct platform_device *pdev)
>         chip->ops = &marvel_env_ops;
>         chip->info = info;
>
> -       hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data, chip,
> -                                                    NULL);
> -       return PTR_ERR_OR_ZERO(hwmon);
> +       data->hwmon = devm_hwmon_device_register_with_info(dev, DRVNAME, data,
> +                                                          chip, NULL);
> +       if (IS_ERR(data->hwmon))
> +               return PTR_ERR(data->hwmon);
> +
> +       init_irq_work(&data->irq_work, marvel_env_irq_work);
> +       INIT_WORK(&data->work, marvel_env_event_work);
> +       data->nb.notifier_call = marvel_env_event;
> +       atomic_notifier_chain_register(&marvel_env_notifier, &data->nb);
> +       return devm_add_action_or_reset(dev, marvel_env_unregister, data);
>  }
>
>  static struct platform_driver marvel_env_driver = {
>
> --
> 2.56.1
>

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>

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

* Re: [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
  2026-11-17  2:59 ` [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer " Matt Turner
  2026-11-17 11:27   ` Magnus Lindholm
@ 2026-11-17 16:13   ` Guenter Roeck
  1 sibling, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2026-11-17 16:13 UTC (permalink / raw)
  To: Matt Turner
  Cc: Richard Henderson, Magnus Lindholm, linux-alpha, linux-kernel,
	linux-hwmon, linux-doc

On Mon, Nov 16, 2026 at 09:59:13PM -0500, Matt Turner wrote:
> The management firmware of the Marvel (EV7) AlphaServers, the GS1280,
> ES80 and ES47, monitors temperatures, fans, voltages and power supplies.
> The SRM console describes each sensor as a packet in a power and
> environment node of its config tree (GCT), and fills in the readings
> when asked to refresh the node. The packet layout was taken from Tru64
> UNIX.
> 
> The firmware gives each temperature, fan and voltage sensor a warning
> limit and a failure limit, and reports the sensor in the warning or
> failure state once its reading reaches one. Neither state means that the
> sensor is broken: a temperature past its failure limit is too high, not
> faulty. Power supplies are either working or failed, with the cause
> (AC, POK, overtemperature, fan) logged by the firmware.
> 
> Export the sensors through hwmon. A temperature's warning and failure
> limits become max and crit, with max_alarm set in either state and
> crit_alarm in the failure state. A fan's warning limit becomes min, with
> min_alarm set in either state and fault in the failure state, which is
> when the firmware counts the fan as failed. A voltage exports its
> reading, with min_alarm or max_alarm set in either state and lcrit_alarm
> or crit_alarm in the failure state, depending on which side of its
> nominal voltage it reads. The console gives the nominal voltage and only
> one other limit, so the voltage limits are not exported. A power supply
> is a voltage channel with only a fault attribute.
> 
> A refresh keeps the boot CPU in the console with interrupts disabled for
> up to 300 ms per node, so refresh a node at most once per
> update_interval. The hwmon core serializes the callbacks, which also
> serializes the refreshes.

This is not how the update_interval is supposed to be used. update_interval
is expected to be programmed into the chip.

Soft intervals should be hard-coded.

Thanks,
Guenter

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

end of thread, other threads:[~2026-11-17 16:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  2:59 [PATCH v2 0/7] alpha: marvel: environmental sensors Matt Turner
2026-11-17  2:59 ` [PATCH v2 1/7] alpha: marvel: fix the environmental subpacket layout Matt Turner
2026-11-17 11:08   ` Magnus Lindholm
2026-11-17  2:59 ` [PATCH v2 2/7] alpha: marvel: report environmental events without VERBOSE_MCHECK Matt Turner
2026-11-17 11:10   ` Magnus Lindholm
2026-11-17  2:59 ` [PATCH v2 3/7] alpha: marvel: refresh environmental readings through the console Matt Turner
2026-11-17 11:17   ` Magnus Lindholm
2026-11-17  2:59 ` [PATCH v2 4/7] alpha: marvel: notify environmental events Matt Turner
2026-11-17 11:10   ` Magnus Lindholm
2026-11-17  2:59 ` [PATCH v2 5/7] alpha: marvel: register a platform device for the environmental sensors Matt Turner
2026-11-17 11:11   ` Magnus Lindholm
2026-11-17  2:59 ` [PATCH v2 6/7] hwmon: Add driver for Marvel AlphaServer " Matt Turner
2026-11-17 11:27   ` Magnus Lindholm
2026-11-17 16:13   ` Guenter Roeck
2026-11-17  2:59 ` [PATCH v2 7/7] hwmon: (marvel-env) Notify userspace of environmental events Matt Turner
2026-11-17 11:30   ` Magnus Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®