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#16 $ 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 60 static void aha2840_load_seeprom(struct ahc_softc *ahc); 61 static ahc_device_setup_t ahc_aic7770_VL_setup; 62 static ahc_device_setup_t ahc_aic7770_EISA_setup;; 63 static ahc_device_setup_t ahc_aic7770_setup; 64 65 66 struct aic7770_identity aic7770_ident_table [] = 67 { 68 { 69 ID_AHA_274x, 70 0xFFFFFFFF, 71 "Adaptec 274X SCSI adapter", 72 ahc_aic7770_EISA_setup 73 }, 74 { 75 ID_AHA_284xB, 76 0xFFFFFFFE, 77 "Adaptec 284X SCSI adapter", 78 ahc_aic7770_VL_setup 79 }, 80 /* Generic chip probes for devices we don't know 'exactly' */ 81 { 82 ID_AIC7770, 83 0xFFFFFFFF, 84 "Adaptec aic7770 SCSI adapter", 85 ahc_aic7770_EISA_setup 86 } 87 }; 88 const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table); 89 90 struct aic7770_identity * 91 aic7770_find_device(uint32_t id) 92 { 93 struct aic7770_identity *entry; 94 int i; 95 96 for (i = 0; i < ahc_num_aic7770_devs; i++) { 97 entry = &aic7770_ident_table[i]; 98 if (entry->full_id == (id & entry->id_mask)) 99 return (entry); 100 } 101 return (NULL); 102 } 103 104 int 105 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io) 106 { 107 int error; 108 u_int hostconf; 109 u_int irq; 110 u_int intdef; 111 112 error = entry->setup(ahc); 113 if (error != 0) 114 return (error); 115 116 error = aic7770_map_registers(ahc, io); 117 if (error != 0) 118 return (error); 119 120 /* 121 * Before we continue probing the card, ensure that 122 * its interrupts are *disabled*. We don't want 123 * a misstep to hang the machine in an interrupt 124 * storm. 125 */ 126 ahc_intr_enable(ahc, FALSE); 127 128 ahc->description = entry->name; 129 error = ahc_softc_init(ahc); 130 131 error = ahc_reset(ahc); 132 if (error != 0) 133 return (error); 134 135 /* Make sure we have a valid interrupt vector */ 136 intdef = ahc_inb(ahc, INTDEF); 137 irq = intdef & VECTOR; 138 switch (irq) { 139 case 9: 140 case 10: 141 case 11: 142 case 12: 143 case 14: 144 case 15: 145 break; 146 default: 147 printf("aic7770_config: illegal irq setting %d\n", intdef); 148 return (ENXIO); 149 } 150 151 if ((intdef & EDGE_TRIG) != 0) 152 ahc->flags |= AHC_EDGE_INTERRUPT; 153 154 switch (ahc->chip & (AHC_EISA|AHC_VL)) { 155 case AHC_EISA: 156 { 157 u_int biosctrl; 158 u_int scsiconf; 159 u_int scsiconf1; 160 161 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL); 162 scsiconf = ahc_inb(ahc, SCSICONF); 163 scsiconf1 = ahc_inb(ahc, SCSICONF + 1); 164 165 /* Get the primary channel information */ 166 if ((biosctrl & CHANNEL_B_PRIMARY) != 0) 167 ahc->flags |= 1; 168 169 if ((biosctrl & BIOSMODE) == BIOSDISABLED) { 170 ahc->flags |= AHC_USEDEFAULTS; 171 } else { 172 if ((ahc->features & AHC_WIDE) != 0) { 173 ahc->our_id = scsiconf1 & HWSCSIID; 174 if (scsiconf & TERM_ENB) 175 ahc->flags |= AHC_TERM_ENB_A; 176 } else { 177 ahc->our_id = scsiconf & HSCSIID; 178 ahc->our_id_b = scsiconf1 & HSCSIID; 179 if (scsiconf & TERM_ENB) 180 ahc->flags |= AHC_TERM_ENB_A; 181 if (scsiconf1 & TERM_ENB) 182 ahc->flags |= AHC_TERM_ENB_B; 183 } 184 } 185 /* 186 * We have no way to tell, so assume extended 187 * translation is enabled. 188 */ 189 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B; 190 break; 191 } 192 case AHC_VL: 193 { 194 aha2840_load_seeprom(ahc); 195 break; 196 } 197 default: 198 break; 199 } 200 201 /* 202 * Ensure autoflush is enabled 203 */ 204 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS); 205 206 /* Setup the FIFO threshold and the bus off time */ 207 hostconf = ahc_inb(ahc, HOSTCONF); 208 ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH); 209 ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF); 210 211 /* 212 * Generic aic7xxx initialization. 213 */ 214 error = ahc_init(ahc); 215 if (error != 0) 216 return (error); 217 218 /* 219 * Link this softc in with all other ahc instances. 220 */ 221 ahc_softc_insert(ahc); 222 223 error = aic7770_map_int(ahc, irq); 224 if (error != 0) 225 return (error); 226 227 /* 228 * Enable the board's BUS drivers 229 */ 230 ahc_outb(ahc, BCTL, ENABLE); 231 232 /* 233 * Allow interrupts. 234 */ 235 ahc_intr_enable(ahc, TRUE); 236 237 return (0); 238 } 239 240 /* 241 * Read the 284x SEEPROM. 242 */ 243 static void 244 aha2840_load_seeprom(struct ahc_softc *ahc) 245 { 246 struct seeprom_descriptor sd; 247 struct seeprom_config sc; 248 uint8_t scsi_conf; 249 int have_seeprom; 250 251 sd.sd_ahc = ahc; 252 sd.sd_control_offset = SEECTL_2840; 253 sd.sd_status_offset = STATUS_2840; 254 sd.sd_dataout_offset = STATUS_2840; 255 sd.sd_chip = C46; 256 sd.sd_MS = 0; 257 sd.sd_RDY = EEPROM_TF; 258 sd.sd_CS = CS_2840; 259 sd.sd_CK = CK_2840; 260 sd.sd_DO = DO_2840; 261 sd.sd_DI = DI_2840; 262 263 if (bootverbose) 264 printf("%s: Reading SEEPROM...", ahc_name(ahc)); 265 have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)&sc, 266 /*start_addr*/0, sizeof(sc)/2); 267 268 if (have_seeprom) { 269 270 if (ahc_verify_cksum(&sc) == 0) { 271 if(bootverbose) 272 printf ("checksum error\n"); 273 have_seeprom = 0; 274 } else if (bootverbose) { 275 printf("done.\n"); 276 } 277 } 278 279 if (!have_seeprom) { 280 if (bootverbose) 281 printf("%s: No SEEPROM available\n", ahc_name(ahc)); 282 ahc->flags |= AHC_USEDEFAULTS; 283 } else { 284 /* 285 * Put the data we've collected down into SRAM 286 * where ahc_init will find it. 287 */ 288 int i; 289 int max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8; 290 uint16_t discenable; 291 292 discenable = 0; 293 for (i = 0; i < max_targ; i++){ 294 uint8_t target_settings; 295 target_settings = (sc.device_flags[i] & CFXFER) << 4; 296 if (sc.device_flags[i] & CFSYNCH) 297 target_settings |= SOFS; 298 if (sc.device_flags[i] & CFWIDEB) 299 target_settings |= WIDEXFER; 300 if (sc.device_flags[i] & CFDISC) 301 discenable |= (0x01 << i); 302 ahc_outb(ahc, TARG_SCSIRATE + i, target_settings); 303 } 304 ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff)); 305 ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff)); 306 307 ahc->our_id = sc.brtime_id & CFSCSIID; 308 309 scsi_conf = (ahc->our_id & 0x7); 310 if (sc.adapter_control & CFSPARITY) 311 scsi_conf |= ENSPCHK; 312 if (sc.adapter_control & CFRESETB) 313 scsi_conf |= RESET_SCSI; 314 315 if (sc.bios_control & CF284XEXTEND) 316 ahc->flags |= AHC_EXTENDED_TRANS_A; 317 /* Set SCSICONF info */ 318 ahc_outb(ahc, SCSICONF, scsi_conf); 319 320 if (sc.adapter_control & CF284XSTERM) 321 ahc->flags |= AHC_TERM_ENB_A; 322 } 323 } 324 325 static int 326 ahc_aic7770_VL_setup(struct ahc_softc *ahc) 327 { 328 int error; 329 330 error = ahc_aic7770_setup(ahc); 331 ahc->chip |= AHC_VL; 332 return (error); 333 } 334 335 static int 336 ahc_aic7770_EISA_setup(struct ahc_softc *ahc) 337 { 338 int error; 339 340 error = ahc_aic7770_setup(ahc); 341 ahc->chip |= AHC_EISA; 342 return (error); 343 } 344 345 static int 346 ahc_aic7770_setup(struct ahc_softc *ahc) 347 { 348 ahc->channel = 'A'; 349 ahc->channel_b = 'B'; 350 ahc->chip = AHC_AIC7770; 351 ahc->features = AHC_AIC7770_FE; 352 ahc->bugs |= AHC_TMODE_WIDEODD_BUG; 353 ahc->flags |= AHC_PAGESCBS; 354 return (0); 355 } 356