1 /* 2 * Product specific probe and attach routines for: 3 * 27/284X and aic7770 motherboard SCSI controllers 4 * 5 * Copyright (c) 1994-1998, 2000, 2001 Justin T. Gibbs. 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, this list of conditions, and the following disclaimer, 13 * without modification. 14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 15 * substantially similar to the "NO WARRANTY" disclaimer below 16 * ("Disclaimer") and any redistribution must be conditioned upon 17 * including a substantially similar Disclaimer requirement for further 18 * binary redistribution. 19 * 3. Neither the names of the above-listed copyright holders nor the names 20 * of any contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * Alternatively, this software may be distributed under the terms of the 24 * GNU General Public License ("GPL") version 2 as published by the Free 25 * Software Foundation. 26 * 27 * NO WARRANTY 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGES. 39 * 40 * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#30 $ 41 * 42 * $FreeBSD$ 43 */ 44 45 #ifdef __linux__ 46 #include "aic7xxx_osm.h" 47 #include "aic7xxx_inline.h" 48 #include "aic7xxx_93cx6.h" 49 #else 50 #include <dev/aic7xxx/aic7xxx_osm.h> 51 #include <dev/aic7xxx/aic7xxx_inline.h> 52 #include <dev/aic7xxx/aic7xxx_93cx6.h> 53 #endif 54 55 #define ID_AIC7770 0x04907770 56 #define ID_AHA_274x 0x04907771 57 #define ID_AHA_284xB 0x04907756 /* BIOS enabled */ 58 #define ID_AHA_284x 0x04907757 /* BIOS disabled*/ 59 #define ID_OLV_274x 0x04907782 /* Olivetti OEM */ 60 #define ID_OLV_274xD 0x04907783 /* Olivetti OEM (Differential) */ 61 62 static int aic7770_chip_init(struct ahc_softc *ahc); 63 static int aic7770_suspend(struct ahc_softc *ahc); 64 static int aic7770_resume(struct ahc_softc *ahc); 65 static int aha2840_load_seeprom(struct ahc_softc *ahc); 66 static ahc_device_setup_t ahc_aic7770_VL_setup; 67 static ahc_device_setup_t ahc_aic7770_EISA_setup;; 68 static ahc_device_setup_t ahc_aic7770_setup; 69 70 71 struct aic7770_identity aic7770_ident_table [] = 72 { 73 { 74 ID_AHA_274x, 75 0xFFFFFFFF, 76 "Adaptec 274X SCSI adapter", 77 ahc_aic7770_EISA_setup 78 }, 79 { 80 ID_AHA_284xB, 81 0xFFFFFFFE, 82 "Adaptec 284X SCSI adapter", 83 ahc_aic7770_VL_setup 84 }, 85 { 86 ID_OLV_274x, 87 0xFFFFFFFF, 88 "Adaptec (Olivetti OEM) 274X SCSI adapter", 89 ahc_aic7770_EISA_setup 90 }, 91 { 92 ID_OLV_274xD, 93 0xFFFFFFFF, 94 "Adaptec (Olivetti OEM) 274X Differential SCSI adapter", 95 ahc_aic7770_EISA_setup 96 }, 97 /* Generic chip probes for devices we don't know 'exactly' */ 98 { 99 ID_AIC7770, 100 0xFFFFFFFF, 101 "Adaptec aic7770 SCSI adapter", 102 ahc_aic7770_EISA_setup 103 } 104 }; 105 const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table); 106 107 struct aic7770_identity * 108 aic7770_find_device(uint32_t id) 109 { 110 struct aic7770_identity *entry; 111 int i; 112 113 for (i = 0; i < ahc_num_aic7770_devs; i++) { 114 entry = &aic7770_ident_table[i]; 115 if (entry->full_id == (id & entry->id_mask)) 116 return (entry); 117 } 118 return (NULL); 119 } 120 121 int 122 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io) 123 { 124 u_long l; 125 int error; 126 int have_seeprom; 127 u_int hostconf; 128 u_int irq; 129 u_int intdef; 130 131 error = entry->setup(ahc); 132 have_seeprom = 0; 133 if (error != 0) 134 return (error); 135 136 error = aic7770_map_registers(ahc, io); 137 if (error != 0) 138 return (error); 139 140 /* 141 * Before we continue probing the card, ensure that 142 * its interrupts are *disabled*. We don't want 143 * a misstep to hang the machine in an interrupt 144 * storm. 145 */ 146 ahc_intr_enable(ahc, FALSE); 147 148 ahc->description = entry->name; 149 error = ahc_softc_init(ahc); 150 if (error != 0) 151 return (error); 152 153 ahc->bus_chip_init = aic7770_chip_init; 154 ahc->bus_suspend = aic7770_suspend; 155 ahc->bus_resume = aic7770_resume; 156 157 error = ahc_reset(ahc); 158 if (error != 0) 159 return (error); 160 161 /* Make sure we have a valid interrupt vector */ 162 intdef = ahc_inb(ahc, INTDEF); 163 irq = intdef & VECTOR; 164 switch (irq) { 165 case 9: 166 case 10: 167 case 11: 168 case 12: 169 case 14: 170 case 15: 171 break; 172 default: 173 printf("aic7770_config: illegal irq setting %d\n", intdef); 174 return (ENXIO); 175 } 176 177 if ((intdef & EDGE_TRIG) != 0) 178 ahc->flags |= AHC_EDGE_INTERRUPT; 179 180 switch (ahc->chip & (AHC_EISA|AHC_VL)) { 181 case AHC_EISA: 182 { 183 u_int biosctrl; 184 u_int scsiconf; 185 u_int scsiconf1; 186 187 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL); 188 scsiconf = ahc_inb(ahc, SCSICONF); 189 scsiconf1 = ahc_inb(ahc, SCSICONF + 1); 190 191 /* Get the primary channel information */ 192 if ((biosctrl & CHANNEL_B_PRIMARY) != 0) 193 ahc->flags |= 1; 194 195 if ((biosctrl & BIOSMODE) == BIOSDISABLED) { 196 ahc->flags |= AHC_USEDEFAULTS; 197 } else { 198 if ((ahc->features & AHC_WIDE) != 0) { 199 ahc->our_id = scsiconf1 & HWSCSIID; 200 if (scsiconf & TERM_ENB) 201 ahc->flags |= AHC_TERM_ENB_A; 202 } else { 203 ahc->our_id = scsiconf & HSCSIID; 204 ahc->our_id_b = scsiconf1 & HSCSIID; 205 if (scsiconf & TERM_ENB) 206 ahc->flags |= AHC_TERM_ENB_A; 207 if (scsiconf1 & TERM_ENB) 208 ahc->flags |= AHC_TERM_ENB_B; 209 } 210 } 211 if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS)) 212 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B; 213 break; 214 } 215 case AHC_VL: 216 { 217 have_seeprom = aha2840_load_seeprom(ahc); 218 break; 219 } 220 default: 221 break; 222 } 223 if (have_seeprom == 0) { 224 free(ahc->seep_config, M_DEVBUF); 225 ahc->seep_config = NULL; 226 } 227 228 /* 229 * Ensure autoflush is enabled 230 */ 231 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS); 232 233 /* Setup the FIFO threshold and the bus off time */ 234 hostconf = ahc_inb(ahc, HOSTCONF); 235 ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH); 236 ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF); 237 238 ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH; 239 ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF; 240 241 /* 242 * Generic aic7xxx initialization. 243 */ 244 error = ahc_init(ahc); 245 if (error != 0) 246 return (error); 247 248 error = aic7770_map_int(ahc, irq); 249 if (error != 0) 250 return (error); 251 252 ahc_list_lock(&l); 253 /* 254 * Link this softc in with all other ahc instances. 255 */ 256 ahc_softc_insert(ahc); 257 258 /* 259 * Enable the board's BUS drivers 260 */ 261 ahc_outb(ahc, BCTL, ENABLE); 262 263 ahc_list_unlock(&l); 264 265 return (0); 266 } 267 268 static int 269 aic7770_chip_init(struct ahc_softc *ahc) 270 { 271 ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd); 272 ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime); 273 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS); 274 ahc_outb(ahc, BCTL, ENABLE); 275 return (ahc_chip_init(ahc)); 276 } 277 278 static int 279 aic7770_suspend(struct ahc_softc *ahc) 280 { 281 return (ahc_suspend(ahc)); 282 } 283 284 static int 285 aic7770_resume(struct ahc_softc *ahc) 286 { 287 return (ahc_resume(ahc)); 288 } 289 290 /* 291 * Read the 284x SEEPROM. 292 */ 293 static int 294 aha2840_load_seeprom(struct ahc_softc *ahc) 295 { 296 struct seeprom_descriptor sd; 297 struct seeprom_config *sc; 298 int have_seeprom; 299 uint8_t scsi_conf; 300 301 sd.sd_ahc = ahc; 302 sd.sd_control_offset = SEECTL_2840; 303 sd.sd_status_offset = STATUS_2840; 304 sd.sd_dataout_offset = STATUS_2840; 305 sd.sd_chip = C46; 306 sd.sd_MS = 0; 307 sd.sd_RDY = EEPROM_TF; 308 sd.sd_CS = CS_2840; 309 sd.sd_CK = CK_2840; 310 sd.sd_DO = DO_2840; 311 sd.sd_DI = DI_2840; 312 sc = ahc->seep_config; 313 314 if (bootverbose) 315 printf("%s: Reading SEEPROM...", ahc_name(ahc)); 316 have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc, 317 /*start_addr*/0, sizeof(*sc)/2); 318 319 if (have_seeprom) { 320 321 if (ahc_verify_cksum(sc) == 0) { 322 if(bootverbose) 323 printf ("checksum error\n"); 324 have_seeprom = 0; 325 } else if (bootverbose) { 326 printf("done.\n"); 327 } 328 } 329 330 if (!have_seeprom) { 331 if (bootverbose) 332 printf("%s: No SEEPROM available\n", ahc_name(ahc)); 333 ahc->flags |= AHC_USEDEFAULTS; 334 } else { 335 /* 336 * Put the data we've collected down into SRAM 337 * where ahc_init will find it. 338 */ 339 int i; 340 int max_targ; 341 uint16_t discenable; 342 343 max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8; 344 discenable = 0; 345 for (i = 0; i < max_targ; i++){ 346 uint8_t target_settings; 347 348 target_settings = (sc->device_flags[i] & CFXFER) << 4; 349 if (sc->device_flags[i] & CFSYNCH) 350 target_settings |= SOFS; 351 if (sc->device_flags[i] & CFWIDEB) 352 target_settings |= WIDEXFER; 353 if (sc->device_flags[i] & CFDISC) 354 discenable |= (0x01 << i); 355 ahc_outb(ahc, TARG_SCSIRATE + i, target_settings); 356 } 357 ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff)); 358 ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff)); 359 360 ahc->our_id = sc->brtime_id & CFSCSIID; 361 362 scsi_conf = (ahc->our_id & 0x7); 363 if (sc->adapter_control & CFSPARITY) 364 scsi_conf |= ENSPCHK; 365 if (sc->adapter_control & CFRESETB) 366 scsi_conf |= RESET_SCSI; 367 368 if (sc->bios_control & CF284XEXTEND) 369 ahc->flags |= AHC_EXTENDED_TRANS_A; 370 /* Set SCSICONF info */ 371 ahc_outb(ahc, SCSICONF, scsi_conf); 372 373 if (sc->adapter_control & CF284XSTERM) 374 ahc->flags |= AHC_TERM_ENB_A; 375 } 376 return (have_seeprom); 377 } 378 379 static int 380 ahc_aic7770_VL_setup(struct ahc_softc *ahc) 381 { 382 int error; 383 384 error = ahc_aic7770_setup(ahc); 385 ahc->chip |= AHC_VL; 386 return (error); 387 } 388 389 static int 390 ahc_aic7770_EISA_setup(struct ahc_softc *ahc) 391 { 392 int error; 393 394 error = ahc_aic7770_setup(ahc); 395 ahc->chip |= AHC_EISA; 396 return (error); 397 } 398 399 static int 400 ahc_aic7770_setup(struct ahc_softc *ahc) 401 { 402 ahc->channel = 'A'; 403 ahc->channel_b = 'B'; 404 ahc->chip = AHC_AIC7770; 405 ahc->features = AHC_AIC7770_FE; 406 ahc->bugs |= AHC_TMODE_WIDEODD_BUG; 407 ahc->flags |= AHC_PAGESCBS; 408 ahc->instruction_ram_size = 448; 409 return (0); 410 } 411