if_ep_pccard.c revision 52589
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 52589 1999-10-28 06:12:58Z 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 60/* XXX should die XXX */ 61#include <sys/select.h> 62#include <sys/module.h> 63#include <pccard/cardinfo.h> 64#include <pccard/slot.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 int error; 78 79 error = ep_alloc(dev); 80 if (error) 81 return error; 82 83 /* 84 * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 85 * 2. Sadly, you need to have a correct cmd_off in order to 86 * identify the card. So we have to hit it with both and 87 * cross our virtual fingers. There's got to be a better way 88 * to do this. jyoung@accessus.net 09/11/1999 89 */ 90 91 epb->cmd_off = 0; 92 epb->prod_id = get_e(sc, EEPROM_PROD_ID); 93 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 94 if (bootverbose) 95 device_printf(dev, "Pass 1 of 2 detection " 96 "failed (nonfatal)\n"); 97 epb->cmd_off = 2; 98 epb->prod_id = get_e(sc, EEPROM_PROD_ID); 99 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 100 device_printf(dev, "Unit failed to come ready or " 101 "product ID unknown! (id 0x%x)\n", epb->prod_id); 102 ep_free(dev); 103 return (ENXIO); 104 } 105 } 106 device_set_desc(dev, desc); 107 ep_free(dev); 108 return (0); 109} 110 111static const char * 112ep_pccard_identify(u_short id) 113{ 114 /* Determine device type and associated MII capabilities */ 115 switch (id) { 116 case 0x6055: /* 3C556 */ 117 return ("3Com 3C556"); 118 case 0x4057: /* 3C574 */ 119 return ("3Com 3C574"); 120 case 0x4b57: /* 3C574B */ 121 return ("3Com 3C574B, Megahertz 3CCFE574BT or " 122 "Fast Etherlink 3C574-TX"); 123 case 0x9058: /* 3C589 */ 124 return ("3Com Etherlink III 3C589"); 125 } 126 return (NULL); 127} 128 129static int 130ep_pccard_card_attach(struct ep_board *epb) 131{ 132 /* Determine device type and associated MII capabilities */ 133 switch (epb->prod_id) { 134 case 0x6055: /* 3C556 */ 135 epb->mii_trans = 1; 136 return (1); 137 case 0x4057: /* 3C574 */ 138 epb->mii_trans = 1; 139 return (1); 140 case 0x4b57: /* 3C574B */ 141 epb->mii_trans = 1; 142 return (1); 143 case 0x9058: /* 3C589 */ 144 epb->mii_trans = 0; 145 return (1); 146 } 147 return (0); 148} 149 150static int 151ep_pccard_attach(device_t dev) 152{ 153 struct ep_softc * sc = device_get_softc(dev); 154 int error = 0; 155 156 if ((error = ep_alloc(dev))) { 157 device_printf(dev, "ep_alloc() failed! (%d)\n", error); 158 goto bad; 159 } 160 161 sc->epb.cmd_off = 0; 162 sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 163 if (!ep_pccard_card_attach(&sc->epb)) { 164 sc->epb.cmd_off = 2; 165 sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 166 sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 167 if (!ep_pccard_card_attach(&sc->epb)) { 168 device_printf(dev, 169 "Probe found ID, attach failed so ignore card!\n"); 170 error = ENXIO; 171 goto bad; 172 } 173 } 174 175 /* ROM size = 0, ROM base = 0 */ 176 /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 177 outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 178 179 /* Fake IRQ must be 3 */ 180 outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 181 182 outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 183 184 if (sc->epb.mii_trans) { 185 /* 186 * turn on the MII transciever 187 */ 188 GO_WINDOW(3); 189 outw(BASE + EP_W3_OPTIONS, 0x8040); 190 DELAY(1000); 191 outw(BASE + EP_W3_OPTIONS, 0xc040); 192 outw(BASE + EP_COMMAND, RX_RESET); 193 outw(BASE + EP_COMMAND, TX_RESET); 194 while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 195 DELAY(1000); 196 outw(BASE + EP_W3_OPTIONS, 0x8040); 197 } else { 198 ep_get_media(sc); 199 } 200 201 if ((error = ep_attach(sc))) { 202 device_printf(dev, "ep_attach() failed! (%d)\n", error); 203 goto bad; 204 } 205 206 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 207 sc, &sc->ep_intrhand))) { 208 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 209 goto bad; 210 } 211 212 return (0); 213bad: 214 ep_free(dev); 215 return (error); 216} 217 218static void 219ep_pccard_detach(device_t dev) 220{ 221 struct ep_softc *sc = device_get_softc(dev); 222 223 printf("detach\n"); 224 225 if (sc->gone) { 226 device_printf(dev, "already unloaded\n"); 227 return; 228 } 229 sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 230 if_down(&sc->arpcom.ac_if); 231 sc->gone = 1; 232 bus_teardown_intr(dev, sc->irq, sc->ep_intrhand); 233 ep_free(dev); 234 device_printf(dev, "unload\n"); 235} 236 237static device_method_t ep_pccard_methods[] = { 238 /* Device interface */ 239 DEVMETHOD(device_probe, ep_pccard_probe), 240 DEVMETHOD(device_attach, ep_pccard_attach), 241 DEVMETHOD(device_detach, ep_pccard_detach), 242 243 { 0, 0 } 244}; 245 246static driver_t ep_pccard_driver = { 247 "ep", 248 ep_pccard_methods, 249 sizeof(struct ep_softc), 250}; 251 252extern devclass_t ep_devclass; 253 254DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 255