1 /* 2 * Product specific probe and attach routines for: 3 * aic7901 and aic7902 SCSI controllers 4 * 5 * Copyright (c) 1994-2001 Justin T. Gibbs. 6 * Copyright (c) 2000-2002 Adaptec Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions, and the following disclaimer, 14 * without modification. 15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 16 * substantially similar to the "NO WARRANTY" disclaimer below 17 * ("Disclaimer") and any redistribution must be conditioned upon 18 * including a substantially similar Disclaimer requirement for further 19 * binary redistribution. 20 * 3. Neither the names of the above-listed copyright holders nor the names 21 * of any contributors may be used to endorse or promote products derived 22 * from this software without specific prior written permission. 23 * 24 * Alternatively, this software may be distributed under the terms of the 25 * GNU General Public License ("GPL") version 2 as published by the Free 26 * Software Foundation. 27 * 28 * NO WARRANTY 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 38 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 * POSSIBILITY OF SUCH DAMAGES. 40 * 41 * $Id: //depot/aic7xxx/aic7xxx/aic79xx_pci.c#66 $ 42 * 43 * $FreeBSD$ 44 */ 45 46 #ifdef __linux__ 47 #include "aic79xx_osm.h" 48 #include "aic79xx_inline.h" 49 #else 50 #include <dev/aic7xxx/aic79xx_osm.h> 51 #include <dev/aic7xxx/aic79xx_inline.h> 52 #endif 53 54 static __inline uint64_t 55 ahd_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor) 56 { 57 uint64_t id; 58 59 id = subvendor 60 | (subdevice << 16) 61 | ((uint64_t)vendor << 32) 62 | ((uint64_t)device << 48); 63 64 return (id); 65 } 66 67 #define ID_ALL_MASK 0xFFFFFFFFFFFFFFFFull 68 #define ID_DEV_VENDOR_MASK 0xFFFFFFFF00000000ull 69 #define ID_9005_GENERIC_MASK 0xFFF0FFFF00000000ull 70 71 #define ID_AIC7901 0x800F9005FFFF9005ull 72 #define ID_AIC7901A 0x801E9005FFFF9005ull 73 #define ID_AIC7901A_IROC 0x809E9005FFFF9005ull 74 #define ID_AHA_29320A 0x8000900500609005ull 75 #define ID_AHA_29320LP 0x8014900500449005ull 76 #define ID_AHA_29320LP_IROC 0x8094900500449005ull 77 78 #define ID_AIC7902 0x801F9005FFFF9005ull 79 #define ID_AIC7902_IROC 0x809F9005FFFF9005ull 80 #define ID_AIC7902_B 0x801D9005FFFF9005ull 81 #define ID_AIC7902_B_IROC 0x809D9005FFFF9005ull 82 #define ID_AHA_39320 0x8010900500409005ull 83 #define ID_AHA_39320A 0x8016900500409005ull 84 #define ID_AHA_39320D 0x8011900500419005ull 85 #define ID_AHA_39320D_B 0x801C900500419005ull 86 #define ID_AHA_39320D_HP 0x8011900500AC0E11ull 87 #define ID_AHA_39320D_B_HP 0x801C900500AC0E11ull 88 #define ID_AHA_29320 0x8012900500429005ull 89 #define ID_AHA_29320B 0x8013900500439005ull 90 #define ID_AIC7902_PCI_REV_A4 0x3 91 #define ID_AIC7902_PCI_REV_B0 0x10 92 #define SUBID_HP 0x0E11 93 94 #define DEVID_9005_TYPE(id) ((id) & 0xF) 95 #define DEVID_9005_TYPE_HBA 0x0 /* Standard Card */ 96 #define DEVID_9005_TYPE_HBA_2EXT 0x1 /* 2 External Ports */ 97 #define DEVID_9005_TYPE_IROC 0x8 /* Raid(0,1,10) Card */ 98 #define DEVID_9005_TYPE_MB 0xF /* On Motherboard */ 99 100 #define DEVID_9005_MFUNC(id) ((id) & 0x10) 101 102 #define DEVID_9005_PACKETIZED(id) ((id) & 0x8000) 103 104 #define SUBID_9005_TYPE(id) ((id) & 0xF) 105 #define SUBID_9005_TYPE_HBA 0x0 /* Standard Card */ 106 #define SUBID_9005_TYPE_MB 0xF /* On Motherboard */ 107 108 #define SUBID_9005_AUTOTERM(id) (((id) & 0x10) == 0) 109 110 #define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20) 111 112 #define SUBID_9005_SEEPTYPE(id) ((id) & 0x0C0) >> 6) 113 #define SUBID_9005_SEEPTYPE_NONE 0x0 114 #define SUBID_9005_SEEPTYPE_4K 0x1 115 116 static ahd_device_setup_t ahd_aic7901A_setup; 117 static ahd_device_setup_t ahd_aic7902_setup; 118 119 struct ahd_pci_identity ahd_pci_ident_table [] = 120 { 121 /* aic7901A based controllers */ 122 { 123 ID_AHA_29320LP, 124 ID_ALL_MASK, 125 "Adaptec 29320LP Ultra320 SCSI adapter", 126 ahd_aic7901A_setup 127 }, 128 { 129 ID_AHA_29320A, 130 ID_ALL_MASK, 131 "Adaptec 29320A Ultra320 SCSI adapter", 132 ahd_aic7901A_setup 133 }, 134 /* aic7902 based controllers */ 135 { 136 ID_AHA_39320, 137 ID_ALL_MASK, 138 "Adaptec 39320 Ultra320 SCSI adapter", 139 ahd_aic7902_setup 140 }, 141 { 142 ID_AHA_39320A, 143 ID_ALL_MASK, 144 "Adaptec 39320A Ultra320 SCSI adapter", 145 ahd_aic7902_setup 146 }, 147 { 148 ID_AHA_39320D, 149 ID_ALL_MASK, 150 "Adaptec 39320D Ultra320 SCSI adapter", 151 ahd_aic7902_setup 152 }, 153 { 154 ID_AHA_39320D_HP, 155 ID_ALL_MASK, 156 "Adaptec (HP OEM) 39320D Ultra320 SCSI adapter", 157 ahd_aic7902_setup 158 }, 159 { 160 ID_AHA_39320D_B, 161 ID_ALL_MASK, 162 "Adaptec 39320D Ultra320 SCSI adapter", 163 ahd_aic7902_setup 164 }, 165 { 166 ID_AHA_39320D_B_HP, 167 ID_ALL_MASK, 168 "Adaptec (HP OEM) 39320D Ultra320 SCSI adapter", 169 ahd_aic7902_setup 170 }, 171 { 172 ID_AHA_29320, 173 ID_ALL_MASK, 174 "Adaptec 29320 Ultra320 SCSI adapter", 175 ahd_aic7902_setup 176 }, 177 { 178 ID_AHA_29320B, 179 ID_ALL_MASK, 180 "Adaptec 29320B Ultra320 SCSI adapter", 181 ahd_aic7902_setup 182 }, 183 /* Generic chip probes for devices we don't know 'exactly' */ 184 { 185 ID_AIC7901A & ID_DEV_VENDOR_MASK, 186 ID_DEV_VENDOR_MASK, 187 "Adaptec AIC7901A Ultra320 SCSI adapter", 188 ahd_aic7901A_setup 189 }, 190 { 191 ID_AIC7902 & ID_9005_GENERIC_MASK, 192 ID_9005_GENERIC_MASK, 193 "Adaptec AIC7902 Ultra320 SCSI adapter", 194 ahd_aic7902_setup 195 } 196 }; 197 198 const u_int ahd_num_pci_devs = NUM_ELEMENTS(ahd_pci_ident_table); 199 200 #define DEVCONFIG 0x40 201 #define PCIXINITPAT 0x0000E000ul 202 #define PCIXINIT_PCI33_66 0x0000E000ul 203 #define PCIXINIT_PCIX50_66 0x0000C000ul 204 #define PCIXINIT_PCIX66_100 0x0000A000ul 205 #define PCIXINIT_PCIX100_133 0x00008000ul 206 #define PCI_BUS_MODES_INDEX(devconfig) \ 207 (((devconfig) & PCIXINITPAT) >> 13) 208 static const char *pci_bus_modes[] = 209 { 210 "PCI bus mode unknown", 211 "PCI bus mode unknown", 212 "PCI bus mode unknown", 213 "PCI bus mode unknown", 214 "PCI-X 101-133Mhz", 215 "PCI-X 67-100Mhz", 216 "PCI-X 50-66Mhz", 217 "PCI 33 or 66Mhz" 218 }; 219 220 #define TESTMODE 0x00000800ul 221 #define IRDY_RST 0x00000200ul 222 #define FRAME_RST 0x00000100ul 223 #define PCI64BIT 0x00000080ul 224 #define MRDCEN 0x00000040ul 225 #define ENDIANSEL 0x00000020ul 226 #define MIXQWENDIANEN 0x00000008ul 227 #define DACEN 0x00000004ul 228 #define STPWLEVEL 0x00000002ul 229 #define QWENDIANSEL 0x00000001ul 230 231 #define DEVCONFIG1 0x44 232 #define PREQDIS 0x01 233 234 #define CSIZE_LATTIME 0x0c 235 #define CACHESIZE 0x000000fful 236 #define LATTIME 0x0000ff00ul 237 238 static int ahd_check_extport(struct ahd_softc *ahd); 239 static void ahd_configure_termination(struct ahd_softc *ahd, 240 u_int adapter_control); 241 static void ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat); 242 243 struct ahd_pci_identity * 244 ahd_find_pci_device(ahd_dev_softc_t pci) 245 { 246 uint64_t full_id; 247 uint16_t device; 248 uint16_t vendor; 249 uint16_t subdevice; 250 uint16_t subvendor; 251 struct ahd_pci_identity *entry; 252 u_int i; 253 254 vendor = ahd_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2); 255 device = ahd_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2); 256 subvendor = ahd_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2); 257 subdevice = ahd_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2); 258 full_id = ahd_compose_id(device, 259 vendor, 260 subdevice, 261 subvendor); 262 263 for (i = 0; i < ahd_num_pci_devs; i++) { 264 entry = &ahd_pci_ident_table[i]; 265 if (entry->full_id == (full_id & entry->id_mask)) { 266 /* Honor exclusion entries. */ 267 if (entry->name == NULL) 268 return (NULL); 269 return (entry); 270 } 271 } 272 return (NULL); 273 } 274 275 int 276 ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry) 277 { 278 struct scb_data *shared_scb_data; 279 u_long l; 280 u_int command; 281 uint32_t devconfig; 282 uint16_t subvendor; 283 int error; 284 285 shared_scb_data = NULL; 286 ahd->description = entry->name; 287 /* 288 * Record if this is an HP board. 289 */ 290 subvendor = ahd_pci_read_config(ahd->dev_softc, 291 PCIR_SUBVEND_0, /*bytes*/2); 292 if (subvendor == SUBID_HP) 293 ahd->flags |= AHD_HP_BOARD; 294 295 error = entry->setup(ahd); 296 if (error != 0) 297 return (error); 298 299 devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4); 300 if ((devconfig & PCIXINITPAT) == PCIXINIT_PCI33_66) { 301 ahd->chip |= AHD_PCI; 302 /* Disable PCIX workarounds when running in PCI mode. */ 303 ahd->bugs &= ~AHD_PCIX_BUG_MASK; 304 } else { 305 ahd->chip |= AHD_PCIX; 306 } 307 ahd->bus_description = pci_bus_modes[PCI_BUS_MODES_INDEX(devconfig)]; 308 309 ahd_power_state_change(ahd, AHD_POWER_STATE_D0); 310 311 error = ahd_pci_map_registers(ahd); 312 if (error != 0) 313 return (error); 314 315 /* 316 * If we need to support high memory, enable dual 317 * address cycles. This bit must be set to enable 318 * high address bit generation even if we are on a 319 * 64bit bus (PCI64BIT set in devconfig). 320 */ 321 if ((ahd->flags & (AHD_39BIT_ADDRESSING|AHD_64BIT_ADDRESSING)) != 0) { 322 uint32_t devconfig; 323 324 if (bootverbose) 325 printf("%s: Enabling 39Bit Addressing\n", 326 ahd_name(ahd)); 327 devconfig = ahd_pci_read_config(ahd->dev_softc, 328 DEVCONFIG, /*bytes*/4); 329 devconfig |= DACEN; 330 ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, 331 devconfig, /*bytes*/4); 332 } 333 334 /* Ensure busmastering is enabled */ 335 command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/1); 336 command |= PCIM_CMD_BUSMASTEREN; 337 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/1); 338 339 error = ahd_softc_init(ahd); 340 if (error != 0) 341 return (error); 342 343 ahd->bus_intr = ahd_pci_intr; 344 345 error = ahd_reset(ahd); 346 if (error != 0) 347 return (ENXIO); 348 349 ahd->pci_cachesize = 350 ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME, 351 /*bytes*/1) & CACHESIZE; 352 ahd->pci_cachesize *= 4; 353 354 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); 355 /* See if we have a SEEPROM and perform auto-term */ 356 error = ahd_check_extport(ahd); 357 if (error != 0) 358 return (error); 359 360 /* Core initialization */ 361 error = ahd_init(ahd); 362 if (error != 0) 363 return (error); 364 365 /* 366 * Allow interrupts now that we are completely setup. 367 */ 368 error = ahd_pci_map_int(ahd); 369 if (error != 0) 370 return (error); 371 372 ahd_list_lock(&l); 373 /* 374 * Link this softc in with all other ahd instances. 375 */ 376 ahd_softc_insert(ahd); 377 ahd_list_unlock(&l); 378 return (0); 379 } 380 381 /* 382 * Perform some simple tests that should catch situations where 383 * our registers are invalidly mapped. 384 */ 385 int 386 ahd_pci_test_register_access(struct ahd_softc *ahd) 387 { 388 ahd_mode_state saved_modes; 389 uint32_t cmd; 390 int error; 391 uint8_t hcntrl; 392 393 saved_modes = ahd_save_modes(ahd); 394 error = EIO; 395 396 /* 397 * Enable PCI error interrupt status, but suppress NMIs 398 * generated by SERR raised due to target aborts. 399 */ 400 cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2); 401 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, 402 cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2); 403 404 /* 405 * First a simple test to see if any 406 * registers can be read. Reading 407 * HCNTRL has no side effects and has 408 * at least one bit that is guaranteed to 409 * be zero so it is a good register to 410 * use for this test. 411 */ 412 hcntrl = ahd_inb(ahd, HCNTRL); 413 if (hcntrl == 0xFF) 414 goto fail; 415 416 /* 417 * Next create a situation where write combining 418 * or read prefetching could be initiated by the 419 * CPU or host bridge. Our device does not support 420 * either, so look for data corruption and/or flaged 421 * PCI errors. 422 */ 423 ahd_outb(ahd, HCNTRL, hcntrl|PAUSE); 424 while (ahd_is_paused(ahd) == 0) 425 ; 426 ahd_outb(ahd, SEQCTL0, PERRORDIS); 427 ahd_outl(ahd, SRAM_BASE, 0x5aa555aa); 428 if (ahd_inl(ahd, SRAM_BASE) != 0x5aa555aa) 429 goto fail; 430 431 if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) { 432 u_int targpcistat; 433 434 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG); 435 targpcistat = ahd_inb(ahd, TARGPCISTAT); 436 if ((targpcistat & STA) != 0) 437 goto fail; 438 } 439 440 error = 0; 441 442 fail: 443 if ((ahd_inb(ahd, INTSTAT) & PCIINT) != 0) { 444 u_int targpcistat; 445 u_int pci_status1; 446 447 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG); 448 targpcistat = ahd_inb(ahd, TARGPCISTAT); 449 450 /* Silently clear any latched errors. */ 451 ahd_outb(ahd, TARGPCISTAT, targpcistat); 452 pci_status1 = ahd_pci_read_config(ahd->dev_softc, 453 PCIR_STATUS + 1, /*bytes*/1); 454 ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1, 455 pci_status1, /*bytes*/1); 456 ahd_outb(ahd, CLRINT, CLRPCIINT); 457 } 458 459 ahd_restore_modes(ahd, saved_modes); 460 ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS); 461 ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2); 462 return (error); 463 } 464 465 /* 466 * Check the external port logic for a serial eeprom 467 * and termination/cable detection contrls. 468 */ 469 static int 470 ahd_check_extport(struct ahd_softc *ahd) 471 { 472 struct seeprom_config *sc; 473 u_int adapter_control; 474 int have_seeprom; 475 int error; 476 477 sc = ahd->seep_config; 478 have_seeprom = ahd_acquire_seeprom(ahd); 479 if (have_seeprom) { 480 u_int start_addr; 481 482 if (bootverbose) 483 printf("%s: Reading SEEPROM...", ahd_name(ahd)); 484 485 /* Address is always in units of 16bit words */ 486 start_addr = (sizeof(*sc) / 2) * (ahd->channel - 'A'); 487 488 error = ahd_read_seeprom(ahd, (uint16_t *)sc, 489 start_addr, sizeof(*sc)/2); 490 491 if (error != 0) { 492 printf("Unable to read SEEPROM\n"); 493 have_seeprom = 0; 494 } else { 495 have_seeprom = ahd_verify_cksum(sc); 496 497 if (bootverbose) { 498 if (have_seeprom == 0) 499 printf ("checksum error\n"); 500 else 501 printf ("done.\n"); 502 } 503 } 504 ahd_release_seeprom(ahd); 505 } 506 507 if (!have_seeprom) { 508 u_int nvram_scb; 509 510 /* 511 * Pull scratch ram settings and treat them as 512 * if they are the contents of an seeprom if 513 * the 'ADPT', 'BIOS', or 'ASPI' signature is found 514 * in SCB 0xFF. We manually compose the data as 16bit 515 * values to avoid endian issues. 516 */ 517 ahd_set_scbptr(ahd, 0xFF); 518 nvram_scb = ahd_inb_scbram(ahd, SCB_BASE + NVRAM_SCB_OFFSET); 519 if (nvram_scb != 0xFF 520 && ((ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A' 521 && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'D' 522 && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P' 523 && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'T') 524 || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'B' 525 && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'I' 526 && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'O' 527 && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'S') 528 || (ahd_inb_scbram(ahd, SCB_BASE + 0) == 'A' 529 && ahd_inb_scbram(ahd, SCB_BASE + 1) == 'S' 530 && ahd_inb_scbram(ahd, SCB_BASE + 2) == 'P' 531 && ahd_inb_scbram(ahd, SCB_BASE + 3) == 'I'))) { 532 uint16_t *sc_data; 533 int i; 534 535 ahd_set_scbptr(ahd, nvram_scb); 536 sc_data = (uint16_t *)sc; 537 for (i = 0; i < 64; i += 2) 538 *sc_data++ = ahd_inw_scbram(ahd, SCB_BASE+i); 539 have_seeprom = ahd_verify_cksum(sc); 540 if (have_seeprom) 541 ahd->flags |= AHD_SCB_CONFIG_USED; 542 } 543 } 544 545 #if AHD_DEBUG 546 if (have_seeprom != 0 547 && (ahd_debug & AHD_DUMP_SEEPROM) != 0) { 548 uint8_t *sc_data; 549 int i; 550 551 printf("%s: Seeprom Contents:", ahd_name(ahd)); 552 sc_data = (uint8_t *)sc; 553 for (i = 0; i < (sizeof(*sc)); i += 2) 554 printf("\n\t0x%.4x", 555 sc_data[i] | (sc_data[i+1] << 8)); 556 printf("\n"); 557 } 558 #endif 559 560 if (!have_seeprom) { 561 if (bootverbose) 562 printf("%s: No SEEPROM available.\n", ahd_name(ahd)); 563 ahd->flags |= AHD_USEDEFAULTS; 564 error = ahd_default_config(ahd); 565 adapter_control = CFAUTOTERM|CFSEAUTOTERM; 566 free(ahd->seep_config, M_DEVBUF); 567 ahd->seep_config = NULL; 568 } else { 569 error = ahd_parse_cfgdata(ahd, sc); 570 adapter_control = sc->adapter_control; 571 } 572 if (error != 0) 573 return (error); 574 575 ahd_configure_termination(ahd, adapter_control); 576 577 return (0); 578 } 579 580 static void 581 ahd_configure_termination(struct ahd_softc *ahd, u_int adapter_control) 582 { 583 int error; 584 u_int sxfrctl1; 585 uint8_t termctl; 586 uint32_t devconfig; 587 588 devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4); 589 devconfig &= ~STPWLEVEL; 590 if ((ahd->flags & AHD_STPWLEVEL_A) != 0) 591 devconfig |= STPWLEVEL; 592 if (bootverbose) 593 printf("%s: STPWLEVEL is %s\n", 594 ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off"); 595 ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4); 596 597 /* Make sure current sensing is off. */ 598 if ((ahd->flags & AHD_CURRENT_SENSING) != 0) { 599 (void)ahd_write_flexport(ahd, FLXADDR_ROMSTAT_CURSENSECTL, 0); 600 } 601 602 /* 603 * Read to sense. Write to set. 604 */ 605 error = ahd_read_flexport(ahd, FLXADDR_TERMCTL, &termctl); 606 if ((adapter_control & CFAUTOTERM) == 0) { 607 if (bootverbose) 608 printf("%s: Manual Primary Termination\n", 609 ahd_name(ahd)); 610 termctl &= ~(FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH); 611 if ((adapter_control & CFSTERM) != 0) 612 termctl |= FLX_TERMCTL_ENPRILOW; 613 if ((adapter_control & CFWSTERM) != 0) 614 termctl |= FLX_TERMCTL_ENPRIHIGH; 615 } else if (error != 0) { 616 printf("%s: Primary Auto-Term Sensing failed! " 617 "Using Defaults.\n", ahd_name(ahd)); 618 termctl = FLX_TERMCTL_ENPRILOW|FLX_TERMCTL_ENPRIHIGH; 619 } 620 621 if ((adapter_control & CFSEAUTOTERM) == 0) { 622 if (bootverbose) 623 printf("%s: Manual Secondary Termination\n", 624 ahd_name(ahd)); 625 termctl &= ~(FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH); 626 if ((adapter_control & CFSELOWTERM) != 0) 627 termctl |= FLX_TERMCTL_ENSECLOW; 628 if ((adapter_control & CFSEHIGHTERM) != 0) 629 termctl |= FLX_TERMCTL_ENSECHIGH; 630 } else if (error != 0) { 631 printf("%s: Secondary Auto-Term Sensing failed! " 632 "Using Defaults.\n", ahd_name(ahd)); 633 termctl |= FLX_TERMCTL_ENSECLOW|FLX_TERMCTL_ENSECHIGH; 634 } 635 636 /* 637 * Now set the termination based on what we found. 638 */ 639 sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN; 640 if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) { 641 ahd->flags |= AHD_TERM_ENB_A; 642 sxfrctl1 |= STPWEN; 643 } 644 /* Must set the latch once in order to be effective. */ 645 ahd_outb(ahd, SXFRCTL1, sxfrctl1|STPWEN); 646 ahd_outb(ahd, SXFRCTL1, sxfrctl1); 647 648 error = ahd_write_flexport(ahd, FLXADDR_TERMCTL, termctl); 649 if (error != 0) { 650 printf("%s: Unable to set termination settings!\n", 651 ahd_name(ahd)); 652 } else if (bootverbose) { 653 printf("%s: Primary High byte termination %sabled\n", 654 ahd_name(ahd), 655 (termctl & FLX_TERMCTL_ENPRIHIGH) ? "En" : "Dis"); 656 657 printf("%s: Primary Low byte termination %sabled\n", 658 ahd_name(ahd), 659 (termctl & FLX_TERMCTL_ENPRILOW) ? "En" : "Dis"); 660 661 printf("%s: Secondary High byte termination %sabled\n", 662 ahd_name(ahd), 663 (termctl & FLX_TERMCTL_ENSECHIGH) ? "En" : "Dis"); 664 665 printf("%s: Secondary Low byte termination %sabled\n", 666 ahd_name(ahd), 667 (termctl & FLX_TERMCTL_ENSECLOW) ? "En" : "Dis"); 668 } 669 return; 670 } 671 672 #define DPE 0x80 673 #define SSE 0x40 674 #define RMA 0x20 675 #define RTA 0x10 676 #define STA 0x08 677 #define DPR 0x01 678 679 static const char *split_status_source[] = 680 { 681 "DFF0", 682 "DFF1", 683 "OVLY", 684 "CMC", 685 }; 686 687 static const char *pci_status_source[] = 688 { 689 "DFF0", 690 "DFF1", 691 "SG", 692 "CMC", 693 "OVLY", 694 "NONE", 695 "MSI", 696 "TARG" 697 }; 698 699 static const char *split_status_strings[] = 700 { 701 "%s: Received split response in %s.\n", 702 "%s: Received split completion error message in %s\n", 703 "%s: Receive overrun in %s\n", 704 "%s: Count not complete in %s\n", 705 "%s: Split completion data bucket in %s\n", 706 "%s: Split completion address error in %s\n", 707 "%s: Split completion byte count error in %s\n", 708 "%s: Signaled Target-abort to early terminate a split in %s\n" 709 }; 710 711 static const char *pci_status_strings[] = 712 { 713 "%s: Data Parity Error has been reported via PERR# in %s\n", 714 "%s: Target initial wait state error in %s\n", 715 "%s: Split completion read data parity error in %s\n", 716 "%s: Split completion address attribute parity error in %s\n", 717 "%s: Received a Target Abort in %s\n", 718 "%s: Received a Master Abort in %s\n", 719 "%s: Signal System Error Detected in %s\n", 720 "%s: Address or Write Phase Parity Error Detected in %s.\n" 721 }; 722 723 void 724 ahd_pci_intr(struct ahd_softc *ahd) 725 { 726 uint8_t pci_status[8]; 727 ahd_mode_state saved_modes; 728 u_int pci_status1; 729 u_int intstat; 730 u_int i; 731 u_int reg; 732 733 intstat = ahd_inb(ahd, INTSTAT); 734 735 if ((intstat & SPLTINT) != 0) 736 ahd_pci_split_intr(ahd, intstat); 737 738 if ((intstat & PCIINT) == 0) 739 return; 740 741 printf("%s: PCI error Interrupt\n", ahd_name(ahd)); 742 saved_modes = ahd_save_modes(ahd); 743 ahd_dump_card_state(ahd); 744 ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG); 745 for (i = 0, reg = DF0PCISTAT; i < 8; i++, reg++) { 746 747 if (i == 5) 748 continue; 749 pci_status[i] = ahd_inb(ahd, reg); 750 /* Clear latched errors. So our interrupt deasserts. */ 751 ahd_outb(ahd, reg, pci_status[i]); 752 } 753 754 for (i = 0; i < 8; i++) { 755 u_int bit; 756 757 if (i == 5) 758 continue; 759 760 for (bit = 0; bit < 8; bit++) { 761 762 if ((pci_status[i] & (0x1 << bit)) != 0) { 763 static const char *s; 764 765 s = pci_status_strings[bit]; 766 if (i == 7/*TARG*/ && bit == 3) 767 s = "%s: Signaled Target Abort\n"; 768 printf(s, ahd_name(ahd), pci_status_source[i]); 769 } 770 } 771 } 772 pci_status1 = ahd_pci_read_config(ahd->dev_softc, 773 PCIR_STATUS + 1, /*bytes*/1); 774 ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1, 775 pci_status1, /*bytes*/1); 776 ahd_restore_modes(ahd, saved_modes); 777 ahd_outb(ahd, CLRINT, CLRPCIINT); 778 ahd_unpause(ahd); 779 } 780 781 static void 782 ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat) 783 { 784 uint8_t split_status[4]; 785 uint8_t split_status1[4]; 786 uint8_t sg_split_status[2]; 787 uint8_t sg_split_status1[2]; 788 ahd_mode_state saved_modes; 789 u_int i; 790 uint16_t pcix_status; 791 792 /* 793 * Check for splits in all modes. Modes 0 and 1 794 * additionally have SG engine splits to look at. 795 */ 796 pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS, 797 /*bytes*/2); 798 printf("%s: PCI Split Interrupt - PCI-X status = 0x%x\n", 799 ahd_name(ahd), pcix_status); 800 saved_modes = ahd_save_modes(ahd); 801 for (i = 0; i < 4; i++) { 802 ahd_set_modes(ahd, i, i); 803 804 split_status[i] = ahd_inb(ahd, DCHSPLTSTAT0); 805 split_status1[i] = ahd_inb(ahd, DCHSPLTSTAT1); 806 /* Clear latched errors. So our interrupt deasserts. */ 807 ahd_outb(ahd, DCHSPLTSTAT0, split_status[i]); 808 ahd_outb(ahd, DCHSPLTSTAT1, split_status1[i]); 809 if (i != 0) 810 continue; 811 sg_split_status[i] = ahd_inb(ahd, SGSPLTSTAT0); 812 sg_split_status1[i] = ahd_inb(ahd, SGSPLTSTAT1); 813 /* Clear latched errors. So our interrupt deasserts. */ 814 ahd_outb(ahd, SGSPLTSTAT0, sg_split_status[i]); 815 ahd_outb(ahd, SGSPLTSTAT1, sg_split_status1[i]); 816 } 817 818 for (i = 0; i < 4; i++) { 819 u_int bit; 820 821 for (bit = 0; bit < 8; bit++) { 822 823 if ((split_status[i] & (0x1 << bit)) != 0) { 824 static const char *s; 825 826 s = split_status_strings[bit]; 827 printf(s, ahd_name(ahd), 828 split_status_source[i]); 829 } 830 831 if (i != 0) 832 continue; 833 834 if ((sg_split_status[i] & (0x1 << bit)) != 0) { 835 static const char *s; 836 837 s = split_status_strings[bit]; 838 printf(s, ahd_name(ahd), "SG"); 839 } 840 } 841 } 842 /* 843 * Clear PCI-X status bits. 844 */ 845 ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS, 846 pcix_status, /*bytes*/2); 847 ahd_outb(ahd, CLRINT, CLRSPLTINT); 848 ahd_restore_modes(ahd, saved_modes); 849 } 850 851 static int 852 ahd_aic7901A_setup(struct ahd_softc *ahd) 853 { 854 int error; 855 856 error = ahd_aic7902_setup(ahd); 857 if (error != 0) 858 return (error); 859 ahd->chip = AHD_AIC7901A; 860 return (0); 861 } 862 863 static int 864 ahd_aic7902_setup(struct ahd_softc *ahd) 865 { 866 ahd_dev_softc_t pci; 867 u_int rev; 868 869 pci = ahd->dev_softc; 870 rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1); 871 if (rev < ID_AIC7902_PCI_REV_A4) { 872 printf("%s: Unable to attach to unsupported chip revision %d\n", 873 ahd_name(ahd), rev); 874 ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/1); 875 return (ENXIO); 876 } 877 ahd->channel = ahd_get_pci_function(pci) + 'A'; 878 ahd->chip = AHD_AIC7902; 879 ahd->features = AHD_AIC7902_FE; 880 if (rev < ID_AIC7902_PCI_REV_B0) { 881 /* 882 * Enable A series workarounds. 883 */ 884 ahd->bugs |= AHD_SENT_SCB_UPDATE_BUG|AHD_ABORT_LQI_BUG 885 | AHD_PKT_BITBUCKET_BUG|AHD_LONG_SETIMO_BUG 886 | AHD_NLQICRC_DELAYED_BUG|AHD_SCSIRST_BUG 887 | AHD_LQO_ATNO_BUG|AHD_AUTOFLUSH_BUG 888 | AHD_CLRLQO_AUTOCLR_BUG|AHD_PCIX_MMAPIO_BUG 889 | AHD_PCIX_CHIPRST_BUG|AHD_PKTIZED_STATUS_BUG 890 | AHD_PKT_LUN_BUG|AHD_MDFF_WSCBPTR_BUG 891 | AHD_REG_SLOW_SETTLE_BUG|AHD_SET_MODE_BUG 892 | AHD_BUSFREEREV_BUG|AHD_NONPACKFIFO_BUG 893 | AHD_PACED_NEGTABLE_BUG; 894 895 /* 896 * IO Cell paramter setup. 897 */ 898 AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29); 899 900 if ((ahd->flags & AHD_HP_BOARD) == 0) 901 AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVA); 902 } else { 903 u_int devconfig1; 904 905 ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS 906 | AHD_NEW_DFCNTRL_OPTS; 907 ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_ABORT_LQI_BUG 908 | AHD_INTCOLLISION_BUG|AHD_EARLY_REQ_BUG; 909 910 /* 911 * IO Cell paramter setup. 912 */ 913 AHD_SET_PRECOMP(ahd, AHD_PRECOMP_CUTBACK_29); 914 AHD_SET_SLEWRATE(ahd, AHD_SLEWRATE_DEF_REVB); 915 AHD_SET_AMPLITUDE(ahd, AHD_AMPLITUDE_DEF); 916 917 /* 918 * Set the PREQDIS bit for H2B which disables some workaround 919 * that doesn't work on regular PCI busses. 920 * XXX - Find out exactly what this does from the hardware 921 * folks! 922 */ 923 devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1); 924 ahd_pci_write_config(pci, DEVCONFIG1, 925 devconfig1|PREQDIS, /*bytes*/1); 926 devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1); 927 } 928 929 return (0); 930 } 931