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> 121da177e4SLinus Torvalds #include <asm/sn/sn0/hub.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 #define CNODEID_NONE (cnodeid_t)-1 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds typedef unsigned long machreg_t; 231da177e4SLinus Torvalds 24598c5abaSRalf Baechle static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED; 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds /* 274939788eSRalf Baechle * Let's see what else we need to do here. Set up sp, gp? 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds void nmi_dump(void) 301da177e4SLinus Torvalds { 311da177e4SLinus Torvalds void cont_nmi_dump(void); 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds cont_nmi_dump(); 341da177e4SLinus Torvalds } 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds void install_cpu_nmi_handler(int slice) 371da177e4SLinus Torvalds { 381da177e4SLinus Torvalds nmi_t *nmi_addr; 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds nmi_addr = (nmi_t *)NMI_ADDR(get_nasid(), slice); 411da177e4SLinus Torvalds if (nmi_addr->call_addr) 421da177e4SLinus Torvalds return; 431da177e4SLinus Torvalds nmi_addr->magic = NMI_MAGIC; 441da177e4SLinus Torvalds nmi_addr->call_addr = (void *)nmi_dump; 451da177e4SLinus Torvalds nmi_addr->call_addr_c = 461da177e4SLinus Torvalds (void *)(~((unsigned long)(nmi_addr->call_addr))); 471da177e4SLinus Torvalds nmi_addr->call_parm = 0; 481da177e4SLinus Torvalds } 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds /* 511da177e4SLinus Torvalds * Copy the cpu registers which have been saved in the IP27prom format 521da177e4SLinus Torvalds * into the eframe format for the node under consideration. 531da177e4SLinus Torvalds */ 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds void nmi_cpu_eframe_save(nasid_t nasid, int slice) 561da177e4SLinus Torvalds { 571da177e4SLinus Torvalds struct reg_struct *nr; 581da177e4SLinus Torvalds int i; 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* Get the pointer to the current cpu's register set. */ 611da177e4SLinus Torvalds nr = (struct reg_struct *) 621da177e4SLinus Torvalds (TO_UNCAC(TO_NODE(nasid, IP27_NMI_KREGS_OFFSET)) + 631da177e4SLinus Torvalds slice * IP27_NMI_KREGS_CPU_SIZE); 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds printk("NMI nasid %d: slice %d\n", nasid, slice); 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* 681da177e4SLinus Torvalds * Saved main processor registers 691da177e4SLinus Torvalds */ 701da177e4SLinus Torvalds for (i = 0; i < 32; ) { 711da177e4SLinus Torvalds if ((i % 4) == 0) 721da177e4SLinus Torvalds printk("$%2d :", i); 731da177e4SLinus Torvalds printk(" %016lx", nr->gpr[i]); 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds i++; 761da177e4SLinus Torvalds if ((i % 4) == 0) 771da177e4SLinus Torvalds printk("\n"); 781da177e4SLinus Torvalds } 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds printk("Hi : (value lost)\n"); 811da177e4SLinus Torvalds printk("Lo : (value lost)\n"); 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* 841da177e4SLinus Torvalds * Saved cp0 registers 851da177e4SLinus Torvalds */ 86b012cffeSRalf Baechle printk("epc : %016lx %pS\n", nr->epc, (void *) nr->epc); 871da177e4SLinus Torvalds printk("%s\n", print_tainted()); 88b012cffeSRalf Baechle printk("ErrEPC: %016lx %pS\n", nr->error_epc, (void *) nr->error_epc); 89b012cffeSRalf Baechle printk("ra : %016lx %pS\n", nr->gpr[31], (void *) nr->gpr[31]); 901da177e4SLinus Torvalds printk("Status: %08lx ", nr->sr); 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds if (nr->sr & ST0_KX) 931da177e4SLinus Torvalds printk("KX "); 941da177e4SLinus Torvalds if (nr->sr & ST0_SX) 951da177e4SLinus Torvalds printk("SX "); 961da177e4SLinus Torvalds if (nr->sr & ST0_UX) 971da177e4SLinus Torvalds printk("UX "); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds switch (nr->sr & ST0_KSU) { 1001da177e4SLinus Torvalds case KSU_USER: 1011da177e4SLinus Torvalds printk("USER "); 1021da177e4SLinus Torvalds break; 1031da177e4SLinus Torvalds case KSU_SUPERVISOR: 1041da177e4SLinus Torvalds printk("SUPERVISOR "); 1051da177e4SLinus Torvalds break; 1061da177e4SLinus Torvalds case KSU_KERNEL: 1071da177e4SLinus Torvalds printk("KERNEL "); 1081da177e4SLinus Torvalds break; 1091da177e4SLinus Torvalds default: 1101da177e4SLinus Torvalds printk("BAD_MODE "); 1111da177e4SLinus Torvalds break; 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds if (nr->sr & ST0_ERL) 1151da177e4SLinus Torvalds printk("ERL "); 1161da177e4SLinus Torvalds if (nr->sr & ST0_EXL) 1171da177e4SLinus Torvalds printk("EXL "); 1181da177e4SLinus Torvalds if (nr->sr & ST0_IE) 1191da177e4SLinus Torvalds printk("IE "); 1201da177e4SLinus Torvalds printk("\n"); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds printk("Cause : %08lx\n", nr->cause); 1231da177e4SLinus Torvalds printk("PrId : %08x\n", read_c0_prid()); 1241da177e4SLinus Torvalds printk("BadVA : %016lx\n", nr->badva); 1251da177e4SLinus Torvalds printk("CErr : %016lx\n", nr->cache_err); 1261da177e4SLinus Torvalds printk("NMI_SR: %016lx\n", nr->nmi_sr); 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds printk("\n"); 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds void nmi_dump_hub_irq(nasid_t nasid, int slice) 1321da177e4SLinus Torvalds { 133*db0e7d4eSThomas Bogendoerfer u64 mask0, mask1, pend0, pend1; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds if (slice == 0) { /* Slice A */ 1361da177e4SLinus Torvalds mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_A); 1371da177e4SLinus Torvalds mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_A); 1381da177e4SLinus Torvalds } else { /* Slice B */ 1391da177e4SLinus Torvalds mask0 = REMOTE_HUB_L(nasid, PI_INT_MASK0_B); 1401da177e4SLinus Torvalds mask1 = REMOTE_HUB_L(nasid, PI_INT_MASK1_B); 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds pend0 = REMOTE_HUB_L(nasid, PI_INT_PEND0); 1441da177e4SLinus Torvalds pend1 = REMOTE_HUB_L(nasid, PI_INT_PEND1); 1451da177e4SLinus Torvalds 14612e22e8eSRalf Baechle printk("PI_INT_MASK0: %16Lx PI_INT_MASK1: %16Lx\n", mask0, mask1); 14712e22e8eSRalf Baechle printk("PI_INT_PEND0: %16Lx PI_INT_PEND1: %16Lx\n", pend0, pend1); 1481da177e4SLinus Torvalds printk("\n\n"); 1491da177e4SLinus Torvalds } 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds /* 1521da177e4SLinus Torvalds * Copy the cpu registers which have been saved in the IP27prom format 1531da177e4SLinus Torvalds * into the eframe format for the node under consideration. 1541da177e4SLinus Torvalds */ 1551da177e4SLinus Torvalds void nmi_node_eframe_save(cnodeid_t cnode) 1561da177e4SLinus Torvalds { 1571da177e4SLinus Torvalds nasid_t nasid; 1581da177e4SLinus Torvalds int slice; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds /* Make sure that we have a valid node */ 1611da177e4SLinus Torvalds if (cnode == CNODEID_NONE) 1621da177e4SLinus Torvalds return; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds nasid = COMPACT_TO_NASID_NODEID(cnode); 1651da177e4SLinus Torvalds if (nasid == INVALID_NASID) 1661da177e4SLinus Torvalds return; 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* Save the registers into eframe for each cpu */ 1691da177e4SLinus Torvalds for (slice = 0; slice < NODE_NUM_CPUS(slice); slice++) { 1701da177e4SLinus Torvalds nmi_cpu_eframe_save(nasid, slice); 1711da177e4SLinus Torvalds nmi_dump_hub_irq(nasid, slice); 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds /* 1761da177e4SLinus Torvalds * Save the nmi cpu registers for all cpus in the system. 1771da177e4SLinus Torvalds */ 1781da177e4SLinus Torvalds void 1791da177e4SLinus Torvalds nmi_eframes_save(void) 1801da177e4SLinus Torvalds { 1811da177e4SLinus Torvalds cnodeid_t cnode; 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds for_each_online_node(cnode) 1841da177e4SLinus Torvalds nmi_node_eframe_save(cnode); 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds void 1881da177e4SLinus Torvalds cont_nmi_dump(void) 1891da177e4SLinus Torvalds { 1901da177e4SLinus Torvalds #ifndef REAL_NMI_SIGNAL 1911da177e4SLinus Torvalds static atomic_t nmied_cpus = ATOMIC_INIT(0); 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds atomic_inc(&nmied_cpus); 1941da177e4SLinus Torvalds #endif 1951da177e4SLinus Torvalds /* 1962ba53e37SRalf Baechle * Only allow 1 cpu to proceed 1971da177e4SLinus Torvalds */ 198598c5abaSRalf Baechle arch_spin_lock(&nmi_lock); 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds #ifdef REAL_NMI_SIGNAL 2011da177e4SLinus Torvalds /* 2021da177e4SLinus Torvalds * Wait up to 15 seconds for the other cpus to respond to the NMI. 2031da177e4SLinus Torvalds * If a cpu has not responded after 10 sec, send it 1 additional NMI. 2041da177e4SLinus Torvalds * This is for 2 reasons: 2051da177e4SLinus Torvalds * - sometimes a MMSC fail to NMI all cpus. 2061da177e4SLinus Torvalds * - on 512p SN0 system, the MMSC will only send NMIs to 2071da177e4SLinus Torvalds * half the cpus. Unfortunately, we don't know which cpus may be 2081da177e4SLinus Torvalds * NMIed - it depends on how the site chooses to configure. 2091da177e4SLinus Torvalds * 2101da177e4SLinus Torvalds * Note: it has been measure that it takes the MMSC up to 2.3 secs to 2111da177e4SLinus Torvalds * send NMIs to all cpus on a 256p system. 2121da177e4SLinus Torvalds */ 2131da177e4SLinus Torvalds for (i=0; i < 1500; i++) { 2141da177e4SLinus Torvalds for_each_online_node(node) 2151da177e4SLinus Torvalds if (NODEPDA(node)->dump_count == 0) 2161da177e4SLinus Torvalds break; 2171da177e4SLinus Torvalds if (node == MAX_NUMNODES) 2181da177e4SLinus Torvalds break; 2191da177e4SLinus Torvalds if (i == 1000) { 2201da177e4SLinus Torvalds for_each_online_node(node) 2211da177e4SLinus Torvalds if (NODEPDA(node)->dump_count == 0) { 2220451fb2eSRusty Russell cpu = cpumask_first(cpumask_of_node(node)); 2231da177e4SLinus Torvalds for (n=0; n < CNODE_NUM_CPUS(node); cpu++, n++) { 2241da177e4SLinus Torvalds CPUMASK_SETB(nmied_cpus, cpu); 2251da177e4SLinus Torvalds /* 2261da177e4SLinus Torvalds * cputonasid, cputoslice 2271da177e4SLinus Torvalds * needs kernel cpuid 2281da177e4SLinus Torvalds */ 2291da177e4SLinus Torvalds SEND_NMI((cputonasid(cpu)), (cputoslice(cpu))); 2301da177e4SLinus Torvalds } 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds } 2341da177e4SLinus Torvalds udelay(10000); 2351da177e4SLinus Torvalds } 2361da177e4SLinus Torvalds #else 2371da177e4SLinus Torvalds while (atomic_read(&nmied_cpus) != num_online_cpus()); 2381da177e4SLinus Torvalds #endif 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds /* 2411da177e4SLinus Torvalds * Save the nmi cpu registers for all cpu in the eframe format. 2421da177e4SLinus Torvalds */ 2431da177e4SLinus Torvalds nmi_eframes_save(); 2441da177e4SLinus Torvalds LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET); 2451da177e4SLinus Torvalds } 246