1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Core definitions and data structures shareable across OS platforms. 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (c) 1994-2001 Justin T. Gibbs. 5*4882a593Smuzhiyun * Copyright (c) 2000-2001 Adaptec Inc. 6*4882a593Smuzhiyun * All rights reserved. 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without 9*4882a593Smuzhiyun * modification, are permitted provided that the following conditions 10*4882a593Smuzhiyun * are met: 11*4882a593Smuzhiyun * 1. Redistributions of source code must retain the above copyright 12*4882a593Smuzhiyun * notice, this list of conditions, and the following disclaimer, 13*4882a593Smuzhiyun * without modification. 14*4882a593Smuzhiyun * 2. Redistributions in binary form must reproduce at minimum a disclaimer 15*4882a593Smuzhiyun * substantially similar to the "NO WARRANTY" disclaimer below 16*4882a593Smuzhiyun * ("Disclaimer") and any redistribution must be conditioned upon 17*4882a593Smuzhiyun * including a substantially similar Disclaimer requirement for further 18*4882a593Smuzhiyun * binary redistribution. 19*4882a593Smuzhiyun * 3. Neither the names of the above-listed copyright holders nor the names 20*4882a593Smuzhiyun * of any contributors may be used to endorse or promote products derived 21*4882a593Smuzhiyun * from this software without specific prior written permission. 22*4882a593Smuzhiyun * 23*4882a593Smuzhiyun * Alternatively, this software may be distributed under the terms of the 24*4882a593Smuzhiyun * GNU General Public License ("GPL") version 2 as published by the Free 25*4882a593Smuzhiyun * Software Foundation. 26*4882a593Smuzhiyun * 27*4882a593Smuzhiyun * NO WARRANTY 28*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 31*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32*4882a593Smuzhiyun * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33*4882a593Smuzhiyun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34*4882a593Smuzhiyun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35*4882a593Smuzhiyun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36*4882a593Smuzhiyun * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 37*4882a593Smuzhiyun * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38*4882a593Smuzhiyun * POSSIBILITY OF SUCH DAMAGES. 39*4882a593Smuzhiyun * 40*4882a593Smuzhiyun * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#85 $ 41*4882a593Smuzhiyun * 42*4882a593Smuzhiyun * $FreeBSD$ 43*4882a593Smuzhiyun */ 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun #ifndef _AIC7XXX_H_ 46*4882a593Smuzhiyun #define _AIC7XXX_H_ 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun /* Register Definitions */ 49*4882a593Smuzhiyun #include "aic7xxx_reg.h" 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun /************************* Forward Declarations *******************************/ 52*4882a593Smuzhiyun struct ahc_platform_data; 53*4882a593Smuzhiyun struct scb_platform_data; 54*4882a593Smuzhiyun struct seeprom_descriptor; 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun /****************************** Useful Macros *********************************/ 57*4882a593Smuzhiyun #ifndef TRUE 58*4882a593Smuzhiyun #define TRUE 1 59*4882a593Smuzhiyun #endif 60*4882a593Smuzhiyun #ifndef FALSE 61*4882a593Smuzhiyun #define FALSE 0 62*4882a593Smuzhiyun #endif 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun #define ALL_CHANNELS '\0' 65*4882a593Smuzhiyun #define ALL_TARGETS_MASK 0xFFFF 66*4882a593Smuzhiyun #define INITIATOR_WILDCARD (~0) 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun #define SCSIID_TARGET(ahc, scsiid) \ 69*4882a593Smuzhiyun (((scsiid) & ((((ahc)->features & AHC_TWIN) != 0) ? TWIN_TID : TID)) \ 70*4882a593Smuzhiyun >> TID_SHIFT) 71*4882a593Smuzhiyun #define SCSIID_OUR_ID(scsiid) \ 72*4882a593Smuzhiyun ((scsiid) & OID) 73*4882a593Smuzhiyun #define SCSIID_CHANNEL(ahc, scsiid) \ 74*4882a593Smuzhiyun ((((ahc)->features & AHC_TWIN) != 0) \ 75*4882a593Smuzhiyun ? ((((scsiid) & TWIN_CHNLB) != 0) ? 'B' : 'A') \ 76*4882a593Smuzhiyun : 'A') 77*4882a593Smuzhiyun #define SCB_IS_SCSIBUS_B(ahc, scb) \ 78*4882a593Smuzhiyun (SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) == 'B') 79*4882a593Smuzhiyun #define SCB_GET_OUR_ID(scb) \ 80*4882a593Smuzhiyun SCSIID_OUR_ID((scb)->hscb->scsiid) 81*4882a593Smuzhiyun #define SCB_GET_TARGET(ahc, scb) \ 82*4882a593Smuzhiyun SCSIID_TARGET((ahc), (scb)->hscb->scsiid) 83*4882a593Smuzhiyun #define SCB_GET_CHANNEL(ahc, scb) \ 84*4882a593Smuzhiyun SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) 85*4882a593Smuzhiyun #define SCB_GET_LUN(scb) \ 86*4882a593Smuzhiyun ((scb)->hscb->lun & LID) 87*4882a593Smuzhiyun #define SCB_GET_TARGET_OFFSET(ahc, scb) \ 88*4882a593Smuzhiyun (SCB_GET_TARGET(ahc, scb) + (SCB_IS_SCSIBUS_B(ahc, scb) ? 8 : 0)) 89*4882a593Smuzhiyun #define SCB_GET_TARGET_MASK(ahc, scb) \ 90*4882a593Smuzhiyun (0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb))) 91*4882a593Smuzhiyun #ifdef AHC_DEBUG 92*4882a593Smuzhiyun #define SCB_IS_SILENT(scb) \ 93*4882a593Smuzhiyun ((ahc_debug & AHC_SHOW_MASKED_ERRORS) == 0 \ 94*4882a593Smuzhiyun && (((scb)->flags & SCB_SILENT) != 0)) 95*4882a593Smuzhiyun #else 96*4882a593Smuzhiyun #define SCB_IS_SILENT(scb) \ 97*4882a593Smuzhiyun (((scb)->flags & SCB_SILENT) != 0) 98*4882a593Smuzhiyun #endif 99*4882a593Smuzhiyun #define TCL_TARGET_OFFSET(tcl) \ 100*4882a593Smuzhiyun ((((tcl) >> 4) & TID) >> 4) 101*4882a593Smuzhiyun #define TCL_LUN(tcl) \ 102*4882a593Smuzhiyun (tcl & (AHC_NUM_LUNS - 1)) 103*4882a593Smuzhiyun #define BUILD_TCL(scsiid, lun) \ 104*4882a593Smuzhiyun ((lun) | (((scsiid) & TID) << 4)) 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun #ifndef AHC_TARGET_MODE 107*4882a593Smuzhiyun #undef AHC_TMODE_ENABLE 108*4882a593Smuzhiyun #define AHC_TMODE_ENABLE 0 109*4882a593Smuzhiyun #endif 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun /**************************** Driver Constants ********************************/ 112*4882a593Smuzhiyun /* 113*4882a593Smuzhiyun * The maximum number of supported targets. 114*4882a593Smuzhiyun */ 115*4882a593Smuzhiyun #define AHC_NUM_TARGETS 16 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun /* 118*4882a593Smuzhiyun * The maximum number of supported luns. 119*4882a593Smuzhiyun * The identify message only supports 64 luns in SPI3. 120*4882a593Smuzhiyun * You can have 2^64 luns when information unit transfers are enabled, 121*4882a593Smuzhiyun * but it is doubtful this driver will ever support IUTs. 122*4882a593Smuzhiyun */ 123*4882a593Smuzhiyun #define AHC_NUM_LUNS 64 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /* 126*4882a593Smuzhiyun * The maximum transfer per S/G segment. 127*4882a593Smuzhiyun */ 128*4882a593Smuzhiyun #define AHC_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */ 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun /* 131*4882a593Smuzhiyun * The maximum amount of SCB storage in hardware on a controller. 132*4882a593Smuzhiyun * This value represents an upper bound. Controllers vary in the number 133*4882a593Smuzhiyun * they actually support. 134*4882a593Smuzhiyun */ 135*4882a593Smuzhiyun #define AHC_SCB_MAX 255 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun /* 138*4882a593Smuzhiyun * The maximum number of concurrent transactions supported per driver instance. 139*4882a593Smuzhiyun * Sequencer Control Blocks (SCBs) store per-transaction information. Although 140*4882a593Smuzhiyun * the space for SCBs on the host adapter varies by model, the driver will 141*4882a593Smuzhiyun * page the SCBs between host and controller memory as needed. We are limited 142*4882a593Smuzhiyun * to 253 because: 143*4882a593Smuzhiyun * 1) The 8bit nature of the RISC engine holds us to an 8bit value. 144*4882a593Smuzhiyun * 2) We reserve one value, 255, to represent the invalid element. 145*4882a593Smuzhiyun * 3) Our input queue scheme requires one SCB to always be reserved 146*4882a593Smuzhiyun * in advance of queuing any SCBs. This takes us down to 254. 147*4882a593Smuzhiyun * 4) To handle our output queue correctly on machines that only 148*4882a593Smuzhiyun * support 32bit stores, we must clear the array 4 bytes at a 149*4882a593Smuzhiyun * time. To avoid colliding with a DMA write from the sequencer, 150*4882a593Smuzhiyun * we must be sure that 4 slots are empty when we write to clear 151*4882a593Smuzhiyun * the queue. This reduces us to 253 SCBs: 1 that just completed 152*4882a593Smuzhiyun * and the known three additional empty slots in the queue that 153*4882a593Smuzhiyun * precede it. 154*4882a593Smuzhiyun */ 155*4882a593Smuzhiyun #define AHC_MAX_QUEUE 253 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun /* 158*4882a593Smuzhiyun * The maximum amount of SCB storage we allocate in host memory. This 159*4882a593Smuzhiyun * number should reflect the 1 additional SCB we require to handle our 160*4882a593Smuzhiyun * qinfifo mechanism. 161*4882a593Smuzhiyun */ 162*4882a593Smuzhiyun #define AHC_SCB_MAX_ALLOC (AHC_MAX_QUEUE+1) 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun /* 165*4882a593Smuzhiyun * Ring Buffer of incoming target commands. 166*4882a593Smuzhiyun * We allocate 256 to simplify the logic in the sequencer 167*4882a593Smuzhiyun * by using the natural wrap point of an 8bit counter. 168*4882a593Smuzhiyun */ 169*4882a593Smuzhiyun #define AHC_TMODE_CMDS 256 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun /* Reset line assertion time in us */ 172*4882a593Smuzhiyun #define AHC_BUSRESET_DELAY 25 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun /******************* Chip Characteristics/Operating Settings *****************/ 175*4882a593Smuzhiyun /* 176*4882a593Smuzhiyun * Chip Type 177*4882a593Smuzhiyun * The chip order is from least sophisticated to most sophisticated. 178*4882a593Smuzhiyun */ 179*4882a593Smuzhiyun typedef enum { 180*4882a593Smuzhiyun AHC_NONE = 0x0000, 181*4882a593Smuzhiyun AHC_CHIPID_MASK = 0x00FF, 182*4882a593Smuzhiyun AHC_AIC7770 = 0x0001, 183*4882a593Smuzhiyun AHC_AIC7850 = 0x0002, 184*4882a593Smuzhiyun AHC_AIC7855 = 0x0003, 185*4882a593Smuzhiyun AHC_AIC7859 = 0x0004, 186*4882a593Smuzhiyun AHC_AIC7860 = 0x0005, 187*4882a593Smuzhiyun AHC_AIC7870 = 0x0006, 188*4882a593Smuzhiyun AHC_AIC7880 = 0x0007, 189*4882a593Smuzhiyun AHC_AIC7895 = 0x0008, 190*4882a593Smuzhiyun AHC_AIC7895C = 0x0009, 191*4882a593Smuzhiyun AHC_AIC7890 = 0x000a, 192*4882a593Smuzhiyun AHC_AIC7896 = 0x000b, 193*4882a593Smuzhiyun AHC_AIC7892 = 0x000c, 194*4882a593Smuzhiyun AHC_AIC7899 = 0x000d, 195*4882a593Smuzhiyun AHC_VL = 0x0100, /* Bus type VL */ 196*4882a593Smuzhiyun AHC_EISA = 0x0200, /* Bus type EISA */ 197*4882a593Smuzhiyun AHC_PCI = 0x0400, /* Bus type PCI */ 198*4882a593Smuzhiyun AHC_BUS_MASK = 0x0F00 199*4882a593Smuzhiyun } ahc_chip; 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun /* 202*4882a593Smuzhiyun * Features available in each chip type. 203*4882a593Smuzhiyun */ 204*4882a593Smuzhiyun typedef enum { 205*4882a593Smuzhiyun AHC_FENONE = 0x00000, 206*4882a593Smuzhiyun AHC_ULTRA = 0x00001, /* Supports 20MHz Transfers */ 207*4882a593Smuzhiyun AHC_ULTRA2 = 0x00002, /* Supports 40MHz Transfers */ 208*4882a593Smuzhiyun AHC_WIDE = 0x00004, /* Wide Channel */ 209*4882a593Smuzhiyun AHC_TWIN = 0x00008, /* Twin Channel */ 210*4882a593Smuzhiyun AHC_MORE_SRAM = 0x00010, /* 80 bytes instead of 64 */ 211*4882a593Smuzhiyun AHC_CMD_CHAN = 0x00020, /* Has a Command DMA Channel */ 212*4882a593Smuzhiyun AHC_QUEUE_REGS = 0x00040, /* Has Queue management registers */ 213*4882a593Smuzhiyun AHC_SG_PRELOAD = 0x00080, /* Can perform auto-SG preload */ 214*4882a593Smuzhiyun AHC_SPIOCAP = 0x00100, /* Has a Serial Port I/O Cap Register */ 215*4882a593Smuzhiyun AHC_MULTI_TID = 0x00200, /* Has bitmask of TIDs for select-in */ 216*4882a593Smuzhiyun AHC_HS_MAILBOX = 0x00400, /* Has HS_MAILBOX register */ 217*4882a593Smuzhiyun AHC_DT = 0x00800, /* Double Transition transfers */ 218*4882a593Smuzhiyun AHC_NEW_TERMCTL = 0x01000, /* Newer termination scheme */ 219*4882a593Smuzhiyun AHC_MULTI_FUNC = 0x02000, /* Multi-Function Twin Channel Device */ 220*4882a593Smuzhiyun AHC_LARGE_SCBS = 0x04000, /* 64byte SCBs */ 221*4882a593Smuzhiyun AHC_AUTORATE = 0x08000, /* Automatic update of SCSIRATE/OFFSET*/ 222*4882a593Smuzhiyun AHC_AUTOPAUSE = 0x10000, /* Automatic pause on register access */ 223*4882a593Smuzhiyun AHC_TARGETMODE = 0x20000, /* Has tested target mode support */ 224*4882a593Smuzhiyun AHC_MULTIROLE = 0x40000, /* Space for two roles at a time */ 225*4882a593Smuzhiyun AHC_REMOVABLE = 0x80000, /* Hot-Swap supported */ 226*4882a593Smuzhiyun AHC_HVD = 0x100000, /* HVD rather than SE */ 227*4882a593Smuzhiyun AHC_AIC7770_FE = AHC_FENONE, 228*4882a593Smuzhiyun /* 229*4882a593Smuzhiyun * The real 7850 does not support Ultra modes, but there are 230*4882a593Smuzhiyun * several cards that use the generic 7850 PCI ID even though 231*4882a593Smuzhiyun * they are using an Ultra capable chip (7859/7860). We start 232*4882a593Smuzhiyun * out with the AHC_ULTRA feature set and then check the DEVSTATUS 233*4882a593Smuzhiyun * register to determine if the capability is really present. 234*4882a593Smuzhiyun */ 235*4882a593Smuzhiyun AHC_AIC7850_FE = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA, 236*4882a593Smuzhiyun AHC_AIC7860_FE = AHC_AIC7850_FE, 237*4882a593Smuzhiyun AHC_AIC7870_FE = AHC_TARGETMODE|AHC_AUTOPAUSE, 238*4882a593Smuzhiyun AHC_AIC7880_FE = AHC_AIC7870_FE|AHC_ULTRA, 239*4882a593Smuzhiyun /* 240*4882a593Smuzhiyun * Although we have space for both the initiator and 241*4882a593Smuzhiyun * target roles on ULTRA2 chips, we currently disable 242*4882a593Smuzhiyun * the initiator role to allow multi-scsi-id target mode 243*4882a593Smuzhiyun * configurations. We can only respond on the same SCSI 244*4882a593Smuzhiyun * ID as our initiator role if we allow initiator operation. 245*4882a593Smuzhiyun * At some point, we should add a configuration knob to 246*4882a593Smuzhiyun * allow both roles to be loaded. 247*4882a593Smuzhiyun */ 248*4882a593Smuzhiyun AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2 249*4882a593Smuzhiyun |AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_MULTI_TID 250*4882a593Smuzhiyun |AHC_HS_MAILBOX|AHC_NEW_TERMCTL|AHC_LARGE_SCBS 251*4882a593Smuzhiyun |AHC_TARGETMODE, 252*4882a593Smuzhiyun AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_DT|AHC_AUTORATE|AHC_AUTOPAUSE, 253*4882a593Smuzhiyun AHC_AIC7895_FE = AHC_AIC7880_FE|AHC_MORE_SRAM|AHC_AUTOPAUSE 254*4882a593Smuzhiyun |AHC_CMD_CHAN|AHC_MULTI_FUNC|AHC_LARGE_SCBS, 255*4882a593Smuzhiyun AHC_AIC7895C_FE = AHC_AIC7895_FE|AHC_MULTI_TID, 256*4882a593Smuzhiyun AHC_AIC7896_FE = AHC_AIC7890_FE|AHC_MULTI_FUNC, 257*4882a593Smuzhiyun AHC_AIC7899_FE = AHC_AIC7892_FE|AHC_MULTI_FUNC 258*4882a593Smuzhiyun } ahc_feature; 259*4882a593Smuzhiyun 260*4882a593Smuzhiyun /* 261*4882a593Smuzhiyun * Bugs in the silicon that we work around in software. 262*4882a593Smuzhiyun */ 263*4882a593Smuzhiyun typedef enum { 264*4882a593Smuzhiyun AHC_BUGNONE = 0x00, 265*4882a593Smuzhiyun /* 266*4882a593Smuzhiyun * On all chips prior to the U2 product line, 267*4882a593Smuzhiyun * the WIDEODD S/G segment feature does not 268*4882a593Smuzhiyun * work during scsi->HostBus transfers. 269*4882a593Smuzhiyun */ 270*4882a593Smuzhiyun AHC_TMODE_WIDEODD_BUG = 0x01, 271*4882a593Smuzhiyun /* 272*4882a593Smuzhiyun * On the aic7890/91 Rev 0 chips, the autoflush 273*4882a593Smuzhiyun * feature does not work. A manual flush of 274*4882a593Smuzhiyun * the DMA FIFO is required. 275*4882a593Smuzhiyun */ 276*4882a593Smuzhiyun AHC_AUTOFLUSH_BUG = 0x02, 277*4882a593Smuzhiyun /* 278*4882a593Smuzhiyun * On many chips, cacheline streaming does not work. 279*4882a593Smuzhiyun */ 280*4882a593Smuzhiyun AHC_CACHETHEN_BUG = 0x04, 281*4882a593Smuzhiyun /* 282*4882a593Smuzhiyun * On the aic7896/97 chips, cacheline 283*4882a593Smuzhiyun * streaming must be enabled. 284*4882a593Smuzhiyun */ 285*4882a593Smuzhiyun AHC_CACHETHEN_DIS_BUG = 0x08, 286*4882a593Smuzhiyun /* 287*4882a593Smuzhiyun * PCI 2.1 Retry failure on non-empty data fifo. 288*4882a593Smuzhiyun */ 289*4882a593Smuzhiyun AHC_PCI_2_1_RETRY_BUG = 0x10, 290*4882a593Smuzhiyun /* 291*4882a593Smuzhiyun * Controller does not handle cacheline residuals 292*4882a593Smuzhiyun * properly on S/G segments if PCI MWI instructions 293*4882a593Smuzhiyun * are allowed. 294*4882a593Smuzhiyun */ 295*4882a593Smuzhiyun AHC_PCI_MWI_BUG = 0x20, 296*4882a593Smuzhiyun /* 297*4882a593Smuzhiyun * An SCB upload using the SCB channel's 298*4882a593Smuzhiyun * auto array entry copy feature may 299*4882a593Smuzhiyun * corrupt data. This appears to only 300*4882a593Smuzhiyun * occur on 66MHz systems. 301*4882a593Smuzhiyun */ 302*4882a593Smuzhiyun AHC_SCBCHAN_UPLOAD_BUG = 0x40 303*4882a593Smuzhiyun } ahc_bug; 304*4882a593Smuzhiyun 305*4882a593Smuzhiyun /* 306*4882a593Smuzhiyun * Configuration specific settings. 307*4882a593Smuzhiyun * The driver determines these settings by probing the 308*4882a593Smuzhiyun * chip/controller's configuration. 309*4882a593Smuzhiyun */ 310*4882a593Smuzhiyun typedef enum { 311*4882a593Smuzhiyun AHC_FNONE = 0x000, 312*4882a593Smuzhiyun AHC_PRIMARY_CHANNEL = 0x003, /* 313*4882a593Smuzhiyun * The channel that should 314*4882a593Smuzhiyun * be probed first. 315*4882a593Smuzhiyun */ 316*4882a593Smuzhiyun AHC_USEDEFAULTS = 0x004, /* 317*4882a593Smuzhiyun * For cards without an seeprom 318*4882a593Smuzhiyun * or a BIOS to initialize the chip's 319*4882a593Smuzhiyun * SRAM, we use the default target 320*4882a593Smuzhiyun * settings. 321*4882a593Smuzhiyun */ 322*4882a593Smuzhiyun AHC_SEQUENCER_DEBUG = 0x008, 323*4882a593Smuzhiyun AHC_SHARED_SRAM = 0x010, 324*4882a593Smuzhiyun AHC_LARGE_SEEPROM = 0x020, /* Uses C56_66 not C46 */ 325*4882a593Smuzhiyun AHC_RESET_BUS_A = 0x040, 326*4882a593Smuzhiyun AHC_RESET_BUS_B = 0x080, 327*4882a593Smuzhiyun AHC_EXTENDED_TRANS_A = 0x100, 328*4882a593Smuzhiyun AHC_EXTENDED_TRANS_B = 0x200, 329*4882a593Smuzhiyun AHC_TERM_ENB_A = 0x400, 330*4882a593Smuzhiyun AHC_TERM_ENB_B = 0x800, 331*4882a593Smuzhiyun AHC_INITIATORROLE = 0x1000, /* 332*4882a593Smuzhiyun * Allow initiator operations on 333*4882a593Smuzhiyun * this controller. 334*4882a593Smuzhiyun */ 335*4882a593Smuzhiyun AHC_TARGETROLE = 0x2000, /* 336*4882a593Smuzhiyun * Allow target operations on this 337*4882a593Smuzhiyun * controller. 338*4882a593Smuzhiyun */ 339*4882a593Smuzhiyun AHC_NEWEEPROM_FMT = 0x4000, 340*4882a593Smuzhiyun AHC_TQINFIFO_BLOCKED = 0x10000, /* Blocked waiting for ATIOs */ 341*4882a593Smuzhiyun AHC_INT50_SPEEDFLEX = 0x20000, /* 342*4882a593Smuzhiyun * Internal 50pin connector 343*4882a593Smuzhiyun * sits behind an aic3860 344*4882a593Smuzhiyun */ 345*4882a593Smuzhiyun AHC_SCB_BTT = 0x40000, /* 346*4882a593Smuzhiyun * The busy targets table is 347*4882a593Smuzhiyun * stored in SCB space rather 348*4882a593Smuzhiyun * than SRAM. 349*4882a593Smuzhiyun */ 350*4882a593Smuzhiyun AHC_BIOS_ENABLED = 0x80000, 351*4882a593Smuzhiyun AHC_ALL_INTERRUPTS = 0x100000, 352*4882a593Smuzhiyun AHC_PAGESCBS = 0x400000, /* Enable SCB paging */ 353*4882a593Smuzhiyun AHC_EDGE_INTERRUPT = 0x800000, /* Device uses edge triggered ints */ 354*4882a593Smuzhiyun AHC_39BIT_ADDRESSING = 0x1000000, /* Use 39 bit addressing scheme. */ 355*4882a593Smuzhiyun AHC_LSCBS_ENABLED = 0x2000000, /* 64Byte SCBs enabled */ 356*4882a593Smuzhiyun AHC_SCB_CONFIG_USED = 0x4000000, /* No SEEPROM but SCB2 had info. */ 357*4882a593Smuzhiyun AHC_NO_BIOS_INIT = 0x8000000, /* No BIOS left over settings. */ 358*4882a593Smuzhiyun AHC_DISABLE_PCI_PERR = 0x10000000, 359*4882a593Smuzhiyun AHC_HAS_TERM_LOGIC = 0x20000000 360*4882a593Smuzhiyun } ahc_flag; 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun /************************* Hardware SCB Definition ***************************/ 363*4882a593Smuzhiyun 364*4882a593Smuzhiyun /* 365*4882a593Smuzhiyun * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB 366*4882a593Smuzhiyun * consists of a "hardware SCB" mirroring the fields available on the card 367*4882a593Smuzhiyun * and additional information the kernel stores for each transaction. 368*4882a593Smuzhiyun * 369*4882a593Smuzhiyun * To minimize space utilization, a portion of the hardware scb stores 370*4882a593Smuzhiyun * different data during different portions of a SCSI transaction. 371*4882a593Smuzhiyun * As initialized by the host driver for the initiator role, this area 372*4882a593Smuzhiyun * contains the SCSI cdb (or a pointer to the cdb) to be executed. After 373*4882a593Smuzhiyun * the cdb has been presented to the target, this area serves to store 374*4882a593Smuzhiyun * residual transfer information and the SCSI status byte. 375*4882a593Smuzhiyun * For the target role, the contents of this area do not change, but 376*4882a593Smuzhiyun * still serve a different purpose than for the initiator role. See 377*4882a593Smuzhiyun * struct target_data for details. 378*4882a593Smuzhiyun */ 379*4882a593Smuzhiyun 380*4882a593Smuzhiyun /* 381*4882a593Smuzhiyun * Status information embedded in the shared poriton of 382*4882a593Smuzhiyun * an SCB after passing the cdb to the target. The kernel 383*4882a593Smuzhiyun * driver will only read this data for transactions that 384*4882a593Smuzhiyun * complete abnormally (non-zero status byte). 385*4882a593Smuzhiyun */ 386*4882a593Smuzhiyun struct status_pkt { 387*4882a593Smuzhiyun uint32_t residual_datacnt; /* Residual in the current S/G seg */ 388*4882a593Smuzhiyun uint32_t residual_sg_ptr; /* The next S/G for this transfer */ 389*4882a593Smuzhiyun uint8_t scsi_status; /* Standard SCSI status byte */ 390*4882a593Smuzhiyun }; 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun /* 393*4882a593Smuzhiyun * Target mode version of the shared data SCB segment. 394*4882a593Smuzhiyun */ 395*4882a593Smuzhiyun struct target_data { 396*4882a593Smuzhiyun uint32_t residual_datacnt; /* Residual in the current S/G seg */ 397*4882a593Smuzhiyun uint32_t residual_sg_ptr; /* The next S/G for this transfer */ 398*4882a593Smuzhiyun uint8_t scsi_status; /* SCSI status to give to initiator */ 399*4882a593Smuzhiyun uint8_t target_phases; /* Bitmap of phases to execute */ 400*4882a593Smuzhiyun uint8_t data_phase; /* Data-In or Data-Out */ 401*4882a593Smuzhiyun uint8_t initiator_tag; /* Initiator's transaction tag */ 402*4882a593Smuzhiyun }; 403*4882a593Smuzhiyun 404*4882a593Smuzhiyun struct hardware_scb { 405*4882a593Smuzhiyun /*0*/ union { 406*4882a593Smuzhiyun /* 407*4882a593Smuzhiyun * If the cdb is 12 bytes or less, we embed it directly 408*4882a593Smuzhiyun * in the SCB. For longer cdbs, we embed the address 409*4882a593Smuzhiyun * of the cdb payload as seen by the chip and a DMA 410*4882a593Smuzhiyun * is used to pull it in. 411*4882a593Smuzhiyun */ 412*4882a593Smuzhiyun uint8_t cdb[12]; 413*4882a593Smuzhiyun uint32_t cdb_ptr; 414*4882a593Smuzhiyun struct status_pkt status; 415*4882a593Smuzhiyun struct target_data tdata; 416*4882a593Smuzhiyun } shared_data; 417*4882a593Smuzhiyun /* 418*4882a593Smuzhiyun * A word about residuals. 419*4882a593Smuzhiyun * The scb is presented to the sequencer with the dataptr and datacnt 420*4882a593Smuzhiyun * fields initialized to the contents of the first S/G element to 421*4882a593Smuzhiyun * transfer. The sgptr field is initialized to the bus address for 422*4882a593Smuzhiyun * the S/G element that follows the first in the in core S/G array 423*4882a593Smuzhiyun * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid 424*4882a593Smuzhiyun * S/G entry for this transfer (single S/G element transfer with the 425*4882a593Smuzhiyun * first elements address and length preloaded in the dataptr/datacnt 426*4882a593Smuzhiyun * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL. 427*4882a593Smuzhiyun * The SG_FULL_RESID flag ensures that the residual will be correctly 428*4882a593Smuzhiyun * noted even if no data transfers occur. Once the data phase is entered, 429*4882a593Smuzhiyun * the residual sgptr and datacnt are loaded from the sgptr and the 430*4882a593Smuzhiyun * datacnt fields. After each S/G element's dataptr and length are 431*4882a593Smuzhiyun * loaded into the hardware, the residual sgptr is advanced. After 432*4882a593Smuzhiyun * each S/G element is expired, its datacnt field is checked to see 433*4882a593Smuzhiyun * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the 434*4882a593Smuzhiyun * residual sg ptr and the transfer is considered complete. If the 435*4882a593Smuzhiyun * sequencer determines that there is a residual in the tranfer, it 436*4882a593Smuzhiyun * will set the SG_RESID_VALID flag in sgptr and dma the scb back into 437*4882a593Smuzhiyun * host memory. To sumarize: 438*4882a593Smuzhiyun * 439*4882a593Smuzhiyun * Sequencer: 440*4882a593Smuzhiyun * o A residual has occurred if SG_FULL_RESID is set in sgptr, 441*4882a593Smuzhiyun * or residual_sgptr does not have SG_LIST_NULL set. 442*4882a593Smuzhiyun * 443*4882a593Smuzhiyun * o We are transferring the last segment if residual_datacnt has 444*4882a593Smuzhiyun * the SG_LAST_SEG flag set. 445*4882a593Smuzhiyun * 446*4882a593Smuzhiyun * Host: 447*4882a593Smuzhiyun * o A residual has occurred if a completed scb has the 448*4882a593Smuzhiyun * SG_RESID_VALID flag set. 449*4882a593Smuzhiyun * 450*4882a593Smuzhiyun * o residual_sgptr and sgptr refer to the "next" sg entry 451*4882a593Smuzhiyun * and so may point beyond the last valid sg entry for the 452*4882a593Smuzhiyun * transfer. 453*4882a593Smuzhiyun */ 454*4882a593Smuzhiyun /*12*/ uint32_t dataptr; 455*4882a593Smuzhiyun /*16*/ uint32_t datacnt; /* 456*4882a593Smuzhiyun * Byte 3 (numbered from 0) of 457*4882a593Smuzhiyun * the datacnt is really the 458*4882a593Smuzhiyun * 4th byte in that data address. 459*4882a593Smuzhiyun */ 460*4882a593Smuzhiyun /*20*/ uint32_t sgptr; 461*4882a593Smuzhiyun #define SG_PTR_MASK 0xFFFFFFF8 462*4882a593Smuzhiyun /*24*/ uint8_t control; /* See SCB_CONTROL in aic7xxx.reg for details */ 463*4882a593Smuzhiyun /*25*/ uint8_t scsiid; /* what to load in the SCSIID register */ 464*4882a593Smuzhiyun /*26*/ uint8_t lun; 465*4882a593Smuzhiyun /*27*/ uint8_t tag; /* 466*4882a593Smuzhiyun * Index into our kernel SCB array. 467*4882a593Smuzhiyun * Also used as the tag for tagged I/O 468*4882a593Smuzhiyun */ 469*4882a593Smuzhiyun /*28*/ uint8_t cdb_len; 470*4882a593Smuzhiyun /*29*/ uint8_t scsirate; /* Value for SCSIRATE register */ 471*4882a593Smuzhiyun /*30*/ uint8_t scsioffset; /* Value for SCSIOFFSET register */ 472*4882a593Smuzhiyun /*31*/ uint8_t next; /* 473*4882a593Smuzhiyun * Used for threading SCBs in the 474*4882a593Smuzhiyun * "Waiting for Selection" and 475*4882a593Smuzhiyun * "Disconnected SCB" lists down 476*4882a593Smuzhiyun * in the sequencer. 477*4882a593Smuzhiyun */ 478*4882a593Smuzhiyun /*32*/ uint8_t cdb32[32]; /* 479*4882a593Smuzhiyun * CDB storage for cdbs of size 480*4882a593Smuzhiyun * 13->32. We store them here 481*4882a593Smuzhiyun * because hardware scbs are 482*4882a593Smuzhiyun * allocated from DMA safe 483*4882a593Smuzhiyun * memory so we are guaranteed 484*4882a593Smuzhiyun * the controller can access 485*4882a593Smuzhiyun * this data. 486*4882a593Smuzhiyun */ 487*4882a593Smuzhiyun }; 488*4882a593Smuzhiyun 489*4882a593Smuzhiyun /************************ Kernel SCB Definitions ******************************/ 490*4882a593Smuzhiyun /* 491*4882a593Smuzhiyun * Some fields of the SCB are OS dependent. Here we collect the 492*4882a593Smuzhiyun * definitions for elements that all OS platforms need to include 493*4882a593Smuzhiyun * in there SCB definition. 494*4882a593Smuzhiyun */ 495*4882a593Smuzhiyun 496*4882a593Smuzhiyun /* 497*4882a593Smuzhiyun * Definition of a scatter/gather element as transferred to the controller. 498*4882a593Smuzhiyun * The aic7xxx chips only support a 24bit length. We use the top byte of 499*4882a593Smuzhiyun * the length to store additional address bits and a flag to indicate 500*4882a593Smuzhiyun * that a given segment terminates the transfer. This gives us an 501*4882a593Smuzhiyun * addressable range of 512GB on machines with 64bit PCI or with chips 502*4882a593Smuzhiyun * that can support dual address cycles on 32bit PCI busses. 503*4882a593Smuzhiyun */ 504*4882a593Smuzhiyun struct ahc_dma_seg { 505*4882a593Smuzhiyun uint32_t addr; 506*4882a593Smuzhiyun uint32_t len; 507*4882a593Smuzhiyun #define AHC_DMA_LAST_SEG 0x80000000 508*4882a593Smuzhiyun #define AHC_SG_HIGH_ADDR_MASK 0x7F000000 509*4882a593Smuzhiyun #define AHC_SG_LEN_MASK 0x00FFFFFF 510*4882a593Smuzhiyun }; 511*4882a593Smuzhiyun 512*4882a593Smuzhiyun struct sg_map_node { 513*4882a593Smuzhiyun bus_dmamap_t sg_dmamap; 514*4882a593Smuzhiyun dma_addr_t sg_physaddr; 515*4882a593Smuzhiyun struct ahc_dma_seg* sg_vaddr; 516*4882a593Smuzhiyun SLIST_ENTRY(sg_map_node) links; 517*4882a593Smuzhiyun }; 518*4882a593Smuzhiyun 519*4882a593Smuzhiyun /* 520*4882a593Smuzhiyun * The current state of this SCB. 521*4882a593Smuzhiyun */ 522*4882a593Smuzhiyun typedef enum { 523*4882a593Smuzhiyun SCB_FREE = 0x0000, 524*4882a593Smuzhiyun SCB_OTHERTCL_TIMEOUT = 0x0002,/* 525*4882a593Smuzhiyun * Another device was active 526*4882a593Smuzhiyun * during the first timeout for 527*4882a593Smuzhiyun * this SCB so we gave ourselves 528*4882a593Smuzhiyun * an additional timeout period 529*4882a593Smuzhiyun * in case it was hogging the 530*4882a593Smuzhiyun * bus. 531*4882a593Smuzhiyun */ 532*4882a593Smuzhiyun SCB_DEVICE_RESET = 0x0004, 533*4882a593Smuzhiyun SCB_SENSE = 0x0008, 534*4882a593Smuzhiyun SCB_CDB32_PTR = 0x0010, 535*4882a593Smuzhiyun SCB_RECOVERY_SCB = 0x0020, 536*4882a593Smuzhiyun SCB_AUTO_NEGOTIATE = 0x0040,/* Negotiate to achieve goal. */ 537*4882a593Smuzhiyun SCB_NEGOTIATE = 0x0080,/* Negotiation forced for command. */ 538*4882a593Smuzhiyun SCB_ABORT = 0x0100, 539*4882a593Smuzhiyun SCB_UNTAGGEDQ = 0x0200, 540*4882a593Smuzhiyun SCB_ACTIVE = 0x0400, 541*4882a593Smuzhiyun SCB_TARGET_IMMEDIATE = 0x0800, 542*4882a593Smuzhiyun SCB_TRANSMISSION_ERROR = 0x1000,/* 543*4882a593Smuzhiyun * We detected a parity or CRC 544*4882a593Smuzhiyun * error that has effected the 545*4882a593Smuzhiyun * payload of the command. This 546*4882a593Smuzhiyun * flag is checked when normal 547*4882a593Smuzhiyun * status is returned to catch 548*4882a593Smuzhiyun * the case of a target not 549*4882a593Smuzhiyun * responding to our attempt 550*4882a593Smuzhiyun * to report the error. 551*4882a593Smuzhiyun */ 552*4882a593Smuzhiyun SCB_TARGET_SCB = 0x2000, 553*4882a593Smuzhiyun SCB_SILENT = 0x4000 /* 554*4882a593Smuzhiyun * Be quiet about transmission type 555*4882a593Smuzhiyun * errors. They are expected and we 556*4882a593Smuzhiyun * don't want to upset the user. This 557*4882a593Smuzhiyun * flag is typically used during DV. 558*4882a593Smuzhiyun */ 559*4882a593Smuzhiyun } scb_flag; 560*4882a593Smuzhiyun 561*4882a593Smuzhiyun struct scb { 562*4882a593Smuzhiyun struct hardware_scb *hscb; 563*4882a593Smuzhiyun union { 564*4882a593Smuzhiyun SLIST_ENTRY(scb) sle; 565*4882a593Smuzhiyun TAILQ_ENTRY(scb) tqe; 566*4882a593Smuzhiyun } links; 567*4882a593Smuzhiyun LIST_ENTRY(scb) pending_links; 568*4882a593Smuzhiyun ahc_io_ctx_t io_ctx; 569*4882a593Smuzhiyun struct ahc_softc *ahc_softc; 570*4882a593Smuzhiyun scb_flag flags; 571*4882a593Smuzhiyun struct scb_platform_data *platform_data; 572*4882a593Smuzhiyun struct sg_map_node *sg_map; 573*4882a593Smuzhiyun struct ahc_dma_seg *sg_list; 574*4882a593Smuzhiyun dma_addr_t sg_list_phys; 575*4882a593Smuzhiyun u_int sg_count;/* How full ahc_dma_seg is */ 576*4882a593Smuzhiyun }; 577*4882a593Smuzhiyun 578*4882a593Smuzhiyun struct scb_data { 579*4882a593Smuzhiyun SLIST_HEAD(, scb) free_scbs; /* 580*4882a593Smuzhiyun * Pool of SCBs ready to be assigned 581*4882a593Smuzhiyun * commands to execute. 582*4882a593Smuzhiyun */ 583*4882a593Smuzhiyun struct scb *scbindex[256]; /* 584*4882a593Smuzhiyun * Mapping from tag to SCB. 585*4882a593Smuzhiyun * As tag identifiers are an 586*4882a593Smuzhiyun * 8bit value, we provide space 587*4882a593Smuzhiyun * for all possible tag values. 588*4882a593Smuzhiyun * Any lookups to entries at or 589*4882a593Smuzhiyun * above AHC_SCB_MAX_ALLOC will 590*4882a593Smuzhiyun * always fail. 591*4882a593Smuzhiyun */ 592*4882a593Smuzhiyun struct hardware_scb *hscbs; /* Array of hardware SCBs */ 593*4882a593Smuzhiyun struct scb *scbarray; /* Array of kernel SCBs */ 594*4882a593Smuzhiyun struct scsi_sense_data *sense; /* Per SCB sense data */ 595*4882a593Smuzhiyun 596*4882a593Smuzhiyun /* 597*4882a593Smuzhiyun * "Bus" addresses of our data structures. 598*4882a593Smuzhiyun */ 599*4882a593Smuzhiyun bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */ 600*4882a593Smuzhiyun bus_dmamap_t hscb_dmamap; 601*4882a593Smuzhiyun dma_addr_t hscb_busaddr; 602*4882a593Smuzhiyun bus_dma_tag_t sense_dmat; 603*4882a593Smuzhiyun bus_dmamap_t sense_dmamap; 604*4882a593Smuzhiyun dma_addr_t sense_busaddr; 605*4882a593Smuzhiyun bus_dma_tag_t sg_dmat; /* dmat for our sg segments */ 606*4882a593Smuzhiyun SLIST_HEAD(, sg_map_node) sg_maps; 607*4882a593Smuzhiyun uint8_t numscbs; 608*4882a593Smuzhiyun uint8_t maxhscbs; /* Number of SCBs on the card */ 609*4882a593Smuzhiyun uint8_t init_level; /* 610*4882a593Smuzhiyun * How far we've initialized 611*4882a593Smuzhiyun * this structure. 612*4882a593Smuzhiyun */ 613*4882a593Smuzhiyun }; 614*4882a593Smuzhiyun 615*4882a593Smuzhiyun /************************ Target Mode Definitions *****************************/ 616*4882a593Smuzhiyun 617*4882a593Smuzhiyun /* 618*4882a593Smuzhiyun * Connection descriptor for select-in requests in target mode. 619*4882a593Smuzhiyun */ 620*4882a593Smuzhiyun struct target_cmd { 621*4882a593Smuzhiyun uint8_t scsiid; /* Our ID and the initiator's ID */ 622*4882a593Smuzhiyun uint8_t identify; /* Identify message */ 623*4882a593Smuzhiyun uint8_t bytes[22]; /* 624*4882a593Smuzhiyun * Bytes contains any additional message 625*4882a593Smuzhiyun * bytes terminated by 0xFF. The remainder 626*4882a593Smuzhiyun * is the cdb to execute. 627*4882a593Smuzhiyun */ 628*4882a593Smuzhiyun uint8_t cmd_valid; /* 629*4882a593Smuzhiyun * When a command is complete, the firmware 630*4882a593Smuzhiyun * will set cmd_valid to all bits set. 631*4882a593Smuzhiyun * After the host has seen the command, 632*4882a593Smuzhiyun * the bits are cleared. This allows us 633*4882a593Smuzhiyun * to just peek at host memory to determine 634*4882a593Smuzhiyun * if more work is complete. cmd_valid is on 635*4882a593Smuzhiyun * an 8 byte boundary to simplify setting 636*4882a593Smuzhiyun * it on aic7880 hardware which only has 637*4882a593Smuzhiyun * limited direct access to the DMA FIFO. 638*4882a593Smuzhiyun */ 639*4882a593Smuzhiyun uint8_t pad[7]; 640*4882a593Smuzhiyun }; 641*4882a593Smuzhiyun 642*4882a593Smuzhiyun /* 643*4882a593Smuzhiyun * Number of events we can buffer up if we run out 644*4882a593Smuzhiyun * of immediate notify ccbs. 645*4882a593Smuzhiyun */ 646*4882a593Smuzhiyun #define AHC_TMODE_EVENT_BUFFER_SIZE 8 647*4882a593Smuzhiyun struct ahc_tmode_event { 648*4882a593Smuzhiyun uint8_t initiator_id; 649*4882a593Smuzhiyun uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */ 650*4882a593Smuzhiyun #define EVENT_TYPE_BUS_RESET 0xFF 651*4882a593Smuzhiyun uint8_t event_arg; 652*4882a593Smuzhiyun }; 653*4882a593Smuzhiyun 654*4882a593Smuzhiyun /* 655*4882a593Smuzhiyun * Per enabled lun target mode state. 656*4882a593Smuzhiyun * As this state is directly influenced by the host OS'es target mode 657*4882a593Smuzhiyun * environment, we let the OS module define it. Forward declare the 658*4882a593Smuzhiyun * structure here so we can store arrays of them, etc. in OS neutral 659*4882a593Smuzhiyun * data structures. 660*4882a593Smuzhiyun */ 661*4882a593Smuzhiyun #ifdef AHC_TARGET_MODE 662*4882a593Smuzhiyun struct ahc_tmode_lstate { 663*4882a593Smuzhiyun struct cam_path *path; 664*4882a593Smuzhiyun struct ccb_hdr_slist accept_tios; 665*4882a593Smuzhiyun struct ccb_hdr_slist immed_notifies; 666*4882a593Smuzhiyun struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE]; 667*4882a593Smuzhiyun uint8_t event_r_idx; 668*4882a593Smuzhiyun uint8_t event_w_idx; 669*4882a593Smuzhiyun }; 670*4882a593Smuzhiyun #else 671*4882a593Smuzhiyun struct ahc_tmode_lstate; 672*4882a593Smuzhiyun #endif 673*4882a593Smuzhiyun 674*4882a593Smuzhiyun /******************** Transfer Negotiation Datastructures *********************/ 675*4882a593Smuzhiyun #define AHC_TRANS_CUR 0x01 /* Modify current neogtiation status */ 676*4882a593Smuzhiyun #define AHC_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */ 677*4882a593Smuzhiyun #define AHC_TRANS_GOAL 0x04 /* Modify negotiation goal */ 678*4882a593Smuzhiyun #define AHC_TRANS_USER 0x08 /* Modify user negotiation settings */ 679*4882a593Smuzhiyun 680*4882a593Smuzhiyun #define AHC_WIDTH_UNKNOWN 0xFF 681*4882a593Smuzhiyun #define AHC_PERIOD_UNKNOWN 0xFF 682*4882a593Smuzhiyun #define AHC_OFFSET_UNKNOWN 0xFF 683*4882a593Smuzhiyun #define AHC_PPR_OPTS_UNKNOWN 0xFF 684*4882a593Smuzhiyun 685*4882a593Smuzhiyun /* 686*4882a593Smuzhiyun * Transfer Negotiation Information. 687*4882a593Smuzhiyun */ 688*4882a593Smuzhiyun struct ahc_transinfo { 689*4882a593Smuzhiyun uint8_t protocol_version; /* SCSI Revision level */ 690*4882a593Smuzhiyun uint8_t transport_version; /* SPI Revision level */ 691*4882a593Smuzhiyun uint8_t width; /* Bus width */ 692*4882a593Smuzhiyun uint8_t period; /* Sync rate factor */ 693*4882a593Smuzhiyun uint8_t offset; /* Sync offset */ 694*4882a593Smuzhiyun uint8_t ppr_options; /* Parallel Protocol Request options */ 695*4882a593Smuzhiyun }; 696*4882a593Smuzhiyun 697*4882a593Smuzhiyun /* 698*4882a593Smuzhiyun * Per-initiator current, goal and user transfer negotiation information. */ 699*4882a593Smuzhiyun struct ahc_initiator_tinfo { 700*4882a593Smuzhiyun uint8_t scsirate; /* Computed value for SCSIRATE reg */ 701*4882a593Smuzhiyun struct ahc_transinfo curr; 702*4882a593Smuzhiyun struct ahc_transinfo goal; 703*4882a593Smuzhiyun struct ahc_transinfo user; 704*4882a593Smuzhiyun }; 705*4882a593Smuzhiyun 706*4882a593Smuzhiyun /* 707*4882a593Smuzhiyun * Per enabled target ID state. 708*4882a593Smuzhiyun * Pointers to lun target state as well as sync/wide negotiation information 709*4882a593Smuzhiyun * for each initiator<->target mapping. For the initiator role we pretend 710*4882a593Smuzhiyun * that we are the target and the targets are the initiators since the 711*4882a593Smuzhiyun * negotiation is the same regardless of role. 712*4882a593Smuzhiyun */ 713*4882a593Smuzhiyun struct ahc_tmode_tstate { 714*4882a593Smuzhiyun struct ahc_tmode_lstate* enabled_luns[AHC_NUM_LUNS]; 715*4882a593Smuzhiyun struct ahc_initiator_tinfo transinfo[AHC_NUM_TARGETS]; 716*4882a593Smuzhiyun 717*4882a593Smuzhiyun /* 718*4882a593Smuzhiyun * Per initiator state bitmasks. 719*4882a593Smuzhiyun */ 720*4882a593Smuzhiyun uint16_t auto_negotiate;/* Auto Negotiation Required */ 721*4882a593Smuzhiyun uint16_t ultraenb; /* Using ultra sync rate */ 722*4882a593Smuzhiyun uint16_t discenable; /* Disconnection allowed */ 723*4882a593Smuzhiyun uint16_t tagenable; /* Tagged Queuing allowed */ 724*4882a593Smuzhiyun }; 725*4882a593Smuzhiyun 726*4882a593Smuzhiyun /* 727*4882a593Smuzhiyun * Data structure for our table of allowed synchronous transfer rates. 728*4882a593Smuzhiyun */ 729*4882a593Smuzhiyun struct ahc_syncrate { 730*4882a593Smuzhiyun u_int sxfr_u2; /* Value of the SXFR parameter for Ultra2+ Chips */ 731*4882a593Smuzhiyun u_int sxfr; /* Value of the SXFR parameter for <= Ultra Chips */ 732*4882a593Smuzhiyun #define ULTRA_SXFR 0x100 /* Rate Requires Ultra Mode set */ 733*4882a593Smuzhiyun #define ST_SXFR 0x010 /* Rate Single Transition Only */ 734*4882a593Smuzhiyun #define DT_SXFR 0x040 /* Rate Double Transition Only */ 735*4882a593Smuzhiyun uint8_t period; /* Period to send to SCSI target */ 736*4882a593Smuzhiyun const char *rate; 737*4882a593Smuzhiyun }; 738*4882a593Smuzhiyun 739*4882a593Smuzhiyun /* Safe and valid period for async negotiations. */ 740*4882a593Smuzhiyun #define AHC_ASYNC_XFER_PERIOD 0x45 741*4882a593Smuzhiyun #define AHC_ULTRA2_XFER_PERIOD 0x0a 742*4882a593Smuzhiyun 743*4882a593Smuzhiyun /* 744*4882a593Smuzhiyun * Indexes into our table of syncronous transfer rates. 745*4882a593Smuzhiyun */ 746*4882a593Smuzhiyun #define AHC_SYNCRATE_DT 0 747*4882a593Smuzhiyun #define AHC_SYNCRATE_ULTRA2 1 748*4882a593Smuzhiyun #define AHC_SYNCRATE_ULTRA 3 749*4882a593Smuzhiyun #define AHC_SYNCRATE_FAST 6 750*4882a593Smuzhiyun #define AHC_SYNCRATE_MAX AHC_SYNCRATE_DT 751*4882a593Smuzhiyun #define AHC_SYNCRATE_MIN 13 752*4882a593Smuzhiyun 753*4882a593Smuzhiyun /***************************** Lookup Tables **********************************/ 754*4882a593Smuzhiyun /* 755*4882a593Smuzhiyun * Phase -> name and message out response 756*4882a593Smuzhiyun * to parity errors in each phase table. 757*4882a593Smuzhiyun */ 758*4882a593Smuzhiyun struct ahc_phase_table_entry { 759*4882a593Smuzhiyun uint8_t phase; 760*4882a593Smuzhiyun uint8_t mesg_out; /* Message response to parity errors */ 761*4882a593Smuzhiyun char *phasemsg; 762*4882a593Smuzhiyun }; 763*4882a593Smuzhiyun 764*4882a593Smuzhiyun /************************** Serial EEPROM Format ******************************/ 765*4882a593Smuzhiyun 766*4882a593Smuzhiyun struct seeprom_config { 767*4882a593Smuzhiyun /* 768*4882a593Smuzhiyun * Per SCSI ID Configuration Flags 769*4882a593Smuzhiyun */ 770*4882a593Smuzhiyun uint16_t device_flags[16]; /* words 0-15 */ 771*4882a593Smuzhiyun #define CFXFER 0x0007 /* synchronous transfer rate */ 772*4882a593Smuzhiyun #define CFSYNCH 0x0008 /* enable synchronous transfer */ 773*4882a593Smuzhiyun #define CFDISC 0x0010 /* enable disconnection */ 774*4882a593Smuzhiyun #define CFWIDEB 0x0020 /* wide bus device */ 775*4882a593Smuzhiyun #define CFSYNCHISULTRA 0x0040 /* CFSYNCH is an ultra offset (2940AU)*/ 776*4882a593Smuzhiyun #define CFSYNCSINGLE 0x0080 /* Single-Transition signalling */ 777*4882a593Smuzhiyun #define CFSTART 0x0100 /* send start unit SCSI command */ 778*4882a593Smuzhiyun #define CFINCBIOS 0x0200 /* include in BIOS scan */ 779*4882a593Smuzhiyun #define CFRNFOUND 0x0400 /* report even if not found */ 780*4882a593Smuzhiyun #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */ 781*4882a593Smuzhiyun #define CFWBCACHEENB 0x4000 /* Enable W-Behind Cache on disks */ 782*4882a593Smuzhiyun #define CFWBCACHENOP 0xc000 /* Don't touch W-Behind Cache */ 783*4882a593Smuzhiyun 784*4882a593Smuzhiyun /* 785*4882a593Smuzhiyun * BIOS Control Bits 786*4882a593Smuzhiyun */ 787*4882a593Smuzhiyun uint16_t bios_control; /* word 16 */ 788*4882a593Smuzhiyun #define CFSUPREM 0x0001 /* support all removeable drives */ 789*4882a593Smuzhiyun #define CFSUPREMB 0x0002 /* support removeable boot drives */ 790*4882a593Smuzhiyun #define CFBIOSEN 0x0004 /* BIOS enabled */ 791*4882a593Smuzhiyun #define CFBIOS_BUSSCAN 0x0008 /* Have the BIOS Scan the Bus */ 792*4882a593Smuzhiyun #define CFSM2DRV 0x0010 /* support more than two drives */ 793*4882a593Smuzhiyun #define CFSTPWLEVEL 0x0010 /* Termination level control */ 794*4882a593Smuzhiyun #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */ 795*4882a593Smuzhiyun #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */ 796*4882a593Smuzhiyun #define CFTERM_MENU 0x0040 /* BIOS displays termination menu */ 797*4882a593Smuzhiyun #define CFEXTEND 0x0080 /* extended translation enabled */ 798*4882a593Smuzhiyun #define CFSCAMEN 0x0100 /* SCAM enable */ 799*4882a593Smuzhiyun #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */ 800*4882a593Smuzhiyun #define CFMSG_VERBOSE 0x0000 801*4882a593Smuzhiyun #define CFMSG_SILENT 0x0200 802*4882a593Smuzhiyun #define CFMSG_DIAG 0x0400 803*4882a593Smuzhiyun #define CFBOOTCD 0x0800 /* Support Bootable CD-ROM */ 804*4882a593Smuzhiyun /* UNUSED 0xff00 */ 805*4882a593Smuzhiyun 806*4882a593Smuzhiyun /* 807*4882a593Smuzhiyun * Host Adapter Control Bits 808*4882a593Smuzhiyun */ 809*4882a593Smuzhiyun uint16_t adapter_control; /* word 17 */ 810*4882a593Smuzhiyun #define CFAUTOTERM 0x0001 /* Perform Auto termination */ 811*4882a593Smuzhiyun #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable */ 812*4882a593Smuzhiyun #define CF284XSELTO 0x0003 /* Selection timeout (284x cards) */ 813*4882a593Smuzhiyun #define CF284XFIFO 0x000C /* FIFO Threshold (284x cards) */ 814*4882a593Smuzhiyun #define CFSTERM 0x0004 /* SCSI low byte termination */ 815*4882a593Smuzhiyun #define CFWSTERM 0x0008 /* SCSI high byte termination */ 816*4882a593Smuzhiyun #define CFSPARITY 0x0010 /* SCSI parity */ 817*4882a593Smuzhiyun #define CF284XSTERM 0x0020 /* SCSI low byte term (284x cards) */ 818*4882a593Smuzhiyun #define CFMULTILUN 0x0020 819*4882a593Smuzhiyun #define CFRESETB 0x0040 /* reset SCSI bus at boot */ 820*4882a593Smuzhiyun #define CFCLUSTERENB 0x0080 /* Cluster Enable */ 821*4882a593Smuzhiyun #define CFBOOTCHAN 0x0300 /* probe this channel first */ 822*4882a593Smuzhiyun #define CFBOOTCHANSHIFT 8 823*4882a593Smuzhiyun #define CFSEAUTOTERM 0x0400 /* Ultra2 Perform secondary Auto Term*/ 824*4882a593Smuzhiyun #define CFSELOWTERM 0x0800 /* Ultra2 secondary low term */ 825*4882a593Smuzhiyun #define CFSEHIGHTERM 0x1000 /* Ultra2 secondary high term */ 826*4882a593Smuzhiyun #define CFENABLEDV 0x4000 /* Perform Domain Validation*/ 827*4882a593Smuzhiyun 828*4882a593Smuzhiyun /* 829*4882a593Smuzhiyun * Bus Release Time, Host Adapter ID 830*4882a593Smuzhiyun */ 831*4882a593Smuzhiyun uint16_t brtime_id; /* word 18 */ 832*4882a593Smuzhiyun #define CFSCSIID 0x000f /* host adapter SCSI ID */ 833*4882a593Smuzhiyun /* UNUSED 0x00f0 */ 834*4882a593Smuzhiyun #define CFBRTIME 0xff00 /* bus release time */ 835*4882a593Smuzhiyun 836*4882a593Smuzhiyun /* 837*4882a593Smuzhiyun * Maximum targets 838*4882a593Smuzhiyun */ 839*4882a593Smuzhiyun uint16_t max_targets; /* word 19 */ 840*4882a593Smuzhiyun #define CFMAXTARG 0x00ff /* maximum targets */ 841*4882a593Smuzhiyun #define CFBOOTLUN 0x0f00 /* Lun to boot from */ 842*4882a593Smuzhiyun #define CFBOOTID 0xf000 /* Target to boot from */ 843*4882a593Smuzhiyun uint16_t res_1[10]; /* words 20-29 */ 844*4882a593Smuzhiyun uint16_t signature; /* Signature == 0x250 */ 845*4882a593Smuzhiyun #define CFSIGNATURE 0x250 846*4882a593Smuzhiyun #define CFSIGNATURE2 0x300 847*4882a593Smuzhiyun uint16_t checksum; /* word 31 */ 848*4882a593Smuzhiyun }; 849*4882a593Smuzhiyun 850*4882a593Smuzhiyun /**************************** Message Buffer *********************************/ 851*4882a593Smuzhiyun typedef enum { 852*4882a593Smuzhiyun MSG_TYPE_NONE = 0x00, 853*4882a593Smuzhiyun MSG_TYPE_INITIATOR_MSGOUT = 0x01, 854*4882a593Smuzhiyun MSG_TYPE_INITIATOR_MSGIN = 0x02, 855*4882a593Smuzhiyun MSG_TYPE_TARGET_MSGOUT = 0x03, 856*4882a593Smuzhiyun MSG_TYPE_TARGET_MSGIN = 0x04 857*4882a593Smuzhiyun } ahc_msg_type; 858*4882a593Smuzhiyun 859*4882a593Smuzhiyun typedef enum { 860*4882a593Smuzhiyun MSGLOOP_IN_PROG, 861*4882a593Smuzhiyun MSGLOOP_MSGCOMPLETE, 862*4882a593Smuzhiyun MSGLOOP_TERMINATED 863*4882a593Smuzhiyun } msg_loop_stat; 864*4882a593Smuzhiyun 865*4882a593Smuzhiyun /*********************** Software Configuration Structure *********************/ 866*4882a593Smuzhiyun TAILQ_HEAD(scb_tailq, scb); 867*4882a593Smuzhiyun 868*4882a593Smuzhiyun struct ahc_aic7770_softc { 869*4882a593Smuzhiyun /* 870*4882a593Smuzhiyun * Saved register state used for chip_init(). 871*4882a593Smuzhiyun */ 872*4882a593Smuzhiyun uint8_t busspd; 873*4882a593Smuzhiyun uint8_t bustime; 874*4882a593Smuzhiyun }; 875*4882a593Smuzhiyun 876*4882a593Smuzhiyun struct ahc_pci_softc { 877*4882a593Smuzhiyun /* 878*4882a593Smuzhiyun * Saved register state used for chip_init(). 879*4882a593Smuzhiyun */ 880*4882a593Smuzhiyun uint32_t devconfig; 881*4882a593Smuzhiyun uint16_t targcrccnt; 882*4882a593Smuzhiyun uint8_t command; 883*4882a593Smuzhiyun uint8_t csize_lattime; 884*4882a593Smuzhiyun uint8_t optionmode; 885*4882a593Smuzhiyun uint8_t crccontrol1; 886*4882a593Smuzhiyun uint8_t dscommand0; 887*4882a593Smuzhiyun uint8_t dspcistatus; 888*4882a593Smuzhiyun uint8_t scbbaddr; 889*4882a593Smuzhiyun uint8_t dff_thrsh; 890*4882a593Smuzhiyun }; 891*4882a593Smuzhiyun 892*4882a593Smuzhiyun union ahc_bus_softc { 893*4882a593Smuzhiyun struct ahc_aic7770_softc aic7770_softc; 894*4882a593Smuzhiyun struct ahc_pci_softc pci_softc; 895*4882a593Smuzhiyun }; 896*4882a593Smuzhiyun 897*4882a593Smuzhiyun typedef void (*ahc_bus_intr_t)(struct ahc_softc *); 898*4882a593Smuzhiyun typedef int (*ahc_bus_chip_init_t)(struct ahc_softc *); 899*4882a593Smuzhiyun typedef int (*ahc_bus_suspend_t)(struct ahc_softc *); 900*4882a593Smuzhiyun typedef int (*ahc_bus_resume_t)(struct ahc_softc *); 901*4882a593Smuzhiyun typedef void ahc_callback_t (void *); 902*4882a593Smuzhiyun 903*4882a593Smuzhiyun struct ahc_softc { 904*4882a593Smuzhiyun bus_space_tag_t tag; 905*4882a593Smuzhiyun bus_space_handle_t bsh; 906*4882a593Smuzhiyun struct scb_data *scb_data; 907*4882a593Smuzhiyun 908*4882a593Smuzhiyun struct scb *next_queued_scb; 909*4882a593Smuzhiyun 910*4882a593Smuzhiyun /* 911*4882a593Smuzhiyun * SCBs that have been sent to the controller 912*4882a593Smuzhiyun */ 913*4882a593Smuzhiyun BSD_LIST_HEAD(, scb) pending_scbs; 914*4882a593Smuzhiyun 915*4882a593Smuzhiyun /* 916*4882a593Smuzhiyun * Counting lock for deferring the release of additional 917*4882a593Smuzhiyun * untagged transactions from the untagged_queues. When 918*4882a593Smuzhiyun * the lock is decremented to 0, all queues in the 919*4882a593Smuzhiyun * untagged_queues array are run. 920*4882a593Smuzhiyun */ 921*4882a593Smuzhiyun u_int untagged_queue_lock; 922*4882a593Smuzhiyun 923*4882a593Smuzhiyun /* 924*4882a593Smuzhiyun * Per-target queue of untagged-transactions. The 925*4882a593Smuzhiyun * transaction at the head of the queue is the 926*4882a593Smuzhiyun * currently pending untagged transaction for the 927*4882a593Smuzhiyun * target. The driver only allows a single untagged 928*4882a593Smuzhiyun * transaction per target. 929*4882a593Smuzhiyun */ 930*4882a593Smuzhiyun struct scb_tailq untagged_queues[AHC_NUM_TARGETS]; 931*4882a593Smuzhiyun 932*4882a593Smuzhiyun /* 933*4882a593Smuzhiyun * Bus attachment specific data. 934*4882a593Smuzhiyun */ 935*4882a593Smuzhiyun union ahc_bus_softc bus_softc; 936*4882a593Smuzhiyun 937*4882a593Smuzhiyun /* 938*4882a593Smuzhiyun * Platform specific data. 939*4882a593Smuzhiyun */ 940*4882a593Smuzhiyun struct ahc_platform_data *platform_data; 941*4882a593Smuzhiyun 942*4882a593Smuzhiyun /* 943*4882a593Smuzhiyun * Platform specific device information. 944*4882a593Smuzhiyun */ 945*4882a593Smuzhiyun ahc_dev_softc_t dev_softc; 946*4882a593Smuzhiyun struct device *dev; 947*4882a593Smuzhiyun 948*4882a593Smuzhiyun /* 949*4882a593Smuzhiyun * Bus specific device information. 950*4882a593Smuzhiyun */ 951*4882a593Smuzhiyun ahc_bus_intr_t bus_intr; 952*4882a593Smuzhiyun 953*4882a593Smuzhiyun /* 954*4882a593Smuzhiyun * Bus specific initialization required 955*4882a593Smuzhiyun * after a chip reset. 956*4882a593Smuzhiyun */ 957*4882a593Smuzhiyun ahc_bus_chip_init_t bus_chip_init; 958*4882a593Smuzhiyun 959*4882a593Smuzhiyun /* 960*4882a593Smuzhiyun * Target mode related state kept on a per enabled lun basis. 961*4882a593Smuzhiyun * Targets that are not enabled will have null entries. 962*4882a593Smuzhiyun * As an initiator, we keep one target entry for our initiator 963*4882a593Smuzhiyun * ID to store our sync/wide transfer settings. 964*4882a593Smuzhiyun */ 965*4882a593Smuzhiyun struct ahc_tmode_tstate *enabled_targets[AHC_NUM_TARGETS]; 966*4882a593Smuzhiyun 967*4882a593Smuzhiyun /* 968*4882a593Smuzhiyun * The black hole device responsible for handling requests for 969*4882a593Smuzhiyun * disabled luns on enabled targets. 970*4882a593Smuzhiyun */ 971*4882a593Smuzhiyun struct ahc_tmode_lstate *black_hole; 972*4882a593Smuzhiyun 973*4882a593Smuzhiyun /* 974*4882a593Smuzhiyun * Device instance currently on the bus awaiting a continue TIO 975*4882a593Smuzhiyun * for a command that was not given the disconnect priveledge. 976*4882a593Smuzhiyun */ 977*4882a593Smuzhiyun struct ahc_tmode_lstate *pending_device; 978*4882a593Smuzhiyun 979*4882a593Smuzhiyun /* 980*4882a593Smuzhiyun * Card characteristics 981*4882a593Smuzhiyun */ 982*4882a593Smuzhiyun ahc_chip chip; 983*4882a593Smuzhiyun ahc_feature features; 984*4882a593Smuzhiyun ahc_bug bugs; 985*4882a593Smuzhiyun ahc_flag flags; 986*4882a593Smuzhiyun struct seeprom_config *seep_config; 987*4882a593Smuzhiyun 988*4882a593Smuzhiyun /* Values to store in the SEQCTL register for pause and unpause */ 989*4882a593Smuzhiyun uint8_t unpause; 990*4882a593Smuzhiyun uint8_t pause; 991*4882a593Smuzhiyun 992*4882a593Smuzhiyun /* Command Queues */ 993*4882a593Smuzhiyun uint8_t qoutfifonext; 994*4882a593Smuzhiyun uint8_t qinfifonext; 995*4882a593Smuzhiyun uint8_t *qoutfifo; 996*4882a593Smuzhiyun uint8_t *qinfifo; 997*4882a593Smuzhiyun 998*4882a593Smuzhiyun /* Critical Section Data */ 999*4882a593Smuzhiyun struct cs *critical_sections; 1000*4882a593Smuzhiyun u_int num_critical_sections; 1001*4882a593Smuzhiyun 1002*4882a593Smuzhiyun /* Channel Names ('A', 'B', etc.) */ 1003*4882a593Smuzhiyun char channel; 1004*4882a593Smuzhiyun char channel_b; 1005*4882a593Smuzhiyun 1006*4882a593Smuzhiyun /* Initiator Bus ID */ 1007*4882a593Smuzhiyun uint8_t our_id; 1008*4882a593Smuzhiyun uint8_t our_id_b; 1009*4882a593Smuzhiyun 1010*4882a593Smuzhiyun /* 1011*4882a593Smuzhiyun * PCI error detection. 1012*4882a593Smuzhiyun */ 1013*4882a593Smuzhiyun int unsolicited_ints; 1014*4882a593Smuzhiyun 1015*4882a593Smuzhiyun /* 1016*4882a593Smuzhiyun * Target incoming command FIFO. 1017*4882a593Smuzhiyun */ 1018*4882a593Smuzhiyun struct target_cmd *targetcmds; 1019*4882a593Smuzhiyun uint8_t tqinfifonext; 1020*4882a593Smuzhiyun 1021*4882a593Smuzhiyun /* 1022*4882a593Smuzhiyun * Cached copy of the sequencer control register. 1023*4882a593Smuzhiyun */ 1024*4882a593Smuzhiyun uint8_t seqctl; 1025*4882a593Smuzhiyun 1026*4882a593Smuzhiyun /* 1027*4882a593Smuzhiyun * Incoming and outgoing message handling. 1028*4882a593Smuzhiyun */ 1029*4882a593Smuzhiyun uint8_t send_msg_perror; 1030*4882a593Smuzhiyun ahc_msg_type msg_type; 1031*4882a593Smuzhiyun uint8_t msgout_buf[12];/* Message we are sending */ 1032*4882a593Smuzhiyun uint8_t msgin_buf[12];/* Message we are receiving */ 1033*4882a593Smuzhiyun u_int msgout_len; /* Length of message to send */ 1034*4882a593Smuzhiyun u_int msgout_index; /* Current index in msgout */ 1035*4882a593Smuzhiyun u_int msgin_index; /* Current index in msgin */ 1036*4882a593Smuzhiyun 1037*4882a593Smuzhiyun /* 1038*4882a593Smuzhiyun * Mapping information for data structures shared 1039*4882a593Smuzhiyun * between the sequencer and kernel. 1040*4882a593Smuzhiyun */ 1041*4882a593Smuzhiyun bus_dma_tag_t parent_dmat; 1042*4882a593Smuzhiyun bus_dma_tag_t shared_data_dmat; 1043*4882a593Smuzhiyun bus_dmamap_t shared_data_dmamap; 1044*4882a593Smuzhiyun dma_addr_t shared_data_busaddr; 1045*4882a593Smuzhiyun 1046*4882a593Smuzhiyun /* 1047*4882a593Smuzhiyun * Bus address of the one byte buffer used to 1048*4882a593Smuzhiyun * work-around a DMA bug for chips <= aic7880 1049*4882a593Smuzhiyun * in target mode. 1050*4882a593Smuzhiyun */ 1051*4882a593Smuzhiyun dma_addr_t dma_bug_buf; 1052*4882a593Smuzhiyun 1053*4882a593Smuzhiyun /* Number of enabled target mode device on this card */ 1054*4882a593Smuzhiyun u_int enabled_luns; 1055*4882a593Smuzhiyun 1056*4882a593Smuzhiyun /* Initialization level of this data structure */ 1057*4882a593Smuzhiyun u_int init_level; 1058*4882a593Smuzhiyun 1059*4882a593Smuzhiyun /* PCI cacheline size. */ 1060*4882a593Smuzhiyun u_int pci_cachesize; 1061*4882a593Smuzhiyun 1062*4882a593Smuzhiyun /* 1063*4882a593Smuzhiyun * Count of parity errors we have seen as a target. 1064*4882a593Smuzhiyun * We auto-disable parity error checking after seeing 1065*4882a593Smuzhiyun * AHC_PCI_TARGET_PERR_THRESH number of errors. 1066*4882a593Smuzhiyun */ 1067*4882a593Smuzhiyun u_int pci_target_perr_count; 1068*4882a593Smuzhiyun #define AHC_PCI_TARGET_PERR_THRESH 10 1069*4882a593Smuzhiyun 1070*4882a593Smuzhiyun /* Maximum number of sequencer instructions supported. */ 1071*4882a593Smuzhiyun u_int instruction_ram_size; 1072*4882a593Smuzhiyun 1073*4882a593Smuzhiyun /* Per-Unit descriptive information */ 1074*4882a593Smuzhiyun const char *description; 1075*4882a593Smuzhiyun char *name; 1076*4882a593Smuzhiyun int unit; 1077*4882a593Smuzhiyun 1078*4882a593Smuzhiyun /* Selection Timer settings */ 1079*4882a593Smuzhiyun int seltime; 1080*4882a593Smuzhiyun int seltime_b; 1081*4882a593Smuzhiyun 1082*4882a593Smuzhiyun uint16_t user_discenable;/* Disconnection allowed */ 1083*4882a593Smuzhiyun uint16_t user_tagenable;/* Tagged Queuing allowed */ 1084*4882a593Smuzhiyun }; 1085*4882a593Smuzhiyun 1086*4882a593Smuzhiyun /************************ Active Device Information ***************************/ 1087*4882a593Smuzhiyun typedef enum { 1088*4882a593Smuzhiyun ROLE_UNKNOWN, 1089*4882a593Smuzhiyun ROLE_INITIATOR, 1090*4882a593Smuzhiyun ROLE_TARGET 1091*4882a593Smuzhiyun } role_t; 1092*4882a593Smuzhiyun 1093*4882a593Smuzhiyun struct ahc_devinfo { 1094*4882a593Smuzhiyun int our_scsiid; 1095*4882a593Smuzhiyun int target_offset; 1096*4882a593Smuzhiyun uint16_t target_mask; 1097*4882a593Smuzhiyun u_int target; 1098*4882a593Smuzhiyun u_int lun; 1099*4882a593Smuzhiyun char channel; 1100*4882a593Smuzhiyun role_t role; /* 1101*4882a593Smuzhiyun * Only guaranteed to be correct if not 1102*4882a593Smuzhiyun * in the busfree state. 1103*4882a593Smuzhiyun */ 1104*4882a593Smuzhiyun }; 1105*4882a593Smuzhiyun 1106*4882a593Smuzhiyun /****************************** PCI Structures ********************************/ 1107*4882a593Smuzhiyun typedef int (ahc_device_setup_t)(struct ahc_softc *); 1108*4882a593Smuzhiyun 1109*4882a593Smuzhiyun struct ahc_pci_identity { 1110*4882a593Smuzhiyun uint64_t full_id; 1111*4882a593Smuzhiyun uint64_t id_mask; 1112*4882a593Smuzhiyun const char *name; 1113*4882a593Smuzhiyun ahc_device_setup_t *setup; 1114*4882a593Smuzhiyun }; 1115*4882a593Smuzhiyun 1116*4882a593Smuzhiyun /***************************** VL/EISA Declarations ***************************/ 1117*4882a593Smuzhiyun struct aic7770_identity { 1118*4882a593Smuzhiyun uint32_t full_id; 1119*4882a593Smuzhiyun uint32_t id_mask; 1120*4882a593Smuzhiyun const char *name; 1121*4882a593Smuzhiyun ahc_device_setup_t *setup; 1122*4882a593Smuzhiyun }; 1123*4882a593Smuzhiyun extern struct aic7770_identity aic7770_ident_table[]; 1124*4882a593Smuzhiyun extern const int ahc_num_aic7770_devs; 1125*4882a593Smuzhiyun 1126*4882a593Smuzhiyun #define AHC_EISA_SLOT_OFFSET 0xc00 1127*4882a593Smuzhiyun #define AHC_EISA_IOSIZE 0x100 1128*4882a593Smuzhiyun 1129*4882a593Smuzhiyun /*************************** Function Declarations ****************************/ 1130*4882a593Smuzhiyun /******************************************************************************/ 1131*4882a593Smuzhiyun 1132*4882a593Smuzhiyun /***************************** PCI Front End *********************************/ 1133*4882a593Smuzhiyun const struct ahc_pci_identity *ahc_find_pci_device(ahc_dev_softc_t); 1134*4882a593Smuzhiyun int ahc_pci_config(struct ahc_softc *, 1135*4882a593Smuzhiyun const struct ahc_pci_identity *); 1136*4882a593Smuzhiyun int ahc_pci_test_register_access(struct ahc_softc *); 1137*4882a593Smuzhiyun #ifdef CONFIG_PM 1138*4882a593Smuzhiyun void ahc_pci_resume(struct ahc_softc *ahc); 1139*4882a593Smuzhiyun #endif 1140*4882a593Smuzhiyun 1141*4882a593Smuzhiyun /*************************** EISA/VL Front End ********************************/ 1142*4882a593Smuzhiyun struct aic7770_identity *aic7770_find_device(uint32_t); 1143*4882a593Smuzhiyun int aic7770_config(struct ahc_softc *ahc, 1144*4882a593Smuzhiyun struct aic7770_identity *, 1145*4882a593Smuzhiyun u_int port); 1146*4882a593Smuzhiyun 1147*4882a593Smuzhiyun /************************** SCB and SCB queue management **********************/ 1148*4882a593Smuzhiyun int ahc_probe_scbs(struct ahc_softc *); 1149*4882a593Smuzhiyun void ahc_qinfifo_requeue_tail(struct ahc_softc *ahc, 1150*4882a593Smuzhiyun struct scb *scb); 1151*4882a593Smuzhiyun int ahc_match_scb(struct ahc_softc *ahc, struct scb *scb, 1152*4882a593Smuzhiyun int target, char channel, int lun, 1153*4882a593Smuzhiyun u_int tag, role_t role); 1154*4882a593Smuzhiyun 1155*4882a593Smuzhiyun /****************************** Initialization ********************************/ 1156*4882a593Smuzhiyun struct ahc_softc *ahc_alloc(void *platform_arg, char *name); 1157*4882a593Smuzhiyun int ahc_softc_init(struct ahc_softc *); 1158*4882a593Smuzhiyun void ahc_controller_info(struct ahc_softc *ahc, char *buf); 1159*4882a593Smuzhiyun int ahc_chip_init(struct ahc_softc *ahc); 1160*4882a593Smuzhiyun int ahc_init(struct ahc_softc *ahc); 1161*4882a593Smuzhiyun void ahc_intr_enable(struct ahc_softc *ahc, int enable); 1162*4882a593Smuzhiyun void ahc_pause_and_flushwork(struct ahc_softc *ahc); 1163*4882a593Smuzhiyun #ifdef CONFIG_PM 1164*4882a593Smuzhiyun int ahc_suspend(struct ahc_softc *ahc); 1165*4882a593Smuzhiyun int ahc_resume(struct ahc_softc *ahc); 1166*4882a593Smuzhiyun #endif 1167*4882a593Smuzhiyun void ahc_set_unit(struct ahc_softc *, int); 1168*4882a593Smuzhiyun void ahc_set_name(struct ahc_softc *, char *); 1169*4882a593Smuzhiyun void ahc_free(struct ahc_softc *ahc); 1170*4882a593Smuzhiyun int ahc_reset(struct ahc_softc *ahc, int reinit); 1171*4882a593Smuzhiyun 1172*4882a593Smuzhiyun /***************************** Error Recovery *********************************/ 1173*4882a593Smuzhiyun typedef enum { 1174*4882a593Smuzhiyun SEARCH_COMPLETE, 1175*4882a593Smuzhiyun SEARCH_COUNT, 1176*4882a593Smuzhiyun SEARCH_REMOVE 1177*4882a593Smuzhiyun } ahc_search_action; 1178*4882a593Smuzhiyun int ahc_search_qinfifo(struct ahc_softc *ahc, int target, 1179*4882a593Smuzhiyun char channel, int lun, u_int tag, 1180*4882a593Smuzhiyun role_t role, uint32_t status, 1181*4882a593Smuzhiyun ahc_search_action action); 1182*4882a593Smuzhiyun int ahc_search_untagged_queues(struct ahc_softc *ahc, 1183*4882a593Smuzhiyun ahc_io_ctx_t ctx, 1184*4882a593Smuzhiyun int target, char channel, 1185*4882a593Smuzhiyun int lun, uint32_t status, 1186*4882a593Smuzhiyun ahc_search_action action); 1187*4882a593Smuzhiyun int ahc_search_disc_list(struct ahc_softc *ahc, int target, 1188*4882a593Smuzhiyun char channel, int lun, u_int tag, 1189*4882a593Smuzhiyun int stop_on_first, int remove, 1190*4882a593Smuzhiyun int save_state); 1191*4882a593Smuzhiyun int ahc_reset_channel(struct ahc_softc *ahc, char channel, 1192*4882a593Smuzhiyun int initiate_reset); 1193*4882a593Smuzhiyun 1194*4882a593Smuzhiyun /*************************** Utility Functions ********************************/ 1195*4882a593Smuzhiyun void ahc_compile_devinfo(struct ahc_devinfo *devinfo, 1196*4882a593Smuzhiyun u_int our_id, u_int target, 1197*4882a593Smuzhiyun u_int lun, char channel, 1198*4882a593Smuzhiyun role_t role); 1199*4882a593Smuzhiyun /************************** Transfer Negotiation ******************************/ 1200*4882a593Smuzhiyun const struct ahc_syncrate* ahc_find_syncrate(struct ahc_softc *ahc, u_int *period, 1201*4882a593Smuzhiyun u_int *ppr_options, u_int maxsync); 1202*4882a593Smuzhiyun u_int ahc_find_period(struct ahc_softc *ahc, 1203*4882a593Smuzhiyun u_int scsirate, u_int maxsync); 1204*4882a593Smuzhiyun /* 1205*4882a593Smuzhiyun * Negotiation types. These are used to qualify if we should renegotiate 1206*4882a593Smuzhiyun * even if our goal and current transport parameters are identical. 1207*4882a593Smuzhiyun */ 1208*4882a593Smuzhiyun typedef enum { 1209*4882a593Smuzhiyun AHC_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */ 1210*4882a593Smuzhiyun AHC_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */ 1211*4882a593Smuzhiyun AHC_NEG_ALWAYS /* Renegotiat even if goal is async. */ 1212*4882a593Smuzhiyun } ahc_neg_type; 1213*4882a593Smuzhiyun int ahc_update_neg_request(struct ahc_softc*, 1214*4882a593Smuzhiyun struct ahc_devinfo*, 1215*4882a593Smuzhiyun struct ahc_tmode_tstate*, 1216*4882a593Smuzhiyun struct ahc_initiator_tinfo*, 1217*4882a593Smuzhiyun ahc_neg_type); 1218*4882a593Smuzhiyun void ahc_set_width(struct ahc_softc *ahc, 1219*4882a593Smuzhiyun struct ahc_devinfo *devinfo, 1220*4882a593Smuzhiyun u_int width, u_int type, int paused); 1221*4882a593Smuzhiyun void ahc_set_syncrate(struct ahc_softc *ahc, 1222*4882a593Smuzhiyun struct ahc_devinfo *devinfo, 1223*4882a593Smuzhiyun const struct ahc_syncrate *syncrate, 1224*4882a593Smuzhiyun u_int period, u_int offset, 1225*4882a593Smuzhiyun u_int ppr_options, 1226*4882a593Smuzhiyun u_int type, int paused); 1227*4882a593Smuzhiyun typedef enum { 1228*4882a593Smuzhiyun AHC_QUEUE_NONE, 1229*4882a593Smuzhiyun AHC_QUEUE_BASIC, 1230*4882a593Smuzhiyun AHC_QUEUE_TAGGED 1231*4882a593Smuzhiyun } ahc_queue_alg; 1232*4882a593Smuzhiyun 1233*4882a593Smuzhiyun /**************************** Target Mode *************************************/ 1234*4882a593Smuzhiyun #ifdef AHC_TARGET_MODE 1235*4882a593Smuzhiyun void ahc_send_lstate_events(struct ahc_softc *, 1236*4882a593Smuzhiyun struct ahc_tmode_lstate *); 1237*4882a593Smuzhiyun void ahc_handle_en_lun(struct ahc_softc *ahc, 1238*4882a593Smuzhiyun struct cam_sim *sim, union ccb *ccb); 1239*4882a593Smuzhiyun cam_status ahc_find_tmode_devs(struct ahc_softc *ahc, 1240*4882a593Smuzhiyun struct cam_sim *sim, union ccb *ccb, 1241*4882a593Smuzhiyun struct ahc_tmode_tstate **tstate, 1242*4882a593Smuzhiyun struct ahc_tmode_lstate **lstate, 1243*4882a593Smuzhiyun int notfound_failure); 1244*4882a593Smuzhiyun #ifndef AHC_TMODE_ENABLE 1245*4882a593Smuzhiyun #define AHC_TMODE_ENABLE 0 1246*4882a593Smuzhiyun #endif 1247*4882a593Smuzhiyun #endif 1248*4882a593Smuzhiyun /******************************* Debug ***************************************/ 1249*4882a593Smuzhiyun #ifdef AHC_DEBUG 1250*4882a593Smuzhiyun extern uint32_t ahc_debug; 1251*4882a593Smuzhiyun #define AHC_SHOW_MISC 0x0001 1252*4882a593Smuzhiyun #define AHC_SHOW_SENSE 0x0002 1253*4882a593Smuzhiyun #define AHC_DUMP_SEEPROM 0x0004 1254*4882a593Smuzhiyun #define AHC_SHOW_TERMCTL 0x0008 1255*4882a593Smuzhiyun #define AHC_SHOW_MEMORY 0x0010 1256*4882a593Smuzhiyun #define AHC_SHOW_MESSAGES 0x0020 1257*4882a593Smuzhiyun #define AHC_SHOW_DV 0x0040 1258*4882a593Smuzhiyun #define AHC_SHOW_SELTO 0x0080 1259*4882a593Smuzhiyun #define AHC_SHOW_QFULL 0x0200 1260*4882a593Smuzhiyun #define AHC_SHOW_QUEUE 0x0400 1261*4882a593Smuzhiyun #define AHC_SHOW_TQIN 0x0800 1262*4882a593Smuzhiyun #define AHC_SHOW_MASKED_ERRORS 0x1000 1263*4882a593Smuzhiyun #define AHC_DEBUG_SEQUENCER 0x2000 1264*4882a593Smuzhiyun #endif 1265*4882a593Smuzhiyun void ahc_print_devinfo(struct ahc_softc *ahc, 1266*4882a593Smuzhiyun struct ahc_devinfo *dev); 1267*4882a593Smuzhiyun void ahc_dump_card_state(struct ahc_softc *ahc); 1268*4882a593Smuzhiyun int ahc_print_register(const ahc_reg_parse_entry_t *table, 1269*4882a593Smuzhiyun u_int num_entries, 1270*4882a593Smuzhiyun const char *name, 1271*4882a593Smuzhiyun u_int address, 1272*4882a593Smuzhiyun u_int value, 1273*4882a593Smuzhiyun u_int *cur_column, 1274*4882a593Smuzhiyun u_int wrap_point); 1275*4882a593Smuzhiyun /******************************* SEEPROM *************************************/ 1276*4882a593Smuzhiyun int ahc_acquire_seeprom(struct ahc_softc *ahc, 1277*4882a593Smuzhiyun struct seeprom_descriptor *sd); 1278*4882a593Smuzhiyun void ahc_release_seeprom(struct seeprom_descriptor *sd); 1279*4882a593Smuzhiyun #endif /* _AIC7XXX_H_ */ 1280