aic7770.c 9.5 KB

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