if_ep_pccard.c revision 55702
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 * $FreeBSD: head/sys/dev/ep/if_ep_pccard.c 55702 2000-01-10 02:32:43Z imp $ 31 */ 32 33/* 34 * Pccard support for 3C589 by: 35 * HAMADA Naoki 36 * nao@tom-yam.or.jp 37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/socket.h> 43 44#include <sys/module.h> 45#include <sys/bus.h> 46 47#include <machine/bus.h> 48#include <machine/resource.h> 49#include <sys/rman.h> 50 51#include <net/if.h> 52#include <net/if_arp.h> 53#include <net/if_media.h> 54 55#include <machine/clock.h> 56 57#include <dev/ep/if_epreg.h> 58#include <dev/ep/if_epvar.h> 59 60static const char *ep_pccard_identify(u_short id); 61 62/* 63 * Initialize the device - called from Slot manager. 64 */ 65static int 66ep_pccard_probe(device_t dev) 67{ 68 struct ep_softc * sc = device_get_softc(dev); 69 struct ep_board * epb = &sc->epb; 70 const char * desc; 71 int error; 72 73 error = ep_alloc(dev); 74 if (error) 75 return error; 76 77 /* 78 * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 79 * 2. Sadly, you need to have a correct cmd_off in order to 80 * identify the card. So we have to hit it with both and 81 * cross our virtual fingers. There's got to be a better way 82 * to do this. jyoung@accessus.net 09/11/1999 83 */ 84 85 epb->cmd_off = 0; 86 epb->prod_id = get_e(sc, EEPROM_PROD_ID); 87 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 88 if (bootverbose) 89 device_printf(dev, "Pass 1 of 2 detection " 90 "failed (nonfatal)\n"); 91 epb->cmd_off = 2; 92 epb->prod_id = get_e(sc, EEPROM_PROD_ID); 93 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 94 device_printf(dev, "Unit failed to come ready or " 95 "product ID unknown! (id 0x%x)\n", epb->prod_id); 96 ep_free(dev); 97 return (ENXIO); 98 } 99 } 100 device_set_desc(dev, desc); 101 ep_free(dev); 102 return (0); 103} 104 105static const char * 106ep_pccard_identify(u_short id) 107{ 108 /* Determine device type and associated MII capabilities */ 109 switch (id) { 110 case 0x6055: /* 3C556 */ 111 return ("3Com 3C556"); 112 case 0x4057: /* 3C574 */ 113 return ("3Com 3C574"); 114 case 0x4b57: /* 3C574B */ 115 return ("3Com 3C574B, Megahertz 3CCFE574BT or " 116 "Fast Etherlink 3C574-TX"); 117 case 0x2b57: /* 3CXSH572BT */ 118 return ("3Com OfficeConnect 572BT"); 119 case 0x9058: /* 3C589 */ 120 return ("3Com Etherlink III 3C589"); 121 case 0x2056: /* 3C562/3C563 */ 122 return ("3Com 3C562D/3C563D"); 123 } 124 return (NULL); 125} 126 127static int 128ep_pccard_card_attach(struct ep_board *epb) 129{ 130 /* Determine device type and associated MII capabilities */ 131 switch (epb->prod_id) { 132 case 0x6055: /* 3C556 */ 133 case 0x2b57: /* 3C572BT */ 134 case 0x4057: /* 3C574 */ 135 case 0x4b57: /* 3C574B */ 136 epb->mii_trans = 1; 137 return (1); 138 case 0x2056: /* 3C562D/3C563D */ 139 case 0x9058: /* 3C589 */ 140 epb->mii_trans = 0; 141 return (1); 142 } 143 return (0); 144} 145 146static int 147ep_pccard_attach(device_t dev) 148{ 149 struct ep_softc * sc = device_get_softc(dev); 150 int error = 0; 151 152 if ((error = ep_alloc(dev))) { 153 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 154 goto bad; 155 } 156 157 sc->epb.cmd_off = 0; 158 sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 159 if (!ep_pccard_card_attach(&sc->epb)) { 160 sc->epb.cmd_off = 2; 161 sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 162 sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 163 if (!ep_pccard_card_attach(&sc->epb)) { 164 device_printf(dev, 165 "Probe found ID, attach failed so ignore card!\n"); 166 error = ENXIO; 167 goto bad; 168 } 169 } 170 171 /* ROM size = 0, ROM base = 0 */ 172 /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 173 outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 174 175 /* Fake IRQ must be 3 */ 176 outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 177 178 outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 179 180 if (sc->epb.mii_trans) { 181 /* 182 * turn on the MII transciever 183 */ 184 GO_WINDOW(3); 185 outw(BASE + EP_W3_OPTIONS, 0x8040); 186 DELAY(1000); 187 outw(BASE + EP_W3_OPTIONS, 0xc040); 188 outw(BASE + EP_COMMAND, RX_RESET); 189 outw(BASE + EP_COMMAND, TX_RESET); 190 while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 191 DELAY(1000); 192 outw(BASE + EP_W3_OPTIONS, 0x8040); 193 } else { 194 ep_get_media(sc); 195 } 196 197 if ((error = ep_attach(sc))) { 198 device_printf(dev, "ep_attach() failed! (%d)\n", error); 199 goto bad; 200 } 201 202 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 203 sc, &sc->ep_intrhand))) { 204 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 205 goto bad; 206 } 207 208 return (0); 209bad: 210 ep_free(dev); 211 return (error); 212} 213 214static int 215ep_pccard_detach(device_t dev) 216{ 217 struct ep_softc *sc = device_get_softc(dev); 218 219 if (sc->gone) { 220 device_printf(dev, "already unloaded\n"); 221 return (0); 222 } 223 sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 224 if_detach(&sc->arpcom.ac_if); 225 sc->gone = 1; 226 bus_teardown_intr(dev, sc->irq, sc->ep_intrhand); 227 ep_free(dev); 228 device_printf(dev, "unload\n"); 229 return (0); 230} 231 232static device_method_t ep_pccard_methods[] = { 233 /* Device interface */ 234 DEVMETHOD(device_probe, ep_pccard_probe), 235 DEVMETHOD(device_attach, ep_pccard_attach), 236 DEVMETHOD(device_detach, ep_pccard_detach), 237 238 { 0, 0 } 239}; 240 241static driver_t ep_pccard_driver = { 242 "ep", 243 ep_pccard_methods, 244 sizeof(struct ep_softc), 245}; 246 247extern devclass_t ep_devclass; 248 249DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 250