rtl80x9.c revision 1.2 1 /* $NetBSD: rtl80x9.c,v 1.2 1998/11/08 22:02:25 veego 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 /* First, set basic media type. */
130 reg = NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2);
131 reg &= ~(RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0);
132 switch (IFM_SUBTYPE(ifm->ifm_cur->ifm_media)) {
133 case IFM_AUTO:
134 /* Nothing to do; both bits clear == auto-detect. */
135 break;
136
137 case IFM_10_T:
138 reg |= RTL3_CONFIG2_PL0;
139 break;
140
141 case IFM_10_2:
142 reg |= RTL3_CONFIG2_PL1|RTL3_CONFIG2_PL0;
143 break;
144 }
145 NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG2, reg);
146
147 /* Now, set duplex mode. */
148 reg = NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3);
149 if (ifm->ifm_cur->ifm_media & IFM_FDX)
150 reg |= RTL3_CONFIG3_FUDUP;
151 else
152 reg &= ~RTL3_CONFIG3_FUDUP;
153 NIC_PUT(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3, reg);
154
155 /* Set NIC to page 0 registers. */
156 NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_0);
157 }
158
159 void
160 rtl80x9_init_media(sc, mediap, nmediap, defmediap)
161 struct dp8390_softc *sc;
162 int **mediap, *nmediap, *defmediap;
163 {
164 static int rtl80x9_media[] = {
165 IFM_ETHER|IFM_AUTO,
166 IFM_ETHER|IFM_10_T,
167 IFM_ETHER|IFM_10_T|IFM_FDX,
168 IFM_ETHER|IFM_10_2,
169 };
170
171 printf("%s: 10base2, 10baseT, 10baseT-FDX, auto, default auto\n",
172 sc->sc_dev.dv_xname);
173
174 *mediap = rtl80x9_media;
175 *nmediap = sizeof(rtl80x9_media) / sizeof(rtl80x9_media[0]);
176 *defmediap = IFM_ETHER|IFM_AUTO;
177 }
178