From owner-svn-src-all@FreeBSD.ORG Mon Mar 26 04:30:47 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 33AAB106566C; Mon, 26 Mar 2012 04:30:47 +0000 (UTC) (envelope-from yongari@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1D5B58FC12; Mon, 26 Mar 2012 04:30:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2Q4UkjF014665; Mon, 26 Mar 2012 04:30:46 GMT (envelope-from yongari@svn.freebsd.org) Received: (from yongari@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2Q4UkCK014662; Mon, 26 Mar 2012 04:30:46 GMT (envelope-from yongari@svn.freebsd.org) Message-Id: <201203260430.q2Q4UkCK014662@svn.freebsd.org> From: Pyun YongHyeon Date: Mon, 26 Mar 2012 04:30:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233494 - in stable/7/sys/dev: mii re X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 04:30:47 -0000 Author: yongari Date: Mon Mar 26 04:30:46 2012 New Revision: 233494 URL: http://svn.freebsd.org/changeset/base/233494 Log: MFC r232246: Prefer RL_GMEDIASTAT register to RGEPHY_MII_SSR register to extract a link status of PHY when parent driver is re(4). RGEPHY_MII_SSR register does not seem to report correct PHY status on some integrated PHYs used with re(4). Unfortunately, RealTek PHYs have no additional information to differentiate integrated PHYs from external ones so relying on PHY model number is not enough to know that. However, it seems RGEPHY_MII_SSR register exists for external RealTek PHYs so checking parent driver would be good indication to know which PHY was used. In other words, for non-re(4) controllers, the PHY is external one and its revision number is greater than or equal to 2. This change fixes intermittent link UP/DOWN messages reported on RTL8169 controller. Also, mii_attach(9) is tried after setting interface name since rgephy(4) have to know parent driver name. PR: kern/165509 Modified: stable/7/sys/dev/mii/rgephy.c stable/7/sys/dev/re/if_re.c Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/dev/mii/rgephy.c ============================================================================== --- stable/7/sys/dev/mii/rgephy.c Mon Mar 26 04:29:06 2012 (r233493) +++ stable/7/sys/dev/mii/rgephy.c Mon Mar 26 04:30:46 2012 (r233494) @@ -122,6 +122,8 @@ rgephy_attach(device_t dev) LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); sc->mii_flags = miibus_get_flags(dev); + if (strcmp(ma->mii_data->mii_ifp->if_dname, "re") == 0) + sc->mii_flags |= MIIF_PHYPRIV0; sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = rgephy_service; @@ -268,7 +270,8 @@ setit: * Check to see if we have link. If we do, we don't * need to restart the autonegotiation process. */ - if (rsc->mii_revision >= 2) { + if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && + rsc->mii_revision >= 2) { /* RTL8211B(L) */ reg = PHY_READ(sc, RGEPHY_MII_SSR); if (reg & RGEPHY_SSR_LINK) { @@ -325,7 +328,7 @@ rgephy_status(struct mii_softc *sc) mii->mii_media_active = IFM_ETHER; rsc = (struct rgephy_softc *)sc; - if (rsc->mii_revision >= 2) { + if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && rsc->mii_revision >= 2) { ssr = PHY_READ(sc, RGEPHY_MII_SSR); if (ssr & RGEPHY_SSR_LINK) mii->mii_media_status |= IFM_ACTIVE; @@ -355,7 +358,7 @@ rgephy_status(struct mii_softc *sc) } } - if (rsc->mii_revision >= 2) { + if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && rsc->mii_revision >= 2) { ssr = PHY_READ(sc, RGEPHY_MII_SSR); switch (ssr & RGEPHY_SSR_SPD_MASK) { case RGEPHY_SSR_S1000: @@ -517,7 +520,7 @@ rgephy_reset(struct mii_softc *sc) uint16_t ssr; rsc = (struct rgephy_softc *)sc; - if (rsc->mii_revision == 3) { + if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && rsc->mii_revision == 3) { /* RTL8211C(L) */ ssr = PHY_READ(sc, RGEPHY_MII_SSR); if ((ssr & RGEPHY_SSR_ALDPS) != 0) { Modified: stable/7/sys/dev/re/if_re.c ============================================================================== --- stable/7/sys/dev/re/if_re.c Mon Mar 26 04:29:06 2012 (r233493) +++ stable/7/sys/dev/re/if_re.c Mon Mar 26 04:30:46 2012 (r233494) @@ -1578,19 +1578,6 @@ re_attach(device_t dev) re_gmii_writereg(dev, 1, 0x0e, 0); } -#define RE_PHYAD_INTERNAL 0 - - /* Do MII setup. */ - phy = RE_PHYAD_INTERNAL; - if (sc->rl_type == RL_8169) - phy = 1; - error = mii_attach(dev, &sc->rl_miibus, ifp, re_ifmedia_upd, - re_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, MIIF_DOPAUSE); - if (error != 0) { - device_printf(dev, "attaching PHYs failed\n"); - goto fail; - } - ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; @@ -1615,6 +1602,19 @@ re_attach(device_t dev) TASK_INIT(&sc->rl_inttask, 0, re_int_task, sc); +#define RE_PHYAD_INTERNAL 0 + + /* Do MII setup. */ + phy = RE_PHYAD_INTERNAL; + if (sc->rl_type == RL_8169) + phy = 1; + error = mii_attach(dev, &sc->rl_miibus, ifp, re_ifmedia_upd, + re_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, MIIF_DOPAUSE); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); + goto fail; + } + /* * Call MI attach routine. */