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