blob: 84889b57d5ff684e32bc2a1897583a0f4770853e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/kernel.h>
3#include <linux/mmzone.h>
4#include <linux/nodemask.h>
5#include <linux/spinlock.h>
6#include <linux/smp.h>
Arun Sharma600634972011-07-26 16:09:06 -07007#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/sn/types.h>
9#include <asm/sn/addrs.h>
10#include <asm/sn/nmi.h>
11#include <asm/sn/arch.h>
Thomas Bogendoerferb78e9d62020-01-09 13:33:40 +010012#include <asm/sn/agent.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
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
Thomas Bogendoerfer5388b5812020-01-09 13:33:41 +010020#define SEND_NMI(_nasid, _slice) \
21 REMOTE_HUB_S((_nasid), (PI_NMI_A + ((_slice) * PI_NMI_OFFSET)), 1)
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023typedef unsigned long machreg_t;
24
Ralf Baechle598c5ab2010-02-27 12:53:38 +010025static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
Ralf Baechle49397882016-05-22 00:39:18 +020028 * Let's see what else we need to do here. Set up sp, gp?
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
30void nmi_dump(void)
31{
32 void cont_nmi_dump(void);
33
34 cont_nmi_dump();
35}
36
37void install_cpu_nmi_handler(int slice)
38{
39 nmi_t *nmi_addr;
40
41 nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
42 if (nmi_addr->call_addr)
43 return;
44 nmi_addr->magic = NMI_MAGIC;
45 nmi_addr->call_addr = (void *)nmi_dump;
46 nmi_addr->call_addr_c =
47 (void *)(~((unsigned long)(nmi_addr->call_addr)));
48 nmi_addr->call_parm = 0;
49}
50
51/*
52 * Copy the cpu registers which have been saved in the IP27prom format
53 * into the eframe format for the node under consideration.
54 */
55
56void nmi_cpu_eframe_save(nasid_t nasid, int slice)
57{
58 struct reg_struct *nr;
Ralf Baechle70342282013-01-22 12:59:30 +010059 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /* Get the pointer to the current cpu's register set. */
62 nr = (struct reg_struct *)
63 (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
64 slice * IP27_NMI_KREGS_CPU_SIZE);
65
Thomas Bogendoerferab682802019-02-19 16:57:17 +010066 pr_emerg("NMI nasid %d: slice %d\n", nasid, slice);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 /*
69 * Saved main processor registers
70 */
71 for (i = 0; i < 32; ) {
72 if ((i % 4) == 0)
Thomas Bogendoerferab682802019-02-19 16:57:17 +010073 pr_emerg("$%2d :", i);
74 pr_cont(" %016lx", nr->gpr[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 i++;
77 if ((i % 4) == 0)
Thomas Bogendoerferab682802019-02-19 16:57:17 +010078 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 }
80
Thomas Bogendoerferab682802019-02-19 16:57:17 +010081 pr_emerg("Hi : (value lost)\n");
82 pr_emerg("Lo : (value lost)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 /*
85 * Saved cp0 registers
86 */
Thomas Bogendoerferab682802019-02-19 16:57:17 +010087 pr_emerg("epc : %016lx %pS\n", nr->epc, (void *)nr->epc);
88 pr_emerg("%s\n", print_tainted());
89 pr_emerg("ErrEPC: %016lx %pS\n", nr->error_epc, (void *)nr->error_epc);
90 pr_emerg("ra : %016lx %pS\n", nr->gpr[31], (void *)nr->gpr[31]);
91 pr_emerg("Status: %08lx ", nr->sr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 if (nr->sr & ST0_KX)
Thomas Bogendoerferab682802019-02-19 16:57:17 +010094 pr_cont("KX ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if (nr->sr & ST0_SX)
Thomas Bogendoerferab682802019-02-19 16:57:17 +010096 pr_cont("SX ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if (nr->sr & ST0_UX)
Thomas Bogendoerferab682802019-02-19 16:57:17 +010098 pr_cont("UX ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 switch (nr->sr & ST0_KSU) {
101 case KSU_USER:
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100102 pr_cont("USER ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 break;
104 case KSU_SUPERVISOR:
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100105 pr_cont("SUPERVISOR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 break;
107 case KSU_KERNEL:
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100108 pr_cont("KERNEL ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 break;
110 default:
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100111 pr_cont("BAD_MODE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 break;
113 }
114
115 if (nr->sr & ST0_ERL)
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100116 pr_cont("ERL ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (nr->sr & ST0_EXL)
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100118 pr_cont("EXL ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (nr->sr & ST0_IE)
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100120 pr_cont("IE ");
121 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100123 pr_emerg("Cause : %08lx\n", nr->cause);
124 pr_emerg("PrId : %08x\n", read_c0_prid());
125 pr_emerg("BadVA : %016lx\n", nr->badva);
126 pr_emerg("CErr : %016lx\n", nr->cache_err);
127 pr_emerg("NMI_SR: %016lx\n", nr->nmi_sr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100129 pr_emerg("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132void nmi_dump_hub_irq(nasid_t nasid, int slice)
133{
Thomas Bogendoerferdb0e7d42019-02-19 16:57:15 +0100134 u64 mask0, mask1, pend0, pend1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 if (slice == 0) { /* Slice A */
137 mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
138 mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
139 } else { /* Slice B */
140 mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
141 mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
142 }
143
144 pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
145 pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
146
Thomas Bogendoerferab682802019-02-19 16:57:17 +0100147 pr_emerg("PI_INT_MASK0: %16llx PI_INT_MASK1: %16llx\n", mask0, mask1);
148 pr_emerg("PI_INT_PEND0: %16llx PI_INT_PEND1: %16llx\n", pend0, pend1);
149 pr_emerg("\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
152/*
153 * Copy the cpu registers which have been saved in the IP27prom format
154 * into the eframe format for the node under consideration.
155 */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200156void nmi_node_eframe_save(nasid_t nasid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int slice;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (nasid == INVALID_NASID)
161 return;
162
163 /* Save the registers into eframe for each cpu */
164 for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
165 nmi_cpu_eframe_save(nasid, slice);
166 nmi_dump_hub_irq(nasid, slice);
167 }
168}
169
170/*
171 * Save the nmi cpu registers for all cpus in the system.
172 */
173void
174nmi_eframes_save(void)
175{
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200176 nasid_t nasid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200178 for_each_online_node(nasid)
179 nmi_node_eframe_save(nasid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
182void
183cont_nmi_dump(void)
184{
185#ifndef REAL_NMI_SIGNAL
186 static atomic_t nmied_cpus = ATOMIC_INIT(0);
187
188 atomic_inc(&nmied_cpus);
189#endif
190 /*
Ralf Baechle2ba53e32010-02-27 12:53:38 +0100191 * Only allow 1 cpu to proceed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 */
Ralf Baechle598c5ab2010-02-27 12:53:38 +0100193 arch_spin_lock(&nmi_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195#ifdef REAL_NMI_SIGNAL
196 /*
197 * Wait up to 15 seconds for the other cpus to respond to the NMI.
198 * If a cpu has not responded after 10 sec, send it 1 additional NMI.
199 * This is for 2 reasons:
200 * - sometimes a MMSC fail to NMI all cpus.
201 * - on 512p SN0 system, the MMSC will only send NMIs to
202 * half the cpus. Unfortunately, we don't know which cpus may be
203 * NMIed - it depends on how the site chooses to configure.
204 *
205 * Note: it has been measure that it takes the MMSC up to 2.3 secs to
206 * send NMIs to all cpus on a 256p system.
207 */
208 for (i=0; i < 1500; i++) {
209 for_each_online_node(node)
210 if (NODEPDA(node)->dump_count == 0)
211 break;
212 if (node == MAX_NUMNODES)
213 break;
214 if (i == 1000) {
215 for_each_online_node(node)
216 if (NODEPDA(node)->dump_count == 0) {
Rusty Russell0451fb22009-03-30 22:05:11 -0600217 cpu = cpumask_first(cpumask_of_node(node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
219 CPUMASK_SETB(nmied_cpus, cpu);
220 /*
221 * cputonasid, cputoslice
222 * needs kernel cpuid
223 */
224 SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
225 }
226 }
227
228 }
229 udelay(10000);
230 }
231#else
232 while (atomic_read(&nmied_cpus) != num_online_cpus());
233#endif
234
235 /*
236 * Save the nmi cpu registers for all cpu in the eframe format.
237 */
238 nmi_eframes_save();
239 LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
240}