From nobody@FreeBSD.org  Fri Apr 27 12:06:17 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id A34B916A406
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Apr 2007 12:06:17 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 96D4113C459
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Apr 2007 12:06:17 +0000 (UTC)
	(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 l3RC6HC0074759
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Apr 2007 12:06:17 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l3RC1GPk074150;
	Fri, 27 Apr 2007 12:01:16 GMT
	(envelope-from nobody)
Message-Id: <200704271201.l3RC1GPk074150@www.freebsd.org>
Date: Fri, 27 Apr 2007 12:01:16 GMT
From: Mark Willson<mark@hydrus.org.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sis driver for natsemi DP83815D autonegotiate failure
X-Send-Pr-Version: www-3.0

>Number:         112179
>Category:       kern
>Synopsis:       [sis] [patch] sis driver for natsemi DP83815D autonegotiate failure
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 27 12:10:08 GMT 2007
>Closed-Date:    Tue Aug 19 21:24:01 UTC 2008
>Last-Modified:  Tue Aug 19 21:24:01 UTC 2008
>Originator:     Mark Willson
>Release:        6.2 Release
>Organization:
>Environment:
FreeBSD crimson 6.2-RELEASE FreeBSD 6.2-RELEASE #23: Fri Apr 27 12:24:50 BST 2007     mark@crimson:/usr/obj/usr/src/sys/CRIMSON  i386
>Description:
The if_sis.c driver for the Natsemi DP38315D chip fails to autonegotiate
properly on a 100baseTX link if the connection breaks for less than 4
seconds.  Ethernet cable is around 5m in length (short cable fix invoked).

The patch below fixes the problem for me.



>How-To-Repeat:
Run sis0 in 100baseTX mode.  Disconnect ethernet cable for less than 4
seconds.  On reconnection, short cable fix reg is 0, and sis0 interface
is non-functional.
>Fix:
Apply the following patch to sys/pci/if_sis.c

--- if_sis.c.orig       Fri Apr 27 12:41:14 2007
+++ if_sis.c    Fri Apr 27 12:41:32 2007
@@ -1909,7 +1909,7 @@
        if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
                CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
                CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
-               if (sc->sis_srr == NS_SRR_15C) {
+               if (sc->sis_srr <= NS_SRR_15D) {
                        /* set val for c2 */
                        CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
                        /* load/kill c2 */


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-i386->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Apr 29 10:05:11 UTC 2007 
Responsible-Changed-Why:  
This does not sound i386-specific. 

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

From: Volker <volker@vwsoft.com>
To: bug-followup@FreeBSD.org, mark@hydrus.org.uk
Cc:  
Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate
 failure
Date: Tue, 12 Feb 2008 22:42:30 +0100

 Mark,
 
 is this problem still valid for you? Can you please check with
 6.3-RELEASE?
 
 This problem _might_ be the same as PR kern/64556
 http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/64556
 
 Nevertheless, without knowing anything about the chipset in question,
 the patch is awful, as it double checks the condition:
 
         if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
 // we're getting here only, if sis_srr is less or equal NS_SRR_15D
 
                 CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
                 CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 -               if (sc->sis_srr == NS_SRR_15C) {
 +               if (sc->sis_srr <= NS_SRR_15D) {
 // and here we're checking for the same value?
 // the piece of code is not reached if sis_srr is > NS_SRR_15D, so
 it's a wasted 'if' construction
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Tue Feb 12 22:57:52 UTC 2008 
State-Changed-Why:  
Note that submitter has been asked for feedback. 

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

From: Mark Willson <mark@hydrus.org.uk>
To: bug-followup@FreeBSD.org, mark@hydrus.org.uk, volker@vwsoft.com
Cc:  
Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate failure
Date: Wed, 13 Feb 2008 16:46:18 GMT

 > Date: Tue, 12 Feb 2008 22:42:30 +0100
 > From: Volker <volker@vwsoft.com>
 > Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate
 >  failure
 >
 > Mark,
 >
 > is this problem still valid for you? Can you please check with
 > 6.3-RELEASE?
 >
 > This problem _might_ be the same as PR kern/64556
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/64556
 >
 > Nevertheless, without knowing anything about the chipset in question,
 > the patch is awful, as it double checks the condition:
 >
 >         if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
 > // we're getting here only, if sis_srr is less or equal NS_SRR_15D
 >
 >                 CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
 >                 CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 > -               if (sc->sis_srr == NS_SRR_15C) {
 > +               if (sc->sis_srr <= NS_SRR_15D) {
 > // and here we're checking for the same value?
 > // the piece of code is not reached if sis_srr is > NS_SRR_15D, so
 > it's a wasted 'if' construction
 >
 
 Volker,
 
 Thanks for your mail.  I'm travelling at the moment and don't have access
 to the machine to try this out until the weekend.  I will provide feedback
 then.
 
 I agree that 112179 might be the same as 64556, but I'm not really
 sure.
 
 And I also agree the patch is lousy; I made the smallest textual
 change compatible with fixing the problem.  Dropping the extra test
 would be much better.  I'm afraid I know nothing about the chip set
 either, the fix was cribbed from the Linux driver.
 
 -mark

From: Mark Willson <mark@hydrus.org.uk>
To: bug-followup@FreeBSD.org, mark@hydrus.org.uk, volker@vwsoft.com
Cc:  
Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate failure
Date: Sat, 16 Feb 2008 13:41:34 GMT

 > Date: Tue, 12 Feb 2008 22:42:30 +0100
 > From: Volker <volker@vwsoft.com>
 > Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate
 >  failure
 >
 > Mark,
 >
 > is this problem still valid for you? Can you please check with
 > 6.3-RELEASE?
 >
 
 Volker,
 
 Following up from my earlier email, I have tested an unpatched
 version of if_sis.c on 6.3-RELEASE and the problem still exists.
 
 Based on your comments re the patch, here's a revised version:
 
 --- sys/pci/if_sis.c
 +++ sys/pci/if_sis.c
 @@ -1895,23 +1895,22 @@
  	}
  
  	/*
 -	 * Short Cable Receive Errors (MP21.E)
 -	 * also: Page 78 of the DP83815 data sheet (september 2002 version)
 -	 * recommends the following register settings "for optimum
 -	 * performance." for rev 15C.  The driver from NS also sets
 -	 * the PHY_CR register for later versions.
 +	 * Short Cable Receive Errors (MP21.E) also: Page 78 of the
 +	 * DP83815 data sheet (september 2002 version) recommends the
 +	 * following register settings "for optimum performance." for rev
 +	 * 15C.  However, the same settings need to be applied to rev 15D
 +	 * to avoid auto-negotiation failures.  The driver from NS also
 +	 * sets the PHY_CR register for later versions.
  	 */
  	if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
  		CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 -		if (sc->sis_srr == NS_SRR_15C) {
 -			/* set val for c2 */
 -			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 -			/* load/kill c2 */
 -			CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 -			/* rais SD off, from 4 to c */
 -			CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
 -		}
 +		/* set val for c2 */
 +		CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 +		/* load/kill c2 */
 +		CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 +		/* rais SD off, from 4 to c */
 +		CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
  	}
  
 -mark
State-Changed-From-To: feedback->open 
State-Changed-By: linimon 
State-Changed-When: Sat Feb 16 14:07:40 UTC 2008 
State-Changed-Why:  
Feedback received. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112179 
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Feb 16 16:04:17 UTC 2008 
Responsible-Changed-Why:  
contains a patch for review, so assign. 

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

From: John Baldwin <jhb@freebsd.org>
To: bug-followup@freebsd.org, mark@hydrus.org.uk
Cc: phk@freebsd.org
Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate failure
Date: Tue, 29 Jul 2008 11:56:38 -0400

 How about the patch below.  This makes the driver match the behavior of the 
 Linux driver (and also fixes a harmless weirdness phk@ introduced.. I think 
 because he thought SIS_SETBIT was CSR_WRITE_4 rather than a RMW op).
 
 Index: if_sis.c
 ===================================================================
 --- if_sis.c	(revision 180877)
 +++ if_sis.c	(working copy)
 @@ -1904,14 +1904,15 @@
  	if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
  		CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 -		if (sc->sis_srr == NS_SRR_15C) {
 -			/* set val for c2 */
 -			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 +		/* set val for c2 */
 +		CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 +		if (sc->sis_srr <= NS_SRR_15C)
  			/* load/kill c2 */
  			CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 -			/* rais SD off, from 4 to c */
 -			CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
 -		}
 +		else
 +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x1000);
 +		/* rais SD off, from 4 to c */
 +		CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
  	}
  
 @@ -2011,12 +2012,11 @@
  		CSR_WRITE_4(sc, NS_PHY_DSPCFG, reg | 0x1000);
  		DELAY(100000);
  		reg = CSR_READ_4(sc, NS_PHY_TDATA) & 0xff;
 -		if ((reg & 0x0080) == 0 || (reg > 0xd8 && reg <= 0xff)) {
 +		if ((reg & 0x0080) == 0 || (reg >= 0xd8 && reg <= 0xff)) {
  			device_printf(sc->sis_dev,
  			    "Applying short cable fix (reg=%x)\n", reg);
  			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x00e8);
 -			reg = CSR_READ_4(sc, NS_PHY_DSPCFG);
 -			SIS_SETBIT(sc, NS_PHY_DSPCFG, reg | 0x20);
 +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x20);
  		}
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
  	}
 
 One other thing the Linux driver does differently than the FreeBSD driver is 
 that it 1) doesn't set 0x1000 in DSPCFG when locking the coeffecient (since 
 it sets it earlier) and 2), it locks the coefficient every time link is 
 established and unlocks it when link is lost.  Doing 2) would require pushing 
 some logic down into the phy driver I think.
 
 -- 
 John Baldwin

