From nobody@FreeBSD.org  Fri Jul 28 20:28:05 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B342416A4E1
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 28 Jul 2006 20:28:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9D29843D66
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 28 Jul 2006 20:28:00 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k6SKS0Gj092040
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 28 Jul 2006 20:28:00 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k6SKS03q092039;
	Fri, 28 Jul 2006 20:28:00 GMT
	(envelope-from nobody)
Message-Id: <200607282028.k6SKS03q092039@www.freebsd.org>
Date: Fri, 28 Jul 2006 20:28:00 GMT
From: Doug Havir <rally@nbs-inc.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: I may have found a subtle bug in the "em" driver in relase 6.1 - duplex/collision mismatch
X-Send-Pr-Version: www-2.3

>Number:         101000
>Category:       kern
>Synopsis:       [em] I may have found a subtle bug in the "em" driver in relase 6.1 - duplex/collision mismatch
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 28 20:30:25 GMT 2006
>Closed-Date:    Mon Aug 28 09:25:50 GMT 2006
>Last-Modified:  Mon Aug 28 09:25:50 GMT 2006
>Originator:     Doug Havir
>Release:        i386 release 6.1
>Organization:
National Bankcard Services, Inc.
>Environment:
FreeBSD bsd.nbs 6.1-RELEASE FreeBSD 6.1-RELEASE #2: Mon Jul 10 09:56:35 CDT 2006     user@bsd.nbs:/usr/obj/usr/src/sys/QNXKERNEL  i386
>Description:
In the file dev/em/if_em_hw.h, which is part of the Intel 825xx ethernet driver, the defines for DUPLEX are as follows:
#define HALF_DUPLEX 1
#define FULL_DUPLEX 2

In the file dev/em/if_em.c the message printed at the end of the em_attach()
call is:

printf("em%d:  Speed:%d Mbps  Duplex:%s\n", adapter->unit, adapter->link_speed,
              adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half");

Given that the code reads right, and nobody has complained about the
message being wrong, one might assume the definitions for FULL and HALF
duplex are correct.  BUT THEN,

In the file dev/em/if_em.c, function em_initialize_transmit_unit(struct adapter * adapter),
line 2396-2400:
if (adapter->link_duplex == 1) {
    reg_tctl |= E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
} else {
    reg_tctl |= E1000_HDX_COLLISION_DISTANCE << E1000_COLD_SHIFT;
}

Correct me if I'm wrong, but what that really says is if link_duplex ==
HALF_DUPLEX then set the collision distance to the full duplex setting.
At least one of the two usages are incorrect.

I figured I'd point it out just in case it actually has a meaningful impact.
Could it possibly explain some of the half duplex workaround stuff in here?
One can only hope....
>How-To-Repeat:
Lookie at the source code.
>Fix:
1) Use the define for FULL_DUPLEX or HALF_DUPLEX instead of "1"
2) Make sure the effects of the if/else match whichever duplex definition
   you choose
3) Spend copious free time seeing if it has any effect on performance or
   reliability :-)

Best regards,
-Doug

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Aug 11 13:38:45 UTC 2006 
Responsible-Changed-Why:  
I will look into this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=101000 
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Mon Aug 14 09:44:01 UTC 2006 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=101000 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Mon Aug 28 09:25:39 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

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