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