aic7770.c 10 KB

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