err_common.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * linux/arch/alpha/kernel/err_common.c
  3. *
  4. * Copyright (C) 2000 Jeff Wiedemeier (Compaq Computer Corporation)
  5. *
  6. * Error handling code supporting Alpha systems
  7. */
  8. #include <linux/init.h>
  9. #include <linux/sched.h>
  10. #include <asm/io.h>
  11. #include <asm/hwrpb.h>
  12. #include <asm/smp.h>
  13. #include <asm/err_common.h>
  14. #include "err_impl.h"
  15. #include "proto.h"
  16. /*
  17. * err_print_prefix -- error handling print routines should prefix
  18. * all prints with this
  19. */
  20. char *err_print_prefix = KERN_NOTICE;
  21. /*
  22. * Generic
  23. */
  24. void
  25. mchk_dump_mem(void *data, size_t length, char **annotation)
  26. {
  27. unsigned long *ldata = data;
  28. size_t i;
  29. for (i = 0; (i * sizeof(*ldata)) < length; i++) {
  30. if (annotation && !annotation[i])
  31. annotation = NULL;
  32. printk("%s %08x: %016lx %s\n",
  33. err_print_prefix,
  34. (unsigned)(i * sizeof(*ldata)), ldata[i],
  35. annotation ? annotation[i] : "");
  36. }
  37. }
  38. void
  39. mchk_dump_logout_frame(struct el_common *mchk_header)
  40. {
  41. printk("%s -- Frame Header --\n"
  42. " Frame Size: %d (0x%x) bytes\n"
  43. " Flags: %s%s\n"
  44. " MCHK Code: 0x%x\n"
  45. " Frame Rev: %d\n"
  46. " Proc Offset: 0x%08x\n"
  47. " Sys Offset: 0x%08x\n"
  48. " -- Processor Region --\n",
  49. err_print_prefix,
  50. mchk_header->size, mchk_header->size,
  51. mchk_header->retry ? "RETRY " : "",
  52. mchk_header->err2 ? "SECOND_ERR " : "",
  53. mchk_header->code,
  54. mchk_header->frame_rev,
  55. mchk_header->proc_offset,
  56. mchk_header->sys_offset);
  57. mchk_dump_mem((void *)
  58. ((unsigned long)mchk_header + mchk_header->proc_offset),
  59. mchk_header->sys_offset - mchk_header->proc_offset,
  60. NULL);
  61. printk("%s -- System Region --\n", err_print_prefix);
  62. mchk_dump_mem((void *)
  63. ((unsigned long)mchk_header + mchk_header->sys_offset),
  64. mchk_header->size - mchk_header->sys_offset,
  65. NULL);
  66. printk("%s -- End of Frame --\n", err_print_prefix);
  67. }
  68. /*
  69. * Console Data Log
  70. */
  71. /* Data */
  72. static struct el_subpacket_handler *subpacket_handler_list = NULL;
  73. static struct el_subpacket_annotation *subpacket_annotation_list = NULL;
  74. static struct el_subpacket *
  75. el_process_header_subpacket(struct el_subpacket *header)
  76. {
  77. union el_timestamp timestamp;
  78. char *name = "UNKNOWN EVENT";
  79. int packet_count = 0;
  80. int length = 0;
  81. if (header->class != EL_CLASS__HEADER) {
  82. printk("%s** Unexpected header CLASS %d TYPE %d, aborting\n",
  83. err_print_prefix,
  84. header->class, header->type);
  85. return NULL;
  86. }
  87. switch(header->type) {
  88. case EL_TYPE__HEADER__SYSTEM_ERROR_FRAME:
  89. name = "SYSTEM ERROR";
  90. length = header->by_type.sys_err.frame_length;
  91. packet_count =
  92. header->by_type.sys_err.frame_packet_count;
  93. timestamp.as_int = 0;
  94. break;
  95. case EL_TYPE__HEADER__SYSTEM_EVENT_FRAME:
  96. name = "SYSTEM EVENT";
  97. length = header->by_type.sys_event.frame_length;
  98. packet_count =
  99. header->by_type.sys_event.frame_packet_count;
  100. timestamp = header->by_type.sys_event.timestamp;
  101. break;
  102. case EL_TYPE__HEADER__HALT_FRAME:
  103. name = "ERROR HALT";
  104. length = header->by_type.err_halt.frame_length;
  105. packet_count =
  106. header->by_type.err_halt.frame_packet_count;
  107. timestamp = header->by_type.err_halt.timestamp;
  108. break;
  109. case EL_TYPE__HEADER__LOGOUT_FRAME:
  110. name = "LOGOUT FRAME";
  111. length = header->by_type.logout_header.frame_length;
  112. packet_count = 1;
  113. timestamp.as_int = 0;
  114. break;
  115. default: /* Unknown */
  116. printk("%s** Unknown header - CLASS %d TYPE %d, aborting\n",
  117. err_print_prefix,
  118. header->class, header->type);
  119. return NULL;
  120. }
  121. printk("%s*** %s:\n"
  122. " CLASS %d, TYPE %d\n",
  123. err_print_prefix,
  124. name,
  125. header->class, header->type);
  126. el_print_timestamp(&timestamp);
  127. /*
  128. * Process the subpackets
  129. */
  130. el_process_subpackets(header, packet_count);
  131. /* return the next header */
  132. header = (struct el_subpacket *)
  133. ((unsigned long)header + header->length + length);
  134. return header;
  135. }
  136. static struct el_subpacket *
  137. el_process_subpacket_reg(struct el_subpacket *header)
  138. {
  139. struct el_subpacket *next = NULL;
  140. struct el_subpacket_handler *h = subpacket_handler_list;
  141. for (; h && h->class != header->class; h = h->next);
  142. if (h) next = h->handler(header);
  143. return next;
  144. }
  145. void
  146. el_print_timestamp(union el_timestamp *timestamp)
  147. {
  148. if (timestamp->as_int)
  149. printk("%s TIMESTAMP: %d/%d/%02d %d:%02d:%0d\n",
  150. err_print_prefix,
  151. timestamp->b.month, timestamp->b.day,
  152. timestamp->b.year, timestamp->b.hour,
  153. timestamp->b.minute, timestamp->b.second);
  154. }
  155. void
  156. el_process_subpackets(struct el_subpacket *header, int packet_count)
  157. {
  158. struct el_subpacket *subpacket;
  159. int i;
  160. subpacket = (struct el_subpacket *)
  161. ((unsigned long)header + header->length);
  162. for (i = 0; subpacket && i < packet_count; i++) {
  163. printk("%sPROCESSING SUBPACKET %d\n", err_print_prefix, i);
  164. subpacket = el_process_subpacket(subpacket);
  165. }
  166. }
  167. struct el_subpacket *
  168. el_process_subpacket(struct el_subpacket *header)
  169. {
  170. struct el_subpacket *next = NULL;
  171. switch(header->class) {
  172. case EL_CLASS__TERMINATION:
  173. /* Termination packet, there are no more */
  174. break;
  175. case EL_CLASS__HEADER:
  176. next = el_process_header_subpacket(header);
  177. break;
  178. default:
  179. if (NULL == (next = el_process_subpacket_reg(header))) {
  180. printk("%s** Unexpected header CLASS %d TYPE %d"
  181. " -- aborting.\n",
  182. err_print_prefix,
  183. header->class, header->type);
  184. }
  185. break;
  186. }
  187. return next;
  188. }
  189. void
  190. el_annotate_subpacket(struct el_subpacket *header)
  191. {
  192. struct el_subpacket_annotation *a;
  193. char **annotation = NULL;
  194. for (a = subpacket_annotation_list; a; a = a->next) {
  195. if (a->class == header->class &&
  196. a->type == header->type &&
  197. a->revision == header->revision) {
  198. /*
  199. * We found the annotation
  200. */
  201. annotation = a->annotation;
  202. printk("%s %s\n", err_print_prefix, a->description);
  203. break;
  204. }
  205. }
  206. mchk_dump_mem(header, header->length, annotation);
  207. }
  208. static void __init
  209. cdl_process_console_data_log(int cpu, struct percpu_struct *pcpu)
  210. {
  211. struct el_subpacket *header = (struct el_subpacket *)
  212. (IDENT_ADDR | pcpu->console_data_log_pa);
  213. int err;
  214. printk("%s******* CONSOLE DATA LOG FOR CPU %d. *******\n"
  215. "*** Error(s) were logged on a previous boot\n",
  216. err_print_prefix, cpu);
  217. for (err = 0; header && (header->class != EL_CLASS__TERMINATION); err++)
  218. header = el_process_subpacket(header);
  219. /* let the console know it's ok to clear the error(s) at restart */
  220. pcpu->console_data_log_pa = 0;
  221. printk("%s*** %d total error(s) logged\n"
  222. "**** END OF CONSOLE DATA LOG FOR CPU %d ****\n",
  223. err_print_prefix, err, cpu);
  224. }
  225. void __init
  226. cdl_check_console_data_log(void)
  227. {
  228. struct percpu_struct *pcpu;
  229. unsigned long cpu;
  230. for (cpu = 0; cpu < hwrpb->nr_processors; cpu++) {
  231. pcpu = (struct percpu_struct *)
  232. ((unsigned long)hwrpb + hwrpb->processor_offset
  233. + cpu * hwrpb->processor_size);
  234. if (pcpu->console_data_log_pa)
  235. cdl_process_console_data_log(cpu, pcpu);
  236. }
  237. }
  238. int __init
  239. cdl_register_subpacket_annotation(struct el_subpacket_annotation *new)
  240. {
  241. struct el_subpacket_annotation *a = subpacket_annotation_list;
  242. if (a == NULL) subpacket_annotation_list = new;
  243. else {
  244. for (; a->next != NULL; a = a->next) {
  245. if ((a->class == new->class && a->type == new->type) ||
  246. a == new) {
  247. printk("Attempted to re-register "
  248. "subpacket annotation\n");
  249. return -EINVAL;
  250. }
  251. }
  252. a->next = new;
  253. }
  254. new->next = NULL;
  255. return 0;
  256. }
  257. int __init
  258. cdl_register_subpacket_handler(struct el_subpacket_handler *new)
  259. {
  260. struct el_subpacket_handler *h = subpacket_handler_list;
  261. if (h == NULL) subpacket_handler_list = new;
  262. else {
  263. for (; h->next != NULL; h = h->next) {
  264. if (h->class == new->class || h == new) {
  265. printk("Attempted to re-register "
  266. "subpacket handler\n");
  267. return -EINVAL;
  268. }
  269. }
  270. h->next = new;
  271. }
  272. new->next = NULL;
  273. return 0;
  274. }