1 /* $NetBSD: dec_kn8ae.c,v 1.27 2001/08/20 12:20:04 wiz Exp $ */ 2 3 /* 4 * Copyright (c) 1997 by Matthew Jacob 5 * NASA AMES Research Center. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice immediately at the beginning of the file, without modification, 13 * this list of conditions, and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 34 35 __KERNEL_RCSID(0, "$NetBSD: dec_kn8ae.c,v 1.27 2001/08/20 12:20:04 wiz Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/device.h> 40 #include <sys/termios.h> 41 #include <dev/cons.h> 42 43 #include <machine/rpb.h> 44 #include <machine/autoconf.h> 45 #include <machine/conf.h> 46 #include <machine/frame.h> 47 #include <machine/alpha.h> 48 #include <machine/cpuconf.h> 49 #include <machine/logout.h> 50 51 #include <dev/ic/comreg.h> 52 #include <dev/ic/comvar.h> 53 54 #include <dev/isa/isavar.h> 55 #include <dev/pci/pcireg.h> 56 #include <dev/pci/pcivar.h> 57 58 #include <dev/scsipi/scsi_all.h> 59 #include <dev/scsipi/scsipi_all.h> 60 #include <dev/scsipi/scsiconf.h> 61 62 #include <alpha/tlsb/tlsbreg.h> 63 #include <alpha/tlsb/tlsbvar.h> 64 #include <alpha/tlsb/kftxxreg.h> 65 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr))) 66 67 68 void dec_kn8ae_init __P((void)); 69 void dec_kn8ae_cons_init __P((void)); 70 static void dec_kn8ae_device_register __P((struct device *, void *)); 71 72 static void dec_kn8ae_mcheck_handler 73 __P((unsigned long, struct trapframe *, unsigned long, unsigned long)); 74 75 const struct alpha_variation_table dec_kn8ae_variations[] = { 76 { 0, "AlphaServer 8400" }, 77 { 0, NULL }, 78 }; 79 80 void 81 dec_kn8ae_init() 82 { 83 u_int64_t variation; 84 85 platform.family = "AlphaServer 8400"; 86 87 if ((platform.model = alpha_dsr_sysname()) == NULL) { 88 variation = hwrpb->rpb_variation & SV_ST_MASK; 89 if ((platform.model = alpha_variation_name(variation, 90 dec_kn8ae_variations)) == NULL) 91 platform.model = alpha_unknown_sysname(); 92 } 93 94 platform.iobus = "tlsb"; 95 platform.cons_init = dec_kn8ae_cons_init; 96 platform.device_register = dec_kn8ae_device_register; 97 platform.mcheck_handler = dec_kn8ae_mcheck_handler; 98 } 99 100 void 101 dec_kn8ae_cons_init() 102 { 103 104 /* 105 * Info to retain: 106 * 107 * The AXP 8X00 seems to encode the 108 * type of console in the ctb_type field, 109 * not the ctb_term_type field. 110 * 111 * XXX Not Type 4 CTB? 112 */ 113 } 114 115 /* #define BDEBUG 1 */ 116 static void 117 dec_kn8ae_device_register(dev, aux) 118 struct device *dev; 119 void *aux; 120 { 121 static int found, initted, scsiboot, netboot; 122 static struct device *pcidev, *scsidev; 123 struct bootdev_data *b = bootdev_data; 124 struct device *parent = dev->dv_parent; 125 struct cfdata *cf = dev->dv_cfdata; 126 struct cfdriver *cd = cf->cf_driver; 127 128 if (found) 129 return; 130 131 if (!initted) { 132 scsiboot = (strcmp(b->protocol, "scsi") == 0); 133 netboot = (strcmp(b->protocol, "bootp") == 0) || 134 (strcmp(b->protocol, "mop") == 0); 135 #if BDEBUG 136 printf("proto:%s bus:%d slot:%d chan:%d", b->protocol, 137 b->bus, b->slot, b->channel); 138 if (b->remote_address) 139 printf(" remote_addr:%s", b->remote_address); 140 printf(" un:%d bdt:%d", b->unit, b->boot_dev_type); 141 if (b->ctrl_dev_type) 142 printf(" cdt:%s\n", b->ctrl_dev_type); 143 else 144 printf("\n"); 145 printf("scsiboot = %d, netboot = %d\n", scsiboot, netboot); 146 #endif 147 initted = 1; 148 } 149 150 if (pcidev == NULL) { 151 if (strcmp(cd->cd_name, "pci")) 152 return; 153 else { 154 struct pcibus_attach_args *pba = aux; 155 156 if ((b->slot / 1000) != pba->pba_bus) 157 return; 158 159 pcidev = dev; 160 #if BDEBUG 161 printf("\npcidev = %s\n", pcidev->dv_xname); 162 #endif 163 return; 164 } 165 } 166 167 if (scsiboot && (scsidev == NULL)) { 168 if (parent != pcidev) 169 return; 170 else { 171 struct pci_attach_args *pa = aux; 172 173 if ((b->slot % 1000) != pa->pa_device) 174 return; 175 176 /* XXX function? */ 177 178 scsidev = dev; 179 #if BDEBUG 180 printf("\nscsidev = %s\n", scsidev->dv_xname); 181 #endif 182 183 return; 184 } 185 } 186 187 if (scsiboot && 188 (!strcmp(cd->cd_name, "sd") || 189 !strcmp(cd->cd_name, "st") || 190 !strcmp(cd->cd_name, "cd"))) { 191 struct scsipibus_attach_args *sa = aux; 192 193 if (parent->dv_parent != scsidev) 194 return; 195 196 if (b->unit / 100 != sa->sa_periph->periph_target) 197 return; 198 199 /* XXX LUN! */ 200 201 /* 202 * the value in boot_dev_type is some weird number 203 * XXX: Only support SD booting for now. 204 */ 205 if (strcmp(cd->cd_name, "sd") && 206 strcmp(cd->cd_name, "cd") && 207 strcmp(cd->cd_name, "st")) 208 return; 209 210 /* we've found it! */ 211 booted_device = dev; 212 #if BDEBUG 213 printf("\nbooted_device = %s\n", booted_device->dv_xname); 214 #endif 215 found = 1; 216 } 217 218 if (netboot) { 219 if (parent != pcidev) 220 return; 221 else { 222 struct pci_attach_args *pa = aux; 223 224 if ((b->slot % 1000) != pa->pa_device) 225 return; 226 227 /* XXX function? */ 228 229 booted_device = dev; 230 #if BDEBUG 231 printf("\nbooted_device = %s\n", booted_device->dv_xname); 232 #endif 233 found = 1; 234 return; 235 } 236 } 237 } 238 239 /* 240 * KN8AE Machine Check Handlers. 241 */ 242 void kn8ae_harderr __P((unsigned long, unsigned long, 243 unsigned long, struct trapframe *)); 244 245 static void kn8ae_softerr __P((unsigned long, unsigned long, 246 unsigned long, struct trapframe *)); 247 248 void kn8ae_mcheck __P((unsigned long, unsigned long, 249 unsigned long, struct trapframe *)); 250 251 /* 252 * Support routine for clearing errors 253 */ 254 static void clear_tlsb_ebits __P((int)); 255 256 static void 257 clear_tlsb_ebits(cpuonly) 258 int cpuonly; 259 { 260 int node; 261 u_int32_t tldev; 262 263 for (node = 0; node <= TLSB_NODE_MAX; ++node) { 264 if ((tlsb_found & (1 << node)) == 0) 265 continue; 266 tldev = TLSB_GET_NODEREG(node, TLDEV); 267 if (tldev == 0) { 268 /* "cannot happen" */ 269 continue; 270 } 271 /* 272 * Registers to clear for all nodes. 273 */ 274 if (TLSB_GET_NODEREG(node, TLBER) & 275 (TLBER_UDE|TLBER_CWDE|TLBER_CRDE)) { 276 TLSB_PUT_NODEREG(node, TLESR0, 277 TLSB_GET_NODEREG(node, TLESR0)); 278 TLSB_PUT_NODEREG(node, TLESR1, 279 TLSB_GET_NODEREG(node, TLESR1)); 280 TLSB_PUT_NODEREG(node, TLESR2, 281 TLSB_GET_NODEREG(node, TLESR2)); 282 TLSB_PUT_NODEREG(node, TLESR3, 283 TLSB_GET_NODEREG(node, TLESR3)); 284 } 285 TLSB_PUT_NODEREG(node, TLBER, 286 TLSB_GET_NODEREG(node, TLBER)); 287 TLSB_PUT_NODEREG(node, TLFADR0, 288 TLSB_GET_NODEREG(node, TLFADR0)); 289 TLSB_PUT_NODEREG(node, TLFADR1, 290 TLSB_GET_NODEREG(node, TLFADR1)); 291 292 if (TLDEV_ISCPU(tldev)) { 293 TLSB_PUT_NODEREG(node, TLEPAERR, 294 TLSB_GET_NODEREG(node, TLEPAERR)); 295 TLSB_PUT_NODEREG(node, TLEPDERR, 296 TLSB_GET_NODEREG(node, TLEPDERR)); 297 TLSB_PUT_NODEREG(node, TLEPMERR, 298 TLSB_GET_NODEREG(node, TLEPMERR)); 299 continue; 300 } 301 /* 302 * If we're only doing CPU nodes, or this was a memory 303 * node, we're done. Onwards. 304 */ 305 if (cpuonly || TLDEV_ISMEM(tldev)) { 306 continue; 307 } 308 309 TLSB_PUT_NODEREG(node, KFT_ICCNSE, 310 TLSB_GET_NODEREG(node, KFT_ICCNSE)); 311 TLSB_PUT_NODEREG(node, KFT_IDPNSE0, 312 TLSB_GET_NODEREG(node, KFT_IDPNSE0)); 313 TLSB_PUT_NODEREG(node, KFT_IDPNSE1, 314 TLSB_GET_NODEREG(node, KFT_IDPNSE1)); 315 if (TLDEV_DTYPE(tldev) == TLDEV_DTYPE_KFTHA) { 316 TLSB_PUT_NODEREG(node, KFT_IDPNSE2, 317 TLSB_GET_NODEREG(node, KFT_IDPNSE2)); 318 TLSB_PUT_NODEREG(node, KFT_IDPNSE3, 319 TLSB_GET_NODEREG(node, KFT_IDPNSE3)); 320 } 321 /* 322 * Digital Unix cleares the Mailbox Transaction Register 323 * here. I don't think we should because we aren't using 324 * mailboxes yet, and the tech manual makes dire warnings 325 * about *not* rewriting this register. 326 */ 327 } 328 } 329 330 /* 331 * System Corrected Errors. 332 */ 333 static const char *fmt1 = " %-25s = 0x%l016x\n"; 334 335 void 336 kn8ae_harderr(mces, type, logout, framep) 337 unsigned long mces; 338 unsigned long type; 339 unsigned long logout; 340 struct trapframe *framep; 341 { 342 int whami, cpuwerr, dof_cnt; 343 mc_hdr_ev5 *hdr; 344 mc_cc_ev5 *mptr; 345 struct tlsb_mchk_fatal *ptr; 346 347 hdr = (mc_hdr_ev5 *) logout; 348 mptr = (mc_cc_ev5 *) (logout + sizeof (*hdr)); 349 ptr = (struct tlsb_mchk_fatal *) 350 (logout + sizeof (*hdr) + sizeof (*mptr)); 351 whami = alpha_pal_whami(); 352 353 printf("kn8ae: CPU ID %d system correctable error\n", whami); 354 355 printf(" Machine Check Code 0x%lx\n", hdr->mcheck_code); 356 printf(fmt1, "EI Status", mptr->ei_stat); 357 printf(fmt1, "EI Address", mptr->ei_addr); 358 printf(fmt1, "Fill Syndrome", mptr->fill_syndrome); 359 printf(fmt1, "Interrupt Status Reg.", mptr->isr); 360 printf("\n"); 361 dof_cnt = (ptr->rsvdheader & 0xffffffff00000000) >> 32; 362 cpuwerr = ptr->rsvdheader & 0xffff; 363 364 printf(fmt1, "CPU W/Error.", cpuwerr); 365 printf(fmt1, "DOF Count.", dof_cnt); 366 printf(fmt1, "TLDEV", ptr->tldev); 367 printf(fmt1, "TLSB Bus Error", ptr->tlber); 368 printf(fmt1, "TLSB CNR", ptr->tlcnr); 369 printf(fmt1, "TLSB VID", ptr->tlvid); 370 printf(fmt1, "TLSB Error Syndrome 0", ptr->tlesr0); 371 printf(fmt1, "TLSB Error Syndrome 1", ptr->tlesr1); 372 printf(fmt1, "TLSB Error Syndrome 2", ptr->tlesr2); 373 printf(fmt1, "TLSB Error Syndrome 3", ptr->tlesr3); 374 printf(fmt1, "TLSB LEP_AERR", ptr->tlepaerr); 375 printf(fmt1, "TLSB MODCONF", ptr->tlmodconfig); 376 printf(fmt1, "TLSB LEP_MERR", ptr->tlepmerr); 377 printf(fmt1, "TLSB LEP_DERR", ptr->tlepderr); 378 printf(fmt1, "TLSB INTRMASK0", ptr->tlintrmask0); 379 printf(fmt1, "TLSB INTRMASK1", ptr->tlintrmask1); 380 printf(fmt1, "TLSB INTRSUM0", ptr->tlintrsum0); 381 printf(fmt1, "TLSB INTRSUM1", ptr->tlintrsum1); 382 printf(fmt1, "TLSB VMG", ptr->tlep_vmg); 383 384 /* CLEAN UP */ 385 /* 386 * Here's what Digital Unix says to do- 387 * 388 * 1. Log the ECC error that got us here 389 * 390 * 2. Turn off error reporting 391 * 392 * 3. Attempt to have CPU read bad memory location (specified by the 393 * tlfadr reg of the TIOP or TMEM (depending on type of error, 394 * see upcoming code branches) and write data back to location. 395 * 396 * 4. When the CPU attempts to read the location, another 620 interrupt 397 * should occur for the cpu at which instant PAL will scrub the 398 * location. Then the o.s. scrub routine finishes. If the PAL scrubs 399 * the location then the scrubbed flag should be 0 (this is what we 400 * expect). 401 * 402 * If it's a 1 then the alpha_scrub_long routine did the scrub. 403 * 404 * 5. We renable correctable error logging and continue 405 */ 406 printf("WARNING THIS IS NOT DONE YET YOU MAY GET DATA CORRUPTION"); 407 clear_tlsb_ebits(0); 408 /* 409 * Clear error by rewriting register. 410 */ 411 alpha_pal_wrmces(mces); 412 } 413 414 /* 415 * Processor Corrected Errors- BCACHE ECC errors. 416 */ 417 418 static void 419 kn8ae_softerr(mces, type, logout, framep) 420 unsigned long mces; 421 unsigned long type; 422 unsigned long logout; 423 struct trapframe *framep; 424 { 425 int whami, cpuwerr, dof_cnt; 426 mc_hdr_ev5 *hdr; 427 mc_cc_ev5 *mptr; 428 struct tlsb_mchk_soft *ptr; 429 430 hdr = (mc_hdr_ev5 *) logout; 431 mptr = (mc_cc_ev5 *) (logout + sizeof (*hdr)); 432 ptr = (struct tlsb_mchk_soft *) 433 (logout + sizeof (*hdr) + sizeof (*mptr)); 434 whami = alpha_pal_whami(); 435 436 printf("kn8ae: CPU ID %d processor correctable error\n", whami); 437 printf(" Machine Check Code 0x%lx\n", hdr->mcheck_code); 438 printf(fmt1, "EI Status", mptr->ei_stat); 439 printf(fmt1, "EI Address", mptr->ei_addr); 440 printf(fmt1, "Fill Syndrome", mptr->fill_syndrome); 441 printf(fmt1, "Interrupt Status Reg.", mptr->isr); 442 printf("\n"); 443 dof_cnt = (ptr->rsvdheader & 0xffffffff00000000) >> 32; 444 cpuwerr = ptr->rsvdheader & 0xffff; 445 446 printf(fmt1, "CPU W/Error.", cpuwerr); 447 printf(fmt1, "DOF Count.", dof_cnt); 448 printf(fmt1, "TLDEV", ptr->tldev); 449 printf(fmt1, "TLSB Bus Error", ptr->tlber); 450 printf(fmt1, "TLSB Error Syndrome 0", ptr->tlesr0); 451 printf(fmt1, "TLSB Error Syndrome 1", ptr->tlesr1); 452 printf(fmt1, "TLSB Error Syndrome 2", ptr->tlesr2); 453 printf(fmt1, "TLSB Error Syndrome 3", ptr->tlesr3); 454 455 /* 456 * Clear TLSB bits on all CPU TLSB nodes. 457 */ 458 clear_tlsb_ebits(1); 459 460 /* 461 * Clear error by rewriting register. 462 */ 463 alpha_pal_wrmces(mces); 464 } 465 466 /* 467 * KN8AE specific machine check handler 468 */ 469 470 void 471 kn8ae_mcheck(mces, type, logout, framep) 472 unsigned long mces; 473 unsigned long type; 474 unsigned long logout; 475 struct trapframe *framep; 476 { 477 struct mchkinfo *mcp; 478 int get_dwlpx_regs; 479 struct tlsb_mchk_fatal mcs[TLSB_NODE_MAX+1], *ptr; 480 mc_hdr_ev5 *hdr; 481 mc_uc_ev5 *mptr; 482 483 /* 484 * If we expected a machine check, just go handle it in common code. 485 */ 486 mcp = &curcpu()->ci_mcinfo; 487 if (mcp->mc_expected) { 488 machine_check(mces, framep, type, logout); 489 return; 490 } 491 492 get_dwlpx_regs = 0; 493 ptr = NULL; 494 memset(mcs, 0, sizeof (mcs)); 495 496 hdr = (mc_hdr_ev5 *) logout; 497 mptr = (mc_uc_ev5 *) (logout + sizeof (*hdr)); 498 499 /* 500 * If detected by the system, we print out some TLASER registers. 501 */ 502 if (type == ALPHA_SYS_MCHECK) { 503 #if 0 504 int get_lsb_regs = 0; 505 int get_dwlpx_regs = 0; 506 #endif 507 508 ptr = (struct tlsb_mchk_fatal *) 509 (logout + sizeof (*hdr) + sizeof (*mptr)); 510 511 #if 0 512 if (ptr->tlepaerr & TLEPAERR_WSPC_RD) { 513 get_dwlpx_regs++; 514 } 515 if ((ptr->tlepaerr & TLEPAERR_IBOX_TMO) && 516 (mptr->ic_perr_stat & EV5_IC_PERR_IBOXTMO) && 517 (ptr->tlepderr & TLEPDERR_GBTMO)) { 518 get_dwlpx_regs++; 519 } 520 #endif 521 } else { 522 /* 523 * We have a processor machine check- which doesn't 524 * have information with it about any TLSB related 525 * failures. 526 */ 527 } 528 529 /* 530 * Now we can finally print some stuff... 531 */ 532 ev5_logout_print(hdr, mptr); 533 if (type == ALPHA_SYS_MCHECK) { 534 if (ptr->tlepaerr & TLEPAERR_WSPC_RD) { 535 printf("\tWSPC READ error\n"); 536 } 537 if ((ptr->tlepaerr & TLEPAERR_IBOX_TMO) && 538 (mptr->ic_perr_stat & EV5_IC_PERR_IBOXTMO) && 539 (ptr->tlepderr & TLEPDERR_GBTMO)) { 540 printf ("\tWSPC IBOX timeout detected\n"); 541 } 542 #ifdef DIAGNOSTIC 543 printf(fmt1, "TLDEV", ptr->tldev); 544 printf(fmt1, "TLSB Bus Error", ptr->tlber); 545 printf(fmt1, "TLSB CNR", ptr->tlcnr); 546 printf(fmt1, "TLSB VID", ptr->tlvid); 547 printf(fmt1, "TLSB Error Syndrome 0", ptr->tlesr0); 548 printf(fmt1, "TLSB Error Syndrome 1", ptr->tlesr1); 549 printf(fmt1, "TLSB Error Syndrome 2", ptr->tlesr2); 550 printf(fmt1, "TLSB Error Syndrome 3", ptr->tlesr3); 551 printf(fmt1, "TLSB LEP_AERR", ptr->tlepaerr); 552 printf(fmt1, "TLSB MODCONF", ptr->tlmodconfig); 553 printf(fmt1, "TLSB LEP_MERR", ptr->tlepmerr); 554 printf(fmt1, "TLSB LEP_DERR", ptr->tlepderr); 555 printf(fmt1, "TLSB INTRMASK0", ptr->tlintrmask0); 556 printf(fmt1, "TLSB INTRMASK1", ptr->tlintrmask1); 557 printf(fmt1, "TLSB INTRSUM0", ptr->tlintrsum0); 558 printf(fmt1, "TLSB INTRSUM1", ptr->tlintrsum1); 559 printf(fmt1, "TLSB VMG", ptr->tlep_vmg); 560 #endif 561 } else { 562 } 563 564 /* 565 * Now that we've printed all sorts of useful information 566 * and have decided that we really can't do any more to 567 * respond to the error, go on to the common code for 568 * final disposition. Usually this means that we die. 569 */ 570 clear_tlsb_ebits(0); 571 572 machine_check(mces, framep, type, logout); 573 } 574 575 static void 576 dec_kn8ae_mcheck_handler(mces, framep, vector, param) 577 unsigned long mces; 578 struct trapframe *framep; 579 unsigned long vector; 580 unsigned long param; 581 { 582 switch (vector) { 583 case ALPHA_SYS_ERROR: 584 kn8ae_harderr(mces, vector, param, framep); 585 break; 586 587 case ALPHA_PROC_ERROR: 588 kn8ae_softerr(mces, vector, param, framep); 589 break; 590 591 case ALPHA_SYS_MCHECK: 592 case ALPHA_PROC_MCHECK: 593 kn8ae_mcheck(mces, vector, param, framep); 594 break; 595 default: 596 printf("KN8AE_MCHECK: unknown check vector 0x%lx\n", vector); 597 machine_check(mces, framep, vector, param); 598 break; 599 } 600 } 601