1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * Copyright 2005-06 Adaptec, Inc. 8 * Copyright (c) 2005-06 Adaptec Inc., Achim Leubner 9 * Copyright (c) 2000 Michael Smith 10 * Copyright (c) 2001 Scott Long 11 * Copyright (c) 2000 BSDi 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.47 2005/10/08 15:55:09 scottl Exp $ 36 */ 37 38 #ifndef _AAC_H_ 39 #define _AAC_H_ 40 41 #pragma ident "%Z%%M% %I% %E% SMI" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #define AAC_ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y)) 48 49 #define AAC_TYPE_DEVO 1 50 #define AAC_TYPE_ALPHA 2 51 #define AAC_TYPE_BETA 3 52 #define AAC_TYPE_RELEASE 4 53 54 #ifndef AAC_DRIVER_BUILD 55 #define AAC_DRIVER_BUILD 1 56 #endif 57 58 #define AAC_DRIVER_MAJOR_VERSION 2 59 #define AAC_DRIVER_MINOR_VERSION 2 60 #define AAC_DRIVER_BUGFIX_LEVEL 2 61 #define AAC_DRIVER_TYPE AAC_TYPE_RELEASE 62 63 #define STR(s) # s 64 #define AAC_VERSION(a, b, c) STR(a.b.c) 65 #define AAC_DRIVER_VERSION AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \ 66 AAC_DRIVER_MINOR_VERSION, \ 67 AAC_DRIVER_BUGFIX_LEVEL) 68 69 #define AACOK 0 70 #define AACERR -1 71 72 #define AAC_MAX_ADAPTERS 64 73 74 /* Definitions for mode sense */ 75 #ifndef SD_MODE_SENSE_PAGE3_CODE 76 #define SD_MODE_SENSE_PAGE3_CODE 0x03 77 #endif 78 79 #ifndef SD_MODE_SENSE_PAGE4_CODE 80 #define SD_MODE_SENSE_PAGE4_CODE 0x04 81 #endif 82 83 #ifndef SCMD_SYNCHRONIZE_CACHE 84 #define SCMD_SYNCHRONIZE_CACHE 0x35 85 #endif 86 87 /* 88 * The controller reports status events in AIFs. We hang on to a number of 89 * these in order to pass them out to user-space management tools. 90 */ 91 #define AAC_AIFQ_LENGTH 64 92 93 #ifdef __x86 94 #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 95 #else 96 #define AAC_IMMEDIATE_TIMEOUT 60 /* seconds */ 97 #endif 98 #define AAC_FWUP_TIMEOUT 180 /* wait up to 3 minutes */ 99 #define AAC_IOCTL_TIMEOUT 180 /* wait up to 3 minutes */ 100 101 /* Adapter hardware interface types */ 102 #define AAC_HWIF_UNKNOWN 0 103 #define AAC_HWIF_I960RX 1 104 #define AAC_HWIF_RKT 2 105 106 #define AAC_TYPE_UNKNOWN 0 107 #define AAC_TYPE_SCSI 1 108 #define AAC_TYPE_SATA 2 109 #define AAC_TYPE_SAS 3 110 111 #define AAC_LS32(d) ((uint32_t)((d) & 0xffffffffull)) 112 #define AAC_MS32(d) ((uint32_t)((d) >> 32)) 113 #define AAC_LO32(p64) ((uint32_t *)(p64)) 114 #define AAC_HI32(p64) ((uint32_t *)(p64) + 1) 115 116 /* 117 * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io 118 * to be served before async FIB io, see aac_start_waiting_io(). 119 * So that io requests sent by interactive userland commands get 120 * responded asap. 121 */ 122 enum aac_cmdq { 123 AAC_CMDQ_SYNC, /* sync FIB queue */ 124 AAC_CMDQ_ASYNC, /* async FIB queue */ 125 AAC_CMDQ_NUM 126 }; 127 128 /* 129 * IO command flags 130 */ 131 #define AAC_IOCMD_SYNC (1 << AAC_CMDQ_SYNC) 132 #define AAC_IOCMD_ASYNC (1 << AAC_CMDQ_ASYNC) 133 #define AAC_IOCMD_OUTSTANDING (1 << AAC_CMDQ_NUM) 134 #define AAC_IOCMD_ALL (AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \ 135 AAC_IOCMD_OUTSTANDING) 136 137 struct aac_cmd_queue { 138 struct aac_cmd *q_head; /* also as the header of aac_cmd */ 139 struct aac_cmd *q_tail; 140 }; 141 142 struct aac_card_type { 143 uint16_t vendor; /* PCI Vendor ID */ 144 uint16_t device; /* PCI Device ID */ 145 uint16_t subvendor; /* PCI Subsystem Vendor ID */ 146 uint16_t subsys; /* PCI Subsystem ID */ 147 uint16_t hwif; /* card chip type: i960 or Rocket */ 148 uint16_t quirks; /* card odd limits */ 149 uint16_t type; /* hard drive type */ 150 char *vid; /* ASCII data for INQUIRY command vendor id */ 151 char *desc; /* ASCII data for INQUIRY command product id */ 152 }; 153 154 /* Array description */ 155 struct aac_container { 156 uint8_t valid; 157 uint32_t cid; /* container id */ 158 uint32_t uid; /* container uid */ 159 uint64_t size; /* in block */ 160 uint8_t locked; 161 uint8_t deleted; 162 uint8_t reset; /* container is being reseted */ 163 int ncmds[AAC_CMDQ_NUM]; /* outstanding cmds of the device */ 164 int throttle[AAC_CMDQ_NUM]; /* hold IO cmds for the device */ 165 }; 166 167 /* 168 * The firmware can support a lot of outstanding commands. Each aac_slot 169 * is corresponding to one of such commands. It records the command and 170 * associated DMA resource for FIB command. 171 */ 172 struct aac_slot { 173 struct aac_slot *next; /* next slot in the free slot list */ 174 int index; /* index of this slot */ 175 ddi_acc_handle_t fib_acc_handle; 176 ddi_dma_handle_t fib_dma_handle; 177 uint64_t fib_phyaddr; /* physical address of FIB memory */ 178 struct aac_cmd *acp; /* command using this slot */ 179 struct aac_fib *fibp; /* virtual address of FIB memory */ 180 }; 181 182 /* Flags for attach tracking */ 183 #define AAC_ATTACH_SOFTSTATE_ALLOCED (1 << 0) 184 #define AAC_ATTACH_CARD_DETECTED (1 << 1) 185 #define AAC_ATTACH_PCI_MEM_MAPPED (1 << 2) 186 #define AAC_ATTACH_KMUTEX_INITED (1 << 3) 187 #define AAC_ATTACH_HARD_INTR_SETUP (1 << 4) 188 #define AAC_ATTACH_SOFT_INTR_SETUP (1 << 5) 189 #define AAC_ATTACH_SCSI_TRAN_SETUP (1 << 6) 190 #define AAC_ATTACH_COMM_SPACE_SETUP (1 << 7) 191 #define AAC_ATTACH_CREATE_DEVCTL (1 << 8) 192 #define AAC_ATTACH_CREATE_SCSI (1 << 9) 193 194 /* Driver running states */ 195 #define AAC_STATE_STOPPED 0 196 #define AAC_STATE_RUN (1 << 0) 197 #define AAC_STATE_RESET (1 << 1) 198 #define AAC_STATE_QUIESCED (1 << 2) 199 #define AAC_STATE_DEAD (1 << 3) 200 201 /* 202 * Flags for aac firmware 203 * Note: Quirks are only valid for the older cards. These cards only supported 204 * old comm. Thus they are not valid for any cards that support new comm. 205 */ 206 #define AAC_FLAGS_SG_64BIT (1 << 0) /* Use 64-bit S/G addresses */ 207 #define AAC_FLAGS_4GB_WINDOW (1 << 1) /* Can access host mem 2-4GB range */ 208 #define AAC_FLAGS_NO4GB (1 << 2) /* quirk: FIB addresses must reside */ 209 /* between 0x2000 & 0x7FFFFFFF */ 210 #define AAC_FLAGS_256FIBS (1 << 3) /* quirk: Can only do 256 commands */ 211 #define AAC_FLAGS_NEW_COMM (1 << 4) /* New comm. interface supported */ 212 #define AAC_FLAGS_RAW_IO (1 << 5) /* Raw I/O interface */ 213 #define AAC_FLAGS_ARRAY_64BIT (1 << 6) /* 64-bit array size */ 214 #define AAC_FLAGS_LBA_64BIT (1 << 7) /* 64-bit LBA supported */ 215 #define AAC_FLAGS_17SG (1 << 8) /* quirk: 17 scatter gather maximum */ 216 #define AAC_FLAGS_34SG (1 << 9) /* quirk: 34 scatter gather maximum */ 217 218 struct aac_softstate; 219 struct aac_interface { 220 int (*aif_get_fwstatus)(struct aac_softstate *); 221 int (*aif_get_mailbox)(struct aac_softstate *, int); 222 void (*aif_set_mailbox)(struct aac_softstate *, uint32_t, 223 uint32_t, uint32_t, uint32_t, uint32_t); 224 }; 225 226 struct aac_fib_context { 227 uint32_t unique; 228 int ctx_idx; 229 int ctx_filled; /* aifq is full for this fib context */ 230 struct aac_fib_context *next, *prev; 231 }; 232 233 typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *); 234 235 #define AAC_VENDOR_LEN 8 236 #define AAC_PRODUCT_LEN 16 237 238 struct aac_softstate { 239 int card; /* index to aac_cards */ 240 uint16_t hwif; /* card chip type: i960 or Rocket */ 241 uint16_t vendid; /* vendor id */ 242 uint16_t subvendid; /* sub vendor id */ 243 uint16_t devid; /* device id */ 244 uint16_t subsysid; /* sub system id */ 245 char vendor_name[AAC_VENDOR_LEN + 1]; 246 char product_name[AAC_PRODUCT_LEN + 1]; 247 uint32_t support_opt; /* firmware features */ 248 uint32_t atu_size; /* actual size of PCI mem space */ 249 uint32_t map_size; /* mapped PCI mem space size */ 250 uint32_t map_size_min; /* minimum size of PCI mem that must be */ 251 /* mapped to address the card */ 252 int flags; /* firmware features enabled */ 253 int instance; 254 dev_info_t *devinfo_p; 255 int slen; 256 257 /* DMA attributes */ 258 ddi_dma_attr_t buf_dma_attr; 259 ddi_dma_attr_t addr_dma_attr; 260 261 /* PCI spaces */ 262 ddi_acc_handle_t pci_mem_handle; 263 char *pci_mem_base_vaddr; 264 uint32_t pci_mem_base_paddr; 265 266 struct aac_interface aac_if; /* adapter hardware interface */ 267 268 struct aac_slot sync_slot; /* sync FIB */ 269 270 /* Communication space */ 271 struct aac_comm_space *comm_space; 272 ddi_acc_handle_t comm_space_acc_handle; 273 ddi_dma_handle_t comm_space_dma_handle; 274 uint32_t comm_space_phyaddr; 275 276 /* Old Comm. interface: message queues */ 277 struct aac_queue_table *qtablep; 278 struct aac_queue_entry *qentries[AAC_QUEUE_COUNT]; 279 280 /* New Comm. interface */ 281 uint32_t aac_max_fibs; /* max. FIB count */ 282 uint32_t aac_max_fib_size; /* max. FIB size */ 283 uint32_t aac_sg_tablesize; /* max. sg count from host */ 284 uint32_t aac_max_sectors; /* max. I/O size from host (blocks) */ 285 286 aac_cmd_fib_t aac_cmd_fib; /* IO cmd FIB construct function */ 287 aac_cmd_fib_t aac_cmd_fib_scsi; /* SRB construct function */ 288 289 ddi_iblock_cookie_t iblock_cookie; 290 ddi_softintr_t softint_id; /* soft intr */ 291 292 kmutex_t io_lock; 293 int state; /* driver state */ 294 295 struct aac_container containers[AAC_MAX_LD]; 296 int container_count; /* max container id + 1 */ 297 298 /* 299 * Command queues 300 * Each aac command flows through wait(or wait_sync) queue, 301 * busy queue, and complete queue sequentially. 302 */ 303 struct aac_cmd_queue q_wait[AAC_CMDQ_NUM]; 304 struct aac_cmd_queue q_busy; /* outstanding cmd queue */ 305 kmutex_t q_comp_mutex; 306 struct aac_cmd_queue q_comp; /* completed io requests */ 307 308 /* I/O slots and FIBs */ 309 int total_slots; /* total slots allocated */ 310 int total_fibs; /* total FIBs allocated */ 311 struct aac_slot *io_slot; /* static list for allocated slots */ 312 struct aac_slot *free_io_slot_head; 313 314 timeout_id_t timeout_id; /* for timeout daemon */ 315 316 kcondvar_t event; /* for ioctl_send_fib() and sync IO */ 317 318 int bus_ncmds[AAC_CMDQ_NUM]; /* total outstanding async cmds */ 319 int bus_throttle[AAC_CMDQ_NUM]; /* hold IO cmds for the bus */ 320 int ndrains; /* number of draining threads */ 321 timeout_id_t drain_timeid; /* for outstanding cmd drain */ 322 kcondvar_t drain_cv; /* for quiesce drain */ 323 324 /* AIF */ 325 kmutex_t aifq_mutex; /* for AIF queue aifq */ 326 kcondvar_t aifv; 327 union aac_fib_align aifq[AAC_AIFQ_LENGTH]; 328 int aifq_idx; /* slot for next new AIF */ 329 int aifq_wrap; /* AIF queue has ever been wrapped */ 330 struct aac_fib_context *fibctx; 331 int devcfg_wait_on; /* AIF event waited for rescan */ 332 333 int fm_capabilities; 334 335 #ifdef DEBUG 336 /* UART trace printf variables */ 337 uint32_t debug_flags; /* debug print flags bitmap */ 338 uint32_t debug_fw_flags; /* FW debug flags */ 339 uint32_t debug_buf_offset; /* offset from DPMEM start */ 340 uint32_t debug_buf_size; /* FW debug buffer size in bytes */ 341 uint32_t debug_header_size; /* size of debug header */ 342 #endif 343 }; 344 345 /* 346 * The following data are kept stable because they are only written at driver 347 * initialization, and we do not allow them changed otherwise even at driver 348 * re-initialization. 349 */ 350 _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \ 351 buf_dma_attr pci_mem_handle pci_mem_base_vaddr \ 352 comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \ 353 aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags})) 354 355 /* 356 * Scatter-gather list structure defined by HBA hardware 357 */ 358 struct aac_sge { 359 uint32_t bcount; /* byte count */ 360 union { 361 uint32_t ad32; /* 32 bit address */ 362 struct { 363 uint32_t lo; 364 uint32_t hi; 365 } ad64; /* 64 bit address */ 366 } addr; 367 }; 368 369 /* aac_cmd flags */ 370 #define AAC_CMD_CONSISTENT (1 << 0) 371 #define AAC_CMD_DMA_PARTIAL (1 << 1) 372 #define AAC_CMD_DMA_VALID (1 << 2) 373 #define AAC_CMD_BUF_READ (1 << 3) 374 #define AAC_CMD_BUF_WRITE (1 << 4) 375 #define AAC_CMD_SYNC (1 << 5) /* use sync FIB */ 376 #define AAC_CMD_NO_INTR (1 << 6) /* poll IO, no intr */ 377 #define AAC_CMD_NO_CB (1 << 7) /* sync IO, no callback */ 378 #define AAC_CMD_NTAG (1 << 8) 379 #define AAC_CMD_CMPLT (1 << 9) /* cmd exec'ed by driver/fw */ 380 #define AAC_CMD_ABORT (1 << 10) 381 #define AAC_CMD_TIMEOUT (1 << 11) 382 #define AAC_CMD_ERR (1 << 12) 383 384 struct aac_cmd { 385 /* 386 * Note: should be the first member for aac_cmd_queue to work 387 * correctly. 388 */ 389 struct aac_cmd *next; 390 struct aac_cmd *prev; 391 392 struct scsi_pkt *pkt; 393 int cmdlen; 394 int flags; 395 uint32_t timeout; /* time when the cmd should have completed */ 396 struct buf *bp; 397 ddi_dma_handle_t buf_dma_handle; 398 399 /* For non-aligned buffer and SRB */ 400 caddr_t abp; 401 ddi_acc_handle_t abh; 402 403 /* Data transfer state */ 404 ddi_dma_cookie_t cookie; 405 uint_t left_cookien; 406 uint_t cur_win; 407 uint_t total_nwin; 408 size_t total_xfer; 409 uint64_t blkno; 410 uint32_t bcount; /* buffer size in byte */ 411 struct aac_sge *sgt; /* sg table */ 412 413 /* FIB construct function */ 414 aac_cmd_fib_t aac_cmd_fib; 415 /* Call back function for completed command */ 416 void (*ac_comp)(struct aac_softstate *, struct aac_cmd *); 417 418 struct aac_slot *slotp; /* slot used by this command */ 419 struct aac_container *dvp; /* target device */ 420 421 /* FIB for this IO command */ 422 int fib_size; /* size of the FIB xferred to/from the card */ 423 struct aac_fib *fibp; 424 }; 425 426 #ifdef DEBUG 427 428 #define AACDB_FLAGS_MASK 0x0000ffff 429 #define AACDB_FLAGS_KERNEL_PRINT 0x00000001 430 #define AACDB_FLAGS_FW_PRINT 0x00000002 431 #define AACDB_FLAGS_NO_HEADERS 0x00000004 432 433 #define AACDB_FLAGS_MISC 0x00000010 434 #define AACDB_FLAGS_FUNC1 0x00000020 435 #define AACDB_FLAGS_FUNC2 0x00000040 436 #define AACDB_FLAGS_SCMD 0x00000080 437 #define AACDB_FLAGS_AIF 0x00000100 438 #define AACDB_FLAGS_FIB 0x00000200 439 #define AACDB_FLAGS_IOCTL 0x00000400 440 441 extern uint32_t aac_debug_flags; 442 extern int aac_dbflag_on(struct aac_softstate *, int); 443 extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...); 444 extern void aac_print_fib(struct aac_softstate *, struct aac_fib *); 445 446 #define AACDB_PRINT(s, lev, ...) { \ 447 if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \ 448 aac_printf((s), (lev), __VA_ARGS__); } 449 450 #define AACDB_PRINT_IOCTL(s, ...) { \ 451 if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \ 452 aac_printf((s), CE_NOTE, __VA_ARGS__); } 453 454 #define AACDB_PRINT_TRAN(s, ...) { \ 455 if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \ 456 aac_printf((s), CE_NOTE, __VA_ARGS__); } 457 458 #define DBCALLED(s, n) { \ 459 if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \ 460 aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); } 461 462 #define AACDB_PRINT_SCMD(s, x) { \ 463 if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); } 464 465 #define AACDB_PRINT_AIF(s, x) { \ 466 if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); } 467 468 #define AACDB_PRINT_FIB(s, x) { \ 469 if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); } 470 471 #else /* DEBUG */ 472 473 #define AACDB_PRINT(s, lev, ...) 474 #define AACDB_PRINT_IOCTL(s, ...) 475 #define AACDB_PRINT_TRAN(s, ...) 476 #define AACDB_PRINT_FIB(s, x) 477 #define AACDB_PRINT_SCMD(s, x) 478 #define AACDB_PRINT_AIF(s, x) 479 #define DBCALLED(s, n) 480 481 #endif /* DEBUG */ 482 483 #ifdef __cplusplus 484 } 485 #endif 486 487 #endif /* _AAC_H_ */ 488