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$");
29117700Smarkm
3051673Smdodd#include <sys/param.h>
31257324Sglebius#include <sys/systm.h>
3251673Smdodd#include <sys/kernel.h>
3351673Smdodd#include <sys/socket.h>
34257324Sglebius#include <sys/lock.h>
3551673Smdodd#include <sys/module.h>
36257324Sglebius#include <sys/mutex.h>
3751673Smdodd#include <sys/bus.h>
3852549Smdodd
3951673Smdodd#include <machine/bus.h>
4051673Smdodd#include <machine/resource.h>
4151673Smdodd#include <sys/rman.h>
42117700Smarkm
43117700Smarkm#include <net/if.h>
4452549Smdodd#include <net/if_media.h>
4551673Smdodd
4651673Smdodd#include <dev/mca/mca_busreg.h>
4751673Smdodd#include <dev/mca/mca_busvar.h>
4851673Smdodd
4951673Smdodd#include <dev/ep/if_epreg.h>
5051673Smdodd#include <dev/ep/if_epvar.h>
5151673Smdodd
5251673Smdodd#define EP_MCA_627C	0x627C
5351673Smdodd#define EP_MCA_627D	0x627D
5451673Smdodd#define EP_MCA_62DB	0x62db
5551673Smdodd#define EP_MCA_62F6	0x62f6
5651673Smdodd#define EP_MCA_62F7	0x62f7
5751673Smdodd
5851673Smdoddstatic struct mca_ident ep_mca_devs[] = {
59117700Smarkm	{EP_MCA_627C, "3Com 3C529 Network Adapter"},
60117700Smarkm	{EP_MCA_627D, "3Com 3C529-TP Network Adapter"},
6151673Smdodd
6251673Smdodd	/*
6351673Smdodd	 * These are from the linux 3c509 driver.
64117700Smarkm	 * I have not seen the ADFs for them and have
6551673Smdodd	 * not tested or even seen the hardware.
6651673Smdodd 	 * Someone with the ADFs should replace the names with
6751673Smdodd	 * whatever is in the AdapterName field of the ADF.
6851673Smdodd	 * (and fix the media setup for the cards as well.)
6951673Smdodd	 */
70117700Smarkm	{EP_MCA_62DB, "3Com 3c529 EtherLink III (test mode)"},
71117700Smarkm	{EP_MCA_62F6, "3Com 3c529 EtherLink III (TP or coax)"},
72117700Smarkm	{EP_MCA_62F7, "3Com 3c529 EtherLink III (TP)"},
7351673Smdodd
74117700Smarkm	{0, NULL},
7551673Smdodd};
7651673Smdodd
7751673Smdodd#define EP_MCA_IOPORT_POS	MCA_ADP_POS(MCA_POS2)
7851673Smdodd#define EP_MCA_IOPORT_MASK	0xfc
7952549Smdodd#define EP_MCA_IOPORT_SIZE	EP_IOSIZE
80140523Simp#define EP_MCA_IOPORT(pos)	((((uint32_t)pos & EP_MCA_IOPORT_MASK) \
8151673Smdodd					| 0x02) << 8)
8251673Smdodd
8351673Smdodd#define EP_MCA_IRQ_POS		MCA_ADP_POS(MCA_POS3)
8451673Smdodd#define EP_MCA_IRQ_MASK		0x0f
8551673Smdodd#define EP_MCA_IRQ(pos)		(pos & EP_MCA_IRQ_MASK)
8651673Smdodd
8751673Smdodd#define EP_MCA_MEDIA_POS	MCA_ADP_POS(MCA_POS2)
8851673Smdodd#define EP_MCA_MEDIA_MASK	0x03
8951673Smdodd#define EP_MCA_MEDIA(pos)	(pos & EP_MCA_MEDIA_MASK)
9051673Smdodd
9151673Smdoddstatic int
92117700Smarkmep_mca_probe(device_t dev)
9351673Smdodd{
94117700Smarkm	const char *desc;
95140523Simp	uint32_t iobase = 0;
96140523Simp	uint8_t irq = 0;
97140523Simp	uint8_t pos;
9851673Smdodd
9951673Smdodd	desc = mca_match_id(mca_get_id(dev), ep_mca_devs);
10051673Smdodd	if (!desc)
10151673Smdodd		return (ENXIO);
10251673Smdodd	device_set_desc(dev, desc);
10351673Smdodd
10451673Smdodd	pos = mca_pos_read(dev, EP_MCA_IOPORT_POS);
10551673Smdodd	iobase = EP_MCA_IOPORT(pos);
10651673Smdodd
10751673Smdodd	pos = mca_pos_read(dev, EP_MCA_IRQ_POS);
10851673Smdodd	irq = EP_MCA_IRQ(pos);
10951673Smdodd
11051673Smdodd	mca_add_iospace(dev, iobase, EP_MCA_IOPORT_SIZE);
11151673Smdodd	mca_add_irq(dev, irq);
11251673Smdodd
11351673Smdodd	return (0);
11451673Smdodd}
11551673Smdodd
11651673Smdoddstatic int
117117700Smarkmep_mca_attach(device_t dev)
11851673Smdodd{
119117700Smarkm	struct ep_softc *sc = device_get_softc(dev);
120117700Smarkm	int error = 0;
12151673Smdodd
122147717Simp	if ((error = ep_alloc(dev)))
12351673Smdodd		goto bad;
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
131147717Simp	if ((error = ep_attach(sc)))
13251673Smdodd		goto bad;
133166906Spiso	if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, NULL, ep_intr,
134117700Smarkm		    sc, &sc->ep_intrhand))) {
13552549Smdodd		device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
13651673Smdodd		goto bad;
13751673Smdodd	}
13851673Smdodd	return (0);
13951673Smdoddbad:
14052549Smdodd	ep_free(dev);
14152549Smdodd	return (error);
14251673Smdodd}
14351673Smdodd
14451673Smdoddstatic device_method_t ep_mca_methods[] = {
14551673Smdodd	/* Device interface */
146117700Smarkm	DEVMETHOD(device_probe, ep_mca_probe),
147117700Smarkm	DEVMETHOD(device_attach, ep_mca_attach),
148117700Smarkm	DEVMETHOD(device_detach, ep_detach),
14951673Smdodd
150246128Ssbz	DEVMETHOD_END
15151673Smdodd};
15251673Smdodd
15351673Smdoddstatic driver_t ep_mca_driver = {
15451673Smdodd	"ep",
15551673Smdodd	ep_mca_methods,
15652549Smdodd	sizeof(struct ep_softc),
15751673Smdodd};
15851673Smdodd
15951673Smdoddstatic devclass_t ep_devclass;
16051673Smdodd
16151673SmdoddDRIVER_MODULE(ep, mca, ep_mca_driver, ep_devclass, 0, 0);
162