diff options
author | msmith <msmith@FreeBSD.org> | 2000-09-13 03:20:35 +0000 |
---|---|---|
committer | msmith <msmith@FreeBSD.org> | 2000-09-13 03:20:35 +0000 |
commit | b3a68de811482a052700bc84248100636ae00408 (patch) | |
tree | dc1873b903b801b371f3bc3552cd5a92d1d41d26 /sys/dev | |
parent | e396c60f6864bbc71b96f3a4f07ea13214a2370a (diff) | |
download | FreeBSD-src-b3a68de811482a052700bc84248100636ae00408.zip FreeBSD-src-b3a68de811482a052700bc84248100636ae00408.tar.gz |
A new driver for PCI:SCSI RAID controllers based on the Adaptec FSA
design. This includes integrated Dell RAID controllers, the Dell
PERC 2/QC and the HP NetRAID-4M.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/aac/aac.c | 1896 | ||||
-rw-r--r-- | sys/dev/aac/aac_compat.h | 64 | ||||
-rw-r--r-- | sys/dev/aac/aac_debug.c | 426 | ||||
-rw-r--r-- | sys/dev/aac/aac_disk.c | 296 | ||||
-rw-r--r-- | sys/dev/aac/aac_ioctl.h | 78 | ||||
-rw-r--r-- | sys/dev/aac/aac_pci.c | 272 | ||||
-rw-r--r-- | sys/dev/aac/aac_tables.h | 117 | ||||
-rw-r--r-- | sys/dev/aac/aacreg.h | 1082 | ||||
-rw-r--r-- | sys/dev/aac/aacvar.h | 451 |
9 files changed, 4682 insertions, 0 deletions
diff --git a/sys/dev/aac/aac.c b/sys/dev/aac/aac.c new file mode 100644 index 0000000..0d91554 --- /dev/null +++ b/sys/dev/aac/aac.c @@ -0,0 +1,1896 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Driver for the Adaptec 'FSA' family of PCI/SCSI RAID adapters. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/malloc.h> +#include <sys/kernel.h> + +#include <dev/aac/aac_compat.h> + +#include <sys/bus.h> +#include <sys/conf.h> +#include <sys/devicestat.h> +#include <sys/disk.h> +#include <sys/file.h> +#include <sys/signalvar.h> + +#include <machine/bus_memio.h> +#include <machine/bus.h> +#include <machine/clock.h> +#include <machine/resource.h> + +#include <dev/aac/aacreg.h> +#include <dev/aac/aacvar.h> +#include <dev/aac/aac_tables.h> +#include <dev/aac/aac_ioctl.h> + +devclass_t aac_devclass; + +static void aac_startup(void *arg); + +/* Command Processing */ +static void aac_startio(struct aac_softc *sc); +static int aac_start(struct aac_command *cm); +static void aac_complete(void *context, int pending); +static int aac_bio_command(struct aac_softc *sc, struct aac_command **cmp); +static void aac_bio_complete(struct aac_command *cm); +static int aac_wait_command(struct aac_command *cm, int timeout); +static void aac_host_command(struct aac_softc *sc); +static void aac_host_response(struct aac_softc *sc); + +/* Command Buffer Management */ +static int aac_alloc_command(struct aac_softc *sc, struct aac_command **cmp); +static void aac_release_command(struct aac_command *cm); +static void aac_map_command_cluster(void *arg, bus_dma_segment_t *segs, int nseg, int error); +static void aac_alloc_command_cluster(struct aac_softc *sc); +static void aac_free_command_cluster(struct aac_command_cluster *cmc); +static void aac_map_command(struct aac_command *cm); +static void aac_unmap_command(struct aac_command *cm); + +/* Hardware Interface */ +static void aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg, int error); +static int aac_init(struct aac_softc *sc); +static int aac_sync_command(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3, + u_int32_t *sp); +static int aac_sync_fib(struct aac_softc *sc, u_int32_t command, u_int32_t xferstate, + void *data, u_int16_t datasize, + void *result, u_int16_t *resultsize); +static int aac_enqueue_fib(struct aac_softc *sc, int queue, u_int32_t fib_size, u_int32_t fib_addr); +static int aac_dequeue_fib(struct aac_softc *sc, int queue, u_int32_t *fib_size, struct aac_fib **fib_addr); + +/* StrongARM interface */ +static int aac_sa_get_fwstatus(struct aac_softc *sc); +static void aac_sa_qnotify(struct aac_softc *sc, int qbit); +static int aac_sa_get_istatus(struct aac_softc *sc); +static void aac_sa_clear_istatus(struct aac_softc *sc, int mask); +static void aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3); +static int aac_sa_get_mailboxstatus(struct aac_softc *sc); +static void aac_sa_set_interrupts(struct aac_softc *sc, int enable); + +struct aac_interface aac_sa_interface = { + aac_sa_get_fwstatus, + aac_sa_qnotify, + aac_sa_get_istatus, + aac_sa_clear_istatus, + aac_sa_set_mailbox, + aac_sa_get_mailboxstatus, + aac_sa_set_interrupts +}; + +/* i960Rx interface */ +static int aac_rx_get_fwstatus(struct aac_softc *sc); +static void aac_rx_qnotify(struct aac_softc *sc, int qbit); +static int aac_rx_get_istatus(struct aac_softc *sc); +static void aac_rx_clear_istatus(struct aac_softc *sc, int mask); +static void aac_rx_set_mailbox(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3); +static int aac_rx_get_mailboxstatus(struct aac_softc *sc); +static void aac_rx_set_interrupts(struct aac_softc *sc, int enable); + +struct aac_interface aac_rx_interface = { + aac_rx_get_fwstatus, + aac_rx_qnotify, + aac_rx_get_istatus, + aac_rx_clear_istatus, + aac_rx_set_mailbox, + aac_rx_get_mailboxstatus, + aac_rx_set_interrupts +}; + +/* Debugging and Diagnostics */ +static void aac_describe_controller(struct aac_softc *sc); +static char *aac_describe_code(struct aac_code_lookup *table, u_int32_t code); + +/* Management Interface */ +static d_open_t aac_open; +static d_close_t aac_close; +static d_ioctl_t aac_ioctl; +static int aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib); +static void aac_handle_aif(struct aac_softc *sc, struct aac_aif_command *aif); +static int aac_return_aif(struct aac_softc *sc, caddr_t uptr); +#ifdef AAC_COMPAT_LINUX +static int aac_linux_rev_check(struct aac_softc *sc, caddr_t udata); +static int aac_linux_getnext_aif(struct aac_softc *sc, caddr_t arg); +#endif + +#define AAC_CDEV_MAJOR 150 + +static struct cdevsw aac_cdevsw = { + aac_open, /* open */ + aac_close, /* close */ + noread, /* read */ + nowrite, /* write */ + aac_ioctl, /* ioctl */ + nopoll, /* poll */ + nommap, /* mmap */ + nostrategy, /* strategy */ + "aac", /* name */ + AAC_CDEV_MAJOR, /* major */ + nodump, /* dump */ + nopsize, /* psize */ + 0, /* flags */ + -1, /* bmaj */ +}; + +/******************************************************************************** + ******************************************************************************** + Device Interface + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Initialise the controller and softc + */ +int +aac_attach(struct aac_softc *sc) +{ + int error, unit; + + debug_called(1); + + /* + * Initialise per-controller queues. + */ + TAILQ_INIT(&sc->aac_freecmds); + TAILQ_INIT(&sc->aac_ready); + TAILQ_INIT(&sc->aac_completed); + TAILQ_INIT(&sc->aac_clusters); + bioq_init(&sc->aac_bioq); + +#if __FreeBSD_version >= 500005 + /* + * Initialise command-completion task. + */ + TASK_INIT(&sc->aac_task_complete, 0, aac_complete, sc); +#endif + + /* disable interrupts before we enable anything */ + AAC_MASK_INTERRUPTS(sc); + + /* mark controller as suspended until we get ourselves organised */ + sc->aac_state |= AAC_STATE_SUSPEND; + + /* + * Initialise the adapter. + */ + if ((error = aac_init(sc))) + return(error); + + /* + * Print a little information about the controller. + */ + aac_describe_controller(sc); + + /* + * Register to probe our containers later. + */ + bzero(&sc->aac_ich, sizeof(struct intr_config_hook)); + sc->aac_ich.ich_func = aac_startup; + sc->aac_ich.ich_arg = sc; + if (config_intrhook_establish(&sc->aac_ich) != 0) { + device_printf(sc->aac_dev, "can't establish configuration hook\n"); + return(ENXIO); + } + + /* + * Make the control device. + */ + unit = device_get_unit(sc->aac_dev); + sc->aac_dev_t = make_dev(&aac_cdevsw, unit, UID_ROOT, GID_WHEEL, 0644, "aac%d", unit); + sc->aac_dev_t->si_drv1 = sc; + + return(0); +} + +/******************************************************************************** + * Probe for containers, create disks. + */ +static void +aac_startup(void *arg) +{ + struct aac_softc *sc = (struct aac_softc *)arg; + struct aac_mntinfo mi; + struct aac_mntinforesponse mir; + device_t child; + u_int16_t rsize; + int i; + + debug_called(1); + + /* disconnect ourselves from the intrhook chain */ + config_intrhook_disestablish(&sc->aac_ich); + + /* loop over possible containers */ + mi.Command = VM_NameServe; + mi.MntType = FT_FILESYS; + for (i = 0; i < AAC_MAX_CONTAINERS; i++) { + /* request information on this container */ + mi.MntCount = i; + if (aac_sync_fib(sc, ContainerCommand, 0, &mi, sizeof(struct aac_mntinfo), &mir, &rsize)) { + debug(2, "error probing container %d", i); + continue; + } + /* check response size */ + if (rsize != sizeof(mir)) { + debug(2, "container info response wrong size (%d should be %d)", rsize, sizeof(*mir)); + continue; + } + /* + * Check container volume type for validity. Note that many of the possible types + * may never show up. + */ + if ((mir.Status == ST_OK) && (mir.MntTable[0].VolType != CT_NONE)) { + debug(1, "%d: id %x name '%.16s' size %u type %d", + i, mir.MntTable[0].ObjectId, + mir.MntTable[0].FileSystemName, mir.MntTable[0].Capacity, + mir.MntTable[0].VolType); + + if ((child = device_add_child(sc->aac_dev, NULL, -1)) == NULL) { + device_printf(sc->aac_dev, "device_add_child failed\n"); + } else { + device_set_ivars(child, &sc->aac_container[i]); + } + device_set_desc(child, aac_describe_code(aac_container_types, mir.MntTable[0].VolType)); + sc->aac_container[i].co_disk = child; + sc->aac_container[i].co_mntobj = mir.MntTable[0]; + } + } + + /* poke the bus to actually attach the child devices */ + if (bus_generic_attach(sc->aac_dev)) + device_printf(sc->aac_dev, "bus_generic_attach failed\n"); + + /* mark the controller up */ + sc->aac_state &= ~AAC_STATE_SUSPEND; + + /* enable interrupts now */ + AAC_UNMASK_INTERRUPTS(sc); +} + +/******************************************************************************** + * Free all of the resources associated with (sc) + * + * Should not be called if the controller is active. + * + * XXX verify that we are freeing all our resources here... + */ +void +aac_free(struct aac_softc *sc) +{ + struct aac_command_cluster *cmc; + + debug_called(1); + + /* remove the control device */ + if (sc->aac_dev_t != NULL) + destroy_dev(sc->aac_dev_t); + + /* throw away any command buffers */ + while ((cmc = aac_dequeue_cluster(sc)) != NULL) + aac_free_command_cluster(cmc); + + /* destroy the common area */ + if (sc->aac_common) { + bus_dmamap_unload(sc->aac_common_dmat, sc->aac_common_dmamap); + bus_dmamem_free(sc->aac_common_dmat, sc->aac_common, sc->aac_common_dmamap); + bus_dma_tag_destroy(sc->aac_common_dmat); + } + + /* disconnect the interrupt handler */ + if (sc->aac_intr) + bus_teardown_intr(sc->aac_dev, sc->aac_irq, sc->aac_intr); + if (sc->aac_irq != NULL) + bus_release_resource(sc->aac_dev, SYS_RES_IRQ, sc->aac_irq_rid, sc->aac_irq); + + /* destroy data-transfer DMA tag */ + if (sc->aac_buffer_dmat) + bus_dma_tag_destroy(sc->aac_buffer_dmat); + + /* destroy FIB DMA tag */ + if (sc->aac_buffer_dmat) + bus_dma_tag_destroy(sc->aac_fib_dmat); + + /* destroy the parent DMA tag */ + if (sc->aac_parent_dmat) + bus_dma_tag_destroy(sc->aac_parent_dmat); + + /* release the register window mapping */ + if (sc->aac_regs_resource != NULL) + bus_release_resource(sc->aac_dev, SYS_RES_MEMORY, sc->aac_regs_rid, sc->aac_regs_resource); +} + +/******************************************************************************** + * Disconnect from the controller completely, in preparation for unload. + */ +int +aac_detach(device_t dev) +{ + struct aac_softc *sc = device_get_softc(dev); + int error; + + debug_called(1); + + if (sc->aac_state & AAC_STATE_OPEN) + return(EBUSY); + + if ((error = aac_shutdown(dev))) + return(error); + + aac_free(sc); + + return(0); +} + +/******************************************************************************** + * Bring the controller down to a dormant state and detach all child devices. + * + * This function is called before detach or system shutdown. + * + * Note that we can assume that the camq on the controller is empty, as we won't + * allow shutdown if any device is open. + */ +int +aac_shutdown(device_t dev) +{ + struct aac_softc *sc = device_get_softc(dev); + struct aac_close_command cc; + int s, i; + + debug_called(1); + + s = splbio(); + + sc->aac_state |= AAC_STATE_SUSPEND; + + /* + * Send a Container shutdown followed by a HostShutdown FIB to the + * controller to convince it that we don't want to talk to it anymore. + * We've been closed and all I/O completed already + */ + device_printf(sc->aac_dev, "shutting down controller..."); + + cc.Command = VM_CloseAll; + cc.ContainerId = 0xffffffff; + if (aac_sync_fib(sc, ContainerCommand, 0, &cc, sizeof(cc), NULL, NULL)) { + printf("FAILED.\n"); + } else { + i = 0; + if (aac_sync_fib(sc, FsaHostShutdown, AAC_FIBSTATE_SHUTDOWN, &i, sizeof(i), NULL, NULL)) { + printf("FAILED.\n"); + } else { + printf("done.\n"); + } + } + + AAC_MASK_INTERRUPTS(sc); + + splx(s); + return(0); +} + +/******************************************************************************** + * Bring the controller to a quiescent state, ready for system suspend. + */ +int +aac_suspend(device_t dev) +{ + struct aac_softc *sc = device_get_softc(dev); + int s; + + debug_called(1); + s = splbio(); + + sc->aac_state |= AAC_STATE_SUSPEND; + + AAC_MASK_INTERRUPTS(sc); + splx(s); + return(0); +} + +/******************************************************************************** + * Bring the controller back to a state ready for operation. + */ +int +aac_resume(device_t dev) +{ + struct aac_softc *sc = device_get_softc(dev); + + debug_called(1); + sc->aac_state &= ~AAC_STATE_SUSPEND; + AAC_UNMASK_INTERRUPTS(sc); + return(0); +} + +/******************************************************************************* + * Take an interrupt. + */ +void +aac_intr(void *arg) +{ + struct aac_softc *sc = (struct aac_softc *)arg; + u_int16_t reason; + + debug_called(2); + + reason = AAC_GET_ISTATUS(sc); + + /* controller wants to talk to the log? XXX should we defer this? */ + if (reason & AAC_DB_PRINTF) { + if (sc->aac_common->ac_printf[0]) { + device_printf(sc->aac_dev, "** %.*s", AAC_PRINTF_BUFSIZE, sc->aac_common->ac_printf); + sc->aac_common->ac_printf[0] = 0; + } + AAC_CLEAR_ISTATUS(sc, AAC_DB_PRINTF); + AAC_QNOTIFY(sc, AAC_DB_PRINTF); + } + + /* controller has a message for us? */ + if (reason & AAC_DB_COMMAND_READY) { + aac_host_command(sc); + AAC_CLEAR_ISTATUS(sc, AAC_DB_COMMAND_READY); + } + + /* controller has a response for us? */ + if (reason & AAC_DB_RESPONSE_READY) { + aac_host_response(sc); + AAC_CLEAR_ISTATUS(sc, AAC_DB_RESPONSE_READY); + } + + /* spurious interrupts that we don't use - reset the mask and clear the interrupts */ + if (reason & (AAC_DB_COMMAND_NOT_FULL | AAC_DB_RESPONSE_NOT_FULL)) { + AAC_UNMASK_INTERRUPTS(sc); + AAC_CLEAR_ISTATUS(sc, AAC_DB_COMMAND_NOT_FULL | AAC_DB_RESPONSE_NOT_FULL); + } +}; + +/******************************************************************************** + ******************************************************************************** + Command Processing + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Start as much queued I/O as possible on the controller + */ +static void +aac_startio(struct aac_softc *sc) +{ + struct aac_command *cm; + + debug_called(2); + + for(;;) { + /* try to get a command that's been put off for lack of resources */ + cm = aac_dequeue_ready(sc); + + /* try to build a command off the bio queue (ignore error return) */ + aac_bio_command(sc, &cm); + + /* nothing to do? */ + if (cm == NULL) + break; + + /* try to give the command to the controller */ + if (aac_start(cm) == EBUSY) { + /* put it on the ready queue for later */ + aac_requeue_ready(cm); + break; + } + } +} + +/******************************************************************************** + * Deliver a command to the controller; allocate controller resources at the + * last moment when possible. + */ +static int +aac_start(struct aac_command *cm) +{ + struct aac_softc *sc = cm->cm_sc; + + debug_called(2); + + /* get the command mapped */ + aac_map_command(cm); + + /* fix up the address values */ + cm->cm_fib->Header.SenderFibAddress = (u_int32_t)cm->cm_fib; + cm->cm_fib->Header.ReceiverFibAddress = cm->cm_fibphys; + + /* save a pointer to the command for speedy reverse-lookup */ + cm->cm_fib->Header.SenderData = (u_int32_t)cm; /* XXX ack, sizing */ + + /* put the FIB on the outbound queue */ + if (aac_enqueue_fib(sc, AAC_ADAP_NORM_CMD_QUEUE, cm->cm_fib->Header.Size, + cm->cm_fib->Header.ReceiverFibAddress)) + return(EBUSY); + + return(0); +} + +/******************************************************************************** + * Handle notification of one or more FIBs coming from the controller. + */ +static void +aac_host_command(struct aac_softc *sc) +{ + struct aac_fib *fib; + u_int32_t fib_size; + + debug_called(1); + + for (;;) { + if (aac_dequeue_fib(sc, AAC_HOST_NORM_CMD_QUEUE, &fib_size, &fib)) + break; /* nothing to do */ + + switch(fib->Header.Command) { + case AifRequest: + aac_handle_aif(sc, (struct aac_aif_command *)&fib->data[0]); + break; + default: + device_printf(sc->aac_dev, "unknown command from controller\n"); + AAC_PRINT_FIB(sc, fib); + break; + } + + /* XXX reply to FIBs requesting responses ?? */ + /* XXX how do we return these FIBs to the controller? */ + } +} + +/******************************************************************************** + * Handle notification of one or more FIBs completed by the controller + */ +static void +aac_host_response(struct aac_softc *sc) +{ + struct aac_command *cm; + struct aac_fib *fib; + u_int32_t fib_size; + + debug_called(2); + + for (;;) { + /* look for completed FIBs on our queue */ + if (aac_dequeue_fib(sc, AAC_HOST_NORM_RESP_QUEUE, &fib_size, &fib)) + break; /* nothing to do */ + + /* get the command, unmap and queue for later processing */ + cm = (struct aac_command *)fib->Header.SenderData; + if (cm == NULL) { + AAC_PRINT_FIB(sc, fib); + } else { + aac_unmap_command(cm); /* XXX defer? */ + aac_enqueue_completed(cm); + } + } + + /* handle completion processing */ +#if __FreeBSD_version >= 500005 + taskqueue_enqueue(taskqueue_swi, &sc->aac_task_complete); +#else + aac_complete(sc, 0); +#endif +} + +/******************************************************************************** + * Process completed commands. + */ +static void +aac_complete(void *context, int pending) +{ + struct aac_softc *sc = (struct aac_softc *)context; + struct aac_command *cm; + + debug_called(2); + + /* pull completed commands off the queue */ + for (;;) { + cm = aac_dequeue_completed(sc); + if (cm == NULL) + return; + cm->cm_flags |= AAC_CMD_COMPLETED; + + /* is there a completion handler? */ + if (cm->cm_complete != NULL) { + cm->cm_complete(cm); + } else { + /* assume that someone is sleeping on this command */ + wakeup(cm); + } + } +} + +/******************************************************************************** + * Handle a bio submitted from a disk device. + */ +void +aac_submit_bio(struct bio *bp) +{ + struct aac_disk *ad = (struct aac_disk *)bp->bio_dev->si_drv1; + struct aac_softc *sc = ad->ad_controller; + + debug_called(2); + + /* queue the BIO and try to get some work done */ + bioq_insert_tail(&sc->aac_bioq, bp); + aac_startio(sc); +} + +/******************************************************************************** + * Get a bio and build a command to go with it. + */ +static int +aac_bio_command(struct aac_softc *sc, struct aac_command **cmp) +{ + struct aac_command *cm; + struct aac_fib *fib; + struct aac_blockread *br; + struct aac_blockwrite *bw; + struct aac_disk *ad; + struct bio *bp; + int s; + + debug_called(2); + + /* get the resources we will need */ + cm = NULL; + s = splbio(); + if ((bp = bioq_first(&sc->aac_bioq))) + bioq_remove(&sc->aac_bioq, bp); + splx(s); + if (bp == NULL) /* no work? */ + goto fail; + if (aac_alloc_command(sc, &cm)) /* get a command */ + goto fail; + + /* fill out the command */ + cm->cm_private = bp; + + /* build the FIB */ + fib = cm->cm_fib; + fib->Header.XferState = + AAC_FIBSTATE_HOSTOWNED | + AAC_FIBSTATE_INITIALISED | + AAC_FIBSTATE_FROMHOST | + AAC_FIBSTATE_REXPECTED | + AAC_FIBSTATE_NORM; + fib->Header.Command = ContainerCommand; + fib->Header.Size = sizeof(struct aac_fib_header); + + /* build the read/write request */ + ad = (struct aac_disk *)bp->bio_dev->si_drv1; + cm->cm_data = (void *)bp->bio_data; + cm->cm_datalen = bp->bio_bcount; + cm->cm_complete = aac_bio_complete; + if (BIO_IS_READ(bp)) { + br = (struct aac_blockread *)&fib->data[0]; + br->Command = VM_CtBlockRead; + br->ContainerId = ad->ad_container->co_mntobj.ObjectId; + br->BlockNumber = bp->bio_pblkno; + br->ByteCount = bp->bio_bcount; + fib->Header.Size += sizeof(struct aac_blockread); + cm->cm_sgtable = &br->SgMap; + cm->cm_flags |= AAC_CMD_DATAIN; + } else { + bw = (struct aac_blockwrite *)&fib->data[0]; + bw->Command = VM_CtBlockWrite; + bw->ContainerId = ad->ad_container->co_mntobj.ObjectId; + bw->BlockNumber = bp->bio_pblkno; + bw->ByteCount = bp->bio_bcount; + bw->Stable = CUNSTABLE; /* XXX what's appropriate here? */ + fib->Header.Size += sizeof(struct aac_blockwrite); + cm->cm_flags |= AAC_CMD_DATAOUT; + cm->cm_sgtable = &bw->SgMap; + } + + *cmp = cm; + return(0); + +fail: + if (bp != NULL) + bioq_insert_tail(&sc->aac_bioq, bp); + if (cm != NULL) + aac_release_command(cm); + return(ENOMEM); +} + +/******************************************************************************** + * Handle a bio-instigated command that has been completed. + */ +static void +aac_bio_complete(struct aac_command *cm) +{ + struct aac_softc *sc = cm->cm_sc; + struct aac_blockread_response *brr; + struct aac_blockwrite_response *bwr; + struct bio *bp; + AAC_FSAStatus status; + + /* fetch relevant status and then release the command */ + bp = (struct bio *)cm->cm_private; + if (BIO_IS_READ(bp)) { + brr = (struct aac_blockread_response *)&cm->cm_fib->data[0]; + status = brr->Status; + } else { + bwr = (struct aac_blockwrite_response *)&cm->cm_fib->data[0]; + status = bwr->Status; + } + aac_release_command(cm); + + /* fix up the bio based on status */ + if (status == ST_OK) { + bp->bio_resid = 0; + } else { + bp->bio_error = EIO; + bp->bio_flags |= BIO_ERROR; + + /* XXX be more verbose? */ + device_printf(sc->aac_dev, "I/O error %d (%s)\n", status, AAC_COMMAND_STATUS(status)); + } + aac_complete_bio(bp); /* XXX rename one of these functions! */ +} + +/******************************************************************************** + * Submit a command to the controller, return when it completes. + */ +static int +aac_wait_command(struct aac_command *cm, int timeout) +{ + int s, error = 0; + + debug_called(2); + + /* Put the command on the ready queue and get things going */ + aac_enqueue_ready(cm); + aac_startio(cm->cm_sc); + s = splbio(); + while(!(cm->cm_flags & AAC_CMD_COMPLETED) && (error != EWOULDBLOCK)) { + error = tsleep(cm, PRIBIO, "aacwait", timeout * hz); + } + splx(s); + return(error); +} + +/******************************************************************************** + ******************************************************************************** + Command Buffer Management + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Allocate a command. + */ +static int +aac_alloc_command(struct aac_softc *sc, struct aac_command **cmp) +{ + struct aac_command *cm; + + debug_called(3); + + cm = aac_dequeue_free(sc); + if (cm == NULL) { + aac_alloc_command_cluster(sc); + cm = aac_dequeue_free(sc); + } + if (cm == NULL) + return(ENOMEM); + + /* initialise the command/FIB */ + cm->cm_sgtable = NULL; + cm->cm_flags = 0; + cm->cm_complete = NULL; + cm->cm_private = NULL; + cm->cm_fib->Header.XferState = AAC_FIBSTATE_EMPTY; + cm->cm_fib->Header.StructType = AAC_FIBTYPE_TFIB; + cm->cm_fib->Header.Flags = 0; + cm->cm_fib->Header.SenderSize = sizeof(struct aac_fib); + + /* + * These are duplicated in aac_start to cover the case where an + * intermediate stage may have destroyed them. They're left + * initialised here for debugging purposes only. + */ + cm->cm_fib->Header.SenderFibAddress = (u_int32_t)cm->cm_fib; + cm->cm_fib->Header.ReceiverFibAddress = cm->cm_fibphys; + + *cmp = cm; + return(0); +} + +/******************************************************************************** + * Release a command back to the freelist. + */ +static void +aac_release_command(struct aac_command *cm) +{ + debug_called(3); + + aac_enqueue_free(cm); +} + +/******************************************************************************** + * Map helper for command cluster allocation. Tell each of the FIBs what its + * address in the adapter's space is, fill in a few other fields. + */ +static void +aac_map_command_cluster(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + struct aac_command_cluster *cmc = (struct aac_command_cluster *)arg; + + debug_called(3); + + cmc->cmc_fibphys = segs[0].ds_addr; +} + +/******************************************************************************** + * Allocate and initialise a cluster of commands. + */ +static void +aac_alloc_command_cluster(struct aac_softc *sc) +{ + struct aac_command_cluster *cmc; + struct aac_command *cm; + int i; + + debug_called(1); + + cmc = malloc(sizeof(struct aac_command_cluster), M_DEVBUF, M_NOWAIT); + if (cmc != NULL) { + bzero(cmc, sizeof(*cmc)); + + /* allocate the FIB cluster in DMAable memory and load it */ + if (bus_dmamem_alloc(sc->aac_fib_dmat, (void **)&cmc->cmc_fibs, BUS_DMA_NOWAIT, &cmc->cmc_fibmap)) { + free(cmc, M_DEVBUF); + return; + } + bus_dmamap_load(sc->aac_fib_dmat, cmc->cmc_fibmap, cmc->cmc_fibs, + AAC_CLUSTER_COUNT * sizeof(struct aac_fib), aac_map_command_cluster, cmc, 0); + + aac_enqueue_cluster(sc, cmc); + for (i = 0; i < AAC_CLUSTER_COUNT; i++) { + cm = &cmc->cmc_command[i]; + cm->cm_sc = sc; + cm->cm_fib = cmc->cmc_fibs + i; + cm->cm_fibphys = cmc->cmc_fibphys + (i * sizeof(struct aac_fib)); + + if (!bus_dmamap_create(sc->aac_buffer_dmat, 0, &cm->cm_datamap)) + aac_release_command(cm); + } + } else { + debug(2, "can't allocate memeory for command cluster"); + } +} + +/******************************************************************************** + * Free a command cluster. + */ +static void +aac_free_command_cluster(struct aac_command_cluster *cmc) +{ + struct aac_softc *sc = cmc->cmc_command[0].cm_sc; + int i; + + debug_called(1); + + for (i = 0; i < AAC_CLUSTER_COUNT; i++) + bus_dmamap_destroy(sc->aac_buffer_dmat, cmc->cmc_command[i].cm_datamap); + bus_dmamap_unload(sc->aac_fib_dmat, cmc->cmc_fibmap); + bus_dmamem_free(sc->aac_fib_dmat, cmc->cmc_fibs, cmc->cmc_fibmap); + + free(cmc, M_DEVBUF); +} + +/******************************************************************************** + * Command-mapping helper function - populate this command's s/g table. + */ +static void +aac_map_command_sg(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + struct aac_command *cm = (struct aac_command *)arg; + struct aac_fib *fib = cm->cm_fib; + struct aac_sg_table *sg; + int i; + + debug_called(3); + + /* find the s/g table */ + sg = cm->cm_sgtable; + + /* copy into the FIB */ + if (sg != NULL) { + sg->SgCount = nseg; + for (i = 0; i < nseg; i++) { + sg->SgEntry[i].SgAddress = segs[i].ds_addr; + sg->SgEntry[i].SgByteCount = segs[i].ds_len; + } + /* update the FIB size for the s/g count */ + fib->Header.Size += nseg * sizeof(struct aac_sg_entry); + } + +} + +/******************************************************************************** + * Map a command into controller-visible space. + */ +static void +aac_map_command(struct aac_command *cm) +{ + struct aac_softc *sc = cm->cm_sc; + + debug_called(2); + + /* don't map more than once */ + if (cm->cm_flags & AAC_CMD_MAPPED) + return; + + if (cm->cm_datalen != 0) { + bus_dmamap_load(sc->aac_buffer_dmat, cm->cm_datamap, cm->cm_data, + cm->cm_datalen, aac_map_command_sg, cm, 0); + + if (cm->cm_flags & AAC_CMD_DATAIN) + bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, BUS_DMASYNC_PREREAD); + if (cm->cm_flags & AAC_CMD_DATAOUT) + bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, BUS_DMASYNC_PREWRITE); + } + cm->cm_flags |= AAC_CMD_MAPPED; +} + +/******************************************************************************** + * Unmap a command from controller-visible space. + */ +static void +aac_unmap_command(struct aac_command *cm) +{ + struct aac_softc *sc = cm->cm_sc; + + debug_called(2); + + if (!(cm->cm_flags & AAC_CMD_MAPPED)) + return; + + if (cm->cm_datalen != 0) { + if (cm->cm_flags & AAC_CMD_DATAIN) + bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, BUS_DMASYNC_POSTREAD); + if (cm->cm_flags & AAC_CMD_DATAOUT) + bus_dmamap_sync(sc->aac_buffer_dmat, cm->cm_datamap, BUS_DMASYNC_POSTWRITE); + + bus_dmamap_unload(sc->aac_buffer_dmat, cm->cm_datamap); + } + cm->cm_flags &= ~AAC_CMD_MAPPED; +} + +/******************************************************************************** + ******************************************************************************** + Hardware Interface + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Initialise the adapter. + */ +static void +aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + struct aac_softc *sc = (struct aac_softc *)arg; + + debug_called(1); + + sc->aac_common_busaddr = segs[0].ds_addr; +} + +static int +aac_init(struct aac_softc *sc) +{ + struct aac_adapter_init *ip; + time_t then; + u_int32_t code; + u_int8_t *qaddr; + + debug_called(1); + + /* + * First wait for the adapter to come ready. + */ + then = time_second; + do { + code = AAC_GET_FWSTATUS(sc); + if (code & AAC_SELF_TEST_FAILED) { + device_printf(sc->aac_dev, "FATAL: selftest failed\n"); + return(ENXIO); + } + if (code & AAC_KERNEL_PANIC) { + device_printf(sc->aac_dev, "FATAL: controller kernel panic\n"); + return(ENXIO); + } + if (time_second > (then + AAC_BOOT_TIMEOUT)) { + device_printf(sc->aac_dev, "FATAL: controller not coming ready, status %x\n", code); + return(ENXIO); + } + } while (!(code & AAC_UP_AND_RUNNING)); + + /* + * Create DMA tag for the common structure and allocate it. + */ + if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + sizeof(struct aac_common), 1,/* maxsize, nsegments */ + BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ + 0, /* flags */ + &sc->aac_common_dmat)) { + device_printf(sc->aac_dev, "can't allocate common structure DMA tag\n"); + return(ENOMEM); + } + if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common, BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) { + device_printf(sc->aac_dev, "can't allocate common structure\n"); + return(ENOMEM); + } + bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap, sc->aac_common, sizeof(*sc->aac_common), + aac_common_map, sc, 0); + bzero(sc->aac_common, sizeof(*sc->aac_common)); + + /* + * Fill in the init structure. This tells the adapter about the physical location + * of various important shared data structures. + */ + ip = &sc->aac_common->ac_init; + ip->InitStructRevision = AAC_INIT_STRUCT_REVISION; + + ip->AdapterFibsPhysicalAddress = sc->aac_common_busaddr + fldoff(aac_common, ac_fibs); + ip->AdapterFibsVirtualAddress = &sc->aac_common->ac_fibs[0]; + ip->AdapterFibsSize = AAC_ADAPTER_FIBS * sizeof(struct aac_fib); + ip->AdapterFibAlign = sizeof(struct aac_fib); + + ip->PrintfBufferAddress = sc->aac_common_busaddr + fldoff(aac_common, ac_printf); + ip->PrintfBufferSize = AAC_PRINTF_BUFSIZE; + + ip->HostPhysMemPages = 0; /* not used? */ + ip->HostElapsedSeconds = time_second; /* reset later if invalid */ + + /* + * Initialise FIB queues. Note that it appears that the layout of the indexes + * and the segmentation of the entries is mandated by the adapter, which is + * only told about the base of the queue index fields. + * + * The initial values of the indices are assumed to inform the adapter + * of the sizes of the respective queues. + * + * The Linux driver uses a much more complex scheme whereby several header + * records are kept for each queue. We use a couple of generic list manipulation + * functions which 'know' the size of each list by virtue of a table. + */ + qaddr = &sc->aac_common->ac_qbuf[0] + AAC_QUEUE_ALIGN; + qaddr -= (u_int32_t)qaddr % AAC_QUEUE_ALIGN; + sc->aac_queues = (struct aac_queue_table *)qaddr; + ip->CommHeaderAddress = sc->aac_common_busaddr + ((u_int32_t)sc->aac_queues - (u_int32_t)sc->aac_common); + bzero(sc->aac_queues, sizeof(struct aac_queue_table)); + + sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX] = AAC_HOST_NORM_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX] = AAC_HOST_NORM_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX] = AAC_HOST_HIGH_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX] = AAC_HOST_HIGH_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX] = AAC_ADAP_NORM_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX] = AAC_ADAP_NORM_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX] = AAC_ADAP_HIGH_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX] = AAC_ADAP_HIGH_CMD_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX] = AAC_HOST_NORM_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX] = AAC_HOST_NORM_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX] = AAC_HOST_HIGH_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX] = AAC_HOST_HIGH_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX] = AAC_ADAP_NORM_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX] = AAC_ADAP_NORM_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX] = AAC_ADAP_HIGH_RESP_ENTRIES; + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX] = AAC_ADAP_HIGH_RESP_ENTRIES; + sc->aac_qentries[AAC_HOST_NORM_CMD_QUEUE] = &sc->aac_queues->qt_HostNormCmdQueue[0]; + sc->aac_qentries[AAC_HOST_HIGH_CMD_QUEUE] = &sc->aac_queues->qt_HostHighCmdQueue[0]; + sc->aac_qentries[AAC_ADAP_NORM_CMD_QUEUE] = &sc->aac_queues->qt_AdapNormCmdQueue[0]; + sc->aac_qentries[AAC_ADAP_HIGH_CMD_QUEUE] = &sc->aac_queues->qt_AdapHighCmdQueue[0]; + sc->aac_qentries[AAC_HOST_NORM_RESP_QUEUE] = &sc->aac_queues->qt_HostNormRespQueue[0]; + sc->aac_qentries[AAC_HOST_HIGH_RESP_QUEUE] = &sc->aac_queues->qt_HostHighRespQueue[0]; + sc->aac_qentries[AAC_ADAP_NORM_RESP_QUEUE] = &sc->aac_queues->qt_AdapNormRespQueue[0]; + sc->aac_qentries[AAC_ADAP_HIGH_RESP_QUEUE] = &sc->aac_queues->qt_AdapHighRespQueue[0]; + + /* + * Do controller-type-specific initialisation + */ + switch (sc->aac_hwif) { + case AAC_HWIF_I960RX: + AAC_SETREG4(sc, AAC_RX_ODBR, ~0); + break; + } + + /* + * Give the init structure to the controller. + */ + if (aac_sync_command(sc, AAC_MONKER_INITSTRUCT, + sc->aac_common_busaddr + fldoff(aac_common, ac_init), + 0, 0, 0, NULL)) { + device_printf(sc->aac_dev, "error establishing init structure\n"); + return(EIO); + } + + return(0); +} + +/******************************************************************************** + * Send a synchronous command to the controller and wait for a result. + */ +static int +aac_sync_command(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3, + u_int32_t *sp) +{ + time_t then; + u_int32_t status; + + debug_called(3); + + /* populate the mailbox */ + AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3); + + /* ensure the sync command doorbell flag is cleared */ + AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND); + + /* then set it to signal the adapter */ + AAC_QNOTIFY(sc, AAC_DB_SYNC_COMMAND); + + /* spin waiting for the command to complete */ + then = time_second; + do { + if (time_second > (then + AAC_IMMEDIATE_TIMEOUT)) { + debug(2, "timed out"); + return(EIO); + } + } while (!(AAC_GET_ISTATUS(sc) & AAC_DB_SYNC_COMMAND)); + + /* clear the completion flag */ + AAC_CLEAR_ISTATUS(sc, AAC_DB_SYNC_COMMAND); + + /* get the command status */ + status = AAC_GET_MAILBOXSTATUS(sc); + if (sp != NULL) + *sp = status; + return(0); /* check command return status? */ +} + +/******************************************************************************** + * Send a synchronous FIB to the controller and wait for a result. + */ +static int +aac_sync_fib(struct aac_softc *sc, u_int32_t command, u_int32_t xferstate, + void *data, u_int16_t datasize, + void *result, u_int16_t *resultsize) +{ + struct aac_fib *fib = &sc->aac_common->ac_sync_fib; + + debug_called(3); + + if (datasize > AAC_FIB_DATASIZE) + return(EINVAL); + + /* + * Set up the sync FIB + */ + fib->Header.XferState = AAC_FIBSTATE_HOSTOWNED | AAC_FIBSTATE_INITIALISED | AAC_FIBSTATE_EMPTY; + fib->Header.XferState |= xferstate; + fib->Header.Command = command; + fib->Header.StructType = AAC_FIBTYPE_TFIB; + fib->Header.Size = sizeof(struct aac_fib) + datasize; + fib->Header.SenderSize = sizeof(struct aac_fib); + fib->Header.SenderFibAddress = (u_int32_t)fib; + fib->Header.ReceiverFibAddress = sc->aac_common_busaddr + fldoff(aac_common, ac_sync_fib); + + /* + * Copy in data. + */ + if (data != NULL) { + bcopy(data, fib->data, datasize); + fib->Header.XferState |= AAC_FIBSTATE_FROMHOST | AAC_FIBSTATE_NORM; + } + + /* + * Give the FIB to the controller, wait for a response. + */ + if (aac_sync_command(sc, AAC_MONKER_SYNCFIB, fib->Header.ReceiverFibAddress, + 0, 0, 0, NULL)) { + debug(2, "IO error"); + return(EIO); + } + + /* + * Copy out the result + */ + if (result != NULL) { + *resultsize = fib->Header.Size - sizeof(struct aac_fib_header); + bcopy(fib->data, result, *resultsize); + } + return(0); +} + +/******************************************************************************** + * Adapter-space FIB queue manipulation + * + * Note that the queue implementation here is a little funky; neither the PI or + * CI will ever be zero. This behaviour is a controller feature. + */ +static struct { + int size; + int notify; +} aac_qinfo[] = { + {AAC_HOST_NORM_CMD_ENTRIES, AAC_DB_COMMAND_NOT_FULL}, + {AAC_HOST_HIGH_CMD_ENTRIES, 0}, + {AAC_ADAP_NORM_CMD_ENTRIES, AAC_DB_COMMAND_READY}, + {AAC_ADAP_HIGH_CMD_ENTRIES, 0}, + {AAC_HOST_NORM_RESP_ENTRIES, AAC_DB_RESPONSE_NOT_FULL}, + {AAC_HOST_HIGH_RESP_ENTRIES, 0}, + {AAC_ADAP_NORM_RESP_ENTRIES, AAC_DB_RESPONSE_READY}, + {AAC_ADAP_HIGH_RESP_ENTRIES, 0} +}; + +/* + * Atomically insert an entry into the nominated queue, returns 0 on success or EBUSY + * if the queue is full. + * + * XXX note that it would be more efficient to defer notifying the controller in + * the case where we may be inserting several entries in rapid succession, but + * implementing this usefully is difficult. + */ +static int +aac_enqueue_fib(struct aac_softc *sc, int queue, u_int32_t fib_size, u_int32_t fib_addr) +{ + u_int32_t pi, ci; + int s, error; + + debug_called(3); + + s = splbio(); + + /* get the producer/consumer indices */ + pi = sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX]; + ci = sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX]; + + /* wrap the queue? */ + if (pi >= aac_qinfo[queue].size) + pi = 0; + + /* check for queue full */ + if ((pi + 1) == ci) { + error = EBUSY; + goto out; + } + + /* populate queue entry */ + (sc->aac_qentries[queue] + pi)->aq_fib_size = fib_size; + (sc->aac_qentries[queue] + pi)->aq_fib_addr = fib_addr; + + /* update producer index */ + sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX] = pi + 1; + + /* notify the adapter if we know how */ + if (aac_qinfo[queue].notify != 0) + AAC_QNOTIFY(sc, aac_qinfo[queue].notify); + + error = 0; + +out: + splx(s); + return(error); +} + +/* + * Atomically remove one entry from the nominated queue, returns 0 on success or ENOENT + * if the queue is empty. + */ +static int +aac_dequeue_fib(struct aac_softc *sc, int queue, u_int32_t *fib_size, struct aac_fib **fib_addr) +{ + u_int32_t pi, ci; + int s, error; + + debug_called(3); + + s = splbio(); + + /* get the producer/consumer indices */ + pi = sc->aac_queues->qt_qindex[queue][AAC_PRODUCER_INDEX]; + ci = sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX]; + + /* check for queue empty */ + if (ci == pi) { + error = ENOENT; + goto out; + } + + /* wrap the queue? */ + if (ci >= aac_qinfo[queue].size) + ci = 0; + + /* fetch the entry */ + *fib_size = (sc->aac_qentries[queue] + ci)->aq_fib_size; + *fib_addr = (struct aac_fib *)(sc->aac_qentries[queue] + ci)->aq_fib_addr; + + /* update consumer index */ + sc->aac_queues->qt_qindex[queue][AAC_CONSUMER_INDEX] = ci + 1; + + /* if we have made the queue un-full, notify the adapter */ + if (((pi + 1) == ci) && (aac_qinfo[queue].notify != 0)) + AAC_QNOTIFY(sc, aac_qinfo[queue].notify); + error = 0; + +out: + splx(s); + return(error); +} + +/******************************************************************************** + ******************************************************************************** + Interface Function Vectors + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Read the current firmware status word. + */ +static int +aac_sa_get_fwstatus(struct aac_softc *sc) +{ + debug_called(3); + + return(AAC_GETREG4(sc, AAC_SA_FWSTATUS)); +} + +static int +aac_rx_get_fwstatus(struct aac_softc *sc) +{ + debug_called(3); + + return(AAC_GETREG4(sc, AAC_RX_FWSTATUS)); +} + +/******************************************************************************** + * Notify the controller of a change in a given queue + */ + +static void +aac_sa_qnotify(struct aac_softc *sc, int qbit) +{ + debug_called(3); + + AAC_SETREG2(sc, AAC_SA_DOORBELL1_SET, qbit); +} + +static void +aac_rx_qnotify(struct aac_softc *sc, int qbit) +{ + debug_called(3); + + AAC_SETREG4(sc, AAC_RX_IDBR, qbit); +} + +/******************************************************************************** + * Get the interrupt reason bits + */ +static int +aac_sa_get_istatus(struct aac_softc *sc) +{ + debug_called(3); + + return(AAC_GETREG2(sc, AAC_SA_DOORBELL0)); +} + +static int +aac_rx_get_istatus(struct aac_softc *sc) +{ + debug_called(3); + + return(AAC_GETREG4(sc, AAC_RX_ODBR)); +} + +/******************************************************************************** + * Clear some interrupt reason bits + */ +static void +aac_sa_clear_istatus(struct aac_softc *sc, int mask) +{ + debug_called(3); + + AAC_SETREG2(sc, AAC_SA_DOORBELL0_CLEAR, mask); +} + +static void +aac_rx_clear_istatus(struct aac_softc *sc, int mask) +{ + debug_called(3); + + AAC_SETREG4(sc, AAC_RX_ODBR, mask); +} + +/******************************************************************************** + * Populate the mailbox and set the command word + */ +static void +aac_sa_set_mailbox(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3) +{ + debug_called(4); + + AAC_SETREG4(sc, AAC_SA_MAILBOX, command); + AAC_SETREG4(sc, AAC_SA_MAILBOX + 4, arg0); + AAC_SETREG4(sc, AAC_SA_MAILBOX + 8, arg1); + AAC_SETREG4(sc, AAC_SA_MAILBOX + 12, arg2); + AAC_SETREG4(sc, AAC_SA_MAILBOX + 16, arg3); +} + +static void +aac_rx_set_mailbox(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3) +{ + debug_called(4); + + AAC_SETREG4(sc, AAC_RX_MAILBOX, command); + AAC_SETREG4(sc, AAC_RX_MAILBOX + 4, arg0); + AAC_SETREG4(sc, AAC_RX_MAILBOX + 8, arg1); + AAC_SETREG4(sc, AAC_RX_MAILBOX + 12, arg2); + AAC_SETREG4(sc, AAC_RX_MAILBOX + 16, arg3); +} + +/******************************************************************************** + * Fetch the immediate command status word + */ +static int +aac_sa_get_mailboxstatus(struct aac_softc *sc) +{ + debug_called(4); + + return(AAC_GETREG4(sc, AAC_SA_MAILBOX)); +} + +static int +aac_rx_get_mailboxstatus(struct aac_softc *sc) +{ + debug_called(4); + + return(AAC_GETREG4(sc, AAC_RX_MAILBOX)); +} + +/******************************************************************************** + * Set/clear interrupt masks + */ +static void +aac_sa_set_interrupts(struct aac_softc *sc, int enable) +{ + debug(2, "%sable interrupts", enable ? "en" : "dis"); + + if (enable) { + AAC_SETREG2((sc), AAC_SA_MASK0_CLEAR, AAC_DB_INTERRUPTS); + } else { + AAC_SETREG2((sc), AAC_SA_MASK0_SET, ~0); + } +} + +static void +aac_rx_set_interrupts(struct aac_softc *sc, int enable) +{ + debug(2, "%sable interrupts", enable ? "en" : "dis"); + + if (enable) { + AAC_SETREG4(sc, AAC_RX_OIMR, ~AAC_DB_INTERRUPTS); + } else { + AAC_SETREG4(sc, AAC_RX_OIMR, ~0); + } +} + +/******************************************************************************** + ******************************************************************************** + Debugging and Diagnostics + ******************************************************************************** + ********************************************************************************/ + +/******************************************************************************** + * Print some information about the controller. + */ +static void +aac_describe_controller(struct aac_softc *sc) +{ + u_int8_t buf[AAC_FIB_DATASIZE]; /* XXX really a bit big for the stack */ + u_int16_t bufsize; + struct aac_adapter_info *info; + u_int8_t arg; + + debug_called(2); + + arg = 0; + if (aac_sync_fib(sc, RequestAdapterInfo, 0, &arg, sizeof(arg), &buf, &bufsize)) { + device_printf(sc->aac_dev, "RequestAdapterInfo failed\n"); + return; + } + if (bufsize != sizeof(*info)) { + device_printf(sc->aac_dev, "RequestAdapterInfo returned wrong data size (%d != %d)\n", + bufsize, sizeof(*info)); + return; + } + info = (struct aac_adapter_info *)&buf[0]; + + device_printf(sc->aac_dev, "%s %dMHz, %dMB total memory, %s (%d)\n", + aac_describe_code(aac_cpu_variant, info->CpuVariant), info->ClockSpeed, + info->TotalMem / (1024 * 1024), + aac_describe_code(aac_battery_platform, info->batteryPlatform), info->batteryPlatform); + + /* save the kernel revision structure for later use */ + sc->aac_revision = info->KernelRevision; + device_printf(sc->aac_dev, "Kernel %d.%d-%d, S/N %llx\n", + info->KernelRevision.external.comp.major, + info->KernelRevision.external.comp.minor, + info->KernelRevision.external.comp.dash, + info->SerialNumber); /* XXX how is this meant to be formatted? */ +} + +/******************************************************************************** + * Look up a text description of a numeric error code and return a pointer to + * same. + */ +static char * +aac_describe_code(struct aac_code_lookup *table, u_int32_t code) +{ + int i; + + for (i = 0; table[i].string != NULL; i++) + if (table[i].code == code) + return(table[i].string); + return(table[i+1].string); +} + +/***************************************************************************** + ***************************************************************************** + Management Interface + ***************************************************************************** + *****************************************************************************/ + +static int +aac_open(dev_t dev, int flags, int fmt, struct proc *p) +{ + struct aac_softc *sc = dev->si_drv1; + + debug_called(2); + + /* Check to make sure the device isn't already open */ + if (sc->aac_state & AAC_STATE_OPEN) { + return EBUSY; + } + sc->aac_state |= AAC_STATE_OPEN; + + return 0; +} + +static int +aac_close(dev_t dev, int flags, int fmt, struct proc *p) +{ + struct aac_softc *sc = dev->si_drv1; + + debug_called(2); + + /* Mark this unit as no longer open */ + sc->aac_state &= ~AAC_STATE_OPEN; + + return 0; +} + +static int +aac_ioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p) +{ + struct aac_softc *sc = dev->si_drv1; + int error = 0, i; + + debug_called(2); + + switch (cmd) { +#ifdef AAC_COMPAT_LINUX + case FSACTL_SENDFIB: + debug(0, "FSACTL_SENDFIB"); + error = aac_ioctl_sendfib(sc, arg); + break; + case FSACTL_AIF_THREAD: + debug(0, "FSACTL_AIF_THREAD"); + error = EINVAL; + break; + case FSACTL_OPEN_GET_ADAPTER_FIB: + debug(0, "FSACTL_OPEN_GET_ADAPTER_FIB"); + /* + * Pass the caller out an AdapterFibContext. + * + * Note that because we only support one opener, we + * basically ignore this. Set the caller's context to a magic + * number just in case. + */ + i = AAC_AIF_SILLYMAGIC; + error = copyout(&i, arg, sizeof(i)); + break; + case FSACTL_GET_NEXT_ADAPTER_FIB: + debug(0, "FSACTL_GET_NEXT_ADAPTER_FIB"); + error = aac_linux_getnext_aif(sc, arg); + break; + case FSACTL_CLOSE_GET_ADAPTER_FIB: + debug(0, "FSACTL_CLOSE_GET_ADAPTER_FIB"); + /* don't do anything here */ + break; + case FSACTL_MINIPORT_REV_CHECK: + debug(0, "FSACTL_MINIPORT_REV_CHECK"); + error = aac_linux_rev_check(sc, arg); + break; +#endif + default: + device_printf(sc->aac_dev, "unsupported cmd 0x%lx\n", cmd); + error = EINVAL; + break; + } + return(error); +} + +/******************************************************************************** + * Send a FIB supplied from userspace + */ +static int +aac_ioctl_sendfib(struct aac_softc *sc, caddr_t ufib) +{ + struct aac_command *cm; + int size, error; + + debug_called(2); + + cm = NULL; + + /* + * Get a command + */ + if (aac_alloc_command(sc, &cm)) { + error = EBUSY; + goto out; + } + + /* + * Fetch the FIB header, then re-copy to get data as well. + */ + if ((error = copyin(ufib, cm->cm_fib, sizeof(struct aac_fib_header))) != 0) + goto out; + size = cm->cm_fib->Header.Size + sizeof(struct aac_fib_header); + if (size > sizeof(struct aac_fib)) { + device_printf(sc->aac_dev, "incoming FIB oversized (%d > %d)\n", size, sizeof(struct aac_fib)); + size = sizeof(struct aac_fib); + } + if ((error = copyin(ufib, cm->cm_fib, size)) != 0) + goto out; + cm->cm_fib->Header.Size = size; + + /* + * Pass the FIB to the controller, wait for it to complete. + */ + if ((error = aac_wait_command(cm, 30)) != 0) /* XXX user timeout? */ + goto out; + + /* + * Copy the FIB and data back out to the caller. + */ + size = cm->cm_fib->Header.Size; + if (size > sizeof(struct aac_fib)) { + device_printf(sc->aac_dev, "outbound FIB oversized (%d > %d)\n", size, sizeof(struct aac_fib)); + size = sizeof(struct aac_fib); + } + error = copyout(cm->cm_fib, ufib, size); + +out: + if (cm != NULL) + aac_release_command(cm); + return(error); +} + +/******************************************************************************** + * Handle an AIF sent to us by the controller; queue it for later reference. + * + * XXX what's the right thing to do here when the queue is full? Drop the older + * or newer entries? + */ +static void +aac_handle_aif(struct aac_softc *sc, struct aac_aif_command *aif) +{ + int next, s; + + debug_called(2); + + s = splbio(); + next = (sc->aac_aifq_head + 1) % AAC_AIFQ_LENGTH; + if (next != sc->aac_aifq_tail) { + bcopy(aif, &sc->aac_aifq[next], sizeof(struct aac_aif_command)); + sc->aac_aifq_head = next; + if (sc->aac_state & AAC_STATE_AIF_SLEEPER) + wakeup(sc->aac_aifq); + } + splx(s); + aac_print_aif(sc, aif); +} + +/******************************************************************************** + * Hand the next AIF off the top of the queue out to userspace. + */ +static int +aac_return_aif(struct aac_softc *sc, caddr_t uptr) +{ + int error, s; + + debug_called(2); + + s = splbio(); + if (sc->aac_aifq_tail == sc->aac_aifq_head) { + error = EAGAIN; + } else { + error = copyout(&sc->aac_aifq[sc->aac_aifq_tail], uptr, sizeof(struct aac_aif_command)); + if (!error) + sc->aac_aifq_tail = (sc->aac_aifq_tail + 1) % AAC_AIFQ_LENGTH; + } + splx(s); + return(error); +} + +/******************************************************************************** + ******************************************************************************** + Linux Management Interface + ******************************************************************************** + ********************************************************************************/ + +#ifdef AAC_COMPAT_LINUX + +#include <machine/../linux/linux.h> +#include <machine/../linux/linux_proto.h> +#include <compat/linux/linux_ioctl.h> + +#define AAC_LINUX_IOCTL_MIN 0x2000 +#define AAC_LINUX_IOCTL_MAX 0x21ff + +static linux_ioctl_function_t aac_linux_ioctl; +static struct linux_ioctl_handler aac_handler = {aac_linux_ioctl, AAC_LINUX_IOCTL_MIN, AAC_LINUX_IOCTL_MAX}; + +SYSINIT (aac_register, SI_SUB_KLD, SI_ORDER_MIDDLE, linux_ioctl_register_handler, &aac_handler); +SYSUNINIT(aac_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE, linux_ioctl_unregister_handler, &aac_handler); + +MODULE_DEPEND(aac, linux, 1, 1, 1); + +static int +aac_linux_ioctl(struct proc *p, struct linux_ioctl_args *args) +{ + struct file *fp = p->p_fd->fd_ofiles[args->fd]; + u_long cmd = args->cmd; + + /* + * Pass the ioctl off to our standard handler. + */ + return(fo_ioctl(fp, cmd, (caddr_t)args->arg, p)); +} + +/******************************************************************************** + * Return the Revision of the driver to the userspace and check to see if the + * userspace app is possibly compatible. This is extremely bogus right now + * because I have no idea how to handle the versioning of this driver. It is + * needed, though, to get aaccli working. + */ +static int +aac_linux_rev_check(struct aac_softc *sc, caddr_t udata) +{ + struct aac_rev_check rev_check; + struct aac_rev_check_resp rev_check_resp; + int error = 0; + + debug_called(2); + + /* + * Copyin the revision struct from userspace + */ + if ((error = copyin(udata, (caddr_t)&rev_check, sizeof(struct aac_rev_check))) != 0) { + return error; + } + + debug(2, "Userland revision= %d\n", rev_check.callingRevision.buildNumber); + + /* + * Doctor up the response struct. + */ + rev_check_resp.possiblyCompatible = 1; + rev_check_resp.adapterSWRevision.external.ul = sc->aac_revision.external.ul; + rev_check_resp.adapterSWRevision.buildNumber = sc->aac_revision.buildNumber; + + return(copyout((caddr_t)&rev_check_resp, udata, sizeof(struct aac_rev_check_resp))); +} + +/******************************************************************************** + * Pass the caller the next AIF in their queue + */ +static int +aac_linux_getnext_aif(struct aac_softc *sc, caddr_t arg) +{ + struct get_adapter_fib_ioctl agf; + int error, s; + + debug_called(2); + + if ((error = copyin(arg, &agf, sizeof(agf))) == 0) { + + /* + * Check the magic number that we gave the caller. + */ + if (agf.AdapterFibContext != AAC_AIF_SILLYMAGIC) { + error = EFAULT; + } else { + + s = splbio(); + error = aac_return_aif(sc, agf.AifFib); + + if ((error == EAGAIN) && (agf.Wait)) { + sc->aac_state |= AAC_STATE_AIF_SLEEPER; + while (error == EAGAIN) { + error = tsleep(sc->aac_aifq, PRIBIO | PCATCH, "aacaif", 0); + if (error == 0) + error = aac_return_aif(sc, agf.AifFib); + } + sc->aac_state &= ~AAC_STATE_AIF_SLEEPER; + } + splx(s); + } + } + return(error); +} + +#endif /* AAC_COMPAT_LINUX */ diff --git a/sys/dev/aac/aac_compat.h b/sys/dev/aac/aac_compat.h new file mode 100644 index 0000000..26429b5 --- /dev/null +++ b/sys/dev/aac/aac_compat.h @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * Backwards compatibility support. + */ + +/* + * Handle the new/old bio/buf changeover + */ + +#if __FreeBSD_version < 500003 /* old buf style */ +# include <sys/buf.h> +# define FREEBSD_4 +# define bio buf +# define bioq_init(x) bufq_init(x) +# define bioq_insert_tail(x, y) bufq_insert_tail(x, y) +# define bioq_remove(x, y) bufq_remove(x, y) +# define bioq_first(x) bufq_first(x) +# define bio_queue_head buf_queue_head +# define bio_bcount b_bcount +# define bio_blkno b_blkno +# define bio_caller1 b_caller1 +# define bio_data b_data +# define bio_dev b_dev +# define bio_driver1 b_driver1 +# define bio_driver2 b_driver2 +# define bio_error b_error +# define bio_flags b_flags +# define bio_pblkno b_pblkno +# define bio_resid b_resid +# define BIO_ERROR B_ERROR +# define devstat_end_transaction_bio(x, y) devstat_end_transaction_buf(x, y) +# define BIO_IS_READ(x) ((x)->b_flags & B_READ) + +#else /* new bio style */ +# include <sys/bio.h> +#define BIO_IS_READ(x) ((x)->bio_cmd == BIO_READ) +#endif diff --git a/sys/dev/aac/aac_debug.c b/sys/dev/aac/aac_debug.c new file mode 100644 index 0000000..09293ad --- /dev/null +++ b/sys/dev/aac/aac_debug.c @@ -0,0 +1,426 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Debugging support. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> + +#include <dev/aac/aac_compat.h> +#include <sys/bus.h> +#include <sys/devicestat.h> +#include <sys/disk.h> + +#include <machine/resource.h> +#include <machine/bus.h> + +#include <dev/aac/aacreg.h> +#include <dev/aac/aacvar.h> + +void aac_printstate0(void); +void aac_intr0(void); + +/******************************************************************************** + * Dump the command queue indices + */ +void +aac_print_queues(struct aac_softc *sc) +{ + device_printf(sc->aac_dev, "FIB queue header at %p queues at %p\n", + &sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][0], + &sc->aac_queues->qt_HostNormCmdQueue[0]); + device_printf(sc->aac_dev, "HOST_NORM_CMD %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_HOST_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX], + AAC_HOST_NORM_CMD_ENTRIES); + device_printf(sc->aac_dev, "HOST_HIGH_CMD %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX], + AAC_HOST_HIGH_CMD_ENTRIES); + device_printf(sc->aac_dev, "ADAP_NORM_CMD %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_CMD_QUEUE][AAC_CONSUMER_INDEX], + AAC_ADAP_NORM_CMD_ENTRIES); + device_printf(sc->aac_dev, "ADAP_HIGH_CMD %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_CMD_QUEUE][AAC_CONSUMER_INDEX], + AAC_ADAP_HIGH_CMD_ENTRIES); + device_printf(sc->aac_dev, "HOST_NORM_RESP %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_HOST_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX], + AAC_HOST_NORM_RESP_ENTRIES); + device_printf(sc->aac_dev, "HOST_HIGH_RESP %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_HOST_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX], + AAC_HOST_HIGH_RESP_ENTRIES); + device_printf(sc->aac_dev, "ADAP_NORM_RESP %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_ADAP_NORM_RESP_QUEUE][AAC_CONSUMER_INDEX], + AAC_ADAP_NORM_RESP_ENTRIES); + device_printf(sc->aac_dev, "ADAP_HIGH_RESP %d/%d (%d)\n", + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_PRODUCER_INDEX], + sc->aac_queues->qt_qindex[AAC_ADAP_HIGH_RESP_QUEUE][AAC_CONSUMER_INDEX], + AAC_ADAP_HIGH_RESP_ENTRIES); + +} + +/******************************************************************************** + * Print the command queue states for controller 0 (callable from DDB) + */ +void +aac_printstate0(void) +{ + struct aac_softc *sc = devclass_get_softc(aac_devclass, 0); + + aac_print_queues(sc); + switch (sc->aac_hwif) { + case AAC_HWIF_I960RX: + device_printf(sc->aac_dev, "IDBR 0x%08x IIMR 0x%08x IISR 0x%08x\n", + AAC_GETREG4(sc, AAC_RX_IDBR), AAC_GETREG4(sc, AAC_RX_IIMR), AAC_GETREG4(sc, AAC_RX_IISR)); + device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x OISR 0x%08x\n", + AAC_GETREG4(sc, AAC_RX_ODBR), AAC_GETREG4(sc, AAC_RX_OIMR), AAC_GETREG4(sc, AAC_RX_OISR)); + AAC_SETREG4(sc, AAC_RX_OIMR, 0/*~(AAC_DB_COMMAND_READY | AAC_DB_RESPONSE_READY | AAC_DB_PRINTF)*/); + device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x OISR 0x%08x\n", + AAC_GETREG4(sc, AAC_RX_ODBR), AAC_GETREG4(sc, AAC_RX_OIMR), AAC_GETREG4(sc, AAC_RX_OISR)); + break; + case AAC_HWIF_STRONGARM: + /* XXX implement */ + } +} + +/******************************************************************************** + * simulate an interrupt for controller 0 + */ +void +aac_intr0(void) +{ + struct aac_softc *sc = devclass_get_softc(aac_devclass, 0); + + aac_intr(sc); +} + +/******************************************************************************** + * Panic in a slightly informative fashion + */ +void +aac_panic(struct aac_softc *sc, char *reason) +{ + aac_print_queues(sc); + panic(reason); +} + +/******************************************************************************** + * Print a FIB + */ +void +aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, char *caller) +{ + device_printf(sc->aac_dev, "%s: FIB @ %p\n", caller, fib); + device_printf(sc->aac_dev, " XferState %b\n", fib->Header.XferState, "\20" + "\1HOSTOWNED" + "\2ADAPTEROWNED" + "\3INITIALISED" + "\4EMPTY" + "\5FROMPOOL" + "\6FROMHOST" + "\7FROMADAP" + "\10REXPECTED" + "\11RNOTEXPECTED" + "\12DONEADAP" + "\13DONEHOST" + "\14HIGH" + "\15NORM" + "\16ASYNC" + "\17PAGEFILEIO" + "\20SHUTDOWN" + "\21LAZYWRITE" + "\22ADAPMICROFIB" + "\23BIOSFIB" + "\24FAST_RESPONSE" + "\25APIFIB\n"); + device_printf(sc->aac_dev, " Command %d\n", fib->Header.Command); + device_printf(sc->aac_dev, " StructType %d\n", fib->Header.StructType); + device_printf(sc->aac_dev, " Flags 0x%x\n", fib->Header.Flags); + device_printf(sc->aac_dev, " Size %d\n", fib->Header.Size); + device_printf(sc->aac_dev, " SenderSize %d\n", fib->Header.SenderSize); + device_printf(sc->aac_dev, " SenderAddress 0x%x\n", fib->Header.SenderFibAddress); + device_printf(sc->aac_dev, " ReceiverAddress 0x%x\n", fib->Header.ReceiverFibAddress); + device_printf(sc->aac_dev, " SenderData 0x%x\n", fib->Header.SenderData); + switch(fib->Header.Command) { + case ContainerCommand: + { + struct aac_blockread *br = (struct aac_blockread *)fib->data; + struct aac_blockwrite *bw = (struct aac_blockwrite *)fib->data; + struct aac_sg_table *sg = NULL; + int i; + if (br->Command == VM_CtBlockRead) { + device_printf(sc->aac_dev, " BlockRead: container %d 0x%x/%d\n", + br->ContainerId, br->BlockNumber, br->ByteCount); + sg = &br->SgMap; + } + if (bw->Command == VM_CtBlockWrite) { + device_printf(sc->aac_dev, " BlockWrite: container %d 0x%x/%d (%s)\n", + bw->ContainerId, bw->BlockNumber, bw->ByteCount, + bw->Stable == CSTABLE ? "stable" : "unstable"); + sg = &bw->SgMap; + } + if (sg != NULL) { + device_printf(sc->aac_dev, " %d s/g entries\n", sg->SgCount); + for (i = 0; i < sg->SgCount; i++) + device_printf(sc->aac_dev, " 0x%08x/%d\n", sg->SgEntry[i].SgAddress, sg->SgEntry[i].SgByteCount); + } + break; + } + default: + device_printf(sc->aac_dev, " %16D\n", fib->data, " "); + device_printf(sc->aac_dev, " %16D\n", fib->data + 16, " "); + break; + } +} + +/******************************************************************************** + * Describe an AIF we have received. + */ +void +aac_print_aif(struct aac_softc *sc, struct aac_aif_command *aif) +{ + switch(aif->command) { + case AifCmdEventNotify: + device_printf(sc->aac_dev, "EventNotify (%d)\n", aif->seqNumber); + switch(aif->data.EN.type) { + case AifEnGeneric: /* Generic notification */ + device_printf(sc->aac_dev, "(Generic) %.*s\n", + (int)sizeof(aif->data.EN.data.EG), aif->data.EN.data.EG.text); + break; + case AifEnTaskComplete: /* Task has completed */ + device_printf(sc->aac_dev, "(TaskComplete)\n"); + break; + case AifEnConfigChange: /* Adapter configuration change occurred */ + device_printf(sc->aac_dev, "(ConfigChange)\n"); + break; + case AifEnContainerChange: /* Adapter specific container configuration change */ + device_printf(sc->aac_dev, "(ContainerChange) container %d,%d\n", + aif->data.EN.data.ECC.container[0], + aif->data.EN.data.ECC.container[1]); + break; + case AifEnDeviceFailure: /* SCSI device failed */ + device_printf(sc->aac_dev, "(DeviceFailure) handle %d\n", + aif->data.EN.data.EDF.deviceHandle); /* XXX interpret */ + break; + case AifEnMirrorFailover: /* Mirror failover started */ + device_printf(sc->aac_dev, "(MirrorFailover) container %d failed, migrating from slice %d to %d\n", + aif->data.EN.data.EMF.container, + aif->data.EN.data.EMF.failedSlice, + aif->data.EN.data.EMF.creatingSlice); + break; + case AifEnContainerEvent: /* Significant container event */ + device_printf(sc->aac_dev, "(ContainerEvent) container %d event %d\n", + aif->data.EN.data.ECE.container, + aif->data.EN.data.ECE.eventType); /* XXX interpret? */ + break; + case AifEnFileSystemChange: /* File system changed */ + device_printf(sc->aac_dev, "(FileSystemChange)\n"); + break; + case AifEnConfigPause: /* Container pause event */ + device_printf(sc->aac_dev, "(ConfigPause)\n"); + break; + case AifEnConfigResume: /* Container resume event */ + device_printf(sc->aac_dev, "(ConfigResume)\n"); + break; + case AifEnFailoverChange: /* Failover space assignment changed */ + device_printf(sc->aac_dev, "(FailoverChange)\n"); + break; + case AifEnRAID5RebuildDone: /* RAID5 rebuild finished */ + device_printf(sc->aac_dev, "(RAID5RebuildDone)\n"); + break; + case AifEnEnclosureManagement: /* Enclosure management event */ + device_printf(sc->aac_dev, "(EnclosureManagement) EMPID %d unit %d event %d\n", + aif->data.EN.data.EEE.empID, + aif->data.EN.data.EEE.unitID, + aif->data.EN.data.EEE.eventType); + break; + case AifEnBatteryEvent: /* Significant NV battery event */ + device_printf(sc->aac_dev, "(BatteryEvent) %d (state was %d, is %d)\n", + aif->data.EN.data.EBE.transition_type, /* XXX interpret */ + aif->data.EN.data.EBE.current_state, + aif->data.EN.data.EBE.prior_state); + break; + case AifEnAddContainer: /* A new container was created. */ + device_printf(sc->aac_dev, "(AddContainer)\n"); + break; + case AifEnDeleteContainer: /* A container was deleted. */ + device_printf(sc->aac_dev, "(DeleteContainer)\n"); + break; + case AifEnBatteryNeedsRecond: /* The battery needs reconditioning */ + device_printf(sc->aac_dev, "(BatteryNeedsRecond)\n"); + break; + case AifEnClusterEvent: /* Some cluster event */ + device_printf(sc->aac_dev, "(ClusterEvent) event %d\n", + aif->data.EN.data.ECLE.eventType); + break; + case AifEnDiskSetEvent: /* A disk set event occured. */ + device_printf(sc->aac_dev, "(DiskSetEvent) event %d diskset %lld creator %lld\n", + aif->data.EN.data.EDS.eventType, + aif->data.EN.data.EDS.DsNum, + aif->data.EN.data.EDS.CreatorId); + break; + case AifDenMorphComplete: /* A morph operation completed */ + device_printf(sc->aac_dev, "(MorphComplete)\n"); + break; + case AifDenVolumeExtendComplete: /* A volume expand operation completed */ + device_printf(sc->aac_dev, "(VolumeExtendComplete)\n"); + break; + default: + device_printf(sc->aac_dev, "(%d)\n", aif->data.EN.type); + break; + } + break; + case AifCmdJobProgress: + { + char *status; + switch(aif->data.PR[0].status) { + case AifJobStsSuccess: + status = "success"; break; + case AifJobStsFinished: + status = "finished"; break; + case AifJobStsAborted: + status = "aborted"; break; + case AifJobStsFailed: + status = "failed"; break; + case AifJobStsSuspended: + status = "suspended"; break; + case AifJobStsRunning: + status = "running"; break; + default: + status = "unknown status"; break; + } + + device_printf(sc->aac_dev, "JobProgress (%d) - %s (%d, %d)\n", aif->seqNumber, status, + aif->data.PR[0].currentTick, aif->data.PR[0].finalTick); + switch(aif->data.PR[0].jd.type) { + case AifJobScsiZero: /* SCSI device clear operation */ + device_printf(sc->aac_dev, "(ScsiZero) handle %d\n", aif->data.PR[0].jd.client.scsi_dh); + break; + case AifJobScsiVerify: /* SCSI device Verify operation NO REPAIR */ + device_printf(sc->aac_dev, "(ScsiVerify) handle %d\n", aif->data.PR[0].jd.client.scsi_dh); + break; + case AifJobScsiExercise: /* SCSI device Exercise operation */ + device_printf(sc->aac_dev, "(ScsiExercise) handle %d\n", aif->data.PR[0].jd.client.scsi_dh); + break; + case AifJobScsiVerifyRepair: /* SCSI device Verify operation WITH repair */ + device_printf(sc->aac_dev, "(ScsiVerifyRepair) handle %d\n", aif->data.PR[0].jd.client.scsi_dh); + break; + case AifJobCtrZero: /* Container clear operation */ + device_printf(sc->aac_dev, "(ConatainerZero) container %d\n", + aif->data.PR[0].jd.client.container.src); + break; + case AifJobCtrCopy: /* Container copy operation */ + device_printf(sc->aac_dev, "(ConatainerCopy) container %d to %d\n", + aif->data.PR[0].jd.client.container.src, aif->data.PR[0].jd.client.container.dst); + break; + case AifJobCtrCreateMirror: /* Container Create Mirror operation */ + device_printf(sc->aac_dev, "(ConatainerCreateMirror) container %d\n", + aif->data.PR[0].jd.client.container.src); /* XXX two containers? */ + break; + case AifJobCtrMergeMirror: /* Container Merge Mirror operation */ + device_printf(sc->aac_dev, "(ConatainerMergeMirror) container %d\n", + aif->data.PR[0].jd.client.container.src); /* XXX two containers? */ + break; + case AifJobCtrScrubMirror: /* Container Scrub Mirror operation */ + device_printf(sc->aac_dev, "(ConatainerScrubMirror) container %d\n", + aif->data.PR[0].jd.client.container.src); + break; + case AifJobCtrRebuildRaid5: /* Container Rebuild Raid5 operation */ + device_printf(sc->aac_dev, "(ConatainerRebuildRaid5) container %d\n", + aif->data.PR[0].jd.client.container.src); + break; + case AifJobCtrScrubRaid5: /* Container Scrub Raid5 operation */ + device_printf(sc->aac_dev, "(ConatainerScrubRaid5) container %d\n", + aif->data.PR[0].jd.client.container.src); + break; + case AifJobCtrMorph: /* Container morph operation */ + device_printf(sc->aac_dev, "(ConatainerMorph) container %d\n", + aif->data.PR[0].jd.client.container.src); /* XXX two containers? */ + break; + case AifJobCtrPartCopy: /* Container Partition copy operation */ + device_printf(sc->aac_dev, "(ConatainerPartCopy) container %d to %d\n", + aif->data.PR[0].jd.client.container.src, aif->data.PR[0].jd.client.container.dst); + break; + case AifJobCtrRebuildMirror: /* Container Rebuild Mirror operation */ + device_printf(sc->aac_dev, "(ConatainerRebuildMirror) container %d\n", + aif->data.PR[0].jd.client.container.src); + break; + case AifJobCtrCrazyCache: /* crazy cache */ + device_printf(sc->aac_dev, "(ConatainerCrazyCache) container %d\n", + aif->data.PR[0].jd.client.container.src); /* XXX two containers? */ + break; + case AifJobFsCreate: /* File System Create operation */ + device_printf(sc->aac_dev, "(FsCreate)\n"); + break; + case AifJobFsVerify: /* File System Verify operation */ + device_printf(sc->aac_dev, "(FsVerivy)\n"); + break; + case AifJobFsExtend: /* File System Extend operation */ + device_printf(sc->aac_dev, "(FsExtend)\n"); + break; + case AifJobApiFormatNTFS: /* Format a drive to NTFS */ + device_printf(sc->aac_dev, "(FormatNTFS)\n"); + break; + case AifJobApiFormatFAT: /* Format a drive to FAT */ + device_printf(sc->aac_dev, "(FormatFAT)\n"); + break; + case AifJobApiUpdateSnapshot: /* update the read/write half of a snapshot */ + device_printf(sc->aac_dev, "(UpdateSnapshot)\n"); + break; + case AifJobApiFormatFAT32: /* Format a drive to FAT32 */ + device_printf(sc->aac_dev, "(FormatFAT32)\n"); + break; + case AifJobCtlContinuousCtrVerify: /* Adapter operation */ + device_printf(sc->aac_dev, "(ContinuousCtrVerify)\n"); + break; + default: + device_printf(sc->aac_dev, "(%d)\n", aif->data.PR[0].jd.type); + break; + } + break; + } + case AifCmdAPIReport: + device_printf(sc->aac_dev, "APIReport (%d)\n", aif->seqNumber); + break; + case AifCmdDriverNotify: + device_printf(sc->aac_dev, "DriverNotify (%d)\n", aif->seqNumber); + break; + default: + device_printf(sc->aac_dev, "AIF %d (%d)\n", aif->command, aif->seqNumber); + break; + } +} diff --git a/sys/dev/aac/aac_disk.c b/sys/dev/aac/aac_disk.c new file mode 100644 index 0000000..b2028ec --- /dev/null +++ b/sys/dev/aac/aac_disk.c @@ -0,0 +1,296 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> + +#include <dev/aac/aac_compat.h> +#include <sys/bus.h> +#include <sys/conf.h> +#include <sys/devicestat.h> +#include <sys/disk.h> + +#include <machine/bus.h> +#include <machine/clock.h> +#include <sys/rman.h> + +#include <dev/aac/aacreg.h> +#include <dev/aac/aacvar.h> + +/* + * Interface to parent. + */ +static int aac_disk_probe(device_t dev); +static int aac_disk_attach(device_t dev); +static int aac_disk_detach(device_t dev); + +/* + * Interface to the device switch. + */ +static d_open_t aac_disk_open; +static d_close_t aac_disk_close; +static d_strategy_t aac_disk_strategy; + +#define AAC_DISK_CDEV_MAJOR 151 + +static struct cdevsw aac_disk_cdevsw = { + /* open */ aac_disk_open, + /* close */ aac_disk_close, + /* read */ physread, + /* write */ physwrite, + /* ioctl */ noioctl, + /* poll */ nopoll, + /* mmap */ nommap, + /* strategy */ aac_disk_strategy, + /* name */ "aacd", + /* maj */ AAC_DISK_CDEV_MAJOR, + /* dump */ nodump, + /* psize */ nopsize, + /* flags */ D_DISK, + /* bmaj */ -1 +}; + +devclass_t aac_disk_devclass; +static struct cdevsw aac_disk_disk_cdevsw; +#ifdef FREEBSD_4 +static int disks_registered = 0; +#endif + +static device_method_t aac_disk_methods[] = { + DEVMETHOD(device_probe, aac_disk_probe), + DEVMETHOD(device_attach, aac_disk_attach), + DEVMETHOD(device_detach, aac_disk_detach), + { 0, 0 } +}; + +static driver_t aac_disk_driver = { + "aacd", + aac_disk_methods, + sizeof(struct aac_disk) +}; + +DRIVER_MODULE(aacd, aac, aac_disk_driver, aac_disk_devclass, 0, 0); + +/******************************************************************************** + * Handle open from generic layer. + * + * This is called by the diskslice code on first open in order to get the + * basic device geometry paramters. + */ +static int +aac_disk_open(dev_t dev, int flags, int fmt, struct proc *p) +{ + struct aac_disk *sc = (struct aac_disk *)dev->si_drv1; + struct disklabel *label; + + debug_called(4); + + if (sc == NULL) + return (ENXIO); + + /* check that the controller is up and running */ + if (sc->ad_controller->aac_state & AAC_STATE_SUSPEND) + return(ENXIO); + + /* build synthetic label */ + label = &sc->ad_disk.d_label; + bzero(label, sizeof(*label)); + label->d_type = DTYPE_ESDI; + label->d_secsize = AAC_BLOCK_SIZE; + label->d_nsectors = sc->ad_sectors; + label->d_ntracks = sc->ad_heads; + label->d_ncylinders = sc->ad_cylinders; + label->d_secpercyl = sc->ad_sectors * sc->ad_heads; + label->d_secperunit = sc->ad_size; + + sc->ad_flags |= AAC_DISK_OPEN; + return (0); +} + +/******************************************************************************** + * Handle last close of the disk device. + */ +static int +aac_disk_close(dev_t dev, int flags, int fmt, struct proc *p) +{ + struct aac_disk *sc = (struct aac_disk *)dev->si_drv1; + + debug_called(4); + + if (sc == NULL) + return (ENXIO); + + sc->ad_flags &= ~AAC_DISK_OPEN; + return (0); +} + +/******************************************************************************** + * Handle an I/O request. + */ +static void +aac_disk_strategy(struct bio *bp) +{ + struct aac_disk *sc = (struct aac_disk *)bp->bio_dev->si_drv1; + + debug_called(4); + + /* bogus disk? */ + if (sc == NULL) { + bp->bio_flags |= BIO_ERROR; + bp->bio_error = EINVAL; + biodone(bp); + return; + } + + /* do-nothing operation? */ + if (bp->bio_bcount == 0) { + bp->bio_resid = bp->bio_bcount; + biodone(bp); + return; + } + + /* perform accounting */ + devstat_start_transaction(&sc->ad_stats); + + /* pass the bio to the controller - it can work out who we are */ + aac_submit_bio(bp); + return; +} + +/******************************************************************************** + * Handle completion of an I/O request. + */ +void +aac_complete_bio(struct bio *bp) +{ + struct aac_disk *sc = (struct aac_disk *)bp->bio_dev->si_drv1; + + debug_called(4); + + devstat_end_transaction_bio(&sc->ad_stats, bp); + biodone(bp); +} + +/******************************************************************************** + * Stub only. + */ +static int +aac_disk_probe(device_t dev) +{ + + debug_called(4); + + return (0); +} + +/******************************************************************************** + * Attach a unit to the controller. + */ +static int +aac_disk_attach(device_t dev) +{ + struct aac_disk *sc = (struct aac_disk *)device_get_softc(dev); + int sgspace; + int maxsg; + + debug_called(4); + + /* initialise our softc */ + sc->ad_controller = (struct aac_softc *)device_get_softc(device_get_parent(dev)); + sc->ad_container = device_get_ivars(dev); + sc->ad_dev = dev; + + /* require that extended translation be enabled XXX document! */ + sc->ad_size = sc->ad_container->co_mntobj.Capacity; + if (sc->ad_size >= (2 * 1024 * 1024)) { /* 2GB */ + sc->ad_heads = 255; + sc->ad_sectors = 63; + } else if (sc->ad_size >= (2 * 1024 * 1024)) { /* 1GB */ + sc->ad_heads = 128; + sc->ad_sectors = 32; + } else { + sc->ad_heads = 64; + sc->ad_sectors = 32; + } + sc->ad_cylinders = (sc->ad_size / (sc->ad_heads * sc->ad_sectors)); + + device_printf(dev, "%uMB (%u sectors)\n", + sc->ad_size / ((1024 * 1024) / AAC_BLOCK_SIZE), sc->ad_size); + + devstat_add_entry(&sc->ad_stats, "aacd", device_get_unit(dev), AAC_BLOCK_SIZE, + DEVSTAT_NO_ORDERED_TAGS, + DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER, + DEVSTAT_PRIORITY_ARRAY); + + /* attach a generic disk device to ourselves */ + sc->ad_dev_t = disk_create(device_get_unit(dev), &sc->ad_disk, 0, &aac_disk_cdevsw, &aac_disk_disk_cdevsw); + sc->ad_dev_t->si_drv1 = sc; +#ifdef FREEBSD_4 + disks_registered++; +#endif + + /* + * We can calculate the maximum number of s/g entries based on the size of the + * FIB and the command structures packed within it. + */ + sgspace = (sizeof(struct aac_fib) - sizeof(struct aac_fib_header) - + imax(sizeof(struct aac_blockwrite), sizeof(struct aac_blockread))); + maxsg = (sgspace - sizeof(struct aac_sg_table)) / sizeof(struct aac_sg_entry); + + /* set the maximum I/O size to the theoretical worst maximum allowed by the S/G list size */ + sc->ad_dev_t->si_iosize_max = (maxsg - 1) * PAGE_SIZE; + + return (0); +} + +/******************************************************************************** + * Disconnect ourselves from the system. + */ +static int +aac_disk_detach(device_t dev) +{ + struct aac_disk *sc = (struct aac_disk *)device_get_softc(dev); + + debug_called(4); + + if (sc->ad_flags & AAC_DISK_OPEN) + return(EBUSY); + + devstat_remove_entry(&sc->ad_stats); +#ifdef FREEBSD_4 + if (--disks_registered == 0) + cdevsw_remove(&aac_disk_disk_cdevsw); +#else + disk_destroy(sc->ad_dev_t); +#endif + + return(0); +} + diff --git a/sys/dev/aac/aac_ioctl.h b/sys/dev/aac/aac_ioctl.h new file mode 100644 index 0000000..354c0aa --- /dev/null +++ b/sys/dev/aac/aac_ioctl.h @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 Scott Long + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifdef AAC_COMPAT_LINUX + +/* + * Ioctl commands likely to be submitted from a Linux management application. + * These bit encodings are actually descended from Windows NT. Ick. + */ + +#define CTL_CODE(devType, func, meth, acc) (((devType) << 16) | ((acc) << 14) | ((func) << 2) | (meth)) +#define METHOD_BUFFERED 0 +#define METHOD_IN_DIRECT 1 +#define METHOD_OUT_DIRECT 2 +#define METHOD_NEITHER 3 +#define FILE_ANY_ACCESS 0 +#define FILE_READ_ACCESS ( 0x0001 ) +#define FILE_WRITE_ACCESS ( 0x0002 ) +#define FILE_DEVICE_CONTROLLER 0x00000004 + +#define FSACTL_SENDFIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2050, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_AIF_THREAD CTL_CODE(FILE_DEVICE_CONTROLLER, 2127, METHOD_NEITHER, FILE_ANY_ACCESS) +#define FSACTL_OPEN_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2100, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_GET_NEXT_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2101, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_CLOSE_GET_ADAPTER_FIB CTL_CODE(FILE_DEVICE_CONTROLLER, 2102, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define FSACTL_MINIPORT_REV_CHECK CTL_CODE(FILE_DEVICE_CONTROLLER, 2107, METHOD_BUFFERED, FILE_ANY_ACCESS) + +/* + * Support for faking the "miniport" version. + */ +struct aac_rev_check { + RevComponent callingComponent; + struct FsaRevision callingRevision; +}; + +struct aac_rev_check_resp { + int possiblyCompatible; + struct FsaRevision adapterSWRevision; +}; + +/* + * Context passed in by a consumer looking to collect an AIF. + */ +#define AAC_AIF_SILLYMAGIC 0xdeadbeef +struct get_adapter_fib_ioctl { + u_int32_t AdapterFibContext; + int Wait; + caddr_t AifFib; +}; + +#endif diff --git a/sys/dev/aac/aac_pci.c b/sys/dev/aac/aac_pci.c new file mode 100644 index 0000000..f931bd1 --- /dev/null +++ b/sys/dev/aac/aac_pci.c @@ -0,0 +1,272 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * PCI bus interface and resource allocation. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> + +#include <dev/aac/aac_compat.h> +#include <sys/bus.h> +#include <sys/conf.h> +#include <sys/devicestat.h> +#include <sys/disk.h> + +#include <machine/bus_memio.h> +#include <machine/bus.h> +#include <machine/resource.h> +#include <sys/rman.h> + +#include <pci/pcireg.h> +#include <pci/pcivar.h> + +#include <dev/aac/aacreg.h> +#include <dev/aac/aacvar.h> + +static int aac_pci_probe(device_t dev); +static int aac_pci_attach(device_t dev); + +static device_method_t aac_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, aac_pci_probe), + DEVMETHOD(device_attach, aac_pci_attach), + DEVMETHOD(device_detach, aac_detach), + DEVMETHOD(device_shutdown, aac_shutdown), + DEVMETHOD(device_suspend, aac_suspend), + DEVMETHOD(device_resume, aac_resume), + + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + { 0, 0 } +}; + +static driver_t aac_pci_driver = { + "aac", + aac_methods, + sizeof(struct aac_softc) +}; + +DRIVER_MODULE(aac, pci, aac_pci_driver, aac_devclass, 0, 0); + +struct aac_ident +{ + u_int16_t vendor; + u_int16_t device; + u_int16_t subvendor; + u_int16_t subdevice; + int hwif; + char *desc; +} aac_identifiers[] = { + {0x1028, 0x0001, 0x1028, 0x0001, AAC_HWIF_I960RX, "Dell PERC 2/Si"}, + {0x1028, 0x0002, 0x1028, 0x0002, AAC_HWIF_I960RX, "Dell PERC 3/Di"}, + {0x1028, 0x0003, 0x1028, 0x0003, AAC_HWIF_I960RX, "Dell PERC 3/Si"}, + {0x9005, 0x0282, 0x9005, 0x0282, AAC_HWIF_I960RX, "Adaptec AAC-2622"}, + {0x1011, 0x0046, 0x9005, 0x0364, AAC_HWIF_STRONGARM, "Adaptec AAC-364"}, + {0x1011, 0x0046, 0x9005, 0x0365, AAC_HWIF_STRONGARM, "Adaptec AAC-3642"}, + {0x1011, 0x0046, 0x9005, 0x1364, AAC_HWIF_STRONGARM, "Dell PERC 2/QC"}, + {0x1011, 0x0046, 0x9005, 0x1365, AAC_HWIF_STRONGARM, "Dell PERC 3/QC"}, /* XXX guess */ + {0x1011, 0x0046, 0x103c, 0x10c2, AAC_HWIF_STRONGARM, "HP NetRaid-4M"}, + {0, 0, 0, 0, 0, 0} +}; + +/******************************************************************************** + * Determine whether this is one of our supported adapters. + */ +static int +aac_pci_probe(device_t dev) +{ + struct aac_ident *m; + + debug_called(1); + + for (m = aac_identifiers; m->vendor != 0; m++) { + if ((m->vendor == pci_get_vendor(dev)) && + (m->device == pci_get_device(dev)) && + ((m->subvendor == 0) || (m->subvendor == pci_get_subvendor(dev))) && + ((m->subdevice == 0) || ((m->subdevice == pci_get_subdevice(dev))))) { + + device_set_desc(dev, m->desc); + return(0); + } + } + return(ENXIO); +} + +/******************************************************************************** + * Allocate resources for our device, set up the bus interface. + */ +static int +aac_pci_attach(device_t dev) +{ + struct aac_softc *sc; + int i, error; + u_int32_t command; + + debug_called(1); + + /* + * Initialise softc. + */ + sc = device_get_softc(dev); + bzero(sc, sizeof(*sc)); + sc->aac_dev = dev; + + /* assume failure is 'not configured' */ + error = ENXIO; + + /* + * Verify that the adapter is correctly set up in PCI space. + */ + command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2); + command |= PCIM_CMD_BUSMASTEREN; + pci_write_config(dev, PCIR_COMMAND, command, 2); + command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2); + if (!(command & PCIM_CMD_BUSMASTEREN)) { + device_printf(sc->aac_dev, "can't enable bus-master feature\n"); + goto out; + } + if ((command & PCIM_CMD_MEMEN) == 0) { + device_printf(sc->aac_dev, "memory window not available\n"); + goto out; + } + + /* + * Allocate the PCI register window. + */ + sc->aac_regs_rid = 0x10; /* first base address register */ + if ((sc->aac_regs_resource = bus_alloc_resource(sc->aac_dev, SYS_RES_MEMORY, &sc->aac_regs_rid, + 0, ~0, 1, RF_ACTIVE)) == NULL) { + device_printf(sc->aac_dev, "couldn't allocate register window\n"); + goto out; + } + sc->aac_btag = rman_get_bustag(sc->aac_regs_resource); + sc->aac_bhandle = rman_get_bushandle(sc->aac_regs_resource); + + /* + * Allocate and connect our interrupt. + */ + sc->aac_irq_rid = 0; + if ((sc->aac_irq = bus_alloc_resource(sc->aac_dev, SYS_RES_IRQ, &sc->aac_irq_rid, + 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL) { + device_printf(sc->aac_dev, "can't allocate interrupt\n"); + goto out; + } + if (bus_setup_intr(sc->aac_dev, sc->aac_irq, INTR_TYPE_BIO, aac_intr, sc, &sc->aac_intr)) { + device_printf(sc->aac_dev, "can't set up interrupt\n"); + goto out; + } + + /* assume failure is 'out of memory' */ + error = ENOMEM; + + /* + * Allocate the parent bus DMA tag appropriate for our PCI interface. + * + * Note that some of these controllers are 64-bit capable. + */ + if (bus_dma_tag_create(NULL, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + MAXBSIZE, AAC_MAXSGENTRIES, /* maxsize, nsegments */ + BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ + BUS_DMA_ALLOCNOW, /* flags */ + &sc->aac_parent_dmat)) { + device_printf(sc->aac_dev, "can't allocate parent DMA tag\n"); + goto out; + } + + /* + * Create DMA tag for mapping buffers into controller-addressable space. + */ + if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + MAXBSIZE, AAC_MAXSGENTRIES, /* maxsize, nsegments */ + BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ + 0, /* flags */ + &sc->aac_buffer_dmat)) { + device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n"); + goto out; + } + + /* + * Create DMA tag for mapping FIBs into controller-addressable space.. + */ + if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */ + 1, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + AAC_CLUSTER_COUNT * sizeof(struct aac_fib), 1,/* maxsize, nsegments */ + BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ + 0, /* flags */ + &sc->aac_fib_dmat)) { + device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n"); + goto out; + } + + /* + * Detect the hardware interface version, set up the bus interface indirection. + */ + for (i = 0; aac_identifiers[i].vendor != 0; i++) { + if ((aac_identifiers[i].vendor == pci_get_vendor(dev)) && + (aac_identifiers[i].device == pci_get_device(dev))) { + sc->aac_hwif = aac_identifiers[i].hwif; + switch(sc->aac_hwif) { + case AAC_HWIF_I960RX: + debug(2, "set hardware up for i960Rx"); + sc->aac_if = aac_rx_interface; + break; + + case AAC_HWIF_STRONGARM: + debug(2, "set hardware up for StrongARM"); + sc->aac_if = aac_sa_interface; + break; + } + break; + } + } + + /* + * Do bus-independent initialisation. + */ + error = aac_attach(sc); + +out: + if (error) + aac_free(sc); + return(error); +} diff --git a/sys/dev/aac/aac_tables.h b/sys/dev/aac/aac_tables.h new file mode 100644 index 0000000..d994ae6 --- /dev/null +++ b/sys/dev/aac/aac_tables.h @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Status codes for block read/write commands, etc. + * + * XXX many of these would not normally be returned, as they are + * relevant only to FSA operations. + */ +static struct aac_code_lookup aac_command_status_table[] = { + {"OK", 0}, + {"operation not permitted", 1}, + {"not found", 2}, + {"I/O error", 5}, + {"device not configured", 6}, + {"too big", 7}, + {"permission denoed", 13}, + {"file exists", 17}, + {"cross-device link", 18}, + {"operation not supported by device", 19}, + {"not a directory", 20}, + {"is a directory", 21}, + {"invalid argument", 22}, + {"file too large", 27}, + {"no space on device", 28}, + {"readonly filesystem", 30}, + {"too many links", 31}, + {"operation would block", 35}, + {"file name too long", 63}, + {"directory not empty", 66}, + {"quota exceeded", 69}, + {"stale file handle", 70}, + {"too many levels of remote in path", 71}, + {"bad file handle", 10001}, + {"not sync", 10002}, + {"bad cookie", 10003}, + {"operation not supported", 10004}, + {"too small", 10005}, + {"server fault", 10006}, + {"bad type", 10007}, + {"jukebox", 10008}, + {"not mounted", 10009}, + {"in maintenace mode", 10010}, + {"stale ACL", 10011}, + {NULL, 0}, + {"unknown command status", 0} +}; + +#define AAC_COMMAND_STATUS(x) aac_describe_code(aac_command_status_table, x) + +static struct aac_code_lookup aac_cpu_variant[] = { + {"i960JX", CPUI960_JX}, + {"i960CX", CPUI960_CX}, + {"i960HX", CPUI960_HX}, + {"i960RX", CPUI960_RX}, + {"StrongARM SA110", CPUARM_SA110}, + {"PowerPC 603e", CPUPPC_603e}, + {"Unknown StrongARM", CPUARM_xxx}, + {"Unknown PowerPC", CPUPPC_xxx}, + {NULL, 0}, + {"Unknown processor", 0} +}; + +static struct aac_code_lookup aac_battery_platform[] = { + {"required battery present", PLATFORM_BAT_REQ_PRESENT}, + {"REQUIRED BATTERY NOT PRESENT", PLATFORM_BAT_REQ_NOTPRESENT}, + {"optional battery present", PLATFORM_BAT_OPT_PRESENT}, + {"optional battery not installed", PLATFORM_BAT_OPT_NOTPRESENT}, + {"no battery support", PLATFORM_BAT_NOT_SUPPORTED}, + {NULL, 0}, + {"unknown battery platform", 0} +}; + +static struct aac_code_lookup aac_container_types[] = { + {"Volume", CT_VOLUME}, + {"RAID 1 (Mirror)", CT_MIRROR}, + {"RAID 0 (Stripe)", CT_STRIPE}, + {"RAID 5", CT_RAID5}, + {"SSRW", CT_SSRW}, + {"SSRO", CT_SSRO}, + {"Morph", CT_MORPH}, + {"Passthrough", CT_PASSTHRU}, + {"RAID 4", CT_RAID4}, + {"RAID 10", CT_RAID10}, + {"RAID 00", CT_RAID00}, + {"Volume of Mirrors", CT_VOLUME_OF_MIRRORS}, + {"Pseudo RAID 3", CT_PSEUDO_RAID3}, + {NULL, 0}, + {"unknown", 0} +}; + diff --git a/sys/dev/aac/aacreg.h b/sys/dev/aac/aacreg.h new file mode 100644 index 0000000..df5ad9a --- /dev/null +++ b/sys/dev/aac/aacreg.h @@ -0,0 +1,1082 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 Scott Long + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Data structures defining the interface between the driver and the Adaptec + * 'FSA' adapters. Note that many field names and comments here are taken + * verbatim from the Adaptec driver source in order to make comparing the + * two slightly easier. + */ + +/******************************************************************************** + * Misc. magic numbers. + */ +#define AAC_MAX_CONTAINERS 64 +#define AAC_BLOCK_SIZE 512 + +/******************************************************************************** + * Communications interface. + * + * Where datastructure layouts are closely parallel to the Adaptec sample code, + * retain their naming conventions (for now) to aid in cross-referencing. + */ + +/* + * We establish 4 command queues and matching response queues. Queues must + * be 16-byte aligned, and are sized as follows: + */ +#define AAC_HOST_NORM_CMD_ENTRIES 8 /* command adapter->host, normal priority */ +#define AAC_HOST_HIGH_CMD_ENTRIES 4 /* command adapter->host, high priority */ +#define AAC_ADAP_NORM_CMD_ENTRIES 512 /* command host->adapter, normal priority */ +#define AAC_ADAP_HIGH_CMD_ENTRIES 4 /* command host->adapter, high priority */ +#define AAC_HOST_NORM_RESP_ENTRIES 512 /* response, adapter->host, normal priority */ +#define AAC_HOST_HIGH_RESP_ENTRIES 4 /* response, adapter->host, high priority */ +#define AAC_ADAP_NORM_RESP_ENTRIES 8 /* response, host->adapter, normal priority */ +#define AAC_ADAP_HIGH_RESP_ENTRIES 4 /* response, host->adapter, high priority */ + +#define AAC_TOTALQ_LENGTH (AAC_HOST_HIGH_CMD_ENTRIES + \ + AAC_HOST_NORM_CMD_ENTRIES + \ + AAC_ADAP_HIGH_CMD_ENTRIES + \ + AAC_ADAP_NORM_CMD_ENTRIES + \ + AAC_HOST_HIGH_RESP_ENTRIES + \ + AAC_HOST_NORM_RESP_ENTRIES + \ + AAC_ADAP_HIGH_RESP_ENTRIES + \ + AAC_ADAP_NORM_RESP_ENTRIES) +#define AAC_QUEUE_COUNT 8 +#define AAC_QUEUE_ALIGN 16 + +struct aac_queue_entry { + u_int32_t aq_fib_size; /* FIB size in bytes */ + u_int32_t aq_fib_addr; /* receiver-space address of the FIB */ +} __attribute__ ((packed)); + +#define AAC_PRODUCER_INDEX 0 +#define AAC_CONSUMER_INDEX 1 + +/* + * Table of queue indices and queues used to communicate with the + * controller. This structure must be aligned to AAC_QUEUE_ALIGN + */ +struct aac_queue_table { + /* queue consumer/producer indexes (layout mandated by adapter) */ + u_int32_t qt_qindex[AAC_QUEUE_COUNT][2]; + + /* queue entry structures (layout mandated by adapter) */ + struct aac_queue_entry qt_HostNormCmdQueue [AAC_HOST_NORM_CMD_ENTRIES]; + struct aac_queue_entry qt_HostHighCmdQueue [AAC_HOST_HIGH_CMD_ENTRIES]; + struct aac_queue_entry qt_AdapNormCmdQueue [AAC_ADAP_NORM_CMD_ENTRIES]; + struct aac_queue_entry qt_AdapHighCmdQueue [AAC_ADAP_HIGH_CMD_ENTRIES]; + struct aac_queue_entry qt_HostNormRespQueue[AAC_HOST_NORM_RESP_ENTRIES]; + struct aac_queue_entry qt_HostHighRespQueue[AAC_HOST_HIGH_RESP_ENTRIES]; + struct aac_queue_entry qt_AdapNormRespQueue[AAC_ADAP_NORM_RESP_ENTRIES]; + struct aac_queue_entry qt_AdapHighRespQueue[AAC_ADAP_HIGH_RESP_ENTRIES]; +} __attribute__ ((packed)); + +/* + * Queue names + * + * Note that we base these at 0 in order to use them as array indices. Adaptec + * used base 1 for some unknown reason, and sorted them in a different order. + */ +#define AAC_HOST_NORM_CMD_QUEUE 0 +#define AAC_HOST_HIGH_CMD_QUEUE 1 +#define AAC_ADAP_NORM_CMD_QUEUE 2 +#define AAC_ADAP_HIGH_CMD_QUEUE 3 +#define AAC_HOST_NORM_RESP_QUEUE 4 +#define AAC_HOST_HIGH_RESP_QUEUE 5 +#define AAC_ADAP_NORM_RESP_QUEUE 6 +#define AAC_ADAP_HIGH_RESP_QUEUE 7 + +/* + * List structure used to chain FIBs (used by the adapter - we hang FIBs off + * our private command structure and don't touch these) + */ +struct aac_fib_list_entry { + struct fib_list_entry *Flink; + struct fib_list_entry *Blink; +} __attribute__ ((packed)); + +/* + * FIB (FSA Interface Block?); this is the datastructure passed between the host + * and adapter. + */ +struct aac_fib_header { + u_int32_t XferState; + u_int16_t Command; + u_int8_t StructType; + u_int8_t Flags; + u_int16_t Size; + u_int16_t SenderSize; + u_int32_t SenderFibAddress; + u_int32_t ReceiverFibAddress; + u_int32_t SenderData; + union { + struct { + u_int32_t ReceiverTimeStart; + u_int32_t ReceiverTimeDone; + } _s; + struct aac_fib_list_entry FibLinks; + } _u; +} __attribute__ ((packed)); + +#define AAC_FIB_DATASIZE (512 - sizeof(struct aac_fib_header)) + +struct aac_fib { + struct aac_fib_header Header; + u_int8_t data[AAC_FIB_DATASIZE]; +} __attribute__ ((packed)); + +/* + * FIB commands + */ +typedef enum { + TestCommandResponse = 1, + TestAdapterCommand = 2, + + /* lowlevel and comm commands */ + LastTestCommand = 100, + ReinitHostNormCommandQueue = 101, + ReinitHostHighCommandQueue = 102, + ReinitHostHighRespQueue = 103, + ReinitHostNormRespQueue = 104, + ReinitAdapNormCommandQueue = 105, + ReinitAdapHighCommandQueue = 107, + ReinitAdapHighRespQueue = 108, + ReinitAdapNormRespQueue = 109, + InterfaceShutdown = 110, + DmaCommandFib = 120, + StartProfile = 121, + TermProfile = 122, + SpeedTest = 123, + TakeABreakPt = 124, + RequestPerfData = 125, + SetInterruptDefTimer= 126, + SetInterruptDefCount= 127, + GetInterruptDefStatus= 128, + LastCommCommand = 129, + + /* filesystem commands */ + NuFileSystem = 300, + UFS = 301, + HostFileSystem = 302, + LastFileSystemCommand = 303, + + /* Container Commands */ + ContainerCommand = 500, + ContainerCommand64 = 501, + + /* Cluster Commands */ + ClusterCommand = 550, + + /* Scsi Port commands (scsi passthrough) */ + ScsiPortCommand = 600, + + /* misc house keeping and generic adapter initiated commands */ + AifRequest = 700, + CheckRevision = 701, + FsaHostShutdown = 702, + RequestAdapterInfo = 703, + IsAdapterPaused = 704, + SendHostTime = 705, + LastMiscCommand = 706 +} AAC_FibCommands; + +/* + * FIB types + */ +#define AAC_FIBTYPE_TFIB 1 +#define AAC_FIBTYPE_TQE 2 +#define AAC_FIBTYPE_TCTPERF 3 + +/* + * FIB transfer state + */ +#define AAC_FIBSTATE_HOSTOWNED (1<<0) /* owned by the host */ +#define AAC_FIBSTATE_ADAPTEROWNED (1<<1) /* owned by the adapter */ +#define AAC_FIBSTATE_INITIALISED (1<<2) /* initialised */ +#define AAC_FIBSTATE_EMPTY (1<<3) /* empty */ +#define AAC_FIBSTATE_FROMPOOL (1<<4) /* allocated from pool */ +#define AAC_FIBSTATE_FROMHOST (1<<5) /* sent from the host */ +#define AAC_FIBSTATE_FROMADAP (1<<6) /* sent from the adapter */ +#define AAC_FIBSTATE_REXPECTED (1<<7) /* response is expected */ +#define AAC_FIBSTATE_RNOTEXPECTED (1<<8) /* response is not expected */ +#define AAC_FIBSTATE_DONEADAP (1<<9) /* processed by the adapter */ +#define AAC_FIBSTATE_DONEHOST (1<<10) /* processed by the host */ +#define AAC_FIBSTATE_HIGH (1<<11) /* high priority */ +#define AAC_FIBSTATE_NORM (1<<12) /* normal priority */ +#define AAC_FIBSTATE_ASYNC (1<<13) +#define AAC_FIBSTATE_ASYNCIO (1<<13) /* to be removed */ +#define AAC_FIBSTATE_PAGEFILEIO (1<<14) /* to be removed */ +#define AAC_FIBSTATE_SHUTDOWN (1<<15) +#define AAC_FIBSTATE_LAZYWRITE (1<<16) /* to be removed */ +#define AAC_FIBSTATE_ADAPMICROFIB (1<<17) +#define AAC_FIBSTATE_BIOSFIB (1<<18) +#define AAC_FIBSTATE_FAST_RESPONSE (1<<19) /* fast response capable */ +#define AAC_FIBSTATE_APIFIB (1<<20) + +/* + * FIB error values + */ +#define AAC_ERROR_NORMAL 0x00 +#define AAC_ERROR_PENDING 0x01 +#define AAC_ERROR_FATAL 0x02 +#define AAC_ERROR_INVALID_QUEUE 0x03 +#define AAC_ERROR_NOENTRIES 0x04 +#define AAC_ERROR_SENDFAILED 0x05 +#define AAC_ERROR_INVALID_QUEUE_PRIORITY 0x06 +#define AAC_ERROR_FIB_ALLOCATION_FAILED 0x07 +#define AAC_ERROR_FIB_DEALLOCATION_FAILED 0x08 + +/* + * Adapter Init Structure: this is passed to the adapter with the + * AAC_MONKER_INITSTRUCT command to point it at our control structures. + */ +struct aac_adapter_init { + u_int32_t InitStructRevision; +#define AAC_INIT_STRUCT_REVISION 3 + u_int32_t MiniPortRevision; + u_int32_t FilesystemRevision; + u_int32_t CommHeaderAddress; + u_int32_t FastIoCommAreaAddress; + u_int32_t AdapterFibsPhysicalAddress; + void *AdapterFibsVirtualAddress; + u_int32_t AdapterFibsSize; + u_int32_t AdapterFibAlign; + u_int32_t PrintfBufferAddress; + u_int32_t PrintfBufferSize; + u_int32_t HostPhysMemPages; + u_int32_t HostElapsedSeconds; +} __attribute__ ((packed)); + +/******************************************************************************** + * Shared data types + */ +/* + * Container types + */ +typedef enum { + CT_NONE = 0, + CT_VOLUME, + CT_MIRROR, + CT_STRIPE, + CT_RAID5, + CT_SSRW, + CT_SSRO, + CT_MORPH, + CT_PASSTHRU, + CT_RAID4, + CT_RAID10, /* stripe of mirror */ + CT_RAID00, /* stripe of stripe */ + CT_VOLUME_OF_MIRRORS, /* volume of mirror */ + CT_PSEUDO_RAID3, /* really raid4 */ +} AAC_FSAVolType; + +/* + * Host-addressable object types + */ +typedef enum { + FT_REG = 1, /* regular file */ + FT_DIR, /* directory */ + FT_BLK, /* "block" device - reserved */ + FT_CHR, /* "character special" device - reserved */ + FT_LNK, /* symbolic link */ + FT_SOCK, /* socket */ + FT_FIFO, /* fifo */ + FT_FILESYS, /* ADAPTEC's "FSA"(tm) filesystem */ + FT_DRIVE, /* physical disk - addressable in scsi by bus/target/lun */ + FT_SLICE, /* virtual disk - raw volume - slice */ + FT_PARTITION, /* FSA partition - carved out of a slice - building block for containers */ + FT_VOLUME, /* Container - Volume Set */ + FT_STRIPE, /* Container - Stripe Set */ + FT_MIRROR, /* Container - Mirror Set */ + FT_RAID5, /* Container - Raid 5 Set */ + FT_DATABASE /* Storage object with "foreign" content manager */ +} AAC_FType; + +/* + * Host-side scatter/gather list for 32-bit commands. + */ +struct aac_sg_entry { + u_int32_t SgAddress; + u_int32_t SgByteCount; +} __attribute__ ((packed)); + +struct aac_sg_table { + u_int32_t SgCount; + struct aac_sg_entry SgEntry[0]; +} __attribute__ ((packed)); + +/* + * Host-side scatter/gather list for 64-bit commands. + */ +struct aac_sg_table64 { + u_int8_t SgCount; + u_int8_t SgSectorsPerPage; + u_int16_t SgByteOffset; + u_int64_t SgEntry[0]; +} __attribute__ ((packed)); + +/* + * Container creation data + */ +struct aac_container_creation { + u_int8_t ViaBuildNumber; + u_int8_t MicroSecond; + u_int8_t Via; /* 1 = FSU, 2 = API, etc. */ + u_int8_t YearsSince1900; + u_int32_t Month:4; /* 1-12 */ + u_int32_t Day:6; /* 1-32 */ + u_int32_t Hour:6; /* 0-23 */ + u_int32_t Minute:6; /* 0-59 */ + u_int32_t Second:6; /* 0-59 */ + u_int64_t ViaAdapterSerialNumber; +} __attribute__ ((packed)); + +/******************************************************************************** + * Revision number handling + */ + +typedef enum { + RevApplication = 1, + RevDkiCli, + RevNetService, + RevApi, + RevFileSysDriver, + RevMiniportDriver, + RevAdapterSW, + RevMonitor, + RevRemoteApi +} RevComponent; + +struct FsaRevision { + union { + struct { + u_int8_t dash; + u_int8_t type; + u_int8_t minor; + u_int8_t major; + } comp; + u_int32_t ul; + } external; + u_int32_t buildNumber; +} __attribute__ ((packed)); + +/******************************************************************************** + * Adapter Information + */ + +typedef enum { + CPU_NTSIM = 1, + CPU_I960, + CPU_ARM, + CPU_SPARC, + CPU_POWERPC, + CPU_ALPHA, + CPU_P7, + CPU_I960_RX, + CPU__last +} AAC_CpuType; + +typedef enum { + CPUI960_JX = 1, + CPUI960_CX, + CPUI960_HX, + CPUI960_RX, + CPUARM_SA110, + CPUARM_xxx, + CPUPPC_603e, + CPUPPC_xxx, + CPUSUBTYPE__last +} AAC_CpuSubType; + +typedef enum { + PLAT_NTSIM = 1, + PLAT_V3ADU, + PLAT_CYCLONE, + PLAT_CYCLONE_HD, + PLAT_BATBOARD, + PLAT_BATBOARD_HD, + PLAT_YOLO, + PLAT_COBRA, + PLAT_ANAHEIM, + PLAT_JALAPENO, + PLAT_QUEENS, + PLAT_JALAPENO_DELL, + PLAT_POBLANO, + PLAT_POBLANO_OPAL, + PLAT_POBLANO_SL0, + PLAT_POBLANO_SL1, + PLAT_POBLANO_SL2, + PLAT_POBLANO_XXX, + PLAT_JALAPENO_P2, + PLAT_HABANERO, + PLAT__last +} AAC_Platform; + +typedef enum { + OEM_FLAVOR_ADAPTEC = 1, + OEM_FLAVOR_DELL, + OEM_FLAVOR_HP, + OEM_FLAVOR_IBM, + OEM_FLAVOR_CPQ, + OEM_FLAVOR_BRAND_X, + OEM_FLAVOR_BRAND_Y, + OEM_FLAVOR_BRAND_Z, + OEM_FLAVOR__last +} AAC_OemFlavor; + +/* + * XXX the aac-2622 with no battery present reports PLATFORM_BAT_OPT_PRESENT + */ +typedef enum +{ + PLATFORM_BAT_REQ_PRESENT = 1, /* BATTERY REQUIRED AND PRESENT */ + PLATFORM_BAT_REQ_NOTPRESENT, /* BATTERY REQUIRED AND NOT PRESENT */ + PLATFORM_BAT_OPT_PRESENT, /* BATTERY OPTIONAL AND PRESENT */ + PLATFORM_BAT_OPT_NOTPRESENT, /* BATTERY OPTIONAL AND NOT PRESENT */ + PLATFORM_BAT_NOT_SUPPORTED /* BATTERY NOT SUPPORTED */ +} AAC_BatteryPlatform; + +/* + * options supported by this board + * there has to be a one to one mapping of these defines and the ones in + * fsaapi.h, search for FSA_SUPPORT_SNAPSHOT + */ +#define AAC_SUPPORTED_SNAPSHOT 0x01 +#define AAC_SUPPORTED_CLUSTERS 0x02 +#define AAC_SUPPORTED_WRITE_CACHE 0x04 +#define AAC_SUPPORTED_64BIT_DATA 0x08 +#define AAC_SUPPORTED_HOST_TIME_FIB 0x10 +#define AAC_SUPPORTED_RAID50 0x20 + +/* + * Structure used to respond to a RequestAdapterInfo fib. + */ +struct aac_adapter_info { + AAC_Platform PlatformBase; /* adapter type */ + AAC_CpuType CpuArchitecture; /* adapter CPU type */ + AAC_CpuSubType CpuVariant; /* adapter CPU subtype */ + u_int32_t ClockSpeed; /* adapter CPU clockspeed */ + u_int32_t ExecutionMem; /* adapter Execution Memory size */ + u_int32_t BufferMem; /* adapter Data Memory */ + u_int32_t TotalMem; /* adapter Total Memory */ + struct FsaRevision KernelRevision; /* adapter Kernel Software Revision */ + struct FsaRevision MonitorRevision; /* adapter Monitor/Diagnostic Software Revision */ + struct FsaRevision HardwareRevision;/* TDB */ + struct FsaRevision BIOSRevision; /* adapter BIOS Revision */ + u_int32_t ClusteringEnabled; + u_int32_t ClusterChannelMask; + u_int64_t SerialNumber; + AAC_BatteryPlatform batteryPlatform; + u_int32_t SupportedOptions; /* supported features of this controller */ + AAC_OemFlavor OemVariant; +} __attribute__ ((packed)); + +/******************************************************************************** + * Monitor/Kernel interface. + */ + +/* + * Synchronous commands to the monitor/kernel. + */ +#define AAC_MONKER_INITSTRUCT 0x05 +#define AAC_MONKER_SYNCFIB 0x0c + +/* + * Adapter Status Register + * + * Phase Staus mailbox is 32bits: + * <31:16> = Phase Status + * <15:0> = Phase + * + * The adapter reports its present state through the phase. Only + * a single phase should be ever be set. Each phase can have multiple + * phase status bits to provide more detailed information about the + * state of the adapter. + */ +#define AAC_SELF_TEST_FAILED 0x00000004 +#define AAC_UP_AND_RUNNING 0x00000080 +#define AAC_KERNEL_PANIC 0x00000100 + +/******************************************************************************** + * Data types relating to control and monitoring of the NVRAM/WriteCache + * subsystem. + */ + +#define AAC_NFILESYS 24 /* maximum number of filesystems */ + +/* + * NVRAM/Write Cache subsystem states + */ +typedef enum { + NVSTATUS_DISABLED = 0, /* present, clean, not being used */ + NVSTATUS_ENABLED, /* present, possibly dirty, ready for use */ + NVSTATUS_ERROR, /* present, dirty, contains dirty data */ + /* for bad/missing device */ + NVSTATUS_BATTERY, /* present, bad or low battery, may contain dirty data */ + /* for bad/missing device */ + NVSTATUS_UNKNOWN +} AAC_NVSTATUS; + +/* + * NVRAM/Write Cache subsystem battery component states + * + */ +typedef enum { + NVBATTSTATUS_NONE = 0, /* battery has no power or is not present */ + NVBATTSTATUS_LOW, /* battery is low on power */ + NVBATTSTATUS_OK, /* battery is okay - normal operation possible only in this state */ + NVBATTSTATUS_RECONDITIONING /* no battery present - reconditioning in process */ +} AAC_NVBATTSTATUS; + +/* + * Battery transition type + */ +typedef enum { + NVBATT_TRANSITION_NONE = 0, /* battery now has no power or is not present */ + NVBATT_TRANSITION_LOW, /* battery is now low on power */ + NVBATT_TRANSITION_OK /* battery is now okay - normal operation possible only in this state */ +} AAC_NVBATT_TRANSITION; + +/* + * NVRAM Info structure returned for NVRAM_GetInfo call + */ +struct aac_nvramdevinfo { + u_int32_t NV_Enabled; /* write caching enabled */ + u_int32_t NV_Error; /* device in error state */ + u_int32_t NV_NDirty; /* count of dirty NVRAM buffers */ + u_int32_t NV_NActive; /* count of NVRAM buffers being written */ +} __attribute__ ((packed)); + +struct aac_nvraminfo { + AAC_NVSTATUS NV_Status; /* nvram subsystem status */ + AAC_NVBATTSTATUS NV_BattStatus; /* battery status */ + u_int32_t NV_Size; /* size of WriteCache NVRAM in bytes */ + u_int32_t NV_BufSize; /* size of NVRAM buffers in bytes */ + u_int32_t NV_NBufs; /* number of NVRAM buffers */ + u_int32_t NV_NDirty; /* count of dirty NVRAM buffers */ + u_int32_t NV_NClean; /* count of clean NVRAM buffers */ + u_int32_t NV_NActive; /* count of NVRAM buffers being written */ + u_int32_t NV_NBrokered; /* count of brokered NVRAM buffers */ + struct aac_nvramdevinfo NV_DevInfo[AAC_NFILESYS]; /* per device info */ + u_int32_t NV_BattNeedsReconditioning; /* boolean */ + u_int32_t NV_TotalSize; /* size of all non-volatile memories in bytes */ +} __attribute__ ((packed)); + +/******************************************************************************** + * Data types relating to adapter-initiated FIBs + * + * Based on types and structures in <aifstruc.h> + */ + +/* + * Progress Reports + */ +typedef enum { + AifJobStsSuccess = 1, + AifJobStsFinished, + AifJobStsAborted, + AifJobStsFailed, + AifJobStsLastReportMarker = 100, /* All before mean last report */ + AifJobStsSuspended, + AifJobStsRunning +} AAC_AifJobStatus; + +typedef enum { + AifJobScsiMin = 1, /* Minimum value for Scsi operation */ + AifJobScsiZero, /* SCSI device clear operation */ + AifJobScsiVerify, /* SCSI device Verify operation NO REPAIR */ + AifJobScsiExercise, /* SCSI device Exercise operation */ + AifJobScsiVerifyRepair, /* SCSI device Verify operation WITH repair */ + AifJobScsiMax = 99, /* Max Scsi value */ + AifJobCtrMin, /* Min Ctr op value */ + AifJobCtrZero, /* Container clear operation */ + AifJobCtrCopy, /* Container copy operation */ + AifJobCtrCreateMirror, /* Container Create Mirror operation */ + AifJobCtrMergeMirror, /* Container Merge Mirror operation */ + AifJobCtrScrubMirror, /* Container Scrub Mirror operation */ + AifJobCtrRebuildRaid5, /* Container Rebuild Raid5 operation */ + AifJobCtrScrubRaid5, /* Container Scrub Raid5 operation */ + AifJobCtrMorph, /* Container morph operation */ + AifJobCtrPartCopy, /* Container Partition copy operation */ + AifJobCtrRebuildMirror, /* Container Rebuild Mirror operation */ + AifJobCtrCrazyCache, /* crazy cache */ + AifJobCtrMax = 199, /* Max Ctr type operation */ + AifJobFsMin, /* Min Fs type operation */ + AifJobFsCreate, /* File System Create operation */ + AifJobFsVerify, /* File System Verify operation */ + AifJobFsExtend, /* File System Extend operation */ + AifJobFsMax = 299, /* Max Fs type operation */ + AifJobApiFormatNTFS, /* Format a drive to NTFS */ + AifJobApiFormatFAT, /* Format a drive to FAT */ + AifJobApiUpdateSnapshot, /* update the read/write half of a snapshot */ + AifJobApiFormatFAT32, /* Format a drive to FAT32 */ + AifJobApiMax = 399, /* Max API type operation */ + AifJobCtlContinuousCtrVerify, /* Adapter operation */ + AifJobCtlMax = 499 /* Max Adapter type operation */ +} AAC_AifJobType; + +struct aac_AifContainers { + u_int32_t src; /* from/master */ + u_int32_t dst; /* to/slave */ +} __attribute__ ((packed)); + +union aac_AifJobClient { + struct aac_AifContainers container; /* For Container and file system progress ops; */ + int32_t scsi_dh; /* For SCSI progress ops */ +}; + +struct aac_AifJobDesc { + u_int32_t jobID; /* DO NOT FILL IN! Will be filled in by AIF */ + AAC_AifJobType type; /* Operation that is being performed */ + union aac_AifJobClient client; /* Details */ +} __attribute__ ((packed)); + +struct aac_AifJobProgressReport { + struct aac_AifJobDesc jd; + AAC_AifJobStatus status; + u_int32_t finalTick; + u_int32_t currentTick; + u_int32_t jobSpecificData1; + u_int32_t jobSpecificData2; +} __attribute__ ((packed)); + +/* + * Event Notification + */ +typedef enum { + /* General application notifies start here */ + AifEnGeneric = 1, /* Generic notification */ + AifEnTaskComplete, /* Task has completed */ + AifEnConfigChange, /* Adapter configuration change occurred */ + AifEnContainerChange, /* Adapter specific container configuration change */ + AifEnDeviceFailure, /* SCSI device failed */ + AifEnMirrorFailover, /* Mirror failover started */ + AifEnContainerEvent, /* Significant container event */ + AifEnFileSystemChange, /* File system changed */ + AifEnConfigPause, /* Container pause event */ + AifEnConfigResume, /* Container resume event */ + AifEnFailoverChange, /* Failover space assignment changed */ + AifEnRAID5RebuildDone, /* RAID5 rebuild finished */ + AifEnEnclosureManagement, /* Enclosure management event */ + AifEnBatteryEvent, /* Significant NV battery event */ + AifEnAddContainer, /* A new container was created. */ + AifEnDeleteContainer, /* A container was deleted. */ + AifEnSMARTEvent, /* SMART Event */ + AifEnBatteryNeedsRecond, /* The battery needs reconditioning */ + AifEnClusterEvent, /* Some cluster event */ + AifEnDiskSetEvent, /* A disk set event occured. */ + AifDriverNotifyStart=199, /* Notifies for host driver go here */ + /* Host driver notifications start here */ + AifDenMorphComplete, /* A morph operation completed */ + AifDenVolumeExtendComplete /* A volume expand operation completed */ +} AAC_AifEventNotifyType; + +struct aac_AifEnsGeneric { + char text[132]; /* Generic text */ +} __attribute__ ((packed)); + +struct aac_AifEnsDeviceFailure { + u_int32_t deviceHandle; /* SCSI device handle */ +} __attribute__ ((packed)); + +struct aac_AifEnsMirrorFailover { + u_int32_t container; /* Container with failed element */ + u_int32_t failedSlice; /* Old slice which failed */ + u_int32_t creatingSlice; /* New slice used for auto-create */ +} __attribute__ ((packed)); + +struct aac_AifEnsContainerChange { + u_int32_t container[2]; /* container that changed, -1 if no container */ +} __attribute__ ((packed)); + +struct aac_AifEnsContainerEvent { + u_int32_t container; /* container number */ + u_int32_t eventType; /* event type */ +} __attribute__ ((packed)); + +struct aac_AifEnsEnclosureEvent { + u_int32_t empID; /* enclosure management processor number */ + u_int32_t unitID; /* unitId, fan id, power supply id, slot id, tempsensor id. */ + u_int32_t eventType; /* event type */ +} __attribute__ ((packed)); + +struct aac_AifEnsBatteryEvent { + AAC_NVBATT_TRANSITION transition_type; /* e.g. from low to ok */ + AAC_NVBATTSTATUS current_state; /* current battery state */ + AAC_NVBATTSTATUS prior_state; /* previous battery state */ +} __attribute__ ((packed)); + +struct aac_AifEnsDiskSetEvent { + u_int32_t eventType; + u_int64_t DsNum; + u_int64_t CreatorId; +} __attribute__ ((packed)); + +typedef enum { + CLUSTER_NULL_EVENT = 0, + CLUSTER_PARTNER_NAME_EVENT, /* change in partner hostname or adaptername from NULL to non-NULL */ + /* (partner's agent may be up) */ + CLUSTER_PARTNER_NULL_NAME_EVENT /* change in partner hostname or adaptername from non-null to NULL */ + /* (partner has rebooted) */ +} AAC_ClusterAifEvent; + +struct aac_AifEnsClusterEvent { + AAC_ClusterAifEvent eventType; +} __attribute__ ((packed)); + +struct aac_AifEventNotify { + AAC_AifEventNotifyType type; + union { + struct aac_AifEnsGeneric EG; + struct aac_AifEnsDeviceFailure EDF; + struct aac_AifEnsMirrorFailover EMF; + struct aac_AifEnsContainerChange ECC; + struct aac_AifEnsContainerEvent ECE; + struct aac_AifEnsEnclosureEvent EEE; + struct aac_AifEnsBatteryEvent EBE; + struct aac_AifEnsDiskSetEvent EDS; +/* struct aac_AifEnsSMARTEvent ES;*/ + struct aac_AifEnsClusterEvent ECLE; + } data; +} __attribute__ ((packed)); + +/* + * Adapter Initiated FIB command structures. Start with the adapter + * initiated FIBs that really come from the adapter, and get responded + * to by the host. + */ +#define AAC_AIF_REPORT_MAX_SIZE 64 + +typedef enum { + AifCmdEventNotify = 1, /* Notify of event */ + AifCmdJobProgress, /* Progress report */ + AifCmdAPIReport, /* Report from other user of API */ + AifCmdDriverNotify, /* Notify host driver of event */ + AifReqJobList = 100, /* Gets back complete job list */ + AifReqJobsForCtr, /* Gets back jobs for specific container */ + AifReqJobsForScsi, /* Gets back jobs for specific SCSI device */ + AifReqJobReport, /* Gets back a specific job report or list of them */ + AifReqTerminateJob, /* Terminates job */ + AifReqSuspendJob, /* Suspends a job */ + AifReqResumeJob, /* Resumes a job */ + AifReqSendAPIReport, /* API generic report requests */ + AifReqAPIJobStart, /* Start a job from the API */ + AifReqAPIJobUpdate, /* Update a job report from the API */ + AifReqAPIJobFinish /* Finish a job from the API */ +} AAC_AifCommand; + +struct aac_aif_command { + AAC_AifCommand command; /* Tell host what type of notify this is */ + u_int32_t seqNumber; /* To allow ordering of reports (if necessary) */ + union { + struct aac_AifEventNotify EN; /* Event notify structure */ + struct aac_AifJobProgressReport PR[1]; /* Progress report */ + u_int8_t AR[AAC_AIF_REPORT_MAX_SIZE]; + } data; +} __attribute__ ((packed)); + +/******************************************************************************** + * Filesystem commands/data + * + * The adapter has a very complex filesystem interface, most of which we ignore. + * (And which seems not to be implemented, anyway.) + */ + +/* + * FSA commands + * (not used?) + */ +typedef enum { + Null = 0, + GetAttributes, + SetAttributes, + Lookup, + ReadLink, + Read, + Write, + Create, + MakeDirectory, + SymbolicLink, + MakeNode, + Removex, + RemoveDirectory, + Rename, + Link, + ReadDirectory, + ReadDirectoryPlus, + FileSystemStatus, + FileSystemInfo, + PathConfigure, + Commit, + Mount, + UnMount, + Newfs, + FsCheck, + FsSync, + SimReadWrite, + SetFileSystemStatus, + BlockRead, + BlockWrite, + NvramIoctl, + FsSyncWait, + ClearArchiveBit, + SetAcl, + GetAcl, + AssignAcl, + FaultInsertion, + CrazyCache +} AAC_FSACommand; + +/* + * Command status values + */ +typedef enum { + ST_OK = 0, + ST_PERM = 1, + ST_NOENT = 2, + ST_IO = 5, + ST_NXIO = 6, + ST_E2BIG = 7, + ST_ACCES = 13, + ST_EXIST = 17, + ST_XDEV = 18, + ST_NODEV = 19, + ST_NOTDIR = 20, + ST_ISDIR = 21, + ST_INVAL = 22, + ST_FBIG = 27, + ST_NOSPC = 28, + ST_ROFS = 30, + ST_MLINK = 31, + ST_WOULDBLOCK = 35, + ST_NAMETOOLONG = 63, + ST_NOTEMPTY = 66, + ST_DQUOT = 69, + ST_STALE = 70, + ST_REMOTE = 71, + ST_BADHANDLE = 10001, + ST_NOT_SYNC = 10002, + ST_BAD_COOKIE = 10003, + ST_NOTSUPP = 10004, + ST_TOOSMALL = 10005, + ST_SERVERFAULT = 10006, + ST_BADTYPE = 10007, + ST_JUKEBOX = 10008, + ST_NOTMOUNTED = 10009, + ST_MAINTMODE = 10010, + ST_STALEACL = 10011 +} AAC_FSAStatus; + +/* + * Volume manager commands + */ +typedef enum _VM_COMMANDS { + VM_Null = 0, + VM_NameServe, + VM_ContainerConfig, + VM_Ioctl, + VM_FilesystemIoctl, + VM_CloseAll, + VM_CtBlockRead, + VM_CtBlockWrite, + VM_SliceBlockRead, /* raw access to configured "storage objects" */ + VM_SliceBlockWrite, + VM_DriveBlockRead, /* raw access to physical devices */ + VM_DriveBlockWrite, + VM_EnclosureMgt, /* enclosure management */ + VM_Unused, /* used to be diskset management */ + VM_CtBlockVerify, + VM_CtPerf, /* performance test */ + VM_CtBlockRead64, + VM_CtBlockWrite64, + VM_CtBlockVerify64, +} AAC_VMCommand; + +/* + * "mountable object" + */ +struct aac_mntobj { + u_int32_t ObjectId; + char FileSystemName[16]; + struct aac_container_creation CreateInfo; + u_int32_t Capacity; + AAC_FSAVolType VolType; + AAC_FType ObjType; + u_int32_t ContentState; +#define FSCS_READONLY 0x0002 /* XXX need more information than this */ + union { + u_int32_t pad[8]; + } ObjExtension; + u_int32_t AlterEgoId; +} __attribute__ ((packed)); + +struct aac_mntinfo { + AAC_VMCommand Command; + AAC_FType MntType; + u_int32_t MntCount; +} __attribute__ ((packed)); + +struct aac_mntinforesponse { + AAC_FSAStatus Status; + AAC_FType MntType; + u_int32_t MntRespCount; + struct aac_mntobj MntTable[1]; +} __attribute__ ((packed)); + +/* + * Container shutdown command. + */ +struct aac_closecommand { + u_int32_t Command; + u_int32_t ComainerId; +} __attribute__ ((packed)); + +/* + * Write 'stability' options. + */ +typedef enum { + CSTABLE = 1, + CUNSTABLE +} AAC_CacheLevel; + +/* + * Commit level response for a write request. + */ +typedef enum { + CMFILE_SYNC_NVRAM = 1, + CMDATA_SYNC_NVRAM, + CMFILE_SYNC, + CMDATA_SYNC, + CMUNSTABLE +} AAC_CommitLevel; + +/* + * Block read/write operations. + * These structures are packed into the 'data' area in the FIB. + */ + +struct aac_blockread { + AAC_VMCommand Command; /* not FSACommand! */ + u_int32_t ContainerId; + u_int32_t BlockNumber; + u_int32_t ByteCount; + struct aac_sg_table SgMap; /* variable size */ +} __attribute__ ((packed)); + +struct aac_blockread_response { + AAC_FSAStatus Status; + u_int32_t ByteCount; +} __attribute__ ((packed)); + +struct aac_blockwrite { + AAC_VMCommand Command; /* not FSACommand! */ + u_int32_t ContainerId; + u_int32_t BlockNumber; + u_int32_t ByteCount; + AAC_CacheLevel Stable; + struct aac_sg_table SgMap; /* variable size */ +} __attribute__ ((packed)); + +struct aac_blockwrite_response { + AAC_FSAStatus Status; + u_int32_t ByteCount; + AAC_CommitLevel Committed; +} __attribute__ ((packed)); + +/* + * Container shutdown command. + */ +struct aac_close_command { + AAC_VMCommand Command; + u_int32_t ContainerId; +}; + +/******************************************************************************** + * Register definitions for the Adaptec AAC-364 'Jalapeno I/II' adapters, based + * on the SA110 'StrongArm'. + */ + +#define AAC_SA_DOORBELL0_CLEAR 0x98 /* doorbell 0 (adapter->host) */ +#define AAC_SA_DOORBELL0_SET 0x9c +#define AAC_SA_DOORBELL0 0x9c +#define AAC_SA_MASK0_CLEAR 0xa0 +#define AAC_SA_MASK0_SET 0xa4 + +#define AAC_SA_DOORBELL1_CLEAR 0x9a /* doorbell 1 (host->adapter) */ +#define AAC_SA_DOORBELL1_SET 0x9e +#define AAC_SA_MASK1_CLEAR 0xa2 +#define AAC_SA_MASK1_SET 0xa6 + +#define AAC_SA_MAILBOX 0xa8 /* mailbox (20 bytes) */ +#define AAC_SA_FWSTATUS 0xc4 + +/******************************************************************************** + * Register definitions for the Adaptec 'Pablano' adapters, based on the i960Rx, + * and other related adapters. + */ + +#define AAC_RX_IDBR 0x20 /* inbound doorbell register */ +#define AAC_RX_IISR 0x24 /* inbound interrupt mask register */ +#define AAC_RX_IIMR 0x28 /* inbound interrupt status register */ +#define AAC_RX_ODBR 0x2c /* outbound doorbell register */ +#define AAC_RX_OISR 0x30 /* outbound interrupt mask register */ +#define AAC_RX_OIMR 0x34 /* outbound interrupt status register */ + +#define AAC_RX_MAILBOX 0x50 /* mailbox (20 bytes) */ +#define AAC_RX_FWSTATUS 0x6c + +/******************************************************************************** + * Common bit definitions for the doorbell registers. + */ + +/* + * Status bits in the doorbell registers. + */ +#define AAC_DB_SYNC_COMMAND (1<<0) /* send/completed synchronous FIB */ +#define AAC_DB_COMMAND_READY (1<<1) /* posted one or more commands */ +#define AAC_DB_RESPONSE_READY (1<<2) /* one or more commands complete */ +#define AAC_DB_COMMAND_NOT_FULL (1<<3) /* command queue not full */ +#define AAC_DB_RESPONSE_NOT_FULL (1<<4) /* response queue not full */ + +/* + * The adapter can request the host print a message by setting the + * DB_PRINTF flag in DOORBELL0. The driver responds by collecting the + * message from the printf buffer, clearing the DB_PRINTF flag in + * DOORBELL0 and setting it in DOORBELL1. + * (ODBR and IDBR respectively for the i960Rx adapters) + */ +#define AAC_DB_PRINTF (1<<5) /* adapter requests host printf */ + +/* + * Mask containing the interrupt bits we care about. We don't anticipate (or want) + * interrupts not in this mask. + */ +#define AAC_DB_INTERRUPTS (AAC_DB_COMMAND_READY | AAC_DB_RESPONSE_READY | AAC_DB_PRINTF) diff --git a/sys/dev/aac/aacvar.h b/sys/dev/aac/aacvar.h new file mode 100644 index 0000000..68d2172 --- /dev/null +++ b/sys/dev/aac/aacvar.h @@ -0,0 +1,451 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/******************************************************************************** + ******************************************************************************** + Driver Parameter Definitions + ******************************************************************************** + ********************************************************************************/ + +/* + * The firmware interface allows for a 16-bit s/g list length. We limit + * ourselves to a reasonable maximum and ensure alignment. + */ +#define AAC_MAXSGENTRIES 64 /* max S/G entries, limit 65535 */ + +/* + * We allocate a small set of FIBs for the adapter to use to send us messages. + */ +#define AAC_ADAPTER_FIBS 8 + +/* + * FIBs are allocated in clusters as we need them; each cluster must be physically + * contiguous. Set the number of FIBs to try to allocate in a cluster. + * Setting this value too high may result in FIBs not being available in conditions + * of high load with fragmented physical memory. The value must be a multiple of + * (PAGE_SIZE / 512). + */ +#define AAC_CLUSTER_COUNT 64 + +/* + * The controller reports status events in AIFs. We hang on to a number of these + * in order to pass them out to user-space management tools. + */ +#define AAC_AIFQ_LENGTH 64 + +/* + * Firmware messages are passed in the printf buffer. + */ +#define AAC_PRINTF_BUFSIZE 256 + +/* + * We wait this many seconds for the adapter to come ready if it is still booting + */ +#define AAC_BOOT_TIMEOUT (3 * 60) + +/* + * Timeout for immediate commands. + */ +#define AAC_IMMEDIATE_TIMEOUT 30 + +/* + * Character device major numbers. + */ +#define AAC_DISK_MAJOR 200 + +/******************************************************************************** + ******************************************************************************** + Driver Variable Definitions + ******************************************************************************** + ********************************************************************************/ + +#if __FreeBSD_version >= 500005 +# include <sys/taskqueue.h> +#endif + +/* + * Per-container data structure + */ +struct aac_container +{ + struct aac_mntobj co_mntobj; + device_t co_disk; +}; + +/* + * Per-disk structure + */ +struct aac_disk +{ + device_t ad_dev; + dev_t ad_dev_t; + struct aac_softc *ad_controller; + struct aac_container *ad_container; + struct disk ad_disk; + struct devstat ad_stats; + struct disklabel ad_label; + int ad_flags; +#define AAC_DISK_OPEN (1<<0) + int ad_cylinders; + int ad_heads; + int ad_sectors; + u_int32_t ad_size; +}; + +/* + * Per-command control structure. + */ +struct aac_command +{ + TAILQ_ENTRY(aac_command) cm_link; /* list linkage */ + + struct aac_softc *cm_sc; /* controller that owns us */ + + struct aac_fib *cm_fib; /* FIB associated with this command */ + u_int32_t cm_fibphys; /* bus address of the FIB */ + struct bio *cm_data; /* pointer to data in kernel space */ + u_int32_t cm_datalen; /* data length */ + bus_dmamap_t cm_datamap; /* DMA map for bio data */ + struct aac_sg_table *cm_sgtable; /* pointer to s/g table in command */ + + int cm_flags; +#define AAC_CMD_MAPPED (1<<0) /* command has had its data mapped */ +#define AAC_CMD_DATAIN (1<<1) /* command involves data moving from controller to host */ +#define AAC_CMD_DATAOUT (1<<2) /* command involves data moving from host to controller */ +#define AAC_CMD_COMPLETED (1<<3) /* command has been completed */ + + void (* cm_complete)(struct aac_command *cm); + void *cm_private; +}; + +/* + * Command/command packet cluster. + * + * Due to the difficulty of using the zone allocator to create a new + * zone from within a module, we use our own clustering to reduce + * memory wastage due to allocating lots of these small structures. + */ +struct aac_command_cluster +{ + TAILQ_ENTRY(aac_command_cluster) cmc_link; + struct aac_fib *cmc_fibs; + bus_dmamap_t cmc_fibmap; + u_int32_t cmc_fibphys; + struct aac_command cmc_command[AAC_CLUSTER_COUNT]; +}; + +/* + * We gather a number of adapter-visible items into a single structure. + * + * The ordering of this strucure may be important; we copy the Linux driver: + * + * Adapter FIBs + * Init struct + * Queue headers (Comm Area) + * Printf buffer + * + * In addition, we add: + * Sync Fib + */ +struct aac_common { + /* fibs for the controller to send us messages */ + struct aac_fib ac_fibs[AAC_ADAPTER_FIBS]; + + /* the init structure */ + struct aac_adapter_init ac_init; + + /* arena within which the queue structures are kept */ + u_int8_t ac_qbuf[sizeof(struct aac_queue_table) + AAC_QUEUE_ALIGN]; + + /* buffer for text messages from the controller */ + char ac_printf[AAC_PRINTF_BUFSIZE]; + + /* fib for synchronous commands */ + struct aac_fib ac_sync_fib; +}; + +/* + * Interface operations + */ +struct aac_interface +{ + int (* aif_get_fwstatus)(struct aac_softc *sc); + void (* aif_qnotify)(struct aac_softc *sc, int qbit); + int (* aif_get_istatus)(struct aac_softc *sc); + void (* aif_set_istatus)(struct aac_softc *sc, int mask); + void (* aif_set_mailbox)(struct aac_softc *sc, u_int32_t command, + u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3); + int (* aif_get_mailboxstatus)(struct aac_softc *sc); + void (* aif_set_interrupts)(struct aac_softc *sc, int enable); +}; +extern struct aac_interface aac_rx_interface; +extern struct aac_interface aac_sa_interface; + +#define AAC_GET_FWSTATUS(sc) ((sc)->aac_if.aif_get_fwstatus((sc))) +#define AAC_QNOTIFY(sc, qbit) ((sc)->aac_if.aif_qnotify((sc), (qbit))) +#define AAC_GET_ISTATUS(sc) ((sc)->aac_if.aif_get_istatus((sc))) +#define AAC_CLEAR_ISTATUS(sc, mask) ((sc)->aac_if.aif_set_istatus((sc), (mask))) +#define AAC_SET_MAILBOX(sc, command, arg0, arg1, arg2, arg3) \ + ((sc)->aac_if.aif_set_mailbox((sc), (command), (arg0), (arg1), (arg2), (arg3))) +#define AAC_GET_MAILBOXSTATUS(sc) ((sc)->aac_if.aif_get_mailboxstatus((sc))) +#define AAC_MASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), 0)) +#define AAC_UNMASK_INTERRUPTS(sc) ((sc)->aac_if.aif_set_interrupts((sc), 1)) + +#define AAC_SETREG4(sc, reg, val) bus_space_write_4(sc->aac_btag, sc->aac_bhandle, reg, val) +#define AAC_GETREG4(sc, reg) bus_space_read_4 (sc->aac_btag, sc->aac_bhandle, reg) +#define AAC_SETREG2(sc, reg, val) bus_space_write_2(sc->aac_btag, sc->aac_bhandle, reg, val) +#define AAC_GETREG2(sc, reg) bus_space_read_2 (sc->aac_btag, sc->aac_bhandle, reg) +#define AAC_SETREG1(sc, reg, val) bus_space_write_1(sc->aac_btag, sc->aac_bhandle, reg, val) +#define AAC_GETREG1(sc, reg) bus_space_read_1 (sc->aac_btag, sc->aac_bhandle, reg) + +/* + * Per-controller structure. + */ +struct aac_softc +{ + /* bus connections */ + device_t aac_dev; + struct resource *aac_regs_resource; /* register interface window */ + int aac_regs_rid; /* resource ID */ + bus_space_handle_t aac_bhandle; /* bus space handle */ + bus_space_tag_t aac_btag; /* bus space tag */ + bus_dma_tag_t aac_parent_dmat; /* parent DMA tag */ + bus_dma_tag_t aac_buffer_dmat; /* data buffer/command DMA tag */ + struct resource *aac_irq; /* interrupt */ + int aac_irq_rid; + void *aac_intr; /* interrupt handle */ + + /* controller features, limits and status */ + int aac_state; +#define AAC_STATE_SUSPEND (1<<0) +#define AAC_STATE_OPEN (1<<1) +#define AAC_STATE_INTERRUPTS_ON (1<<2) +#define AAC_STATE_AIF_SLEEPER (1<<3) + struct FsaRevision aac_revision; + + /* controller hardware interface */ + int aac_hwif; +#define AAC_HWIF_I960RX 0 +#define AAC_HWIF_STRONGARM 1 + bus_dma_tag_t aac_common_dmat; /* common structure DMA tag */ + bus_dmamap_t aac_common_dmamap; /* common structure DMA map */ + struct aac_common *aac_common; + u_int32_t aac_common_busaddr; + struct aac_interface aac_if; + + /* command/fib resources */ + TAILQ_HEAD(,aac_command_cluster) aac_clusters; /* command memory blocks */ + bus_dma_tag_t aac_fib_dmat; /* DMA tag for allocating FIBs */ + + /* command management */ + TAILQ_HEAD(,aac_command) aac_freecmds; /* command structures available for reuse */ + TAILQ_HEAD(,aac_command) aac_ready; /* commands on hold for controller resources */ + TAILQ_HEAD(,aac_command) aac_completed; /* commands which have been returned by the controller */ + struct bio_queue_head aac_bioq; + struct aac_queue_table *aac_queues; + struct aac_queue_entry *aac_qentries[AAC_QUEUE_COUNT]; + + /* connected containters */ + struct aac_container aac_container[AAC_MAX_CONTAINERS]; + + /* delayed activity infrastructure */ +#if __FreeBSD_version >= 500005 + struct task aac_task_complete; /* deferred-completion task */ +#endif + struct intr_config_hook aac_ich; + + /* management interface */ + dev_t aac_dev_t; + struct aac_aif_command aac_aifq[AAC_AIFQ_LENGTH]; + int aac_aifq_head; + int aac_aifq_tail; +}; + + +/* + * Public functions + */ +extern void aac_free(struct aac_softc *sc); +extern int aac_attach(struct aac_softc *sc); +extern int aac_detach(device_t dev); +extern int aac_shutdown(device_t dev); +extern int aac_suspend(device_t dev); +extern int aac_resume(device_t dev); +extern void aac_intr(void *arg); +extern devclass_t aac_devclass; +extern void aac_submit_bio(struct bio *bp); +extern void aac_complete_bio(struct bio *bp); + +/* + * Debugging levels: + * 0 - quiet, only emit warnings + * 1 - noisy, emit major function points and things done + * 2 - extremely noisy, emit trace items in loops, etc. + */ +#ifdef AAC_DEBUG +#define debug(level, fmt, args...) do { if (level <= AAC_DEBUG) printf("%s: " fmt "\n", __FUNCTION__ , ##args); } while(0) +#define debug_called(level) do { if (level <= AAC_DEBUG) printf(__FUNCTION__ ": called\n"); } while(0) + +extern void aac_print_queues(struct aac_softc *sc); +extern void aac_panic(struct aac_softc *sc, char *reason); +extern void aac_print_fib(struct aac_softc *sc, struct aac_fib *fib, char *caller); +extern void aac_print_aif(struct aac_softc *sc, struct aac_aif_command *aif); + +#define AAC_PRINT_FIB(sc, fib) aac_print_fib(sc, fib, __FUNCTION__) + +#else +#define debug(level, fmt, args...) +#define debug_called(level) + +#define aac_print_queues(sc) +#define aac_panic(sc, reason) +#define aac_print_aif(sc, aif) + +#define AAC_PRINT_FIB(sc, fib) +#endif + +struct aac_code_lookup { + char *string; + u_int32_t code; +}; + +/* + * Borrowed from <struct.h> + */ +/* Offset of the field in the structure. */ +#define fldoff(name, field) \ + ((int)&(((struct name *)0)->field)) + +/******************************************************************************** + * Queue primitives + * + * These are broken out individually to make statistics gathering easier. + */ + +static __inline void +aac_enqueue_ready(struct aac_command *cm) +{ + int s; + + s = splbio(); + TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ready, cm, cm_link); + splx(s); +} + +static __inline void +aac_requeue_ready(struct aac_command *cm) +{ + int s; + + s = splbio(); + TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ready, cm, cm_link); + splx(s); +} + +static __inline struct aac_command * +aac_dequeue_ready(struct aac_softc *sc) +{ + struct aac_command *cm; + int s; + + s = splbio(); + if ((cm = TAILQ_FIRST(&sc->aac_ready)) != NULL) + TAILQ_REMOVE(&sc->aac_ready, cm, cm_link); + splx(s); + return(cm); +} + +static __inline void +aac_enqueue_completed(struct aac_command *cm) +{ + int s; + + s = splbio(); + TAILQ_INSERT_TAIL(&cm->cm_sc->aac_completed, cm, cm_link); + splx(s); +} + +static __inline struct aac_command * +aac_dequeue_completed(struct aac_softc *sc) +{ + struct aac_command *cm; + int s; + + s = splbio(); + if ((cm = TAILQ_FIRST(&sc->aac_completed)) != NULL) + TAILQ_REMOVE(&sc->aac_completed, cm, cm_link); + splx(s); + return(cm); +} + +static __inline void +aac_enqueue_free(struct aac_command *cm) +{ + int s; + + s = splbio(); + TAILQ_INSERT_HEAD(&cm->cm_sc->aac_freecmds, cm, cm_link); + splx(s); +} + +static __inline struct aac_command * +aac_dequeue_free(struct aac_softc *sc) +{ + struct aac_command *cm; + int s; + + s = splbio(); + if ((cm = TAILQ_FIRST(&sc->aac_freecmds)) != NULL) + TAILQ_REMOVE(&sc->aac_freecmds, cm, cm_link); + splx(s); + return(cm); +} + +static __inline void +aac_enqueue_cluster(struct aac_softc *sc, struct aac_command_cluster *cmc) +{ + int s; + + s = splbio(); + TAILQ_INSERT_HEAD(&sc->aac_clusters, cmc, cmc_link); + splx(s); +} + +static __inline struct aac_command_cluster * +aac_dequeue_cluster(struct aac_softc *sc) +{ + struct aac_command_cluster *cmc; + int s; + + s = splbio(); + if ((cmc = TAILQ_FIRST(&sc->aac_clusters)) != NULL) + TAILQ_REMOVE(&sc->aac_clusters, cmc, cmc_link); + splx(s); + return(cmc); +} |