From: Mark Willson <mark@hydrus.org.uk>
To: bug-followup@FreeBSD.org, jhb@FreeBSD.org
Cc: phk@FreeBSD.org
Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D autonegotiate failure
Date: Wed, 30 Jul 2008 13:04:59 +0100 (BST)

 > From: John Baldwin <jhb@FreeBSD.org>
 > Subject: Re: kern/112179: [sis] [patch] sis driver for natsemi DP83815D
 > 	autonegotiate failure
 > Date: Tue, 29 Jul 2008 11:56:38 -0400
 > Cc: phk@FreeBSD.org
 >
 > How about the patch below.  This makes the driver match the behavior of the 
 > Linux driver (and also fixes a harmless weirdness phk@ introduced.. I think 
 > because he thought SIS_SETBIT was CSR_WRITE_4 rather than a RMW op).
 >
 > Index: if_sis.c
 > ===================================================================
 > --- if_sis.c	(revision 180877)
 > +++ if_sis.c	(working copy)
 > @@ -1904,14 +1904,15 @@
 >  	if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
 >  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
 >  		CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 > -		if (sc->sis_srr == NS_SRR_15C) {
 > -			/* set val for c2 */
 > -			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 > +		/* set val for c2 */
 > +		CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 > +		if (sc->sis_srr <= NS_SRR_15C)
 >  			/* load/kill c2 */
 >  			CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 > -			/* rais SD off, from 4 to c */
 > -			CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
 > -		}
 > +		else
 > +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x1000);
 > +		/* rais SD off, from 4 to c */
 > +		CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
 >  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
 >  	}
 >  
 > @@ -2011,12 +2012,11 @@
 >  		CSR_WRITE_4(sc, NS_PHY_DSPCFG, reg | 0x1000);
 >  		DELAY(100000);
 >  		reg = CSR_READ_4(sc, NS_PHY_TDATA) & 0xff;
 > -		if ((reg & 0x0080) == 0 || (reg > 0xd8 && reg <= 0xff)) {
 > +		if ((reg & 0x0080) == 0 || (reg >= 0xd8 && reg <= 0xff)) {
 >  			device_printf(sc->sis_dev,
 >  			    "Applying short cable fix (reg=%x)\n", reg);
 >  			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x00e8);
 > -			reg = CSR_READ_4(sc, NS_PHY_DSPCFG);
 > -			SIS_SETBIT(sc, NS_PHY_DSPCFG, reg | 0x20);
 > +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x20);
 >  		}
 >  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
 >  	}
 >
 
 John,
 
 Thanks for the patch.  I tried it out on my system, but it did not fix
 the problem.  However, if I make a small change, it works fine.
 
 It seems the call  "CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);" is
 necessary for the NS_SRR_15D revision of the card.
 
 Here's the modified patch:
 
 --- if_sis.c.orig	2008-07-30 11:04:53.000000000 +0100
 +++ if_sis.c	2008-07-30 11:08:15.000000000 +0100
 @@ -1904,14 +1904,14 @@
  	if (sc->sis_type == SIS_TYPE_83815 && sc->sis_srr <= NS_SRR_15D) {
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001);
  		CSR_WRITE_4(sc, NS_PHY_CR, 0x189C);
 -		if (sc->sis_srr == NS_SRR_15C) {
 -			/* set val for c2 */
 -			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 -			/* load/kill c2 */
 -			CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 -			/* rais SD off, from 4 to c */
 -			CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
 -		}
 +		/* set val for c2 */
 +		CSR_WRITE_4(sc, NS_PHY_TDATA, 0x0000);
 +        /* load/kill c2 */
 +        CSR_WRITE_4(sc, NS_PHY_DSPCFG, 0x5040);
 +		if (sc->sis_srr > NS_SRR_15C)
 +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x1000);
 +		/* rais SD off, from 4 to c */
 +		CSR_WRITE_4(sc, NS_PHY_SDCFG, 0x008C);
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
  	}
  
 @@ -2011,12 +2011,11 @@
  		CSR_WRITE_4(sc, NS_PHY_DSPCFG, reg | 0x1000);
  		DELAY(100000);
  		reg = CSR_READ_4(sc, NS_PHY_TDATA) & 0xff;
 -		if ((reg & 0x0080) == 0 || (reg > 0xd8 && reg <= 0xff)) {
 +		if ((reg & 0x0080) == 0 || (reg >= 0xd8 && reg <= 0xff)) {
  			device_printf(sc->sis_dev,
  			    "Applying short cable fix (reg=%x)\n", reg);
  			CSR_WRITE_4(sc, NS_PHY_TDATA, 0x00e8);
 -			reg = CSR_READ_4(sc, NS_PHY_DSPCFG);
 -			SIS_SETBIT(sc, NS_PHY_DSPCFG, reg | 0x20);
 +			SIS_SETBIT(sc, NS_PHY_DSPCFG, 0x20);
  		}
  		CSR_WRITE_4(sc, NS_PHY_PAGE, 0);
  	}
 
 -mark
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Wed Jul 30 17:31:15 UTC 2008 
State-Changed-Why:  
I've committed the original patch (more or less) and will MFC it in a week 
or so. 


Responsible-Changed-From-To: freebsd-net->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Wed Jul 30 17:31:15 UTC 2008 
Responsible-Changed-Why:  
I've committed the original patch (more or less) and will MFC it in a week 
or so. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/112179: commit references a PR
Date: Wed, 30 Jul 2008 18:23:18 +0000 (UTC)

 jhb         2008-07-30 17:28:49 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/pci              if_sis.c 
   Log:
   SVN rev 181002 on 2008-07-30 17:28:49Z by jhb
   
   Set all of the "optimum performance" PHY registers for the 15D parts as
   well as the 15C since it seems to be required in practice.  The Linux
   natsemi.c driver mostly does this as well.
   
   PR:             kern/112179
   Submitted by:   Mark Willson  mark - hydrus org uk
   MFC after:      1 week
   
   Revision  Changes    Path
   1.152     +8 -10     src/sys/pci/if_sis.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Tue Aug 19 21:23:49 UTC 2008 
State-Changed-Why:  
Fixes MFC'd. 

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