1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2001 Scott Long 4 * Copyright (c) 2000 BSDi 5 * Copyright (c) 2001-2010 Adaptec, Inc. 6 * Copyright (c) 2010-2012 PMC-Sierra, Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 */ 32 33 #include <sys/bio.h> 34 #if __FreeBSD_version >= 800000 35 #include <sys/callout.h> 36 #endif 37 #include <sys/lock.h> 38 #include <sys/mutex.h> 39 #include <sys/taskqueue.h> 40 #include <sys/selinfo.h> 41 #include <geom/geom_disk.h> 42 43 #define AAC_TYPE_DEVO 1 44 #define AAC_TYPE_ALPHA 2 45 #define AAC_TYPE_BETA 3 46 #define AAC_TYPE_RELEASE 4 47 48 #define AAC_DRIVER_MAJOR_VERSION 3 49 #define AAC_DRIVER_MINOR_VERSION 1 50 #define AAC_DRIVER_BUGFIX_LEVEL 1 51 #define AAC_DRIVER_TYPE AAC_TYPE_RELEASE 52 53 #ifndef AAC_DRIVER_BUILD 54 # define AAC_DRIVER_BUILD 1 55 #endif 56 57 #if __FreeBSD_version <= 601000 58 #define bus_get_dma_tag(x) NULL 59 #endif 60 61 /* **************************** NewBUS interrupt Crock ************************/ 62 #if __FreeBSD_version < 700031 63 #define aac_bus_setup_intr(d, i, f, U, if, ifa, hp) \ 64 bus_setup_intr(d, i, f, if, ifa, hp) 65 #else 66 #define aac_bus_setup_intr bus_setup_intr 67 #endif 68 69 /* **************************** NewBUS CAM Support ****************************/ 70 #if __FreeBSD_version < 700049 71 #define aac_xpt_bus_register(sim, parent, bus) \ 72 xpt_bus_register(sim, bus) 73 #else 74 #define aac_xpt_bus_register xpt_bus_register 75 #endif 76 77 /**************************** Kernel Thread Support ***************************/ 78 #if __FreeBSD_version > 800001 79 #define aac_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 80 kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 81 #define aac_kthread_exit(status) \ 82 kproc_exit(status) 83 #else 84 #define aac_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ 85 kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) 86 #define aac_kthread_exit(status) \ 87 kthread_exit(status) 88 #endif 89 90 /* 91 * Driver Parameter Definitions 92 */ 93 94 /* 95 * We allocate a small set of FIBs for the adapter to use to send us messages. 96 */ 97 #define AAC_ADAPTER_FIBS 8 98 99 /* 100 * The controller reports status events in AIFs. We hang on to a number of 101 * these in order to pass them out to user-space management tools. 102 */ 103 #define AAC_AIFQ_LENGTH 64 104 105 /* 106 * Firmware messages are passed in the printf buffer. 107 */ 108 #define AAC_PRINTF_BUFSIZE 256 109 110 /* 111 * We wait this many seconds for the adapter to come ready if it is still 112 * booting 113 */ 114 #define AAC_BOOT_TIMEOUT (3 * 60) 115 116 /* 117 * Timeout for immediate commands. 118 */ 119 #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 120 121 /* 122 * Timeout for normal commands 123 */ 124 #define AAC_CMD_TIMEOUT 120 /* seconds */ 125 126 /* 127 * Rate at which we periodically check for timed out commands and kick the 128 * controller. 129 */ 130 #define AAC_PERIODIC_INTERVAL 20 /* seconds */ 131 132 #define PASSTHROUGH_BUS 0 133 #define CONTAINER_BUS 1 134 /* 135 * Per-container data structure 136 */ 137 struct aac_container 138 { 139 struct aac_mntobj co_mntobj; 140 int co_found; 141 u_int32_t co_uid; 142 TAILQ_ENTRY(aac_container) co_link; 143 }; 144 145 /* 146 * Per-SIM data structure 147 */ 148 struct aac_cam; 149 struct aac_sim 150 { 151 device_t sim_dev; 152 int TargetsPerBus; 153 int BusNumber; 154 int BusType; 155 int InitiatorBusId; 156 struct aac_softc *aac_sc; 157 struct aac_cam *aac_cam; 158 TAILQ_ENTRY(aac_sim) sim_link; 159 }; 160 161 /* 162 * Per-disk structure 163 */ 164 struct aac_disk 165 { 166 device_t ad_dev; 167 struct aac_softc *ad_controller; 168 struct aac_container *ad_container; 169 struct disk *ad_disk; 170 int ad_flags; 171 #define AAC_DISK_OPEN (1<<0) 172 int ad_cylinders; 173 int ad_heads; 174 int ad_sectors; 175 u_int64_t ad_size; 176 int unit; 177 }; 178 179 /* 180 * Per-command control structure. 181 */ 182 struct aac_command 183 { 184 TAILQ_ENTRY(aac_command) cm_link; /* list linkage */ 185 186 struct aac_softc *cm_sc; /* controller that owns us */ 187 188 struct aac_fib *cm_fib; /* FIB associated with this 189 * command */ 190 u_int64_t cm_fibphys; /* bus address of the FIB */ 191 struct bio *cm_data; /* pointer to data in kernel 192 * space */ 193 u_int32_t cm_datalen; /* data length */ 194 bus_dmamap_t cm_datamap; /* DMA map for bio data */ 195 struct aac_sg_table *cm_sgtable; /* pointer to s/g table in 196 * command */ 197 int cm_flags; 198 #define AAC_CMD_MAPPED (1<<0) /* command has had its data 199 * mapped */ 200 #define AAC_CMD_DATAIN (1<<1) /* command involves data moving 201 * from controller to host */ 202 #define AAC_CMD_DATAOUT (1<<2) /* command involves data moving 203 * from host to controller */ 204 #define AAC_CMD_COMPLETED (1<<3) /* command has been completed */ 205 #define AAC_CMD_TIMEDOUT (1<<4) /* command taken too long */ 206 #define AAC_ON_AACQ_FREE (1<<5) 207 #define AAC_ON_AACQ_READY (1<<6) 208 #define AAC_ON_AACQ_BUSY (1<<7) 209 #define AAC_ON_AACQ_AIF (1<<8) 210 #define AAC_ON_AACQ_NORM (1<<10) 211 #define AAC_ON_AACQ_MASK ((1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<10)) 212 #define AAC_CMD_RESET (1<<9) 213 #define AAC_CMD_FASTRESP (1<<11) 214 #define AAC_CMD_WAIT (1<<12) 215 216 void (* cm_complete)(struct aac_command *cm); 217 union ccb *cm_ccb; 218 time_t cm_timestamp; /* command creation time */ 219 int cm_index; 220 bus_dma_tag_t cm_passthr_dmat; /* passthrough buffer/command 221 * DMA tag */ 222 }; 223 224 struct aac_fibmap { 225 TAILQ_ENTRY(aac_fibmap) fm_link; /* list linkage */ 226 struct aac_fib *aac_fibs; 227 bus_dmamap_t aac_fibmap; 228 struct aac_command *aac_commands; 229 }; 230 231 /* 232 * We gather a number of adapter-visible items into a single structure. 233 * 234 * The ordering of this strucure may be important; we copy the Linux driver: 235 * 236 * Adapter FIBs 237 * Init struct 238 * Queue headers (Comm Area) 239 * Printf buffer 240 * 241 * In addition, we add: 242 * Sync Fib 243 */ 244 struct aac_common { 245 /* fibs for the controller to send us messages */ 246 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 247 248 /* the init structure */ 249 struct aac_adapter_init ac_init; 250 251 /* buffer for text messages from the controller */ 252 char ac_printf[AAC_PRINTF_BUFSIZE]; 253 254 /* fib for synchronous commands */ 255 struct aac_fib ac_sync_fib; 256 257 /* response buffer for SRC (new comm. type1) - must be last element */ 258 u_int32_t ac_host_rrq[0]; 259 }; 260 261 /* 262 * Interface operations 263 */ 264 struct aac_interface 265 { 266 int (*aif_get_fwstatus)(struct aac_softc *sc); 267 void (*aif_qnotify)(struct aac_softc *sc, int qbit); 268 int (*aif_get_istatus)(struct aac_softc *sc); 269 void (*aif_clr_istatus)(struct aac_softc *sc, int mask); 270 void (*aif_set_mailbox)(struct aac_softc *sc, u_int32_t command, 271 u_int32_t arg0, u_int32_t arg1, 272 u_int32_t arg2, u_int32_t arg3); 273 int (*aif_get_mailbox)(struct aac_softc *sc, int mb); 274 void (*aif_set_interrupts)(struct aac_softc *sc, int enable); 275 int (*aif_send_command)(struct aac_softc *sc, struct aac_command *cm); 276 int (*aif_get_outb_queue)(struct aac_softc *sc); 277 void (*aif_set_outb_queue)(struct aac_softc *sc, int index); 278 }; 279 extern struct aac_interface aacraid_src_interface; 280 extern struct aac_interface aacraid_srcv_interface; 281 282 #define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) 283 #define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) 284 #define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) 285 #define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_clr_istatus((sc), \ 286 (mask))) 287 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 288 ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ 289 (arg3))) 290 #define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if.aif_get_mailbox((sc), \ 291 (mb))) 292 #define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 293 0)) 294 #define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 295 1)) 296 #define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if.aif_send_command((sc), (cm))) 297 #define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if.aif_get_outb_queue((sc))) 298 #define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if.aif_set_outb_queue((sc), (idx))) 299 300 #define AAC_MEM0_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag0, \ 301 sc->aac_bhandle0, reg, val) 302 #define AAC_MEM0_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag0, \ 303 sc->aac_bhandle0, reg) 304 #define AAC_MEM0_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag0, \ 305 sc->aac_bhandle0, reg, val) 306 #define AAC_MEM0_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag0, \ 307 sc->aac_bhandle0, reg) 308 #define AAC_MEM0_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag0, \ 309 sc->aac_bhandle0, reg, val) 310 #define AAC_MEM0_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag0, \ 311 sc->aac_bhandle0, reg) 312 313 #define AAC_MEM1_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag1, \ 314 sc->aac_bhandle1, reg, val) 315 #define AAC_MEM1_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag1, \ 316 sc->aac_bhandle1, reg) 317 #define AAC_MEM1_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag1, \ 318 sc->aac_bhandle1, reg, val) 319 #define AAC_MEM1_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag1, \ 320 sc->aac_bhandle1, reg) 321 #define AAC_MEM1_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag1, \ 322 sc->aac_bhandle1, reg, val) 323 #define AAC_MEM1_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag1, \ 324 sc->aac_bhandle1, reg) 325 326 /* fib context (IOCTL) */ 327 struct aac_fib_context { 328 u_int32_t unique; 329 int ctx_idx; 330 int ctx_wrap; 331 struct aac_fib_context *next, *prev; 332 }; 333 334 /* 335 * Per-controller structure. 336 */ 337 struct aac_softc 338 { 339 /* bus connections */ 340 device_t aac_dev; 341 struct resource *aac_regs_res0, *aac_regs_res1; /* reg. if. window */ 342 int aac_regs_rid0, aac_regs_rid1; /* resource ID */ 343 bus_space_handle_t aac_bhandle0, aac_bhandle1; /* bus space handle */ 344 bus_space_tag_t aac_btag0, aac_btag1; /* bus space tag */ 345 bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ 346 bus_dma_tag_t aac_buffer_dmat; /* data buffer/command 347 * DMA tag */ 348 struct resource *aac_irq; /* interrupt */ 349 int aac_irq_rid; 350 void *aac_intr; /* interrupt handle */ 351 eventhandler_tag eh; 352 #if __FreeBSD_version >= 800000 353 struct callout aac_daemontime; /* clock daemon callout */ 354 #else 355 struct callout_handle timeout_id; /* timeout handle */ 356 #endif 357 358 /* controller features, limits and status */ 359 int aac_state; 360 #define AAC_STATE_SUSPEND (1<<0) 361 #define AAC_STATE_UNUSED0 (1<<1) 362 #define AAC_STATE_INTERRUPTS_ON (1<<2) 363 #define AAC_STATE_AIF_SLEEPER (1<<3) 364 #define AAC_STATE_RESET (1<<4) 365 struct FsaRevision aac_revision; 366 367 /* controller hardware interface */ 368 int aac_hwif; 369 #define AAC_HWIF_SRC 5 370 #define AAC_HWIF_SRCV 6 371 #define AAC_HWIF_UNKNOWN -1 372 bus_dma_tag_t aac_common_dmat; /* common structure 373 * DMA tag */ 374 bus_dmamap_t aac_common_dmamap; /* common structure 375 * DMA map */ 376 struct aac_common *aac_common; 377 u_int32_t aac_common_busaddr; 378 u_int32_t aac_host_rrq_idx; 379 struct aac_interface aac_if; 380 381 /* command/fib resources */ 382 bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */ 383 TAILQ_HEAD(,aac_fibmap) aac_fibmap_tqh; 384 u_int total_fibs; 385 struct aac_command *aac_commands; 386 387 /* command management */ 388 TAILQ_HEAD(,aac_command) aac_free; /* command structures 389 * available for reuse */ 390 TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for 391 * controller resources */ 392 TAILQ_HEAD(,aac_command) aac_busy; 393 TAILQ_HEAD(,aac_event) aac_ev_cmfree; 394 struct bio_queue_head aac_bioq; 395 396 struct aac_qstat aac_qstat[AACQ_COUNT]; /* queue statistics */ 397 398 /* connected containters */ 399 TAILQ_HEAD(,aac_container) aac_container_tqh; 400 struct mtx aac_container_lock; 401 402 /* 403 * The general I/O lock. This protects the sync fib, the lists, the 404 * queues, and the registers. 405 */ 406 struct mtx aac_io_lock; 407 408 struct intr_config_hook aac_ich; 409 410 /* sync. transfer mode */ 411 struct aac_command *aac_sync_cm; 412 413 /* management interface */ 414 struct cdev *aac_dev_t; 415 struct mtx aac_aifq_lock; 416 struct aac_fib aac_aifq[AAC_AIFQ_LENGTH]; 417 int aifq_idx; 418 int aifq_filled; 419 int aif_pending; 420 struct aac_fib_context *fibctx; 421 struct selinfo rcv_select; 422 struct proc *aifthread; 423 int aifflags; 424 #define AAC_AIFFLAGS_RUNNING (1 << 0) 425 #define AAC_AIFFLAGS_AIF (1 << 1) 426 #define AAC_AIFFLAGS_EXIT (1 << 2) 427 #define AAC_AIFFLAGS_EXITED (1 << 3) 428 #define AAC_AIFFLAGS_PRINTF (1 << 4) 429 #define AAC_AIFFLAGS_ALLOCFIBS (1 << 5) 430 #define AAC_AIFFLAGS_PENDING (AAC_AIFFLAGS_AIF | AAC_AIFFLAGS_PRINTF | \ 431 AAC_AIFFLAGS_ALLOCFIBS) 432 u_int32_t flags; 433 #define AAC_FLAGS_PERC2QC (1 << 0) 434 #define AAC_FLAGS_ENABLE_CAM (1 << 1) /* No SCSI passthrough */ 435 #define AAC_FLAGS_CAM_NORESET (1 << 2) /* Fake SCSI resets */ 436 #define AAC_FLAGS_CAM_PASSONLY (1 << 3) /* Only create pass devices */ 437 #define AAC_FLAGS_SG_64BIT (1 << 4) /* Use 64-bit S/G addresses */ 438 #define AAC_FLAGS_4GB_WINDOW (1 << 5) /* Device can access host mem 439 * 2GB-4GB range */ 440 #define AAC_FLAGS_NO4GB (1 << 6) /* Can't access host mem >2GB */ 441 #define AAC_FLAGS_256FIBS (1 << 7) /* Can only do 256 commands */ 442 #define AAC_FLAGS_BROKEN_MEMMAP (1 << 8) /* Broken HostPhysMemPages */ 443 #define AAC_FLAGS_SLAVE (1 << 9) 444 #define AAC_FLAGS_MASTER (1 << 10) 445 #define AAC_FLAGS_NEW_COMM (1 << 11) /* New comm. interface supported */ 446 #define AAC_FLAGS_RAW_IO (1 << 12) /* Raw I/O interface */ 447 #define AAC_FLAGS_ARRAY_64BIT (1 << 13) /* 64-bit array size */ 448 #define AAC_FLAGS_LBA_64BIT (1 << 14) /* 64-bit LBA support */ 449 #define AAC_QUEUE_FRZN (1 << 15) /* Freeze the processing of 450 * commands on the queue. */ 451 #define AAC_FLAGS_NEW_COMM_TYPE1 (1 << 16) /* New comm. type1 supported */ 452 #define AAC_FLAGS_NEW_COMM_TYPE2 (1 << 17) /* New comm. type2 supported */ 453 #define AAC_FLAGS_NEW_COMM_TYPE34 (1 << 18) /* New comm. type3/4 */ 454 #define AAC_FLAGS_SYNC_MODE (1 << 18) /* Sync. transfer mode */ 455 u_int32_t hint_flags; /* driver parameters */ 456 int sim_freezed; /* flag for sim_freeze/release */ 457 u_int32_t supported_options; 458 u_int32_t scsi_method_id; 459 TAILQ_HEAD(,aac_sim) aac_sim_tqh; 460 461 u_int32_t aac_max_fibs; /* max. FIB count */ 462 u_int32_t aac_max_fibs_alloc; /* max. alloc. per alloc_commands() */ 463 u_int32_t aac_max_fib_size; /* max. FIB size */ 464 u_int32_t aac_sg_tablesize; /* max. sg count from host */ 465 u_int32_t aac_max_sectors; /* max. I/O size from host (blocks) */ 466 u_int32_t aac_feature_bits; /* feature bits from suppl. info */ 467 u_int32_t aac_support_opt2; /* supp. options from suppl. info */ 468 u_int32_t aac_max_aif; /* max. AIF count */ 469 #define AAC_CAM_TARGET_WILDCARD ~0 470 void (*cam_rescan_cb)(struct aac_softc *, uint32_t, 471 uint32_t); 472 u_int32_t DebugFlags; /* Debug print flags bitmap */ 473 u_int32_t DebugOffset; /* Offset from DPMEM start */ 474 u_int32_t DebugHeaderSize; /* Size of debug header */ 475 u_int32_t FwDebugFlags; /* FW Debug Flags */ 476 u_int32_t FwDebugBufferSize; /* FW Debug Buffer size */ 477 }; 478 479 /* 480 * Event callback mechanism for the driver 481 */ 482 #define AAC_EVENT_NONE 0x00 483 #define AAC_EVENT_CMFREE 0x01 484 #define AAC_EVENT_MASK 0xff 485 #define AAC_EVENT_REPEAT 0x100 486 487 typedef void aac_event_cb_t(struct aac_softc *sc, struct aac_event *event, 488 void *arg); 489 struct aac_event { 490 TAILQ_ENTRY(aac_event) ev_links; 491 int ev_type; 492 aac_event_cb_t *ev_callback; 493 void *ev_arg; 494 }; 495 496 /* 497 * Public functions 498 */ 499 extern void aacraid_free(struct aac_softc *sc); 500 extern int aacraid_attach(struct aac_softc *sc); 501 extern int aacraid_detach(device_t dev); 502 extern int aacraid_shutdown(device_t dev); 503 extern int aacraid_suspend(device_t dev); 504 extern int aacraid_resume(device_t dev); 505 extern void aacraid_new_intr_type1(void *arg); 506 extern void aacraid_submit_bio(struct bio *bp); 507 extern void aacraid_biodone(struct bio *bp); 508 extern void aacraid_startio(struct aac_softc *sc); 509 extern int aacraid_alloc_command(struct aac_softc *sc, 510 struct aac_command **cmp); 511 extern void aacraid_release_command(struct aac_command *cm); 512 extern void aacraid_add_event(struct aac_softc *sc, struct aac_event 513 *event); 514 extern void aacraid_map_command_sg(void *arg, bus_dma_segment_t *segs, 515 int nseg, int error); 516 extern int aacraid_wait_command(struct aac_command *cmp); 517 518 /* #define AACRAID_DEBUG */ 519 520 #ifdef AACRAID_DEBUG 521 # define fwprintf(sc, flags, fmt, args...) \ 522 aacraid_fw_printf(sc, flags, "%s: " fmt, __func__, ##args); 523 524 extern void aacraid_print_queues(struct aac_softc *sc); 525 extern void aacraid_print_fib(struct aac_softc *sc, struct aac_fib *fib, 526 const char *caller); 527 extern void aacraid_print_aif(struct aac_softc *sc, 528 struct aac_aif_command *aif); 529 530 #define AAC_PRINT_FIB(sc, fib) aacraid_print_fib(sc, fib, __func__) 531 532 #else 533 # define fwprintf(sc, flags, fmt, args...) 534 535 # define aacraid_print_queues(sc) 536 537 # define AAC_PRINT_FIB(sc, fib) 538 # define aacraid_print_aif(sc, aac_aif_command) 539 #endif 540 541 struct aac_code_lookup { 542 char *string; 543 u_int32_t code; 544 }; 545 546 /* 547 * Queue primitives for driver queues. 548 */ 549 #define AACQ_ADD(sc, qname) \ 550 do { \ 551 struct aac_qstat *qs; \ 552 \ 553 qs = &(sc)->aac_qstat[qname]; \ 554 \ 555 qs->q_length++; \ 556 if (qs->q_length > qs->q_max) \ 557 qs->q_max = qs->q_length; \ 558 } while (0) 559 560 #define AACQ_REMOVE(sc, qname) (sc)->aac_qstat[qname].q_length-- 561 #define AACQ_INIT(sc, qname) \ 562 do { \ 563 sc->aac_qstat[qname].q_length = 0; \ 564 sc->aac_qstat[qname].q_max = 0; \ 565 } while (0) 566 567 568 #define AACQ_COMMAND_QUEUE(name, index) \ 569 static __inline void \ 570 aac_initq_ ## name (struct aac_softc *sc) \ 571 { \ 572 TAILQ_INIT(&sc->aac_ ## name); \ 573 AACQ_INIT(sc, index); \ 574 } \ 575 static __inline void \ 576 aac_enqueue_ ## name (struct aac_command *cm) \ 577 { \ 578 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 579 printf("command %p is on another queue, flags = %#x\n", \ 580 cm, cm->cm_flags); \ 581 panic("command is on another queue"); \ 582 } \ 583 TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 584 cm->cm_flags |= AAC_ON_ ## index; \ 585 AACQ_ADD(cm->cm_sc, index); \ 586 } \ 587 static __inline void \ 588 aac_requeue_ ## name (struct aac_command *cm) \ 589 { \ 590 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 591 printf("command %p is on another queue, flags = %#x\n", \ 592 cm, cm->cm_flags); \ 593 panic("command is on another queue"); \ 594 } \ 595 TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 596 cm->cm_flags |= AAC_ON_ ## index; \ 597 AACQ_ADD(cm->cm_sc, index); \ 598 } \ 599 static __inline struct aac_command * \ 600 aac_dequeue_ ## name (struct aac_softc *sc) \ 601 { \ 602 struct aac_command *cm; \ 603 \ 604 if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) { \ 605 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 606 printf("command %p not in queue, flags = %#x, " \ 607 "bit = %#x\n", cm, cm->cm_flags, \ 608 AAC_ON_ ## index); \ 609 panic("command not in queue"); \ 610 } \ 611 TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link); \ 612 cm->cm_flags &= ~AAC_ON_ ## index; \ 613 AACQ_REMOVE(sc, index); \ 614 } \ 615 return(cm); \ 616 } \ 617 static __inline void \ 618 aac_remove_ ## name (struct aac_command *cm) \ 619 { \ 620 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 621 printf("command %p not in queue, flags = %#x, " \ 622 "bit = %#x\n", cm, cm->cm_flags, \ 623 AAC_ON_ ## index); \ 624 panic("command not in queue"); \ 625 } \ 626 TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 627 cm->cm_flags &= ~AAC_ON_ ## index; \ 628 AACQ_REMOVE(cm->cm_sc, index); \ 629 } \ 630 struct hack 631 632 AACQ_COMMAND_QUEUE(free, AACQ_FREE); 633 AACQ_COMMAND_QUEUE(ready, AACQ_READY); 634 AACQ_COMMAND_QUEUE(busy, AACQ_BUSY); 635 636 static __inline void 637 aac_print_printf(struct aac_softc *sc) 638 { 639 /* 640 * XXX We have the ability to read the length of the printf string 641 * from out of the mailboxes. 642 */ 643 device_printf(sc->aac_dev, "**Monitor** %.*s", AAC_PRINTF_BUFSIZE, 644 sc->aac_common->ac_printf); 645 sc->aac_common->ac_printf[0] = 0; 646 AAC_QNOTIFY(sc, AAC_DB_PRINTF); 647 } 648 649 static __inline int 650 aac_alloc_sync_fib(struct aac_softc *sc, struct aac_fib **fib) 651 { 652 653 mtx_assert(&sc->aac_io_lock, MA_OWNED); 654 *fib = &sc->aac_common->ac_sync_fib; 655 return (0); 656 } 657 658 static __inline void 659 aac_release_sync_fib(struct aac_softc *sc) 660 { 661 662 mtx_assert(&sc->aac_io_lock, MA_OWNED); 663 } 664