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$ 30 */ 31 32 #include <sys/bio.h> 33 #include <sys/callout.h> 34 #include <sys/lock.h> 35 #include <sys/mutex.h> 36 #include <sys/taskqueue.h> 37 #include <sys/selinfo.h> 38 #include <geom/geom_disk.h> 39 40 #define AAC_TYPE_DEVO 1 41 #define AAC_TYPE_ALPHA 2 42 #define AAC_TYPE_BETA 3 43 #define AAC_TYPE_RELEASE 4 44 45 #define AAC_DRIVER_MAJOR_VERSION 2 46 #define AAC_DRIVER_MINOR_VERSION 1 47 #define AAC_DRIVER_BUGFIX_LEVEL 9 48 #define AAC_DRIVER_TYPE AAC_TYPE_RELEASE 49 50 #ifndef AAC_DRIVER_BUILD 51 # define AAC_DRIVER_BUILD 1 52 #endif 53 54 /* 55 * Driver Parameter Definitions 56 */ 57 58 /* 59 * The firmware interface allows for a 16-bit s/g list length. We limit 60 * ourselves to a reasonable maximum and ensure alignment. 61 */ 62 #define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ 63 64 /* 65 * We allocate a small set of FIBs for the adapter to use to send us messages. 66 */ 67 #define AAC_ADAPTER_FIBS 8 68 69 /* 70 * The controller reports status events in AIFs. We hang on to a number of 71 * these in order to pass them out to user-space management tools. 72 */ 73 #define AAC_AIFQ_LENGTH 64 74 75 /* 76 * Firmware messages are passed in the printf buffer. 77 */ 78 #define AAC_PRINTF_BUFSIZE 256 79 80 /* 81 * We wait this many seconds for the adapter to come ready if it is still 82 * booting 83 */ 84 #define AAC_BOOT_TIMEOUT (3 * 60) 85 86 /* 87 * Timeout for immediate commands. 88 */ 89 #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 90 91 /* 92 * Timeout for normal commands 93 */ 94 #define AAC_CMD_TIMEOUT 120 /* seconds */ 95 96 /* 97 * Rate at which we periodically check for timed out commands and kick the 98 * controller. 99 */ 100 #define AAC_PERIODIC_INTERVAL 20 /* seconds */ 101 102 /* 103 * Per-container data structure 104 */ 105 struct aac_container 106 { 107 struct aac_mntobj co_mntobj; 108 device_t co_disk; 109 int co_found; 110 TAILQ_ENTRY(aac_container) co_link; 111 }; 112 113 /* 114 * Per-SIM data structure 115 */ 116 struct aac_cam; 117 struct aac_sim 118 { 119 device_t sim_dev; 120 int TargetsPerBus; 121 int BusNumber; 122 int InitiatorBusId; 123 struct aac_softc *aac_sc; 124 struct aac_cam *aac_cam; 125 TAILQ_ENTRY(aac_sim) sim_link; 126 }; 127 128 /* 129 * Per-disk structure 130 */ 131 struct aac_disk 132 { 133 device_t ad_dev; 134 struct aac_softc *ad_controller; 135 struct aac_container *ad_container; 136 struct disk *ad_disk; 137 int ad_flags; 138 #define AAC_DISK_OPEN (1<<0) 139 int ad_cylinders; 140 int ad_heads; 141 int ad_sectors; 142 u_int64_t ad_size; 143 int unit; 144 }; 145 146 /* 147 * Per-command control structure. 148 */ 149 struct aac_command 150 { 151 TAILQ_ENTRY(aac_command) cm_link; /* list linkage */ 152 153 struct aac_softc *cm_sc; /* controller that owns us */ 154 155 struct aac_fib *cm_fib; /* FIB associated with this 156 * command */ 157 u_int64_t cm_fibphys; /* bus address of the FIB */ 158 struct bio *cm_data; /* pointer to data in kernel 159 * space */ 160 u_int32_t cm_datalen; /* data length */ 161 bus_dmamap_t cm_datamap; /* DMA map for bio data */ 162 struct aac_sg_table *cm_sgtable; /* pointer to s/g table in 163 * command */ 164 int cm_flags; 165 #define AAC_CMD_MAPPED (1<<0) /* command has had its data 166 * mapped */ 167 #define AAC_CMD_DATAIN (1<<1) /* command involves data moving 168 * from controller to host */ 169 #define AAC_CMD_DATAOUT (1<<2) /* command involves data moving 170 * from host to controller */ 171 #define AAC_CMD_COMPLETED (1<<3) /* command has been completed */ 172 #define AAC_CMD_TIMEDOUT (1<<4) /* command taken too long */ 173 #define AAC_ON_AACQ_FREE (1<<5) 174 #define AAC_ON_AACQ_READY (1<<6) 175 #define AAC_ON_AACQ_BUSY (1<<7) 176 #define AAC_ON_AACQ_AIF (1<<8) 177 #define AAC_ON_AACQ_NORM (1<<10) 178 #define AAC_ON_AACQ_MASK ((1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<10)) 179 #define AAC_QUEUE_FRZN (1<<9) /* Freeze the processing of 180 * commands on the queue. */ 181 182 void (* cm_complete)(struct aac_command *cm); 183 void *cm_private; 184 time_t cm_timestamp; /* command creation time */ 185 int cm_queue; 186 int cm_index; 187 }; 188 189 struct aac_fibmap { 190 TAILQ_ENTRY(aac_fibmap) fm_link; /* list linkage */ 191 struct aac_fib *aac_fibs; 192 bus_dmamap_t aac_fibmap; 193 struct aac_command *aac_commands; 194 }; 195 196 /* 197 * We gather a number of adapter-visible items into a single structure. 198 * 199 * The ordering of this strucure may be important; we copy the Linux driver: 200 * 201 * Adapter FIBs 202 * Init struct 203 * Queue headers (Comm Area) 204 * Printf buffer 205 * 206 * In addition, we add: 207 * Sync Fib 208 */ 209 struct aac_common { 210 /* fibs for the controller to send us messages */ 211 struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 212 213 /* the init structure */ 214 struct aac_adapter_init ac_init; 215 216 /* arena within which the queue structures are kept */ 217 u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + 218 AAC_QUEUE_ALIGN]; 219 220 /* buffer for text messages from the controller */ 221 char ac_printf[AAC_PRINTF_BUFSIZE]; 222 223 /* fib for synchronous commands */ 224 struct aac_fib ac_sync_fib; 225 }; 226 227 /* 228 * Interface operations 229 */ 230 struct aac_interface 231 { 232 int (*aif_get_fwstatus)(struct aac_softc *sc); 233 void (*aif_qnotify)(struct aac_softc *sc, int qbit); 234 int (*aif_get_istatus)(struct aac_softc *sc); 235 void (*aif_clr_istatus)(struct aac_softc *sc, int mask); 236 void (*aif_set_mailbox)(struct aac_softc *sc, u_int32_t command, 237 u_int32_t arg0, u_int32_t arg1, 238 u_int32_t arg2, u_int32_t arg3); 239 int (*aif_get_mailbox)(struct aac_softc *sc, int mb); 240 void (*aif_set_interrupts)(struct aac_softc *sc, int enable); 241 int (*aif_send_command)(struct aac_softc *sc, struct aac_command *cm); 242 int (*aif_get_outb_queue)(struct aac_softc *sc); 243 void (*aif_set_outb_queue)(struct aac_softc *sc, int index); 244 }; 245 extern struct aac_interface aac_rx_interface; 246 extern struct aac_interface aac_sa_interface; 247 extern struct aac_interface aac_fa_interface; 248 extern struct aac_interface aac_rkt_interface; 249 250 #define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) 251 #define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) 252 #define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) 253 #define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_clr_istatus((sc), \ 254 (mask))) 255 #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 256 ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ 257 (arg3))) 258 #define AAC_GET_MAILBOX(sc, mb) ((sc)->aac_if.aif_get_mailbox((sc), \ 259 (mb))) 260 #define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 261 0)) 262 #define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), \ 263 1)) 264 #define AAC_SEND_COMMAND(sc, cm) ((sc)->aac_if.aif_send_command((sc), (cm))) 265 #define AAC_GET_OUTB_QUEUE(sc) ((sc)->aac_if.aif_get_outb_queue((sc))) 266 #define AAC_SET_OUTB_QUEUE(sc, idx) ((sc)->aac_if.aif_set_outb_queue((sc), (idx))) 267 268 #define AAC_MEM0_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag0, \ 269 sc->aac_bhandle0, reg, val) 270 #define AAC_MEM0_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag0, \ 271 sc->aac_bhandle0, reg) 272 #define AAC_MEM0_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag0, \ 273 sc->aac_bhandle0, reg, val) 274 #define AAC_MEM0_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag0, \ 275 sc->aac_bhandle0, reg) 276 #define AAC_MEM0_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag0, \ 277 sc->aac_bhandle0, reg, val) 278 #define AAC_MEM0_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag0, \ 279 sc->aac_bhandle0, reg) 280 281 #define AAC_MEM1_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag1, \ 282 sc->aac_bhandle1, reg, val) 283 #define AAC_MEM1_GETREG4(sc, reg) bus_space_read_4(sc->aac_btag1, \ 284 sc->aac_bhandle1, reg) 285 #define AAC_MEM1_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag1, \ 286 sc->aac_bhandle1, reg, val) 287 #define AAC_MEM1_GETREG2(sc, reg) bus_space_read_2(sc->aac_btag1, \ 288 sc->aac_bhandle1, reg) 289 #define AAC_MEM1_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag1, \ 290 sc->aac_bhandle1, reg, val) 291 #define AAC_MEM1_GETREG1(sc, reg) bus_space_read_1(sc->aac_btag1, \ 292 sc->aac_bhandle1, reg) 293 294 /* fib context (IOCTL) */ 295 struct aac_fib_context { 296 u_int32_t unique; 297 int ctx_idx; 298 int ctx_wrap; 299 struct aac_fib_context *next, *prev; 300 }; 301 302 /* 303 * Per-controller structure. 304 */ 305 struct aac_softc 306 { 307 /* bus connections */ 308 device_t aac_dev; 309 struct resource *aac_regs_res0, *aac_regs_res1; /* reg. if. window */ 310 int aac_regs_rid0, aac_regs_rid1; /* resource ID */ 311 bus_space_handle_t aac_bhandle0, aac_bhandle1; /* bus space handle */ 312 bus_space_tag_t aac_btag0, aac_btag1; /* bus space tag */ 313 bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ 314 bus_dma_tag_t aac_buffer_dmat; /* data buffer/command 315 * DMA tag */ 316 struct resource *aac_irq; /* interrupt */ 317 int aac_irq_rid; 318 void *aac_intr; /* interrupt handle */ 319 eventhandler_tag eh; 320 321 /* controller features, limits and status */ 322 int aac_state; 323 #define AAC_STATE_SUSPEND (1<<0) 324 #define AAC_STATE_UNUSED0 (1<<1) 325 #define AAC_STATE_INTERRUPTS_ON (1<<2) 326 #define AAC_STATE_AIF_SLEEPER (1<<3) 327 struct FsaRevision aac_revision; 328 329 /* controller hardware interface */ 330 int aac_hwif; 331 #define AAC_HWIF_I960RX 0 332 #define AAC_HWIF_STRONGARM 1 333 #define AAC_HWIF_RKT 3 334 #define AAC_HWIF_NARK 4 335 #define AAC_HWIF_UNKNOWN -1 336 bus_dma_tag_t aac_common_dmat; /* common structure 337 * DMA tag */ 338 bus_dmamap_t aac_common_dmamap; /* common structure 339 * DMA map */ 340 struct aac_common *aac_common; 341 u_int32_t aac_common_busaddr; 342 struct aac_interface aac_if; 343 344 /* command/fib resources */ 345 bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */ 346 TAILQ_HEAD(,aac_fibmap) aac_fibmap_tqh; 347 u_int total_fibs; 348 struct aac_command *aac_commands; 349 350 /* command management */ 351 TAILQ_HEAD(,aac_command) aac_free; /* command structures 352 * available for reuse */ 353 TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for 354 * controller resources */ 355 TAILQ_HEAD(,aac_command) aac_busy; 356 TAILQ_HEAD(,aac_event) aac_ev_cmfree; 357 struct bio_queue_head aac_bioq; 358 struct aac_queue_table *aac_queues; 359 struct aac_queue_entry *aac_qentries[AAC_QUEUE_COUNT]; 360 361 struct aac_qstat aac_qstat[AACQ_COUNT]; /* queue statistics */ 362 363 /* connected containters */ 364 TAILQ_HEAD(,aac_container) aac_container_tqh; 365 struct mtx aac_container_lock; 366 367 /* 368 * The general I/O lock. This protects the sync fib, the lists, the 369 * queues, and the registers. 370 */ 371 struct mtx aac_io_lock; 372 373 /* delayed activity infrastructure */ 374 struct task aac_task_complete; /* deferred-completion 375 * task */ 376 struct intr_config_hook aac_ich; 377 378 /* management interface */ 379 struct cdev *aac_dev_t; 380 struct mtx aac_aifq_lock; 381 struct aac_fib aac_aifq[AAC_AIFQ_LENGTH]; 382 int aifq_idx; 383 int aifq_filled; 384 struct aac_fib_context *fibctx; 385 struct selinfo rcv_select; 386 struct proc *aifthread; 387 int aifflags; 388 #define AAC_AIFFLAGS_RUNNING (1 << 0) 389 #define AAC_AIFFLAGS_UNUSED0 (1 << 1) 390 #define AAC_AIFFLAGS_EXIT (1 << 2) 391 #define AAC_AIFFLAGS_EXITED (1 << 3) 392 #define AAC_AIFFLAGS_UNUSED1 (1 << 4) 393 #define AAC_AIFFLAGS_ALLOCFIBS (1 << 5) 394 #define AAC_AIFFLAGS_PENDING AAC_AIFFLAGS_ALLOCFIBS 395 u_int32_t flags; 396 #define AAC_FLAGS_PERC2QC (1 << 0) 397 #define AAC_FLAGS_ENABLE_CAM (1 << 1) /* No SCSI passthrough */ 398 #define AAC_FLAGS_CAM_NORESET (1 << 2) /* Fake SCSI resets */ 399 #define AAC_FLAGS_CAM_PASSONLY (1 << 3) /* Only create pass devices */ 400 #define AAC_FLAGS_SG_64BIT (1 << 4) /* Use 64-bit S/G addresses */ 401 #define AAC_FLAGS_4GB_WINDOW (1 << 5) /* Device can access host mem 402 * 2GB-4GB range */ 403 #define AAC_FLAGS_NO4GB (1 << 6) /* Can't access host mem >2GB */ 404 #define AAC_FLAGS_256FIBS (1 << 7) /* Can only do 256 commands */ 405 #define AAC_FLAGS_BROKEN_MEMMAP (1 << 8) /* Broken HostPhysMemPages */ 406 #define AAC_FLAGS_SLAVE (1 << 9) 407 #define AAC_FLAGS_MASTER (1 << 10) 408 #define AAC_FLAGS_NEW_COMM (1 << 11) /* New comm. interface supported */ 409 #define AAC_FLAGS_RAW_IO (1 << 12) /* Raw I/O interface */ 410 #define AAC_FLAGS_ARRAY_64BIT (1 << 13) /* 64-bit array size */ 411 #define AAC_FLAGS_LBA_64BIT (1 << 14) /* 64-bit LBA support */ 412 413 u_int32_t supported_options; 414 u_int32_t scsi_method_id; 415 TAILQ_HEAD(,aac_sim) aac_sim_tqh; 416 417 struct callout aac_daemontime; /* clock daemon callout */ 418 419 u_int32_t aac_max_fibs; /* max. FIB count */ 420 u_int32_t aac_max_fibs_alloc; /* max. alloc. per alloc_commands() */ 421 u_int32_t aac_max_fib_size; /* max. FIB size */ 422 u_int32_t aac_sg_tablesize; /* max. sg count from host */ 423 u_int32_t aac_max_sectors; /* max. I/O size from host (blocks) */ 424 #define AAC_CAM_TARGET_WILDCARD ~0 425 void (*cam_rescan_cb)(struct aac_softc *, uint32_t, 426 uint32_t); 427 }; 428 429 /* 430 * Event callback mechanism for the driver 431 */ 432 #define AAC_EVENT_NONE 0x00 433 #define AAC_EVENT_CMFREE 0x01 434 #define AAC_EVENT_MASK 0xff 435 #define AAC_EVENT_REPEAT 0x100 436 437 typedef void aac_event_cb_t(struct aac_softc *sc, struct aac_event *event, 438 void *arg); 439 struct aac_event { 440 TAILQ_ENTRY(aac_event) ev_links; 441 int ev_type; 442 aac_event_cb_t *ev_callback; 443 void *ev_arg; 444 }; 445 446 /* 447 * Public functions 448 */ 449 extern void aac_free(struct aac_softc *sc); 450 extern int aac_attach(struct aac_softc *sc); 451 extern int aac_detach(device_t dev); 452 extern int aac_shutdown(device_t dev); 453 extern int aac_suspend(device_t dev); 454 extern int aac_resume(device_t dev); 455 extern void aac_new_intr(void *arg); 456 extern int aac_filter(void *arg); 457 extern void aac_submit_bio(struct bio *bp); 458 extern void aac_biodone(struct bio *bp); 459 extern void aac_startio(struct aac_softc *sc); 460 extern int aac_alloc_command(struct aac_softc *sc, 461 struct aac_command **cmp); 462 extern void aac_release_command(struct aac_command *cm); 463 extern int aac_sync_fib(struct aac_softc *sc, u_int32_t command, 464 u_int32_t xferstate, struct aac_fib *fib, 465 u_int16_t datasize); 466 extern void aac_add_event(struct aac_softc *sc, struct aac_event 467 *event); 468 469 #ifdef AAC_DEBUG 470 extern int aac_debug_enable; 471 # define fwprintf(sc, flags, fmt, args...) \ 472 do { \ 473 if (!aac_debug_enable) \ 474 break; \ 475 if (sc != NULL) \ 476 device_printf(((struct aac_softc *)sc)->aac_dev, \ 477 "%s: " fmt "\n", __func__, ##args); \ 478 else \ 479 printf("%s: " fmt "\n", __func__, ##args); \ 480 } while(0) 481 482 extern void aac_print_queues(struct aac_softc *sc); 483 extern void aac_panic(struct aac_softc *sc, char *reason); 484 extern void aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, 485 const char *caller); 486 extern void aac_print_aif(struct aac_softc *sc, 487 struct aac_aif_command *aif); 488 489 #define AAC_PRINT_FIB(sc, fib) aac_print_fib(sc, fib, __func__) 490 491 #else 492 # define fwprintf(sc, flags, fmt, args...) 493 494 # define aac_print_queues(sc) 495 # define aac_panic(sc, reason) 496 497 # define AAC_PRINT_FIB(sc, fib) 498 # define aac_print_aif(sc, aac_aif_command) 499 #endif 500 501 struct aac_code_lookup { 502 char *string; 503 u_int32_t code; 504 }; 505 506 /* 507 * Queue primitives for driver queues. 508 */ 509 #define AACQ_ADD(sc, qname) \ 510 do { \ 511 struct aac_qstat *qs; \ 512 \ 513 qs = &(sc)->aac_qstat[qname]; \ 514 \ 515 qs->q_length++; \ 516 if (qs->q_length > qs->q_max) \ 517 qs->q_max = qs->q_length; \ 518 } while (0) 519 520 #define AACQ_REMOVE(sc, qname) (sc)->aac_qstat[qname].q_length-- 521 #define AACQ_INIT(sc, qname) \ 522 do { \ 523 sc->aac_qstat[qname].q_length = 0; \ 524 sc->aac_qstat[qname].q_max = 0; \ 525 } while (0) 526 527 528 #define AACQ_COMMAND_QUEUE(name, index) \ 529 static __inline void \ 530 aac_initq_ ## name (struct aac_softc *sc) \ 531 { \ 532 TAILQ_INIT(&sc->aac_ ## name); \ 533 AACQ_INIT(sc, index); \ 534 } \ 535 static __inline void \ 536 aac_enqueue_ ## name (struct aac_command *cm) \ 537 { \ 538 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 539 panic("aac: command %p is on another queue, flags = %#x", \ 540 cm, cm->cm_flags); \ 541 } \ 542 TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 543 cm->cm_flags |= AAC_ON_ ## index; \ 544 AACQ_ADD(cm->cm_sc, index); \ 545 } \ 546 static __inline void \ 547 aac_requeue_ ## name (struct aac_command *cm) \ 548 { \ 549 if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 550 panic("aac: command %p is on another queue, flags = %#x", \ 551 cm, cm->cm_flags); \ 552 } \ 553 TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 554 cm->cm_flags |= AAC_ON_ ## index; \ 555 AACQ_ADD(cm->cm_sc, index); \ 556 } \ 557 static __inline struct aac_command * \ 558 aac_dequeue_ ## name (struct aac_softc *sc) \ 559 { \ 560 struct aac_command *cm; \ 561 \ 562 if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) { \ 563 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 564 panic("aac: command %p not in queue, flags = %#x, bit = %#x", \ 565 cm, cm->cm_flags, AAC_ON_ ## index); \ 566 } \ 567 TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link); \ 568 cm->cm_flags &= ~AAC_ON_ ## index; \ 569 AACQ_REMOVE(sc, index); \ 570 } \ 571 return(cm); \ 572 } \ 573 static __inline void \ 574 aac_remove_ ## name (struct aac_command *cm) \ 575 { \ 576 if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 577 panic("aac: command %p not in queue, flags = %#x, bit = %#x", \ 578 cm, cm->cm_flags, AAC_ON_ ## index); \ 579 } \ 580 TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 581 cm->cm_flags &= ~AAC_ON_ ## index; \ 582 AACQ_REMOVE(cm->cm_sc, index); \ 583 } \ 584 struct hack 585 586 AACQ_COMMAND_QUEUE(free, AACQ_FREE); 587 AACQ_COMMAND_QUEUE(ready, AACQ_READY); 588 AACQ_COMMAND_QUEUE(busy, AACQ_BUSY); 589 590 /* 591 * outstanding bio queue 592 */ 593 static __inline void 594 aac_initq_bio(struct aac_softc *sc) 595 { 596 bioq_init(&sc->aac_bioq); 597 AACQ_INIT(sc, AACQ_BIO); 598 } 599 600 static __inline void 601 aac_enqueue_bio(struct aac_softc *sc, struct bio *bp) 602 { 603 bioq_insert_tail(&sc->aac_bioq, bp); 604 AACQ_ADD(sc, AACQ_BIO); 605 } 606 607 static __inline struct bio * 608 aac_dequeue_bio(struct aac_softc *sc) 609 { 610 struct bio *bp; 611 612 if ((bp = bioq_first(&sc->aac_bioq)) != NULL) { 613 bioq_remove(&sc->aac_bioq, bp); 614 AACQ_REMOVE(sc, AACQ_BIO); 615 } 616 return(bp); 617 } 618 619 static __inline void 620 aac_print_printf(struct aac_softc *sc) 621 { 622 /* 623 * XXX We have the ability to read the length of the printf string 624 * from out of the mailboxes. 625 */ 626 device_printf(sc->aac_dev, "**Monitor** %.*s", AAC_PRINTF_BUFSIZE, 627 sc->aac_common->ac_printf); 628 sc->aac_common->ac_printf[0] = 0; 629 AAC_QNOTIFY(sc, AAC_DB_PRINTF); 630 } 631 632 static __inline int 633 aac_alloc_sync_fib(struct aac_softc *sc, struct aac_fib **fib) 634 { 635 636 mtx_assert(&sc->aac_io_lock, MA_OWNED); 637 *fib = &sc->aac_common->ac_sync_fib; 638 return (0); 639 } 640 641 static __inline void 642 aac_release_sync_fib(struct aac_softc *sc) 643 { 644 645 mtx_assert(&sc->aac_io_lock, MA_OWNED); 646 } 647 648