jmphy.c (213893) | jmphy.c (215298) |
---|---|
1/*- 2 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/dev/mii/jmphy.c 213893 2010-10-15 14:52:11Z marius $"); | 29__FBSDID("$FreeBSD: head/sys/dev/mii/jmphy.c 215298 2010-11-14 13:31:01Z marius $"); |
30 31/* 32 * Driver for the JMicron JMP211 10/100/1000, JMP202 10/100 PHY. 33 */ 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> --- 7 unchanged lines hidden (view full) --- 45#include <dev/mii/mii.h> 46#include <dev/mii/miivar.h> 47#include "miidevs.h" 48 49#include <dev/mii/jmphyreg.h> 50 51#include "miibus_if.h" 52 | 30 31/* 32 * Driver for the JMicron JMP211 10/100/1000, JMP202 10/100 PHY. 33 */ 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> --- 7 unchanged lines hidden (view full) --- 45#include <dev/mii/mii.h> 46#include <dev/mii/miivar.h> 47#include "miidevs.h" 48 49#include <dev/mii/jmphyreg.h> 50 51#include "miibus_if.h" 52 |
53static int jmphy_probe(device_t); 54static int jmphy_attach(device_t); | 53static int jmphy_probe(device_t); 54static int jmphy_attach(device_t); |
55static void jmphy_reset(struct mii_softc *); 56static uint16_t jmphy_anar(struct ifmedia_entry *); | 55static void jmphy_reset(struct mii_softc *); 56static uint16_t jmphy_anar(struct ifmedia_entry *); |
57static int jmphy_auto(struct mii_softc *, struct ifmedia_entry *); | 57static int jmphy_setmedia(struct mii_softc *, struct ifmedia_entry *); |
58 59struct jmphy_softc { 60 struct mii_softc mii_sc; 61 int mii_oui; 62 int mii_model; 63 int mii_rev; 64}; 65 --- 83 unchanged lines hidden (view full) --- 149 150 case MII_MEDIACHG: 151 /* 152 * If the interface is not up, don't do anything. 153 */ 154 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 155 break; 156 | 58 59struct jmphy_softc { 60 struct mii_softc mii_sc; 61 int mii_oui; 62 int mii_model; 63 int mii_rev; 64}; 65 --- 83 unchanged lines hidden (view full) --- 149 150 case MII_MEDIACHG: 151 /* 152 * If the interface is not up, don't do anything. 153 */ 154 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 155 break; 156 |
157 if (jmphy_auto(sc, ife) != EJUSTRETURN) | 157 if (jmphy_setmedia(sc, ife) != EJUSTRETURN) |
158 return (EINVAL); 159 break; 160 161 case MII_TICK: 162 /* 163 * Is the interface even up? 164 */ 165 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) --- 15 unchanged lines hidden (view full) --- 181 182 /* Announce link loss right after it happens. */ 183 if (sc->mii_ticks++ == 0) 184 break; 185 if (sc->mii_ticks <= sc->mii_anegticks) 186 return (0); 187 188 sc->mii_ticks = 0; | 158 return (EINVAL); 159 break; 160 161 case MII_TICK: 162 /* 163 * Is the interface even up? 164 */ 165 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) --- 15 unchanged lines hidden (view full) --- 181 182 /* Announce link loss right after it happens. */ 183 if (sc->mii_ticks++ == 0) 184 break; 185 if (sc->mii_ticks <= sc->mii_anegticks) 186 return (0); 187 188 sc->mii_ticks = 0; |
189 jmphy_auto(sc, ife); | 189 (void)jmphy_setmedia(sc, ife); |
190 break; 191 } 192 193 /* Update the media status. */ 194 jmphy_status(sc); 195 196 /* Callback if something changed. */ 197 mii_phy_update(sc, cmd); --- 48 unchanged lines hidden (view full) --- 246 sc->mii_ticks = 0; 247 break; 248 default: 249 mii->mii_media_active |= IFM_NONE; 250 return; 251 } 252 253 if ((ssr & JMPHY_SSR_DUPLEX) != 0) | 190 break; 191 } 192 193 /* Update the media status. */ 194 jmphy_status(sc); 195 196 /* Callback if something changed. */ 197 mii_phy_update(sc, cmd); --- 48 unchanged lines hidden (view full) --- 246 sc->mii_ticks = 0; 247 break; 248 default: 249 mii->mii_media_active |= IFM_NONE; 250 return; 251 } 252 253 if ((ssr & JMPHY_SSR_DUPLEX) != 0) |
254 mii->mii_media_active |= IFM_FDX; | 254 mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc); |
255 else 256 mii->mii_media_active |= IFM_HDX; | 255 else 256 mii->mii_media_active |= IFM_HDX; |
257 /* XXX Flow-control. */ 258#ifdef notyet | 257 |
259 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) { 260 if ((PHY_READ(sc, MII_100T2SR) & GTSR_MS_RES) != 0) 261 mii->mii_media_active |= IFM_ETH_MASTER; 262 } | 258 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) { 259 if ((PHY_READ(sc, MII_100T2SR) & GTSR_MS_RES) != 0) 260 mii->mii_media_active |= IFM_ETH_MASTER; 261 } |
263#endif | |
264} 265 266static void 267jmphy_reset(struct mii_softc *sc) 268{ 269 struct jmphy_softc *jsc; 270 int i; 271 --- 32 unchanged lines hidden (view full) --- 304 default: 305 break; 306 } 307 308 return (anar); 309} 310 311static int | 262} 263 264static void 265jmphy_reset(struct mii_softc *sc) 266{ 267 struct jmphy_softc *jsc; 268 int i; 269 --- 32 unchanged lines hidden (view full) --- 302 default: 303 break; 304 } 305 306 return (anar); 307} 308 309static int |
312jmphy_auto(struct mii_softc *sc, struct ifmedia_entry *ife) | 310jmphy_setmedia(struct mii_softc *sc, struct ifmedia_entry *ife) |
313{ 314 uint16_t anar, bmcr, gig; 315 316 gig = 0; 317 bmcr = PHY_READ(sc, MII_BMCR); 318 switch (IFM_SUBTYPE(ife->ifm_media)) { 319 case IFM_AUTO: 320 gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; --- 10 unchanged lines hidden (view full) --- 331 default: 332 return (EINVAL); 333 } 334 335 if ((ife->ifm_media & IFM_LOOP) != 0) 336 bmcr |= BMCR_LOOP; 337 338 anar = jmphy_anar(ife); | 311{ 312 uint16_t anar, bmcr, gig; 313 314 gig = 0; 315 bmcr = PHY_READ(sc, MII_BMCR); 316 switch (IFM_SUBTYPE(ife->ifm_media)) { 317 case IFM_AUTO: 318 gig |= GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX; --- 10 unchanged lines hidden (view full) --- 329 default: 330 return (EINVAL); 331 } 332 333 if ((ife->ifm_media & IFM_LOOP) != 0) 334 bmcr |= BMCR_LOOP; 335 336 anar = jmphy_anar(ife); |
339 /* XXX Always advertise pause capability. */ 340 anar |= (3 << 10); | 337 if (((IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO || 338 (ife->ifm_media & IFM_FDX) != 0) && 339 (ife->ifm_media & IFM_FLOW) != 0) || 340 (sc->mii_flags & MIIF_FORCEPAUSE) != 0) 341 anar |= ANAR_PAUSE_TOWARDS; |
341 342 if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) { | 342 343 if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) { |
343#ifdef notyet 344 struct mii_data *mii; 345 346 mii = sc->mii_pdata; 347 if ((mii->mii_media.ifm_media & IFM_ETH_MASTER) != 0) 348 gig |= GTCR_MAN_MS | GTCR_MAN_ADV; 349#endif | 344 if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { 345 gig |= GTCR_MAN_MS; 346 if ((ife->ifm_media & IFM_ETH_MASTER) != 0) 347 gig |= GTCR_ADV_MS; 348 } |
350 PHY_WRITE(sc, MII_100T2CR, gig); 351 } 352 PHY_WRITE(sc, MII_ANAR, anar | ANAR_CSMA); 353 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_AUTOEN | BMCR_STARTNEG); 354 355 return (EJUSTRETURN); 356} | 349 PHY_WRITE(sc, MII_100T2CR, gig); 350 } 351 PHY_WRITE(sc, MII_ANAR, anar | ANAR_CSMA); 352 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_AUTOEN | BMCR_STARTNEG); 353 354 return (EJUSTRETURN); 355} |