Home | History | Annotate | Line # | Download | only in dev
      1  1.6  riastrad /* $NetBSD: ipmivar.h,v 1.6 2024/12/04 15:25:45 riastradh Exp $ */
      2  1.1   mlelstv 
      3  1.1   mlelstv /*
      4  1.1   mlelstv  * Copyright (c) 2005 Jordan Hargrave
      5  1.1   mlelstv  * All rights reserved.
      6  1.1   mlelstv  *
      7  1.1   mlelstv  * Redistribution and use in source and binary forms, with or without
      8  1.1   mlelstv  * modification, are permitted provided that the following conditions
      9  1.1   mlelstv  * are met:
     10  1.1   mlelstv  * 1. Redistributions of source code must retain the above copyright
     11  1.1   mlelstv  *    notice, this list of conditions and the following disclaimer.
     12  1.1   mlelstv  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   mlelstv  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   mlelstv  *    documentation and/or other materials provided with the distribution.
     15  1.1   mlelstv  *
     16  1.1   mlelstv  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
     17  1.1   mlelstv  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1   mlelstv  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1   mlelstv  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
     20  1.1   mlelstv  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1   mlelstv  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1   mlelstv  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1   mlelstv  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1   mlelstv  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1   mlelstv  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1   mlelstv  * SUCH DAMAGE.
     27  1.1   mlelstv  */
     28  1.1   mlelstv 
     29  1.6  riastrad #ifndef _IPMIVAR_H_
     30  1.6  riastrad #define _IPMIVAR_H_
     31  1.6  riastrad 
     32  1.6  riastrad #include <sys/types.h>
     33  1.6  riastrad 
     34  1.6  riastrad #include <sys/bus.h>
     35  1.6  riastrad #include <sys/condvar.h>
     36  1.6  riastrad #include <sys/ipmi.h>
     37  1.1   mlelstv #include <sys/mutex.h>
     38  1.1   mlelstv 
     39  1.1   mlelstv #include <dev/sysmon/sysmonvar.h>
     40  1.1   mlelstv 
     41  1.1   mlelstv #define IPMI_IF_KCS		1
     42  1.1   mlelstv #define IPMI_IF_SMIC		2
     43  1.1   mlelstv #define IPMI_IF_BT		3
     44  1.1   mlelstv #define IPMI_IF_SSIF		4
     45  1.1   mlelstv 
     46  1.1   mlelstv #define IPMI_IF_KCS_NREGS	2
     47  1.1   mlelstv #define IPMI_IF_SMIC_NREGS	3
     48  1.1   mlelstv #define IPMI_IF_BT_NREGS	3
     49  1.1   mlelstv #define IPMI_IF_SSIF_NREGS	2
     50  1.1   mlelstv 
     51  1.1   mlelstv struct ipmi_thread;
     52  1.1   mlelstv struct ipmi_softc;
     53  1.1   mlelstv 
     54  1.1   mlelstv struct ipmi_attach_args {
     55  1.1   mlelstv 	bus_space_tag_t	iaa_iot;
     56  1.1   mlelstv 	bus_space_tag_t	iaa_memt;
     57  1.1   mlelstv 
     58  1.1   mlelstv 	int		iaa_if_type;
     59  1.1   mlelstv 	int		iaa_if_rev;
     60  1.1   mlelstv 	int		iaa_if_iotype;
     61  1.1   mlelstv 	bus_addr_t	iaa_if_iobase;
     62  1.1   mlelstv 	int		iaa_if_iospacing;
     63  1.1   mlelstv 	int		iaa_if_irq;
     64  1.1   mlelstv 	int		iaa_if_irqlvl;
     65  1.1   mlelstv };
     66  1.1   mlelstv 
     67  1.1   mlelstv struct ipmi_if {
     68  1.1   mlelstv 	const char	*name;
     69  1.1   mlelstv 	int		nregs;
     70  1.1   mlelstv 	void		*(*buildmsg)(struct ipmi_softc *, int, int, int,
     71  1.1   mlelstv 			    const void *, int *);
     72  1.1   mlelstv 	int		(*sendmsg)(struct ipmi_softc *, int, const uint8_t *);
     73  1.1   mlelstv 	int		(*recvmsg)(struct ipmi_softc *, int, int *, uint8_t *);
     74  1.1   mlelstv 	int		(*reset)(struct ipmi_softc *);
     75  1.1   mlelstv 	int		(*probe)(struct ipmi_softc *);
     76  1.1   mlelstv };
     77  1.1   mlelstv 
     78  1.1   mlelstv struct ipmi_softc {
     79  1.1   mlelstv 	device_t		sc_dev;
     80  1.1   mlelstv 
     81  1.1   mlelstv 	struct ipmi_if		*sc_if;		/* Interface layer */
     82  1.1   mlelstv 	int			sc_if_iospacing; /* Spacing of I/O ports */
     83  1.1   mlelstv 	int			sc_if_rev;	/* IPMI Revision */
     84  1.1   mlelstv 	struct ipmi_attach_args	sc_ia;
     85  1.1   mlelstv 
     86  1.1   mlelstv 	void			*sc_ih;		/* Interrupt/IO handles */
     87  1.1   mlelstv 	bus_space_tag_t		sc_iot;
     88  1.1   mlelstv 	bus_space_handle_t	sc_ioh;
     89  1.1   mlelstv 
     90  1.1   mlelstv 	int			sc_btseq;
     91  1.1   mlelstv 
     92  1.1   mlelstv 	struct lwp		*sc_kthread;
     93  1.1   mlelstv 
     94  1.1   mlelstv 	int			sc_max_retries;
     95  1.1   mlelstv 
     96  1.1   mlelstv 	kmutex_t		sc_poll_mtx;
     97  1.1   mlelstv 	kcondvar_t		sc_poll_cv;
     98  1.3   mlelstv 	kcondvar_t		sc_mode_cv;
     99  1.1   mlelstv 
    100  1.1   mlelstv 	kmutex_t		sc_cmd_mtx;
    101  1.1   mlelstv 
    102  1.1   mlelstv 	struct ipmi_bmc_args	*sc_iowait_args;
    103  1.1   mlelstv 
    104  1.1   mlelstv 	struct ipmi_sensor	*current_sensor;
    105  1.4  riastrad 	bool			sc_thread_running;
    106  1.4  riastrad 	bool			sc_thread_ready;
    107  1.4  riastrad 	bool			sc_tickle_due;
    108  1.1   mlelstv 	struct sysmon_wdog	sc_wdog;
    109  1.1   mlelstv 	struct sysmon_envsys	*sc_envsys;
    110  1.1   mlelstv 	envsys_data_t		*sc_sensor;
    111  1.1   mlelstv 	int 		sc_nsensors; /* total number of sensors */
    112  1.1   mlelstv 
    113  1.6  riastrad 	char		sc_buf[IPMI_MAX_RX + 3];
    114  1.1   mlelstv 	bool		sc_buf_rsvd;
    115  1.3   mlelstv 
    116  1.3   mlelstv 	/* request busy */
    117  1.3   mlelstv 	int		sc_mode;
    118  1.3   mlelstv #define IPMI_MODE_IDLE		0
    119  1.3   mlelstv #define IPMI_MODE_COMMAND	1
    120  1.3   mlelstv #define IPMI_MODE_ENVSYS	2
    121  1.3   mlelstv 	bool		sc_sent;
    122  1.3   mlelstv 
    123  1.3   mlelstv 	/* dummy */
    124  1.3   mlelstv 	int		sc_address;
    125  1.3   mlelstv 	int		sc_lun;
    126  1.3   mlelstv 
    127  1.3   mlelstv 	/* saved from last SEND_COMMAND */
    128  1.3   mlelstv 	int		sc_msgid;
    129  1.3   mlelstv 	int		sc_netfn;
    130  1.3   mlelstv 	int		sc_cmd;
    131  1.1   mlelstv };
    132  1.1   mlelstv 
    133  1.2   mlelstv struct ipmi_device_id {
    134  1.2   mlelstv 	uint8_t		deviceid;
    135  1.2   mlelstv 	uint8_t		revision;
    136  1.2   mlelstv 	uint8_t		fwrev1;
    137  1.2   mlelstv 	uint8_t		fwrev2;
    138  1.2   mlelstv 	uint8_t		version;
    139  1.2   mlelstv 	uint8_t		additional;
    140  1.2   mlelstv 	uint8_t		manufacturer[3];
    141  1.2   mlelstv 	uint8_t		product[2];
    142  1.2   mlelstv 	uint8_t		vendor[4];
    143  1.2   mlelstv } __packed;
    144  1.2   mlelstv 
    145  1.1   mlelstv struct ipmi_thread {
    146  1.1   mlelstv 	struct ipmi_softc   *sc;
    147  1.1   mlelstv 	volatile int	    running;
    148  1.1   mlelstv };
    149  1.1   mlelstv 
    150  1.1   mlelstv #define IPMI_WDOG_USE_NOLOG		__BIT(7)
    151  1.1   mlelstv #define IPMI_WDOG_USE_NOSTOP		__BIT(6)
    152  1.1   mlelstv #define IPMI_WDOG_USE_RSVD1		__BITS(5, 3)
    153  1.1   mlelstv #define IPMI_WDOG_USE_USE_MASK		__BITS(2, 0)
    154  1.1   mlelstv #define IPMI_WDOG_USE_USE_RSVD		__SHIFTIN(0, IPMI_WDOG_USE_USE_MASK);
    155  1.1   mlelstv #define IPMI_WDOG_USE_USE_FRB2		__SHIFTIN(1, IPMI_WDOG_USE_USE_MASK);
    156  1.1   mlelstv #define IPMI_WDOG_USE_USE_POST		__SHIFTIN(2, IPMI_WDOG_USE_USE_MASK);
    157  1.1   mlelstv #define IPMI_WDOG_USE_USE_OSLOAD	__SHIFTIN(3, IPMI_WDOG_USE_USE_MASK);
    158  1.1   mlelstv #define IPMI_WDOG_USE_USE_OS		__SHIFTIN(4, IPMI_WDOG_USE_USE_MASK);
    159  1.1   mlelstv #define IPMI_WDOG_USE_USE_OEM		__SHIFTIN(5, IPMI_WDOG_USE_USE_MASK);
    160  1.1   mlelstv 
    161  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_RSVD1		__BIT(7)
    162  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_MASK		__BITS(6, 4)
    163  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_DISABLED	__SHIFTIN(0, IPMI_WDOG_ACT_MASK)
    164  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_SMI		__SHIFTIN(1, IPMI_WDOG_ACT_MASK)
    165  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_NMI		__SHIFTIN(2, IPMI_WDOG_ACT_MASK)
    166  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_INTERRUPT	__SHIFTIN(3, IPMI_WDOG_ACT_MASK)
    167  1.1   mlelstv #define IPMI_WDOG_ACT_PRE_RSVD0		__BIT(3)
    168  1.1   mlelstv #define IPMI_WDOG_ACT_MASK		__BITS(2, 0)
    169  1.1   mlelstv #define IPMI_WDOG_ACT_DISABLED		__SHIFTIN(0, IPMI_WDOG_ACT_MASK)
    170  1.1   mlelstv #define IPMI_WDOG_ACT_RESET		__SHIFTIN(1, IPMI_WDOG_ACT_MASK)
    171  1.1   mlelstv #define IPMI_WDOG_ACT_PWROFF		__SHIFTIN(2, IPMI_WDOG_ACT_MASK)
    172  1.1   mlelstv #define IPMI_WDOG_ACT_PWRCYCLE		__SHIFTIN(3, IPMI_WDOG_ACT_MASK)
    173  1.1   mlelstv 
    174  1.1   mlelstv #define IPMI_WDOG_FLAGS_RSVD1		__BITS(7, 6)
    175  1.1   mlelstv #define IPMI_WDOG_FLAGS_OEM		__BIT(5)
    176  1.1   mlelstv #define IPMI_WDOG_FLAGS_OS		__BIT(4)
    177  1.1   mlelstv #define IPMI_WDOG_FLAGS_OSLOAD		__BIT(3)
    178  1.1   mlelstv #define IPMI_WDOG_FLAGS_POST		__BIT(2)
    179  1.1   mlelstv #define IPMI_WDOG_FLAGS_FRB2		__BIT(1)
    180  1.1   mlelstv #define IPMI_WDOG_FLAGS_RSVD0		__BIT(0)
    181  1.1   mlelstv 
    182  1.1   mlelstv struct ipmi_set_watchdog {
    183  1.1   mlelstv 	uint8_t		wdog_use;
    184  1.1   mlelstv 	uint8_t		wdog_action;
    185  1.1   mlelstv 	uint8_t		wdog_pretimeout;
    186  1.1   mlelstv 	uint8_t		wdog_flags;
    187  1.1   mlelstv 	uint16_t		wdog_timeout;
    188  1.1   mlelstv } __packed;
    189  1.1   mlelstv 
    190  1.1   mlelstv struct ipmi_get_watchdog {
    191  1.1   mlelstv 	uint8_t		wdog_use;
    192  1.1   mlelstv 	uint8_t		wdog_action;
    193  1.1   mlelstv 	uint8_t		wdog_pretimeout;
    194  1.1   mlelstv 	uint8_t		wdog_flags;
    195  1.1   mlelstv 	uint16_t		wdog_timeout;
    196  1.1   mlelstv 	uint16_t		wdog_countdown;
    197  1.1   mlelstv } __packed;
    198  1.1   mlelstv 
    199  1.1   mlelstv struct dmd_ipmi {
    200  1.1   mlelstv 	uint8_t	dmd_sig[4];		/* Signature 'IPMI' */
    201  1.1   mlelstv 	uint8_t	dmd_i2c_address;	/* Address of BMC */
    202  1.1   mlelstv 	uint8_t	dmd_nvram_address;	/* Address of NVRAM */
    203  1.1   mlelstv 	uint8_t	dmd_if_type;		/* IPMI Interface Type */
    204  1.1   mlelstv 	uint8_t	dmd_if_rev;		/* IPMI Interface Revision */
    205  1.1   mlelstv } __packed;
    206  1.1   mlelstv 
    207  1.1   mlelstv #define APP_NETFN			0x06
    208  1.1   mlelstv #define APP_GET_DEVICE_ID		0x01
    209  1.1   mlelstv #define APP_RESET_WATCHDOG		0x22
    210  1.1   mlelstv #define APP_SET_WATCHDOG_TIMER		0x24
    211  1.1   mlelstv #define APP_GET_WATCHDOG_TIMER		0x25
    212  1.1   mlelstv 
    213  1.1   mlelstv #define TRANSPORT_NETFN			0xC
    214  1.1   mlelstv #define BRIDGE_NETFN			0x2
    215  1.1   mlelstv 
    216  1.1   mlelstv #define STORAGE_NETFN			0x0A
    217  1.1   mlelstv #define STORAGE_GET_FRU_INV_AREA	0x10
    218  1.1   mlelstv #define STORAGE_READ_FRU_DATA		0x11
    219  1.1   mlelstv #define STORAGE_RESERVE_SDR		0x22
    220  1.1   mlelstv #define STORAGE_GET_SDR			0x23
    221  1.1   mlelstv #define STORAGE_ADD_SDR			0x24
    222  1.1   mlelstv #define STORAGE_ADD_PARTIAL_SDR		0x25
    223  1.1   mlelstv #define STORAGE_DELETE_SDR		0x26
    224  1.1   mlelstv #define STORAGE_RESERVE_SEL		0x42
    225  1.1   mlelstv #define STORAGE_GET_SEL			0x43
    226  1.1   mlelstv #define STORAGE_ADD_SEL			0x44
    227  1.1   mlelstv #define STORAGE_ADD_PARTIAL_SEL		0x45
    228  1.1   mlelstv #define STORAGE_DELETE_SEL		0x46
    229  1.1   mlelstv 
    230  1.1   mlelstv #define SE_NETFN			0x04
    231  1.1   mlelstv #define SE_GET_SDR_INFO			0x20
    232  1.1   mlelstv #define SE_GET_SDR			0x21
    233  1.1   mlelstv #define SE_RESERVE_SDR			0x22
    234  1.1   mlelstv #define SE_GET_SENSOR_FACTOR		0x23
    235  1.1   mlelstv #define SE_SET_SENSOR_HYSTERESIS	0x24
    236  1.1   mlelstv #define SE_GET_SENSOR_HYSTERESIS	0x25
    237  1.1   mlelstv #define SE_SET_SENSOR_THRESHOLD		0x26
    238  1.1   mlelstv #define SE_GET_SENSOR_THRESHOLD		0x27
    239  1.1   mlelstv #define SE_SET_SENSOR_EVENT_ENABLE	0x28
    240  1.1   mlelstv #define SE_GET_SENSOR_EVENT_ENABLE	0x29
    241  1.1   mlelstv #define SE_REARM_SENSOR_EVENTS		0x2A
    242  1.1   mlelstv #define SE_GET_SENSOR_EVENT_STATUS	0x2B
    243  1.1   mlelstv #define SE_GET_SENSOR_READING		0x2D
    244  1.1   mlelstv #define SE_SET_SENSOR_TYPE		0x2E
    245  1.1   mlelstv #define SE_GET_SENSOR_TYPE		0x2F
    246  1.1   mlelstv 
    247  1.1   mlelstv struct sdrhdr {
    248  1.1   mlelstv 	uint16_t	record_id;		/* SDR Record ID */
    249  1.1   mlelstv 	uint8_t	sdr_version;		/* SDR Version */
    250  1.1   mlelstv 	uint8_t	record_type;		/* SDR Record Type */
    251  1.1   mlelstv 	uint8_t	record_length;		/* SDR Record Length */
    252  1.1   mlelstv } __packed;
    253  1.1   mlelstv 
    254  1.1   mlelstv /* SDR: Record Type 1 */
    255  1.1   mlelstv struct sdrtype1 {
    256  1.1   mlelstv 	struct sdrhdr	sdrhdr;
    257  1.1   mlelstv 
    258  1.1   mlelstv 	uint8_t	owner_id;
    259  1.1   mlelstv 	uint8_t	owner_lun;
    260  1.1   mlelstv 	uint8_t	sensor_num;
    261  1.1   mlelstv 
    262  1.1   mlelstv 	uint8_t	entity_id;
    263  1.1   mlelstv 	uint8_t	entity_instance;
    264  1.1   mlelstv 	uint8_t	sensor_init;
    265  1.1   mlelstv 	uint8_t	sensor_caps;
    266  1.1   mlelstv 	uint8_t	sensor_type;
    267  1.1   mlelstv 	uint8_t	event_code;
    268  1.1   mlelstv 	uint16_t	trigger_mask;
    269  1.1   mlelstv 	uint16_t	reading_mask;
    270  1.1   mlelstv 	uint16_t	settable_mask;
    271  1.1   mlelstv 	uint8_t	units1;
    272  1.1   mlelstv 	uint8_t	units2;
    273  1.1   mlelstv 	uint8_t	units3;
    274  1.1   mlelstv 	uint8_t	linear;
    275  1.1   mlelstv 	uint8_t	m;
    276  1.1   mlelstv 	uint8_t	m_tolerance;
    277  1.1   mlelstv 	uint8_t	b;
    278  1.1   mlelstv 	uint8_t	b_accuracy;
    279  1.1   mlelstv 	uint8_t	accuracyexp;
    280  1.1   mlelstv 	uint8_t	rbexp;
    281  1.1   mlelstv 	uint8_t	analogchars;
    282  1.1   mlelstv 	uint8_t	nominalreading;
    283  1.1   mlelstv 	uint8_t	normalmax;
    284  1.1   mlelstv 	uint8_t	normalmin;
    285  1.1   mlelstv 	uint8_t	sensormax;
    286  1.1   mlelstv 	uint8_t	sensormin;
    287  1.1   mlelstv 	uint8_t	uppernr;
    288  1.1   mlelstv 	uint8_t	upperc;
    289  1.1   mlelstv 	uint8_t	uppernc;
    290  1.1   mlelstv 	uint8_t	lowernr;
    291  1.1   mlelstv 	uint8_t	lowerc;
    292  1.1   mlelstv 	uint8_t	lowernc;
    293  1.1   mlelstv 	uint8_t	physt;
    294  1.1   mlelstv 	uint8_t	nhyst;
    295  1.1   mlelstv 	uint8_t	resvd[2];
    296  1.1   mlelstv 	uint8_t	oem;
    297  1.1   mlelstv 	uint8_t	typelen;
    298  1.1   mlelstv 	uint8_t	name[1];
    299  1.1   mlelstv } __packed;
    300  1.1   mlelstv 
    301  1.1   mlelstv /* SDR: Record Type 2 */
    302  1.1   mlelstv struct sdrtype2 {
    303  1.1   mlelstv 	struct sdrhdr	sdrhdr;
    304  1.1   mlelstv 
    305  1.1   mlelstv 	uint8_t	owner_id;
    306  1.1   mlelstv 	uint8_t	owner_lun;
    307  1.1   mlelstv 	uint8_t	sensor_num;
    308  1.1   mlelstv 
    309  1.1   mlelstv 	uint8_t	entity_id;
    310  1.1   mlelstv 	uint8_t	entity_instance;
    311  1.1   mlelstv 	uint8_t	sensor_init;
    312  1.1   mlelstv 	uint8_t	sensor_caps;
    313  1.1   mlelstv 	uint8_t	sensor_type;
    314  1.1   mlelstv 	uint8_t	event_code;
    315  1.1   mlelstv 	uint16_t	trigger_mask;
    316  1.1   mlelstv 	uint16_t	reading_mask;
    317  1.1   mlelstv 	uint16_t	set_mask;
    318  1.1   mlelstv 	uint8_t	units1;
    319  1.1   mlelstv 	uint8_t	units2;
    320  1.1   mlelstv 	uint8_t	units3;
    321  1.1   mlelstv 	uint8_t	share1;
    322  1.1   mlelstv 	uint8_t	share2;
    323  1.1   mlelstv 	uint8_t	physt;
    324  1.1   mlelstv 	uint8_t	nhyst;
    325  1.1   mlelstv 	uint8_t	resvd[3];
    326  1.1   mlelstv 	uint8_t	oem;
    327  1.1   mlelstv 	uint8_t	typelen;
    328  1.1   mlelstv 	uint8_t	name[1];
    329  1.1   mlelstv } __packed;
    330  1.1   mlelstv 
    331  1.1   mlelstv #endif				/* _IPMIVAR_H_ */
    332