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  * $FreeBSD$
   33  */
   34 
   35 /*
   36  * This is a PCI shim for the Aironet PC4500/4800 wireless network
   37  * driver. Aironet makes PCMCIA, ISA and PCI versions of these devices,
   38  * which all have basically the same interface. The ISA and PCI cards
   39  * are actually bridge adapters with PCMCIA cards inserted into them,
   40  * however they appear as normal PCI or ISA devices to the host.
   41  *
   42  * All we do here is handle the PCI probe and attach and set up an
   43  * interrupt handler entry point. The PCI version of the card uses
   44  * a PLX 9050 PCI to "dumb bus" bridge chip, which provides us with
   45  * multiple PCI address space mappings. The primary mapping at PCI
   46  * register 0x14 is for the PLX chip itself, *NOT* the Aironet card.
   47  * The I/O address of the Aironet is actually at register 0x18, which
   48  * is the local bus mapping register for bus space 0. There are also
   49  * registers for additional register spaces at registers 0x1C and
   50  * 0x20, but these are unused in the Aironet devices. To find out
   51  * more, you need a datasheet for the 9050 from PLX, but you have
   52  * to go through their sales office to get it. Bleh.
   53  */
   54 
   55 #include "opt_inet.h"
   56 
   57 #ifdef INET
   58 #define ANCACHE
   59 #endif
   60 
   61 #include <sys/param.h>
   62 #include <sys/systm.h>
   63 #include <sys/sockio.h>
   64 #include <sys/mbuf.h>
   65 #include <sys/malloc.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 <machine/resource.h>
   74 
   75 #include <net/if.h>
   76 #include <net/if_arp.h>
   77 #include <net/ethernet.h>
   78 #include <net/if_dl.h>
   79 #include <net/if_media.h>
   80 
   81 #include <pci/pcireg.h>
   82 #include <pci/pcivar.h>
   83 
   84 #ifndef lint
   85 static const char rcsid[] =
   86  "$FreeBSD$";
   87 #endif
   88 
   89 #include <dev/an/if_aironet_ieee.h>
   90 #include <dev/an/if_anreg.h>
   91 
   92 struct an_type {
   93         u_int16_t               an_vid;
   94         u_int16_t               an_did;
   95         char                    *an_name;
   96 };
   97 
   98 #define AIRONET_VENDORID        0x14B9
   99 #define AIRONET_DEVICEID_35x    0x0350
  100 #define AIRONET_DEVICEID_4500   0x4500
  101 #define AIRONET_DEVICEID_4800   0x4800
  102 #define AIRONET_DEVICEID_4xxx   0x0001
  103 #define AIRONET_DEVICEID_MPI350 0xA504
  104 #define AN_PCI_PLX_LOIO         0x14    /* PLX chip iobase */
  105 #define AN_PCI_LOIO             0x18    /* Aironet iobase */
  106 
  107 static struct an_type an_devs[] = {
  108         { AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" },
  109         { AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" },
  110         { AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" },
  111         { AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" },
  112         { 0, 0, NULL }
  113 };
  114 
  115 static int an_probe_pci         __P((device_t));
  116 static int an_attach_pci        __P((device_t));
  117 static int an_detach_pci        __P((device_t));
  118 static int an_suspend_pci       __P((device_t));
  119 static int an_resume_pci        __P((device_t));
  120 
  121 static int
  122 an_probe_pci(device_t dev)
  123 {
  124         struct an_type          *t;
  125 
  126         t = an_devs;
  127 
  128         while (t->an_name != NULL) {
  129                 if (pci_get_vendor(dev) == t->an_vid &&
  130                     pci_get_device(dev) == t->an_did) {
  131                         device_set_desc(dev, t->an_name);
  132                         return(0);
  133                 }
  134                 t++;
  135         }
  136 
  137         if (pci_get_vendor(dev) == AIRONET_VENDORID &&
  138             pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
  139                 device_set_desc(dev, "Cisco Aironet MPI350");
  140                 return(0);
  141         }
  142 
  143         return(ENXIO);
  144 }
  145 
  146 static int
  147 an_attach_pci(dev)
  148         device_t                dev;
  149 {
  150         int                     s;
  151         u_int32_t               command;
  152         struct an_softc         *sc;
  153         int                     unit, flags, error = 0;
  154 
  155         s = splimp();
  156 
  157         sc = device_get_softc(dev);
  158         unit = device_get_unit(dev);
  159         flags = device_get_flags(dev);
  160         bzero(sc, sizeof(struct an_softc));
  161 
  162         if (pci_get_vendor(dev) == AIRONET_VENDORID &&
  163             pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
  164                 sc->mpi350 = 1;
  165                 sc->port_rid = PCIR_MAPS;
  166         } else {
  167                 /*
  168                  * Map control/status registers.
  169                  */
  170                 command = pci_read_config(dev, PCIR_COMMAND, 4);
  171                 command |= PCIM_CMD_PORTEN;
  172                 pci_write_config(dev, PCIR_COMMAND, command, 4);
  173                 command = pci_read_config(dev, PCIR_COMMAND, 4);
  174 
  175                 if (!(command & PCIM_CMD_PORTEN)) {
  176                         printf("an%d: failed to enable I/O ports!\n", unit);
  177                         error = ENXIO;
  178                         goto fail;
  179                 }
  180                 sc->port_rid = AN_PCI_LOIO;
  181         }
  182         error = an_alloc_port(dev, sc->port_rid, 1);
  183 
  184         if (error) {
  185                 printf("an%d: couldn't map ports\n", unit);
  186                 goto fail;
  187         }
  188 
  189         sc->an_btag = rman_get_bustag(sc->port_res);
  190         sc->an_bhandle = rman_get_bushandle(sc->port_res);
  191 
  192         /* Allocate memory for MPI350 */
  193         if (sc->mpi350) {
  194                 /* Allocate memory */
  195                 sc->mem_rid = PCIR_MAPS + 4;
  196                 error = an_alloc_memory(dev, sc->mem_rid, 1);
  197                 if (error) {
  198                         printf("an%d: couldn't map memory\n", unit);
  199                         goto fail;
  200                 }
  201                 sc->an_mem_btag = rman_get_bustag(sc->mem_res);
  202                 sc->an_mem_bhandle = rman_get_bushandle(sc->mem_res);
  203 
  204                 /* Allocate aux. memory */
  205                 sc->mem_aux_rid = PCIR_MAPS + 8;
  206                 error = an_alloc_aux_memory(dev, sc->mem_aux_rid, 
  207                     AN_AUX_MEM_SIZE);
  208                 if (error) {
  209                         printf("an%d: couldn't map aux memory\n", unit);
  210                         goto fail;
  211                 }
  212                 sc->an_mem_aux_btag = rman_get_bustag(sc->mem_aux_res);
  213                 sc->an_mem_aux_bhandle = rman_get_bushandle(sc->mem_aux_res);
  214 
  215                 /* Allocate DMA region */
  216                 error = bus_dma_tag_create(NULL,        /* parent */
  217                                1, 0,                    /* alignment, bounds */
  218                                BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  219                                BUS_SPACE_MAXADDR,       /* highaddr */
  220                                NULL, NULL,              /* filter, filterarg */
  221                                0x3ffff,                 /* maxsize XXX */
  222                                1,                       /* nsegments */
  223                                0xffff,                  /* maxsegsize XXX */
  224                                BUS_DMA_ALLOCNOW,        /* flags */
  225                                &sc->an_dtag);
  226                 if (error) {
  227                         printf("an%d: couldn't get DMA region\n", unit);
  228                         goto fail;
  229                 }
  230         }
  231 
  232         /* Allocate interrupt */
  233         error = an_alloc_irq(dev, 0, RF_SHAREABLE);
  234         if (error) {
  235                 goto fail;
  236         }
  237 
  238         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
  239             an_intr, sc, &sc->irq_handle);
  240         if (error) {
  241                 goto fail;
  242         }
  243 
  244         sc->an_dev = dev;
  245         error = an_attach(sc, device_get_unit(dev), flags);
  246 
  247 fail:
  248         if (error)
  249                 an_release_resources(dev);
  250         splx(s);
  251 
  252         return(error);
  253 }
  254 
  255 static int
  256 an_detach_pci(device_t dev)
  257 {
  258         struct an_softc         *sc = device_get_softc(dev);
  259         struct ifnet            *ifp = &sc->arpcom.ac_if;
  260 
  261         an_stop(sc);
  262         ifmedia_removeall(&sc->an_ifmedia);
  263         ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
  264         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
  265         an_release_resources(dev);
  266 
  267         return (0);
  268 }
  269 
  270 static int
  271 an_suspend_pci(device_t dev)
  272 {
  273         an_shutdown(dev);
  274         
  275         return (0);
  276 }
  277 
  278 static int
  279 an_resume_pci(device_t dev)
  280 {
  281         an_resume(dev);
  282 
  283         return (0);
  284 }
  285 
  286 static device_method_t an_pci_methods[] = {
  287         /* Device interface */
  288         DEVMETHOD(device_probe,         an_probe_pci),
  289         DEVMETHOD(device_attach,        an_attach_pci),
  290         DEVMETHOD(device_detach,        an_detach_pci),
  291         DEVMETHOD(device_shutdown,      an_shutdown),
  292         DEVMETHOD(device_suspend,       an_suspend_pci),
  293         DEVMETHOD(device_resume,        an_resume_pci),
  294         { 0, 0 }
  295 };
  296 
  297 static driver_t an_pci_driver = {
  298         "an",
  299         an_pci_methods,
  300         sizeof(struct an_softc),
  301 };
  302 
  303 static devclass_t an_devclass;
  304 
  305 DRIVER_MODULE(if_an, pci, an_pci_driver, an_devclass, 0, 0);

Cache object: 043b16a053f4113da204f09412e13a56


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