Home | History | Annotate | Line # | Download | only in ic
aic77xx.c revision 1.3
      1 /*	$NetBSD: aic77xx.c,v 1.3 2003/04/19 19:33:29 fvdl Exp $	*/
      2 
      3 /*
      4  * Common routines for AHA-27/284X and aic7770 motherboard SCSI controllers.
      5  *
      6  * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice immediately at the beginning of the file, without modification,
     14  *    this list of conditions, and the following disclaimer.
     15  * 2. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     22  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  *
     30  * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: aic77xx.c,v 1.3 2003/04/19 19:33:29 fvdl Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <machine/bus.h>
     41 #include <machine/intr.h>
     42 
     43 #include <dev/scsipi/scsi_all.h>
     44 #include <dev/scsipi/scsipi_all.h>
     45 #include <dev/scsipi/scsiconf.h>
     46 
     47 #include <dev/ic/aic7xxx_osm.h>
     48 #include <dev/ic/aic7xxx_inline.h>
     49 #include <dev/ic/aic77xxreg.h>
     50 #include <dev/ic/aic77xxvar.h>
     51 
     52 /*
     53  * Return irq setting of the board, otherwise -1.
     54  */
     55 int
     56 ahc_aic77xx_irq(iot, ioh)
     57 	bus_space_tag_t iot;
     58 	bus_space_handle_t ioh;
     59 {
     60 	int irq;
     61 	u_int8_t intdef;
     62 	u_int8_t hcntrl;
     63 
     64 	/* Pause the card preseving the IRQ type */
     65 	hcntrl = bus_space_read_1(iot, ioh, HCNTRL) & IRQMS;
     66 	bus_space_write_1(iot, ioh, HCNTRL, hcntrl | PAUSE);
     67 
     68 	intdef = bus_space_read_1(iot, ioh, INTDEF);
     69 	irq = (intdef & INTDEF_IRQ_MASK);
     70 	switch (irq) {
     71 	case 9:
     72 	case 10:
     73 	case 11:
     74 	case 12:
     75 	case 14:
     76 	case 15:
     77 		break;
     78 	default:
     79 		printf("ahc_aic77xx_irq: illegal irq setting %d\n", intdef);
     80 		return (-1);
     81 	}
     82 
     83 	return (irq);
     84 }
     85 
     86 int
     87 ahc_aic77xx_attach(ahc)
     88 	struct ahc_softc *ahc;
     89 {
     90 	char *id_string;
     91 	u_int8_t sblkctl;
     92 	u_int8_t sblkctl_orig;
     93 	u_int8_t hostconf;
     94 
     95 	/*
     96 	 * See if we have a Rev E or higher aic7770. Anything below a
     97 	 * Rev E will have a R/O autoflush disable configuration bit.
     98 	 */
     99 	sblkctl_orig = ahc_inb(ahc, SBLKCTL);
    100 	sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
    101 	ahc_outb(ahc, SBLKCTL, sblkctl);
    102 	sblkctl = ahc_inb(ahc, SBLKCTL);
    103 	if (sblkctl != sblkctl_orig) {
    104 		id_string = "aic7770 >= Rev E, ";
    105 		/*
    106 		 * Ensure autoflush is enabled
    107 		 */
    108 		sblkctl &= ~AUTOFLUSHDIS;
    109 		ahc_outb(ahc, SBLKCTL, sblkctl);
    110 	} else
    111 		id_string = "aic7770 <= Rev C, ";
    112 
    113 	printf("%s: %s", ahc_name(ahc), id_string);
    114 
    115 	/* Setup the FIFO threshold and the bus off time */
    116 	hostconf = ahc_inb(ahc, HOSTCONF);
    117 	ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
    118 	ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
    119 
    120 	/*
    121 	 * Generic aic7xxx initialization.
    122 	 */
    123 	if (ahc_init(ahc)) {
    124 		/*
    125 		 * The board's IRQ line is not yet enabled so it's safe
    126 		 * to release the irq.
    127 		 */
    128 		return (ENXIO);
    129 	}
    130 
    131 	/*
    132 	 * Enable the board's BUS drivers
    133 	 */
    134 	ahc_outb(ahc, BCTL, ENABLE);
    135 
    136 	/* Attach sub-devices - always succeeds */
    137 	ahc_attach(ahc);
    138 
    139 	return 0;
    140 }
    141