1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2001 Scott Long 4 * Copyright (c) 2000 BSDi 5 * Copyright (c) 2001 Adaptec, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.4.2.7 2003/04/08 13:22:08 scottl Exp $ 30 * $DragonFly: src/sys/dev/raid/aac/aacvar.h,v 1.22 2008/06/10 17:20:48 dillon Exp $ 31 */ 32 33 #include <sys/buf.h> 34 #include <sys/buf2.h> 35 #include <sys/eventhandler.h> 36 #include <sys/lock.h> 37 #include <sys/event.h> 38 #include <sys/taskqueue.h> 39 #include <sys/thread2.h> 40 41 /* 42 * Driver Parameter Definitions 43 */ 44 45 /* 46 * The firmware interface allows for a 16-bit s/g list length. We limit 47 * ourselves to a reasonable maximum and ensure alignment. 48 */ 49 #define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ 50 51 /* 52 * We allocate a small set of FIBs for the adapter to use to send us messages. 53 */ 54 #define AAC_ADAPTER_FIBS 8 55 56 /* 57 * FIBs are allocated in page-size chunks and can grow up to the 512 58 * limit imposed by the hardware. 59 */ 60 #define AAC_PREALLOCATE_FIBS 128 61 #define AAC_NUM_MGT_FIB 8 62 /* 63 * The controller reports status events in AIFs. We hang on to a number of 64 * these in order to pass them out to user-space management tools. 65 */ 66 #define AAC_AIFQ_LENGTH 64 67 68 /* 69 * Firmware messages are passed in the kprintf buffer. 70 */ 71 #define AAC_PRINTF_BUFSIZE 256 72 73 /* 74 * We wait this many seconds for the adapter to come ready if it is still 75 * booting 76 */ 77 #define AAC_BOOT_TIMEOUT (3 * 60) 78 79 /* 80 * Timeout for immediate commands. 81 */ 82 #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 83 84 /* 85 * Timeout for normal commands 86 */ 87 #define AAC_CMD_TIMEOUT 30 /* seconds */ 88 89 /* 90 * Rate at which we periodically check for timed out commands and kick the 91 * controller. 92 */ 93 #define AAC_PERIODIC_INTERVAL 20 /* seconds */ 94 95 /* 96 * Character device major numbers. 97 */ 98 #define AAC_DISK_MAJOR 200 99 100 /* 101 * Per-container data structure 102 */ 103 struct aac_container 104 { 105 struct aac_mntobj co_mntobj; 106 device_t co_disk; 107 int co_found; 108 TAILQ_ENTRY(aac_container) co_link; 109 }; 110 111 /* 112 * Per-SIM data structure 113 */ 114 struct aac_sim 115 { 116 device_t sim_dev; 117 int TargetsPerBus; 118 int BusNumber; 119 int InitiatorBusId; 120 struct aac_softc *aac_sc; 121 TAILQ_ENTRY(aac_sim) sim_link; 122 }; 123 124 /* 125 * Per-disk structure 126 */ 127 struct aac_disk 128 { 129 device_t ad_dev; 130 cdev_t ad_dev_t; 131 struct aac_softc *ad_controller; 132 struct aac_container *ad_container; 133 struct disk ad_disk; 134 struct devstat ad_stats; 135 int ad_flags; 136 #define AAC_DISK_OPEN (1<<0) 137 int ad_cylinders; 138 int ad_heads; 139 int ad_sectors; 140 u_int32_t ad_size; 141 int unit; 142 }; 143 144 /* 145 * Per-command control structure. 146 */ 147 struct aac_command 148 { 149 TAILQ_ENTRY(aac_command) cm_link; /* list linkage */ 150 151 struct aac_softc *cm_sc; /* controller that owns us */ 152 153 struct aac_fib *cm_fib; /* FIB associated with this 154 * command */ 155 u_int64_t cm_fibphys; /* bus address of the FIB */ 156 struct buf *cm_data; /* pointer to data in kernel 157 * space */ 158 u_int32_t cm_datalen; /* data length */ 159 bus_dmamap_t cm_datamap; /* DMA map for bio data */ 160 struct aac_sg_table *cm_sgtable; /* pointer to s/g table in 161 * command */ 162 int cm_flags; 163 #define AAC_CMD_MAPPED (1<<0) /* command has had its data 164 * mapped */ 165 #define AAC_CMD_DATAIN (1<<1) /* command involves data moving 166 * from controller to host */ 167 #define AAC_CMD_DATAOUT (1<<2) /* command involves data moving 168 * from host to controller */ 169 #define AAC_CMD_COMPLETED (1<<3) /* command has been completed */ 170 #define AAC_CMD_TIMEDOUT (1<<4) /* command taken too long */ 171 #define AAC_ON_AACQ_FREE (1<<5) 172 #define AAC_ON_AACQ_READY (1<<6) 173 #define AAC_ON_AACQ_BUSY (1<<7) 174 #define AAC_ON_AACQ_COMPLETE (1<<8) 175 #define AAC_ON_AACQ_NORM (1<<10) 176 #define AAC_ON_AACQ_AIF (1<<11) 177 #define AAC_ON_AACQ_MASK ((1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<10)|(1<<11)) 178 #define AAC_QUEUE_FRZN (1<<9) /* Freeze the processing of 179 * commands on the queue. */ 180 181 void (* cm_complete)(struct aac_command *cm); 182 void *cm_private; 183 time_t cm_timestamp; /* command creation time */ 184 int cm_queue; 185 int cm_index; 186 }; 187 188 struct aac_fibmap { 189 TAILQ_ENTRY(aac_fibmap) fm_link; /* list linkage */ 190 struct aac_fib *aac_fibs; 191 bus_dmamap_t aac_fibmap; 192 struct aac_command *aac_commands; 193 }; 194 195 /* 196 * We gather a number of adapter-visible items into a single structure. 197 * 198 * The ordering of this strucure may be important; we copy the Linux driver: 199 * 200 * Adapter FIBs 201 * Init struct 202 * Queue headers (Comm Area) 203 * Printf buffer 204 * 205 * In addition, we add: 206 * Sync Fib 207 */ 208 struct aac_common { 209 /* fibs for the controller to send us messages */ 210 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 211 212 /* the init structure */ 213 struct aac_adapter_init ac_init; 214 215 /* arena within which the queue structures are kept */ 216 u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + 217 AAC_QUEUE_ALIGN]; 218 219 /* buffer for text messages from the controller */ 220 char ac_printf[AAC_PRINTF_BUFSIZE]; 221 222 /* fib for synchronous commands */ 223 struct aac_fib ac_sync_fib; 224 }; 225 226 /* 227 * Interface operations 228 */ 229 struct aac_interface 230 { 231 int (*aif_get_fwstatus)(struct aac_softc *sc); 232 void (*aif_qnotify)(struct aac_softc *sc, int qbit); 233 int (*aif_get_istatus)(struct aac_softc *sc); 234 void (*aif_clr_istatus)(struct aac_softc *sc, int mask); 235 void (*aif_set_mailbox)(struct aac_softc *sc, u_int32_t command, 236 u_int32_t arg0, u_int32_t arg1, 237 u_int32_t arg2, u_int32_t arg3); 238 int (*aif_get_mailbox)(struct aac_softc *sc, int mb); 239 void (*aif_set_interrupts)(struct aac_softc *sc, int enable); 240 int (*aif_send_command)(struct aac_softc *sc, struct aac_command *cm); 241 int (*aif_get_outb_queue)(struct aac_softc *sc); 242 void (*aif_set_outb_queue)(struct aac_softc *sc, int index); 243 }; 244 extern struct aac_interface aac_rx_interface; 245 extern struct aac_interface aac_sa_interface; 246 extern struct aac_interface aac_fa_interface; 247 extern struct aac_interface aac_rkt_interface; 248 249 #define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) 250 #define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) 251 #define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) 252 #define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_clr_istatus((sc), \ 253 (mask))) 254 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 255 ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ 256 (arg3))) 257 #define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if.aif_get_mailbox((sc), \ 258 (mb))) 259 #define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 260 0)) 261 #define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 262 1)) 263 #define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if.aif_send_command((sc), (cm))) 264 #define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if.aif_get_outb_queue((sc))) 265 #define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if.aif_set_outb_queue((sc), (idx))) 266 267 #define AAC_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag, \ 268 sc->aac_bhandle, reg, val) 269 #define AAC_GETREG4(sc, reg) bus_space_read_4 (sc->aac_btag, \ 270 sc->aac_bhandle, reg) 271 #define AAC_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag, \ 272 sc->aac_bhandle, reg, val) 273 #define AAC_GETREG2(sc, reg) bus_space_read_2 (sc->aac_btag, \ 274 sc->aac_bhandle, reg) 275 #define AAC_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag, \ 276 sc->aac_bhandle, reg, val) 277 #define AAC_GETREG1(sc, reg) bus_space_read_1 (sc->aac_btag, \ 278 sc->aac_bhandle, reg) 279 280 /* Define the OS version specific locks */ 281 typedef struct lock aac_lock_t; 282 #define AAC_LOCK_INIT(l, s) lockinit(l, s, 0, LK_CANRECURSE) 283 #define AAC_LOCK_ACQUIRE(l) lockmgr(l, LK_EXCLUSIVE) 284 #define AAC_LOCK_RELEASE(l) lockmgr(l, LK_RELEASE) 285 286 /* 287 * Per-controller structure. 288 */ 289 struct aac_softc 290 { 291 /* bus connections */ 292 device_t aac_dev; 293 struct callout aac_watchdog; 294 struct resource *aac_regs_resource; /* register interface 295 * window */ 296 int aac_regs_rid; /* resource ID */ 297 bus_space_handle_t aac_bhandle; /* bus space handle */ 298 bus_space_tag_t aac_btag; /* bus space tag */ 299 bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ 300 bus_dma_tag_t aac_buffer_dmat; /* data buffer/command 301 * DMA tag */ 302 struct resource *aac_irq; /* interrupt */ 303 int aac_irq_rid; 304 void *aac_intr; /* interrupt handle */ 305 eventhandler_tag eh; 306 307 /* controller features, limits and status */ 308 int aac_state; 309 #define AAC_STATE_SUSPEND (1<<0) 310 #define AAC_STATE_OPEN (1<<1) 311 #define AAC_STATE_INTERRUPTS_ON (1<<2) 312 #define AAC_STATE_AIF_SLEEPER (1<<3) 313 struct FsaRevision aac_revision; 314 315 /* controller hardware interface */ 316 int aac_hwif; 317 #define AAC_HWIF_I960RX 0 318 #define AAC_HWIF_STRONGARM 1 319 #define AAC_HWIF_FALCON 2 320 #define AAC_HWIF_RKT 3 321 #define AAC_HWIF_UNKNOWN -1 322 bus_dma_tag_t aac_common_dmat; /* common structure 323 * DMA tag */ 324 bus_dmamap_t aac_common_dmamap; /* common structure 325 * DMA map */ 326 struct aac_common *aac_common; 327 u_int32_t aac_common_busaddr; 328 struct aac_interface aac_if; 329 330 /* command/fib resources */ 331 bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */ 332 TAILQ_HEAD(,aac_fibmap) aac_fibmap_tqh; 333 u_int total_fibs; 334 struct aac_command *aac_commands; 335 336 /* command management */ 337 TAILQ_HEAD(,aac_command) aac_free; /* command structures 338 * available for reuse */ 339 TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for 340 * controller resources */ 341 TAILQ_HEAD(,aac_command) aac_busy; 342 TAILQ_HEAD(,aac_command) aac_complete; /* commands which have been 343 * returned by the controller */ 344 TAILQ_HEAD(,aac_command) aac_aif; 345 #if 0 346 TAILQ_HEAD(,aac_command) aac_norm; 347 #endif 348 TAILQ_HEAD(,aac_event) aac_ev_cmfree; 349 struct bio_queue_head aac_bioq; 350 struct aac_queue_table *aac_queues; 351 struct aac_queue_entry *aac_qentries[AAC_QUEUE_COUNT]; 352 353 struct aac_qstat aac_qstat[AACQ_COUNT]; /* queue statistics */ 354 355 /* connected containters */ 356 TAILQ_HEAD(,aac_container) aac_container_tqh; 357 aac_lock_t aac_container_lock; 358 359 /* 360 * The general I/O lock. This protects the sync fib, the lists, the 361 * queues, and the registers. 362 */ 363 aac_lock_t aac_io_lock; 364 365 /* delayed activity infrastructure */ 366 struct task aac_task_complete; /* deferred-completion 367 * task */ 368 struct intr_config_hook aac_ich; 369 370 /* management interface */ 371 cdev_t aac_dev_t; 372 aac_lock_t aac_aifq_lock; 373 struct aac_aif_command aac_aifq[AAC_AIFQ_LENGTH]; 374 int aac_aifq_head; 375 int aac_aifq_tail; 376 struct kqinfo rcv_kq; 377 struct thread *aifthread; 378 int aifflags; 379 #define AAC_AIFFLAGS_RUNNING (1 << 0) 380 #define AAC_AIFFLAGS_AIF (1 << 1) 381 #define AAC_AIFFLAGS_EXIT (1 << 2) 382 #define AAC_AIFFLAGS_EXITED (1 << 3) 383 #define AAC_AIFFLAGS_PRINTF (1 << 4) 384 #define AAC_AIFFLAGS_ALLOCFIBS (1 << 5) 385 #define AAC_AIFFLAGS_PENDING (AAC_AIFFLAGS_AIF | AAC_AIFFLAGS_PRINTF | \ 386 AAC_AIFFLAGS_ALLOCFIBS) 387 u_int32_t flags; 388 #define AAC_FLAGS_PERC2QC (1 << 0) 389 #define AAC_FLAGS_ENABLE_CAM (1 << 1) /* No SCSI passthrough */ 390 #define AAC_FLAGS_CAM_NORESET (1 << 2) /* Fake SCSI resets */ 391 #define AAC_FLAGS_CAM_PASSONLY (1 << 3) /* Only create pass devices */ 392 #define AAC_FLAGS_SG_64BIT (1 << 4) /* Use 64-bit S/G addresses */ 393 #define AAC_FLAGS_4GB_WINDOW (1 << 5) /* Device can access host mem 394 * 2GB-4GB range */ 395 #define AAC_FLAGS_NO4GB (1 << 6) /* Can't access host mem >2GB */ 396 #define AAC_FLAGS_256FIBS (1 << 7) /* Can only do 256 commands */ 397 #define AAC_FLAGS_BROKEN_MEMMAP (1 << 8) /* Broken HostPhysMemPages */ 398 #define AAC_FLAGS_SLAVE (1 << 9) 399 #define AAC_FLAGS_MASTER (1 << 10) 400 #define AAC_FLAGS_NEW_COMM (1 << 11) /* New comm. interface supported */ 401 #define AAC_FLAGS_RAW_IO (1 << 12) /* Raw I/O interface */ 402 #define AAC_FLAGS_ARRAY_64BIT (1 << 13) /* 64-bit array size */ 403 404 u_int32_t supported_options; 405 u_int32_t scsi_method_id; 406 TAILQ_HEAD(,aac_sim) aac_sim_tqh; 407 408 u_int32_t aac_max_fibs; /* max. FIB count */ 409 u_int32_t aac_max_fibs_alloc; /* max. alloc. per alloc_commands() */ 410 u_int32_t aac_max_fib_size; /* max. FIB size */ 411 u_int32_t aac_sg_tablesize; /* max. sg count from host */ 412 u_int32_t aac_max_sectors; /* max. I/O size from host (blocks) */ 413 }; 414 415 /* 416 * Event callback mechanism for the driver 417 */ 418 #define AAC_EVENT_NONE 0x00 419 #define AAC_EVENT_CMFREE 0x01 420 #define AAC_EVENT_MASK 0xff 421 #define AAC_EVENT_REPEAT 0x100 422 423 typedef void aac_event_cb_t(struct aac_softc *sc, struct aac_event *event, 424 void *arg); 425 struct aac_event { 426 TAILQ_ENTRY(aac_event) ev_links; 427 int ev_type; 428 aac_event_cb_t *ev_callback; 429 void *ev_arg; 430 }; 431 432 #ifndef AAC_DRIVER_BUILD 433 # define AAC_DRIVER_BUILD 1 434 #endif 435 436 /* 437 * Public functions 438 */ 439 extern void aac_free(struct aac_softc *sc); 440 extern int aac_attach(struct aac_softc *sc); 441 extern int aac_detach(device_t dev); 442 extern int aac_suspend(device_t dev); 443 extern int aac_resume(device_t dev); 444 extern void aac_new_intr(void *arg); 445 extern void aac_fast_intr(void *arg); 446 extern devclass_t aac_devclass; 447 extern void aac_submit_bio(struct aac_disk *ad, struct bio *bio); 448 extern void aac_biodone(struct bio *bio, const char *code); 449 extern int aac_dump_enqueue(struct aac_disk *ad, u_int64_t lba, 450 void *data, int nblks); 451 extern void aac_dump_complete(struct aac_softc *sc); 452 extern void aac_startio(struct aac_softc *sc); 453 extern int aac_alloc_command(struct aac_softc *sc, 454 struct aac_command **cmp); 455 extern void aac_release_command(struct aac_command *cm); 456 extern int aac_sync_fib(struct aac_softc *sc, u_int32_t command, 457 u_int32_t xferstate, struct aac_fib *fib, 458 u_int16_t datasize); 459 extern void aac_add_event(struct aac_softc *sc, struct aac_event 460 *event); 461 462 /* 463 * Debugging levels: 464 * 0 - quiet, only emit warnings 465 * 1 - noisy, emit major function points and things done 466 * 2 - extremely noisy, emit trace items in loops, etc. 467 */ 468 #ifdef AAC_DEBUG 469 # define debug(level, fmt, args...) \ 470 do { \ 471 if (level <=AAC_DEBUG) kprintf("%s: " fmt "\n", __func__ , ##args); \ 472 } while (0) 473 # define debug_called(level) \ 474 do { \ 475 if (level <= AAC_DEBUG) kprintf("%s: called\n", __func__); \ 476 } while (0) 477 478 extern void aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, 479 const char *caller); 480 extern void aac_print_aif(struct aac_softc *sc, 481 struct aac_aif_command *aif); 482 483 # define AAC_PRINT_FIB(sc, fib) aac_print_fib(sc, fib, __func__) 484 485 #else 486 # define debug(level, fmt, args...) 487 # define debug_called(level) 488 489 # define AAC_PRINT_FIB(sc, fib) 490 # define aac_print_aif(sc, aac_aif_command) 491 #endif 492 493 struct aac_code_lookup { 494 char *string; 495 u_int32_t code; 496 }; 497 498 /* 499 * Queue primitives for driver queues. 500 */ 501 #define AACQ_ADD(sc, qname) \ 502 do { \ 503 struct aac_qstat *qs; \ 504 \ 505 qs = &(sc)->aac_qstat[qname]; \ 506 \ 507 qs->q_length++; \ 508 if (qs->q_length > qs->q_max) \ 509 qs->q_max = qs->q_length; \ 510 } while (0) 511 512 #define AACQ_REMOVE(sc, qname) (sc)->aac_qstat[qname].q_length-- 513 #define AACQ_INIT(sc, qname) \ 514 do { \ 515 sc->aac_qstat[qname].q_length = 0; \ 516 sc->aac_qstat[qname].q_max = 0; \ 517 } while (0) 518 519 520 #define AACQ_COMMAND_QUEUE(name, index) \ 521 static __inline void \ 522 aac_initq_ ## name (struct aac_softc *sc) \ 523 { \ 524 TAILQ_INIT(&sc->aac_ ## name); \ 525 AACQ_INIT(sc, index); \ 526 } \ 527 static __inline void \ 528 aac_enqueue_ ## name (struct aac_command *cm) \ 529 { \ 530 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 531 kprintf("command %p is on another queue, flags = %#x\n", \ 532 cm, cm->cm_flags); \ 533 panic("command is on another queue"); \ 534 } \ 535 TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 536 cm->cm_flags |= AAC_ON_ ## index; \ 537 AACQ_ADD(cm->cm_sc, index); \ 538 } \ 539 static __inline void \ 540 aac_requeue_ ## name (struct aac_command *cm) \ 541 { \ 542 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 543 kprintf("command %p is on another queue, flags = %#x\n", \ 544 cm, cm->cm_flags); \ 545 panic("command is on another queue"); \ 546 } \ 547 TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 548 cm->cm_flags |= AAC_ON_ ## index; \ 549 AACQ_ADD(cm->cm_sc, index); \ 550 } \ 551 static __inline struct aac_command * \ 552 aac_dequeue_ ## name (struct aac_softc *sc) \ 553 { \ 554 struct aac_command *cm; \ 555 \ 556 if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) { \ 557 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 558 kprintf("command %p not in queue, flags = %#x, " \ 559 "bit = %#x\n", cm, cm->cm_flags, \ 560 AAC_ON_ ## index); \ 561 panic("command not in queue"); \ 562 } \ 563 TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link); \ 564 cm->cm_flags &= ~AAC_ON_ ## index; \ 565 AACQ_REMOVE(sc, index); \ 566 } \ 567 return(cm); \ 568 } \ 569 static __inline void \ 570 aac_remove_ ## name (struct aac_command *cm) \ 571 { \ 572 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 573 kprintf("command %p not in queue, flags = %#x, " \ 574 "bit = %#x\n", cm, cm->cm_flags, \ 575 AAC_ON_ ## index); \ 576 panic("command not in queue"); \ 577 } \ 578 TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 579 cm->cm_flags &= ~AAC_ON_ ## index; \ 580 AACQ_REMOVE(cm->cm_sc, index); \ 581 } \ 582 struct hack 583 584 AACQ_COMMAND_QUEUE(free, AACQ_FREE); 585 AACQ_COMMAND_QUEUE(ready, AACQ_READY); 586 AACQ_COMMAND_QUEUE(busy, AACQ_BUSY); 587 AACQ_COMMAND_QUEUE(complete, AACQ_COMPLETE); 588 589 /* 590 * outstanding bio queue 591 */ 592 static __inline void 593 aac_initq_bio(struct aac_softc *sc) 594 { 595 bioq_init(&sc->aac_bioq); 596 AACQ_INIT(sc, AACQ_BIO); 597 } 598 599 static __inline void 600 aac_enqueue_bio(struct aac_softc *sc, struct bio *bio) 601 { 602 bioqdisksort(&sc->aac_bioq, bio); 603 AACQ_ADD(sc, AACQ_BIO); 604 } 605 606 static __inline struct bio * 607 aac_dequeue_bio(struct aac_softc *sc) 608 { 609 struct bio *bio; 610 611 if ((bio = bioq_first(&sc->aac_bioq)) != NULL) { 612 bioq_remove(&sc->aac_bioq, bio); 613 AACQ_REMOVE(sc, AACQ_BIO); 614 } 615 return(bio); 616 } 617 618 static __inline void 619 aac_print_printf(struct aac_softc *sc) 620 { 621 /* 622 * XXX We have the ability to read the length of the kprintf string 623 * from out of the mailboxes. 624 */ 625 device_printf(sc->aac_dev, "**Monitor** %.*s", AAC_PRINTF_BUFSIZE, 626 sc->aac_common->ac_printf); 627 sc->aac_common->ac_printf[0] = 0; 628 AAC_QNOTIFY(sc, AAC_DB_PRINTF); 629 } 630 631 static __inline int 632 aac_alloc_sync_fib(struct aac_softc *sc, struct aac_fib **fib) 633 { 634 635 KKASSERT(lockstatus(&sc->aac_io_lock, curthread) != 0); 636 *fib = &sc->aac_common->ac_sync_fib; 637 return (0); 638 } 639 640 static __inline void 641 aac_release_sync_fib(struct aac_softc *sc) 642 { 643 644 KKASSERT(lockstatus(&sc->aac_io_lock, curthread) != 0); 645 } 646 647