aic79xxvar.h revision 1.27 1 1.1 fvdl /*
2 1.15 wiz * Core definitions and data structures sharable across OS platforms.
3 1.1 fvdl *
4 1.1 fvdl * Copyright (c) 1994-2002 Justin T. Gibbs.
5 1.1 fvdl * Copyright (c) 2000-2002 Adaptec Inc.
6 1.1 fvdl * All rights reserved.
7 1.1 fvdl *
8 1.1 fvdl * Redistribution and use in source and binary forms, with or without
9 1.1 fvdl * modification, are permitted provided that the following conditions
10 1.1 fvdl * are met:
11 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
12 1.1 fvdl * notice, this list of conditions, and the following disclaimer,
13 1.1 fvdl * without modification.
14 1.1 fvdl * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 1.1 fvdl * substantially similar to the "NO WARRANTY" disclaimer below
16 1.1 fvdl * ("Disclaimer") and any redistribution must be conditioned upon
17 1.1 fvdl * including a substantially similar Disclaimer requirement for further
18 1.1 fvdl * binary redistribution.
19 1.1 fvdl * 3. Neither the names of the above-listed copyright holders nor the names
20 1.1 fvdl * of any contributors may be used to endorse or promote products derived
21 1.1 fvdl * from this software without specific prior written permission.
22 1.1 fvdl *
23 1.1 fvdl * Alternatively, this software may be distributed under the terms of the
24 1.1 fvdl * GNU General Public License ("GPL") version 2 as published by the Free
25 1.1 fvdl * Software Foundation.
26 1.1 fvdl *
27 1.1 fvdl * NO WARRANTY
28 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 1.1 fvdl * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 1.1 fvdl * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31 1.1 fvdl * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 1.1 fvdl * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 1.1 fvdl * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 1.1 fvdl * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 1.1 fvdl * POSSIBILITY OF SUCH DAMAGES.
39 1.1 fvdl *
40 1.11 thorpej * Id: //depot/aic7xxx/aic7xxx/aic79xx.h#94 $
41 1.1 fvdl *
42 1.11 thorpej * $FreeBSD: src/sys/dev/aic7xxx/aic79xx.h,v 1.15 2003/06/28 04:45:25 gibbs Exp $
43 1.1 fvdl */
44 1.1 fvdl /*
45 1.1 fvdl * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
46 1.1 fvdl */
47 1.1 fvdl
48 1.1 fvdl #ifndef _AIC79XXVAR_H_
49 1.1 fvdl #define _AIC79XXVAR_H_
50 1.1 fvdl
51 1.1 fvdl /* Register Definitions */
52 1.1 fvdl #include <dev/microcode/aic7xxx/aic79xx_reg.h>
53 1.1 fvdl
54 1.1 fvdl /************************* Forward Declarations *******************************/
55 1.1 fvdl struct ahd_platform_data;
56 1.1 fvdl struct scb_platform_data;
57 1.1 fvdl
58 1.1 fvdl /****************************** Useful Macros *********************************/
59 1.1 fvdl #ifndef MAX
60 1.1 fvdl #define MAX(a,b) (((a) > (b)) ? (a) : (b))
61 1.1 fvdl #endif
62 1.1 fvdl
63 1.1 fvdl #ifndef MIN
64 1.1 fvdl #define MIN(a,b) (((a) < (b)) ? (a) : (b))
65 1.1 fvdl #endif
66 1.1 fvdl
67 1.1 fvdl #ifndef TRUE
68 1.1 fvdl #define TRUE 1
69 1.1 fvdl #endif
70 1.1 fvdl #ifndef FALSE
71 1.1 fvdl #define FALSE 0
72 1.1 fvdl #endif
73 1.1 fvdl
74 1.1 fvdl #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
75 1.1 fvdl
76 1.1 fvdl #define ALL_CHANNELS '\0'
77 1.1 fvdl #define ALL_TARGETS_MASK 0xFFFF
78 1.1 fvdl #define INITIATOR_WILDCARD (~0)
79 1.1 fvdl #define SCB_LIST_NULL 0xFF00
80 1.1 fvdl #define SCB_LIST_NULL_LE (ahd_htole16(SCB_LIST_NULL))
81 1.1 fvdl #define QOUTFIFO_ENTRY_VALID 0x8000
82 1.1 fvdl #define QOUTFIFO_ENTRY_VALID_LE (ahd_htole16(0x8000))
83 1.1 fvdl #define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
84 1.1 fvdl
85 1.1 fvdl #define SCSIID_TARGET(ahd, scsiid) \
86 1.1 fvdl (((scsiid) & TID) >> TID_SHIFT)
87 1.1 fvdl #define SCSIID_OUR_ID(scsiid) \
88 1.1 fvdl ((scsiid) & OID)
89 1.1 fvdl #define SCSIID_CHANNEL(ahd, scsiid) ('A')
90 1.1 fvdl #define SCB_IS_SCSIBUS_B(ahd, scb) (0)
91 1.1 fvdl #define SCB_GET_OUR_ID(scb) \
92 1.1 fvdl SCSIID_OUR_ID((scb)->hscb->scsiid)
93 1.1 fvdl #define SCB_GET_TARGET(ahd, scb) \
94 1.1 fvdl SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
95 1.1 fvdl #define SCB_GET_CHANNEL(ahd, scb) \
96 1.1 fvdl SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
97 1.1 fvdl #define SCB_GET_LUN(scb) \
98 1.1 fvdl ((scb)->hscb->lun)
99 1.1 fvdl #define SCB_GET_TARGET_OFFSET(ahd, scb) \
100 1.1 fvdl SCB_GET_TARGET(ahd, scb)
101 1.1 fvdl #define SCB_GET_TARGET_MASK(ahd, scb) \
102 1.1 fvdl (0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
103 1.1 fvdl #ifdef AHD_DEBUG
104 1.1 fvdl #define SCB_IS_SILENT(scb) \
105 1.1 fvdl ((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0 \
106 1.1 fvdl && (((scb)->flags & SCB_SILENT) != 0))
107 1.1 fvdl #else
108 1.1 fvdl #define SCB_IS_SILENT(scb) \
109 1.1 fvdl (((scb)->flags & SCB_SILENT) != 0)
110 1.1 fvdl #endif
111 1.1 fvdl /*
112 1.1 fvdl * TCLs have the following format: TTTTLLLLLLLL
113 1.1 fvdl */
114 1.1 fvdl #define TCL_TARGET_OFFSET(tcl) \
115 1.1 fvdl ((((tcl) >> 4) & TID) >> 4)
116 1.1 fvdl #define TCL_LUN(tcl) \
117 1.1 fvdl (tcl & (AHD_NUM_LUNS - 1))
118 1.1 fvdl #define BUILD_TCL(scsiid, lun) \
119 1.1 fvdl ((lun) | (((scsiid) & TID) << 4))
120 1.1 fvdl #define BUILD_TCL_RAW(target, channel, lun) \
121 1.1 fvdl ((lun) | ((target) << 8))
122 1.1 fvdl
123 1.1 fvdl #define SCB_GET_TAG(scb) \
124 1.1 fvdl ahd_le16toh(scb->hscb->tag)
125 1.1 fvdl
126 1.1 fvdl #ifndef AHD_TARGET_MODE
127 1.1 fvdl #undef AHD_TMODE_ENABLE
128 1.1 fvdl #define AHD_TMODE_ENABLE 0
129 1.1 fvdl #endif
130 1.1 fvdl
131 1.1 fvdl #define AHD_BUILD_COL_IDX(target, lun) \
132 1.1 fvdl (((lun) << 4) | target)
133 1.1 fvdl
134 1.1 fvdl #define AHD_GET_SCB_COL_IDX(ahd, scb) \
135 1.1 fvdl ((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
136 1.1 fvdl
137 1.1 fvdl #define AHD_SET_SCB_COL_IDX(scb, col_idx) \
138 1.1 fvdl do { \
139 1.1 fvdl (scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID; \
140 1.1 fvdl (scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1); \
141 1.1 fvdl } while (0)
142 1.1 fvdl
143 1.1 fvdl #define AHD_COPY_SCB_COL_IDX(dst, src) \
144 1.1 fvdl do { \
145 1.1 fvdl dst->hscb->scsiid = src->hscb->scsiid; \
146 1.1 fvdl dst->hscb->lun = src->hscb->lun; \
147 1.1 fvdl } while (0)
148 1.1 fvdl
149 1.1 fvdl #define AHD_NEVER_COL_IDX 0xFFFF
150 1.1 fvdl
151 1.1 fvdl /**************************** Driver Constants ********************************/
152 1.1 fvdl /*
153 1.1 fvdl * The maximum number of supported targets.
154 1.1 fvdl */
155 1.1 fvdl #define AHD_NUM_TARGETS 16
156 1.1 fvdl
157 1.1 fvdl /*
158 1.1 fvdl * The maximum number of supported luns.
159 1.1 fvdl * The identify message only supports 64 luns in non-packetized transfers.
160 1.1 fvdl * You can have 2^64 luns when information unit transfers are enabled,
161 1.1 fvdl * but until we see a need to support that many, we support 256.
162 1.1 fvdl */
163 1.1 fvdl #define AHD_NUM_LUNS_NONPKT 64
164 1.1 fvdl #define AHD_NUM_LUNS 256
165 1.1 fvdl
166 1.1 fvdl /*
167 1.1 fvdl * The maximum transfer per S/G segment.
168 1.13 fvdl * Limited by MAXPHYS or a 24bit counter.
169 1.1 fvdl */
170 1.13 fvdl #define AHD_MAXTRANSFER_SIZE MIN(MAXPHYS,0x00ffffff)
171 1.1 fvdl
172 1.1 fvdl /*
173 1.1 fvdl * The maximum amount of SCB storage in hardware on a controller.
174 1.1 fvdl * This value represents an upper bound. Due to software design,
175 1.1 fvdl * we may not be able to use this number.
176 1.1 fvdl */
177 1.1 fvdl #define AHD_SCB_MAX 512
178 1.1 fvdl
179 1.1 fvdl /*
180 1.1 fvdl * The maximum number of concurrent transactions supported per driver instance.
181 1.1 fvdl * Sequencer Control Blocks (SCBs) store per-transaction information.
182 1.1 fvdl */
183 1.1 fvdl #define AHD_MAX_QUEUE AHD_SCB_MAX
184 1.1 fvdl
185 1.1 fvdl /*
186 1.1 fvdl * Define the size of our QIN and QOUT FIFOs. They must be a power of 2
187 1.7 thorpej * in size and accommodate as many transactions as can be queued concurrently.
188 1.1 fvdl */
189 1.1 fvdl #define AHD_QIN_SIZE AHD_MAX_QUEUE
190 1.1 fvdl #define AHD_QOUT_SIZE AHD_MAX_QUEUE
191 1.1 fvdl
192 1.1 fvdl #define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
193 1.1 fvdl /*
194 1.1 fvdl * The maximum amount of SCB storage we allocate in host memory.
195 1.1 fvdl */
196 1.1 fvdl #define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
197 1.1 fvdl
198 1.1 fvdl /*
199 1.1 fvdl * Ring Buffer of incoming target commands.
200 1.1 fvdl * We allocate 256 to simplify the logic in the sequencer
201 1.1 fvdl * by using the natural wrap point of an 8bit counter.
202 1.1 fvdl */
203 1.1 fvdl #define AHD_TMODE_CMDS 256
204 1.1 fvdl
205 1.1 fvdl /* Reset line assertion time in us */
206 1.1 fvdl #define AHD_BUSRESET_DELAY 25
207 1.1 fvdl
208 1.1 fvdl /******************* Chip Characteristics/Operating Settings *****************/
209 1.1 fvdl /*
210 1.1 fvdl * Chip Type
211 1.1 fvdl * The chip order is from least sophisticated to most sophisticated.
212 1.1 fvdl */
213 1.1 fvdl typedef enum {
214 1.1 fvdl AHD_NONE = 0x0000,
215 1.1 fvdl AHD_CHIPID_MASK = 0x00FF,
216 1.1 fvdl AHD_AIC7901 = 0x0001,
217 1.1 fvdl AHD_AIC7902 = 0x0002,
218 1.1 fvdl AHD_AIC7901A = 0x0003,
219 1.1 fvdl AHD_PCI = 0x0100, /* Bus type PCI */
220 1.1 fvdl AHD_PCIX = 0x0200, /* Bus type PCIX */
221 1.1 fvdl AHD_BUS_MASK = 0x0F00
222 1.1 fvdl } ahd_chip;
223 1.1 fvdl
224 1.1 fvdl /*
225 1.1 fvdl * Features available in each chip type.
226 1.1 fvdl */
227 1.1 fvdl typedef enum {
228 1.1 fvdl AHD_FENONE = 0x00000,
229 1.1 fvdl AHD_WIDE = 0x00001,/* Wide Channel */
230 1.1 fvdl AHD_MULTI_FUNC = 0x00100,/* Multi-Function/Channel Device */
231 1.1 fvdl AHD_TARGETMODE = 0x01000,/* Has tested target mode support */
232 1.1 fvdl AHD_MULTIROLE = 0x02000,/* Space for two roles at a time */
233 1.1 fvdl AHD_RTI = 0x04000,/* Retained Training Support */
234 1.1 fvdl AHD_NEW_IOCELL_OPTS = 0x08000,/* More Signal knobs in the IOCELL */
235 1.1 fvdl AHD_NEW_DFCNTRL_OPTS = 0x10000,/* SCSIENWRDIS bit */
236 1.1 fvdl AHD_REMOVABLE = 0x00000,/* Hot-Swap supported - None so far*/
237 1.1 fvdl AHD_AIC7901_FE = AHD_FENONE,
238 1.10 thorpej AHD_AIC7901A_FE = AHD_FENONE,
239 1.1 fvdl AHD_AIC7902_FE = AHD_MULTI_FUNC
240 1.1 fvdl } ahd_feature;
241 1.1 fvdl
242 1.1 fvdl /*
243 1.1 fvdl * Bugs in the silicon that we work around in software.
244 1.1 fvdl */
245 1.1 fvdl typedef enum {
246 1.1 fvdl AHD_BUGNONE = 0x0000,
247 1.1 fvdl /*
248 1.1 fvdl * Rev A hardware fails to update LAST/CURR/NEXTSCB
249 1.1 fvdl * correctly in certain packetized selection cases.
250 1.1 fvdl */
251 1.1 fvdl AHD_SENT_SCB_UPDATE_BUG = 0x0001,
252 1.1 fvdl /* The wrong SCB is accessed to check the abort pending bit. */
253 1.1 fvdl AHD_ABORT_LQI_BUG = 0x0002,
254 1.1 fvdl /* Packetized bitbucket crosses packet boundaries. */
255 1.1 fvdl AHD_PKT_BITBUCKET_BUG = 0x0004,
256 1.1 fvdl /* The selection timer runs twice as long as its setting. */
257 1.1 fvdl AHD_LONG_SETIMO_BUG = 0x0008,
258 1.1 fvdl /* The Non-LQ CRC error status is delayed until phase change. */
259 1.1 fvdl AHD_NLQICRC_DELAYED_BUG = 0x0010,
260 1.1 fvdl /* The chip must be reset for all outgoing bus resets. */
261 1.1 fvdl AHD_SCSIRST_BUG = 0x0020,
262 1.1 fvdl /* Some PCIX fields must be saved and restored across chip reset. */
263 1.1 fvdl AHD_PCIX_CHIPRST_BUG = 0x0040,
264 1.1 fvdl /* MMAPIO is not functional in PCI-X mode. */
265 1.1 fvdl AHD_PCIX_MMAPIO_BUG = 0x0080,
266 1.1 fvdl /* Reads to SCBRAM fail to reset the discard timer. */
267 1.1 fvdl AHD_PCIX_SCBRAM_RD_BUG = 0x0100,
268 1.1 fvdl /* Bug workarounds that can be disabled on non-PCIX busses. */
269 1.1 fvdl AHD_PCIX_BUG_MASK = AHD_PCIX_CHIPRST_BUG
270 1.1 fvdl | AHD_PCIX_MMAPIO_BUG
271 1.1 fvdl | AHD_PCIX_SCBRAM_RD_BUG,
272 1.1 fvdl /*
273 1.1 fvdl * LQOSTOP0 status set even for forced selections with ATN
274 1.1 fvdl * to perform non-packetized message delivery.
275 1.1 fvdl */
276 1.1 fvdl AHD_LQO_ATNO_BUG = 0x0200,
277 1.1 fvdl /* FIFO auto-flush does not always trigger. */
278 1.1 fvdl AHD_AUTOFLUSH_BUG = 0x0400,
279 1.1 fvdl /* The CLRLQO registers are not self-clearing. */
280 1.1 fvdl AHD_CLRLQO_AUTOCLR_BUG = 0x0800,
281 1.1 fvdl /* The PACKETIZED status bit refers to the previous connection. */
282 1.1 fvdl AHD_PKTIZED_STATUS_BUG = 0x1000,
283 1.1 fvdl /* "Short Luns" are not placed into outgoing LQ packets correctly. */
284 1.1 fvdl AHD_PKT_LUN_BUG = 0x2000,
285 1.1 fvdl /*
286 1.1 fvdl * Only the FIFO allocated to the non-packetized connection may
287 1.1 fvdl * be in use during a non-packetzied connection.
288 1.1 fvdl */
289 1.1 fvdl AHD_NONPACKFIFO_BUG = 0x4000,
290 1.1 fvdl /*
291 1.1 fvdl * Writing to a DFF SCBPTR register may fail if concurent with
292 1.1 fvdl * a hardware write to the other DFF SCBPTR register. This is
293 1.1 fvdl * not currently a concern in our sequencer since all chips with
294 1.1 fvdl * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
295 1.1 fvdl * occur in non-packetized connections.
296 1.1 fvdl */
297 1.1 fvdl AHD_MDFF_WSCBPTR_BUG = 0x8000,
298 1.1 fvdl /* SGHADDR updates are slow. */
299 1.1 fvdl AHD_REG_SLOW_SETTLE_BUG = 0x10000,
300 1.1 fvdl /*
301 1.1 fvdl * Changing the MODE_PTR coincident with an interrupt that
302 1.1 fvdl * switches to a different mode will cause the interrupt to
303 1.1 fvdl * be in the mode written outside of interrupt context.
304 1.1 fvdl */
305 1.1 fvdl AHD_SET_MODE_BUG = 0x20000,
306 1.1 fvdl /* Non-packetized busfree revision does not work. */
307 1.1 fvdl AHD_BUSFREEREV_BUG = 0x40000,
308 1.1 fvdl /*
309 1.1 fvdl * Paced transfers are indicated with a non-standard PPR
310 1.1 fvdl * option bit in the neg table, 160MHz is indicated by
311 1.1 fvdl * sync factor 0x7, and the offset if off by a factor of 2.
312 1.1 fvdl */
313 1.1 fvdl AHD_PACED_NEGTABLE_BUG = 0x80000,
314 1.1 fvdl /* LQOOVERRUN false positives. */
315 1.1 fvdl AHD_LQOOVERRUN_BUG = 0x100000,
316 1.1 fvdl /*
317 1.1 fvdl * Controller write to INTSTAT will lose to a host
318 1.1 fvdl * write to CLRINT.
319 1.1 fvdl */
320 1.1 fvdl AHD_INTCOLLISION_BUG = 0x200000,
321 1.1 fvdl /*
322 1.1 fvdl * The GEM318 violates the SCSI spec by not waiting
323 1.1 fvdl * the mandated bus settle delay between phase changes
324 1.1 fvdl * in some situations. Some aic79xx chip revs. are more
325 1.1 fvdl * strict in this regard and will treat REQ assertions
326 1.1 fvdl * that fall within the bus settle delay window as
327 1.1 fvdl * glitches. This flag tells the firmware to tolerate
328 1.1 fvdl * early REQ assertions.
329 1.1 fvdl */
330 1.7 thorpej AHD_EARLY_REQ_BUG = 0x400000,
331 1.7 thorpej /*
332 1.7 thorpej * The LED does not stay on long enough in packetized modes.
333 1.7 thorpej */
334 1.7 thorpej AHD_FAINT_LED_BUG = 0x800000
335 1.1 fvdl } ahd_bug;
336 1.1 fvdl
337 1.1 fvdl /*
338 1.1 fvdl * Configuration specific settings.
339 1.1 fvdl * The driver determines these settings by probing the
340 1.1 fvdl * chip/controller's configuration.
341 1.1 fvdl */
342 1.1 fvdl typedef enum {
343 1.1 fvdl AHD_FNONE = 0x00000,
344 1.7 thorpej AHD_BOOT_CHANNEL = 0x00001,/* We were set as the boot channel. */
345 1.1 fvdl AHD_USEDEFAULTS = 0x00004,/*
346 1.1 fvdl * For cards without an seeprom
347 1.1 fvdl * or a BIOS to initialize the chip's
348 1.1 fvdl * SRAM, we use the default target
349 1.1 fvdl * settings.
350 1.1 fvdl */
351 1.1 fvdl AHD_SEQUENCER_DEBUG = 0x00008,
352 1.1 fvdl AHD_RESET_BUS_A = 0x00010,
353 1.1 fvdl AHD_EXTENDED_TRANS_A = 0x00020,
354 1.1 fvdl AHD_TERM_ENB_A = 0x00040,
355 1.1 fvdl AHD_SPCHK_ENB_A = 0x00080,
356 1.1 fvdl AHD_STPWLEVEL_A = 0x00100,
357 1.1 fvdl AHD_INITIATORROLE = 0x00200,/*
358 1.1 fvdl * Allow initiator operations on
359 1.1 fvdl * this controller.
360 1.1 fvdl */
361 1.1 fvdl AHD_TARGETROLE = 0x00400,/*
362 1.1 fvdl * Allow target operations on this
363 1.1 fvdl * controller.
364 1.1 fvdl */
365 1.1 fvdl AHD_RESOURCE_SHORTAGE = 0x00800,
366 1.1 fvdl AHD_TQINFIFO_BLOCKED = 0x01000,/* Blocked waiting for ATIOs */
367 1.1 fvdl AHD_INT50_SPEEDFLEX = 0x02000,/*
368 1.1 fvdl * Internal 50pin connector
369 1.1 fvdl * sits behind an aic3860
370 1.1 fvdl */
371 1.1 fvdl AHD_BIOS_ENABLED = 0x04000,
372 1.1 fvdl AHD_ALL_INTERRUPTS = 0x08000,
373 1.1 fvdl AHD_39BIT_ADDRESSING = 0x10000,/* Use 39 bit addressing scheme. */
374 1.1 fvdl AHD_64BIT_ADDRESSING = 0x20000,/* Use 64 bit addressing scheme. */
375 1.1 fvdl AHD_CURRENT_SENSING = 0x40000,
376 1.1 fvdl AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */
377 1.1 fvdl AHD_HP_BOARD = 0x100000,
378 1.1 fvdl AHD_RESET_POLL_ACTIVE = 0x200000,
379 1.1 fvdl AHD_UPDATE_PEND_CMDS = 0x400000,
380 1.11 thorpej AHD_RUNNING_QOUTFIFO = 0x800000,
381 1.11 thorpej AHD_HAD_FIRST_SEL = 0x1000000
382 1.1 fvdl } ahd_flag;
383 1.1 fvdl
384 1.1 fvdl /************************* Hardware SCB Definition ***************************/
385 1.1 fvdl
386 1.1 fvdl /*
387 1.1 fvdl * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB
388 1.1 fvdl * consists of a "hardware SCB" mirroring the fields available on the card
389 1.1 fvdl * and additional information the kernel stores for each transaction.
390 1.1 fvdl *
391 1.1 fvdl * To minimize space utilization, a portion of the hardware scb stores
392 1.1 fvdl * different data during different portions of a SCSI transaction.
393 1.1 fvdl * As initialized by the host driver for the initiator role, this area
394 1.1 fvdl * contains the SCSI cdb (or a pointer to the cdb) to be executed. After
395 1.1 fvdl * the cdb has been presented to the target, this area serves to store
396 1.1 fvdl * residual transfer information and the SCSI status byte.
397 1.1 fvdl * For the target role, the contents of this area do not change, but
398 1.1 fvdl * still serve a different purpose than for the initiator role. See
399 1.1 fvdl * struct target_data for details.
400 1.1 fvdl */
401 1.1 fvdl
402 1.1 fvdl /*
403 1.1 fvdl * Status information embedded in the shared portion of
404 1.1 fvdl * an SCB after passing the cdb to the target. The kernel
405 1.1 fvdl * driver will only read this data for transactions that
406 1.1 fvdl * complete abnormally.
407 1.1 fvdl */
408 1.1 fvdl struct initiator_status {
409 1.1 fvdl uint32_t residual_datacnt; /* Residual in the current S/G seg */
410 1.1 fvdl uint32_t residual_sgptr; /* The next S/G for this transfer */
411 1.1 fvdl uint8_t scsi_status; /* Standard SCSI status byte */
412 1.1 fvdl };
413 1.1 fvdl
414 1.1 fvdl struct target_status {
415 1.1 fvdl uint32_t residual_datacnt; /* Residual in the current S/G seg */
416 1.1 fvdl uint32_t residual_sgptr; /* The next S/G for this transfer */
417 1.1 fvdl uint8_t scsi_status; /* SCSI status to give to initiator */
418 1.1 fvdl uint8_t target_phases; /* Bitmap of phases to execute */
419 1.1 fvdl uint8_t data_phase; /* Data-In or Data-Out */
420 1.1 fvdl uint8_t initiator_tag; /* Initiator's transaction tag */
421 1.1 fvdl };
422 1.1 fvdl
423 1.1 fvdl /*
424 1.1 fvdl * Initiator mode SCB shared data area.
425 1.1 fvdl * If the embedded CDB is 12 bytes or less, we embed
426 1.1 fvdl * the sense buffer address in the SCB. This allows
427 1.1 fvdl * us to retrieve sense information without interrupting
428 1.1 fvdl * the host in packetized mode.
429 1.1 fvdl */
430 1.1 fvdl typedef uint32_t sense_addr_t;
431 1.1 fvdl #define MAX_CDB_LEN 16
432 1.1 fvdl #define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
433 1.1 fvdl union initiator_data {
434 1.1 fvdl struct {
435 1.1 fvdl uint64_t cdbptr;
436 1.1 fvdl uint8_t cdblen;
437 1.1 fvdl } cdb_from_host;
438 1.1 fvdl uint8_t cdb[MAX_CDB_LEN];
439 1.1 fvdl struct {
440 1.1 fvdl uint8_t cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
441 1.1 fvdl sense_addr_t sense_addr;
442 1.1 fvdl } cdb_plus_saddr;
443 1.1 fvdl };
444 1.1 fvdl
445 1.1 fvdl /*
446 1.1 fvdl * Target mode version of the shared data SCB segment.
447 1.1 fvdl */
448 1.1 fvdl struct target_data {
449 1.17 perry uint32_t spare[2];
450 1.1 fvdl uint8_t scsi_status; /* SCSI status to give to initiator */
451 1.1 fvdl uint8_t target_phases; /* Bitmap of phases to execute */
452 1.1 fvdl uint8_t data_phase; /* Data-In or Data-Out */
453 1.1 fvdl uint8_t initiator_tag; /* Initiator's transaction tag */
454 1.1 fvdl };
455 1.1 fvdl
456 1.1 fvdl struct hardware_scb {
457 1.1 fvdl /*0*/ union {
458 1.1 fvdl union initiator_data idata;
459 1.1 fvdl struct target_data tdata;
460 1.1 fvdl struct initiator_status istatus;
461 1.1 fvdl struct target_status tstatus;
462 1.1 fvdl } shared_data;
463 1.1 fvdl /*
464 1.1 fvdl * A word about residuals.
465 1.1 fvdl * The scb is presented to the sequencer with the dataptr and datacnt
466 1.1 fvdl * fields initialized to the contents of the first S/G element to
467 1.1 fvdl * transfer. The sgptr field is initialized to the bus address for
468 1.1 fvdl * the S/G element that follows the first in the in core S/G array
469 1.1 fvdl * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid
470 1.1 fvdl * S/G entry for this transfer (single S/G element transfer with the
471 1.1 fvdl * first elements address and length preloaded in the dataptr/datacnt
472 1.1 fvdl * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.
473 1.1 fvdl * The SG_FULL_RESID flag ensures that the residual will be correctly
474 1.1 fvdl * noted even if no data transfers occur. Once the data phase is entered,
475 1.1 fvdl * the residual sgptr and datacnt are loaded from the sgptr and the
476 1.1 fvdl * datacnt fields. After each S/G element's dataptr and length are
477 1.1 fvdl * loaded into the hardware, the residual sgptr is advanced. After
478 1.1 fvdl * each S/G element is expired, its datacnt field is checked to see
479 1.1 fvdl * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the
480 1.1 fvdl * residual sg ptr and the transfer is considered complete. If the
481 1.14 wiz * sequencer determines that there is a residual in the transfer, or
482 1.1 fvdl * there is non-zero status, it will set the SG_STATUS_VALID flag in
483 1.3 wiz * sgptr and DMA the scb back into host memory. To summarize:
484 1.1 fvdl *
485 1.1 fvdl * Sequencer:
486 1.1 fvdl * o A residual has occurred if SG_FULL_RESID is set in sgptr,
487 1.1 fvdl * or residual_sgptr does not have SG_LIST_NULL set.
488 1.1 fvdl *
489 1.1 fvdl * o We are transfering the last segment if residual_datacnt has
490 1.1 fvdl * the SG_LAST_SEG flag set.
491 1.1 fvdl *
492 1.1 fvdl * Host:
493 1.1 fvdl * o A residual can only have occurred if a completed scb has the
494 1.1 fvdl * SG_STATUS_VALID flag set. Inspection of the SCSI status field,
495 1.1 fvdl * the residual_datacnt, and the residual_sgptr field will tell
496 1.1 fvdl * for sure.
497 1.1 fvdl *
498 1.1 fvdl * o residual_sgptr and sgptr refer to the "next" sg entry
499 1.1 fvdl * and so may point beyond the last valid sg entry for the
500 1.1 fvdl * transfer.
501 1.17 perry */
502 1.1 fvdl #define SG_PTR_MASK 0xFFFFFFF8
503 1.9 thorpej /*16*/ uint16_t tag; /* Reused by Sequencer. */
504 1.9 thorpej /*18*/ uint8_t control; /* See SCB_CONTROL in aic79xx.reg for details */
505 1.9 thorpej /*19*/ uint8_t scsiid; /*
506 1.1 fvdl * Selection out Id
507 1.1 fvdl * Our Id (bits 0-3) Their ID (bits 4-7)
508 1.1 fvdl */
509 1.9 thorpej /*20*/ uint8_t lun;
510 1.9 thorpej /*21*/ uint8_t task_attribute;
511 1.9 thorpej /*22*/ uint8_t cdb_len;
512 1.9 thorpej /*23*/ uint8_t task_management;
513 1.9 thorpej /*24*/ uint64_t dataptr;
514 1.9 thorpej /*32*/ uint32_t datacnt; /* Byte 3 is spare. */
515 1.9 thorpej /*36*/ uint32_t sgptr;
516 1.9 thorpej /*40*/ uint32_t hscb_busaddr;
517 1.9 thorpej /*44*/ uint32_t next_hscb_busaddr;
518 1.7 thorpej /********** Long lun field only downloaded for full 8 byte lun support ********/
519 1.1 fvdl /*48*/ uint8_t pkt_long_lun[8];
520 1.1 fvdl /******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
521 1.1 fvdl /*56*/ uint8_t spare[8];
522 1.1 fvdl };
523 1.1 fvdl
524 1.1 fvdl /************************ Kernel SCB Definitions ******************************/
525 1.1 fvdl /*
526 1.1 fvdl * Some fields of the SCB are OS dependent. Here we collect the
527 1.1 fvdl * definitions for elements that all OS platforms need to include
528 1.1 fvdl * in there SCB definition.
529 1.1 fvdl */
530 1.1 fvdl
531 1.1 fvdl /*
532 1.14 wiz * Definition of a scatter/gather element as transferred to the controller.
533 1.1 fvdl * The aic7xxx chips only support a 24bit length. We use the top byte of
534 1.1 fvdl * the length to store additional address bits and a flag to indicate
535 1.1 fvdl * that a given segment terminates the transfer. This gives us an
536 1.1 fvdl * addressable range of 512GB on machines with 64bit PCI or with chips
537 1.1 fvdl * that can support dual address cycles on 32bit PCI busses.
538 1.1 fvdl */
539 1.1 fvdl struct ahd_dma_seg {
540 1.1 fvdl uint32_t addr;
541 1.1 fvdl uint32_t len;
542 1.1 fvdl #define AHD_DMA_LAST_SEG 0x80000000
543 1.1 fvdl #define AHD_SG_HIGH_ADDR_MASK 0x7F000000
544 1.1 fvdl #define AHD_SG_LEN_MASK 0x00FFFFFF
545 1.1 fvdl };
546 1.1 fvdl
547 1.1 fvdl struct ahd_dma64_seg {
548 1.1 fvdl uint64_t addr;
549 1.1 fvdl uint32_t len;
550 1.1 fvdl uint32_t pad;
551 1.1 fvdl };
552 1.1 fvdl
553 1.1 fvdl struct map_node {
554 1.1 fvdl bus_dmamap_t dmamap;
555 1.1 fvdl bus_addr_t physaddr;
556 1.1 fvdl uint8_t *vaddr;
557 1.1 fvdl bus_dma_segment_t dmasegs;
558 1.1 fvdl int nseg;
559 1.1 fvdl SLIST_ENTRY(map_node) links;
560 1.1 fvdl };
561 1.1 fvdl
562 1.1 fvdl struct ahd_pci_busdata {
563 1.1 fvdl pci_chipset_tag_t pc;
564 1.1 fvdl pcitag_t tag;
565 1.1 fvdl u_int dev;
566 1.1 fvdl u_int func;
567 1.1 fvdl int pcix_off;
568 1.1 fvdl };
569 1.1 fvdl
570 1.1 fvdl /*
571 1.1 fvdl * The current state of this SCB.
572 1.1 fvdl */
573 1.1 fvdl typedef enum {
574 1.1 fvdl SCB_FLAG_NONE = 0x00000,
575 1.1 fvdl SCB_TRANSMISSION_ERROR = 0x00001,/*
576 1.1 fvdl * We detected a parity or CRC
577 1.1 fvdl * error that has effected the
578 1.1 fvdl * payload of the command. This
579 1.1 fvdl * flag is checked when normal
580 1.1 fvdl * status is returned to catch
581 1.1 fvdl * the case of a target not
582 1.1 fvdl * responding to our attempt
583 1.1 fvdl * to report the error.
584 1.1 fvdl */
585 1.1 fvdl SCB_OTHERTCL_TIMEOUT = 0x00002,/*
586 1.1 fvdl * Another device was active
587 1.1 fvdl * during the first timeout for
588 1.1 fvdl * this SCB so we gave ourselves
589 1.1 fvdl * an additional timeout period
590 1.1 fvdl * in case it was hogging the
591 1.1 fvdl * bus.
592 1.1 fvdl */
593 1.1 fvdl SCB_DEVICE_RESET = 0x00004,
594 1.1 fvdl SCB_SENSE = 0x00008,
595 1.1 fvdl SCB_CDB32_PTR = 0x00010,
596 1.1 fvdl SCB_RECOVERY_SCB = 0x00020,
597 1.1 fvdl SCB_AUTO_NEGOTIATE = 0x00040,/* Negotiate to achieve goal. */
598 1.1 fvdl SCB_NEGOTIATE = 0x00080,/* Negotiation forced for command. */
599 1.1 fvdl SCB_ABORT = 0x00100,
600 1.1 fvdl SCB_ACTIVE = 0x00200,
601 1.1 fvdl SCB_TARGET_IMMEDIATE = 0x00400,
602 1.1 fvdl SCB_PACKETIZED = 0x00800,
603 1.1 fvdl SCB_EXPECT_PPR_BUSFREE = 0x01000,
604 1.1 fvdl SCB_PKT_SENSE = 0x02000,
605 1.1 fvdl SCB_CMDPHASE_ABORT = 0x04000,
606 1.1 fvdl SCB_ON_COL_LIST = 0x08000,
607 1.1 fvdl SCB_SILENT = 0x10000,/*
608 1.1 fvdl * Be quiet about transmission type
609 1.1 fvdl * errors. They are expected and we
610 1.1 fvdl * don't want to upset the user. This
611 1.1 fvdl * flag is typically used during DV.
612 1.1 fvdl */
613 1.1 fvdl SCB_FREEZE_QUEUE = 0x20000,
614 1.1 fvdl SCB_REQUEUE = 0x40000,
615 1.1 fvdl } scb_flag;
616 1.1 fvdl
617 1.1 fvdl struct scb {
618 1.1 fvdl struct hardware_scb *hscb;
619 1.1 fvdl union {
620 1.1 fvdl SLIST_ENTRY(scb) sle;
621 1.1 fvdl LIST_ENTRY(scb) le;
622 1.1 fvdl TAILQ_ENTRY(scb) tqe;
623 1.1 fvdl } links;
624 1.1 fvdl union {
625 1.1 fvdl SLIST_ENTRY(scb) sle;
626 1.1 fvdl LIST_ENTRY(scb) le;
627 1.1 fvdl TAILQ_ENTRY(scb) tqe;
628 1.1 fvdl } links2;
629 1.1 fvdl #define pending_links links2.le
630 1.1 fvdl #define collision_links links2.le
631 1.1 fvdl struct scb *col_scb;
632 1.1 fvdl struct scsipi_xfer *xs;
633 1.1 fvdl
634 1.1 fvdl struct ahd_softc *ahd_softc;
635 1.1 fvdl scb_flag flags;
636 1.1 fvdl bus_dmamap_t dmamap;
637 1.1 fvdl struct scb_platform_data *platform_data;
638 1.1 fvdl struct map_node *hscb_map;
639 1.1 fvdl struct map_node *sg_map;
640 1.1 fvdl struct map_node *sense_map;
641 1.1 fvdl void *sg_list;
642 1.1 fvdl uint8_t *sense_data;
643 1.1 fvdl bus_addr_t sg_list_busaddr;
644 1.1 fvdl bus_addr_t sense_busaddr;
645 1.1 fvdl u_int sg_count;/* How full ahd_dma_seg is */
646 1.1 fvdl #define AHD_MAX_LQ_CRC_ERRORS 5
647 1.1 fvdl u_int crc_retry_count;
648 1.1 fvdl };
649 1.1 fvdl
650 1.1 fvdl TAILQ_HEAD(scb_tailq, scb);
651 1.1 fvdl LIST_HEAD(scb_list, scb);
652 1.1 fvdl
653 1.1 fvdl struct scb_data {
654 1.1 fvdl /*
655 1.1 fvdl * TAILQ of lists of free SCBs grouped by device
656 1.1 fvdl * collision domains.
657 1.1 fvdl */
658 1.1 fvdl struct scb_tailq free_scbs;
659 1.1 fvdl
660 1.1 fvdl /*
661 1.1 fvdl * Per-device lists of SCBs whose tag ID would collide
662 1.1 fvdl * with an already active tag on the device.
663 1.1 fvdl */
664 1.1 fvdl struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
665 1.1 fvdl
666 1.1 fvdl /*
667 1.1 fvdl * SCBs that will not collide with any active device.
668 1.1 fvdl */
669 1.1 fvdl struct scb_list any_dev_free_scb_list;
670 1.1 fvdl
671 1.1 fvdl /*
672 1.1 fvdl * Mapping from tag to SCB.
673 1.1 fvdl */
674 1.1 fvdl struct scb *scbindex[AHD_SCB_MAX];
675 1.1 fvdl
676 1.1 fvdl SLIST_HEAD(, map_node) hscb_maps;
677 1.1 fvdl SLIST_HEAD(, map_node) sg_maps;
678 1.1 fvdl SLIST_HEAD(, map_node) sense_maps;
679 1.1 fvdl
680 1.1 fvdl int scbs_left; /* unallocated scbs in head map_node */
681 1.1 fvdl int sgs_left; /* unallocated sgs in head map_node */
682 1.1 fvdl int sense_left; /* unallocated sense in head map_node */
683 1.1 fvdl uint16_t numscbs;
684 1.1 fvdl uint16_t maxhscbs; /* Number of SCBs on the card */
685 1.1 fvdl uint8_t init_level; /*
686 1.1 fvdl * How far we've initialized
687 1.1 fvdl * this structure.
688 1.1 fvdl */
689 1.1 fvdl };
690 1.1 fvdl
691 1.1 fvdl /************************ Target Mode Definitions *****************************/
692 1.1 fvdl
693 1.1 fvdl /*
694 1.1 fvdl * Connection desciptor for select-in requests in target mode.
695 1.1 fvdl */
696 1.1 fvdl struct target_cmd {
697 1.1 fvdl uint8_t scsiid; /* Our ID and the initiator's ID */
698 1.1 fvdl uint8_t identify; /* Identify message */
699 1.17 perry uint8_t bytes[22]; /*
700 1.1 fvdl * Bytes contains any additional message
701 1.1 fvdl * bytes terminated by 0xFF. The remainder
702 1.1 fvdl * is the cdb to execute.
703 1.1 fvdl */
704 1.1 fvdl uint8_t cmd_valid; /*
705 1.1 fvdl * When a command is complete, the firmware
706 1.1 fvdl * will set cmd_valid to all bits set.
707 1.1 fvdl * After the host has seen the command,
708 1.1 fvdl * the bits are cleared. This allows us
709 1.1 fvdl * to just peek at host memory to determine
710 1.1 fvdl * if more work is complete. cmd_valid is on
711 1.1 fvdl * an 8 byte boundary to simplify setting
712 1.1 fvdl * it on aic7880 hardware which only has
713 1.1 fvdl * limited direct access to the DMA FIFO.
714 1.1 fvdl */
715 1.1 fvdl uint8_t pad[7];
716 1.1 fvdl };
717 1.1 fvdl
718 1.1 fvdl /*
719 1.1 fvdl * Number of events we can buffer up if we run out
720 1.1 fvdl * of immediate notify ccbs.
721 1.1 fvdl */
722 1.1 fvdl #define AHD_TMODE_EVENT_BUFFER_SIZE 8
723 1.1 fvdl struct ahd_tmode_event {
724 1.1 fvdl uint8_t initiator_id;
725 1.1 fvdl uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
726 1.1 fvdl #define EVENT_TYPE_BUS_RESET 0xFF
727 1.1 fvdl uint8_t event_arg;
728 1.1 fvdl };
729 1.1 fvdl
730 1.1 fvdl /*
731 1.1 fvdl * Per enabled lun target mode state.
732 1.1 fvdl * As this state is directly influenced by the host OS'es target mode
733 1.1 fvdl * environment, we let the OS module define it. Forward declare the
734 1.1 fvdl * structure here so we can store arrays of them, etc. in OS neutral
735 1.1 fvdl * data structures.
736 1.1 fvdl */
737 1.17 perry #ifdef AHD_TARGET_MODE
738 1.1 fvdl struct ahd_tmode_lstate {
739 1.1 fvdl struct cam_path *path;
740 1.1 fvdl struct ccb_hdr_slist accept_tios;
741 1.1 fvdl struct ccb_hdr_slist immed_notifies;
742 1.1 fvdl struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
743 1.1 fvdl uint8_t event_r_idx;
744 1.1 fvdl uint8_t event_w_idx;
745 1.1 fvdl };
746 1.1 fvdl #else
747 1.1 fvdl struct ahd_tmode_lstate;
748 1.1 fvdl #endif
749 1.1 fvdl
750 1.1 fvdl /******************** Transfer Negotiation Datastructures *********************/
751 1.14 wiz #define AHD_TRANS_CUR 0x01 /* Modify current negotiation status */
752 1.1 fvdl #define AHD_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
753 1.1 fvdl #define AHD_TRANS_GOAL 0x04 /* Modify negontiation goal */
754 1.1 fvdl #define AHD_TRANS_USER 0x08 /* Modify user negotiation settings */
755 1.1 fvdl #define AHD_PERIOD_10MHz 0x19
756 1.1 fvdl
757 1.1 fvdl #define AHD_WIDTH_UNKNOWN 0xFF
758 1.1 fvdl #define AHD_PERIOD_UNKNOWN 0xFF
759 1.1 fvdl #define AHD_OFFSET_UNKNOWN 0xFF
760 1.1 fvdl #define AHD_PPR_OPTS_UNKNOWN 0xFF
761 1.1 fvdl
762 1.1 fvdl /*
763 1.1 fvdl * Transfer Negotiation Information.
764 1.1 fvdl */
765 1.1 fvdl struct ahd_transinfo {
766 1.1 fvdl uint8_t protocol_version; /* SCSI Revision level */
767 1.1 fvdl uint8_t transport_version; /* SPI Revision level */
768 1.1 fvdl uint8_t width; /* Bus width */
769 1.1 fvdl uint8_t period; /* Sync rate factor */
770 1.1 fvdl uint8_t offset; /* Sync offset */
771 1.1 fvdl uint8_t ppr_options; /* Parallel Protocol Request options */
772 1.1 fvdl };
773 1.1 fvdl
774 1.1 fvdl /*
775 1.1 fvdl * Per-initiator current, goal and user transfer negotiation information. */
776 1.1 fvdl struct ahd_initiator_tinfo {
777 1.1 fvdl struct ahd_transinfo curr;
778 1.1 fvdl struct ahd_transinfo goal;
779 1.1 fvdl struct ahd_transinfo user;
780 1.1 fvdl };
781 1.1 fvdl
782 1.1 fvdl /*
783 1.1 fvdl * Per enabled target ID state.
784 1.1 fvdl * Pointers to lun target state as well as sync/wide negotiation information
785 1.1 fvdl * for each initiator<->target mapping. For the initiator role we pretend
786 1.1 fvdl * that we are the target and the targets are the initiators since the
787 1.1 fvdl * negotiation is the same regardless of role.
788 1.1 fvdl */
789 1.1 fvdl struct ahd_tmode_tstate {
790 1.1 fvdl struct ahd_tmode_lstate* enabled_luns[AHD_NUM_LUNS];
791 1.1 fvdl struct ahd_initiator_tinfo transinfo[AHD_NUM_TARGETS];
792 1.1 fvdl
793 1.1 fvdl /*
794 1.1 fvdl * Per initiator state bitmasks.
795 1.1 fvdl */
796 1.1 fvdl uint16_t auto_negotiate;/* Auto Negotiation Required */
797 1.1 fvdl uint16_t discenable; /* Disconnection allowed */
798 1.1 fvdl uint16_t tagenable; /* Tagged Queuing allowed */
799 1.1 fvdl };
800 1.1 fvdl
801 1.1 fvdl /*
802 1.1 fvdl * Points of interest along the negotiated transfer scale.
803 1.1 fvdl */
804 1.1 fvdl #define AHD_SYNCRATE_160 0x8
805 1.1 fvdl #define AHD_SYNCRATE_PACED 0x8
806 1.1 fvdl #define AHD_SYNCRATE_DT 0x9
807 1.1 fvdl #define AHD_SYNCRATE_ULTRA2 0xa
808 1.1 fvdl #define AHD_SYNCRATE_ULTRA 0xc
809 1.1 fvdl #define AHD_SYNCRATE_FAST 0x19
810 1.1 fvdl #define AHD_SYNCRATE_MIN_DT AHD_SYNCRATE_FAST
811 1.1 fvdl #define AHD_SYNCRATE_SYNC 0x32
812 1.1 fvdl #define AHD_SYNCRATE_MIN 0x60
813 1.1 fvdl #define AHD_SYNCRATE_ASYNC 0xFF
814 1.1 fvdl #define AHD_SYNCRATE_MAX AHD_SYNCRATE_160
815 1.1 fvdl
816 1.1 fvdl /* Safe and valid period for async negotiations. */
817 1.1 fvdl #define AHD_ASYNC_XFER_PERIOD 0x44
818 1.1 fvdl
819 1.1 fvdl /*
820 1.1 fvdl * In RevA, the synctable uses a 120MHz rate for the period
821 1.1 fvdl * factor 8 and 160MHz for the period factor 7. The 120MHz
822 1.1 fvdl * rate never made it into the official SCSI spec, so we must
823 1.1 fvdl * compensate when setting the negotiation table for Rev A
824 1.1 fvdl * parts.
825 1.1 fvdl */
826 1.1 fvdl #define AHD_SYNCRATE_REVA_120 0x8
827 1.1 fvdl #define AHD_SYNCRATE_REVA_160 0x7
828 1.1 fvdl
829 1.1 fvdl /***************************** Lookup Tables **********************************/
830 1.1 fvdl /*
831 1.1 fvdl * Phase -> name and message out response
832 1.17 perry * to parity errors in each phase table.
833 1.1 fvdl */
834 1.1 fvdl struct ahd_phase_table_entry {
835 1.25 tsutsui uint8_t phase;
836 1.25 tsutsui uint8_t mesg_out; /* Message response to parity errors */
837 1.18 christos const char *phasemsg;
838 1.1 fvdl };
839 1.1 fvdl
840 1.1 fvdl /************************** Serial EEPROM Format ******************************/
841 1.1 fvdl
842 1.1 fvdl struct seeprom_config {
843 1.1 fvdl /*
844 1.1 fvdl * Per SCSI ID Configuration Flags
845 1.1 fvdl */
846 1.1 fvdl uint16_t device_flags[16]; /* words 0-15 */
847 1.1 fvdl #define CFXFER 0x003F /* synchronous transfer rate */
848 1.1 fvdl #define CFXFER_ASYNC 0x3F
849 1.1 fvdl #define CFQAS 0x0040 /* Negotiate QAS */
850 1.1 fvdl #define CFPACKETIZED 0x0080 /* Negotiate Packetized Transfers */
851 1.1 fvdl #define CFSTART 0x0100 /* send start unit SCSI command */
852 1.1 fvdl #define CFINCBIOS 0x0200 /* include in BIOS scan */
853 1.1 fvdl #define CFDISC 0x0400 /* enable disconnection */
854 1.1 fvdl #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
855 1.1 fvdl #define CFWIDEB 0x1000 /* wide bus device */
856 1.1 fvdl #define CFHOSTMANAGED 0x8000 /* Managed by a RAID controller */
857 1.1 fvdl
858 1.1 fvdl /*
859 1.1 fvdl * BIOS Control Bits
860 1.1 fvdl */
861 1.1 fvdl uint16_t bios_control; /* word 16 */
862 1.15 wiz #define CFSUPREM 0x0001 /* support all removable drives */
863 1.15 wiz #define CFSUPREMB 0x0002 /* support removable boot drives */
864 1.1 fvdl #define CFBIOSSTATE 0x000C /* BIOS Action State */
865 1.1 fvdl #define CFBS_DISABLED 0x00
866 1.1 fvdl #define CFBS_ENABLED 0x04
867 1.1 fvdl #define CFBS_DISABLED_SCAN 0x08
868 1.1 fvdl #define CFENABLEDV 0x0010 /* Perform Domain Validation */
869 1.17 perry #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
870 1.1 fvdl #define CFSPARITY 0x0040 /* SCSI parity */
871 1.1 fvdl #define CFEXTEND 0x0080 /* extended translation enabled */
872 1.1 fvdl #define CFBOOTCD 0x0100 /* Support Bootable CD-ROM */
873 1.1 fvdl #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
874 1.1 fvdl #define CFMSG_VERBOSE 0x0000
875 1.1 fvdl #define CFMSG_SILENT 0x0200
876 1.1 fvdl #define CFMSG_DIAG 0x0400
877 1.1 fvdl #define CFRESETB 0x0800 /* reset SCSI bus at boot */
878 1.1 fvdl /* UNUSED 0xf000 */
879 1.1 fvdl
880 1.1 fvdl /*
881 1.1 fvdl * Host Adapter Control Bits
882 1.1 fvdl */
883 1.17 perry uint16_t adapter_control; /* word 17 */
884 1.1 fvdl #define CFAUTOTERM 0x0001 /* Perform Auto termination */
885 1.1 fvdl #define CFSTERM 0x0002 /* SCSI low byte termination */
886 1.1 fvdl #define CFWSTERM 0x0004 /* SCSI high byte termination */
887 1.1 fvdl #define CFSEAUTOTERM 0x0008 /* Ultra2 Perform secondary Auto Term*/
888 1.1 fvdl #define CFSELOWTERM 0x0010 /* Ultra2 secondary low term */
889 1.1 fvdl #define CFSEHIGHTERM 0x0020 /* Ultra2 secondary high term */
890 1.1 fvdl #define CFSTPWLEVEL 0x0040 /* Termination level control */
891 1.1 fvdl #define CFBIOSAUTOTERM 0x0080 /* Perform Auto termination */
892 1.17 perry #define CFTERM_MENU 0x0100 /* BIOS displays termination menu */
893 1.1 fvdl #define CFCLUSTERENB 0x8000 /* Cluster Enable */
894 1.1 fvdl
895 1.1 fvdl /*
896 1.1 fvdl * Bus Release Time, Host Adapter ID
897 1.1 fvdl */
898 1.1 fvdl uint16_t brtime_id; /* word 18 */
899 1.1 fvdl #define CFSCSIID 0x000f /* host adapter SCSI ID */
900 1.1 fvdl /* UNUSED 0x00f0 */
901 1.1 fvdl #define CFBRTIME 0xff00 /* bus release time/PCI Latency Time */
902 1.1 fvdl
903 1.1 fvdl /*
904 1.1 fvdl * Maximum targets
905 1.1 fvdl */
906 1.17 perry uint16_t max_targets; /* word 19 */
907 1.1 fvdl #define CFMAXTARG 0x00ff /* maximum targets */
908 1.1 fvdl #define CFBOOTLUN 0x0f00 /* Lun to boot from */
909 1.1 fvdl #define CFBOOTID 0xf000 /* Target to boot from */
910 1.1 fvdl uint16_t res_1[10]; /* words 20-29 */
911 1.1 fvdl uint16_t signature; /* BIOS Signature */
912 1.1 fvdl #define CFSIGNATURE 0x400
913 1.1 fvdl uint16_t checksum; /* word 31 */
914 1.1 fvdl };
915 1.1 fvdl
916 1.7 thorpej /*
917 1.7 thorpej * Vital Product Data used during POST and by the BIOS.
918 1.7 thorpej */
919 1.7 thorpej struct vpd_config {
920 1.7 thorpej uint8_t bios_flags;
921 1.7 thorpej #define VPDMASTERBIOS 0x0001
922 1.7 thorpej #define VPDBOOTHOST 0x0002
923 1.7 thorpej uint8_t reserved_1[21];
924 1.7 thorpej uint8_t resource_type;
925 1.7 thorpej uint8_t resource_len[2];
926 1.7 thorpej uint8_t resource_data[8];
927 1.7 thorpej uint8_t vpd_tag;
928 1.7 thorpej uint16_t vpd_len;
929 1.7 thorpej uint8_t vpd_keyword[2];
930 1.7 thorpej uint8_t length;
931 1.7 thorpej uint8_t revision;
932 1.7 thorpej uint8_t device_flags;
933 1.7 thorpej uint8_t termnation_menus[2];
934 1.7 thorpej uint8_t fifo_threshold;
935 1.7 thorpej uint8_t end_tag;
936 1.7 thorpej uint8_t vpd_checksum;
937 1.7 thorpej uint16_t default_target_flags;
938 1.7 thorpej uint16_t default_bios_flags;
939 1.7 thorpej uint16_t default_ctrl_flags;
940 1.7 thorpej uint8_t default_irq;
941 1.7 thorpej uint8_t pci_lattime;
942 1.7 thorpej uint8_t max_target;
943 1.7 thorpej uint8_t boot_lun;
944 1.7 thorpej uint16_t signature;
945 1.7 thorpej uint8_t reserved_2;
946 1.7 thorpej uint8_t checksum;
947 1.7 thorpej uint8_t reserved_3[4];
948 1.7 thorpej };
949 1.7 thorpej
950 1.1 fvdl /****************************** Flexport Logic ********************************/
951 1.1 fvdl #define FLXADDR_TERMCTL 0x0
952 1.1 fvdl #define FLX_TERMCTL_ENSECHIGH 0x8
953 1.1 fvdl #define FLX_TERMCTL_ENSECLOW 0x4
954 1.1 fvdl #define FLX_TERMCTL_ENPRIHIGH 0x2
955 1.1 fvdl #define FLX_TERMCTL_ENPRILOW 0x1
956 1.1 fvdl #define FLXADDR_ROMSTAT_CURSENSECTL 0x1
957 1.1 fvdl #define FLX_ROMSTAT_SEECFG 0xF0
958 1.1 fvdl #define FLX_ROMSTAT_EECFG 0x0F
959 1.1 fvdl #define FLX_ROMSTAT_SEE_93C66 0x00
960 1.1 fvdl #define FLX_ROMSTAT_SEE_NONE 0xF0
961 1.1 fvdl #define FLX_ROMSTAT_EE_512x8 0x0
962 1.1 fvdl #define FLX_ROMSTAT_EE_1MBx8 0x1
963 1.1 fvdl #define FLX_ROMSTAT_EE_2MBx8 0x2
964 1.1 fvdl #define FLX_ROMSTAT_EE_4MBx8 0x3
965 1.1 fvdl #define FLX_ROMSTAT_EE_16MBx8 0x4
966 1.1 fvdl #define CURSENSE_ENB 0x1
967 1.1 fvdl #define FLXADDR_FLEXSTAT 0x2
968 1.1 fvdl #define FLX_FSTAT_BUSY 0x1
969 1.1 fvdl #define FLXADDR_CURRENT_STAT 0x4
970 1.1 fvdl #define FLX_CSTAT_SEC_HIGH 0xC0
971 1.1 fvdl #define FLX_CSTAT_SEC_LOW 0x30
972 1.1 fvdl #define FLX_CSTAT_PRI_HIGH 0x0C
973 1.1 fvdl #define FLX_CSTAT_PRI_LOW 0x03
974 1.1 fvdl #define FLX_CSTAT_MASK 0x03
975 1.1 fvdl #define FLX_CSTAT_SHIFT 2
976 1.1 fvdl #define FLX_CSTAT_OKAY 0x0
977 1.1 fvdl #define FLX_CSTAT_OVER 0x1
978 1.1 fvdl #define FLX_CSTAT_UNDER 0x2
979 1.1 fvdl #define FLX_CSTAT_INVALID 0x3
980 1.1 fvdl
981 1.7 thorpej int ahd_read_seeprom(struct ahd_softc *, uint16_t *, u_int, u_int,
982 1.7 thorpej int);
983 1.1 fvdl
984 1.5 itojun int ahd_write_seeprom(struct ahd_softc *, uint16_t *, u_int, u_int);
985 1.5 itojun int ahd_wait_seeprom(struct ahd_softc *);
986 1.7 thorpej int ahd_verify_vpd_cksum(struct vpd_config *);
987 1.5 itojun int ahd_verify_cksum(struct seeprom_config *);
988 1.5 itojun int ahd_acquire_seeprom(struct ahd_softc *);
989 1.5 itojun void ahd_release_seeprom(struct ahd_softc *);
990 1.1 fvdl
991 1.1 fvdl /**************************** Message Buffer *********************************/
992 1.1 fvdl typedef enum {
993 1.1 fvdl MSG_FLAG_NONE = 0x00,
994 1.1 fvdl MSG_FLAG_EXPECT_PPR_BUSFREE = 0x01,
995 1.1 fvdl MSG_FLAG_IU_REQ_CHANGED = 0x02,
996 1.1 fvdl MSG_FLAG_EXPECT_IDE_BUSFREE = 0x04,
997 1.1 fvdl MSG_FLAG_EXPECT_QASREJ_BUSFREE = 0x08,
998 1.1 fvdl MSG_FLAG_PACKETIZED = 0x10
999 1.1 fvdl } ahd_msg_flags;
1000 1.1 fvdl
1001 1.1 fvdl typedef enum {
1002 1.1 fvdl MSG_TYPE_NONE = 0x00,
1003 1.1 fvdl MSG_TYPE_INITIATOR_MSGOUT = 0x01,
1004 1.1 fvdl MSG_TYPE_INITIATOR_MSGIN = 0x02,
1005 1.1 fvdl MSG_TYPE_TARGET_MSGOUT = 0x03,
1006 1.1 fvdl MSG_TYPE_TARGET_MSGIN = 0x04
1007 1.1 fvdl } ahd_msg_type;
1008 1.1 fvdl
1009 1.1 fvdl typedef enum {
1010 1.1 fvdl MSGLOOP_IN_PROG,
1011 1.1 fvdl MSGLOOP_MSGCOMPLETE,
1012 1.1 fvdl MSGLOOP_TERMINATED
1013 1.1 fvdl } msg_loop_stat;
1014 1.1 fvdl
1015 1.1 fvdl /*********************** Software Configuration Structure *********************/
1016 1.1 fvdl struct ahd_suspend_channel_state {
1017 1.1 fvdl uint8_t scsiseq;
1018 1.1 fvdl uint8_t sxfrctl0;
1019 1.1 fvdl uint8_t sxfrctl1;
1020 1.1 fvdl uint8_t simode0;
1021 1.1 fvdl uint8_t simode1;
1022 1.1 fvdl uint8_t seltimer;
1023 1.1 fvdl uint8_t seqctl;
1024 1.1 fvdl };
1025 1.1 fvdl
1026 1.1 fvdl struct ahd_suspend_state {
1027 1.1 fvdl struct ahd_suspend_channel_state channel[2];
1028 1.1 fvdl uint8_t optionmode;
1029 1.1 fvdl uint8_t dscommand0;
1030 1.1 fvdl uint8_t dspcistatus;
1031 1.1 fvdl /* hsmailbox */
1032 1.1 fvdl uint8_t crccontrol1;
1033 1.1 fvdl uint8_t scbbaddr;
1034 1.1 fvdl /* Host and sequencer SCB counts */
1035 1.1 fvdl uint8_t dff_thrsh;
1036 1.1 fvdl uint8_t *scratch_ram;
1037 1.1 fvdl uint8_t *btt;
1038 1.1 fvdl };
1039 1.1 fvdl
1040 1.1 fvdl typedef int (*ahd_bus_intr_t)(struct ahd_softc *);
1041 1.1 fvdl
1042 1.1 fvdl typedef enum {
1043 1.1 fvdl AHD_MODE_DFF0,
1044 1.1 fvdl AHD_MODE_DFF1,
1045 1.1 fvdl AHD_MODE_CCHAN,
1046 1.1 fvdl AHD_MODE_SCSI,
1047 1.1 fvdl AHD_MODE_CFG,
1048 1.1 fvdl AHD_MODE_UNKNOWN
1049 1.1 fvdl } ahd_mode;
1050 1.1 fvdl
1051 1.1 fvdl #define AHD_MK_MSK(x) (0x01 << (x))
1052 1.1 fvdl #define AHD_MODE_DFF0_MSK AHD_MK_MSK(AHD_MODE_DFF0)
1053 1.1 fvdl #define AHD_MODE_DFF1_MSK AHD_MK_MSK(AHD_MODE_DFF1)
1054 1.1 fvdl #define AHD_MODE_CCHAN_MSK AHD_MK_MSK(AHD_MODE_CCHAN)
1055 1.1 fvdl #define AHD_MODE_SCSI_MSK AHD_MK_MSK(AHD_MODE_SCSI)
1056 1.1 fvdl #define AHD_MODE_CFG_MSK AHD_MK_MSK(AHD_MODE_CFG)
1057 1.1 fvdl #define AHD_MODE_UNKNOWN_MSK AHD_MK_MSK(AHD_MODE_UNKNOWN)
1058 1.1 fvdl #define AHD_MODE_ANY_MSK (~0)
1059 1.1 fvdl
1060 1.1 fvdl typedef uint8_t ahd_mode_state;
1061 1.1 fvdl
1062 1.1 fvdl typedef void ahd_callback_t (void *);
1063 1.1 fvdl
1064 1.1 fvdl struct ahd_softc {
1065 1.27 tsutsui device_t sc_dev;
1066 1.1 fvdl
1067 1.1 fvdl struct scsipi_channel sc_channel;
1068 1.24 cegger device_t sc_child;
1069 1.1 fvdl struct scsipi_adapter sc_adapter;
1070 1.1 fvdl
1071 1.1 fvdl bus_space_tag_t tags[2];
1072 1.1 fvdl bus_space_handle_t bshs[2];
1073 1.1 fvdl
1074 1.1 fvdl struct scb_data scb_data;
1075 1.1 fvdl
1076 1.1 fvdl struct hardware_scb *next_queued_hscb;
1077 1.6 thorpej struct map_node *next_queued_hscb_map;
1078 1.1 fvdl
1079 1.1 fvdl /*
1080 1.1 fvdl * SCBs that have been sent to the controller
1081 1.1 fvdl */
1082 1.1 fvdl LIST_HEAD(, scb) pending_scbs;
1083 1.1 fvdl
1084 1.1 fvdl /*
1085 1.1 fvdl * Current register window mode information.
1086 1.1 fvdl */
1087 1.1 fvdl ahd_mode dst_mode;
1088 1.1 fvdl ahd_mode src_mode;
1089 1.1 fvdl
1090 1.1 fvdl /*
1091 1.1 fvdl * Saved register window mode information
1092 1.1 fvdl * used for restore on next unpause.
1093 1.1 fvdl */
1094 1.1 fvdl ahd_mode saved_dst_mode;
1095 1.1 fvdl ahd_mode saved_src_mode;
1096 1.1 fvdl
1097 1.1 fvdl /*
1098 1.1 fvdl * Platform specific data.
1099 1.1 fvdl */
1100 1.1 fvdl struct ahd_platform_data *platform_data;
1101 1.1 fvdl
1102 1.1 fvdl /*
1103 1.1 fvdl * Bus specific device information.
1104 1.1 fvdl */
1105 1.1 fvdl ahd_bus_intr_t bus_intr;
1106 1.1 fvdl
1107 1.1 fvdl /*
1108 1.1 fvdl * Target mode related state kept on a per enabled lun basis.
1109 1.1 fvdl * Targets that are not enabled will have null entries.
1110 1.1 fvdl * As an initiator, we keep one target entry for our initiator
1111 1.1 fvdl * ID to store our sync/wide transfer settings.
1112 1.1 fvdl */
1113 1.1 fvdl struct ahd_tmode_tstate *enabled_targets[AHD_NUM_TARGETS];
1114 1.1 fvdl
1115 1.1 fvdl char inited_target[AHD_NUM_TARGETS];
1116 1.1 fvdl
1117 1.1 fvdl /*
1118 1.1 fvdl * The black hole device responsible for handling requests for
1119 1.1 fvdl * disabled luns on enabled targets.
1120 1.1 fvdl */
1121 1.1 fvdl struct ahd_tmode_lstate *black_hole;
1122 1.1 fvdl
1123 1.1 fvdl /*
1124 1.1 fvdl * Device instance currently on the bus awaiting a continue TIO
1125 1.14 wiz * for a command that was not given the disconnect priviledge.
1126 1.1 fvdl */
1127 1.1 fvdl struct ahd_tmode_lstate *pending_device;
1128 1.1 fvdl
1129 1.1 fvdl /*
1130 1.1 fvdl * Timer handles for timer driven callbacks.
1131 1.1 fvdl */
1132 1.1 fvdl ahd_timer_t reset_timer;
1133 1.1 fvdl ahd_timer_t stat_timer;
1134 1.1 fvdl
1135 1.1 fvdl /*
1136 1.1 fvdl * Statistics.
1137 1.1 fvdl */
1138 1.1 fvdl #define AHD_STAT_UPDATE_US 250000 /* 250ms */
1139 1.1 fvdl #define AHD_STAT_BUCKETS 4
1140 1.1 fvdl u_int cmdcmplt_bucket;
1141 1.1 fvdl uint32_t cmdcmplt_counts[AHD_STAT_BUCKETS];
1142 1.1 fvdl uint32_t cmdcmplt_total;
1143 1.1 fvdl
1144 1.1 fvdl /*
1145 1.1 fvdl * Card characteristics
1146 1.1 fvdl */
1147 1.1 fvdl ahd_chip chip;
1148 1.1 fvdl ahd_feature features;
1149 1.1 fvdl ahd_bug bugs;
1150 1.1 fvdl ahd_flag flags;
1151 1.1 fvdl struct seeprom_config *seep_config;
1152 1.1 fvdl
1153 1.1 fvdl /* Values to store in the SEQCTL register for pause and unpause */
1154 1.1 fvdl uint8_t unpause;
1155 1.1 fvdl uint8_t pause;
1156 1.1 fvdl
1157 1.1 fvdl /* Command Queues */
1158 1.1 fvdl uint16_t qoutfifonext;
1159 1.1 fvdl uint16_t qoutfifonext_valid_tag;
1160 1.1 fvdl uint16_t qinfifonext;
1161 1.1 fvdl uint16_t qinfifo[AHD_SCB_MAX];
1162 1.1 fvdl uint16_t *qoutfifo;
1163 1.1 fvdl
1164 1.1 fvdl /* Critical Section Data */
1165 1.1 fvdl struct cs *critical_sections;
1166 1.1 fvdl u_int num_critical_sections;
1167 1.1 fvdl
1168 1.1 fvdl /* Buffer for handling packetized bitbucket. */
1169 1.1 fvdl uint8_t *overrun_buf;
1170 1.1 fvdl
1171 1.1 fvdl /* Links for chaining softcs */
1172 1.1 fvdl TAILQ_ENTRY(ahd_softc) links;
1173 1.1 fvdl
1174 1.1 fvdl /* Channel Names ('A', 'B', etc.) */
1175 1.1 fvdl char channel;
1176 1.1 fvdl
1177 1.1 fvdl /* Initiator Bus ID */
1178 1.1 fvdl uint8_t our_id;
1179 1.1 fvdl
1180 1.1 fvdl /*
1181 1.1 fvdl * Target incoming command FIFO.
1182 1.1 fvdl */
1183 1.1 fvdl struct target_cmd *targetcmds;
1184 1.1 fvdl uint8_t tqinfifonext;
1185 1.1 fvdl
1186 1.1 fvdl /*
1187 1.1 fvdl * Cached verson of the hs_mailbox so we can avoid
1188 1.1 fvdl * pausing the sequencer during mailbox updates.
1189 1.1 fvdl */
1190 1.1 fvdl uint8_t hs_mailbox;
1191 1.1 fvdl
1192 1.1 fvdl /*
1193 1.1 fvdl * Incoming and outgoing message handling.
1194 1.1 fvdl */
1195 1.1 fvdl uint8_t send_msg_perror;
1196 1.1 fvdl ahd_msg_flags msg_flags;
1197 1.1 fvdl ahd_msg_type msg_type;
1198 1.1 fvdl uint8_t msgout_buf[12];/* Message we are sending */
1199 1.1 fvdl uint8_t msgin_buf[12];/* Message we are receiving */
1200 1.1 fvdl u_int msgout_len; /* Length of message to send */
1201 1.1 fvdl u_int msgout_index; /* Current index in msgout */
1202 1.1 fvdl u_int msgin_index; /* Current index in msgin */
1203 1.1 fvdl
1204 1.1 fvdl /*
1205 1.1 fvdl * Mapping information for data structures shared
1206 1.1 fvdl * between the sequencer and kernel.
1207 1.1 fvdl */
1208 1.1 fvdl bus_dma_tag_t parent_dmat;
1209 1.1 fvdl bus_dma_tag_t shared_data_dmat;
1210 1.6 thorpej struct map_node shared_data_map;
1211 1.1 fvdl int shared_data_size;
1212 1.1 fvdl int sc_dmaflags;
1213 1.1 fvdl
1214 1.1 fvdl /* Information saved through suspend/resume cycles */
1215 1.1 fvdl struct ahd_suspend_state suspend_state;
1216 1.1 fvdl
1217 1.1 fvdl /* Number of enabled target mode device on this card */
1218 1.1 fvdl u_int enabled_luns;
1219 1.1 fvdl
1220 1.1 fvdl /* Initialization level of this data structure */
1221 1.1 fvdl u_int init_level;
1222 1.1 fvdl
1223 1.1 fvdl /* PCI cacheline size. */
1224 1.1 fvdl u_int pci_cachesize;
1225 1.1 fvdl
1226 1.1 fvdl /* IO Cell Parameters */
1227 1.1 fvdl uint8_t iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
1228 1.1 fvdl
1229 1.1 fvdl u_int stack_size;
1230 1.1 fvdl uint16_t *saved_stack;
1231 1.1 fvdl
1232 1.1 fvdl /* Per-Unit descriptive information */
1233 1.1 fvdl const char *description;
1234 1.1 fvdl const char *bus_description;
1235 1.23 dyoung const char *name;
1236 1.1 fvdl int unit;
1237 1.1 fvdl
1238 1.1 fvdl /* Selection Timer settings */
1239 1.1 fvdl int seltime;
1240 1.1 fvdl
1241 1.1 fvdl /*
1242 1.4 wiz * Interrupt coalescing settings.
1243 1.1 fvdl */
1244 1.4 wiz #define AHD_INT_COALESCING_TIMER_DEFAULT 250 /*us*/
1245 1.4 wiz #define AHD_INT_COALESCING_MAXCMDS_DEFAULT 10
1246 1.4 wiz #define AHD_INT_COALESCING_MAXCMDS_MAX 127
1247 1.4 wiz #define AHD_INT_COALESCING_MINCMDS_DEFAULT 5
1248 1.4 wiz #define AHD_INT_COALESCING_MINCMDS_MAX 127
1249 1.4 wiz #define AHD_INT_COALESCING_THRESHOLD_DEFAULT 2000
1250 1.4 wiz #define AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT 1000
1251 1.4 wiz u_int int_coalescing_timer;
1252 1.4 wiz u_int int_coalescing_maxcmds;
1253 1.4 wiz u_int int_coalescing_mincmds;
1254 1.4 wiz u_int int_coalescing_threshold;
1255 1.4 wiz u_int int_coalescing_stop_threshold;
1256 1.1 fvdl
1257 1.1 fvdl uint16_t user_discenable;/* Disconnection allowed */
1258 1.1 fvdl uint16_t user_tagenable;/* Tagged Queuing allowed */
1259 1.1 fvdl
1260 1.25 tsutsui /* Adapter interrupt routine */
1261 1.1 fvdl void* ih;
1262 1.1 fvdl struct ahd_pci_busdata *bus_data;
1263 1.1 fvdl };
1264 1.1 fvdl
1265 1.1 fvdl TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
1266 1.1 fvdl extern struct ahd_softc_tailq ahd_tailq;
1267 1.1 fvdl
1268 1.1 fvdl /*************************** IO Cell Configuration ****************************/
1269 1.1 fvdl #define AHD_PRECOMP_SLEW_INDEX \
1270 1.1 fvdl (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
1271 1.1 fvdl
1272 1.1 fvdl #define AHD_AMPLITUDE_INDEX \
1273 1.1 fvdl (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
1274 1.1 fvdl
1275 1.1 fvdl #define AHD_SET_SLEWRATE(ahd, new_slew) \
1276 1.1 fvdl do { \
1277 1.1 fvdl (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK; \
1278 1.1 fvdl (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
1279 1.1 fvdl (((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK); \
1280 1.1 fvdl } while (0)
1281 1.1 fvdl
1282 1.1 fvdl #define AHD_SET_PRECOMP(ahd, new_pcomp) \
1283 1.1 fvdl do { \
1284 1.1 fvdl (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK; \
1285 1.1 fvdl (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
1286 1.1 fvdl (((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK); \
1287 1.1 fvdl } while (0)
1288 1.1 fvdl
1289 1.1 fvdl #define AHD_SET_AMPLITUDE(ahd, new_amp) \
1290 1.1 fvdl do { \
1291 1.1 fvdl (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK; \
1292 1.1 fvdl (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |= \
1293 1.1 fvdl (((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK); \
1294 1.1 fvdl } while (0)
1295 1.1 fvdl
1296 1.1 fvdl /************************ Active Device Information ***************************/
1297 1.1 fvdl typedef enum {
1298 1.1 fvdl ROLE_UNKNOWN,
1299 1.1 fvdl ROLE_INITIATOR,
1300 1.1 fvdl ROLE_TARGET
1301 1.1 fvdl } role_t;
1302 1.1 fvdl
1303 1.1 fvdl struct ahd_devinfo {
1304 1.1 fvdl int our_scsiid;
1305 1.1 fvdl int target_offset;
1306 1.1 fvdl uint16_t target_mask;
1307 1.1 fvdl u_int target;
1308 1.1 fvdl u_int lun;
1309 1.1 fvdl char channel;
1310 1.1 fvdl role_t role; /*
1311 1.1 fvdl * Only guaranteed to be correct if not
1312 1.1 fvdl * in the busfree state.
1313 1.1 fvdl */
1314 1.1 fvdl };
1315 1.1 fvdl
1316 1.1 fvdl /****************************** PCI Structures ********************************/
1317 1.1 fvdl #define AHD_PCI_IOADDR0 PCI_MAPREG_START /* I/O BAR*/
1318 1.1 fvdl #define AHD_PCI_MEMADDR (PCI_MAPREG_START + 4) /* Memory BAR */
1319 1.1 fvdl #define AHD_PCI_IOADDR1 (PCI_MAPREG_START + 12)/* Second I/O BAR */
1320 1.1 fvdl
1321 1.1 fvdl typedef int (ahd_device_setup_t)(struct ahd_softc *, struct pci_attach_args *);
1322 1.1 fvdl
1323 1.1 fvdl struct ahd_pci_identity {
1324 1.1 fvdl uint64_t full_id;
1325 1.1 fvdl uint64_t id_mask;
1326 1.18 christos const char *name;
1327 1.1 fvdl ahd_device_setup_t *setup;
1328 1.1 fvdl };
1329 1.1 fvdl
1330 1.1 fvdl /***************************** VL/EISA Declarations ***************************/
1331 1.1 fvdl struct aic7770_identity {
1332 1.1 fvdl uint32_t full_id;
1333 1.1 fvdl uint32_t id_mask;
1334 1.18 christos const char *name;
1335 1.1 fvdl ahd_device_setup_t *setup;
1336 1.1 fvdl };
1337 1.1 fvdl extern struct aic7770_identity aic7770_ident_table [];
1338 1.1 fvdl extern const int ahd_num_aic7770_devs;
1339 1.1 fvdl
1340 1.1 fvdl #define AHD_EISA_SLOT_OFFSET 0xc00
1341 1.1 fvdl #define AHD_EISA_IOSIZE 0x100
1342 1.1 fvdl
1343 1.1 fvdl /*************************** Function Declarations ****************************/
1344 1.1 fvdl /******************************************************************************/
1345 1.5 itojun void ahd_reset_cmds_pending(struct ahd_softc *);
1346 1.5 itojun u_int ahd_find_busy_tcl(struct ahd_softc *, u_int);
1347 1.5 itojun void ahd_busy_tcl(struct ahd_softc *, u_int, u_int);
1348 1.22 perry static __inline void ahd_unbusy_tcl(struct ahd_softc *, u_int);
1349 1.22 perry static __inline void
1350 1.1 fvdl ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
1351 1.1 fvdl {
1352 1.1 fvdl ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
1353 1.1 fvdl }
1354 1.1 fvdl
1355 1.1 fvdl /************************** SCB and SCB queue management **********************/
1356 1.1 fvdl int ahd_probe_scbs(struct ahd_softc *);
1357 1.5 itojun void ahd_qinfifo_requeue_tail(struct ahd_softc *,
1358 1.5 itojun struct scb *);
1359 1.5 itojun int ahd_match_scb(struct ahd_softc *, struct scb *,
1360 1.5 itojun int, char, int, u_int, role_t);
1361 1.1 fvdl
1362 1.1 fvdl /****************************** Initialization ********************************/
1363 1.5 itojun /*struct ahd_softc *ahd_alloc(void *, char *);*/
1364 1.1 fvdl int ahd_softc_init(struct ahd_softc *);
1365 1.16 itojun void ahd_controller_info(struct ahd_softc *, char *, size_t);
1366 1.5 itojun int ahd_init(struct ahd_softc *);
1367 1.5 itojun int ahd_default_config(struct ahd_softc *);
1368 1.7 thorpej int ahd_parse_vpddata(struct ahd_softc *,
1369 1.7 thorpej struct vpd_config *);
1370 1.5 itojun int ahd_parse_cfgdata(struct ahd_softc *,
1371 1.5 itojun struct seeprom_config *);
1372 1.5 itojun void ahd_intr_enable(struct ahd_softc *, int);
1373 1.5 itojun void ahd_update_coalescing_values(struct ahd_softc *,
1374 1.5 itojun u_int, u_int, u_int);
1375 1.5 itojun void ahd_enable_coalescing(struct ahd_softc *, int);
1376 1.5 itojun void ahd_pause_and_flushwork(struct ahd_softc *);
1377 1.17 perry int ahd_suspend(struct ahd_softc *);
1378 1.5 itojun int ahd_resume(struct ahd_softc *);
1379 1.1 fvdl void ahd_set_unit(struct ahd_softc *, int);
1380 1.23 dyoung void ahd_set_name(struct ahd_softc *, const char *);
1381 1.5 itojun struct scb *ahd_get_scb(struct ahd_softc *, u_int);
1382 1.5 itojun void ahd_free_scb(struct ahd_softc *, struct scb *);
1383 1.20 bouyer int ahd_alloc_scbs(struct ahd_softc *);
1384 1.5 itojun void ahd_free(struct ahd_softc *);
1385 1.8 thorpej int ahd_reset(struct ahd_softc *, int);
1386 1.5 itojun void ahd_shutdown(void *);
1387 1.8 thorpej int ahd_write_flexport(struct ahd_softc *,
1388 1.8 thorpej u_int, u_int);
1389 1.8 thorpej int ahd_read_flexport(struct ahd_softc *, u_int,
1390 1.8 thorpej uint8_t *);
1391 1.8 thorpej int ahd_wait_flexport(struct ahd_softc *);
1392 1.1 fvdl
1393 1.1 fvdl /*************************** Interrupt Services *******************************/
1394 1.5 itojun void ahd_clear_intstat(struct ahd_softc *);
1395 1.5 itojun void ahd_flush_qoutfifo(struct ahd_softc *);
1396 1.5 itojun void ahd_run_qoutfifo(struct ahd_softc *);
1397 1.5 itojun void ahd_run_post_qoutfifo(struct ahd_softc *);
1398 1.1 fvdl #ifdef AHD_TARGET_MODE
1399 1.5 itojun void ahd_run_tqinfifo(struct ahd_softc *, int);
1400 1.1 fvdl #endif
1401 1.5 itojun void ahd_handle_hwerrint(struct ahd_softc *);
1402 1.5 itojun void ahd_handle_seqint(struct ahd_softc *, u_int);
1403 1.5 itojun void ahd_handle_scsiint(struct ahd_softc *, u_int);
1404 1.5 itojun void ahd_clear_critical_section(struct ahd_softc *);
1405 1.1 fvdl
1406 1.1 fvdl /***************************** Error Recovery *********************************/
1407 1.1 fvdl typedef enum {
1408 1.1 fvdl SEARCH_COMPLETE,
1409 1.1 fvdl SEARCH_COUNT,
1410 1.1 fvdl SEARCH_REMOVE,
1411 1.1 fvdl SEARCH_PRINT
1412 1.1 fvdl } ahd_search_action;
1413 1.5 itojun int ahd_search_qinfifo(struct ahd_softc *, int, char, int,
1414 1.5 itojun u_int, role_t, uint32_t, ahd_search_action);
1415 1.5 itojun int ahd_search_disc_list(struct ahd_softc *, int, char,
1416 1.5 itojun int, u_int, int, int, int);
1417 1.5 itojun void ahd_freeze_devq(struct ahd_softc *, struct scb *);
1418 1.5 itojun int ahd_reset_channel(struct ahd_softc *, char, int);
1419 1.5 itojun int ahd_abort_scbs(struct ahd_softc *, int, char, int,
1420 1.5 itojun u_int, role_t, uint32_t);
1421 1.5 itojun void ahd_restart(struct ahd_softc *);
1422 1.5 itojun void ahd_clear_fifo(struct ahd_softc *, u_int);
1423 1.5 itojun void ahd_handle_scb_status(struct ahd_softc *, struct scb *);
1424 1.5 itojun void ahd_handle_scsi_status(struct ahd_softc *,
1425 1.5 itojun struct scb *);
1426 1.5 itojun void ahd_calc_residual(struct ahd_softc *, struct scb *);
1427 1.1 fvdl /*************************** Utility Functions ********************************/
1428 1.1 fvdl struct ahd_phase_table_entry*
1429 1.5 itojun ahd_lookup_phase_entry(int);
1430 1.5 itojun void ahd_compile_devinfo(struct ahd_devinfo *, u_int, u_int,
1431 1.5 itojun u_int, char, role_t);
1432 1.1 fvdl /************************** Transfer Negotiation ******************************/
1433 1.5 itojun void ahd_find_syncrate(struct ahd_softc *, u_int *,
1434 1.5 itojun u_int *, u_int);
1435 1.5 itojun void ahd_validate_offset(struct ahd_softc *,
1436 1.5 itojun struct ahd_initiator_tinfo *, u_int, u_int *,
1437 1.5 itojun int, role_t);
1438 1.5 itojun void ahd_validate_width(struct ahd_softc *,
1439 1.5 itojun struct ahd_initiator_tinfo *, u_int *, role_t);
1440 1.1 fvdl /*
1441 1.1 fvdl * Negotiation types. These are used to qualify if we should renegotiate
1442 1.1 fvdl * even if our goal and current transport parameters are identical.
1443 1.1 fvdl */
1444 1.1 fvdl typedef enum {
1445 1.1 fvdl AHD_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */
1446 1.1 fvdl AHD_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */
1447 1.1 fvdl AHD_NEG_ALWAYS /* Renegotiat even if goal is async. */
1448 1.1 fvdl } ahd_neg_type;
1449 1.5 itojun int ahd_update_neg_request(struct ahd_softc *,
1450 1.5 itojun struct ahd_devinfo *, struct ahd_tmode_tstate *,
1451 1.5 itojun struct ahd_initiator_tinfo *, ahd_neg_type);
1452 1.5 itojun void ahd_set_width(struct ahd_softc *,
1453 1.5 itojun struct ahd_devinfo *, u_int, u_int, int);
1454 1.5 itojun void ahd_set_syncrate(struct ahd_softc *,
1455 1.5 itojun struct ahd_devinfo *, u_int, u_int, u_int,
1456 1.5 itojun u_int, int);
1457 1.1 fvdl typedef enum {
1458 1.1 fvdl AHD_QUEUE_NONE,
1459 1.1 fvdl AHD_QUEUE_BASIC,
1460 1.1 fvdl AHD_QUEUE_TAGGED
1461 1.1 fvdl } ahd_queue_alg;
1462 1.1 fvdl
1463 1.5 itojun void ahd_set_tags(struct ahd_softc *, struct ahd_devinfo *,
1464 1.5 itojun ahd_queue_alg);
1465 1.1 fvdl
1466 1.1 fvdl /**************************** Target Mode *************************************/
1467 1.1 fvdl #ifdef AHD_TARGET_MODE
1468 1.1 fvdl void ahd_send_lstate_events(struct ahd_softc *,
1469 1.5 itojun struct ahd_tmode_lstate *);
1470 1.5 itojun void ahd_handle_en_lun(struct ahd_softc *,
1471 1.5 itojun struct cam_sim *, union ccb *);
1472 1.5 itojun cam_status ahd_find_tmode_devs(struct ahd_softc *, struct cam_sim *,
1473 1.5 itojun union ccb *, struct ahd_tmode_tstate **,
1474 1.5 itojun struct ahd_tmode_lstate **, int);
1475 1.1 fvdl #ifndef AHD_TMODE_ENABLE
1476 1.1 fvdl #define AHD_TMODE_ENABLE 0
1477 1.1 fvdl #endif
1478 1.1 fvdl #endif
1479 1.1 fvdl /******************************* Debug ***************************************/
1480 1.1 fvdl #ifdef AHD_DEBUG
1481 1.1 fvdl extern uint32_t ahd_debug;
1482 1.1 fvdl #define AHD_SHOW_MISC 0x00001
1483 1.1 fvdl #define AHD_SHOW_SENSE 0x00002
1484 1.1 fvdl #define AHD_SHOW_RECOVERY 0x00004
1485 1.1 fvdl #define AHD_DUMP_SEEPROM 0x00008
1486 1.1 fvdl #define AHD_SHOW_TERMCTL 0x00010
1487 1.1 fvdl #define AHD_SHOW_MEMORY 0x00020
1488 1.1 fvdl #define AHD_SHOW_MESSAGES 0x00040
1489 1.1 fvdl #define AHD_SHOW_MODEPTR 0x00080
1490 1.1 fvdl #define AHD_SHOW_SELTO 0x00100
1491 1.1 fvdl #define AHD_SHOW_FIFOS 0x00200
1492 1.1 fvdl #define AHD_SHOW_QFULL 0x00400
1493 1.1 fvdl #define AHD_SHOW_DV 0x00800
1494 1.1 fvdl #define AHD_SHOW_MASKED_ERRORS 0x01000
1495 1.1 fvdl #define AHD_SHOW_QUEUE 0x02000
1496 1.1 fvdl #define AHD_SHOW_TQIN 0x04000
1497 1.1 fvdl #define AHD_SHOW_SG 0x08000
1498 1.4 wiz #define AHD_SHOW_INT_COALESCING 0x10000
1499 1.1 fvdl #define AHD_DEBUG_SEQUENCER 0x20000
1500 1.1 fvdl #endif
1501 1.5 itojun void ahd_print_scb(struct scb *);
1502 1.5 itojun void ahd_print_devinfo(struct ahd_softc *,
1503 1.5 itojun struct ahd_devinfo *);
1504 1.5 itojun void ahd_dump_sglist(struct scb *);
1505 1.1 fvdl void ahd_dump_all_cards_state(void);
1506 1.5 itojun void ahd_dump_card_state(struct ahd_softc *);
1507 1.5 itojun int ahd_print_register(ahd_reg_parse_entry_t *, u_int,
1508 1.5 itojun const char *, u_int, u_int, u_int *, u_int);
1509 1.5 itojun void ahd_dump_scbs(struct ahd_softc *);
1510 1.1 fvdl #endif /* _AIC79XXVAR_H_ */
1511