135863739SMike Smith /*- 235863739SMike Smith * Copyright (c) 2000 Michael Smith 3c6eafcf2SScott Long * Copyright (c) 2001 Scott Long 435863739SMike Smith * Copyright (c) 2000 BSDi 5c6eafcf2SScott Long * Copyright (c) 2001 Adaptec, Inc. 635863739SMike Smith * All rights reserved. 735863739SMike Smith * 835863739SMike Smith * Redistribution and use in source and binary forms, with or without 935863739SMike Smith * modification, are permitted provided that the following conditions 1035863739SMike Smith * are met: 1135863739SMike Smith * 1. Redistributions of source code must retain the above copyright 1235863739SMike Smith * notice, this list of conditions and the following disclaimer. 1335863739SMike Smith * 2. Redistributions in binary form must reproduce the above copyright 1435863739SMike Smith * notice, this list of conditions and the following disclaimer in the 1535863739SMike Smith * documentation and/or other materials provided with the distribution. 1635863739SMike Smith * 1735863739SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1835863739SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1935863739SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2035863739SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2135863739SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2235863739SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2335863739SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2435863739SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2535863739SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2635863739SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2735863739SMike Smith * SUCH DAMAGE. 2835863739SMike Smith * 2935863739SMike Smith * $FreeBSD$ 3035863739SMike Smith */ 3135863739SMike Smith 32c6eafcf2SScott Long /****************************************************************************** 33c6eafcf2SScott Long ****************************************************************************** 3435863739SMike Smith Driver Parameter Definitions 35c6eafcf2SScott Long ****************************************************************************** 36c6eafcf2SScott Long ******************************************************************************/ 3735863739SMike Smith 3835863739SMike Smith /* 3935863739SMike Smith * The firmware interface allows for a 16-bit s/g list length. We limit 4035863739SMike Smith * ourselves to a reasonable maximum and ensure alignment. 4135863739SMike Smith */ 4235863739SMike Smith #define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ 4335863739SMike Smith 4435863739SMike Smith /* 4535863739SMike Smith * We allocate a small set of FIBs for the adapter to use to send us messages. 4635863739SMike Smith */ 4735863739SMike Smith #define AAC_ADAPTER_FIBS 8 4835863739SMike Smith 4935863739SMike Smith /* 500b94a66eSMike Smith * FIBs are allocated up-front, and the pool isn't grown. We should allocate 510b94a66eSMike Smith * enough here to let us keep the adapter busy without wasting large amounts 520b94a66eSMike Smith * of kernel memory. The current interface implementation limits us to 512 530b94a66eSMike Smith * FIBs queued for the adapter at any one time. 5435863739SMike Smith */ 550b94a66eSMike Smith #define AAC_FIB_COUNT 128 5635863739SMike Smith 5735863739SMike Smith /* 58c6eafcf2SScott Long * The controller reports status events in AIFs. We hang on to a number of 59c6eafcf2SScott Long * these in order to pass them out to user-space management tools. 6035863739SMike Smith */ 6135863739SMike Smith #define AAC_AIFQ_LENGTH 64 6235863739SMike Smith 6335863739SMike Smith /* 6435863739SMike Smith * Firmware messages are passed in the printf buffer. 6535863739SMike Smith */ 6635863739SMike Smith #define AAC_PRINTF_BUFSIZE 256 6735863739SMike Smith 6835863739SMike Smith /* 69c6eafcf2SScott Long * We wait this many seconds for the adapter to come ready if it is still 70c6eafcf2SScott Long * booting 7135863739SMike Smith */ 7235863739SMike Smith #define AAC_BOOT_TIMEOUT (3 * 60) 7335863739SMike Smith 7435863739SMike Smith /* 7535863739SMike Smith * Timeout for immediate commands. 7635863739SMike Smith */ 770b94a66eSMike Smith #define AAC_IMMEDIATE_TIMEOUT 30 /* seconds */ 780b94a66eSMike Smith 790b94a66eSMike Smith /* 800b94a66eSMike Smith * Timeout for normal commands 810b94a66eSMike Smith */ 820b94a66eSMike Smith #define AAC_CMD_TIMEOUT 30 /* seconds */ 830b94a66eSMike Smith 840b94a66eSMike Smith /* 850b94a66eSMike Smith * Rate at which we periodically check for timed out commands and kick the 860b94a66eSMike Smith * controller. 870b94a66eSMike Smith */ 8836e0bf6eSScott Long #define AAC_PERIODIC_INTERVAL 20 /* seconds */ 8935863739SMike Smith 9035863739SMike Smith /* 9135863739SMike Smith * Character device major numbers. 9235863739SMike Smith */ 9335863739SMike Smith #define AAC_DISK_MAJOR 200 9435863739SMike Smith 95c6eafcf2SScott Long /****************************************************************************** 96c6eafcf2SScott Long ****************************************************************************** 9735863739SMike Smith Driver Variable Definitions 98c6eafcf2SScott Long ****************************************************************************** 99c6eafcf2SScott Long ******************************************************************************/ 10035863739SMike Smith 10135863739SMike Smith #if __FreeBSD_version >= 500005 10235863739SMike Smith # include <sys/taskqueue.h> 10335863739SMike Smith #endif 10435863739SMike Smith 10535863739SMike Smith /* 10635863739SMike Smith * Per-container data structure 10735863739SMike Smith */ 10835863739SMike Smith struct aac_container 10935863739SMike Smith { 11035863739SMike Smith struct aac_mntobj co_mntobj; 11135863739SMike Smith device_t co_disk; 11236e0bf6eSScott Long int co_found; 11336e0bf6eSScott Long TAILQ_ENTRY(aac_container) co_link; 11435863739SMike Smith }; 11535863739SMike Smith 11635863739SMike Smith /* 11735863739SMike Smith * Per-disk structure 11835863739SMike Smith */ 11935863739SMike Smith struct aac_disk 12035863739SMike Smith { 12135863739SMike Smith device_t ad_dev; 12235863739SMike Smith dev_t ad_dev_t; 12335863739SMike Smith struct aac_softc *ad_controller; 12435863739SMike Smith struct aac_container *ad_container; 12535863739SMike Smith struct disk ad_disk; 12635863739SMike Smith struct devstat ad_stats; 12735863739SMike Smith struct disklabel ad_label; 12835863739SMike Smith int ad_flags; 12935863739SMike Smith #define AAC_DISK_OPEN (1<<0) 13035863739SMike Smith int ad_cylinders; 13135863739SMike Smith int ad_heads; 13235863739SMike Smith int ad_sectors; 13335863739SMike Smith u_int32_t ad_size; 13436e0bf6eSScott Long int unit; 13535863739SMike Smith }; 13635863739SMike Smith 13735863739SMike Smith /* 13835863739SMike Smith * Per-command control structure. 13935863739SMike Smith */ 14035863739SMike Smith struct aac_command 14135863739SMike Smith { 14235863739SMike Smith TAILQ_ENTRY(aac_command) cm_link; /* list linkage */ 14335863739SMike Smith 14435863739SMike Smith struct aac_softc *cm_sc; /* controller that owns us */ 14535863739SMike Smith 146c6eafcf2SScott Long struct aac_fib *cm_fib; /* FIB associated with this 147c6eafcf2SScott Long * command */ 14835863739SMike Smith u_int32_t cm_fibphys; /* bus address of the FIB */ 149c6eafcf2SScott Long struct bio *cm_data; /* pointer to data in kernel 150c6eafcf2SScott Long * space */ 15135863739SMike Smith u_int32_t cm_datalen; /* data length */ 15235863739SMike Smith bus_dmamap_t cm_datamap; /* DMA map for bio data */ 153c6eafcf2SScott Long struct aac_sg_table *cm_sgtable; /* pointer to s/g table in 154c6eafcf2SScott Long * command */ 15535863739SMike Smith 15635863739SMike Smith int cm_flags; 157c6eafcf2SScott Long #define AAC_CMD_MAPPED (1<<0) /* command has had its data 158c6eafcf2SScott Long * mapped */ 159c6eafcf2SScott Long #define AAC_CMD_DATAIN (1<<1) /* command involves data moving 160c6eafcf2SScott Long * from controller to host */ 161c6eafcf2SScott Long #define AAC_CMD_DATAOUT (1<<2) /* command involves data moving 162c6eafcf2SScott Long * from host to controller */ 16335863739SMike Smith #define AAC_CMD_COMPLETED (1<<3) /* command has been completed */ 1640b94a66eSMike Smith #define AAC_CMD_TIMEDOUT (1<<4) /* command taken too long */ 165f6c4dd3fSScott Long #define AAC_ON_AACQ_FREE (1<<5) 166f6c4dd3fSScott Long #define AAC_ON_AACQ_READY (1<<6) 167f6c4dd3fSScott Long #define AAC_ON_AACQ_BUSY (1<<7) 168f6c4dd3fSScott Long #define AAC_ON_AACQ_COMPLETE (1<<8) 169f6c4dd3fSScott Long #define AAC_ON_AACQ_MASK ((1<<5)|(1<<6)|(1<<7)|(1<<8)) 17035863739SMike Smith 17135863739SMike Smith void (* cm_complete)(struct aac_command *cm); 17235863739SMike Smith void *cm_private; 1730b94a66eSMike Smith time_t cm_timestamp; /* command creation time */ 17436e0bf6eSScott Long int cm_queue; 17535863739SMike Smith }; 17635863739SMike Smith 17735863739SMike Smith /* 17835863739SMike Smith * We gather a number of adapter-visible items into a single structure. 17935863739SMike Smith * 18035863739SMike Smith * The ordering of this strucure may be important; we copy the Linux driver: 18135863739SMike Smith * 18235863739SMike Smith * Adapter FIBs 18335863739SMike Smith * Init struct 18435863739SMike Smith * Queue headers (Comm Area) 18535863739SMike Smith * Printf buffer 18635863739SMike Smith * 18735863739SMike Smith * In addition, we add: 18835863739SMike Smith * Sync Fib 18935863739SMike Smith */ 19035863739SMike Smith struct aac_common { 19135863739SMike Smith /* fibs for the controller to send us messages */ 19235863739SMike Smith struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; 19335863739SMike Smith 19435863739SMike Smith /* the init structure */ 19535863739SMike Smith struct aac_adapter_init ac_init; 19635863739SMike Smith 19735863739SMike Smith /* arena within which the queue structures are kept */ 198c6eafcf2SScott Long u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + 199c6eafcf2SScott Long AAC_QUEUE_ALIGN]; 20035863739SMike Smith 20135863739SMike Smith /* buffer for text messages from the controller */ 20235863739SMike Smith char ac_printf[AAC_PRINTF_BUFSIZE]; 20335863739SMike Smith 20435863739SMike Smith /* fib for synchronous commands */ 20535863739SMike Smith struct aac_fib ac_sync_fib; 20635863739SMike Smith }; 20735863739SMike Smith 20835863739SMike Smith /* 20935863739SMike Smith * Interface operations 21035863739SMike Smith */ 21135863739SMike Smith struct aac_interface 21235863739SMike Smith { 21335863739SMike Smith int (* aif_get_fwstatus)(struct aac_softc *sc); 21435863739SMike Smith void (* aif_qnotify)(struct aac_softc *sc, int qbit); 21535863739SMike Smith int (* aif_get_istatus)(struct aac_softc *sc); 21635863739SMike Smith void (* aif_set_istatus)(struct aac_softc *sc, int mask); 21735863739SMike Smith void (* aif_set_mailbox)(struct aac_softc *sc, u_int32_t command, 218c6eafcf2SScott Long u_int32_t arg0, u_int32_t arg1, 219c6eafcf2SScott Long u_int32_t arg2, u_int32_t arg3); 22035863739SMike Smith int (* aif_get_mailboxstatus)(struct aac_softc *sc); 22135863739SMike Smith void (* aif_set_interrupts)(struct aac_softc *sc, int enable); 22235863739SMike Smith }; 22335863739SMike Smith extern struct aac_interface aac_rx_interface; 22435863739SMike Smith extern struct aac_interface aac_sa_interface; 22535863739SMike Smith 22635863739SMike Smith #define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) 22735863739SMike Smith #define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) 22835863739SMike Smith #define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) 229c6eafcf2SScott Long #define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_set_istatus((sc), \ 230c6eafcf2SScott Long (mask))) 23135863739SMike Smith #define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ 232c6eafcf2SScott Long ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), \ 233c6eafcf2SScott Long (arg3))) 23435863739SMike Smith #define AAC_GET_MAILBOXSTATUS(sc) ((sc)->aac_if.aif_get_mailboxstatus((sc))) 23535863739SMike Smith #define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), 0)) 23635863739SMike Smith #define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), 1)) 23735863739SMike Smith 238c6eafcf2SScott Long #define AAC_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag, \ 239c6eafcf2SScott Long sc->aac_bhandle, reg, val) 240c6eafcf2SScott Long #define AAC_GETREG4(sc, reg) bus_space_read_4 (sc->aac_btag, \ 241c6eafcf2SScott Long sc->aac_bhandle, reg) 242c6eafcf2SScott Long #define AAC_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag, \ 243c6eafcf2SScott Long sc->aac_bhandle, reg, val) 244c6eafcf2SScott Long #define AAC_GETREG2(sc, reg) bus_space_read_2 (sc->aac_btag, \ 245c6eafcf2SScott Long sc->aac_bhandle, reg) 246c6eafcf2SScott Long #define AAC_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag, \ 247c6eafcf2SScott Long sc->aac_bhandle, reg, val) 248c6eafcf2SScott Long #define AAC_GETREG1(sc, reg) bus_space_read_1 (sc->aac_btag, \ 249c6eafcf2SScott Long sc->aac_bhandle, reg) 25035863739SMike Smith 25136e0bf6eSScott Long TAILQ_HEAD(aac_container_tq, aac_container); 25236e0bf6eSScott Long 25336e0bf6eSScott Long /* Define the OS version specific locks */ 25436e0bf6eSScott Long #if __FreeBSD_version >= 500005 25536e0bf6eSScott Long #include <sys/lock.h> 25636e0bf6eSScott Long #include <sys/mutex.h> 25736e0bf6eSScott Long typedef struct mtx aac_lock_t; 25836e0bf6eSScott Long #define AAC_LOCK_INIT(l) mtx_init(l, "AAC Container Mutex", MTX_DEF) 25936e0bf6eSScott Long #define AAC_LOCK_AQUIRE(l) mtx_lock(l) 26036e0bf6eSScott Long #define AAC_LOCK_RELEASE(l) mtx_unlock(l) 26136e0bf6eSScott Long #else 26236e0bf6eSScott Long typedef struct simplelock aac_lock_t; 26336e0bf6eSScott Long #define AAC_LOCK_INIT(l) simple_lock_init(l) 26436e0bf6eSScott Long #define AAC_LOCK_AQUIRE(l) simple_lock(l) 26536e0bf6eSScott Long #define AAC_LOCK_RELEASE(l) simple_unlock(l) 26636e0bf6eSScott Long #endif 26736e0bf6eSScott Long 26835863739SMike Smith /* 26935863739SMike Smith * Per-controller structure. 27035863739SMike Smith */ 27135863739SMike Smith struct aac_softc 27235863739SMike Smith { 27335863739SMike Smith /* bus connections */ 27435863739SMike Smith device_t aac_dev; 275c6eafcf2SScott Long struct resource *aac_regs_resource; /* register interface 276c6eafcf2SScott Long * window */ 27735863739SMike Smith int aac_regs_rid; /* resource ID */ 27835863739SMike Smith bus_space_handle_t aac_bhandle; /* bus space handle */ 27935863739SMike Smith bus_space_tag_t aac_btag; /* bus space tag */ 28035863739SMike Smith bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ 281c6eafcf2SScott Long bus_dma_tag_t aac_buffer_dmat; /* data buffer/command 282c6eafcf2SScott Long * DMA tag */ 28335863739SMike Smith struct resource *aac_irq; /* interrupt */ 28435863739SMike Smith int aac_irq_rid; 28535863739SMike Smith void *aac_intr; /* interrupt handle */ 28635863739SMike Smith 28735863739SMike Smith /* controller features, limits and status */ 28835863739SMike Smith int aac_state; 28935863739SMike Smith #define AAC_STATE_SUSPEND (1<<0) 29035863739SMike Smith #define AAC_STATE_OPEN (1<<1) 29135863739SMike Smith #define AAC_STATE_INTERRUPTS_ON (1<<2) 29235863739SMike Smith #define AAC_STATE_AIF_SLEEPER (1<<3) 29335863739SMike Smith struct FsaRevision aac_revision; 29435863739SMike Smith 29535863739SMike Smith /* controller hardware interface */ 29635863739SMike Smith int aac_hwif; 29735863739SMike Smith #define AAC_HWIF_I960RX 0 29835863739SMike Smith #define AAC_HWIF_STRONGARM 1 2990b94a66eSMike Smith #define AAC_HWIF_UNKNOWN -1 300c6eafcf2SScott Long bus_dma_tag_t aac_common_dmat; /* common structure 301c6eafcf2SScott Long * DMA tag */ 302c6eafcf2SScott Long bus_dmamap_t aac_common_dmamap; /* common structure 303c6eafcf2SScott Long * DMA map */ 30435863739SMike Smith struct aac_common *aac_common; 30535863739SMike Smith u_int32_t aac_common_busaddr; 30635863739SMike Smith struct aac_interface aac_if; 30735863739SMike Smith 30835863739SMike Smith /* command/fib resources */ 309c6eafcf2SScott Long bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocing FIBs */ 3100b94a66eSMike Smith struct aac_fib *aac_fibs; 3110b94a66eSMike Smith bus_dmamap_t aac_fibmap; 3120b94a66eSMike Smith u_int32_t aac_fibphys; 3130b94a66eSMike Smith struct aac_command aac_command[AAC_FIB_COUNT]; 31435863739SMike Smith 31535863739SMike Smith /* command management */ 316c6eafcf2SScott Long TAILQ_HEAD(,aac_command) aac_free; /* command structures 317c6eafcf2SScott Long * available for reuse */ 318c6eafcf2SScott Long TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for 319c6eafcf2SScott Long * controller resources */ 3200b94a66eSMike Smith TAILQ_HEAD(,aac_command) aac_busy; 321c6eafcf2SScott Long TAILQ_HEAD(,aac_command) aac_complete; /* commands which have been 322c6eafcf2SScott Long * returned by the controller */ 32335863739SMike Smith struct bio_queue_head aac_bioq; 32435863739SMike Smith struct aac_queue_table *aac_queues; 32535863739SMike Smith struct aac_queue_entry *aac_qentries[AAC_QUEUE_COUNT]; 32635863739SMike Smith 3270b94a66eSMike Smith struct aac_qstat aac_qstat[AACQ_COUNT]; /* queue statistics */ 3280b94a66eSMike Smith 32935863739SMike Smith /* connected containters */ 33036e0bf6eSScott Long struct aac_container_tq aac_container_tqh; 33136e0bf6eSScott Long aac_lock_t aac_container_lock; 33235863739SMike Smith 33335863739SMike Smith /* delayed activity infrastructure */ 33435863739SMike Smith #if __FreeBSD_version >= 500005 335c6eafcf2SScott Long struct task aac_task_complete; /* deferred-completion 336c6eafcf2SScott Long * task */ 33735863739SMike Smith #endif 33835863739SMike Smith struct intr_config_hook aac_ich; 33935863739SMike Smith 34035863739SMike Smith /* management interface */ 34135863739SMike Smith dev_t aac_dev_t; 34235863739SMike Smith struct aac_aif_command aac_aifq[AAC_AIFQ_LENGTH]; 34335863739SMike Smith int aac_aifq_head; 34435863739SMike Smith int aac_aifq_tail; 34536e0bf6eSScott Long struct proc *aifthread; 34636e0bf6eSScott Long int aifflags; 34736e0bf6eSScott Long #define AAC_AIFFLAGS_RUNNING (1 << 0) 34836e0bf6eSScott Long #define AAC_AIFFLAGS_PENDING (1 << 1) 34936e0bf6eSScott Long #define AAC_AIFFLAGS_EXIT (1 << 2) 35036e0bf6eSScott Long #define AAC_AIFFLAGS_EXITED (1 << 3) 35135863739SMike Smith }; 35235863739SMike Smith 35335863739SMike Smith 35435863739SMike Smith /* 35535863739SMike Smith * Public functions 35635863739SMike Smith */ 35735863739SMike Smith extern void aac_free(struct aac_softc *sc); 35835863739SMike Smith extern int aac_attach(struct aac_softc *sc); 35935863739SMike Smith extern int aac_detach(device_t dev); 36035863739SMike Smith extern int aac_shutdown(device_t dev); 36135863739SMike Smith extern int aac_suspend(device_t dev); 36235863739SMike Smith extern int aac_resume(device_t dev); 36335863739SMike Smith extern void aac_intr(void *arg); 36435863739SMike Smith extern devclass_t aac_devclass; 36535863739SMike Smith extern void aac_submit_bio(struct bio *bp); 3660b94a66eSMike Smith extern void aac_biodone(struct bio *bp); 36736e0bf6eSScott Long extern int aac_dump_enqueue(struct aac_disk *ad, u_int32_t lba, 36836e0bf6eSScott Long void *data, int nblks); 36936e0bf6eSScott Long extern void aac_dump_complete(struct aac_softc *sc); 37035863739SMike Smith 37135863739SMike Smith /* 37235863739SMike Smith * Debugging levels: 37335863739SMike Smith * 0 - quiet, only emit warnings 37435863739SMike Smith * 1 - noisy, emit major function points and things done 37535863739SMike Smith * 2 - extremely noisy, emit trace items in loops, etc. 37635863739SMike Smith */ 37735863739SMike Smith #ifdef AAC_DEBUG 3780b94a66eSMike Smith # define debug(level, fmt, args...) \ 3790b94a66eSMike Smith do { \ 3800b94a66eSMike Smith if (level <=AAC_DEBUG) printf("%s: " fmt "\n", __FUNCTION__ , ##args); \ 3810b94a66eSMike Smith } while(0) 3820b94a66eSMike Smith # define debug_called(level) \ 3830b94a66eSMike Smith do { \ 3840b94a66eSMike Smith if (level <= AAC_DEBUG) printf(__FUNCTION__ ": called\n"); \ 3850b94a66eSMike Smith } while(0) 38635863739SMike Smith 38735863739SMike Smith extern void aac_print_queues(struct aac_softc *sc); 38835863739SMike Smith extern void aac_panic(struct aac_softc *sc, char *reason); 389c6eafcf2SScott Long extern void aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, 390c6eafcf2SScott Long char *caller); 391c6eafcf2SScott Long extern void aac_print_aif(struct aac_softc *sc, 392c6eafcf2SScott Long struct aac_aif_command *aif); 39335863739SMike Smith 39435863739SMike Smith # define AAC_PRINT_FIB(sc, fib) aac_print_fib(sc, fib, __FUNCTION__) 39535863739SMike Smith 39635863739SMike Smith #else 39735863739SMike Smith # define debug(level, fmt, args...) 39835863739SMike Smith # define debug_called(level) 39935863739SMike Smith 40035863739SMike Smith # define aac_print_queues(sc) 40135863739SMike Smith # define aac_panic(sc, reason) 40235863739SMike Smith 40335863739SMike Smith # define AAC_PRINT_FIB(sc, fib) 40436e0bf6eSScott Long # define aac_print_aif(sc, aac_aif_command) 40535863739SMike Smith #endif 40635863739SMike Smith 40735863739SMike Smith struct aac_code_lookup { 40835863739SMike Smith char *string; 40935863739SMike Smith u_int32_t code; 41035863739SMike Smith }; 41135863739SMike Smith 412c6eafcf2SScott Long /****************************************************************************** 4130b94a66eSMike Smith * Queue primitives for driver queues. 41435863739SMike Smith */ 4150b94a66eSMike Smith #define AACQ_ADD(sc, qname) \ 4160b94a66eSMike Smith do { \ 4170b94a66eSMike Smith struct aac_qstat *qs = &(sc)->aac_qstat[qname]; \ 4180b94a66eSMike Smith \ 4190b94a66eSMike Smith qs->q_length++; \ 4200b94a66eSMike Smith if (qs->q_length > qs->q_max) \ 4210b94a66eSMike Smith qs->q_max = qs->q_length; \ 4220b94a66eSMike Smith } while(0) 42335863739SMike Smith 4240b94a66eSMike Smith #define AACQ_REMOVE(sc, qname) (sc)->aac_qstat[qname].q_length-- 4250b94a66eSMike Smith #define AACQ_INIT(sc, qname) \ 4260b94a66eSMike Smith do { \ 4270b94a66eSMike Smith sc->aac_qstat[qname].q_length = 0; \ 4280b94a66eSMike Smith sc->aac_qstat[qname].q_max = 0; \ 4290b94a66eSMike Smith } while(0) 4300b94a66eSMike Smith 4310b94a66eSMike Smith 4320b94a66eSMike Smith #define AACQ_COMMAND_QUEUE(name, index) \ 4330b94a66eSMike Smith static __inline void \ 4340b94a66eSMike Smith aac_initq_ ## name (struct aac_softc *sc) \ 4350b94a66eSMike Smith { \ 4360b94a66eSMike Smith TAILQ_INIT(&sc->aac_ ## name); \ 4370b94a66eSMike Smith AACQ_INIT(sc, index); \ 4380b94a66eSMike Smith } \ 4390b94a66eSMike Smith static __inline void \ 4400b94a66eSMike Smith aac_enqueue_ ## name (struct aac_command *cm) \ 4410b94a66eSMike Smith { \ 4420b94a66eSMike Smith int s; \ 4430b94a66eSMike Smith \ 4440b94a66eSMike Smith s = splbio(); \ 445f6c4dd3fSScott Long if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 446f6c4dd3fSScott Long printf("command %p is on another queue, flags = %#x\n", \ 447f6c4dd3fSScott Long cm, cm->cm_flags); \ 448f6c4dd3fSScott Long panic("command is on another queue"); \ 449f6c4dd3fSScott Long } \ 4500b94a66eSMike Smith TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 451f6c4dd3fSScott Long cm->cm_flags |= AAC_ON_ ## index; \ 4520b94a66eSMike Smith AACQ_ADD(cm->cm_sc, index); \ 4530b94a66eSMike Smith splx(s); \ 4540b94a66eSMike Smith } \ 4550b94a66eSMike Smith static __inline void \ 4560b94a66eSMike Smith aac_requeue_ ## name (struct aac_command *cm) \ 4570b94a66eSMike Smith { \ 4580b94a66eSMike Smith int s; \ 4590b94a66eSMike Smith \ 4600b94a66eSMike Smith s = splbio(); \ 461f6c4dd3fSScott Long if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) { \ 462f6c4dd3fSScott Long printf("command %p is on another queue, flags = %#x\n", \ 463f6c4dd3fSScott Long cm, cm->cm_flags); \ 464f6c4dd3fSScott Long panic("command is on another queue"); \ 465f6c4dd3fSScott Long } \ 4660b94a66eSMike Smith TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 467f6c4dd3fSScott Long cm->cm_flags |= AAC_ON_ ## index; \ 4680b94a66eSMike Smith AACQ_ADD(cm->cm_sc, index); \ 4690b94a66eSMike Smith splx(s); \ 4700b94a66eSMike Smith } \ 4710b94a66eSMike Smith static __inline struct aac_command * \ 4720b94a66eSMike Smith aac_dequeue_ ## name (struct aac_softc *sc) \ 4730b94a66eSMike Smith { \ 4740b94a66eSMike Smith struct aac_command *cm; \ 4750b94a66eSMike Smith int s; \ 4760b94a66eSMike Smith \ 4770b94a66eSMike Smith s = splbio(); \ 4780b94a66eSMike Smith if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) { \ 479f6c4dd3fSScott Long if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 480f6c4dd3fSScott Long printf("command %p not in queue, flags = %#x, bit = %#x\n",\ 481f6c4dd3fSScott Long cm, cm->cm_flags, AAC_ON_ ## index); \ 482f6c4dd3fSScott Long panic("command not in queue"); \ 483f6c4dd3fSScott Long } \ 4840b94a66eSMike Smith TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link); \ 485f6c4dd3fSScott Long cm->cm_flags &= ~AAC_ON_ ## index; \ 4860b94a66eSMike Smith AACQ_REMOVE(sc, index); \ 4870b94a66eSMike Smith } \ 4880b94a66eSMike Smith splx(s); \ 4890b94a66eSMike Smith return(cm); \ 4900b94a66eSMike Smith } \ 4910b94a66eSMike Smith static __inline void \ 4920b94a66eSMike Smith aac_remove_ ## name (struct aac_command *cm) \ 4930b94a66eSMike Smith { \ 4940b94a66eSMike Smith int s; \ 4950b94a66eSMike Smith \ 4960b94a66eSMike Smith s = splbio(); \ 497f6c4dd3fSScott Long if ((cm->cm_flags & AAC_ON_ ## index) == 0) { \ 498f6c4dd3fSScott Long printf("command %p not in queue, flags = %#x, bit = %#x\n", \ 499f6c4dd3fSScott Long cm, cm->cm_flags, AAC_ON_ ## index); \ 500f6c4dd3fSScott Long panic("command not in queue"); \ 501f6c4dd3fSScott Long } \ 5020b94a66eSMike Smith TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link); \ 503f6c4dd3fSScott Long cm->cm_flags &= ~AAC_ON_ ## index; \ 5040b94a66eSMike Smith AACQ_REMOVE(cm->cm_sc, index); \ 5050b94a66eSMike Smith splx(s); \ 5060b94a66eSMike Smith } \ 5070b94a66eSMike Smith struct hack 5080b94a66eSMike Smith 5090b94a66eSMike Smith AACQ_COMMAND_QUEUE(free, AACQ_FREE); 5100b94a66eSMike Smith AACQ_COMMAND_QUEUE(ready, AACQ_READY); 5110b94a66eSMike Smith AACQ_COMMAND_QUEUE(busy, AACQ_BUSY); 5120b94a66eSMike Smith AACQ_COMMAND_QUEUE(complete, AACQ_COMPLETE); 5130b94a66eSMike Smith 5140b94a66eSMike Smith /* 5150b94a66eSMike Smith * outstanding bio queue 5160b94a66eSMike Smith */ 51735863739SMike Smith static __inline void 5180b94a66eSMike Smith aac_initq_bio(struct aac_softc *sc) 51935863739SMike Smith { 5200b94a66eSMike Smith bioq_init(&sc->aac_bioq); 5210b94a66eSMike Smith AACQ_INIT(sc, AACQ_BIO); 52235863739SMike Smith } 52335863739SMike Smith 52435863739SMike Smith static __inline void 5250b94a66eSMike Smith aac_enqueue_bio(struct aac_softc *sc, struct bio *bp) 52635863739SMike Smith { 52735863739SMike Smith int s; 52835863739SMike Smith 52935863739SMike Smith s = splbio(); 5300b94a66eSMike Smith bioq_insert_tail(&sc->aac_bioq, bp); 5310b94a66eSMike Smith AACQ_ADD(sc, AACQ_BIO); 53235863739SMike Smith splx(s); 53335863739SMike Smith } 53435863739SMike Smith 5350b94a66eSMike Smith static __inline struct bio * 5360b94a66eSMike Smith aac_dequeue_bio(struct aac_softc *sc) 53735863739SMike Smith { 53835863739SMike Smith int s; 5390b94a66eSMike Smith struct bio *bp; 54035863739SMike Smith 54135863739SMike Smith s = splbio(); 5420b94a66eSMike Smith if ((bp = bioq_first(&sc->aac_bioq)) != NULL) { 5430b94a66eSMike Smith bioq_remove(&sc->aac_bioq, bp); 5440b94a66eSMike Smith AACQ_REMOVE(sc, AACQ_BIO); 54535863739SMike Smith } 54635863739SMike Smith splx(s); 5470b94a66eSMike Smith return(bp); 54835863739SMike Smith } 54936e0bf6eSScott Long 55036e0bf6eSScott Long static __inline void 55136e0bf6eSScott Long aac_print_printf(struct aac_softc *sc) 55236e0bf6eSScott Long { 55336e0bf6eSScott Long if (sc->aac_common->ac_printf[0]) { 55436e0bf6eSScott Long device_printf(sc->aac_dev, "**Monitor** %.*s", AAC_PRINTF_BUFSIZE, 55536e0bf6eSScott Long sc->aac_common->ac_printf); 55636e0bf6eSScott Long sc->aac_common->ac_printf[0] = 0; 55736e0bf6eSScott Long AAC_QNOTIFY(sc, AAC_DB_PRINTF); 55836e0bf6eSScott Long } 55936e0bf6eSScott Long } 560