if_ep_pccard.c revision 52589
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 52589 1999-10-28 06:12:58Z 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 6052472Simp/* XXX should die XXX */ 6151673Smdodd#include <sys/select.h> 6251673Smdodd#include <sys/module.h> 6351673Smdodd#include <pccard/cardinfo.h> 6451673Smdodd#include <pccard/slot.h> 6551673Smdodd 6652472Simpstatic const char *ep_pccard_identify(u_short id); 6751673Smdodd 6851673Smdodd/* 6951673Smdodd * Initialize the device - called from Slot manager. 7051673Smdodd */ 7151673Smdoddstatic int 7252472Simpep_pccard_probe(device_t dev) 7351673Smdodd{ 7452549Smdodd struct ep_softc * sc = device_get_softc(dev); 7552549Smdodd struct ep_board * epb = &sc->epb; 7652549Smdodd const char * desc; 7752549Smdodd int error; 7851673Smdodd 7952589Simp error = ep_alloc(dev); 8052589Simp if (error) 8152472Simp return error; 8252549Smdodd 8352472Simp /* 8452472Simp * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 8552472Simp * 2. Sadly, you need to have a correct cmd_off in order to 8652472Simp * identify the card. So we have to hit it with both and 8752472Simp * cross our virtual fingers. There's got to be a better way 8852472Simp * to do this. jyoung@accessus.net 09/11/1999 8952472Simp */ 9051673Smdodd 9152472Simp epb->cmd_off = 0; 9251673Smdodd epb->prod_id = get_e(sc, EEPROM_PROD_ID); 9352472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 9452472Simp if (bootverbose) 9552472Simp device_printf(dev, "Pass 1 of 2 detection " 9652472Simp "failed (nonfatal)\n"); 9752472Simp epb->cmd_off = 2; 9852472Simp epb->prod_id = get_e(sc, EEPROM_PROD_ID); 9952589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 10052472Simp device_printf(dev, "Unit failed to come ready or " 10152472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 10252589Simp ep_free(dev); 10352472Simp return (ENXIO); 10452472Simp } 10551673Smdodd } 10652589Simp device_set_desc(dev, desc); 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"); 12352472Simp case 0x9058: /* 3C589 */ 12452589Simp return ("3Com Etherlink III 3C589"); 12552472Simp } 12652589Simp return (NULL); 12751673Smdodd} 12851673Smdodd 12951673Smdoddstatic int 13052472Simpep_pccard_card_attach(struct ep_board *epb) 13151673Smdodd{ 13252472Simp /* Determine device type and associated MII capabilities */ 13352472Simp switch (epb->prod_id) { 13451673Smdodd case 0x6055: /* 3C556 */ 13552472Simp epb->mii_trans = 1; 13652472Simp return (1); 13751673Smdodd case 0x4057: /* 3C574 */ 13852472Simp epb->mii_trans = 1; 13952472Simp return (1); 14051673Smdodd case 0x4b57: /* 3C574B */ 14152472Simp epb->mii_trans = 1; 14252472Simp return (1); 14351673Smdodd case 0x9058: /* 3C589 */ 14452472Simp epb->mii_trans = 0; 14552472Simp return (1); 14652472Simp } 14752472Simp return (0); 14851673Smdodd} 14951673Smdodd 15051673Smdoddstatic int 15152472Simpep_pccard_attach(device_t dev) 15251673Smdodd{ 15352549Smdodd struct ep_softc * sc = device_get_softc(dev); 15452549Smdodd int error = 0; 15551673Smdodd 15652585Simp if ((error = ep_alloc(dev))) { 15752549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 15852472Simp goto bad; 15952472Simp } 16051673Smdodd 16152589Simp sc->epb.cmd_off = 0; 16252589Simp sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 16352549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 16452549Smdodd sc->epb.cmd_off = 2; 16552549Smdodd sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); 16652549Smdodd sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); 16752549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 16852472Simp device_printf(dev, 16952472Simp "Probe found ID, attach failed so ignore card!\n"); 17052549Smdodd error = ENXIO; 17152549Smdodd goto bad; 17252472Simp } 17352472Simp } 17451673Smdodd 17552472Simp /* ROM size = 0, ROM base = 0 */ 17652472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 17752472Simp outw(BASE + EP_W0_ADDRESS_CFG, get_e(sc, EEPROM_ADDR_CFG) & 0xc000); 17852472Simp 17952472Simp /* Fake IRQ must be 3 */ 18052549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 18152472Simp 18252549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 18352472Simp 18452549Smdodd if (sc->epb.mii_trans) { 18552472Simp /* 18652472Simp * turn on the MII transciever 18752472Simp */ 18852472Simp GO_WINDOW(3); 18952472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19052472Simp DELAY(1000); 19152472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 19252472Simp outw(BASE + EP_COMMAND, RX_RESET); 19352472Simp outw(BASE + EP_COMMAND, TX_RESET); 19452472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 19552472Simp DELAY(1000); 19652472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 19752549Smdodd } else { 19852549Smdodd ep_get_media(sc); 19952472Simp } 20052472Simp 20152549Smdodd if ((error = ep_attach(sc))) { 20252549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 20352472Simp goto bad; 20452472Simp } 20552472Simp 20652585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 20752585Simp sc, &sc->ep_intrhand))) { 20852549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 20952472Simp goto bad; 21052472Simp } 21152472Simp 21252549Smdodd return (0); 21352472Simpbad: 21452585Simp ep_free(dev); 21552549Smdodd return (error); 21651673Smdodd} 21751673Smdodd 21851673Smdoddstatic void 21952472Simpep_pccard_detach(device_t dev) 22051673Smdodd{ 22152472Simp struct ep_softc *sc = device_get_softc(dev); 22251673Smdodd 22352472Simp printf("detach\n"); 22452472Simp 22552472Simp if (sc->gone) { 22652472Simp device_printf(dev, "already unloaded\n"); 22752472Simp return; 22852472Simp } 22952472Simp sc->arpcom.ac_if.if_flags &= ~IFF_RUNNING; 23052472Simp if_down(&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"); 23551673Smdodd} 23651673Smdodd 23752472Simpstatic device_method_t ep_pccard_methods[] = { 23852472Simp /* Device interface */ 23952472Simp DEVMETHOD(device_probe, ep_pccard_probe), 24052472Simp DEVMETHOD(device_attach, ep_pccard_attach), 24152472Simp DEVMETHOD(device_detach, ep_pccard_detach), 24251673Smdodd 24352472Simp { 0, 0 } 24452472Simp}; 24551673Smdodd 24652472Simpstatic driver_t ep_pccard_driver = { 24752472Simp "ep", 24852472Simp ep_pccard_methods, 24952549Smdodd sizeof(struct ep_softc), 25052472Simp}; 25151673Smdodd 25252472Simpextern devclass_t ep_devclass; 25352472Simp 25452472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 255