[PATCH] drivers/message/i2o/pci.c: fix a NULL pointer dereference
[linux-2.6] / drivers / message / i2o / debug.c
1 #include <linux/config.h>
2 #include <linux/module.h>
3 #include <linux/kernel.h>
4 #include <linux/pci.h>
5 #include <linux/i2o.h>
6
7 static void i2o_report_util_cmd(u8 cmd);
8 static void i2o_report_exec_cmd(u8 cmd);
9 static void i2o_report_fail_status(u8 req_status, u32 * msg);
10 static void i2o_report_common_status(u8 req_status);
11 static void i2o_report_common_dsc(u16 detailed_status);
12
13 /*
14  * Used for error reporting/debugging purposes.
15  * Report Cmd name, Request status, Detailed Status.
16  */
17 void i2o_report_status(const char *severity, const char *str,
18                        struct i2o_message *m)
19 {
20         u32 *msg = (u32 *) m;
21         u8 cmd = (msg[1] >> 24) & 0xFF;
22         u8 req_status = (msg[4] >> 24) & 0xFF;
23         u16 detailed_status = msg[4] & 0xFFFF;
24
25         if (cmd == I2O_CMD_UTIL_EVT_REGISTER)
26                 return;         // No status in this reply
27
28         printk(KERN_DEBUG "%s%s: ", severity, str);
29
30         if (cmd < 0x1F)         // Utility cmd
31                 i2o_report_util_cmd(cmd);
32
33         else if (cmd >= 0xA0 && cmd <= 0xEF)    // Executive cmd
34                 i2o_report_exec_cmd(cmd);
35         else
36                 printk(KERN_DEBUG "Cmd = %0#2x, ", cmd);        // Other cmds
37
38         if (msg[0] & MSG_FAIL) {
39                 i2o_report_fail_status(req_status, msg);
40                 return;
41         }
42
43         i2o_report_common_status(req_status);
44
45         if (cmd < 0x1F || (cmd >= 0xA0 && cmd <= 0xEF))
46                 i2o_report_common_dsc(detailed_status);
47         else
48                 printk(KERN_DEBUG " / DetailedStatus = %0#4x.\n",
49                        detailed_status);
50 }
51
52 /* Used to dump a message to syslog during debugging */
53 void i2o_dump_message(struct i2o_message *m)
54 {
55 #ifdef DEBUG
56         u32 *msg = (u32 *) m;
57         int i;
58         printk(KERN_INFO "Dumping I2O message size %d @ %p\n",
59                msg[0] >> 16 & 0xffff, msg);
60         for (i = 0; i < ((msg[0] >> 16) & 0xffff); i++)
61                 printk(KERN_INFO "  msg[%d] = %0#10x\n", i, msg[i]);
62 #endif
63 }
64
65 /*
66  * Used for error reporting/debugging purposes.
67  * Following fail status are common to all classes.
68  * The preserved message must be handled in the reply handler.
69  */
70 static void i2o_report_fail_status(u8 req_status, u32 * msg)
71 {
72         static char *FAIL_STATUS[] = {
73                 "0x80",         /* not used */
74                 "SERVICE_SUSPENDED",    /* 0x81 */
75                 "SERVICE_TERMINATED",   /* 0x82 */
76                 "CONGESTION",
77                 "FAILURE",
78                 "STATE_ERROR",
79                 "TIME_OUT",
80                 "ROUTING_FAILURE",
81                 "INVALID_VERSION",
82                 "INVALID_OFFSET",
83                 "INVALID_MSG_FLAGS",
84                 "FRAME_TOO_SMALL",
85                 "FRAME_TOO_LARGE",
86                 "INVALID_TARGET_ID",
87                 "INVALID_INITIATOR_ID",
88                 "INVALID_INITIATOR_CONTEX",     /* 0x8F */
89                 "UNKNOWN_FAILURE"       /* 0xFF */
90         };
91
92         if (req_status == I2O_FSC_TRANSPORT_UNKNOWN_FAILURE)
93                 printk(KERN_DEBUG "TRANSPORT_UNKNOWN_FAILURE (%0#2x).\n",
94                        req_status);
95         else
96                 printk(KERN_DEBUG "TRANSPORT_%s.\n",
97                        FAIL_STATUS[req_status & 0x0F]);
98
99         /* Dump some details */
100
101         printk(KERN_ERR "  InitiatorId = %d, TargetId = %d\n",
102                (msg[1] >> 12) & 0xFFF, msg[1] & 0xFFF);
103         printk(KERN_ERR "  LowestVersion = 0x%02X, HighestVersion = 0x%02X\n",
104                (msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
105         printk(KERN_ERR "  FailingHostUnit = 0x%04X,  FailingIOP = 0x%03X\n",
106                msg[5] >> 16, msg[5] & 0xFFF);
107
108         printk(KERN_ERR "  Severity:  0x%02X ", (msg[4] >> 16) & 0xFF);
109         if (msg[4] & (1 << 16))
110                 printk(KERN_DEBUG "(FormatError), "
111                        "this msg can never be delivered/processed.\n");
112         if (msg[4] & (1 << 17))
113                 printk(KERN_DEBUG "(PathError), "
114                        "this msg can no longer be delivered/processed.\n");
115         if (msg[4] & (1 << 18))
116                 printk(KERN_DEBUG "(PathState), "
117                        "the system state does not allow delivery.\n");
118         if (msg[4] & (1 << 19))
119                 printk(KERN_DEBUG
120                        "(Congestion), resources temporarily not available;"
121                        "do not retry immediately.\n");
122 }
123
124 /*
125  * Used for error reporting/debugging purposes.
126  * Following reply status are common to all classes.
127  */
128 static void i2o_report_common_status(u8 req_status)
129 {
130         static char *REPLY_STATUS[] = {
131                 "SUCCESS",
132                 "ABORT_DIRTY",
133                 "ABORT_NO_DATA_TRANSFER",
134                 "ABORT_PARTIAL_TRANSFER",
135                 "ERROR_DIRTY",
136                 "ERROR_NO_DATA_TRANSFER",
137                 "ERROR_PARTIAL_TRANSFER",
138                 "PROCESS_ABORT_DIRTY",
139                 "PROCESS_ABORT_NO_DATA_TRANSFER",
140                 "PROCESS_ABORT_PARTIAL_TRANSFER",
141                 "TRANSACTION_ERROR",
142                 "PROGRESS_REPORT"
143         };
144
145         if (req_status >= ARRAY_SIZE(REPLY_STATUS))
146                 printk(KERN_DEBUG "RequestStatus = %0#2x", req_status);
147         else
148                 printk(KERN_DEBUG "%s", REPLY_STATUS[req_status]);
149 }
150
151 /*
152  * Used for error reporting/debugging purposes.
153  * Following detailed status are valid  for executive class,
154  * utility class, DDM class and for transaction error replies.
155  */
156 static void i2o_report_common_dsc(u16 detailed_status)
157 {
158         static char *COMMON_DSC[] = {
159                 "SUCCESS",
160                 "0x01",         // not used
161                 "BAD_KEY",
162                 "TCL_ERROR",
163                 "REPLY_BUFFER_FULL",
164                 "NO_SUCH_PAGE",
165                 "INSUFFICIENT_RESOURCE_SOFT",
166                 "INSUFFICIENT_RESOURCE_HARD",
167                 "0x08",         // not used
168                 "CHAIN_BUFFER_TOO_LARGE",
169                 "UNSUPPORTED_FUNCTION",
170                 "DEVICE_LOCKED",
171                 "DEVICE_RESET",
172                 "INAPPROPRIATE_FUNCTION",
173                 "INVALID_INITIATOR_ADDRESS",
174                 "INVALID_MESSAGE_FLAGS",
175                 "INVALID_OFFSET",
176                 "INVALID_PARAMETER",
177                 "INVALID_REQUEST",
178                 "INVALID_TARGET_ADDRESS",
179                 "MESSAGE_TOO_LARGE",
180                 "MESSAGE_TOO_SMALL",
181                 "MISSING_PARAMETER",
182                 "TIMEOUT",
183                 "UNKNOWN_ERROR",
184                 "UNKNOWN_FUNCTION",
185                 "UNSUPPORTED_VERSION",
186                 "DEVICE_BUSY",
187                 "DEVICE_NOT_AVAILABLE"
188         };
189
190         if (detailed_status > I2O_DSC_DEVICE_NOT_AVAILABLE)
191                 printk(KERN_DEBUG " / DetailedStatus = %0#4x.\n",
192                        detailed_status);
193         else
194                 printk(KERN_DEBUG " / %s.\n", COMMON_DSC[detailed_status]);
195 }
196
197 /*
198  * Used for error reporting/debugging purposes
199  */
200 static void i2o_report_util_cmd(u8 cmd)
201 {
202         switch (cmd) {
203         case I2O_CMD_UTIL_NOP:
204                 printk(KERN_DEBUG "UTIL_NOP, ");
205                 break;
206         case I2O_CMD_UTIL_ABORT:
207                 printk(KERN_DEBUG "UTIL_ABORT, ");
208                 break;
209         case I2O_CMD_UTIL_CLAIM:
210                 printk(KERN_DEBUG "UTIL_CLAIM, ");
211                 break;
212         case I2O_CMD_UTIL_RELEASE:
213                 printk(KERN_DEBUG "UTIL_CLAIM_RELEASE, ");
214                 break;
215         case I2O_CMD_UTIL_CONFIG_DIALOG:
216                 printk(KERN_DEBUG "UTIL_CONFIG_DIALOG, ");
217                 break;
218         case I2O_CMD_UTIL_DEVICE_RESERVE:
219                 printk(KERN_DEBUG "UTIL_DEVICE_RESERVE, ");
220                 break;
221         case I2O_CMD_UTIL_DEVICE_RELEASE:
222                 printk(KERN_DEBUG "UTIL_DEVICE_RELEASE, ");
223                 break;
224         case I2O_CMD_UTIL_EVT_ACK:
225                 printk(KERN_DEBUG "UTIL_EVENT_ACKNOWLEDGE, ");
226                 break;
227         case I2O_CMD_UTIL_EVT_REGISTER:
228                 printk(KERN_DEBUG "UTIL_EVENT_REGISTER, ");
229                 break;
230         case I2O_CMD_UTIL_LOCK:
231                 printk(KERN_DEBUG "UTIL_LOCK, ");
232                 break;
233         case I2O_CMD_UTIL_LOCK_RELEASE:
234                 printk(KERN_DEBUG "UTIL_LOCK_RELEASE, ");
235                 break;
236         case I2O_CMD_UTIL_PARAMS_GET:
237                 printk(KERN_DEBUG "UTIL_PARAMS_GET, ");
238                 break;
239         case I2O_CMD_UTIL_PARAMS_SET:
240                 printk(KERN_DEBUG "UTIL_PARAMS_SET, ");
241                 break;
242         case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY:
243                 printk(KERN_DEBUG "UTIL_REPLY_FAULT_NOTIFY, ");
244                 break;
245         default:
246                 printk(KERN_DEBUG "Cmd = %0#2x, ", cmd);
247         }
248 }
249
250 /*
251  * Used for error reporting/debugging purposes
252  */
253 static void i2o_report_exec_cmd(u8 cmd)
254 {
255         switch (cmd) {
256         case I2O_CMD_ADAPTER_ASSIGN:
257                 printk(KERN_DEBUG "EXEC_ADAPTER_ASSIGN, ");
258                 break;
259         case I2O_CMD_ADAPTER_READ:
260                 printk(KERN_DEBUG "EXEC_ADAPTER_READ, ");
261                 break;
262         case I2O_CMD_ADAPTER_RELEASE:
263                 printk(KERN_DEBUG "EXEC_ADAPTER_RELEASE, ");
264                 break;
265         case I2O_CMD_BIOS_INFO_SET:
266                 printk(KERN_DEBUG "EXEC_BIOS_INFO_SET, ");
267                 break;
268         case I2O_CMD_BOOT_DEVICE_SET:
269                 printk(KERN_DEBUG "EXEC_BOOT_DEVICE_SET, ");
270                 break;
271         case I2O_CMD_CONFIG_VALIDATE:
272                 printk(KERN_DEBUG "EXEC_CONFIG_VALIDATE, ");
273                 break;
274         case I2O_CMD_CONN_SETUP:
275                 printk(KERN_DEBUG "EXEC_CONN_SETUP, ");
276                 break;
277         case I2O_CMD_DDM_DESTROY:
278                 printk(KERN_DEBUG "EXEC_DDM_DESTROY, ");
279                 break;
280         case I2O_CMD_DDM_ENABLE:
281                 printk(KERN_DEBUG "EXEC_DDM_ENABLE, ");
282                 break;
283         case I2O_CMD_DDM_QUIESCE:
284                 printk(KERN_DEBUG "EXEC_DDM_QUIESCE, ");
285                 break;
286         case I2O_CMD_DDM_RESET:
287                 printk(KERN_DEBUG "EXEC_DDM_RESET, ");
288                 break;
289         case I2O_CMD_DDM_SUSPEND:
290                 printk(KERN_DEBUG "EXEC_DDM_SUSPEND, ");
291                 break;
292         case I2O_CMD_DEVICE_ASSIGN:
293                 printk(KERN_DEBUG "EXEC_DEVICE_ASSIGN, ");
294                 break;
295         case I2O_CMD_DEVICE_RELEASE:
296                 printk(KERN_DEBUG "EXEC_DEVICE_RELEASE, ");
297                 break;
298         case I2O_CMD_HRT_GET:
299                 printk(KERN_DEBUG "EXEC_HRT_GET, ");
300                 break;
301         case I2O_CMD_ADAPTER_CLEAR:
302                 printk(KERN_DEBUG "EXEC_IOP_CLEAR, ");
303                 break;
304         case I2O_CMD_ADAPTER_CONNECT:
305                 printk(KERN_DEBUG "EXEC_IOP_CONNECT, ");
306                 break;
307         case I2O_CMD_ADAPTER_RESET:
308                 printk(KERN_DEBUG "EXEC_IOP_RESET, ");
309                 break;
310         case I2O_CMD_LCT_NOTIFY:
311                 printk(KERN_DEBUG "EXEC_LCT_NOTIFY, ");
312                 break;
313         case I2O_CMD_OUTBOUND_INIT:
314                 printk(KERN_DEBUG "EXEC_OUTBOUND_INIT, ");
315                 break;
316         case I2O_CMD_PATH_ENABLE:
317                 printk(KERN_DEBUG "EXEC_PATH_ENABLE, ");
318                 break;
319         case I2O_CMD_PATH_QUIESCE:
320                 printk(KERN_DEBUG "EXEC_PATH_QUIESCE, ");
321                 break;
322         case I2O_CMD_PATH_RESET:
323                 printk(KERN_DEBUG "EXEC_PATH_RESET, ");
324                 break;
325         case I2O_CMD_STATIC_MF_CREATE:
326                 printk(KERN_DEBUG "EXEC_STATIC_MF_CREATE, ");
327                 break;
328         case I2O_CMD_STATIC_MF_RELEASE:
329                 printk(KERN_DEBUG "EXEC_STATIC_MF_RELEASE, ");
330                 break;
331         case I2O_CMD_STATUS_GET:
332                 printk(KERN_DEBUG "EXEC_STATUS_GET, ");
333                 break;
334         case I2O_CMD_SW_DOWNLOAD:
335                 printk(KERN_DEBUG "EXEC_SW_DOWNLOAD, ");
336                 break;
337         case I2O_CMD_SW_UPLOAD:
338                 printk(KERN_DEBUG "EXEC_SW_UPLOAD, ");
339                 break;
340         case I2O_CMD_SW_REMOVE:
341                 printk(KERN_DEBUG "EXEC_SW_REMOVE, ");
342                 break;
343         case I2O_CMD_SYS_ENABLE:
344                 printk(KERN_DEBUG "EXEC_SYS_ENABLE, ");
345                 break;
346         case I2O_CMD_SYS_MODIFY:
347                 printk(KERN_DEBUG "EXEC_SYS_MODIFY, ");
348                 break;
349         case I2O_CMD_SYS_QUIESCE:
350                 printk(KERN_DEBUG "EXEC_SYS_QUIESCE, ");
351                 break;
352         case I2O_CMD_SYS_TAB_SET:
353                 printk(KERN_DEBUG "EXEC_SYS_TAB_SET, ");
354                 break;
355         default:
356                 printk(KERN_DEBUG "Cmd = %#02x, ", cmd);
357         }
358 }
359
360 void i2o_debug_state(struct i2o_controller *c)
361 {
362         printk(KERN_INFO "%s: State = ", c->name);
363         switch (((i2o_status_block *) c->status_block.virt)->iop_state) {
364         case 0x01:
365                 printk(KERN_DEBUG "INIT\n");
366                 break;
367         case 0x02:
368                 printk(KERN_DEBUG "RESET\n");
369                 break;
370         case 0x04:
371                 printk(KERN_DEBUG "HOLD\n");
372                 break;
373         case 0x05:
374                 printk(KERN_DEBUG "READY\n");
375                 break;
376         case 0x08:
377                 printk(KERN_DEBUG "OPERATIONAL\n");
378                 break;
379         case 0x10:
380                 printk(KERN_DEBUG "FAILED\n");
381                 break;
382         case 0x11:
383                 printk(KERN_DEBUG "FAULTED\n");
384                 break;
385         default:
386                 printk(KERN_DEBUG "%x (unknown !!)\n",
387                        ((i2o_status_block *) c->status_block.virt)->iop_state);
388         }
389 };
390
391 void i2o_dump_hrt(struct i2o_controller *c)
392 {
393         u32 *rows = (u32 *) c->hrt.virt;
394         u8 *p = (u8 *) c->hrt.virt;
395         u8 *d;
396         int count;
397         int length;
398         int i;
399         int state;
400
401         if (p[3] != 0) {
402                 printk(KERN_ERR
403                        "%s: HRT table for controller is too new a version.\n",
404                        c->name);
405                 return;
406         }
407
408         count = p[0] | (p[1] << 8);
409         length = p[2];
410
411         printk(KERN_INFO "%s: HRT has %d entries of %d bytes each.\n",
412                c->name, count, length << 2);
413
414         rows += 2;
415
416         for (i = 0; i < count; i++) {
417                 printk(KERN_INFO "Adapter %08X: ", rows[0]);
418                 p = (u8 *) (rows + 1);
419                 d = (u8 *) (rows + 2);
420                 state = p[1] << 8 | p[0];
421
422                 printk(KERN_DEBUG "TID %04X:[", state & 0xFFF);
423                 state >>= 12;
424                 if (state & (1 << 0))
425                         printk(KERN_DEBUG "H"); /* Hidden */
426                 if (state & (1 << 2)) {
427                         printk(KERN_DEBUG "P"); /* Present */
428                         if (state & (1 << 1))
429                                 printk(KERN_DEBUG "C"); /* Controlled */
430                 }
431                 if (state > 9)
432                         printk(KERN_DEBUG "*"); /* Hard */
433
434                 printk(KERN_DEBUG "]:");
435
436                 switch (p[3] & 0xFFFF) {
437                 case 0:
438                         /* Adapter private bus - easy */
439                         printk(KERN_DEBUG
440                                "Local bus %d: I/O at 0x%04X Mem 0x%08X", p[2],
441                                d[1] << 8 | d[0], *(u32 *) (d + 4));
442                         break;
443                 case 1:
444                         /* ISA bus */
445                         printk(KERN_DEBUG
446                                "ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X", p[2],
447                                d[2], d[1] << 8 | d[0], *(u32 *) (d + 4));
448                         break;
449
450                 case 2: /* EISA bus */
451                         printk(KERN_DEBUG
452                                "EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
453                                p[2], d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
454                         break;
455
456                 case 3: /* MCA bus */
457                         printk(KERN_DEBUG
458                                "MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X", p[2],
459                                d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
460                         break;
461
462                 case 4: /* PCI bus */
463                         printk(KERN_DEBUG
464                                "PCI %d: Bus %d Device %d Function %d", p[2],
465                                d[2], d[1], d[0]);
466                         break;
467
468                 case 0x80:      /* Other */
469                 default:
470                         printk(KERN_DEBUG "Unsupported bus type.");
471                         break;
472                 }
473                 printk(KERN_DEBUG "\n");
474                 rows += length;
475         }
476 }
477
478 EXPORT_SYMBOL(i2o_dump_message);