2 * Core definitions and data structures shareable across OS platforms.
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2000-2002 Adaptec Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
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.
40 * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#56 $
48 /* Register Definitions */
49 #include "aic79xx_reg.h"
51 /************************* Forward Declarations *******************************/
52 struct ahd_platform_data;
53 struct scb_platform_data;
55 /****************************** Useful Macros *********************************/
57 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
61 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
71 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
73 #define ALL_CHANNELS '\0'
74 #define ALL_TARGETS_MASK 0xFFFF
75 #define INITIATOR_WILDCARD (~0)
76 #define SCB_LIST_NULL 0xFF00
77 #define SCB_LIST_NULL_LE (ahd_htole16(SCB_LIST_NULL))
78 #define QOUTFIFO_ENTRY_VALID 0x8000
79 #define QOUTFIFO_ENTRY_VALID_LE (ahd_htole16(0x8000))
80 #define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
82 #define SCSIID_TARGET(ahd, scsiid) \
83 (((scsiid) & TID) >> TID_SHIFT)
84 #define SCSIID_OUR_ID(scsiid) \
86 #define SCSIID_CHANNEL(ahd, scsiid) ('A')
87 #define SCB_IS_SCSIBUS_B(ahd, scb) (0)
88 #define SCB_GET_OUR_ID(scb) \
89 SCSIID_OUR_ID((scb)->hscb->scsiid)
90 #define SCB_GET_TARGET(ahd, scb) \
91 SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
92 #define SCB_GET_CHANNEL(ahd, scb) \
93 SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
94 #define SCB_GET_LUN(scb) \
96 #define SCB_GET_TARGET_OFFSET(ahd, scb) \
97 SCB_GET_TARGET(ahd, scb)
98 #define SCB_GET_TARGET_MASK(ahd, scb) \
99 (0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
101 * TCLs have the following format: TTTTLLLLLLLL
103 #define TCL_TARGET_OFFSET(tcl) \
104 ((((tcl) >> 4) & TID) >> 4)
105 #define TCL_LUN(tcl) \
106 (tcl & (AHD_NUM_LUNS - 1))
107 #define BUILD_TCL(scsiid, lun) \
108 ((lun) | (((scsiid) & TID) << 4))
109 #define BUILD_TCL_RAW(target, channel, lun) \
110 ((lun) | ((target) << 8))
112 #define SCB_GET_TAG(scb) \
113 ahd_le16toh(scb->hscb->tag)
115 #ifndef AHD_TARGET_MODE
116 #undef AHD_TMODE_ENABLE
117 #define AHD_TMODE_ENABLE 0
120 #define AHD_BUILD_COL_IDX(target, lun) \
121 (((lun) << 4) | target)
123 #define AHD_GET_SCB_COL_IDX(ahd, scb) \
124 ((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
126 #define AHD_SET_SCB_COL_IDX(scb, col_idx) \
128 (scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID; \
129 (scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1); \
132 #define AHD_COPY_SCB_COL_IDX(dst, src) \
134 dst->hscb->scsiid = src->hscb->scsiid; \
135 dst->hscb->lun = src->hscb->lun; \
138 #define AHD_NEVER_COL_IDX 0xFFFF
140 /**************************** Driver Constants ********************************/
142 * The maximum number of supported targets.
144 #define AHD_NUM_TARGETS 16
147 * The maximum number of supported luns.
148 * The identify message only supports 64 luns in non-packetized transfers.
149 * You can have 2^64 luns when information unit transfers are enabled,
150 * but until we see a need to support that many, we support 256.
152 #define AHD_NUM_LUNS_NONPKT 64
153 #define AHD_NUM_LUNS 256
156 * The maximum transfer per S/G segment.
158 #define AHD_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */
161 * The maximum amount of SCB storage in hardware on a controller.
162 * This value represents an upper bound. Due to software design,
163 * we may not be able to use this number.
165 #define AHD_SCB_MAX 512
168 * The maximum number of concurrent transactions supported per driver instance.
169 * Sequencer Control Blocks (SCBs) store per-transaction information.
171 #define AHD_MAX_QUEUE AHD_SCB_MAX
174 * Define the size of our QIN and QOUT FIFOs. They must be a power of 2
175 * in size and accomodate as many transactions as can be queued concurrently.
177 #define AHD_QIN_SIZE AHD_MAX_QUEUE
178 #define AHD_QOUT_SIZE AHD_MAX_QUEUE
180 #define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
182 * The maximum amount of SCB storage we allocate in host memory.
184 #define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
187 * Ring Buffer of incoming target commands.
188 * We allocate 256 to simplify the logic in the sequencer
189 * by using the natural wrap point of an 8bit counter.
191 #define AHD_TMODE_CMDS 256
193 /* Reset line assertion time in us */
194 #define AHD_BUSRESET_DELAY 25
196 /******************* Chip Characteristics/Operating Settings *****************/
199 * The chip order is from least sophisticated to most sophisticated.
203 AHD_CHIPID_MASK = 0x00FF,
204 AHD_AIC7901 = 0x0001,
205 AHD_AIC7902 = 0x0002,
206 AHD_AIC7901A = 0x0003,
207 AHD_PCI = 0x0100, /* Bus type PCI */
208 AHD_PCIX = 0x0200, /* Bus type PCIX */
209 AHD_BUS_MASK = 0x0F00
213 * Features available in each chip type.
216 AHD_FENONE = 0x00000,
217 AHD_WIDE = 0x00001, /* Wide Channel */
218 AHD_MULTI_FUNC = 0x00100, /* Multi-Function Twin Channel Device */
219 AHD_TARGETMODE = 0x01000, /* Has tested target mode support */
220 AHD_MULTIROLE = 0x02000, /* Space for two roles at a time */
221 AHD_REMOVABLE = 0x00000, /* Hot-Swap supported - None so far*/
222 AHD_AIC7901_FE = AHD_FENONE,
223 AHD_AIC7902_FE = AHD_MULTI_FUNC
227 * Bugs in the silicon that we work around in software.
230 AHD_BUGNONE = 0x0000,
231 AHD_SENT_SCB_UPDATE_BUG = 0x0001,
232 AHD_ABORT_LQI_BUG = 0x0002,
233 AHD_PKT_BITBUCKET_BUG = 0x0004,
234 AHD_LONG_SETIMO_BUG = 0x0008,
235 AHD_NLQICRC_DELAYED_BUG = 0x0010,
236 AHD_SCSIRST_BUG = 0x0020,
237 AHD_PCIX_CHIPRST_BUG = 0x0040,
238 AHD_PCIX_MMAPIO_BUG = 0x0080,
239 /* Bug workarounds that can be disabled on non-PCIX busses. */
240 AHD_PCIX_BUG_MASK = AHD_PCIX_CHIPRST_BUG
241 | AHD_PCIX_MMAPIO_BUG,
242 AHD_LQO_ATNO_BUG = 0x0100,
243 AHD_AUTOFLUSH_BUG = 0x0200,
244 AHD_CLRLQO_AUTOCLR_BUG = 0x0400,
245 AHD_PKTIZED_STATUS_BUG = 0x0800,
246 AHD_PKT_LUN_BUG = 0x1000
250 * Configuration specific settings.
251 * The driver determines these settings by probing the
252 * chip/controller's configuration.
256 AHD_PRIMARY_CHANNEL = 0x00003,/*
257 * The channel that should
260 AHD_USEDEFAULTS = 0x00004,/*
261 * For cards without an seeprom
262 * or a BIOS to initialize the chip's
263 * SRAM, we use the default target
266 AHD_SEQUENCER_DEBUG = 0x00008,
267 AHD_RESET_BUS_A = 0x00010,
268 AHD_EXTENDED_TRANS_A = 0x00020,
269 AHD_TERM_ENB_A = 0x00040,
270 AHD_SPCHK_ENB_A = 0x00080,
271 AHD_STPWLEVEL_A = 0x00100,
272 AHD_INITIATORROLE = 0x00200,/*
273 * Allow initiator operations on
276 AHD_TARGETROLE = 0x00400,/*
277 * Allow target operations on this
280 AHD_RESOURCE_SHORTAGE = 0x00800,
281 AHD_TQINFIFO_BLOCKED = 0x01000,/* Blocked waiting for ATIOs */
282 AHD_INT50_SPEEDFLEX = 0x02000,/*
283 * Internal 50pin connector
284 * sits behind an aic3860
286 AHD_BIOS_ENABLED = 0x04000,
287 AHD_ALL_INTERRUPTS = 0x08000,
288 AHD_39BIT_ADDRESSING = 0x10000,/* Use 39 bit addressing scheme. */
289 AHD_64BIT_ADDRESSING = 0x20000,/* Use 64 bit addressing scheme. */
290 AHD_CURRENT_SENSING = 0x40000,
291 AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */
292 AHD_CPQ_BOARD = 0x100000,
293 AHD_RESET_POLL_ACTIVE = 0x200000
296 /************************* Hardware SCB Definition ***************************/
299 * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB
300 * consists of a "hardware SCB" mirroring the fields availible on the card
301 * and additional information the kernel stores for each transaction.
303 * To minimize space utilization, a portion of the hardware scb stores
304 * different data during different portions of a SCSI transaction.
305 * As initialized by the host driver for the initiator role, this area
306 * contains the SCSI cdb (or a pointer to the cdb) to be executed. After
307 * the cdb has been presented to the target, this area serves to store
308 * residual transfer information and the SCSI status byte.
309 * For the target role, the contents of this area do not change, but
310 * still serve a different purpose than for the initiator role. See
311 * struct target_data for details.
315 * Status information embedded in the shared poriton of
316 * an SCB after passing the cdb to the target. The kernel
317 * driver will only read this data for transactions that
318 * complete abnormally.
320 struct initiator_status {
321 uint32_t residual_datacnt; /* Residual in the current S/G seg */
322 uint32_t residual_sgptr; /* The next S/G for this transfer */
323 uint8_t scsi_status; /* Standard SCSI status byte */
326 struct target_status {
327 uint32_t residual_datacnt; /* Residual in the current S/G seg */
328 uint32_t residual_sgptr; /* The next S/G for this transfer */
329 uint8_t scsi_status; /* SCSI status to give to initiator */
330 uint8_t target_phases; /* Bitmap of phases to execute */
331 uint8_t data_phase; /* Data-In or Data-Out */
332 uint8_t initiator_tag; /* Initiator's transaction tag */
336 * Initiator mode SCB shared data area.
337 * If the embedded CDB is 12 bytes or less, we embed
338 * the sense buffer address in the SCB. This allows
339 * us to retrieve sense information without interupting
340 * the host in packetized mode.
342 typedef uint32_t sense_addr_t;
343 #define MAX_CDB_LEN 16
344 #define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
345 union initiator_data {
347 uint8_t cdb[MAX_CDB_LEN];
349 uint8_t cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
350 sense_addr_t sense_addr;
355 * Target mode version of the shared data SCB segment.
359 uint8_t scsi_status; /* SCSI status to give to initiator */
360 uint8_t target_phases; /* Bitmap of phases to execute */
361 uint8_t data_phase; /* Data-In or Data-Out */
362 uint8_t initiator_tag; /* Initiator's transaction tag */
365 struct hardware_scb {
367 union initiator_data idata;
368 struct target_data tdata;
369 struct initiator_status istatus;
370 struct target_status tstatus;
373 * A word about residuals.
374 * The scb is presented to the sequencer with the dataptr and datacnt
375 * fields initialized to the contents of the first S/G element to
376 * transfer. The sgptr field is initialized to the bus address for
377 * the S/G element that follows the first in the in core S/G array
378 * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid
379 * S/G entry for this transfer (single S/G element transfer with the
380 * first elements address and length preloaded in the dataptr/datacnt
381 * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.
382 * The SG_FULL_RESID flag ensures that the residual will be correctly
383 * noted even if no data transfers occur. Once the data phase is entered,
384 * the residual sgptr and datacnt are loaded from the sgptr and the
385 * datacnt fields. After each S/G element's dataptr and length are
386 * loaded into the hardware, the residual sgptr is advanced. After
387 * each S/G element is expired, its datacnt field is checked to see
388 * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the
389 * residual sg ptr and the transfer is considered complete. If the
390 * sequencer determines that there is a residual in the tranfer, or
391 * there is non-zero status, it will set the SG_STATUS_VALID flag in
392 * sgptr and dma the scb back into host memory. To sumarize:
395 * o A residual has occurred if SG_FULL_RESID is set in sgptr,
396 * or residual_sgptr does not have SG_LIST_NULL set.
398 * o We are transfering the last segment if residual_datacnt has
399 * the SG_LAST_SEG flag set.
402 * o A residual can only have occurred if a completed scb has the
403 * SG_STATUS_VALID flag set. Inspection of the SCSI status field,
404 * the residual_datacnt, and the residual_sgptr field will tell
407 * o residual_sgptr and sgptr refer to the "next" sg entry
408 * and so may point beyond the last valid sg entry for the
411 #define SG_PTR_MASK 0xFFFFFFF8
412 /*16*/ uint8_t cdb_len;
413 /*17*/ uint8_t task_management;
415 /*20*/ uint32_t next_hscb_busaddr;
416 /*24*/ uint64_t dataptr;
417 /*32*/ uint32_t datacnt; /* Byte 3 is spare. */
418 /*36*/ uint32_t sgptr;
419 /*40*/ uint8_t control; /* See SCB_CONTROL in aic79xx.reg for details */
420 /*41*/ uint8_t scsiid; /*
422 * Our Id (bits 0-3) Their ID (bits 4-7)
425 /*43*/ uint8_t task_attribute_nonpkt_tag;
426 /*44*/ uint32_t hscb_busaddr;
427 /******* Long lun field only downloaded for full 8 byte lun support *******/
428 /*48*/ uint8_t pkt_long_lun[8];
429 /******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
430 /*56*/ uint8_t spare[8];
433 /************************ Kernel SCB Definitions ******************************/
435 * Some fields of the SCB are OS dependent. Here we collect the
436 * definitions for elements that all OS platforms need to include
437 * in there SCB definition.
441 * Definition of a scatter/gather element as transfered to the controller.
442 * The aic7xxx chips only support a 24bit length. We use the top byte of
443 * the length to store additional address bits and a flag to indicate
444 * that a given segment terminates the transfer. This gives us an
445 * addressable range of 512GB on machines with 64bit PCI or with chips
446 * that can support dual address cycles on 32bit PCI busses.
451 #define AHD_DMA_LAST_SEG 0x80000000
452 #define AHD_SG_HIGH_ADDR_MASK 0x7F000000
453 #define AHD_SG_LEN_MASK 0x00FFFFFF
456 struct ahd_dma64_seg {
466 SLIST_ENTRY(map_node) links;
470 * The current state of this SCB.
473 SCB_FLAG_NONE = 0x00000,
474 SCB_TRANSMISSION_ERROR = 0x00001,/*
475 * We detected a parity or CRC
476 * error that has effected the
477 * payload of the command. This
478 * flag is checked when normal
479 * status is returned to catch
480 * the case of a target not
481 * responding to our attempt
482 * to report the error.
484 SCB_OTHERTCL_TIMEOUT = 0x00002,/*
485 * Another device was active
486 * during the first timeout for
487 * this SCB so we gave ourselves
488 * an additional timeout period
489 * in case it was hogging the
492 SCB_DEVICE_RESET = 0x00004,
494 SCB_CDB32_PTR = 0x00010,
495 SCB_RECOVERY_SCB = 0x00020,
496 SCB_AUTO_NEGOTIATE = 0x00040,/* Negotiate to achieve goal. */
497 SCB_NEGOTIATE = 0x00080,/* Negotiation forced for command. */
499 SCB_ACTIVE = 0x00400,
500 SCB_TARGET_IMMEDIATE = 0x00800,
501 SCB_PACKETIZED = 0x01000,
502 SCB_EXPECT_PPR_BUSFREE = 0x02000,
503 SCB_PKT_SENSE = 0x04000,
504 SCB_CMDPHASE_ABORT = 0x08000,
505 SCB_ON_COL_LIST = 0x10000
509 struct hardware_scb *hscb;
511 SLIST_ENTRY(scb) sle;
513 TAILQ_ENTRY(scb) tqe;
516 SLIST_ENTRY(scb) sle;
518 TAILQ_ENTRY(scb) tqe;
520 #define pending_links links2.le
521 #define collision_links links2.le
524 struct ahd_softc *ahd_softc;
529 struct scb_platform_data *platform_data;
530 struct map_node *hscb_map;
531 struct map_node *sg_map;
532 struct map_node *sense_map;
535 bus_addr_t sg_list_busaddr;
536 bus_addr_t sense_busaddr;
537 u_int sg_count;/* How full ahd_dma_seg is */
540 TAILQ_HEAD(scb_tailq, scb);
541 LIST_HEAD(scb_list, scb);
545 * TAILQ of lists of free SCBs grouped by device
548 struct scb_tailq free_scbs;
551 * Per-device lists of SCBs whose tag ID would collide
552 * with an already active tag on the device.
554 struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
557 * SCBs that will not collide with any active device.
559 struct scb_list any_dev_free_scb_list;
562 * Mapping from tag to SCB.
564 struct scb *scbindex[AHD_SCB_MAX];
567 * "Bus" addresses of our data structures.
569 bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */
570 bus_dma_tag_t sg_dmat; /* dmat for our sg segments */
571 bus_dma_tag_t sense_dmat; /* dmat for our sense buffers */
572 SLIST_HEAD(, map_node) hscb_maps;
573 SLIST_HEAD(, map_node) sg_maps;
574 SLIST_HEAD(, map_node) sense_maps;
575 int scbs_left; /* unallocated scbs in head map_node */
576 int sgs_left; /* unallocated sgs in head map_node */
577 int sense_left; /* unallocated sense in head map_node */
579 uint16_t maxhscbs; /* Number of SCBs on the card */
580 uint8_t init_level; /*
581 * How far we've initialized
586 /************************ Target Mode Definitions *****************************/
589 * Connection desciptor for select-in requests in target mode.
592 uint8_t scsiid; /* Our ID and the initiator's ID */
593 uint8_t identify; /* Identify message */
594 uint8_t bytes[22]; /*
595 * Bytes contains any additional message
596 * bytes terminated by 0xFF. The remainder
597 * is the cdb to execute.
599 uint8_t cmd_valid; /*
600 * When a command is complete, the firmware
601 * will set cmd_valid to all bits set.
602 * After the host has seen the command,
603 * the bits are cleared. This allows us
604 * to just peek at host memory to determine
605 * if more work is complete. cmd_valid is on
606 * an 8 byte boundary to simplify setting
607 * it on aic7880 hardware which only has
608 * limited direct access to the DMA FIFO.
614 * Number of events we can buffer up if we run out
615 * of immediate notify ccbs.
617 #define AHD_TMODE_EVENT_BUFFER_SIZE 8
618 struct ahd_tmode_event {
619 uint8_t initiator_id;
620 uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
621 #define EVENT_TYPE_BUS_RESET 0xFF
626 * Per enabled lun target mode state.
627 * As this state is directly influenced by the host OS'es target mode
628 * environment, we let the OS module define it. Forward declare the
629 * structure here so we can store arrays of them, etc. in OS neutral
632 #ifdef AHD_TARGET_MODE
633 struct ahd_tmode_lstate {
634 struct cam_path *path;
635 struct ccb_hdr_slist accept_tios;
636 struct ccb_hdr_slist immed_notifies;
637 struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
642 struct ahd_tmode_lstate;
645 /******************** Transfer Negotiation Datastructures *********************/
646 #define AHD_TRANS_CUR 0x01 /* Modify current neogtiation status */
647 #define AHD_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
648 #define AHD_TRANS_GOAL 0x04 /* Modify negotiation goal */
649 #define AHD_TRANS_USER 0x08 /* Modify user negotiation settings */
650 #define AHD_PERIOD_ASYNC 0xFF
651 #define AHD_PERIOD_10MHz 0x19
654 * Transfer Negotiation Information.
656 struct ahd_transinfo {
657 uint8_t protocol_version; /* SCSI Revision level */
658 uint8_t transport_version; /* SPI Revision level */
659 uint8_t width; /* Bus width */
660 uint8_t period; /* Sync rate factor */
661 uint8_t offset; /* Sync offset */
662 uint8_t ppr_options; /* Parallel Protocol Request options */
666 * Per-initiator current, goal and user transfer negotiation information. */
667 struct ahd_initiator_tinfo {
668 struct ahd_transinfo curr;
669 struct ahd_transinfo goal;
670 struct ahd_transinfo user;
674 * Per enabled target ID state.
675 * Pointers to lun target state as well as sync/wide negotiation information
676 * for each initiator<->target mapping. For the initiator role we pretend
677 * that we are the target and the targets are the initiators since the
678 * negotiation is the same regardless of role.
680 struct ahd_tmode_tstate {
681 struct ahd_tmode_lstate* enabled_luns[AHD_NUM_LUNS];
682 struct ahd_initiator_tinfo transinfo[AHD_NUM_TARGETS];
685 * Per initiator state bitmasks.
687 uint16_t auto_negotiate;/* Auto Negotiation Required */
688 uint16_t discenable; /* Disconnection allowed */
689 uint16_t tagenable; /* Tagged Queuing allowed */
693 * Points of interest along the negotiated transfer scale.
695 #define AHD_SYNCRATE_MAX 0x8
696 #define AHD_SYNCRATE_160 0x8
697 #define AHD_SYNCRATE_PACED 0x8
698 #define AHD_SYNCRATE_DT 0x9
699 #define AHD_SYNCRATE_ULTRA2 0xa
700 #define AHD_SYNCRATE_ULTRA 0xc
701 #define AHD_SYNCRATE_FAST 0x19
702 #define AHD_SYNCRATE_MIN_DT AHD_SYNCRATE_FAST
703 #define AHD_SYNCRATE_SYNC 0x32
704 #define AHD_SYNCRATE_MIN 0x60
705 #define AHD_SYNCRATE_ASYNC 0xFF
708 * In RevA, the synctable uses a 120MHz rate for the period
709 * factor 8 and 160MHz for the period factor 7. The 120MHz
710 * rate never made it into the official SCSI spec, so we must
711 * compensate when setting the negotiation table for Rev A
714 #define AHD_SYNCRATE_REVA_120 0x8
715 #define AHD_SYNCRATE_REVA_160 0x7
717 /***************************** Lookup Tables **********************************/
719 * Phase -> name and message out response
720 * to parity errors in each phase table.
722 struct ahd_phase_table_entry {
724 uint8_t mesg_out; /* Message response to parity errors */
728 /************************** Serial EEPROM Format ******************************/
730 struct seeprom_config {
732 * Per SCSI ID Configuration Flags
734 uint16_t device_flags[16]; /* words 0-15 */
735 #define CFXFER 0x003F /* synchronous transfer rate */
736 #define CFXFER_ASYNC 0x3F
737 #define CFQAS 0x0040 /* Negotiate QAS */
738 #define CFPACKETIZED 0x0080 /* Negotiate Packetized Transfers */
739 #define CFSTART 0x0100 /* send start unit SCSI command */
740 #define CFINCBIOS 0x0200 /* include in BIOS scan */
741 #define CFDISC 0x0400 /* enable disconnection */
742 #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
743 #define CFWIDEB 0x1000 /* wide bus device */
744 #define CFHOSTMANAGED 0x8000 /* Managed by a RAID controller */
749 uint16_t bios_control; /* word 16 */
750 #define CFSUPREM 0x0001 /* support all removeable drives */
751 #define CFSUPREMB 0x0002 /* support removeable boot drives */
752 #define CFBIOSSTATE 0x000C /* BIOS Action State */
753 #define CFBS_DISABLED 0x00
754 #define CFBS_ENABLED 0x04
755 #define CFBS_DISABLED_SCAN 0x08
756 #define CFENABLEDV 0x0010 /* Perform Domain Validation */
757 #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
758 #define CFSPARITY 0x0040 /* SCSI parity */
759 #define CFEXTEND 0x0080 /* extended translation enabled */
760 #define CFBOOTCD 0x0100 /* Support Bootable CD-ROM */
761 #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
762 #define CFMSG_VERBOSE 0x0000
763 #define CFMSG_SILENT 0x0200
764 #define CFMSG_DIAG 0x0400
765 #define CFRESETB 0x0800 /* reset SCSI bus at boot */
769 * Host Adapter Control Bits
771 uint16_t adapter_control; /* word 17 */
772 #define CFAUTOTERM 0x0001 /* Perform Auto termination */
773 #define CFSTERM 0x0002 /* SCSI low byte termination */
774 #define CFWSTERM 0x0004 /* SCSI high byte termination */
775 #define CFSEAUTOTERM 0x0008 /* Ultra2 Perform secondary Auto Term*/
776 #define CFSELOWTERM 0x0010 /* Ultra2 secondary low term */
777 #define CFSEHIGHTERM 0x0020 /* Ultra2 secondary high term */
778 #define CFSTPWLEVEL 0x0040 /* Termination level control */
779 #define CFBIOSAUTOTERM 0x0080 /* Perform Auto termination */
780 #define CFTERM_MENU 0x0100 /* BIOS displays termination menu */
781 #define CFCLUSTERENB 0x8000 /* Cluster Enable */
784 * Bus Release Time, Host Adapter ID
786 uint16_t brtime_id; /* word 18 */
787 #define CFSCSIID 0x000f /* host adapter SCSI ID */
789 #define CFBRTIME 0xff00 /* bus release time/PCI Latency Time */
794 uint16_t max_targets; /* word 19 */
795 #define CFMAXTARG 0x00ff /* maximum targets */
796 #define CFBOOTLUN 0x0f00 /* Lun to boot from */
797 #define CFBOOTID 0xf000 /* Target to boot from */
798 uint16_t res_1[10]; /* words 20-29 */
799 uint16_t signature; /* BIOS Signature */
800 #define CFSIGNATURE 0x400
801 uint16_t checksum; /* word 31 */
804 /****************************** Flexport Logic ********************************/
805 #define FLXADDR_TERMCTL 0x0
806 #define FLX_TERMCTL_ENSECHIGH 0x8
807 #define FLX_TERMCTL_ENSECLOW 0x4
808 #define FLX_TERMCTL_ENPRIHIGH 0x2
809 #define FLX_TERMCTL_ENPRILOW 0x1
810 #define FLXADDR_ROMSTAT_CURSENSECTL 0x1
811 #define FLX_ROMSTAT_SEECFG 0xF0
812 #define FLX_ROMSTAT_EECFG 0x0F
813 #define FLX_ROMSTAT_SEE_93C66 0x00
814 #define FLX_ROMSTAT_SEE_NONE 0xF0
815 #define FLX_ROMSTAT_EE_512x8 0x0
816 #define FLX_ROMSTAT_EE_1MBx8 0x1
817 #define FLX_ROMSTAT_EE_2MBx8 0x2
818 #define FLX_ROMSTAT_EE_4MBx8 0x3
819 #define FLX_ROMSTAT_EE_16MBx8 0x4
820 #define CURSENSE_ENB 0x1
821 #define FLXADDR_FLEXSTAT 0x2
822 #define FLX_FSTAT_BUSY 0x1
823 #define FLXADDR_CURRENT_STAT 0x4
824 #define FLX_CSTAT_SEC_HIGH 0xC0
825 #define FLX_CSTAT_SEC_LOW 0x30
826 #define FLX_CSTAT_PRI_HIGH 0x0C
827 #define FLX_CSTAT_PRI_LOW 0x03
828 #define FLX_CSTAT_MASK 0x03
829 #define FLX_CSTAT_SHIFT 2
830 #define FLX_CSTAT_OKAY 0x0
831 #define FLX_CSTAT_OVER 0x1
832 #define FLX_CSTAT_UNDER 0x2
833 #define FLX_CSTAT_INVALID 0x3
835 int ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
836 u_int start_addr, u_int count);
838 int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
839 u_int start_addr, u_int count);
840 int ahd_wait_seeprom(struct ahd_softc *ahd);
841 int ahd_verify_cksum(struct seeprom_config *sc);
842 int ahd_acquire_seeprom(struct ahd_softc *ahd);
843 void ahd_release_seeprom(struct ahd_softc *ahd);
845 /**************************** Message Buffer *********************************/
847 MSG_FLAG_NONE = 0x00,
848 MSG_FLAG_EXPECT_PPR_BUSFREE = 0x01,
849 MSG_FLAG_IU_REQ_CHANGED = 0x02,
850 MSG_FLAG_EXPECT_IDE_BUSFREE = 0x04,
851 MSG_FLAG_PACKETIZED = 0x08
855 MSG_TYPE_NONE = 0x00,
856 MSG_TYPE_INITIATOR_MSGOUT = 0x01,
857 MSG_TYPE_INITIATOR_MSGIN = 0x02,
858 MSG_TYPE_TARGET_MSGOUT = 0x03,
859 MSG_TYPE_TARGET_MSGIN = 0x04
868 /*********************** Software Configuration Structure *********************/
869 struct ahd_suspend_channel_state {
879 struct ahd_suspend_state {
880 struct ahd_suspend_channel_state channel[2];
887 /* Host and sequencer SCB counts */
889 uint8_t *scratch_ram;
893 typedef void (*ahd_bus_intr_t)(struct ahd_softc *);
904 #define AHD_MK_MSK(x) (0x01 << (x))
905 #define AHD_MODE_DFF0_MSK AHD_MK_MSK(AHD_MODE_DFF0)
906 #define AHD_MODE_DFF1_MSK AHD_MK_MSK(AHD_MODE_DFF1)
907 #define AHD_MODE_CCHAN_MSK AHD_MK_MSK(AHD_MODE_CCHAN)
908 #define AHD_MODE_SCSI_MSK AHD_MK_MSK(AHD_MODE_SCSI)
909 #define AHD_MODE_CFG_MSK AHD_MK_MSK(AHD_MODE_CFG)
910 #define AHD_MODE_UNKNOWN_MSK AHD_MK_MSK(AHD_MODE_UNKNOWN)
911 #define AHD_MODE_ANY_MSK (~0)
913 typedef uint8_t ahd_mode_state;
915 typedef void ahd_callback_t (void *);
918 bus_space_tag_t tags[2];
919 bus_space_handle_t bshs[2];
921 bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */
923 struct scb_data scb_data;
925 struct hardware_scb *next_queued_hscb;
928 * SCBs that have been sent to the controller
930 LIST_HEAD(, scb) pending_scbs;
933 * Current register window mode information.
939 * Saved register window mode information
940 * used for restore on next unpause.
942 ahd_mode saved_dst_mode;
943 ahd_mode saved_src_mode;
946 * Platform specific data.
948 struct ahd_platform_data *platform_data;
951 * Platform specific device information.
953 ahd_dev_softc_t dev_softc;
956 * Bus specific device information.
958 ahd_bus_intr_t bus_intr;
961 * Target mode related state kept on a per enabled lun basis.
962 * Targets that are not enabled will have null entries.
963 * As an initiator, we keep one target entry for our initiator
964 * ID to store our sync/wide transfer settings.
966 struct ahd_tmode_tstate *enabled_targets[AHD_NUM_TARGETS];
969 * The black hole device responsible for handling requests for
970 * disabled luns on enabled targets.
972 struct ahd_tmode_lstate *black_hole;
975 * Device instance currently on the bus awaiting a continue TIO
976 * for a command that was not given the disconnect priveledge.
978 struct ahd_tmode_lstate *pending_device;
981 * Timer handles for timer driven callbacks.
983 ahd_timer_t reset_timer;
986 * Card characteristics
989 ahd_feature features;
992 struct seeprom_config *seep_config;
994 /* Values to store in the SEQCTL register for pause and unpause */
999 uint16_t qoutfifonext;
1000 uint16_t qoutfifonext_valid_tag;
1001 uint16_t qinfifonext;
1002 uint16_t qinfifo[AHD_SCB_MAX];
1005 /* Critical Section Data */
1006 struct cs *critical_sections;
1007 u_int num_critical_sections;
1009 /* Buffer for handling packetized bitbucket. */
1010 uint8_t *overrun_buf;
1012 /* Links for chaining softcs */
1013 TAILQ_ENTRY(ahd_softc) links;
1015 /* Channel Names ('A', 'B', etc.) */
1018 /* Initiator Bus ID */
1022 * PCI error detection.
1024 int unsolicited_ints;
1027 * Target incoming command FIFO.
1029 struct target_cmd *targetcmds;
1030 uint8_t tqinfifonext;
1033 * Incoming and outgoing message handling.
1035 uint8_t send_msg_perror;
1036 ahd_msg_flags msg_flags;
1037 ahd_msg_type msg_type;
1038 uint8_t msgout_buf[12];/* Message we are sending */
1039 uint8_t msgin_buf[12];/* Message we are receiving */
1040 u_int msgout_len; /* Length of message to send */
1041 u_int msgout_index; /* Current index in msgout */
1042 u_int msgin_index; /* Current index in msgin */
1045 * Mapping information for data structures shared
1046 * between the sequencer and kernel.
1048 bus_dma_tag_t parent_dmat;
1049 bus_dma_tag_t shared_data_dmat;
1050 bus_dmamap_t shared_data_dmamap;
1051 bus_addr_t shared_data_busaddr;
1053 /* Information saved through suspend/resume cycles */
1054 struct ahd_suspend_state suspend_state;
1056 /* Number of enabled target mode device on this card */
1059 /* Initialization level of this data structure */
1062 /* PCI cacheline size. */
1063 u_int pci_cachesize;
1065 /* Per-Unit descriptive information */
1066 const char *description;
1067 const char *bus_description;
1071 /* Selection Timer settings */
1074 uint16_t user_discenable;/* Disconnection allowed */
1075 uint16_t user_tagenable;/* Tagged Queuing allowed */
1078 TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
1079 extern struct ahd_softc_tailq ahd_tailq;
1081 /************************ Active Device Information ***************************/
1088 struct ahd_devinfo {
1091 uint16_t target_mask;
1096 * Only guaranteed to be correct if not
1097 * in the busfree state.
1101 /****************************** PCI Structures ********************************/
1102 #define AHD_PCI_IOADDR0 PCIR_MAPS /* I/O BAR*/
1103 #define AHD_PCI_MEMADDR (PCIR_MAPS + 4) /* Memory BAR */
1104 #define AHD_PCI_IOADDR1 (PCIR_MAPS + 12)/* Second I/O BAR */
1106 typedef int (ahd_device_setup_t)(struct ahd_softc *);
1108 struct ahd_pci_identity {
1112 ahd_device_setup_t *setup;
1114 extern struct ahd_pci_identity ahd_pci_ident_table [];
1115 extern const u_int ahd_num_pci_devs;
1117 /***************************** VL/EISA Declarations ***************************/
1118 struct aic7770_identity {
1122 ahd_device_setup_t *setup;
1124 extern struct aic7770_identity aic7770_ident_table [];
1125 extern const int ahd_num_aic7770_devs;
1127 #define AHD_EISA_SLOT_OFFSET 0xc00
1128 #define AHD_EISA_IOSIZE 0x100
1130 /*************************** Function Declarations ****************************/
1131 /******************************************************************************/
1132 u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
1133 void ahd_busy_tcl(struct ahd_softc *ahd,
1134 u_int tcl, u_int busyid);
1135 static __inline void ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl);
1136 static __inline void
1137 ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
1139 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
1142 /***************************** PCI Front End *********************************/
1143 struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
1144 int ahd_pci_config(struct ahd_softc *,
1145 struct ahd_pci_identity *);
1147 /*************************** EISA/VL Front End ********************************/
1148 struct aic7770_identity *aic7770_find_device(uint32_t);
1149 int aic7770_config(struct ahd_softc *ahd,
1150 struct aic7770_identity *);
1152 /************************** SCB and SCB queue management **********************/
1153 int ahd_probe_scbs(struct ahd_softc *);
1154 void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
1156 int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
1157 int target, char channel, int lun,
1158 u_int tag, role_t role);
1160 /****************************** Initialization ********************************/
1161 struct ahd_softc *ahd_alloc(void *platform_arg, char *name);
1162 int ahd_softc_init(struct ahd_softc *);
1163 void ahd_controller_info(struct ahd_softc *ahd, char *buf);
1164 int ahd_init(struct ahd_softc *ahd);
1165 int ahd_default_config(struct ahd_softc *ahd);
1166 int ahd_parse_cfgdata(struct ahd_softc *ahd,
1167 struct seeprom_config *sc);
1168 void ahd_intr_enable(struct ahd_softc *ahd, int enable);
1169 void ahd_pause_and_flushwork(struct ahd_softc *ahd);
1170 int ahd_suspend(struct ahd_softc *ahd);
1171 int ahd_resume(struct ahd_softc *ahd);
1172 void ahd_softc_insert(struct ahd_softc *);
1173 struct ahd_softc *ahd_find_softc(struct ahd_softc *ahd);
1174 void ahd_set_unit(struct ahd_softc *, int);
1175 void ahd_set_name(struct ahd_softc *, char *);
1176 struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
1177 void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
1178 void ahd_alloc_scbs(struct ahd_softc *ahd);
1179 void ahd_free(struct ahd_softc *ahd);
1180 int ahd_reset(struct ahd_softc *ahd);
1181 void ahd_shutdown(void *arg);
1182 int ahd_write_flexport(struct ahd_softc *ahd,
1183 u_int addr, u_int value);
1184 int ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
1186 int ahd_wait_flexport(struct ahd_softc *ahd);
1188 /*************************** Interrupt Services *******************************/
1189 void ahd_pci_intr(struct ahd_softc *ahd);
1190 void ahd_clear_intstat(struct ahd_softc *ahd);
1191 void ahd_run_qoutfifo(struct ahd_softc *ahd);
1192 #ifdef AHD_TARGET_MODE
1193 void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);
1195 void ahd_handle_hwerrint(struct ahd_softc *ahd);
1196 void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);
1197 void ahd_handle_scsiint(struct ahd_softc *ahd,
1199 void ahd_clear_critical_section(struct ahd_softc *ahd);
1201 /***************************** Error Recovery *********************************/
1207 } ahd_search_action;
1208 int ahd_search_qinfifo(struct ahd_softc *ahd, int target,
1209 char channel, int lun, u_int tag,
1210 role_t role, uint32_t status,
1211 ahd_search_action action);
1212 int ahd_search_disc_list(struct ahd_softc *ahd, int target,
1213 char channel, int lun, u_int tag,
1214 int stop_on_first, int remove,
1216 void ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
1217 int ahd_reset_channel(struct ahd_softc *ahd, char channel,
1218 int initiate_reset);
1219 int ahd_abort_scbs(struct ahd_softc *ahd, int target,
1220 char channel, int lun, u_int tag,
1221 role_t role, uint32_t status);
1222 void ahd_restart(struct ahd_softc *ahd);
1223 void ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo);
1224 void ahd_handle_scb_status(struct ahd_softc *ahd,
1226 void ahd_handle_scsi_status(struct ahd_softc *ahd,
1228 void ahd_calc_residual(struct ahd_softc *ahd,
1230 /*************************** Utility Functions ********************************/
1231 struct ahd_phase_table_entry*
1232 ahd_lookup_phase_entry(int phase);
1233 void ahd_compile_devinfo(struct ahd_devinfo *devinfo,
1234 u_int our_id, u_int target,
1235 u_int lun, char channel,
1237 /************************** Transfer Negotiation ******************************/
1238 void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
1239 u_int *ppr_options, u_int maxsync);
1240 void ahd_validate_offset(struct ahd_softc *ahd,
1241 struct ahd_initiator_tinfo *tinfo,
1242 u_int period, u_int *offset,
1243 int wide, role_t role);
1244 void ahd_validate_width(struct ahd_softc *ahd,
1245 struct ahd_initiator_tinfo *tinfo,
1248 int ahd_update_neg_request(struct ahd_softc*,
1249 struct ahd_devinfo*,
1250 struct ahd_tmode_tstate*,
1251 struct ahd_initiator_tinfo*,
1253 void ahd_set_width(struct ahd_softc *ahd,
1254 struct ahd_devinfo *devinfo,
1255 u_int width, u_int type, int paused);
1256 void ahd_set_syncrate(struct ahd_softc *ahd,
1257 struct ahd_devinfo *devinfo,
1258 u_int period, u_int offset,
1260 u_int type, int paused);
1267 void ahd_set_tags(struct ahd_softc *ahd,
1268 struct ahd_devinfo *devinfo,
1271 /**************************** Target Mode *************************************/
1272 #ifdef AHD_TARGET_MODE
1273 void ahd_send_lstate_events(struct ahd_softc *,
1274 struct ahd_tmode_lstate *);
1275 void ahd_handle_en_lun(struct ahd_softc *ahd,
1276 struct cam_sim *sim, union ccb *ccb);
1277 cam_status ahd_find_tmode_devs(struct ahd_softc *ahd,
1278 struct cam_sim *sim, union ccb *ccb,
1279 struct ahd_tmode_tstate **tstate,
1280 struct ahd_tmode_lstate **lstate,
1281 int notfound_failure);
1282 #ifndef AHD_TMODE_ENABLE
1283 #define AHD_TMODE_ENABLE 0
1286 /******************************* Debug ***************************************/
1288 extern uint32_t ahd_debug;
1289 #define AHD_SHOW_MISC 0x0001
1290 #define AHD_SHOW_SENSE 0x0002
1291 #define AHD_DUMP_SEEPROM 0x0004
1292 #define AHD_SHOW_TERMCTL 0x0008
1293 #define AHD_SHOW_MEMORY 0x0010
1294 #define AHD_SHOW_MESSAGES 0x0020
1295 #define AHD_SHOW_MODEPTR 0x0040
1296 #define AHD_SHOW_SELTO 0x0080
1297 #define AHD_SHOW_FIFOS 0x0100
1298 #define AHD_SHOW_QFULL 0x0200
1299 #define AHD_SHOW_QUEUE 0x0400
1300 #define AHD_SHOW_TQIN 0x0800
1301 #define AHD_SHOW_SG 0x0800
1302 #define AHD_DEBUG_SEQUENCER 0x2000
1304 void ahd_print_scb(struct scb *scb);
1305 void ahd_dump_sglist(struct scb *scb);
1306 void ahd_dump_all_cards_state(void);
1307 void ahd_dump_card_state(struct ahd_softc *ahd);
1308 int ahd_print_register(ahd_reg_parse_entry_t *table,
1315 void ahd_dump_scbs(struct ahd_softc *ahd);
1316 #endif /* _AIC79XX_H_ */