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