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/mfi/mfi_pci.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2006 IronPort Systems
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD$");
   29 
   30 /* PCI/PCI-X/PCIe bus interface for the LSI MegaSAS controllers */
   31 
   32 #include "opt_mfi.h"
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/kernel.h>
   37 #include <sys/select.h>
   38 #include <sys/module.h>
   39 #include <sys/bus.h>
   40 #include <sys/conf.h>
   41 #include <sys/malloc.h>
   42 #include <sys/uio.h>
   43 
   44 #include <dev/mfi/mfi_compat.h>
   45 #include <machine/bus.h>
   46 #include <machine/resource.h>
   47 #include <sys/rman.h>
   48 
   49 #include <pci/pcireg.h>
   50 #include <pci/pcivar.h>
   51 
   52 #include <dev/mfi/mfireg.h>
   53 #include <dev/mfi/mfi_ioctl.h>
   54 #include <dev/mfi/mfivar.h>
   55 
   56 static int      mfi_pci_probe(device_t);
   57 static int      mfi_pci_attach(device_t);
   58 static int      mfi_pci_detach(device_t);
   59 static int      mfi_pci_suspend(device_t);
   60 static int      mfi_pci_resume(device_t);
   61 static void     mfi_pci_free(struct mfi_softc *);
   62 
   63 static device_method_t mfi_methods[] = {
   64         DEVMETHOD(device_probe,         mfi_pci_probe),
   65         DEVMETHOD(device_attach,        mfi_pci_attach),
   66         DEVMETHOD(device_detach,        mfi_pci_detach),
   67         DEVMETHOD(device_suspend,       mfi_pci_suspend),
   68         DEVMETHOD(device_resume,        mfi_pci_resume),
   69         DEVMETHOD(bus_print_child,      bus_generic_print_child),
   70         DEVMETHOD(bus_driver_added,     bus_generic_driver_added),
   71         { 0, 0 }
   72 };
   73 
   74 static driver_t mfi_pci_driver = {
   75         "mfi",
   76         mfi_methods,
   77         sizeof(struct mfi_softc)
   78 };
   79 
   80 static devclass_t       mfi_devclass;
   81 DRIVER_MODULE(mfi, pci, mfi_pci_driver, mfi_devclass, 0, 0);
   82 
   83 struct mfi_ident {
   84         uint16_t        vendor;
   85         uint16_t        device;
   86         uint16_t        subvendor;
   87         uint16_t        subdevice;
   88         int             flags;
   89         const char      *desc;
   90 } mfi_identifiers[] = {
   91         {0x1000, 0x0411, 0xffff, 0xffff, 0, "LSI MegaSAS 1064R"}, /* Brocton IOP */
   92         {0x1000, 0x0413, 0xffff, 0xffff, 0, "LSI MegaSAS 1064R"}, /* Verde ZCR */
   93         {0x1028, 0x0015, 0xffff, 0xffff, 0, "Dell PERC 5/i"},
   94         {0, 0, 0, 0, 0, NULL}
   95 };
   96 
   97 static struct mfi_ident *
   98 mfi_find_ident(device_t dev)
   99 {
  100         struct mfi_ident *m;
  101 
  102         for (m = mfi_identifiers; m->vendor != 0; m++) {
  103                 if ((m->vendor == pci_get_vendor(dev)) &&
  104                     (m->device == pci_get_device(dev)) &&
  105                     ((m->subvendor == pci_get_subvendor(dev)) ||
  106                     (m->subvendor == 0xffff)) &&
  107                     ((m->subdevice == pci_get_subdevice(dev)) ||
  108                     (m->subdevice == 0xffff)))
  109                         return (m);
  110         }
  111 
  112         return (NULL);
  113 }
  114 
  115 static int
  116 mfi_pci_probe(device_t dev)
  117 {
  118         struct mfi_ident *id;
  119 
  120         if ((id = mfi_find_ident(dev)) != NULL) {
  121                 device_set_desc(dev, id->desc);
  122                 return (BUS_PROBE_DEFAULT);
  123         }
  124         return (ENXIO);
  125 }
  126 
  127 static int
  128 mfi_pci_attach(device_t dev)
  129 {
  130         struct mfi_softc *sc;
  131         struct mfi_ident *m;
  132         uint32_t command;
  133         int error;
  134 
  135         sc = device_get_softc(dev);
  136         bzero(sc, sizeof(*sc));
  137         sc->mfi_dev = dev;
  138 
  139         /* Verify that the adapter can be set up in PCI space */
  140         command = pci_read_config(dev, PCIR_COMMAND, 2);
  141         command |= PCIM_CMD_BUSMASTEREN;
  142         pci_write_config(dev, PCIR_COMMAND, command, 2);
  143         command = pci_read_config(dev, PCIR_COMMAND, 2);
  144         if ((command & PCIM_CMD_BUSMASTEREN) == 0) {
  145                 device_printf(dev, "Can't enable PCI busmaster\n");
  146                 return (ENXIO);
  147         }
  148         if ((command & PCIM_CMD_MEMEN) == 0) {
  149                 device_printf(dev, "PCI memory window not available\n");
  150                 return (ENXIO);
  151         }
  152 
  153         /* Allocate PCI registers */
  154         sc->mfi_regs_rid = PCIR_BAR(0);
  155         if ((sc->mfi_regs_resource = bus_alloc_resource_any(sc->mfi_dev,
  156             SYS_RES_MEMORY, &sc->mfi_regs_rid, RF_ACTIVE)) == NULL) {
  157                 device_printf(dev, "Cannot allocate PCI registers\n");
  158                 return (ENXIO);
  159         }
  160         sc->mfi_btag = rman_get_bustag(sc->mfi_regs_resource);
  161         sc->mfi_bhandle = rman_get_bushandle(sc->mfi_regs_resource);
  162 
  163         error = ENOMEM;
  164 
  165         /* Allocate parent DMA tag */
  166         if (bus_dma_tag_create( NULL,                   /* parent */
  167                                 1, 0,                   /* algnmnt, boundary */
  168                                 BUS_SPACE_MAXADDR,      /* lowaddr */
  169                                 BUS_SPACE_MAXADDR,      /* highaddr */
  170                                 NULL, NULL,             /* filter, filterarg */
  171                                 BUS_SPACE_MAXSIZE_32BIT,/* maxsize */
  172                                 BUS_SPACE_UNRESTRICTED, /* nsegments */
  173                                 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
  174                                 0,                      /* flags */
  175                                 &sc->mfi_parent_dmat)) {
  176                 device_printf(dev, "Cannot allocate parent DMA tag\n");
  177                 goto out;
  178         }
  179 
  180         m = mfi_find_ident(dev);
  181         sc->mfi_flags = m->flags;
  182 
  183         error = mfi_attach(sc);
  184 out:
  185         if (error) {
  186                 mfi_free(sc);
  187                 mfi_pci_free(sc);
  188         }
  189 
  190         return (error);
  191 }
  192 
  193 static int
  194 mfi_pci_detach(device_t dev)
  195 {
  196         struct mfi_softc *sc;
  197         struct mfi_ld *ld;
  198         int error;
  199 
  200         sc = device_get_softc(dev);
  201 
  202         if ((sc->mfi_flags & MFI_FLAGS_OPEN) != 0)
  203                 return (EBUSY);
  204 
  205         while ((ld = TAILQ_FIRST(&sc->mfi_ld_tqh)) != NULL) {
  206                 error = device_delete_child(dev, ld->ld_disk);
  207                 if (error)
  208                         return (error);
  209                 TAILQ_REMOVE(&sc->mfi_ld_tqh, ld, ld_link);
  210                 free(ld->ld_info, M_MFIBUF);
  211                 free(ld, M_MFIBUF);
  212         }
  213 
  214         EVENTHANDLER_DEREGISTER(shutdown_final, sc->mfi_eh);
  215 
  216         mfi_shutdown(sc);
  217         mfi_free(sc);
  218         mfi_pci_free(sc);
  219         return (0);
  220 }
  221 
  222 static void
  223 mfi_pci_free(struct mfi_softc *sc)
  224 {
  225 
  226         if (sc->mfi_regs_resource != NULL) {
  227                 bus_release_resource(sc->mfi_dev, SYS_RES_MEMORY,
  228                     sc->mfi_regs_rid, sc->mfi_regs_resource);
  229         }
  230 
  231         return;
  232 }
  233 
  234 static int
  235 mfi_pci_suspend(device_t dev)
  236 {
  237 
  238         return (EINVAL);
  239 }
  240 
  241 static int
  242 mfi_pci_resume(device_t dev)
  243 {
  244 
  245         return (EINVAL);
  246 }

Cache object: cd8c1b7a7c36883b1843426434734d38


[ 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.