1 /* 2 * Copyright (c) 1999 M. Warner Losh <imp@village.org> 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 ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $FreeBSD: src/sys/dev/sn/if_sn_pccard.c,v 1.3.2.2 2001/01/25 19:40:27 imp Exp $ 26 * $DragonFly: src/sys/dev/netif/sn/if_sn_pccard.c,v 1.6 2004/03/14 15:36:52 joerg Exp $ 27 */ 28 29 /* 30 * Modifications for Megahertz X-Jack Ethernet Card (XJ-10BT) 31 * 32 * Copyright (c) 1996 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org> 33 * BSD-nomads, Tokyo, Japan. 34 */ 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/socket.h> 40 41 #include <sys/module.h> 42 #include <sys/bus.h> 43 44 #include <machine/bus.h> 45 #include <machine/resource.h> 46 #include <sys/rman.h> 47 48 #include <net/ethernet.h> 49 #include <net/if.h> 50 #include <net/if_arp.h> 51 #include <net/if_media.h> 52 53 #include <machine/clock.h> 54 55 #include "if_snreg.h" 56 #include "if_snvar.h" 57 #include <bus/pccard/pccardvar.h> 58 #include <bus/pccard/pccarddevs.h> 59 60 #include "card_if.h" 61 62 static const struct pccard_product sn_pccard_products[] = { 63 PCMCIA_CARD(DSPSI, XJACK, 0), 64 PCMCIA_CARD(NEWMEDIA, BASICS, 0), 65 #if 0 66 PCMCIA_CARD(SMC, 8020BT, 0), 67 #endif 68 { NULL } 69 }; 70 71 static int 72 sn_pccard_match(device_t dev) 73 { 74 const struct pccard_product *pp; 75 76 if ((pp = pccard_product_lookup(dev, sn_pccard_products, 77 sizeof(sn_pccard_products[0]), NULL)) != NULL) { 78 if (pp->pp_name != NULL) 79 device_set_desc(dev, pp->pp_name); 80 return 0; 81 } 82 return EIO; 83 } 84 85 /* 86 * Initialize the device - called from Slot manager. 87 */ 88 static int 89 sn_pccard_probe(device_t dev) 90 { 91 return (sn_probe(dev, 1)); 92 } 93 94 static int 95 sn_pccard_attach(device_t dev) 96 { 97 struct sn_softc *sc = device_get_softc(dev); 98 int i; 99 uint8_t sum; 100 uint8_t *ether_addr; 101 102 sc->pccard_enaddr = 0; 103 ether_addr = pccard_get_ether(dev); 104 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++) 105 sum |= ether_addr[i]; 106 if (sum) { 107 sc->pccard_enaddr = 1; 108 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 109 } 110 111 return (sn_attach(dev)); 112 } 113 114 static int 115 sn_pccard_detach(device_t dev) 116 { 117 struct sn_softc *sc = device_get_softc(dev); 118 119 sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 120 ether_ifdetach(&sc->arpcom.ac_if); 121 sn_deactivate(dev); 122 return 0; 123 } 124 125 static device_method_t sn_pccard_methods[] = { 126 /* Device interface */ 127 DEVMETHOD(device_probe, pccard_compat_probe), 128 DEVMETHOD(device_attach, pccard_compat_attach), 129 DEVMETHOD(device_detach, sn_pccard_detach), 130 131 /* Card interface */ 132 DEVMETHOD(card_compat_match, sn_pccard_match), 133 DEVMETHOD(card_compat_probe, sn_pccard_probe), 134 DEVMETHOD(card_compat_attach, sn_pccard_attach), 135 136 { 0, 0 } 137 }; 138 139 static driver_t sn_pccard_driver = { 140 "sn", 141 sn_pccard_methods, 142 sizeof(struct sn_softc), 143 }; 144 145 extern devclass_t sn_devclass; 146 147 DRIVER_MODULE(if_sn, pccard, sn_pccard_driver, sn_devclass, 0, 0); 148