1239310Sdim/*	$OpenBSD: adw.h,v 1.11 2020/02/18 20:24:52 krw Exp $ */
2239310Sdim/*      $NetBSD: adw.h,v 1.9 2000/05/26 15:13:43 dante Exp $        */
3239310Sdim
4239310Sdim/*
5239310Sdim * Generic driver definitions and exported functions for the Advanced
6239310Sdim * Systems Inc. SCSI controllers
7239310Sdim *
8239310Sdim * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
9239310Sdim * All rights reserved.
10239310Sdim *
11239310Sdim * Author: Baldassare Dante Profeta <dante@mclink.it>
12239310Sdim *
13239310Sdim * Redistribution and use in source and binary forms, with or without
14239310Sdim * modification, are permitted provided that the following conditions
15239310Sdim * are met:
16249423Sdim * 1. Redistributions of source code must retain the above copyright
17239310Sdim *    notice, this list of conditions and the following disclaimer.
18239310Sdim * 2. Redistributions in binary form must reproduce the above copyright
19239310Sdim *    notice, this list of conditions and the following disclaimer in the
20249423Sdim *    documentation and/or other materials provided with the distribution.
21249423Sdim *
22239310Sdim * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23239310Sdim * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24239310Sdim * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25239310Sdim * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26239310Sdim * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27239310Sdim * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28249423Sdim * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29249423Sdim * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30239310Sdim * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31239310Sdim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32239310Sdim * POSSIBILITY OF SUCH DAMAGE.
33239310Sdim */
34239310Sdim
35249423Sdim#ifndef _ADVANSYS_WIDE_H_
36239310Sdim#define _ADVANSYS_WIDE_H_
37249423Sdim
38239310Sdim/******************************************************************************/
39249423Sdim
40239310Sdimtypedef int (* ADW_ISR_CALLBACK) (ADW_SOFTC *, ADW_SCSI_REQ_Q *);
41249423Sdimtypedef void (* ADW_ASYNC_CALLBACK) (ADW_SOFTC *, u_int8_t);
42239310Sdim
43249423Sdim
44239310Sdim/*
45249423Sdim * per request scatter-gather element limit
46239310Sdim * We could have up to 256 SG lists.
47239310Sdim */
48239310Sdim#define ADW_MAX_SG_LIST		255
49239310Sdim
50239310Sdim/*
51249423Sdim * Scatter-Gather Definitions per request.
52239310Sdim */
53239310Sdim
54239310Sdim#define NO_OF_SG_PER_BLOCK	15
55239310Sdim
56263508Sdim/* Number of SG blocks needed. */
57249423Sdim#define ADW_NUM_SG_BLOCK \
58263508Sdim	((ADW_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK)
59249423Sdim
60239310Sdim
61249423Sdimstruct adw_ccb {
62239310Sdim	ADW_SCSI_REQ_Q		scsiq;
63249423Sdim	ADW_SG_BLOCK		sg_block[ADW_NUM_SG_BLOCK];
64239310Sdim
65249423Sdim	struct scsi_sense_data  scsi_sense;
66239310Sdim
67249423Sdim	TAILQ_ENTRY(adw_ccb)	chain;
68239310Sdim	struct adw_ccb		*nexthash;
69239310Sdim	u_int32_t		hashkey;
70239310Sdim
71239310Sdim	struct scsi_xfer	*xs;	/* the scsi_xfer for this cmd */
72239310Sdim	int			flags;	/* see below */
73239310Sdim
74263508Sdim	int			timeout;
75249423Sdim
76239310Sdim	/*
77239310Sdim	 * This DMA map maps the buffer involved in the transfer.
78239310Sdim	 */
79239310Sdim	bus_dmamap_t		dmamap_xfer;
80239310Sdim};
81249423Sdim
82249423Sdimtypedef struct adw_ccb ADW_CCB;
83239310Sdim
84239310Sdim/* flags for ADW_CCB */
85239310Sdim#define CCB_ALLOC	0x01
86239310Sdim#define CCB_ABORTING	0x02
87239310Sdim#define CCB_ABORTED	0x04
88249423Sdim
89239310Sdim
90249423Sdim#define ADW_MAX_CCB	63	/* Max. number commands per device (63) */
91239310Sdim
92239310Sdimstruct adw_control {
93239310Sdim	ADW_CCB		ccbs[ADW_MAX_CCB];	/* all our control blocks */
94239310Sdim	ADW_CARRIER	*carriers;		/* all our carriers */
95239310Sdim};
96239310Sdim
97239310Sdim/*
98239310Sdim * Offset of a CCB from the beginning of the control DMA mapping.
99249423Sdim */
100249423Sdim#define	ADW_CCB_OFF(c)	(offsetof(struct adw_control, ccbs[0]) +	\
101249423Sdim		    (((u_long)(c)) - ((u_long)&sc->sc_control->ccbs[0])))
102239310Sdim
103239310Sdim/******************************************************************************/
104239310Sdim
105249423Sdimint adw_init(ADW_SOFTC *sc);
106239310Sdimvoid adw_attach(ADW_SOFTC *sc);
107239310Sdimint adw_intr(void *arg);
108239310SdimADW_CCB *adw_ccb_phys_kv(ADW_SOFTC *, u_int32_t);
109249423Sdim
110239310Sdim/******************************************************************************/
111239310Sdim
112249423Sdim#endif /* _ADVANSYS_ADW_H_ */
113249423Sdim