xref: /illumos-gate/usr/src/uts/intel/io/ipmi/ipmivars.h (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/dev/ipmi/ipmivars.h,v 1.3 2008/08/28 02:13:53 jhb Exp $
27  */
28 
29 /*
30  * Copyright 2012, Joyent, Inc.  All rights reserved.
31  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
32  */
33 
34 #ifndef _IPMIVARS_H_
35 #define	_IPMIVARS_H_
36 
37 #include <sys/types.h>
38 #include <sys/queue.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 struct ipmi_device;
45 struct ipmi_request;
46 
47 typedef enum {
48 	IRS_ALLOCATED,
49 	IRS_QUEUED,
50 	IRS_PROCESSED,
51 	IRS_COMPLETED,
52 	IRS_CANCELED
53 } ir_status_t;
54 
55 struct ipmi_request {
56 	TAILQ_ENTRY(ipmi_request) ir_link;
57 	struct ipmi_device *ir_owner;	/* Driver uses NULL. */
58 	uchar_t		*ir_request;	/* Request is data to send to BMC. */
59 	size_t		ir_requestlen;
60 	uchar_t		*ir_reply;	/* Reply is data read from BMC. */
61 	size_t		ir_replybuflen;	/* Length of ir_reply[] buffer. */
62 	int		ir_replylen;	/* Length of reply from BMC. */
63 	int		ir_error;
64 	long		ir_msgid;
65 	uint8_t		ir_addr;
66 	uint8_t		ir_command;
67 	uint8_t		ir_compcode;
68 	int		ir_sz;		/* size of request */
69 
70 	kcondvar_t	ir_cv;
71 	ir_status_t	ir_status;
72 };
73 
74 #define	MAX_RES				3
75 #define	KCS_DATA			0
76 #define	KCS_CTL_STS			1
77 #define	SMIC_DATA			0
78 #define	SMIC_CTL_STS			1
79 #define	SMIC_FLAGS			2
80 
81 #define	IPMI_BUSY	0x1
82 #define	IPMI_CLOSING	0x2
83 
84 /* Per file descriptor data. */
85 typedef struct ipmi_device {
86 	TAILQ_HEAD(, ipmi_request) ipmi_completed_requests;
87 	pollhead_t		ipmi_pollhead;
88 	int			ipmi_requests;
89 	uchar_t			ipmi_address;	/* IPMB address. */
90 	uchar_t			ipmi_lun;
91 	dev_t			ipmi_dev;
92 	list_node_t		ipmi_node;	/* list link for open devs */
93 	int			ipmi_status;
94 	kcondvar_t		ipmi_cv;
95 } ipmi_device_t;
96 
97 struct ipmi_softc {
98 	int			ipmi_io_rid;
99 	int			ipmi_io_type;
100 	uint64_t		ipmi_io_address;
101 	int			ipmi_io_mode;
102 	int			ipmi_io_spacing;
103 	int			ipmi_io_irq;
104 	void			*ipmi_irq;
105 	int			ipmi_detaching;
106 	TAILQ_HEAD(, ipmi_request) ipmi_pending_requests;
107 	kmutex_t		ipmi_lock;
108 	kcondvar_t		ipmi_request_added;
109 	taskq_t			*ipmi_kthread;
110 	int			(*ipmi_startup)(struct ipmi_softc *);
111 	int			(*ipmi_enqueue_request)(struct ipmi_softc *,
112 				    struct ipmi_request *);
113 };
114 
115 #define	KCS_MODE		0x01
116 #define	SMIC_MODE		0x02
117 #define	BT_MODE			0x03
118 #define	SSIF_MODE		0x04
119 
120 /* KCS status flags */
121 #define	KCS_STATUS_OBF			0x01 /* Data Out ready from BMC */
122 #define	KCS_STATUS_IBF			0x02 /* Data In from System */
123 #define	KCS_STATUS_SMS_ATN		0x04 /* Ready in RX queue */
124 #define	KCS_STATUS_C_D			0x08 /* Command/Data register write */
125 #define	KCS_STATUS_OEM1			0x10
126 #define	KCS_STATUS_OEM2			0x20
127 #define	KCS_STATUS_S0			0x40
128 #define	KCS_STATUS_S1			0x80
129 #define	KCS_STATUS_STATE(x)		((x)>>6)
130 #define	KCS_STATUS_STATE_IDLE		0x0
131 #define	KCS_STATUS_STATE_READ		0x1
132 #define	KCS_STATUS_STATE_WRITE		0x2
133 #define	KCS_STATUS_STATE_ERROR		0x3
134 #define	KCS_IFACE_STATUS_OK		0x00
135 #define	KCS_IFACE_STATUS_ABORT		0x01
136 #define	KCS_IFACE_STATUS_ILLEGAL	0x02
137 #define	KCS_IFACE_STATUS_LENGTH_ERR	0x06
138 #define	KCS_IFACE_STATUS_UNKNOWN_ERR	0xff
139 
140 /* KCS control codes */
141 #define	KCS_CONTROL_GET_STATUS_ABORT	0x60
142 #define	KCS_CONTROL_WRITE_START		0x61
143 #define	KCS_CONTROL_WRITE_END		0x62
144 #define	KCS_DATA_IN_READ		0x68
145 
146 /* SMIC status flags */
147 #define	SMIC_STATUS_BUSY		0x01 /* System set and BMC clears it */
148 #define	SMIC_STATUS_SMS_ATN		0x04 /* BMC has a message */
149 #define	SMIC_STATUS_EVT_ATN		0x08 /* Event has been RX */
150 #define	SMIC_STATUS_SMI			0x10 /* asserted SMI */
151 #define	SMIC_STATUS_TX_RDY		0x40 /* Ready to accept WRITE */
152 #define	SMIC_STATUS_RX_RDY		0x80 /* Ready to read */
153 #define	SMIC_STATUS_RESERVED		0x22
154 
155 /* SMIC control codes */
156 #define	SMIC_CC_SMS_GET_STATUS		0x40
157 #define	SMIC_CC_SMS_WR_START		0x41
158 #define	SMIC_CC_SMS_WR_NEXT		0x42
159 #define	SMIC_CC_SMS_WR_END		0x43
160 #define	SMIC_CC_SMS_RD_START		0x44
161 #define	SMIC_CC_SMS_RD_NEXT		0x45
162 #define	SMIC_CC_SMS_RD_END		0x46
163 
164 /* SMIC status codes */
165 #define	SMIC_SC_SMS_RDY			0xc0
166 #define	SMIC_SC_SMS_WR_START		0xc1
167 #define	SMIC_SC_SMS_WR_NEXT		0xc2
168 #define	SMIC_SC_SMS_WR_END		0xc3
169 #define	SMIC_SC_SMS_RD_START		0xc4
170 #define	SMIC_SC_SMS_RD_NEXT		0xc5
171 #define	SMIC_SC_SMS_RD_END		0xc6
172 
173 #define	IPMI_ADDR(netfn, lun)		((netfn) << 2 | (lun))
174 #define	IPMI_REPLY_ADDR(addr)		((addr) + 0x4)
175 
176 #define	IPMI_LOCK(sc)			mutex_enter(&(sc)->ipmi_lock)
177 #define	IPMI_UNLOCK(sc)			mutex_exit(&(sc)->ipmi_lock)
178 #define	IPMI_LOCK_ASSERT(sc)		ASSERT(MUTEX_HELD(&(sc)->ipmi_lock))
179 
180 #define	ipmi_alloc_driver_request(addr, cmd, reqlen, replylen)		\
181 	ipmi_alloc_request(NULL, 0, (addr), (cmd), (reqlen), (replylen))
182 
183 #define	INB(sc, x)							\
184 	inb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x)))
185 #define	OUTB(sc, x, value)						\
186 	outb((sc)->ipmi_io_address + ((sc)->ipmi_io_spacing * (x)), value)
187 
188 #define	MAX_TIMEOUT (3 * hz)
189 
190 /* Manage requests. */
191 void	ipmi_complete_request(struct ipmi_softc *, struct ipmi_request *);
192 struct ipmi_request *ipmi_dequeue_request(struct ipmi_softc *);
193 int	ipmi_polled_enqueue_request(struct ipmi_softc *, struct ipmi_request *);
194 struct ipmi_request *ipmi_alloc_request(struct ipmi_device *, long msgid,
195 	    uint8_t, uint8_t, size_t, size_t);
196 void	ipmi_free_request(struct ipmi_request *);
197 
198 /* Interface attach routines. */
199 boolean_t ipmi_startup(struct ipmi_softc *sc);
200 int	ipmi_kcs_attach(struct ipmi_softc *);
201 
202 /* Interface detach cleanup */
203 void	ipmi_shutdown(struct ipmi_softc *sc);
204 
205 #ifdef	__cplusplus
206 }
207 #endif
208 
209 #endif	/* _IPMIVARS_H_ */
210