if_ep_pccard.c revision 56017
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 56017 2000-01-15 05:21:43Z mdodd $ 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> 4952472Simp#include <sys/rman.h> 5052549Smdodd 5152549Smdodd#include <net/if.h> 5252549Smdodd#include <net/if_arp.h> 5352549Smdodd#include <net/if_media.h> 5451673Smdodd 5551673Smdodd#include <machine/clock.h> 5651673Smdodd 5752472Simp#include <dev/ep/if_epreg.h> 5852472Simp#include <dev/ep/if_epvar.h> 5952472Simp 6052472Simpstatic const char *ep_pccard_identify(u_short id); 6151673Smdodd 6251673Smdodd/* 6351673Smdodd * Initialize the device - called from Slot manager. 6451673Smdodd */ 6551673Smdoddstatic int 6652472Simpep_pccard_probe(device_t dev) 6751673Smdodd{ 6852549Smdodd struct ep_softc * sc = device_get_softc(dev); 6952549Smdodd struct ep_board * epb = &sc->epb; 7052549Smdodd const char * desc; 7152549Smdodd int error; 7251673Smdodd 7352589Simp error = ep_alloc(dev); 7452589Simp if (error) 7552472Simp return error; 7652549Smdodd 7752472Simp /* 7852472Simp * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 7952472Simp * 2. Sadly, you need to have a correct cmd_off in order to 8052472Simp * identify the card. So we have to hit it with both and 8152472Simp * cross our virtual fingers. There's got to be a better way 8252472Simp * to do this. jyoung@accessus.net 09/11/1999 8352472Simp */ 8451673Smdodd 8552472Simp epb->cmd_off = 0; 8651673Smdodd epb->prod_id = get_e(sc, EEPROM_PROD_ID); 8752472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 8852472Simp if (bootverbose) 8952472Simp device_printf(dev, "Pass 1 of 2 detection " 9052472Simp "failed (nonfatal)\n"); 9152472Simp epb->cmd_off = 2; 9252472Simp epb->prod_id = get_e(sc, EEPROM_PROD_ID); 9352589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 9452472Simp device_printf(dev, "Unit failed to come ready or " 9552472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 9652589Simp ep_free(dev); 9752472Simp return (ENXIO); 9852472Simp } 9951673Smdodd } 10052589Simp device_set_desc(dev, desc); 10156017Smdodd 10256017Smdodd /* 10356017Smdodd * For some reason the 3c574 needs this. 10456017Smdodd */ 10556017Smdodd ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 10656017Smdodd 10752589Simp ep_free(dev); 10852472Simp return (0); 10952472Simp} 11051673Smdodd 11152472Simpstatic const char * 11252472Simpep_pccard_identify(u_short id) 11352472Simp{ 11452472Simp /* Determine device type and associated MII capabilities */ 11552472Simp switch (id) { 11652472Simp case 0x6055: /* 3C556 */ 11752472Simp return ("3Com 3C556"); 11852472Simp case 0x4057: /* 3C574 */ 11952589Simp return ("3Com 3C574"); 12052472Simp case 0x4b57: /* 3C574B */ 12152589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 12252472Simp "Fast Etherlink 3C574-TX"); 12355702Simp case 0x2b57: /* 3CXSH572BT */ 12455702Simp return ("3Com OfficeConnect 572BT"); 12552472Simp case 0x9058: /* 3C589 */ 12652589Simp return ("3Com Etherlink III 3C589"); 12752621Simp case 0x2056: /* 3C562/3C563 */ 12852621Simp return ("3Com 3C562D/3C563D"); 12952472Simp } 13052589Simp return (NULL); 13151673Smdodd} 13251673Smdodd 13351673Smdoddstatic int 13452472Simpep_pccard_card_attach(struct ep_board *epb) 13551673Smdodd{ 13652472Simp /* Determine device type and associated MII capabilities */ 13752472Simp switch (epb->prod_id) { 13851673Smdodd case 0x6055: /* 3C556 */ 13955702Simp case 0x2b57: /* 3C572BT */ 14051673Smdodd case 0x4057: /* 3C574 */ 14151673Smdodd case 0x4b57: /* 3C574B */ 14252472Simp epb->mii_trans = 1; 14352472Simp return (1); 14452621Simp case 0x2056: /* 3C562D/3C563D */ 14551673Smdodd case 0x9058: /* 3C589 */ 14652472Simp epb->mii_trans = 0; 14752472Simp return (1); 14852472Simp } 14952472Simp return (0); 15051673Smdodd} 15151673Smdodd 15251673Smdoddstatic int 15352472Simpep_pccard_attach(device_t dev) 15451673Smdodd{ 15552549Smdodd struct ep_softc * sc = device_get_softc(dev); 15652549Smdodd int error = 0; 15751673Smdodd 15852585Simp if ((error = ep_alloc(dev))) { 15952549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 16052472Simp goto bad; 16152472Simp } 16251673Smdodd 16352589Simp sc->epb.cmd_off = 0; 16452589Simp sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 16552549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 16652549Smdodd sc->epb.cmd_off = 2; 16752549Smdodd sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 16852549Smdodd sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 16952549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 17052472Simp device_printf(dev, 17152472Simp "Probe found ID, attach failed so ignore card!\n"); 17252549Smdodd error = ENXIO; 17352549Smdodd goto bad; 17452472Simp } 17552472Simp } 17651673Smdodd 17752472Simp /* ROM size = 0, ROM base = 0 */ 17852472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 17952472Simp outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 18052472Simp 18152472Simp /* Fake IRQ must be 3 */ 18252549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 18352472Simp 18452549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 18552472Simp 18652549Smdodd if (sc->epb.mii_trans) { 18752472Simp /* 18852472Simp * turn on the MII transciever 18952472Simp */ 19052472Simp GO_WINDOW(3); 19152472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19252472Simp DELAY(1000); 19352472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 19452472Simp outw(BASE + EP_COMMAND, RX_RESET); 19552472Simp outw(BASE + EP_COMMAND, TX_RESET); 19652472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 19752472Simp DELAY(1000); 19852472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19952549Smdodd } else { 20052549Smdodd ep_get_media(sc); 20152472Simp } 20252472Simp 20352549Smdodd if ((error = ep_attach(sc))) { 20452549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 20552472Simp goto bad; 20652472Simp } 20752472Simp 20852585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 20952585Simp sc, &sc->ep_intrhand))) { 21052549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 21152472Simp goto bad; 21252472Simp } 21352472Simp 21452549Smdodd return (0); 21552472Simpbad: 21652585Simp ep_free(dev); 21752549Smdodd return (error); 21851673Smdodd} 21951673Smdodd 22053978Simpstatic int 22152472Simpep_pccard_detach(device_t dev) 22251673Smdodd{ 22352472Simp struct ep_softc *sc = device_get_softc(dev); 22451673Smdodd 22552472Simp if (sc->gone) { 22652472Simp device_printf(dev, "already unloaded\n"); 22753978Simp return (0); 22852472Simp } 22952472Simp sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 23053978Simp if_detach(&sc->arpcom.ac_if); 23152472Simp sc->gone = 1; 23252549Smdodd bus_teardown_intr(dev, sc->irq, sc->ep_intrhand); 23352549Smdodd ep_free(dev); 23452472Simp device_printf(dev, "unload\n"); 23553978Simp return (0); 23651673Smdodd} 23751673Smdodd 23852472Simpstatic device_method_t ep_pccard_methods[] = { 23952472Simp /* Device interface */ 24052472Simp DEVMETHOD(device_probe, ep_pccard_probe), 24152472Simp DEVMETHOD(device_attach, ep_pccard_attach), 24252472Simp DEVMETHOD(device_detach, ep_pccard_detach), 24351673Smdodd 24452472Simp { 0, 0 } 24552472Simp}; 24651673Smdodd 24752472Simpstatic driver_t ep_pccard_driver = { 24852472Simp "ep", 24952472Simp ep_pccard_methods, 25052549Smdodd sizeof(struct ep_softc), 25152472Simp}; 25251673Smdodd 25352472Simpextern devclass_t ep_devclass; 25452472Simp 25552472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 256