ip27-nmi.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/mmzone.h>
  4. #include <linux/nodemask.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/smp.h>
  7. #include <linux/atomic.h>
  8. #include <asm/sn/types.h>
  9. #include <asm/sn/addrs.h>
  10. #include <asm/sn/nmi.h>
  11. #include <asm/sn/arch.h>
  12. #include <asm/sn/agent.h>
  13. #include "ip27-common.h"
  14. #if 0
  15. #define NODE_NUM_CPUS(n) CNODE_NUM_CPUS(n)
  16. #else
  17. #define NODE_NUM_CPUS(n) CPUS_PER_NODE
  18. #endif
  19. #define SEND_NMI(_nasid, _slice) \
  20. REMOTE_HUB_S((_nasid), (PI_NMI_A + ((_slice) * PI_NMI_OFFSET)), 1)
  21. typedef unsigned long machreg_t;
  22. static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  23. static void nmi_dump(void);
  24. void install_cpu_nmi_handler(int slice)
  25. {
  26. nmi_t *nmi_addr;
  27. nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
  28. if (nmi_addr->call_addr)
  29. return;
  30. nmi_addr->magic = NMI_MAGIC;
  31. nmi_addr->call_addr = (void *)nmi_dump;
  32. nmi_addr->call_addr_c =
  33. (void *)(~((unsigned long)(nmi_addr->call_addr)));
  34. nmi_addr->call_parm = 0;
  35. }
  36. /*
  37. * Copy the cpu registers which have been saved in the IP27prom format
  38. * into the eframe format for the node under consideration.
  39. */
  40. static void nmi_cpu_eframe_save(nasid_t nasid, int slice)
  41. {
  42. struct reg_struct *nr;
  43. int i;
  44. /* Get the pointer to the current cpu's register set. */
  45. nr = (struct reg_struct *)
  46. (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
  47. slice * IP27_NMI_KREGS_CPU_SIZE);
  48. pr_emerg("NMI nasid %d: slice %d\n", nasid, slice);
  49. /*
  50. * Saved main processor registers
  51. */
  52. for (i = 0; i < 32; ) {
  53. if ((i % 4) == 0)
  54. pr_emerg("$%2d :", i);
  55. pr_cont(" %016lx", nr->gpr[i]);
  56. i++;
  57. if ((i % 4) == 0)
  58. pr_cont("\n");
  59. }
  60. pr_emerg("Hi : (value lost)\n");
  61. pr_emerg("Lo : (value lost)\n");
  62. /*
  63. * Saved cp0 registers
  64. */
  65. pr_emerg("epc : %016lx %pS\n", nr->epc, (void *)nr->epc);
  66. pr_emerg("%s\n", print_tainted());
  67. pr_emerg("ErrEPC: %016lx %pS\n", nr->error_epc, (void *)nr->error_epc);
  68. pr_emerg("ra : %016lx %pS\n", nr->gpr[31], (void *)nr->gpr[31]);
  69. pr_emerg("Status: %08lx ", nr->sr);
  70. if (nr->sr & ST0_KX)
  71. pr_cont("KX ");
  72. if (nr->sr & ST0_SX)
  73. pr_cont("SX ");
  74. if (nr->sr & ST0_UX)
  75. pr_cont("UX ");
  76. switch (nr->sr & ST0_KSU) {
  77. case KSU_USER:
  78. pr_cont("USER ");
  79. break;
  80. case KSU_SUPERVISOR:
  81. pr_cont("SUPERVISOR ");
  82. break;
  83. case KSU_KERNEL:
  84. pr_cont("KERNEL ");
  85. break;
  86. default:
  87. pr_cont("BAD_MODE ");
  88. break;
  89. }
  90. if (nr->sr & ST0_ERL)
  91. pr_cont("ERL ");
  92. if (nr->sr & ST0_EXL)
  93. pr_cont("EXL ");
  94. if (nr->sr & ST0_IE)
  95. pr_cont("IE ");
  96. pr_cont("\n");
  97. pr_emerg("Cause : %08lx\n", nr->cause);
  98. pr_emerg("PrId : %08x\n", read_c0_prid());
  99. pr_emerg("BadVA : %016lx\n", nr->badva);
  100. pr_emerg("CErr : %016lx\n", nr->cache_err);
  101. pr_emerg("NMI_SR: %016lx\n", nr->nmi_sr);
  102. pr_emerg("\n");
  103. }
  104. static void nmi_dump_hub_irq(nasid_t nasid, int slice)
  105. {
  106. u64 mask0, mask1, pend0, pend1;
  107. if (slice == 0) { /* Slice A */
  108. mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
  109. mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
  110. } else { /* Slice B */
  111. mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
  112. mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
  113. }
  114. pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
  115. pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
  116. pr_emerg("PI_INT_MASK0: %16llx PI_INT_MASK1: %16llx\n", mask0, mask1);
  117. pr_emerg("PI_INT_PEND0: %16llx PI_INT_PEND1: %16llx\n", pend0, pend1);
  118. pr_emerg("\n\n");
  119. }
  120. /*
  121. * Copy the cpu registers which have been saved in the IP27prom format
  122. * into the eframe format for the node under consideration.
  123. */
  124. static void nmi_node_eframe_save(nasid_t nasid)
  125. {
  126. int slice;
  127. if (nasid == INVALID_NASID)
  128. return;
  129. /* Save the registers into eframe for each cpu */
  130. for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
  131. nmi_cpu_eframe_save(nasid, slice);
  132. nmi_dump_hub_irq(nasid, slice);
  133. }
  134. }
  135. /*
  136. * Save the nmi cpu registers for all cpus in the system.
  137. */
  138. static void nmi_eframes_save(void)
  139. {
  140. nasid_t nasid;
  141. for_each_online_node(nasid)
  142. nmi_node_eframe_save(nasid);
  143. }
  144. static void nmi_dump(void)
  145. {
  146. #ifndef REAL_NMI_SIGNAL
  147. static atomic_t nmied_cpus = ATOMIC_INIT(0);
  148. atomic_inc(&nmied_cpus);
  149. #endif
  150. /*
  151. * Only allow 1 cpu to proceed
  152. */
  153. arch_spin_lock(&nmi_lock);
  154. #ifdef REAL_NMI_SIGNAL
  155. /*
  156. * Wait up to 15 seconds for the other cpus to respond to the NMI.
  157. * If a cpu has not responded after 10 sec, send it 1 additional NMI.
  158. * This is for 2 reasons:
  159. * - sometimes a MMSC fail to NMI all cpus.
  160. * - on 512p SN0 system, the MMSC will only send NMIs to
  161. * half the cpus. Unfortunately, we don't know which cpus may be
  162. * NMIed - it depends on how the site chooses to configure.
  163. *
  164. * Note: it has been measure that it takes the MMSC up to 2.3 secs to
  165. * send NMIs to all cpus on a 256p system.
  166. */
  167. for (i=0; i < 1500; i++) {
  168. for_each_online_node(node)
  169. if (NODEPDA(node)->dump_count == 0)
  170. break;
  171. if (node == MAX_NUMNODES)
  172. break;
  173. if (i == 1000) {
  174. for_each_online_node(node)
  175. if (NODEPDA(node)->dump_count == 0) {
  176. cpu = cpumask_first(cpumask_of_node(node));
  177. for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
  178. CPUMASK_SETB(nmied_cpus, cpu);
  179. /*
  180. * cputonasid, cputoslice
  181. * needs kernel cpuid
  182. */
  183. SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
  184. }
  185. }
  186. }
  187. udelay(10000);
  188. }
  189. #else
  190. while (atomic_read(&nmied_cpus) != num_online_cpus());
  191. #endif
  192. /*
  193. * Save the nmi cpu registers for all cpu in the eframe format.
  194. */
  195. nmi_eframes_save();
  196. LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
  197. }