if_ep_mca.c revision 140523
151673Smdodd/*- 251673Smdodd * Copyright (c) 1999 Matthew N. Dodd <winter@jurai.net> 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 * 1451673Smdodd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1551673Smdodd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1651673Smdodd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1751673Smdodd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1851673Smdodd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1951673Smdodd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2051673Smdodd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2151673Smdodd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2251673Smdodd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2351673Smdodd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2451673Smdodd * SUCH DAMAGE. 2551673Smdodd */ 2651673Smdodd 27117700Smarkm#include <sys/cdefs.h> 28117700Smarkm__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_mca.c 140523 2005-01-20 19:39:33Z imp $"); 29117700Smarkm 3051673Smdodd#include <sys/param.h> 3151673Smdodd#include <sys/kernel.h> 3251673Smdodd#include <sys/socket.h> 3351673Smdodd#include <sys/module.h> 3451673Smdodd#include <sys/bus.h> 3552549Smdodd 3651673Smdodd#include <machine/bus.h> 3751673Smdodd#include <machine/resource.h> 3851673Smdodd#include <sys/rman.h> 39117700Smarkm 40117700Smarkm#include <net/if.h> 4152549Smdodd#include <net/if_arp.h> 4252549Smdodd#include <net/if_media.h> 4351673Smdodd 4451673Smdodd#include <dev/mca/mca_busreg.h> 4551673Smdodd#include <dev/mca/mca_busvar.h> 4651673Smdodd 4751673Smdodd#include <dev/ep/if_epreg.h> 4851673Smdodd#include <dev/ep/if_epvar.h> 4951673Smdodd 5051673Smdodd#define EP_MCA_627C 0x627C 5151673Smdodd#define EP_MCA_627D 0x627D 5251673Smdodd#define EP_MCA_62DB 0x62db 5351673Smdodd#define EP_MCA_62F6 0x62f6 5451673Smdodd#define EP_MCA_62F7 0x62f7 5551673Smdodd 5651673Smdoddstatic struct mca_ident ep_mca_devs[] = { 57117700Smarkm {EP_MCA_627C, "3Com 3C529 Network Adapter"}, 58117700Smarkm {EP_MCA_627D, "3Com 3C529-TP Network Adapter"}, 5951673Smdodd 6051673Smdodd /* 6151673Smdodd * These are from the linux 3c509 driver. 62117700Smarkm * I have not seen the ADFs for them and have 6351673Smdodd * not tested or even seen the hardware. 6451673Smdodd * Someone with the ADFs should replace the names with 6551673Smdodd * whatever is in the AdapterName field of the ADF. 6651673Smdodd * (and fix the media setup for the cards as well.) 6751673Smdodd */ 68117700Smarkm {EP_MCA_62DB, "3Com 3c529 EtherLink III (test mode)"}, 69117700Smarkm {EP_MCA_62F6, "3Com 3c529 EtherLink III (TP or coax)"}, 70117700Smarkm {EP_MCA_62F7, "3Com 3c529 EtherLink III (TP)"}, 7151673Smdodd 72117700Smarkm {0, NULL}, 7351673Smdodd}; 7451673Smdodd 7551673Smdodd#define EP_MCA_IOPORT_POS MCA_ADP_POS(MCA_POS2) 7651673Smdodd#define EP_MCA_IOPORT_MASK 0xfc 7752549Smdodd#define EP_MCA_IOPORT_SIZE EP_IOSIZE 78140523Simp#define EP_MCA_IOPORT(pos) ((((uint32_t)pos & EP_MCA_IOPORT_MASK) \ 7951673Smdodd | 0x02) << 8) 8051673Smdodd 8151673Smdodd#define EP_MCA_IRQ_POS MCA_ADP_POS(MCA_POS3) 8251673Smdodd#define EP_MCA_IRQ_MASK 0x0f 8351673Smdodd#define EP_MCA_IRQ(pos) (pos & EP_MCA_IRQ_MASK) 8451673Smdodd 8551673Smdodd#define EP_MCA_MEDIA_POS MCA_ADP_POS(MCA_POS2) 8651673Smdodd#define EP_MCA_MEDIA_MASK 0x03 8751673Smdodd#define EP_MCA_MEDIA(pos) (pos & EP_MCA_MEDIA_MASK) 8851673Smdodd 8951673Smdoddstatic int 90117700Smarkmep_mca_probe(device_t dev) 9151673Smdodd{ 92117700Smarkm const char *desc; 93140523Simp uint32_t iobase = 0; 94140523Simp uint8_t irq = 0; 95140523Simp uint8_t pos; 9651673Smdodd 9751673Smdodd desc = mca_match_id(mca_get_id(dev), ep_mca_devs); 9851673Smdodd if (!desc) 9951673Smdodd return (ENXIO); 10051673Smdodd device_set_desc(dev, desc); 10151673Smdodd 10251673Smdodd pos = mca_pos_read(dev, EP_MCA_IOPORT_POS); 10351673Smdodd iobase = EP_MCA_IOPORT(pos); 10451673Smdodd 10551673Smdodd pos = mca_pos_read(dev, EP_MCA_IRQ_POS); 10651673Smdodd irq = EP_MCA_IRQ(pos); 10751673Smdodd 10851673Smdodd mca_add_iospace(dev, iobase, EP_MCA_IOPORT_SIZE); 10951673Smdodd mca_add_irq(dev, irq); 11051673Smdodd 11151673Smdodd return (0); 11251673Smdodd} 11351673Smdodd 11451673Smdoddstatic int 115117700Smarkmep_mca_attach(device_t dev) 11651673Smdodd{ 117117700Smarkm struct ep_softc *sc = device_get_softc(dev); 118117700Smarkm int error = 0; 11951673Smdodd 12052549Smdodd if ((error = ep_alloc(dev))) { 12152549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 12251673Smdodd goto bad; 12351673Smdodd } 12452549Smdodd sc->stat = F_ACCESS_32_BITS; 12551673Smdodd 12652549Smdodd ep_get_media(sc); 12752549Smdodd 128121588Simp GO_WINDOW(sc, 0); 129121241Sbms SET_IRQ(sc, rman_get_start(sc->irq)); 13052549Smdodd 13152549Smdodd if ((error = ep_attach(sc))) { 13252549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 13351673Smdodd goto bad; 13451673Smdodd } 135121492Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, ep_intr, 136117700Smarkm sc, &sc->ep_intrhand))) { 13752549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 13851673Smdodd goto bad; 13951673Smdodd } 14051673Smdodd return (0); 14151673Smdoddbad: 14252549Smdodd ep_free(dev); 14352549Smdodd return (error); 14451673Smdodd} 14551673Smdodd 14651673Smdoddstatic device_method_t ep_mca_methods[] = { 14751673Smdodd /* Device interface */ 148117700Smarkm DEVMETHOD(device_probe, ep_mca_probe), 149117700Smarkm DEVMETHOD(device_attach, ep_mca_attach), 150117700Smarkm DEVMETHOD(device_detach, ep_detach), 15151673Smdodd 152117700Smarkm {0, 0} 15351673Smdodd}; 15451673Smdodd 15551673Smdoddstatic driver_t ep_mca_driver = { 15651673Smdodd "ep", 15751673Smdodd ep_mca_methods, 15852549Smdodd sizeof(struct ep_softc), 15951673Smdodd}; 16051673Smdodd 16151673Smdoddstatic devclass_t ep_devclass; 16251673Smdodd 16351673SmdoddDRIVER_MODULE(ep, mca, ep_mca_driver, ep_devclass, 0, 0); 164