Home | History | Annotate | Line # | Download | only in ic
rtl80x9.c revision 1.3
      1  1.3       is /*	$NetBSD: rtl80x9.c,v 1.3 2000/03/03 21:37:18 is Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1  thorpej  * NASA Ames Research Center.
     10  1.1  thorpej  *
     11  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.1  thorpej  * modification, are permitted provided that the following conditions
     13  1.1  thorpej  * are met:
     14  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.1  thorpej  *    must display the following acknowledgement:
     21  1.1  thorpej  *	This product includes software developed by the NetBSD
     22  1.1  thorpej  *	Foundation, Inc. and its contributors.
     23  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     25  1.1  thorpej  *    from this software without specific prior written permission.
     26  1.1  thorpej  *
     27  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  thorpej  */
     39  1.1  thorpej 
     40  1.1  thorpej #include "opt_inet.h"
     41  1.1  thorpej #include "bpfilter.h"
     42  1.1  thorpej 
     43  1.1  thorpej #include <sys/param.h>
     44  1.1  thorpej #include <sys/systm.h>
     45  1.1  thorpej #include <sys/mbuf.h>
     46  1.1  thorpej #include <sys/syslog.h>
     47  1.1  thorpej #include <sys/socket.h>
     48  1.1  thorpej #include <sys/device.h>
     49  1.1  thorpej 
     50  1.1  thorpej #include <net/if.h>
     51  1.1  thorpej #include <net/if_ether.h>
     52  1.1  thorpej #include <net/if_media.h>
     53  1.1  thorpej 
     54  1.1  thorpej #ifdef INET
     55  1.1  thorpej #include <netinet/in.h>
     56  1.1  thorpej #include <netinet/if_inarp.h>
     57  1.1  thorpej #endif
     58  1.1  thorpej 
     59  1.1  thorpej #include <machine/bus.h>
     60  1.1  thorpej #include <machine/intr.h>
     61  1.1  thorpej 
     62  1.1  thorpej #include <dev/ic/dp8390reg.h>
     63  1.1  thorpej #include <dev/ic/dp8390var.h>
     64  1.1  thorpej 
     65  1.1  thorpej #include <dev/ic/ne2000reg.h>
     66  1.1  thorpej #include <dev/ic/ne2000var.h>
     67  1.1  thorpej 
     68  1.1  thorpej #include <dev/ic/rtl80x9reg.h>
     69  1.1  thorpej #include <dev/ic/rtl80x9var.h>
     70  1.1  thorpej 
     71  1.1  thorpej int
     72  1.1  thorpej rtl80x9_mediachange(dsc)
     73  1.1  thorpej 	struct dp8390_softc *dsc;
     74  1.1  thorpej {
     75  1.1  thorpej 
     76  1.1  thorpej 	/*
     77  1.1  thorpej 	 * Current media is already set up.  Just reset the interface
     78  1.1  thorpej 	 * to let the new value take hold.  The new media will be
     79  1.1  thorpej 	 * set up in ne_pci_rtl8029_init_card() called via dp8390_init().
     80  1.1  thorpej 	 */
     81  1.1  thorpej 	dp8390_reset(dsc);
     82  1.1  thorpej 	return (0);
     83  1.1  thorpej }
     84  1.1  thorpej 
     85  1.1  thorpej void
     86  1.1  thorpej rtl80x9_mediastatus(sc, ifmr)
     87  1.1  thorpej 	struct dp8390_softc *sc;
     88  1.1  thorpej 	struct ifmediareq *ifmr;
     89  1.1  thorpej {
     90  1.1  thorpej 	struct ifnet *ifp = &sc->sc_ec.ec_if;
     91  1.1  thorpej 	u_int8_t cr_proto = sc->cr_proto |
     92  1.1  thorpej 	    ((ifp->if_flags & IFF_RUNNING) ? ED_CR_STA : ED_CR_STP);
     93  1.1  thorpej 
     94  1.1  thorpej 	/*
     95  1.1  thorpej 	 * Sigh, can detect which media is being used, but can't
     96  1.1  thorpej 	 * detect if we have link or not.
     97  1.1  thorpej 	 */
     98  1.1  thorpej 
     99  1.1  thorpej 	/* Set NIC to page 3 registers. */
    100  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_3);
    101  1.1  thorpej 
    102  1.1  thorpej 	if (NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG0) &
    103  1.1  thorpej 	    RTL3_CONFIG0_BNC)
    104  1.1  thorpej 		ifmr->ifm_active = IFM_ETHER|IFM_10_2;
    105  1.1  thorpej 	else {
    106  1.1  thorpej 		ifmr->ifm_active = IFM_ETHER|IFM_10_T;
    107  1.1  thorpej 		if (NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3) &
    108  1.1  thorpej 		    RTL3_CONFIG3_FUDUP)
    109  1.1  thorpej 			ifmr->ifm_active |= IFM_FDX;
    110  1.1  thorpej 	}
    111  1.1  thorpej 
    112  1.1  thorpej 	/* Set NIC to page 0 registers. */
    113  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_0);
    114  1.1  thorpej }
    115  1.1  thorpej 
    116  1.1  thorpej void
    117  1.1  thorpej rtl80x9_init_card(sc)
    118  1.1  thorpej 	struct dp8390_softc *sc;
    119  1.1  thorpej {
    120  1.1  thorpej 	struct ifmedia *ifm = &sc->sc_media;
    121  1.1  thorpej 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    122  1.1  thorpej 	u_int8_t cr_proto = sc->cr_proto |
    123  1.1  thorpej 	    ((ifp->if_flags & IFF_RUNNING) ? ED_CR_STA : ED_CR_STP);
    124  1.1  thorpej 	u_int8_t reg;
    125  1.1  thorpej 
    126  1.1  thorpej 	/* Set NIC to page 3 registers. */
    127  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_3);
    128  1.1  thorpej 
    129  1.3       is 	/* write enable config1-3. */
    130  1.3       is 	NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_EECR,
    131  1.3       is 	    RTL3_EECR_EEM1|RTL3_EECR_EEM0);
    132  1.3       is 
    133  1.1  thorpej 	/* First, set basic media type. */
    134  1.1  thorpej 	reg = NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2);
    135  1.1  thorpej 	reg &= ~(RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0);
    136  1.1  thorpej 	switch (IFM_SUBTYPE(ifm->ifm_cur->ifm_media)) {
    137  1.1  thorpej 	case IFM_AUTO:
    138  1.1  thorpej 		/* Nothing to do; both bits clear == auto-detect. */
    139  1.1  thorpej 		break;
    140  1.1  thorpej 
    141  1.1  thorpej 	case IFM_10_T:
    142  1.1  thorpej 		reg |= RTL3_CONFIG2_PL0;
    143  1.1  thorpej 		break;
    144  1.1  thorpej 
    145  1.1  thorpej 	case IFM_10_2:
    146  1.1  thorpej 		reg |= RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0;
    147  1.1  thorpej 		break;
    148  1.1  thorpej 	}
    149  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2, reg);
    150  1.1  thorpej 
    151  1.1  thorpej 	/* Now, set duplex mode. */
    152  1.1  thorpej 	reg = NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3);
    153  1.1  thorpej 	if (ifm->ifm_cur->ifm_media & IFM_FDX)
    154  1.1  thorpej 		reg |= RTL3_CONFIG3_FUDUP;
    155  1.1  thorpej 	else
    156  1.1  thorpej 		reg &= ~RTL3_CONFIG3_FUDUP;
    157  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3, reg);
    158  1.1  thorpej 
    159  1.3       is 	/* write disable config1-3 */
    160  1.3       is 	NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_EECR, 0);
    161  1.3       is 
    162  1.1  thorpej 	/* Set NIC to page 0 registers. */
    163  1.1  thorpej 	NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_0);
    164  1.1  thorpej }
    165  1.1  thorpej 
    166  1.1  thorpej void
    167  1.1  thorpej rtl80x9_init_media(sc, mediap, nmediap, defmediap)
    168  1.1  thorpej 	struct dp8390_softc *sc;
    169  1.1  thorpej 	int **mediap, *nmediap, *defmediap;
    170  1.1  thorpej {
    171  1.1  thorpej 	static int rtl80x9_media[] = {
    172  1.1  thorpej 		IFM_ETHER|IFM_AUTO,
    173  1.1  thorpej 		IFM_ETHER|IFM_10_T,
    174  1.1  thorpej 		IFM_ETHER|IFM_10_T|IFM_FDX,
    175  1.1  thorpej 		IFM_ETHER|IFM_10_2,
    176  1.1  thorpej 	};
    177  1.1  thorpej 
    178  1.3       is 	u_int8_t conf2, conf3;
    179  1.1  thorpej 
    180  1.1  thorpej 	*mediap = rtl80x9_media;
    181  1.1  thorpej 	*nmediap = sizeof(rtl80x9_media) / sizeof(rtl80x9_media[0]);
    182  1.3       is 
    183  1.3       is 	printf("%s: 10base2, 10baseT, 10baseT-FDX, auto, default ",
    184  1.3       is 	    sc->sc_dev.dv_xname);
    185  1.3       is 
    186  1.3       is 	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR, ED_CR_PAGE_3);
    187  1.3       is 
    188  1.3       is 	conf2 = bus_space_read_1(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2);
    189  1.3       is 	conf3 = bus_space_read_1(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3);
    190  1.3       is 	printf("[0x%02x 0x%02x] ", conf2, conf3);
    191  1.3       is 
    192  1.3       is 	conf2 &= RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0;
    193  1.3       is 
    194  1.3       is 	switch (conf2) {
    195  1.3       is 	case 0:
    196  1.3       is 		*defmediap = IFM_ETHER|IFM_AUTO;
    197  1.3       is 		printf("auto\n");
    198  1.3       is 		break;
    199  1.3       is 
    200  1.3       is 	case RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0:
    201  1.3       is 	case RTL3_CONFIG2_PL1:	/* XXX rtl docs sys 10base5, but chip cant do */
    202  1.3       is 		*defmediap = IFM_ETHER|IFM_10_2;
    203  1.3       is 		printf("10base2\n");
    204  1.3       is 		break;
    205  1.3       is 
    206  1.3       is 	case RTL3_CONFIG2_PL0:
    207  1.3       is 		if (conf3 & RTL3_CONFIG3_FUDUP) {
    208  1.3       is 			*defmediap = IFM_ETHER|IFM_10_T|IFM_FDX;
    209  1.3       is 			printf("10baseT-FDX\n");
    210  1.3       is 		} else {
    211  1.3       is 			*defmediap = IFM_ETHER|IFM_10_T;
    212  1.3       is 			printf("10baseT\n");
    213  1.3       is 		}
    214  1.3       is 		break;
    215  1.3       is 	}
    216  1.3       is 
    217  1.3       is 	bus_space_write_1(sc->sc_regt, sc->sc_regh, ED_P0_CR, ED_CR_PAGE_0);
    218  1.1  thorpej }
    219