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