The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/ips/ips_pci.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2002 Adaptec Inc.
    3  * All rights reserved.
    4  *
    5  * Written by: David Jeffery
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  * $FreeBSD: stable/4/sys/dev/ips/ips_pci.c 140149 2005-01-13 00:46:40Z scottl $
   29  */
   30 
   31 #include <dev/ips/ips.h>
   32 
   33 static int ips_pci_free(ips_softc_t *sc);
   34 static void ips_intrhook(void *arg);
   35 
   36 static int ips_pci_probe(device_t dev)
   37 {
   38 
   39         if ((pci_get_vendor(dev) == IPS_VENDOR_ID) &&
   40             (pci_get_device(dev) == IPS_MORPHEUS_DEVICE_ID)) {
   41                 device_set_desc(dev, "IBM ServeRAID Adapter");
   42                 return 0;
   43         } else if ((pci_get_vendor(dev) == IPS_VENDOR_ID) &&
   44             (pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID)) {
   45                 device_set_desc(dev, "IBM ServeRAID Adapter");
   46                 return (0);
   47         } else if ((pci_get_vendor(dev) == IPS_VENDOR_ID_ADAPTEC) &&
   48             (pci_get_device(dev) == IPS_MARCO_DEVICE_ID)) {
   49                 device_set_desc(dev, "Adaptec ServeRAID Adapter");
   50                 return (0);
   51         }
   52         return(ENXIO);
   53 }
   54 
   55 static int ips_pci_attach(device_t dev)
   56 {
   57         u_int32_t command;
   58         ips_softc_t *sc;
   59         int tval;
   60 
   61 
   62         tval = 0;
   63         if (resource_int_value(device_get_name(dev), device_get_unit(dev),
   64             "disabled", &tval) == 0 && tval) {
   65                 device_printf(dev, "device is disabled\n");
   66                 /* but return 0 so the !$)$)*!$*) unit isn't reused */
   67                 return (0);
   68         }
   69 
   70         DEVICE_PRINTF(1, dev, "in attach.\n");
   71         sc = (ips_softc_t *)device_get_softc(dev);
   72         if(!sc){
   73                 printf("how is sc NULL?!\n");
   74                 return (ENXIO);
   75         }
   76         bzero(sc, sizeof(ips_softc_t));
   77         sc->dev = dev;
   78 
   79         if(pci_get_device(dev) == IPS_MORPHEUS_DEVICE_ID){
   80                 sc->ips_adapter_reinit = ips_morpheus_reinit;
   81                 sc->ips_adapter_intr = ips_morpheus_intr;
   82                 sc->ips_issue_cmd    = ips_issue_morpheus_cmd;
   83         } else if(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID){
   84                 sc->ips_adapter_reinit = ips_copperhead_reinit;
   85                 sc->ips_adapter_intr = ips_copperhead_intr;
   86                 sc->ips_issue_cmd    = ips_issue_copperhead_cmd;
   87         } else if (pci_get_device(dev) == IPS_MARCO_DEVICE_ID){
   88                 sc->ips_adapter_reinit = ips_morpheus_reinit;
   89                 sc->ips_adapter_intr = ips_morpheus_intr;
   90                 sc->ips_issue_cmd = ips_issue_morpheus_cmd;
   91         } else
   92                 goto error;
   93         /* make sure busmastering is on */
   94         command = pci_read_config(dev, PCIR_COMMAND, 1);
   95         command |= PCIM_CMD_BUSMASTEREN;
   96         pci_write_config(dev, PCIR_COMMAND, command, 1);
   97         /* seting up io space */
   98         sc->iores = NULL;
   99         if(command & PCIM_CMD_MEMEN){
  100                 PRINTF(10, "trying MEMIO\n");
  101                 if(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID)
  102                         sc->rid = PCIR_BAR(1);
  103                 else
  104                         sc->rid = PCIR_BAR(0);
  105                 sc->iotype = SYS_RES_MEMORY;
  106                 sc->iores = bus_alloc_resource(dev, sc->iotype, &sc->rid,
  107                         0, ~0, 1, RF_ACTIVE);
  108         }
  109         if(!sc->iores && command & PCIM_CMD_PORTEN){
  110                 PRINTF(10, "trying PORTIO\n");
  111                 sc->rid = PCIR_BAR(0);
  112                 sc->iotype = SYS_RES_IOPORT;
  113                 sc->iores = bus_alloc_resource(dev, sc->iotype, &sc->rid,
  114                         0, ~0, 1, RF_ACTIVE);
  115         }
  116         if(sc->iores == NULL){
  117                 device_printf(dev, "resource allocation failed\n");
  118                 return (ENXIO);
  119         }
  120         sc->bustag = rman_get_bustag(sc->iores);
  121         sc->bushandle = rman_get_bushandle(sc->iores);
  122         /*allocate an interrupt. when does the irq become active? after leaving attach? */
  123         sc->irqrid = 0;
  124         if(!(sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqrid,
  125                 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE))){
  126                 device_printf(dev, "irq allocation failed\n");
  127                 goto error;
  128         }
  129         if(bus_setup_intr(dev, sc->irqres, INTR_TYPE_BIO, sc->ips_adapter_intr, sc, &sc->irqcookie)){
  130                 device_printf(dev, "irq setup failed\n");
  131                 goto error;
  132         }
  133         if (bus_dma_tag_create( /* parent    */ NULL,
  134                                 /* alignemnt */ 1,
  135                                 /* boundary  */ 0,
  136                                 /* lowaddr   */ BUS_SPACE_MAXADDR_32BIT,
  137                                 /* highaddr  */ BUS_SPACE_MAXADDR,
  138                                 /* filter    */ NULL,
  139                                 /* filterarg */ NULL,
  140                                 /* maxsize   */ BUS_SPACE_MAXSIZE_32BIT,
  141                                 /* numsegs   */ IPS_MAX_SG_ELEMENTS,
  142                                 /* maxsegsize*/ BUS_SPACE_MAXSIZE_32BIT,
  143                                 /* flags     */ 0,
  144                                 &sc->adapter_dmatag) != 0) {
  145                 printf("IPS can't alloc dma tag\n");
  146                 goto error;
  147         }
  148         sc->ips_ich.ich_func = ips_intrhook;
  149         sc->ips_ich.ich_arg = sc;
  150         bufq_init(&sc->queue);
  151         if (config_intrhook_establish(&sc->ips_ich) != 0) {
  152                 printf("IPS can't establish configuration hook\n");
  153                 goto error;
  154         }
  155         return 0;
  156 error:
  157         ips_pci_free(sc);
  158         return (ENXIO);
  159 }
  160 
  161 static void
  162 ips_intrhook(void *arg)
  163 {
  164         struct ips_softc *sc = (struct ips_softc *)arg;
  165 
  166         config_intrhook_disestablish(&sc->ips_ich);
  167         if (ips_adapter_init(sc))
  168                 ips_pci_free(sc);
  169         else
  170                 sc->configured = 1;
  171 }
  172 
  173 static int ips_pci_free(ips_softc_t *sc)
  174 {
  175         if(sc->adapter_dmatag)
  176                 bus_dma_tag_destroy(sc->adapter_dmatag);
  177         if(sc->irqcookie)
  178                 bus_teardown_intr(sc->dev, sc->irqres, sc->irqcookie);
  179         if(sc->irqres)
  180                bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irqrid, sc->irqres);
  181         if(sc->iores)
  182                 bus_release_resource(sc->dev, sc->iotype, sc->rid, sc->iores);
  183         sc->configured = 0;
  184         return 0;
  185 }
  186 
  187 static int ips_pci_detach(device_t dev)
  188 {
  189         ips_softc_t *sc;
  190         DEVICE_PRINTF(1, dev, "detaching ServeRaid\n");
  191         sc = (ips_softc_t *) device_get_softc(dev);
  192         if (sc->configured) {
  193                 sc->configured = 0;
  194                 ips_flush_cache(sc);
  195                 if(ips_adapter_free(sc))
  196                         return EBUSY;
  197                 ips_pci_free(sc);
  198 #if 0   /* XXX */
  199                 bioq_flush(&sc->queue, NULL, ENXIO);
  200 #endif
  201         }
  202         return 0;
  203 }
  204 
  205 static int ips_pci_shutdown(device_t dev)
  206 {
  207         ips_softc_t *sc = (ips_softc_t *) device_get_softc(dev);
  208         if (sc->configured) {
  209                 ips_flush_cache(sc);
  210         }
  211         return 0;
  212 }
  213 
  214 static device_method_t ips_driver_methods[] = {
  215         DEVMETHOD(device_probe, ips_pci_probe),
  216         DEVMETHOD(device_attach, ips_pci_attach),
  217         DEVMETHOD(device_detach, ips_pci_detach),
  218         DEVMETHOD(device_shutdown, ips_pci_shutdown),
  219         {0,0}
  220 };
  221 
  222 static driver_t ips_pci_driver = {
  223         "ips",
  224         ips_driver_methods,
  225         sizeof(ips_softc_t),
  226 };
  227 
  228 static devclass_t ips_devclass;
  229 DRIVER_MODULE(ips, pci, ips_pci_driver, ips_devclass, 0, 0);

Cache object: f72226c881cb8c3dcdb155c37d8a1821


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.