Separate checking of sensor value vs threshold/limit value into two

routines, so we can distinguish between an over-limit vs under-limit
condition.  Set sensor state appropriately based on which threshold
is exceeded.

To do: come up with a means of detecting non-existent fans vs broken
fans.  Currently, both report a valid value of "0 RPM" at least on
some platforms.

OK garbled@
Tested by simonb@
This commit is contained in:
pgoyette 2008-09-08 03:05:38 +00:00
parent 6779aaaeb8
commit 15c5293824

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipmi.c,v 1.18 2008/04/17 05:26:11 cegger Exp $ */
/* $NetBSD: ipmi.c,v 1.19 2008/09/08 03:05:38 pgoyette Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
*
@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.18 2008/04/17 05:26:11 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.19 2008/09/08 03:05:38 pgoyette Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -214,7 +214,8 @@ void ipmi_unmap_regs(struct ipmi_softc *sc, struct ipmi_attach_args *ia);
void *scan_sig(long, long, int, int, const void *);
int ipmi_test_threshold(uint8_t, uint8_t, uint8_t, uint8_t);
int ipmi_test_threshold_lo(uint8_t, uint8_t, uint8_t);
int ipmi_test_threshold_hi(uint8_t, uint8_t, uint8_t);
int ipmi_sensor_status(struct ipmi_softc *, struct ipmi_sensor *,
envsys_data_t *, uint8_t *);
@ -1307,11 +1308,17 @@ ipmi_convert(uint8_t v, struct sdrtype1 *s1, long adj)
}
int
ipmi_test_threshold(uint8_t v, uint8_t valid, uint8_t hi, uint8_t lo)
ipmi_test_threshold_hi(uint8_t v, uint8_t valid, uint8_t hi)
{
dbg_printf(10, "thresh: %.2x %.2x %.2x %d\n", v, lo, hi,valid);
return ((valid & 1 && lo != 0x00 && v <= lo) ||
(valid & 8 && hi != 0xFF && v >= hi));
dbg_printf(10, "thresh_hi: %.2x %.2x %d\n", v, hi, valid);
return (valid & 8 && hi != 0xFF && v >= hi);
}
int
ipmi_test_threshold_lo(uint8_t v, uint8_t valid, uint8_t lo)
{
dbg_printf(10, "thresh_lo: %.2x %.2x %d\n", v, lo, valid);
return (valid & 1 && lo != 0x00 && v <= lo);
}
int
@ -1357,18 +1364,24 @@ ipmi_sensor_status(struct ipmi_softc *sc, struct ipmi_sensor *psensor,
data[0], data[1], data[2], data[3], data[4], data[5],
data[6]);
if (ipmi_test_threshold(*reading, data[0] >> 2 ,
data[6], data[3]))
if (ipmi_test_threshold_hi(*reading, data[0] >> 2 , data[6]))
return ENVSYS_SCRITOVER;
if (ipmi_test_threshold(*reading, data[0] >> 1,
data[5], data[2]))
if (ipmi_test_threshold_hi(*reading, data[0] >> 1, data[5]))
return ENVSYS_SCRITOVER;
if (ipmi_test_threshold(*reading, data[0] ,
data[4], data[1]))
if (ipmi_test_threshold_hi(*reading, data[0] , data[4]))
return ENVSYS_SWARNOVER;
if (ipmi_test_threshold_lo(*reading, data[0] >> 2 , data[3]))
return ENVSYS_SCRITUNDER;
if (ipmi_test_threshold_lo(*reading, data[0] >> 1, data[2]))
return ENVSYS_SCRITUNDER;
if (ipmi_test_threshold_lo(*reading, data[0] , data[1]))
return ENVSYS_SWARNUNDER;
break;
case IPMI_SENSOR_TYPE_INTRUSION: