Initial import of a driver for the 3ware Escalade family of ATA RAID

controllers.
This commit is contained in:
Mike Smith 2000-05-24 23:35:23 +00:00
parent 1bd2fef771
commit 2597312222
4 changed files with 2592 additions and 0 deletions

1898
sys/dev/twe/twe.c Normal file

File diff suppressed because it is too large Load Diff

305
sys/dev/twe/twe_disk.c Normal file
View File

@ -0,0 +1,305 @@
/*-
* 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>
#if __FreeBSD_version < 500000
# include <dev/twe/twe_compat.h>
#else
# include <sys/bio.h>
#endif
#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/twe/twereg.h>
#include <dev/twe/twevar.h>
/*
* Interface to controller.
*/
static int twed_probe(device_t dev);
static int twed_attach(device_t dev);
static int twed_detach(device_t dev);
/*
* Interface to the device switch
*/
static d_open_t twed_open;
static d_close_t twed_close;
static d_strategy_t twed_strategy;
#define TWED_CDEV_MAJOR 147
static struct cdevsw twed_cdevsw = {
/* open */ twed_open,
/* close */ twed_close,
/* read */ physread,
/* write */ physwrite,
/* ioctl */ noioctl,
/* poll */ nopoll,
/* mmap */ nommap,
/* strategy */ twed_strategy,
/* name */ "twed",
/* maj */ TWED_CDEV_MAJOR,
/* dump */ nodump,
/* psize */ nopsize,
/* flags */ D_DISK,
/* bmaj */ -1
};
devclass_t twed_devclass;
static struct cdevsw tweddisk_cdevsw;
#ifdef FREEBSD_4
static int disks_registered = 0;
#endif
static device_method_t twed_methods[] = {
DEVMETHOD(device_probe, twed_probe),
DEVMETHOD(device_attach, twed_attach),
DEVMETHOD(device_detach, twed_detach),
{ 0, 0 }
};
static driver_t twed_driver = {
"twed",
twed_methods,
sizeof(struct twed_softc)
};
DRIVER_MODULE(twed, twe, twed_driver, twed_devclass, 0, 0);
/********************************************************************************
* Handle open from generic layer.
*
* Note that this is typically only called by the diskslice code, and not
* for opens on subdevices (eg. slices, partitions).
*/
static int
twed_open(dev_t dev, int flags, int fmt, struct proc *p)
{
struct twed_softc *sc = (struct twed_softc *)dev->si_drv1;
struct disklabel *label;
debug_called(4);
if (sc == NULL)
return (ENXIO);
/* check that the controller is up and running */
if (sc->twed_controller->twe_state & TWE_STATE_SHUTDOWN)
return(ENXIO);
/* build synthetic label */
label = &sc->twed_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_ESDI;
label->d_secsize = TWE_BLOCK_SIZE;
label->d_nsectors = sc->twed_drive->td_sectors;
label->d_ntracks = sc->twed_drive->td_heads;
label->d_ncylinders = sc->twed_drive->td_cylinders;
label->d_secpercyl = sc->twed_drive->td_sectors * sc->twed_drive->td_heads;
label->d_secperunit = sc->twed_drive->td_size;
sc->twed_flags |= TWED_OPEN;
return (0);
}
/********************************************************************************
* Handle last close of the disk device.
*/
static int
twed_close(dev_t dev, int flags, int fmt, struct proc *p)
{
struct twed_softc *sc = (struct twed_softc *)dev->si_drv1;
debug_called(4);
if (sc == NULL)
return (ENXIO);
sc->twed_flags &= ~TWED_OPEN;
return (0);
}
/********************************************************************************
* Handle an I/O request.
*/
static void
twed_strategy(struct bio *bp)
{
struct twed_softc *sc = (struct twed_softc *)bp->bio_dev->si_drv1;
debug_called(4);
/* bogus disk? */
if (sc == NULL) {
bp->bio_flags |= BIO_ERROR;
bp->bio_error = EINVAL;
return;
}
/* do-nothing operation? */
if (bp->bio_bcount == 0) {
bp->bio_resid = bp->bio_bcount;
biodone(bp);
return;
}
/* perform accounting */
devstat_start_transaction(&sc->twed_stats);
/* pass the bio to the controller - it can work out who we are */
twe_submit_buf(sc->twed_controller, bp);
return;
}
/********************************************************************************
* Handle completion of an I/O request.
*/
void
twed_intr(void *data)
{
struct bio *bp = (struct bio *)data;
struct twed_softc *sc = (struct twed_softc *)bp->bio_dev->si_drv1;
debug_called(4);
/* check for error from controller code */
if (bp->bio_flags & BIO_ERROR) {
bp->bio_error = EIO;
} else {
bp->bio_resid = 0;
}
devstat_end_transaction_bio(&sc->twed_stats, bp);
biodone(bp);
}
/********************************************************************************
* Stub to provide device identification when probed.
*/
static int
twed_probe(device_t dev)
{
debug_called(4);
device_set_desc(dev, "3ware RAID unit");
return (0);
}
/********************************************************************************
* Attach a unit to the controller.
*/
static int
twed_attach(device_t dev)
{
struct twed_softc *sc = (struct twed_softc *)device_get_softc(dev);
device_t parent;
char *state;
dev_t dsk;
debug_called(4);
/* initialise our softc */
parent = device_get_parent(dev);
sc->twed_controller = (struct twe_softc *)device_get_softc(parent);
sc->twed_drive = device_get_ivars(dev);
sc->twed_dev = dev;
/* report some basic status */
switch(sc->twed_drive->td_state) {
case TWE_DRIVE_READY:
state = "ready";
break;
case TWE_DRIVE_DEGRADED:
state = "degraded";
break;
case TWE_DRIVE_OFFLINE:
state = "offline";
break;
default:
state = "unknown";
break;
}
device_printf(dev, "%uMB (%u sectors) RAID %d (%s)\n",
sc->twed_drive->td_size / ((1024 * 1024) / TWE_BLOCK_SIZE),
sc->twed_drive->td_size, sc->twed_drive->td_raidlevel, state);
devstat_add_entry(&sc->twed_stats, "twed", device_get_unit(dev), TWE_BLOCK_SIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER,
DEVSTAT_PRIORITY_ARRAY);
/* attach a generic disk device to ourselves */
dsk = disk_create(device_get_unit(dev), &sc->twed_disk, 0, &twed_cdevsw, &tweddisk_cdevsw);
dsk->si_drv1 = sc;
sc->twed_dev_t = dsk;
#ifdef FREEBSD_4
disks_registered++;
#endif
/* set the maximum I/O size to the theoretical maximum allowed by the S/G list size */
dsk->si_iosize_max = (TWE_MAX_SGL_LENGTH - 1) * PAGE_SIZE;
return (0);
}
/********************************************************************************
* Disconnect ourselves from the system.
*/
static int
twed_detach(device_t dev)
{
struct twed_softc *sc = (struct twed_softc *)device_get_softc(dev);
debug_called(4);
if (sc->twed_flags & TWED_OPEN)
return(EBUSY);
devstat_remove_entry(&sc->twed_stats);
#ifdef FREEBSD_4
if (--disks_registered == 0)
cdevsw_remove(&tweddisk_cdevsw);
#else
disk_destroy(sc->twed_dev_t);
#endif
return(0);
}

