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/snc/if_snc_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) 1995, David Greenman
    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 unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  *
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: releng/8.4/sys/dev/snc/if_snc_pccard.c 181393 2008-08-07 20:55:20Z imp $");
   31 
   32 /*
   33  *      National Semiconductor  DP8393X SONIC Driver
   34  *
   35  *      This is the PC Card attachment on FreeBSD
   36  *              written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp> and
   37  *                         Hiroshi Yamashita <bluemoon@msj.biglobe.ne.jp>
   38  */
   39 
   40 #include <sys/param.h>
   41 #include <sys/systm.h>
   42 #include <sys/socket.h>
   43 #include <sys/kernel.h>
   44 
   45 #include <sys/module.h>
   46 #include <sys/bus.h>
   47 #include <machine/bus.h>
   48 
   49 #include <net/ethernet.h>
   50 #include <net/if.h>
   51 #include <net/if_arp.h>
   52 #include <net/if_media.h>
   53 
   54 #include <dev/snc/dp83932var.h>
   55 #include <dev/snc/if_sncvar.h>
   56 #include <dev/snc/if_sncreg.h>
   57 
   58 #include <dev/pccard/pccardvar.h>
   59 #include <dev/pccard/pccard_cis.h>
   60 #include "pccarddevs.h"
   61 
   62 static const struct pccard_product snc_pccard_products[] = {
   63         PCMCIA_CARD(NEC, PC9801N_J02),
   64         PCMCIA_CARD(NEC, PC9801N_J02R),
   65         { NULL }
   66 };
   67 
   68 /*
   69  *      PC Card (PCMCIA) specific code.
   70  */
   71 static int      snc_pccard_probe(device_t);
   72 static int      snc_pccard_attach(device_t);
   73 static int      snc_pccard_detach(device_t);
   74 
   75 
   76 static device_method_t snc_pccard_methods[] = {
   77         /* Device interface */
   78         DEVMETHOD(device_probe,         snc_pccard_probe),
   79         DEVMETHOD(device_attach,        snc_pccard_attach),
   80         DEVMETHOD(device_detach,        snc_pccard_detach),
   81 
   82         { 0, 0 }
   83 };
   84 
   85 static driver_t snc_pccard_driver = {
   86         "snc",
   87         snc_pccard_methods,
   88         sizeof(struct snc_softc)
   89 };
   90 
   91 DRIVER_MODULE(snc, pccard, snc_pccard_driver, snc_devclass, 0, 0);
   92 MODULE_DEPEND(snc, ether, 1, 1, 1);
   93 
   94 /*
   95  *      snc_pccard_detach - detach this instance from the device.
   96  */
   97 static int
   98 snc_pccard_detach(device_t dev)
   99 {
  100         struct snc_softc *sc = device_get_softc(dev);
  101         struct ifnet *ifp = sc->sc_ifp;
  102 
  103         if (sc->gone) {
  104                 device_printf(dev, "already unloaded\n");
  105                 return (0);
  106         }
  107         SNC_LOCK(sc);
  108         sncshutdown(sc);
  109         SNC_UNLOCK(sc);
  110         callout_drain(&sc->sc_timer);
  111         ether_ifdetach(ifp);
  112         sc->gone = 1;
  113         bus_teardown_intr(dev, sc->irq, sc->irq_handle);
  114         snc_release_resources(dev);
  115         mtx_destroy(&sc->sc_lock);
  116         return (0);
  117 }
  118 
  119 /* 
  120  * Probe the pccard.
  121  */
  122 static int
  123 snc_pccard_probe(device_t dev)
  124 {
  125         const struct pccard_product *pp;
  126 
  127         if ((pp = pccard_product_lookup(dev, snc_pccard_products,
  128             sizeof(snc_pccard_products[0]), NULL)) == NULL)
  129                 return (EIO);
  130         if (pp->pp_name != NULL)
  131                 device_set_desc(dev, pp->pp_name);
  132         return (0);
  133 }
  134 
  135 static int
  136 snc_pccard_attach(device_t dev)
  137 {
  138         struct snc_softc *sc = device_get_softc(dev);
  139         int error;
  140         
  141         /*
  142          * Not sure that this belongs here or in snc_pccard_attach
  143          */
  144         if ((error = snc_alloc_port(dev, 0)) != 0)
  145                 goto err;
  146         if ((error = snc_alloc_memory(dev, 0)) != 0)
  147                 goto err;
  148         if ((error = snc_alloc_irq(dev, 0, 0)) != 0)
  149                 goto err;
  150         if ((error = snc_probe(dev, SNEC_TYPE_PNP)) != 0)
  151                 goto err;
  152         /* This interface is always enabled. */
  153         sc->sc_enabled = 1;
  154         /* pccard_get_ether(dev, ether_addr); */
  155         if ((error = snc_attach(dev)) != 0)
  156                 goto err;
  157         return 0;
  158 err:;
  159         snc_release_resources(dev);
  160         return error;
  161 } 

Cache object: d1c4ea45cc24dc4316599b8d2c889d4e


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