alpha: marvel: environmental sensors
Subsystems (3)
Matt Turner
maintainercover alpha: marvel: environmental sensors
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, and patch 4 registers a platform device. Patch 5 is the hwmon driver, which polls. Patches 6 and 7 make 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 alarms. No environmental event fired during testing, so patches 6 and 7 are only build tested.
---
Matt Turner (7):
alpha: marvel: report environmental events without VERBOSE_MCHECK
alpha: marvel: fix the environmental subpacket layout
alpha: marvel: refresh environmental readings through the console
alpha: marvel: register a platform device for the environmental sensors
hwmon: Add driver for Marvel AlphaServer environmental sensors
alpha: marvel: notify environmental events
hwmon: (marvel-env) Notify userspace of environmental events
Documentation/hwmon/index.rst | 1 + Documentation/hwmon/marvel-env.rst | 64 ++++ MAINTAINERS | 8 + arch/alpha/include/asm/console.h | 2 + arch/alpha/include/asm/err_ev7.h | 16 +- arch/alpha/include/asm/marvel_env.h | 17 + arch/alpha/include/uapi/asm/console.h | 2 + arch/alpha/kernel/core_marvel.c | 59 ++++ 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 | 633 ++++++++++++++++++++++++++++++++++ 15 files changed, 840 insertions(+), 19 deletions(-)
---
base-commit: 0b4cadbe7c39d830dec35c4a2655483de0dae568
change-id: 20261114-marvel-env-d0289c736ba3
Best regards,
Signature · 1 line
Matt Turner <[email protected]>
Matt Turner
maintainerPATCH 1/7 alpha: marvel: report environmental events without VERBOSE_MCHECK
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.
--- arch/alpha/kernel/err_marvel.c | 2 -- 1 file changed, 2 deletions(-)
arch/alpha/kernel/err_marvel.c +0 -2
@@ -24,7 +24,6 @@static void marvel_print_680_frame (struct ev7_lf_subpackets *lf_subpackets) { -#ifdef CONFIG_VERBOSE_MCHECKstruct ev7_pal_environmental_subpacket *env;struct {int type;char *name; } ev_packets[] = { {EL_TYPE__PAL__ENV__AMBIENT_TEMPERATURE ,
@@ -62,7 +61,6 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets) env->unit_id, env->condition); } -#endif /* CONFIG_VERBOSE_MCHECK */ } static int
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 1/7] alpha: marvel: report environmental events without VERBOSE_MCHECK
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
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 withoutCONFIG_VERBOSE_MCHECKonly the header line reaches the log, which does not say which sensor or what happened. Print the subpackets unconditionally.Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerRe: [PATCH 1/7] alpha: marvel: report environmental events without VERBOSE_MCHECK
In reply to Matt TurnerQuoted 7 lines · 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 withoutCONFIG_VERBOSE_MCHECKonly the header line reaches the log, which does not say which sensor or what happened. Print the subpackets unconditionally.Assisted-by Claude:claude-opus-5-5
For all patches: This is obsolete. Please base your patches on the latest kernel and ask the agent to follow AGENTS.md.
Thanks,
Guenter
Quoted 26 lines
Signed-off-by Matt Turner <[email protected]>--- arch/alpha/kernel/err_marvel.c | 2 -- 1 file changed, 2 deletions(-)arch/alpha/kernel/err_marvel.c +0
-2@@ -24,7 +24,6 @@static void marvel_print_680_frame (struct ev7_lf_subpackets *lf_subpackets) { -#ifdef CONFIG_VERBOSE_MCHECKstruct ev7_pal_environmental_subpacket *env;struct {int type;char *name; } ev_packets[] = { {EL_TYPE__PAL__ENV__AMBIENT_TEMPERATURE ,@@ -62,7 +61,6 @@ marvel_print_680_frame(struct ev7_lf_subpackets *lf_subpackets) env->unit_id, env->condition); } -#endif /* CONFIG_VERBOSE_MCHECK */ } static int
Matt Turner
maintainerRe: [PATCH 1/7] alpha: marvel: report environmental events without VERBOSE_MCHECK
Quoted 8 lines · Guenter Roeck
Quoted 6 lines · 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 withoutCONFIG_VERBOSE_MCHECKonly the header line reaches the log, which does not say which sensor or what happened. Print the subpackets unconditionally.
Quoted 4 lines
Quoted 1 line
Assisted-by Claude:claude-opus-5-5For all patches: This is obsolete. Please base your patches on the latest kernel and ask the agent to follow AGENTS.md.
Sorry about that. The series is on v7.4-rc1, which already has the removal, so the trailer was my mistake rather than a stale base. In v2 I've dropped it from every patch and mentioned the tool use in the cover letter instead.
Matt Turner
maintainerPATCH 2/7 alpha: marvel: fix the environmental subpacket layout
In reply to Matt Turnerstruct 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.
--- arch/alpha/include/asm/err_ev7.h | 16 ++++++++++++---- arch/alpha/kernel/err_marvel.c | 28 +++++++++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-)
arch/alpha/include/asm/err_ev7.h +12 -4
@@ -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 */
arch/alpha/kernel/err_marvel.c +17 -11
@@ -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) {
@@ -49,17 +62,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); } }
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 2/7] alpha: marvel: fix the environmental subpacket layout
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
struct
ev7_pal_environmental_subpacketdoes 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
Quoted 7 lines
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.
Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Matt Turner
maintainerPATCH 3/7 alpha: marvel: refresh environmental readings through the console
In reply to Matt TurnerThe 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. 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.
--- arch/alpha/include/asm/console.h | 2 ++ arch/alpha/include/asm/marvel_env.h | 12 +++++++++ arch/alpha/include/uapi/asm/console.h | 2 ++ arch/alpha/kernel/core_marvel.c | 48 +++++++++++++++++++++++++++++++++++ arch/alpha/kernel/proto.h | 1 + arch/alpha/kernel/srmcons.c | 3 ++- arch/alpha/lib/callback_srm.S | 1 + 7 files changed, 68 insertions(+), 1 deletion(-)
arch/alpha/include/asm/console.h +2 -0
@@ -15,6 +15,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);
arch/alpha/include/asm/marvel_env.h new file +12 -0
@@ -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, or -ENODEV when not booted from SRM. +*/ +long marvel_cfgtree_partial_update (unsigned long offset); + +#endif /* __ALPHA_MARVEL_ENV_H */
arch/alpha/include/uapi/asm/console.h +2 -0
@@ -25,6 +25,8 @@#define CCB_GET_ENV 0x22#define CCB_SAVE_ENV 0x23 +#define CCB_CFGTREE 0x28 +#define CCB_PSWITCH 0x30#define CCB_BIOS_EMUL 0x32
arch/alpha/kernel/core_marvel.c +48 -0
61 lines not on this page · raw message
arch/alpha/kernel/proto.h +1 -0
@@ -111,6 +111,7 @@ extern void * __init move_initrd(unsigned long);extern struct screen_info vgacon_screen_info;/* srmcons.c */ +extern spinlock_t srmcons_callback_lock;#if defined(CONFIG_ALPHA_GENERIC ) || defined(CONFIG_ALPHA_SRM )extern void register_srm_console (void );extern void unregister_srm_console (void );
arch/alpha/kernel/srmcons.c +2 -1
@@ -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 ;/*
arch/alpha/lib/callback_srm.S +1 -0
@@ -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)
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 3/7] alpha: marvel: refresh environmental readings through the console
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
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, function0x1f. Add the callback andmarvel_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.
Quoted 6 lines
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.
Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Magnus Lindholm
maintainerRe: [PATCH 3/7] alpha: marvel: refresh environmental readings through the console
In reply to Matt TurnerHi Matt,
Quoted 66 lines · 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, function0x1f. Add the callback andmarvel_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.
Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>--- arch/alpha/include/asm/console.h | 2 ++ arch/alpha/include/asm/marvel_env.h | 12 +++++++++ arch/alpha/include/uapi/asm/console.h | 2 ++ arch/alpha/kernel/core_marvel.c | 48 +++++++++++++++++++++++++++++++++++ arch/alpha/kernel/proto.h | 1 + arch/alpha/kernel/srmcons.c | 3 ++- arch/alpha/lib/callback_srm.S | 1 + 7 files changed, 68 insertions(+), 1 deletion(-)arch/alpha/include/asm/console.h +2
-0@@ -15,6 +15,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);arch/alpha/include/asm/marvel_env.h new file +12
-0@@ -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, or -ENODEV when not booted from SRM. +*/ +long marvel_cfgtree_partial_update (unsigned long offset); + +#endif /* __ALPHA_MARVEL_ENV_H */ arch/alpha/include/uapi/asm/console.h +0
-0
arch/alpha/include/uapi/asm/console.h line 29
Quoted 5 lines
arch/alpha/include/uapi/asm/console.h +2
-0@@ -25,6 +25,8 @@#define CCB_GET_ENV 0x22#define CCB_SAVE_ENV 0x23 +#define CCB_CFGTREE 0x28 +
0x28 is not an architected callback: ARM 4th ed. Table 26-9 (p. 26-30) marks every code it does not list as Reserved. So this is a Marvel firmware extension. I'd keep it out of the uapi header, e.g. in asm/console.h, which callback_srm.S already includes, and say in the commit message that it comes from Tru64.
The boot-CPU-only call is fine by ARM 26.3.1 ("some console routines may be invoked only on the primary processor").
Quoted 110 lines
arch/alpha/include/uapi/asm/console.h +0
-0#define CCB_PSWITCH 0x30#define CCB_BIOS_EMUL 0x32arch/alpha/kernel/core_marvel.c +48
-0@@ -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,48 @@ 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; + +if (!alpha_using_srm) +return -ENODEV ; + +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);arch/alpha/kernel/proto.h +1
-0@@ -111,6 +111,7 @@ extern void * __init move_initrd(unsigned long);extern struct screen_info vgacon_screen_info;/* srmcons.c */ +extern spinlock_t srmcons_callback_lock;#if defined(CONFIG_ALPHA_GENERIC ) || defined(CONFIG_ALPHA_SRM )extern void register_srm_console (void );extern void unregister_srm_console (void );arch/alpha/kernel/srmcons.c +2
-1@@ -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 ;/* arch/alpha/lib/callback_srm.S +1
-1@@ -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) --
Quoted 2 lines
2.56.1
Magnus
Matt Turner
maintainerPATCH 4/7 alpha: marvel: register a platform device for the environmental sensors
In reply to Matt TurnerRegister a "marvel_env" platform device on Marvel systems booted from SRM, for the hwmon driver to bind to.
--- arch/alpha/kernel/core_marvel.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/alpha/kernel/core_marvel.c +11 -0
@@ -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>
@@ -1142,3 +1143,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);
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 4/7] alpha: marvel: register a platform device for the environmental sensors
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Register a "
marvel_env" platform device on Marvel systems booted from SRM, for the hwmon driver to bind to.Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Matt Turner
maintainerPATCH 5/7 hwmon: Add driver for Marvel AlphaServer environmental sensors
In reply to Matt TurnerThe 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.
Export the sensors through hwmon. Temperatures come with their warning and fault thresholds and fans with their warning threshold. Voltages export a reading and an alarm, power supplies only an alarm.
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.
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/marvel-env.rst | 60 ++++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/marvel-env.c | 552 +++++++++++++++++++++++++++++++++++++ 6 files changed, 633 insertions(+)
Documentation/hwmon/index.rst +1 -0
@@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers ltc4286 lx1308 macsmc-hwmon + marvel-env max127 max15301 max16064
Documentation/hwmon/marvel-env.rst new file +60 -0
60 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -16100,6 +16100,14 @@ L: [email protected] S: Maintained F: arch/mips/boot/dts/img/pistachio* +MARVEL ALPHASERVER ENVIRONMENTAL SENSOR DRIVER +M: Matt Turner <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/hwmon/marvel-env.rst +F: drivers/hwmon/marvel-env.c + MARVELL 88E6XXX ETHERNET SWITCH FABRIC DRIVER M: Andrew Lunn <[email protected]> L: [email protected]
drivers/hwmon/Kconfig +11 -0
@@ -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 + 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
drivers/hwmon/Makefile +1 -0
@@ -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
drivers/hwmon/marvel-env.c new file +552 -0
552 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] hwmon: (marvel-env) link failure when CONFIG_ALPHA_LEGACY_START_ADDRESS=y - [Low] hwmon…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] hwmon: (marvel-env) link failure when CONFIG_ALPHA_LEGACY_START_ADDRESS=y
- [Low] hwmon: (marvel-env) redundant driver-private mutex instead of hwmon_lock()
--
commit 0d0046c1ab7829344c10cd3a7021d92b64106a5d
Author: Matt Turner <[email protected]>
hwmon: Add driver for Marvel AlphaServer environmental sensors
This commit adds a hwmon driver for the temperature, fan, voltage, and power supply sensors exposed by the SRM console configuration tree on Marvel (EV7) AlphaServers.
drivers/hwmon/Kconfig config SENSORS_MACSMC_HWMON · line 1260
Quoted 11 lines
drivers/hwmon/Kconfig +3
-0@@ -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
[Severity: High]
Does this fail to link when CONFIG_ALPHA_GENERIC=y and CONFIG_ALPHA_LEGACY_START_ADDRESS=y (as in alpha defconfig and allmodconfig)?
marvel_env_refresh() calls marvel_cfgtree_partial_update() in core_marvel.o, which is omitted on ALPHA_GENERIC builds when CONFIG_ALPHA_LEGACY_START_ADDRESS is enabled:
arch/alpha/kernel/Makefile:
ifdef CONFIG_ALPHA_GENERIC
...
ifndef CONFIG_ALPHA_LEGACY_START_ADDRESS
obj-y += core_marvel.o core_titan.o core_wildfire.o
...
endifShould this depend on ALPHA_MARVEL || (ALPHA_GENERIC && !ALPHA_LEGACY_START_ADDRESS)?
[ ... ]
Quoted 5 lines
drivers/hwmon/marvel-env.c new file +0
-0
[ ... ]
Quoted 9 lines
drivers/hwmon/marvel-env.c new file +9
-0+struct marvel_env_data { +struct device *dev; +struct mutex lock;/* serializes refreshes and reads */ +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]; +};
[ ... ]
Quoted 10 lines
drivers/hwmon/marvel-env.c new file +10
-0+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; +
drivers/hwmon/marvel-env.c line 349
Quoted 10 lines
drivers/hwmon/marvel-env.c new file +10
-0+if (type == hwmon_chip) { + *val = data->update_interval; +return 0 ; + } + + c = &data->chans[type][channel]; + n = c->node; + pkt = c->pkt; + +mutex_lock (&data->lock);
[Severity: Low]
This isn't a bug, but is the driver-private data->lock mutex needed here and in marvel_env_write()?
The hwmon core already serializes .read and .write callbacks under its internal lock, and non-hwmon_ops paths (such as the event workqueue added later in this series) can use hwmon_lock() and hwmon_unlock() instead of maintaining a separate mutex.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Guenter Roeck
maintainerRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
In reply to Matt TurnerQuoted 73 lines · 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.
Export the sensors through hwmon. Temperatures come with their warning and fault thresholds and fans with their warning threshold. Voltages export a reading and an alarm, power supplies only an alarm.
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.Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/marvel-env.rst | 60 ++++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/marvel-env.c | 552 +++++++++++++++++++++++++++++++++++++ 6 files changed, 633 insertions(+)Documentation/hwmon/index.rst +1
-0@@ -157,6 +157,7 @@ Hardware Monitoring Kernel Drivers ltc4286 lx1308 macsmc-hwmon + marvel-env max127 max15301 max16064Documentation/hwmon/marvel-env.rst new file +29
-0@@ -0,0 +1,60 @@ +.. 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 <[email protected]> + +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). +
Documentation/hwmon/marvel-env.rst line 39
Quoted 10 lines
Documentation/hwmon/marvel-env.rst new file +10
-0+Sysfs entries +------------- + +=========================== ================================================= +``update_interval`` Minimum time between refreshes of a unit, in ms + +``temp[1-*]_input`` Temperature +``temp[1-*]_max`` Warning threshold +``temp[1-*]_crit`` Fault threshold +``temp[1-*]_max_alarm`` Sensor is in the warning or fault state
"fault": Sensor is broken.
"max_alarm": Temperature is too high.
That is distincly different. A faulty sensor should not be reported as "temperature too high".
Documentation/hwmon/marvel-env.rst line 40
Quoted 1 line
Documentation/hwmon/marvel-env.rst new file +1
-0+``temp[1-*]_crit_alarm`` Sensor is in the fault state
"fault" and "critical" have a different meaning. If this is a fault state (sensor is broken), it should be reported as such.
Documentation/hwmon/marvel-env.rst line 45
Quoted 5 lines
Documentation/hwmon/marvel-env.rst new file +5
-0+``temp[1-*]_label`` Sensor label + +``fan[1-*]_input`` Fan speed +``fan[1-*]_min`` Warning threshold +``fan[1-*]_min_alarm`` Fan is in the warning or fault state
This is wrong since there is also a separate fault attribute, and "fault" means defective, not "speed too low".
Documentation/hwmon/marvel-env.rst line 50
Quoted 5 lines
Documentation/hwmon/marvel-env.rst new file +5
-0+``fan[1-*]_fault`` Fan is in the fault state +``fan[1-*]_label`` Fan label + +``in[0-*]_input`` Voltage +``in[0-*]_alarm`` Sensor is in the warning or fault state
Which one is it ? Is it distinct ? A "fault" means that the hardware is broken/defective. An alarm means that the voltage is too high or too low. A faulty channel should not be reported as alarm but as fault.
Documentation/hwmon/marvel-env.rst line 54
Quoted 4 lines
Documentation/hwmon/marvel-env.rst new file +4
-0+``in[0-*]_label`` Sensor label + +``power[1-*]_alarm`` Power supply is in the warning or fault state +``power[1-*]_label`` Power supply label
"power" is supposed to report the system power, not a "power supply warning or fault state". If there is nothing else, this should be identical to the matching inX_alarm and/or inX_fault attribute.
Thanks,
Guenter
Quoted 618 lines
Documentation/hwmon/marvel-env.rst new file +6
-0+=========================== ================================================= + +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 +attribute fails with ``-ENODATA``, as does reading the alarm of a voltage +sensor or power supply.MAINTAINERS +8
-0@@ -16100,6 +16100,14 @@ L: [email protected] S: Maintained F: arch/mips/boot/dts/img/pistachio* +MARVEL ALPHASERVER ENVIRONMENTAL SENSOR DRIVER +M: Matt Turner <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/hwmon/marvel-env.rst +F: drivers/hwmon/marvel-env.c + MARVELL 88E6XXX ETHERNET SWITCH FABRIC DRIVER M: Andrew Lunn <[email protected]> L: [email protected]drivers/hwmon/Kconfig +11
-0@@ -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 + 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_MASTERdrivers/hwmon/Makefile +1
-0@@ -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.odrivers/hwmon/marvel-env.c new file +552
-0@@ -0,0 +1,552 @@ +// 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. +*/ + +#include <linux/hwmon.h> +#include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.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_TYPE_PE 0x13 +#define GCT_FLAGS_REQUIRED BIT(9) +#define GCT_FLAGS_EXCLUDED (BIT(2) | BIT(7) | BIT(12) | BIT(14)) + +/* Packet types. */ +#define ENV_PKT_POWER_SUPPLY 0x08 +#define ENV_PKT_FAN 0x09 +#define ENV_PKT_SENSOR 0x2a + +/* +* Sensor packet: kind, status, reading, high warning, high fault. +* Temperatures are in tenths of a degree Celsius, voltages in millivolts. +* For voltages the two thresholds look like the nominal voltage and an upper +* limit, so they are not exported. +*/ +#define SENSOR_KIND 0x28 +#define SENSOR_STATUS 0x2c +#define SENSOR_VALUE 0x30 +#define SENSOR_WARN 0x34 +#define SENSOR_FAULT 0x38 +#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, low fault. */ +#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 +#define ENV_FAULT 2 +#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 */ +char label[32 ]; +}; + +struct marvel_env_data { +struct device *dev; +struct mutex lock;/* serializes refreshes and reads */ +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" , +}; + +static inline u32 env_rd (struct marvel_env_node *n,unsigned int off) +{ +return *(u32 *)((char *)n->node + off); +} + +static inline u8 env_status (struct marvel_env_node *n,unsigned int off) +{ +return env_rd (n, off) &0xff ; +} + +static bool env_status_valid (u8 status) +{ +return status !=ENV_UNKNOWN && status !=ENV_NOT_PRESENT ; +} + +static bool env_status_alarm (u8 status) +{ +return status ==ENV_WARNING || status ==ENV_FAULT ; +} + +static unsigned int env_status_off (enum hwmon_sensor_types type) +{ +switch (type) { +case hwmon_fan: +return FAN_STATUS ; +case hwmon_power: +return PS_STATUS ; +default : +return SENSOR_STATUS ; + } +} + +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 ==0x3d ) + 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_power; +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, +unsigned int index) +{ +static const char *const what[hwmon_max] = { + [hwmon_temp] ="Temp" , [hwmon_fan] ="Fan" , + [hwmon_in] ="Volt" , [hwmon_power] ="PS" , + }; +struct marvel_env_chan *c; +const char *pe =NULL ; +size_t len =0 ; + + c = &data->chans[type][data->nr_chans[type]++]; + c->node = n; + c->pkt = pkt; + +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[type],strlen (what[type]))) +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[type], index); +else +scnprintf (c->label + len,sizeof (c->label) - len,"PE%u %s %u" , + n->pe, what[type], index); +} + +/* +* Walk a P&E node's packets, counting them, or adding them when @add. The +* header at hd_extension holds the count at +0x10 and the offset of the +* first packet at +0x14. 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 +0x18 > size) +return ; + count =env_rd (n, hdr +0x10 ); + pkt =env_rd (n, hdr +0x14 ); + +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_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; +const struct marvel_env_chan *c; + +if (type == hwmon_chip) +return 0644 ; + +/* Hide sensors that are absent when the driver loads. */ + c = &data->chans[type][channel]; +if (!env_status_valid (env_status (c->node, c->pkt +env_status_off (type)))) +return 0 ; +return 0444 ; +} + +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; + +mutex_lock (&data->lock); + ret =marvel_env_refresh (data, n); +if (ret) + goto out; + +switch (type) { +case hwmon_temp: + status =env_status (n, pkt +SENSOR_STATUS ); +switch (attr) { +case hwmon_temp_input: +if (!env_status_valid (status)) + ret = -ENODATA ; +else + *val = (s32 )env_rd (n, pkt +SENSOR_VALUE ) *100L ; +break ; +case hwmon_temp_max: + *val = (s32 )env_rd (n, pkt +SENSOR_WARN ) *100L ; +break ; +case hwmon_temp_crit: + *val = (s32 )env_rd (n, pkt +SENSOR_FAULT ) *100L ; +break ; +case hwmon_temp_max_alarm: + *val =env_status_alarm (status); +break ; +case hwmon_temp_crit_alarm: + *val = status ==ENV_FAULT ; +break ; +default : + ret = -EOPNOTSUPP ; + } +break ; +case hwmon_fan: + status =env_status (n, pkt +FAN_STATUS ); +switch (attr) { +case hwmon_fan_input: +if (!env_status_valid (status)) + ret = -ENODATA ; +else + *val =env_rd (n, pkt +FAN_VALUE ); +break ; +case hwmon_fan_min: + *val =env_rd (n, pkt +FAN_WARN ); +break ; +case hwmon_fan_min_alarm: + *val =env_status_alarm (status); +break ; +case hwmon_fan_fault: + *val = status ==ENV_FAULT ; +break ; +default : + ret = -EOPNOTSUPP ; + } +break ; +case hwmon_in: +case hwmon_power: + status =env_status (n, pkt +env_status_off (type)); +if (!env_status_valid (status)) + ret = -ENODATA ; +else if (type == hwmon_in && attr == hwmon_in_input) + *val = (s32 )env_rd (n, pkt +SENSOR_VALUE ); +else + *val =env_status_alarm (status); +break ; +default : + ret = -EOPNOTSUPP ; + } +out: +mutex_unlock (&data->lock); +return ret; +} + +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 ; + +mutex_lock (&data->lock); + data->update_interval =clamp_val (val,0 ,3600 *MSEC_PER_SEC ); +mutex_unlock (&data->lock); +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 const struct { +enum hwmon_sensor_types type; +u32 config; +} marvel_env_hwmon[] = { + { hwmon_temp,HWMON_T_INPUT |HWMON_T_MAX |HWMON_T_CRIT | +HWMON_T_MAX_ALARM |HWMON_T_CRIT_ALARM |HWMON_T_LABEL }, + { hwmon_fan,HWMON_F_INPUT |HWMON_F_MIN |HWMON_F_MIN_ALARM | +HWMON_F_FAULT |HWMON_F_LABEL }, + { hwmon_in,HWMON_I_INPUT |HWMON_I_ALARM |HWMON_I_LABEL }, + { hwmon_power,HWMON_P_ALARM |HWMON_P_LABEL }, +}; + +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) +{ +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 ; +mutex_init (&data->lock); + +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_hwmon) +2 , +sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + info[nr_info++] = marvel_env_chip_info; + +for (k =0 ; k <ARRAY_SIZE (marvel_env_hwmon); k++) { +enum hwmon_sensor_types type = marvel_env_hwmon[k].type; +struct hwmon_channel_info *ci; +u32 *config; + +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 =devm_kcalloc (dev, data->nr_chans[type] +1 , +sizeof (*config),GFP_KERNEL ); +if (!data->chans[type] || !ci || !config) +return -ENOMEM ; +for (i =0 ; i < data->nr_chans[type]; i++) + config[i] = marvel_env_hwmon[k].config; + ci->type = type; + ci->config = config; + 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); + + 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" );
Matt Turner
maintainerRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
Quoted 7 lines · Guenter Roeck
Quoted 1 line
+``temp[1-*]_max_alarm`` Sensor is in the warning or fault state
"fault": Sensor is broken.
"max_alarm": Temperature is too high.That is distincly different. A faulty sensor should not be reported as "temperature too high".
My wording was the problem here, sorry. "Fault" was my name for what the firmware calls the Failure state, and it does not mean the sensor is broken. The AlphaServer Management Utility user guide [1] (section 3.16) says the firmware keeps a warning limit and a failure limit for each fan, voltage and temperature sensor, and puts the sensor in the Warning or Failure state when a reading meets or exceeds the matching limit. The status byte in the console's packet only says OK, Warning, Failure, Unknown or Not present (Table B-1 of the same guide), so a broken sensor cannot be told apart from a bad reading at all.
For temperatures, v2 reports Warning as temp_max_alarm and Failure as temp_max_alarm plus temp_crit_alarm, with temp_max and temp_crit being the warning and failure limits. Nothing is reported as a fault.
Quoted 4 lines
Quoted 1 line
+``fan[1-*]_min_alarm`` Fan is in the warning or fault state
This is wrong since there is also a separate fault attribute, and "fault" means defective, not "speed too low".
A fan in the Failure state has slowed to its failure limit, and the firmware treats it as a failed fan (a drawer is powered off for having too few running fans). v2 reports Warning as fan_min_alarm and Failure as fan_min_alarm plus fan_fault. If you would rather keep fan_fault for something else, I can report Failure as fan_min_alarm only, but then nothing in sysfs separates a slow fan from a stopped one.
Quoted 6 lines
Quoted 1 line
+``in[0-*]_alarm`` Sensor is in the warning or fault state
Which one is it ? Is it distinct ? A "fault" means that the hardware is broken/defective. An alarm means that the voltage is too high or too low. A faulty channel should not be reported as alarm but as fault.
It is always the voltage being out of range: Warning is the reading outside the warning limits (5% from nominal), Failure outside the failure limits (10%). Both are reported as in_alarm in v2. The limits are not in the console's packet, so they are not exported.
Quoted 6 lines
Quoted 1 line
+``power[1-*]_alarm`` Power supply is in the warning or fault state
"power" is supposed to report the system power, not a "power supply warning or fault state". If there is nothing else, this should be identical to the matching
inX_alarmand/orinX_faultattribute.
There is nothing else: the firmware reports a supply only as OK or Failure, with no reading. Failure means the supply itself has failed (lost AC, power not OK, supply fail, over temperature or fan), so v2 reports each supply as an in channel with only in_fault and in_label.
I'll send v2 tomorrow.
Thanks a bunch for the review!
Matt
Guenter Roeck
maintainerRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
On 11/14/26 18:50, Matt Turner wrote:
...
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
+``in[0-*]_alarm`` Sensor is in the warning or fault state
Which one is it ? Is it distinct ? A "fault" means that the hardware is broken/defective. An alarm means that the voltage is too high or too low. A faulty channel should not be reported as alarm but as fault.
Quoted 5 lines
It is always the voltage being out of range: Warning is the reading outside the warning limits (5% from nominal), Failure outside the failure limits (10%). Both are reported as
in_alarmin v2. The limits are not in the console's packet, so they are not exported.
This could be reported as inX_max_alarm and inX_crit_alarm.
Thanks,
Guenter
Magnus Lindholm
maintainerRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
Hi,
Quoted 10 lines · Guenter Roeck
On 11/14/26 18:50, Matt Turner wrote:
...Quoted 7 lines
Quoted 6 lines
Quoted 1 line
+``in[0-*]_alarm`` Sensor is in the warning or fault state
Which one is it ? Is it distinct ? A "fault" means that the hardware is broken/defective. An alarm means that the voltage is too high or too low. A faulty channel should not be reported as alarm but as fault.
Quoted 8 lines
Quoted 5 lines
It is always the voltage being out of range: Warning is the reading outside the warning limits (5% from nominal), Failure outside the failure limits (10%). Both are reported as
in_alarmin v2. The limits are not in the console's packet, so they are not exported.This could be reported as
inX_max_alarmandinX_crit_alarm.
Only if the direction is known. "Outside" covers both, and in_crit is the critical max (Documentation/hwmon/sysfs-interface.rst, in_crit vs in_lcrit), so an undervoltage would read as too high. Matt, if the first threshold in the packet is the nominal, as the comment in 5/7 says, comparing in_input against it would pick min/lcrit or max/crit; otherwise in_alarm alone is the safe choice.
Magnus
kernel test robot
build botRe: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors
In reply to Matt Turnerkernel test robot noticed the following build errors:
Hi Matt,
kernel test robot noticed the following build errors:
[auto build test ERROR on 0b4cadbe7c39d830dec35c4a2655483de0dae568]
url: https://github.com/intel-lab-lkp/linux/commits/Matt-Turner/alpha-marvel-report-environmental-events-without-VERBOSE_MCHECK/20261114-123947 base: 0b4cadbe7c39d830dec35c4a2655483de0dae568 patch link: https://lore.kernel.org/r/20261114-marvel-env-v1-5-890328e4b7e5%40gmail.com patch subject: [PATCH 5/7] hwmon: Add driver for Marvel AlphaServer environmental sensors config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20261116/[email protected]/config) compiler: alpha-linux-gcc (GCC) 16.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261116/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
.exit.text' referenced in section .init.text' of fs/nfs/blocklayout/blocklayout.o: defined in discarded section .exit.text' of fs/nfs/blocklayout/blocklayout.o .exit.text' referenced in section .init.text' of fs/nfs/blocklayout/blocklayout.o: defined in discarded section .exit.text' of fs/nfs/blocklayout/blocklayout.o
alpha-linux-ld: drivers/hwmon/marvel-env.o: in function `marvel_env_refresh':
>> (.text+0x528): undefined reference to `marvel_cfgtree_partial_update' >> alpha-linux-ld: (.text+0x52c): undefined reference to `marvel_cfgtree_partial_update'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Matt Turner
maintainerPATCH 6/7 alpha: marvel: notify environmental events
In reply to Matt TurnerA 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.
--- arch/alpha/include/asm/marvel_env.h | 5 +++++ arch/alpha/kernel/err_marvel.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
arch/alpha/include/asm/marvel_env.h +5 -0
@@ -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 */
arch/alpha/kernel/err_marvel.c +8 -1
@@ -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; }
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 6/7] alpha: marvel: notify environmental events
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
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.
Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Matt Turner
maintainerPATCH 7/7 hwmon: (marvel-env) Notify userspace of environmental events
In reply to Matt TurnerThe 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 the alarms that changed. The notifier runs in machine check context, so it only queues an irq_work, which queues the work.
--- Documentation/hwmon/marvel-env.rst | 4 ++ drivers/hwmon/Kconfig | 1 + drivers/hwmon/marvel-env.c | 89 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 4 deletions(-)
Documentation/hwmon/marvel-env.rst +4 -0
@@ -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 -------------
drivers/hwmon/Kconfig +1 -0
@@ -1258,6 +1258,7 @@ config SENSORS_MACSMC_HWMON config SENSORS_MARVEL_ENV tristate "Marvel (EV7) AlphaServer environmental sensors" depends on ALPHA_MARVEL || ALPHA_GENERIC + 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
drivers/hwmon/marvel-env.c +85 -4
143 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 7/7] hwmon: (marvel-env) Notify userspace of environmental events
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] hwmon: marvel-env: incomplete alarm notifications in marvel_env_event_work() - [Low] hwmon…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] hwmon: marvel-env: incomplete alarm notifications in marvel_env_event_work()
- [Low] hwmon: marvel-env: private mutex used instead of hwmon_lock() --
commit d84479ee83faacee9e88f233e9993cccd529e1af
Author: Matt Turner <[email protected]>
hwmon: (marvel-env) Notify userspace of environmental events
This commit registers a machine check notifier to refresh all sensor nodes from a workqueue and notify userspace of alarm status changes via hwmon_notify_event().
Quoted 4 lines
drivers/hwmon/marvel-env.c +0
-0
[ ... ]
Quoted 27 lines
drivers/hwmon/marvel-env.c +23
-0@@ -460,6 +469,72 @@ static const struct { { hwmon_power, HWMON_P_ALARM | HWMON_P_LABEL }, }; +static const u32 marvel_env_alarm[hwmon_max] = { + [hwmon_temp] = hwmon_temp_max_alarm, + [hwmon_fan] = hwmon_fan_min_alarm, + [hwmon_in] = hwmon_in_alarm, + [hwmon_power] = hwmon_power_alarm, +}; + +/* 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; + +mutex_lock (&data->lock); +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_hwmon); k++) { +enum hwmon_sensor_types type = marvel_env_hwmon[k].type; +
drivers/hwmon/marvel-env.c static const struct { · line 504
Quoted 10 lines
drivers/hwmon/marvel-env.c +10
-0+for (i =0 ; i < data->nr_chans[type]; i++) { +struct marvel_env_chan *c = &data->chans[type][i]; +u8 status =env_status (c->node, + c->pkt +env_status_off (type)); + +if (status == c->last_status) +continue ; + c->last_status = status; +hwmon_notify_event (data->hwmon, type, + marvel_env_alarm[type], i);
[Severity: Medium]
Does marvel_env_event_work() miss notifications for hwmon_temp_crit_alarm and hwmon_fan_fault while emitting notifications for attributes that did not change?
In marvel_env_read(), temperature channels expose both hwmon_temp_max_alarm (via env_status_alarm(), which is true for ENV_WARNING and ENV_FAULT) and hwmon_temp_crit_alarm (true for ENV_FAULT), and fan channels expose both hwmon_fan_min_alarm and hwmon_fan_fault:
drivers/hwmon/marvel-env.c:marvel_env_read() {
...
case hwmon_temp_max_alarm:
*val = env_status_alarm(status);
break;
case hwmon_temp_crit_alarm:
*val = status == ENV_FAULT;
break;
...
case hwmon_fan_min_alarm:
*val = env_status_alarm(status);
break;
case hwmon_fan_fault:
*val = status == ENV_FAULT;
break;
...
}Because marvel_env_alarm[] only maps each sensor type to a single attribute, a transition into or out of ENV_FAULT never calls hwmon_notify_event() for hwmon_temp_crit_alarm or hwmon_fan_fault, so userspace polling tempN_crit_alarm or fanN_fault is not woken. Conversely, a transition between ENV_WARNING and ENV_FAULT leaves env_status_alarm() at 1, yet notifies tempN_max_alarm, fanN_min_alarm, inN_alarm, or powerN_alarm even though their values did not change. Transitions involving ENV_UNKNOWN or ENV_NOT_PRESENT also trigger notifications even when env_status_alarm() does not change or the channel was hidden at probe time by marvel_env_is_visible().
drivers/hwmon/marvel-env.c static const struct { · line 508
Quoted 4 lines
drivers/hwmon/marvel-env.c +4
-0+ } + } +mutex_unlock (&data->lock); +}
[Severity: Low]
This isn't a bug, but the hwmon subsystem prefers hwmon_lock(data->hwmon) and hwmon_unlock(data->hwmon) over a driver-private mutex when synchronizing asynchronous work with hwmon callbacks, since the hwmon core already holds the device lock across .read and .write ops.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Magnus Lindholm
maintainerRe: [PATCH 7/7] hwmon: (marvel-env) Notify userspace of environmental events
In reply to Matt TurnerHi Matt,
Quoted 94 lines · 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 the alarms that changed. The notifier runs in machine check context, so it only queues an
irq_work, which queues the work.Assisted-by Claude:claude-opus-5-5Signed-off-by Matt Turner <[email protected]>--- Documentation/hwmon/marvel-env.rst | 4 ++ drivers/hwmon/Kconfig | 1 + drivers/hwmon/marvel-env.c | 89 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 4 deletions(-)Documentation/hwmon/marvel-env.rst +4
-0@@ -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 -------------drivers/hwmon/Kconfig +1
-0@@ -1258,6 +1258,7 @@ config SENSORS_MACSMC_HWMON config SENSORS_MARVEL_ENV tristate "Marvel (EV7) AlphaServer environmental sensors" depends on ALPHA_MARVEL || ALPHA_GENERIC + select IRQ_WORK help If you say yes here you get support for the temperature, fan, voltage and power supply sensors of Marvel AlphaServers (thedrivers/hwmon/marvel-env.c +9
-0@@ -11,13 +11,16 @@*/ #include <linux/hwmon.h> +#include <linux/irq_work.h> #include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.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> @@ -81,17 +84,22 @@ struct marvel_env_node {struct marvel_env_chan {struct marvel_env_node *node;unsigned int pkt;/* packet offset in the node */ +u8 last_status;char label[32 ]; };struct marvel_env_data {struct device *dev; +struct device *hwmon;struct mutex lock;/* serializes refreshes and reads */ 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[] = {@@ -226,6 +234,7 @@ static void marvel_env_add_chan(struct marvel_env_data *data, c = &data->chans[type][data->nr_chans[type]++]; c->node = n; c->pkt = pkt; + c->last_status =env_status (n, pkt +env_status_off (type));if (n->cabinet || n->drawer) len = scnprintf(c->label, sizeof(c->label), "Cab%u Dra%u ",
drivers/hwmon/marvel-env.c static const struct { · line 478
Quoted 10 lines
drivers/hwmon/marvel-env.c +7
-0@@ -460,6 +469,72 @@ static const struct { { hwmon_power, HWMON_P_ALARM | HWMON_P_LABEL }, }; +static const u32 marvel_env_alarm[hwmon_max] = { + [hwmon_temp] = hwmon_temp_max_alarm, + [hwmon_fan] = hwmon_fan_min_alarm, + [hwmon_in] = hwmon_in_alarm, + [hwmon_power] = hwmon_power_alarm, +}; +
With the v2 mapping from the 5/7 thread, one attribute per type is not enough. A Warning to Failure change flips only temp_crit_alarm or fan_fault, so nobody polling those is woken. For a supply as an in channel, hwmon_in_alarm does not exist, so sysfs_notify() finds nothing while the uevent still says NAME=inN_alarm (hwmon_notify_event() does not check the attribute, drivers/hwmon/hwmon.c). Notifying every alarm/fault attribute the channel has would cover both.
The machine check -> irq_work -> work chain and the teardown order look right to me. If the ES47 has a redundant supply, pulling one should exercise this end to end.
Quoted 92 lines
drivers/hwmon/marvel-env.c +69
-5+/* 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; + +mutex_lock (&data->lock); +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_hwmon); k++) { +enum hwmon_sensor_types type = marvel_env_hwmon[k].type; + +for (i =0 ; i < data->nr_chans[type]; i++) { +struct marvel_env_chan *c = &data->chans[type][i]; +u8 status =env_status (c->node, + c->pkt +env_status_off (type)); + +if (status == c->last_status) +continue ; + c->last_status = status; +hwmon_notify_event (data->hwmon, type, + marvel_env_alarm[type], i); + } + } +mutex_unlock (&data->lock); +} + +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 );@@ -469,7 +544,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 );@@ -534,9 +608,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 = { --
Quoted 2 lines
2.56.1
Magnus