xref: /linux/arch/mips/sgi-ip27/ip27-nmi.c (revision b78e9d63a3b6307b6b786e6ba189d3978b60ceb5)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds #include <linux/kernel.h>
31da177e4SLinus Torvalds #include <linux/mmzone.h>
41da177e4SLinus Torvalds #include <linux/nodemask.h>
51da177e4SLinus Torvalds #include <linux/spinlock.h>
61da177e4SLinus Torvalds #include <linux/smp.h>
760063497SArun Sharma #include <linux/atomic.h>
81da177e4SLinus Torvalds #include <asm/sn/types.h>
91da177e4SLinus Torvalds #include <asm/sn/addrs.h>
101da177e4SLinus Torvalds #include <asm/sn/nmi.h>
111da177e4SLinus Torvalds #include <asm/sn/arch.h>
12*b78e9d63SThomas Bogendoerfer #include <asm/sn/agent.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #if 0
151da177e4SLinus Torvalds #define NODE_NUM_CPUS(n)	CNODE_NUM_CPUS(n)
161da177e4SLinus Torvalds #else
171da177e4SLinus Torvalds #define NODE_NUM_CPUS(n)	CPUS_PER_NODE
181da177e4SLinus Torvalds #endif
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds typedef unsigned long machreg_t;
211da177e4SLinus Torvalds 
22598c5abaSRalf Baechle static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds /*
254939788eSRalf Baechle  * Let's see what else we need to do here. Set up sp, gp?
261da177e4SLinus Torvalds  */
271da177e4SLinus Torvalds void nmi_dump(void)
281da177e4SLinus Torvalds {
291da177e4SLinus Torvalds 	void cont_nmi_dump(void);
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds 	cont_nmi_dump();
321da177e4SLinus Torvalds }
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds void install_cpu_nmi_handler(int slice)
351da177e4SLinus Torvalds {
361da177e4SLinus Torvalds 	nmi_t *nmi_addr;
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds 	nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
391da177e4SLinus Torvalds 	if (nmi_addr->call_addr)
401da177e4SLinus Torvalds 		return;
411da177e4SLinus Torvalds 	nmi_addr->magic = NMI_MAGIC;
421da177e4SLinus Torvalds 	nmi_addr->call_addr = (void *)nmi_dump;
431da177e4SLinus Torvalds 	nmi_addr->call_addr_c =
441da177e4SLinus Torvalds 		(void *)(~((unsigned long)(nmi_addr->call_addr)));
451da177e4SLinus Torvalds 	nmi_addr->call_parm = 0;
461da177e4SLinus Torvalds }
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds /*
491da177e4SLinus Torvalds  * Copy the cpu registers which have been saved in the IP27prom format
501da177e4SLinus Torvalds  * into the eframe format for the node under consideration.
511da177e4SLinus Torvalds  */
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds void nmi_cpu_eframe_save(nasid_t nasid, int slice)
541da177e4SLinus Torvalds {
551da177e4SLinus Torvalds 	struct reg_struct *nr;
561da177e4SLinus Torvalds 	int		i;
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds 	/* Get the pointer to the current cpu's register set. */
591da177e4SLinus Torvalds 	nr = (struct reg_struct *)
601da177e4SLinus Torvalds 		(TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
611da177e4SLinus Torvalds 		slice * IP27_NMI_KREGS_CPU_SIZE);
621da177e4SLinus Torvalds 
63ab68280eSThomas Bogendoerfer 	pr_emerg("NMI nasid %d: slice %d\n", nasid, slice);
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	/*
661da177e4SLinus Torvalds 	 * Saved main processor registers
671da177e4SLinus Torvalds 	 */
681da177e4SLinus Torvalds 	for (i = 0; i < 32; ) {
691da177e4SLinus Torvalds 		if ((i % 4) == 0)
70ab68280eSThomas Bogendoerfer 			pr_emerg("$%2d   :", i);
71ab68280eSThomas Bogendoerfer 		pr_cont(" %016lx", nr->gpr[i]);
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 		i++;
741da177e4SLinus Torvalds 		if ((i % 4) == 0)
75ab68280eSThomas Bogendoerfer 			pr_cont("\n");
761da177e4SLinus Torvalds 	}
771da177e4SLinus Torvalds 
78ab68280eSThomas Bogendoerfer 	pr_emerg("Hi    : (value lost)\n");
79ab68280eSThomas Bogendoerfer 	pr_emerg("Lo    : (value lost)\n");
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds 	/*
821da177e4SLinus Torvalds 	 * Saved cp0 registers
831da177e4SLinus Torvalds 	 */
84ab68280eSThomas Bogendoerfer 	pr_emerg("epc   : %016lx %pS\n", nr->epc, (void *)nr->epc);
85ab68280eSThomas Bogendoerfer 	pr_emerg("%s\n", print_tainted());
86ab68280eSThomas Bogendoerfer 	pr_emerg("ErrEPC: %016lx %pS\n", nr->error_epc, (void *)nr->error_epc);
87ab68280eSThomas Bogendoerfer 	pr_emerg("ra    : %016lx %pS\n", nr->gpr[31], (void *)nr->gpr[31]);
88ab68280eSThomas Bogendoerfer 	pr_emerg("Status: %08lx	      ", nr->sr);
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds 	if (nr->sr & ST0_KX)
91ab68280eSThomas Bogendoerfer 		pr_cont("KX ");
921da177e4SLinus Torvalds 	if (nr->sr & ST0_SX)
93ab68280eSThomas Bogendoerfer 		pr_cont("SX ");
941da177e4SLinus Torvalds 	if (nr->sr & ST0_UX)
95ab68280eSThomas Bogendoerfer 		pr_cont("UX ");
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	switch (nr->sr & ST0_KSU) {
981da177e4SLinus Torvalds 	case KSU_USER:
99ab68280eSThomas Bogendoerfer 		pr_cont("USER ");
1001da177e4SLinus Torvalds 		break;
1011da177e4SLinus Torvalds 	case KSU_SUPERVISOR:
102ab68280eSThomas Bogendoerfer 		pr_cont("SUPERVISOR ");
1031da177e4SLinus Torvalds 		break;
1041da177e4SLinus Torvalds 	case KSU_KERNEL:
105ab68280eSThomas Bogendoerfer 		pr_cont("KERNEL ");
1061da177e4SLinus Torvalds 		break;
1071da177e4SLinus Torvalds 	default:
108ab68280eSThomas Bogendoerfer 		pr_cont("BAD_MODE ");
1091da177e4SLinus Torvalds 		break;
1101da177e4SLinus Torvalds 	}
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	if (nr->sr & ST0_ERL)
113ab68280eSThomas Bogendoerfer 		pr_cont("ERL ");
1141da177e4SLinus Torvalds 	if (nr->sr & ST0_EXL)
115ab68280eSThomas Bogendoerfer 		pr_cont("EXL ");
1161da177e4SLinus Torvalds 	if (nr->sr & ST0_IE)
117ab68280eSThomas Bogendoerfer 		pr_cont("IE ");
118ab68280eSThomas Bogendoerfer 	pr_cont("\n");
1191da177e4SLinus Torvalds 
120ab68280eSThomas Bogendoerfer 	pr_emerg("Cause : %08lx\n", nr->cause);
121ab68280eSThomas Bogendoerfer 	pr_emerg("PrId  : %08x\n", read_c0_prid());
122ab68280eSThomas Bogendoerfer 	pr_emerg("BadVA : %016lx\n", nr->badva);
123ab68280eSThomas Bogendoerfer 	pr_emerg("CErr  : %016lx\n", nr->cache_err);
124ab68280eSThomas Bogendoerfer 	pr_emerg("NMI_SR: %016lx\n", nr->nmi_sr);
1251da177e4SLinus Torvalds 
126ab68280eSThomas Bogendoerfer 	pr_emerg("\n");
1271da177e4SLinus Torvalds }
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds void nmi_dump_hub_irq(nasid_t nasid, int slice)
1301da177e4SLinus Torvalds {
131db0e7d4eSThomas Bogendoerfer 	u64 mask0, mask1, pend0, pend1;
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds 	if (slice == 0) {				/* Slice A */
1341da177e4SLinus Torvalds 		mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
1351da177e4SLinus Torvalds 		mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
1361da177e4SLinus Torvalds 	} else {					/* Slice B */
1371da177e4SLinus Torvalds 		mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
1381da177e4SLinus Torvalds 		mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
1391da177e4SLinus Torvalds 	}
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds 	pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
1421da177e4SLinus Torvalds 	pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
1431da177e4SLinus Torvalds 
144ab68280eSThomas Bogendoerfer 	pr_emerg("PI_INT_MASK0: %16llx PI_INT_MASK1: %16llx\n", mask0, mask1);
145ab68280eSThomas Bogendoerfer 	pr_emerg("PI_INT_PEND0: %16llx PI_INT_PEND1: %16llx\n", pend0, pend1);
146ab68280eSThomas Bogendoerfer 	pr_emerg("\n\n");
1471da177e4SLinus Torvalds }
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds /*
1501da177e4SLinus Torvalds  * Copy the cpu registers which have been saved in the IP27prom format
1511da177e4SLinus Torvalds  * into the eframe format for the node under consideration.
1521da177e4SLinus Torvalds  */
1534bf841ebSThomas Bogendoerfer void nmi_node_eframe_save(nasid_t nasid)
1541da177e4SLinus Torvalds {
1551da177e4SLinus Torvalds 	int slice;
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds 	if (nasid == INVALID_NASID)
1581da177e4SLinus Torvalds 		return;
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds 	/* Save the registers into eframe for each cpu */
1611da177e4SLinus Torvalds 	for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
1621da177e4SLinus Torvalds 		nmi_cpu_eframe_save(nasid, slice);
1631da177e4SLinus Torvalds 		nmi_dump_hub_irq(nasid, slice);
1641da177e4SLinus Torvalds 	}
1651da177e4SLinus Torvalds }
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds /*
1681da177e4SLinus Torvalds  * Save the nmi cpu registers for all cpus in the system.
1691da177e4SLinus Torvalds  */
1701da177e4SLinus Torvalds void
1711da177e4SLinus Torvalds nmi_eframes_save(void)
1721da177e4SLinus Torvalds {
1734bf841ebSThomas Bogendoerfer 	nasid_t nasid;
1741da177e4SLinus Torvalds 
1754bf841ebSThomas Bogendoerfer 	for_each_online_node(nasid)
1764bf841ebSThomas Bogendoerfer 		nmi_node_eframe_save(nasid);
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds void
1801da177e4SLinus Torvalds cont_nmi_dump(void)
1811da177e4SLinus Torvalds {
1821da177e4SLinus Torvalds #ifndef REAL_NMI_SIGNAL
1831da177e4SLinus Torvalds 	static atomic_t nmied_cpus = ATOMIC_INIT(0);
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds 	atomic_inc(&nmied_cpus);
1861da177e4SLinus Torvalds #endif
1871da177e4SLinus Torvalds 	/*
1882ba53e37SRalf Baechle 	 * Only allow 1 cpu to proceed
1891da177e4SLinus Torvalds 	 */
190598c5abaSRalf Baechle 	arch_spin_lock(&nmi_lock);
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds #ifdef REAL_NMI_SIGNAL
1931da177e4SLinus Torvalds 	/*
1941da177e4SLinus Torvalds 	 * Wait up to 15 seconds for the other cpus to respond to the NMI.
1951da177e4SLinus Torvalds 	 * If a cpu has not responded after 10 sec, send it 1 additional NMI.
1961da177e4SLinus Torvalds 	 * This is for 2 reasons:
1971da177e4SLinus Torvalds 	 *	- sometimes a MMSC fail to NMI all cpus.
1981da177e4SLinus Torvalds 	 *	- on 512p SN0 system, the MMSC will only send NMIs to
1991da177e4SLinus Torvalds 	 *	  half the cpus. Unfortunately, we don't know which cpus may be
2001da177e4SLinus Torvalds 	 *	  NMIed - it depends on how the site chooses to configure.
2011da177e4SLinus Torvalds 	 *
2021da177e4SLinus Torvalds 	 * Note: it has been measure that it takes the MMSC up to 2.3 secs to
2031da177e4SLinus Torvalds 	 * send NMIs to all cpus on a 256p system.
2041da177e4SLinus Torvalds 	 */
2051da177e4SLinus Torvalds 	for (i=0; i < 1500; i++) {
2061da177e4SLinus Torvalds 		for_each_online_node(node)
2071da177e4SLinus Torvalds 			if (NODEPDA(node)->dump_count == 0)
2081da177e4SLinus Torvalds 				break;
2091da177e4SLinus Torvalds 		if (node == MAX_NUMNODES)
2101da177e4SLinus Torvalds 			break;
2111da177e4SLinus Torvalds 		if (i == 1000) {
2121da177e4SLinus Torvalds 			for_each_online_node(node)
2131da177e4SLinus Torvalds 				if (NODEPDA(node)->dump_count == 0) {
2140451fb2eSRusty Russell 					cpu = cpumask_first(cpumask_of_node(node));
2151da177e4SLinus Torvalds 					for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
2161da177e4SLinus Torvalds 						CPUMASK_SETB(nmied_cpus, cpu);
2171da177e4SLinus Torvalds 						/*
2181da177e4SLinus Torvalds 						 * cputonasid, cputoslice
2191da177e4SLinus Torvalds 						 * needs kernel cpuid
2201da177e4SLinus Torvalds 						 */
2211da177e4SLinus Torvalds 						SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
2221da177e4SLinus Torvalds 					}
2231da177e4SLinus Torvalds 				}
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds 		}
2261da177e4SLinus Torvalds 		udelay(10000);
2271da177e4SLinus Torvalds 	}
2281da177e4SLinus Torvalds #else
2291da177e4SLinus Torvalds 	while (atomic_read(&nmied_cpus) != num_online_cpus());
2301da177e4SLinus Torvalds #endif
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds 	/*
2331da177e4SLinus Torvalds 	 * Save the nmi cpu registers for all cpu in the eframe format.
2341da177e4SLinus Torvalds 	 */
2351da177e4SLinus Torvalds 	nmi_eframes_save();
2361da177e4SLinus Torvalds 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
2371da177e4SLinus Torvalds }
238