226
sys/dev/twe/twereg.h Normal file
View File

@ -0,0 +1,226 @@
/*-
* 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$
*/
/*
* Register names, bit definitions, structure names and members are
* identical with those in the Linux driver where possible and sane
* for simplicity's sake. (The TW_ prefix has become TWE_)
* Some defines that are clearly irrelevant to FreeBSD have been
* removed.
*/
/* control register bit definitions */
#define TWE_CONTROL_CLEAR_HOST_INTERRUPT 0x00080000
#define TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT 0x00040000
#define TWE_CONTROL_MASK_COMMAND_INTERRUPT 0x00020000
#define TWE_CONTROL_MASK_RESPONSE_INTERRUPT 0x00010000
#define TWE_CONTROL_UNMASK_COMMAND_INTERRUPT 0x00008000
#define TWE_CONTROL_UNMASK_RESPONSE_INTERRUPT 0x00004000
#define TWE_CONTROL_CLEAR_ERROR_STATUS 0x00000200
#define TWE_CONTROL_ISSUE_SOFT_RESET 0x00000100
#define TWE_CONTROL_ENABLE_INTERRUPTS 0x00000080
#define TWE_CONTROL_DISABLE_INTERRUPTS 0x00000040
#define TWE_CONTROL_ISSUE_HOST_INTERRUPT 0x00000020
#define TWE_SOFT_RESET(sc) TWE_CONTROL(sc, TWE_CONTROL_ISSUE_SOFT_RESET | \
TWE_CONTROL_CLEAR_HOST_INTERRUPT | \
TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT | \
TWE_CONTROL_MASK_COMMAND_INTERRUPT | \
TWE_CONTROL_MASK_RESPONSE_INTERRUPT | \
TWE_CONTROL_CLEAR_ERROR_STATUS | \
TWE_CONTROL_DISABLE_INTERRUPTS)
/* status register bit definitions */
#define TWE_STATUS_MAJOR_VERSION_MASK 0xF0000000
#define TWE_STATUS_MINOR_VERSION_MASK 0x0F000000
#define TWE_STATUS_PCI_PARITY_ERROR 0x00800000
#define TWE_STATUS_QUEUE_ERROR 0x00400000
#define TWE_STATUS_MICROCONTROLLER_ERROR 0x00200000
#define TWE_STATUS_PCI_ABORT 0x00100000
#define TWE_STATUS_HOST_INTERRUPT 0x00080000
#define TWE_STATUS_ATTENTION_INTERRUPT 0x00040000
#define TWE_STATUS_COMMAND_INTERRUPT 0x00020000
#define TWE_STATUS_RESPONSE_INTERRUPT 0x00010000
#define TWE_STATUS_COMMAND_QUEUE_FULL 0x00008000
#define TWE_STATUS_RESPONSE_QUEUE_EMPTY 0x00004000
#define TWE_STATUS_MICROCONTROLLER_READY 0x00002000
#define TWE_STATUS_COMMAND_QUEUE_EMPTY 0x00001000
#define TWE_STATUS_ALL_INTERRUPTS 0x000F0000
#define TWE_STATUS_CLEARABLE_BITS 0x00D00000
#define TWE_STATUS_EXPECTED_BITS 0x00002000
#define TWE_STATUS_UNEXPECTED_BITS 0x00F80000
/* for use with the %b printf format */
#define TWE_STATUS_BITS_DESCRIPTION \
"\20\15CQEMPTY\16UCREADY\17RQEMPTY\20CQFULL\21RINTR\22CINTR\23AINTR\24HINTR\25PCIABRT\26MCERR\27QERR\30PCIPERR\n"
/* detect inconsistencies in the status register */
#define TWE_STATUS_ERRORS(x) \
(((x & TWE_STATUS_PCI_ABORT) || \
(x & TWE_STATUS_PCI_PARITY_ERROR) || \
(x & TWE_STATUS_QUEUE_ERROR) || \
(x & TWE_STATUS_MICROCONTROLLER_ERROR)) && \
(x & TWE_STATUS_MICROCONTROLLER_READY))
/* Response queue bit definitions */
#define TWE_RESPONSE_ID_MASK 0x00000FF0
/* PCI related defines */
#define TWE_IO_CONFIG_REG 0x10
#define TWE_DEVICE_NAME "3ware Storage Controller"
#define TWE_VENDOR_ID 0x13C1
#define TWE_DEVICE_ID 0x1000
/* command packet opcodes */
#define TWE_OP_NOP 0x0
#define TWE_OP_INIT_CONNECTION 0x1
#define TWE_OP_READ 0x2
#define TWE_OP_WRITE 0x3
#define TWE_OP_VERIFY 0x4
#define TWE_OP_GET_PARAM 0x12
#define TWE_OP_SET_PARAM 0x13
#define TWE_OP_SECTOR_INFO 0x1a
#define TWE_OP_AEN_LISTEN 0x1c
/* asynchronous event notification (AEN) codes */
#define TWE_AEN_QUEUE_EMPTY 0x0000
#define TWE_AEN_SOFT_RESET 0x0001
#define TWE_AEN_DEGRADED_MIRROR 0x0002
#define TWE_AEN_CONTROLLER_ERROR 0x0003
#define TWE_AEN_REBUILD_FAIL 0x0004
#define TWE_AEN_REBUILD_DONE 0x0005
#define TWE_AEN_QUEUE_FULL 0x00ff
#define TWE_AEN_TABLE_UNDEFINED 0x15
/* misc defines */
#define TWE_ALIGNMENT 0x200
#define TWE_MAX_UNITS 16
#define TWE_COMMAND_ALIGNMENT_MASK 0x1ff
#define TWE_INIT_MESSAGE_CREDITS 0x100
#define TWE_INIT_COMMAND_PACKET_SIZE 0x3
#define TWE_MAX_SGL_LENGTH 62
#define TWE_Q_LENGTH 256
#define TWE_Q_START 0
#define TWE_MAX_RESET_TRIES 3
#define TWE_UNIT_INFORMATION_TABLE_BASE 0x300
#define TWE_BLOCK_SIZE 0x200 /* 512-byte blocks */
#define TWE_SECTOR_SIZE 0x200 /* generic I/O bufffer */
#define TWE_IOCTL 0x80
#define TWE_MAX_AEN_TRIES 100
/* wrappers for bus-space actions */
#define TWE_CONTROL(sc, val) bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x0, (u_int32_t)val)
#define TWE_STATUS(sc) (u_int32_t)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0x4)
#define TWE_COMMAND_QUEUE(sc, val) bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x8, (u_int32_t)val)
#define TWE_RESPONSE_QUEUE(sc) (TWE_Response_Queue)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0xc)
/* scatter/gather list entry */
typedef struct
{
u_int32_t address;
u_int32_t length;
} TWE_SG_Entry __attribute__ ((packed));
/* command packet - must be TWE_ALIGNMENT aligned */
typedef struct
{
u_int8_t opcode:5;
u_int8_t sgl_offset:3;
u_int8_t size;
u_int8_t request_id;
u_int8_t unit:4;
u_int8_t host_id:4;
u_int8_t status;
u_int8_t flags;
u_int16_t count; /* block count, parameter count, message credits */
union {
struct {
u_int32_t lba;
TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH];
} io __attribute__ ((packed));
struct {
TWE_SG_Entry sgl[TWE_MAX_SGL_LENGTH];
} param;
struct {
u_int32_t response_queue_pointer;
} init_connection;
} args;
} TWE_Command __attribute__ ((packed));
/* argument to TWE_OP_GET/SET_PARAM */
typedef struct
{
u_int16_t table_id;
u_int8_t parameter_id;
u_int8_t parameter_size_bytes;
u_int8_t data[1];
} TWE_Param __attribute__ ((packed));
/* response queue entry */
typedef union
{
struct
{
u_int32_t undefined_1:4;
u_int32_t response_id:8;
u_int32_t undefined_2:20;
} u;
u_int32_t value;
} TWE_Response_Queue;
#if 0 /* no idea what these will be useful for yet */
typedef struct
{
int32_t buffer;
u_int8_t opcode;
u_int16_t table_id;
u_int8_t parameter_id;
u_int8_t parameter_size_bytes;
u_int8_t data[1];
} TWE_Ioctl __attribute__ ((packed));
typedef struct
{
u_int32_t base_addr;
u_int32_t control_reg_addr;
u_int32_t status_reg_addr;
u_int32_t command_que_addr;
u_int32_t response_que_addr;
} TWE_Registers __attribute__ ((packed));
typedef struct
{
char *buffer;
int32_t length;
int32_t offset;
int32_t position;
} TWE_Info __attribute__ ((packed));
#endif

