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/an/if_an_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) 1997, 1998, 1999
    3  *      Bill Paul <wpaul@ctr.columbia.edu>.  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  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by Bill Paul.
   16  * 4. Neither the name of the author nor the names of any co-contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
   24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   30  * THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __FBSDID("$FreeBSD$");
   35 
   36 /*
   37  * This is a PCI shim for the Aironet PC4500/4800 wireless network
   38  * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices,
   39  * which all have basically the same interface. The ISA and PCI cards
   40  * are actually bridge adapters with PCMCIA cards inserted into them,
   41  * however they appear as normal PCI or ISA devices to the host.
   42  *
   43  * All we do here is handle the PCI probe and attach and set up an
   44  * interrupt handler entry point. The PCI version of the card uses
   45  * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with
   46  * multiple PCI address space mappings. The primary mapping at PCI
   47  * register 0x14 is for the PLX chip itself, *NOT* the Aironet card.
   48  * The I/O address of the Aironet is actually at register 0x18, which
   49  * is the local bus mapping register for bus space 0. There are also
   50  * registers for additional register spaces at registers 0x1C and
   51  * 0x20, but these are unused in the Aironet devices. To find out
   52  * more, you need a datasheet for the 9050 from PLX, but you have
   53  * to go through their sales office to get it. Bleh.
   54  */
   55 
   56 #include "opt_inet.h"
   57 
   58 #ifdef INET
   59 #define ANCACHE
   60 #endif
   61 
   62 #include <sys/param.h>
   63 #include <sys/systm.h>
   64 #include <sys/sockio.h>
   65 #include <sys/mbuf.h>
   66 #include <sys/kernel.h>
   67 #include <sys/socket.h>
   68 
   69 #include <sys/module.h>
   70 #include <sys/bus.h>
   71 #include <machine/bus.h>
   72 #include <sys/rman.h>
   73 #include <sys/lock.h>
   74 #include <sys/mutex.h>
   75 #include <machine/resource.h>
   76 
   77 #include <net/if.h>
   78 #include <net/if_arp.h>
   79 #include <net/ethernet.h>
   80 #include <net/if_dl.h>
   81 #include <net/if_media.h>
   82 
   83 #include <dev/pci/pcireg.h>
   84 #include <dev/pci/pcivar.h>
   85 
   86 #include <dev/an/if_aironet_ieee.h>
   87 #include <dev/an/if_anreg.h>
   88 
   89 struct an_type {
   90         u_int16_t               an_vid;
   91         u_int16_t               an_did;
   92         char                    *an_name;
   93 };
   94 
   95 #define AIRONET_VENDORID        0x14B9
   96 #define AIRONET_DEVICEID_35x    0x0350
   97 #define AIRONET_DEVICEID_4500   0x4500
   98 #define AIRONET_DEVICEID_4800   0x4800
   99 #define AIRONET_DEVICEID_4xxx   0x0001
  100 #define AIRONET_DEVICEID_MPI350 0xA504
  101 #define AN_PCI_PLX_LOIO         0x14    /* PLX chip iobase */
  102 #define AN_PCI_LOIO             0x18    /* Aironet iobase */
  103 
  104 static struct an_type an_devs[] = {
  105         { AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" },
  106         { AIRONET_VENDORID, AIRONET_DEVICEID_MPI350, "Cisco Aironet MPI350" },
  107         { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" },
  108         { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" },
  109         { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" },
  110         { 0, 0, NULL }
  111 };
  112 
  113 static int an_probe_pci         (device_t);
  114 static int an_attach_pci        (device_t);
  115 static int an_suspend_pci       (device_t);
  116 static int an_resume_pci        (device_t);
  117 
  118 static int
  119 an_probe_pci(device_t dev)
  120 {
  121         struct an_type          *t;
  122         uint16_t vid, did;
  123 
  124         t = an_devs;
  125         vid = pci_get_vendor(dev);
  126         did = pci_get_device(dev);
  127 
  128         while (t->an_name != NULL) {
  129                 if (vid == t->an_vid &&
  130                     did == t->an_did) {
  131                         device_set_desc(dev, t->an_name);
  132                         return(BUS_PROBE_DEFAULT);
  133                 }
  134                 t++;
  135         }
  136 
  137         return(ENXIO);
  138 }
  139 
  140 static int
  141 an_attach_pci(dev)
  142         device_t                dev;
  143 {
  144         struct an_softc         *sc;
  145         int                     flags, error = 0;
  146 
  147         sc = device_get_softc(dev);
  148         bzero(sc, sizeof(struct an_softc));
  149         flags = device_get_flags(dev);
  150 
  151         /*
  152          * Setup the lock in PCI attachment since it skips the an_probe
  153          * function.
  154          */
  155         mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
  156             MTX_DEF);
  157 
  158         if (pci_get_vendor(dev) == AIRONET_VENDORID &&
  159             pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
  160                 sc->mpi350 = 1;
  161                 sc->port_rid = PCIR_BAR(0);
  162         } else {
  163                 sc->port_rid = AN_PCI_LOIO;
  164         }
  165         error = an_alloc_port(dev, sc->port_rid, 1);
  166 
  167         if (error) {
  168                 device_printf(dev, "couldn't map ports\n");
  169                 goto fail;
  170         }
  171 
  172         /* Allocate memory for MPI350 */
  173         if (sc->mpi350) {
  174                 /* Allocate memory */
  175                 sc->mem_rid = PCIR_BAR(1);
  176                 error = an_alloc_memory(dev, sc->mem_rid, 1);
  177                 if (error) {
  178                         device_printf(dev, "couldn't map memory\n");
  179                         goto fail;
  180                 }
  181 
  182                 /* Allocate aux. memory */
  183                 sc->mem_aux_rid = PCIR_BAR(2);
  184                 error = an_alloc_aux_memory(dev, sc->mem_aux_rid, 
  185                     AN_AUX_MEM_SIZE);
  186                 if (error) {
  187                         device_printf(dev, "couldn't map aux memory\n");
  188                         goto fail;
  189                 }
  190 
  191                 /* Allocate DMA region */
  192                 error = bus_dma_tag_create(bus_get_dma_tag(dev),/* parent */
  193                                1, 0,                    /* alignment, bounds */
  194                                BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  195                                BUS_SPACE_MAXADDR,       /* highaddr */
  196                                NULL, NULL,              /* filter, filterarg */
  197                                0x3ffff,                 /* maxsize XXX */
  198                                1,                       /* nsegments */
  199                                0xffff,                  /* maxsegsize XXX */
  200                                BUS_DMA_ALLOCNOW,        /* flags */
  201                                NULL,                    /* lockfunc */
  202                                NULL,                    /* lockarg */
  203                                &sc->an_dtag);
  204                 if (error) {
  205                         device_printf(dev, "couldn't get DMA region\n");
  206                         goto fail;
  207                 }
  208         }
  209 
  210         /* Allocate interrupt */
  211         error = an_alloc_irq(dev, 0, RF_SHAREABLE);
  212         if (error) {
  213                 device_printf(dev, "couldn't get interrupt\n");
  214                 goto fail;
  215         }
  216 
  217         sc->an_dev = dev;
  218         error = an_attach(sc, flags);
  219         if (error) {
  220                 device_printf(dev, "couldn't attach\n");
  221                 goto fail;
  222         }
  223 
  224         /*
  225          * Must setup the interrupt after the an_attach to prevent racing.
  226          */
  227         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
  228             NULL, an_intr, sc, &sc->irq_handle);
  229         if (error)
  230                 device_printf(dev, "couldn't setup interrupt\n");
  231 
  232 fail:
  233         if (error)
  234                 an_release_resources(dev);
  235         return(error);
  236 }
  237 
  238 static int
  239 an_suspend_pci(device_t dev)
  240 {
  241         an_shutdown(dev);
  242         
  243         return (0);
  244 }
  245 
  246 static int
  247 an_resume_pci(device_t dev)
  248 {
  249         an_resume(dev);
  250 
  251         return (0);
  252 }
  253 
  254 static device_method_t an_pci_methods[] = {
  255         /* Device interface */
  256         DEVMETHOD(device_probe,         an_probe_pci),
  257         DEVMETHOD(device_attach,        an_attach_pci),
  258         DEVMETHOD(device_detach,        an_detach),
  259         DEVMETHOD(device_shutdown,      an_shutdown),
  260         DEVMETHOD(device_suspend,       an_suspend_pci),
  261         DEVMETHOD(device_resume,        an_resume_pci),
  262         { 0, 0 }
  263 };
  264 
  265 static driver_t an_pci_driver = {
  266         "an",
  267         an_pci_methods,
  268         sizeof(struct an_softc),
  269 };
  270 
  271 static devclass_t an_devclass;
  272 
  273 DRIVER_MODULE(an, pci, an_pci_driver, an_devclass, 0, 0);
  274 MODULE_DEPEND(an, pci, 1, 1, 1);
  275 MODULE_DEPEND(an, wlan, 1, 1, 1);

Cache object: c7beb14a45ba9ea9b057b9548c145f5e


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