if_gem.c (212725) | if_gem.c (213893) |
---|---|
1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2001-2003 Thomas Moestl 4 * Copyright (c) 2007 Marius Strobl <marius@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 15 unchanged lines hidden (view full) --- 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from: NetBSD: gem.c,v 1.21 2002/06/01 23:50:58 lukem Exp 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2001 Eduardo Horvath. 3 * Copyright (c) 2001-2003 Thomas Moestl 4 * Copyright (c) 2007 Marius Strobl <marius@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 15 unchanged lines hidden (view full) --- 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from: NetBSD: gem.c,v 1.21 2002/06/01 23:50:58 lukem Exp 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem.c 212725 2010-09-16 09:29:48Z marius $"); | 32__FBSDID("$FreeBSD: head/sys/dev/gem/if_gem.c 213893 2010-10-15 14:52:11Z marius $"); |
33 34/* 35 * Driver for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers 36 */ 37 38#if 0 39#define GEM_DEBUG 40#endif --- 103 unchanged lines hidden (view full) --- 144#define GEM_BANK2_BITWAIT(sc, r, clr, set) \ 145 gem_bitwait((sc), GEM_RES_BANK2, (r), (clr), (set)) 146 147int 148gem_attach(struct gem_softc *sc) 149{ 150 struct gem_txsoft *txs; 151 struct ifnet *ifp; | 33 34/* 35 * Driver for Apple GMAC, Sun ERI and Sun GEM Ethernet controllers 36 */ 37 38#if 0 39#define GEM_DEBUG 40#endif --- 103 unchanged lines hidden (view full) --- 144#define GEM_BANK2_BITWAIT(sc, r, clr, set) \ 145 gem_bitwait((sc), GEM_RES_BANK2, (r), (clr), (set)) 146 147int 148gem_attach(struct gem_softc *sc) 149{ 150 struct gem_txsoft *txs; 151 struct ifnet *ifp; |
152 int error, i; | 152 int error, i, phy; |
153 uint32_t v; 154 155 if (bootverbose) 156 device_printf(sc->sc_dev, "flags=0x%x\n", sc->sc_flags); 157 158 /* Set up ifnet structure. */ 159 ifp = sc->sc_ifp = if_alloc(IFT_ETHER); 160 if (ifp == NULL) --- 128 unchanged lines hidden (view full) --- 289 v = GEM_BANK1_READ_4(sc, GEM_MIF_CONFIG); 290 if ((v & GEM_MIF_CONFIG_MDI1) != 0) { 291 v |= GEM_MIF_CONFIG_PHY_SEL; 292 GEM_BANK1_WRITE_4(sc, GEM_MIF_CONFIG, v); 293 GEM_BANK1_BARRIER(sc, GEM_MIF_CONFIG, 4, 294 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); 295 switch (sc->sc_variant) { 296 case GEM_SUN_ERI: | 153 uint32_t v; 154 155 if (bootverbose) 156 device_printf(sc->sc_dev, "flags=0x%x\n", sc->sc_flags); 157 158 /* Set up ifnet structure. */ 159 ifp = sc->sc_ifp = if_alloc(IFT_ETHER); 160 if (ifp == NULL) --- 128 unchanged lines hidden (view full) --- 289 v = GEM_BANK1_READ_4(sc, GEM_MIF_CONFIG); 290 if ((v & GEM_MIF_CONFIG_MDI1) != 0) { 291 v |= GEM_MIF_CONFIG_PHY_SEL; 292 GEM_BANK1_WRITE_4(sc, GEM_MIF_CONFIG, v); 293 GEM_BANK1_BARRIER(sc, GEM_MIF_CONFIG, 4, 294 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); 295 switch (sc->sc_variant) { 296 case GEM_SUN_ERI: |
297 sc->sc_phyad = GEM_PHYAD_EXTERNAL; | 297 phy = GEM_PHYAD_EXTERNAL; |
298 break; 299 default: | 298 break; 299 default: |
300 sc->sc_phyad = -1; | 300 phy = MII_PHY_ANY; |
301 break; 302 } | 301 break; 302 } |
303 error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, 304 gem_mediachange, gem_mediastatus); | 303 error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, 304 gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, phy, 305 MII_OFFSET_ANY, 0); |
305 } 306 307 /* 308 * Fall back on an internal PHY if no external PHY was found. 309 * Note that with Apple (K2) GMACs GEM_MIF_CONFIG_MDI0 can't be 310 * trusted when the firmware has powered down the chip. 311 */ 312 if (error != 0 && 313 ((v & GEM_MIF_CONFIG_MDI0) != 0 || GEM_IS_APPLE(sc))) { 314 v &= ~GEM_MIF_CONFIG_PHY_SEL; 315 GEM_BANK1_WRITE_4(sc, GEM_MIF_CONFIG, v); 316 GEM_BANK1_BARRIER(sc, GEM_MIF_CONFIG, 4, 317 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); 318 switch (sc->sc_variant) { 319 case GEM_SUN_ERI: 320 case GEM_APPLE_K2_GMAC: | 306 } 307 308 /* 309 * Fall back on an internal PHY if no external PHY was found. 310 * Note that with Apple (K2) GMACs GEM_MIF_CONFIG_MDI0 can't be 311 * trusted when the firmware has powered down the chip. 312 */ 313 if (error != 0 && 314 ((v & GEM_MIF_CONFIG_MDI0) != 0 || GEM_IS_APPLE(sc))) { 315 v &= ~GEM_MIF_CONFIG_PHY_SEL; 316 GEM_BANK1_WRITE_4(sc, GEM_MIF_CONFIG, v); 317 GEM_BANK1_BARRIER(sc, GEM_MIF_CONFIG, 4, 318 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); 319 switch (sc->sc_variant) { 320 case GEM_SUN_ERI: 321 case GEM_APPLE_K2_GMAC: |
321 sc->sc_phyad = GEM_PHYAD_INTERNAL; | 322 phy = GEM_PHYAD_INTERNAL; |
322 break; 323 case GEM_APPLE_GMAC: | 323 break; 324 case GEM_APPLE_GMAC: |
324 sc->sc_phyad = GEM_PHYAD_EXTERNAL; | 325 phy = GEM_PHYAD_EXTERNAL; |
325 break; 326 default: | 326 break; 327 default: |
327 sc->sc_phyad = -1; | 328 phy = MII_PHY_ANY; |
328 break; 329 } | 329 break; 330 } |
330 error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, 331 gem_mediachange, gem_mediastatus); | 331 error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, 332 gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, phy, 333 MII_OFFSET_ANY, 0); |
332 } 333 334 /* 335 * Try the external PCS SERDES if we didn't find any PHYs. 336 */ 337 if (error != 0 && sc->sc_variant == GEM_SUN_GEM) { 338 serdes: 339 GEM_BANK1_WRITE_4(sc, GEM_MII_DATAPATH_MODE, 340 GEM_MII_DATAPATH_SERDES); 341 GEM_BANK1_BARRIER(sc, GEM_MII_DATAPATH_MODE, 4, 342 BUS_SPACE_BARRIER_WRITE); 343 GEM_BANK1_WRITE_4(sc, GEM_MII_SLINK_CONTROL, 344 GEM_MII_SLINK_LOOPBACK | GEM_MII_SLINK_EN_SYNC_D); 345 GEM_BANK1_BARRIER(sc, GEM_MII_SLINK_CONTROL, 4, 346 BUS_SPACE_BARRIER_WRITE); 347 GEM_BANK1_WRITE_4(sc, GEM_MII_CONFIG, GEM_MII_CONFIG_ENABLE); 348 GEM_BANK1_BARRIER(sc, GEM_MII_CONFIG, 4, 349 BUS_SPACE_BARRIER_WRITE); 350 sc->sc_flags |= GEM_SERDES; | 334 } 335 336 /* 337 * Try the external PCS SERDES if we didn't find any PHYs. 338 */ 339 if (error != 0 && sc->sc_variant == GEM_SUN_GEM) { 340 serdes: 341 GEM_BANK1_WRITE_4(sc, GEM_MII_DATAPATH_MODE, 342 GEM_MII_DATAPATH_SERDES); 343 GEM_BANK1_BARRIER(sc, GEM_MII_DATAPATH_MODE, 4, 344 BUS_SPACE_BARRIER_WRITE); 345 GEM_BANK1_WRITE_4(sc, GEM_MII_SLINK_CONTROL, 346 GEM_MII_SLINK_LOOPBACK | GEM_MII_SLINK_EN_SYNC_D); 347 GEM_BANK1_BARRIER(sc, GEM_MII_SLINK_CONTROL, 4, 348 BUS_SPACE_BARRIER_WRITE); 349 GEM_BANK1_WRITE_4(sc, GEM_MII_CONFIG, GEM_MII_CONFIG_ENABLE); 350 GEM_BANK1_BARRIER(sc, GEM_MII_CONFIG, 4, 351 BUS_SPACE_BARRIER_WRITE); 352 sc->sc_flags |= GEM_SERDES; |
351 sc->sc_phyad = GEM_PHYAD_EXTERNAL; 352 error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, 353 gem_mediachange, gem_mediastatus); | 353 error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, 354 gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, 355 GEM_PHYAD_EXTERNAL, MII_OFFSET_ANY, 0); |
354 } 355 if (error != 0) { | 356 } 357 if (error != 0) { |
356 device_printf(sc->sc_dev, "PHY probe failed: %d\n", error); | 358 device_printf(sc->sc_dev, "attaching PHYs failed\n"); |
357 goto fail_rxd; 358 } 359 sc->sc_mii = device_get_softc(sc->sc_miibus); 360 361 /* 362 * From this point forward, the attachment cannot fail. A failure 363 * before this point releases all resources that may have been 364 * allocated. --- 1478 unchanged lines hidden (view full) --- 1843 int n; 1844 uint32_t v; 1845 1846#ifdef GEM_DEBUG_PHY 1847 printf("%s: phy %d reg %d\n", __func__, phy, reg); 1848#endif 1849 1850 sc = device_get_softc(dev); | 359 goto fail_rxd; 360 } 361 sc->sc_mii = device_get_softc(sc->sc_miibus); 362 363 /* 364 * From this point forward, the attachment cannot fail. A failure 365 * before this point releases all resources that may have been 366 * allocated. --- 1478 unchanged lines hidden (view full) --- 1845 int n; 1846 uint32_t v; 1847 1848#ifdef GEM_DEBUG_PHY 1849 printf("%s: phy %d reg %d\n", __func__, phy, reg); 1850#endif 1851 1852 sc = device_get_softc(dev); |
1851 if (sc->sc_phyad != -1 && phy != sc->sc_phyad) 1852 return (0); 1853 | |
1854 if ((sc->sc_flags & GEM_SERDES) != 0) { 1855 switch (reg) { 1856 case MII_BMCR: 1857 reg = GEM_MII_CONTROL; 1858 break; 1859 case MII_BMSR: 1860 reg = GEM_MII_STATUS; 1861 break; --- 42 unchanged lines hidden (view full) --- 1904 int n; 1905 uint32_t v; 1906 1907#ifdef GEM_DEBUG_PHY 1908 printf("%s: phy %d reg %d val %x\n", phy, reg, val, __func__); 1909#endif 1910 1911 sc = device_get_softc(dev); | 1853 if ((sc->sc_flags & GEM_SERDES) != 0) { 1854 switch (reg) { 1855 case MII_BMCR: 1856 reg = GEM_MII_CONTROL; 1857 break; 1858 case MII_BMSR: 1859 reg = GEM_MII_STATUS; 1860 break; --- 42 unchanged lines hidden (view full) --- 1903 int n; 1904 uint32_t v; 1905 1906#ifdef GEM_DEBUG_PHY 1907 printf("%s: phy %d reg %d val %x\n", phy, reg, val, __func__); 1908#endif 1909 1910 sc = device_get_softc(dev); |
1912 if (sc->sc_phyad != -1 && phy != sc->sc_phyad) 1913 return (0); 1914 | |
1915 if ((sc->sc_flags & GEM_SERDES) != 0) { 1916 switch (reg) { 1917 case MII_BMSR: 1918 reg = GEM_MII_STATUS; 1919 break; 1920 case MII_BMCR: 1921 reg = GEM_MII_CONTROL; 1922 if ((val & GEM_MII_CONTROL_RESET) == 0) --- 64 unchanged lines hidden (view full) --- 1987 uint32_t rxcfg, txcfg, v; 1988 1989 sc = device_get_softc(dev); 1990 1991 GEM_LOCK_ASSERT(sc, MA_OWNED); 1992 1993#ifdef GEM_DEBUG 1994 if ((sc->sc_ifp->if_flags & IFF_DEBUG) != 0) | 1911 if ((sc->sc_flags & GEM_SERDES) != 0) { 1912 switch (reg) { 1913 case MII_BMSR: 1914 reg = GEM_MII_STATUS; 1915 break; 1916 case MII_BMCR: 1917 reg = GEM_MII_CONTROL; 1918 if ((val & GEM_MII_CONTROL_RESET) == 0) --- 64 unchanged lines hidden (view full) --- 1983 uint32_t rxcfg, txcfg, v; 1984 1985 sc = device_get_softc(dev); 1986 1987 GEM_LOCK_ASSERT(sc, MA_OWNED); 1988 1989#ifdef GEM_DEBUG 1990 if ((sc->sc_ifp->if_flags & IFF_DEBUG) != 0) |
1995 device_printf(sc->sc_dev, "%s: status change: PHY = %d\n", 1996 __func__, sc->sc_phyad); | 1991 device_printf(sc->sc_dev, "%s: status change\n", __func__); |
1997#endif 1998 1999 if ((sc->sc_mii->mii_media_status & IFM_ACTIVE) != 0 && 2000 IFM_SUBTYPE(sc->sc_mii->mii_media_active) != IFM_NONE) 2001 sc->sc_flags |= GEM_LINK; 2002 else 2003 sc->sc_flags &= ~GEM_LINK; 2004 --- 256 unchanged lines hidden --- | 1992#endif 1993 1994 if ((sc->sc_mii->mii_media_status & IFM_ACTIVE) != 0 && 1995 IFM_SUBTYPE(sc->sc_mii->mii_media_active) != IFM_NONE) 1996 sc->sc_flags |= GEM_LINK; 1997 else 1998 sc->sc_flags &= ~GEM_LINK; 1999 --- 256 unchanged lines hidden --- |