if_ep_pccard.c revision 55702
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 55702 2000-01-10 02:32:43Z 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> 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); 10152589Simp ep_free(dev); 10252472Simp return (0); 10352472Simp} 10451673Smdodd 10552472Simpstatic const char * 10652472Simpep_pccard_identify(u_short id) 10752472Simp{ 10852472Simp /* Determine device type and associated MII capabilities */ 10952472Simp switch (id) { 11052472Simp case 0x6055: /* 3C556 */ 11152472Simp return ("3Com 3C556"); 11252472Simp case 0x4057: /* 3C574 */ 11352589Simp return ("3Com 3C574"); 11452472Simp case 0x4b57: /* 3C574B */ 11552589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 11652472Simp "Fast Etherlink 3C574-TX"); 11755702Simp case 0x2b57: /* 3CXSH572BT */ 11855702Simp return ("3Com OfficeConnect 572BT"); 11952472Simp case 0x9058: /* 3C589 */ 12052589Simp return ("3Com Etherlink III 3C589"); 12152621Simp case 0x2056: /* 3C562/3C563 */ 12252621Simp return ("3Com 3C562D/3C563D"); 12352472Simp } 12452589Simp return (NULL); 12551673Smdodd} 12651673Smdodd 12751673Smdoddstatic int 12852472Simpep_pccard_card_attach(struct ep_board *epb) 12951673Smdodd{ 13052472Simp /* Determine device type and associated MII capabilities */ 13152472Simp switch (epb->prod_id) { 13251673Smdodd case 0x6055: /* 3C556 */ 13355702Simp case 0x2b57: /* 3C572BT */ 13451673Smdodd case 0x4057: /* 3C574 */ 13551673Smdodd case 0x4b57: /* 3C574B */ 13652472Simp epb->mii_trans = 1; 13752472Simp return (1); 13852621Simp case 0x2056: /* 3C562D/3C563D */ 13951673Smdodd case 0x9058: /* 3C589 */ 14052472Simp epb->mii_trans = 0; 14152472Simp return (1); 14252472Simp } 14352472Simp return (0); 14451673Smdodd} 14551673Smdodd 14651673Smdoddstatic int 14752472Simpep_pccard_attach(device_t dev) 14851673Smdodd{ 14952549Smdodd struct ep_softc * sc = device_get_softc(dev); 15052549Smdodd int error = 0; 15151673Smdodd 15252585Simp if ((error = ep_alloc(dev))) { 15352549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 15452472Simp goto bad; 15552472Simp } 15651673Smdodd 15752589Simp sc->epb.cmd_off = 0; 15852589Simp sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 15952549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 16052549Smdodd sc->epb.cmd_off = 2; 16152549Smdodd sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 16252549Smdodd sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 16352549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 16452472Simp device_printf(dev, 16552472Simp "Probe found ID, attach failed so ignore card!\n"); 16652549Smdodd error = ENXIO; 16752549Smdodd goto bad; 16852472Simp } 16952472Simp } 17051673Smdodd 17152472Simp /* ROM size = 0, ROM base = 0 */ 17252472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 17352472Simp outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 17452472Simp 17552472Simp /* Fake IRQ must be 3 */ 17652549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 17752472Simp 17852549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 17952472Simp 18052549Smdodd if (sc->epb.mii_trans) { 18152472Simp /* 18252472Simp * turn on the MII transciever 18352472Simp */ 18452472Simp GO_WINDOW(3); 18552472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 18652472Simp DELAY(1000); 18752472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 18852472Simp outw(BASE + EP_COMMAND, RX_RESET); 18952472Simp outw(BASE + EP_COMMAND, TX_RESET); 19052472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 19152472Simp DELAY(1000); 19252472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19352549Smdodd } else { 19452549Smdodd ep_get_media(sc); 19552472Simp } 19652472Simp 19752549Smdodd if ((error = ep_attach(sc))) { 19852549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 19952472Simp goto bad; 20052472Simp } 20152472Simp 20252585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 20352585Simp sc, &sc->ep_intrhand))) { 20452549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 20552472Simp goto bad; 20652472Simp } 20752472Simp 20852549Smdodd return (0); 20952472Simpbad: 21052585Simp ep_free(dev); 21152549Smdodd return (error); 21251673Smdodd} 21351673Smdodd 21453978Simpstatic int 21552472Simpep_pccard_detach(device_t dev) 21651673Smdodd{ 21752472Simp struct ep_softc *sc = device_get_softc(dev); 21851673Smdodd 21952472Simp if (sc->gone) { 22052472Simp device_printf(dev, "already unloaded\n"); 22153978Simp return (0); 22252472Simp } 22352472Simp sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 22453978Simp if_detach(&sc->arpcom.ac_if); 22552472Simp sc->gone = 1; 22652549Smdodd bus_teardown_intr(dev, sc->irq, sc->ep_intrhand); 22752549Smdodd ep_free(dev); 22852472Simp device_printf(dev, "unload\n"); 22953978Simp return (0); 23051673Smdodd} 23151673Smdodd 23252472Simpstatic device_method_t ep_pccard_methods[] = { 23352472Simp /* Device interface */ 23452472Simp DEVMETHOD(device_probe, ep_pccard_probe), 23552472Simp DEVMETHOD(device_attach, ep_pccard_attach), 23652472Simp DEVMETHOD(device_detach, ep_pccard_detach), 23751673Smdodd 23852472Simp { 0, 0 } 23952472Simp}; 24051673Smdodd 24152472Simpstatic driver_t ep_pccard_driver = { 24252472Simp "ep", 24352472Simp ep_pccard_methods, 24452549Smdodd sizeof(struct ep_softc), 24552472Simp}; 24651673Smdodd 24752472Simpextern devclass_t ep_devclass; 24852472Simp 24952472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 250