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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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$");
   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 #include <dev/ex/if_exreg.h>
   48 #include <dev/ex/if_exvar.h>
   49 
   50 #include <dev/pccard/pccardvar.h>
   51 #include <dev/pccard/pccard_cis.h>
   52 
   53 #include "pccarddevs.h"
   54 
   55 static const struct pccard_product ex_pccard_products[] = {
   56         PCMCIA_CARD(OLICOM, OC2220, 0),
   57         PCMCIA_CARD(INTEL, ETHEREXPPRO, 0),
   58         { NULL }
   59 };
   60 
   61 /* Bus Front End Functions */
   62 static int      ex_pccard_match(device_t);
   63 static int      ex_pccard_probe(device_t);
   64 static int      ex_pccard_attach(device_t);
   65 
   66 static device_method_t ex_pccard_methods[] = {
   67         /* Device interface */
   68         DEVMETHOD(device_probe,         pccard_compat_probe),
   69         DEVMETHOD(device_attach,        pccard_compat_attach),
   70         DEVMETHOD(device_detach,        ex_detach),
   71 
   72         /* Card interface */
   73         DEVMETHOD(card_compat_match,    ex_pccard_match),
   74         DEVMETHOD(card_compat_probe,    ex_pccard_probe),
   75         DEVMETHOD(card_compat_attach,   ex_pccard_attach),
   76 
   77         { 0, 0 }
   78 };
   79 
   80 static driver_t ex_pccard_driver = {
   81         "ex",
   82         ex_pccard_methods,
   83         sizeof(struct ex_softc),
   84 };
   85 
   86 DRIVER_MODULE(ex, pccard, ex_pccard_driver, ex_devclass, 0, 0);
   87 
   88 static int
   89 ex_pccard_match(device_t dev)
   90 {
   91         const struct pccard_product *pp;
   92         int error;
   93         uint32_t        fcn = PCCARD_FUNCTION_UNSPEC;
   94 
   95         /* Make sure we're a network function */
   96         error = pccard_get_function(dev, &fcn);
   97         if (error != 0)
   98                 return (error);
   99         if (fcn != PCCARD_FUNCTION_NETWORK)
  100                 return (ENXIO);
  101 
  102         if ((pp = pccard_product_lookup(dev, ex_pccard_products,
  103             sizeof(ex_pccard_products[0]), NULL)) != NULL) {
  104                 if (pp->pp_name != NULL)
  105                         device_set_desc(dev, pp->pp_name);
  106                 return 0;
  107         }
  108         return EIO;
  109 }
  110 
  111 static int
  112 ex_pccard_probe(device_t dev)
  113 {
  114         u_int           iobase;
  115         u_int           irq;
  116 
  117         iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0);
  118         if (!iobase) {
  119                 printf("ex: no iobase?\n");
  120                 return(ENXIO);
  121         }
  122 
  123         if (bootverbose)
  124                 printf("ex: ex_pccard_probe() found card at 0x%03x\n", iobase);
  125 
  126         irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0);
  127 
  128         if (irq == 0) {
  129                 printf("ex: invalid IRQ.\n");
  130                 return(ENXIO);
  131         }
  132 
  133         return(0);
  134 }
  135 
  136 static int
  137 ex_pccard_enet_ok(u_char *enaddr)
  138 {
  139         int                     i;
  140         u_char                  sum;
  141 
  142         if (enaddr[0] == 0xff)
  143                 return (0);
  144         for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
  145                 sum |= enaddr[i];
  146         return (sum != 0);
  147 }
  148 
  149 #if 0
  150 #ifdef NETBSD_LIKE
  151 static int
  152 ex_pccard_silicom_cb(struct pccard_tuple *tuple, void *arg)
  153 {
  154         u_char *enaddr = arg;
  155 
  156         if (tuple->code != PCMCIA_CISTPL_FUNCE)
  157                 return (0);
  158         if (tuple->length != 15)
  159                 return (0);
  160         if (CARD_CIS_READ_1(tuple->dev, tuple, 6) != 6)
  161                 return (0);
  162         for (i = 0; i < 6; i++)
  163                 enaddr[i] = CARD_CIS_READ_1(tuple->dev, tuple, 7 + i);
  164         return (1);
  165 }
  166 #endif
  167 #endif
  168 
  169 static void
  170 ex_pccard_get_silicom_mac(device_t dev, u_char *ether_addr)
  171 {
  172 #if 0
  173 #ifdef  NETBSD_LIKE
  174         CARD_CIS_SCAN(dev, ex_pccard_silicom_cb, ether_addr);
  175 #endif
  176 #ifdef  CS_LIKE
  177         uint8_t buffer[64];
  178         tuple_t tuple;
  179         int i;
  180         
  181         tuple.TupleData = buffer;
  182         tuple.TupleDataMax = sizeof(buffer);
  183         tuple.TupleOffset = 0;
  184         tuple.DesiredTuple = CISTPL_FUNCE;
  185         tuple.Attributes = TUPLE_RETURN_COMMON;
  186         if (CARD_SERVICE(dev, GetFirstTuple, &tuple) != CS_SUCCESS)
  187                 return;
  188         if (CARD_SERVICES(dev, GetTupleData, &tuple) != CS_SUCCESS)
  189                 return;
  190         if (tuple.TupleLength != 15)
  191                 return;
  192         if (buffer[6] != 6)
  193                 return;
  194         for (i = 0; i < 6; i++)
  195                 ether_addr[i] = buffer[7 + i);
  196 #endif
  197 #endif
  198 }
  199 
  200 static int
  201 ex_pccard_attach(device_t dev)
  202 {
  203         struct ex_softc *       sc = device_get_softc(dev);
  204         int                     error = 0;
  205         u_char                  ether_addr[ETHER_ADDR_LEN];
  206 
  207         sc->dev = dev;
  208         sc->ioport_rid = 0;
  209         sc->irq_rid = 0;
  210 
  211         if ((error = ex_alloc_resources(dev)) != 0) {
  212                 device_printf(dev, "ex_alloc_resources() failed!\n");
  213                 goto bad;
  214         }
  215 
  216         /*
  217          * Fill in several fields of the softc structure:
  218          *      - Hardware Ethernet address.
  219          *      - IRQ number.
  220          */
  221         sc->irq_no = rman_get_start(sc->irq);
  222 
  223         /* Try to get the ethernet address from the chip, then the CIS */
  224         ex_get_address(sc, ether_addr);
  225         if (!ex_pccard_enet_ok(ether_addr))
  226                 pccard_get_ether(dev, ether_addr);
  227         if (!ex_pccard_enet_ok(ether_addr))
  228                 ex_pccard_get_silicom_mac(dev, ether_addr);
  229         if (!ex_pccard_enet_ok(ether_addr)) {
  230                 device_printf(dev, "No NIC address found.\n");
  231                 error = ENXIO;
  232                 goto bad;
  233         }
  234         bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
  235 
  236         if ((error = ex_attach(dev)) != 0) {
  237                 device_printf(dev, "ex_attach() failed!\n");
  238                 goto bad;
  239         }
  240 
  241         error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
  242             ex_intr, (void *)sc, &sc->ih);
  243         if (error) {
  244                 device_printf(dev, "bus_setup_intr() failed!\n");
  245                 goto bad;
  246         }
  247 
  248         return(0);
  249 bad:
  250         ex_release_resources(dev);
  251         return (error);
  252 }

Cache object: 14531b9137eb57ea22491649f0a23130


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