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/ex/if_ex_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 Mitsuru IWASAKI
    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 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: releng/5.2/sys/dev/ex/if_ex_pccard.c 121565 2003-10-26 06:34:22Z imp $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/kernel.h>
   34 #include <sys/socket.h>
   35 
   36 #include <sys/module.h>
   37 #include <sys/bus.h>
   38 
   39 #include <machine/bus.h>
   40 #include <machine/resource.h>
   41 #include <sys/rman.h>
   42 
   43 #include <net/if.h>
   44 #include <net/if_arp.h>
   45 #include <net/if_media.h> 
   46 
   47 
   48 #include <dev/ex/if_exreg.h>
   49 #include <dev/ex/if_exvar.h>
   50 
   51 #include <dev/pccard/pccardvar.h>
   52 #include <dev/pccard/pccarddevs.h>
   53 
   54 static const struct pccard_product ex_pccard_products[] = {
   55         PCMCIA_CARD(OLICOM, OC2220, 0),
   56         { NULL }
   57 };
   58 
   59 /* Bus Front End Functions */
   60 static int      ex_pccard_match         (device_t);
   61 static int      ex_pccard_probe         (device_t);
   62 static int      ex_pccard_attach        (device_t);
   63 
   64 static device_method_t ex_pccard_methods[] = {
   65         /* Device interface */
   66         DEVMETHOD(device_probe,         pccard_compat_probe),
   67         DEVMETHOD(device_attach,        pccard_compat_attach),
   68         DEVMETHOD(device_detach,        ex_detach),
   69 
   70         /* Card interface */
   71         DEVMETHOD(card_compat_match,    ex_pccard_match),
   72         DEVMETHOD(card_compat_probe,    ex_pccard_probe),
   73         DEVMETHOD(card_compat_attach,   ex_pccard_attach),
   74 
   75         { 0, 0 }
   76 };
   77 
   78 static driver_t ex_pccard_driver = {
   79         "ex",
   80         ex_pccard_methods,
   81         sizeof(struct ex_softc),
   82 };
   83 
   84 DRIVER_MODULE(ex, pccard, ex_pccard_driver, ex_devclass, 0, 0);
   85 
   86 static int
   87 ex_pccard_match(device_t dev)
   88 {
   89         const struct pccard_product *pp;
   90 
   91         if ((pp = pccard_product_lookup(dev, ex_pccard_products,
   92             sizeof(ex_pccard_products[0]), NULL)) != NULL) {
   93                 if (pp->pp_name != NULL)
   94                         device_set_desc(dev, pp->pp_name);
   95                 return 0;
   96         }
   97         return EIO;
   98 }
   99 
  100 static int
  101 ex_pccard_probe(device_t dev)
  102 {
  103         u_int           iobase;
  104         u_int           irq;
  105 
  106         iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0);
  107         if (!iobase) {
  108                 printf("ex: no iobase?\n");
  109                 return(ENXIO);
  110         }
  111 
  112         if (bootverbose)
  113                 printf("ex: ex_pccard_probe() found card at 0x%03x\n", iobase);
  114 
  115         irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0);
  116 
  117         if (irq == 0) {
  118                 printf("ex: invalid IRQ.\n");
  119                 return(ENXIO);
  120         }
  121 
  122         return(0);
  123 }
  124 
  125 static int
  126 ex_pccard_attach(device_t dev)
  127 {
  128         struct ex_softc *       sc = device_get_softc(dev);
  129         int                     error = 0;
  130         int                     i;
  131         u_char                  sum;
  132         u_char                  ether_addr[ETHER_ADDR_LEN];
  133 
  134         sc->dev = dev;
  135         sc->ioport_rid = 0;
  136         sc->irq_rid = 0;
  137 
  138         if ((error = ex_alloc_resources(dev)) != 0) {
  139                 device_printf(dev, "ex_alloc_resources() failed!\n");
  140                 goto bad;
  141         }
  142 
  143         /*
  144          * Fill in several fields of the softc structure:
  145          *      - I/O base address.
  146          *      - Hardware Ethernet address.
  147          *      - IRQ number.
  148          */
  149         sc->iobase = rman_get_start(sc->ioport);
  150         sc->irq_no = rman_get_start(sc->irq);
  151 
  152         pccard_get_ether(dev, ether_addr);
  153         for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
  154                 sum |= ether_addr[i];
  155         if (sum)
  156                 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
  157 
  158         if ((error = ex_attach(dev)) != 0) {
  159                 device_printf(dev, "ex_attach() failed!\n");
  160                 goto bad;
  161         }
  162 
  163         error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
  164                                 ex_intr, (void *)sc, &sc->ih);
  165         if (error) {
  166                 device_printf(dev, "bus_setup_intr() failed!\n");
  167                 goto bad;
  168         }
  169 
  170         return(0);
  171 bad:
  172         ex_release_resources(dev);
  173         return (error);
  174 }

Cache object: e8b0821a84b6f086d85ebc506bb963f7


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