2 * Copyright (c) 1995, David Greenman
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 unmodified, this list of conditions, and the following
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.
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
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/socket.h>
33 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <machine/bus.h>
39 #include <net/ethernet.h>
41 #include <net/if_arp.h>
42 #include <net/if_mib.h>
44 #include <dev/ed/if_edvar.h>
45 #include <dev/pccard/pccardvar.h>
48 * PC-Card (PCMCIA) specific code.
50 static int ed_pccard_probe(device_t);
51 static int ed_pccard_attach(device_t);
52 static int ed_pccard_detach(device_t);
54 static device_method_t ed_pccard_methods[] = {
55 /* Device interface */
56 DEVMETHOD(device_probe, ed_pccard_probe),
57 DEVMETHOD(device_attach, ed_pccard_attach),
58 DEVMETHOD(device_detach, ed_pccard_detach),
63 static driver_t ed_pccard_driver = {
66 sizeof(struct ed_softc)
69 static devclass_t ed_pccard_devclass;
71 DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_pccard_devclass, 0, 0);
74 * ed_pccard_detach - unload the driver and clear the table.
76 * This is usually called when the card is ejected, but
77 * can be caused by a modunload of a controller driver.
78 * The idea is to reset the driver's view of the device
79 * and ensure that any driver entry points such as
80 * read and write do not hang.
83 ed_pccard_detach(device_t dev)
85 struct ed_softc *sc = device_get_softc(dev);
86 struct ifnet *ifp = &sc->arpcom.ac_if;
89 device_printf(dev, "already unloaded\n");
93 ifp->if_flags &= ~IFF_RUNNING;
96 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
97 ed_release_resources(dev);
102 * Probe framework for pccards. Replicates the standard framework,
103 * minus the pccard driver registration and ignores the ether address
104 * supplied (from the CIS), relying on the probe to find it instead.
107 ed_pccard_probe(device_t dev)
111 error = ed_probe_Novell(dev);
114 ed_release_resources(dev);
116 error = ed_probe_WD80x3(dev);
119 ed_release_resources(dev);
123 error = ed_alloc_irq(dev, 0, 0);
125 ed_release_resources(dev);
130 ed_pccard_attach(device_t dev)
132 struct ed_softc *sc = device_get_softc(dev);
133 int flags = device_get_flags(dev);
137 u_char ether_addr[ETHER_ADDR_LEN];
139 if (sc->port_used > 0)
140 ed_alloc_port(dev, sc->port_rid, sc->port_used);
142 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used);
143 ed_alloc_irq(dev, sc->irq_rid, 0);
145 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
146 edintr, sc, &sc->irq_handle);
148 printf("setup intr failed %d \n", error);
149 ed_release_resources(dev);
153 if (ed_get_Linksys(sc) == 0) {
154 pccard_get_ether(dev, ether_addr);
155 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
156 sum |= ether_addr[i];
158 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
161 error = ed_attach(sc, device_get_unit(dev), flags);