if_ep_pccard.c revision 86395
151673Smdodd/* 251673Smdodd * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 351673Smdodd * All rights reserved. 451673Smdodd * 551673Smdodd * Redistribution and use in source and binary forms, with or without 651673Smdodd * modification, are permitted provided that the following conditions 751673Smdodd * are met: 851673Smdodd * 1. Redistributions of source code must retain the above copyright 951673Smdodd * notice, this list of conditions and the following disclaimer. 1051673Smdodd * 2. Redistributions in binary form must reproduce the above copyright 1151673Smdodd * notice, this list of conditions and the following disclaimer in the 1251673Smdodd * documentation and/or other materials provided with the distribution. 1351673Smdodd * 3. All advertising materials mentioning features or use of this software 1451673Smdodd * must display the following acknowledgement: 1551673Smdodd * This product includes software developed by Herb Peyerl. 1651673Smdodd * 4. The name of Herb Peyerl may not be used to endorse or promote products 1751673Smdodd * derived from this software without specific prior written permission. 1851673Smdodd * 1951673Smdodd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2051673Smdodd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2151673Smdodd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2251673Smdodd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2351673Smdodd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2451673Smdodd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2551673Smdodd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2651673Smdodd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2751673Smdodd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2851673Smdodd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2951673Smdodd * 3051673Smdodd * $FreeBSD: head/sys/dev/ep/if_ep_pccard.c 86395 2001-11-15 07:57:38Z imp $ 3151673Smdodd */ 3251673Smdodd 3351673Smdodd/* 3451673Smdodd * Pccard support for 3C589 by: 3551673Smdodd * HAMADA Naoki 3651673Smdodd * nao@tom-yam.or.jp 3751673Smdodd */ 3851673Smdodd 3951673Smdodd#include <sys/param.h> 4052549Smdodd#include <sys/systm.h> 4151673Smdodd#include <sys/kernel.h> 4251673Smdodd#include <sys/socket.h> 4352549Smdodd 4452549Smdodd#include <sys/module.h> 4552472Simp#include <sys/bus.h> 4652549Smdodd 4752472Simp#include <machine/bus.h> 4852549Smdodd#include <machine/resource.h> 4952549Smdodd 5063090Sarchie#include <net/ethernet.h> 5152549Smdodd#include <net/if.h> 5252549Smdodd#include <net/if_arp.h> 5352549Smdodd#include <net/if_media.h> 5451673Smdodd 5551673Smdodd 5652472Simp#include <dev/ep/if_epreg.h> 5752472Simp#include <dev/ep/if_epvar.h> 5852472Simp 5966058Simp#include "card_if.h" 6066058Simp#include <dev/pccard/pccardvar.h> 6170765Speter#include <dev/pccard/pccarddevs.h> 6266058Simp 6352472Simpstatic const char *ep_pccard_identify(u_short id); 6451673Smdodd 6551673Smdodd/* 6651673Smdodd * Initialize the device - called from Slot manager. 6751673Smdodd */ 6851673Smdoddstatic int 6952472Simpep_pccard_probe(device_t dev) 7051673Smdodd{ 7152549Smdodd struct ep_softc * sc = device_get_softc(dev); 7252549Smdodd struct ep_board * epb = &sc->epb; 7352549Smdodd const char * desc; 7452549Smdodd int error; 7551673Smdodd 7652589Simp error = ep_alloc(dev); 7752589Simp if (error) 7852472Simp return error; 7952549Smdodd 8052472Simp /* 8152472Simp * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 8252472Simp * 2. Sadly, you need to have a correct cmd_off in order to 8352472Simp * identify the card. So we have to hit it with both and 8452472Simp * cross our virtual fingers. There's got to be a better way 8552472Simp * to do this. jyoung@accessus.net 09/11/1999 8652472Simp */ 8751673Smdodd 8852472Simp epb->cmd_off = 0; 8951673Smdodd epb->prod_id = get_e(sc, EEPROM_PROD_ID); 9052472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 9152472Simp if (bootverbose) 9252472Simp device_printf(dev, "Pass 1 of 2 detection " 9365794Simp "failed (nonfatal) id 0x%x\n", epb->prod_id); 9452472Simp epb->cmd_off = 2; 9552472Simp epb->prod_id = get_e(sc, EEPROM_PROD_ID); 9652589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 9752472Simp device_printf(dev, "Unit failed to come ready or " 9852472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 9952589Simp ep_free(dev); 10052472Simp return (ENXIO); 10152472Simp } 10251673Smdodd } 10352589Simp device_set_desc(dev, desc); 10456017Smdodd 10556017Smdodd /* 10656017Smdodd * For some reason the 3c574 needs this. 10756017Smdodd */ 10856017Smdodd ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 10956017Smdodd 11052589Simp ep_free(dev); 11152472Simp return (0); 11252472Simp} 11351673Smdodd 11452472Simpstatic const char * 11552472Simpep_pccard_identify(u_short id) 11652472Simp{ 11752472Simp /* Determine device type and associated MII capabilities */ 11852472Simp switch (id) { 11952472Simp case 0x6055: /* 3C556 */ 12052472Simp return ("3Com 3C556"); 12152472Simp case 0x4057: /* 3C574 */ 12252589Simp return ("3Com 3C574"); 12352472Simp case 0x4b57: /* 3C574B */ 12452589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 12552472Simp "Fast Etherlink 3C574-TX"); 12655702Simp case 0x2b57: /* 3CXSH572BT */ 12755702Simp return ("3Com OfficeConnect 572BT"); 12852472Simp case 0x9058: /* 3C589 */ 12952589Simp return ("3Com Etherlink III 3C589"); 13052621Simp case 0x2056: /* 3C562/3C563 */ 13152621Simp return ("3Com 3C562D/3C563D"); 13265794Simp case 0x0010: /* 3C1 */ 13365794Simp return ("3Com Megahertz C1"); 13452472Simp } 13552589Simp return (NULL); 13651673Smdodd} 13751673Smdodd 13851673Smdoddstatic int 13952472Simpep_pccard_card_attach(struct ep_board *epb) 14051673Smdodd{ 14152472Simp /* Determine device type and associated MII capabilities */ 14252472Simp switch (epb->prod_id) { 14351673Smdodd case 0x6055: /* 3C556 */ 14455702Simp case 0x2b57: /* 3C572BT */ 14551673Smdodd case 0x4057: /* 3C574 */ 14651673Smdodd case 0x4b57: /* 3C574B */ 14765794Simp case 0x0010: /* 3C1 */ 14852472Simp epb->mii_trans = 1; 14952472Simp return (1); 15052621Simp case 0x2056: /* 3C562D/3C563D */ 15151673Smdodd case 0x9058: /* 3C589 */ 15252472Simp epb->mii_trans = 0; 15352472Simp return (1); 15452472Simp } 15552472Simp return (0); 15651673Smdodd} 15751673Smdodd 15851673Smdoddstatic int 15952472Simpep_pccard_attach(device_t dev) 16051673Smdodd{ 16152549Smdodd struct ep_softc * sc = device_get_softc(dev); 16252549Smdodd int error = 0; 16351673Smdodd 16452585Simp if ((error = ep_alloc(dev))) { 16552549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 16652472Simp goto bad; 16752472Simp } 16851673Smdodd 16952589Simp sc->epb.cmd_off = 0; 17052589Simp sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 17152549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 17252549Smdodd sc->epb.cmd_off = 2; 17352549Smdodd sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 17452549Smdodd sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 17552549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 17652472Simp device_printf(dev, 17752472Simp "Probe found ID, attach failed so ignore card!\n"); 17852549Smdodd error = ENXIO; 17952549Smdodd goto bad; 18052472Simp } 18152472Simp } 18251673Smdodd 18352472Simp /* ROM size = 0, ROM base = 0 */ 18452472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 18552472Simp outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 18652472Simp 18752472Simp /* Fake IRQ must be 3 */ 18852549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 18952472Simp 19052549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 19152472Simp 19252549Smdodd if (sc->epb.mii_trans) { 19352472Simp /* 19452472Simp * turn on the MII transciever 19552472Simp */ 19652472Simp GO_WINDOW(3); 19752472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19852472Simp DELAY(1000); 19952472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 20052472Simp outw(BASE + EP_COMMAND, RX_RESET); 20152472Simp outw(BASE + EP_COMMAND, TX_RESET); 20252472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 20352472Simp DELAY(1000); 20452472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 20552549Smdodd } else { 20652549Smdodd ep_get_media(sc); 20752472Simp } 20852472Simp 20952549Smdodd if ((error = ep_attach(sc))) { 21052549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 21152472Simp goto bad; 21252472Simp } 21352472Simp 21452585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 21552585Simp sc, &sc->ep_intrhand))) { 21652549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 21752472Simp goto bad; 21852472Simp } 21952472Simp 22052549Smdodd return (0); 22152472Simpbad: 22252585Simp ep_free(dev); 22352549Smdodd return (error); 22451673Smdodd} 22551673Smdodd 22653978Simpstatic int 22752472Simpep_pccard_detach(device_t dev) 22851673Smdodd{ 22952472Simp struct ep_softc *sc = device_get_softc(dev); 23051673Smdodd 23152472Simp if (sc->gone) { 23252472Simp device_printf(dev, "already unloaded\n"); 23353978Simp return (0); 23452472Simp } 23552472Simp sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 23663090Sarchie ether_ifdetach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED); 23752472Simp sc->gone = 1; 23852549Smdodd bus_teardown_intr(dev, sc->irq, sc->ep_intrhand); 23952549Smdodd ep_free(dev); 24053978Simp return (0); 24151673Smdodd} 24251673Smdodd 24370765Speterstatic const struct pccard_product ep_pccard_products[] = { 24486395Simp PCMCIA_CARD(3COM, 3C1, 0), 24586395Simp PCMCIA_CARD(3COM, 3C562, 0), 24686395Simp PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 24786394Simp PCMCIA_CARD(3COM, 3C589, 0), 24886395Simp PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 24986394Simp PCMCIA_CARD(3COM, 3CXEM556, 0), 25086394Simp PCMCIA_CARD(3COM, 3CXEM556INT, 0), 25170765Speter { NULL } 25270765Speter}; 25370765Speter 25466058Simpstatic int 25566058Simpep_pccard_match(device_t dev) 25666058Simp{ 25770765Speter const struct pccard_product *pp; 25870765Speter 25970765Speter if ((pp = pccard_product_lookup(dev, ep_pccard_products, 26070765Speter sizeof(ep_pccard_products[0]), NULL)) != NULL) { 26170765Speter device_set_desc(dev, pp->pp_name); 26270765Speter return 0; 26370765Speter } 26466058Simp return EIO; 26566058Simp} 26666058Simp 26752472Simpstatic device_method_t ep_pccard_methods[] = { 26852472Simp /* Device interface */ 26966058Simp DEVMETHOD(device_probe, pccard_compat_probe), 27066058Simp DEVMETHOD(device_attach, pccard_compat_attach), 27152472Simp DEVMETHOD(device_detach, ep_pccard_detach), 27251673Smdodd 27366058Simp /* Card interface */ 27466058Simp DEVMETHOD(card_compat_match, ep_pccard_match), 27566058Simp DEVMETHOD(card_compat_probe, ep_pccard_probe), 27666058Simp DEVMETHOD(card_compat_attach, ep_pccard_attach), 27766058Simp 27852472Simp { 0, 0 } 27952472Simp}; 28051673Smdodd 28152472Simpstatic driver_t ep_pccard_driver = { 28252472Simp "ep", 28352472Simp ep_pccard_methods, 28452549Smdodd sizeof(struct ep_softc), 28552472Simp}; 28651673Smdodd 28752472Simpextern devclass_t ep_devclass; 28852472Simp 28952472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 290