Tue Jul 7 06:59:22 2020 UTC ()
"no media present" is intended case on tlphy(4), so don't use
aprint_error_dev().


(msaitoh)
diff -r1.68 -r1.69 src/sys/dev/mii/tlphy.c

cvs diff -r1.68 -r1.69 src/sys/dev/mii/tlphy.c (switch to unified diff)

--- src/sys/dev/mii/tlphy.c 2020/03/15 23:04:50 1.68
+++ src/sys/dev/mii/tlphy.c 2020/07/07 06:59:22 1.69
@@ -1,390 +1,392 @@ @@ -1,390 +1,392 @@
1/* $NetBSD: tlphy.c,v 1.68 2020/03/15 23:04:50 thorpej Exp $ */ 1/* $NetBSD: tlphy.c,v 1.69 2020/07/07 06:59:22 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Copyright (c) 1997 Manuel Bouyer. All rights reserved. 34 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 37 * modification, are permitted provided that the following conditions
38 * are met: 38 * are met:
39 * 1. Redistributions of source code must retain the above copyright 39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 43 * documentation and/or other materials provided with the distribution.
44 * 44 *
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */ 55 */
56 56
57/* 57/*
58 * Driver for Texas Instruments's ThunderLAN PHYs 58 * Driver for Texas Instruments's ThunderLAN PHYs
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62__KERNEL_RCSID(0, "$NetBSD: tlphy.c,v 1.68 2020/03/15 23:04:50 thorpej Exp $"); 62__KERNEL_RCSID(0, "$NetBSD: tlphy.c,v 1.69 2020/07/07 06:59:22 msaitoh Exp $");
63 63
64#include <sys/param.h> 64#include <sys/param.h>
65#include <sys/systm.h> 65#include <sys/systm.h>
66#include <sys/kernel.h> 66#include <sys/kernel.h>
67#include <sys/device.h> 67#include <sys/device.h>
68#include <sys/socket.h> 68#include <sys/socket.h>
69#include <sys/errno.h> 69#include <sys/errno.h>
70 70
71#include <sys/bus.h> 71#include <sys/bus.h>
72 72
73#include <net/if.h> 73#include <net/if.h>
74#include <net/if_media.h> 74#include <net/if_media.h>
75 75
76#include <net/if_ether.h> 76#include <net/if_ether.h>
77 77
78#include <dev/mii/mii.h> 78#include <dev/mii/mii.h>
79#include <dev/mii/miivar.h> 79#include <dev/mii/miivar.h>
80#include <dev/mii/miidevs.h> 80#include <dev/mii/miidevs.h>
81 81
82#include <dev/mii/tlphyreg.h> 82#include <dev/mii/tlphyreg.h>
83#include <dev/mii/tlphyvar.h> 83#include <dev/mii/tlphyvar.h>
84 84
85/* ThunderLAN PHY can only be on a ThunderLAN */ 85/* ThunderLAN PHY can only be on a ThunderLAN */
86#include <dev/pci/if_tlvar.h> 86#include <dev/pci/if_tlvar.h>
87 87
88struct tlphy_softc { 88struct tlphy_softc {
89 struct mii_softc sc_mii; /* generic PHY */ 89 struct mii_softc sc_mii; /* generic PHY */
90 int sc_tlphycap; 90 int sc_tlphycap;
91 int sc_need_acomp; 91 int sc_need_acomp;
92}; 92};
93 93
94static int tlphymatch(device_t, cfdata_t, void *); 94static int tlphymatch(device_t, cfdata_t, void *);
95static void tlphyattach(device_t, device_t, void *); 95static void tlphyattach(device_t, device_t, void *);
96 96
97CFATTACH_DECL_NEW(tlphy, sizeof(struct tlphy_softc), 97CFATTACH_DECL_NEW(tlphy, sizeof(struct tlphy_softc),
98 tlphymatch, tlphyattach, mii_phy_detach, mii_phy_activate); 98 tlphymatch, tlphyattach, mii_phy_detach, mii_phy_activate);
99 99
100static int tlphy_service(struct mii_softc *, struct mii_data *, int); 100static int tlphy_service(struct mii_softc *, struct mii_data *, int);
101static int tlphy_auto(struct tlphy_softc *, int); 101static int tlphy_auto(struct tlphy_softc *, int);
102static void tlphy_acomp(struct tlphy_softc *); 102static void tlphy_acomp(struct tlphy_softc *);
103static void tlphy_status(struct mii_softc *); 103static void tlphy_status(struct mii_softc *);
104 104
105static const struct mii_phy_funcs tlphy_funcs = { 105static const struct mii_phy_funcs tlphy_funcs = {
106 tlphy_service, tlphy_status, mii_phy_reset, 106 tlphy_service, tlphy_status, mii_phy_reset,
107}; 107};
108 108
109static const struct mii_phydesc tlphys[] = { 109static const struct mii_phydesc tlphys[] = {
110 MII_PHY_DESC(TI, TLAN10T), 110 MII_PHY_DESC(TI, TLAN10T),
111 MII_PHY_END, 111 MII_PHY_END,
112}; 112};
113 113
114static int 114static int
115tlphymatch(device_t parent, cfdata_t match, void *aux) 115tlphymatch(device_t parent, cfdata_t match, void *aux)
116{ 116{
117 struct mii_attach_args *ma = aux; 117 struct mii_attach_args *ma = aux;
118 118
119 if (mii_phy_match(ma, tlphys) != NULL) 119 if (mii_phy_match(ma, tlphys) != NULL)
120 return 10; 120 return 10;
121 121
122 return 0; 122 return 0;
123} 123}
124 124
125static void 125static void
126tlphyattach(device_t parent, device_t self, void *aux) 126tlphyattach(device_t parent, device_t self, void *aux)
127{ 127{
128 struct tlphy_softc *tsc = device_private(self); 128 struct tlphy_softc *tsc = device_private(self);
129 struct mii_softc *sc = &tsc->sc_mii; 129 struct mii_softc *sc = &tsc->sc_mii;
130 struct tl_softc *tlsc = device_private(device_parent(self)); 130 struct tl_softc *tlsc = device_private(device_parent(self));
131 struct mii_attach_args *ma = aux; 131 struct mii_attach_args *ma = aux;
132 struct mii_data *mii = ma->mii_data; 132 struct mii_data *mii = ma->mii_data;
133 const struct mii_phydesc *mpd; 133 const struct mii_phydesc *mpd;
134 const char *sep = ""; 134 const char *sep = "";
135 135
136 mpd = mii_phy_match(ma, tlphys); 136 mpd = mii_phy_match(ma, tlphys);
137 aprint_naive(": Media interface\n"); 137 aprint_naive(": Media interface\n");
138 aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2)); 138 aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
139 139
140 sc->mii_dev = self; 140 sc->mii_dev = self;
141 sc->mii_inst = mii->mii_instance; 141 sc->mii_inst = mii->mii_instance;
142 sc->mii_phy = ma->mii_phyno; 142 sc->mii_phy = ma->mii_phyno;
143 sc->mii_funcs = &tlphy_funcs; 143 sc->mii_funcs = &tlphy_funcs;
144 sc->mii_pdata = mii; 144 sc->mii_pdata = mii;
145 sc->mii_flags = ma->mii_flags; 145 sc->mii_flags = ma->mii_flags;
146 146
147 mii_lock(mii); 147 mii_lock(mii);
148 148
149 PHY_RESET(sc); 149 PHY_RESET(sc);
150 150
151 /* 151 /*
152 * Note that if we're on a device that also supports 100baseTX, we are 152 * Note that if we're on a device that also supports 100baseTX, we are
153 * not going to want to use the built-in 10baseT port, since there will 153 * not going to want to use the built-in 10baseT port, since there will
154 * be another PHY on the MII wired up to the UTP connector. The parent 154 * be another PHY on the MII wired up to the UTP connector. The parent
155 * indicates this to us by specifying the TLPHY_MEDIA_NO_10_T bit. 155 * indicates this to us by specifying the TLPHY_MEDIA_NO_10_T bit.
156 */ 156 */
157 tsc->sc_tlphycap = tlsc->tl_product->tp_tlphymedia; 157 tsc->sc_tlphycap = tlsc->tl_product->tp_tlphymedia;
158 if ((tsc->sc_tlphycap & TLPHY_MEDIA_NO_10_T) == 0) { 158 if ((tsc->sc_tlphycap & TLPHY_MEDIA_NO_10_T) == 0) {
159 PHY_READ(sc, MII_BMSR, &sc->mii_capabilities); 159 PHY_READ(sc, MII_BMSR, &sc->mii_capabilities);
160 sc->mii_capabilities &= ma->mii_capmask; 160 sc->mii_capabilities &= ma->mii_capmask;
161 } else 161 } else
162 sc->mii_capabilities = 0; 162 sc->mii_capabilities = 0;
163 163
164 mii_unlock(mii); 164 mii_unlock(mii);
165 165
166#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) 166#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
167#define PRINT(str) aprint_normal("%s%s", sep, str); sep = ", " 167#define PRINT(str) \
 168 do { \
 169 aprint_normal("%s%s", sep, str); \
 170 sep = ", "; \
 171 } while (/* CONSTCOND */0)
