if_ep_pccard.c revision 140523
1/*- 2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 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 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Herb Peyerl. 16 * 4. The name of Herb Peyerl may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31/* 32 * Pccard support for 3C589 by: 33 * HAMADA Naoki 34 * nao@tom-yam.or.jp 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 140523 2005-01-20 19:39:33Z imp $"); 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/socket.h> 44#include <sys/module.h> 45#include <sys/bus.h> 46 47#include <machine/bus.h> 48#include <machine/resource.h> 49 50#include <net/ethernet.h> 51#include <net/if.h> 52#include <net/if_arp.h> 53#include <net/if_media.h> 54 55#include <dev/ep/if_epreg.h> 56#include <dev/ep/if_epvar.h> 57 58#include <dev/pccard/pccardvar.h> 59#include <dev/pccard/pccard_cis.h> 60 61#include "card_if.h" 62#include "pccarddevs.h" 63 64static const char *ep_pccard_identify(u_short id); 65 66/* 67 * Initialize the device - called from Slot manager. 68 */ 69static int 70ep_pccard_probe(device_t dev) 71{ 72 struct ep_softc *sc = device_get_softc(dev); 73 struct ep_board *epb = &sc->epb; 74 const char *desc; 75 uint16_t result; 76 int error; 77 78 error = ep_alloc(dev); 79 if (error) 80 return (error); 81 82 /* 83 * It appears that the eeprom comes in two sizes. There's 84 * a 512 byte eeprom and a 2k eeprom. Bit 13 of the eeprom 85 * command register is supposed to contain the size of the 86 * eeprom. 87 */ 88 /* 89 * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 90 * 2. Sadly, you need to have a correct cmd_off in order to 91 * identify the card. So we have to hit it with both and 92 * cross our virtual fingers. There's got to be a better way 93 * to do this. jyoung@accessus.net 09/11/1999 94 */ 95 96 epb->cmd_off = 0; 97 98 /* XXX check return */ 99 error = get_e(sc, EEPROM_PROD_ID, &result); 100 epb->prod_id = result; 101 102 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 103 if (bootverbose) 104 device_printf(dev, "Pass 1 of 2 detection " 105 "failed (nonfatal) id 0x%x\n", epb->prod_id); 106 epb->cmd_off = 2; 107 /* XXX check return */ 108 error = get_e(sc, EEPROM_PROD_ID, &result); 109 epb->prod_id = result; 110 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 111 device_printf(dev, "Unit failed to come ready or " 112 "product ID unknown! (id 0x%x)\n", epb->prod_id); 113 ep_free(dev); 114 return (ENXIO); 115 } 116 } 117 device_set_desc(dev, desc); 118 119 /* 120 * Newer cards supported by this device need to have their 121 * MAC address set. 122 */ 123 error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 124 125 ep_free(dev); 126 return (0); 127} 128 129static const char * 130ep_pccard_identify(u_short id) 131{ 132 /* Determine device type and associated MII capabilities */ 133 switch (id) { 134 case 0x6055: /* 3C556 */ 135 return ("3Com 3C556"); 136 case 0x4057: /* 3C574 */ 137 return ("3Com 3C574"); 138 case 0x4b57: /* 3C574B */ 139 return ("3Com 3C574B, Megahertz 3CCFE574BT or " 140 "Fast Etherlink 3C574-TX"); 141 case 0x2b57: /* 3CXSH572BT */ 142 return ("3Com OfficeConnect 572BT"); 143 case 0x9058: /* 3C589 */ 144 return ("3Com Etherlink III 3C589"); 145 case 0x2056: /* 3C562/3C563 */ 146 return ("3Com 3C562D/3C563D"); 147 case 0x0010: /* 3C1 */ 148 return ("3Com Megahertz C1"); 149 case 0x0035: 150 return ("3Com 3CCEM556"); 151 default: 152 printf("Unknown ID: 0x%x\n", id); 153 return (NULL); 154 } 155} 156 157static int 158ep_pccard_card_attach(struct ep_board * epb) 159{ 160 /* Determine device type and associated MII capabilities */ 161 switch (epb->prod_id) { 162 case 0x6055: /* 3C556 */ 163 case 0x2b57: /* 3C572BT */ 164 case 0x4057: /* 3C574 */ 165 case 0x4b57: /* 3C574B */ 166 epb->mii_trans = 1; 167 return (1); 168 case 0x2056: /* 3C562D/3C563D */ 169 case 0x9058: /* 3C589 */ 170 case 0x0010: /* 3C1 */ 171 case 0x0035: /* 3C[XC]EM556 */ 172 epb->mii_trans = 0; 173 return (1); 174 default: 175 return (0); 176 } 177} 178 179static int 180ep_pccard_attach(device_t dev) 181{ 182 struct ep_softc *sc = device_get_softc(dev); 183 uint16_t result; 184 int error = 0; 185 186 if ((error = ep_alloc(dev))) { 187 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 188 goto bad; 189 } 190 sc->epb.cmd_off = 0; 191 192 /* XXX check return */ 193 error = get_e(sc, EEPROM_PROD_ID, &result); 194 sc->epb.prod_id = result; 195 196 if (!ep_pccard_card_attach(&sc->epb)) { 197 sc->epb.cmd_off = 2; 198 error = get_e(sc, EEPROM_PROD_ID, &result); 199 sc->epb.prod_id = result; 200 error = get_e(sc, EEPROM_RESOURCE_CFG, &result); 201 sc->epb.res_cfg = result; 202 if (!ep_pccard_card_attach(&sc->epb)) { 203 device_printf(dev, 204 "Probe found ID, attach failed so ignore card!\n"); 205 error = ENXIO; 206 goto bad; 207 } 208 } 209 error = get_e(sc, EEPROM_ADDR_CFG, &result); 210 211 /* ROM size = 0, ROM base = 0 */ 212 /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 213 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000); 214 215 /* 216 * Fake IRQ must be 3 for 3C589 and 3C589B. 3C589D and newer 217 * ignore this value. 3C589C is unknown, as are the other 218 * cards supported by this driver, but it appears to never hurt 219 * and always helps. 220 */ 221 SET_IRQ(sc, 3); 222 CSR_WRITE_2(sc, EP_W0_PRODUCT_ID, sc->epb.prod_id); 223 224 if (sc->epb.mii_trans) { 225 /* 226 * turn on the MII transciever 227 */ 228 GO_WINDOW(sc, 3); 229 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 230 DELAY(1000); 231 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040); 232 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); 233 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); 234 EP_BUSY_WAIT(sc); 235 DELAY(1000); 236 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 237 } else 238 ep_get_media(sc); 239 240 if ((error = ep_attach(sc))) { 241 device_printf(dev, "ep_attach() failed! (%d)\n", error); 242 goto bad; 243 } 244 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, ep_intr, 245 sc, &sc->ep_intrhand))) { 246 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 247 goto bad; 248 } 249 return (0); 250bad: 251 ep_free(dev); 252 return (error); 253} 254 255static const struct pccard_product ep_pccard_products[] = { 256 PCMCIA_CARD(3COM, 3C1, 0), 257 PCMCIA_CARD(3COM, 3C562, 0), 258 PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 259 PCMCIA_CARD(3COM, 3C589, 0), 260 PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 261 PCMCIA_CARD(3COM, 3CXEM556, 0), 262 PCMCIA_CARD(3COM, 3CXEM556INT, 0), 263 {NULL} 264}; 265 266static int 267ep_pccard_match(device_t dev) 268{ 269 const struct pccard_product *pp; 270 int error; 271 uint32_t fcn = PCCARD_FUNCTION_UNSPEC; 272 273 /* Make sure we're a network function */ 274 error = pccard_get_function(dev, &fcn); 275 if (error != 0) 276 return (error); 277 if (fcn != PCCARD_FUNCTION_NETWORK) 278 return (ENXIO); 279 280 if ((pp = pccard_product_lookup(dev, ep_pccard_products, 281 sizeof(ep_pccard_products[0]), NULL)) != NULL) { 282 if (pp->pp_name != NULL) 283 device_set_desc(dev, pp->pp_name); 284 return 0; 285 } 286 return EIO; 287} 288 289static device_method_t ep_pccard_methods[] = { 290 /* Device interface */ 291 DEVMETHOD(device_probe, pccard_compat_probe), 292 DEVMETHOD(device_attach, pccard_compat_attach), 293 DEVMETHOD(device_detach, ep_detach), 294 295 /* Card interface */ 296 DEVMETHOD(card_compat_match, ep_pccard_match), 297 DEVMETHOD(card_compat_probe, ep_pccard_probe), 298 DEVMETHOD(card_compat_attach, ep_pccard_attach), 299 300 {0, 0} 301}; 302 303static driver_t ep_pccard_driver = { 304 "ep", 305 ep_pccard_methods, 306 sizeof(struct ep_softc), 307}; 308 309extern devclass_t ep_devclass; 310 311DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 312