if_fe_pccard.c revision 113315
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 113315 2003-04-10 04:36:02Z imp $ 23 */ 24 25#include <sys/param.h> 26#include <sys/kernel.h> 27#include <sys/socket.h> 28#include <sys/systm.h> 29#include <sys/module.h> 30 31#include <sys/bus.h> 32#include <machine/bus.h> 33#include <machine/resource.h> 34 35#include <net/ethernet.h> 36#include <net/if.h> 37#include <net/if_mib.h> 38#include <net/if_media.h> 39 40#include <netinet/in.h> 41#include <netinet/if_ether.h> 42 43#include <i386/isa/ic/mb86960.h> 44#include <dev/fe/if_fereg.h> 45#include <dev/fe/if_fevar.h> 46 47#include <dev/pccard/pccardvar.h> 48#include <dev/pccard/pccarddevs.h> 49#include "card_if.h" 50#include <pccard/cardinfo.h> 51 52/* 53 * PC-Card (PCMCIA) specific code. 54 */ 55static int fe_pccard_probe(device_t); 56static int fe_pccard_attach(device_t); 57static int fe_pccard_detach(device_t); 58static int fe_pccard_match(device_t); 59 60static const struct fe_pccard_product { 61 struct pccard_product mpp_product; 62 u_int32_t mpp_ioalign; /* required alignment */ 63 int mpp_enet_maddr; 64} fe_pccard_products[] = { 65 { PCMCIA_CARD(TDK, LAK_CD021BX, 0), 0, -1 }, 66 { PCMCIA_CARD(TDK, LAK_CF010, 0), 0, -1 }, 67#if 0 /* XXX 86960-based? */ 68 { PCMCIA_CARD(TDK, LAK_DFL9610, 1), 0, -1 }, 69#endif 70 { PCMCIA_CARD(CONTEC, CNETPC, 0), 0, -1 }, 71 { PCMCIA_CARD(FUJITSU, LA501, 0), 0x20, -1 }, 72 { PCMCIA_CARD(FUJITSU, LA10S, 0), 0, -1 }, 73 { PCMCIA_CARD(RATOC, REX_R280, 0), 0, 0x1fc }, 74 { { NULL } } 75}; 76 77static int 78fe_pccard_match(device_t dev) 79{ 80 const struct pccard_product *pp; 81 82 if ((pp = pccard_product_lookup(dev, 83 (const struct pccard_product *)fe_pccard_products, 84 sizeof(fe_pccard_products[0]), NULL)) != NULL) { 85 if (pp->pp_name != NULL) 86 device_set_desc(dev, pp->pp_name); 87 return 0; 88 } 89 return EIO; 90} 91 92static device_method_t fe_pccard_methods[] = { 93 /* Device interface */ 94 DEVMETHOD(device_probe, pccard_compat_probe), 95 DEVMETHOD(device_attach, pccard_compat_attach), 96 DEVMETHOD(device_detach, fe_pccard_detach), 97 98 /* Card interface */ 99 DEVMETHOD(card_compat_match, fe_pccard_match), 100 DEVMETHOD(card_compat_probe, fe_pccard_probe), 101 DEVMETHOD(card_compat_attach, fe_pccard_attach), 102 103 { 0, 0 } 104}; 105 106static driver_t fe_pccard_driver = { 107 "fe", 108 fe_pccard_methods, 109 sizeof (struct fe_softc) 110}; 111 112DRIVER_MODULE(fe, pccard, fe_pccard_driver, fe_devclass, 0, 0); 113 114 115static int fe_probe_mbh(device_t); 116static int fe_probe_tdk(device_t); 117 118/* 119 * Initialize the device - called from Slot manager. 120 */ 121static int 122fe_pccard_probe(device_t dev) 123{ 124 struct fe_softc *sc; 125 int error; 126 127 /* Prepare for the device probe process. */ 128 sc = device_get_softc(dev); 129 sc->sc_unit = device_get_unit(dev); 130 131 pccard_get_ether(dev, sc->sc_enaddr); 132 133 /* Probe for supported cards. */ 134 if ((error = fe_probe_mbh(dev)) == 0) 135 goto end; 136 fe_release_resource(dev); 137 138 if ((error = fe_probe_tdk(dev)) == 0) 139 goto end; 140 fe_release_resource(dev); 141 142end: 143 if (error == 0) 144 error = fe_alloc_irq(dev, 0); 145 146 fe_release_resource(dev); 147 return (error); 148} 149 150static int 151fe_pccard_attach(device_t dev) 152{ 153 struct fe_softc *sc = device_get_softc(dev); 154 155 if (sc->port_used) 156 fe_alloc_port(dev, sc->port_used); 157 fe_alloc_irq(dev, 0); 158 159 return fe_attach(dev); 160} 161 162/* 163 * feunload - unload the driver and clear the table. 164 * XXX TODO: 165 * This is usually called when the card is ejected, but 166 * can be caused by a modunload of a controller driver. 167 * The idea is to reset the driver's view of the device 168 * and ensure that any driver entry points such as 169 * read and write do not hang. 170 */ 171static int 172fe_pccard_detach(device_t dev) 173{ 174 struct fe_softc *sc = device_get_softc(dev); 175 struct ifnet *ifp = &sc->arpcom.ac_if; 176 177 fe_stop(sc); 178 ether_ifdetach(ifp); 179 bus_teardown_intr(dev, sc->irq_res, sc->irq_handle); 180 fe_release_resource(dev); 181 182 return 0; 183} 184 185 186/* 187 * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface. 188 * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk(). 189 */ 190static void 191fe_init_mbh(struct fe_softc *sc) 192{ 193 /* Minimal initialization of 86960. */ 194 DELAY(200); 195 fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 196 DELAY(200); 197 198 /* Disable all interrupts. */ 199 fe_outb(sc, FE_DLCR2, 0); 200 fe_outb(sc, FE_DLCR3, 0); 201 202 /* Enable master interrupt flag. */ 203 fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE); 204} 205 206static int 207fe_probe_mbh(device_t dev) 208{ 209 struct fe_softc *sc = device_get_softc(dev); 210 211 static struct fe_simple_probe_struct probe_table [] = { 212 { FE_DLCR2, 0x58, 0x00 }, 213 { FE_DLCR4, 0x08, 0x00 }, 214 { FE_DLCR6, 0xFF, 0xB6 }, 215 { 0 } 216 }; 217 218 /* MBH10302 occupies 32 I/O addresses. */ 219 if (fe_alloc_port(dev, 32)) 220 return ENXIO; 221 222 /* Ethernet MAC address should *NOT* have been given by pccardd, 223 if this is a true MBH10302; i.e., Ethernet address must be 224 "all-zero" upon entry. */ 225 if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] || 226 sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5]) 227 return ENXIO; 228 229 /* Fill the softc struct with default values. */ 230 fe_softc_defaults(sc); 231 232 /* 233 * See if MBH10302 is on its address. 234 * I'm not sure the following probe code works. FIXME. 235 */ 236 if (!fe_simple_probe(sc, probe_table)) 237 return ENXIO; 238 239 /* Get our station address from EEPROM. */ 240 fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN); 241 242 /* Make sure we got a valid station address. */ 243 if (!valid_Ether_p(sc->sc_enaddr, 0)) 244 return ENXIO; 245 246 /* Determine the card type. */ 247 sc->type = FE_TYPE_MBH; 248 sc->typestr = "MBH10302 (PCMCIA)"; 249 250 /* We seems to need our own IDENT bits... FIXME. */ 251 sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE; 252 253 /* Setup hooks. We need a special initialization procedure. */ 254 sc->init = fe_init_mbh; 255 256 return 0; 257} 258 259/* 260 * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface. 261 * by MASUI Kenji <masui@cs.titech.ac.jp> 262 * 263 * (Contec uses TDK Ethenet chip -- hosokawa) 264 * 265 * This version of fe_probe_tdk has been rewrote to handle 266 * *generic* PC card implementation of Fujitsu MB8696x family. The 267 * name _tdk is just for a historical reason. :-) 268 */ 269static int 270fe_probe_tdk (device_t dev) 271{ 272 struct fe_softc *sc = device_get_softc(dev); 273 274 static struct fe_simple_probe_struct probe_table [] = { 275 { FE_DLCR2, 0x50, 0x00 }, 276 { FE_DLCR4, 0x08, 0x00 }, 277 /* { FE_DLCR5, 0x80, 0x00 }, Does not work well. */ 278 { 0 } 279 }; 280 281 /* C-NET(PC)C occupies 16 I/O addresses. */ 282 if (fe_alloc_port(dev, 16)) 283 return ENXIO; 284 285 /* Fill the softc struct with default values. */ 286 fe_softc_defaults(sc); 287 288 /* 289 * See if C-NET(PC)C is on its address. 290 */ 291 if (!fe_simple_probe(sc, probe_table)) 292 return ENXIO; 293 294 /* Determine the card type. */ 295 sc->type = FE_TYPE_TDK; 296 sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)"; 297 298 /* Make sure we got a valid station address. */ 299 if (!valid_Ether_p(sc->sc_enaddr, 0)) 300 return ENXIO; 301 302 return 0; 303} 304