2 * Copyright (c) 2000 Mitsuru IWASAKI
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/socket.h>
36 #include <sys/module.h>
39 #include <machine/bus.h>
40 #include <machine/resource.h>
44 #include <net/if_arp.h>
45 #include <net/if_media.h>
47 #include <dev/ex/if_exreg.h>
48 #include <dev/ex/if_exvar.h>
50 #include <dev/pccard/pccardvar.h>
51 #include <dev/pccard/pccard_cis.h>
53 #include "pccarddevs.h"
55 static const struct pccard_product ex_pccard_products[] = {
56 PCMCIA_CARD(OLICOM, OC2220),
57 PCMCIA_CARD(OLICOM, OC2231),
58 PCMCIA_CARD(OLICOM, OC2232),
59 PCMCIA_CARD(INTEL, ETHEREXPPRO),
63 /* Bus Front End Functions */
64 static int ex_pccard_probe(device_t);
65 static int ex_pccard_attach(device_t);
68 ex_pccard_enet_ok(u_char *enaddr)
73 if (enaddr[0] == 0xff)
75 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
81 ex_pccard_silicom_cb(const struct pccard_tuple *tuple, void *arg)
86 if (tuple->code != CISTPL_FUNCE)
88 if (tuple->length != 15)
90 if (pccard_tuple_read_1(tuple, 6) != 6)
92 for (i = 0; i < 6; i++)
93 enaddr[i] = pccard_tuple_read_1(tuple, 7 + i);
98 ex_pccard_get_silicom_mac(device_t dev, u_char *ether_addr)
100 pccard_cis_scan(dev, ex_pccard_silicom_cb, ether_addr);
104 ex_pccard_probe(device_t dev)
106 const struct pccard_product *pp;
108 uint32_t fcn = PCCARD_FUNCTION_UNSPEC;
110 /* Make sure we're a network function */
111 error = pccard_get_function(dev, &fcn);
114 if (fcn != PCCARD_FUNCTION_NETWORK)
117 if ((pp = pccard_product_lookup(dev, ex_pccard_products,
118 sizeof(ex_pccard_products[0]), NULL)) != NULL) {
119 if (pp->pp_name != NULL)
120 device_set_desc(dev, pp->pp_name);
127 ex_pccard_attach(device_t dev)
129 struct ex_softc * sc = device_get_softc(dev);
131 u_char ether_addr[ETHER_ADDR_LEN];
137 if ((error = ex_alloc_resources(dev)) != 0) {
138 device_printf(dev, "ex_alloc_resources() failed!\n");
143 * Fill in several fields of the softc structure:
144 * - Hardware Ethernet address.
147 sc->irq_no = rman_get_start(sc->irq);
149 /* Try to get the ethernet address from the chip, then the CIS */
150 ex_get_address(sc, ether_addr);
151 if (!ex_pccard_enet_ok(ether_addr))
152 pccard_get_ether(dev, ether_addr);
153 if (!ex_pccard_enet_ok(ether_addr))
154 ex_pccard_get_silicom_mac(dev, ether_addr);
155 if (!ex_pccard_enet_ok(ether_addr)) {
156 device_printf(dev, "No NIC address found.\n");
160 bcopy(ether_addr, sc->enaddr, ETHER_ADDR_LEN);
162 if ((error = ex_attach(dev)) != 0) {
163 device_printf(dev, "ex_attach() failed!\n");
167 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
168 NULL, ex_intr, (void *)sc, &sc->ih);
170 device_printf(dev, "bus_setup_intr() failed!\n");
176 ex_release_resources(dev);
179 static device_method_t ex_pccard_methods[] = {
180 /* Device interface */
181 DEVMETHOD(device_probe, ex_pccard_probe),
182 DEVMETHOD(device_attach, ex_pccard_attach),
183 DEVMETHOD(device_detach, ex_detach),
188 static driver_t ex_pccard_driver = {
191 sizeof(struct ex_softc),
194 DRIVER_MODULE(ex, pccard, ex_pccard_driver, ex_devclass, 0, 0);