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/awi/if_awi_pccard.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) 2000 Atsushi Onoe <onoe@sm.sony.co.jp>
    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 ``AS IS'' AND ANY EXPRESS OR
   15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   24  */
   25 
   26 #include <sys/cdefs.h>
   27 __FBSDID("$FreeBSD: releng/5.4/sys/dev/awi/if_awi_pccard.c 141016 2005-01-30 01:00:13Z imp $");
   28 
   29 #include <sys/param.h>
   30 #include <sys/systm.h>
   31 #include <sys/kernel.h>
   32 #include <sys/socket.h>
   33 
   34 #include <sys/module.h>
   35 #include <sys/bus.h>
   36 
   37 #include <machine/bus.h>
   38 #include <machine/resource.h>
   39 #include <sys/rman.h>
   40  
   41 #include <net/if.h> 
   42 #include <net/if_arp.h>
   43 #include <net/if_media.h>
   44 #include <net/ethernet.h>
   45 
   46 #include <net80211/ieee80211_var.h>
   47 
   48 #include <dev/awi/am79c930reg.h>
   49 #include <dev/awi/am79c930var.h>
   50 #include <dev/awi/awireg.h>
   51 #include <dev/awi/awivar.h>
   52 
   53 #include <dev/pccard/pccardvar.h>
   54 
   55 #include "card_if.h"
   56 #include "pccarddevs.h"
   57 
   58 struct awi_pccard_softc {
   59         struct awi_softc        sc_awi;
   60 
   61         u_int8_t        sc_version[AWI_BANNER_LEN];
   62         int             sc_intr_mask;
   63         void            *sc_intrhand;
   64         struct resource *sc_irq_res;
   65         int             sc_irq_rid;
   66         struct resource *sc_port_res;
   67         int             sc_port_rid;
   68         struct resource *sc_mem_res;
   69         int             sc_mem_rid;
   70 };
   71 
   72 static const struct pccard_product awi_pccard_products[] = {
   73         PCMCIA_CARD(AMD, AM79C930, 0),
   74         PCMCIA_CARD(BAY, STACK_650, 0),
   75         PCMCIA_CARD(BAY, STACK_660, 0),
   76         PCMCIA_CARD(BAY, SURFER_PRO, 0),
   77         PCMCIA_CARD(ICOM, SL200, 0),
   78         PCMCIA_CARD(NOKIA, C020_WLAN, 0),
   79         PCMCIA_CARD(FARALLON, SKYLINE, 0),
   80         PCMCIA_CARD(ZOOM, AIR_4000, 0),
   81         { NULL }
   82 };
   83 
   84 static int awi_pccard_match(device_t);
   85 static int awi_pccard_probe(device_t);
   86 static int awi_pccard_attach(device_t);
   87 static int awi_pccard_detach(device_t);
   88 static void awi_pccard_shutdown(device_t);
   89 static int awi_pccard_enable(struct awi_softc *);
   90 static void awi_pccard_disable(struct awi_softc *);
   91 
   92 static int
   93 awi_pccard_match(device_t dev)
   94 {
   95         const struct pccard_product *pp;
   96 
   97         if ((pp = pccard_product_lookup(dev, awi_pccard_products,
   98             sizeof(awi_pccard_products[0]), NULL)) != NULL) {
   99                 if (pp->pp_name != NULL)
  100                         device_set_desc(dev, pp->pp_name);
  101                 return 0;
  102         }
  103         return ENXIO;
  104 }
  105 
  106 /*
  107  * Initialize the device - called from Slot manager.
  108  */
  109 static int
  110 awi_pccard_probe(device_t dev)
  111 {
  112         struct awi_pccard_softc *psc = device_get_softc(dev);
  113         struct awi_softc *sc = &psc->sc_awi;
  114         int error = 0;
  115 
  116         psc->sc_port_rid = 0;
  117         psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
  118             &psc->sc_port_rid, 0, ~0, AM79C930_IO_SIZE,
  119             rman_make_alignment_flags(AM79C930_IO_ALIGN) | RF_ACTIVE);
  120         if (!psc->sc_port_res)
  121                 return ENOMEM;
  122 
  123         sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
  124         sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
  125         am79c930_chip_init(&sc->sc_chip, 0);
  126         tsleep(sc, PWAIT, "awiprb", 1);
  127 
  128         awi_read_bytes(sc, AWI_BANNER, psc->sc_version, AWI_BANNER_LEN);
  129         if (memcmp(psc->sc_version, "PCnetMobile:", 12) != 0)  {
  130                 device_printf(dev, "awi_pccard_probe: bad banner: %12D\n",
  131                     psc->sc_version, " ");
  132                 error = ENXIO;
  133         } else
  134                 device_set_desc(dev, psc->sc_version);
  135         bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
  136             psc->sc_port_res);
  137         psc->sc_port_res = 0;
  138 
  139         return error;
  140 }
  141 
  142 static int
  143 awi_pccard_attach(device_t dev)
  144 {
  145         struct awi_pccard_softc *psc = device_get_softc(dev);
  146         struct awi_softc *sc = &psc->sc_awi;
  147         int error = 0;
  148 
  149         psc->sc_port_res = 0;
  150         psc->sc_irq_res = 0;
  151         psc->sc_mem_res = 0;
  152         psc->sc_intrhand = 0;
  153 
  154         psc->sc_port_rid = 0;
  155         psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
  156             &psc->sc_port_rid, 0, ~0, 16,
  157             rman_make_alignment_flags(64) | RF_ACTIVE);
  158         if (!psc->sc_port_res) {
  159                 device_printf(dev, "awi_pccard_attach: port alloc failed\n");
  160                 goto fail;
  161         }
  162         sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
  163         sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
  164 
  165         psc->sc_irq_rid = 0;
  166         psc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
  167             &psc->sc_irq_rid, RF_ACTIVE);
  168         if (!psc->sc_irq_res) {
  169                 device_printf(dev, "awi_pccard_attach: irq alloc failed\n");
  170                 goto fail;
  171         }
  172 
  173         psc->sc_mem_rid = 0;
  174 #if 1
  175         /*
  176          * XXX: awi needs to access memory with 8bit,
  177          * but pccardd apparently maps memory with MDF_16BITS flag.
  178          * So memory mapped access is disabled and use IO port instead.
  179          * Also, memory mapping is not yet supported on pccard.
  180          */
  181         psc->sc_mem_res = 0;
  182 #else
  183         psc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
  184             &psc->sc_mem_rid, 0, ~0, 0x8000, RF_ACTIVE);
  185 #endif
  186         if (psc->sc_mem_res) {
  187                 sc->sc_chip.sc_memt = rman_get_bustag(psc->sc_mem_res);
  188                 sc->sc_chip.sc_memh = rman_get_bushandle(psc->sc_mem_res);
  189                 am79c930_chip_init(&sc->sc_chip, 1);
  190         } else
  191                 am79c930_chip_init(&sc->sc_chip, 0);
  192 
  193         sc->sc_dev = dev;
  194         sc->sc_cansleep = 1;
  195         sc->sc_enable = awi_pccard_enable;
  196         sc->sc_disable = awi_pccard_disable;
  197 
  198         if (awi_pccard_enable(sc))
  199                 goto fail;
  200         sc->sc_enabled = 1;
  201         error = awi_attach(sc);
  202         sc->sc_enabled = 0;     /*XXX*/
  203         awi_pccard_disable(sc);
  204         if (error == 0)
  205                 return 0;
  206         device_printf(dev, "awi_pccard_attach: awi_attach failed\n");
  207 
  208   fail:
  209         awi_pccard_detach(dev);
  210         if (error == 0)
  211                 error = ENXIO;
  212         return error;
  213 }
  214 
  215 static int
  216 awi_pccard_detach(device_t dev)
  217 {
  218         struct awi_pccard_softc *psc = device_get_softc(dev);
  219         struct awi_softc *sc = &psc->sc_awi;
  220 
  221         awi_detach(sc);
  222         if (psc->sc_mem_res) {
  223                 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
  224                     psc->sc_mem_res);
  225                 psc->sc_mem_res = 0;
  226         }
  227         if (psc->sc_irq_res) {
  228                 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
  229                     psc->sc_irq_res);
  230                 psc->sc_irq_res = 0;
  231         }
  232         if (psc->sc_port_res) {
  233                 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
  234                     psc->sc_port_res);
  235                 psc->sc_port_res = 0;
  236         }
  237         return 0;
  238 }
  239 
  240 static void
  241 awi_pccard_shutdown(device_t dev)
  242 {
  243         struct awi_pccard_softc *psc = device_get_softc(dev);
  244         struct awi_softc *sc = &psc->sc_awi;
  245 
  246         awi_shutdown(sc);
  247 }
  248 
  249 static int
  250 awi_pccard_enable(struct awi_softc *sc)
  251 {
  252         device_t dev = sc->sc_dev;
  253         struct awi_pccard_softc *psc = device_get_softc(dev);
  254         int error;
  255 
  256         if (psc->sc_intrhand == 0) {
  257                 error = bus_setup_intr(dev, psc->sc_irq_res, INTR_TYPE_NET,
  258                     (void (*)(void *))awi_intr, sc, &psc->sc_intrhand);
  259                 if (error) {
  260                         device_printf(dev,
  261                             "couldn't establish interrupt error=%d\n", error);
  262                         return error;
  263                 }
  264         }
  265         return 0;
  266 }
  267 
  268 static void
  269 awi_pccard_disable(struct awi_softc *sc)
  270 {
  271         device_t dev = sc->sc_dev;
  272         struct awi_pccard_softc *psc = device_get_softc(dev);
  273 
  274         if (psc->sc_intrhand) {
  275                 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
  276                 psc->sc_intrhand = 0;
  277         }
  278 }
  279 
  280 static device_method_t awi_pccard_methods[] = {
  281         /* Device interface */
  282         DEVMETHOD(device_probe,         pccard_compat_probe),
  283         DEVMETHOD(device_attach,        pccard_compat_attach),
  284         DEVMETHOD(device_detach,        awi_pccard_detach),
  285         DEVMETHOD(device_shutdown,      awi_pccard_shutdown),
  286 
  287         /* Card interface */
  288         DEVMETHOD(card_compat_match,    awi_pccard_match),
  289         DEVMETHOD(card_compat_probe,    awi_pccard_probe),
  290         DEVMETHOD(card_compat_attach,   awi_pccard_attach),
  291 
  292         { 0, 0 }
  293 };
  294 
  295 static driver_t awi_pccard_driver = {
  296         "awi",
  297         awi_pccard_methods,
  298         sizeof(struct awi_pccard_softc),
  299 };
  300 
  301 extern devclass_t awi_devclass;
  302 
  303 DRIVER_MODULE(awi, pccard, awi_pccard_driver, awi_devclass, 0, 0);
  304 MODULE_DEPEND(awi, wlan, 1, 1, 1);

Cache object: beac59aa57e1022770005d6e024030f5


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