#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bio.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <geom/geom_disk.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/mlx/mlxio.h>
#include <dev/mlx/mlxvar.h>
#include <dev/mlx/mlxreg.h>
static int mlx_pci_probe(device_t dev);
static int mlx_pci_attach(device_t dev);
static device_method_t mlx_methods[] = {
DEVMETHOD(device_probe, mlx_pci_probe),
DEVMETHOD(device_attach, mlx_pci_attach),
DEVMETHOD(device_detach, mlx_detach),
DEVMETHOD(device_shutdown, mlx_shutdown),
DEVMETHOD(device_suspend, mlx_suspend),
DEVMETHOD(device_resume, mlx_resume),
DEVMETHOD_END
};
static driver_t mlx_pci_driver = {
"mlx",
mlx_methods,
sizeof(struct mlx_softc)
};
DRIVER_MODULE(mlx, pci, mlx_pci_driver, 0, 0);
struct mlx_ident
{
u_int16_t vendor;
u_int16_t device;
u_int16_t subvendor;
u_int16_t subdevice;
int iftype;
char *desc;
} mlx_identifiers[] = {
{0x1069, 0x0001, 0x0000, 0x0000, MLX_IFTYPE_2, "Mylex version 2 RAID interface"},
{0x1069, 0x0002, 0x0000, 0x0000, MLX_IFTYPE_3, "Mylex version 3 RAID interface"},
{0x1069, 0x0010, 0x0000, 0x0000, MLX_IFTYPE_4, "Mylex version 4 RAID interface"},
{0x1011, 0x1065, 0x1069, 0x0020, MLX_IFTYPE_5, "Mylex version 5 RAID interface"},
{0, 0, 0, 0, 0, 0}
};
static struct mlx_ident *
mlx_pci_match(device_t dev)
{
struct mlx_ident *m;
for (m = mlx_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 == pci_get_subdevice(dev)))))
return (m);
}
return (NULL);
}
static int
mlx_pci_probe(device_t dev)
{
struct mlx_ident *m;
debug_called(1);
m = mlx_pci_match(dev);
if (m != NULL) {
device_set_desc(dev, m->desc);
return(BUS_PROBE_DEFAULT);
}
return(ENXIO);
}
static int
mlx_pci_attach(device_t dev)
{
struct mlx_softc *sc;
struct mlx_ident *m;
int error;
debug_called(1);
pci_enable_busmaster(dev);
sc = device_get_softc(dev);
sc->mlx_dev = dev;
m = mlx_pci_match(dev);
if (m == NULL)
return(ENXIO);
sc->mlx_iftype = m->iftype;
mtx_init(&sc->mlx_io_lock, "mlx I/O", NULL, MTX_DEF);
sx_init(&sc->mlx_config_lock, "mlx config");
callout_init_mtx(&sc->mlx_timeout, &sc->mlx_io_lock, 0);
switch(sc->mlx_iftype) {
case MLX_IFTYPE_2:
case MLX_IFTYPE_3:
sc->mlx_mem_type = SYS_RES_MEMORY;
sc->mlx_mem_rid = MLX_CFG_BASE1;
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
&sc->mlx_mem_rid, RF_ACTIVE);
if (sc->mlx_mem == NULL) {
sc->mlx_mem_type = SYS_RES_IOPORT;
sc->mlx_mem_rid = MLX_CFG_BASE0;
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
&sc->mlx_mem_rid, RF_ACTIVE);
}
break;
case MLX_IFTYPE_4:
case MLX_IFTYPE_5:
sc->mlx_mem_type = SYS_RES_MEMORY;
sc->mlx_mem_rid = MLX_CFG_BASE0;
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
&sc->mlx_mem_rid, RF_ACTIVE);
break;
}
if (sc->mlx_mem == NULL) {
device_printf(sc->mlx_dev, "couldn't allocate mailbox window\n");
mlx_free(sc);
return(ENXIO);
}
error = bus_dma_tag_create(bus_get_dma_tag(dev),
1, 0,
BUS_SPACE_MAXADDR_32BIT,
BUS_SPACE_MAXADDR,
NULL, NULL,
BUS_SPACE_MAXSIZE_32BIT,
BUS_SPACE_UNRESTRICTED,
BUS_SPACE_MAXSIZE_32BIT,
BUS_DMA_ALLOCNOW,
NULL,
NULL,
&sc->mlx_parent_dmat);
if (error != 0) {
device_printf(dev, "can't allocate parent DMA tag\n");
mlx_free(sc);
return(ENOMEM);
}
error = mlx_attach(sc);
if (error != 0) {
mlx_free(sc);
return(error);
}
mlx_startup(sc);
return(0);
}