if_ed_pccard.c revision 63090
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 * $FreeBSD: head/sys/dev/ed/if_ed_pccard.c 63090 2000-07-13 22:54:34Z archie $ 28 */ 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/socket.h> 33#include <sys/kernel.h> 34 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <machine/bus.h> 38 39#include <net/ethernet.h> 40#include <net/if.h> 41#include <net/if_arp.h> 42#include <net/if_mib.h> 43 44#include <dev/ed/if_edvar.h> 45#include <dev/pccard/pccardvar.h> 46 47/* 48 * PC-Card (PCMCIA) specific code. 49 */ 50static int ed_pccard_probe(device_t); 51static int ed_pccard_attach(device_t); 52static int ed_pccard_detach(device_t); 53 54static 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), 59 60 { 0, 0 } 61}; 62 63static driver_t ed_pccard_driver = { 64 "ed", 65 ed_pccard_methods, 66 sizeof(struct ed_softc) 67}; 68 69static devclass_t ed_pccard_devclass; 70 71DRIVER_MODULE(ed, pccard, ed_pccard_driver, ed_pccard_devclass, 0, 0); 72 73/* 74 * ed_pccard_detach - unload the driver and clear the table. 75 * XXX TODO: 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. 81 */ 82static int 83ed_pccard_detach(device_t dev) 84{ 85 struct ed_softc *sc = device_get_softc(dev); 86 struct ifnet *ifp = &sc->arpcom.ac_if; 87 88 if (sc->gone) { 89 device_printf(dev, "already unloaded\n"); 90 return (0); 91 } 92 ed_stop(sc); 93 ifp->if_flags &= ~IFF_RUNNING; 94 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); 95 sc->gone = 1; 96 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 97 ed_release_resources(dev); 98 return (0); 99} 100 101/* 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. 105 */ 106static int 107ed_pccard_probe(device_t dev) 108{ 109 int error; 110 111 error = ed_probe_Novell(dev); 112 if (error == 0) 113 goto end; 114 ed_release_resources(dev); 115 116 error = ed_probe_WD80x3(dev); 117 if (error == 0) 118 goto end; 119 ed_release_resources(dev); 120 121end: 122 if (error == 0) 123 error = ed_alloc_irq(dev, 0, 0); 124 125 ed_release_resources(dev); 126 return (error); 127} 128 129static int 130ed_pccard_attach(device_t dev) 131{ 132 struct ed_softc *sc = device_get_softc(dev); 133 int flags = device_get_flags(dev); 134 int error; 135 int i; 136 u_char sum; 137 u_char ether_addr[ETHER_ADDR_LEN]; 138 139 if (sc->port_used > 0) 140 ed_alloc_port(dev, sc->port_rid, sc->port_used); 141 if (sc->mem_used) 142 ed_alloc_memory(dev, sc->mem_rid, sc->mem_used); 143 ed_alloc_irq(dev, sc->irq_rid, 0); 144 145 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET, 146 edintr, sc, &sc->irq_handle); 147 if (error) { 148 printf("setup intr failed %d \n", error); 149 ed_release_resources(dev); 150 return (error); 151 } 152 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]; 157 if (sum) 158 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 159 } 160 161 error = ed_attach(sc, device_get_unit(dev), flags); 162 return (error); 163} 164