/*-1* Core definitions and data structures shareable across OS platforms.2*3* SPDX-License-Identifier: BSD-3-Clause4*5* Copyright (c) 1994-2002 Justin T. Gibbs.6* Copyright (c) 2000-2002 Adaptec Inc.7* All rights reserved.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions, and the following disclaimer,14* without modification.15* 2. Redistributions in binary form must reproduce at minimum a disclaimer16* substantially similar to the "NO WARRANTY" disclaimer below17* ("Disclaimer") and any redistribution must be conditioned upon18* including a substantially similar Disclaimer requirement for further19* binary redistribution.20* 3. Neither the names of the above-listed copyright holders nor the names21* of any contributors may be used to endorse or promote products derived22* from this software without specific prior written permission.23*24* Alternatively, this software may be distributed under the terms of the25* GNU General Public License ("GPL") version 2 as published by the Free26* Software Foundation.27*28* NO WARRANTY29* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS30* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT31* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR32* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT33* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL34* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS35* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)36* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,37* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING38* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE39* POSSIBILITY OF SUCH DAMAGES.40*41* $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#107 $42*/4344#ifndef _AIC79XX_H_45#define _AIC79XX_H_4647/* Register Definitions */48#include "aic79xx_reg.h"4950/************************* Forward Declarations *******************************/51struct ahd_platform_data;52struct scb_platform_data;5354/****************************** Useful Macros *********************************/55#ifndef MAX56#define MAX(a,b) (((a) > (b)) ? (a) : (b))57#endif5859#ifndef MIN60#define MIN(a,b) (((a) < (b)) ? (a) : (b))61#endif6263#ifndef TRUE64#define TRUE 165#endif66#ifndef FALSE67#define FALSE 068#endif6970#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))7172#define ALL_CHANNELS '\0'73#define ALL_TARGETS_MASK 0xFFFF74#define INITIATOR_WILDCARD (~0)75#define SCB_LIST_NULL 0xFF0076#define SCB_LIST_NULL_LE (aic_htole16(SCB_LIST_NULL))77#define QOUTFIFO_ENTRY_VALID 0x8078#define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)7980#define SCSIID_TARGET(ahd, scsiid) \81(((scsiid) & TID) >> TID_SHIFT)82#define SCSIID_OUR_ID(scsiid) \83((scsiid) & OID)84#define SCSIID_CHANNEL(ahd, scsiid) ('A')85#define SCB_IS_SCSIBUS_B(ahd, scb) (0)86#define SCB_GET_OUR_ID(scb) \87SCSIID_OUR_ID((scb)->hscb->scsiid)88#define SCB_GET_TARGET(ahd, scb) \89SCSIID_TARGET((ahd), (scb)->hscb->scsiid)90#define SCB_GET_CHANNEL(ahd, scb) \91SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)92#define SCB_GET_LUN(scb) \93((scb)->hscb->lun)94#define SCB_GET_TARGET_OFFSET(ahd, scb) \95SCB_GET_TARGET(ahd, scb)96#define SCB_GET_TARGET_MASK(ahd, scb) \97(0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))98#ifdef AHD_DEBUG99#define SCB_IS_SILENT(scb) \100((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0 \101&& (((scb)->flags & SCB_SILENT) != 0))102#else103#define SCB_IS_SILENT(scb) \104(((scb)->flags & SCB_SILENT) != 0)105#endif106/*107* TCLs have the following format: TTTTLLLLLLLL108*/109#define TCL_TARGET_OFFSET(tcl) \110((((tcl) >> 4) & TID) >> 4)111#define TCL_LUN(tcl) \112(tcl & (AHD_NUM_LUNS - 1))113#define BUILD_TCL(scsiid, lun) \114((lun) | (((scsiid) & TID) << 4))115#define BUILD_TCL_RAW(target, channel, lun) \116((lun) | ((target) << 8))117118#define SCB_GET_TAG(scb) \119aic_le16toh(scb->hscb->tag)120121#ifndef AHD_TARGET_MODE122#undef AHD_TMODE_ENABLE123#define AHD_TMODE_ENABLE 0124#endif125126#define AHD_BUILD_COL_IDX(target, lun) \127(((lun) << 4) | target)128129#define AHD_GET_SCB_COL_IDX(ahd, scb) \130((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))131132#define AHD_SET_SCB_COL_IDX(scb, col_idx) \133do { \134(scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID; \135(scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1); \136} while (0)137138#define AHD_COPY_SCB_COL_IDX(dst, src) \139do { \140dst->hscb->scsiid = src->hscb->scsiid; \141dst->hscb->lun = src->hscb->lun; \142} while (0)143144#define AHD_NEVER_COL_IDX 0xFFFF145146/**************************** Driver Constants ********************************/147/*148* The maximum number of supported targets.149*/150#define AHD_NUM_TARGETS 16151152/*153* The maximum number of supported luns.154* The identify message only supports 64 luns in non-packetized transfers.155* You can have 2^64 luns when information unit transfers are enabled,156* but until we see a need to support that many, we support 256.157*/158#define AHD_NUM_LUNS_NONPKT 64159#define AHD_NUM_LUNS 256160161/*162* The maximum transfer per S/G segment.163*/164#define AHD_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */165166/*167* The maximum amount of SCB storage in hardware on a controller.168* This value represents an upper bound. Due to software design,169* we may not be able to use this number.170*/171#define AHD_SCB_MAX 512172173/*174* The maximum number of concurrent transactions supported per driver instance.175* Sequencer Control Blocks (SCBs) store per-transaction information.176*/177#define AHD_MAX_QUEUE AHD_SCB_MAX178179/*180* Define the size of our QIN and QOUT FIFOs. They must be a power of 2181* in size and accommodate as many transactions as can be queued concurrently.182*/183#define AHD_QIN_SIZE AHD_MAX_QUEUE184#define AHD_QOUT_SIZE AHD_MAX_QUEUE185186#define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))187/*188* The maximum amount of SCB storage we allocate in host memory.189*/190#define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE191192/*193* Ring Buffer of incoming target commands.194* We allocate 256 to simplify the logic in the sequencer195* by using the natural wrap point of an 8bit counter.196*/197#define AHD_TMODE_CMDS 256198199/* Reset line assertion time in us */200#define AHD_BUSRESET_DELAY 25201202/******************* Chip Characteristics/Operating Settings *****************/203extern uint32_t ahd_attach_to_HostRAID_controllers;204205/*206* Chip Type207* The chip order is from least sophisticated to most sophisticated.208*/209typedef enum {210AHD_NONE = 0x0000,211AHD_CHIPID_MASK = 0x00FF,212AHD_AIC7901 = 0x0001,213AHD_AIC7902 = 0x0002,214AHD_AIC7901A = 0x0003,215AHD_PCI = 0x0100, /* Bus type PCI */216AHD_PCIX = 0x0200, /* Bus type PCIX */217AHD_BUS_MASK = 0x0F00218} ahd_chip;219220/*221* Features available in each chip type.222*/223typedef enum {224AHD_FENONE = 0x00000,225AHD_WIDE = 0x00001,/* Wide Channel */226AHD_MULTI_FUNC = 0x00100,/* Multi-Function/Channel Device */227AHD_TARGETMODE = 0x01000,/* Has tested target mode support */228AHD_MULTIROLE = 0x02000,/* Space for two roles at a time */229AHD_RTI = 0x04000,/* Retained Training Support */230AHD_NEW_IOCELL_OPTS = 0x08000,/* More Signal knobs in the IOCELL */231AHD_NEW_DFCNTRL_OPTS = 0x10000,/* SCSIENWRDIS bit */232AHD_FAST_CDB_DELIVERY = 0x20000,/* CDB acks released to Output Sync */233AHD_REMOVABLE = 0x00000,/* Hot-Swap supported - None so far*/234AHD_AIC7901_FE = AHD_FENONE,235AHD_AIC7901A_FE = AHD_FENONE,236AHD_AIC7902_FE = AHD_MULTI_FUNC237} ahd_feature;238239/*240* Bugs in the silicon that we work around in software.241*/242typedef enum {243AHD_BUGNONE = 0x0000,244/*245* Rev A hardware fails to update LAST/CURR/NEXTSCB246* correctly in certain packetized selection cases.247*/248AHD_SENT_SCB_UPDATE_BUG = 0x0001,249/* The wrong SCB is accessed to check the abort pending bit. */250AHD_ABORT_LQI_BUG = 0x0002,251/* Packetized bitbucket crosses packet boundaries. */252AHD_PKT_BITBUCKET_BUG = 0x0004,253/* The selection timer runs twice as long as its setting. */254AHD_LONG_SETIMO_BUG = 0x0008,255/* The Non-LQ CRC error status is delayed until phase change. */256AHD_NLQICRC_DELAYED_BUG = 0x0010,257/* The chip must be reset for all outgoing bus resets. */258AHD_SCSIRST_BUG = 0x0020,259/* Some PCIX fields must be saved and restored across chip reset. */260AHD_PCIX_CHIPRST_BUG = 0x0040,261/* MMAPIO is not functional in PCI-X mode. */262AHD_PCIX_MMAPIO_BUG = 0x0080,263/* Reads to SCBRAM fail to reset the discard timer. */264AHD_PCIX_SCBRAM_RD_BUG = 0x0100,265/* Bug workarounds that can be disabled on non-PCIX busses. */266AHD_PCIX_BUG_MASK = AHD_PCIX_CHIPRST_BUG267| AHD_PCIX_MMAPIO_BUG268| AHD_PCIX_SCBRAM_RD_BUG,269/*270* LQOSTOP0 status set even for forced selections with ATN271* to perform non-packetized message delivery.272*/273AHD_LQO_ATNO_BUG = 0x0200,274/* FIFO auto-flush does not always trigger. */275AHD_AUTOFLUSH_BUG = 0x0400,276/* The CLRLQO registers are not self-clearing. */277AHD_CLRLQO_AUTOCLR_BUG = 0x0800,278/* The PACKETIZED status bit refers to the previous connection. */279AHD_PKTIZED_STATUS_BUG = 0x1000,280/* "Short Luns" are not placed into outgoing LQ packets correctly. */281AHD_PKT_LUN_BUG = 0x2000,282/*283* Only the FIFO allocated to the non-packetized connection may284* be in use during a non-packetzied connection.285*/286AHD_NONPACKFIFO_BUG = 0x4000,287/*288* Writing to a DFF SCBPTR register may fail if concurrent with289* a hardware write to the other DFF SCBPTR register. This is290* not currently a concern in our sequencer since all chips with291* this bug have the AHD_NONPACKFIFO_BUG and all writes of concern292* occur in non-packetized connections.293*/294AHD_MDFF_WSCBPTR_BUG = 0x8000,295/* SGHADDR updates are slow. */296AHD_REG_SLOW_SETTLE_BUG = 0x10000,297/*298* Changing the MODE_PTR coincident with an interrupt that299* switches to a different mode will cause the interrupt to300* be in the mode written outside of interrupt context.301*/302AHD_SET_MODE_BUG = 0x20000,303/* Non-packetized busfree revision does not work. */304AHD_BUSFREEREV_BUG = 0x40000,305/*306* Paced transfers are indicated with a non-standard PPR307* option bit in the neg table, 160MHz is indicated by308* sync factor 0x7, and the offset if off by a factor of 2.309*/310AHD_PACED_NEGTABLE_BUG = 0x80000,311/* LQOOVERRUN false positives. */312AHD_LQOOVERRUN_BUG = 0x100000,313/*314* Controller write to INTSTAT will lose to a host315* write to CLRINT.316*/317AHD_INTCOLLISION_BUG = 0x200000,318/*319* The GEM318 violates the SCSI spec by not waiting320* the mandated bus settle delay between phase changes321* in some situations. Some aic79xx chip revs. are more322* strict in this regard and will treat REQ assertions323* that fall within the bus settle delay window as324* glitches. This flag tells the firmware to tolerate325* early REQ assertions.326*/327AHD_EARLY_REQ_BUG = 0x400000,328/*329* The LED does not stay on long enough in packetized modes.330*/331AHD_FAINT_LED_BUG = 0x800000332} ahd_bug;333334/*335* Configuration specific settings.336* The driver determines these settings by probing the337* chip/controller's configuration.338*/339typedef enum {340AHD_FNONE = 0x00000,341AHD_BOOT_CHANNEL = 0x00001,/* We were set as the boot channel. */342AHD_USEDEFAULTS = 0x00004,/*343* For cards without an seeprom344* or a BIOS to initialize the chip's345* SRAM, we use the default target346* settings.347*/348AHD_SEQUENCER_DEBUG = 0x00008,349AHD_RESET_BUS_A = 0x00010,350AHD_EXTENDED_TRANS_A = 0x00020,351AHD_TERM_ENB_A = 0x00040,352AHD_SPCHK_ENB_A = 0x00080,353AHD_STPWLEVEL_A = 0x00100,354AHD_INITIATORROLE = 0x00200,/*355* Allow initiator operations on356* this controller.357*/358AHD_TARGETROLE = 0x00400,/*359* Allow target operations on this360* controller.361*/362AHD_RESOURCE_SHORTAGE = 0x00800,363AHD_TQINFIFO_BLOCKED = 0x01000,/* Blocked waiting for ATIOs */364AHD_INT50_SPEEDFLEX = 0x02000,/*365* Internal 50pin connector366* sits behind an aic3860367*/368AHD_BIOS_ENABLED = 0x04000,369AHD_ALL_INTERRUPTS = 0x08000,370AHD_39BIT_ADDRESSING = 0x10000,/* Use 39 bit addressing scheme. */371AHD_64BIT_ADDRESSING = 0x20000,/* Use 64 bit addressing scheme. */372AHD_CURRENT_SENSING = 0x40000,373AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */374AHD_HP_BOARD = 0x100000,375AHD_RESET_POLL_ACTIVE = 0x200000,376AHD_UPDATE_PEND_CMDS = 0x400000,377AHD_RUNNING_QOUTFIFO = 0x800000,378AHD_HAD_FIRST_SEL = 0x1000000,379AHD_SHUTDOWN_RECOVERY = 0x2000000, /* Terminate recovery thread. */380AHD_HOSTRAID_BOARD = 0x4000000381} ahd_flag;382383/************************* Hardware SCB Definition ***************************/384385/*386* The driver keeps up to MAX_SCB scb structures per card in memory. The SCB387* consists of a "hardware SCB" mirroring the fields available on the card388* and additional information the kernel stores for each transaction.389*390* To minimize space utilization, a portion of the hardware scb stores391* different data during different portions of a SCSI transaction.392* As initialized by the host driver for the initiator role, this area393* contains the SCSI cdb (or a pointer to the cdb) to be executed. After394* the cdb has been presented to the target, this area serves to store395* residual transfer information and the SCSI status byte.396* For the target role, the contents of this area do not change, but397* still serve a different purpose than for the initiator role. See398* struct target_data for details.399*/400401/*402* Status information embedded in the shared poriton of403* an SCB after passing the cdb to the target. The kernel404* driver will only read this data for transactions that405* complete abnormally.406*/407struct initiator_status {408uint32_t residual_datacnt; /* Residual in the current S/G seg */409uint32_t residual_sgptr; /* The next S/G for this transfer */410uint8_t scsi_status; /* Standard SCSI status byte */411};412413struct target_status {414uint32_t residual_datacnt; /* Residual in the current S/G seg */415uint32_t residual_sgptr; /* The next S/G for this transfer */416uint8_t scsi_status; /* SCSI status to give to initiator */417uint8_t target_phases; /* Bitmap of phases to execute */418uint8_t data_phase; /* Data-In or Data-Out */419uint8_t initiator_tag; /* Initiator's transaction tag */420};421422/*423* Initiator mode SCB shared data area.424* If the embedded CDB is 12 bytes or less, we embed425* the sense buffer address in the SCB. This allows426* us to retrieve sense information without interrupting427* the host in packetized mode.428*/429typedef uint32_t sense_addr_t;430#define MAX_CDB_LEN 16431#define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))432union initiator_data {433struct {434uint64_t cdbptr;435uint8_t cdblen;436} cdb_from_host;437uint8_t cdb[MAX_CDB_LEN];438struct {439uint8_t cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];440sense_addr_t sense_addr;441} cdb_plus_saddr;442};443444/*445* Target mode version of the shared data SCB segment.446*/447struct target_data {448uint32_t spare[2];449uint8_t scsi_status; /* SCSI status to give to initiator */450uint8_t target_phases; /* Bitmap of phases to execute */451uint8_t data_phase; /* Data-In or Data-Out */452uint8_t initiator_tag; /* Initiator's transaction tag */453};454455struct hardware_scb {456/*0*/ union {457union initiator_data idata;458struct target_data tdata;459struct initiator_status istatus;460struct target_status tstatus;461} shared_data;462/*463* A word about residuals.464* The scb is presented to the sequencer with the dataptr and datacnt465* fields initialized to the contents of the first S/G element to466* transfer. The sgptr field is initialized to the bus address for467* the S/G element that follows the first in the in core S/G array468* or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid469* S/G entry for this transfer (single S/G element transfer with the470* first elements address and length preloaded in the dataptr/datacnt471* fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.472* The SG_FULL_RESID flag ensures that the residual will be correctly473* noted even if no data transfers occur. Once the data phase is entered,474* the residual sgptr and datacnt are loaded from the sgptr and the475* datacnt fields. After each S/G element's dataptr and length are476* loaded into the hardware, the residual sgptr is advanced. After477* each S/G element is expired, its datacnt field is checked to see478* if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the479* residual sg ptr and the transfer is considered complete. If the480* sequencer determines that there is a residual in the transfer, or481* there is non-zero status, it will set the SG_STATUS_VALID flag in482* sgptr and dma the scb back into host memory. To sumarize:483*484* Sequencer:485* o A residual has occurred if SG_FULL_RESID is set in sgptr,486* or residual_sgptr does not have SG_LIST_NULL set.487*488* o We are transferring the last segment if residual_datacnt has489* the SG_LAST_SEG flag set.490*491* Host:492* o A residual can only have occurred if a completed scb has the493* SG_STATUS_VALID flag set. Inspection of the SCSI status field,494* the residual_datacnt, and the residual_sgptr field will tell495* for sure.496*497* o residual_sgptr and sgptr refer to the "next" sg entry498* and so may point beyond the last valid sg entry for the499* transfer.500*/501#define SG_PTR_MASK 0xFFFFFFF8502/*16*/ uint16_t tag; /* Reused by Sequencer. */503/*18*/ uint8_t control; /* See SCB_CONTROL in aic79xx.reg for details */504/*19*/ uint8_t scsiid; /*505* Selection out Id506* Our Id (bits 0-3) Their ID (bits 4-7)507*/508/*20*/ uint8_t lun;509/*21*/ uint8_t task_attribute;510/*22*/ uint8_t cdb_len;511/*23*/ uint8_t task_management;512/*24*/ uint64_t dataptr;513/*32*/ uint32_t datacnt; /* Byte 3 is spare. */514/*36*/ uint32_t sgptr;515/*40*/ uint32_t hscb_busaddr;516/*44*/ uint32_t next_hscb_busaddr;517/********** Long lun field only downloaded for full 8 byte lun support ********/518/*48*/ uint8_t pkt_long_lun[8];519/******* Fields below are not Downloaded (Sequencer may use for scratch) ******/520/*56*/ uint8_t spare[8];521};522523/************************ Kernel SCB Definitions ******************************/524/*525* Some fields of the SCB are OS dependent. Here we collect the526* definitions for elements that all OS platforms need to include527* in there SCB definition.528*/529530/*531* Definition of a scatter/gather element as transferred to the controller.532* The aic7xxx chips only support a 24bit length. We use the top byte of533* the length to store additional address bits and a flag to indicate534* that a given segment terminates the transfer. This gives us an535* addressable range of 512GB on machines with 64bit PCI or with chips536* that can support dual address cycles on 32bit PCI busses.537*/538struct ahd_dma_seg {539uint32_t addr;540uint32_t len;541#define AHD_DMA_LAST_SEG 0x80000000542#define AHD_SG_HIGH_ADDR_MASK 0x7F000000543#define AHD_SG_LEN_MASK 0x00FFFFFF544};545546struct ahd_dma64_seg {547uint64_t addr;548uint32_t len;549uint32_t pad;550};551552struct map_node {553bus_dmamap_t dmamap;554bus_addr_t busaddr;555uint8_t *vaddr;556SLIST_ENTRY(map_node) links;557};558559/*560* The current state of this SCB.561*/562typedef enum {563SCB_FLAG_NONE = 0x00000,564SCB_TRANSMISSION_ERROR = 0x00001,/*565* We detected a parity or CRC566* error that has effected the567* payload of the command. This568* flag is checked when normal569* status is returned to catch570* the case of a target not571* responding to our attempt572* to report the error.573*/574SCB_OTHERTCL_TIMEOUT = 0x00002,/*575* Another device was active576* during the first timeout for577* this SCB so we gave ourselves578* an additional timeout period579* in case it was hogging the580* bus.581*/582SCB_DEVICE_RESET = 0x00004,583SCB_SENSE = 0x00008,584SCB_CDB32_PTR = 0x00010,585SCB_RECOVERY_SCB = 0x00020,586SCB_AUTO_NEGOTIATE = 0x00040,/* Negotiate to achieve goal. */587SCB_NEGOTIATE = 0x00080,/* Negotiation forced for command. */588SCB_ABORT = 0x00100,589SCB_ACTIVE = 0x00200,590SCB_TARGET_IMMEDIATE = 0x00400,591SCB_PACKETIZED = 0x00800,592SCB_EXPECT_PPR_BUSFREE = 0x01000,593SCB_PKT_SENSE = 0x02000,594SCB_CMDPHASE_ABORT = 0x04000,595SCB_ON_COL_LIST = 0x08000,596SCB_SILENT = 0x10000,/*597* Be quiet about transmission type598* errors. They are expected and we599* don't want to upset the user. This600* flag is typically used during DV.601*/602SCB_TIMEDOUT = 0x20000/*603* SCB has timed out and is on the604* timedout list.605*/606} scb_flag;607608struct scb {609struct hardware_scb *hscb;610union {611SLIST_ENTRY(scb) sle;612LIST_ENTRY(scb) le;613TAILQ_ENTRY(scb) tqe;614} links;615union {616SLIST_ENTRY(scb) sle;617LIST_ENTRY(scb) le;618TAILQ_ENTRY(scb) tqe;619} links2;620#define pending_links links2.le621#define collision_links links2.le622LIST_ENTRY(scb) timedout_links;623struct scb *col_scb;624aic_io_ctx_t io_ctx;625struct ahd_softc *ahd_softc;626scb_flag flags;627bus_dmamap_t dmamap;628struct scb_platform_data *platform_data;629struct map_node *hscb_map;630struct map_node *sg_map;631struct map_node *sense_map;632void *sg_list;633uint8_t *sense_data;634bus_addr_t sg_list_busaddr;635bus_addr_t sense_busaddr;636u_int sg_count;/* How full ahd_dma_seg is */637#define AHD_MAX_LQ_CRC_ERRORS 5638u_int crc_retry_count;639aic_timer_t io_timer;640};641642TAILQ_HEAD(scb_tailq, scb);643LIST_HEAD(scb_list, scb);644645struct scb_data {646/*647* TAILQ of lists of free SCBs grouped by device648* collision domains.649*/650struct scb_tailq free_scbs;651652/*653* Per-device lists of SCBs whose tag ID would collide654* with an already active tag on the device.655*/656struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];657658/*659* SCBs that will not collide with any active device.660*/661struct scb_list any_dev_free_scb_list;662663/*664* Mapping from tag to SCB.665*/666struct scb *scbindex[AHD_SCB_MAX];667668u_int recovery_scbs; /* Transactions currently in recovery */669670/*671* "Bus" addresses of our data structures.672*/673bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */674bus_dma_tag_t sg_dmat; /* dmat for our sg segments */675bus_dma_tag_t sense_dmat; /* dmat for our sense buffers */676677SLIST_HEAD(, map_node) hscb_maps;678SLIST_HEAD(, map_node) sg_maps;679SLIST_HEAD(, map_node) sense_maps;680int scbs_left; /* unallocated scbs in head map_node */681int sgs_left; /* unallocated sgs in head map_node */682int sense_left; /* unallocated sense in head map_node */683uint16_t numscbs;684uint16_t maxhscbs; /* Number of SCBs on the card */685uint8_t init_level; /*686* How far we've initialized687* this structure.688*/689};690691/************************ Target Mode Definitions *****************************/692693/*694* Connection descriptor for select-in requests in target mode.695*/696struct target_cmd {697uint8_t scsiid; /* Our ID and the initiator's ID */698uint8_t identify; /* Identify message */699uint8_t bytes[22]; /*700* Bytes contains any additional message701* bytes terminated by 0xFF. The remainder702* is the cdb to execute.703*/704uint8_t cmd_valid; /*705* When a command is complete, the firmware706* will set cmd_valid to all bits set.707* After the host has seen the command,708* the bits are cleared. This allows us709* to just peek at host memory to determine710* if more work is complete. cmd_valid is on711* an 8 byte boundary to simplify setting712* it on aic7880 hardware which only has713* limited direct access to the DMA FIFO.714*/715uint8_t pad[7];716};717718/*719* Number of events we can buffer up if we run out720* of immediate notify ccbs.721*/722#define AHD_TMODE_EVENT_BUFFER_SIZE 8723struct ahd_tmode_event {724uint8_t initiator_id;725uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */726#define EVENT_TYPE_BUS_RESET 0xFF727uint8_t event_arg;728};729730/*731* Per enabled lun target mode state.732* As this state is directly influenced by the host OS'es target mode733* environment, we let the OS module define it. Forward declare the734* structure here so we can store arrays of them, etc. in OS neutral735* data structures.736*/737#ifdef AHD_TARGET_MODE738struct ahd_tmode_lstate {739struct cam_path *path;740struct ccb_hdr_slist accept_tios;741struct ccb_hdr_slist immed_notifies;742struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];743uint8_t event_r_idx;744uint8_t event_w_idx;745};746#else747struct ahd_tmode_lstate;748#endif749750/******************** Transfer Negotiation Datastructures *********************/751#define AHD_TRANS_CUR 0x01 /* Modify current neogtiation status */752#define AHD_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */753#define AHD_TRANS_GOAL 0x04 /* Modify negotiation goal */754#define AHD_TRANS_USER 0x08 /* Modify user negotiation settings */755#define AHD_PERIOD_10MHz 0x19756757#define AHD_WIDTH_UNKNOWN 0xFF758#define AHD_PERIOD_UNKNOWN 0xFF759#define AHD_OFFSET_UNKNOWN 0xFF760#define AHD_PPR_OPTS_UNKNOWN 0xFF761762/*763* Transfer Negotiation Information.764*/765struct ahd_transinfo {766uint8_t protocol_version; /* SCSI Revision level */767uint8_t transport_version; /* SPI Revision level */768uint8_t width; /* Bus width */769uint8_t period; /* Sync rate factor */770uint8_t offset; /* Sync offset */771uint8_t ppr_options; /* Parallel Protocol Request options */772};773774/*775* Per-initiator current, goal and user transfer negotiation information. */776struct ahd_initiator_tinfo {777struct ahd_transinfo curr;778struct ahd_transinfo goal;779struct ahd_transinfo user;780};781782/*783* Per enabled target ID state.784* Pointers to lun target state as well as sync/wide negotiation information785* for each initiator<->target mapping. For the initiator role we pretend786* that we are the target and the targets are the initiators since the787* negotiation is the same regardless of role.788*/789struct ahd_tmode_tstate {790struct ahd_tmode_lstate* enabled_luns[AHD_NUM_LUNS];791struct ahd_initiator_tinfo transinfo[AHD_NUM_TARGETS];792793/*794* Per initiator state bitmasks.795*/796uint16_t auto_negotiate;/* Auto Negotiation Required */797uint16_t discenable; /* Disconnection allowed */798uint16_t tagenable; /* Tagged Queuing allowed */799};800801/*802* Points of interest along the negotiated transfer scale.803*/804#define AHD_SYNCRATE_160 0x8805#define AHD_SYNCRATE_PACED 0x8806#define AHD_SYNCRATE_DT 0x9807#define AHD_SYNCRATE_ULTRA2 0xa808#define AHD_SYNCRATE_ULTRA 0xc809#define AHD_SYNCRATE_FAST 0x19810#define AHD_SYNCRATE_MIN_DT AHD_SYNCRATE_FAST811#define AHD_SYNCRATE_SYNC 0x32812#define AHD_SYNCRATE_MIN 0x60813#define AHD_SYNCRATE_ASYNC 0xFF814#define AHD_SYNCRATE_MAX AHD_SYNCRATE_160815816/* Safe and valid period for async negotiations. */817#define AHD_ASYNC_XFER_PERIOD 0x44818819/*820* In RevA, the synctable uses a 120MHz rate for the period821* factor 8 and 160MHz for the period factor 7. The 120MHz822* rate never made it into the official SCSI spec, so we must823* compensate when setting the negotiation table for Rev A824* parts.825*/826#define AHD_SYNCRATE_REVA_120 0x8827#define AHD_SYNCRATE_REVA_160 0x7828829/***************************** Lookup Tables **********************************/830/*831* Phase -> name and message out response832* to parity errors in each phase table.833*/834struct ahd_phase_table_entry {835uint8_t phase;836uint8_t mesg_out; /* Message response to parity errors */837char *phasemsg;838};839840/************************** Serial EEPROM Format ******************************/841842struct seeprom_config {843/*844* Per SCSI ID Configuration Flags845*/846uint16_t device_flags[16]; /* words 0-15 */847#define CFXFER 0x003F /* synchronous transfer rate */848#define CFXFER_ASYNC 0x3F849#define CFQAS 0x0040 /* Negotiate QAS */850#define CFPACKETIZED 0x0080 /* Negotiate Packetized Transfers */851#define CFSTART 0x0100 /* send start unit SCSI command */852#define CFINCBIOS 0x0200 /* include in BIOS scan */853#define CFDISC 0x0400 /* enable disconnection */854#define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */855#define CFWIDEB 0x1000 /* wide bus device */856#define CFHOSTMANAGED 0x8000 /* Managed by a RAID controller */857858/*859* BIOS Control Bits860*/861uint16_t bios_control; /* word 16 */862#define CFSUPREM 0x0001 /* support all removeable drives */863#define CFSUPREMB 0x0002 /* support removeable boot drives */864#define CFBIOSSTATE 0x000C /* BIOS Action State */865#define CFBS_DISABLED 0x00866#define CFBS_ENABLED 0x04867#define CFBS_DISABLED_SCAN 0x08868#define CFENABLEDV 0x0010 /* Perform Domain Validation */869#define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */870#define CFSPARITY 0x0040 /* SCSI parity */871#define CFEXTEND 0x0080 /* extended translation enabled */872#define CFBOOTCD 0x0100 /* Support Bootable CD-ROM */873#define CFMSG_LEVEL 0x0600 /* BIOS Message Level */874#define CFMSG_VERBOSE 0x0000875#define CFMSG_SILENT 0x0200876#define CFMSG_DIAG 0x0400877#define CFRESETB 0x0800 /* reset SCSI bus at boot */878/* UNUSED 0xf000 */879880/*881* Host Adapter Control Bits882*/883uint16_t adapter_control; /* word 17 */884#define CFAUTOTERM 0x0001 /* Perform Auto termination */885#define CFSTERM 0x0002 /* SCSI low byte termination */886#define CFWSTERM 0x0004 /* SCSI high byte termination */887#define CFSEAUTOTERM 0x0008 /* Ultra2 Perform secondary Auto Term*/888#define CFSELOWTERM 0x0010 /* Ultra2 secondary low term */889#define CFSEHIGHTERM 0x0020 /* Ultra2 secondary high term */890#define CFSTPWLEVEL 0x0040 /* Termination level control */891#define CFBIOSAUTOTERM 0x0080 /* Perform Auto termination */892#define CFTERM_MENU 0x0100 /* BIOS displays termination menu */893#define CFCLUSTERENB 0x8000 /* Cluster Enable */894895/*896* Bus Release Time, Host Adapter ID897*/898uint16_t brtime_id; /* word 18 */899#define CFSCSIID 0x000f /* host adapter SCSI ID */900/* UNUSED 0x00f0 */901#define CFBRTIME 0xff00 /* bus release time/PCI Latency Time */902903/*904* Maximum targets905*/906uint16_t max_targets; /* word 19 */907#define CFMAXTARG 0x00ff /* maximum targets */908#define CFBOOTLUN 0x0f00 /* Lun to boot from */909#define CFBOOTID 0xf000 /* Target to boot from */910uint16_t res_1[10]; /* words 20-29 */911uint16_t signature; /* BIOS Signature */912#define CFSIGNATURE 0x400913uint16_t checksum; /* word 31 */914};915916/*917* Vital Product Data used during POST and by the BIOS.918*/919struct vpd_config {920uint8_t bios_flags;921#define VPDMASTERBIOS 0x0001922#define VPDBOOTHOST 0x0002923uint8_t reserved_1[21];924uint8_t resource_type;925uint8_t resource_len[2];926uint8_t resource_data[8];927uint8_t vpd_tag;928uint16_t vpd_len;929uint8_t vpd_keyword[2];930uint8_t length;931uint8_t revision;932uint8_t device_flags;933uint8_t termnation_menus[2];934uint8_t fifo_threshold;935uint8_t end_tag;936uint8_t vpd_checksum;937uint16_t default_target_flags;938uint16_t default_bios_flags;939uint16_t default_ctrl_flags;940uint8_t default_irq;941uint8_t pci_lattime;942uint8_t max_target;943uint8_t boot_lun;944uint16_t signature;945uint8_t reserved_2;946uint8_t checksum;947uint8_t reserved_3[4];948};949950/****************************** Flexport Logic ********************************/951#define FLXADDR_TERMCTL 0x0952#define FLX_TERMCTL_ENSECHIGH 0x8953#define FLX_TERMCTL_ENSECLOW 0x4954#define FLX_TERMCTL_ENPRIHIGH 0x2955#define FLX_TERMCTL_ENPRILOW 0x1956#define FLXADDR_ROMSTAT_CURSENSECTL 0x1957#define FLX_ROMSTAT_SEECFG 0xF0958#define FLX_ROMSTAT_EECFG 0x0F959#define FLX_ROMSTAT_SEE_93C66 0x00960#define FLX_ROMSTAT_SEE_NONE 0xF0961#define FLX_ROMSTAT_EE_512x8 0x0962#define FLX_ROMSTAT_EE_1MBx8 0x1963#define FLX_ROMSTAT_EE_2MBx8 0x2964#define FLX_ROMSTAT_EE_4MBx8 0x3965#define FLX_ROMSTAT_EE_16MBx8 0x4966#define CURSENSE_ENB 0x1967#define FLXADDR_FLEXSTAT 0x2968#define FLX_FSTAT_BUSY 0x1969#define FLXADDR_CURRENT_STAT 0x4970#define FLX_CSTAT_SEC_HIGH 0xC0971#define FLX_CSTAT_SEC_LOW 0x30972#define FLX_CSTAT_PRI_HIGH 0x0C973#define FLX_CSTAT_PRI_LOW 0x03974#define FLX_CSTAT_MASK 0x03975#define FLX_CSTAT_SHIFT 2976#define FLX_CSTAT_OKAY 0x0977#define FLX_CSTAT_OVER 0x1978#define FLX_CSTAT_UNDER 0x2979#define FLX_CSTAT_INVALID 0x3980981int ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,982u_int start_addr, u_int count, int bstream);983984int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,985u_int start_addr, u_int count);986int ahd_wait_seeprom(struct ahd_softc *ahd);987int ahd_verify_vpd_cksum(struct vpd_config *vpd);988int ahd_verify_cksum(struct seeprom_config *sc);989int ahd_acquire_seeprom(struct ahd_softc *ahd);990void ahd_release_seeprom(struct ahd_softc *ahd);991992/**************************** Message Buffer *********************************/993typedef enum {994MSG_FLAG_NONE = 0x00,995MSG_FLAG_EXPECT_PPR_BUSFREE = 0x01,996MSG_FLAG_IU_REQ_CHANGED = 0x02,997MSG_FLAG_EXPECT_IDE_BUSFREE = 0x04,998MSG_FLAG_EXPECT_QASREJ_BUSFREE = 0x08,999MSG_FLAG_PACKETIZED = 0x101000} ahd_msg_flags;10011002typedef enum {1003MSG_TYPE_NONE = 0x00,1004MSG_TYPE_INITIATOR_MSGOUT = 0x01,1005MSG_TYPE_INITIATOR_MSGIN = 0x02,1006MSG_TYPE_TARGET_MSGOUT = 0x03,1007MSG_TYPE_TARGET_MSGIN = 0x041008} ahd_msg_type;10091010typedef enum {1011MSGLOOP_IN_PROG,1012MSGLOOP_MSGCOMPLETE,1013MSGLOOP_TERMINATED1014} msg_loop_stat;10151016/*********************** Software Configuration Structure *********************/1017struct ahd_suspend_channel_state {1018uint8_t scsiseq;1019uint8_t sxfrctl0;1020uint8_t sxfrctl1;1021uint8_t simode0;1022uint8_t simode1;1023uint8_t seltimer;1024uint8_t seqctl;1025};10261027struct ahd_suspend_state {1028struct ahd_suspend_channel_state channel[2];1029uint8_t optionmode;1030uint8_t dscommand0;1031uint8_t dspcistatus;1032/* hsmailbox */1033uint8_t crccontrol1;1034uint8_t scbbaddr;1035/* Host and sequencer SCB counts */1036uint8_t dff_thrsh;1037uint8_t *scratch_ram;1038uint8_t *btt;1039};10401041typedef void (*ahd_bus_intr_t)(struct ahd_softc *);10421043typedef enum {1044AHD_MODE_DFF0,1045AHD_MODE_DFF1,1046AHD_MODE_CCHAN,1047AHD_MODE_SCSI,1048AHD_MODE_CFG,1049AHD_MODE_UNKNOWN1050} ahd_mode;10511052#define AHD_MK_MSK(x) (0x01 << (x))1053#define AHD_MODE_DFF0_MSK AHD_MK_MSK(AHD_MODE_DFF0)1054#define AHD_MODE_DFF1_MSK AHD_MK_MSK(AHD_MODE_DFF1)1055#define AHD_MODE_CCHAN_MSK AHD_MK_MSK(AHD_MODE_CCHAN)1056#define AHD_MODE_SCSI_MSK AHD_MK_MSK(AHD_MODE_SCSI)1057#define AHD_MODE_CFG_MSK AHD_MK_MSK(AHD_MODE_CFG)1058#define AHD_MODE_UNKNOWN_MSK AHD_MK_MSK(AHD_MODE_UNKNOWN)1059#define AHD_MODE_ANY_MSK (~0)10601061typedef enum {1062AHD_SYSCTL_ROOT,1063AHD_SYSCTL_SUMMARY,1064AHD_SYSCTL_DEBUG,1065AHD_SYSCTL_NUMBER1066} ahd_sysctl_types_t;10671068typedef enum {1069AHD_ERRORS_CORRECTABLE,1070AHD_ERRORS_UNCORRECTABLE,1071AHD_ERRORS_FATAL,1072AHD_ERRORS_NUMBER1073} ahd_sysctl_errors_t;10741075#define AHD_CORRECTABLE_ERROR(sc) \1076(((sc)->summerr[AHD_ERRORS_CORRECTABLE])++)1077#define AHD_UNCORRECTABLE_ERROR(sc) \1078(((sc)->summerr[AHD_ERRORS_UNCORRECTABLE])++)1079#define AHD_FATAL_ERROR(sc) \1080(((sc)->summerr[AHD_ERRORS_FATAL])++)10811082typedef uint8_t ahd_mode_state;10831084typedef void ahd_callback_t (void *);10851086struct ahd_completion1087{1088uint16_t tag;1089uint8_t sg_status;1090uint8_t valid_tag;1091};10921093#define AIC_SCB_DATA(softc) (&(softc)->scb_data)10941095struct ahd_softc {1096bus_space_tag_t tags[2];1097bus_space_handle_t bshs[2];1098bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */1099struct scb_data scb_data;11001101struct hardware_scb *next_queued_hscb;1102struct map_node *next_queued_hscb_map;11031104/*1105* SCBs that have been sent to the controller1106*/1107LIST_HEAD(, scb) pending_scbs;11081109/*1110* SCBs whose timeout routine has been called.1111*/1112LIST_HEAD(, scb) timedout_scbs;11131114/*1115* Current register window mode information.1116*/1117ahd_mode dst_mode;1118ahd_mode src_mode;11191120/*1121* Saved register window mode information1122* used for restore on next unpause.1123*/1124ahd_mode saved_dst_mode;1125ahd_mode saved_src_mode;11261127/*1128* Platform specific data.1129*/1130struct ahd_platform_data *platform_data;11311132/*1133* Platform specific device information.1134*/1135aic_dev_softc_t dev_softc;11361137/*1138* Bus specific device information.1139*/1140ahd_bus_intr_t bus_intr;11411142/*1143* Target mode related state kept on a per enabled lun basis.1144* Targets that are not enabled will have null entries.1145* As an initiator, we keep one target entry for our initiator1146* ID to store our sync/wide transfer settings.1147*/1148struct ahd_tmode_tstate *enabled_targets[AHD_NUM_TARGETS];11491150/*1151* The black hole device responsible for handling requests for1152* disabled luns on enabled targets.1153*/1154struct ahd_tmode_lstate *black_hole;11551156/*1157* Device instance currently on the bus awaiting a continue TIO1158* for a command that was not given the disconnect priveledge.1159*/1160struct ahd_tmode_lstate *pending_device;11611162/*1163* Timer handles for timer driven callbacks.1164*/1165aic_timer_t reset_timer;1166aic_timer_t stat_timer;11671168/*1169* Statistics.1170*/1171#define AHD_STAT_UPDATE_MS 2501172#define AHD_STAT_BUCKETS 41173u_int cmdcmplt_bucket;1174uint32_t cmdcmplt_counts[AHD_STAT_BUCKETS];1175uint32_t cmdcmplt_total;11761177/*1178* Errors statistics and printouts.1179*/1180struct sysctl_ctx_list sysctl_ctx[AHD_SYSCTL_NUMBER];1181struct sysctl_oid *sysctl_tree[AHD_SYSCTL_NUMBER];1182u_int summerr[AHD_ERRORS_NUMBER];11831184/*1185* Card characteristics1186*/1187ahd_chip chip;1188ahd_feature features;1189ahd_bug bugs;1190ahd_flag flags;1191struct seeprom_config *seep_config;11921193/* Command Queues */1194struct ahd_completion *qoutfifo;1195uint16_t qoutfifonext;1196uint16_t qoutfifonext_valid_tag;1197uint16_t qinfifonext;1198uint16_t qinfifo[AHD_SCB_MAX];11991200/*1201* Our qfreeze count. The sequencer compares1202* this value with its own counter to determine1203* whether to allow selections to occur.1204*/1205uint16_t qfreeze_cnt;12061207/* Values to store in the SEQCTL register for pause and unpause */1208uint8_t unpause;1209uint8_t pause;12101211/* Critical Section Data */1212struct cs *critical_sections;1213u_int num_critical_sections;12141215/* Buffer for handling packetized bitbucket. */1216uint8_t *overrun_buf;12171218/* Links for chaining softcs */1219TAILQ_ENTRY(ahd_softc) links;12201221/* Channel Names ('A', 'B', etc.) */1222char channel;12231224/* Initiator Bus ID */1225uint8_t our_id;12261227/*1228* Target incoming command FIFO.1229*/1230struct target_cmd *targetcmds;1231uint8_t tqinfifonext;12321233/*1234* Cached verson of the hs_mailbox so we can avoid1235* pausing the sequencer during mailbox updates.1236*/1237uint8_t hs_mailbox;12381239/*1240* Incoming and outgoing message handling.1241*/1242uint8_t send_msg_perror;1243ahd_msg_flags msg_flags;1244ahd_msg_type msg_type;1245uint8_t msgout_buf[12];/* Message we are sending */1246uint8_t msgin_buf[12];/* Message we are receiving */1247u_int msgout_len; /* Length of message to send */1248u_int msgout_index; /* Current index in msgout */1249u_int msgin_index; /* Current index in msgin */12501251/*1252* Mapping information for data structures shared1253* between the sequencer and kernel.1254*/1255bus_dma_tag_t parent_dmat;1256bus_dma_tag_t shared_data_dmat;1257struct map_node shared_data_map;12581259/* Information saved through suspend/resume cycles */1260struct ahd_suspend_state suspend_state;12611262/* Number of enabled target mode device on this card */1263u_int enabled_luns;12641265/* Initialization level of this data structure */1266u_int init_level;12671268/* PCI cacheline size. */1269u_int pci_cachesize;12701271/* PCI-X capability offset. */1272int pcix_ptr;12731274/* IO Cell Parameters */1275uint8_t iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];12761277u_int stack_size;1278uint16_t *saved_stack;12791280/* Per-Unit descriptive information */1281const char *description;1282const char *bus_description;1283char *name;1284int unit;12851286/* Selection Timer settings */1287int seltime;12881289/*1290* Interrupt coalescing settings.1291*/1292#define AHD_INT_COALESCING_TIMER_DEFAULT 250 /*us*/1293#define AHD_INT_COALESCING_MAXCMDS_DEFAULT 101294#define AHD_INT_COALESCING_MAXCMDS_MAX 1271295#define AHD_INT_COALESCING_MINCMDS_DEFAULT 51296#define AHD_INT_COALESCING_MINCMDS_MAX 1271297#define AHD_INT_COALESCING_THRESHOLD_DEFAULT 20001298#define AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT 10001299u_int int_coalescing_timer;1300u_int int_coalescing_maxcmds;1301u_int int_coalescing_mincmds;1302u_int int_coalescing_threshold;1303u_int int_coalescing_stop_threshold;13041305uint16_t user_discenable;/* Disconnection allowed */1306uint16_t user_tagenable;/* Tagged Queuing allowed */1307};13081309TAILQ_HEAD(ahd_softc_tailq, ahd_softc);1310extern struct ahd_softc_tailq ahd_tailq;13111312/*************************** IO Cell Configuration ****************************/1313#define AHD_PRECOMP_SLEW_INDEX \1314(AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)13151316#define AHD_AMPLITUDE_INDEX \1317(AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)13181319#define AHD_SET_SLEWRATE(ahd, new_slew) \1320do { \1321(ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK; \1322(ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \1323(((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK); \1324} while (0)13251326#define AHD_SET_PRECOMP(ahd, new_pcomp) \1327do { \1328(ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK; \1329(ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \1330(((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK); \1331} while (0)13321333#define AHD_SET_AMPLITUDE(ahd, new_amp) \1334do { \1335(ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK; \1336(ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |= \1337(((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK); \1338} while (0)13391340/************************ Active Device Information ***************************/1341typedef enum {1342ROLE_UNKNOWN,1343ROLE_INITIATOR,1344ROLE_TARGET1345} role_t;13461347struct ahd_devinfo {1348int our_scsiid;1349int target_offset;1350uint16_t target_mask;1351u_int target;1352u_int lun;1353char channel;1354role_t role; /*1355* Only guaranteed to be correct if not1356* in the busfree state.1357*/1358};13591360/****************************** PCI Structures ********************************/1361#define AHD_PCI_IOADDR0 PCIR_BAR(0) /* I/O BAR*/1362#define AHD_PCI_MEMADDR PCIR_BAR(1) /* Memory BAR */1363#define AHD_PCI_IOADDR1 PCIR_BAR(3) /* Second I/O BAR */13641365typedef int (ahd_device_setup_t)(struct ahd_softc *);13661367struct ahd_pci_identity {1368uint64_t full_id;1369uint64_t id_mask;1370char *name;1371ahd_device_setup_t *setup;1372};1373extern struct ahd_pci_identity ahd_pci_ident_table [];1374extern const u_int ahd_num_pci_devs;13751376/*************************** Function Declarations ****************************/1377/******************************************************************************/1378void ahd_reset_cmds_pending(struct ahd_softc *ahd);1379u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);1380void ahd_busy_tcl(struct ahd_softc *ahd,1381u_int tcl, u_int busyid);1382static __inline void ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl);1383static __inline void1384ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)1385{1386ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);1387}13881389/***************************** PCI Front End *********************************/1390struct ahd_pci_identity *ahd_find_pci_device(aic_dev_softc_t);1391int ahd_pci_config(struct ahd_softc *,1392struct ahd_pci_identity *);1393int ahd_pci_test_register_access(struct ahd_softc *);13941395/************************** SCB and SCB queue management **********************/1396int ahd_probe_scbs(struct ahd_softc *);1397void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,1398struct scb *scb);1399int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,1400int target, char channel, int lun,1401u_int tag, role_t role);14021403/****************************** Initialization ********************************/1404struct ahd_softc *ahd_alloc(void *platform_arg, char *name);1405int ahd_softc_init(struct ahd_softc *);1406void ahd_controller_info(struct ahd_softc *ahd, char *buf);1407int ahd_init(struct ahd_softc *ahd);1408int ahd_default_config(struct ahd_softc *ahd);1409int ahd_parse_vpddata(struct ahd_softc *ahd,1410struct vpd_config *vpd);1411int ahd_parse_cfgdata(struct ahd_softc *ahd,1412struct seeprom_config *sc);1413void ahd_intr_enable(struct ahd_softc *ahd, int enable);1414void ahd_update_coalescing_values(struct ahd_softc *ahd,1415u_int timer,1416u_int maxcmds,1417u_int mincmds);1418void ahd_enable_coalescing(struct ahd_softc *ahd,1419int enable);1420void ahd_pause_and_flushwork(struct ahd_softc *ahd);1421int ahd_suspend(struct ahd_softc *ahd);1422int ahd_resume(struct ahd_softc *ahd);1423void ahd_softc_insert(struct ahd_softc *);1424void ahd_set_unit(struct ahd_softc *, int);1425void ahd_set_name(struct ahd_softc *, char *);1426struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);1427void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);1428int ahd_alloc_scbs(struct ahd_softc *ahd);1429void ahd_free(struct ahd_softc *ahd);1430int ahd_reset(struct ahd_softc *ahd, int reinit);1431void ahd_shutdown(void *arg);1432int ahd_write_flexport(struct ahd_softc *ahd,1433u_int addr, u_int value);1434int ahd_read_flexport(struct ahd_softc *ahd, u_int addr,1435uint8_t *value);1436int ahd_wait_flexport(struct ahd_softc *ahd);14371438/*************************** Interrupt Services *******************************/1439void ahd_pci_intr(struct ahd_softc *ahd);1440void ahd_clear_intstat(struct ahd_softc *ahd);1441void ahd_flush_qoutfifo(struct ahd_softc *ahd);1442void ahd_run_qoutfifo(struct ahd_softc *ahd);1443#ifdef AHD_TARGET_MODE1444void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);1445#endif1446void ahd_handle_hwerrint(struct ahd_softc *ahd);1447void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);1448void ahd_handle_scsiint(struct ahd_softc *ahd,1449u_int intstat);1450void ahd_clear_critical_section(struct ahd_softc *ahd);14511452/***************************** Error Recovery *********************************/1453typedef enum {1454SEARCH_COMPLETE,1455SEARCH_COUNT,1456SEARCH_REMOVE,1457SEARCH_PRINT1458} ahd_search_action;1459void ahd_done_with_status(struct ahd_softc *ahd,1460struct scb *scb, uint32_t status);1461int ahd_search_qinfifo(struct ahd_softc *ahd, int target,1462char channel, int lun, u_int tag,1463role_t role, uint32_t status,1464ahd_search_action action);1465int ahd_search_disc_list(struct ahd_softc *ahd, int target,1466char channel, int lun, u_int tag,1467int stop_on_first, int remove,1468int save_state);1469void ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb);1470int ahd_reset_channel(struct ahd_softc *ahd, char channel,1471int initiate_reset);1472int ahd_abort_scbs(struct ahd_softc *ahd, int target,1473char channel, int lun, u_int tag,1474role_t role, uint32_t status);1475void ahd_restart(struct ahd_softc *ahd);1476void ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo);1477void ahd_handle_scb_status(struct ahd_softc *ahd,1478struct scb *scb);1479void ahd_handle_scsi_status(struct ahd_softc *ahd,1480struct scb *scb);1481void ahd_calc_residual(struct ahd_softc *ahd,1482struct scb *scb);1483void ahd_timeout(struct scb *scb);1484void ahd_recover_commands(struct ahd_softc *ahd);1485/*************************** Utility Functions ********************************/1486struct ahd_phase_table_entry*1487ahd_lookup_phase_entry(int phase);1488void ahd_compile_devinfo(struct ahd_devinfo *devinfo,1489u_int our_id, u_int target,1490u_int lun, char channel,1491role_t role);1492/************************** Transfer Negotiation ******************************/1493void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,1494u_int *ppr_options, u_int maxsync);1495void ahd_validate_offset(struct ahd_softc *ahd,1496struct ahd_initiator_tinfo *tinfo,1497u_int period, u_int *offset,1498int wide, role_t role);1499void ahd_validate_width(struct ahd_softc *ahd,1500struct ahd_initiator_tinfo *tinfo,1501u_int *bus_width,1502role_t role);1503/*1504* Negotiation types. These are used to qualify if we should renegotiate1505* even if our goal and current transport parameters are identical.1506*/1507typedef enum {1508AHD_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */1509AHD_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */1510AHD_NEG_ALWAYS /* Renegotiat even if goal is async. */1511} ahd_neg_type;1512int ahd_update_neg_request(struct ahd_softc*,1513struct ahd_devinfo*,1514struct ahd_tmode_tstate*,1515struct ahd_initiator_tinfo*,1516ahd_neg_type);1517void ahd_set_width(struct ahd_softc *ahd,1518struct ahd_devinfo *devinfo,1519u_int width, u_int type, int paused);1520void ahd_set_syncrate(struct ahd_softc *ahd,1521struct ahd_devinfo *devinfo,1522u_int period, u_int offset,1523u_int ppr_options,1524u_int type, int paused);1525typedef enum {1526AHD_QUEUE_NONE,1527AHD_QUEUE_BASIC,1528AHD_QUEUE_TAGGED1529} ahd_queue_alg;15301531void ahd_set_tags(struct ahd_softc *ahd,1532struct ahd_devinfo *devinfo,1533ahd_queue_alg alg);15341535/**************************** Target Mode *************************************/1536#ifdef AHD_TARGET_MODE1537void ahd_send_lstate_events(struct ahd_softc *,1538struct ahd_tmode_lstate *);1539void ahd_handle_en_lun(struct ahd_softc *ahd,1540struct cam_sim *sim, union ccb *ccb);1541cam_status ahd_find_tmode_devs(struct ahd_softc *ahd,1542struct cam_sim *sim, union ccb *ccb,1543struct ahd_tmode_tstate **tstate,1544struct ahd_tmode_lstate **lstate,1545int notfound_failure);1546#ifndef AHD_TMODE_ENABLE1547#define AHD_TMODE_ENABLE 01548#endif1549#endif1550/******************************* Debug ***************************************/1551#ifdef AHD_DEBUG1552extern uint32_t ahd_debug;1553#define AHD_SHOW_MISC 0x000011554#define AHD_SHOW_SENSE 0x000021555#define AHD_SHOW_RECOVERY 0x000041556#define AHD_DUMP_SEEPROM 0x000081557#define AHD_SHOW_TERMCTL 0x000101558#define AHD_SHOW_MEMORY 0x000201559#define AHD_SHOW_MESSAGES 0x000401560#define AHD_SHOW_MODEPTR 0x000801561#define AHD_SHOW_SELTO 0x001001562#define AHD_SHOW_FIFOS 0x002001563#define AHD_SHOW_QFULL 0x004001564#define AHD_SHOW_DV 0x008001565#define AHD_SHOW_MASKED_ERRORS 0x010001566#define AHD_SHOW_QUEUE 0x020001567#define AHD_SHOW_TQIN 0x040001568#define AHD_SHOW_SG 0x080001569#define AHD_SHOW_INT_COALESCING 0x100001570#define AHD_DEBUG_SEQUENCER 0x200001571#endif1572void ahd_print_scb(struct scb *scb);1573void ahd_print_devinfo(struct ahd_softc *ahd,1574struct ahd_devinfo *devinfo);1575void ahd_dump_sglist(struct scb *scb);1576void ahd_dump_all_cards_state(void);1577void ahd_dump_card_state(struct ahd_softc *ahd);1578int ahd_print_register(ahd_reg_parse_entry_t *table,1579u_int num_entries,1580const char *name,1581u_int address,1582u_int value,1583u_int *cur_column,1584u_int wrap_point);1585void ahd_dump_scbs(struct ahd_softc *ahd);1586#endif /* _AIC79XX_H_ */158715881589