aic7xxxvar.h revision 1.11 1 /* $NetBSD: aic7xxxvar.h,v 1.11 1996/12/02 19:06:44 thorpej 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_space_read_1((ahc)->sc_iot, (ahc)->sc_ioh, port)
74 #define AHC_INSB(ahc, port, valp, size) \
75 bus_space_read_multi_1((ahc)->sc_iot, (ahc)->sc_ioh, port, valp, size)
76 #define AHC_OUTB(ahc, port, val) \
77 bus_space_write_1((ahc)->sc_iot, (ahc)->sc_ioh, port, val)
78 #define AHC_OUTSB(ahc, port, valp, size) \
79 bus_space_write_multi_1((ahc)->sc_iot, (ahc)->sc_ioh, port, valp, size)
80 #define AHC_OUTSL(ahc, port, valp, size) \
81 bus_space_write_multi_4((ahc)->sc_iot, (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 u_int32_t physaddr;
96 #if defined(__FreeBSD__)
97 extern u_long ahc_unit;
98 #endif
99
100 struct ahc_dma_seg {
101 physaddr addr;
102 u_int32_t 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_294AU = 0x421, /* aic7860 based '2940' */
119 AHC_294 = 0x440, /* PCI Based Controller */
120 AHC_294U = 0x441, /* ULTRA PCI Based Controller */
121 AHC_394 = 0x840, /* Twin Channel PCI Controller */
122 AHC_394U = 0x841, /* Twin, ULTRA Channel PCI Controller */
123 }ahc_type;
124
125 typedef enum {
126 AHC_FNONE = 0x00,
127 AHC_INIT = 0x01,
128 AHC_RUNNING = 0x02,
129 AHC_PAGESCBS = 0x04, /* Enable SCB paging */
130 AHC_CHANNEL_B_PRIMARY = 0x08, /*
131 * On twin channel adapters, probe
132 * channel B first since it is the
133 * primary bus.
134 */
135 AHC_USEDEFAULTS = 0x10, /*
136 * For cards without an seeprom
137 * or a BIOS to initialize the chip's
138 * SRAM, we use the default target
139 * settings.
140 */
141 AHC_CHNLB = 0x20, /*
142 * Second controller on 3940
143 * Also encodes the offset in the
144 * SEEPROM for CHNLB info (32)
145 */
146 }ahc_flag;
147
148 typedef enum {
149 SCB_FREE = 0x0000,
150 SCB_ACTIVE = 0x0001,
151 SCB_ABORTED = 0x0002,
152 SCB_DEVICE_RESET = 0x0004,
153 SCB_IMMED = 0x0008,
154 SCB_SENSE = 0x0010,
155 SCB_TIMEDOUT = 0x0020,
156 SCB_QUEUED_FOR_DONE = 0x0040,
157 SCB_PAGED_OUT = 0x0080,
158 SCB_WAITINGQ = 0x0100,
159 SCB_ASSIGNEDQ = 0x0200,
160 SCB_SENTORDEREDTAG = 0x0400,
161 SCB_MSGOUT_SDTR = 0x0800,
162 SCB_MSGOUT_WDTR = 0x1000
163 }scb_flag;
164
165 /*
166 * The driver keeps up to MAX_SCB scb structures per card in memory. Only the
167 * first 28 bytes of the structure need to be transfered to the card during
168 * normal operation. The fields starting at byte 28 are used for kernel level
169 * bookkeeping.
170 */
171 struct scb {
172 /* ------------ Begin hardware supported fields ---------------- */
173 /*0*/ u_char control;
174 /*1*/ u_char tcl; /* 4/1/3 bits */
175 /*2*/ u_char status;
176 /*3*/ u_char SG_segment_count;
177 /*4*/ physaddr SG_list_pointer;
178 /*8*/ u_char residual_SG_segment_count;
179 /*9*/ u_char residual_data_count[3];
180 /*12*/ physaddr data;
181 /*16*/ u_int32_t datalen; /* Really only three bits, but its
182 * faster to treat it as a long on
183 * a quad boundary.
184 */
185 /*20*/ physaddr cmdpointer;
186 /*24*/ u_char cmdlen;
187 /*25*/ u_char tag; /* Index into our kernel SCB array.
188 * Also used as the tag for tagged I/O
189 */
190 #define SCB_PIO_TRANSFER_SIZE 26 /* amount we need to upload/download
191 * via PIO to initialize a transaction.
192 */
193 /*26*/ u_char next; /* Used for threading SCBs in the
194 * "Waiting for Selection" and
195 * "Disconnected SCB" lists down
196 * in the sequencer.
197 */
198 /*27*/ u_char prev;
199 /*-----------------end of hardware supported fields----------------*/
200 STAILQ_ENTRY(scb) links; /* for chaining */
201 struct scsi_xfer *xs; /* the scsi_xfer for this cmd */
202 scb_flag flags;
203 u_char position; /* Position in card's scbarray */
204 struct ahc_dma_seg ahc_dma[AHC_NSEG] __attribute__ ((packed));
205 struct scsi_sense sense_cmd; /* SCSI command block */
206 };
207
208 struct ahc_data {
209 #if defined(__FreeBSD__)
210 int unit;
211 #elif defined(__NetBSD__)
212 struct device sc_dev;
213 void *sc_ih;
214 bus_space_tag_t sc_iot;
215 bus_space_handle_t sc_ioh;
216 LIST_HEAD(, scsi_xfer) sc_xxxq; /* XXX software request queue */
217 struct scsi_xfer *sc_xxxqlast; /* last entry in queue */
218 #endif
219 ahc_type type;
220 ahc_flag flags;
221 #if defined(__FreeBSD__)
222 u_long baseport;
223 #endif
224 struct scb *scbarray[AHC_SCB_MAX]; /* Mirror boards scbarray */
225 struct scb *pagedout_ntscbs[16];/*
226 * Paged out, non-tagged scbs
227 * indexed by target.
228 */
229 STAILQ_HEAD(, scb) free_scbs; /*
230 * SCBs assigned to free slots
231 * on the card. (no paging required)
232 */
233 STAILQ_HEAD(, scb) page_scbs; /*
234 * SCBs that will require paging
235 * before use (no assigned slot)
236 */
237 STAILQ_HEAD(, scb) waiting_scbs;/*
238 * SCBs waiting to be paged in
239 * and started.
240 */
241 STAILQ_HEAD(, scb)assigned_scbs;/*
242 * SCBs that were waiting but have
243 * now been assigned a slot by
244 * ahc_free_scb.
245 */
246 struct scsi_link sc_link;
247 struct scsi_link sc_link_b; /* Second bus for Twin channel cards */
248 u_short needsdtr_orig; /* Targets we initiate sync neg with */
249 u_short needwdtr_orig; /* Targets we initiate wide neg with */
250 u_short needsdtr; /* Current list of negotiated targets */
251 u_short needwdtr; /* Current list of negotiated targets */
252 u_short sdtrpending; /* Pending SDTR to these targets */
253 u_short wdtrpending; /* Pending WDTR to these targets */
254 u_short tagenable; /* Targets that can handle tagqueing */
255 u_short orderedtag; /* Targets to use ordered tag on */
256 u_short discenable; /* Targets allowed to disconnect */
257 u_char our_id; /* our scsi id */
258 u_char our_id_b; /* B channel scsi id */
259 u_char numscbs;
260 u_char activescbs;
261 u_char maxhscbs; /* Number of SCBs on the card */
262 u_char maxscbs; /*
263 * Max SCBs we allocate total including
264 * any that will force us to page SCBs
265 */
266 u_char qcntmask;
267 u_char unpause;
268 u_char pause;
269 u_char in_timeout;
270 };
271
272 /* #define AHC_DEBUG */
273 #ifdef AHC_DEBUG
274 /* Different debugging levels used when AHC_DEBUG is defined */
275 #define AHC_SHOWMISC 0x0001
276 #define AHC_SHOWCMDS 0x0002
277 #define AHC_SHOWSCBS 0x0004
278 #define AHC_SHOWABORTS 0x0008
279 #define AHC_SHOWSENSE 0x0010
280 #define AHC_SHOWSCBCNT 0x0020
281
282 extern int ahc_debug; /* Initialized in i386/scsi/aic7xxx.c */
283 #endif
284
285 #if defined(__FreeBSD__)
286
287 char *ahc_name __P((struct ahc_data *ahc));
288
289 void ahc_reset __P((u_long iobase));
290 struct ahc_data *ahc_alloc __P((int unit, u_long io_base, ahc_type type, ahc_flag flags));
291 #elif defined(__NetBSD__)
292
293 #define ahc_name(ahc) (ahc)->sc_dev.dv_xname
294
295 void ahc_reset __P((char *devname, bus_space_tag_t iot,
296 bus_space_handle_t ioh));
297 void ahc_construct __P((struct ahc_data *ahc, bus_space_tag_t iot,
298 bus_space_handle_t ioh, ahc_type type, ahc_flag flags));
299 #endif
300 void ahc_free __P((struct ahc_data *));
301 int ahc_init __P((struct ahc_data *));
302 int ahc_attach __P((struct ahc_data *));
303 #if defined(__FreeBSD__)
304 void ahc_intr __P((void *arg));
305 #elif defined(__NetBSD__)
306 int ahc_intr __P((void *arg));
307 #endif
308
309 #endif /* _AIC7XXX_H_ */
310