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