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