1942c5e3cSpl196000 /* 2*3fced439Szhongyan gu - Sun Microsystems - Beijing China * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3942c5e3cSpl196000 */ 4942c5e3cSpl196000 5942c5e3cSpl196000 /* 6942c5e3cSpl196000 * Copyright 2005-06 Adaptec, Inc. 7942c5e3cSpl196000 * Copyright (c) 2005-06 Adaptec Inc., Achim Leubner 8942c5e3cSpl196000 * Copyright (c) 2000 Michael Smith 9942c5e3cSpl196000 * Copyright (c) 2001 Scott Long 10942c5e3cSpl196000 * Copyright (c) 2000 BSDi 11942c5e3cSpl196000 * All rights reserved. 12942c5e3cSpl196000 * 13942c5e3cSpl196000 * Redistribution and use in source and binary forms, with or without 14942c5e3cSpl196000 * modification, are permitted provided that the following conditions 15942c5e3cSpl196000 * are met: 16942c5e3cSpl196000 * 1. Redistributions of source code must retain the above copyright 17942c5e3cSpl196000 * notice, this list of conditions and the following disclaimer. 18942c5e3cSpl196000 * 2. Redistributions in binary form must reproduce the above copyright 19942c5e3cSpl196000 * notice, this list of conditions and the following disclaimer in the 20942c5e3cSpl196000 * documentation and/or other materials provided with the distribution. 21942c5e3cSpl196000 * 22942c5e3cSpl196000 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23942c5e3cSpl196000 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24942c5e3cSpl196000 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25942c5e3cSpl196000 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26942c5e3cSpl196000 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27942c5e3cSpl196000 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28942c5e3cSpl196000 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29942c5e3cSpl196000 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30942c5e3cSpl196000 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31942c5e3cSpl196000 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32942c5e3cSpl196000 * SUCH DAMAGE. 33942c5e3cSpl196000 * 34942c5e3cSpl196000 * $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.47 2005/10/08 15:55:09 scottl Exp $ 35942c5e3cSpl196000 */ 36942c5e3cSpl196000 37942c5e3cSpl196000 #ifndef _AAC_H_ 38942c5e3cSpl196000 #define _AAC_H_ 39942c5e3cSpl196000 40942c5e3cSpl196000 #ifdef __cplusplus 41942c5e3cSpl196000 extern "C" { 42942c5e3cSpl196000 #endif 43942c5e3cSpl196000 44942c5e3cSpl196000 #define AAC_ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y)) 45942c5e3cSpl196000 46942c5e3cSpl196000 #define AAC_TYPE_DEVO 1 47942c5e3cSpl196000 #define AAC_TYPE_ALPHA 2 48942c5e3cSpl196000 #define AAC_TYPE_BETA 3 49942c5e3cSpl196000 #define AAC_TYPE_RELEASE 4 50942c5e3cSpl196000 51942c5e3cSpl196000 #ifndef AAC_DRIVER_BUILD 52942c5e3cSpl196000 #define AAC_DRIVER_BUILD 1 53942c5e3cSpl196000 #endif 54942c5e3cSpl196000 55942c5e3cSpl196000 #define AAC_DRIVER_MAJOR_VERSION 2 56942c5e3cSpl196000 #define AAC_DRIVER_MINOR_VERSION 2 57*3fced439Szhongyan gu - Sun Microsystems - Beijing China #define AAC_DRIVER_BUGFIX_LEVEL 11 58942c5e3cSpl196000 #define AAC_DRIVER_TYPE AAC_TYPE_RELEASE 59942c5e3cSpl196000 60942c5e3cSpl196000 #define STR(s) # s 61942c5e3cSpl196000 #define AAC_VERSION(a, b, c) STR(a.b.c) 62942c5e3cSpl196000 #define AAC_DRIVER_VERSION AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \ 63942c5e3cSpl196000 AAC_DRIVER_MINOR_VERSION, \ 64942c5e3cSpl196000 AAC_DRIVER_BUGFIX_LEVEL) 65942c5e3cSpl196000 66942c5e3cSpl196000 #define AACOK 0 67942c5e3cSpl196000 #define AACERR -1 68942c5e3cSpl196000 69942c5e3cSpl196000 #define AAC_MAX_ADAPTERS 64 70942c5e3cSpl196000 71942c5e3cSpl196000 /* Definitions for mode sense */ 72942c5e3cSpl196000 #ifndef SD_MODE_SENSE_PAGE3_CODE 73942c5e3cSpl196000 #define SD_MODE_SENSE_PAGE3_CODE 0x03 74942c5e3cSpl196000 #endif 75942c5e3cSpl196000 76942c5e3cSpl196000 #ifndef SD_MODE_SENSE_PAGE4_CODE 77942c5e3cSpl196000 #define SD_MODE_SENSE_PAGE4_CODE 0x04 78942c5e3cSpl196000 #endif 79942c5e3cSpl196000 80942c5e3cSpl196000 #ifndef SCMD_SYNCHRONIZE_CACHE 81942c5e3cSpl196000 #define SCMD_SYNCHRONIZE_CACHE 0x35 82942c5e3cSpl196000 #endif 83942c5e3cSpl196000 84942c5e3cSpl196000 /* 85942c5e3cSpl196000 * The controller reports status events in AIFs. We hang on to a number of 86942c5e3cSpl196000 * these in order to pass them out to user-space management tools. 87942c5e3cSpl196000 */ 88942c5e3cSpl196000 #define AAC_AIFQ_LENGTH 64 89942c5e3cSpl196000 90942c5e3cSpl196000 #ifdef __x86 91942c5e3cSpl196000 #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 92942c5e3cSpl196000 #else 93942c5e3cSpl196000 #define AAC_IMMEDIATE_TIMEOUT 60 /* seconds */ 94942c5e3cSpl196000 #endif 95942c5e3cSpl196000 #define AAC_FWUP_TIMEOUT 180 /* wait up to 3 minutes */ 9658bc78c7SXin Chen #define AAC_IOCTL_TIMEOUT 900 /* wait up to 15 minutes */ 97f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_SYNC_TIMEOUT 900 /* wait up to 15 minutes */ 98942c5e3cSpl196000 99942c5e3cSpl196000 /* Adapter hardware interface types */ 100942c5e3cSpl196000 #define AAC_HWIF_UNKNOWN 0 101942c5e3cSpl196000 #define AAC_HWIF_I960RX 1 102942c5e3cSpl196000 #define AAC_HWIF_RKT 2 103942c5e3cSpl196000 104942c5e3cSpl196000 #define AAC_TYPE_UNKNOWN 0 105942c5e3cSpl196000 #define AAC_TYPE_SCSI 1 106942c5e3cSpl196000 #define AAC_TYPE_SATA 2 107942c5e3cSpl196000 #define AAC_TYPE_SAS 3 108942c5e3cSpl196000 109942c5e3cSpl196000 #define AAC_LS32(d) ((uint32_t)((d) & 0xffffffffull)) 110942c5e3cSpl196000 #define AAC_MS32(d) ((uint32_t)((d) >> 32)) 111942c5e3cSpl196000 #define AAC_LO32(p64) ((uint32_t *)(p64)) 112942c5e3cSpl196000 #define AAC_HI32(p64) ((uint32_t *)(p64) + 1) 113942c5e3cSpl196000 114942c5e3cSpl196000 /* 1150749e8deSXin Chen - Sun Microsystems - Beijing China * Internal events that will be handled serially by aac_event_thread() 1160749e8deSXin Chen - Sun Microsystems - Beijing China */ 1170749e8deSXin Chen - Sun Microsystems - Beijing China #define AAC_EVENT_AIF (1 << 0) 1180749e8deSXin Chen - Sun Microsystems - Beijing China #define AAC_EVENT_TIMEOUT (1 << 1) 1190749e8deSXin Chen - Sun Microsystems - Beijing China #define AAC_EVENT_SYNCTICK (1 << 2) 1200749e8deSXin Chen - Sun Microsystems - Beijing China 1210749e8deSXin Chen - Sun Microsystems - Beijing China /* 122942c5e3cSpl196000 * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io 123942c5e3cSpl196000 * to be served before async FIB io, see aac_start_waiting_io(). 124942c5e3cSpl196000 * So that io requests sent by interactive userland commands get 125942c5e3cSpl196000 * responded asap. 126942c5e3cSpl196000 */ 127942c5e3cSpl196000 enum aac_cmdq { 128942c5e3cSpl196000 AAC_CMDQ_SYNC, /* sync FIB queue */ 129942c5e3cSpl196000 AAC_CMDQ_ASYNC, /* async FIB queue */ 130942c5e3cSpl196000 AAC_CMDQ_NUM 131942c5e3cSpl196000 }; 132942c5e3cSpl196000 133942c5e3cSpl196000 /* 134942c5e3cSpl196000 * IO command flags 135942c5e3cSpl196000 */ 136942c5e3cSpl196000 #define AAC_IOCMD_SYNC (1 << AAC_CMDQ_SYNC) 137942c5e3cSpl196000 #define AAC_IOCMD_ASYNC (1 << AAC_CMDQ_ASYNC) 138942c5e3cSpl196000 #define AAC_IOCMD_OUTSTANDING (1 << AAC_CMDQ_NUM) 139942c5e3cSpl196000 #define AAC_IOCMD_ALL (AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \ 140942c5e3cSpl196000 AAC_IOCMD_OUTSTANDING) 141942c5e3cSpl196000 142942c5e3cSpl196000 struct aac_cmd_queue { 143942c5e3cSpl196000 struct aac_cmd *q_head; /* also as the header of aac_cmd */ 144942c5e3cSpl196000 struct aac_cmd *q_tail; 145942c5e3cSpl196000 }; 146942c5e3cSpl196000 147942c5e3cSpl196000 struct aac_card_type { 148942c5e3cSpl196000 uint16_t vendor; /* PCI Vendor ID */ 149942c5e3cSpl196000 uint16_t device; /* PCI Device ID */ 150942c5e3cSpl196000 uint16_t subvendor; /* PCI Subsystem Vendor ID */ 151942c5e3cSpl196000 uint16_t subsys; /* PCI Subsystem ID */ 152942c5e3cSpl196000 uint16_t hwif; /* card chip type: i960 or Rocket */ 153942c5e3cSpl196000 uint16_t quirks; /* card odd limits */ 154942c5e3cSpl196000 uint16_t type; /* hard drive type */ 155942c5e3cSpl196000 char *vid; /* ASCII data for INQUIRY command vendor id */ 156942c5e3cSpl196000 char *desc; /* ASCII data for INQUIRY command product id */ 157942c5e3cSpl196000 }; 158942c5e3cSpl196000 15958bc78c7SXin Chen /* Device types */ 16058bc78c7SXin Chen #define AAC_DEV_LD 0 /* logical device */ 16158bc78c7SXin Chen #define AAC_DEV_PD 1 /* physical device */ 16258bc78c7SXin Chen 16358bc78c7SXin Chen /* Device flags */ 16458bc78c7SXin Chen #define AAC_DFLAG_VALID (1 << 0) 16558bc78c7SXin Chen #define AAC_DFLAG_CONFIGURING (1 << 1) 16658bc78c7SXin Chen 16758bc78c7SXin Chen #define AAC_DEV_IS_VALID(dvp) ((dvp)->flags & AAC_DFLAG_VALID) 168*3fced439Szhongyan gu - Sun Microsystems - Beijing China #define AAC_P2VTGT(softs, bus, tgt) \ 169*3fced439Szhongyan gu - Sun Microsystems - Beijing China ((softs)->tgt_max * (bus) + (tgt) + AAC_MAX_LD) 17058bc78c7SXin Chen 1710749e8deSXin Chen - Sun Microsystems - Beijing China /* 1720749e8deSXin Chen - Sun Microsystems - Beijing China * Device config change events 1730749e8deSXin Chen - Sun Microsystems - Beijing China */ 1740749e8deSXin Chen - Sun Microsystems - Beijing China enum aac_cfg_event { 1750749e8deSXin Chen - Sun Microsystems - Beijing China AAC_CFG_NULL_NOEXIST = 0, /* No change with no device */ 1760749e8deSXin Chen - Sun Microsystems - Beijing China AAC_CFG_NULL_EXIST, /* No change but have device */ 1770749e8deSXin Chen - Sun Microsystems - Beijing China AAC_CFG_ADD, /* Device added */ 1780749e8deSXin Chen - Sun Microsystems - Beijing China AAC_CFG_DELETE, /* Device deleted */ 1790749e8deSXin Chen - Sun Microsystems - Beijing China AAC_CFG_CHANGE /* Device changed */ 1800749e8deSXin Chen - Sun Microsystems - Beijing China }; 1810749e8deSXin Chen - Sun Microsystems - Beijing China 18258bc78c7SXin Chen struct aac_device { 18358bc78c7SXin Chen int flags; 18458bc78c7SXin Chen 18558bc78c7SXin Chen uint8_t type; 18658bc78c7SXin Chen dev_info_t *dip; 18758bc78c7SXin Chen int ncmds[AAC_CMDQ_NUM]; /* outstanding cmds of the device */ 18858bc78c7SXin Chen int throttle[AAC_CMDQ_NUM]; /* hold IO cmds for the device */ 18958bc78c7SXin Chen }; 19058bc78c7SXin Chen 191942c5e3cSpl196000 /* Array description */ 192942c5e3cSpl196000 struct aac_container { 19358bc78c7SXin Chen struct aac_device dev; 19458bc78c7SXin Chen 195942c5e3cSpl196000 uint32_t cid; /* container id */ 196942c5e3cSpl196000 uint32_t uid; /* container uid */ 197942c5e3cSpl196000 uint64_t size; /* in block */ 198942c5e3cSpl196000 uint8_t locked; 199942c5e3cSpl196000 uint8_t deleted; 200942c5e3cSpl196000 uint8_t reset; /* container is being reseted */ 20158bc78c7SXin Chen }; 20258bc78c7SXin Chen 20358bc78c7SXin Chen /* Non-DASD phys. device descrption, eg. CDROM or tape */ 20458bc78c7SXin Chen struct aac_nondasd { 20558bc78c7SXin Chen struct aac_device dev; 20658bc78c7SXin Chen 20758bc78c7SXin Chen uint32_t bus; 20858bc78c7SXin Chen uint32_t tid; 209942c5e3cSpl196000 }; 210942c5e3cSpl196000 211942c5e3cSpl196000 /* 212942c5e3cSpl196000 * The firmware can support a lot of outstanding commands. Each aac_slot 213942c5e3cSpl196000 * is corresponding to one of such commands. It records the command and 214942c5e3cSpl196000 * associated DMA resource for FIB command. 215942c5e3cSpl196000 */ 216942c5e3cSpl196000 struct aac_slot { 217942c5e3cSpl196000 struct aac_slot *next; /* next slot in the free slot list */ 218942c5e3cSpl196000 int index; /* index of this slot */ 219942c5e3cSpl196000 ddi_acc_handle_t fib_acc_handle; 220942c5e3cSpl196000 ddi_dma_handle_t fib_dma_handle; 221942c5e3cSpl196000 uint64_t fib_phyaddr; /* physical address of FIB memory */ 222942c5e3cSpl196000 struct aac_cmd *acp; /* command using this slot */ 223942c5e3cSpl196000 struct aac_fib *fibp; /* virtual address of FIB memory */ 224942c5e3cSpl196000 }; 225942c5e3cSpl196000 226f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* 227f42c2f53Szhongyan gu - Sun Microsystems - Beijing China * Scatter-gather list structure defined by HBA hardware 228f42c2f53Szhongyan gu - Sun Microsystems - Beijing China */ 229f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_sge { 230f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t bcount; /* byte count */ 231f42c2f53Szhongyan gu - Sun Microsystems - Beijing China union { 232f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t ad32; /* 32 bit address */ 233f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct { 234f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t lo; 235f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t hi; 236f42c2f53Szhongyan gu - Sun Microsystems - Beijing China } ad64; /* 64 bit address */ 237f42c2f53Szhongyan gu - Sun Microsystems - Beijing China } addr; 238f42c2f53Szhongyan gu - Sun Microsystems - Beijing China }; 239f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 240f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* aac_cmd flags */ 241f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_CONSISTENT (1 << 0) 242f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_DMA_PARTIAL (1 << 1) 243f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_DMA_VALID (1 << 2) 244f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_BUF_READ (1 << 3) 245f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_BUF_WRITE (1 << 4) 246f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_SYNC (1 << 5) /* use sync FIB */ 247f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_NO_INTR (1 << 6) /* poll IO, no intr */ 248f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_NO_CB (1 << 7) /* sync IO, no callback */ 249f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_NTAG (1 << 8) 250f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_CMPLT (1 << 9) /* cmd exec'ed by driver/fw */ 251f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_ABORT (1 << 10) 252f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_TIMEOUT (1 << 11) 253f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_ERR (1 << 12) 254f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_CMD_IN_SYNC_SLOT (1 << 13) 255f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 256f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_softstate; 257f42c2f53Szhongyan gu - Sun Microsystems - Beijing China typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *); 258f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 259f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_cmd { 260f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* 261f42c2f53Szhongyan gu - Sun Microsystems - Beijing China * Note: should be the first member for aac_cmd_queue to work 262f42c2f53Szhongyan gu - Sun Microsystems - Beijing China * correctly. 263f42c2f53Szhongyan gu - Sun Microsystems - Beijing China */ 264f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_cmd *next; 265f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_cmd *prev; 266f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 267f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct scsi_pkt *pkt; 268f42c2f53Szhongyan gu - Sun Microsystems - Beijing China int cmdlen; 269f42c2f53Szhongyan gu - Sun Microsystems - Beijing China int flags; 270f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t timeout; /* time when the cmd should have completed */ 271f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct buf *bp; 272f42c2f53Szhongyan gu - Sun Microsystems - Beijing China ddi_dma_handle_t buf_dma_handle; 273f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 274f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* For non-aligned buffer and SRB */ 275f42c2f53Szhongyan gu - Sun Microsystems - Beijing China caddr_t abp; 276f42c2f53Szhongyan gu - Sun Microsystems - Beijing China ddi_acc_handle_t abh; 277f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 278f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* Data transfer state */ 279f42c2f53Szhongyan gu - Sun Microsystems - Beijing China ddi_dma_cookie_t cookie; 280f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint_t left_cookien; 281f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint_t cur_win; 282f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint_t total_nwin; 283f42c2f53Szhongyan gu - Sun Microsystems - Beijing China size_t total_xfer; 284f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint64_t blkno; 285f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t bcount; /* buffer size in byte */ 286f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_sge *sgt; /* sg table */ 287f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 288f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* FIB construct function */ 289f42c2f53Szhongyan gu - Sun Microsystems - Beijing China aac_cmd_fib_t aac_cmd_fib; 290f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* Call back function for completed command */ 291f42c2f53Szhongyan gu - Sun Microsystems - Beijing China void (*ac_comp)(struct aac_softstate *, struct aac_cmd *); 292f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 293f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_slot *slotp; /* slot used by this command */ 294f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_device *dvp; /* target device */ 295f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 296f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* FIB for this IO command */ 297f42c2f53Szhongyan gu - Sun Microsystems - Beijing China int fib_size; /* size of the FIB xferred to/from the card */ 298f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_fib *fibp; 299f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 300f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #ifdef DEBUG 301f42c2f53Szhongyan gu - Sun Microsystems - Beijing China uint32_t fib_flags; 302f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #endif 303f42c2f53Szhongyan gu - Sun Microsystems - Beijing China }; 304f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 305942c5e3cSpl196000 /* Flags for attach tracking */ 306942c5e3cSpl196000 #define AAC_ATTACH_SOFTSTATE_ALLOCED (1 << 0) 307942c5e3cSpl196000 #define AAC_ATTACH_CARD_DETECTED (1 << 1) 308942c5e3cSpl196000 #define AAC_ATTACH_PCI_MEM_MAPPED (1 << 2) 309942c5e3cSpl196000 #define AAC_ATTACH_KMUTEX_INITED (1 << 3) 310f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_ATTACH_SCSI_TRAN_SETUP (1 << 4) 311f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_ATTACH_COMM_SPACE_SETUP (1 << 5) 312f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_ATTACH_CREATE_DEVCTL (1 << 6) 313f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define AAC_ATTACH_CREATE_SCSI (1 << 7) 314942c5e3cSpl196000 315942c5e3cSpl196000 /* Driver running states */ 316942c5e3cSpl196000 #define AAC_STATE_STOPPED 0 317942c5e3cSpl196000 #define AAC_STATE_RUN (1 << 0) 318942c5e3cSpl196000 #define AAC_STATE_RESET (1 << 1) 319942c5e3cSpl196000 #define AAC_STATE_QUIESCED (1 << 2) 320942c5e3cSpl196000 #define AAC_STATE_DEAD (1 << 3) 3211ee13a44SXinChen #define AAC_STATE_INTR (1 << 4) 322942c5e3cSpl196000 323942c5e3cSpl196000 /* 324942c5e3cSpl196000 * Flags for aac firmware 325942c5e3cSpl196000 * Note: Quirks are only valid for the older cards. These cards only supported 326942c5e3cSpl196000 * old comm. Thus they are not valid for any cards that support new comm. 327942c5e3cSpl196000 */ 328942c5e3cSpl196000 #define AAC_FLAGS_SG_64BIT (1 << 0) /* Use 64-bit S/G addresses */ 329942c5e3cSpl196000 #define AAC_FLAGS_4GB_WINDOW (1 << 1) /* Can access host mem 2-4GB range */ 330942c5e3cSpl196000 #define AAC_FLAGS_NO4GB (1 << 2) /* quirk: FIB addresses must reside */ 331942c5e3cSpl196000 /* between 0x2000 & 0x7FFFFFFF */ 332942c5e3cSpl196000 #define AAC_FLAGS_256FIBS (1 << 3) /* quirk: Can only do 256 commands */ 333942c5e3cSpl196000 #define AAC_FLAGS_NEW_COMM (1 << 4) /* New comm. interface supported */ 334942c5e3cSpl196000 #define AAC_FLAGS_RAW_IO (1 << 5) /* Raw I/O interface */ 335942c5e3cSpl196000 #define AAC_FLAGS_ARRAY_64BIT (1 << 6) /* 64-bit array size */ 336942c5e3cSpl196000 #define AAC_FLAGS_LBA_64BIT (1 << 7) /* 64-bit LBA supported */ 337942c5e3cSpl196000 #define AAC_FLAGS_17SG (1 << 8) /* quirk: 17 scatter gather maximum */ 338942c5e3cSpl196000 #define AAC_FLAGS_34SG (1 << 9) /* quirk: 34 scatter gather maximum */ 33958bc78c7SXin Chen #define AAC_FLAGS_NONDASD (1 << 10) /* non-DASD device supported */ 34072888e72Speng liu - Sun Microsystems - Beijing China #define AAC_FLAGS_BRKUP (1 << 11) /* pkt breakup support */ 341*3fced439Szhongyan gu - Sun Microsystems - Beijing China #define AAC_FLAGS_JBOD (1 << 12) /* JBOD mode support */ 342942c5e3cSpl196000 343942c5e3cSpl196000 struct aac_softstate; 344942c5e3cSpl196000 struct aac_interface { 345942c5e3cSpl196000 int (*aif_get_fwstatus)(struct aac_softstate *); 346942c5e3cSpl196000 int (*aif_get_mailbox)(struct aac_softstate *, int); 347942c5e3cSpl196000 void (*aif_set_mailbox)(struct aac_softstate *, uint32_t, 348942c5e3cSpl196000 uint32_t, uint32_t, uint32_t, uint32_t); 349942c5e3cSpl196000 }; 350942c5e3cSpl196000 3510749e8deSXin Chen - Sun Microsystems - Beijing China #define AAC_CTXFLAG_FILLED 0x01 /* aifq's full for this ctx */ 3520749e8deSXin Chen - Sun Microsystems - Beijing China #define AAC_CTXFLAG_RESETED 0x02 3530749e8deSXin Chen - Sun Microsystems - Beijing China 354942c5e3cSpl196000 struct aac_fib_context { 355942c5e3cSpl196000 uint32_t unique; 356942c5e3cSpl196000 int ctx_idx; 357942c5e3cSpl196000 int ctx_filled; /* aifq is full for this fib context */ 3580749e8deSXin Chen - Sun Microsystems - Beijing China int ctx_flags; 3590749e8deSXin Chen - Sun Microsystems - Beijing China int ctx_overrun; 360942c5e3cSpl196000 struct aac_fib_context *next, *prev; 361942c5e3cSpl196000 }; 362942c5e3cSpl196000 363942c5e3cSpl196000 #define AAC_VENDOR_LEN 8 364942c5e3cSpl196000 #define AAC_PRODUCT_LEN 16 365942c5e3cSpl196000 366942c5e3cSpl196000 struct aac_softstate { 367942c5e3cSpl196000 int card; /* index to aac_cards */ 368942c5e3cSpl196000 uint16_t hwif; /* card chip type: i960 or Rocket */ 369942c5e3cSpl196000 uint16_t vendid; /* vendor id */ 370942c5e3cSpl196000 uint16_t subvendid; /* sub vendor id */ 371942c5e3cSpl196000 uint16_t devid; /* device id */ 372942c5e3cSpl196000 uint16_t subsysid; /* sub system id */ 373942c5e3cSpl196000 char vendor_name[AAC_VENDOR_LEN + 1]; 374942c5e3cSpl196000 char product_name[AAC_PRODUCT_LEN + 1]; 375942c5e3cSpl196000 uint32_t support_opt; /* firmware features */ 376b40e8a89Szhongyan gu - Sun Microsystems - Beijing China uint32_t support_opt2; 377b40e8a89Szhongyan gu - Sun Microsystems - Beijing China uint32_t feature_bits; 378942c5e3cSpl196000 uint32_t atu_size; /* actual size of PCI mem space */ 379942c5e3cSpl196000 uint32_t map_size; /* mapped PCI mem space size */ 380942c5e3cSpl196000 uint32_t map_size_min; /* minimum size of PCI mem that must be */ 381942c5e3cSpl196000 /* mapped to address the card */ 382942c5e3cSpl196000 int flags; /* firmware features enabled */ 383942c5e3cSpl196000 int instance; 384942c5e3cSpl196000 dev_info_t *devinfo_p; 38558bc78c7SXin Chen scsi_hba_tran_t *hba_tran; 386942c5e3cSpl196000 int slen; 38758bc78c7SXin Chen int legacy; /* legacy device naming */ 38872888e72Speng liu - Sun Microsystems - Beijing China uint32_t dma_max; /* for buf breakup */ 389942c5e3cSpl196000 390942c5e3cSpl196000 /* DMA attributes */ 391942c5e3cSpl196000 ddi_dma_attr_t buf_dma_attr; 392942c5e3cSpl196000 ddi_dma_attr_t addr_dma_attr; 393942c5e3cSpl196000 394942c5e3cSpl196000 /* PCI spaces */ 39558bc78c7SXin Chen ddi_device_acc_attr_t acc_attr; 396837c1ac4SStephen Hanson ddi_device_acc_attr_t reg_attr; 397942c5e3cSpl196000 ddi_acc_handle_t pci_mem_handle; 398a74f7440Spl196000 uint8_t *pci_mem_base_vaddr; 399942c5e3cSpl196000 uint32_t pci_mem_base_paddr; 400942c5e3cSpl196000 401942c5e3cSpl196000 struct aac_interface aac_if; /* adapter hardware interface */ 402942c5e3cSpl196000 403f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_cmd sync_ac; /* sync FIB */ 404942c5e3cSpl196000 405942c5e3cSpl196000 /* Communication space */ 406942c5e3cSpl196000 struct aac_comm_space *comm_space; 407942c5e3cSpl196000 ddi_acc_handle_t comm_space_acc_handle; 408942c5e3cSpl196000 ddi_dma_handle_t comm_space_dma_handle; 409942c5e3cSpl196000 uint32_t comm_space_phyaddr; 410942c5e3cSpl196000 411942c5e3cSpl196000 /* Old Comm. interface: message queues */ 412942c5e3cSpl196000 struct aac_queue_table *qtablep; 413942c5e3cSpl196000 struct aac_queue_entry *qentries[AAC_QUEUE_COUNT]; 414942c5e3cSpl196000 415942c5e3cSpl196000 /* New Comm. interface */ 416942c5e3cSpl196000 uint32_t aac_max_fibs; /* max. FIB count */ 417942c5e3cSpl196000 uint32_t aac_max_fib_size; /* max. FIB size */ 418942c5e3cSpl196000 uint32_t aac_sg_tablesize; /* max. sg count from host */ 419942c5e3cSpl196000 uint32_t aac_max_sectors; /* max. I/O size from host (blocks) */ 420942c5e3cSpl196000 421942c5e3cSpl196000 aac_cmd_fib_t aac_cmd_fib; /* IO cmd FIB construct function */ 422942c5e3cSpl196000 aac_cmd_fib_t aac_cmd_fib_scsi; /* SRB construct function */ 423942c5e3cSpl196000 424942c5e3cSpl196000 ddi_softintr_t softint_id; /* soft intr */ 425942c5e3cSpl196000 426942c5e3cSpl196000 kmutex_t io_lock; 427942c5e3cSpl196000 int state; /* driver state */ 428942c5e3cSpl196000 429942c5e3cSpl196000 struct aac_container containers[AAC_MAX_LD]; 430942c5e3cSpl196000 int container_count; /* max container id + 1 */ 43158bc78c7SXin Chen struct aac_nondasd *nondasds; 43258bc78c7SXin Chen uint32_t bus_max; /* max FW buses exposed */ 43358bc78c7SXin Chen uint32_t tgt_max; /* max FW target per bus */ 434942c5e3cSpl196000 435942c5e3cSpl196000 /* 436942c5e3cSpl196000 * Command queues 437942c5e3cSpl196000 * Each aac command flows through wait(or wait_sync) queue, 438942c5e3cSpl196000 * busy queue, and complete queue sequentially. 439942c5e3cSpl196000 */ 440942c5e3cSpl196000 struct aac_cmd_queue q_wait[AAC_CMDQ_NUM]; 441942c5e3cSpl196000 struct aac_cmd_queue q_busy; /* outstanding cmd queue */ 442942c5e3cSpl196000 kmutex_t q_comp_mutex; 443942c5e3cSpl196000 struct aac_cmd_queue q_comp; /* completed io requests */ 444942c5e3cSpl196000 445942c5e3cSpl196000 /* I/O slots and FIBs */ 446942c5e3cSpl196000 int total_slots; /* total slots allocated */ 447942c5e3cSpl196000 int total_fibs; /* total FIBs allocated */ 448942c5e3cSpl196000 struct aac_slot *io_slot; /* static list for allocated slots */ 449942c5e3cSpl196000 struct aac_slot *free_io_slot_head; 450942c5e3cSpl196000 451942c5e3cSpl196000 kcondvar_t event; /* for ioctl_send_fib() and sync IO */ 4521ee13a44SXinChen kcondvar_t sync_fib_cv; /* for sync_fib_slot_bind/release */ 453942c5e3cSpl196000 454942c5e3cSpl196000 int bus_ncmds[AAC_CMDQ_NUM]; /* total outstanding async cmds */ 455942c5e3cSpl196000 int bus_throttle[AAC_CMDQ_NUM]; /* hold IO cmds for the bus */ 456942c5e3cSpl196000 int ndrains; /* number of draining threads */ 457942c5e3cSpl196000 timeout_id_t drain_timeid; /* for outstanding cmd drain */ 458942c5e3cSpl196000 kcondvar_t drain_cv; /* for quiesce drain */ 459942c5e3cSpl196000 4600749e8deSXin Chen - Sun Microsystems - Beijing China /* Internal timer */ 4610749e8deSXin Chen - Sun Microsystems - Beijing China kmutex_t time_mutex; 4620749e8deSXin Chen - Sun Microsystems - Beijing China timeout_id_t timeout_id; /* for timeout daemon */ 4630749e8deSXin Chen - Sun Microsystems - Beijing China uint32_t timebase; /* internal timer in seconds */ 4640749e8deSXin Chen - Sun Microsystems - Beijing China uint32_t time_sync; /* next time to sync with firmware */ 4650749e8deSXin Chen - Sun Microsystems - Beijing China uint32_t time_out; /* next time to check timeout */ 4660749e8deSXin Chen - Sun Microsystems - Beijing China uint32_t time_throttle; /* next time to restore throttle */ 4670749e8deSXin Chen - Sun Microsystems - Beijing China 4680749e8deSXin Chen - Sun Microsystems - Beijing China /* Internal events handling */ 4690749e8deSXin Chen - Sun Microsystems - Beijing China kmutex_t ev_lock; 4700749e8deSXin Chen - Sun Microsystems - Beijing China int events; 4710749e8deSXin Chen - Sun Microsystems - Beijing China kthread_t *event_thread; /* for AIF & timeout */ 4720749e8deSXin Chen - Sun Microsystems - Beijing China kcondvar_t event_wait_cv; 4730749e8deSXin Chen - Sun Microsystems - Beijing China kcondvar_t event_disp_cv; 4740749e8deSXin Chen - Sun Microsystems - Beijing China 475942c5e3cSpl196000 /* AIF */ 476942c5e3cSpl196000 kmutex_t aifq_mutex; /* for AIF queue aifq */ 4770749e8deSXin Chen - Sun Microsystems - Beijing China kcondvar_t aifq_cv; 478942c5e3cSpl196000 union aac_fib_align aifq[AAC_AIFQ_LENGTH]; 479942c5e3cSpl196000 int aifq_idx; /* slot for next new AIF */ 480942c5e3cSpl196000 int aifq_wrap; /* AIF queue has ever been wrapped */ 4810749e8deSXin Chen - Sun Microsystems - Beijing China struct aac_fib_context aifctx; /* sys aif ctx */ 4820749e8deSXin Chen - Sun Microsystems - Beijing China struct aac_fib_context *fibctx_p; 483942c5e3cSpl196000 int devcfg_wait_on; /* AIF event waited for rescan */ 484942c5e3cSpl196000 485942c5e3cSpl196000 int fm_capabilities; 486942c5e3cSpl196000 487b6094a86Sjd218194 /* MSI specific fields */ 488b6094a86Sjd218194 ddi_intr_handle_t *htable; /* For array of interrupts */ 489b6094a86Sjd218194 int intr_type; /* What type of interrupt */ 490b6094a86Sjd218194 int intr_cnt; /* # of intrs count returned */ 491f42c2f53Szhongyan gu - Sun Microsystems - Beijing China int intr_size; 492b6094a86Sjd218194 uint_t intr_pri; /* Interrupt priority */ 493b6094a86Sjd218194 int intr_cap; /* Interrupt capabilities */ 494b6094a86Sjd218194 495942c5e3cSpl196000 #ifdef DEBUG 496942c5e3cSpl196000 /* UART trace printf variables */ 497942c5e3cSpl196000 uint32_t debug_flags; /* debug print flags bitmap */ 49858bc78c7SXin Chen uint32_t debug_fib_flags; /* debug FIB print flags bitmap */ 499942c5e3cSpl196000 uint32_t debug_fw_flags; /* FW debug flags */ 500942c5e3cSpl196000 uint32_t debug_buf_offset; /* offset from DPMEM start */ 501942c5e3cSpl196000 uint32_t debug_buf_size; /* FW debug buffer size in bytes */ 502942c5e3cSpl196000 uint32_t debug_header_size; /* size of debug header */ 503942c5e3cSpl196000 #endif 504942c5e3cSpl196000 }; 505942c5e3cSpl196000 506942c5e3cSpl196000 /* 507942c5e3cSpl196000 * The following data are kept stable because they are only written at driver 508942c5e3cSpl196000 * initialization, and we do not allow them changed otherwise even at driver 509942c5e3cSpl196000 * re-initialization. 510942c5e3cSpl196000 */ 511942c5e3cSpl196000 _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \ 512942c5e3cSpl196000 buf_dma_attr pci_mem_handle pci_mem_base_vaddr \ 513942c5e3cSpl196000 comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \ 51458bc78c7SXin Chen aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags bus_max tgt_max})) 515942c5e3cSpl196000 516942c5e3cSpl196000 #ifdef DEBUG 517942c5e3cSpl196000 518942c5e3cSpl196000 #define AACDB_FLAGS_MASK 0x0000ffff 519942c5e3cSpl196000 #define AACDB_FLAGS_KERNEL_PRINT 0x00000001 520942c5e3cSpl196000 #define AACDB_FLAGS_FW_PRINT 0x00000002 521942c5e3cSpl196000 #define AACDB_FLAGS_NO_HEADERS 0x00000004 522942c5e3cSpl196000 523942c5e3cSpl196000 #define AACDB_FLAGS_MISC 0x00000010 524942c5e3cSpl196000 #define AACDB_FLAGS_FUNC1 0x00000020 525942c5e3cSpl196000 #define AACDB_FLAGS_FUNC2 0x00000040 526942c5e3cSpl196000 #define AACDB_FLAGS_SCMD 0x00000080 527942c5e3cSpl196000 #define AACDB_FLAGS_AIF 0x00000100 528942c5e3cSpl196000 #define AACDB_FLAGS_FIB 0x00000200 529942c5e3cSpl196000 #define AACDB_FLAGS_IOCTL 0x00000400 530942c5e3cSpl196000 53158bc78c7SXin Chen /* 53258bc78c7SXin Chen * Flags for FIB print 53358bc78c7SXin Chen */ 53458bc78c7SXin Chen /* FIB sources */ 53558bc78c7SXin Chen #define AACDB_FLAGS_FIB_SCMD 0x00000001 53658bc78c7SXin Chen #define AACDB_FLAGS_FIB_IOCTL 0x00000002 53758bc78c7SXin Chen #define AACDB_FLAGS_FIB_SRB 0x00000004 53858bc78c7SXin Chen #define AACDB_FLAGS_FIB_SYNC 0x00000008 53958bc78c7SXin Chen /* FIB components */ 54058bc78c7SXin Chen #define AACDB_FLAGS_FIB_HEADER 0x00000010 54158bc78c7SXin Chen /* FIB states */ 54258bc78c7SXin Chen #define AACDB_FLAGS_FIB_TIMEOUT 0x00000100 54358bc78c7SXin Chen 544942c5e3cSpl196000 extern uint32_t aac_debug_flags; 545942c5e3cSpl196000 extern int aac_dbflag_on(struct aac_softstate *, int); 546942c5e3cSpl196000 extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...); 54758bc78c7SXin Chen extern void aac_print_fib(struct aac_softstate *, struct aac_slot *); 548942c5e3cSpl196000 549942c5e3cSpl196000 #define AACDB_PRINT(s, lev, ...) { \ 550942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \ 551942c5e3cSpl196000 aac_printf((s), (lev), __VA_ARGS__); } 552942c5e3cSpl196000 553942c5e3cSpl196000 #define AACDB_PRINT_IOCTL(s, ...) { \ 554942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \ 555942c5e3cSpl196000 aac_printf((s), CE_NOTE, __VA_ARGS__); } 556942c5e3cSpl196000 557942c5e3cSpl196000 #define AACDB_PRINT_TRAN(s, ...) { \ 558942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \ 559942c5e3cSpl196000 aac_printf((s), CE_NOTE, __VA_ARGS__); } 560942c5e3cSpl196000 561942c5e3cSpl196000 #define DBCALLED(s, n) { \ 562942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \ 563942c5e3cSpl196000 aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); } 564942c5e3cSpl196000 565942c5e3cSpl196000 #define AACDB_PRINT_SCMD(s, x) { \ 566942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); } 567942c5e3cSpl196000 568942c5e3cSpl196000 #define AACDB_PRINT_AIF(s, x) { \ 569942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); } 570942c5e3cSpl196000 571942c5e3cSpl196000 #define AACDB_PRINT_FIB(s, x) { \ 572942c5e3cSpl196000 if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); } 573942c5e3cSpl196000 574942c5e3cSpl196000 #else /* DEBUG */ 575942c5e3cSpl196000 576942c5e3cSpl196000 #define AACDB_PRINT(s, lev, ...) 577942c5e3cSpl196000 #define AACDB_PRINT_IOCTL(s, ...) 578942c5e3cSpl196000 #define AACDB_PRINT_TRAN(s, ...) 579942c5e3cSpl196000 #define AACDB_PRINT_FIB(s, x) 580942c5e3cSpl196000 #define AACDB_PRINT_SCMD(s, x) 581942c5e3cSpl196000 #define AACDB_PRINT_AIF(s, x) 582942c5e3cSpl196000 #define DBCALLED(s, n) 583942c5e3cSpl196000 584942c5e3cSpl196000 #endif /* DEBUG */ 585942c5e3cSpl196000 586942c5e3cSpl196000 #ifdef __cplusplus 587942c5e3cSpl196000 } 588942c5e3cSpl196000 #endif 589942c5e3cSpl196000 590942c5e3cSpl196000 #endif /* _AAC_H_ */ 591