aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/ipmi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/ipmi')
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c643
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c65
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c18
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c943
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c114
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c450
-rw-r--r--drivers/char/ipmi/ipmi_smic_sm.c14
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c141
8 files changed, 1706 insertions, 682 deletions
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index 0030cd8e2e95..e736119b6497 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -33,11 +33,15 @@
33#include <linux/ipmi_msgdefs.h> /* for completion codes */ 33#include <linux/ipmi_msgdefs.h> /* for completion codes */
34#include "ipmi_si_sm.h" 34#include "ipmi_si_sm.h"
35 35
36static int bt_debug = 0x00; /* Production value 0, see following flags */ 36#define BT_DEBUG_OFF 0 /* Used in production */
37#define BT_DEBUG_ENABLE 1 /* Generic messages */
38#define BT_DEBUG_MSG 2 /* Prints all request/response buffers */
39#define BT_DEBUG_STATES 4 /* Verbose look at state changes */
40/* BT_DEBUG_OFF must be zero to correspond to the default uninitialized
41 value */
42
43static int bt_debug; /* 0 == BT_DEBUG_OFF */
37 44
38#define BT_DEBUG_ENABLE 1
39#define BT_DEBUG_MSG 2
40#define BT_DEBUG_STATES 4
41module_param(bt_debug, int, 0644); 45module_param(bt_debug, int, 0644);
42MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states"); 46MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
43 47
@@ -47,38 +51,54 @@ MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
47 Since the Open IPMI architecture is single-message oriented at this 51 Since the Open IPMI architecture is single-message oriented at this
48 stage, the queue depth of BT is of no concern. */ 52 stage, the queue depth of BT is of no concern. */
49 53
50#define BT_NORMAL_TIMEOUT 5000000 /* seconds in microseconds */ 54#define BT_NORMAL_TIMEOUT 5 /* seconds */
51#define BT_RETRY_LIMIT 2 55#define BT_NORMAL_RETRY_LIMIT 2
52#define BT_RESET_DELAY 6000000 /* 6 seconds after warm reset */ 56#define BT_RESET_DELAY 6 /* seconds after warm reset */
57
58/* States are written in chronological order and usually cover
59 multiple rows of the state table discussion in the IPMI spec. */
53 60
54enum bt_states { 61enum bt_states {
55 BT_STATE_IDLE, 62 BT_STATE_IDLE = 0, /* Order is critical in this list */
56 BT_STATE_XACTION_START, 63 BT_STATE_XACTION_START,
57 BT_STATE_WRITE_BYTES, 64 BT_STATE_WRITE_BYTES,
58 BT_STATE_WRITE_END,
59 BT_STATE_WRITE_CONSUME, 65 BT_STATE_WRITE_CONSUME,
60 BT_STATE_B2H_WAIT, 66 BT_STATE_READ_WAIT,
61 BT_STATE_READ_END, 67 BT_STATE_CLEAR_B2H,
62 BT_STATE_RESET1, /* These must come last */ 68 BT_STATE_READ_BYTES,
69 BT_STATE_RESET1, /* These must come last */
63 BT_STATE_RESET2, 70 BT_STATE_RESET2,
64 BT_STATE_RESET3, 71 BT_STATE_RESET3,
65 BT_STATE_RESTART, 72 BT_STATE_RESTART,
66 BT_STATE_HOSED 73 BT_STATE_PRINTME,
74 BT_STATE_CAPABILITIES_BEGIN,
75 BT_STATE_CAPABILITIES_END,
76 BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */
67}; 77};
68 78
79/* Macros seen at the end of state "case" blocks. They help with legibility
80 and debugging. */
81
82#define BT_STATE_CHANGE(X,Y) { bt->state = X; return Y; }
83
84#define BT_SI_SM_RETURN(Y) { last_printed = BT_STATE_PRINTME; return Y; }
85
69struct si_sm_data { 86struct si_sm_data {
70 enum bt_states state; 87 enum bt_states state;
71 enum bt_states last_state; /* assist printing and resets */
72 unsigned char seq; /* BT sequence number */ 88 unsigned char seq; /* BT sequence number */
73 struct si_sm_io *io; 89 struct si_sm_io *io;
74 unsigned char write_data[IPMI_MAX_MSG_LENGTH]; 90 unsigned char write_data[IPMI_MAX_MSG_LENGTH];
75 int write_count; 91 int write_count;
76 unsigned char read_data[IPMI_MAX_MSG_LENGTH]; 92 unsigned char read_data[IPMI_MAX_MSG_LENGTH];
77 int read_count; 93 int read_count;
78 int truncated; 94 int truncated;
79 long timeout; 95 long timeout; /* microseconds countdown */
80 unsigned int error_retries; /* end of "common" fields */ 96 int error_retries; /* end of "common" fields */
81 int nonzero_status; /* hung BMCs stay all 0 */ 97 int nonzero_status; /* hung BMCs stay all 0 */
98 enum bt_states complete; /* to divert the state machine */
99 int BT_CAP_outreqs;
100 long BT_CAP_req2rsp;
101 int BT_CAP_retries; /* Recommended retries */
82}; 102};
83 103
84#define BT_CLR_WR_PTR 0x01 /* See IPMI 1.5 table 11.6.4 */ 104#define BT_CLR_WR_PTR 0x01 /* See IPMI 1.5 table 11.6.4 */
@@ -111,86 +131,118 @@ struct si_sm_data {
111static char *state2txt(unsigned char state) 131static char *state2txt(unsigned char state)
112{ 132{
113 switch (state) { 133 switch (state) {
114 case BT_STATE_IDLE: return("IDLE"); 134 case BT_STATE_IDLE: return("IDLE");
115 case BT_STATE_XACTION_START: return("XACTION"); 135 case BT_STATE_XACTION_START: return("XACTION");
116 case BT_STATE_WRITE_BYTES: return("WR_BYTES"); 136 case BT_STATE_WRITE_BYTES: return("WR_BYTES");
117 case BT_STATE_WRITE_END: return("WR_END"); 137 case BT_STATE_WRITE_CONSUME: return("WR_CONSUME");
118 case BT_STATE_WRITE_CONSUME: return("WR_CONSUME"); 138 case BT_STATE_READ_WAIT: return("RD_WAIT");
119 case BT_STATE_B2H_WAIT: return("B2H_WAIT"); 139 case BT_STATE_CLEAR_B2H: return("CLEAR_B2H");
120 case BT_STATE_READ_END: return("RD_END"); 140 case BT_STATE_READ_BYTES: return("RD_BYTES");
121 case BT_STATE_RESET1: return("RESET1"); 141 case BT_STATE_RESET1: return("RESET1");
122 case BT_STATE_RESET2: return("RESET2"); 142 case BT_STATE_RESET2: return("RESET2");
123 case BT_STATE_RESET3: return("RESET3"); 143 case BT_STATE_RESET3: return("RESET3");
124 case BT_STATE_RESTART: return("RESTART"); 144 case BT_STATE_RESTART: return("RESTART");
125 case BT_STATE_HOSED: return("HOSED"); 145 case BT_STATE_LONG_BUSY: return("LONG_BUSY");
146 case BT_STATE_CAPABILITIES_BEGIN: return("CAP_BEGIN");
147 case BT_STATE_CAPABILITIES_END: return("CAP_END");
126 } 148 }
127 return("BAD STATE"); 149 return("BAD STATE");
128} 150}
129#define STATE2TXT state2txt(bt->state) 151#define STATE2TXT state2txt(bt->state)
130 152
131static char *status2txt(unsigned char status, char *buf) 153static char *status2txt(unsigned char status)
132{ 154{
155 /*
156 * This cannot be called by two threads at the same time and
157 * the buffer is always consumed immediately, so the static is
158 * safe to use.
159 */
160 static char buf[40];
161
133 strcpy(buf, "[ "); 162 strcpy(buf, "[ ");
134 if (status & BT_B_BUSY) strcat(buf, "B_BUSY "); 163 if (status & BT_B_BUSY)
135 if (status & BT_H_BUSY) strcat(buf, "H_BUSY "); 164 strcat(buf, "B_BUSY ");
136 if (status & BT_OEM0) strcat(buf, "OEM0 "); 165 if (status & BT_H_BUSY)
137 if (status & BT_SMS_ATN) strcat(buf, "SMS "); 166 strcat(buf, "H_BUSY ");
138 if (status & BT_B2H_ATN) strcat(buf, "B2H "); 167 if (status & BT_OEM0)
139 if (status & BT_H2B_ATN) strcat(buf, "H2B "); 168 strcat(buf, "OEM0 ");
169 if (status & BT_SMS_ATN)
170 strcat(buf, "SMS ");
171 if (status & BT_B2H_ATN)
172 strcat(buf, "B2H ");
173 if (status & BT_H2B_ATN)
174 strcat(buf, "H2B ");
140 strcat(buf, "]"); 175 strcat(buf, "]");
141 return buf; 176 return buf;
142} 177}
143#define STATUS2TXT(buf) status2txt(status, buf) 178#define STATUS2TXT status2txt(status)
179
180/* called externally at insmod time, and internally on cleanup */
144 181
145/* This will be called from within this module on a hosed condition */
146#define FIRST_SEQ 0
147static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io) 182static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io)
148{ 183{
149 bt->state = BT_STATE_IDLE; 184 memset(bt, 0, sizeof(struct si_sm_data));
150 bt->last_state = BT_STATE_IDLE; 185 if (bt->io != io) { /* external: one-time only things */
151 bt->seq = FIRST_SEQ; 186 bt->io = io;
152 bt->io = io; 187 bt->seq = 0;
153 bt->write_count = 0; 188 }
154 bt->read_count = 0; 189 bt->state = BT_STATE_IDLE; /* start here */
155 bt->error_retries = 0; 190 bt->complete = BT_STATE_IDLE; /* end here */
156 bt->nonzero_status = 0; 191 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * 1000000;
157 bt->truncated = 0; 192 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT;
158 bt->timeout = BT_NORMAL_TIMEOUT; 193 /* BT_CAP_outreqs == zero is a flag to read BT Capabilities */
159 return 3; /* We claim 3 bytes of space; ought to check SPMI table */ 194 return 3; /* We claim 3 bytes of space; ought to check SPMI table */
160} 195}
161 196
197/* Jam a completion code (probably an error) into a response */
198
199static void force_result(struct si_sm_data *bt, unsigned char completion_code)
200{
201 bt->read_data[0] = 4; /* # following bytes */
202 bt->read_data[1] = bt->write_data[1] | 4; /* Odd NetFn/LUN */
203 bt->read_data[2] = bt->write_data[2]; /* seq (ignored) */
204 bt->read_data[3] = bt->write_data[3]; /* Command */
205 bt->read_data[4] = completion_code;
206 bt->read_count = 5;
207}
208
209/* The upper state machine starts here */
210
162static int bt_start_transaction(struct si_sm_data *bt, 211static int bt_start_transaction(struct si_sm_data *bt,
163 unsigned char *data, 212 unsigned char *data,
164 unsigned int size) 213 unsigned int size)
165{ 214{
166 unsigned int i; 215 unsigned int i;
167 216
168 if ((size < 2) || (size > (IPMI_MAX_MSG_LENGTH - 2))) 217 if (size < 2)
169 return -1; 218 return IPMI_REQ_LEN_INVALID_ERR;
219 if (size > IPMI_MAX_MSG_LENGTH)
220 return IPMI_REQ_LEN_EXCEEDED_ERR;
170 221
171 if ((bt->state != BT_STATE_IDLE) && (bt->state != BT_STATE_HOSED)) 222 if (bt->state == BT_STATE_LONG_BUSY)
172 return -2; 223 return IPMI_NODE_BUSY_ERR;
224
225 if (bt->state != BT_STATE_IDLE)
226 return IPMI_NOT_IN_MY_STATE_ERR;
173 227
174 if (bt_debug & BT_DEBUG_MSG) { 228 if (bt_debug & BT_DEBUG_MSG) {
175 printk(KERN_WARNING "+++++++++++++++++++++++++++++++++++++\n"); 229 printk(KERN_WARNING "BT: +++++++++++++++++ New command\n");
176 printk(KERN_WARNING "BT: write seq=0x%02X:", bt->seq); 230 printk(KERN_WARNING "BT: NetFn/LUN CMD [%d data]:", size - 2);
177 for (i = 0; i < size; i ++) 231 for (i = 0; i < size; i ++)
178 printk (" %02x", data[i]); 232 printk (" %02x", data[i]);
179 printk("\n"); 233 printk("\n");
180 } 234 }
181 bt->write_data[0] = size + 1; /* all data plus seq byte */ 235 bt->write_data[0] = size + 1; /* all data plus seq byte */
182 bt->write_data[1] = *data; /* NetFn/LUN */ 236 bt->write_data[1] = *data; /* NetFn/LUN */
183 bt->write_data[2] = bt->seq; 237 bt->write_data[2] = bt->seq++;
184 memcpy(bt->write_data + 3, data + 1, size - 1); 238 memcpy(bt->write_data + 3, data + 1, size - 1);
185 bt->write_count = size + 2; 239 bt->write_count = size + 2;
186
187 bt->error_retries = 0; 240 bt->error_retries = 0;
188 bt->nonzero_status = 0; 241 bt->nonzero_status = 0;
189 bt->read_count = 0;
190 bt->truncated = 0; 242 bt->truncated = 0;
191 bt->state = BT_STATE_XACTION_START; 243 bt->state = BT_STATE_XACTION_START;
192 bt->last_state = BT_STATE_IDLE; 244 bt->timeout = bt->BT_CAP_req2rsp;
193 bt->timeout = BT_NORMAL_TIMEOUT; 245 force_result(bt, IPMI_ERR_UNSPECIFIED);
194 return 0; 246 return 0;
195} 247}
196 248
@@ -198,38 +250,30 @@ static int bt_start_transaction(struct si_sm_data *bt,
198 it calls this. Strip out the length and seq bytes. */ 250 it calls this. Strip out the length and seq bytes. */
199 251
200static int bt_get_result(struct si_sm_data *bt, 252static int bt_get_result(struct si_sm_data *bt,
201 unsigned char *data, 253 unsigned char *data,
202 unsigned int length) 254 unsigned int length)
203{ 255{
204 int i, msg_len; 256 int i, msg_len;
205 257
206 msg_len = bt->read_count - 2; /* account for length & seq */ 258 msg_len = bt->read_count - 2; /* account for length & seq */
207 /* Always NetFn, Cmd, cCode */
208 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) { 259 if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH) {
209 printk(KERN_DEBUG "BT results: bad msg_len = %d\n", msg_len); 260 force_result(bt, IPMI_ERR_UNSPECIFIED);
210 data[0] = bt->write_data[1] | 0x4; /* Kludge a response */
211 data[1] = bt->write_data[3];
212 data[2] = IPMI_ERR_UNSPECIFIED;
213 msg_len = 3; 261 msg_len = 3;
214 } else { 262 }
215 data[0] = bt->read_data[1]; 263 data[0] = bt->read_data[1];
216 data[1] = bt->read_data[3]; 264 data[1] = bt->read_data[3];
217 if (length < msg_len) 265 if (length < msg_len || bt->truncated) {
218 bt->truncated = 1; 266 data[2] = IPMI_ERR_MSG_TRUNCATED;
219 if (bt->truncated) { /* can be set in read_all_bytes() */ 267 msg_len = 3;
220 data[2] = IPMI_ERR_MSG_TRUNCATED; 268 } else
221 msg_len = 3; 269 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
222 } else
223 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
224 270
225 if (bt_debug & BT_DEBUG_MSG) { 271 if (bt_debug & BT_DEBUG_MSG) {
226 printk (KERN_WARNING "BT: res (raw)"); 272 printk (KERN_WARNING "BT: result %d bytes:", msg_len);
227 for (i = 0; i < msg_len; i++) 273 for (i = 0; i < msg_len; i++)
228 printk(" %02x", data[i]); 274 printk(" %02x", data[i]);
229 printk ("\n"); 275 printk ("\n");
230 }
231 } 276 }
232 bt->read_count = 0; /* paranoia */
233 return msg_len; 277 return msg_len;
234} 278}
235 279
@@ -238,22 +282,40 @@ static int bt_get_result(struct si_sm_data *bt,
238 282
239static void reset_flags(struct si_sm_data *bt) 283static void reset_flags(struct si_sm_data *bt)
240{ 284{
285 if (bt_debug)
286 printk(KERN_WARNING "IPMI BT: flag reset %s\n",
287 status2txt(BT_STATUS));
241 if (BT_STATUS & BT_H_BUSY) 288 if (BT_STATUS & BT_H_BUSY)
242 BT_CONTROL(BT_H_BUSY); 289 BT_CONTROL(BT_H_BUSY); /* force clear */
243 if (BT_STATUS & BT_B_BUSY) 290 BT_CONTROL(BT_CLR_WR_PTR); /* always reset */
244 BT_CONTROL(BT_B_BUSY); 291 BT_CONTROL(BT_SMS_ATN); /* always clear */
245 BT_CONTROL(BT_CLR_WR_PTR); 292 BT_INTMASK_W(BT_BMC_HWRST);
246 BT_CONTROL(BT_SMS_ATN); 293}
247 294
248 if (BT_STATUS & BT_B2H_ATN) { 295/* Get rid of an unwanted/stale response. This should only be needed for
249 int i; 296 BMCs that support multiple outstanding requests. */
250 BT_CONTROL(BT_H_BUSY); 297
251 BT_CONTROL(BT_B2H_ATN); 298static void drain_BMC2HOST(struct si_sm_data *bt)
252 BT_CONTROL(BT_CLR_RD_PTR); 299{
253 for (i = 0; i < IPMI_MAX_MSG_LENGTH + 2; i++) 300 int i, size;
254 BMC2HOST; 301
255 BT_CONTROL(BT_H_BUSY); 302 if (!(BT_STATUS & BT_B2H_ATN)) /* Not signalling a response */
256 } 303 return;
304
305 BT_CONTROL(BT_H_BUSY); /* now set */
306 BT_CONTROL(BT_B2H_ATN); /* always clear */
307 BT_STATUS; /* pause */
308 BT_CONTROL(BT_B2H_ATN); /* some BMCs are stubborn */
309 BT_CONTROL(BT_CLR_RD_PTR); /* always reset */
310 if (bt_debug)
311 printk(KERN_WARNING "IPMI BT: stale response %s; ",
312 status2txt(BT_STATUS));
313 size = BMC2HOST;
314 for (i = 0; i < size ; i++)
315 BMC2HOST;
316 BT_CONTROL(BT_H_BUSY); /* now clear */
317 if (bt_debug)
318 printk("drained %d bytes\n", size + 1);
257} 319}
258 320
259static inline void write_all_bytes(struct si_sm_data *bt) 321static inline void write_all_bytes(struct si_sm_data *bt)
@@ -261,201 +323,256 @@ static inline void write_all_bytes(struct si_sm_data *bt)
261 int i; 323 int i;
262 324
263 if (bt_debug & BT_DEBUG_MSG) { 325 if (bt_debug & BT_DEBUG_MSG) {
264 printk(KERN_WARNING "BT: write %d bytes seq=0x%02X", 326 printk(KERN_WARNING "BT: write %d bytes seq=0x%02X",
265 bt->write_count, bt->seq); 327 bt->write_count, bt->seq);
266 for (i = 0; i < bt->write_count; i++) 328 for (i = 0; i < bt->write_count; i++)
267 printk (" %02x", bt->write_data[i]); 329 printk (" %02x", bt->write_data[i]);
268 printk ("\n"); 330 printk ("\n");
269 } 331 }
270 for (i = 0; i < bt->write_count; i++) 332 for (i = 0; i < bt->write_count; i++)
271 HOST2BMC(bt->write_data[i]); 333 HOST2BMC(bt->write_data[i]);
272} 334}
273 335
274static inline int read_all_bytes(struct si_sm_data *bt) 336static inline int read_all_bytes(struct si_sm_data *bt)
275{ 337{
276 unsigned char i; 338 unsigned char i;
277 339
340 /* length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
341 Keep layout of first four bytes aligned with write_data[] */
342
278 bt->read_data[0] = BMC2HOST; 343 bt->read_data[0] = BMC2HOST;
279 bt->read_count = bt->read_data[0]; 344 bt->read_count = bt->read_data[0];
280 if (bt_debug & BT_DEBUG_MSG)
281 printk(KERN_WARNING "BT: read %d bytes:", bt->read_count);
282 345
283 /* minimum: length, NetFn, Seq, Cmd, cCode == 5 total, or 4 more
284 following the length byte. */
285 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { 346 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) {
286 if (bt_debug & BT_DEBUG_MSG) 347 if (bt_debug & BT_DEBUG_MSG)
287 printk("bad length %d\n", bt->read_count); 348 printk(KERN_WARNING "BT: bad raw rsp len=%d\n",
349 bt->read_count);
288 bt->truncated = 1; 350 bt->truncated = 1;
289 return 1; /* let next XACTION START clean it up */ 351 return 1; /* let next XACTION START clean it up */
290 } 352 }
291 for (i = 1; i <= bt->read_count; i++) 353 for (i = 1; i <= bt->read_count; i++)
292 bt->read_data[i] = BMC2HOST; 354 bt->read_data[i] = BMC2HOST;
293 bt->read_count++; /* account for the length byte */ 355 bt->read_count++; /* Account internally for length byte */
294 356
295 if (bt_debug & BT_DEBUG_MSG) { 357 if (bt_debug & BT_DEBUG_MSG) {
296 for (i = 0; i < bt->read_count; i++) 358 int max = bt->read_count;
359
360 printk(KERN_WARNING "BT: got %d bytes seq=0x%02X",
361 max, bt->read_data[2]);
362 if (max > 16)
363 max = 16;
364 for (i = 0; i < max; i++)
297 printk (" %02x", bt->read_data[i]); 365 printk (" %02x", bt->read_data[i]);
298 printk ("\n"); 366 printk ("%s\n", bt->read_count == max ? "" : " ...");
299 } 367 }
300 if (bt->seq != bt->write_data[2]) /* idiot check */
301 printk(KERN_DEBUG "BT: internal error: sequence mismatch\n");
302 368
303 /* per the spec, the (NetFn, Seq, Cmd) tuples should match */ 369 /* per the spec, the (NetFn[1], Seq[2], Cmd[3]) tuples must match */
304 if ((bt->read_data[3] == bt->write_data[3]) && /* Cmd */ 370 if ((bt->read_data[3] == bt->write_data[3]) &&
305 (bt->read_data[2] == bt->write_data[2]) && /* Sequence */ 371 (bt->read_data[2] == bt->write_data[2]) &&
306 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8))) 372 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8)))
307 return 1; 373 return 1;
308 374
309 if (bt_debug & BT_DEBUG_MSG) 375 if (bt_debug & BT_DEBUG_MSG)
310 printk(KERN_WARNING "BT: bad packet: " 376 printk(KERN_WARNING "IPMI BT: bad packet: "
311 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", 377 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n",
312 bt->write_data[1], bt->write_data[2], bt->write_data[3], 378 bt->write_data[1] | 0x04, bt->write_data[2], bt->write_data[3],
313 bt->read_data[1], bt->read_data[2], bt->read_data[3]); 379 bt->read_data[1], bt->read_data[2], bt->read_data[3]);
314 return 0; 380 return 0;
315} 381}
316 382
317/* Modifies bt->state appropriately, need to get into the bt_event() switch */ 383/* Restart if retries are left, or return an error completion code */
318 384
319static void error_recovery(struct si_sm_data *bt, char *reason) 385static enum si_sm_result error_recovery(struct si_sm_data *bt,
386 unsigned char status,
387 unsigned char cCode)
320{ 388{
321 unsigned char status; 389 char *reason;
322 char buf[40]; /* For getting status */
323 390
324 bt->timeout = BT_NORMAL_TIMEOUT; /* various places want to retry */ 391 bt->timeout = bt->BT_CAP_req2rsp;
325 392
326 status = BT_STATUS; 393 switch (cCode) {
327 printk(KERN_DEBUG "BT: %s in %s %s\n", reason, STATE2TXT, 394 case IPMI_TIMEOUT_ERR:
328 STATUS2TXT(buf)); 395 reason = "timeout";
396 break;
397 default:
398 reason = "internal error";
399 break;
400 }
401
402 printk(KERN_WARNING "IPMI BT: %s in %s %s ", /* open-ended line */
403 reason, STATE2TXT, STATUS2TXT);
329 404
405 /* Per the IPMI spec, retries are based on the sequence number
406 known only to this module, so manage a restart here. */
330 (bt->error_retries)++; 407 (bt->error_retries)++;
331 if (bt->error_retries > BT_RETRY_LIMIT) { 408 if (bt->error_retries < bt->BT_CAP_retries) {
332 printk(KERN_DEBUG "retry limit (%d) exceeded\n", BT_RETRY_LIMIT); 409 printk("%d retries left\n",
333 bt->state = BT_STATE_HOSED; 410 bt->BT_CAP_retries - bt->error_retries);
334 if (!bt->nonzero_status) 411 bt->state = BT_STATE_RESTART;
335 printk(KERN_ERR "IPMI: BT stuck, try power cycle\n"); 412 return SI_SM_CALL_WITHOUT_DELAY;
336 else if (bt->error_retries <= BT_RETRY_LIMIT + 1) {
337 printk(KERN_DEBUG "IPMI: BT reset (takes 5 secs)\n");
338 bt->state = BT_STATE_RESET1;
339 }
340 return;
341 } 413 }
342 414
343 /* Sometimes the BMC queues get in an "off-by-one" state...*/ 415 printk("failed %d retries, sending error response\n",
344 if ((bt->state == BT_STATE_B2H_WAIT) && (status & BT_B2H_ATN)) { 416 bt->BT_CAP_retries);
345 printk(KERN_DEBUG "retry B2H_WAIT\n"); 417 if (!bt->nonzero_status)
346 return; 418 printk(KERN_ERR "IPMI BT: stuck, try power cycle\n");
419
420 /* this is most likely during insmod */
421 else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) {
422 printk(KERN_WARNING "IPMI: BT reset (takes 5 secs)\n");
423 bt->state = BT_STATE_RESET1;
424 return SI_SM_CALL_WITHOUT_DELAY;
347 } 425 }
348 426
349 printk(KERN_DEBUG "restart command\n"); 427 /* Concoct a useful error message, set up the next state, and
350 bt->state = BT_STATE_RESTART; 428 be done with this sequence. */
429
430 bt->state = BT_STATE_IDLE;
431 switch (cCode) {
432 case IPMI_TIMEOUT_ERR:
433 if (status & BT_B_BUSY) {
434 cCode = IPMI_NODE_BUSY_ERR;
435 bt->state = BT_STATE_LONG_BUSY;
436 }
437 break;
438 default:
439 break;
440 }
441 force_result(bt, cCode);
442 return SI_SM_TRANSACTION_COMPLETE;
351} 443}
352 444
353/* Check the status and (possibly) advance the BT state machine. The 445/* Check status and (usually) take action and change this state machine. */
354 default return is SI_SM_CALL_WITH_DELAY. */
355 446
356static enum si_sm_result bt_event(struct si_sm_data *bt, long time) 447static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
357{ 448{
358 unsigned char status; 449 unsigned char status, BT_CAP[8];
359 char buf[40]; /* For getting status */ 450 static enum bt_states last_printed = BT_STATE_PRINTME;
360 int i; 451 int i;
361 452
362 status = BT_STATUS; 453 status = BT_STATUS;
363 bt->nonzero_status |= status; 454 bt->nonzero_status |= status;
364 455 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) {
365 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != bt->last_state))
366 printk(KERN_WARNING "BT: %s %s TO=%ld - %ld \n", 456 printk(KERN_WARNING "BT: %s %s TO=%ld - %ld \n",
367 STATE2TXT, 457 STATE2TXT,
368 STATUS2TXT(buf), 458 STATUS2TXT,
369 bt->timeout, 459 bt->timeout,
370 time); 460 time);
371 bt->last_state = bt->state; 461 last_printed = bt->state;
462 }
372 463
373 if (bt->state == BT_STATE_HOSED) 464 /* Commands that time out may still (eventually) provide a response.
374 return SI_SM_HOSED; 465 This stale response will get in the way of a new response so remove
466 it if possible (hopefully during IDLE). Even if it comes up later
467 it will be rejected by its (now-forgotten) seq number. */
468
469 if ((bt->state < BT_STATE_WRITE_BYTES) && (status & BT_B2H_ATN)) {
470 drain_BMC2HOST(bt);
471 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
472 }
375 473
376 if (bt->state != BT_STATE_IDLE) { /* do timeout test */ 474 if ((bt->state != BT_STATE_IDLE) &&
475 (bt->state < BT_STATE_PRINTME)) { /* check timeout */
377 bt->timeout -= time; 476 bt->timeout -= time;
378 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) { 477 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1))
379 error_recovery(bt, "timed out"); 478 return error_recovery(bt,
380 return SI_SM_CALL_WITHOUT_DELAY; 479 status,
381 } 480 IPMI_TIMEOUT_ERR);
382 } 481 }
383 482
384 switch (bt->state) { 483 switch (bt->state) {
385 484
386 case BT_STATE_IDLE: /* check for asynchronous messages */ 485 /* Idle state first checks for asynchronous messages from another
486 channel, then does some opportunistic housekeeping. */
487
488 case BT_STATE_IDLE:
387 if (status & BT_SMS_ATN) { 489 if (status & BT_SMS_ATN) {
388 BT_CONTROL(BT_SMS_ATN); /* clear it */ 490 BT_CONTROL(BT_SMS_ATN); /* clear it */
389 return SI_SM_ATTN; 491 return SI_SM_ATTN;
390 } 492 }
391 return SI_SM_IDLE;
392 493
393 case BT_STATE_XACTION_START: 494 if (status & BT_H_BUSY) /* clear a leftover H_BUSY */
394 if (status & BT_H_BUSY) {
395 BT_CONTROL(BT_H_BUSY); 495 BT_CONTROL(BT_H_BUSY);
396 break;
397 }
398 if (status & BT_B2H_ATN)
399 break;
400 bt->state = BT_STATE_WRITE_BYTES;
401 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
402 496
403 case BT_STATE_WRITE_BYTES: 497 /* Read BT capabilities if it hasn't been done yet */
498 if (!bt->BT_CAP_outreqs)
499 BT_STATE_CHANGE(BT_STATE_CAPABILITIES_BEGIN,
500 SI_SM_CALL_WITHOUT_DELAY);
501 bt->timeout = bt->BT_CAP_req2rsp;
502 BT_SI_SM_RETURN(SI_SM_IDLE);
503
504 case BT_STATE_XACTION_START:
404 if (status & (BT_B_BUSY | BT_H2B_ATN)) 505 if (status & (BT_B_BUSY | BT_H2B_ATN))
405 break; 506 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
507 if (BT_STATUS & BT_H_BUSY)
508 BT_CONTROL(BT_H_BUSY); /* force clear */
509 BT_STATE_CHANGE(BT_STATE_WRITE_BYTES,
510 SI_SM_CALL_WITHOUT_DELAY);
511
512 case BT_STATE_WRITE_BYTES:
513 if (status & BT_H_BUSY)
514 BT_CONTROL(BT_H_BUSY); /* clear */
406 BT_CONTROL(BT_CLR_WR_PTR); 515 BT_CONTROL(BT_CLR_WR_PTR);
407 write_all_bytes(bt); 516 write_all_bytes(bt);
408 BT_CONTROL(BT_H2B_ATN); /* clears too fast to catch? */ 517 BT_CONTROL(BT_H2B_ATN); /* can clear too fast to catch */
409 bt->state = BT_STATE_WRITE_CONSUME; 518 BT_STATE_CHANGE(BT_STATE_WRITE_CONSUME,
410 return SI_SM_CALL_WITHOUT_DELAY; /* it MIGHT sail through */ 519 SI_SM_CALL_WITHOUT_DELAY);
411
412 case BT_STATE_WRITE_CONSUME: /* BMCs usually blow right thru here */
413 if (status & (BT_H2B_ATN | BT_B_BUSY))
414 break;
415 bt->state = BT_STATE_B2H_WAIT;
416 /* fall through with status */
417
418 /* Stay in BT_STATE_B2H_WAIT until a packet matches. However, spinning
419 hard here, constantly reading status, seems to hold off the
420 generation of B2H_ATN so ALWAYS return CALL_WITH_DELAY. */
421
422 case BT_STATE_B2H_WAIT:
423 if (!(status & BT_B2H_ATN))
424 break;
425
426 /* Assume ordered, uncached writes: no need to wait */
427 if (!(status & BT_H_BUSY))
428 BT_CONTROL(BT_H_BUSY); /* set */
429 BT_CONTROL(BT_B2H_ATN); /* clear it, ACK to the BMC */
430 BT_CONTROL(BT_CLR_RD_PTR); /* reset the queue */
431 i = read_all_bytes(bt);
432 BT_CONTROL(BT_H_BUSY); /* clear */
433 if (!i) /* Try this state again */
434 break;
435 bt->state = BT_STATE_READ_END;
436 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
437
438 case BT_STATE_READ_END:
439
440 /* I could wait on BT_H_BUSY to go clear for a truly clean
441 exit. However, this is already done in XACTION_START
442 and the (possible) extra loop/status/possible wait affects
443 performance. So, as long as it works, just ignore H_BUSY */
444
445#ifdef MAKE_THIS_TRUE_IF_NECESSARY
446 520
447 if (status & BT_H_BUSY) 521 case BT_STATE_WRITE_CONSUME:
448 break; 522 if (status & (BT_B_BUSY | BT_H2B_ATN))
449#endif 523 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
450 bt->seq++; 524 BT_STATE_CHANGE(BT_STATE_READ_WAIT,
451 bt->state = BT_STATE_IDLE; 525 SI_SM_CALL_WITHOUT_DELAY);
452 return SI_SM_TRANSACTION_COMPLETE; 526
527 /* Spinning hard can suppress B2H_ATN and force a timeout */
528
529 case BT_STATE_READ_WAIT:
530 if (!(status & BT_B2H_ATN))
531 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
532 BT_CONTROL(BT_H_BUSY); /* set */
533
534 /* Uncached, ordered writes should just proceeed serially but
535 some BMCs don't clear B2H_ATN with one hit. Fast-path a
536 workaround without too much penalty to the general case. */
537
538 BT_CONTROL(BT_B2H_ATN); /* clear it to ACK the BMC */
539 BT_STATE_CHANGE(BT_STATE_CLEAR_B2H,
540 SI_SM_CALL_WITHOUT_DELAY);
541
542 case BT_STATE_CLEAR_B2H:
543 if (status & BT_B2H_ATN) { /* keep hitting it */
544 BT_CONTROL(BT_B2H_ATN);
545 BT_SI_SM_RETURN(SI_SM_CALL_WITH_DELAY);
546 }
547 BT_STATE_CHANGE(BT_STATE_READ_BYTES,
548 SI_SM_CALL_WITHOUT_DELAY);
549
550 case BT_STATE_READ_BYTES:
551 if (!(status & BT_H_BUSY)) /* check in case of retry */
552 BT_CONTROL(BT_H_BUSY);
553 BT_CONTROL(BT_CLR_RD_PTR); /* start of BMC2HOST buffer */
554 i = read_all_bytes(bt); /* true == packet seq match */
555 BT_CONTROL(BT_H_BUSY); /* NOW clear */
556 if (!i) /* Not my message */
557 BT_STATE_CHANGE(BT_STATE_READ_WAIT,
558 SI_SM_CALL_WITHOUT_DELAY);
559 bt->state = bt->complete;
560 return bt->state == BT_STATE_IDLE ? /* where to next? */
561 SI_SM_TRANSACTION_COMPLETE : /* normal */
562 SI_SM_CALL_WITHOUT_DELAY; /* Startup magic */
563
564 case BT_STATE_LONG_BUSY: /* For example: after FW update */
565 if (!(status & BT_B_BUSY)) {
566 reset_flags(bt); /* next state is now IDLE */
567 bt_init_data(bt, bt->io);
568 }
569 return SI_SM_CALL_WITH_DELAY; /* No repeat printing */
453 570
454 case BT_STATE_RESET1: 571 case BT_STATE_RESET1:
455 reset_flags(bt); 572 reset_flags(bt);
456 bt->timeout = BT_RESET_DELAY; 573 drain_BMC2HOST(bt);
457 bt->state = BT_STATE_RESET2; 574 BT_STATE_CHANGE(BT_STATE_RESET2,
458 break; 575 SI_SM_CALL_WITH_DELAY);
459 576
460 case BT_STATE_RESET2: /* Send a soft reset */ 577 case BT_STATE_RESET2: /* Send a soft reset */
461 BT_CONTROL(BT_CLR_WR_PTR); 578 BT_CONTROL(BT_CLR_WR_PTR);
@@ -464,29 +581,59 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
464 HOST2BMC(42); /* Sequence number */ 581 HOST2BMC(42); /* Sequence number */
465 HOST2BMC(3); /* Cmd == Soft reset */ 582 HOST2BMC(3); /* Cmd == Soft reset */
466 BT_CONTROL(BT_H2B_ATN); 583 BT_CONTROL(BT_H2B_ATN);
467 bt->state = BT_STATE_RESET3; 584 bt->timeout = BT_RESET_DELAY * 1000000;
468 break; 585 BT_STATE_CHANGE(BT_STATE_RESET3,
586 SI_SM_CALL_WITH_DELAY);
469 587
470 case BT_STATE_RESET3: 588 case BT_STATE_RESET3: /* Hold off everything for a bit */
471 if (bt->timeout > 0) 589 if (bt->timeout > 0)
472 return SI_SM_CALL_WITH_DELAY; 590 return SI_SM_CALL_WITH_DELAY;
473 bt->state = BT_STATE_RESTART; /* printk in debug modes */ 591 drain_BMC2HOST(bt);
474 break; 592 BT_STATE_CHANGE(BT_STATE_RESTART,
593 SI_SM_CALL_WITH_DELAY);
475 594
476 case BT_STATE_RESTART: /* don't reset retries! */ 595 case BT_STATE_RESTART: /* don't reset retries or seq! */
477 reset_flags(bt);
478 bt->write_data[2] = ++bt->seq;
479 bt->read_count = 0; 596 bt->read_count = 0;
480 bt->nonzero_status = 0; 597 bt->nonzero_status = 0;
481 bt->timeout = BT_NORMAL_TIMEOUT; 598 bt->timeout = bt->BT_CAP_req2rsp;
482 bt->state = BT_STATE_XACTION_START; 599 BT_STATE_CHANGE(BT_STATE_XACTION_START,
483 break; 600 SI_SM_CALL_WITH_DELAY);
484 601
485 default: /* HOSED is supposed to be caught much earlier */ 602 /* Get BT Capabilities, using timing of upper level state machine.
486 error_recovery(bt, "internal logic error"); 603 Set outreqs to prevent infinite loop on timeout. */
487 break; 604 case BT_STATE_CAPABILITIES_BEGIN:
488 } 605 bt->BT_CAP_outreqs = 1;
489 return SI_SM_CALL_WITH_DELAY; 606 {
607 unsigned char GetBT_CAP[] = { 0x18, 0x36 };
608 bt->state = BT_STATE_IDLE;
609 bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
610 }
611 bt->complete = BT_STATE_CAPABILITIES_END;
612 BT_STATE_CHANGE(BT_STATE_XACTION_START,
613 SI_SM_CALL_WITH_DELAY);
614
615 case BT_STATE_CAPABILITIES_END:
616 i = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
617 bt_init_data(bt, bt->io);
618 if ((i == 8) && !BT_CAP[2]) {
619 bt->BT_CAP_outreqs = BT_CAP[3];
620 bt->BT_CAP_req2rsp = BT_CAP[6] * 1000000;
621 bt->BT_CAP_retries = BT_CAP[7];
622 } else
623 printk(KERN_WARNING "IPMI BT: using default values\n");
624 if (!bt->BT_CAP_outreqs)
625 bt->BT_CAP_outreqs = 1;
626 printk(KERN_WARNING "IPMI BT: req2rsp=%ld secs retries=%d\n",
627 bt->BT_CAP_req2rsp / 1000000L, bt->BT_CAP_retries);
628 bt->timeout = bt->BT_CAP_req2rsp;
629 return SI_SM_CALL_WITHOUT_DELAY;
630
631 default: /* should never occur */
632 return error_recovery(bt,
633 status,
634 IPMI_ERR_UNSPECIFIED);
635 }
636 return SI_SM_CALL_WITH_DELAY;
490} 637}
491 638
492static int bt_detect(struct si_sm_data *bt) 639static int bt_detect(struct si_sm_data *bt)
@@ -497,7 +644,7 @@ static int bt_detect(struct si_sm_data *bt)
497 test that first. The calling routine uses negative logic. */ 644 test that first. The calling routine uses negative logic. */
498 645
499 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF)) 646 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF))
500 return 1; 647 return 1;
501 reset_flags(bt); 648 reset_flags(bt);
502 return 0; 649 return 0;
503} 650}
@@ -513,11 +660,11 @@ static int bt_size(void)
513 660
514struct si_sm_handlers bt_smi_handlers = 661struct si_sm_handlers bt_smi_handlers =
515{ 662{
516 .init_data = bt_init_data, 663 .init_data = bt_init_data,
517 .start_transaction = bt_start_transaction, 664 .start_transaction = bt_start_transaction,
518 .get_result = bt_get_result, 665 .get_result = bt_get_result,
519 .event = bt_event, 666 .event = bt_event,
520 .detect = bt_detect, 667 .detect = bt_detect,
521 .cleanup = bt_cleanup, 668 .cleanup = bt_cleanup,
522 .size = bt_size, 669 .size = bt_size,
523}; 670};
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 68d7c61a864e..ff2d052177cb 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -377,7 +377,8 @@ static int ipmi_ioctl(struct inode *inode,
377 break; 377 break;
378 } 378 }
379 379
380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd); 380 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
381 IPMI_CHAN_ALL);
381 break; 382 break;
382 } 383 }
383 384
@@ -390,7 +391,36 @@ static int ipmi_ioctl(struct inode *inode,
390 break; 391 break;
391 } 392 }
392 393
393 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd); 394 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
395 IPMI_CHAN_ALL);
396 break;
397 }
398
399 case IPMICTL_REGISTER_FOR_CMD_CHANS:
400 {
401 struct ipmi_cmdspec_chans val;
402
403 if (copy_from_user(&val, arg, sizeof(val))) {
404 rv = -EFAULT;
405 break;
406 }
407
408 rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
409 val.chans);
410 break;
411 }
412
413 case IPMICTL_UNREGISTER_FOR_CMD_CHANS:
414 {
415 struct ipmi_cmdspec_chans val;
416
417 if (copy_from_user(&val, arg, sizeof(val))) {
418 rv = -EFAULT;
419 break;
420 }
421
422 rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
423 val.chans);
394 break; 424 break;
395 } 425 }
396 426
@@ -566,6 +596,31 @@ static int ipmi_ioctl(struct inode *inode,
566 rv = 0; 596 rv = 0;
567 break; 597 break;
568 } 598 }
599
600 case IPMICTL_GET_MAINTENANCE_MODE_CMD:
601 {
602 int mode;
603
604 mode = ipmi_get_maintenance_mode(priv->user);
605 if (copy_to_user(arg, &mode, sizeof(mode))) {
606 rv = -EFAULT;
607 break;
608 }
609 rv = 0;
610 break;
611 }
612
613 case IPMICTL_SET_MAINTENANCE_MODE_CMD:
614 {
615 int mode;
616
617 if (copy_from_user(&mode, arg, sizeof(mode))) {
618 rv = -EFAULT;
619 break;
620 }
621 rv = ipmi_set_maintenance_mode(priv->user, mode);
622 break;
623 }
569 } 624 }
570 625
571 return rv; 626 return rv;
@@ -743,7 +798,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
743 if (copy_to_user(precv64, &recv64, sizeof(recv64))) 798 if (copy_to_user(precv64, &recv64, sizeof(recv64)))
744 return -EFAULT; 799 return -EFAULT;
745 800
746 rc = ipmi_ioctl(filep->f_dentry->d_inode, filep, 801 rc = ipmi_ioctl(filep->f_path.dentry->d_inode, filep,
747 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG) 802 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
748 ? IPMICTL_RECEIVE_MSG 803 ? IPMICTL_RECEIVE_MSG
749 : IPMICTL_RECEIVE_MSG_TRUNC), 804 : IPMICTL_RECEIVE_MSG_TRUNC),
@@ -760,7 +815,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
760 return rc; 815 return rc;
761 } 816 }
762 default: 817 default:
763 return ipmi_ioctl(filep->f_dentry->d_inode, filep, cmd, arg); 818 return ipmi_ioctl(filep->f_path.dentry->d_inode, filep, cmd, arg);
764 } 819 }
765} 820}
766#endif 821#endif
@@ -779,7 +834,7 @@ static const struct file_operations ipmi_fops = {
779 834
780#define DEVICE_NAME "ipmidev" 835#define DEVICE_NAME "ipmidev"
781 836
782static int ipmi_major = 0; 837static int ipmi_major;
783module_param(ipmi_major, int, 0); 838module_param(ipmi_major, int, 0);
784MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By" 839MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By"
785 " default, or if you set it to zero, it will choose the next" 840 " default, or if you set it to zero, it will choose the next"
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 2062675f9e99..c1b8228cb7b6 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -93,8 +93,8 @@ enum kcs_states {
93 state machine. */ 93 state machine. */
94}; 94};
95 95
96#define MAX_KCS_READ_SIZE 80 96#define MAX_KCS_READ_SIZE IPMI_MAX_MSG_LENGTH
97#define MAX_KCS_WRITE_SIZE 80 97#define MAX_KCS_WRITE_SIZE IPMI_MAX_MSG_LENGTH
98 98
99/* Timeouts in microseconds. */ 99/* Timeouts in microseconds. */
100#define IBF_RETRY_TIMEOUT 1000000 100#define IBF_RETRY_TIMEOUT 1000000
@@ -261,12 +261,14 @@ static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data,
261{ 261{
262 unsigned int i; 262 unsigned int i;
263 263
264 if ((size < 2) || (size > MAX_KCS_WRITE_SIZE)) { 264 if (size < 2)
265 return -1; 265 return IPMI_REQ_LEN_INVALID_ERR;
266 } 266 if (size > MAX_KCS_WRITE_SIZE)
267 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) { 267 return IPMI_REQ_LEN_EXCEEDED_ERR;
268 return -2; 268
269 } 269 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED))
270 return IPMI_NOT_IN_MY_STATE_ERR;
271
270 if (kcs_debug & KCS_DEBUG_MSG) { 272 if (kcs_debug & KCS_DEBUG_MSG) {
271 printk(KERN_DEBUG "start_kcs_transaction -"); 273 printk(KERN_DEBUG "start_kcs_transaction -");
272 for (i = 0; i < size; i ++) { 274 for (i = 0; i < size; i ++) {
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 843d34c8627c..4e4691a53890 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -48,17 +48,20 @@
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50 50
51#define IPMI_DRIVER_VERSION "39.0" 51#define IPMI_DRIVER_VERSION "39.1"
52 52
53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
55 55
56static int initialized = 0; 56static int initialized;
57 57
58#ifdef CONFIG_PROC_FS 58#ifdef CONFIG_PROC_FS
59static struct proc_dir_entry *proc_ipmi_root = NULL; 59static struct proc_dir_entry *proc_ipmi_root;
60#endif /* CONFIG_PROC_FS */ 60#endif /* CONFIG_PROC_FS */
61 61
62/* Remain in auto-maintenance mode for this amount of time (in ms). */
63#define IPMI_MAINTENANCE_MODE_TIMEOUT 30000
64
62#define MAX_EVENTS_IN_QUEUE 25 65#define MAX_EVENTS_IN_QUEUE 25
63 66
64/* Don't let a message sit in a queue forever, always time it with at lest 67/* Don't let a message sit in a queue forever, always time it with at lest
@@ -96,6 +99,7 @@ struct cmd_rcvr
96 ipmi_user_t user; 99 ipmi_user_t user;
97 unsigned char netfn; 100 unsigned char netfn;
98 unsigned char cmd; 101 unsigned char cmd;
102 unsigned int chans;
99 103
100 /* 104 /*
101 * This is used to form a linked lised during mass deletion. 105 * This is used to form a linked lised during mass deletion.
@@ -192,17 +196,28 @@ struct ipmi_smi
192 196
193 struct kref refcount; 197 struct kref refcount;
194 198
199 /* Used for a list of interfaces. */
200 struct list_head link;
201
195 /* The list of upper layers that are using me. seq_lock 202 /* The list of upper layers that are using me. seq_lock
196 * protects this. */ 203 * protects this. */
197 struct list_head users; 204 struct list_head users;
198 205
206 /* Information to supply to users. */
207 unsigned char ipmi_version_major;
208 unsigned char ipmi_version_minor;
209
199 /* Used for wake ups at startup. */ 210 /* Used for wake ups at startup. */
200 wait_queue_head_t waitq; 211 wait_queue_head_t waitq;
201 212
202 struct bmc_device *bmc; 213 struct bmc_device *bmc;
203 char *my_dev_name; 214 char *my_dev_name;
215 char *sysfs_name;
204 216
205 /* This is the lower-layer's sender routine. */ 217 /* This is the lower-layer's sender routine. Note that you
218 * must either be holding the ipmi_interfaces_mutex or be in
219 * an umpreemptible region to use this. You must fetch the
220 * value into a local variable and make sure it is not NULL. */
206 struct ipmi_smi_handlers *handlers; 221 struct ipmi_smi_handlers *handlers;
207 void *send_info; 222 void *send_info;
208 223
@@ -241,6 +256,7 @@ struct ipmi_smi
241 spinlock_t events_lock; /* For dealing with event stuff. */ 256 spinlock_t events_lock; /* For dealing with event stuff. */
242 struct list_head waiting_events; 257 struct list_head waiting_events;
243 unsigned int waiting_events_count; /* How many events in queue? */ 258 unsigned int waiting_events_count; /* How many events in queue? */
259 int delivering_events;
244 260
245 /* The event receiver for my BMC, only really used at panic 261 /* The event receiver for my BMC, only really used at panic
246 shutdown as a place to store this. */ 262 shutdown as a place to store this. */
@@ -249,6 +265,12 @@ struct ipmi_smi
249 unsigned char local_sel_device; 265 unsigned char local_sel_device;
250 unsigned char local_event_generator; 266 unsigned char local_event_generator;
251 267
268 /* For handling of maintenance mode. */
269 int maintenance_mode;
270 int maintenance_mode_enable;
271 int auto_maintenance_timeout;
272 spinlock_t maintenance_mode_lock; /* Used in a timer... */
273
252 /* A cheap hack, if this is non-null and a message to an 274 /* A cheap hack, if this is non-null and a message to an
253 interface comes in with a NULL user, call this routine with 275 interface comes in with a NULL user, call this routine with
254 it. Note that the message will still be freed by the 276 it. Note that the message will still be freed by the
@@ -337,13 +359,6 @@ struct ipmi_smi
337}; 359};
338#define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev) 360#define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
339 361
340/* Used to mark an interface entry that cannot be used but is not a
341 * free entry, either, primarily used at creation and deletion time so
342 * a slot doesn't get reused too quickly. */
343#define IPMI_INVALID_INTERFACE_ENTRY ((ipmi_smi_t) ((long) 1))
344#define IPMI_INVALID_INTERFACE(i) (((i) == NULL) \
345 || (i == IPMI_INVALID_INTERFACE_ENTRY))
346
347/** 362/**
348 * The driver model view of the IPMI messaging driver. 363 * The driver model view of the IPMI messaging driver.
349 */ 364 */
@@ -353,16 +368,13 @@ static struct device_driver ipmidriver = {
353}; 368};
354static DEFINE_MUTEX(ipmidriver_mutex); 369static DEFINE_MUTEX(ipmidriver_mutex);
355 370
356#define MAX_IPMI_INTERFACES 4 371static struct list_head ipmi_interfaces = LIST_HEAD_INIT(ipmi_interfaces);
357static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES]; 372static DEFINE_MUTEX(ipmi_interfaces_mutex);
358
359/* Directly protects the ipmi_interfaces data structure. */
360static DEFINE_SPINLOCK(interfaces_lock);
361 373
362/* List of watchers that want to know when smi's are added and 374/* List of watchers that want to know when smi's are added and
363 deleted. */ 375 deleted. */
364static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers); 376static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
365static DECLARE_RWSEM(smi_watchers_sem); 377static DEFINE_MUTEX(smi_watchers_mutex);
366 378
367 379
368static void free_recv_msg_list(struct list_head *q) 380static void free_recv_msg_list(struct list_head *q)
@@ -375,13 +387,23 @@ static void free_recv_msg_list(struct list_head *q)
375 } 387 }
376} 388}
377 389
390static void free_smi_msg_list(struct list_head *q)
391{
392 struct ipmi_smi_msg *msg, *msg2;
393
394 list_for_each_entry_safe(msg, msg2, q, link) {
395 list_del(&msg->link);
396 ipmi_free_smi_msg(msg);
397 }
398}
399
378static void clean_up_interface_data(ipmi_smi_t intf) 400static void clean_up_interface_data(ipmi_smi_t intf)
379{ 401{
380 int i; 402 int i;
381 struct cmd_rcvr *rcvr, *rcvr2; 403 struct cmd_rcvr *rcvr, *rcvr2;
382 struct list_head list; 404 struct list_head list;
383 405
384 free_recv_msg_list(&intf->waiting_msgs); 406 free_smi_msg_list(&intf->waiting_msgs);
385 free_recv_msg_list(&intf->waiting_events); 407 free_recv_msg_list(&intf->waiting_events);
386 408
387 /* Wholesale remove all the entries from the list in the 409 /* Wholesale remove all the entries from the list in the
@@ -412,48 +434,84 @@ static void intf_free(struct kref *ref)
412 kfree(intf); 434 kfree(intf);
413} 435}
414 436
437struct watcher_entry {
438 int intf_num;
439 ipmi_smi_t intf;
440 struct list_head link;
441};
442
415int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) 443int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
416{ 444{
417 int i; 445 ipmi_smi_t intf;
418 unsigned long flags; 446 struct list_head to_deliver = LIST_HEAD_INIT(to_deliver);
447 struct watcher_entry *e, *e2;
419 448
420 down_write(&smi_watchers_sem); 449 mutex_lock(&smi_watchers_mutex);
421 list_add(&(watcher->link), &smi_watchers); 450
422 up_write(&smi_watchers_sem); 451 mutex_lock(&ipmi_interfaces_mutex);
423 spin_lock_irqsave(&interfaces_lock, flags); 452
424 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 453 /* Build a list of things to deliver. */
425 ipmi_smi_t intf = ipmi_interfaces[i]; 454 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
426 if (IPMI_INVALID_INTERFACE(intf)) 455 if (intf->intf_num == -1)
427 continue; 456 continue;
428 spin_unlock_irqrestore(&interfaces_lock, flags); 457 e = kmalloc(sizeof(*e), GFP_KERNEL);
429 watcher->new_smi(i, intf->si_dev); 458 if (!e)
430 spin_lock_irqsave(&interfaces_lock, flags); 459 goto out_err;
460 kref_get(&intf->refcount);
461 e->intf = intf;
462 e->intf_num = intf->intf_num;
463 list_add_tail(&e->link, &to_deliver);
431 } 464 }
432 spin_unlock_irqrestore(&interfaces_lock, flags); 465
466 /* We will succeed, so add it to the list. */
467 list_add(&watcher->link, &smi_watchers);
468
469 mutex_unlock(&ipmi_interfaces_mutex);
470
471 list_for_each_entry_safe(e, e2, &to_deliver, link) {
472 list_del(&e->link);
473 watcher->new_smi(e->intf_num, e->intf->si_dev);
474 kref_put(&e->intf->refcount, intf_free);
475 kfree(e);
476 }
477
478 mutex_unlock(&smi_watchers_mutex);
479
433 return 0; 480 return 0;
481
482 out_err:
483 mutex_unlock(&ipmi_interfaces_mutex);
484 mutex_unlock(&smi_watchers_mutex);
485 list_for_each_entry_safe(e, e2, &to_deliver, link) {
486 list_del(&e->link);
487 kref_put(&e->intf->refcount, intf_free);
488 kfree(e);
489 }
490 return -ENOMEM;
434} 491}
435 492
436int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher) 493int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher)
437{ 494{
438 down_write(&smi_watchers_sem); 495 mutex_lock(&smi_watchers_mutex);
439 list_del(&(watcher->link)); 496 list_del(&(watcher->link));
440 up_write(&smi_watchers_sem); 497 mutex_unlock(&smi_watchers_mutex);
441 return 0; 498 return 0;
442} 499}
443 500
501/*
502 * Must be called with smi_watchers_mutex held.
503 */
444static void 504static void
445call_smi_watchers(int i, struct device *dev) 505call_smi_watchers(int i, struct device *dev)
446{ 506{
447 struct ipmi_smi_watcher *w; 507 struct ipmi_smi_watcher *w;
448 508
449 down_read(&smi_watchers_sem);
450 list_for_each_entry(w, &smi_watchers, link) { 509 list_for_each_entry(w, &smi_watchers, link) {
451 if (try_module_get(w->owner)) { 510 if (try_module_get(w->owner)) {
452 w->new_smi(i, dev); 511 w->new_smi(i, dev);
453 module_put(w->owner); 512 module_put(w->owner);
454 } 513 }
455 } 514 }
456 up_read(&smi_watchers_sem);
457} 515}
458 516
459static int 517static int
@@ -579,6 +637,17 @@ static void deliver_response(struct ipmi_recv_msg *msg)
579 } 637 }
580} 638}
581 639
640static void
641deliver_err_response(struct ipmi_recv_msg *msg, int err)
642{
643 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
644 msg->msg_data[0] = err;
645 msg->msg.netfn |= 1; /* Convert to a response. */
646 msg->msg.data_len = 1;
647 msg->msg.data = msg->msg_data;
648 deliver_response(msg);
649}
650
582/* Find the next sequence number not being used and add the given 651/* Find the next sequence number not being used and add the given
583 message with the given timeout to the sequence table. This must be 652 message with the given timeout to the sequence table. This must be
584 called with the interface's seq_lock held. */ 653 called with the interface's seq_lock held. */
@@ -716,14 +785,8 @@ static int intf_err_seq(ipmi_smi_t intf,
716 } 785 }
717 spin_unlock_irqrestore(&(intf->seq_lock), flags); 786 spin_unlock_irqrestore(&(intf->seq_lock), flags);
718 787
719 if (msg) { 788 if (msg)
720 msg->recv_type = IPMI_RESPONSE_RECV_TYPE; 789 deliver_err_response(msg, err);
721 msg->msg_data[0] = err;
722 msg->msg.netfn |= 1; /* Convert to a response. */
723 msg->msg.data_len = 1;
724 msg->msg.data = msg->msg_data;
725 deliver_response(msg);
726 }
727 790
728 return rv; 791 return rv;
729} 792}
@@ -765,17 +828,18 @@ int ipmi_create_user(unsigned int if_num,
765 if (!new_user) 828 if (!new_user)
766 return -ENOMEM; 829 return -ENOMEM;
767 830
768 spin_lock_irqsave(&interfaces_lock, flags); 831 mutex_lock(&ipmi_interfaces_mutex);
769 intf = ipmi_interfaces[if_num]; 832 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
770 if ((if_num >= MAX_IPMI_INTERFACES) || IPMI_INVALID_INTERFACE(intf)) { 833 if (intf->intf_num == if_num)
771 spin_unlock_irqrestore(&interfaces_lock, flags); 834 goto found;
772 rv = -EINVAL;
773 goto out_kfree;
774 } 835 }
836 /* Not found, return an error */
837 rv = -EINVAL;
838 goto out_kfree;
775 839
840 found:
776 /* Note that each existing user holds a refcount to the interface. */ 841 /* Note that each existing user holds a refcount to the interface. */
777 kref_get(&intf->refcount); 842 kref_get(&intf->refcount);
778 spin_unlock_irqrestore(&interfaces_lock, flags);
779 843
780 kref_init(&new_user->refcount); 844 kref_init(&new_user->refcount);
781 new_user->handler = handler; 845 new_user->handler = handler;
@@ -796,6 +860,10 @@ int ipmi_create_user(unsigned int if_num,
796 } 860 }
797 } 861 }
798 862
863 /* Hold the lock so intf->handlers is guaranteed to be good
864 * until now */
865 mutex_unlock(&ipmi_interfaces_mutex);
866
799 new_user->valid = 1; 867 new_user->valid = 1;
800 spin_lock_irqsave(&intf->seq_lock, flags); 868 spin_lock_irqsave(&intf->seq_lock, flags);
801 list_add_rcu(&new_user->link, &intf->users); 869 list_add_rcu(&new_user->link, &intf->users);
@@ -806,6 +874,7 @@ int ipmi_create_user(unsigned int if_num,
806out_kref: 874out_kref:
807 kref_put(&intf->refcount, intf_free); 875 kref_put(&intf->refcount, intf_free);
808out_kfree: 876out_kfree:
877 mutex_unlock(&ipmi_interfaces_mutex);
809 kfree(new_user); 878 kfree(new_user);
810 return rv; 879 return rv;
811} 880}
@@ -835,6 +904,7 @@ int ipmi_destroy_user(ipmi_user_t user)
835 && (intf->seq_table[i].recv_msg->user == user)) 904 && (intf->seq_table[i].recv_msg->user == user))
836 { 905 {
837 intf->seq_table[i].inuse = 0; 906 intf->seq_table[i].inuse = 0;
907 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
838 } 908 }
839 } 909 }
840 spin_unlock_irqrestore(&intf->seq_lock, flags); 910 spin_unlock_irqrestore(&intf->seq_lock, flags);
@@ -861,9 +931,13 @@ int ipmi_destroy_user(ipmi_user_t user)
861 kfree(rcvr); 931 kfree(rcvr);
862 } 932 }
863 933
864 module_put(intf->handlers->owner); 934 mutex_lock(&ipmi_interfaces_mutex);
865 if (intf->handlers->dec_usecount) 935 if (intf->handlers) {
866 intf->handlers->dec_usecount(intf->send_info); 936 module_put(intf->handlers->owner);
937 if (intf->handlers->dec_usecount)
938 intf->handlers->dec_usecount(intf->send_info);
939 }
940 mutex_unlock(&ipmi_interfaces_mutex);
867 941
868 kref_put(&intf->refcount, intf_free); 942 kref_put(&intf->refcount, intf_free);
869 943
@@ -876,8 +950,8 @@ void ipmi_get_version(ipmi_user_t user,
876 unsigned char *major, 950 unsigned char *major,
877 unsigned char *minor) 951 unsigned char *minor)
878{ 952{
879 *major = ipmi_version_major(&user->intf->bmc->id); 953 *major = user->intf->ipmi_version_major;
880 *minor = ipmi_version_minor(&user->intf->bmc->id); 954 *minor = user->intf->ipmi_version_minor;
881} 955}
882 956
883int ipmi_set_my_address(ipmi_user_t user, 957int ipmi_set_my_address(ipmi_user_t user,
@@ -920,6 +994,65 @@ int ipmi_get_my_LUN(ipmi_user_t user,
920 return 0; 994 return 0;
921} 995}
922 996
997int ipmi_get_maintenance_mode(ipmi_user_t user)
998{
999 int mode;
1000 unsigned long flags;
1001
1002 spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags);
1003 mode = user->intf->maintenance_mode;
1004 spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags);
1005
1006 return mode;
1007}
1008EXPORT_SYMBOL(ipmi_get_maintenance_mode);
1009
1010static void maintenance_mode_update(ipmi_smi_t intf)
1011{
1012 if (intf->handlers->set_maintenance_mode)
1013 intf->handlers->set_maintenance_mode(
1014 intf->send_info, intf->maintenance_mode_enable);
1015}
1016
1017int ipmi_set_maintenance_mode(ipmi_user_t user, int mode)
1018{
1019 int rv = 0;
1020 unsigned long flags;
1021 ipmi_smi_t intf = user->intf;
1022
1023 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
1024 if (intf->maintenance_mode != mode) {
1025 switch (mode) {
1026 case IPMI_MAINTENANCE_MODE_AUTO:
1027 intf->maintenance_mode = mode;
1028 intf->maintenance_mode_enable
1029 = (intf->auto_maintenance_timeout > 0);
1030 break;
1031
1032 case IPMI_MAINTENANCE_MODE_OFF:
1033 intf->maintenance_mode = mode;
1034 intf->maintenance_mode_enable = 0;
1035 break;
1036
1037 case IPMI_MAINTENANCE_MODE_ON:
1038 intf->maintenance_mode = mode;
1039 intf->maintenance_mode_enable = 1;
1040 break;
1041
1042 default:
1043 rv = -EINVAL;
1044 goto out_unlock;
1045 }
1046
1047 maintenance_mode_update(intf);
1048 }
1049 out_unlock:
1050 spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags);
1051
1052 return rv;
1053}
1054EXPORT_SYMBOL(ipmi_set_maintenance_mode);
1055
923int ipmi_set_gets_events(ipmi_user_t user, int val) 1056int ipmi_set_gets_events(ipmi_user_t user, int val)
924{ 1057{
925 unsigned long flags; 1058 unsigned long flags;
@@ -932,20 +1065,33 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
932 spin_lock_irqsave(&intf->events_lock, flags); 1065 spin_lock_irqsave(&intf->events_lock, flags);
933 user->gets_events = val; 1066 user->gets_events = val;
934 1067
935 if (val) { 1068 if (intf->delivering_events)
936 /* Deliver any queued events. */ 1069 /*
1070 * Another thread is delivering events for this, so
1071 * let it handle any new events.
1072 */
1073 goto out;
1074
1075 /* Deliver any queued events. */
1076 while (user->gets_events && !list_empty(&intf->waiting_events)) {
937 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) 1077 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link)
938 list_move_tail(&msg->link, &msgs); 1078 list_move_tail(&msg->link, &msgs);
939 intf->waiting_events_count = 0; 1079 intf->waiting_events_count = 0;
940 }
941 1080
942 /* Hold the events lock while doing this to preserve order. */ 1081 intf->delivering_events = 1;
943 list_for_each_entry_safe(msg, msg2, &msgs, link) { 1082 spin_unlock_irqrestore(&intf->events_lock, flags);
944 msg->user = user; 1083
945 kref_get(&user->refcount); 1084 list_for_each_entry_safe(msg, msg2, &msgs, link) {
946 deliver_response(msg); 1085 msg->user = user;
1086 kref_get(&user->refcount);
1087 deliver_response(msg);
1088 }
1089
1090 spin_lock_irqsave(&intf->events_lock, flags);
1091 intf->delivering_events = 0;
947 } 1092 }
948 1093
1094 out:
949 spin_unlock_irqrestore(&intf->events_lock, flags); 1095 spin_unlock_irqrestore(&intf->events_lock, flags);
950 1096
951 return 0; 1097 return 0;
@@ -953,24 +1099,41 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
953 1099
954static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, 1100static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf,
955 unsigned char netfn, 1101 unsigned char netfn,
956 unsigned char cmd) 1102 unsigned char cmd,
1103 unsigned char chan)
957{ 1104{
958 struct cmd_rcvr *rcvr; 1105 struct cmd_rcvr *rcvr;
959 1106
960 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { 1107 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
961 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) 1108 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
1109 && (rcvr->chans & (1 << chan)))
962 return rcvr; 1110 return rcvr;
963 } 1111 }
964 return NULL; 1112 return NULL;
965} 1113}
966 1114
1115static int is_cmd_rcvr_exclusive(ipmi_smi_t intf,
1116 unsigned char netfn,
1117 unsigned char cmd,
1118 unsigned int chans)
1119{
1120 struct cmd_rcvr *rcvr;
1121
1122 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
1123 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)
1124 && (rcvr->chans & chans))
1125 return 0;
1126 }
1127 return 1;
1128}
1129
967int ipmi_register_for_cmd(ipmi_user_t user, 1130int ipmi_register_for_cmd(ipmi_user_t user,
968 unsigned char netfn, 1131 unsigned char netfn,
969 unsigned char cmd) 1132 unsigned char cmd,
1133 unsigned int chans)
970{ 1134{
971 ipmi_smi_t intf = user->intf; 1135 ipmi_smi_t intf = user->intf;
972 struct cmd_rcvr *rcvr; 1136 struct cmd_rcvr *rcvr;
973 struct cmd_rcvr *entry;
974 int rv = 0; 1137 int rv = 0;
975 1138
976 1139
@@ -979,12 +1142,12 @@ int ipmi_register_for_cmd(ipmi_user_t user,
979 return -ENOMEM; 1142 return -ENOMEM;
980 rcvr->cmd = cmd; 1143 rcvr->cmd = cmd;
981 rcvr->netfn = netfn; 1144 rcvr->netfn = netfn;
1145 rcvr->chans = chans;
982 rcvr->user = user; 1146 rcvr->user = user;
983 1147
984 mutex_lock(&intf->cmd_rcvrs_mutex); 1148 mutex_lock(&intf->cmd_rcvrs_mutex);
985 /* Make sure the command/netfn is not already registered. */ 1149 /* Make sure the command/netfn is not already registered. */
986 entry = find_cmd_rcvr(intf, netfn, cmd); 1150 if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
987 if (entry) {
988 rv = -EBUSY; 1151 rv = -EBUSY;
989 goto out_unlock; 1152 goto out_unlock;
990 } 1153 }
@@ -1001,30 +1164,46 @@ int ipmi_register_for_cmd(ipmi_user_t user,
1001 1164
1002int ipmi_unregister_for_cmd(ipmi_user_t user, 1165int ipmi_unregister_for_cmd(ipmi_user_t user,
1003 unsigned char netfn, 1166 unsigned char netfn,
1004 unsigned char cmd) 1167 unsigned char cmd,
1168 unsigned int chans)
1005{ 1169{
1006 ipmi_smi_t intf = user->intf; 1170 ipmi_smi_t intf = user->intf;
1007 struct cmd_rcvr *rcvr; 1171 struct cmd_rcvr *rcvr;
1172 struct cmd_rcvr *rcvrs = NULL;
1173 int i, rv = -ENOENT;
1008 1174
1009 mutex_lock(&intf->cmd_rcvrs_mutex); 1175 mutex_lock(&intf->cmd_rcvrs_mutex);
1010 /* Make sure the command/netfn is not already registered. */ 1176 for (i = 0; i < IPMI_NUM_CHANNELS; i++) {
1011 rcvr = find_cmd_rcvr(intf, netfn, cmd); 1177 if (((1 << i) & chans) == 0)
1012 if ((rcvr) && (rcvr->user == user)) { 1178 continue;
1013 list_del_rcu(&rcvr->link); 1179 rcvr = find_cmd_rcvr(intf, netfn, cmd, i);
1014 mutex_unlock(&intf->cmd_rcvrs_mutex); 1180 if (rcvr == NULL)
1015 synchronize_rcu(); 1181 continue;
1182 if (rcvr->user == user) {
1183 rv = 0;
1184 rcvr->chans &= ~chans;
1185 if (rcvr->chans == 0) {
1186 list_del_rcu(&rcvr->link);
1187 rcvr->next = rcvrs;
1188 rcvrs = rcvr;
1189 }
1190 }
1191 }
1192 mutex_unlock(&intf->cmd_rcvrs_mutex);
1193 synchronize_rcu();
1194 while (rcvrs) {
1195 rcvr = rcvrs;
1196 rcvrs = rcvr->next;
1016 kfree(rcvr); 1197 kfree(rcvr);
1017 return 0;
1018 } else {
1019 mutex_unlock(&intf->cmd_rcvrs_mutex);
1020 return -ENOENT;
1021 } 1198 }
1199 return rv;
1022} 1200}
1023 1201
1024void ipmi_user_set_run_to_completion(ipmi_user_t user, int val) 1202void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
1025{ 1203{
1026 ipmi_smi_t intf = user->intf; 1204 ipmi_smi_t intf = user->intf;
1027 intf->handlers->set_run_to_completion(intf->send_info, val); 1205 if (intf->handlers)
1206 intf->handlers->set_run_to_completion(intf->send_info, val);
1028} 1207}
1029 1208
1030static unsigned char 1209static unsigned char
@@ -1135,10 +1314,11 @@ static int i_ipmi_request(ipmi_user_t user,
1135 int retries, 1314 int retries,
1136 unsigned int retry_time_ms) 1315 unsigned int retry_time_ms)
1137{ 1316{
1138 int rv = 0; 1317 int rv = 0;
1139 struct ipmi_smi_msg *smi_msg; 1318 struct ipmi_smi_msg *smi_msg;
1140 struct ipmi_recv_msg *recv_msg; 1319 struct ipmi_recv_msg *recv_msg;
1141 unsigned long flags; 1320 unsigned long flags;
1321 struct ipmi_smi_handlers *handlers;
1142 1322
1143 1323
1144 if (supplied_recv) { 1324 if (supplied_recv) {
@@ -1161,6 +1341,13 @@ static int i_ipmi_request(ipmi_user_t user,
1161 } 1341 }
1162 } 1342 }
1163 1343
1344 rcu_read_lock();
1345 handlers = intf->handlers;
1346 if (!handlers) {
1347 rv = -ENODEV;
1348 goto out_err;
1349 }
1350
1164 recv_msg->user = user; 1351 recv_msg->user = user;
1165 if (user) 1352 if (user)
1166 kref_get(&user->refcount); 1353 kref_get(&user->refcount);
@@ -1203,6 +1390,24 @@ static int i_ipmi_request(ipmi_user_t user,
1203 goto out_err; 1390 goto out_err;
1204 } 1391 }
1205 1392
1393 if (((msg->netfn == IPMI_NETFN_APP_REQUEST)
1394 && ((msg->cmd == IPMI_COLD_RESET_CMD)
1395 || (msg->cmd == IPMI_WARM_RESET_CMD)))
1396 || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST))
1397 {
1398 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
1399 intf->auto_maintenance_timeout
1400 = IPMI_MAINTENANCE_MODE_TIMEOUT;
1401 if (!intf->maintenance_mode
1402 && !intf->maintenance_mode_enable)
1403 {
1404 intf->maintenance_mode_enable = 1;
1405 maintenance_mode_update(intf);
1406 }
1407 spin_unlock_irqrestore(&intf->maintenance_mode_lock,
1408 flags);
1409 }
1410
1206 if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) { 1411 if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) {
1207 spin_lock_irqsave(&intf->counter_lock, flags); 1412 spin_lock_irqsave(&intf->counter_lock, flags);
1208 intf->sent_invalid_commands++; 1413 intf->sent_invalid_commands++;
@@ -1477,11 +1682,14 @@ static int i_ipmi_request(ipmi_user_t user,
1477 printk("\n"); 1682 printk("\n");
1478 } 1683 }
1479#endif 1684#endif
1480 intf->handlers->sender(intf->send_info, smi_msg, priority); 1685
1686 handlers->sender(intf->send_info, smi_msg, priority);
1687 rcu_read_unlock();
1481 1688
1482 return 0; 1689 return 0;
1483 1690
1484 out_err: 1691 out_err:
1692 rcu_read_unlock();
1485 ipmi_free_smi_msg(smi_msg); 1693 ipmi_free_smi_msg(smi_msg);
1486 ipmi_free_recv_msg(recv_msg); 1694 ipmi_free_recv_msg(recv_msg);
1487 return rv; 1695 return rv;
@@ -1561,6 +1769,7 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1561 -1, 0); 1769 -1, 0);
1562} 1770}
1563 1771
1772#ifdef CONFIG_PROC_FS
1564static int ipmb_file_read_proc(char *page, char **start, off_t off, 1773static int ipmb_file_read_proc(char *page, char **start, off_t off,
1565 int count, int *eof, void *data) 1774 int count, int *eof, void *data)
1566{ 1775{
@@ -1649,6 +1858,7 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
1649 1858
1650 return (out - ((char *) page)); 1859 return (out - ((char *) page));
1651} 1860}
1861#endif /* CONFIG_PROC_FS */
1652 1862
1653int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, 1863int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
1654 read_proc_t *read_proc, write_proc_t *write_proc, 1864 read_proc_t *read_proc, write_proc_t *write_proc,
@@ -1774,13 +1984,12 @@ static int __find_bmc_prod_dev_id(struct device *dev, void *data)
1774 struct bmc_device *bmc = dev_get_drvdata(dev); 1984 struct bmc_device *bmc = dev_get_drvdata(dev);
1775 1985
1776 return (bmc->id.product_id == id->product_id 1986 return (bmc->id.product_id == id->product_id
1777 && bmc->id.product_id == id->product_id
1778 && bmc->id.device_id == id->device_id); 1987 && bmc->id.device_id == id->device_id);
1779} 1988}
1780 1989
1781static struct bmc_device *ipmi_find_bmc_prod_dev_id( 1990static struct bmc_device *ipmi_find_bmc_prod_dev_id(
1782 struct device_driver *drv, 1991 struct device_driver *drv,
1783 unsigned char product_id, unsigned char device_id) 1992 unsigned int product_id, unsigned char device_id)
1784{ 1993{
1785 struct prod_dev_id id = { 1994 struct prod_dev_id id = {
1786 .product_id = product_id, 1995 .product_id = product_id,
@@ -1811,7 +2020,7 @@ static ssize_t provides_dev_sdrs_show(struct device *dev,
1811 struct bmc_device *bmc = dev_get_drvdata(dev); 2020 struct bmc_device *bmc = dev_get_drvdata(dev);
1812 2021
1813 return snprintf(buf, 10, "%u\n", 2022 return snprintf(buf, 10, "%u\n",
1814 bmc->id.device_revision && 0x80 >> 7); 2023 (bmc->id.device_revision & 0x80) >> 7);
1815} 2024}
1816 2025
1817static ssize_t revision_show(struct device *dev, struct device_attribute *attr, 2026static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
@@ -1820,7 +2029,7 @@ static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
1820 struct bmc_device *bmc = dev_get_drvdata(dev); 2029 struct bmc_device *bmc = dev_get_drvdata(dev);
1821 2030
1822 return snprintf(buf, 20, "%u\n", 2031 return snprintf(buf, 20, "%u\n",
1823 bmc->id.device_revision && 0x0F); 2032 bmc->id.device_revision & 0x0F);
1824} 2033}
1825 2034
1826static ssize_t firmware_rev_show(struct device *dev, 2035static ssize_t firmware_rev_show(struct device *dev,
@@ -1895,12 +2104,10 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
1895 (long long) bmc->guid[8]); 2104 (long long) bmc->guid[8]);
1896} 2105}
1897 2106
1898static void 2107static void remove_files(struct bmc_device *bmc)
1899cleanup_bmc_device(struct kref *ref)
1900{ 2108{
1901 struct bmc_device *bmc; 2109 if (!bmc->dev)
1902 2110 return;
1903 bmc = container_of(ref, struct bmc_device, refcount);
1904 2111
1905 device_remove_file(&bmc->dev->dev, 2112 device_remove_file(&bmc->dev->dev,
1906 &bmc->device_id_attr); 2113 &bmc->device_id_attr);
@@ -1918,12 +2125,23 @@ cleanup_bmc_device(struct kref *ref)
1918 &bmc->manufacturer_id_attr); 2125 &bmc->manufacturer_id_attr);
1919 device_remove_file(&bmc->dev->dev, 2126 device_remove_file(&bmc->dev->dev,
1920 &bmc->product_id_attr); 2127 &bmc->product_id_attr);
2128
1921 if (bmc->id.aux_firmware_revision_set) 2129 if (bmc->id.aux_firmware_revision_set)
1922 device_remove_file(&bmc->dev->dev, 2130 device_remove_file(&bmc->dev->dev,
1923 &bmc->aux_firmware_rev_attr); 2131 &bmc->aux_firmware_rev_attr);
1924 if (bmc->guid_set) 2132 if (bmc->guid_set)
1925 device_remove_file(&bmc->dev->dev, 2133 device_remove_file(&bmc->dev->dev,
1926 &bmc->guid_attr); 2134 &bmc->guid_attr);
2135}
2136
2137static void
2138cleanup_bmc_device(struct kref *ref)
2139{
2140 struct bmc_device *bmc;
2141
2142 bmc = container_of(ref, struct bmc_device, refcount);
2143
2144 remove_files(bmc);
1927 platform_device_unregister(bmc->dev); 2145 platform_device_unregister(bmc->dev);
1928 kfree(bmc); 2146 kfree(bmc);
1929} 2147}
@@ -1932,7 +2150,11 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
1932{ 2150{
1933 struct bmc_device *bmc = intf->bmc; 2151 struct bmc_device *bmc = intf->bmc;
1934 2152
1935 sysfs_remove_link(&intf->si_dev->kobj, "bmc"); 2153 if (intf->sysfs_name) {
2154 sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name);
2155 kfree(intf->sysfs_name);
2156 intf->sysfs_name = NULL;
2157 }
1936 if (intf->my_dev_name) { 2158 if (intf->my_dev_name) {
1937 sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); 2159 sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name);
1938 kfree(intf->my_dev_name); 2160 kfree(intf->my_dev_name);
@@ -1941,10 +2163,135 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
1941 2163
1942 mutex_lock(&ipmidriver_mutex); 2164 mutex_lock(&ipmidriver_mutex);
1943 kref_put(&bmc->refcount, cleanup_bmc_device); 2165 kref_put(&bmc->refcount, cleanup_bmc_device);
2166 intf->bmc = NULL;
1944 mutex_unlock(&ipmidriver_mutex); 2167 mutex_unlock(&ipmidriver_mutex);
1945} 2168}
1946 2169
1947static int ipmi_bmc_register(ipmi_smi_t intf) 2170static int create_files(struct bmc_device *bmc)
2171{
2172 int err;
2173
2174 bmc->device_id_attr.attr.name = "device_id";
2175 bmc->device_id_attr.attr.owner = THIS_MODULE;
2176 bmc->device_id_attr.attr.mode = S_IRUGO;
2177 bmc->device_id_attr.show = device_id_show;
2178
2179 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
2180 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE;
2181 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
2182 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2183
2184 bmc->revision_attr.attr.name = "revision";
2185 bmc->revision_attr.attr.owner = THIS_MODULE;
2186 bmc->revision_attr.attr.mode = S_IRUGO;
2187 bmc->revision_attr.show = revision_show;
2188
2189 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2190 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2191 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2192 bmc->firmware_rev_attr.show = firmware_rev_show;
2193
2194 bmc->version_attr.attr.name = "ipmi_version";
2195 bmc->version_attr.attr.owner = THIS_MODULE;
2196 bmc->version_attr.attr.mode = S_IRUGO;
2197 bmc->version_attr.show = ipmi_version_show;
2198
2199 bmc->add_dev_support_attr.attr.name = "additional_device_support";
2200 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2201 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2202 bmc->add_dev_support_attr.show = add_dev_support_show;
2203
2204 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2205 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2206 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2207 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2208
2209 bmc->product_id_attr.attr.name = "product_id";
2210 bmc->product_id_attr.attr.owner = THIS_MODULE;
2211 bmc->product_id_attr.attr.mode = S_IRUGO;
2212 bmc->product_id_attr.show = product_id_show;
2213
2214 bmc->guid_attr.attr.name = "guid";
2215 bmc->guid_attr.attr.owner = THIS_MODULE;
2216 bmc->guid_attr.attr.mode = S_IRUGO;
2217 bmc->guid_attr.show = guid_show;
2218
2219 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2220 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2221 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2222 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2223
2224 err = device_create_file(&bmc->dev->dev,
2225 &bmc->device_id_attr);
2226 if (err) goto out;
2227 err = device_create_file(&bmc->dev->dev,
2228 &bmc->provides_dev_sdrs_attr);
2229 if (err) goto out_devid;
2230 err = device_create_file(&bmc->dev->dev,
2231 &bmc->revision_attr);
2232 if (err) goto out_sdrs;
2233 err = device_create_file(&bmc->dev->dev,
2234 &bmc->firmware_rev_attr);
2235 if (err) goto out_rev;
2236 err = device_create_file(&bmc->dev->dev,
2237 &bmc->version_attr);
2238 if (err) goto out_firm;
2239 err = device_create_file(&bmc->dev->dev,
2240 &bmc->add_dev_support_attr);
2241 if (err) goto out_version;
2242 err = device_create_file(&bmc->dev->dev,
2243 &bmc->manufacturer_id_attr);
2244 if (err) goto out_add_dev;
2245 err = device_create_file(&bmc->dev->dev,
2246 &bmc->product_id_attr);
2247 if (err) goto out_manu;
2248 if (bmc->id.aux_firmware_revision_set) {
2249 err = device_create_file(&bmc->dev->dev,
2250 &bmc->aux_firmware_rev_attr);
2251 if (err) goto out_prod_id;
2252 }
2253 if (bmc->guid_set) {
2254 err = device_create_file(&bmc->dev->dev,
2255 &bmc->guid_attr);
2256 if (err) goto out_aux_firm;
2257 }
2258
2259 return 0;
2260
2261out_aux_firm:
2262 if (bmc->id.aux_firmware_revision_set)
2263 device_remove_file(&bmc->dev->dev,
2264 &bmc->aux_firmware_rev_attr);
2265out_prod_id:
2266 device_remove_file(&bmc->dev->dev,
2267 &bmc->product_id_attr);
2268out_manu:
2269 device_remove_file(&bmc->dev->dev,
2270 &bmc->manufacturer_id_attr);
2271out_add_dev:
2272 device_remove_file(&bmc->dev->dev,
2273 &bmc->add_dev_support_attr);
2274out_version:
2275 device_remove_file(&bmc->dev->dev,
2276 &bmc->version_attr);
2277out_firm:
2278 device_remove_file(&bmc->dev->dev,
2279 &bmc->firmware_rev_attr);
2280out_rev:
2281 device_remove_file(&bmc->dev->dev,
2282 &bmc->revision_attr);
2283out_sdrs:
2284 device_remove_file(&bmc->dev->dev,
2285 &bmc->provides_dev_sdrs_attr);
2286out_devid:
2287 device_remove_file(&bmc->dev->dev,
2288 &bmc->device_id_attr);
2289out:
2290 return err;
2291}
2292
2293static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
2294 const char *sysfs_name)
1948{ 2295{
1949 int rv; 2296 int rv;
1950 struct bmc_device *bmc = intf->bmc; 2297 struct bmc_device *bmc = intf->bmc;
@@ -1984,9 +2331,38 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
1984 bmc->id.product_id, 2331 bmc->id.product_id,
1985 bmc->id.device_id); 2332 bmc->id.device_id);
1986 } else { 2333 } else {
1987 bmc->dev = platform_device_alloc("ipmi_bmc", 2334 char name[14];
1988 bmc->id.device_id); 2335 unsigned char orig_dev_id = bmc->id.device_id;
2336 int warn_printed = 0;
2337
2338 snprintf(name, sizeof(name),
2339 "ipmi_bmc.%4.4x", bmc->id.product_id);
2340
2341 while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
2342 bmc->id.product_id,
2343 bmc->id.device_id)) {
2344 if (!warn_printed) {
2345 printk(KERN_WARNING PFX
2346 "This machine has two different BMCs"
2347 " with the same product id and device"
2348 " id. This is an error in the"
2349 " firmware, but incrementing the"
2350 " device id to work around the problem."
2351 " Prod ID = 0x%x, Dev ID = 0x%x\n",
2352 bmc->id.product_id, bmc->id.device_id);
2353 warn_printed = 1;
2354 }
2355 bmc->id.device_id++; /* Wraps at 255 */
2356 if (bmc->id.device_id == orig_dev_id) {
2357 printk(KERN_ERR PFX
2358 "Out of device ids!\n");
2359 break;
2360 }
2361 }
2362
2363 bmc->dev = platform_device_alloc(name, bmc->id.device_id);
1989 if (!bmc->dev) { 2364 if (!bmc->dev) {
2365 mutex_unlock(&ipmidriver_mutex);
1990 printk(KERN_ERR 2366 printk(KERN_ERR
1991 "ipmi_msghandler:" 2367 "ipmi_msghandler:"
1992 " Unable to allocate platform device\n"); 2368 " Unable to allocate platform device\n");
@@ -1996,9 +2372,11 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
1996 dev_set_drvdata(&bmc->dev->dev, bmc); 2372 dev_set_drvdata(&bmc->dev->dev, bmc);
1997 kref_init(&bmc->refcount); 2373 kref_init(&bmc->refcount);
1998 2374
1999 rv = platform_device_register(bmc->dev); 2375 rv = platform_device_add(bmc->dev);
2000 mutex_unlock(&ipmidriver_mutex); 2376 mutex_unlock(&ipmidriver_mutex);
2001 if (rv) { 2377 if (rv) {
2378 platform_device_put(bmc->dev);
2379 bmc->dev = NULL;
2002 printk(KERN_ERR 2380 printk(KERN_ERR
2003 "ipmi_msghandler:" 2381 "ipmi_msghandler:"
2004 " Unable to register bmc device: %d\n", 2382 " Unable to register bmc device: %d\n",
@@ -2008,80 +2386,14 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
2008 return rv; 2386 return rv;
2009 } 2387 }
2010 2388
2011 bmc->device_id_attr.attr.name = "device_id"; 2389 rv = create_files(bmc);
2012 bmc->device_id_attr.attr.owner = THIS_MODULE; 2390 if (rv) {
2013 bmc->device_id_attr.attr.mode = S_IRUGO; 2391 mutex_lock(&ipmidriver_mutex);
2014 bmc->device_id_attr.show = device_id_show; 2392 platform_device_unregister(bmc->dev);
2015 2393 mutex_unlock(&ipmidriver_mutex);
2016 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2394
2017 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE; 2395 return rv;
2018 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2396 }
2019 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2020
2021
2022 bmc->revision_attr.attr.name = "revision";
2023 bmc->revision_attr.attr.owner = THIS_MODULE;
2024 bmc->revision_attr.attr.mode = S_IRUGO;
2025 bmc->revision_attr.show = revision_show;
2026
2027 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2028 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2029 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2030 bmc->firmware_rev_attr.show = firmware_rev_show;
2031
2032 bmc->version_attr.attr.name = "ipmi_version";
2033 bmc->version_attr.attr.owner = THIS_MODULE;
2034 bmc->version_attr.attr.mode = S_IRUGO;
2035 bmc->version_attr.show = ipmi_version_show;
2036
2037 bmc->add_dev_support_attr.attr.name
2038 = "additional_device_support";
2039 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2040 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2041 bmc->add_dev_support_attr.show = add_dev_support_show;
2042
2043 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2044 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2045 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2046 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2047
2048 bmc->product_id_attr.attr.name = "product_id";
2049 bmc->product_id_attr.attr.owner = THIS_MODULE;
2050 bmc->product_id_attr.attr.mode = S_IRUGO;
2051 bmc->product_id_attr.show = product_id_show;
2052
2053 bmc->guid_attr.attr.name = "guid";
2054 bmc->guid_attr.attr.owner = THIS_MODULE;
2055 bmc->guid_attr.attr.mode = S_IRUGO;
2056 bmc->guid_attr.show = guid_show;
2057
2058 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2059 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2060 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2061 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2062
2063 device_create_file(&bmc->dev->dev,
2064 &bmc->device_id_attr);
2065 device_create_file(&bmc->dev->dev,
2066 &bmc->provides_dev_sdrs_attr);
2067 device_create_file(&bmc->dev->dev,
2068 &bmc->revision_attr);
2069 device_create_file(&bmc->dev->dev,
2070 &bmc->firmware_rev_attr);
2071 device_create_file(&bmc->dev->dev,
2072 &bmc->version_attr);
2073 device_create_file(&bmc->dev->dev,
2074 &bmc->add_dev_support_attr);
2075 device_create_file(&bmc->dev->dev,
2076 &bmc->manufacturer_id_attr);
2077 device_create_file(&bmc->dev->dev,
2078 &bmc->product_id_attr);
2079 if (bmc->id.aux_firmware_revision_set)
2080 device_create_file(&bmc->dev->dev,
2081 &bmc->aux_firmware_rev_attr);
2082 if (bmc->guid_set)
2083 device_create_file(&bmc->dev->dev,
2084 &bmc->guid_attr);
2085 2397
2086 printk(KERN_INFO 2398 printk(KERN_INFO
2087 "ipmi: Found new BMC (man_id: 0x%6.6x, " 2399 "ipmi: Found new BMC (man_id: 0x%6.6x, "
@@ -2095,29 +2407,44 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
2095 * create symlink from system interface device to bmc device 2407 * create symlink from system interface device to bmc device
2096 * and back. 2408 * and back.
2097 */ 2409 */
2410 intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL);
2411 if (!intf->sysfs_name) {
2412 rv = -ENOMEM;
2413 printk(KERN_ERR
2414 "ipmi_msghandler: allocate link to BMC: %d\n",
2415 rv);
2416 goto out_err;
2417 }
2418
2098 rv = sysfs_create_link(&intf->si_dev->kobj, 2419 rv = sysfs_create_link(&intf->si_dev->kobj,
2099 &bmc->dev->dev.kobj, "bmc"); 2420 &bmc->dev->dev.kobj, intf->sysfs_name);
2100 if (rv) { 2421 if (rv) {
2422 kfree(intf->sysfs_name);
2423 intf->sysfs_name = NULL;
2101 printk(KERN_ERR 2424 printk(KERN_ERR
2102 "ipmi_msghandler: Unable to create bmc symlink: %d\n", 2425 "ipmi_msghandler: Unable to create bmc symlink: %d\n",
2103 rv); 2426 rv);
2104 goto out_err; 2427 goto out_err;
2105 } 2428 }
2106 2429
2107 size = snprintf(dummy, 0, "ipmi%d", intf->intf_num); 2430 size = snprintf(dummy, 0, "ipmi%d", ifnum);
2108 intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); 2431 intf->my_dev_name = kmalloc(size+1, GFP_KERNEL);
2109 if (!intf->my_dev_name) { 2432 if (!intf->my_dev_name) {
2433 kfree(intf->sysfs_name);
2434 intf->sysfs_name = NULL;
2110 rv = -ENOMEM; 2435 rv = -ENOMEM;
2111 printk(KERN_ERR 2436 printk(KERN_ERR
2112 "ipmi_msghandler: allocate link from BMC: %d\n", 2437 "ipmi_msghandler: allocate link from BMC: %d\n",
2113 rv); 2438 rv);
2114 goto out_err; 2439 goto out_err;
2115 } 2440 }
2116 snprintf(intf->my_dev_name, size+1, "ipmi%d", intf->intf_num); 2441 snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum);
2117 2442
2118 rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, 2443 rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj,
2119 intf->my_dev_name); 2444 intf->my_dev_name);
2120 if (rv) { 2445 if (rv) {
2446 kfree(intf->sysfs_name);
2447 intf->sysfs_name = NULL;
2121 kfree(intf->my_dev_name); 2448 kfree(intf->my_dev_name);
2122 intf->my_dev_name = NULL; 2449 intf->my_dev_name = NULL;
2123 printk(KERN_ERR 2450 printk(KERN_ERR
@@ -2302,17 +2629,14 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2302 void *send_info, 2629 void *send_info,
2303 struct ipmi_device_id *device_id, 2630 struct ipmi_device_id *device_id,
2304 struct device *si_dev, 2631 struct device *si_dev,
2632 const char *sysfs_name,
2305 unsigned char slave_addr) 2633 unsigned char slave_addr)
2306{ 2634{
2307 int i, j; 2635 int i, j;
2308 int rv; 2636 int rv;
2309 ipmi_smi_t intf; 2637 ipmi_smi_t intf;
2310 unsigned long flags; 2638 ipmi_smi_t tintf;
2311 int version_major; 2639 struct list_head *link;
2312 int version_minor;
2313
2314 version_major = ipmi_version_major(device_id);
2315 version_minor = ipmi_version_minor(device_id);
2316 2640
2317 /* Make sure the driver is actually initialized, this handles 2641 /* Make sure the driver is actually initialized, this handles
2318 problems with initialization order. */ 2642 problems with initialization order. */
@@ -2330,12 +2654,16 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2330 if (!intf) 2654 if (!intf)
2331 return -ENOMEM; 2655 return -ENOMEM;
2332 memset(intf, 0, sizeof(*intf)); 2656 memset(intf, 0, sizeof(*intf));
2657
2658 intf->ipmi_version_major = ipmi_version_major(device_id);
2659 intf->ipmi_version_minor = ipmi_version_minor(device_id);
2660
2333 intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL); 2661 intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL);
2334 if (!intf->bmc) { 2662 if (!intf->bmc) {
2335 kfree(intf); 2663 kfree(intf);
2336 return -ENOMEM; 2664 return -ENOMEM;
2337 } 2665 }
2338 intf->intf_num = -1; 2666 intf->intf_num = -1; /* Mark it invalid for now. */
2339 kref_init(&intf->refcount); 2667 kref_init(&intf->refcount);
2340 intf->bmc->id = *device_id; 2668 intf->bmc->id = *device_id;
2341 intf->si_dev = si_dev; 2669 intf->si_dev = si_dev;
@@ -2363,26 +2691,30 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2363 INIT_LIST_HEAD(&intf->waiting_events); 2691 INIT_LIST_HEAD(&intf->waiting_events);
2364 intf->waiting_events_count = 0; 2692 intf->waiting_events_count = 0;
2365 mutex_init(&intf->cmd_rcvrs_mutex); 2693 mutex_init(&intf->cmd_rcvrs_mutex);
2694 spin_lock_init(&intf->maintenance_mode_lock);
2366 INIT_LIST_HEAD(&intf->cmd_rcvrs); 2695 INIT_LIST_HEAD(&intf->cmd_rcvrs);
2367 init_waitqueue_head(&intf->waitq); 2696 init_waitqueue_head(&intf->waitq);
2368 2697
2369 spin_lock_init(&intf->counter_lock); 2698 spin_lock_init(&intf->counter_lock);
2370 intf->proc_dir = NULL; 2699 intf->proc_dir = NULL;
2371 2700
2372 rv = -ENOMEM; 2701 mutex_lock(&smi_watchers_mutex);
2373 spin_lock_irqsave(&interfaces_lock, flags); 2702 mutex_lock(&ipmi_interfaces_mutex);
2374 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2703 /* Look for a hole in the numbers. */
2375 if (ipmi_interfaces[i] == NULL) { 2704 i = 0;
2376 intf->intf_num = i; 2705 link = &ipmi_interfaces;
2377 /* Reserve the entry till we are done. */ 2706 list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) {
2378 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY; 2707 if (tintf->intf_num != i) {
2379 rv = 0; 2708 link = &tintf->link;
2380 break; 2709 break;
2381 } 2710 }
2711 i++;
2382 } 2712 }
2383 spin_unlock_irqrestore(&interfaces_lock, flags); 2713 /* Add the new interface in numeric order. */
2384 if (rv) 2714 if (i == 0)
2385 goto out; 2715 list_add_rcu(&intf->link, &ipmi_interfaces);
2716 else
2717 list_add_tail_rcu(&intf->link, link);
2386 2718
2387 rv = handlers->start_processing(send_info, intf); 2719 rv = handlers->start_processing(send_info, intf);
2388 if (rv) 2720 if (rv)
@@ -2390,8 +2722,9 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2390 2722
2391 get_guid(intf); 2723 get_guid(intf);
2392 2724
2393 if ((version_major > 1) 2725 if ((intf->ipmi_version_major > 1)
2394 || ((version_major == 1) && (version_minor >= 5))) 2726 || ((intf->ipmi_version_major == 1)
2727 && (intf->ipmi_version_minor >= 5)))
2395 { 2728 {
2396 /* Start scanning the channels to see what is 2729 /* Start scanning the channels to see what is
2397 available. */ 2730 available. */
@@ -2414,64 +2747,67 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2414 if (rv == 0) 2747 if (rv == 0)
2415 rv = add_proc_entries(intf, i); 2748 rv = add_proc_entries(intf, i);
2416 2749
2417 rv = ipmi_bmc_register(intf); 2750 rv = ipmi_bmc_register(intf, i, sysfs_name);
2418 2751
2419 out: 2752 out:
2420 if (rv) { 2753 if (rv) {
2421 if (intf->proc_dir) 2754 if (intf->proc_dir)
2422 remove_proc_entries(intf); 2755 remove_proc_entries(intf);
2756 intf->handlers = NULL;
2757 list_del_rcu(&intf->link);
2758 mutex_unlock(&ipmi_interfaces_mutex);
2759 mutex_unlock(&smi_watchers_mutex);
2760 synchronize_rcu();
2423 kref_put(&intf->refcount, intf_free); 2761 kref_put(&intf->refcount, intf_free);
2424 if (i < MAX_IPMI_INTERFACES) {
2425 spin_lock_irqsave(&interfaces_lock, flags);
2426 ipmi_interfaces[i] = NULL;
2427 spin_unlock_irqrestore(&interfaces_lock, flags);
2428 }
2429 } else { 2762 } else {
2430 spin_lock_irqsave(&interfaces_lock, flags); 2763 /* After this point the interface is legal to use. */
2431 ipmi_interfaces[i] = intf; 2764 intf->intf_num = i;
2432 spin_unlock_irqrestore(&interfaces_lock, flags); 2765 mutex_unlock(&ipmi_interfaces_mutex);
2433 call_smi_watchers(i, intf->si_dev); 2766 call_smi_watchers(i, intf->si_dev);
2767 mutex_unlock(&smi_watchers_mutex);
2434 } 2768 }
2435 2769
2436 return rv; 2770 return rv;
2437} 2771}
2438 2772
2773static void cleanup_smi_msgs(ipmi_smi_t intf)
2774{
2775 int i;
2776 struct seq_table *ent;
2777
2778 /* No need for locks, the interface is down. */
2779 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
2780 ent = &(intf->seq_table[i]);
2781 if (!ent->inuse)
2782 continue;
2783 deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED);
2784 }
2785}
2786
2439int ipmi_unregister_smi(ipmi_smi_t intf) 2787int ipmi_unregister_smi(ipmi_smi_t intf)
2440{ 2788{
2441 int i;
2442 struct ipmi_smi_watcher *w; 2789 struct ipmi_smi_watcher *w;
2443 unsigned long flags; 2790 int intf_num = intf->intf_num;
2444 2791
2445 ipmi_bmc_unregister(intf); 2792 ipmi_bmc_unregister(intf);
2446 2793
2447 spin_lock_irqsave(&interfaces_lock, flags); 2794 mutex_lock(&smi_watchers_mutex);
2448 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 2795 mutex_lock(&ipmi_interfaces_mutex);
2449 if (ipmi_interfaces[i] == intf) { 2796 intf->intf_num = -1;
2450 /* Set the interface number reserved until we 2797 intf->handlers = NULL;
2451 * are done. */ 2798 list_del_rcu(&intf->link);
2452 ipmi_interfaces[i] = IPMI_INVALID_INTERFACE_ENTRY; 2799 mutex_unlock(&ipmi_interfaces_mutex);
2453 intf->intf_num = -1; 2800 synchronize_rcu();
2454 break;
2455 }
2456 }
2457 spin_unlock_irqrestore(&interfaces_lock,flags);
2458 2801
2459 if (i == MAX_IPMI_INTERFACES) 2802 cleanup_smi_msgs(intf);
2460 return -ENODEV;
2461 2803
2462 remove_proc_entries(intf); 2804 remove_proc_entries(intf);
2463 2805
2464 /* Call all the watcher interfaces to tell them that 2806 /* Call all the watcher interfaces to tell them that
2465 an interface is gone. */ 2807 an interface is gone. */
2466 down_read(&smi_watchers_sem);
2467 list_for_each_entry(w, &smi_watchers, link) 2808 list_for_each_entry(w, &smi_watchers, link)
2468 w->smi_gone(i); 2809 w->smi_gone(intf_num);
2469 up_read(&smi_watchers_sem); 2810 mutex_unlock(&smi_watchers_mutex);
2470
2471 /* Allow the entry to be reused now. */
2472 spin_lock_irqsave(&interfaces_lock, flags);
2473 ipmi_interfaces[i] = NULL;
2474 spin_unlock_irqrestore(&interfaces_lock,flags);
2475 2811
2476 kref_put(&intf->refcount, intf_free); 2812 kref_put(&intf->refcount, intf_free);
2477 return 0; 2813 return 0;
@@ -2548,10 +2884,12 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2548 int rv = 0; 2884 int rv = 0;
2549 unsigned char netfn; 2885 unsigned char netfn;
2550 unsigned char cmd; 2886 unsigned char cmd;
2887 unsigned char chan;
2551 ipmi_user_t user = NULL; 2888 ipmi_user_t user = NULL;
2552 struct ipmi_ipmb_addr *ipmb_addr; 2889 struct ipmi_ipmb_addr *ipmb_addr;
2553 struct ipmi_recv_msg *recv_msg; 2890 struct ipmi_recv_msg *recv_msg;
2554 unsigned long flags; 2891 unsigned long flags;
2892 struct ipmi_smi_handlers *handlers;
2555 2893
2556 if (msg->rsp_size < 10) { 2894 if (msg->rsp_size < 10) {
2557 /* Message not big enough, just ignore it. */ 2895 /* Message not big enough, just ignore it. */
@@ -2568,9 +2906,10 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2568 2906
2569 netfn = msg->rsp[4] >> 2; 2907 netfn = msg->rsp[4] >> 2;
2570 cmd = msg->rsp[8]; 2908 cmd = msg->rsp[8];
2909 chan = msg->rsp[3] & 0xf;
2571 2910
2572 rcu_read_lock(); 2911 rcu_read_lock();
2573 rcvr = find_cmd_rcvr(intf, netfn, cmd); 2912 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2574 if (rcvr) { 2913 if (rcvr) {
2575 user = rcvr->user; 2914 user = rcvr->user;
2576 kref_get(&user->refcount); 2915 kref_get(&user->refcount);
@@ -2607,10 +2946,16 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2607 printk("\n"); 2946 printk("\n");
2608 } 2947 }
2609#endif 2948#endif
2610 intf->handlers->sender(intf->send_info, msg, 0); 2949 rcu_read_lock();
2611 2950 handlers = intf->handlers;
2612 rv = -1; /* We used the message, so return the value that 2951 if (handlers) {
2613 causes it to not be freed or queued. */ 2952 handlers->sender(intf->send_info, msg, 0);
2953 /* We used the message, so return the value
2954 that causes it to not be freed or
2955 queued. */
2956 rv = -1;
2957 }
2958 rcu_read_unlock();
2614 } else { 2959 } else {
2615 /* Deliver the message to the user. */ 2960 /* Deliver the message to the user. */
2616 spin_lock_irqsave(&intf->counter_lock, flags); 2961 spin_lock_irqsave(&intf->counter_lock, flags);
@@ -2728,6 +3073,7 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2728 int rv = 0; 3073 int rv = 0;
2729 unsigned char netfn; 3074 unsigned char netfn;
2730 unsigned char cmd; 3075 unsigned char cmd;
3076 unsigned char chan;
2731 ipmi_user_t user = NULL; 3077 ipmi_user_t user = NULL;
2732 struct ipmi_lan_addr *lan_addr; 3078 struct ipmi_lan_addr *lan_addr;
2733 struct ipmi_recv_msg *recv_msg; 3079 struct ipmi_recv_msg *recv_msg;
@@ -2748,9 +3094,10 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2748 3094
2749 netfn = msg->rsp[6] >> 2; 3095 netfn = msg->rsp[6] >> 2;
2750 cmd = msg->rsp[10]; 3096 cmd = msg->rsp[10];
3097 chan = msg->rsp[3] & 0xf;
2751 3098
2752 rcu_read_lock(); 3099 rcu_read_lock();
2753 rcvr = find_cmd_rcvr(intf, netfn, cmd); 3100 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
2754 if (rcvr) { 3101 if (rcvr) {
2755 user = rcvr->user; 3102 user = rcvr->user;
2756 kref_get(&user->refcount); 3103 kref_get(&user->refcount);
@@ -3131,7 +3478,9 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
3131 report the error immediately. */ 3478 report the error immediately. */
3132 if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0) 3479 if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0)
3133 && (msg->rsp[2] != IPMI_NODE_BUSY_ERR) 3480 && (msg->rsp[2] != IPMI_NODE_BUSY_ERR)
3134 && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)) 3481 && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)
3482 && (msg->rsp[2] != IPMI_BUS_ERR)
3483 && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR))
3135 { 3484 {
3136 int chan = msg->rsp[3] & 0xf; 3485 int chan = msg->rsp[3] & 0xf;
3137 3486
@@ -3196,16 +3545,6 @@ void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
3196 rcu_read_unlock(); 3545 rcu_read_unlock();
3197} 3546}
3198 3547
3199static void
3200handle_msg_timeout(struct ipmi_recv_msg *msg)
3201{
3202 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
3203 msg->msg_data[0] = IPMI_TIMEOUT_COMPLETION_CODE;
3204 msg->msg.netfn |= 1; /* Convert to a response. */
3205 msg->msg.data_len = 1;
3206 msg->msg.data = msg->msg_data;
3207 deliver_response(msg);
3208}
3209 3548
3210static struct ipmi_smi_msg * 3549static struct ipmi_smi_msg *
3211smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, 3550smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
@@ -3237,7 +3576,11 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
3237 struct list_head *timeouts, long timeout_period, 3576 struct list_head *timeouts, long timeout_period,
3238 int slot, unsigned long *flags) 3577 int slot, unsigned long *flags)
3239{ 3578{
3240 struct ipmi_recv_msg *msg; 3579 struct ipmi_recv_msg *msg;
3580 struct ipmi_smi_handlers *handlers;
3581
3582 if (intf->intf_num == -1)
3583 return;
3241 3584
3242 if (!ent->inuse) 3585 if (!ent->inuse)
3243 return; 3586 return;
@@ -3280,13 +3623,19 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
3280 return; 3623 return;
3281 3624
3282 spin_unlock_irqrestore(&intf->seq_lock, *flags); 3625 spin_unlock_irqrestore(&intf->seq_lock, *flags);
3626
3283 /* Send the new message. We send with a zero 3627 /* Send the new message. We send with a zero
3284 * priority. It timed out, I doubt time is 3628 * priority. It timed out, I doubt time is
3285 * that critical now, and high priority 3629 * that critical now, and high priority
3286 * messages are really only for messages to the 3630 * messages are really only for messages to the
3287 * local MC, which don't get resent. */ 3631 * local MC, which don't get resent. */
3288 intf->handlers->sender(intf->send_info, 3632 handlers = intf->handlers;
3289 smi_msg, 0); 3633 if (handlers)
3634 intf->handlers->sender(intf->send_info,
3635 smi_msg, 0);
3636 else
3637 ipmi_free_smi_msg(smi_msg);
3638
3290 spin_lock_irqsave(&intf->seq_lock, *flags); 3639 spin_lock_irqsave(&intf->seq_lock, *flags);
3291 } 3640 }
3292} 3641}
@@ -3298,18 +3647,12 @@ static void ipmi_timeout_handler(long timeout_period)
3298 struct ipmi_recv_msg *msg, *msg2; 3647 struct ipmi_recv_msg *msg, *msg2;
3299 struct ipmi_smi_msg *smi_msg, *smi_msg2; 3648 struct ipmi_smi_msg *smi_msg, *smi_msg2;
3300 unsigned long flags; 3649 unsigned long flags;
3301 int i, j; 3650 int i;
3302 3651
3303 INIT_LIST_HEAD(&timeouts); 3652 INIT_LIST_HEAD(&timeouts);
3304 3653
3305 spin_lock(&interfaces_lock); 3654 rcu_read_lock();
3306 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3655 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3307 intf = ipmi_interfaces[i];
3308 if (IPMI_INVALID_INTERFACE(intf))
3309 continue;
3310 kref_get(&intf->refcount);
3311 spin_unlock(&interfaces_lock);
3312
3313 /* See if any waiting messages need to be processed. */ 3656 /* See if any waiting messages need to be processed. */
3314 spin_lock_irqsave(&intf->waiting_msgs_lock, flags); 3657 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
3315 list_for_each_entry_safe(smi_msg, smi_msg2, 3658 list_for_each_entry_safe(smi_msg, smi_msg2,
@@ -3329,35 +3672,60 @@ static void ipmi_timeout_handler(long timeout_period)
3329 have timed out, putting them in the timeouts 3672 have timed out, putting them in the timeouts
3330 list. */ 3673 list. */
3331 spin_lock_irqsave(&intf->seq_lock, flags); 3674 spin_lock_irqsave(&intf->seq_lock, flags);
3332 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) 3675 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
3333 check_msg_timeout(intf, &(intf->seq_table[j]), 3676 check_msg_timeout(intf, &(intf->seq_table[i]),
3334 &timeouts, timeout_period, j, 3677 &timeouts, timeout_period, i,
3335 &flags); 3678 &flags);
3336 spin_unlock_irqrestore(&intf->seq_lock, flags); 3679 spin_unlock_irqrestore(&intf->seq_lock, flags);
3337 3680
3338 list_for_each_entry_safe(msg, msg2, &timeouts, link) 3681 list_for_each_entry_safe(msg, msg2, &timeouts, link)
3339 handle_msg_timeout(msg); 3682 deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE);
3340 3683
3341 kref_put(&intf->refcount, intf_free); 3684 /*
3342 spin_lock(&interfaces_lock); 3685 * Maintenance mode handling. Check the timeout
3686 * optimistically before we claim the lock. It may
3687 * mean a timeout gets missed occasionally, but that
3688 * only means the timeout gets extended by one period
3689 * in that case. No big deal, and it avoids the lock
3690 * most of the time.
3691 */
3692 if (intf->auto_maintenance_timeout > 0) {
3693 spin_lock_irqsave(&intf->maintenance_mode_lock, flags);
3694 if (intf->auto_maintenance_timeout > 0) {
3695 intf->auto_maintenance_timeout
3696 -= timeout_period;
3697 if (!intf->maintenance_mode
3698 && (intf->auto_maintenance_timeout <= 0))
3699 {
3700 intf->maintenance_mode_enable = 0;
3701 maintenance_mode_update(intf);
3702 }
3703 }
3704 spin_unlock_irqrestore(&intf->maintenance_mode_lock,
3705 flags);
3706 }
3343 } 3707 }
3344 spin_unlock(&interfaces_lock); 3708 rcu_read_unlock();
3345} 3709}
3346 3710
3347static void ipmi_request_event(void) 3711static void ipmi_request_event(void)
3348{ 3712{
3349 ipmi_smi_t intf; 3713 ipmi_smi_t intf;
3350 int i; 3714 struct ipmi_smi_handlers *handlers;
3351 3715
3352 spin_lock(&interfaces_lock); 3716 rcu_read_lock();
3353 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3717 /* Called from the timer, no need to check if handlers is
3354 intf = ipmi_interfaces[i]; 3718 * valid. */
3355 if (IPMI_INVALID_INTERFACE(intf)) 3719 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3720 /* No event requests when in maintenance mode. */
3721 if (intf->maintenance_mode_enable)
3356 continue; 3722 continue;
3357 3723
3358 intf->handlers->request_events(intf->send_info); 3724 handlers = intf->handlers;
3725 if (handlers)
3726 handlers->request_events(intf->send_info);
3359 } 3727 }
3360 spin_unlock(&interfaces_lock); 3728 rcu_read_unlock();
3361} 3729}
3362 3730
3363static struct timer_list ipmi_timer; 3731static struct timer_list ipmi_timer;
@@ -3486,7 +3854,6 @@ static void send_panic_events(char *str)
3486 struct kernel_ipmi_msg msg; 3854 struct kernel_ipmi_msg msg;
3487 ipmi_smi_t intf; 3855 ipmi_smi_t intf;
3488 unsigned char data[16]; 3856 unsigned char data[16];
3489 int i;
3490 struct ipmi_system_interface_addr *si; 3857 struct ipmi_system_interface_addr *si;
3491 struct ipmi_addr addr; 3858 struct ipmi_addr addr;
3492 struct ipmi_smi_msg smi_msg; 3859 struct ipmi_smi_msg smi_msg;
@@ -3520,9 +3887,9 @@ static void send_panic_events(char *str)
3520 recv_msg.done = dummy_recv_done_handler; 3887 recv_msg.done = dummy_recv_done_handler;
3521 3888
3522 /* For every registered interface, send the event. */ 3889 /* For every registered interface, send the event. */
3523 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3890 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3524 intf = ipmi_interfaces[i]; 3891 if (!intf->handlers)
3525 if (IPMI_INVALID_INTERFACE(intf)) 3892 /* Interface is not ready. */
3526 continue; 3893 continue;
3527 3894
3528 /* Send the event announcing the panic. */ 3895 /* Send the event announcing the panic. */
@@ -3547,13 +3914,14 @@ static void send_panic_events(char *str)
3547 if (!str) 3914 if (!str)
3548 return; 3915 return;
3549 3916
3550 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3917 /* For every registered interface, send the event. */
3918 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3551 char *p = str; 3919 char *p = str;
3552 struct ipmi_ipmb_addr *ipmb; 3920 struct ipmi_ipmb_addr *ipmb;
3553 int j; 3921 int j;
3554 3922
3555 intf = ipmi_interfaces[i]; 3923 if (intf->intf_num == -1)
3556 if (IPMI_INVALID_INTERFACE(intf)) 3924 /* Interface was not ready yet. */
3557 continue; 3925 continue;
3558 3926
3559 /* First job here is to figure out where to send the 3927 /* First job here is to figure out where to send the
@@ -3673,13 +4041,12 @@ static void send_panic_events(char *str)
3673} 4041}
3674#endif /* CONFIG_IPMI_PANIC_EVENT */ 4042#endif /* CONFIG_IPMI_PANIC_EVENT */
3675 4043
3676static int has_panicked = 0; 4044static int has_panicked;
3677 4045
3678static int panic_event(struct notifier_block *this, 4046static int panic_event(struct notifier_block *this,
3679 unsigned long event, 4047 unsigned long event,
3680 void *ptr) 4048 void *ptr)
3681{ 4049{
3682 int i;
3683 ipmi_smi_t intf; 4050 ipmi_smi_t intf;
3684 4051
3685 if (has_panicked) 4052 if (has_panicked)
@@ -3687,9 +4054,9 @@ static int panic_event(struct notifier_block *this,
3687 has_panicked = 1; 4054 has_panicked = 1;
3688 4055
3689 /* For every registered interface, set it to run to completion. */ 4056 /* For every registered interface, set it to run to completion. */
3690 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 4057 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3691 intf = ipmi_interfaces[i]; 4058 if (!intf->handlers)
3692 if (IPMI_INVALID_INTERFACE(intf)) 4059 /* Interface is not ready. */
3693 continue; 4060 continue;
3694 4061
3695 intf->handlers->set_run_to_completion(intf->send_info, 1); 4062 intf->handlers->set_run_to_completion(intf->send_info, 1);
@@ -3710,7 +4077,6 @@ static struct notifier_block panic_block = {
3710 4077
3711static int ipmi_init_msghandler(void) 4078static int ipmi_init_msghandler(void)
3712{ 4079{
3713 int i;
3714 int rv; 4080 int rv;
3715 4081
3716 if (initialized) 4082 if (initialized)
@@ -3725,9 +4091,6 @@ static int ipmi_init_msghandler(void)
3725 printk(KERN_INFO "ipmi message handler version " 4091 printk(KERN_INFO "ipmi message handler version "
3726 IPMI_DRIVER_VERSION "\n"); 4092 IPMI_DRIVER_VERSION "\n");
3727 4093
3728 for (i = 0; i < MAX_IPMI_INTERFACES; i++)
3729 ipmi_interfaces[i] = NULL;
3730
3731#ifdef CONFIG_PROC_FS 4094#ifdef CONFIG_PROC_FS
3732 proc_ipmi_root = proc_mkdir("ipmi", NULL); 4095 proc_ipmi_root = proc_mkdir("ipmi", NULL);
3733 if (!proc_ipmi_root) { 4096 if (!proc_ipmi_root) {
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 8d941db83457..9d23136e598a 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -43,6 +43,9 @@
43 43
44#define PFX "IPMI poweroff: " 44#define PFX "IPMI poweroff: "
45 45
46static void ipmi_po_smi_gone(int if_num);
47static void ipmi_po_new_smi(int if_num, struct device *device);
48
46/* Definitions for controlling power off (if the system supports it). It 49/* Definitions for controlling power off (if the system supports it). It
47 * conveniently matches the IPMI chassis control values. */ 50 * conveniently matches the IPMI chassis control values. */
48#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */ 51#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
@@ -51,6 +54,37 @@
51/* the IPMI data command */ 54/* the IPMI data command */
52static int poweroff_powercycle; 55static int poweroff_powercycle;
53 56
57/* Which interface to use, -1 means the first we see. */
58static int ifnum_to_use = -1;
59
60/* Our local state. */
61static int ready;
62static ipmi_user_t ipmi_user;
63static int ipmi_ifnum;
64static void (*specific_poweroff_func)(ipmi_user_t user);
65
66/* Holds the old poweroff function so we can restore it on removal. */
67static void (*old_poweroff_func)(void);
68
69static int set_param_ifnum(const char *val, struct kernel_param *kp)
70{
71 int rv = param_set_int(val, kp);
72 if (rv)
73 return rv;
74 if ((ifnum_to_use < 0) || (ifnum_to_use == ipmi_ifnum))
75 return 0;
76
77 ipmi_po_smi_gone(ipmi_ifnum);
78 ipmi_po_new_smi(ifnum_to_use, NULL);
79 return 0;
80}
81
82module_param_call(ifnum_to_use, set_param_ifnum, param_get_int,
83 &ifnum_to_use, 0644);
84MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
85 "timer. Setting to -1 defaults to the first registered "
86 "interface");
87
54/* parameter definition to allow user to flag power cycle */ 88/* parameter definition to allow user to flag power cycle */
55module_param(poweroff_powercycle, int, 0644); 89module_param(poweroff_powercycle, int, 0644);
56MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down."); 90MODULE_PARM_DESC(poweroff_powercycle, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
@@ -142,6 +176,42 @@ static int ipmi_request_in_rc_mode(ipmi_user_t user,
142#define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01 176#define IPMI_ATCA_GET_ADDR_INFO_CMD 0x01
143#define IPMI_PICMG_ID 0 177#define IPMI_PICMG_ID 0
144 178
179#define IPMI_NETFN_OEM 0x2e
180#define IPMI_ATCA_PPS_GRACEFUL_RESTART 0x11
181#define IPMI_ATCA_PPS_IANA "\x00\x40\x0A"
182#define IPMI_MOTOROLA_MANUFACTURER_ID 0x0000A1
183#define IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID 0x0051
184
185static void (*atca_oem_poweroff_hook)(ipmi_user_t user);
186
187static void pps_poweroff_atca (ipmi_user_t user)
188{
189 struct ipmi_system_interface_addr smi_addr;
190 struct kernel_ipmi_msg send_msg;
191 int rv;
192 /*
193 * Configure IPMI address for local access
194 */
195 smi_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
196 smi_addr.channel = IPMI_BMC_CHANNEL;
197 smi_addr.lun = 0;
198
199 printk(KERN_INFO PFX "PPS powerdown hook used");
200
201 send_msg.netfn = IPMI_NETFN_OEM;
202 send_msg.cmd = IPMI_ATCA_PPS_GRACEFUL_RESTART;
203 send_msg.data = IPMI_ATCA_PPS_IANA;
204 send_msg.data_len = 3;
205 rv = ipmi_request_in_rc_mode(user,
206 (struct ipmi_addr *) &smi_addr,
207 &send_msg);
208 if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) {
209 printk(KERN_ERR PFX "Unable to send ATCA ,"
210 " IPMI error 0x%x\n", rv);
211 }
212 return;
213}
214
145static int ipmi_atca_detect (ipmi_user_t user) 215static int ipmi_atca_detect (ipmi_user_t user)
146{ 216{
147 struct ipmi_system_interface_addr smi_addr; 217 struct ipmi_system_interface_addr smi_addr;
@@ -167,6 +237,13 @@ static int ipmi_atca_detect (ipmi_user_t user)
167 rv = ipmi_request_wait_for_response(user, 237 rv = ipmi_request_wait_for_response(user,
168 (struct ipmi_addr *) &smi_addr, 238 (struct ipmi_addr *) &smi_addr,
169 &send_msg); 239 &send_msg);
240
241 printk(KERN_INFO PFX "ATCA Detect mfg 0x%X prod 0x%X\n", mfg_id, prod_id);
242 if((mfg_id == IPMI_MOTOROLA_MANUFACTURER_ID)
243 && (prod_id == IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID)) {
244 printk(KERN_INFO PFX "Installing Pigeon Point Systems Poweroff Hook\n");
245 atca_oem_poweroff_hook = pps_poweroff_atca;
246 }
170 return !rv; 247 return !rv;
171} 248}
172 249
@@ -200,12 +277,19 @@ static void ipmi_poweroff_atca (ipmi_user_t user)
200 rv = ipmi_request_in_rc_mode(user, 277 rv = ipmi_request_in_rc_mode(user,
201 (struct ipmi_addr *) &smi_addr, 278 (struct ipmi_addr *) &smi_addr,
202 &send_msg); 279 &send_msg);
203 if (rv) { 280 /** At this point, the system may be shutting down, and most
281 ** serial drivers (if used) will have interrupts turned off
282 ** it may be better to ignore IPMI_UNKNOWN_ERR_COMPLETION_CODE
283 ** return code
284 **/
285 if (rv && rv != IPMI_UNKNOWN_ERR_COMPLETION_CODE) {
204 printk(KERN_ERR PFX "Unable to send ATCA powerdown message," 286 printk(KERN_ERR PFX "Unable to send ATCA powerdown message,"
205 " IPMI error 0x%x\n", rv); 287 " IPMI error 0x%x\n", rv);
206 goto out; 288 goto out;
207 } 289 }
208 290
291 if(atca_oem_poweroff_hook)
292 return atca_oem_poweroff_hook(user);
209 out: 293 out:
210 return; 294 return;
211} 295}
@@ -440,15 +524,6 @@ static struct poweroff_function poweroff_functions[] = {
440 / sizeof(struct poweroff_function)) 524 / sizeof(struct poweroff_function))
441 525
442 526
443/* Our local state. */
444static int ready = 0;
445static ipmi_user_t ipmi_user;
446static void (*specific_poweroff_func)(ipmi_user_t user) = NULL;
447
448/* Holds the old poweroff function so we can restore it on removal. */
449static void (*old_poweroff_func)(void);
450
451
452/* Called on a powerdown request. */ 527/* Called on a powerdown request. */
453static void ipmi_poweroff_function (void) 528static void ipmi_poweroff_function (void)
454{ 529{
@@ -473,6 +548,9 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
473 if (ready) 548 if (ready)
474 return; 549 return;
475 550
551 if ((ifnum_to_use >= 0) && (ifnum_to_use != if_num))
552 return;
553
476 rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL, 554 rv = ipmi_create_user(if_num, &ipmi_poweroff_handler, NULL,
477 &ipmi_user); 555 &ipmi_user);
478 if (rv) { 556 if (rv) {
@@ -481,6 +559,8 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
481 return; 559 return;
482 } 560 }
483 561
562 ipmi_ifnum = if_num;
563
484 /* 564 /*
485 * Do a get device ide and store some results, since this is 565 * Do a get device ide and store some results, since this is
486 * used by several functions. 566 * used by several functions.
@@ -541,9 +621,15 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
541 621
542static void ipmi_po_smi_gone(int if_num) 622static void ipmi_po_smi_gone(int if_num)
543{ 623{
544 /* This can never be called, because once poweroff driver is 624 if (!ready)
545 registered, the interface can't go away until the power 625 return;
546 driver is unregistered. */ 626
627 if (ipmi_ifnum != if_num)
628 return;
629
630 ready = 0;
631 ipmi_destroy_user(ipmi_user);
632 pm_power_off = old_poweroff_func;
547} 633}
548 634
549static struct ipmi_smi_watcher smi_watcher = 635static struct ipmi_smi_watcher smi_watcher =
@@ -616,9 +702,9 @@ static int ipmi_poweroff_init (void)
616 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); 702 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
617 goto out_err; 703 goto out_err;
618 } 704 }
619#endif
620 705
621 out_err: 706 out_err:
707#endif
622 return rv; 708 return rv;
623} 709}
624 710
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index abca98beac14..f1afd26a509f 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -61,6 +61,10 @@
61#include "ipmi_si_sm.h" 61#include "ipmi_si_sm.h"
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/dmi.h> 63#include <linux/dmi.h>
64#include <linux/string.h>
65#include <linux/ctype.h>
66
67#define PFX "ipmi_si: "
64 68
65/* Measure times between events in the driver. */ 69/* Measure times between events in the driver. */
66#undef DEBUG_TIMING 70#undef DEBUG_TIMING
@@ -92,7 +96,7 @@ enum si_intf_state {
92enum si_type { 96enum si_type {
93 SI_KCS, SI_SMIC, SI_BT 97 SI_KCS, SI_SMIC, SI_BT
94}; 98};
95static char *si_to_str[] = { "KCS", "SMIC", "BT" }; 99static char *si_to_str[] = { "kcs", "smic", "bt" };
96 100
97#define DEVICE_NAME "ipmi_si" 101#define DEVICE_NAME "ipmi_si"
98 102
@@ -217,7 +221,15 @@ struct smi_info
217 struct list_head link; 221 struct list_head link;
218}; 222};
219 223
224#define SI_MAX_PARMS 4
225
226static int force_kipmid[SI_MAX_PARMS];
227static int num_force_kipmid;
228
229static int unload_when_empty = 1;
230
220static int try_smi_init(struct smi_info *smi); 231static int try_smi_init(struct smi_info *smi);
232static void cleanup_one_si(struct smi_info *to_clean);
221 233
222static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); 234static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
223static int register_xaction_notifier(struct notifier_block * nb) 235static int register_xaction_notifier(struct notifier_block * nb)
@@ -235,14 +247,18 @@ static void deliver_recv_msg(struct smi_info *smi_info,
235 spin_lock(&(smi_info->si_lock)); 247 spin_lock(&(smi_info->si_lock));
236} 248}
237 249
238static void return_hosed_msg(struct smi_info *smi_info) 250static void return_hosed_msg(struct smi_info *smi_info, int cCode)
239{ 251{
240 struct ipmi_smi_msg *msg = smi_info->curr_msg; 252 struct ipmi_smi_msg *msg = smi_info->curr_msg;
241 253
254 if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED)
255 cCode = IPMI_ERR_UNSPECIFIED;
256 /* else use it as is */
257
242 /* Make it a reponse */ 258 /* Make it a reponse */
243 msg->rsp[0] = msg->data[0] | 4; 259 msg->rsp[0] = msg->data[0] | 4;
244 msg->rsp[1] = msg->data[1]; 260 msg->rsp[1] = msg->data[1];
245 msg->rsp[2] = 0xFF; /* Unknown error. */ 261 msg->rsp[2] = cCode;
246 msg->rsp_size = 3; 262 msg->rsp_size = 3;
247 263
248 smi_info->curr_msg = NULL; 264 smi_info->curr_msg = NULL;
@@ -293,7 +309,7 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
293 smi_info->curr_msg->data, 309 smi_info->curr_msg->data,
294 smi_info->curr_msg->data_size); 310 smi_info->curr_msg->data_size);
295 if (err) { 311 if (err) {
296 return_hosed_msg(smi_info); 312 return_hosed_msg(smi_info, err);
297 } 313 }
298 314
299 rv = SI_SM_CALL_WITHOUT_DELAY; 315 rv = SI_SM_CALL_WITHOUT_DELAY;
@@ -635,7 +651,7 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
635 /* If we were handling a user message, format 651 /* If we were handling a user message, format
636 a response to send to the upper layer to 652 a response to send to the upper layer to
637 tell it about the error. */ 653 tell it about the error. */
638 return_hosed_msg(smi_info); 654 return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED);
639 } 655 }
640 si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); 656 si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
641 } 657 }
@@ -679,22 +695,24 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
679 { 695 {
680 /* We are idle and the upper layer requested that I fetch 696 /* We are idle and the upper layer requested that I fetch
681 events, so do so. */ 697 events, so do so. */
682 unsigned char msg[2]; 698 atomic_set(&smi_info->req_events, 0);
683 699
684 spin_lock(&smi_info->count_lock); 700 smi_info->curr_msg = ipmi_alloc_smi_msg();
685 smi_info->flag_fetches++; 701 if (!smi_info->curr_msg)
686 spin_unlock(&smi_info->count_lock); 702 goto out;
687 703
688 atomic_set(&smi_info->req_events, 0); 704 smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
689 msg[0] = (IPMI_NETFN_APP_REQUEST << 2); 705 smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
690 msg[1] = IPMI_GET_MSG_FLAGS_CMD; 706 smi_info->curr_msg->data_size = 2;
691 707
692 smi_info->handlers->start_transaction( 708 smi_info->handlers->start_transaction(
693 smi_info->si_sm, msg, 2); 709 smi_info->si_sm,
694 smi_info->si_state = SI_GETTING_FLAGS; 710 smi_info->curr_msg->data,
711 smi_info->curr_msg->data_size);
712 smi_info->si_state = SI_GETTING_EVENTS;
695 goto restart; 713 goto restart;
696 } 714 }
697 715 out:
698 return si_sm_result; 716 return si_sm_result;
699} 717}
700 718
@@ -709,6 +727,15 @@ static void sender(void *send_info,
709 struct timeval t; 727 struct timeval t;
710#endif 728#endif
711 729
730 if (atomic_read(&smi_info->stop_operation)) {
731 msg->rsp[0] = msg->data[0] | 4;
732 msg->rsp[1] = msg->data[1];
733 msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
734 msg->rsp_size = 3;
735 deliver_recv_msg(smi_info, msg);
736 return;
737 }
738
712 spin_lock_irqsave(&(smi_info->msg_lock), flags); 739 spin_lock_irqsave(&(smi_info->msg_lock), flags);
713#ifdef DEBUG_TIMING 740#ifdef DEBUG_TIMING
714 do_gettimeofday(&t); 741 do_gettimeofday(&t);
@@ -800,17 +827,25 @@ static void poll(void *send_info)
800{ 827{
801 struct smi_info *smi_info = send_info; 828 struct smi_info *smi_info = send_info;
802 829
803 smi_event_handler(smi_info, 0); 830 /*
831 * Make sure there is some delay in the poll loop so we can
832 * drive time forward and timeout things.
833 */
834 udelay(10);
835 smi_event_handler(smi_info, 10);
804} 836}
805 837
806static void request_events(void *send_info) 838static void request_events(void *send_info)
807{ 839{
808 struct smi_info *smi_info = send_info; 840 struct smi_info *smi_info = send_info;
809 841
842 if (atomic_read(&smi_info->stop_operation))
843 return;
844
810 atomic_set(&smi_info->req_events, 1); 845 atomic_set(&smi_info->req_events, 1);
811} 846}
812 847
813static int initialized = 0; 848static int initialized;
814 849
815static void smi_timeout(unsigned long data) 850static void smi_timeout(unsigned long data)
816{ 851{
@@ -867,7 +902,7 @@ static void smi_timeout(unsigned long data)
867 add_timer(&(smi_info->si_timer)); 902 add_timer(&(smi_info->si_timer));
868} 903}
869 904
870static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs) 905static irqreturn_t si_irq_handler(int irq, void *data)
871{ 906{
872 struct smi_info *smi_info = data; 907 struct smi_info *smi_info = data;
873 unsigned long flags; 908 unsigned long flags;
@@ -894,20 +929,21 @@ static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs)
894 return IRQ_HANDLED; 929 return IRQ_HANDLED;
895} 930}
896 931
897static irqreturn_t si_bt_irq_handler(int irq, void *data, struct pt_regs *regs) 932static irqreturn_t si_bt_irq_handler(int irq, void *data)
898{ 933{
899 struct smi_info *smi_info = data; 934 struct smi_info *smi_info = data;
900 /* We need to clear the IRQ flag for the BT interface. */ 935 /* We need to clear the IRQ flag for the BT interface. */
901 smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, 936 smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG,
902 IPMI_BT_INTMASK_CLEAR_IRQ_BIT 937 IPMI_BT_INTMASK_CLEAR_IRQ_BIT
903 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); 938 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
904 return si_irq_handler(irq, data, regs); 939 return si_irq_handler(irq, data);
905} 940}
906 941
907static int smi_start_processing(void *send_info, 942static int smi_start_processing(void *send_info,
908 ipmi_smi_t intf) 943 ipmi_smi_t intf)
909{ 944{
910 struct smi_info *new_smi = send_info; 945 struct smi_info *new_smi = send_info;
946 int enable = 0;
911 947
912 new_smi->intf = intf; 948 new_smi->intf = intf;
913 949
@@ -916,7 +952,19 @@ static int smi_start_processing(void *send_info,
916 new_smi->last_timeout_jiffies = jiffies; 952 new_smi->last_timeout_jiffies = jiffies;
917 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); 953 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
918 954
919 if (new_smi->si_type != SI_BT) { 955 /*
956 * Check if the user forcefully enabled the daemon.
957 */
958 if (new_smi->intf_num < num_force_kipmid)
959 enable = force_kipmid[new_smi->intf_num];
960 /*
961 * The BT interface is efficient enough to not need a thread,
962 * and there is no need for a thread if we have interrupts.
963 */
964 else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))
965 enable = 1;
966
967 if (enable) {
920 new_smi->thread = kthread_run(ipmi_thread, new_smi, 968 new_smi->thread = kthread_run(ipmi_thread, new_smi,
921 "kipmi%d", new_smi->intf_num); 969 "kipmi%d", new_smi->intf_num);
922 if (IS_ERR(new_smi->thread)) { 970 if (IS_ERR(new_smi->thread)) {
@@ -931,12 +979,21 @@ static int smi_start_processing(void *send_info,
931 return 0; 979 return 0;
932} 980}
933 981
982static void set_maintenance_mode(void *send_info, int enable)
983{
984 struct smi_info *smi_info = send_info;
985
986 if (!enable)
987 atomic_set(&smi_info->req_events, 0);
988}
989
934static struct ipmi_smi_handlers handlers = 990static struct ipmi_smi_handlers handlers =
935{ 991{
936 .owner = THIS_MODULE, 992 .owner = THIS_MODULE,
937 .start_processing = smi_start_processing, 993 .start_processing = smi_start_processing,
938 .sender = sender, 994 .sender = sender,
939 .request_events = request_events, 995 .request_events = request_events,
996 .set_maintenance_mode = set_maintenance_mode,
940 .set_run_to_completion = set_run_to_completion, 997 .set_run_to_completion = set_run_to_completion,
941 .poll = poll, 998 .poll = poll,
942}; 999};
@@ -944,7 +1001,6 @@ static struct ipmi_smi_handlers handlers =
944/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses, 1001/* There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
945 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */ 1002 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */
946 1003
947#define SI_MAX_PARMS 4
948static LIST_HEAD(smi_infos); 1004static LIST_HEAD(smi_infos);
949static DEFINE_MUTEX(smi_infos_lock); 1005static DEFINE_MUTEX(smi_infos_lock);
950static int smi_num; /* Used to sequence the SMIs */ 1006static int smi_num; /* Used to sequence the SMIs */
@@ -962,14 +1018,24 @@ static int num_ports;
962static int irqs[SI_MAX_PARMS]; 1018static int irqs[SI_MAX_PARMS];
963static int num_irqs; 1019static int num_irqs;
964static int regspacings[SI_MAX_PARMS]; 1020static int regspacings[SI_MAX_PARMS];
965static int num_regspacings = 0; 1021static int num_regspacings;
966static int regsizes[SI_MAX_PARMS]; 1022static int regsizes[SI_MAX_PARMS];
967static int num_regsizes = 0; 1023static int num_regsizes;
968static int regshifts[SI_MAX_PARMS]; 1024static int regshifts[SI_MAX_PARMS];
969static int num_regshifts = 0; 1025static int num_regshifts;
970static int slave_addrs[SI_MAX_PARMS]; 1026static int slave_addrs[SI_MAX_PARMS];
971static int num_slave_addrs = 0; 1027static int num_slave_addrs;
1028
1029#define IPMI_IO_ADDR_SPACE 0
1030#define IPMI_MEM_ADDR_SPACE 1
1031static char *addr_space_to_str[] = { "i/o", "mem" };
1032
1033static int hotmod_handler(const char *val, struct kernel_param *kp);
972 1034
1035module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);
1036MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See"
1037 " Documentation/IPMI.txt in the kernel sources for the"
1038 " gory details.");
973 1039
974module_param_named(trydefaults, si_trydefaults, bool, 0); 1040module_param_named(trydefaults, si_trydefaults, bool, 0);
975MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" 1041MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the"
@@ -1017,12 +1083,16 @@ MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
1017 " the controller. Normally this is 0x20, but can be" 1083 " the controller. Normally this is 0x20, but can be"
1018 " overridden by this parm. This is an array indexed" 1084 " overridden by this parm. This is an array indexed"
1019 " by interface number."); 1085 " by interface number.");
1086module_param_array(force_kipmid, int, &num_force_kipmid, 0);
1087MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
1088 " disabled(0). Normally the IPMI driver auto-detects"
1089 " this, but the value may be overridden by this parm.");
1090module_param(unload_when_empty, int, 0);
1091MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"
1092 " specified or found, default is 1. Setting to 0"
1093 " is useful for hot add of devices using hotmod.");
1020 1094
1021 1095
1022#define IPMI_IO_ADDR_SPACE 0
1023#define IPMI_MEM_ADDR_SPACE 1
1024static char *addr_space_to_str[] = { "I/O", "memory" };
1025
1026static void std_irq_cleanup(struct smi_info *info) 1096static void std_irq_cleanup(struct smi_info *info)
1027{ 1097{
1028 if (info->si_type == SI_BT) 1098 if (info->si_type == SI_BT)
@@ -1190,7 +1260,7 @@ static void intf_mem_outb(struct si_sm_io *io, unsigned int offset,
1190static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset) 1260static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset)
1191{ 1261{
1192 return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) 1262 return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift)
1193 && 0xff; 1263 & 0xff;
1194} 1264}
1195 1265
1196static void intf_mem_outw(struct si_sm_io *io, unsigned int offset, 1266static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
@@ -1202,7 +1272,7 @@ static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
1202static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset) 1272static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset)
1203{ 1273{
1204 return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) 1274 return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift)
1205 && 0xff; 1275 & 0xff;
1206} 1276}
1207 1277
1208static void intf_mem_outl(struct si_sm_io *io, unsigned int offset, 1278static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
@@ -1215,7 +1285,7 @@ static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
1215static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset) 1285static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset)
1216{ 1286{
1217 return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) 1287 return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift)
1218 && 0xff; 1288 & 0xff;
1219} 1289}
1220 1290
1221static void mem_outq(struct si_sm_io *io, unsigned int offset, 1291static void mem_outq(struct si_sm_io *io, unsigned int offset,
@@ -1296,6 +1366,250 @@ static int mem_setup(struct smi_info *info)
1296 return 0; 1366 return 0;
1297} 1367}
1298 1368
1369/*
1370 * Parms come in as <op1>[:op2[:op3...]]. ops are:
1371 * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]]
1372 * Options are:
1373 * rsp=<regspacing>
1374 * rsi=<regsize>
1375 * rsh=<regshift>
1376 * irq=<irq>
1377 * ipmb=<ipmb addr>
1378 */
1379enum hotmod_op { HM_ADD, HM_REMOVE };
1380struct hotmod_vals {
1381 char *name;
1382 int val;
1383};
1384static struct hotmod_vals hotmod_ops[] = {
1385 { "add", HM_ADD },
1386 { "remove", HM_REMOVE },
1387 { NULL }
1388};
1389static struct hotmod_vals hotmod_si[] = {
1390 { "kcs", SI_KCS },
1391 { "smic", SI_SMIC },
1392 { "bt", SI_BT },
1393 { NULL }
1394};
1395static struct hotmod_vals hotmod_as[] = {
1396 { "mem", IPMI_MEM_ADDR_SPACE },
1397 { "i/o", IPMI_IO_ADDR_SPACE },
1398 { NULL }
1399};
1400
1401static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
1402{
1403 char *s;
1404 int i;
1405
1406 s = strchr(*curr, ',');
1407 if (!s) {
1408 printk(KERN_WARNING PFX "No hotmod %s given.\n", name);
1409 return -EINVAL;
1410 }
1411 *s = '\0';
1412 s++;
1413 for (i = 0; hotmod_ops[i].name; i++) {
1414 if (strcmp(*curr, v[i].name) == 0) {
1415 *val = v[i].val;
1416 *curr = s;
1417 return 0;
1418 }
1419 }
1420
1421 printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);
1422 return -EINVAL;
1423}
1424
1425static int check_hotmod_int_op(const char *curr, const char *option,
1426 const char *name, int *val)
1427{
1428 char *n;
1429
1430 if (strcmp(curr, name) == 0) {
1431 if (!option) {
1432 printk(KERN_WARNING PFX
1433 "No option given for '%s'\n",
1434 curr);
1435 return -EINVAL;
1436 }
1437 *val = simple_strtoul(option, &n, 0);
1438 if ((*n != '\0') || (*option == '\0')) {
1439 printk(KERN_WARNING PFX
1440 "Bad option given for '%s'\n",
1441 curr);
1442 return -EINVAL;
1443 }
1444 return 1;
1445 }
1446 return 0;
1447}
1448
1449static int hotmod_handler(const char *val, struct kernel_param *kp)
1450{
1451 char *str = kstrdup(val, GFP_KERNEL);
1452 int rv;
1453 char *next, *curr, *s, *n, *o;
1454 enum hotmod_op op;
1455 enum si_type si_type;
1456 int addr_space;
1457 unsigned long addr;
1458 int regspacing;
1459 int regsize;
1460 int regshift;
1461 int irq;
1462 int ipmb;
1463 int ival;
1464 int len;
1465 struct smi_info *info;
1466
1467 if (!str)
1468 return -ENOMEM;
1469
1470 /* Kill any trailing spaces, as we can get a "\n" from echo. */
1471 len = strlen(str);
1472 ival = len - 1;
1473 while ((ival >= 0) && isspace(str[ival])) {
1474 str[ival] = '\0';
1475 ival--;
1476 }
1477
1478 for (curr = str; curr; curr = next) {
1479 regspacing = 1;
1480 regsize = 1;
1481 regshift = 0;
1482 irq = 0;
1483 ipmb = 0x20;
1484
1485 next = strchr(curr, ':');
1486 if (next) {
1487 *next = '\0';
1488 next++;
1489 }
1490
1491 rv = parse_str(hotmod_ops, &ival, "operation", &curr);
1492 if (rv)
1493 break;
1494 op = ival;
1495
1496 rv = parse_str(hotmod_si, &ival, "interface type", &curr);
1497 if (rv)
1498 break;
1499 si_type = ival;
1500
1501 rv = parse_str(hotmod_as, &addr_space, "address space", &curr);
1502 if (rv)
1503 break;
1504
1505 s = strchr(curr, ',');
1506 if (s) {
1507 *s = '\0';
1508 s++;
1509 }
1510 addr = simple_strtoul(curr, &n, 0);
1511 if ((*n != '\0') || (*curr == '\0')) {
1512 printk(KERN_WARNING PFX "Invalid hotmod address"
1513 " '%s'\n", curr);
1514 break;
1515 }
1516
1517 while (s) {
1518 curr = s;
1519 s = strchr(curr, ',');
1520 if (s) {
1521 *s = '\0';
1522 s++;
1523 }
1524 o = strchr(curr, '=');
1525 if (o) {
1526 *o = '\0';
1527 o++;
1528 }
1529 rv = check_hotmod_int_op(curr, o, "rsp", &regspacing);
1530 if (rv < 0)
1531 goto out;
1532 else if (rv)
1533 continue;
1534 rv = check_hotmod_int_op(curr, o, "rsi", &regsize);
1535 if (rv < 0)
1536 goto out;
1537 else if (rv)
1538 continue;
1539 rv = check_hotmod_int_op(curr, o, "rsh", &regshift);
1540 if (rv < 0)
1541 goto out;
1542 else if (rv)
1543 continue;
1544 rv = check_hotmod_int_op(curr, o, "irq", &irq);
1545 if (rv < 0)
1546 goto out;
1547 else if (rv)
1548 continue;
1549 rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb);
1550 if (rv < 0)
1551 goto out;
1552 else if (rv)
1553 continue;
1554
1555 rv = -EINVAL;
1556 printk(KERN_WARNING PFX
1557 "Invalid hotmod option '%s'\n",
1558 curr);
1559 goto out;
1560 }
1561
1562 if (op == HM_ADD) {
1563 info = kzalloc(sizeof(*info), GFP_KERNEL);
1564 if (!info) {
1565 rv = -ENOMEM;
1566 goto out;
1567 }
1568
1569 info->addr_source = "hotmod";
1570 info->si_type = si_type;
1571 info->io.addr_data = addr;
1572 info->io.addr_type = addr_space;
1573 if (addr_space == IPMI_MEM_ADDR_SPACE)
1574 info->io_setup = mem_setup;
1575 else
1576 info->io_setup = port_setup;
1577
1578 info->io.addr = NULL;
1579 info->io.regspacing = regspacing;
1580 if (!info->io.regspacing)
1581 info->io.regspacing = DEFAULT_REGSPACING;
1582 info->io.regsize = regsize;
1583 if (!info->io.regsize)
1584 info->io.regsize = DEFAULT_REGSPACING;
1585 info->io.regshift = regshift;
1586 info->irq = irq;
1587 if (info->irq)
1588 info->irq_setup = std_irq_setup;
1589 info->slave_addr = ipmb;
1590
1591 try_smi_init(info);
1592 } else {
1593 /* remove */
1594 struct smi_info *e, *tmp_e;
1595
1596 mutex_lock(&smi_infos_lock);
1597 list_for_each_entry_safe(e, tmp_e, &smi_infos, link) {
1598 if (e->io.addr_type != addr_space)
1599 continue;
1600 if (e->si_type != si_type)
1601 continue;
1602 if (e->io.addr_data == addr)
1603 cleanup_one_si(e);
1604 }
1605 mutex_unlock(&smi_infos_lock);
1606 }
1607 }
1608 rv = len;
1609 out:
1610 kfree(str);
1611 return rv;
1612}
1299 1613
1300static __devinit void hardcode_find_bmc(void) 1614static __devinit void hardcode_find_bmc(void)
1301{ 1615{
@@ -1370,7 +1684,7 @@ static __devinit void hardcode_find_bmc(void)
1370/* Once we get an ACPI failure, we don't try any more, because we go 1684/* Once we get an ACPI failure, we don't try any more, because we go
1371 through the tables sequentially. Once we don't find a table, there 1685 through the tables sequentially. Once we don't find a table, there
1372 are no more. */ 1686 are no more. */
1373static int acpi_failure = 0; 1687static int acpi_failure;
1374 1688
1375/* For GPE-type interrupts. */ 1689/* For GPE-type interrupts. */
1376static u32 ipmi_acpi_gpe(void *context) 1690static u32 ipmi_acpi_gpe(void *context)
@@ -1481,7 +1795,6 @@ struct SPMITable {
1481static __devinit int try_init_acpi(struct SPMITable *spmi) 1795static __devinit int try_init_acpi(struct SPMITable *spmi)
1482{ 1796{
1483 struct smi_info *info; 1797 struct smi_info *info;
1484 char *io_type;
1485 u8 addr_space; 1798 u8 addr_space;
1486 1799
1487 if (spmi->IPMIlegacy != 1) { 1800 if (spmi->IPMIlegacy != 1) {
@@ -1545,11 +1858,9 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1545 info->io.regshift = spmi->addr.register_bit_offset; 1858 info->io.regshift = spmi->addr.register_bit_offset;
1546 1859
1547 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1860 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1548 io_type = "memory";
1549 info->io_setup = mem_setup; 1861 info->io_setup = mem_setup;
1550 info->io.addr_type = IPMI_IO_ADDR_SPACE; 1862 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1551 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1863 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1552 io_type = "I/O";
1553 info->io_setup = port_setup; 1864 info->io_setup = port_setup;
1554 info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1555 } else { 1866 } else {
@@ -1730,6 +2041,7 @@ static void __devinit dmi_find_bmc(void)
1730 int rv; 2041 int rv;
1731 2042
1732 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 2043 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
2044 memset(&data, 0, sizeof(data));
1733 rv = decode_dmi((struct dmi_header *) dev->device_data, &data); 2045 rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
1734 if (!rv) 2046 if (!rv)
1735 try_init_dmi(&data); 2047 try_init_dmi(&data);
@@ -1767,7 +2079,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
1767 2079
1768 info = kzalloc(sizeof(*info), GFP_KERNEL); 2080 info = kzalloc(sizeof(*info), GFP_KERNEL);
1769 if (!info) 2081 if (!info)
1770 return ENOMEM; 2082 return -ENOMEM;
1771 2083
1772 info->addr_source = "PCI"; 2084 info->addr_source = "PCI";
1773 2085
@@ -1788,7 +2100,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
1788 kfree(info); 2100 kfree(info);
1789 printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n", 2101 printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n",
1790 pci_name(pdev), class_type); 2102 pci_name(pdev), class_type);
1791 return ENOMEM; 2103 return -ENOMEM;
1792 } 2104 }
1793 2105
1794 rv = pci_enable_device(pdev); 2106 rv = pci_enable_device(pdev);
@@ -1845,7 +2157,7 @@ static int ipmi_pci_resume(struct pci_dev *pdev)
1845 2157
1846static struct pci_device_id ipmi_pci_devices[] = { 2158static struct pci_device_id ipmi_pci_devices[] = {
1847 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, 2159 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
1848 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE) } 2160 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }
1849}; 2161};
1850MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); 2162MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
1851 2163
@@ -1930,19 +2242,9 @@ static int try_get_dev_id(struct smi_info *smi_info)
1930static int type_file_read_proc(char *page, char **start, off_t off, 2242static int type_file_read_proc(char *page, char **start, off_t off,
1931 int count, int *eof, void *data) 2243 int count, int *eof, void *data)
1932{ 2244{
1933 char *out = (char *) page;
1934 struct smi_info *smi = data; 2245 struct smi_info *smi = data;
1935 2246
1936 switch (smi->si_type) { 2247 return sprintf(page, "%s\n", si_to_str[smi->si_type]);
1937 case SI_KCS:
1938 return sprintf(out, "kcs\n");
1939 case SI_SMIC:
1940 return sprintf(out, "smic\n");
1941 case SI_BT:
1942 return sprintf(out, "bt\n");
1943 default:
1944 return 0;
1945 }
1946} 2248}
1947 2249
1948static int stat_file_read_proc(char *page, char **start, off_t off, 2250static int stat_file_read_proc(char *page, char **start, off_t off,
@@ -1978,7 +2280,24 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
1978 out += sprintf(out, "incoming_messages: %ld\n", 2280 out += sprintf(out, "incoming_messages: %ld\n",
1979 smi->incoming_messages); 2281 smi->incoming_messages);
1980 2282
1981 return (out - ((char *) page)); 2283 return out - page;
2284}
2285
2286static int param_read_proc(char *page, char **start, off_t off,
2287 int count, int *eof, void *data)
2288{
2289 struct smi_info *smi = data;
2290
2291 return sprintf(page,
2292 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
2293 si_to_str[smi->si_type],
2294 addr_space_to_str[smi->io.addr_type],
2295 smi->io.addr_data,
2296 smi->io.regspacing,
2297 smi->io.regsize,
2298 smi->io.regshift,
2299 smi->irq,
2300 smi->slave_addr);
1982} 2301}
1983 2302
1984/* 2303/*
@@ -2324,7 +2643,7 @@ static int try_smi_init(struct smi_info *new_smi)
2324 new_smi->dev = &new_smi->pdev->dev; 2643 new_smi->dev = &new_smi->pdev->dev;
2325 new_smi->dev->driver = &ipmi_driver; 2644 new_smi->dev->driver = &ipmi_driver;
2326 2645
2327 rv = platform_device_register(new_smi->pdev); 2646 rv = platform_device_add(new_smi->pdev);
2328 if (rv) { 2647 if (rv) {
2329 printk(KERN_ERR 2648 printk(KERN_ERR
2330 "ipmi_si_intf:" 2649 "ipmi_si_intf:"
@@ -2340,6 +2659,7 @@ static int try_smi_init(struct smi_info *new_smi)
2340 new_smi, 2659 new_smi,
2341 &new_smi->device_id, 2660 &new_smi->device_id,
2342 new_smi->dev, 2661 new_smi->dev,
2662 "bmc",
2343 new_smi->slave_addr); 2663 new_smi->slave_addr);
2344 if (rv) { 2664 if (rv) {
2345 printk(KERN_ERR 2665 printk(KERN_ERR
@@ -2368,6 +2688,16 @@ static int try_smi_init(struct smi_info *new_smi)
2368 goto out_err_stop_timer; 2688 goto out_err_stop_timer;
2369 } 2689 }
2370 2690
2691 rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
2692 param_read_proc, NULL,
2693 new_smi, THIS_MODULE);
2694 if (rv) {
2695 printk(KERN_ERR
2696 "ipmi_si: Unable to create proc entry: %d\n",
2697 rv);
2698 goto out_err_stop_timer;
2699 }
2700
2371 list_add_tail(&new_smi->link, &smi_infos); 2701 list_add_tail(&new_smi->link, &smi_infos);
2372 2702
2373 mutex_unlock(&smi_infos_lock); 2703 mutex_unlock(&smi_infos_lock);
@@ -2456,12 +2786,16 @@ static __devinit int init_ipmi_si(void)
2456#endif 2786#endif
2457 2787
2458#ifdef CONFIG_ACPI 2788#ifdef CONFIG_ACPI
2459 if (si_trydefaults) 2789 acpi_find_bmc();
2460 acpi_find_bmc();
2461#endif 2790#endif
2462 2791
2463#ifdef CONFIG_PCI 2792#ifdef CONFIG_PCI
2464 pci_module_init(&ipmi_pci_driver); 2793 rv = pci_register_driver(&ipmi_pci_driver);
2794 if (rv){
2795 printk(KERN_ERR
2796 "init_ipmi_si: Unable to register PCI driver: %d\n",
2797 rv);
2798 }
2465#endif 2799#endif
2466 2800
2467 if (si_trydefaults) { 2801 if (si_trydefaults) {
@@ -2476,7 +2810,7 @@ static __devinit int init_ipmi_si(void)
2476 } 2810 }
2477 2811
2478 mutex_lock(&smi_infos_lock); 2812 mutex_lock(&smi_infos_lock);
2479 if (list_empty(&smi_infos)) { 2813 if (unload_when_empty && list_empty(&smi_infos)) {
2480 mutex_unlock(&smi_infos_lock); 2814 mutex_unlock(&smi_infos_lock);
2481#ifdef CONFIG_PCI 2815#ifdef CONFIG_PCI
2482 pci_unregister_driver(&ipmi_pci_driver); 2816 pci_unregister_driver(&ipmi_pci_driver);
@@ -2491,7 +2825,7 @@ static __devinit int init_ipmi_si(void)
2491} 2825}
2492module_init(init_ipmi_si); 2826module_init(init_ipmi_si);
2493 2827
2494static void __devexit cleanup_one_si(struct smi_info *to_clean) 2828static void cleanup_one_si(struct smi_info *to_clean)
2495{ 2829{
2496 int rv; 2830 int rv;
2497 unsigned long flags; 2831 unsigned long flags;
diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c
index 39d7e5ef1a2b..e64ea7d25d24 100644
--- a/drivers/char/ipmi/ipmi_smic_sm.c
+++ b/drivers/char/ipmi/ipmi_smic_sm.c
@@ -141,12 +141,14 @@ static int start_smic_transaction(struct si_sm_data *smic,
141{ 141{
142 unsigned int i; 142 unsigned int i;
143 143
144 if ((size < 2) || (size > MAX_SMIC_WRITE_SIZE)) { 144 if (size < 2)
145 return -1; 145 return IPMI_REQ_LEN_INVALID_ERR;
146 } 146 if (size > MAX_SMIC_WRITE_SIZE)
147 if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED)) { 147 return IPMI_REQ_LEN_EXCEEDED_ERR;
148 return -2; 148
149 } 149 if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED))
150 return IPMI_NOT_IN_MY_STATE_ERR;
151
150 if (smic_debug & SMIC_DEBUG_MSG) { 152 if (smic_debug & SMIC_DEBUG_MSG) {
151 printk(KERN_INFO "start_smic_transaction -"); 153 printk(KERN_INFO "start_smic_transaction -");
152 for (i = 0; i < size; i ++) { 154 for (i = 0; i < size; i ++) {
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index accaaf1a6b69..78280380a905 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -134,13 +134,14 @@
134 134
135static int nowayout = WATCHDOG_NOWAYOUT; 135static int nowayout = WATCHDOG_NOWAYOUT;
136 136
137static ipmi_user_t watchdog_user = NULL; 137static ipmi_user_t watchdog_user;
138static int watchdog_ifnum;
138 139
139/* Default the timeout to 10 seconds. */ 140/* Default the timeout to 10 seconds. */
140static int timeout = 10; 141static int timeout = 10;
141 142
142/* The pre-timeout is disabled by default. */ 143/* The pre-timeout is disabled by default. */
143static int pretimeout = 0; 144static int pretimeout;
144 145
145/* Default action is to reset the board on a timeout. */ 146/* Default action is to reset the board on a timeout. */
146static unsigned char action_val = WDOG_TIMEOUT_RESET; 147static unsigned char action_val = WDOG_TIMEOUT_RESET;
@@ -155,12 +156,14 @@ static unsigned char preop_val = WDOG_PREOP_NONE;
155 156
156static char preop[16] = "preop_none"; 157static char preop[16] = "preop_none";
157static DEFINE_SPINLOCK(ipmi_read_lock); 158static DEFINE_SPINLOCK(ipmi_read_lock);
158static char data_to_read = 0; 159static char data_to_read;
159static DECLARE_WAIT_QUEUE_HEAD(read_q); 160static DECLARE_WAIT_QUEUE_HEAD(read_q);
160static struct fasync_struct *fasync_q = NULL; 161static struct fasync_struct *fasync_q;
161static char pretimeout_since_last_heartbeat = 0; 162static char pretimeout_since_last_heartbeat;
162static char expect_close; 163static char expect_close;
163 164
165static int ifnum_to_use = -1;
166
164static DECLARE_RWSEM(register_sem); 167static DECLARE_RWSEM(register_sem);
165 168
166/* Parameters to ipmi_set_timeout */ 169/* Parameters to ipmi_set_timeout */
@@ -169,10 +172,12 @@ static DECLARE_RWSEM(register_sem);
169#define IPMI_SET_TIMEOUT_FORCE_HB 2 172#define IPMI_SET_TIMEOUT_FORCE_HB 2
170 173
171static int ipmi_set_timeout(int do_heartbeat); 174static int ipmi_set_timeout(int do_heartbeat);
175static void ipmi_register_watchdog(int ipmi_intf);
176static void ipmi_unregister_watchdog(int ipmi_intf);
172 177
173/* If true, the driver will start running as soon as it is configured 178/* If true, the driver will start running as soon as it is configured
174 and ready. */ 179 and ready. */
175static int start_now = 0; 180static int start_now;
176 181
177static int set_param_int(const char *val, struct kernel_param *kp) 182static int set_param_int(const char *val, struct kernel_param *kp)
178{ 183{
@@ -245,6 +250,26 @@ static int get_param_str(char *buffer, struct kernel_param *kp)
245 return strlen(buffer); 250 return strlen(buffer);
246} 251}
247 252
253
254static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp)
255{
256 int rv = param_set_int(val, kp);
257 if (rv)
258 return rv;
259 if ((ifnum_to_use < 0) || (ifnum_to_use == watchdog_ifnum))
260 return 0;
261
262 ipmi_unregister_watchdog(watchdog_ifnum);
263 ipmi_register_watchdog(ifnum_to_use);
264 return 0;
265}
266
267module_param_call(ifnum_to_use, set_param_wdog_ifnum, get_param_int,
268 &ifnum_to_use, 0644);
269MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
270 "timer. Setting to -1 defaults to the first registered "
271 "interface");
272
248module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644); 273module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644);
249MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 274MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
250 275
@@ -263,27 +288,28 @@ module_param_call(preop, set_param_str, get_param_str, preop_op, 0644);
263MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 288MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: "
264 "preop_none, preop_panic, preop_give_data."); 289 "preop_none, preop_panic, preop_give_data.");
265 290
266module_param(start_now, int, 0); 291module_param(start_now, int, 0444);
267MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as" 292MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as"
268 "soon as the driver is loaded."); 293 "soon as the driver is loaded.");
269 294
270module_param(nowayout, int, 0644); 295module_param(nowayout, int, 0644);
271MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 296MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
297 "(default=CONFIG_WATCHDOG_NOWAYOUT)");
272 298
273/* Default state of the timer. */ 299/* Default state of the timer. */
274static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 300static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
275 301
276/* If shutting down via IPMI, we ignore the heartbeat. */ 302/* If shutting down via IPMI, we ignore the heartbeat. */
277static int ipmi_ignore_heartbeat = 0; 303static int ipmi_ignore_heartbeat;
278 304
279/* Is someone using the watchdog? Only one user is allowed. */ 305/* Is someone using the watchdog? Only one user is allowed. */
280static unsigned long ipmi_wdog_open = 0; 306static unsigned long ipmi_wdog_open;
281 307
282/* If set to 1, the heartbeat command will set the state to reset and 308/* If set to 1, the heartbeat command will set the state to reset and
283 start the timer. The timer doesn't normally run when the driver is 309 start the timer. The timer doesn't normally run when the driver is
284 first opened until the heartbeat is set the first time, this 310 first opened until the heartbeat is set the first time, this
285 variable is used to accomplish this. */ 311 variable is used to accomplish this. */
286static int ipmi_start_timer_on_heartbeat = 0; 312static int ipmi_start_timer_on_heartbeat;
287 313
288/* IPMI version of the BMC. */ 314/* IPMI version of the BMC. */
289static unsigned char ipmi_version_major; 315static unsigned char ipmi_version_major;
@@ -872,6 +898,11 @@ static void ipmi_register_watchdog(int ipmi_intf)
872 if (watchdog_user) 898 if (watchdog_user)
873 goto out; 899 goto out;
874 900
901 if ((ifnum_to_use >= 0) && (ifnum_to_use != ipmi_intf))
902 goto out;
903
904 watchdog_ifnum = ipmi_intf;
905
875 rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user); 906 rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user);
876 if (rv < 0) { 907 if (rv < 0) {
877 printk(KERN_CRIT PFX "Unable to register with ipmi\n"); 908 printk(KERN_CRIT PFX "Unable to register with ipmi\n");
@@ -901,9 +932,42 @@ static void ipmi_register_watchdog(int ipmi_intf)
901 } 932 }
902} 933}
903 934
935static void ipmi_unregister_watchdog(int ipmi_intf)
936{
937 int rv;
938
939 down_write(&register_sem);
940
941 if (!watchdog_user)
942 goto out;
943
944 if (watchdog_ifnum != ipmi_intf)
945 goto out;
946
947 /* Make sure no one can call us any more. */
948 misc_deregister(&ipmi_wdog_miscdev);
949
950 /* Wait to make sure the message makes it out. The lower layer has
951 pointers to our buffers, we want to make sure they are done before
952 we release our memory. */
953 while (atomic_read(&set_timeout_tofree))
954 schedule_timeout_uninterruptible(1);
955
956 /* Disconnect from IPMI. */
957 rv = ipmi_destroy_user(watchdog_user);
958 if (rv) {
959 printk(KERN_WARNING PFX "error unlinking from IPMI: %d\n",
960 rv);
961 }
962 watchdog_user = NULL;
963
964 out:
965 up_write(&register_sem);
966}
967
904#ifdef HAVE_NMI_HANDLER 968#ifdef HAVE_NMI_HANDLER
905static int 969static int
906ipmi_nmi(void *dev_id, struct pt_regs *regs, int cpu, int handled) 970ipmi_nmi(void *dev_id, int cpu, int handled)
907{ 971{
908 /* If we are not expecting a timeout, ignore it. */ 972 /* If we are not expecting a timeout, ignore it. */
909 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE) 973 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
@@ -1004,9 +1068,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
1004 1068
1005static void ipmi_smi_gone(int if_num) 1069static void ipmi_smi_gone(int if_num)
1006{ 1070{
1007 /* This can never be called, because once the watchdog is 1071 ipmi_unregister_watchdog(if_num);
1008 registered, the interface can't go away until the watchdog
1009 is unregistered. */
1010} 1072}
1011 1073
1012static struct ipmi_smi_watcher smi_watcher = 1074static struct ipmi_smi_watcher smi_watcher =
@@ -1148,30 +1210,32 @@ static int __init ipmi_wdog_init(void)
1148 1210
1149 check_parms(); 1211 check_parms();
1150 1212
1213 register_reboot_notifier(&wdog_reboot_notifier);
1214 atomic_notifier_chain_register(&panic_notifier_list,
1215 &wdog_panic_notifier);
1216
1151 rv = ipmi_smi_watcher_register(&smi_watcher); 1217 rv = ipmi_smi_watcher_register(&smi_watcher);
1152 if (rv) { 1218 if (rv) {
1153#ifdef HAVE_NMI_HANDLER 1219#ifdef HAVE_NMI_HANDLER
1154 if (preaction_val == WDOG_PRETIMEOUT_NMI) 1220 if (preaction_val == WDOG_PRETIMEOUT_NMI)
1155 release_nmi(&ipmi_nmi_handler); 1221 release_nmi(&ipmi_nmi_handler);
1156#endif 1222#endif
1223 atomic_notifier_chain_unregister(&panic_notifier_list,
1224 &wdog_panic_notifier);
1225 unregister_reboot_notifier(&wdog_reboot_notifier);
1157 printk(KERN_WARNING PFX "can't register smi watcher\n"); 1226 printk(KERN_WARNING PFX "can't register smi watcher\n");
1158 return rv; 1227 return rv;
1159 } 1228 }
1160 1229
1161 register_reboot_notifier(&wdog_reboot_notifier);
1162 atomic_notifier_chain_register(&panic_notifier_list,
1163 &wdog_panic_notifier);
1164
1165 printk(KERN_INFO PFX "driver initialized\n"); 1230 printk(KERN_INFO PFX "driver initialized\n");
1166 1231
1167 return 0; 1232 return 0;
1168} 1233}
1169 1234
1170static __exit void ipmi_unregister_watchdog(void) 1235static void __exit ipmi_wdog_exit(void)
1171{ 1236{
1172 int rv; 1237 ipmi_smi_watcher_unregister(&smi_watcher);
1173 1238 ipmi_unregister_watchdog(watchdog_ifnum);
1174 down_write(&register_sem);
1175 1239
1176#ifdef HAVE_NMI_HANDLER 1240#ifdef HAVE_NMI_HANDLER
1177 if (nmi_handler_registered) 1241 if (nmi_handler_registered)
@@ -1179,37 +1243,8 @@ static __exit void ipmi_unregister_watchdog(void)
1179#endif 1243#endif
1180 1244
1181 atomic_notifier_chain_unregister(&panic_notifier_list, 1245 atomic_notifier_chain_unregister(&panic_notifier_list,
1182 &wdog_panic_notifier); 1246 &wdog_panic_notifier);
1183 unregister_reboot_notifier(&wdog_reboot_notifier); 1247 unregister_reboot_notifier(&wdog_reboot_notifier);
1184
1185 if (! watchdog_user)
1186 goto out;
1187
1188 /* Make sure no one can call us any more. */
1189 misc_deregister(&ipmi_wdog_miscdev);
1190
1191 /* Wait to make sure the message makes it out. The lower layer has
1192 pointers to our buffers, we want to make sure they are done before
1193 we release our memory. */
1194 while (atomic_read(&set_timeout_tofree))
1195 schedule_timeout_uninterruptible(1);
1196
1197 /* Disconnect from IPMI. */
1198 rv = ipmi_destroy_user(watchdog_user);
1199 if (rv) {
1200 printk(KERN_WARNING PFX "error unlinking from IPMI: %d\n",
1201 rv);
1202 }
1203 watchdog_user = NULL;
1204
1205 out:
1206 up_write(&register_sem);
1207}
1208
1209static void __exit ipmi_wdog_exit(void)
1210{
1211 ipmi_smi_watcher_unregister(&smi_watcher);
1212 ipmi_unregister_watchdog();
1213} 1248}
1214module_exit(ipmi_wdog_exit); 1249module_exit(ipmi_wdog_exit);
1215module_init(ipmi_wdog_init); 1250module_init(ipmi_wdog_init);