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