From nobody@FreeBSD.org  Mon Feb 27 21:59:05 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 96251106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Feb 2012 21:59:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 81DCA8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Feb 2012 21:59:05 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q1RLx5XU071772
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Feb 2012 21:59:05 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q1RLx5lD071771;
	Mon, 27 Feb 2012 21:59:05 GMT
	(envelope-from nobody)
Message-Id: <201202272159.q1RLx5lD071771@red.freebsd.org>
Date: Mon, 27 Feb 2012 21:59:05 GMT
From: Nugroho Atmotaruno <atmotaruno@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: re(4) intermittently UP/DOWN on TPLink TG-3268
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         165509
>Category:       kern
>Synopsis:       [re] re(4) intermittently UP/DOWN on TPLink TG-3268
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yongari
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 27 22:00:32 UTC 2012
>Closed-Date:    Mon Mar 26 05:02:30 UTC 2012
>Last-Modified:  Mon Mar 26 05:02:30 UTC 2012
>Originator:     Nugroho Atmotaruno
>Release:        FreeBSD 9.0 -RELEASE
>Organization:
ARC ITB
>Environment:
FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64

>Description:
TPLink TG-3268 (rl8169) flapping (UP/DOWN every several seconds).

[root@xtreme ~]# tail /var/log/messages
Feb 23 04:47:05 xtreme kernel: re0: link state changed to UP
Feb 23 04:47:07 xtreme kernel: re0: link state changed to DOWN
Feb 23 04:47:10 xtreme kernel: re0: link state changed to UP
Feb 23 04:47:16 xtreme kernel: re0: link state changed to DOWN
Feb 23 04:47:19 xtreme kernel: re0: link state changed to UP
Feb 23 04:47:20 xtreme kernel: re0: link state changed to DOWN
Feb 23 04:47:23 xtreme kernel: re0: link state changed to UP
Feb 23 04:48:44 xtreme kernel: re0: link state changed to DOWN
Feb 23 04:48:47 xtreme kernel: re0: link state changed to UP


[root@xtreme ~]# pciconf -lcv
re0@pci0:2:5:0: class=0x020000 card=0x816910ec chip=0x816910ec rev=0x10 hdr=0x00
   vendor     = 'Realtek Semiconductor Co., Ltd.'
   device     = 'RTL-8169 Gigabit Ethernet'
   class      = network
   subclass   = ethernet
   cap 01[dc] = powerspec 2  supports D0 D1 D2 D3  current D0

[root@xtreme ~]# devinfo -rv | grep rg
rgephy0 pnpinfo oui=0xe04c model=0x11 rev=0x3 at phyno=1
>How-To-Repeat:

>Fix:
YongHyeon PYUN sent following patch.

Patch attached with submission follows:

Index: sys/dev/mii/rgephy.c
===================================================================
--- sys/dev/mii/rgephy.c	(revision 232144)
+++ sys/dev/mii/rgephy.c	(working copy)
@@ -110,11 +110,16 @@
 rgephy_attach(device_t dev)
 {
 	struct mii_softc *sc;
+	struct mii_attach_args *ma;
+	u_int flags;
 
 	sc = device_get_softc(dev);
+	ma = device_get_ivars(dev);
+	flags = 0;
+	if (strcmp(ma->mii_data->mii_ifp->if_dname, "re") == 0)
+		flags |= MIIF_PHYPRIV0;
+	mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);
 
-	mii_phy_dev_attach(dev, 0, &rgephy_funcs, 0);
-
 	/* RTL8169S do not report auto-sense; add manually. */
 	sc->mii_capabilities = (PHY_READ(sc, MII_BMSR) | BMSR_ANEG) &
 	    sc->mii_capmask;
@@ -243,7 +248,8 @@
 		 * Check to see if we have link.  If we do, we don't
 		 * need to restart the autonegotiation process.
 		 */
