Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jan 2004 13:35:17 -0800 (PST)
From:      Tim Draegen-Gilman <tim@eudaemon.net>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/61448: RealTek driver (rl) fails to adjust TX threshold on TX underrun
Message-ID:  <200401162135.i0GLZHAh036043@www.freebsd.org>
Resent-Message-ID: <200401162140.i0GLe6X5004502@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         61448
>Category:       kern
>Synopsis:       RealTek driver (rl) fails to adjust TX threshold on TX underrun
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 16 13:40:05 PST 2004
>Closed-Date:
>Last-Modified:
>Originator:     Tim Draegen-Gilman
>Release:        4.8
>Organization:
Vernier Networks, Inc.
>Environment:
FreeBSD 4.8-RELEASE i386
>Description:
The rl driver fails to properly detect the TX underflow condition.  This stems from a RealTek documentation ambiguity.  This failure to detect TX underflow leads to the driver never being able to increase the TX threshold, which causes the NIC to (over time)
continue to underflow.  This results in malformed packets appearing on the wire.
>How-To-Repeat:
1.  Get yourself a RealTek 8139-based NIC.
2.  Connect your NIC to a Cisco Switch
3.  Watch as the Cisco reports CRC errors.
4.  CRC errors exactly match unaddressed TX underflow condition from RealTek chip.
>Fix:
The follwing patch corrects this problem.  It adds comments, deals with the
underflow condition while processing a "TX_OK" bit (this is the documentation
flaw -- underflow and OK are both set at the same time), increases the Tx threshold
step from 32 to 64, adds a sanity check to provide a TX threshold ceiling, and
avoids reset/init cycle of the chip on out-put error (this is a bit heavy handed).
The two debug printfs can be removed (but are necessary to show that the
"underrun" and "OK" bits are both set at the same time).

Index: freebsd/sys/pci/if_rl.c
===================================================================
RCS file: /home/cvs/ambit2/freebsd/sys/pci/if_rl.c,v
retrieving revision 1.4
diff -u -r1.4 if_rl.c
--- freebsd/sys/pci/if_rl.c     20 Jun 2003 04:24:31 -0000      1.4
+++ freebsd/sys/pci/if_rl.c     16 Jan 2004 02:36:51 -0000
@@ -1209,36 +1209,48 @@
         * frames that have been uploaded.
         */
        do {
+               /* Grab the TX status */
                txstat = CSR_READ_4(sc, RL_LAST_TXSTAT(sc));
+
+               /* Only deal with OK, Underrun, and Abort conditions */
                if (!(txstat & (RL_TXSTAT_TX_OK|
                    RL_TXSTAT_TX_UNDERRUN|RL_TXSTAT_TXABRT)))
                        break;
 
-               ifp->if_collisions += (txstat & RL_TXSTAT_COLLCNT) >> 24;
-
+               /* Free up memory */
                if (RL_LAST_TXMBUF(sc) != NULL) {
                        m_freem(RL_LAST_TXMBUF(sc));
                        RL_LAST_TXMBUF(sc) = NULL;
                }
-               if (txstat & RL_TXSTAT_TX_OK)
-                       ifp->if_opackets++;
-               else {
-                       int                     oldthresh;
+
+               /* Deal with abort/out-of-window condition */
+               if (txstat & (RL_TXSTAT_OUTOFWIN | RL_TXSTAT_TXABRT)) {
                        ifp->if_oerrors++;
-                       if ((txstat & RL_TXSTAT_TXABRT) ||
-                           (txstat & RL_TXSTAT_OUTOFWIN))
-                               CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CONFIG);
-                       oldthresh = sc->rl_txthresh;
-                       /* error recovery */
-                       rl_reset(sc);
-                       rl_init(sc);
+
+       printf("rl_txeof error: TSR is %x\n", txstat);
+
+                       /* If abort-condition, clear the abort */
+                       if (txstat & RL_TXSTAT_TXABRT) {
+                               CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CLRABRT);
+                       }
+               } else {
+                       ifp->if_opackets++;
+
                        /*
-                        * If there was a transmit underrun,
-                        * bump the TX threshold.
+                        * Update the RX threshold if underrun is reported.
+                        * Datasheet says threshold must be between 000001 and
+                        * 111111 inclusive.  We start at 000011 (96).
                         */
-                       if (txstat & RL_TXSTAT_TX_UNDERRUN)
-                               sc->rl_txthresh = oldthresh + 32;
-                       return;
+                       if ((txstat & RL_TXSTAT_TX_UNDERRUN) &&
+                           (sc->rl_txthresh < 2016)) {
+                               sc->rl_txthresh += 64;
+       printf("rl_txeof underrun: TSR is %x, txthresh now %d\n", txstat,
+           sc->rl_txthresh);
+                       }
+
+                       /* Update collision count, if any */
+                       ifp->if_collisions +=
+                           (txstat & RL_TXSTAT_COLLCNT) >> 24;
                }
                RL_INC(sc->rl_cdata.last_tx);
                ifp->if_flags &= ~IFF_OACTIVE;

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401162135.i0GLZHAh036043>