2003-05-11 06:36:49 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-05-11 06:36:49 +00:00
|
|
|
* Copyright (c) 2002 Adaptec Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by: David Jeffery
|
|
|
|
*
|
|
|
|
* 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$");
|
2003-05-11 06:36:49 +00:00
|
|
|
|
2005-11-29 09:39:41 +00:00
|
|
|
#include <dev/ips/ipsreg.h>
|
2003-05-11 06:36:49 +00:00
|
|
|
#include <dev/ips/ips.h>
|
2003-08-24 17:55:58 +00:00
|
|
|
|
2005-11-29 09:39:41 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
2003-05-11 06:36:49 +00:00
|
|
|
static int ips_pci_free(ips_softc_t *sc);
|
2003-09-11 23:30:28 +00:00
|
|
|
static void ips_intrhook(void *arg);
|
2003-05-11 06:36:49 +00:00
|
|
|
|
|
|
|
static int ips_pci_probe(device_t dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((pci_get_vendor(dev) == IPS_VENDOR_ID) &&
|
|
|
|
(pci_get_device(dev) == IPS_MORPHEUS_DEVICE_ID)) {
|
|
|
|
device_set_desc(dev, "IBM ServeRAID Adapter");
|
2005-03-05 18:17:35 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2003-05-11 06:36:49 +00:00
|
|
|
} else if ((pci_get_vendor(dev) == IPS_VENDOR_ID) &&
|
|
|
|
(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID)) {
|
|
|
|
device_set_desc(dev, "IBM ServeRAID Adapter");
|
2005-03-05 18:17:35 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2004-03-19 17:36:47 +00:00
|
|
|
} else if ((pci_get_vendor(dev) == IPS_VENDOR_ID_ADAPTEC) &&
|
|
|
|
(pci_get_device(dev) == IPS_MARCO_DEVICE_ID)) {
|
|
|
|
device_set_desc(dev, "Adaptec ServeRAID Adapter");
|
2005-03-05 18:17:35 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2004-03-19 17:36:47 +00:00
|
|
|
}
|
2003-05-11 06:36:49 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ips_pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
ips_softc_t *sc;
|
|
|
|
|
|
|
|
DEVICE_PRINTF(1, dev, "in attach.\n");
|
|
|
|
sc = (ips_softc_t *)device_get_softc(dev);
|
|
|
|
sc->dev = dev;
|
2014-11-13 22:06:57 +00:00
|
|
|
mtx_init(&sc->queue_mtx, "IPS bioqueue lock", NULL, MTX_DEF);
|
|
|
|
sema_init(&sc->cmd_sema, 0, "IPS Command Semaphore");
|
|
|
|
callout_init_mtx(&sc->timer, &sc->queue_mtx, 0);
|
2003-05-11 06:36:49 +00:00
|
|
|
|
|
|
|
if(pci_get_device(dev) == IPS_MORPHEUS_DEVICE_ID){
|
|
|
|
sc->ips_adapter_reinit = ips_morpheus_reinit;
|
|
|
|
sc->ips_adapter_intr = ips_morpheus_intr;
|
|
|
|
sc->ips_issue_cmd = ips_issue_morpheus_cmd;
|
2005-01-30 17:45:45 +00:00
|
|
|
sc->ips_poll_cmd = ips_morpheus_poll;
|
2003-05-11 06:36:49 +00:00
|
|
|
} else if(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID){
|
|
|
|
sc->ips_adapter_reinit = ips_copperhead_reinit;
|
|
|
|
sc->ips_adapter_intr = ips_copperhead_intr;
|
|
|
|
sc->ips_issue_cmd = ips_issue_copperhead_cmd;
|
2005-01-30 17:45:45 +00:00
|
|
|
sc->ips_poll_cmd = ips_copperhead_poll;
|
2004-03-19 17:36:47 +00:00
|
|
|
} else if (pci_get_device(dev) == IPS_MARCO_DEVICE_ID){
|
|
|
|
sc->ips_adapter_reinit = ips_morpheus_reinit;
|
|
|
|
sc->ips_adapter_intr = ips_morpheus_intr;
|
|
|
|
sc->ips_issue_cmd = ips_issue_morpheus_cmd;
|
2005-01-30 17:45:45 +00:00
|
|
|
sc->ips_poll_cmd = ips_morpheus_poll;
|
2003-05-11 06:36:49 +00:00
|
|
|
} else
|
|
|
|
goto error;
|
|
|
|
/* make sure busmastering is on */
|
2013-08-12 23:30:01 +00:00
|
|
|
pci_enable_busmaster(dev);
|
2014-11-13 22:06:57 +00:00
|
|
|
/* setting up io space */
|
2003-05-11 06:36:49 +00:00
|
|
|
sc->iores = NULL;
|
2013-08-12 23:30:01 +00:00
|
|
|
PRINTF(10, "trying MEMIO\n");
|
|
|
|
if(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID)
|
|
|
|
sc->rid = PCIR_BAR(1);
|
|
|
|
else
|
|
|
|
sc->rid = PCIR_BAR(0);
|
|
|
|
sc->iotype = SYS_RES_MEMORY;
|
|
|
|
sc->iores = bus_alloc_resource_any(dev, sc->iotype, &sc->rid,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if(!sc->iores){
|
2003-05-11 06:36:49 +00:00
|
|
|
PRINTF(10, "trying PORTIO\n");
|
2003-09-02 17:30:40 +00:00
|
|
|
sc->rid = PCIR_BAR(0);
|
2003-05-11 06:36:49 +00:00
|
|
|
sc->iotype = SYS_RES_IOPORT;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->iores = bus_alloc_resource_any(dev, sc->iotype,
|
|
|
|
&sc->rid, RF_ACTIVE);
|
2003-05-11 06:36:49 +00:00
|
|
|
}
|
|
|
|
if(sc->iores == NULL){
|
|
|
|
device_printf(dev, "resource allocation failed\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
/*allocate an interrupt. when does the irq become active? after leaving attach? */
|
|
|
|
sc->irqrid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
if(!(sc->irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ,
|
|
|
|
&sc->irqrid, RF_SHAREABLE | RF_ACTIVE))){
|
2003-05-11 06:36:49 +00:00
|
|
|
device_printf(dev, "irq allocation failed\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2007-02-23 12:19:07 +00:00
|
|
|
if(bus_setup_intr(dev, sc->irqres, INTR_TYPE_BIO|INTR_MPSAFE, NULL,
|
|
|
|
sc->ips_adapter_intr, sc, &sc->irqcookie)){
|
2003-05-11 06:36:49 +00:00
|
|
|
device_printf(dev, "irq setup failed\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2012-03-12 08:03:51 +00:00
|
|
|
if (bus_dma_tag_create( /* PCI parent */bus_get_dma_tag(dev),
|
2003-05-11 06:36:49 +00:00
|
|
|
/* alignemnt */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* numsegs */ IPS_MAX_SG_ELEMENTS,
|
|
|
|
/* maxsegsize*/ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ 0,
|
2005-01-28 05:02:13 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-05-11 06:36:49 +00:00
|
|
|
&sc->adapter_dmatag) != 0) {
|
2014-11-13 22:06:57 +00:00
|
|
|
device_printf(dev, "can't alloc dma tag\n");
|
2003-05-11 06:36:49 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2003-09-11 23:30:28 +00:00
|
|
|
sc->ips_ich.ich_func = ips_intrhook;
|
|
|
|
sc->ips_ich.ich_arg = sc;
|
2004-02-28 19:14:41 +00:00
|
|
|
bioq_init(&sc->queue);
|
2003-09-11 23:30:28 +00:00
|
|
|
if (config_intrhook_establish(&sc->ips_ich) != 0) {
|
|
|
|
printf("IPS can't establish configuration hook\n");
|
2003-05-11 06:36:49 +00:00
|
|
|
goto error;
|
2003-09-11 23:30:28 +00:00
|
|
|
}
|
2003-05-11 06:36:49 +00:00
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
ips_pci_free(sc);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2003-09-11 23:30:28 +00:00
|
|
|
static void
|
|
|
|
ips_intrhook(void *arg)
|
|
|
|
{
|
|
|
|
struct ips_softc *sc = (struct ips_softc *)arg;
|
|
|
|
|
|
|
|
config_intrhook_disestablish(&sc->ips_ich);
|
|
|
|
if (ips_adapter_init(sc))
|
|
|
|
ips_pci_free(sc);
|
|
|
|
else
|
|
|
|
sc->configured = 1;
|
|
|
|
}
|
|
|
|
|
2003-05-11 06:36:49 +00:00
|
|
|
static int ips_pci_free(ips_softc_t *sc)
|
|
|
|
{
|
|
|
|
if(sc->adapter_dmatag)
|
|
|
|
bus_dma_tag_destroy(sc->adapter_dmatag);
|
|
|
|
if(sc->irqcookie)
|
|
|
|
bus_teardown_intr(sc->dev, sc->irqres, sc->irqcookie);
|
|
|
|
if(sc->irqres)
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irqrid, sc->irqres);
|
|
|
|
if(sc->iores)
|
|
|
|
bus_release_resource(sc->dev, sc->iotype, sc->rid, sc->iores);
|
2003-06-26 00:03:59 +00:00
|
|
|
sc->configured = 0;
|
2005-01-28 05:02:13 +00:00
|
|
|
mtx_destroy(&sc->queue_mtx);
|
|
|
|
sema_destroy(&sc->cmd_sema);
|
2003-05-11 06:36:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ips_pci_detach(device_t dev)
|
|
|
|
{
|
|
|
|
ips_softc_t *sc;
|
|
|
|
DEVICE_PRINTF(1, dev, "detaching ServeRaid\n");
|
|
|
|
sc = (ips_softc_t *) device_get_softc(dev);
|
2003-06-26 00:03:59 +00:00
|
|
|
if (sc->configured) {
|
|
|
|
sc->configured = 0;
|
|
|
|
ips_flush_cache(sc);
|
|
|
|
if(ips_adapter_free(sc))
|
|
|
|
return EBUSY;
|
|
|
|
ips_pci_free(sc);
|
2004-02-28 19:14:41 +00:00
|
|
|
bioq_flush(&sc->queue, NULL, ENXIO);
|
2003-06-26 00:03:59 +00:00
|
|
|
}
|
2003-05-11 06:36:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ips_pci_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
ips_softc_t *sc = (ips_softc_t *) device_get_softc(dev);
|
2003-06-26 00:03:59 +00:00
|
|
|
if (sc->configured) {
|
|
|
|
ips_flush_cache(sc);
|
|
|
|
}
|
2003-05-11 06:36:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t ips_driver_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, ips_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, ips_pci_attach),
|
|
|
|
DEVMETHOD(device_detach, ips_pci_detach),
|
|
|
|
DEVMETHOD(device_shutdown, ips_pci_shutdown),
|
|
|
|
{0,0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ips_pci_driver = {
|
|
|
|
"ips",
|
|
|
|
ips_driver_methods,
|
|
|
|
sizeof(ips_softc_t),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t ips_devclass;
|
|
|
|
DRIVER_MODULE(ips, pci, ips_pci_driver, ips_devclass, 0, 0);
|