xref: /linux/arch/mips/sgi-ip27/ip27-nmi.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
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>
12b78e9d63SThomas Bogendoerfer #include <asm/sn/agent.h>
131da177e4SLinus Torvalds 
14*f134bd1eSThomas Bogendoerfer #include "ip27-common.h"
15*f134bd1eSThomas Bogendoerfer 
161da177e4SLinus Torvalds #if 0
171da177e4SLinus Torvalds #define NODE_NUM_CPUS(n)	CNODE_NUM_CPUS(n)
181da177e4SLinus Torvalds #else
191da177e4SLinus Torvalds #define NODE_NUM_CPUS(n)	CPUS_PER_NODE
201da177e4SLinus Torvalds #endif
211da177e4SLinus Torvalds 
225388b581SThomas Bogendoerfer #define SEND_NMI(_nasid, _slice)	\
235388b581SThomas Bogendoerfer 	REMOTE_HUB_S((_nasid),  (PI_NMI_A + ((_slice) * PI_NMI_OFFSET)), 1)
245388b581SThomas Bogendoerfer 
251da177e4SLinus Torvalds typedef unsigned long machreg_t;
261da177e4SLinus Torvalds 
27598c5abaSRalf Baechle static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
28*f134bd1eSThomas Bogendoerfer static void nmi_dump(void);
291da177e4SLinus Torvalds 
install_cpu_nmi_handler(int slice)301da177e4SLinus Torvalds void install_cpu_nmi_handler(int slice)
311da177e4SLinus Torvalds {
321da177e4SLinus Torvalds 	nmi_t *nmi_addr;
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds 	nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice);
351da177e4SLinus Torvalds 	if (nmi_addr->call_addr)
361da177e4SLinus Torvalds 		return;
371da177e4SLinus Torvalds 	nmi_addr->magic = NMI_MAGIC;
381da177e4SLinus Torvalds 	nmi_addr->call_addr = (void *)nmi_dump;
391da177e4SLinus Torvalds 	nmi_addr->call_addr_c =
401da177e4SLinus Torvalds 		(void *)(~((unsigned long)(nmi_addr->call_addr)));
411da177e4SLinus Torvalds 	nmi_addr->call_parm = 0;
421da177e4SLinus Torvalds }
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds /*
451da177e4SLinus Torvalds  * Copy the cpu registers which have been saved in the IP27prom format
461da177e4SLinus Torvalds  * into the eframe format for the node under consideration.
471da177e4SLinus Torvalds  */
481da177e4SLinus Torvalds 
nmi_cpu_eframe_save(nasid_t nasid,int slice)49*f134bd1eSThomas Bogendoerfer static void nmi_cpu_eframe_save(nasid_t nasid, int slice)
501da177e4SLinus Torvalds {
511da177e4SLinus Torvalds 	struct reg_struct *nr;
521da177e4SLinus Torvalds 	int		i;
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds 	/* Get the pointer to the current cpu's register set. */
551da177e4SLinus Torvalds 	nr = (struct reg_struct *)
561da177e4SLinus Torvalds 		(TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) +
571da177e4SLinus Torvalds 		slice * IP27_NMI_KREGS_CPU_SIZE);
581da177e4SLinus Torvalds 
59ab68280eSThomas Bogendoerfer 	pr_emerg("NMI nasid %d: slice %d\n", nasid, slice);
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds 	/*
621da177e4SLinus Torvalds 	 * Saved main processor registers
631da177e4SLinus Torvalds 	 */
641da177e4SLinus Torvalds 	for (i = 0; i < 32; ) {
651da177e4SLinus Torvalds 		if ((i % 4) == 0)
66ab68280eSThomas Bogendoerfer 			pr_emerg("$%2d   :", i);
67ab68280eSThomas Bogendoerfer 		pr_cont(" %016lx", nr->gpr[i]);
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds 		i++;
701da177e4SLinus Torvalds 		if ((i % 4) == 0)
71ab68280eSThomas Bogendoerfer 			pr_cont("\n");
721da177e4SLinus Torvalds 	}
731da177e4SLinus Torvalds 
74ab68280eSThomas Bogendoerfer 	pr_emerg("Hi    : (value lost)\n");
75ab68280eSThomas Bogendoerfer 	pr_emerg("Lo    : (value lost)\n");
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds 	/*
781da177e4SLinus Torvalds 	 * Saved cp0 registers
791da177e4SLinus Torvalds 	 */
80ab68280eSThomas Bogendoerfer 	pr_emerg("epc   : %016lx %pS\n", nr->epc, (void *)nr->epc);
81ab68280eSThomas Bogendoerfer 	pr_emerg("%s\n", print_tainted());
82ab68280eSThomas Bogendoerfer 	pr_emerg("ErrEPC: %016lx %pS\n", nr->error_epc, (void *)nr->error_epc);
83ab68280eSThomas Bogendoerfer 	pr_emerg("ra    : %016lx %pS\n", nr->gpr[31], (void *)nr->gpr[31]);
84ab68280eSThomas Bogendoerfer 	pr_emerg("Status: %08lx	      ", nr->sr);
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds 	if (nr->sr & ST0_KX)
87ab68280eSThomas Bogendoerfer 		pr_cont("KX ");
881da177e4SLinus Torvalds 	if (nr->sr & ST0_SX)
89ab68280eSThomas Bogendoerfer 		pr_cont("SX ");
901da177e4SLinus Torvalds 	if (nr->sr & ST0_UX)
91ab68280eSThomas Bogendoerfer 		pr_cont("UX ");
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds 	switch (nr->sr & ST0_KSU) {
941da177e4SLinus Torvalds 	case KSU_USER:
95ab68280eSThomas Bogendoerfer 		pr_cont("USER ");
961da177e4SLinus Torvalds 		break;
971da177e4SLinus Torvalds 	case KSU_SUPERVISOR:
98ab68280eSThomas Bogendoerfer 		pr_cont("SUPERVISOR ");
991da177e4SLinus Torvalds 		break;
1001da177e4SLinus Torvalds 	case KSU_KERNEL:
101ab68280eSThomas Bogendoerfer 		pr_cont("KERNEL ");
1021da177e4SLinus Torvalds 		break;
1031da177e4SLinus Torvalds 	default:
104ab68280eSThomas Bogendoerfer 		pr_cont("BAD_MODE ");
1051da177e4SLinus Torvalds 		break;
1061da177e4SLinus Torvalds 	}
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds 	if (nr->sr & ST0_ERL)
109ab68280eSThomas Bogendoerfer 		pr_cont("ERL ");
1101da177e4SLinus Torvalds 	if (nr->sr & ST0_EXL)
111ab68280eSThomas Bogendoerfer 		pr_cont("EXL ");
1121da177e4SLinus Torvalds 	if (nr->sr & ST0_IE)
113ab68280eSThomas Bogendoerfer 		pr_cont("IE ");
114ab68280eSThomas Bogendoerfer 	pr_cont("\n");
1151da177e4SLinus Torvalds 
116ab68280eSThomas Bogendoerfer 	pr_emerg("Cause : %08lx\n", nr->cause);
117ab68280eSThomas Bogendoerfer 	pr_emerg("PrId  : %08x\n", read_c0_prid());
118ab68280eSThomas Bogendoerfer 	pr_emerg("BadVA : %016lx\n", nr->badva);
119ab68280eSThomas Bogendoerfer 	pr_emerg("CErr  : %016lx\n", nr->cache_err);
120ab68280eSThomas Bogendoerfer 	pr_emerg("NMI_SR: %016lx\n", nr->nmi_sr);
1211da177e4SLinus Torvalds 
122ab68280eSThomas Bogendoerfer 	pr_emerg("\n");
1231da177e4SLinus Torvalds }
1241da177e4SLinus Torvalds 
nmi_dump_hub_irq(nasid_t nasid,int slice)125*f134bd1eSThomas Bogendoerfer static void nmi_dump_hub_irq(nasid_t nasid, int slice)
1261da177e4SLinus Torvalds {
127db0e7d4eSThomas Bogendoerfer 	u64 mask0, mask1, pend0, pend1;
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds 	if (slice == 0) {				/* Slice A */
1301da177e4SLinus Torvalds 		mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A);
1311da177e4SLinus Torvalds 		mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A);
1321da177e4SLinus Torvalds 	} else {					/* Slice B */
1331da177e4SLinus Torvalds 		mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B);
1341da177e4SLinus Torvalds 		mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B);
1351da177e4SLinus Torvalds 	}
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds 	pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0);
1381da177e4SLinus Torvalds 	pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1);
1391da177e4SLinus Torvalds 
140ab68280eSThomas Bogendoerfer 	pr_emerg("PI_INT_MASK0: %16llx PI_INT_MASK1: %16llx\n", mask0, mask1);
141ab68280eSThomas Bogendoerfer 	pr_emerg("PI_INT_PEND0: %16llx PI_INT_PEND1: %16llx\n", pend0, pend1);
142ab68280eSThomas Bogendoerfer 	pr_emerg("\n\n");
1431da177e4SLinus Torvalds }
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds /*
1461da177e4SLinus Torvalds  * Copy the cpu registers which have been saved in the IP27prom format
1471da177e4SLinus Torvalds  * into the eframe format for the node under consideration.
1481da177e4SLinus Torvalds  */
nmi_node_eframe_save(nasid_t nasid)149*f134bd1eSThomas Bogendoerfer static void nmi_node_eframe_save(nasid_t nasid)
1501da177e4SLinus Torvalds {
1511da177e4SLinus Torvalds 	int slice;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	if (nasid == INVALID_NASID)
1541da177e4SLinus Torvalds 		return;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	/* Save the registers into eframe for each cpu */
1571da177e4SLinus Torvalds 	for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) {
1581da177e4SLinus Torvalds 		nmi_cpu_eframe_save(nasid, slice);
1591da177e4SLinus Torvalds 		nmi_dump_hub_irq(nasid, slice);
1601da177e4SLinus Torvalds 	}
1611da177e4SLinus Torvalds }
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds /*
1641da177e4SLinus Torvalds  * Save the nmi cpu registers for all cpus in the system.
1651da177e4SLinus Torvalds  */
nmi_eframes_save(void)166*f134bd1eSThomas Bogendoerfer static void nmi_eframes_save(void)
1671da177e4SLinus Torvalds {
1684bf841ebSThomas Bogendoerfer 	nasid_t nasid;
1691da177e4SLinus Torvalds 
1704bf841ebSThomas Bogendoerfer 	for_each_online_node(nasid)
1714bf841ebSThomas Bogendoerfer 		nmi_node_eframe_save(nasid);
1721da177e4SLinus Torvalds }
1731da177e4SLinus Torvalds 
nmi_dump(void)174*f134bd1eSThomas Bogendoerfer static void nmi_dump(void)
1751da177e4SLinus Torvalds {
1761da177e4SLinus Torvalds #ifndef REAL_NMI_SIGNAL
1771da177e4SLinus Torvalds 	static atomic_t nmied_cpus = ATOMIC_INIT(0);
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds 	atomic_inc(&nmied_cpus);
1801da177e4SLinus Torvalds #endif
1811da177e4SLinus Torvalds 	/*
1822ba53e37SRalf Baechle 	 * Only allow 1 cpu to proceed
1831da177e4SLinus Torvalds 	 */
184598c5abaSRalf Baechle 	arch_spin_lock(&nmi_lock);
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds #ifdef REAL_NMI_SIGNAL
1871da177e4SLinus Torvalds 	/*
1881da177e4SLinus Torvalds 	 * Wait up to 15 seconds for the other cpus to respond to the NMI.
1891da177e4SLinus Torvalds 	 * If a cpu has not responded after 10 sec, send it 1 additional NMI.
1901da177e4SLinus Torvalds 	 * This is for 2 reasons:
1911da177e4SLinus Torvalds 	 *	- sometimes a MMSC fail to NMI all cpus.
1921da177e4SLinus Torvalds 	 *	- on 512p SN0 system, the MMSC will only send NMIs to
1931da177e4SLinus Torvalds 	 *	  half the cpus. Unfortunately, we don't know which cpus may be
1941da177e4SLinus Torvalds 	 *	  NMIed - it depends on how the site chooses to configure.
1951da177e4SLinus Torvalds 	 *
1961da177e4SLinus Torvalds 	 * Note: it has been measure that it takes the MMSC up to 2.3 secs to
1971da177e4SLinus Torvalds 	 * send NMIs to all cpus on a 256p system.
1981da177e4SLinus Torvalds 	 */
1991da177e4SLinus Torvalds 	for (i=0; i < 1500; i++) {
2001da177e4SLinus Torvalds 		for_each_online_node(node)
2011da177e4SLinus Torvalds 			if (NODEPDA(node)->dump_count == 0)
2021da177e4SLinus Torvalds 				break;
2031da177e4SLinus Torvalds 		if (node == MAX_NUMNODES)
2041da177e4SLinus Torvalds 			break;
2051da177e4SLinus Torvalds 		if (i == 1000) {
2061da177e4SLinus Torvalds 			for_each_online_node(node)
2071da177e4SLinus Torvalds 				if (NODEPDA(node)->dump_count == 0) {
2080451fb2eSRusty Russell 					cpu = cpumask_first(cpumask_of_node(node));
2091da177e4SLinus Torvalds 					for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) {
2101da177e4SLinus Torvalds 						CPUMASK_SETB(nmied_cpus, cpu);
2111da177e4SLinus Torvalds 						/*
2121da177e4SLinus Torvalds 						 * cputonasid, cputoslice
2131da177e4SLinus Torvalds 						 * needs kernel cpuid
2141da177e4SLinus Torvalds 						 */
2151da177e4SLinus Torvalds 						SEND_NMI((cputonasid(cpu)), (cputoslice(cpu)));
2161da177e4SLinus Torvalds 					}
2171da177e4SLinus Torvalds 				}
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 		}
2201da177e4SLinus Torvalds 		udelay(10000);
2211da177e4SLinus Torvalds 	}
2221da177e4SLinus Torvalds #else
2231da177e4SLinus Torvalds 	while (atomic_read(&nmied_cpus) != num_online_cpus());
2241da177e4SLinus Torvalds #endif
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 	/*
2271da177e4SLinus Torvalds 	 * Save the nmi cpu registers for all cpu in the eframe format.
2281da177e4SLinus Torvalds 	 */
2291da177e4SLinus Torvalds 	nmi_eframes_save();
2301da177e4SLinus Torvalds 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
2311da177e4SLinus Torvalds }
232