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