1999-10-07 02:20:32 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
1999-10-07 02:20:32 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-10-07 02:20:32 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2012-09-26 14:17:14 +00:00
|
|
|
#include <sys/bio.h>
|
1999-10-07 02:20:32 +00:00
|
|
|
#include <sys/kernel.h>
|
2012-09-17 15:27:30 +00:00
|
|
|
#include <sys/lock.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2012-09-17 15:27:30 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/sx.h>
|
1999-10-07 02:20:32 +00:00
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2003-04-01 15:06:26 +00:00
|
|
|
#include <geom/geom_disk.h>
|
|
|
|
|
2003-08-22 06:42:59 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
1999-10-07 02:20:32 +00:00
|
|
|
|
|
|
|
#include <dev/mlx/mlxio.h>
|
|
|
|
#include <dev/mlx/mlxvar.h>
|
1999-10-26 23:20:43 +00:00
|
|
|
#include <dev/mlx/mlxreg.h>
|
1999-10-07 02:20:32 +00:00
|
|
|
|
|
|
|
static int mlx_pci_probe(device_t dev);
|
|
|
|
static int mlx_pci_attach(device_t dev);
|
|
|
|
|
|
|
|
static device_method_t mlx_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
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),
|
|
|
|
|
2011-11-22 21:28:20 +00:00
|
|
|
DEVMETHOD_END
|
1999-10-07 02:20:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t mlx_pci_driver = {
|
|
|
|
"mlx",
|
|
|
|
mlx_methods,
|
|
|
|
sizeof(struct mlx_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(mlx, pci, mlx_pci_driver, mlx_devclass, 0, 0);
|
|
|
|
|
1999-12-11 00:00:13 +00:00
|
|
|
struct mlx_ident
|
1999-10-07 02:20:32 +00:00
|
|
|
{
|
|
|
|
u_int16_t vendor;
|
|
|
|
u_int16_t device;
|
1999-12-11 00:00:13 +00:00
|
|
|
u_int16_t subvendor;
|
|
|
|
u_int16_t subdevice;
|
1999-10-07 02:20:32 +00:00
|
|
|
int iftype;
|
|
|
|
char *desc;
|
|
|
|
} mlx_identifiers[] = {
|
2000-03-18 02:01:37 +00:00
|
|
|
{0x1069, 0x0001, 0x0000, 0x0000, MLX_IFTYPE_2, "Mylex version 2 RAID interface"},
|
1999-12-11 00:00:13 +00:00
|
|
|
{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}
|
1999-10-07 02:20:32 +00:00
|
|
|
};
|
|
|
|
|
2012-09-17 15:27:30 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1999-10-07 02:20:32 +00:00
|
|
|
static int
|
|
|
|
mlx_pci_probe(device_t dev)
|
|
|
|
{
|
1999-12-11 00:00:13 +00:00
|
|
|
struct mlx_ident *m;
|
1999-10-07 02:20:32 +00:00
|
|
|
|
2000-03-18 02:01:37 +00:00
|
|
|
debug_called(1);
|
1999-10-07 02:20:32 +00:00
|
|
|
|
2012-09-17 15:27:30 +00:00
|
|
|
m = mlx_pci_match(dev);
|
|
|
|
if (m != NULL) {
|
|
|
|
device_set_desc(dev, m->desc);
|
|
|
|
return(BUS_PROBE_DEFAULT);
|
1999-10-07 02:20:32 +00:00
|
|
|
}
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mlx_pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct mlx_softc *sc;
|
2012-09-17 15:27:30 +00:00
|
|
|
struct mlx_ident *m;
|
|
|
|
int error;
|
1999-10-07 02:20:32 +00:00
|
|
|
|
2000-03-18 02:01:37 +00:00
|
|
|
debug_called(1);
|
1999-10-07 02:20:32 +00:00
|
|
|
|
2012-09-17 15:27:30 +00:00
|
|
|
pci_enable_busmaster(dev);
|
1999-10-07 02:20:32 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->mlx_dev = dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work out what sort of adapter this is (we need to know this in order
|
|
|
|
* to map the appropriate interface resources).
|
|
|
|
*/
|
2012-09-17 15:27:30 +00:00
|
|
|
m = mlx_pci_match(dev);
|
|
|
|
if (m == NULL) /* shouldn't happen */
|
1999-10-07 02:20:32 +00:00
|
|
|
return(ENXIO);
|
2012-09-17 15:27:30 +00:00
|
|
|
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);
|
|
|
|
|
1999-10-07 02:20:32 +00:00
|
|
|
/*
|
|
|
|
* Allocate the PCI register window.
|
|
|
|
*/
|
|
|
|
|
2000-08-04 06:52:00 +00:00
|
|
|
/* type 2/3 adapters have an I/O region we don't prefer at base 0 */
|
2000-03-18 02:01:37 +00:00
|
|
|
switch(sc->mlx_iftype) {
|
|
|
|
case MLX_IFTYPE_2:
|
|
|
|
case MLX_IFTYPE_3:
|
2000-11-28 06:17:32 +00:00
|
|
|
sc->mlx_mem_type = SYS_RES_MEMORY;
|
|
|
|
sc->mlx_mem_rid = MLX_CFG_BASE1;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
|
|
|
|
&sc->mlx_mem_rid, RF_ACTIVE);
|
2000-08-04 06:52:00 +00:00
|
|
|
if (sc->mlx_mem == NULL) {
|
2000-11-28 06:17:32 +00:00
|
|
|
sc->mlx_mem_type = SYS_RES_IOPORT;
|
|
|
|
sc->mlx_mem_rid = MLX_CFG_BASE0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
|
|
|
|
&sc->mlx_mem_rid, RF_ACTIVE);
|
2000-08-04 06:52:00 +00:00
|
|
|
}
|
2000-03-18 02:01:37 +00:00
|
|
|
break;
|
|
|
|
case MLX_IFTYPE_4:
|
|
|
|
case MLX_IFTYPE_5:
|
2000-11-28 06:17:32 +00:00
|
|
|
sc->mlx_mem_type = SYS_RES_MEMORY;
|
|
|
|
sc->mlx_mem_rid = MLX_CFG_BASE0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->mlx_mem = bus_alloc_resource_any(dev, sc->mlx_mem_type,
|
|
|
|
&sc->mlx_mem_rid, RF_ACTIVE);
|
2000-03-18 02:01:37 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-10-07 02:20:32 +00:00
|
|
|
if (sc->mlx_mem == NULL) {
|
|
|
|
device_printf(sc->mlx_dev, "couldn't allocate mailbox window\n");
|
|
|
|
mlx_free(sc);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the parent bus DMA tag appropriate for PCI.
|
|
|
|
*/
|
2012-03-12 08:03:51 +00:00
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(dev), /* PCI parent */
|
1999-10-07 02:20:32 +00:00
|
|
|
1, 0, /* alignment, boundary */
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
|
|
|
|
BUS_SPACE_MAXADDR, /* highaddr */
|
|
|
|
NULL, NULL, /* filter, filterarg */
|
2015-03-22 16:10:28 +00:00
|
|
|
BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
|
|
|
|
BUS_SPACE_UNRESTRICTED, /* nsegments */
|
1999-10-07 02:20:32 +00:00
|
|
|
BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
|
|
|
|
BUS_DMA_ALLOCNOW, /* flags */
|
2003-07-01 15:52:06 +00:00
|
|
|
NULL, /* lockfunc */
|
|
|
|
NULL, /* lockarg */
|
1999-10-07 02:20:32 +00:00
|
|
|
&sc->mlx_parent_dmat);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(dev, "can't allocate parent DMA tag\n");
|
|
|
|
mlx_free(sc);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do bus-independant initialisation.
|
|
|
|
*/
|
|
|
|
error = mlx_attach(sc);
|
2005-07-30 15:53:40 +00:00
|
|
|
if (error != 0) {
|
2005-03-26 21:58:09 +00:00
|
|
|
mlx_free(sc);
|
1999-10-07 02:20:32 +00:00
|
|
|
return(error);
|
2005-07-30 15:53:40 +00:00
|
|
|
}
|
1999-10-07 02:20:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the controller.
|
|
|
|
*/
|
|
|
|
mlx_startup(sc);
|
|
|
|
return(0);
|
|
|
|
}
|