-		if (sc->mii_mpd_rev >= 2) {
+		if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 &&
+		    sc->mii_mpd_rev >= 2) {
 			/* RTL8211B(L) */
 			reg = PHY_READ(sc, RGEPHY_MII_SSR);
 			if (reg & RGEPHY_SSR_LINK) {
@@ -298,7 +304,7 @@
 	mii->mii_media_status = IFM_AVALID;
 	mii->mii_media_active = IFM_ETHER;
 
-	if (sc->mii_mpd_rev >= 2) {
+	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
 		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
 		if (ssr & RGEPHY_SSR_LINK)
 			mii->mii_media_status |= IFM_ACTIVE;
@@ -328,7 +334,7 @@
 		}
 	}
 
-	if (sc->mii_mpd_rev >= 2) {
+	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
 		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
 		switch (ssr & RGEPHY_SSR_SPD_MASK) {
 		case RGEPHY_SSR_S1000:
@@ -484,7 +490,7 @@
 {
 	uint16_t ssr;
 
-	if (sc->mii_mpd_rev == 3) {
+	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev == 3) {
 		/* RTL8211C(L) */
 		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
 		if ((ssr & RGEPHY_SSR_ALDPS) != 0) {
Index: sys/dev/re/if_re.c
===================================================================
--- sys/dev/re/if_re.c	(revision 232145)
+++ sys/dev/re/if_re.c	(working copy)
@@ -1577,19 +1577,6 @@
 		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;
@@ -1614,6 +1601,19 @@
 
 	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.
 	 */


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Feb 28 04:26:12 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165509 
Responsible-Changed-From-To: freebsd-net->yongari 
Responsible-Changed-By: yongari 
Responsible-Changed-When: Tue Feb 28 05:10:07 UTC 2012 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165509 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165509: commit references a PR
Date: Tue, 28 Feb 2012 05:23:40 +0000 (UTC)

 Author: yongari
 Date: Tue Feb 28 05:23:29 2012
 New Revision: 232246
 URL: http://svn.freebsd.org/changeset/base/232246
 
 Log:
   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:
   head/sys/dev/mii/rgephy.c
   head/sys/dev/re/if_re.c
 
 Modified: head/sys/dev/mii/rgephy.c
 ==============================================================================
 --- head/sys/dev/mii/rgephy.c	Tue Feb 28 04:06:42 2012	(r232245)
 +++ head/sys/dev/mii/rgephy.c	Tue Feb 28 05:23:29 2012	(r232246)
 @@ -110,10 +110,15 @@ static int
  rgephy_attach(device_t dev)
  {
  	struct mii_softc *sc;
 +	struct mii_attach_args *ma;
 +	u_int flags;
  
  	sc = device_get_softc(dev);
 -
 -	mii_phy_dev_attach(dev, 0, &rgephy_funcs, 0);
 +	ma = device_get_ivars(dev);
 +	flags = 0;
 +	if (strcmp(ma->mii_data->mii_ifp->if_dname, "re") == 0)
 +		flags |= MIIF_PHYPRIV0;
 +	mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);
  
  	/* RTL8169S do not report auto-sense; add manually. */
  	sc->mii_capabilities = (PHY_READ(sc, MII_BMSR) | BMSR_ANEG) &
 @@ -243,7 +248,8 @@ setit:
  		 * Check to see if we have link.  If we do, we don't
  		 * need to restart the autonegotiation process.
  		 */
 -		if (sc->mii_mpd_rev >= 2) {
 +		if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 &&
 +		    sc->mii_mpd_rev >= 2) {
  			/* RTL8211B(L) */
  			reg = PHY_READ(sc, RGEPHY_MII_SSR);
  			if (reg & RGEPHY_SSR_LINK) {
 @@ -298,7 +304,7 @@ rgephy_status(struct mii_softc *sc)
  	mii->mii_media_status = IFM_AVALID;
  	mii->mii_media_active = IFM_ETHER;
  
 -	if (sc->mii_mpd_rev >= 2) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		if (ssr & RGEPHY_SSR_LINK)
  			mii->mii_media_status |= IFM_ACTIVE;
 @@ -328,7 +334,7 @@ rgephy_status(struct mii_softc *sc)
  		}
  	}
  
 -	if (sc->mii_mpd_rev >= 2) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		switch (ssr & RGEPHY_SSR_SPD_MASK) {
  		case RGEPHY_SSR_S1000:
 @@ -484,7 +490,7 @@ rgephy_reset(struct mii_softc *sc)
  {
  	uint16_t ssr;
  
 -	if (sc->mii_mpd_rev == 3) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev == 3) {
  		/* RTL8211C(L) */
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		if ((ssr & RGEPHY_SSR_ALDPS) != 0) {
 
 Modified: head/sys/dev/re/if_re.c
 ==============================================================================
 --- head/sys/dev/re/if_re.c	Tue Feb 28 04:06:42 2012	(r232245)
 +++ head/sys/dev/re/if_re.c	Tue Feb 28 05:23:29 2012	(r232246)
 @@ -1577,19 +1577,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;
 @@ -1614,6 +1601,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.
  	 */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: yongari 
State-Changed-When: Tue Feb 28 05:37:54 UTC 2012 
State-Changed-Why:  
Committed to HEAD(r232246). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165509 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165509: commit references a PR
Date: Mon, 26 Mar 2012 04:27:10 +0000 (UTC)

 Author: yongari
 Date: Mon Mar 26 04:27:01 2012
 New Revision: 233492
 URL: http://svn.freebsd.org/changeset/base/233492
 
 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/9/sys/dev/mii/rgephy.c
   stable/9/sys/dev/re/if_re.c
 Directory Properties:
   stable/9/sys/   (props changed)
   stable/9/sys/amd64/include/xen/   (props changed)
   stable/9/sys/boot/   (props changed)
   stable/9/sys/boot/i386/efi/   (props changed)
   stable/9/sys/boot/ia64/efi/   (props changed)
   stable/9/sys/boot/ia64/ski/   (props changed)
   stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
   stable/9/sys/boot/powerpc/ofw/   (props changed)
   stable/9/sys/cddl/contrib/opensolaris/   (props changed)
   stable/9/sys/conf/   (props changed)
   stable/9/sys/contrib/dev/acpica/   (props changed)
   stable/9/sys/contrib/octeon-sdk/   (props changed)
   stable/9/sys/contrib/pf/   (props changed)
   stable/9/sys/contrib/x86emu/   (props changed)
   stable/9/sys/fs/   (props changed)
   stable/9/sys/fs/ntfs/   (props changed)
   stable/9/sys/i386/conf/XENHVM   (props changed)
 
 Modified: stable/9/sys/dev/mii/rgephy.c
 ==============================================================================
 --- stable/9/sys/dev/mii/rgephy.c	Mon Mar 26 03:56:52 2012	(r233491)
 +++ stable/9/sys/dev/mii/rgephy.c	Mon Mar 26 04:27:01 2012	(r233492)
 @@ -110,10 +110,15 @@ static int
  rgephy_attach(device_t dev)
  {
  	struct mii_softc *sc;
 +	struct mii_attach_args *ma;
 +	u_int flags;
  
  	sc = device_get_softc(dev);
 -
 -	mii_phy_dev_attach(dev, 0, &rgephy_funcs, 0);
 +	ma = device_get_ivars(dev);
 +	flags = 0;
 +	if (strcmp(ma->mii_data->mii_ifp->if_dname, "re") == 0)
 +		flags |= MIIF_PHYPRIV0;
 +	mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);
  
  	/* RTL8169S do not report auto-sense; add manually. */
  	sc->mii_capabilities = (PHY_READ(sc, MII_BMSR) | BMSR_ANEG) &
 @@ -243,7 +248,8 @@ setit:
  		 * Check to see if we have link.  If we do, we don't
  		 * need to restart the autonegotiation process.
  		 */
 -		if (sc->mii_mpd_rev >= 2) {
 +		if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 &&
 +		    sc->mii_mpd_rev >= 2) {
  			/* RTL8211B(L) */
  			reg = PHY_READ(sc, RGEPHY_MII_SSR);
  			if (reg & RGEPHY_SSR_LINK) {
 @@ -298,7 +304,7 @@ rgephy_status(struct mii_softc *sc)
  	mii->mii_media_status = IFM_AVALID;
  	mii->mii_media_active = IFM_ETHER;
  
 -	if (sc->mii_mpd_rev >= 2) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		if (ssr & RGEPHY_SSR_LINK)
  			mii->mii_media_status |= IFM_ACTIVE;
 @@ -328,7 +334,7 @@ rgephy_status(struct mii_softc *sc)
  		}
  	}
  
 -	if (sc->mii_mpd_rev >= 2) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev >= 2) {
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		switch (ssr & RGEPHY_SSR_SPD_MASK) {
  		case RGEPHY_SSR_S1000:
 @@ -484,7 +490,7 @@ rgephy_reset(struct mii_softc *sc)
  {
  	uint16_t ssr;
  
 -	if (sc->mii_mpd_rev == 3) {
 +	if ((sc->mii_flags & MIIF_PHYPRIV0) == 0 && sc->mii_mpd_rev == 3) {
  		/* RTL8211C(L) */
  		ssr = PHY_READ(sc, RGEPHY_MII_SSR);
  		if ((ssr & RGEPHY_SSR_ALDPS) != 0) {
 
 Modified: stable/9/sys/dev/re/if_re.c
 ==============================================================================
 --- stable/9/sys/dev/re/if_re.c	Mon Mar 26 03:56:52 2012	(r233491)
 +++ stable/9/sys/dev/re/if_re.c	Mon Mar 26 04:27:01 2012	(r233492)
 @@ -1573,19 +1573,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;
 @@ -1610,6 +1597,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.
  	 */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165509: commit references a PR
Date: Mon, 26 Mar 2012 04:29:22 +0000 (UTC)

 Author: yongari
 Date: Mon Mar 26 04:29:06 2012
 New Revision: 233493
 URL: http://svn.freebsd.org/changeset/base/233493
 
 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/8/sys/dev/mii/rgephy.c
   stable/8/sys/dev/re/if_re.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/boot/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
   stable/8/sys/dev/e1000/   (props changed)
   stable/8/sys/i386/conf/XENHVM   (props changed)
 
 Modified: stable/8/sys/dev/mii/rgephy.c
 ==============================================================================
 --- stable/8/sys/dev/mii/rgephy.c	Mon Mar 26 04:27:01 2012	(r233492)
 +++ stable/8/sys/dev/mii/rgephy.c	Mon Mar 26 04:29:06 2012	(r233493)
 @@ -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/8/sys/dev/re/if_re.c
 ==============================================================================
 --- stable/8/sys/dev/re/if_re.c	Mon Mar 26 04:27:01 2012	(r233492)
 +++ stable/8/sys/dev/re/if_re.c	Mon Mar 26 04:29:06 2012	(r233493)
 @@ -1573,19 +1573,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;
 @@ -1610,6 +1597,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.
  	 */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165509: commit references a PR
Date: Mon, 26 Mar 2012 04:30:58 +0000 (UTC)

 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.
  	 */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: yongari 
State-Changed-When: Mon Mar 26 05:01:27 UTC 2012 
State-Changed-Why:  
MFC to stable/[7-9] done. 
Thanks for reporting! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165509 
>Unformatted:
