From uspoerlein@gmail.com  Tue Jun 20 20:50:27 2006
Return-Path: <uspoerlein@gmail.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 5391016A4C7
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Jun 2006 20:50:27 +0000 (UTC)
	(envelope-from uspoerlein@gmail.com)
Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.184])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DE5DC43D6D
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Jun 2006 20:50:19 +0000 (GMT)
	(envelope-from uspoerlein@gmail.com)
Received: by nf-out-0910.google.com with SMTP id h2so1246nfe
        for <FreeBSD-gnats-submit@freebsd.org>; Tue, 20 Jun 2006 13:50:19 -0700 (PDT)
Received: by 10.48.143.15 with SMTP id q15mr5989748nfd;
        Tue, 20 Jun 2006 13:43:51 -0700 (PDT)
Received: from roadrunner.q.local ( [217.185.119.244])
        by mx.gmail.com with ESMTP id a24sm7139686nfc.2006.06.20.13.43.49;
        Tue, 20 Jun 2006 13:43:51 -0700 (PDT)
Received: from roadrunner.q.local (localhost [127.0.0.1])
	by roadrunner.q.local (8.13.6/8.13.6) with ESMTP id k5KKi37P003488;
	Tue, 20 Jun 2006 22:44:03 +0200 (CEST)
	(envelope-from q@roadrunner.q.local)
Received: (from q@localhost)
	by roadrunner.q.local (8.13.6/8.13.6/Submit) id k5KHX5Fd002353;
	Tue, 20 Jun 2006 19:33:05 +0200 (CEST)
	(envelope-from q)
Message-Id: <200606201733.k5KHX5Fd002353@roadrunner.q.local>
Date: Tue, 20 Jun 2006 19:33:05 +0200 (CEST)
From: Ulrich Spoerlein <uspoerlein@gmail.com>
Reply-To: Ulrich Spoerlein <uspoerlein@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Mike Silbersack <silby@silby.com>
Subject: [PATCH] make bfe(4) always detect LINK_DOWN events
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         99216
>Category:       kern
>Synopsis:       [bfe] [patch] make bfe(4) always detect LINK_DOWN events
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yongari
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 20 21:00:43 GMT 2006
>Closed-Date:    Tue Mar 18 02:20:43 UTC 2008
>Last-Modified:  Tue Mar 18 02:20:43 UTC 2008
>Originator:     Ulrich Spoerlein
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
>Environment:
>Description:
I investigated a bug/missing feature in the bfe(4) driver, which makes
it not see any LINK DOWN events unless you happen to invoke ifconfig.

This was tested by me and Ben Kaduk with an BCM4401, card=0x81271028 chip=0x440114e4;
Jean-Marc Zucconi, BCM4401, card=0x80a81043 chip=0x440114e4;
Mikko Tyljrvi, card=0x018d1028 chip=0x170c14e4

NB: Some variants of the chip work correctly even without the patch, though
no regression for these was found by
Lars Engels, BCM4401, card=0x108217c0 chip=0x440114e4
>How-To-Repeat:
1. Plug in ethernet cable
2. Watch dmesg/syslogd for the LINK UP message
3. Remove the cable
4. No LINK DOWN message. Only after you issue 'ifconfig'
>Fix:

--- if_bfe.c.orig	Wed Jun  7 21:34:49 2006
+++ if_bfe.c	Wed Jun  7 21:37:07 2006
@@ -1552,17 +1552,21 @@ bfe_tick(void *xsc)
 	mii = device_get_softc(sc->bfe_miibus);
 
 	bfe_stats_update(sc);
-	sc->bfe_stat_ch = timeout(bfe_tick, sc, hz);
 
-	if(sc->bfe_link) {
-		BFE_UNLOCK(sc);
-		return;
+	if (sc->bfe_miibus != NULL)
+		mii_tick(mii);
+
+	if (!sc->bfe_link) {
+		if (mii->mii_media_status & IFM_ACTIVE)
+			sc->bfe_link++;
+	} else {
+		mii_pollstat(mii);
+
+		if (!(mii->mii_media_status & IFM_ACTIVE))
+			sc->bfe_link = 0;
 	}
 
-	mii_tick(mii);
-	if (!sc->bfe_link && mii->mii_media_status & IFM_ACTIVE &&
-			IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)
-		sc->bfe_link++;
+	sc->bfe_stat_ch = timeout(bfe_tick, sc, hz);
 
 	BFE_UNLOCK(sc);
 }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->yongari 
Responsible-Changed-By: yongari 
Responsible-Changed-When: Thu Jan 31 03:33:43 UTC 2008 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99216 
State-Changed-From-To: open->patched 
State-Changed-By: yongari 
State-Changed-When: Sun Feb 3 02:42:40 UTC 2008 
State-Changed-Why:  
Submitter confirms that if_bfe.c, rev 1.44 fixed the link state 
handling. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99216 
State-Changed-From-To: patched->closed 
State-Changed-By: yongari 
State-Changed-When: Tue Mar 18 02:20:18 UTC 2008 
State-Changed-Why:  
MFC done. Thanks for testing! 

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