aic7xxxvar.h revision 1.8 1 /* $NetBSD: aic7xxxvar.h,v 1.8 1996/07/10 22:50:48 explorer Exp $ */
2
3 /*
4 * Interface to the generic driver for the aic7xxx based adaptec
5 * SCSI controllers. This is used to implement product specific
6 * probe and attach routines.
7 *
8 * Copyright (c) 1994, 1995, 1996 Justin T. Gibbs.
9 * All rights reserved.
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 immediately at the beginning of the file, without modification,
16 * 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. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from Id: aic7xxx.h,v 1.28 1996/05/30 07:19:59 gibbs Exp
36 */
37
38 #ifndef _AIC7XXX_H_
39 #define _AIC7XXX_H_
40
41 #if defined(__FreeBSD__)
42 #include "ahc.h" /* for NAHC from config */
43 #endif
44
45 #if defined(__NetBSD__)
46 /*
47 * convert FreeBSD's <sys/queue.h> symbols to NetBSD's
48 */
49 #define STAILQ_ENTRY SIMPLEQ_ENTRY
50 #define STAILQ_HEAD SIMPLEQ_HEAD
51 #define STAILQ_INIT SIMPLEQ_INIT
52 #define STAILQ_INSERT_HEAD SIMPLEQ_INSERT_HEAD
53 #define STAILQ_INSERT_TAIL SIMPLEQ_INSERT_TAIL
54 #define STAILQ_REMOVE_HEAD(head, field) \
55 SIMPLEQ_REMOVE_HEAD(head, (head)->sqh_first, field)
56 #define stqh_first sqh_first
57 #define stqe_next sqe_next
58 #endif
59
60 #if defined(__FreeBSD__)
61 #define AHC_INB(ahc, port) \
62 inb((ahc)->baseport+(port))
63 #define AHC_INSB(ahc, port, valp, size) \
64 insb((ahc)->baseport+(port), valp, size)
65 #define AHC_OUTB(ahc, port, val) \
66 outb((ahc)->baseport+(port), val)
67 #define AHC_OUTSB(ahc, port, valp, size) \
68 outsb((ahc)->baseport+(port), valp, size)
69 #define AHC_OUTSL(ahc, port, valp, size) \
70 outsl((ahc)->baseport+(port), valp, size)
71 #elif defined(__NetBSD__)
72 #define AHC_INB(ahc, port) \
73 bus_io_read_1((ahc)->sc_bc, (ahc)->sc_ioh, port)
74 #define AHC_INSB(ahc, port, valp, size) \
75 bus_io_read_multi_1((ahc)->sc_bc, (ahc)->sc_ioh, port, valp, size)
76 #define AHC_OUTB(ahc, port, val) \
77 bus_io_write_1((ahc)->sc_bc, (ahc)->sc_ioh, port, val)
78 #define AHC_OUTSB(ahc, port, valp, size) \
79 bus_io_write_multi_1((ahc)->sc_bc, (ahc)->sc_ioh, port, valp, size)
80 #define AHC_OUTSL(ahc, port, valp, size) \
81 bus_io_write_multi_4((ahc)->sc_bc, (ahc)->sc_ioh, port, valp, size)
82 #endif
83
84 #define AHC_NSEG 256 /* number of dma segments supported */
85
86 #define AHC_SCB_MAX 255 /*
87 * Up to 255 SCBs on some types of aic7xxx
88 * based boards. The aic7870 have 16 internal
89 * SCBs, but external SRAM bumps this to 255.
90 * The aic7770 family have only 4, and the
91 * aic7850 has only 3.
92 */
93
94
95 typedef unsigned long int physaddr;
96 #if defined(__FreeBSD__)
97 extern u_long ahc_unit;
98 #endif
99
100 struct ahc_dma_seg {
101 physaddr addr;
102 long len;
103 };
104
105 typedef enum {
106 AHC_NONE = 0x000,
107 AHC_ULTRA = 0x001, /* Supports 20MHz Transfers */
108 AHC_WIDE = 0x002, /* Wide Channel */
109 AHC_TWIN = 0x008, /* Twin Channel */
110 AHC_AIC7770 = 0x010,
111 AHC_AIC7850 = 0x020,
112 AHC_AIC7860 = 0x021, /* ULTRA version of the aic7850 */
113 AHC_AIC7870 = 0x040,
114 AHC_AIC7880 = 0x041,
115 AHC_AIC78X0 = 0x060, /* PCI Based Controller */
116 AHC_274 = 0x110, /* EISA Based Controller */
117 AHC_284 = 0x210, /* VL/ISA Based Controller */
118 AHC_294 = 0x440, /* PCI Based Controller */
119 AHC_294U = 0x441, /* ULTRA PCI Based Controller */
120 AHC_394 = 0x840, /* Twin Channel PCI Controller */
121 AHC_394U = 0x841, /* Twin, ULTRA Channel PCI Controller */
122 }ahc_type;
123
124 typedef enum {
125 AHC_FNONE = 0x00,
126 AHC_INIT = 0x01,
127 AHC_RUNNING = 0x02,
128 AHC_PAGESCBS = 0x04, /* Enable SCB paging */
129 AHC_CHANNEL_B_PRIMARY = 0x08, /*
130 * On twin channel adapters, probe
131 * channel B first since it is the
132 * primary bus.
133 */
134 AHC_USEDEFAULTS = 0x10, /*
135 * For cards without an seeprom
136 * or a BIOS to initialize the chip's
137 * SRAM, we use the default target
138 * settings.
139 */
140 AHC_CHNLB = 0x20, /*
141 * Second controller on 3940
142 * Also encodes the offset in the
143 * SEEPROM for CHNLB info (32)
144 */
145 }ahc_flag;
146
147 typedef enum {
148 SCB_FREE = 0x000,
149 SCB_ACTIVE = 0x001,
150 SCB_ABORTED = 0x002,
151 SCB_DEVICE_RESET = 0x004,
152 SCB_IMMED = 0x008,
153 SCB_SENSE = 0x010,
154 SCB_TIMEDOUT = 0x020,
155 SCB_QUEUED_FOR_DONE = 0x040,
156 SCB_PAGED_OUT = 0x080,
157 SCB_WAITINGQ = 0x100,
158 SCB_ASSIGNEDQ = 0x200,
159 SCB_SENTORDEREDTAG = 0x400
160 }scb_flag;
161
162 /*
163 * The driver keeps up to MAX_SCB scb structures per card in memory. Only the
164 * first 28 bytes of the structure need to be transfered to the card during
165 * normal operation. The fields starting at byte 28 are used for kernel level
166 * bookkeeping.
167 */
168 struct scb {
169 /* ------------ Begin hardware supported fields ---------------- */
170 /*0*/ u_char control;
171 /*1*/ u_char tcl; /* 4/1/3 bits */
172 /*2*/ u_char status;
173 /*3*/ u_char SG_segment_count;
174 /*4*/ physaddr SG_list_pointer;
175 /*8*/ u_char residual_SG_segment_count;
176 /*9*/ u_char residual_data_count[3];
177 /*12*/ physaddr data;
178 /*16*/ u_long datalen; /* Really only three bits, but its
179 * faster to treat it as a long on
180 * a quad boundary.
181 */
182 /*20*/ physaddr cmdpointer;
183 /*24*/ u_char cmdlen;
184 /*25*/ u_char tag; /* Index into our kernel SCB array.
185 * Also used as the tag for tagged I/O
186 */
187 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
188 * via PIO to initialize a transaction.
189 */
190 /*26*/ u_char next; /* Used for threading SCBs in the
191 * "Waiting for Selection" and
192 * "Disconnected SCB" lists down
193 * in the sequencer.
194 */
195 /*27*/ u_char prev;
196 /*-----------------end of hardware supported fields----------------*/
197 STAILQ_ENTRY(scb) links; /* for chaining */
198 struct scsi_xfer *xs; /* the scsi_xfer for this cmd */
199 scb_flag flags;
200 u_char position; /* Position in card's scbarray */
201 struct ahc_dma_seg ahc_dma[AHC_NSEG] __attribute__ ((packed));
202 struct scsi_sense sense_cmd; /* SCSI command block */
203 };
204
205 struct ahc_data {
206 #if defined(__FreeBSD__)
207 int unit;
208 #elif defined(__NetBSD__)
209 struct device sc_dev;
210 void *sc_ih;
211 bus_chipset_tag_t sc_bc;
212 bus_io_handle_t sc_ioh;
213 #endif
214 ahc_type type;
215 ahc_flag flags;
216 #if defined(__FreeBSD__)
217 u_long baseport;
218 #endif
219 struct scb *scbarray[AHC_SCB_MAX]; /* Mirror boards scbarray */
220 struct scb *pagedout_ntscbs[16];/*
221 * Paged out, non-tagged scbs
222 * indexed by target.
223 */
224 STAILQ_HEAD(, scb) free_scbs; /*
225 * SCBs assigned to free slots
226 * on the card. (no paging required)
227 */
228 STAILQ_HEAD(, scb) page_scbs; /*
229 * SCBs that will require paging
230 * before use (no assigned slot)
231 */
232 STAILQ_HEAD(, scb) waiting_scbs;/*
233 * SCBs waiting to be paged in
234 * and started.
235 */
236 STAILQ_HEAD(, scb)assigned_scbs;/*
237 * SCBs that were waiting but have
238 * now been assigned a slot by
239 * ahc_free_scb.
240 */
241 struct scsi_link sc_link;
242 struct scsi_link sc_link_b; /* Second bus for Twin channel cards */
243 u_short needsdtr_orig; /* Targets we initiate sync neg with */
244 u_short needwdtr_orig; /* Targets we initiate wide neg with */
245 u_short needsdtr; /* Current list of negotiated targets */
246 u_short needwdtr; /* Current list of negotiated targets */
247 u_short sdtrpending; /* Pending SDTR to these targets */
248 u_short wdtrpending; /* Pending WDTR to these targets */
249 u_short tagenable; /* Targets that can handle tagqueing */
250 u_short orderedtag; /* Targets to use ordered tag on */
251 u_short discenable; /* Targets allowed to disconnect */
252 u_char our_id; /* our scsi id */
253 u_char our_id_b; /* B channel scsi id */
254 u_char numscbs;
255 u_char activescbs;
256 u_char maxhscbs; /* Number of SCBs on the card */
257 u_char maxscbs; /*
258 * Max SCBs we allocate total including
259 * any that will force us to page SCBs
260 */
261 u_char qcntmask;
262 u_char unpause;
263 u_char pause;
264 u_char in_timeout;
265 };
266
267 /* #define AHC_DEBUG */
268 #ifdef AHC_DEBUG
269 /* Different debugging levels used when AHC_DEBUG is defined */
270 #define AHC_SHOWMISC 0x0001
271 #define AHC_SHOWCMDS 0x0002
272 #define AHC_SHOWSCBS 0x0004
273 #define AHC_SHOWABORTS 0x0008
274 #define AHC_SHOWSENSE 0x0010
275 #define AHC_SHOWSCBCNT 0x0020
276
277 extern int ahc_debug; /* Initialized in i386/scsi/aic7xxx.c */
278 #endif
279
280 #if defined(__FreeBSD__)
281
282 char *ahc_name __P((struct ahc_data *ahc));
283
284 void ahc_reset __P((u_long iobase));
285 struct ahc_data *ahc_alloc __P((int unit, u_long io_base, ahc_type type, ahc_flag flags));
286 #elif defined(__NetBSD__)
287
288 #define ahc_name(ahc) (ahc)->sc_dev.dv_xname
289
290 void ahc_reset __P((char *devname, bus_chipset_tag_t bc, bus_io_handle_t ioh));
291 void ahc_construct __P((struct ahc_data *ahc, bus_chipset_tag_t bc, bus_io_handle_t ioh, ahc_type type, ahc_flag flags));
292 #endif
293 void ahc_free __P((struct ahc_data *));
294 int ahc_init __P((struct ahc_data *));
295 int ahc_attach __P((struct ahc_data *));
296 #if defined(__FreeBSD__)
297 void ahc_intr __P((void *arg));
298 #elif defined(__NetBSD__)
299 int ahc_intr __P((void *arg));
300 #endif
301
302 #endif /* _AIC7XXX_H_ */
303