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