From ea520bd62c00b93a39e2e7082216b4eb3ce4ad3f Mon Sep 17 00:00:00 2001 From: jlemon Date: Wed, 8 Mar 2000 16:16:31 +0000 Subject: Add support for older EISA compaq cards and newer Smart 4200 cards. Change disk names to `idad' to avoid naming conflicts with the controller, and enable the new disk code to pick up the drives. Tested by: david.w.james@bt.com (existing compaq support) Reviewed by: msmith Approved by: jordan --- sys/dev/ida/ida.c | 98 +++++++++------ sys/dev/ida/ida_disk.c | 127 +++++++------------ sys/dev/ida/ida_eisa.c | 330 +++++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/ida/ida_pci.c | 150 +++++++++++++++++----- sys/dev/ida/idareg.h | 41 +++++- sys/dev/ida/idavar.h | 38 +++++- 6 files changed, 623 insertions(+), 161 deletions(-) create mode 100644 sys/dev/ida/ida_eisa.c (limited to 'sys/dev/ida') diff --git a/sys/dev/ida/ida.c b/sys/dev/ida/ida.c index ae25391..c53f2c9 100644 --- a/sys/dev/ida/ida.c +++ b/sys/dev/ida/ida.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999 Jonathan Lemon + * Copyright (c) 1999,2000 Jonathan Lemon * All rights reserved. * # Derived from the original IDA Compaq RAID driver, which is @@ -48,6 +48,7 @@ #include #include #include +#include #if NPCI > 0 #include @@ -60,12 +61,6 @@ #include #include -#define ida_inl(ida, port) \ - bus_space_read_4((ida)->tag, (ida)->bsh, port) - -#define ida_outl(ida, port, val) \ - bus_space_write_4((ida)->tag, (ida)->bsh, port, val) - /* prototypes */ static void ida_alloc_qcb(struct ida_softc *ida); static void ida_construct_qcb(struct ida_softc *ida); @@ -76,11 +71,10 @@ static void ida_wait(struct ida_softc *ida, struct ida_qcb *qcb, int delay); void ida_free(struct ida_softc *ida) { + int i; - /* - * still need to call bus_dmamap_destroy() for each map created - * in ida_alloc_qcb(). - */ + for (i = 0; i < ida->num_qcbs; i++) + bus_dmamap_destroy(ida->buffer_dmat, ida->qcbs[i].dmamap); if (ida->hwqcb_busaddr) bus_dmamap_unload(ida->hwqcb_dmat, ida->hwqcb_dmamap); @@ -140,6 +134,23 @@ ida_get_qcb(struct ida_softc *ida) return (qcb); } +static __inline bus_addr_t +idahwqcbvtop(struct ida_softc *ida, struct ida_hardware_qcb *hwqcb) +{ + return (ida->hwqcb_busaddr + + ((bus_addr_t)hwqcb - (bus_addr_t)ida->hwqcbs)); +} + +static __inline struct ida_qcb * +idahwqcbptov(struct ida_softc *ida, bus_addr_t hwqcb_addr) +{ + struct ida_hardware_qcb *hwqcb; + + hwqcb = (struct ida_hardware_qcb *) + ((bus_addr_t)ida->hwqcbs + (hwqcb_addr - ida->hwqcb_busaddr)); + return (hwqcb->qcb); +} + /* * XXX * since we allocate all QCB space up front during initialization, then @@ -163,6 +174,7 @@ ida_alloc_qcb(struct ida_softc *ida) qcb->flags = QCB_FREE; qcb->hwqcb = &ida->hwqcbs[ida->num_qcbs]; qcb->hwqcb->qcb = qcb; + qcb->hwqcb_busaddr = idahwqcbvtop(ida, qcb->hwqcb); SLIST_INSERT_HEAD(&ida->free_qcbs, qcb, link.sle); ida->num_qcbs++; } @@ -236,7 +248,7 @@ ida_attach(struct ida_softc *ida) struct ida_controller_info cinfo; int error, i; - ida_outl(ida, R_INT_MASK, INT_DISABLE); + ida->cmd.int_enable(ida, 0); error = ida_command(ida, CMD_GET_CTRL_INFO, &cinfo, sizeof(cinfo), IDA_CONTROLLER, DMA_DATA_IN); @@ -252,11 +264,36 @@ ida_attach(struct ida_softc *ida) ida->num_drives = cinfo.num_drvs; for (i = 0; i < ida->num_drives; i++) - device_add_child(ida->dev, "id", i); + device_add_child(ida->dev, /*"idad"*/NULL, -1); bus_generic_attach(ida->dev); - ida_outl(ida, R_INT_MASK, INT_ENABLE); + ida->cmd.int_enable(ida, 1); +} + +int +ida_detach(device_t dev) +{ + struct ida_softc *ida; + int error = 0; + + ida = (struct ida_softc *)device_get_softc(dev); + + /* + * XXX + * before detaching, we must make sure that the system is + * quiescent; nothing mounted, no pending activity. + */ + + /* + * XXX + * now, how are we supposed to maintain a list of our drives? + * iterate over our "child devices"? + */ + + + ida_free(ida); + return (error); } static void @@ -372,23 +409,6 @@ ida_construct_qcb(struct ida_softc *ida) STAILQ_INSERT_TAIL(&ida->qcb_queue, qcb, link.stqe); } -static __inline bus_addr_t -idahwqcbvtop(struct ida_softc *ida, struct ida_hardware_qcb *hwqcb) -{ - return (ida->hwqcb_busaddr + - ((bus_addr_t)hwqcb - (bus_addr_t)ida->hwqcbs)); -} - -static __inline struct ida_qcb * -idahwqcbptov(struct ida_softc *ida, bus_addr_t hwqcb_addr) -{ - struct ida_hardware_qcb *hwqcb; - - hwqcb = (struct ida_hardware_qcb *) - ((bus_addr_t)ida->hwqcbs + (hwqcb_addr - ida->hwqcb_busaddr)); - return (hwqcb->qcb); -} - /* * This routine will be called from ida_intr in order to queue up more * I/O, meaning that we may be in an interrupt context. Hence, we should @@ -400,19 +420,15 @@ ida_start(struct ida_softc *ida) struct ida_qcb *qcb; while ((qcb = STAILQ_FIRST(&ida->qcb_queue)) != NULL) { - if (ida_inl(ida, R_CMD_FIFO) == 0) - break; /* fifo is full */ + if (ida->cmd.fifo_full(ida)) + break; STAILQ_REMOVE_HEAD(&ida->qcb_queue, link.stqe); /* * XXX * place the qcb on an active list and set a timeout? */ qcb->state = QCB_ACTIVE; - /* - * XXX - * cache the physaddr so we don't keep doing this? - */ - ida_outl(ida, R_CMD_FIFO, idahwqcbvtop(ida, qcb->hwqcb)); + ida->cmd.submit(ida, qcb); } } @@ -429,7 +445,7 @@ ida_wait(struct ida_softc *ida, struct ida_qcb *qcb, int delay) return; } - while ((completed = ida_inl(ida, R_DONE_FIFO)) == 0) { + while ((completed = ida->cmd.done(ida)) == 0) { if (delay-- == 0) panic("ida_wait: timeout waiting for completion"); DELAY(10); @@ -451,10 +467,10 @@ ida_intr(void *data) ida = (struct ida_softc *)data; - if (ida_inl(ida, R_INT_PENDING) == 0) + if (ida->cmd.int_pending(ida) == 0) return; /* not our interrupt */ - while ((completed = ida_inl(ida, R_DONE_FIFO)) != 0) { + while ((completed = ida->cmd.done(ida)) != 0) { qcb = idahwqcbptov(ida, completed & ~3); if (qcb == NULL || qcb->state != QCB_ACTIVE) { diff --git a/sys/dev/ida/ida_disk.c b/sys/dev/ida/ida_disk.c index 5b996d4..b910235 100644 --- a/sys/dev/ida/ida_disk.c +++ b/sys/dev/ida/ida_disk.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999 Jonathan Lemon + * Copyright (c) 1999,2000 Jonathan Lemon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,8 +39,7 @@ #include #include #include -#include -#include +#include #if NPCI > 0 #include @@ -54,15 +53,13 @@ #include /* prototypes */ -static void id_drvinit(void); static int idprobe(device_t dev); static int idattach(device_t dev); +static int iddetach(device_t dev); static d_open_t idopen; static d_close_t idclose; static d_strategy_t idstrategy; -static d_ioctl_t idioctl; -static d_psize_t idsize; #define ID_BDEV_MAJOR 29 #define ID_CDEV_MAJOR 109 @@ -75,29 +72,31 @@ static struct cdevsw id_cdevsw = { /* close */ idclose, /* read */ physread, /* write */ physwrite, - /* ioctl */ idioctl, + /* ioctl */ noioctl, /* poll */ nopoll, /* mmap */ nommap, /* strategy */ idstrategy, /* name */ "id", /* maj */ ID_CDEV_MAJOR, /* dump */ nodump, - /* psize */ idsize, + /* psize */ nopsize, /* flags */ D_DISK, /* bmaj */ ID_BDEV_MAJOR }; -static struct cdevsw stolen_cdevsw; static devclass_t id_devclass; +static struct cdevsw iddisk_cdevsw; +static int disks_registered = 0; static device_method_t id_methods[] = { DEVMETHOD(device_probe, idprobe), DEVMETHOD(device_attach, idattach), + DEVMETHOD(device_detach, iddetach), { 0, 0 } }; static driver_t id_driver = { - "id", + "idad", id_methods, sizeof(struct id_softc) }; @@ -105,42 +104,31 @@ static driver_t id_driver = { static __inline struct id_softc * idgetsoftc(dev_t dev) { - int unit; - unit = dkunit(dev); - return ((struct id_softc *)devclass_get_softc(id_devclass, unit)); + return ((struct id_softc *)dev->si_drv1); } static int idopen(dev_t dev, int flags, int fmt, struct proc *p) { struct id_softc *drv; - struct disklabel label; - int error; + struct disklabel *label; drv = idgetsoftc(dev); if (drv == NULL) return (ENXIO); - /* XXX block against race where > 1 person is reading label? */ + label = &drv->disk.d_label; + bzero(label, sizeof(*label)); + label->d_type = DTYPE_SCSI; + label->d_secsize = drv->secsize; + label->d_nsectors = drv->sectors; + label->d_ntracks = drv->heads; + label->d_ncylinders = drv->cylinders; + label->d_secpercyl = drv->sectors * drv->heads; + label->d_secperunit = drv->secperunit; - bzero(&label, sizeof(label)); - label.d_type = DTYPE_SCSI; /* XXX should this be DTYPE_RAID? */ -/* - strncpy(label.d_typename, ... - strncpy(label.d_packname, ... -*/ - label.d_secsize = drv->secsize; - label.d_nsectors = drv->sectors; - label.d_ntracks = drv->heads; - label.d_ncylinders = drv->cylinders; - label.d_secpercyl = drv->sectors * drv->heads; - label.d_secperunit = drv->secperunit; - - /* Initialize slice tables. */ - error = dsopen(dev, fmt, 0, &drv->slices, &label); - - return (error); + return (0); } static int @@ -151,39 +139,9 @@ idclose(dev_t dev, int flags, int fmt, struct proc *p) drv = idgetsoftc(dev); if (drv == NULL) return (ENXIO); - dsclose(dev, fmt, drv->slices); return (0); } -static int -idioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p) -{ - struct id_softc *drv; - int error; - - drv = idgetsoftc(dev); - if (drv == NULL) - return (ENXIO); - - error = dsioctl(dev, cmd, addr, flag, &drv->slices); - - if (error == ENOIOCTL) - return (ENOTTY); - - return (error); -} - -static int -idsize(dev_t dev) -{ - struct id_softc *drv; - - drv = idgetsoftc(dev); - if (drv == NULL) - return (ENXIO); - return (dssize(dev, &drv->slices)); -} - /* * Read/write routine for a buffer. Finds the proper unit, range checks * arguments, and schedules the transfer. Does not wait for the transfer @@ -202,9 +160,6 @@ idstrategy(struct buf *bp) goto bad; } - if (dscheck(bp, drv->slices) <= 0) - goto done; - /* * software write protect check */ @@ -252,22 +207,6 @@ id_intr(struct buf *bp) biodone(bp); } -static void -id_drvinit(void) -{ - static int devsw_installed = 0; - - if (devsw_installed) - return; /* XXX is this needed? */ - - cdevsw_add(&id_cdevsw); - stolen_cdevsw = id_cdevsw; - stolen_cdevsw.d_maj = WD_CDEV_MAJOR; - stolen_cdevsw.d_bmaj = WD_BDEV_MAJOR; - cdevsw_add(&stolen_cdevsw); - devsw_installed = 1; -} - static int idprobe(device_t dev) { @@ -282,9 +221,9 @@ idattach(device_t dev) struct ida_drive_info dinfo; struct id_softc *drv; device_t parent; + dev_t dsk; int error; - id_drvinit(); drv = (struct id_softc *)device_get_softc(dev); parent = device_get_parent(dev); drv->controller = (struct ida_softc *)device_get_softc(parent); @@ -315,7 +254,27 @@ idattach(device_t dev) DEVSTAT_TYPE_STORARRAY| DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_ARRAY); + dsk = disk_create(drv->unit, &drv->disk, 0, + &id_cdevsw, &iddisk_cdevsw); + + dsk->si_drv1 = drv; + dsk->si_iosize_max = 256 * drv->secsize; /* XXX guess? */ + disks_registered++; + + return (0); +} + +static int +iddetach(device_t dev) +{ + struct id_softc *drv; + + drv = (struct id_softc *)device_get_softc(dev); + devstat_remove_entry(&drv->stats); + + if (--disks_registered == 0) + cdevsw_remove(&iddisk_cdevsw); return (0); } -DRIVER_MODULE(id, ida, id_driver, id_devclass, 0, 0); +DRIVER_MODULE(idad, ida, id_driver, id_devclass, 0, 0); diff --git a/sys/dev/ida/ida_eisa.c b/sys/dev/ida/ida_eisa.c new file mode 100644 index 0000000..4ecba8d --- /dev/null +++ b/sys/dev/ida/ida_eisa.c @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2000 Jonathan Lemon + * Copyright (c) 1999 by Matthew N. Dodd + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * 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 +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#define IDA_EISA_IOPORT_START 0x0c88 +#define IDA_EISA_IOPORT_LEN 0x0017 + +#define IDA_EISA_IRQ_REG 0x0cc0 +#define IDA_EISA_IRQ_MASK 0xf0 +#define IDA_EISA_IRQ_15 0x80 +#define IDA_EISA_IRQ_14 0x40 +#define IDA_EISA_IRQ_11 0x10 +#define IDA_EISA_IRQ_10 0x20 + +static int +ida_v1_fifo_full(struct ida_softc *ida) +{ + u_int8_t status; + + status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL); + return ((status & EISA_CHANNEL_CLEAR) == 0); +} + +static void +ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb) +{ + u_int16_t size; + + /* + * On these cards, this location is actually for control flags. + * Set them to zero and pass in structure size via an I/O port. + */ + size = qcb->hwqcb->hdr.size << 2; + qcb->hwqcb->hdr.size = 0; + + ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR); + ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr); + ida_outw(ida, R_EISA_LIST_LEN, size); + ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR); +} + +static bus_addr_t +ida_v1_done(struct ida_softc *ida) +{ + struct ida_hardware_qcb *hwqcb; + bus_addr_t completed; + u_int8_t status; + + if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0) + return (0); + + ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY); + completed = ida_inl(ida, R_EISA_COMPLETE_ADDR); + status = ida_inb(ida, R_EISA_LIST_STATUS); + ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR); + + if (completed != 0) { + hwqcb = (struct ida_hardware_qcb *) + ((bus_addr_t)ida->hwqcbs + + ((completed & ~3) - ida->hwqcb_busaddr)); + hwqcb->req.error = status; + } + + return (completed); +} + +static int +ida_v1_int_pending(struct ida_softc *ida) +{ + return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY); +} + +static void +ida_v1_int_enable(struct ida_softc *ida, int enable) +{ + if (enable) { + ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR); + ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY); + ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE); + ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE); + } else { + ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE); + } +} + +static int +ida_v2_fifo_full(struct ida_softc *ida) +{ + return (ida_inl(ida, R_CMD_FIFO) == 0); +} + +static void +ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb) +{ + ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr); +} + +static bus_addr_t +ida_v2_done(struct ida_softc *ida) +{ + return (ida_inl(ida, R_DONE_FIFO)); +} + +static int +ida_v2_int_pending(struct ida_softc *ida) +{ + return (ida_inl(ida, R_INT_PENDING)); +} + +static void +ida_v2_int_enable(struct ida_softc *ida, int enable) +{ + ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE); +} + +static struct ida_access ida_v1_access = { + ida_v1_fifo_full, + ida_v1_submit, + ida_v1_done, + ida_v1_int_pending, + ida_v1_int_enable, +}; + +static struct ida_access ida_v2_access = { + ida_v2_fifo_full, + ida_v2_submit, + ida_v2_done, + ida_v2_int_pending, + ida_v2_int_enable, +}; + +static struct ida_board board_id[] = { + { 0x0e114001, "Compaq IDA controller", &ida_v1_access }, + { 0x0e114002, "Compaq IDA-2 controller", &ida_v1_access }, + { 0x0e114010, "Compaq IAES controller", &ida_v1_access }, + { 0x0e114020, "Compaq SMART array controller", &ida_v1_access }, + { 0x0e114030, "Compaq SMART-2/E array controller", &ida_v2_access }, + + { 0, "", 0 } +}; + +static struct ida_board *ida_eisa_match(eisa_id_t); +static int ida_eisa_probe(device_t); +static int ida_eisa_attach(device_t); + +static device_method_t ida_eisa_methods[] = { + DEVMETHOD(device_probe, ida_eisa_probe), + DEVMETHOD(device_attach, ida_eisa_attach), + DEVMETHOD(device_detach, ida_detach), + + { 0, 0 } +}; + +static driver_t ida_eisa_driver = { + "ida", + ida_eisa_methods, + sizeof(struct ida_softc) +}; + +static devclass_t ida_devclass; + +static struct ida_board * +ida_eisa_match(eisa_id_t id) +{ + int i; + + for (i = 0; board_id[i].board; i++) + if (board_id[i].board == id) + return (&board_id[i]); + return (NULL); +} + +static int +ida_eisa_probe(device_t dev) +{ + struct ida_board *board; + u_int32_t io_base; + u_int irq = 0; + + board = ida_eisa_match(eisa_get_id(dev)); + if (board == NULL) + return (ENXIO); + device_set_desc(dev, board->desc); + + io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE); + + switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) { + case IDA_EISA_IRQ_15: + irq = 15; + break; + case IDA_EISA_IRQ_14: + irq = 14; + break; + case IDA_EISA_IRQ_11: + irq = 11; + break; + case IDA_EISA_IRQ_10: + irq = 10; + break; + default: + device_printf(dev, "slot %d, illegal irq setting.\n", + eisa_get_slot(dev)); + return (ENXIO); + } + + eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START), + IDA_EISA_IOPORT_LEN, RESVADDR_NONE); + + eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */ + + return (0); +} + +static int +ida_eisa_attach(device_t dev) +{ + struct ida_softc *ida; + struct ida_board *board; + int error; + int rid; + + ida = device_get_softc(dev); + ida->dev = dev; + + board = ida_eisa_match(eisa_get_id(dev)); + ida->cmd = *board->accessor; + + ida->regs_res_type = SYS_RES_IOPORT; + ida->regs_res_id = 0; + ida->regs = bus_alloc_resource(dev, ida->regs_res_type, + &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE); + if (ida->regs == NULL) { + device_printf(dev, "can't allocate register resources\n"); + return (ENOMEM); + } + + error = bus_dma_tag_create( + /* parent */ NULL, + /* alignment */ 0, + /* boundary */ 0, + /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, + /* highaddr */ BUS_SPACE_MAXADDR, + /* filter */ NULL, + /* filterarg */ NULL, + /* maxsize */ MAXBSIZE, + /* nsegments */ IDA_NSEG, + /* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT, + /* flags */ BUS_DMA_ALLOCNOW, + &ida->parent_dmat); + + if (error != 0) { + device_printf(dev, "can't allocate DMA tag\n"); + ida_free(ida); + return (ENOMEM); + } + + rid = 0; + ida->irq_res_type = SYS_RES_IRQ; + ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid, + 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE); + if (ida->irq == NULL) { + ida_free(ida); + return (ENOMEM); + } + + error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO, + ida_intr, ida, &ida->ih); + if (error) { + device_printf(dev, "can't setup interrupt\n"); + ida_free(ida); + return (ENOMEM); + } + + error = ida_init(ida); + if (error) { + ida_free(ida); + return (error); + } + + ida_attach(ida); + ida->flags = IDA_ATTACHED; + + return (0); +} + +DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0); diff --git a/sys/dev/ida/ida_pci.c b/sys/dev/ida/ida_pci.c index 4e97181..d43a157 100644 --- a/sys/dev/ida/ida_pci.c +++ b/sys/dev/ida/ida_pci.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999 Jonathan Lemon + * Copyright (c) 1999,2000 Jonathan Lemon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,7 @@ #include #include +#include #define IDA_PCI_MAX_DMA_ADDR 0xFFFFFFFF #define IDA_PCI_MAX_DMA_COUNT 0xFFFFFFFF @@ -53,17 +55,101 @@ #define IDA_DEVICEID_SMART 0xAE100E11 -static struct { - u_long board; - char *desc; -} board_id[] = { - { 0x4030, "Compaq SMART-2/P array controller" }, - { 0x4031, "Compaq SMART-2SL array controller" }, - { 0x4032, "Compaq Smart Array 3200 controller" }, - { 0x4033, "Compaq Smart Array 3100ES controller" }, - { 0x4034, "Compaq Smart Array 221 controller" }, - - { 0, "" }, +static int +ida_v3_fifo_full(struct ida_softc *ida) +{ + return (ida_inl(ida, R_CMD_FIFO) == 0); +} + +static void +ida_v3_submit(struct ida_softc *ida, struct ida_qcb *qcb) +{ + ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr); +} + +static bus_addr_t +ida_v3_done(struct ida_softc *ida) +{ + return (ida_inl(ida, R_DONE_FIFO)); +} + +static int +ida_v3_int_pending(struct ida_softc *ida) +{ + return (ida_inl(ida, R_INT_PENDING)); +} + +static void +ida_v3_int_enable(struct ida_softc *ida, int enable) +{ + ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE); +} + +static int +ida_v4_fifo_full(struct ida_softc *ida) +{ + return (ida_inl(ida, R_42XX_REQUEST) != 0); +} + +static void +ida_v4_submit(struct ida_softc *ida, struct ida_qcb *qcb) +{ + ida_outl(ida, R_42XX_REQUEST, qcb->hwqcb_busaddr); +} + +static bus_addr_t +ida_v4_done(struct ida_softc *ida) +{ + bus_addr_t completed; + + completed = ida_inl(ida, R_42XX_REPLY); + if (completed == -1) + return (0); /* fifo is empty */ + ida_outl(ida, R_42XX_REPLY, 0); /* confirm read */ + return (completed); +} + +static int +ida_v4_int_pending(struct ida_softc *ida) +{ + return (ida_inl(ida, R_42XX_STATUS) & STATUS_42XX_INT_PENDING); +} + +static void +ida_v4_int_enable(struct ida_softc *ida, int enable) +{ + ida_outl(ida, R_42XX_INT_MASK, + enable ? INT_ENABLE_42XX : INT_DISABLE_42XX); +} + +static struct ida_access ida_v3_access = { + ida_v3_fifo_full, + ida_v3_submit, + ida_v3_done, + ida_v3_int_pending, + ida_v3_int_enable, +}; + +static struct ida_access ida_v4_access = { + ida_v4_fifo_full, + ida_v4_submit, + ida_v4_done, + ida_v4_int_pending, + ida_v4_int_enable, +}; + +static struct ida_board board_id[] = { + { 0x4030, "Compaq SMART-2/P array controller", &ida_v3_access }, + { 0x4031, "Compaq SMART-2SL array controller", &ida_v3_access }, + { 0x4032, "Compaq Smart Array 3200 controller", &ida_v3_access }, + { 0x4033, "Compaq Smart Array 3100ES controller", &ida_v3_access }, + { 0x4034, "Compaq Smart Array 221 controller", &ida_v3_access }, + + { 0x4040, "Compaq Integrated Array controller", &ida_v4_access }, + { 0x4050, "Compaq Smart Array 4200 controller", &ida_v4_access }, + { 0x4051, "Compaq Smart Array 4250ES controller", &ida_v4_access }, + + { 0, "", 0 }, }; static int ida_pci_probe(device_t dev); @@ -72,6 +158,7 @@ static int ida_pci_attach(device_t dev); static device_method_t ida_pci_methods[] = { DEVMETHOD(device_probe, ida_pci_probe), DEVMETHOD(device_attach, ida_pci_attach), + DEVMETHOD(device_detach, ida_detach), DEVMETHOD(bus_print_child, bus_generic_print_child), @@ -86,26 +173,28 @@ static driver_t ida_pci_driver = { static devclass_t ida_devclass; +static struct ida_board * +ida_pci_match(u_int32_t id) +{ + int i; + + for (i = 0; board_id[i].board; i++) + if (board_id[i].board == id) + return (&board_id[i]); + return (NULL); +} + static int ida_pci_probe(device_t dev) { - u_long board; - int i; + struct ida_board *board; if (pci_get_devid(dev) == IDA_DEVICEID_SMART) { - board = pci_get_subdevice(dev); - for (i = 0; board_id[i].board; i++) { - if (board_id[i].board == board) { - device_set_desc(dev, board_id[i].desc); - return (0); - } + board = ida_pci_match(pci_get_subdevice(dev)); + if (board != NULL) { + device_set_desc(dev, board->desc); + return (0); } - /* - * It's an unknown Compaq SMART device, but assume we - * can support it. - */ - device_set_desc(dev, "Unknown Compaq Smart Array controller"); - return (0); } return (ENXIO); } @@ -113,6 +202,7 @@ ida_pci_probe(device_t dev) static int ida_pci_attach(device_t dev) { + struct ida_board *board; struct ida_softc *ida; u_int command; int error, rid; @@ -120,11 +210,6 @@ ida_pci_attach(device_t dev) command = pci_read_config(dev, PCIR_COMMAND, 1); /* - * for multiple card types, need to re-determine which type is - * being attached here - */ - - /* * it appears that this board only does MEMIO access. */ if ((command & PCIM_CMD_MEMEN) == 0) { @@ -135,6 +220,9 @@ ida_pci_attach(device_t dev) ida = (struct ida_softc *)device_get_softc(dev); ida->dev = dev; + board = ida_pci_match(pci_get_subdevice(dev)); + ida->cmd = *board->accessor; + ida->regs_res_type = SYS_RES_MEMORY; ida->regs_res_id = IDA_PCI_MEMADDR; ida->regs = bus_alloc_resource(dev, ida->regs_res_type, diff --git a/sys/dev/ida/idareg.h b/sys/dev/ida/idareg.h index 506c495..8a28c15 100644 --- a/sys/dev/ida/idareg.h +++ b/sys/dev/ida/idareg.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999 Jonathan Lemon + * Copyright (c) 1999,2000 Jonathan Lemon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,25 @@ */ /* - * board register offsets + * defines for older EISA controllers (IDA, IDA-2, IAES, SMART) + */ +#define R_EISA_INT_MASK 0xC89 +#define R_EISA_LOCAL_MASK 0xC8C +#define R_EISA_LOCAL_DOORBELL 0xC8D +#define R_EISA_SYSTEM_MASK 0xC8E +#define R_EISA_SYSTEM_DOORBELL 0xC8F +#define R_EISA_LIST_ADDR 0xC90 +#define R_EISA_LIST_LEN 0xC94 +#define R_EISA_TAG 0xC97 +#define R_EISA_COMPLETE_ADDR 0xC98 +#define R_EISA_LIST_STATUS 0xC9E + +#define EISA_CHANNEL_BUSY 0x01 +#define EISA_CHANNEL_CLEAR 0x02 + + +/* + * board register offsets for SMART-2 controllers */ #define R_CMD_FIFO 0x04 #define R_DONE_FIFO 0x08 @@ -40,11 +58,28 @@ #define R_INT_PENDING 0x14 /* - * interrupt mask values + * interrupt mask values for SMART series */ #define INT_DISABLE 0x00 #define INT_ENABLE 0x01 + +/* + * board offsets for the 42xx series + */ +#define R_42XX_STATUS 0x30 +#define R_42XX_INT_MASK 0x34 +#define R_42XX_REQUEST 0x40 +#define R_42XX_REPLY 0x44 + +/* + * interrupt values for 42xx series + */ +#define INT_ENABLE_42XX 0x00 +#define INT_DISABLE_42XX 0x08 +#define STATUS_42XX_INT_PENDING 0x08 + + /* * return status codes */ diff --git a/sys/dev/ida/idavar.h b/sys/dev/ida/idavar.h index 75401b4..c2614ee 100644 --- a/sys/dev/ida/idavar.h +++ b/sys/dev/ida/idavar.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1999 Jonathan Lemon + * Copyright (c) 1999,2000 Jonathan Lemon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,6 +33,20 @@ #ifndef _IDAVAR_H #define _IDAVAR_H +#define ida_inb(ida, port) \ + bus_space_read_1((ida)->tag, (ida)->bsh, port) +#define ida_inw(ida, port) \ + bus_space_read_2((ida)->tag, (ida)->bsh, port) +#define ida_inl(ida, port) \ + bus_space_read_4((ida)->tag, (ida)->bsh, port) + +#define ida_outb(ida, port, val) \ + bus_space_write_1((ida)->tag, (ida)->bsh, port, val) +#define ida_outw(ida, port, val) \ + bus_space_write_2((ida)->tag, (ida)->bsh, port, val) +#define ida_outl(ida, port, val) \ + bus_space_write_4((ida)->tag, (ida)->bsh, port, val) + struct ida_hdr { u_int8_t drive; /* logical drive */ u_int8_t priority; /* block priority */ @@ -88,9 +102,20 @@ struct ida_qcb { SLIST_ENTRY(ida_qcb) sle; } link; bus_dmamap_t dmamap; + bus_addr_t hwqcb_busaddr; struct buf *buf; /* buf associated with qcb */ }; +struct ida_softc; + +struct ida_access { + int (*fifo_full)(struct ida_softc *); + void (*submit)(struct ida_softc *, struct ida_qcb *); + bus_addr_t (*done)(struct ida_softc *); + int (*int_pending)(struct ida_softc *); + void (*int_enable)(struct ida_softc *, int); +}; + /* * flags for the controller */ @@ -130,6 +155,8 @@ struct ida_softc { SLIST_HEAD(, ida_qcb) free_qcbs; STAILQ_HEAD(, ida_qcb) qcb_queue; struct buf_queue_head buf_queue; + + struct ida_access cmd; }; /* @@ -140,7 +167,7 @@ struct ida_softc { struct id_softc { device_t dev; struct ida_softc *controller; - struct diskslices *slices; + struct disk disk; struct devstat stats; int unit; int cylinders; @@ -151,6 +178,13 @@ struct id_softc { int flags; }; +struct ida_board { + u_int32_t board; + char *desc; + struct ida_access *accessor; +}; + +extern int ida_detach(device_t dev); extern struct ida_softc *ida_alloc(device_t dev, struct resource *regs, int regs_type, int regs_id, bus_dma_tag_t parent_dmat); extern void ida_free(struct ida_softc *ida); -- cgit v1.1