Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Ignore non-recoverable and critical limits smaller t...



details:   https://anonhg.NetBSD.org/src/rev/1c9d5d992e30
branches:  trunk
changeset: 373947:1c9d5d992e30
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Wed Mar 22 13:00:54 2023 +0000

description:
Ignore non-recoverable and critical limits smaller than the warning limits.
These are usually invalid.

Name the limit flags to make code more readable.

diffstat:

 sys/dev/ipmi.c |  42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diffs (92 lines):

diff -r c1a016cecfd4 -r 1c9d5d992e30 sys/dev/ipmi.c
--- a/sys/dev/ipmi.c    Wed Mar 22 03:17:18 2023 +0000
+++ b/sys/dev/ipmi.c    Wed Mar 22 13:00:54 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipmi.c,v 1.9 2021/06/15 00:20:33 riastradh Exp $ */
+/*     $NetBSD: ipmi.c,v 1.10 2023/03/22 13:00:54 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2019 Michael van Elst
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.9 2021/06/15 00:20:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.10 2023/03/22 13:00:54 mlelstv Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1533,6 +1533,14 @@
        return;
 }
 
+/* valid bits for (upper,lower) x (non-recoverable, critical, warn) */
+#define UN     0x20
+#define UC     0x10
+#define UW     0x08
+#define LN     0x04
+#define LC     0x02
+#define LW     0x01
+
 static void
 ipmi_get_sensor_limits(struct ipmi_softc *sc, struct ipmi_sensor *psensor,
                       sysmon_envsys_lim_t *limits, uint32_t *props)
@@ -1540,7 +1548,7 @@
        struct sdrtype1 *s1 = (struct sdrtype1 *)psensor->i_sdr;
        bool failure;
        int     rxlen;
-       uint8_t data[32];
+       uint8_t data[32], valid;
        uint32_t prop_critmax, prop_warnmax, prop_critmin, prop_warnmin;
        int32_t *pcritmax, *pwarnmax, *pcritmin, *pwarnmin;
 
@@ -1582,27 +1590,43 @@
                break;
        }
 
-       if (data[0] & 0x20 && data[6] != 0xff) {
+       valid = data[0];
+
+       /* if upper non-recoverable < warning, ignore it */
+       if ((valid & (UN|UW)) == (UN|UW) && data[6] < data[4])
+               valid ^= UN;
+       /* if upper critical < warning, ignore it */
+       if ((valid & (UC|UW)) == (UC|UW) && data[5] < data[4])
+               valid ^= UC;
+
+       /* if lower non-recoverable > warning, ignore it */
+       if ((data[0] & (LN|LW)) == (LN|LW) && data[3] > data[1])
+               valid ^= LN;
+       /* if lower critical > warning, ignore it */
+       if ((data[0] & (LC|LW)) == (LC|LW) && data[2] > data[1])
+               valid ^= LC;
+
+       if (valid & UN && data[6] != 0xff) {
                *pcritmax = ipmi_convert_sensor(&data[6], psensor);
                *props |= prop_critmax;
        }
-       if (data[0] & 0x10 && data[5] != 0xff) {
+       if (valid & UC && data[5] != 0xff) {
                *pcritmax = ipmi_convert_sensor(&data[5], psensor);
                *props |= prop_critmax;
        }
-       if (data[0] & 0x08 && data[4] != 0xff) {
+       if (valid & UW && data[4] != 0xff) {
                *pwarnmax = ipmi_convert_sensor(&data[4], psensor);
                *props |= prop_warnmax;
        }
-       if (data[0] & 0x04 && data[3] != 0x00) {
+       if (valid & LN && data[3] != 0x00) {
                *pcritmin = ipmi_convert_sensor(&data[3], psensor);
                *props |= prop_critmin;
        }
-       if (data[0] & 0x02 && data[2] != 0x00) {
+       if (valid & LC && data[2] != 0x00) {
                *pcritmin = ipmi_convert_sensor(&data[2], psensor);
                *props |= prop_critmin;
        }
-       if (data[0] & 0x01 && data[1] != 0x00) {
+       if (valid & LW && data[1] != 0x00) {
                *pwarnmin = ipmi_convert_sensor(&data[1], psensor);
                *props |= prop_warnmin;
        }



Home | Main Index | Thread Index | Old Index