190792Sgshapiro/*	$NetBSD: ahavar.h,v 1.14 2008/04/28 20:23:49 martin Exp $	*/
2261363Sgshapiro
390792Sgshapiro/*-
490792Sgshapiro * Copyright (c) 1998 The NetBSD Foundation, Inc.
590792Sgshapiro * All rights reserved.
690792Sgshapiro *
790792Sgshapiro * This code is derived from software contributed to The NetBSD Foundation
890792Sgshapiro * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
990792Sgshapiro * Simulation Facility, NASA Ames Research Center.
1090792Sgshapiro *
11266692Sgshapiro * Redistribution and use in source and binary forms, with or without
1290792Sgshapiro * modification, are permitted provided that the following conditions
1390792Sgshapiro * are met:
1490792Sgshapiro * 1. Redistributions of source code must retain the above copyright
1590792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1690792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1790792Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1890792Sgshapiro *    documentation and/or other materials provided with the distribution.
1990792Sgshapiro *
2090792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2190792Sgshapiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2290792Sgshapiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2390792Sgshapiro * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2490792Sgshapiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2590792Sgshapiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2690792Sgshapiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2790792Sgshapiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2890792Sgshapiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2990792Sgshapiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3090792Sgshapiro * POSSIBILITY OF SUCH DAMAGE.
3190792Sgshapiro */
3290792Sgshapiro
3390792Sgshapiro#ifndef _DEV_IC_AHAVAR_H_
3490792Sgshapiro#define	_DEV_IC_AHAVAR_H_
3590792Sgshapiro
3690792Sgshapiro#include <sys/queue.h>
3790792Sgshapiro
3890792Sgshapiro/*
3990792Sgshapiro * Mail box defs  etc.
4090792Sgshapiro * these could be bigger but we need the aha_softc to fit on a single page..
4190792Sgshapiro */
4290792Sgshapiro#define AHA_MBX_SIZE	16	/* mail box size  (MAX 255 MBxs) */
4390792Sgshapiro				/* don't need that many really */
4490792Sgshapiro#define AHA_CCB_MAX	16	/* store up to 16 CCBs at one time */
4590792Sgshapiro#define	CCB_HASH_SIZE	16	/* hash table size for phystokv */
4690792Sgshapiro#define	CCB_HASH_SHIFT	9
4790792Sgshapiro#define CCB_HASH(x)	((((long)(x))>>CCB_HASH_SHIFT) & (CCB_HASH_SIZE - 1))
4890792Sgshapiro
4990792Sgshapiro#define aha_nextmbx(wmb, mbx, mbio) \
5090792Sgshapiro	if ((wmb) == &(mbx)->mbio[AHA_MBX_SIZE - 1])	\
5190792Sgshapiro		(wmb) = &(mbx)->mbio[0];		\
5290792Sgshapiro	else						\
5390792Sgshapiro		(wmb)++;
5490792Sgshapiro
5590792Sgshapirostruct aha_mbx {
5690792Sgshapiro	struct aha_mbx_out mbo[AHA_MBX_SIZE];
5790792Sgshapiro	struct aha_mbx_in mbi[AHA_MBX_SIZE];
5890792Sgshapiro	struct aha_mbx_out *cmbo;	/* Collection Mail Box out */
5990792Sgshapiro	struct aha_mbx_out *tmbo;	/* Target Mail Box out */
6090792Sgshapiro	struct aha_mbx_in *tmbi;	/* Target Mail Box in */
6190792Sgshapiro};
6290792Sgshapiro
6390792Sgshapirostruct aha_control {
6490792Sgshapiro	struct aha_mbx ac_mbx;		/* all our mailboxes */
6590792Sgshapiro	struct aha_ccb ac_ccbs[AHA_CCB_MAX]; /* all our control blocks */
6690792Sgshapiro};
6790792Sgshapiro
6890792Sgshapirostruct aha_softc {
6990792Sgshapiro	device_t sc_dev;
70
71	bus_space_tag_t sc_iot;
72	bus_space_handle_t sc_ioh;
73	bus_dma_tag_t sc_dmat;
74	bus_dmamap_t sc_dmamap_control;	/* maps the control structures */
75	void *sc_ih;
76
77	struct aha_control *sc_control;	/* control structures */
78
79#define	wmbx	(&sc->sc_control->ac_mbx)
80
81	struct aha_ccb *sc_ccbhash[CCB_HASH_SIZE];
82	TAILQ_HEAD(, aha_ccb) sc_free_ccb, sc_waiting_ccb;
83	int sc_mbofull;
84
85	struct scsipi_adapter sc_adapter;
86	struct scsipi_channel sc_channel;
87
88	char sc_model[18],
89	     sc_firmware[4];
90};
91
92/*
93 * Offset of a Mail Box In from the beginning of the control DMA mapping.
94 */
95#define	AHA_MBI_OFF(m)	(offsetof(struct aha_control, ac_mbx.mbi[0]) +	\
96			    (((u_long)(m)) - ((u_long)&wmbx->mbi[0])))
97
98/*
99 * Offset of a Mail Box Out from the beginning of the control DMA mapping.
100 */
101#define	AHA_MBO_OFF(m)	(offsetof(struct aha_control, ac_mbx.mbo[0]) +	\
102			    (((u_long)(m)) - ((u_long)&wmbx->mbo[0])))
103
104/*
105 * Offset of a CCB from the beginning of the control DMA mapping.
106 */
107#define	AHA_CCB_OFF(c)	(offsetof(struct aha_control, ac_ccbs[0]) +	\
108		    (((u_long)(c)) - ((u_long)&sc->sc_control->ac_ccbs[0])))
109
110struct aha_probe_data {
111	int sc_irq, sc_drq;
112	int sc_scsi_dev;		/* adapters scsi id */
113};
114
115int	aha_find(bus_space_tag_t, bus_space_handle_t,
116	    struct aha_probe_data *);
117void	aha_attach(struct aha_softc *, struct aha_probe_data *);
118int	aha_intr(void *);
119
120#endif /* _DEV_IC_AHAVAR_H_ */
121