if_fe_pccard.c revision 66235
1/* 2 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995 3 * 4 * This software may be used, modified, copied, distributed, and sold, in 5 * both source and binary form provided that the above copyright, these 6 * terms and the following disclaimer are retained. The name of the author 7 * and/or the contributor may not be used to endorse or promote products 8 * derived from this software without specific prior written permission. 9 * 10 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND 11 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE 14 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 15 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 16 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION. 17 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 18 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 20 * SUCH DAMAGE. 21 * 22 * $FreeBSD: head/sys/dev/fe/if_fe_pccard.c 66235 2000-09-22 09:59:23Z nyan $ 23 */ 24 25#include "opt_fe.h" 26#include "opt_inet.h" 27#include "opt_ipx.h" 28 29#include <sys/param.h> 30#include <sys/kernel.h> 31#include <sys/socket.h> 32#include <sys/module.h> 33#include <machine/clock.h> 34 35#include <sys/bus.h> 36#include <machine/bus.h> 37#include <machine/resource.h> 38 39#include <net/ethernet.h> 40#include <net/if.h> 41#include <net/if_mib.h> 42#include <net/if_media.h> 43 44#include <netinet/in.h> 45#include <netinet/if_ether.h> 46 47#include <i386/isa/ic/mb86960.h> 48#include <dev/fe/if_fereg.h> 49#include <dev/fe/if_fevar.h> 50 51#include <dev/pccard/pccardvar.h> 52#include <pccard/cardinfo.h> 53 54/* 55 * PC-Card (PCMCIA) specific code. 56 */ 57static int fe_pccard_probe(device_t); 58static int fe_pccard_attach(device_t); 59static int fe_pccard_detach(device_t); 60 61static device_method_t fe_pccard_methods[] = { 62 /* Device interface */ 63 DEVMETHOD(device_probe, fe_pccard_probe), 64 DEVMETHOD(device_attach, fe_pccard_attach), 65 DEVMETHOD(device_detach, fe_pccard_detach), 66 67 { 0, 0 } 68}; 69 70static driver_t fe_pccard_driver = { 71 "fe", 72 fe_pccard_methods, 73 sizeof (struct fe_softc) 74}; 75 76DRIVER_MODULE(fe, pccard, fe_pccard_driver, fe_devclass, 0, 0); 77 78 79static int fe_probe_mbh(device_t); 80static int fe_probe_tdk(device_t); 81 82/* 83 * Initialize the device - called from Slot manager. 84 */ 85static int 86fe_pccard_probe(device_t dev) 87{ 88 struct fe_softc *sc; 89 int error; 90 91 /* Prepare for the device probe process. */ 92 sc = device_get_softc(dev); 93 sc->sc_unit = device_get_unit(dev); 94 95 pccard_get_ether(dev, sc->sc_enaddr); 96 97 /* Probe for supported cards. */ 98 if ((error = fe_probe_mbh(dev)) == 0) 99 goto end; 100 fe_release_resource(dev); 101 102 if ((error = fe_probe_tdk(dev)) == 0) 103 goto end; 104 fe_release_resource(dev); 105 106end: 107 if (error == 0) 108 error = fe_alloc_irq(dev, 0); 109 110 fe_release_resource(dev); 111 return (error); 112} 113 114static int 115fe_pccard_attach(device_t dev) 116{ 117 struct fe_softc *sc = device_get_softc(dev); 118 119 if (sc->port_used) 120 fe_alloc_port(dev, sc->port_used); 121 fe_alloc_irq(dev, 0); 122 123 return fe_attach(dev); 124} 125 126/* 127 * feunload - unload the driver and clear the table. 128 * XXX TODO: 129 * This is usually called when the card is ejected, but 130 * can be caused by a modunload of a controller driver. 131 * The idea is to reset the driver's view of the device 132 * and ensure that any driver entry points such as 133 * read and write do not hang. 134 */ 135static int 136fe_pccard_detach(device_t dev) 137{ 138 struct fe_softc *sc = device_get_softc(dev); 139 struct ifnet *ifp = &sc->arpcom.ac_if; 140 141 fe_stop(sc); 142 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); 143 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 144 fe_release_resource(dev); 145 146 return 0; 147} 148 149 150/* 151 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface. 152 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk(). 153 */ 154static void 155fe_init_mbh(struct fe_softc *sc) 156{ 157 /* Minimal initialization of 86960. */ 158 DELAY(200); 159 fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 160 DELAY(200); 161 162 /* Disable all interrupts. */ 163 fe_outb(sc, FE_DLCR2, 0); 164 fe_outb(sc, FE_DLCR3, 0); 165 166 /* Enable master interrupt flag. */ 167 fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE); 168} 169 170static int 171fe_probe_mbh(device_t dev) 172{ 173 struct fe_softc *sc = device_get_softc(dev); 174 175 static struct fe_simple_probe_struct probe_table [] = { 176 { FE_DLCR2, 0x58, 0x00 }, 177 { FE_DLCR4, 0x08, 0x00 }, 178 { FE_DLCR6, 0xFF, 0xB6 }, 179 { 0 } 180 }; 181 182 /* MBH10302 occupies 32 I/O addresses. */ 183 if (fe_alloc_port(dev, 32)) 184 return ENXIO; 185 186 /* Ethernet MAC address should *NOT* have been given by pccardd, 187 if this is a true MBH10302; i.e., Ethernet address must be 188 "all-zero" upon entry. */ 189 if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] || 190 sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5]) 191 return ENXIO; 192 193 /* Fill the softc struct with default values. */ 194 fe_softc_defaults(sc); 195 196 /* 197 * See if MBH10302 is on its address. 198 * I'm not sure the following probe code works. FIXME. 199 */ 200 if (!fe_simple_probe(sc, probe_table)) 201 return ENXIO; 202 203 /* Get our station address from EEPROM. */ 204 fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN); 205 206 /* Make sure we got a valid station address. */ 207 if (!valid_Ether_p(sc->sc_enaddr, 0)) 208 return ENXIO; 209 210 /* Determine the card type. */ 211 sc->type = FE_TYPE_MBH; 212 sc->typestr = "MBH10302 (PCMCIA)"; 213 214 /* We seems to need our own IDENT bits... FIXME. */ 215 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE; 216 217 /* Setup hooks. We need a special initialization procedure. */ 218 sc->init = fe_init_mbh; 219 220 return 0; 221} 222 223/* 224 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface. 225 * by MASUI Kenji <masui@cs.titech.ac.jp> 226 * 227 * (Contec uses TDK Ethenet chip -- hosokawa) 228 * 229 * This version of fe_probe_tdk has been rewrote to handle 230 * *generic* PC card implementation of Fujitsu MB8696x family. The 231 * name _tdk is just for a historical reason. :-) 232 */ 233static int 234fe_probe_tdk (device_t dev) 235{ 236 struct fe_softc *sc = device_get_softc(dev); 237 238 static struct fe_simple_probe_struct probe_table [] = { 239 { FE_DLCR2, 0x50, 0x00 }, 240 { FE_DLCR4, 0x08, 0x00 }, 241 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */ 242 { 0 } 243 }; 244 245 /* C-NET(PC)C occupies 16 I/O addresses. */ 246 if (fe_alloc_port(dev, 16)) 247 return ENXIO; 248 249 /* Fill the softc struct with default values. */ 250 fe_softc_defaults(sc); 251 252 /* 253 * See if C-NET(PC)C is on its address. 254 */ 255 if (!fe_simple_probe(sc, probe_table)) 256 return ENXIO; 257 258 /* Determine the card type. */ 259 sc->type = FE_TYPE_TDK; 260 sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)"; 261 262 /* Make sure we got a valid station address. */ 263 if (!valid_Ether_p(sc->sc_enaddr, 0)) 264 return ENXIO; 265 266 return 0; 267} 268