168 172
169 if (tsc->sc_tlphycap) { 173 if (tsc->sc_tlphycap) {
170 mii_lock(mii); 174 mii_lock(mii);
171 sc->mii_anegticks = MII_ANEGTICKS; 175 sc->mii_anegticks = MII_ANEGTICKS;
172 mii_unlock(mii); 176 mii_unlock(mii);
173 aprint_normal_dev(self, ""); 177 aprint_normal_dev(self, "");
174 if (tsc->sc_tlphycap & TLPHY_MEDIA_10_2) { 178 if (tsc->sc_tlphycap & TLPHY_MEDIA_10_2) {
175 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->mii_inst), 179 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->mii_inst),
176 0); 180 0);
177 PRINT("10base2"); 181 PRINT("10base2");
178 } else if (tsc->sc_tlphycap & TLPHY_MEDIA_10_5) { 182 } else if (tsc->sc_tlphycap & TLPHY_MEDIA_10_5) {
179 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc->mii_inst), 183 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc->mii_inst),
180 0); 184 0);
181 PRINT("10base5"); 185 PRINT("10base5");
182 } 186 } else
 187 PRINT("no media present");
183 aprint_normal("\n"); 188 aprint_normal("\n");
184 } 189 }
185 if (sc->mii_capabilities & BMSR_MEDIAMASK) 190 if (sc->mii_capabilities & BMSR_MEDIAMASK)
186 mii_phy_add_media(sc); 191 mii_phy_add_media(sc);
187 else { 192 else {
188 if ((tsc->sc_tlphycap & 
189 (TLPHY_MEDIA_10_2 | TLPHY_MEDIA_10_5)) == 0) 
190 aprint_error_dev(self, "no media present\n"); 
191 /* 193 /*
192 * mii_phy_add_media() automatically install power handler, 194 * mii_phy_add_media() automatically install power handler,
193 * but if_media_add() doesn't. Do it now. 195 * but if_media_add() doesn't. Do it now.
194 */ 196 */
195 if (!pmf_device_register(self, NULL, mii_phy_resume)) { 197 if (!pmf_device_register(self, NULL, mii_phy_resume)) {
196 aprint_error_dev(self, 198 aprint_error_dev(self,
197 "couldn't establish power handler\n"); 199 "couldn't establish power handler\n");
198 } 200 }
199 } 201 }
200#undef ADD 202#undef ADD
201#undef PRINT 203#undef PRINT
202} 204}
203 205
204static int 206static int
205tlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 207tlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
206{ 208{
207 struct tlphy_softc *tsc = (struct tlphy_softc *)sc; 209 struct tlphy_softc *tsc = (struct tlphy_softc *)sc;
208 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 210 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
209 uint16_t reg; 211 uint16_t reg;
210 212
211 KASSERT(mii_locked(mii)); 213 KASSERT(mii_locked(mii));
212 214
213 if ((sc->mii_flags & MIIF_DOINGAUTO) == 0 && tsc->sc_need_acomp) 215 if ((sc->mii_flags & MIIF_DOINGAUTO) == 0 && tsc->sc_need_acomp)
214 tlphy_acomp(tsc); 216 tlphy_acomp(tsc);
215 217
216 switch (cmd) { 218 switch (cmd) {
217 case MII_POLLSTAT: 219 case MII_POLLSTAT:
218 /* If we're not polling our PHY instance, just return. */ 220 /* If we're not polling our PHY instance, just return. */
219 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 221 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
220 return 0; 222 return 0;
221 break; 223 break;
222 224
223 case MII_MEDIACHG: 225 case MII_MEDIACHG:
224 /* 226 /*
225 * If the media indicates a different PHY instance, 227 * If the media indicates a different PHY instance,
226 * isolate ourselves. 228 * isolate ourselves.
227 */ 229 */
228 if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 230 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
229 PHY_READ(sc, MII_BMCR, &reg); 231 PHY_READ(sc, MII_BMCR, &reg);
230 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); 232 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
231 return 0; 233 return 0;
232 } 234 }
233 235
234 /* If the interface is not up, don't do anything. */ 236 /* If the interface is not up, don't do anything. */
235 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 237 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
236 break; 238 break;
237 239
238 switch (IFM_SUBTYPE(ife->ifm_media)) { 240 switch (IFM_SUBTYPE(ife->ifm_media)) {
239 case IFM_AUTO: 241 case IFM_AUTO:
240 /* 242 /*
241 * The ThunderLAN PHY doesn't self-configure after 243 * The ThunderLAN PHY doesn't self-configure after
242 * an autonegotiation cycle, so there's no such 244 * an autonegotiation cycle, so there's no such
243 * thing as "already in auto mode". 245 * thing as "already in auto mode".
244 */ 246 */
245 (void) tlphy_auto(tsc, 1); 247 (void) tlphy_auto(tsc, 1);
246 break; 248 break;
247 case IFM_10_2: 249 case IFM_10_2:
248 case IFM_10_5: 250 case IFM_10_5:
249 PHY_WRITE(sc, MII_BMCR, 0); 251 PHY_WRITE(sc, MII_BMCR, 0);
250 PHY_WRITE(sc, MII_TLPHY_CTRL, CTRL_AUISEL); 252 PHY_WRITE(sc, MII_TLPHY_CTRL, CTRL_AUISEL);
251 delay(100000); 253 delay(100000);
252 break; 254 break;
253 default: 255 default:
254 PHY_WRITE(sc, MII_TLPHY_CTRL, 0); 256 PHY_WRITE(sc, MII_TLPHY_CTRL, 0);
255 delay(100000); 257 delay(100000);
256 mii_phy_setmedia(sc); 258 mii_phy_setmedia(sc);
257 } 259 }
258 break; 260 break;
259 261
260 case MII_TICK: 262 case MII_TICK:
261 /* If we're not currently selected, just return. */ 263 /* If we're not currently selected, just return. */
262 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 264 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
263 return 0; 265 return 0;
264 266
265 /* 267 /*
266 * XXX WHAT ABOUT CHECKING LINK ON THE BNC/AUI?! 268 * XXX WHAT ABOUT CHECKING LINK ON THE BNC/AUI?!
267 */ 269 */
268 270
269 if (mii_phy_tick(sc) == EJUSTRETURN) 271 if (mii_phy_tick(sc) == EJUSTRETURN)
270 return 0; 272 return 0;
271 break; 273 break;
272 274
273 case MII_DOWN: 275 case MII_DOWN:
274 mii_phy_down(sc); 276 mii_phy_down(sc);
275 return 0; 277 return 0;
276 } 278 }
277 279
278 /* Update the media status. */ 280 /* Update the media status. */
279 mii_phy_status(sc); 281 mii_phy_status(sc);
280 282
281 /* Callback if something changed. */ 283 /* Callback if something changed. */
282 mii_phy_update(sc, cmd); 284 mii_phy_update(sc, cmd);
283 return 0; 285 return 0;
284} 286}
285 287
286static void 288static void
287tlphy_status(struct mii_softc *sc) 289tlphy_status(struct mii_softc *sc)
288{ 290{
289 struct tlphy_softc *tsc = (struct tlphy_softc *)sc; 291 struct tlphy_softc *tsc = (struct tlphy_softc *)sc;
290 struct mii_data *mii = sc->mii_pdata; 292 struct mii_data *mii = sc->mii_pdata;
291 uint16_t bmsr, bmcr, tlctrl; 293 uint16_t bmsr, bmcr, tlctrl;
292 294
293 KASSERT(mii_locked(mii)); 295 KASSERT(mii_locked(mii));
294 296
295 mii->mii_media_status = IFM_AVALID; 297 mii->mii_media_status = IFM_AVALID;
296 mii->mii_media_active = IFM_ETHER; 298 mii->mii_media_active = IFM_ETHER;
297 299
298 PHY_READ(sc, MII_BMCR, &bmcr); 300 PHY_READ(sc, MII_BMCR, &bmcr);
299 if (bmcr & BMCR_ISO) { 301 if (bmcr & BMCR_ISO) {
300 mii->mii_media_active |= IFM_NONE; 302 mii->mii_media_active |= IFM_NONE;
301 mii->mii_media_status = 0; 303 mii->mii_media_status = 0;
302 return; 304 return;
303 } 305 }
304 306
305 PHY_READ(sc, MII_TLPHY_CTRL, &tlctrl); 307 PHY_READ(sc, MII_TLPHY_CTRL, &tlctrl);
306 if (tlctrl & CTRL_AUISEL) { 308 if (tlctrl & CTRL_AUISEL) {
307 if (tsc->sc_tlphycap & TLPHY_MEDIA_10_2) 309 if (tsc->sc_tlphycap & TLPHY_MEDIA_10_2)
308 mii->mii_media_active |= IFM_10_2; 310 mii->mii_media_active |= IFM_10_2;
309 else if (tsc->sc_tlphycap & TLPHY_MEDIA_10_5) 311 else if (tsc->sc_tlphycap & TLPHY_MEDIA_10_5)
310 mii->mii_media_active |= IFM_10_5; 312 mii->mii_media_active |= IFM_10_5;
311 else 313 else
312 printf("%s: AUI selected with no matching media !\n", 314 printf("%s: AUI selected with no matching media !\n",
313 device_xname(sc->mii_dev)); 315 device_xname(sc->mii_dev));
314 mii->mii_media_status |= IFM_ACTIVE; 316 mii->mii_media_status |= IFM_ACTIVE;
315 return; 317 return;
316 } 318 }
317 319
318 PHY_READ(sc, MII_BMSR, &bmsr); 320 PHY_READ(sc, MII_BMSR, &bmsr);
319 PHY_READ(sc, MII_BMSR, &bmsr); 321 PHY_READ(sc, MII_BMSR, &bmsr);
320 if (bmsr & BMSR_LINK) 322 if (bmsr & BMSR_LINK)
321 mii->mii_media_status |= IFM_ACTIVE; 323 mii->mii_media_status |= IFM_ACTIVE;
322 324
323 if (bmcr & BMCR_LOOP) 325 if (bmcr & BMCR_LOOP)
324 mii->mii_media_active |= IFM_LOOP; 326 mii->mii_media_active |= IFM_LOOP;
325 327
326 /* 328 /*
327 * Grr, braindead ThunderLAN PHY doesn't have any way to tell which 329 * Grr, braindead ThunderLAN PHY doesn't have any way to tell which
328 * media is actually active. (Note it also doesn't self-configure 330 * media is actually active. (Note it also doesn't self-configure
329 * after autonegotiation.) We just have to report what's in the BMCR. 331 * after autonegotiation.) We just have to report what's in the BMCR.
330 */ 332 */
331 if (bmcr & BMCR_FDX) 333 if (bmcr & BMCR_FDX)
332 mii->mii_media_active |= IFM_FDX; 334 mii->mii_media_active |= IFM_FDX;
333 else 335 else
334 mii->mii_media_active |= IFM_HDX; 336 mii->mii_media_active |= IFM_HDX;
335 mii->mii_media_active |= IFM_10_T; 337 mii->mii_media_active |= IFM_10_T;
336} 338}
337 339
338static int 340static int
339tlphy_auto(struct tlphy_softc *tsc, int waitfor) 341tlphy_auto(struct tlphy_softc *tsc, int waitfor)
340{ 342{
341 struct mii_softc *sc = &tsc->sc_mii; 343 struct mii_softc *sc = &tsc->sc_mii;
342 int error; 344 int error;
343 345
344 switch ((error = mii_phy_auto(sc, waitfor))) { 346 switch ((error = mii_phy_auto(sc, waitfor))) {
345 case EIO: 347 case EIO:
346 /* 348 /*
347 * Just assume we're not in full-duplex mode. 349 * Just assume we're not in full-duplex mode.
348 * XXX Check link and try AUI/BNC? 350 * XXX Check link and try AUI/BNC?
349 */ 351 */
350 PHY_WRITE(sc, MII_BMCR, 0); 352 PHY_WRITE(sc, MII_BMCR, 0);
351 break; 353 break;
352 354
353 case EJUSTRETURN: 355 case EJUSTRETURN:
354 /* Flag that we need to program when it completes. */ 356 /* Flag that we need to program when it completes. */
355 tsc->sc_need_acomp = 1; 357 tsc->sc_need_acomp = 1;
356 break; 358 break;
357 359
358 default: 360 default:
359 tlphy_acomp(tsc); 361 tlphy_acomp(tsc);
360 } 362 }
361 363
362 return error; 364 return error;
363} 365}
364 366
365static void 367static void
366tlphy_acomp(struct tlphy_softc *tsc) 368tlphy_acomp(struct tlphy_softc *tsc)
367{ 369{
368 struct mii_softc *sc = &tsc->sc_mii; 370 struct mii_softc *sc = &tsc->sc_mii;
369 uint16_t aner, anar, anlpar, result; 371 uint16_t aner, anar, anlpar, result;
370 372
371 tsc->sc_need_acomp = 0; 373 tsc->sc_need_acomp = 0;
372 374
373 /* 375 /*
374 * Grr, braindead ThunderLAN PHY doesn't self-configure 376 * Grr, braindead ThunderLAN PHY doesn't self-configure
375 * after autonegotiation. We have to do it ourselves 377 * after autonegotiation. We have to do it ourselves
376 * based on the link partner status. 378 * based on the link partner status.
377 */ 379 */
378 380
379 PHY_READ(sc, MII_ANER, &aner); 381 PHY_READ(sc, MII_ANER, &aner);
380 if (aner & ANER_LPAN) { 382 if (aner & ANER_LPAN) {
381 PHY_READ(sc, MII_ANAR, &anar); 383 PHY_READ(sc, MII_ANAR, &anar);
382 PHY_READ(sc, MII_ANLPAR, &anlpar); 384 PHY_READ(sc, MII_ANLPAR, &anlpar);
383 result = anar & anlpar; 385 result = anar & anlpar;
384 if (result & ANAR_10_FD) { 386 if (result & ANAR_10_FD) {
385 PHY_WRITE(sc, MII_BMCR, BMCR_FDX); 387 PHY_WRITE(sc, MII_BMCR, BMCR_FDX);
386 return; 388 return;
387 } 389 }
388 } 390 }
389 PHY_WRITE(sc, MII_BMCR, 0); 391 PHY_WRITE(sc, MII_BMCR, 0);
390} 392}