xref: /netbsd-src/sys/dev/ic/ahavar.h (revision c8a52f80baacc22e61f6d0db64f624265cc444e1)
1*c8a52f80Stsutsui /*	$NetBSD: ahavar.h,v 1.15 2009/09/21 08:12:47 tsutsui Exp $	*/
2eda74e61Sthorpej 
3eda74e61Sthorpej /*-
4eda74e61Sthorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5eda74e61Sthorpej  * All rights reserved.
6eda74e61Sthorpej  *
7eda74e61Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
862b1bf3eSmycroft  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
962b1bf3eSmycroft  * Simulation Facility, NASA Ames Research Center.
10eda74e61Sthorpej  *
11eda74e61Sthorpej  * Redistribution and use in source and binary forms, with or without
12eda74e61Sthorpej  * modification, are permitted provided that the following conditions
13eda74e61Sthorpej  * are met:
14eda74e61Sthorpej  * 1. Redistributions of source code must retain the above copyright
15eda74e61Sthorpej  *    notice, this list of conditions and the following disclaimer.
16eda74e61Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
17eda74e61Sthorpej  *    notice, this list of conditions and the following disclaimer in the
18eda74e61Sthorpej  *    documentation and/or other materials provided with the distribution.
19eda74e61Sthorpej  *
20eda74e61Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21eda74e61Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22eda74e61Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23eda74e61Sthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24eda74e61Sthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25eda74e61Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26eda74e61Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27eda74e61Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28eda74e61Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29eda74e61Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30eda74e61Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
31eda74e61Sthorpej  */
321dd15049Smycroft 
338b2ffcedSthorpej #ifndef _DEV_IC_AHAVAR_H_
348b2ffcedSthorpej #define	_DEV_IC_AHAVAR_H_
358b2ffcedSthorpej 
3603a0c2d9Sthorpej #include <sys/queue.h>
3703a0c2d9Sthorpej 
381dd15049Smycroft /*
391dd15049Smycroft  * Mail box defs  etc.
401dd15049Smycroft  * these could be bigger but we need the aha_softc to fit on a single page..
411dd15049Smycroft  */
421dd15049Smycroft #define AHA_MBX_SIZE	16	/* mail box size  (MAX 255 MBxs) */
431dd15049Smycroft 				/* don't need that many really */
441dd15049Smycroft #define AHA_CCB_MAX	16	/* store up to 16 CCBs at one time */
451dd15049Smycroft #define	CCB_HASH_SIZE	16	/* hash table size for phystokv */
461dd15049Smycroft #define	CCB_HASH_SHIFT	9
471dd15049Smycroft #define CCB_HASH(x)	((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1))
481dd15049Smycroft 
491dd15049Smycroft #define aha_nextmbx(wmb, mbx, mbio) \
501dd15049Smycroft 	if ((wmb) == &(mbx)->mbio[AHA_MBX_SIZE - 1])	\
511dd15049Smycroft 		(wmb) = &(mbx)->mbio[0];		\
521dd15049Smycroft 	else						\
531dd15049Smycroft 		(wmb)++;
541dd15049Smycroft 
551dd15049Smycroft struct aha_mbx {
561dd15049Smycroft 	struct aha_mbx_out mbo[AHA_MBX_SIZE];
571dd15049Smycroft 	struct aha_mbx_in mbi[AHA_MBX_SIZE];
581dd15049Smycroft 	struct aha_mbx_out *cmbo;	/* Collection Mail Box out */
591dd15049Smycroft 	struct aha_mbx_out *tmbo;	/* Target Mail Box out */
601dd15049Smycroft 	struct aha_mbx_in *tmbi;	/* Target Mail Box in */
611dd15049Smycroft };
621dd15049Smycroft 
63eda74e61Sthorpej struct aha_control {
64eda74e61Sthorpej 	struct aha_mbx ac_mbx;		/* all our mailboxes */
65eda74e61Sthorpej 	struct aha_ccb ac_ccbs[AHA_CCB_MAX]; /* all our control blocks */
66eda74e61Sthorpej };
67eda74e61Sthorpej 
681dd15049Smycroft struct aha_softc {
69*c8a52f80Stsutsui 	device_t sc_dev;
70080350dcSmycroft 
711dd15049Smycroft 	bus_space_tag_t sc_iot;
721dd15049Smycroft 	bus_space_handle_t sc_ioh;
73fbc0df0aSthorpej 	bus_dma_tag_t sc_dmat;
74eda74e61Sthorpej 	bus_dmamap_t sc_dmamap_control;	/* maps the control structures */
751dd15049Smycroft 	void *sc_ih;
761dd15049Smycroft 
77eda74e61Sthorpej 	struct aha_control *sc_control;	/* control structures */
78eda74e61Sthorpej 
79eda74e61Sthorpej #define	wmbx	(&sc->sc_control->ac_mbx)
80eda74e61Sthorpej 
811dd15049Smycroft 	struct aha_ccb *sc_ccbhash[CCB_HASH_SIZE];
821dd15049Smycroft 	TAILQ_HEAD(, aha_ccb) sc_free_ccb, sc_waiting_ccb;
83eda74e61Sthorpej 	int sc_mbofull;
84080350dcSmycroft 
85937a7a3eSbouyer 	struct scsipi_adapter sc_adapter;
86937a7a3eSbouyer 	struct scsipi_channel sc_channel;
8703a0c2d9Sthorpej 
88080350dcSmycroft 	char sc_model[18],
89080350dcSmycroft 	     sc_firmware[4];
90080350dcSmycroft };
91080350dcSmycroft 
92eda74e61Sthorpej /*
93eda74e61Sthorpej  * Offset of a Mail Box In from the beginning of the control DMA mapping.
94eda74e61Sthorpej  */
95eda74e61Sthorpej #define	AHA_MBI_OFF(m)	(offsetof(struct aha_control, ac_mbx.mbi[0]) +	\
96eda74e61Sthorpej 			    (((u_long)(m)) - ((u_long)&wmbx->mbi[0])))
97eda74e61Sthorpej 
98eda74e61Sthorpej /*
99eda74e61Sthorpej  * Offset of a Mail Box Out from the beginning of the control DMA mapping.
100eda74e61Sthorpej  */
101eda74e61Sthorpej #define	AHA_MBO_OFF(m)	(offsetof(struct aha_control, ac_mbx.mbo[0]) +	\
102eda74e61Sthorpej 			    (((u_long)(m)) - ((u_long)&wmbx->mbo[0])))
103eda74e61Sthorpej 
104eda74e61Sthorpej /*
105eda74e61Sthorpej  * Offset of a CCB from the beginning of the control DMA mapping.
106eda74e61Sthorpej  */
107eda74e61Sthorpej #define	AHA_CCB_OFF(c)	(offsetof(struct aha_control, ac_ccbs[0]) +	\
108eda74e61Sthorpej 		    (((u_long)(c)) - ((u_long)&sc->sc_control->ac_ccbs[0])))
109eda74e61Sthorpej 
110080350dcSmycroft struct aha_probe_data {
111080350dcSmycroft 	int sc_irq, sc_drq;
112080350dcSmycroft 	int sc_scsi_dev;		/* adapters scsi id */
1131dd15049Smycroft };
1141dd15049Smycroft 
1158b2ffcedSthorpej int	aha_find(bus_space_tag_t, bus_space_handle_t,
1168b2ffcedSthorpej 	    struct aha_probe_data *);
1178b2ffcedSthorpej void	aha_attach(struct aha_softc *, struct aha_probe_data *);
1188b2ffcedSthorpej int	aha_intr(void *);
1198b2ffcedSthorpej 
1208b2ffcedSthorpej #endif /* _DEV_IC_AHAVAR_H_ */
121