rtl80x9.c revision 1.1 1 /* $NetBSD: rtl80x9.c,v 1.1 1998/10/31 00:44:33 thorpej 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/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64 #include <dev/pci/pcidevs.h>
65
66 #include <dev/ic/dp8390reg.h>
67 #include <dev/ic/dp8390var.h>
68
69 #include <dev/ic/ne2000reg.h>
70 #include <dev/ic/ne2000var.h>
71
72 #include <dev/ic/rtl80x9reg.h>
73 #include <dev/ic/rtl80x9var.h>
74
75 int
76 rtl80x9_mediachange(dsc)
77 struct dp8390_softc *dsc;
78 {
79
80 /*
81 * Current media is already set up. Just reset the interface
82 * to let the new value take hold. The new media will be
83 * set up in ne_pci_rtl8029_init_card() called via dp8390_init().
84 */
85 dp8390_reset(dsc);
86 return (0);
87 }
88
89 void
90 rtl80x9_mediastatus(sc, ifmr)
91 struct dp8390_softc *sc;
92 struct ifmediareq *ifmr;
93 {
94 struct ifnet *ifp = &sc->sc_ec.ec_if;
95 u_int8_t cr_proto = sc->cr_proto |
96 ((ifp->if_flags & IFF_RUNNING) ? ED_CR_STA : ED_CR_STP);
97
98 /*
99 * Sigh, can detect which media is being used, but can't
100 * detect if we have link or not.
101 */
102
103 /* Set NIC to page 3 registers. */
104 NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_3);
105
106 if (NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG0) &
107 RTL3_CONFIG0_BNC)
108 ifmr->ifm_active = IFM_ETHER|IFM_10_2;
109 else {
110 ifmr->ifm_active = IFM_ETHER|IFM_10_T;
111 if (NIC_GET(sc->sc_regt, sc->sc_regh, NERTL_RTL3_CONFIG3) &
112 RTL3_CONFIG3_FUDUP)
113 ifmr->ifm_active |= IFM_FDX;
114 }
115
116 /* Set NIC to page 0 registers. */
117 NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_0);
118 }
119
120 void
121 rtl80x9_init_card(sc)
122 struct dp8390_softc *sc;
123 {
124 struct ifmedia *ifm = &sc->sc_media;
125 struct ifnet *ifp = &sc->sc_ec.ec_if;
126 u_int8_t cr_proto = sc->cr_proto |
127 ((ifp->if_flags & IFF_RUNNING) ? ED_CR_STA : ED_CR_STP);
128 u_int8_t reg;
129
130 /* Set NIC to page 3 registers. */
131 NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_3);
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 /* Set NIC to page 0 registers. */
160 NIC_PUT(sc->sc_regt, sc->sc_regh, ED_P0_CR, cr_proto | ED_CR_PAGE_0);
161 }
162
163 void
164 rtl80x9_init_media(sc, mediap, nmediap, defmediap)
165 struct dp8390_softc *sc;
166 int **mediap, *nmediap, *defmediap;
167 {
168 static int rtl80x9_media[] = {
169 IFM_ETHER|IFM_AUTO,
170 IFM_ETHER|IFM_10_T,
171 IFM_ETHER|IFM_10_T|IFM_FDX,
172 IFM_ETHER|IFM_10_2,
173 };
174
175 printf("%s: 10base2, 10baseT, 10baseT-FDX, auto, default auto\n",
176 sc->sc_dev.dv_xname);
177
178 *mediap = rtl80x9_media;
179 *nmediap = sizeof(rtl80x9_media) / sizeof(rtl80x9_media[0]);
180 *defmediap = IFM_ETHER|IFM_AUTO;
181 }
182