1/*- 2 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 * NASA Ames Research Center. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of The NetBSD Foundation nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * Copyright (c) 1997 Manuel Bouyer. All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * This product includes software developed by Manuel Bouyer. 52 * 4. The name of the author may not be used to endorse or promote products 53 * derived from this software without specific prior written permission. 54 * 55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 56 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 57 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 58 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 59 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 60 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 64 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67/* 68 * Driver for Altima AC101 10/100 PHY 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> 73#include <sys/kernel.h> 74#include <sys/socket.h> 75#include <sys/errno.h> 76#include <sys/module.h> 77#include <sys/bus.h> 78 79#include <net/if.h> 80#include <net/if_media.h> 81 82#include <dev/mii/mii.h> 83#include <dev/mii/miivar.h> 84#include <dev/mii/miidevs.h> 85 86#include <dev/mii/acphyreg.h> 87 88#include "miibus_if.h" 89 90#if !defined(lint) 91static const char rcsid[] =
| 1/*- 2 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 * NASA Ames Research Center. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of The NetBSD Foundation nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * Copyright (c) 1997 Manuel Bouyer. All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * This product includes software developed by Manuel Bouyer. 52 * 4. The name of the author may not be used to endorse or promote products 53 * derived from this software without specific prior written permission. 54 * 55 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 56 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 57 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 58 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 59 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 60 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 64 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67/* 68 * Driver for Altima AC101 10/100 PHY 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> 73#include <sys/kernel.h> 74#include <sys/socket.h> 75#include <sys/errno.h> 76#include <sys/module.h> 77#include <sys/bus.h> 78 79#include <net/if.h> 80#include <net/if_media.h> 81 82#include <dev/mii/mii.h> 83#include <dev/mii/miivar.h> 84#include <dev/mii/miidevs.h> 85 86#include <dev/mii/acphyreg.h> 87 88#include "miibus_if.h" 89 90#if !defined(lint) 91static const char rcsid[] =
|
92 "$FreeBSD: head/sys/dev/mii/acphy.c 95667 2002-04-28 19:25:07Z phk $";
| 92 "$FreeBSD: head/sys/dev/mii/acphy.c 95722 2002-04-29 13:07:38Z phk $";
|
93#endif 94 95static int acphy_probe (device_t); 96static int acphy_attach (device_t);
| 93#endif 94 95static int acphy_probe (device_t); 96static int acphy_attach (device_t);
|
97static int acphy_detach (device_t);
| |
98 99static device_method_t acphy_methods[] = { 100 /* device interface */ 101 DEVMETHOD(device_probe, acphy_probe), 102 DEVMETHOD(device_attach, acphy_attach),
| 97 98static device_method_t acphy_methods[] = { 99 /* device interface */ 100 DEVMETHOD(device_probe, acphy_probe), 101 DEVMETHOD(device_attach, acphy_attach),
|
103 DEVMETHOD(device_detach, acphy_detach),
| 102 DEVMETHOD(device_detach, mii_phy_detach),
|
104 DEVMETHOD(device_shutdown, bus_generic_shutdown), 105 { 0, 0 } 106}; 107 108static devclass_t acphy_devclass; 109 110static driver_t acphy_driver = { 111 "acphy", 112 acphy_methods, 113 sizeof(struct mii_softc) 114}; 115 116DRIVER_MODULE(acphy, miibus, acphy_driver, acphy_devclass, 0, 0); 117 118static int acphy_service(struct mii_softc *, struct mii_data *, int); 119static void acphy_reset(struct mii_softc *); 120static void acphy_status(struct mii_softc *); 121 122static int acphy_probe(dev) 123 device_t dev; 124{ 125 struct mii_attach_args *ma; 126 127 ma = device_get_ivars(dev); 128 129 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxALTIMA && 130 MII_MODEL(ma->mii_id2) == MII_MODEL_xxALTIMA_AC101) { 131 device_set_desc(dev, MII_STR_xxALTIMA_AC101); 132 } else 133 return (ENXIO); 134 135 return (0); 136} 137 138static int acphy_attach(dev) 139 device_t dev; 140{ 141 struct mii_softc *sc; 142 struct mii_attach_args *ma; 143 struct mii_data *mii; 144 145 sc = device_get_softc(dev); 146 ma = device_get_ivars(dev); 147 sc->mii_dev = device_get_parent(dev); 148 mii = device_get_softc(sc->mii_dev); 149 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 150 151 sc->mii_inst = mii->mii_instance; 152 sc->mii_phy = ma->mii_phyno; 153 sc->mii_service = acphy_service; 154 sc->mii_pdata = mii; 155 sc->mii_flags |= MIIF_NOISOLATE; 156 157 acphy_reset(sc); 158 159 mii->mii_instance++; 160 161 sc->mii_capabilities = 162 PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 163 device_printf(dev, " "); 164 mii_add_media(sc); 165 printf("\n"); 166 167 MIIBUS_MEDIAINIT(sc->mii_dev); 168 return (0); 169} 170
| 103 DEVMETHOD(device_shutdown, bus_generic_shutdown), 104 { 0, 0 } 105}; 106 107static devclass_t acphy_devclass; 108 109static driver_t acphy_driver = { 110 "acphy", 111 acphy_methods, 112 sizeof(struct mii_softc) 113}; 114 115DRIVER_MODULE(acphy, miibus, acphy_driver, acphy_devclass, 0, 0); 116 117static int acphy_service(struct mii_softc *, struct mii_data *, int); 118static void acphy_reset(struct mii_softc *); 119static void acphy_status(struct mii_softc *); 120 121static int acphy_probe(dev) 122 device_t dev; 123{ 124 struct mii_attach_args *ma; 125 126 ma = device_get_ivars(dev); 127 128 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxALTIMA && 129 MII_MODEL(ma->mii_id2) == MII_MODEL_xxALTIMA_AC101) { 130 device_set_desc(dev, MII_STR_xxALTIMA_AC101); 131 } else 132 return (ENXIO); 133 134 return (0); 135} 136 137static int acphy_attach(dev) 138 device_t dev; 139{ 140 struct mii_softc *sc; 141 struct mii_attach_args *ma; 142 struct mii_data *mii; 143 144 sc = device_get_softc(dev); 145 ma = device_get_ivars(dev); 146 sc->mii_dev = device_get_parent(dev); 147 mii = device_get_softc(sc->mii_dev); 148 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 149 150 sc->mii_inst = mii->mii_instance; 151 sc->mii_phy = ma->mii_phyno; 152 sc->mii_service = acphy_service; 153 sc->mii_pdata = mii; 154 sc->mii_flags |= MIIF_NOISOLATE; 155 156 acphy_reset(sc); 157 158 mii->mii_instance++; 159 160 sc->mii_capabilities = 161 PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 162 device_printf(dev, " "); 163 mii_add_media(sc); 164 printf("\n"); 165 166 MIIBUS_MEDIAINIT(sc->mii_dev); 167 return (0); 168} 169
|
171static int acphy_detach(dev) 172 device_t dev; 173{ 174 struct mii_softc *sc; 175 struct mii_data *mii; 176 177 sc = device_get_softc(dev); 178 mii = device_get_softc(device_get_parent(dev)); 179 sc->mii_dev = NULL; 180 LIST_REMOVE(sc, mii_list); 181 182 return(0); 183} 184
| |
185static int 186acphy_service(sc, mii, cmd) 187 struct mii_softc *sc; 188 struct mii_data *mii; 189 int cmd; 190{ 191 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 192 int reg; 193 194 switch (cmd) { 195 case MII_POLLSTAT: 196 /* 197 * If we're not polling our PHY instance, just return. 198 */ 199 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 200 return (0); 201 break; 202 203 case MII_MEDIACHG: 204 /* 205 * If the media indicates a different PHY instance, 206 * isolate ourselves. 207 */ 208 if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 209 reg = PHY_READ(sc, MII_BMCR); 210 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO | BMCR_PDOWN); 211 return (0); 212 } 213 214 /* 215 * If the interface is not up, don't do anything. 216 */ 217 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 218 break; 219 220 /* Wake & deisolate up is needed */ 221 reg = PHY_READ(sc, MII_BMCR); 222 if (reg & (BMCR_ISO | BMCR_PDOWN)) 223 PHY_WRITE(sc, MII_BMCR, reg & ~(BMCR_ISO | BMCR_PDOWN)); 224 225 switch (IFM_SUBTYPE(ife->ifm_media)) { 226 case IFM_AUTO: 227 /* 228 * If we're already in auto mode, just return. 229 */ 230 if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) 231 return (0); 232 233 (void) mii_phy_auto(sc, 1); 234 break; 235 236 default: 237 /* 238 * BMCR data is stored in the ifmedia entry. 239 */ 240 PHY_WRITE(sc, MII_ANAR, 241 mii_anar(ife->ifm_media)); 242 PHY_WRITE(sc, MII_BMCR, ife->ifm_data); 243 } 244 break; 245 246 case MII_TICK: 247 /* 248 * If we're not currently selected, just return. 249 */ 250 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 251 return (0); 252 253 /* 254 * Is the interface even up? 255 */ 256 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 257 return (0); 258 259 /* 260 * Only used for autonegotiation. 261 */ 262 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) 263 break; 264 265 /* 266 * check for link. 267 * Read the status register twice; BMSR_LINK is latch-low. 268 */ 269 reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); 270 if (reg & BMSR_LINK) 271 break; 272 273 /* 274 * Only retry autonegotiation every 5 seconds. 275 */ 276 if (++sc->mii_ticks != 5) 277 return (0); 278 279 sc->mii_ticks = 0; 280 acphy_reset(sc); 281 if (mii_phy_auto(sc, 0) == EJUSTRETURN) 282 return (0); 283 break; 284 } 285 286 /* Update the media status. */ 287 acphy_status(sc); 288 289 /* Callback if something changed. */ 290 mii_phy_update(sc, cmd); 291 return (0); 292} 293 294static void 295acphy_status(sc) 296 struct mii_softc *sc; 297{ 298 struct mii_data *mii = sc->mii_pdata; 299 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 300 int bmsr, bmcr, diag; 301 302 mii->mii_media_status = IFM_AVALID; 303 mii->mii_media_active = IFM_ETHER; 304 305 bmsr = PHY_READ(sc, MII_BMSR) | 306 PHY_READ(sc, MII_BMSR); 307 if (bmsr & BMSR_LINK) 308 mii->mii_media_status |= IFM_ACTIVE; 309 310 bmcr = PHY_READ(sc, MII_BMCR); 311 if (bmcr & BMCR_ISO) { 312 mii->mii_media_active |= IFM_NONE; 313 mii->mii_media_status = 0; 314 return; 315 } 316 317 if (bmcr & BMCR_LOOP) 318 mii->mii_media_active |= IFM_LOOP; 319 320 if (bmcr & BMCR_AUTOEN) { 321 if ((bmsr & BMSR_ACOMP) == 0) { 322 /* Erg, still trying, I guess... */ 323 mii->mii_media_active |= IFM_NONE; 324 return; 325 } 326 diag = PHY_READ(sc, MII_ACPHY_DIAG) | 327 PHY_READ(sc, MII_ACPHY_DIAG); 328 if (diag & AC_DIAG_SPEED) 329 mii->mii_media_active |= IFM_100_TX; 330 else 331 mii->mii_media_active |= IFM_10_T; 332 333 if (diag & AC_DIAG_DUPLEX) 334 mii->mii_media_active |= IFM_FDX; 335 } else 336 mii->mii_media_active = ife->ifm_media; 337} 338 339static void 340acphy_reset(sc) 341 struct mii_softc *sc; 342{ 343 344 mii_phy_reset(sc); 345 PHY_WRITE(sc, MII_ACPHY_INT, 0); 346}
| 170static int 171acphy_service(sc, mii, cmd) 172 struct mii_softc *sc; 173 struct mii_data *mii; 174 int cmd; 175{ 176 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 177 int reg; 178 179 switch (cmd) { 180 case MII_POLLSTAT: 181 /* 182 * If we're not polling our PHY instance, just return. 183 */ 184 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 185 return (0); 186 break; 187 188 case MII_MEDIACHG: 189 /* 190 * If the media indicates a different PHY instance, 191 * isolate ourselves. 192 */ 193 if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 194 reg = PHY_READ(sc, MII_BMCR); 195 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO | BMCR_PDOWN); 196 return (0); 197 } 198 199 /* 200 * If the interface is not up, don't do anything. 201 */ 202 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 203 break; 204 205 /* Wake & deisolate up is needed */ 206 reg = PHY_READ(sc, MII_BMCR); 207 if (reg & (BMCR_ISO | BMCR_PDOWN)) 208 PHY_WRITE(sc, MII_BMCR, reg & ~(BMCR_ISO | BMCR_PDOWN)); 209 210 switch (IFM_SUBTYPE(ife->ifm_media)) { 211 case IFM_AUTO: 212 /* 213 * If we're already in auto mode, just return. 214 */ 215 if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) 216 return (0); 217 218 (void) mii_phy_auto(sc, 1); 219 break; 220 221 default: 222 /* 223 * BMCR data is stored in the ifmedia entry. 224 */ 225 PHY_WRITE(sc, MII_ANAR, 226 mii_anar(ife->ifm_media)); 227 PHY_WRITE(sc, MII_BMCR, ife->ifm_data); 228 } 229 break; 230 231 case MII_TICK: 232 /* 233 * If we're not currently selected, just return. 234 */ 235 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 236 return (0); 237 238 /* 239 * Is the interface even up? 240 */ 241 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 242 return (0); 243 244 /* 245 * Only used for autonegotiation. 246 */ 247 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) 248 break; 249 250 /* 251 * check for link. 252 * Read the status register twice; BMSR_LINK is latch-low. 253 */ 254 reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); 255 if (reg & BMSR_LINK) 256 break; 257 258 /* 259 * Only retry autonegotiation every 5 seconds. 260 */ 261 if (++sc->mii_ticks != 5) 262 return (0); 263 264 sc->mii_ticks = 0; 265 acphy_reset(sc); 266 if (mii_phy_auto(sc, 0) == EJUSTRETURN) 267 return (0); 268 break; 269 } 270 271 /* Update the media status. */ 272 acphy_status(sc); 273 274 /* Callback if something changed. */ 275 mii_phy_update(sc, cmd); 276 return (0); 277} 278 279static void 280acphy_status(sc) 281 struct mii_softc *sc; 282{ 283 struct mii_data *mii = sc->mii_pdata; 284 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 285 int bmsr, bmcr, diag; 286 287 mii->mii_media_status = IFM_AVALID; 288 mii->mii_media_active = IFM_ETHER; 289 290 bmsr = PHY_READ(sc, MII_BMSR) | 291 PHY_READ(sc, MII_BMSR); 292 if (bmsr & BMSR_LINK) 293 mii->mii_media_status |= IFM_ACTIVE; 294 295 bmcr = PHY_READ(sc, MII_BMCR); 296 if (bmcr & BMCR_ISO) { 297 mii->mii_media_active |= IFM_NONE; 298 mii->mii_media_status = 0; 299 return; 300 } 301 302 if (bmcr & BMCR_LOOP) 303 mii->mii_media_active |= IFM_LOOP; 304 305 if (bmcr & BMCR_AUTOEN) { 306 if ((bmsr & BMSR_ACOMP) == 0) { 307 /* Erg, still trying, I guess... */ 308 mii->mii_media_active |= IFM_NONE; 309 return; 310 } 311 diag = PHY_READ(sc, MII_ACPHY_DIAG) | 312 PHY_READ(sc, MII_ACPHY_DIAG); 313 if (diag & AC_DIAG_SPEED) 314 mii->mii_media_active |= IFM_100_TX; 315 else 316 mii->mii_media_active |= IFM_10_T; 317 318 if (diag & AC_DIAG_DUPLEX) 319 mii->mii_media_active |= IFM_FDX; 320 } else 321 mii->mii_media_active = ife->ifm_media; 322} 323 324static void 325acphy_reset(sc) 326 struct mii_softc *sc; 327{ 328 329 mii_phy_reset(sc); 330 PHY_WRITE(sc, MII_ACPHY_INT, 0); 331}
|