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