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