aic7770.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:9k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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