Home | History | Annotate | Line # | Download | only in apbus
if_tlp_ap.c revision 1.1.8.1
      1  1.1.8.1  thorpej /*	$NetBSD: if_tlp_ap.c,v 1.1.8.1 2001/11/13 22:24:09 thorpej Exp $	*/
      2      1.1     onoe 
      3      1.1     onoe /*
      4      1.1     onoe  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5      1.1     onoe  * All rights reserved.
      6      1.1     onoe  *
      7      1.1     onoe  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1     onoe  * by Atsushi Onoe.
      9      1.1     onoe  *
     10      1.1     onoe  * Redistribution and use in source and binary forms, with or without
     11      1.1     onoe  * modification, are permitted provided that the following conditions
     12      1.1     onoe  * are met:
     13      1.1     onoe  * 1. Redistributions of source code must retain the above copyright
     14      1.1     onoe  *    notice, this list of conditions and the following disclaimer.
     15      1.1     onoe  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1     onoe  *    notice, this list of conditions and the following disclaimer in the
     17      1.1     onoe  *    documentation and/or other materials provided with the distribution.
     18      1.1     onoe  * 3. All advertising materials mentioning features or use of this software
     19      1.1     onoe  *    must display the following acknowledgement:
     20      1.1     onoe  *	This product includes software developed by the NetBSD
     21      1.1     onoe  *	Foundation, Inc. and its contributors.
     22      1.1     onoe  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1     onoe  *    contributors may be used to endorse or promote products derived
     24      1.1     onoe  *    from this software without specific prior written permission.
     25      1.1     onoe  *
     26      1.1     onoe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1     onoe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1     onoe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1     onoe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1     onoe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1     onoe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1     onoe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1     onoe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1     onoe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1     onoe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1     onoe  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1     onoe  */
     38      1.1     onoe 
     39      1.1     onoe #include <sys/param.h>
     40      1.1     onoe #include <sys/device.h>
     41      1.1     onoe #include <sys/errno.h>
     42      1.1     onoe #include <sys/ioctl.h>
     43      1.1     onoe #include <sys/malloc.h>
     44      1.1     onoe #include <sys/socket.h>
     45      1.1     onoe #include <sys/syslog.h>
     46      1.1     onoe #include <sys/systm.h>
     47      1.1     onoe 
     48      1.1     onoe #include <net/if.h>
     49      1.1     onoe #include <net/if_dl.h>
     50      1.1     onoe #include <net/if_media.h>
     51      1.1     onoe #include <net/if_ether.h>
     52      1.1     onoe 
     53      1.1     onoe #include <machine/bus.h>
     54      1.1     onoe #include <machine/intr.h>
     55  1.1.8.1  thorpej 
     56  1.1.8.1  thorpej #include <mips/cache.h>
     57      1.1     onoe 
     58      1.1     onoe #include <dev/mii/miivar.h>
     59      1.1     onoe #include <dev/mii/mii_bitbang.h>
     60      1.1     onoe 
     61      1.1     onoe #include <dev/ic/tulipreg.h>
     62      1.1     onoe #include <dev/ic/tulipvar.h>
     63      1.1     onoe 
     64      1.1     onoe #include <newsmips/apbus/apbusvar.h>
     65      1.1     onoe 
     66      1.1     onoe #define	TLP_AP_ROM	0x00000000	/* AProm entry address */
     67      1.1     onoe #define	TLP_AP_CFG	0x00040000	/* PCI configuration registers */
     68      1.1     onoe #define		TLP_AP_CFG_CFID	0x00		/* Identification */
     69      1.1     onoe #define		TLP_AP_CFG_CFCS	0x04		/* Command and status */
     70      1.1     onoe #define		TLP_AP_CFG_CFRV	0x08		/* Revision */
     71      1.1     onoe #define		TLP_AP_CFG_CFLT	0x0c		/* Latency timer */
     72      1.1     onoe #define		TLP_AP_CFG_CBIO	0x10		/* Base I/O address */
     73      1.1     onoe #define		TLP_AP_CFG_CBMA	0x14		/* Base memory address */
     74      1.1     onoe #define		TLP_AP_CFG_CFIT	0x3c		/* Interrupt */
     75      1.1     onoe #define	TLP_AP_CSR	0x00080000	/* CSR base address */
     76      1.1     onoe #define	TLP_AP_RST	0x00100000	/* Board Reset */
     77      1.1     onoe 
     78      1.1     onoe 
     79      1.1     onoe extern void tlp_idle __P((struct tulip_softc *, u_int32_t));
     80      1.1     onoe 
     81      1.1     onoe struct tulip_ap_softc {
     82      1.1     onoe 	struct tulip_softc sc_tulip;	/* real Tulip softc */
     83      1.1     onoe 	bus_space_tag_t sc_cfst;
     84      1.1     onoe 	bus_space_handle_t sc_cfsh;
     85      1.1     onoe };
     86      1.1     onoe 
     87      1.1     onoe static int	tlp_ap_match __P((struct device *, struct cfdata *, void *));
     88      1.1     onoe static void	tlp_ap_attach __P((struct device *, struct device *, void *));
     89      1.1     onoe 
     90      1.1     onoe struct cfattach tlp_ap_ca = {
     91      1.1     onoe 	sizeof(struct tulip_ap_softc), tlp_ap_match, tlp_ap_attach
     92      1.1     onoe };
     93      1.1     onoe 
     94      1.1     onoe static void tlp_ap_preinit __P((struct tulip_softc *));
     95      1.1     onoe static void tlp_ap_tmsw_init __P((struct tulip_softc *));
     96      1.1     onoe static void tlp_ap_getmedia __P((struct tulip_softc *, struct ifmediareq *));
     97      1.1     onoe static int tlp_ap_setmedia __P((struct tulip_softc *));
     98      1.1     onoe 
     99      1.1     onoe const struct tulip_mediasw tlp_ap_mediasw = {
    100      1.1     onoe 	tlp_ap_tmsw_init, tlp_ap_getmedia, tlp_ap_setmedia
    101      1.1     onoe };
    102      1.1     onoe 
    103      1.1     onoe static int
    104      1.1     onoe tlp_ap_match(parent, cf, aux)
    105      1.1     onoe 	struct device *parent;
    106      1.1     onoe 	struct cfdata *cf;
    107      1.1     onoe 	void *aux;
    108      1.1     onoe {
    109      1.1     onoe 	struct apbus_attach_args *apa = aux;
    110      1.1     onoe 
    111      1.1     onoe 	if (strcmp(apa->apa_name, "cbasetx") != 0)
    112      1.1     onoe 		return 0;
    113      1.1     onoe 
    114      1.1     onoe 	return 1;
    115      1.1     onoe }
    116      1.1     onoe 
    117      1.1     onoe /*
    118      1.1     onoe  * Install interface into kernel networking data structures
    119      1.1     onoe  */
    120      1.1     onoe static void
    121      1.1     onoe tlp_ap_attach(parent, self, aux)
    122      1.1     onoe 	struct device *parent, *self;
    123      1.1     onoe 	void   *aux;
    124      1.1     onoe {
    125      1.1     onoe 	struct tulip_ap_softc *psc = (void *) self;
    126      1.1     onoe 	struct tulip_softc *sc = &psc->sc_tulip;
    127      1.1     onoe 	struct apbus_attach_args *apa = aux;
    128      1.1     onoe 	u_int8_t enaddr[ETHER_ADDR_LEN];
    129      1.1     onoe 	u_int intrmask;
    130      1.1     onoe 	int i;
    131      1.1     onoe 
    132      1.1     onoe 	printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
    133      1.1     onoe 
    134      1.1     onoe 	/* PCI configuration register */
    135      1.1     onoe 	psc->sc_cfst = 0;
    136      1.1     onoe 	psc->sc_cfsh = apa->apa_hwbase + TLP_AP_CFG;
    137      1.1     onoe 	sc->sc_devno = apa->apa_slotno;
    138      1.1     onoe 	sc->sc_rev = bus_space_read_4(psc->sc_cfst, psc->sc_cfsh,
    139      1.1     onoe 	    TLP_AP_CFG_CFRV);
    140      1.1     onoe 	switch (bus_space_read_4(psc->sc_cfst, psc->sc_cfsh, TLP_AP_CFG_CFID)) {
    141      1.1     onoe 	case 0x00091011:
    142      1.1     onoe 		if (sc->sc_rev >= 0x20)
    143      1.1     onoe 			sc->sc_chip = TULIP_CHIP_21140A;
    144      1.1     onoe 		else
    145      1.1     onoe 			sc->sc_chip = TULIP_CHIP_21140;
    146      1.1     onoe 		break;
    147      1.1     onoe 	default:
    148      1.1     onoe 		printf(": unable to handle your board\n");
    149      1.1     onoe 		return;
    150      1.1     onoe 	}
    151      1.1     onoe 
    152      1.1     onoe 	printf(": %s Ethernet, pass %d.%d\n",
    153      1.1     onoe 	    tlp_chip_names[sc->sc_chip],
    154      1.1     onoe 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    155      1.1     onoe 
    156      1.1     onoe 	/* CSR */
    157      1.1     onoe 	sc->sc_st = 0;
    158      1.1     onoe 	sc->sc_sh = apa->apa_hwbase + TLP_AP_CSR;
    159      1.1     onoe 	sc->sc_dmat = apbus_dmatag_init(apa);
    160      1.1     onoe 	if (sc->sc_dmat == NULL) {
    161      1.1     onoe 		printf("%s: cannot allocate memory\n", sc->sc_dev.dv_xname);
    162      1.1     onoe 		return;
    163      1.1     onoe 	}
    164      1.1     onoe 
    165      1.1     onoe 	/*
    166      1.1     onoe 	 * Initialize bus specific parameters.
    167      1.1     onoe 	 */
    168  1.1.8.1  thorpej 	if (mips_sdcache_line_size > 0)
    169  1.1.8.1  thorpej 		sc->sc_cacheline = mips_sdcache_line_size / 4;
    170  1.1.8.1  thorpej 	else if (mips_pdcache_line_size > 0)
    171  1.1.8.1  thorpej 		sc->sc_cacheline = mips_pdcache_line_size / 4;
    172      1.1     onoe 	else
    173      1.1     onoe 		sc->sc_cacheline = 4;
    174      1.1     onoe 	sc->sc_maxburst = sc->sc_cacheline;		/* XXX */
    175      1.1     onoe 	sc->sc_regshift = 3;
    176      1.1     onoe 	sc->sc_flags |= TULIPF_DBO | TULIPF_BLE;	/* Big Endian BUS */
    177      1.1     onoe 	sc->sc_flags |= TULIPF_ENABLED;			/* No Power Mgmt */
    178      1.1     onoe 
    179      1.1     onoe 	/*
    180      1.1     onoe 	 * Reset hardware.
    181      1.1     onoe 	 */
    182      1.1     onoe 	bus_space_write_4(0, apa->apa_hwbase + TLP_AP_RST, 0, 1);
    183      1.1     onoe 	delay(100);
    184      1.1     onoe 
    185      1.1     onoe 	/*
    186      1.1     onoe 	 * Initialize PCI configuration register
    187      1.1     onoe 	 */
    188      1.1     onoe 	bus_space_write_4(psc->sc_cfst, psc->sc_cfsh,
    189      1.1     onoe 	    TLP_AP_CFG_CFCS, 0x00000005);	/* Master, IO */
    190      1.1     onoe 	bus_space_write_4(psc->sc_cfst, psc->sc_cfsh,
    191      1.1     onoe 	    TLP_AP_CFG_CFLT, 0x00000100);
    192      1.1     onoe 	bus_space_write_4(psc->sc_cfst, psc->sc_cfsh,
    193      1.1     onoe 	    TLP_AP_CFG_CBIO, MIPS_KSEG1_TO_PHYS(sc->sc_sh));
    194      1.1     onoe 	bus_space_write_4(psc->sc_cfst, psc->sc_cfsh,
    195      1.1     onoe 	    TLP_AP_CFG_CFIT, 0x00000101);
    196      1.1     onoe 
    197      1.1     onoe 	/*
    198      1.1     onoe 	 * Initialize general purpose port register.
    199      1.1     onoe 	 */
    200      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, GPP_GPC | 0xc0);	/* read */
    201      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, 0x40);			/* dipsw port on */
    202      1.1     onoe 	i = TULIP_READ(sc, CSR_GPP) & GPP_MD;		/* dipsw contents */
    203      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, 0xc0);			/* dipsw port off */
    204      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, GPP_GPC | 0xcf);	/* read write */
    205      1.1     onoe 	if (sc->sc_maxburst == 16) {
    206      1.1     onoe 		TULIP_WRITE(sc, CSR_GPP, 0x8f);		/* 16word burst */
    207      1.1     onoe 		TULIP_WRITE(sc, CSR_GPP, 0xcf);
    208      1.1     onoe 	} else {
    209      1.1     onoe 		TULIP_WRITE(sc, CSR_GPP, 0x8e);		/* 8word burst */
    210      1.1     onoe 		TULIP_WRITE(sc, CSR_GPP, 0xce);
    211      1.1     onoe 	}
    212      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, GPP_GPC | 0xcf);	/* read write */
    213      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, 0xc3);			/* mask abort/dma err */
    214      1.1     onoe 	TULIP_WRITE(sc, CSR_GPP, 0xcf);			/* mask abort/dma err */
    215      1.1     onoe 
    216      1.1     onoe 	if (tlp_read_srom(sc) == 0) {
    217      1.1     onoe 		printf("%s: srom read failed\n", sc->sc_dev.dv_xname);
    218      1.1     onoe 		free(sc->sc_dmat, M_DEVBUF);
    219      1.1     onoe 		return;
    220      1.1     onoe 	}
    221      1.1     onoe 	for (i = 0; i < ETHER_ADDR_LEN; i++)
    222      1.1     onoe 		enaddr[i] = sc->sc_srom[0x11 + i * 2];
    223      1.1     onoe 
    224      1.1     onoe 	sc->sc_mediasw = &tlp_ap_mediasw;
    225      1.1     onoe 
    226      1.1     onoe 	/*
    227      1.1     onoe 	 * Finish off the attach.
    228      1.1     onoe 	 */
    229      1.1     onoe 	tlp_attach(sc, enaddr);
    230      1.1     onoe 
    231      1.1     onoe 	intrmask = SLOTTOMASK(apa->apa_slotno);
    232      1.1     onoe 	apbus_intr_establish(0, /* interrupt level (0 or 1) */
    233      1.1     onoe 			     intrmask,
    234      1.1     onoe 			     0, /* priority */
    235      1.1     onoe 			     tlp_intr, sc, apa->apa_name, apa->apa_ctlnum);
    236      1.1     onoe }
    237      1.1     onoe 
    238      1.1     onoe static void
    239      1.1     onoe tlp_ap_preinit(sc)
    240      1.1     onoe 	struct tulip_softc *sc;
    241      1.1     onoe {
    242      1.1     onoe 
    243      1.1     onoe 	sc->sc_opmode |= OPMODE_MBO | OPMODE_SCR | OPMODE_PCS | OPMODE_HBD |
    244      1.1     onoe 	    OPMODE_PS;
    245      1.1     onoe 	TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
    246      1.1     onoe }
    247      1.1     onoe 
    248      1.1     onoe static void
    249      1.1     onoe tlp_ap_tmsw_init(sc)
    250      1.1     onoe 	struct tulip_softc *sc;
    251      1.1     onoe {
    252      1.1     onoe 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    253      1.1     onoe 
    254      1.1     onoe 	sc->sc_preinit = tlp_ap_preinit;
    255      1.1     onoe 
    256      1.1     onoe 	sc->sc_mii.mii_ifp = ifp;
    257      1.1     onoe 	sc->sc_mii.mii_readreg = NULL;
    258      1.1     onoe 	sc->sc_mii.mii_writereg = NULL;
    259      1.1     onoe 	sc->sc_mii.mii_statchg = sc->sc_statchg;
    260      1.1     onoe 	ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
    261      1.1     onoe 	    tlp_mediastatus);
    262      1.1     onoe 	ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_TX, 0, NULL);
    263      1.1     onoe 	ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_TX|IFM_FDX, 0,
    264      1.1     onoe 	    NULL);
    265      1.1     onoe 	ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_TX);
    266      1.1     onoe }
    267      1.1     onoe 
    268      1.1     onoe static void
    269      1.1     onoe tlp_ap_getmedia(sc, ifmr)
    270      1.1     onoe 	struct tulip_softc *sc;
    271      1.1     onoe 	struct ifmediareq *ifmr;
    272      1.1     onoe {
    273      1.1     onoe 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    274      1.1     onoe 
    275      1.1     onoe 	ifmr->ifm_status = IFM_AVALID;
    276      1.1     onoe 	if (ifp->if_flags & IFF_RUNNING)
    277      1.1     onoe 		ifmr->ifm_status |= IFM_ACTIVE;
    278      1.1     onoe 	ifmr->ifm_active = sc->sc_mii.mii_media_active;
    279      1.1     onoe }
    280      1.1     onoe 
    281      1.1     onoe static int
    282      1.1     onoe tlp_ap_setmedia(sc)
    283      1.1     onoe 	struct tulip_softc *sc;
    284      1.1     onoe {
    285      1.1     onoe 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    286      1.1     onoe 
    287      1.1     onoe 	sc->sc_mii.mii_media_active = sc->sc_mii.mii_media.ifm_cur->ifm_media;
    288      1.1     onoe 
    289      1.1     onoe 	if (ifp->if_flags & IFF_UP)
    290      1.1     onoe 		tlp_idle(sc, OPMODE_ST|OPMODE_SR);
    291      1.1     onoe 	if (sc->sc_mii.mii_media_active & IFM_FDX)
    292      1.1     onoe 		sc->sc_opmode |= OPMODE_FD;
    293      1.1     onoe 	else
    294      1.1     onoe 		sc->sc_opmode &= ~OPMODE_FD;
    295      1.1     onoe 	if (ifp->if_flags & IFF_UP)
    296      1.1     onoe 		TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
    297      1.1     onoe 	return (0);
    298      1.1     onoe }
    299