1999-09-26 06:42:36 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 Matthew N. Dodd <winter@jurai.net>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-09-26 06:42:36 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
|
1999-09-26 06:42:36 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
2003-07-17 19:37:56 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_media.h>
|
1999-09-26 06:42:36 +00:00
|
|
|
|
|
|
|
#include <dev/mca/mca_busreg.h>
|
|
|
|
#include <dev/mca/mca_busvar.h>
|
|
|
|
|
|
|
|
#include <dev/ep/if_epreg.h>
|
|
|
|
#include <dev/ep/if_epvar.h>
|
|
|
|
|
|
|
|
#define EP_MCA_627C 0x627C
|
|
|
|
#define EP_MCA_627D 0x627D
|
|
|
|
#define EP_MCA_62DB 0x62db
|
|
|
|
#define EP_MCA_62F6 0x62f6
|
|
|
|
#define EP_MCA_62F7 0x62f7
|
|
|
|
|
|
|
|
static struct mca_ident ep_mca_devs[] = {
|
2003-07-17 19:37:56 +00:00
|
|
|
{EP_MCA_627C, "3Com 3C529 Network Adapter"},
|
|
|
|
{EP_MCA_627D, "3Com 3C529-TP Network Adapter"},
|
1999-09-26 06:42:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are from the linux 3c509 driver.
|
2003-07-17 19:37:56 +00:00
|
|
|
* I have not seen the ADFs for them and have
|
1999-09-26 06:42:36 +00:00
|
|
|
* not tested or even seen the hardware.
|
|
|
|
* Someone with the ADFs should replace the names with
|
|
|
|
* whatever is in the AdapterName field of the ADF.
|
|
|
|
* (and fix the media setup for the cards as well.)
|
|
|
|
*/
|
2003-07-17 19:37:56 +00:00
|
|
|
{EP_MCA_62DB, "3Com 3c529 EtherLink III (test mode)"},
|
|
|
|
{EP_MCA_62F6, "3Com 3c529 EtherLink III (TP or coax)"},
|
|
|
|
{EP_MCA_62F7, "3Com 3c529 EtherLink III (TP)"},
|
1999-09-26 06:42:36 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
{0, NULL},
|
1999-09-26 06:42:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define EP_MCA_IOPORT_POS MCA_ADP_POS(MCA_POS2)
|
|
|
|
#define EP_MCA_IOPORT_MASK 0xfc
|
1999-10-27 06:25:16 +00:00
|
|
|
#define EP_MCA_IOPORT_SIZE EP_IOSIZE
|
2005-01-20 19:39:33 +00:00
|
|
|
#define EP_MCA_IOPORT(pos) ((((uint32_t)pos & EP_MCA_IOPORT_MASK) \
|
1999-09-26 06:42:36 +00:00
|
|
|
| 0x02) << 8)
|
|
|
|
|
|
|
|
#define EP_MCA_IRQ_POS MCA_ADP_POS(MCA_POS3)
|
|
|
|
#define EP_MCA_IRQ_MASK 0x0f
|
|
|
|
#define EP_MCA_IRQ(pos) (pos & EP_MCA_IRQ_MASK)
|
|
|
|
|
|
|
|
#define EP_MCA_MEDIA_POS MCA_ADP_POS(MCA_POS2)
|
|
|
|
#define EP_MCA_MEDIA_MASK 0x03
|
|
|
|
#define EP_MCA_MEDIA(pos) (pos & EP_MCA_MEDIA_MASK)
|
|
|
|
|
|
|
|
static int
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_mca_probe(device_t dev)
|
1999-09-26 06:42:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
const char *desc;
|
2005-01-20 19:39:33 +00:00
|
|
|
uint32_t iobase = 0;
|
|
|
|
uint8_t irq = 0;
|
|
|
|
uint8_t pos;
|
1999-09-26 06:42:36 +00:00
|
|
|
|
|
|
|
desc = mca_match_id(mca_get_id(dev), ep_mca_devs);
|
|
|
|
if (!desc)
|
|
|
|
return (ENXIO);
|
|
|
|
device_set_desc(dev, desc);
|
|
|
|
|
|
|
|
pos = mca_pos_read(dev, EP_MCA_IOPORT_POS);
|
|
|
|
iobase = EP_MCA_IOPORT(pos);
|
|
|
|
|
|
|
|
pos = mca_pos_read(dev, EP_MCA_IRQ_POS);
|
|
|
|
irq = EP_MCA_IRQ(pos);
|
|
|
|
|
|
|
|
mca_add_iospace(dev, iobase, EP_MCA_IOPORT_SIZE);
|
|
|
|
mca_add_irq(dev, irq);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_mca_attach(device_t dev)
|
1999-09-26 06:42:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = device_get_softc(dev);
|
|
|
|
int error = 0;
|
1999-09-26 06:42:36 +00:00
|
|
|
|
2005-07-01 05:31:23 +00:00
|
|
|
if ((error = ep_alloc(dev)))
|
1999-09-26 06:42:36 +00:00
|
|
|
goto bad;
|
|
|
|
sc->stat = F_ACCESS_32_BITS;
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_get_media(sc);
|
1999-09-26 06:42:36 +00:00
|
|
|
|
2003-10-26 22:28:20 +00:00
|
|
|
GO_WINDOW(sc, 0);
|
2003-10-19 09:31:07 +00:00
|
|
|
SET_IRQ(sc, rman_get_start(sc->irq));
|
1999-09-26 06:42:36 +00:00
|
|
|
|
2005-07-01 05:31:23 +00:00
|
|
|
if ((error = ep_attach(sc)))
|
1999-10-27 06:25:16 +00:00
|
|
|
goto bad;
|
2007-02-23 15:55:37 +00:00
|
|
|
if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, NULL, ep_intr,
|
2003-07-17 19:37:56 +00:00
|
|
|
sc, &sc->ep_intrhand))) {
|
1999-10-27 06:25:16 +00:00
|
|
|
device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
|
|
|
|
goto bad;
|
|
|
|
}
|
1999-09-26 06:42:36 +00:00
|
|
|
return (0);
|
|
|
|
bad:
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_free(dev);
|
|
|
|
return (error);
|
1999-09-26 06:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t ep_mca_methods[] = {
|
|
|
|
/* Device interface */
|
2003-07-17 19:37:56 +00:00
|
|
|
DEVMETHOD(device_probe, ep_mca_probe),
|
|
|
|
DEVMETHOD(device_attach, ep_mca_attach),
|
|
|
|
DEVMETHOD(device_detach, ep_detach),
|
1999-09-26 06:42:36 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
{0, 0}
|
1999-09-26 06:42:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ep_mca_driver = {
|
|
|
|
"ep",
|
|
|
|
ep_mca_methods,
|
1999-10-27 06:25:16 +00:00
|
|
|
sizeof(struct ep_softc),
|
1999-09-26 06:42:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t ep_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(ep, mca, ep_mca_driver, ep_devclass, 0, 0);
|