163
sys/dev/twe/twevar.h Normal file
View File

@ -0,0 +1,163 @@
/*-
* 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$
*/
#ifdef TWE_DEBUG
#define debug(level, fmt, args...) do { if (level <= TWE_DEBUG) printf("%s: " fmt "\n", __FUNCTION__ , ##args); } while(0)
#define debug_called(level) do { if (level <= TWE_DEBUG) printf(__FUNCTION__ ": called\n"); } while(0)
#else
#define debug(level, fmt, args...)
#define debug_called(level)
#endif
/*
* Structure describing a logical unit as attached to the controller
*/
struct twe_drive
{
/* unit properties */
u_int32_t td_size;
int td_cylinders;
int td_heads;
int td_sectors;
int td_unit;
/* unit state */
int td_state;
#define TWE_DRIVE_READY 0
#define TWE_DRIVE_DEGRADED 1
#define TWE_DRIVE_OFFLINE 2
int td_raidlevel;
#define TWE_DRIVE_RAID0 0
#define TWE_DRIVE_RAID1 1
#define TWE_DRIVE_UNKNOWN 0xff
/* handle for attached driver */
device_t td_disk;
};
/*
* Per-command control structure.
*
* Note that due to alignment constraints on the tc_command field, this *must* be 64-byte aligned.
* We achieve this by placing the command at the beginning of the structure, and using malloc()
* to allocate each structure.
*/
struct twe_request
{
/* controller command */
TWE_Command tr_command; /* command as submitted to controller */
bus_dmamap_t tr_cmdmap; /* DMA map for command */
u_int32_t tr_cmdphys; /* address of command in controller space */
/* command payload */
void *tr_data; /* data buffer */
void *tr_realdata; /* copy of real data buffer pointer for alignment fixup */
size_t tr_length;
bus_dmamap_t tr_dmamap; /* DMA map for data */
u_int32_t tr_dataphys; /* data buffer base address in controller space */
TAILQ_ENTRY(twe_request) tr_link; /* list linkage */
struct twe_softc *tr_sc; /* controller that owns us */
int tr_status; /* command status */
#define TWE_CMD_SETUP 0 /* being assembled */
#define TWE_CMD_BUSY 1 /* submitted to controller */
#define TWE_CMD_COMPLETE 2 /* completed by controller (maybe with error) */
#define TWE_CMD_FAILED 3 /* failed submission to controller */
int tr_flags;
#define TWE_CMD_DATAIN (1<<0)
#define TWE_CMD_DATAOUT (1<<1)
#define TWE_CMD_ALIGNBUF (1<<2) /* data in bio is misaligned, have to copy to/from private buffer */
void (* tr_complete)(struct twe_request *tr); /* completion handler */
void *tr_private; /* submitter-private data or wait channel */
};
/*
* Per-controller state.
*/
struct twe_softc
{
/* bus connections */
device_t twe_dev;
dev_t twe_dev_t;
struct resource *twe_io; /* register interface window */
bus_space_handle_t twe_bhandle; /* bus space handle */
bus_space_tag_t twe_btag; /* bus space tag */
bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */
bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */
struct resource *twe_irq; /* interrupt */
void *twe_intr; /* interrupt handle */
/* controller queues and arrays */
TAILQ_HEAD(, twe_request) twe_freecmds; /* command structures available for reuse */
TAILQ_HEAD(, twe_request) twe_work; /* active commands (busy or waiting for completion) */
struct twe_request *twe_cmdlookup[TWE_Q_LENGTH]; /* busy commands indexed by request ID */
int twe_busycmds; /* count of busy commands */
struct twe_drive twe_drive[TWE_MAX_UNITS]; /* attached drives */
struct bio_queue_head twe_bioq; /* outstanding I/O operations */
struct twe_request *twe_deferred; /* request that the controller wouldn't take */
u_int16_t twe_aen_queue[TWE_Q_LENGTH]; /* AENs queued for userland tool(s) */
int twe_aen_head, twe_aen_tail; /* ringbuffer pointers for AEN queue */
/* controller status */
int twe_state;
#define TWE_STATE_INTEN (1<<0) /* interrupts have been enabled */
#define TWE_STATE_SHUTDOWN (1<<1) /* controller is shut down */
#define TWE_STATE_OPEN (1<<2) /* control device is open */
#define TWE_STATE_SUSPEND (1<<3) /* controller is suspended */
/* delayed configuration hook */
struct intr_config_hook twe_ich;
/* wait-for-aen notification */
int twe_wait_aen;
};
/*
* Virtual disk driver.
*/
struct twed_softc
{
device_t twed_dev;
dev_t twed_dev_t;
struct twe_softc *twed_controller; /* parent device softc */
struct twe_drive *twed_drive; /* drive data in parent softc */
struct disk twed_disk; /* generic disk handle */
struct devstat twed_stats; /* accounting */
struct disklabel twed_label; /* synthetic label */
int twed_flags;
#define TWED_OPEN (1<<0) /* drive is open (can't shut down) */
};
/*
* Interface betwen driver core and disk driver (should be using a bus?)
*/
extern int twe_submit_buf(struct twe_softc *sc, struct bio *bp);
extern void twed_intr(void *data);