if_fe_pccard.c revision 140041
1139749Simp/*-
265832Snyan * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
365832Snyan *
465832Snyan * This software may be used, modified, copied, distributed, and sold, in
565832Snyan * both source and binary form provided that the above copyright, these
665832Snyan * terms and the following disclaimer are retained.  The name of the author
765832Snyan * and/or the contributor may not be used to endorse or promote products
865832Snyan * derived from this software without specific prior written permission.
965832Snyan *
1065832Snyan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
1165832Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1265832Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1365832Snyan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
1465832Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1565832Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1665832Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
1765832Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1865832Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1965832Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2065832Snyan * SUCH DAMAGE.
2165832Snyan *
2265832Snyan */
2365832Snyan
24119418Sobrien#include <sys/cdefs.h>
25119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/fe/if_fe_pccard.c 140041 2005-01-11 06:48:38Z imp $");
26119418Sobrien
2765832Snyan#include <sys/param.h>
2865832Snyan#include <sys/kernel.h>
2965832Snyan#include <sys/socket.h>
3067158Sphk#include <sys/systm.h>
3165832Snyan#include <sys/module.h>
3265832Snyan
3365832Snyan#include <sys/bus.h>
3465832Snyan#include <machine/bus.h>
3565832Snyan#include <machine/resource.h>
3665832Snyan
3765832Snyan#include <net/ethernet.h>
3865832Snyan#include <net/if.h>
3965832Snyan#include <net/if_mib.h>
4065832Snyan#include <net/if_media.h>
4165832Snyan
4265832Snyan#include <netinet/in.h>
4365832Snyan#include <netinet/if_ether.h>
4465832Snyan
4565832Snyan#include <i386/isa/ic/mb86960.h>
4665832Snyan#include <dev/fe/if_fereg.h>
4765832Snyan#include <dev/fe/if_fevar.h>
4865832Snyan
4965832Snyan#include <dev/pccard/pccardvar.h>
50129764Simp
51129764Simp#include "card_if.h"
52129740Simp#include "pccarddevs.h"
5365832Snyan
5465832Snyan/*
5565832Snyan *	PC-Card (PCMCIA) specific code.
5665832Snyan */
5765832Snyanstatic int fe_pccard_probe(device_t);
5865832Snyanstatic int fe_pccard_attach(device_t);
5965832Snyanstatic int fe_pccard_detach(device_t);
6082778Sshibastatic int fe_pccard_match(device_t);
6165832Snyan
6282778Sshibastatic const struct fe_pccard_product {
6382778Sshiba        struct pccard_product mpp_product;
64140041Simp        uint32_t mpp_ioalign;                  /* required alignment */
6582778Sshiba        int mpp_enet_maddr;
66140041Simp	int mpp_flags;
67140041Simp#define MBH10302		0x1		/* Fujitsu MBH10302 */
6882778Sshiba} fe_pccard_products[] = {
69140041Simp	/* These need to be first */
70140041Simp	{ PCMCIA_CARD(FUJITSU2, FMV_J181, 0), 0, -1, MBH10302},
71140041Simp	{ PCMCIA_CARD(FUJITSU2, FMV_J182, 0), 0, 0xf2c},
72140041Simp	{ PCMCIA_CARD(FUJITSU2, FMV_J182A, 0), 0, 0x1cc},
73140041Simp	{ PCMCIA_CARD(FUJITSU2, ITCFJ182A, 0), 0, 0x1cc},
74140041Simp	/* These need to be second */
7586394Simp        { PCMCIA_CARD(TDK, LAK_CD021BX, 0), 0, -1 },
7686394Simp        { PCMCIA_CARD(TDK, LAK_CF010, 0), 0, -1 },
7782778Sshiba#if 0 /* XXX 86960-based? */
7886394Simp        { PCMCIA_CARD(TDK, LAK_DFL9610, 1), 0, -1 },
7982778Sshiba#endif
8086394Simp        { PCMCIA_CARD(CONTEC, CNETPC, 0), 0, -1 },
8186394Simp	{ PCMCIA_CARD(FUJITSU, LA501, 0), 0x20, -1 },
8286394Simp	{ PCMCIA_CARD(FUJITSU, LA10S, 0), 0, -1 },
83140041Simp	{ PCMCIA_CARD(FUJITSU, NE200T, 0), 0, -1, MBH10302},/* Sold by Eagle */
8486394Simp	{ PCMCIA_CARD(RATOC, REX_R280, 0), 0, 0x1fc },
8582778Sshiba        { { NULL } }
8682778Sshiba};
8782778Sshiba
8882778Sshibastatic int
8982778Sshibafe_pccard_match(device_t dev)
9082778Sshiba{
9182778Sshiba        const struct pccard_product *pp;
9282778Sshiba
9382778Sshiba        if ((pp = pccard_product_lookup(dev,
9482778Sshiba	    (const struct pccard_product *)fe_pccard_products,
9582778Sshiba            sizeof(fe_pccard_products[0]), NULL)) != NULL) {
96113315Simp		if (pp->pp_name != NULL)
97113315Simp			device_set_desc(dev, pp->pp_name);
9882778Sshiba                return 0;
9982778Sshiba        }
10082778Sshiba        return EIO;
10182778Sshiba}
10282778Sshiba
10365832Snyanstatic device_method_t fe_pccard_methods[] = {
10482778Sshiba        /* Device interface */
10582778Sshiba        DEVMETHOD(device_probe,         pccard_compat_probe),
10682778Sshiba        DEVMETHOD(device_attach,        pccard_compat_attach),
10782778Sshiba        DEVMETHOD(device_detach,        fe_pccard_detach),
10865832Snyan
10982778Sshiba        /* Card interface */
11082778Sshiba        DEVMETHOD(card_compat_match,    fe_pccard_match),
11182778Sshiba        DEVMETHOD(card_compat_probe,    fe_pccard_probe),
11282778Sshiba        DEVMETHOD(card_compat_attach,   fe_pccard_attach),
11382778Sshiba
11465832Snyan	{ 0, 0 }
11565832Snyan};
11665832Snyan
11765832Snyanstatic driver_t fe_pccard_driver = {
11865832Snyan	"fe",
11965832Snyan	fe_pccard_methods,
12065832Snyan	sizeof (struct fe_softc)
12165832Snyan};
12265832Snyan
12365832SnyanDRIVER_MODULE(fe, pccard, fe_pccard_driver, fe_devclass, 0, 0);
12465832Snyan
12565832Snyan
12665832Snyanstatic int fe_probe_mbh(device_t);
12765832Snyanstatic int fe_probe_tdk(device_t);
12865832Snyan
12965832Snyan/*
13065832Snyan *      Initialize the device - called from Slot manager.
13165832Snyan */
13265832Snyanstatic int
13365832Snyanfe_pccard_probe(device_t dev)
13465832Snyan{
13565832Snyan	struct fe_softc *sc;
13665832Snyan	int error;
13765832Snyan
13865832Snyan	/* Prepare for the device probe process.  */
13965832Snyan	sc = device_get_softc(dev);
14065832Snyan	sc->sc_unit = device_get_unit(dev);
14165832Snyan
14265832Snyan	pccard_get_ether(dev, sc->sc_enaddr);
14365832Snyan
14465832Snyan	/* Probe for supported cards.  */
14565832Snyan	if ((error = fe_probe_mbh(dev)) == 0)
14665832Snyan		goto end;
14765832Snyan	fe_release_resource(dev);
14865832Snyan
14965832Snyan	if ((error = fe_probe_tdk(dev)) == 0)
15065832Snyan		goto end;
15165832Snyan	fe_release_resource(dev);
15265832Snyan
15365832Snyanend:
15465832Snyan	if (error == 0)
15565832Snyan		error = fe_alloc_irq(dev, 0);
15665832Snyan
15765832Snyan	fe_release_resource(dev);
15865832Snyan	return (error);
15965832Snyan}
16065832Snyan
16165832Snyanstatic int
16265832Snyanfe_pccard_attach(device_t dev)
16365832Snyan{
16465832Snyan	struct fe_softc *sc = device_get_softc(dev);
16565832Snyan
16665832Snyan	if (sc->port_used)
16765832Snyan		fe_alloc_port(dev, sc->port_used);
16865832Snyan	fe_alloc_irq(dev, 0);
16965832Snyan
17065832Snyan	return fe_attach(dev);
17165832Snyan}
17265832Snyan
17365832Snyan/*
17465832Snyan *	feunload - unload the driver and clear the table.
17565832Snyan */
17665832Snyanstatic int
17765832Snyanfe_pccard_detach(device_t dev)
17865832Snyan{
17965832Snyan	struct fe_softc *sc = device_get_softc(dev);
18065832Snyan	struct ifnet *ifp = &sc->arpcom.ac_if;
18165832Snyan
18265832Snyan	fe_stop(sc);
183106937Ssam	ether_ifdetach(ifp);
18465832Snyan	bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
18565832Snyan	fe_release_resource(dev);
18665832Snyan
18765832Snyan	return 0;
18865832Snyan}
18965832Snyan
19065832Snyan
19165832Snyan/*
19265832Snyan * Probe and initialization for Fujitsu MBH10302 PCMCIA Ethernet interface.
19365832Snyan * Note that this is for 10302 only; MBH10304 is handled by fe_probe_tdk().
19465832Snyan */
19565832Snyanstatic void
19665832Snyanfe_init_mbh(struct fe_softc *sc)
19765832Snyan{
19865832Snyan	/* Minimal initialization of 86960.  */
19965832Snyan	DELAY(200);
20065832Snyan	fe_outb(sc, FE_DLCR6, sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
20165832Snyan	DELAY(200);
20265832Snyan
20365832Snyan	/* Disable all interrupts.  */
20465832Snyan	fe_outb(sc, FE_DLCR2, 0);
20565832Snyan	fe_outb(sc, FE_DLCR3, 0);
20665832Snyan
20765832Snyan	/* Enable master interrupt flag.  */
20865832Snyan	fe_outb(sc, FE_MBH0, FE_MBH0_MAGIC | FE_MBH0_INTR_ENABLE);
20965832Snyan}
21065832Snyan
21165832Snyanstatic int
21265832Snyanfe_probe_mbh(device_t dev)
21365832Snyan{
21465832Snyan	struct fe_softc *sc = device_get_softc(dev);
21565832Snyan
21665832Snyan	static struct fe_simple_probe_struct probe_table [] = {
21765832Snyan		{ FE_DLCR2, 0x58, 0x00 },
21865832Snyan		{ FE_DLCR4, 0x08, 0x00 },
21965832Snyan		{ FE_DLCR6, 0xFF, 0xB6 },
22065832Snyan		{ 0 }
22165832Snyan	};
22265832Snyan
22365832Snyan	/* MBH10302 occupies 32 I/O addresses. */
22465832Snyan	if (fe_alloc_port(dev, 32))
22565832Snyan		return ENXIO;
22665832Snyan
22765832Snyan	/* Ethernet MAC address should *NOT* have been given by pccardd,
22865832Snyan	   if this is a true MBH10302; i.e., Ethernet address must be
22965832Snyan	   "all-zero" upon entry.  */
23065832Snyan	if (sc->sc_enaddr[0] || sc->sc_enaddr[1] || sc->sc_enaddr[2] ||
23165832Snyan	    sc->sc_enaddr[3] || sc->sc_enaddr[4] || sc->sc_enaddr[5])
23265832Snyan		return ENXIO;
23365832Snyan
23465832Snyan	/* Fill the softc struct with default values.  */
23565832Snyan	fe_softc_defaults(sc);
23665832Snyan
23765832Snyan	/*
23865832Snyan	 * See if MBH10302 is on its address.
23965832Snyan	 * I'm not sure the following probe code works.  FIXME.
24065832Snyan	 */
24165832Snyan	if (!fe_simple_probe(sc, probe_table))
24265832Snyan		return ENXIO;
24365832Snyan
24465832Snyan	/* Get our station address from EEPROM.  */
24565832Snyan	fe_inblk(sc, FE_MBH10, sc->sc_enaddr, ETHER_ADDR_LEN);
24665832Snyan
24765832Snyan	/* Make sure we got a valid station address.  */
248139972Simp	if (!fe_valid_Ether_p(sc->sc_enaddr, 0))
24965832Snyan		return ENXIO;
25065832Snyan
25165832Snyan	/* Determine the card type.  */
25265832Snyan	sc->type = FE_TYPE_MBH;
25365832Snyan	sc->typestr = "MBH10302 (PCMCIA)";
25465832Snyan
25565832Snyan	/* We seems to need our own IDENT bits...  FIXME.  */
25665832Snyan	sc->proto_dlcr7 = FE_D7_BYTSWP_LH | FE_D7_IDENT_NICE;
25765832Snyan
25865832Snyan	/* Setup hooks.  We need a special initialization procedure.  */
25965832Snyan	sc->init = fe_init_mbh;
26065832Snyan
26165832Snyan	return 0;
26265832Snyan}
26365832Snyan
26465832Snyan/*
26565832Snyan * Probe and initialization for TDK/CONTEC PCMCIA Ethernet interface.
26665832Snyan * by MASUI Kenji <masui@cs.titech.ac.jp>
26765832Snyan *
26865832Snyan * (Contec uses TDK Ethenet chip -- hosokawa)
26965832Snyan *
27065832Snyan * This version of fe_probe_tdk has been rewrote to handle
27165832Snyan * *generic* PC card implementation of Fujitsu MB8696x family.  The
27265832Snyan * name _tdk is just for a historical reason. :-)
27365832Snyan */
27465832Snyanstatic int
27565832Snyanfe_probe_tdk (device_t dev)
27665832Snyan{
27765832Snyan	struct fe_softc *sc = device_get_softc(dev);
27865832Snyan
27965832Snyan        static struct fe_simple_probe_struct probe_table [] = {
28065832Snyan                { FE_DLCR2, 0x50, 0x00 },
28165832Snyan                { FE_DLCR4, 0x08, 0x00 },
28265832Snyan            /*  { FE_DLCR5, 0x80, 0x00 },       Does not work well.  */
28365832Snyan                { 0 }
28465832Snyan        };
28565832Snyan
28665832Snyan        /* C-NET(PC)C occupies 16 I/O addresses. */
28765832Snyan	if (fe_alloc_port(dev, 16))
28865832Snyan		return ENXIO;
28965832Snyan
29065832Snyan	/* Fill the softc struct with default values.  */
29165832Snyan	fe_softc_defaults(sc);
29265832Snyan
29365832Snyan        /*
29465832Snyan         * See if C-NET(PC)C is on its address.
29565832Snyan         */
29665832Snyan        if (!fe_simple_probe(sc, probe_table))
29765832Snyan		return ENXIO;
29865832Snyan
29965832Snyan        /* Determine the card type.  */
30065832Snyan	sc->type = FE_TYPE_TDK;
30165832Snyan        sc->typestr = "Generic MB8696x/78Q837x Ethernet (PCMCIA)";
30265832Snyan
30365832Snyan        /* Make sure we got a valid station address.  */
304139972Simp        if (!fe_valid_Ether_p(sc->sc_enaddr, 0))
30565832Snyan		return ENXIO;
30665832Snyan
30765832Snyan        return 0;
30865832Snyan}
309