aic7770.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 = ARRAY_SIZE(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. int error;
  123. int have_seeprom;
  124. u_int hostconf;
  125. u_int irq;
  126. u_int intdef;
  127. error = entry->setup(ahc);
  128. have_seeprom = 0;
  129. if (error != 0)
  130. return (error);
  131. error = aic7770_map_registers(ahc, io);
  132. if (error != 0)
  133. return (error);
  134. /*
  135. * Before we continue probing the card, ensure that
  136. * its interrupts are *disabled*. We don't want
  137. * a misstep to hang the machine in an interrupt
  138. * storm.
  139. */
  140. ahc_intr_enable(ahc, FALSE);
  141. ahc->description = entry->name;
  142. error = ahc_softc_init(ahc);
  143. if (error != 0)
  144. return (error);
  145. ahc->bus_chip_init = aic7770_chip_init;
  146. ahc->bus_suspend = aic7770_suspend;
  147. ahc->bus_resume = aic7770_resume;
  148. error = ahc_reset(ahc, /*reinit*/FALSE);
  149. if (error != 0)
  150. return (error);
  151. /* Make sure we have a valid interrupt vector */
  152. intdef = ahc_inb(ahc, INTDEF);
  153. irq = intdef & VECTOR;
  154. switch (irq) {
  155. case 9:
  156. case 10:
  157. case 11:
  158. case 12:
  159. case 14:
  160. case 15:
  161. break;
  162. default:
  163. printf("aic7770_config: invalid irq setting %d\n", intdef);
  164. return (ENXIO);
  165. }
  166. if ((intdef & EDGE_TRIG) != 0)
  167. ahc->flags |= AHC_EDGE_INTERRUPT;
  168. switch (ahc->chip & (AHC_EISA|AHC_VL)) {
  169. case AHC_EISA:
  170. {
  171. u_int biosctrl;
  172. u_int scsiconf;
  173. u_int scsiconf1;
  174. biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
  175. scsiconf = ahc_inb(ahc, SCSICONF);
  176. scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
  177. /* Get the primary channel information */
  178. if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
  179. ahc->flags |= 1;
  180. if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
  181. ahc->flags |= AHC_USEDEFAULTS;
  182. } else {
  183. if ((ahc->features & AHC_WIDE) != 0) {
  184. ahc->our_id = scsiconf1 & HWSCSIID;
  185. if (scsiconf & TERM_ENB)
  186. ahc->flags |= AHC_TERM_ENB_A;
  187. } else {
  188. ahc->our_id = scsiconf & HSCSIID;
  189. ahc->our_id_b = scsiconf1 & HSCSIID;
  190. if (scsiconf & TERM_ENB)
  191. ahc->flags |= AHC_TERM_ENB_A;
  192. if (scsiconf1 & TERM_ENB)
  193. ahc->flags |= AHC_TERM_ENB_B;
  194. }
  195. }
  196. if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
  197. ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
  198. break;
  199. }
  200. case AHC_VL:
  201. {
  202. have_seeprom = aha2840_load_seeprom(ahc);
  203. break;
  204. }
  205. default:
  206. break;
  207. }
  208. if (have_seeprom == 0) {
  209. free(ahc->seep_config, M_DEVBUF);
  210. ahc->seep_config = NULL;
  211. }
  212. /*
  213. * Ensure autoflush is enabled
  214. */
  215. ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
  216. /* Setup the FIFO threshold and the bus off time */
  217. hostconf = ahc_inb(ahc, HOSTCONF);
  218. ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
  219. ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
  220. ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH;
  221. ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF;
  222. /*
  223. * Generic aic7xxx initialization.
  224. */
  225. error = ahc_init(ahc);
  226. if (error != 0)
  227. return (error);
  228. error = aic7770_map_int(ahc, irq);
  229. if (error != 0)
  230. return (error);
  231. ahc->init_level++;
  232. /*
  233. * Enable the board's BUS drivers
  234. */
  235. ahc_outb(ahc, BCTL, ENABLE);
  236. return (0);
  237. }
  238. static int
  239. aic7770_chip_init(struct ahc_softc *ahc)
  240. {
  241. ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd);
  242. ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime);
  243. ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
  244. ahc_outb(ahc, BCTL, ENABLE);
  245. return (ahc_chip_init(ahc));
  246. }
  247. static int
  248. aic7770_suspend(struct ahc_softc *ahc)
  249. {
  250. return (ahc_suspend(ahc));
  251. }
  252. static int
  253. aic7770_resume(struct ahc_softc *ahc)
  254. {
  255. return (ahc_resume(ahc));
  256. }
  257. /*
  258. * Read the 284x SEEPROM.
  259. */
  260. static int
  261. aha2840_load_seeprom(struct ahc_softc *ahc)
  262. {
  263. struct seeprom_descriptor sd;
  264. struct seeprom_config *sc;
  265. int have_seeprom;
  266. uint8_t scsi_conf;
  267. sd.sd_ahc = ahc;
  268. sd.sd_control_offset = SEECTL_2840;
  269. sd.sd_status_offset = STATUS_2840;
  270. sd.sd_dataout_offset = STATUS_2840;
  271. sd.sd_chip = C46;
  272. sd.sd_MS = 0;
  273. sd.sd_RDY = EEPROM_TF;
  274. sd.sd_CS = CS_2840;
  275. sd.sd_CK = CK_2840;
  276. sd.sd_DO = DO_2840;
  277. sd.sd_DI = DI_2840;
  278. sc = ahc->seep_config;
  279. if (bootverbose)
  280. printf("%s: Reading SEEPROM...", ahc_name(ahc));
  281. have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
  282. /*start_addr*/0, sizeof(*sc)/2);
  283. if (have_seeprom) {
  284. if (ahc_verify_cksum(sc) == 0) {
  285. if(bootverbose)
  286. printf ("checksum error\n");
  287. have_seeprom = 0;
  288. } else if (bootverbose) {
  289. printf("done.\n");
  290. }
  291. }
  292. if (!have_seeprom) {
  293. if (bootverbose)
  294. printf("%s: No SEEPROM available\n", ahc_name(ahc));
  295. ahc->flags |= AHC_USEDEFAULTS;
  296. } else {
  297. /*
  298. * Put the data we've collected down into SRAM
  299. * where ahc_init will find it.
  300. */
  301. int i;
  302. int max_targ;
  303. uint16_t discenable;
  304. max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
  305. discenable = 0;
  306. for (i = 0; i < max_targ; i++){
  307. uint8_t target_settings;
  308. target_settings = (sc->device_flags[i] & CFXFER) << 4;
  309. if (sc->device_flags[i] & CFSYNCH)
  310. target_settings |= SOFS;
  311. if (sc->device_flags[i] & CFWIDEB)
  312. target_settings |= WIDEXFER;
  313. if (sc->device_flags[i] & CFDISC)
  314. discenable |= (0x01 << i);
  315. ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
  316. }
  317. ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
  318. ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
  319. ahc->our_id = sc->brtime_id & CFSCSIID;
  320. scsi_conf = (ahc->our_id & 0x7);
  321. if (sc->adapter_control & CFSPARITY)
  322. scsi_conf |= ENSPCHK;
  323. if (sc->adapter_control & CFRESETB)
  324. scsi_conf |= RESET_SCSI;
  325. if (sc->bios_control & CF284XEXTEND)
  326. ahc->flags |= AHC_EXTENDED_TRANS_A;
  327. /* Set SCSICONF info */
  328. ahc_outb(ahc, SCSICONF, scsi_conf);
  329. if (sc->adapter_control & CF284XSTERM)
  330. ahc->flags |= AHC_TERM_ENB_A;
  331. }
  332. return (have_seeprom);
  333. }
  334. static int
  335. ahc_aic7770_VL_setup(struct ahc_softc *ahc)
  336. {
  337. int error;
  338. error = ahc_aic7770_setup(ahc);
  339. ahc->chip |= AHC_VL;
  340. return (error);
  341. }
  342. static int
  343. ahc_aic7770_EISA_setup(struct ahc_softc *ahc)
  344. {
  345. int error;
  346. error = ahc_aic7770_setup(ahc);
  347. ahc->chip |= AHC_EISA;
  348. return (error);
  349. }
  350. static int
  351. ahc_aic7770_setup(struct ahc_softc *ahc)
  352. {
  353. ahc->channel = 'A';
  354. ahc->channel_b = 'B';
  355. ahc->chip = AHC_AIC7770;
  356. ahc->features = AHC_AIC7770_FE;
  357. ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
  358. ahc->flags |= AHC_PAGESCBS;
  359. ahc->instruction_ram_size = 448;
  360. return (0);
  361. }