This is a driver for the AMI MegaRAID family of controllers. It all of
the AMI PCI controllers using the 8LD firmware interface (40LD firmware will be supported as soon as I have hardware to test with). These controllers are rebadged by Dell as the PERC, as well as by HP and possibly other vendors.
This commit is contained in:
parent
1ac4b82b11
commit
d5a51e03e7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=51974
1498
sys/dev/amr/amr.c
Normal file
1498
sys/dev/amr/amr.c
Normal file
File diff suppressed because it is too large
Load Diff
299
sys/dev/amr/amr_disk.c
Normal file
299
sys/dev/amr/amr_disk.c
Normal file
@ -0,0 +1,299 @@
|
||||
/*-
|
||||
* Copyright (c) 1999 Jonathan Lemon
|
||||
* Copyright (c) 1999 Michael Smith
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Disk driver for AMI MegaRaid controllers
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kernel.h>
|
||||
|
||||
#include <sys/buf.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/amr/amrio.h>
|
||||
#include <dev/amr/amrreg.h>
|
||||
#include <dev/amr/amrvar.h>
|
||||
|
||||
#if 0
|
||||
#define debug(fmt, args...) printf("%s: " fmt "\n", __FUNCTION__ , ##args)
|
||||
#else
|
||||
#define debug(fmt, args...)
|
||||
#endif
|
||||
|
||||
/* prototypes */
|
||||
static int amrd_probe(device_t dev);
|
||||
static int amrd_attach(device_t dev);
|
||||
static int amrd_detach(device_t dev);
|
||||
|
||||
static d_open_t amrd_open;
|
||||
static d_close_t amrd_close;
|
||||
static d_strategy_t amrd_strategy;
|
||||
static d_ioctl_t amrd_ioctl;
|
||||
|
||||
#define AMRD_BDEV_MAJOR 35
|
||||
#define AMRD_CDEV_MAJOR 133
|
||||
|
||||
static struct cdevsw amrd_cdevsw = {
|
||||
/* open */ amrd_open,
|
||||
/* close */ amrd_close,
|
||||
/* read */ physread,
|
||||
/* write */ physwrite,
|
||||
/* ioctl */ amrd_ioctl,
|
||||
/* poll */ nopoll,
|
||||
/* mmap */ nommap,
|
||||
/* strategy */ amrd_strategy,
|
||||
/* name */ "amrd",
|
||||
/* maj */ AMRD_CDEV_MAJOR,
|
||||
/* dump */ nodump,
|
||||
/* psize */ nopsize,
|
||||
/* flags */ D_DISK,
|
||||
/* bmaj */ AMRD_BDEV_MAJOR
|
||||
};
|
||||
|
||||
static devclass_t amrd_devclass;
|
||||
static struct cdevsw amrddisk_cdevsw;
|
||||
static int disks_registered = 0;
|
||||
|
||||
static device_method_t amrd_methods[] = {
|
||||
DEVMETHOD(device_probe, amrd_probe),
|
||||
DEVMETHOD(device_attach, amrd_attach),
|
||||
DEVMETHOD(device_detach, amrd_detach),
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static driver_t amrd_driver = {
|
||||
"amrd",
|
||||
amrd_methods,
|
||||
sizeof(struct amrd_softc)
|
||||
};
|
||||
|
||||
DRIVER_MODULE(amrd, amr, amrd_driver, amrd_devclass, 0, 0);
|
||||
|
||||
static __inline struct amrd_softc *
|
||||
amrd_getsoftc(dev_t dev)
|
||||
{
|
||||
int unit;
|
||||
|
||||
unit = dkunit(dev);
|
||||
return ((struct amrd_softc *)devclass_get_softc(amrd_devclass, unit));
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_open(dev_t dev, int flags, int fmt, struct proc *p)
|
||||
{
|
||||
struct amrd_softc *sc = amrd_getsoftc(dev);
|
||||
struct disklabel *label;
|
||||
|
||||
debug("called");
|
||||
|
||||
if (sc == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
/* controller not active? */
|
||||
if (sc->amrd_controller->amr_state & AMR_STATE_SHUTDOWN)
|
||||
return(ENXIO);
|
||||
|
||||
label = &sc->amrd_disk.d_label;
|
||||
bzero(label, sizeof(*label));
|
||||
label->d_type = DTYPE_SCSI;
|
||||
label->d_secsize = AMR_BLKSIZE;
|
||||
label->d_nsectors = sc->amrd_drive->al_sectors;
|
||||
label->d_ntracks = sc->amrd_drive->al_heads;
|
||||
label->d_ncylinders = sc->amrd_drive->al_cylinders;
|
||||
label->d_secpercyl = sc->amrd_drive->al_sectors * sc->amrd_drive->al_heads;
|
||||
label->d_secperunit = sc->amrd_drive->al_size;
|
||||
|
||||
sc->amrd_flags |= AMRD_OPEN;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_close(dev_t dev, int flags, int fmt, struct proc *p)
|
||||
{
|
||||
struct amrd_softc *sc = amrd_getsoftc(dev);
|
||||
|
||||
debug("called");
|
||||
|
||||
if (sc == NULL)
|
||||
return (ENXIO);
|
||||
sc->amrd_flags &= ~AMRD_OPEN;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_ioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
|
||||
{
|
||||
struct amrd_softc *sc = amrd_getsoftc(dev);
|
||||
int error;
|
||||
|
||||
debug("called");
|
||||
|
||||
if (sc == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
if ((error = amr_submit_ioctl(sc->amrd_controller, sc->amrd_drive, cmd, addr, flag, p)) != ENOIOCTL) {
|
||||
debug("amr_submit_ioctl returned %d\n", error);
|
||||
return(error);
|
||||
}
|
||||
return (ENOTTY);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read/write routine for a buffer. Finds the proper unit, range checks
|
||||
* arguments, and schedules the transfer. Does not wait for the transfer
|
||||
* to complete. Multi-page transfers are supported. All I/O requests must
|
||||
* be a multiple of a sector in length.
|
||||
*/
|
||||
static void
|
||||
amrd_strategy(struct buf *bp)
|
||||
{
|
||||
struct amrd_softc *sc = amrd_getsoftc(bp->b_dev);
|
||||
int s;
|
||||
|
||||
debug("called");
|
||||
|
||||
/* bogus disk? */
|
||||
if (sc == NULL) {
|
||||
bp->b_error = EINVAL;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* XXX may only be temporarily offline - sleep? */
|
||||
if (sc->amrd_drive->ld_state == AMR_SYSD_OFFLINE) {
|
||||
bp->b_error = ENXIO;
|
||||
goto bad;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* do-nothing operation */
|
||||
if (bp->b_bcount == 0)
|
||||
goto done;
|
||||
|
||||
/* pass reference to us */
|
||||
bp->b_driver1 = sc;
|
||||
s = splbio();
|
||||
devstat_start_transaction(&sc->amrd_stats);
|
||||
amr_submit_buf(sc->amrd_controller, bp);
|
||||
splx(s);
|
||||
return;
|
||||
|
||||
bad:
|
||||
bp->b_flags |= B_ERROR;
|
||||
|
||||
done:
|
||||
/*
|
||||
* Correctly set the buf to indicate a completed transfer
|
||||
*/
|
||||
bp->b_resid = bp->b_bcount;
|
||||
biodone(bp);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
amrd_intr(void *data)
|
||||
{
|
||||
struct buf *bp = (struct buf *)data;
|
||||
struct amrd_softc *sc = (struct amrd_softc *)bp->b_driver1;
|
||||
|
||||
debug("called");
|
||||
|
||||
if (bp->b_flags & B_ERROR)
|
||||
bp->b_error = EIO;
|
||||
else
|
||||
bp->b_resid = 0;
|
||||
|
||||
devstat_end_transaction_buf(&sc->amrd_stats, bp);
|
||||
biodone(bp);
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_probe(device_t dev)
|
||||
{
|
||||
|
||||
debug("called");
|
||||
|
||||
device_set_desc(dev, "MegaRAID logical drive");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_attach(device_t dev)
|
||||
{
|
||||
struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev);
|
||||
device_t parent;
|
||||
|
||||
debug("called");
|
||||
|
||||
parent = device_get_parent(dev);
|
||||
sc->amrd_controller = (struct amr_softc *)device_get_softc(parent);
|
||||
sc->amrd_unit = device_get_unit(dev);
|
||||
sc->amrd_drive = device_get_ivars(dev);
|
||||
|
||||
device_printf(dev, "%uMB (%u sectors), state 0x%x properties 0x%x\n",
|
||||
sc->amrd_drive->al_size / ((1024 * 1024) / AMR_BLKSIZE),
|
||||
sc->amrd_drive->al_size, sc->amrd_drive->al_state, sc->amrd_drive->al_properties);
|
||||
|
||||
devstat_add_entry(&sc->amrd_stats, "amrd", sc->amrd_unit, AMR_BLKSIZE,
|
||||
DEVSTAT_NO_ORDERED_TAGS,
|
||||
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
|
||||
DEVSTAT_PRIORITY_DA);
|
||||
|
||||
disk_create(sc->amrd_unit, &sc->amrd_disk, 0, &amrd_cdevsw, &amrddisk_cdevsw);
|
||||
disks_registered++;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
amrd_detach(device_t dev)
|
||||
{
|
||||
struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev);
|
||||
|
||||
debug("called");
|
||||
|
||||
devstat_remove_entry(&sc->amrd_stats);
|
||||
|
||||
/* hack to handle lack of destroy_disk() */
|
||||
if (--disks_registered == 0)
|
||||
cdevsw_remove(&amrddisk_cdevsw);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
208
sys/dev/amr/amr_pci.c
Normal file
208
sys/dev/amr/amr_pci.c
Normal file
@ -0,0 +1,208 @@
|
||||
/*-
|
||||
* Copyright (c) 1999 Michael Smith
|
||||
* 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/malloc.h>
|
||||
#include <sys/kernel.h>
|
||||
|
||||
#include <sys/bus.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/devicestat.h>
|
||||
#include <sys/disk.h>
|
||||
|
||||
#include <machine/bus_memio.h>
|
||||
#include <machine/bus_pio.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include <pci/pcireg.h>
|
||||
#include <pci/pcivar.h>
|
||||
|
||||
#include <dev/amr/amrio.h>
|
||||
#include <dev/amr/amrreg.h>
|
||||
#include <dev/amr/amrvar.h>
|
||||
|
||||
#if 0
|
||||
#define debug(fmt, args...) printf("%s: " fmt "\n", __FUNCTION__ , ##args)
|
||||
#else
|
||||
#define debug(fmt, args...)
|
||||
#endif
|
||||
|
||||
static int amr_pci_probe(device_t dev);
|
||||
static int amr_pci_attach(device_t dev);
|
||||
|
||||
static device_method_t amr_methods[] = {
|
||||
/* Device interface */
|
||||
DEVMETHOD(device_probe, amr_pci_probe),
|
||||
DEVMETHOD(device_attach, amr_pci_attach),
|
||||
DEVMETHOD(device_detach, amr_detach),
|
||||
DEVMETHOD(device_shutdown, amr_shutdown),
|
||||
DEVMETHOD(device_suspend, amr_suspend),
|
||||
DEVMETHOD(device_resume, amr_resume),
|
||||
|
||||
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
||||
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static driver_t amr_pci_driver = {
|
||||
"amr",
|
||||
amr_methods,
|
||||
sizeof(struct amr_softc)
|
||||
};
|
||||
|
||||
DRIVER_MODULE(amr, pci, amr_pci_driver, amr_devclass, 0, 0);
|
||||
|
||||
static struct
|
||||
{
|
||||
int vendor;
|
||||
int device;
|
||||
int flag;
|
||||
#define PROBE_SIGNATURE (1<<0)
|
||||
} amr_device_ids[] = {
|
||||
{0x101e, 0x9010, 0},
|
||||
{0x101e, 0x9060, 0},
|
||||
{0x8086, 0x1960, PROBE_SIGNATURE}, /* generic i960RD, check signature */
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
static int
|
||||
amr_pci_probe(device_t dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
debug("called");
|
||||
|
||||
for (i = 0; amr_device_ids[i].vendor != 0; i++) {
|
||||
if ((pci_get_vendor(dev) == amr_device_ids[i].vendor) &&
|
||||
(pci_get_device(dev) == amr_device_ids[i].device)) {
|
||||
|
||||
/* do we need to test for a signature? */
|
||||
if ((amr_device_ids[i].flag & PROBE_SIGNATURE) &&
|
||||
(pci_read_config(dev, AMR_CFG_SIG, 2) != AMR_SIGNATURE))
|
||||
continue;
|
||||
device_set_desc(dev, "AMI MegaRAID");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
return(ENXIO);
|
||||
}
|
||||
|
||||
static int
|
||||
amr_pci_attach(device_t dev)
|
||||
{
|
||||
struct amr_softc *sc;
|
||||
int rid, rtype, error;
|
||||
u_int32_t command;
|
||||
|
||||
debug("called");
|
||||
|
||||
/*
|
||||
* Initialise softc.
|
||||
*/
|
||||
sc = device_get_softc(dev);
|
||||
bzero(sc, sizeof(*sc));
|
||||
sc->amr_dev = dev;
|
||||
|
||||
/*
|
||||
* Determine board type..
|
||||
*/
|
||||
command = pci_read_config(dev, PCIR_COMMAND, 1);
|
||||
if ((pci_get_vendor(dev) == 0x8086) && (pci_get_device(dev) == 0x1960)) {
|
||||
sc->amr_type = AMR_TYPE_QUARTZ;
|
||||
|
||||
/*
|
||||
* Make sure we are going to be able to talk to this board.
|
||||
*/
|
||||
if ((command & PCIM_CMD_MEMEN) == 0) {
|
||||
device_printf(dev, "memory window not available\n");
|
||||
return(ENXIO);
|
||||
}
|
||||
|
||||
} else {
|
||||
sc->amr_type = AMR_TYPE_STD;
|
||||
|
||||
/*
|
||||
* Make sure we are going to be able to talk to this board.
|
||||
*/
|
||||
if ((command & PCIM_CMD_PORTEN) == 0) {
|
||||
device_printf(dev, "I/O window not available\n");
|
||||
return(ENXIO);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate the PCI register window.
|
||||
*/
|
||||
rid = AMR_CFG_BASE;
|
||||
rtype = (sc->amr_type == AMR_TYPE_QUARTZ) ? SYS_RES_MEMORY : SYS_RES_IOPORT;
|
||||
sc->amr_reg = bus_alloc_resource(dev, rtype, &rid, 0, ~0, 1, RF_ACTIVE);
|
||||
if (sc->amr_reg == NULL) {
|
||||
device_printf(sc->amr_dev, "couldn't allocate register window\n");
|
||||
amr_free(sc);
|
||||
return(ENXIO);
|
||||
}
|
||||
sc->amr_btag = rman_get_bustag(sc->amr_reg);
|
||||
sc->amr_bhandle = rman_get_bushandle(sc->amr_reg);
|
||||
|
||||
/*
|
||||
* Allocate the parent bus DMA tag appropriate for PCI.
|
||||
*/
|
||||
error = bus_dma_tag_create(NULL, /* parent */
|
||||
1, 0, /* alignment, boundary */
|
||||
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
||||
BUS_SPACE_MAXADDR, /* highaddr */
|
||||
NULL, NULL, /* filter, filterarg */
|
||||
MAXBSIZE, AMR_NSEG, /* maxsize, nsegments */
|
||||
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
|
||||
BUS_DMA_ALLOCNOW, /* flags */
|
||||
&sc->amr_parent_dmat);
|
||||
if (error != 0) {
|
||||
device_printf(dev, "can't allocate parent DMA tag\n");
|
||||
amr_free(sc);
|
||||
return(ENOMEM);
|
||||
}
|
||||
|
||||
/*
|
||||
* Do bus-independant initialisation.
|
||||
*/
|
||||
error = amr_attach(sc);
|
||||
if (error != 0) {
|
||||
amr_free(sc);
|
||||
return(error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start the controller.
|
||||
*/
|
||||
amr_startup(sc);
|
||||
return(0);
|
||||
}
|
28
sys/dev/amr/amrio.h
Normal file
28
sys/dev/amr/amrio.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*-
|
||||
* Copyright (c) 1999 Michael Smith
|
||||
* 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$
|
||||
*/
|
||||
|
199
sys/dev/amr/amrreg.h
Normal file
199
sys/dev/amr/amrreg.h
Normal file
@ -0,0 +1,199 @@
|
||||
/*-
|
||||
* Copyright (c) 1999 Michael Smith
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Mailbox commands
|
||||
*/
|
||||
#define AMR_CMD_LREAD 0x01
|
||||
#define AMR_CMD_LWRITE 0x02
|
||||
#define AMR_CMD_ENQUIRY 0x05
|
||||
#define AMR_CMD_FLUSH 0x0a
|
||||
#define AMR_CMD_CONFIG 0xa1
|
||||
#define AMR_CONFIG_PRODINFO 0x0e
|
||||
#define AMR_CONFIG_ENQ3 0x0f
|
||||
#define AMR_CONFIG_ENQ3_SOLICITED_NOTIFY 0x01
|
||||
#define AMR_CONFIG_ENQ3_SOLICITED_FULL 0x02
|
||||
#define AMR_CONFIG_ENQ3_UNSOLICITED 0x03
|
||||
|
||||
/*
|
||||
* Command results
|
||||
*/
|
||||
#define AMR_STATUS_SUCCESS 0x00
|
||||
#define AMR_STATUS_ABORTED 0x02
|
||||
#define AMR_STATUS_FAILED 0x80
|
||||
|
||||
/*
|
||||
* Quartz doorbell registers
|
||||
*/
|
||||
#define AMR_QIDB 0x20
|
||||
#define AMR_QODB 0x2c
|
||||
#define AMR_QIDB_SUBMIT 0x00000001 /* mailbox ready for work */
|
||||
#define AMR_QIDB_ACK 0x00000002 /* mailbox done */
|
||||
#define AMR_QODB_READY 0x10001234 /* work ready to be processed */
|
||||
|
||||
/*
|
||||
* Standard I/O registers
|
||||
*/
|
||||
#define AMR_SCMD 0x10 /* command/ack register (write) */
|
||||
#define AMR_SMBOX_BUSY 0x10 /* mailbox status (read) */
|
||||
#define AMR_STOGGLE 0x11 /* interrupt enable bit here */
|
||||
#define AMR_SMBOX_0 0x14 /* mailbox physical address low byte */
|
||||
#define AMR_SMBOX_1 0x15
|
||||
#define AMR_SMBOX_2 0x16
|
||||
#define AMR_SMBOX_3 0x17 /* high byte */
|
||||
#define AMR_SMBOX_ENABLE 0x18 /* atomic mailbox address enable */
|
||||
#define AMR_SINTR 0x1a /* interrupt status */
|
||||
|
||||
/*
|
||||
* Standard I/O magic numbers
|
||||
*/
|
||||
#define AMR_SCMD_POST 0x10 /* -> SCMD to initiate action on mailbox */
|
||||
#define AMR_SCMD_ACKINTR 0x08 /* -> SCMD to ack mailbox retrieved */
|
||||
#define AMR_STOGL_IENABLE 0xc0 /* in STOGGLE */
|
||||
#define AMR_SINTR_VALID 0x40 /* in SINTR */
|
||||
#define AMR_SMBOX_BUSYFLAG 0x10 /* in SMBOX_BUSY */
|
||||
#define AMR_SMBOX_ADDR 0x00 /* -> SMBOX_ENABLE */
|
||||
|
||||
/*
|
||||
* Old Enquiry results
|
||||
*/
|
||||
#define AMR_8LD_MAXDRIVES 8
|
||||
#define AMR_8LD_MAXCHAN 5
|
||||
#define AMR_8LD_MAXTARG 15
|
||||
#define AMR_8LD_MAXPHYSDRIVES (AMR_8LD_MAXCHAN * AMR_8LD_MAXTARG)
|
||||
|
||||
struct amr_adapter_info
|
||||
{
|
||||
u_int8_t aa_maxio;
|
||||
u_int8_t aa_rebuild_rate;
|
||||
u_int8_t aa_maxtargchan;
|
||||
u_int8_t aa_channels;
|
||||
u_int8_t aa_firmware[4];
|
||||
u_int16_t aa_flashage;
|
||||
u_int8_t aa_chipsetvalue;
|
||||
u_int8_t aa_memorysize;
|
||||
u_int8_t aa_cacheflush;
|
||||
u_int8_t aa_bios[4];
|
||||
u_int8_t res1[7];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_logdrive_info
|
||||
{
|
||||
u_int8_t al_numdrives;
|
||||
u_int8_t res1[3];
|
||||
u_int32_t al_size[AMR_8LD_MAXDRIVES];
|
||||
u_int8_t al_properties[AMR_8LD_MAXDRIVES];
|
||||
u_int8_t al_state[AMR_8LD_MAXDRIVES];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_physdrive_info
|
||||
{
|
||||
u_int8_t ap_state[AMR_8LD_MAXPHYSDRIVES];
|
||||
u_int8_t res1;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_enquiry
|
||||
{
|
||||
struct amr_adapter_info ae_adapter;
|
||||
struct amr_logdrive_info ae_ldrv;
|
||||
struct amr_physdrive_info ae_pdrv;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_prodinfo
|
||||
{
|
||||
u_int32_t ap_size; /* current size in bytes (not including resvd) */
|
||||
u_int32_t ap_configsig; /* default is 0x00282008, indicating 0x28 maximum
|
||||
* logical drives, 0x20 maximum stripes and 0x08
|
||||
* maximum spans */
|
||||
u_int8_t ap_firmware[16]; /* printable identifiers */
|
||||
u_int8_t ap_bios[16];
|
||||
u_int8_t ap_product[80];
|
||||
u_int8_t ap_maxio; /* maximum number of concurrent commands supported */
|
||||
u_int8_t ap_nschan; /* number of SCSI channels present */
|
||||
u_int8_t ap_fcloops; /* number of fibre loops present */
|
||||
u_int8_t ap_memtype; /* memory type */
|
||||
u_int32_t ap_signature;
|
||||
u_int16_t ap_memsize; /* onboard memory in MB */
|
||||
u_int16_t ap_subsystem; /* subsystem identifier */
|
||||
u_int16_t ap_subvendor; /* subsystem vendor ID */
|
||||
u_int8_t ap_numnotifyctr; /* number of notify counters */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define AMR_MBOX_CMDSIZE 0x10 /* portion worth copying for controller */
|
||||
|
||||
struct amr_mailbox
|
||||
{
|
||||
u_int8_t mb_command;
|
||||
u_int8_t mb_ident;
|
||||
u_int16_t mb_blkcount;
|
||||
u_int32_t mb_lba;
|
||||
u_int32_t mb_physaddr;
|
||||
u_int8_t mb_drive;
|
||||
u_int8_t mb_nsgelem;
|
||||
u_int8_t res1;
|
||||
u_int8_t mb_busy;
|
||||
u_int8_t mb_nstatus;
|
||||
u_int8_t mb_status;
|
||||
u_int8_t mb_completed[46];
|
||||
u_int8_t mb_poll;
|
||||
u_int8_t mb_ack;
|
||||
u_int8_t res2[16];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_mailbox64
|
||||
{
|
||||
u_int32_t mb64_segment; /* for 64-bit controllers */
|
||||
struct amr_mailbox mb;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_mailbox_ioctl
|
||||
{
|
||||
u_int8_t mb_command;
|
||||
u_int8_t mb_ident;
|
||||
u_int8_t mb_channel;
|
||||
u_int8_t mb_param;
|
||||
u_int8_t res1[4];
|
||||
u_int32_t mb_physaddr;
|
||||
u_int8_t mb_drive;
|
||||
u_int8_t mb_nsgelem;
|
||||
u_int8_t res2;
|
||||
u_int8_t mb_busy;
|
||||
u_int8_t mb_nstatus;
|
||||
u_int8_t mb_completed[46];
|
||||
u_int8_t mb_poll;
|
||||
u_int8_t mb_ack;
|
||||
u_int8_t res3[16];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct amr_sgentry
|
||||
{
|
||||
u_int32_t sg_addr;
|
||||
u_int32_t sg_count;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
216
sys/dev/amr/amrvar.h
Normal file
216
sys/dev/amr/amrvar.h
Normal file
@ -0,0 +1,216 @@
|
||||
/*-
|
||||
* Copyright (c) 1999 Michael Smith
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/*
|
||||
* We could actually use all 17 segments, but using only 16 means that
|
||||
* each scatter/gather map is 128 bytes in size, and thus we don't have to worry about
|
||||
* maps crossing page boundaries.
|
||||
*/
|
||||
#define AMR_NSEG 16
|
||||
|
||||
#define AMR_CFG_BASE 0x10
|
||||
#define AMR_CFG_SIG 0xa0
|
||||
#define AMR_SIGNATURE 0x3344
|
||||
|
||||
#define AMR_MAXCMD 255 /* ident = 0 not allowed */
|
||||
#define AMR_MAXLD 40
|
||||
|
||||
#define AMR_BLKSIZE 512
|
||||
|
||||
struct amr_softc;
|
||||
|
||||
/*
|
||||
* Per-logical-drive datastructure
|
||||
*/
|
||||
struct amr_logdrive
|
||||
{
|
||||
u_int32_t al_size;
|
||||
int al_state;
|
||||
int al_properties;
|
||||
|
||||
/* synthetic geometry */
|
||||
int al_cylinders;
|
||||
int al_heads;
|
||||
int al_sectors;
|
||||
|
||||
/* driver */
|
||||
device_t al_disk;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Per-command control structure.
|
||||
*/
|
||||
struct amr_command
|
||||
{
|
||||
TAILQ_ENTRY(amr_command) ac_link;
|
||||
|
||||
struct amr_softc *ac_sc;
|
||||
u_int8_t ac_slot;
|
||||
int ac_status;
|
||||
#define AMR_STATUS_BUSY 0xffff
|
||||
#define AMR_STATUS_WEDGED 0xdead
|
||||
struct amr_mailbox ac_mailbox;
|
||||
u_int32_t ac_sgphys;
|
||||
int ac_nsgent;
|
||||
int ac_flags;
|
||||
#define AMR_CMD_DATAIN (1<<0)
|
||||
#define AMR_CMD_DATAOUT (1<<1)
|
||||
#define AMR_CMD_PRIORITY (1<<2)
|
||||
time_t ac_stamp;
|
||||
|
||||
void *ac_data;
|
||||
size_t ac_length;
|
||||
bus_dmamap_t ac_dmamap;
|
||||
u_int32_t ac_dataphys;
|
||||
|
||||
void (* ac_complete)(struct amr_command *ac);
|
||||
void *ac_private;
|
||||
};
|
||||
|
||||
struct amr_softc
|
||||
{
|
||||
/* bus attachments */
|
||||
device_t amr_dev;
|
||||
struct resource *amr_reg; /* control registers */
|
||||
bus_space_handle_t amr_bhandle;
|
||||
bus_space_tag_t amr_btag;
|
||||
bus_dma_tag_t amr_parent_dmat; /* parent DMA tag */
|
||||
bus_dma_tag_t amr_buffer_dmat; /* data buffer DMA tag */
|
||||
struct resource *amr_irq; /* interrupt */
|
||||
void *amr_intr;
|
||||
|
||||
/* mailbox */
|
||||
struct amr_mailbox *amr_mailbox;
|
||||
struct amr_mailbox64 *amr_mailbox64;
|
||||
u_int32_t amr_mailboxphys;
|
||||
bus_dma_tag_t amr_mailbox_dmat;
|
||||
bus_dmamap_t amr_mailbox_dmamap;
|
||||
|
||||
/* scatter/gather lists and their controller-visible mappings */
|
||||
struct amr_sgentry *amr_sgtable; /* s/g lists */
|
||||
u_int32_t amr_sgbusaddr; /* s/g table base address in bus space */
|
||||
bus_dma_tag_t amr_sg_dmat; /* s/g buffer DMA tag */
|
||||
bus_dmamap_t amr_sg_dmamap; /* map for s/g buffers */
|
||||
|
||||
/* controller limits and features */
|
||||
int amr_maxio; /* maximum number of I/O transactions */
|
||||
int amr_maxdrives; /* max number of logical drives */
|
||||
|
||||
/* connected logical drives */
|
||||
struct amr_logdrive amr_drive[AMR_MAXLD];
|
||||
|
||||
/* controller status */
|
||||
int amr_state;
|
||||
#define AMR_STATE_OPEN (1<<0)
|
||||
#define AMR_STATE_SUSPEND (1<<1)
|
||||
#define AMR_STATE_INTEN (1<<2)
|
||||
#define AMR_STATE_SHUTDOWN (1<<3)
|
||||
|
||||
/* per-controller queues */
|
||||
struct buf_queue_head amr_bufq; /* pending I/O */
|
||||
int amr_waitbufs;
|
||||
struct amr_command *amr_busycmd[AMR_MAXCMD];
|
||||
int amr_busycmdcount;
|
||||
TAILQ_HEAD(,amr_command) amr_donecmds;
|
||||
int amr_donecmdcount;
|
||||
TAILQ_HEAD(,amr_command) amr_freecmds;
|
||||
|
||||
/* controller type-specific support */
|
||||
int amr_type;
|
||||
#define AMR_TYPE_STD 0
|
||||
#define AMR_TYPE_QUARTZ 1
|
||||
void (* amr_submit_command)(struct amr_softc *sc);
|
||||
int (* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave);
|
||||
void (* amr_attach_mailbox)(struct amr_softc *sc);
|
||||
};
|
||||
|
||||
/*
|
||||
* I/O primitives
|
||||
*/
|
||||
/* Quartz */
|
||||
#define AMR_QPUT_IDB(sc, val) bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QIDB, val)
|
||||
#define AMR_QGET_IDB(sc) bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QIDB)
|
||||
#define AMR_QPUT_ODB(sc, val) bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QODB, val)
|
||||
#define AMR_QGET_ODB(sc) bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QODB)
|
||||
|
||||
/* Standard */
|
||||
#define AMR_SPUT_ISTAT(sc, val) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SINTR, val)
|
||||
#define AMR_SGET_ISTAT(sc) bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SINTR)
|
||||
#define AMR_SACK_INTERRUPT(sc) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_ACKINTR)
|
||||
#define AMR_SPOST_COMMAND(sc) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_POST)
|
||||
#define AMR_SGET_MBSTAT(sc) bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SMBOX_BUSY)
|
||||
#define AMR_SENABLE_INTR(sc) \
|
||||
bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, \
|
||||
bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) | AMR_STOGL_IENABLE)
|
||||
#define AMR_SDISABLE_INTR(sc) \
|
||||
bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, \
|
||||
bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) & ~AMR_STOGL_IENABLE)
|
||||
#define AMR_SBYTE_SET(sc, reg, val) bus_space_write_1(sc->amr_btag, sc->amr_bhandle, reg, val)
|
||||
|
||||
/*
|
||||
* Interface between bus connections and driver core.
|
||||
*/
|
||||
extern void amr_free(struct amr_softc *sc);
|
||||
extern int amr_attach(struct amr_softc *sc);
|
||||
extern void amr_startup(struct amr_softc *sc);
|
||||
extern void amr_intr(void *data);
|
||||
extern int amr_detach(device_t dev);
|
||||
extern int amr_shutdown(device_t dev);
|
||||
extern int amr_suspend(device_t dev);
|
||||
extern int amr_resume(device_t dev);
|
||||
extern d_open_t amr_open;
|
||||
extern d_close_t amr_close;
|
||||
extern d_ioctl_t amr_ioctl;
|
||||
|
||||
extern devclass_t amr_devclass;
|
||||
|
||||
/*
|
||||
* MegaRAID logical disk driver
|
||||
*/
|
||||
struct amrd_softc
|
||||
{
|
||||
device_t amrd_dev;
|
||||
struct amr_softc *amrd_controller;
|
||||
struct amr_logdrive *amrd_drive;
|
||||
struct disk amrd_disk;
|
||||
struct devstat amrd_stats;
|
||||
struct disklabel amrd_label;
|
||||
int amrd_unit;
|
||||
int amrd_flags;
|
||||
#define AMRD_OPEN (1<<0) /* drive is open (can't shut down) */
|
||||
};
|
||||
|
||||
/*
|
||||
* Interface between driver core and disk driver (should be using a bus?)
|
||||
*/
|
||||
extern int amr_submit_buf(struct amr_softc *sc, struct buf *bp);
|
||||
extern int amr_submit_ioctl(struct amr_softc *sc, struct amr_logdrive *drive, u_long cmd,
|
||||
caddr_t addr, int32_t flag, struct proc *p);
|
||||
extern void amrd_intr(void *data);
|
||||
|
22
sys/modules/amr/Makefile
Normal file
22
sys/modules/amr/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
# $FreeBSD$
|
||||
|
||||
S = ${.CURDIR}/../..
|
||||
.PATH: $S/dev/amr
|
||||
KMOD = amr
|
||||
SRCS = amr.c amr_pci.c amr_disk.c device_if.h bus_if.h pci_if.h
|
||||
CLEANFILES += amr.h device_if.h bus_if.h pci_if.h
|
||||
CFLAGS += ${DEBUG_FLAGS}
|
||||
|
||||
amr.h:
|
||||
echo "#define NAMR 1" > amr.h
|
||||
|
||||
device_if.h: $S/kern/makedevops.pl $S/kern/device_if.m
|
||||
perl $S/kern/makedevops.pl -h $S/kern/device_if.m
|
||||
|
||||
bus_if.h: $S/kern/makedevops.pl $S/kern/bus_if.m
|
||||
perl $S/kern/makedevops.pl -h $S/kern/bus_if.m
|
||||
|
||||
pci_if.h: $S/kern/makedevops.pl $S/pci/pci_if.m
|
||||
perl $S/kern/makedevops.pl -h $S/pci/pci_if.m
|
||||
|
||||
.include <bsd.kmod.mk>
|
Loading…
Reference in New Issue
Block a user