Home | History | Annotate | Line # | Download | only in ic
bhavar.h revision 1.10
      1 /*	$NetBSD: bhavar.h,v 1.10 1998/02/06 23:06:48 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1994, 1996, 1997 Charles M. Hannum.  All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by Charles M. Hannum.
     54  * 4. The name of the author may not be used to endorse or promote products
     55  *    derived from this software without specific prior written permission.
     56  *
     57  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67  */
     68 
     69 #include <sys/queue.h>
     70 
     71 /*
     72  * Mail box defs  etc.
     73  * these could be bigger but we need the bha_softc to fit on a single page..
     74  */
     75 #define BHA_MBX_SIZE	32	/* mail box size  (MAX 255 MBxs) */
     76 				/* don't need that many really */
     77 #define BHA_CCB_MAX	32	/* store up to 32 CCBs at one time */
     78 #define	CCB_HASH_SIZE	32	/* hash table size for phystokv */
     79 #define	CCB_HASH_SHIFT	9
     80 #define CCB_HASH(x)	((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1))
     81 
     82 #define bha_nextmbx(wmb, mbx, mbio) \
     83 	if ((wmb) == &(mbx)->mbio[BHA_MBX_SIZE - 1])	\
     84 		(wmb) = &(mbx)->mbio[0];		\
     85 	else						\
     86 		(wmb)++;
     87 
     88 struct bha_mbx {
     89 	struct bha_mbx_out mbo[BHA_MBX_SIZE];
     90 	struct bha_mbx_in mbi[BHA_MBX_SIZE];
     91 	struct bha_mbx_out *cmbo;	/* Collection Mail Box out */
     92 	struct bha_mbx_out *tmbo;	/* Target Mail Box out */
     93 	struct bha_mbx_in *tmbi;	/* Target Mail Box in */
     94 };
     95 
     96 struct bha_control {
     97 	struct bha_mbx bc_mbx;		/* all our mailboxes */
     98 	struct bha_ccb bc_ccbs[BHA_CCB_MAX]; /* all our control blocks */
     99 };
    100 
    101 struct bha_softc {
    102 	struct device sc_dev;
    103 
    104 	bus_space_tag_t sc_iot;
    105 	bus_space_handle_t sc_ioh;
    106 	bus_dma_tag_t sc_dmat;
    107 	bus_dmamap_t sc_dmamap_control;	/* maps the control structures */
    108 	int sc_dmaflags;		/* bus-specific dma map flags */
    109 	void *sc_ih;
    110 
    111 	struct bha_control *sc_control;	/* control structures */
    112 
    113 #define	wmbx	(&sc->sc_control->bc_mbx)
    114 
    115 	struct bha_ccb *sc_ccbhash[CCB_HASH_SIZE];
    116 	TAILQ_HEAD(, bha_ccb) sc_free_ccb, sc_waiting_ccb;
    117 	int sc_mbofull;
    118 	struct scsipi_link sc_link;	/* prototype for devs */
    119 
    120 	LIST_HEAD(, scsipi_xfer) sc_queue;
    121 	struct scsipi_xfer *sc_queuelast;
    122 
    123 	char sc_model[7],
    124 	     sc_firmware[6];
    125 };
    126 
    127 /*
    128  * Offset of a Mail Box In from the beginning of the control DMA mapping.
    129  */
    130 #define	BHA_MBI_OFF(m)	(offsetof(struct bha_control, bc_mbx.mbi[0]) +	\
    131 			    (((u_long)(m)) - ((u_long)&wmbx->mbi[0])))
    132 
    133 /*
    134  * Offset of a Mail Box Out from the beginning of the control DMA mapping.
    135  */
    136 #define	BHA_MBO_OFF(m)	(offsetof(struct bha_control, bc_mbx.mbo[0]) +	\
    137 			    (((u_long)(m)) - ((u_long)&wmbx->mbo[0])))
    138 
    139 /*
    140  * Offset of a CCB from the beginning of the control DMA mapping.
    141  */
    142 #define	BHA_CCB_OFF(c)	(offsetof(struct bha_control, bc_ccbs[0]) +	\
    143 		    (((u_long)(c)) - ((u_long)&sc->sc_control->bc_ccbs[0])))
    144 
    145 struct bha_probe_data {
    146 	int sc_irq, sc_drq;
    147 	int sc_scsi_dev;		/* adapters scsi id */
    148 	int sc_iswide;			/* adapter is wide */
    149 };
    150 
    151 #define	ISWIDE(sc)	(sc->sc_link.scsipi_scsi.max_target >= 8)
    152 
    153 int	bha_find __P((bus_space_tag_t, bus_space_handle_t,
    154 	    struct bha_probe_data *));
    155 void	bha_attach __P((struct bha_softc *, struct bha_probe_data *));
    156 int	bha_intr __P((void *));
    157 
    158 int	bha_disable_isacompat __P((struct bha_softc *));
    159 void	bha_inquire_setup_information __P((struct bha_softc *));
    160