This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / 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 int verbose;
8 extern struct i2o_driver **i2o_drivers;
9 extern unsigned int i2o_max_drivers;
10 static void i2o_report_util_cmd(u8 cmd);
11 static void i2o_report_exec_cmd(u8 cmd);
12 void i2o_report_fail_status(u8 req_status, u32 * msg);
13 void i2o_report_common_status(u8 req_status);
14 static void i2o_report_common_dsc(u16 detailed_status);
15
16 void i2o_dump_status_block(i2o_status_block * sb)
17 {
18         pr_debug("Organization ID: %d\n", sb->org_id);
19         pr_debug("IOP ID:          %d\n", sb->iop_id);
20         pr_debug("Host Unit ID:    %d\n", sb->host_unit_id);
21         pr_debug("Segment Number:  %d\n", sb->segment_number);
22         pr_debug("I2O Version:     %d\n", sb->i2o_version);
23         pr_debug("IOP State:       %d\n", sb->iop_state);
24         pr_debug("Messanger Type:  %d\n", sb->msg_type);
25         pr_debug("Inbound Frame Size:      %d\n", sb->inbound_frame_size);
26         pr_debug("Init Code:               %d\n", sb->init_code);
27         pr_debug("Max Inbound MFrames:     %d\n", sb->max_inbound_frames);
28         pr_debug("Current Inbound MFrames: %d\n", sb->cur_inbound_frames);
29         pr_debug("Max Outbound MFrames:    %d\n", sb->max_outbound_frames);
30         pr_debug("Product ID String: %s\n", sb->product_id);
31         pr_debug("Expected LCT Size: %d\n", sb->expected_lct_size);
32         pr_debug("IOP Capabilities:  %d\n", sb->iop_capabilities);
33         pr_debug("Desired Private MemSize: %d\n", sb->desired_mem_size);
34         pr_debug("Current Private MemSize: %d\n", sb->current_mem_size);
35         pr_debug("Current Private MemBase: %d\n", sb->current_mem_base);
36         pr_debug("Desired Private IO Size: %d\n", sb->desired_io_size);
37         pr_debug("Current Private IO Size: %d\n", sb->current_io_size);
38         pr_debug("Current Private IO Base: %d\n", sb->current_io_base);
39 };
40
41 /*
42  * Used for error reporting/debugging purposes.
43  * Report Cmd name, Request status, Detailed Status.
44  */
45 void i2o_report_status(const char *severity, const char *str,
46                        struct i2o_message *m)
47 {
48         u32 *msg = (u32 *) m;
49         u8 cmd = (msg[1] >> 24) & 0xFF;
50         u8 req_status = (msg[4] >> 24) & 0xFF;
51         u16 detailed_status = msg[4] & 0xFFFF;
52         //struct i2o_driver *h = i2o_drivers[msg[2] & (i2o_max_drivers-1)];
53
54         if (cmd == I2O_CMD_UTIL_EVT_REGISTER)
55                 return;         // No status in this reply
56
57         printk("%s%s: ", severity, str);
58
59         if (cmd < 0x1F)         // Utility cmd
60                 i2o_report_util_cmd(cmd);
61
62         else if (cmd >= 0xA0 && cmd <= 0xEF)    // Executive cmd
63                 i2o_report_exec_cmd(cmd);
64         else
65                 printk("Cmd = %0#2x, ", cmd);   // Other cmds
66
67         if (msg[0] & MSG_FAIL) {
68                 i2o_report_fail_status(req_status, msg);
69                 return;
70         }
71
72         i2o_report_common_status(req_status);
73
74         if (cmd < 0x1F || (cmd >= 0xA0 && cmd <= 0xEF))
75                 i2o_report_common_dsc(detailed_status);
76         else
77                 printk(" / DetailedStatus = %0#4x.\n", detailed_status);
78 }
79
80 /* Used to dump a message to syslog during debugging */
81 void i2o_dump_message(struct i2o_message *m)
82 {
83 #ifdef DEBUG
84         u32 *msg = (u32 *) m;
85         int i;
86         printk(KERN_INFO "Dumping I2O message size %d @ %p\n",
87                msg[0] >> 16 & 0xffff, msg);
88         for (i = 0; i < ((msg[0] >> 16) & 0xffff); i++)
89                 printk(KERN_INFO "  msg[%d] = %0#10x\n", i, msg[i]);
90 #endif
91 }
92
93 /**
94  *      i2o_report_controller_unit - print information about a tid
95  *      @c: controller
96  *      @d: device
97  *
98  *      Dump an information block associated with a given unit (TID). The
99  *      tables are read and a block of text is output to printk that is
100  *      formatted intended for the user.
101  */
102
103 void i2o_report_controller_unit(struct i2o_controller *c, struct i2o_device *d)
104 {
105         char buf[64];
106         char str[22];
107         int ret;
108
109         if (verbose == 0)
110                 return;
111
112         printk(KERN_INFO "Target ID %03x.\n", d->lct_data.tid);
113         if ((ret = i2o_parm_field_get(d, 0xF100, 3, buf, 16)) >= 0) {
114                 buf[16] = 0;
115                 printk(KERN_INFO "     Vendor: %s\n", buf);
116         }
117         if ((ret = i2o_parm_field_get(d, 0xF100, 4, buf, 16)) >= 0) {
118                 buf[16] = 0;
119                 printk(KERN_INFO "     Device: %s\n", buf);
120         }
121         if (i2o_parm_field_get(d, 0xF100, 5, buf, 16) >= 0) {
122                 buf[16] = 0;
123                 printk(KERN_INFO "     Description: %s\n", buf);
124         }
125         if ((ret = i2o_parm_field_get(d, 0xF100, 6, buf, 8)) >= 0) {
126                 buf[8] = 0;
127                 printk(KERN_INFO "        Rev: %s\n", buf);
128         }
129
130         printk(KERN_INFO "    Class: ");
131         //sprintf(str, "%-21s", i2o_get_class_name(d->lct_data.class_id));
132         printk("%s\n", str);
133
134         printk(KERN_INFO "  Subclass: 0x%04X\n", d->lct_data.sub_class);
135         printk(KERN_INFO "     Flags: ");
136
137         if (d->lct_data.device_flags & (1 << 0))
138                 printk("C");    // ConfigDialog requested
139         if (d->lct_data.device_flags & (1 << 1))
140                 printk("U");    // Multi-user capable
141         if (!(d->lct_data.device_flags & (1 << 4)))
142                 printk("P");    // Peer service enabled!
143         if (!(d->lct_data.device_flags & (1 << 5)))
144                 printk("M");    // Mgmt service enabled!
145         printk("\n");
146 }
147
148 /*
149 MODULE_PARM(verbose, "i");
150 MODULE_PARM_DESC(verbose, "Verbose diagnostics");
151 */
152 /*
153  * Used for error reporting/debugging purposes.
154  * Following fail status are common to all classes.
155  * The preserved message must be handled in the reply handler.
156  */
157 void i2o_report_fail_status(u8 req_status, u32 * msg)
158 {
159         static char *FAIL_STATUS[] = {
160                 "0x80",         /* not used */
161                 "SERVICE_SUSPENDED",    /* 0x81 */
162                 "SERVICE_TERMINATED",   /* 0x82 */
163                 "CONGESTION",
164                 "FAILURE",
165                 "STATE_ERROR",
166                 "TIME_OUT",
167                 "ROUTING_FAILURE",
168                 "INVALID_VERSION",
169                 "INVALID_OFFSET",
170                 "INVALID_MSG_FLAGS",
171                 "FRAME_TOO_SMALL",
172                 "FRAME_TOO_LARGE",
173                 "INVALID_TARGET_ID",
174                 "INVALID_INITIATOR_ID",
175                 "INVALID_INITIATOR_CONTEX",     /* 0x8F */
176                 "UNKNOWN_FAILURE"       /* 0xFF */
177         };
178
179         if (req_status == I2O_FSC_TRANSPORT_UNKNOWN_FAILURE)
180                 printk("TRANSPORT_UNKNOWN_FAILURE (%0#2x)\n.", req_status);
181         else
182                 printk("TRANSPORT_%s.\n", FAIL_STATUS[req_status & 0x0F]);
183
184         /* Dump some details */
185
186         printk(KERN_ERR "  InitiatorId = %d, TargetId = %d\n",
187                (msg[1] >> 12) & 0xFFF, msg[1] & 0xFFF);
188         printk(KERN_ERR "  LowestVersion = 0x%02X, HighestVersion = 0x%02X\n",
189                (msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
190         printk(KERN_ERR "  FailingHostUnit = 0x%04X,  FailingIOP = 0x%03X\n",
191                msg[5] >> 16, msg[5] & 0xFFF);
192
193         printk(KERN_ERR "  Severity:  0x%02X ", (msg[4] >> 16) & 0xFF);
194         if (msg[4] & (1 << 16))
195                 printk("(FormatError), "
196                        "this msg can never be delivered/processed.\n");
197         if (msg[4] & (1 << 17))
198                 printk("(PathError), "
199                        "this msg can no longer be delivered/processed.\n");
200         if (msg[4] & (1 << 18))
201                 printk("(PathState), "
202                        "the system state does not allow delivery.\n");
203         if (msg[4] & (1 << 19))
204                 printk("(Congestion), resources temporarily not available;"
205                        "do not retry immediately.\n");
206 }
207
208 /*
209  * Used for error reporting/debugging purposes.
210  * Following reply status are common to all classes.
211  */
212 void i2o_report_common_status(u8 req_status)
213 {
214         static char *REPLY_STATUS[] = {
215                 "SUCCESS",
216                 "ABORT_DIRTY",
217                 "ABORT_NO_DATA_TRANSFER",
218                 "ABORT_PARTIAL_TRANSFER",
219                 "ERROR_DIRTY",
220                 "ERROR_NO_DATA_TRANSFER",
221                 "ERROR_PARTIAL_TRANSFER",
222                 "PROCESS_ABORT_DIRTY",
223                 "PROCESS_ABORT_NO_DATA_TRANSFER",
224                 "PROCESS_ABORT_PARTIAL_TRANSFER",
225                 "TRANSACTION_ERROR",
226                 "PROGRESS_REPORT"
227         };
228
229         if (req_status >= ARRAY_SIZE(REPLY_STATUS))
230                 printk("RequestStatus = %0#2x", req_status);
231         else
232                 printk("%s", REPLY_STATUS[req_status]);
233 }
234
235 /*
236  * Used for error reporting/debugging purposes.
237  * Following detailed status are valid  for executive class,
238  * utility class, DDM class and for transaction error replies.
239  */
240 static void i2o_report_common_dsc(u16 detailed_status)
241 {
242         static char *COMMON_DSC[] = {
243                 "SUCCESS",
244                 "0x01",         // not used
245                 "BAD_KEY",
246                 "TCL_ERROR",
247                 "REPLY_BUFFER_FULL",
248                 "NO_SUCH_PAGE",
249                 "INSUFFICIENT_RESOURCE_SOFT",
250                 "INSUFFICIENT_RESOURCE_HARD",
251                 "0x08",         // not used
252                 "CHAIN_BUFFER_TOO_LARGE",
253                 "UNSUPPORTED_FUNCTION",
254                 "DEVICE_LOCKED",
255                 "DEVICE_RESET",
256                 "INAPPROPRIATE_FUNCTION",
257                 "INVALID_INITIATOR_ADDRESS",
258                 "INVALID_MESSAGE_FLAGS",
259                 "INVALID_OFFSET",
260                 "INVALID_PARAMETER",
261                 "INVALID_REQUEST",
262                 "INVALID_TARGET_ADDRESS",
263                 "MESSAGE_TOO_LARGE",
264                 "MESSAGE_TOO_SMALL",
265                 "MISSING_PARAMETER",
266                 "TIMEOUT",
267                 "UNKNOWN_ERROR",
268                 "UNKNOWN_FUNCTION",
269                 "UNSUPPORTED_VERSION",
270                 "DEVICE_BUSY",
271                 "DEVICE_NOT_AVAILABLE"
272         };
273
274         if (detailed_status > I2O_DSC_DEVICE_NOT_AVAILABLE)
275                 printk(" / DetailedStatus = %0#4x.\n", detailed_status);
276         else
277                 printk(" / %s.\n", COMMON_DSC[detailed_status]);
278 }
279
280 /*
281  * Used for error reporting/debugging purposes
282  */
283 static void i2o_report_util_cmd(u8 cmd)
284 {
285         switch (cmd) {
286         case I2O_CMD_UTIL_NOP:
287                 printk("UTIL_NOP, ");
288                 break;
289         case I2O_CMD_UTIL_ABORT:
290                 printk("UTIL_ABORT, ");
291                 break;
292         case I2O_CMD_UTIL_CLAIM:
293                 printk("UTIL_CLAIM, ");
294                 break;
295         case I2O_CMD_UTIL_RELEASE:
296                 printk("UTIL_CLAIM_RELEASE, ");
297                 break;
298         case I2O_CMD_UTIL_CONFIG_DIALOG:
299                 printk("UTIL_CONFIG_DIALOG, ");
300                 break;
301         case I2O_CMD_UTIL_DEVICE_RESERVE:
302                 printk("UTIL_DEVICE_RESERVE, ");
303                 break;
304         case I2O_CMD_UTIL_DEVICE_RELEASE:
305                 printk("UTIL_DEVICE_RELEASE, ");
306                 break;
307         case I2O_CMD_UTIL_EVT_ACK:
308                 printk("UTIL_EVENT_ACKNOWLEDGE, ");
309                 break;
310         case I2O_CMD_UTIL_EVT_REGISTER:
311                 printk("UTIL_EVENT_REGISTER, ");
312                 break;
313         case I2O_CMD_UTIL_LOCK:
314                 printk("UTIL_LOCK, ");
315                 break;
316         case I2O_CMD_UTIL_LOCK_RELEASE:
317                 printk("UTIL_LOCK_RELEASE, ");
318                 break;
319         case I2O_CMD_UTIL_PARAMS_GET:
320                 printk("UTIL_PARAMS_GET, ");
321                 break;
322         case I2O_CMD_UTIL_PARAMS_SET:
323                 printk("UTIL_PARAMS_SET, ");
324                 break;
325         case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY:
326                 printk("UTIL_REPLY_FAULT_NOTIFY, ");
327                 break;
328         default:
329                 printk("Cmd = %0#2x, ", cmd);
330         }
331 }
332
333 /*
334  * Used for error reporting/debugging purposes
335  */
336 static void i2o_report_exec_cmd(u8 cmd)
337 {
338         switch (cmd) {
339         case I2O_CMD_ADAPTER_ASSIGN:
340                 printk("EXEC_ADAPTER_ASSIGN, ");
341                 break;
342         case I2O_CMD_ADAPTER_READ:
343                 printk("EXEC_ADAPTER_READ, ");
344                 break;
345         case I2O_CMD_ADAPTER_RELEASE:
346                 printk("EXEC_ADAPTER_RELEASE, ");
347                 break;
348         case I2O_CMD_BIOS_INFO_SET:
349                 printk("EXEC_BIOS_INFO_SET, ");
350                 break;
351         case I2O_CMD_BOOT_DEVICE_SET:
352                 printk("EXEC_BOOT_DEVICE_SET, ");
353                 break;
354         case I2O_CMD_CONFIG_VALIDATE:
355                 printk("EXEC_CONFIG_VALIDATE, ");
356                 break;
357         case I2O_CMD_CONN_SETUP:
358                 printk("EXEC_CONN_SETUP, ");
359                 break;
360         case I2O_CMD_DDM_DESTROY:
361                 printk("EXEC_DDM_DESTROY, ");
362                 break;
363         case I2O_CMD_DDM_ENABLE:
364                 printk("EXEC_DDM_ENABLE, ");
365                 break;
366         case I2O_CMD_DDM_QUIESCE:
367                 printk("EXEC_DDM_QUIESCE, ");
368                 break;
369         case I2O_CMD_DDM_RESET:
370                 printk("EXEC_DDM_RESET, ");
371                 break;
372         case I2O_CMD_DDM_SUSPEND:
373                 printk("EXEC_DDM_SUSPEND, ");
374                 break;
375         case I2O_CMD_DEVICE_ASSIGN:
376                 printk("EXEC_DEVICE_ASSIGN, ");
377                 break;
378         case I2O_CMD_DEVICE_RELEASE:
379                 printk("EXEC_DEVICE_RELEASE, ");
380                 break;
381         case I2O_CMD_HRT_GET:
382                 printk("EXEC_HRT_GET, ");
383                 break;
384         case I2O_CMD_ADAPTER_CLEAR:
385                 printk("EXEC_IOP_CLEAR, ");
386                 break;
387         case I2O_CMD_ADAPTER_CONNECT:
388                 printk("EXEC_IOP_CONNECT, ");
389                 break;
390         case I2O_CMD_ADAPTER_RESET:
391                 printk("EXEC_IOP_RESET, ");
392                 break;
393         case I2O_CMD_LCT_NOTIFY:
394                 printk("EXEC_LCT_NOTIFY, ");
395                 break;
396         case I2O_CMD_OUTBOUND_INIT:
397                 printk("EXEC_OUTBOUND_INIT, ");
398                 break;
399         case I2O_CMD_PATH_ENABLE:
400                 printk("EXEC_PATH_ENABLE, ");
401                 break;
402         case I2O_CMD_PATH_QUIESCE:
403                 printk("EXEC_PATH_QUIESCE, ");
404                 break;
405         case I2O_CMD_PATH_RESET:
406                 printk("EXEC_PATH_RESET, ");
407                 break;
408         case I2O_CMD_STATIC_MF_CREATE:
409                 printk("EXEC_STATIC_MF_CREATE, ");
410                 break;
411         case I2O_CMD_STATIC_MF_RELEASE:
412                 printk("EXEC_STATIC_MF_RELEASE, ");
413                 break;
414         case I2O_CMD_STATUS_GET:
415                 printk("EXEC_STATUS_GET, ");
416                 break;
417         case I2O_CMD_SW_DOWNLOAD:
418                 printk("EXEC_SW_DOWNLOAD, ");
419                 break;
420         case I2O_CMD_SW_UPLOAD:
421                 printk("EXEC_SW_UPLOAD, ");
422                 break;
423         case I2O_CMD_SW_REMOVE:
424                 printk("EXEC_SW_REMOVE, ");
425                 break;
426         case I2O_CMD_SYS_ENABLE:
427                 printk("EXEC_SYS_ENABLE, ");
428                 break;
429         case I2O_CMD_SYS_MODIFY:
430                 printk("EXEC_SYS_MODIFY, ");
431                 break;
432         case I2O_CMD_SYS_QUIESCE:
433                 printk("EXEC_SYS_QUIESCE, ");
434                 break;
435         case I2O_CMD_SYS_TAB_SET:
436                 printk("EXEC_SYS_TAB_SET, ");
437                 break;
438         default:
439                 printk("Cmd = %#02x, ", cmd);
440         }
441 }
442
443 void i2o_debug_state(struct i2o_controller *c)
444 {
445         printk(KERN_INFO "%s: State = ", c->name);
446         switch (((i2o_status_block *) c->status_block.virt)->iop_state) {
447         case 0x01:
448                 printk("INIT\n");
449                 break;
450         case 0x02:
451                 printk("RESET\n");
452                 break;
453         case 0x04:
454                 printk("HOLD\n");
455                 break;
456         case 0x05:
457                 printk("READY\n");
458                 break;
459         case 0x08:
460                 printk("OPERATIONAL\n");
461                 break;
462         case 0x10:
463                 printk("FAILED\n");
464                 break;
465         case 0x11:
466                 printk("FAULTED\n");
467                 break;
468         default:
469                 printk("%x (unknown !!)\n",
470                        ((i2o_status_block *) c->status_block.virt)->iop_state);
471         }
472 };
473
474 void i2o_systab_debug(struct i2o_sys_tbl *sys_tbl)
475 {
476         u32 *table;
477         int count;
478         u32 size;
479
480         table = (u32 *) sys_tbl;
481         size = sizeof(struct i2o_sys_tbl) + sys_tbl->num_entries
482             * sizeof(struct i2o_sys_tbl_entry);
483
484         for (count = 0; count < (size >> 2); count++)
485                 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n", count, table[count]);
486 }
487
488 void i2o_dump_hrt(struct i2o_controller *c)
489 {
490         u32 *rows = (u32 *) c->hrt.virt;
491         u8 *p = (u8 *) c->hrt.virt;
492         u8 *d;
493         int count;
494         int length;
495         int i;
496         int state;
497
498         if (p[3] != 0) {
499                 printk(KERN_ERR
500                        "%s: HRT table for controller is too new a version.\n",
501                        c->name);
502                 return;
503         }
504
505         count = p[0] | (p[1] << 8);
506         length = p[2];
507
508         printk(KERN_INFO "%s: HRT has %d entries of %d bytes each.\n",
509                c->name, count, length << 2);
510
511         rows += 2;
512
513         for (i = 0; i < count; i++) {
514                 printk(KERN_INFO "Adapter %08X: ", rows[0]);
515                 p = (u8 *) (rows + 1);
516                 d = (u8 *) (rows + 2);
517                 state = p[1] << 8 | p[0];
518
519                 printk("TID %04X:[", state & 0xFFF);
520                 state >>= 12;
521                 if (state & (1 << 0))
522                         printk("H");    /* Hidden */
523                 if (state & (1 << 2)) {
524                         printk("P");    /* Present */
525                         if (state & (1 << 1))
526                                 printk("C");    /* Controlled */
527                 }
528                 if (state > 9)
529                         printk("*");    /* Hard */
530
531                 printk("]:");
532
533                 switch (p[3] & 0xFFFF) {
534                 case 0:
535                         /* Adapter private bus - easy */
536                         printk("Local bus %d: I/O at 0x%04X Mem 0x%08X",
537                                p[2], d[1] << 8 | d[0], *(u32 *) (d + 4));
538                         break;
539                 case 1:
540                         /* ISA bus */
541                         printk("ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X",
542                                p[2], d[2], d[1] << 8 | d[0], *(u32 *) (d + 4));
543                         break;
544
545                 case 2: /* EISA bus */
546                         printk("EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
547                                p[2], d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
548                         break;
549
550                 case 3: /* MCA bus */
551                         printk("MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
552                                p[2], d[3], d[1] << 8 | d[0], *(u32 *) (d + 4));
553                         break;
554
555                 case 4: /* PCI bus */
556                         printk("PCI %d: Bus %d Device %d Function %d",
557                                p[2], d[2], d[1], d[0]);
558                         break;
559
560                 case 0x80:      /* Other */
561                 default:
562                         printk("Unsupported bus type.");
563                         break;
564                 }
565                 printk("\n");
566                 rows += length;
567         }
568 }
569
570 EXPORT_SYMBOL(i2o_dump_status_block);
571 EXPORT_SYMBOL(i2o_dump_message);