if_ep_pccard.c revision 121492
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#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 121492 2003-10-25 04:09:49Z imp $"); 33 34/* 35 * Pccard support for 3C589 by: 36 * HAMADA Naoki 37 * nao@tom-yam.or.jp 38 */ 39 40#include <sys/cdefs.h> 41__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 121492 2003-10-25 04:09:49Z imp $"); 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> 46#include <sys/socket.h> 47#include <sys/module.h> 48#include <sys/bus.h> 49 50#include <machine/bus.h> 51#include <machine/resource.h> 52 53#include <net/ethernet.h> 54#include <net/if.h> 55#include <net/if_arp.h> 56#include <net/if_media.h> 57 58#include <dev/ep/if_epreg.h> 59#include <dev/ep/if_epvar.h> 60 61#include <dev/pccard/pccardvar.h> 62#include <dev/pccard/pccarddevs.h> 63 64#include "card_if.h" 65 66static const char *ep_pccard_identify(u_short id); 67 68/* 69 * Initialize the device - called from Slot manager. 70 */ 71static int 72ep_pccard_probe(device_t dev) 73{ 74 struct ep_softc *sc = device_get_softc(dev); 75 struct ep_board *epb = &sc->epb; 76 const char *desc; 77 u_int16_t result; 78 int error; 79 80 error = ep_alloc(dev); 81 if (error) 82 return (error); 83 84 /* 85 * It appears that the eeprom comes in two sizes. There's 86 * a 512 byte eeprom and a 2k eeprom. Bit 13 of the eeprom 87 * command register is supposed to contain the size of the 88 * eeprom. 89 */ 90 /* 91 * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 92 * 2. Sadly, you need to have a correct cmd_off in order to 93 * identify the card. So we have to hit it with both and 94 * cross our virtual fingers. There's got to be a better way 95 * to do this. jyoung@accessus.net 09/11/1999 96 */ 97 98 epb->cmd_off = 0; 99 100 /* XXX check return */ 101 error = get_e(sc, EEPROM_PROD_ID, &result); 102 epb->prod_id = result; 103 104 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 105 if (bootverbose) 106 device_printf(dev, "Pass 1 of 2 detection " 107 "failed (nonfatal) id 0x%x\n", epb->prod_id); 108 epb->cmd_off = 2; 109 /* XXX check return */ 110 error = get_e(sc, EEPROM_PROD_ID, &result); 111 epb->prod_id = result; 112 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 113 device_printf(dev, "Unit failed to come ready or " 114 "product ID unknown! (id 0x%x)\n", epb->prod_id); 115 ep_free(dev); 116 return (ENXIO); 117 } 118 } 119 device_set_desc(dev, desc); 120 121 /* 122 * For some reason the 3c574 needs this. 123 */ 124 error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 125 126 ep_free(dev); 127 return (0); 128} 129 130static const char * 131ep_pccard_identify(u_short id) 132{ 133 /* Determine device type and associated MII capabilities */ 134 switch (id) { 135 case 0x6055: /* 3C556 */ 136 return ("3Com 3C556"); 137 case 0x4057: /* 3C574 */ 138 return ("3Com 3C574"); 139 case 0x4b57: /* 3C574B */ 140 return ("3Com 3C574B, Megahertz 3CCFE574BT or " 141 "Fast Etherlink 3C574-TX"); 142 case 0x2b57: /* 3CXSH572BT */ 143 return ("3Com OfficeConnect 572BT"); 144 case 0x9058: /* 3C589 */ 145 return ("3Com Etherlink III 3C589"); 146 case 0x2056: /* 3C562/3C563 */ 147 return ("3Com 3C562D/3C563D"); 148 case 0x0010: /* 3C1 */ 149 return ("3Com Megahertz C1"); 150 default: 151 return (NULL); 152 } 153} 154 155static int 156ep_pccard_card_attach(struct ep_board * epb) 157{ 158 /* Determine device type and associated MII capabilities */ 159 switch (epb->prod_id) { 160 case 0x6055: /* 3C556 */ 161 case 0x2b57: /* 3C572BT */ 162 case 0x4057: /* 3C574 */ 163 case 0x4b57: /* 3C574B */ 164 epb->mii_trans = 1; 165 return (1); 166 case 0x2056: /* 3C562D/3C563D */ 167 case 0x9058: /* 3C589 */ 168 case 0x0010: /* 3C1 */ 169 epb->mii_trans = 0; 170 return (1); 171 default: 172 return (0); 173 } 174} 175 176static int 177ep_pccard_attach(device_t dev) 178{ 179 struct ep_softc *sc = device_get_softc(dev); 180 u_int16_t result; 181 int error = 0; 182 183 if ((error = ep_alloc(dev))) { 184 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 185 goto bad; 186 } 187 sc->epb.cmd_off = 0; 188 189 /* XXX check return */ 190 error = get_e(sc, EEPROM_PROD_ID, &result); 191 sc->epb.prod_id = result; 192 193 if (!ep_pccard_card_attach(&sc->epb)) { 194 sc->epb.cmd_off = 2; 195 error = get_e(sc, EEPROM_PROD_ID, &result); 196 sc->epb.prod_id = result; 197 error = get_e(sc, EEPROM_RESOURCE_CFG, &result); 198 sc->epb.res_cfg = result; 199 if (!ep_pccard_card_attach(&sc->epb)) { 200 device_printf(dev, 201 "Probe found ID, attach failed so ignore card!\n"); 202 error = ENXIO; 203 goto bad; 204 } 205 } 206 error = get_e(sc, EEPROM_ADDR_CFG, &result); 207 208 /* ROM size = 0, ROM base = 0 */ 209 /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 210 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000); 211 212 /* Fake IRQ must be 3 */ 213 CSR_WRITE_2(sc, EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 214 215 CSR_WRITE_2(sc, EP_W0_PRODUCT_ID, sc->epb.prod_id); 216 217 if (sc->epb.mii_trans) { 218 /* 219 * turn on the MII transciever 220 */ 221 GO_WINDOW(3); 222 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 223 DELAY(1000); 224 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040); 225 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET); 226 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET); 227 EP_BUSY_WAIT; 228 DELAY(1000); 229 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 230 } else 231 ep_get_media(sc); 232 233 if ((error = ep_attach(sc))) { 234 device_printf(dev, "ep_attach() failed! (%d)\n", error); 235 goto bad; 236 } 237 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, ep_intr, 238 sc, &sc->ep_intrhand))) { 239 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 240 goto bad; 241 } 242 return (0); 243bad: 244 ep_free(dev); 245 return (error); 246} 247 248static const struct pccard_product ep_pccard_products[] = { 249 PCMCIA_CARD(3COM, 3C1, 0), 250 PCMCIA_CARD(3COM, 3C562, 0), 251 PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 252 PCMCIA_CARD(3COM, 3C589, 0), 253 PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 254 PCMCIA_CARD(3COM, 3CXEM556, 0), 255 PCMCIA_CARD(3COM, 3CXEM556INT, 0), 256 {NULL} 257}; 258 259static int 260ep_pccard_match(device_t dev) 261{ 262 const struct pccard_product *pp; 263 264 if ((pp = pccard_product_lookup(dev, ep_pccard_products, 265 sizeof(ep_pccard_products[0]), NULL)) != NULL) { 266 if (pp->pp_name != NULL) 267 device_set_desc(dev, pp->pp_name); 268 return 0; 269 } 270 return EIO; 271} 272 273static device_method_t ep_pccard_methods[] = { 274 /* Device interface */ 275 DEVMETHOD(device_probe, pccard_compat_probe), 276 DEVMETHOD(device_attach, pccard_compat_attach), 277 DEVMETHOD(device_detach, ep_detach), 278 279 /* Card interface */ 280 DEVMETHOD(card_compat_match, ep_pccard_match), 281 DEVMETHOD(card_compat_probe, ep_pccard_probe), 282 DEVMETHOD(card_compat_attach, ep_pccard_attach), 283 284 {0, 0} 285}; 286 287static driver_t ep_pccard_driver = { 288 "ep", 289 ep_pccard_methods, 290 sizeof(struct ep_softc), 291}; 292 293extern devclass_t ep_devclass; 294 295DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 296