Subject: Problem rtk driver with 1.5W
To: None <current-users@netbsd.org>
From: Masanori Kanaoka <kanaoka@ann.hi-ho.ne.jp>
List: current-users
Date: 07/24/2001 19:08:44
Hi,

I usually use rtk CardBus with NetBSD-current(1.5)/i386.
I find the problem when I put a big file(48M) via ftp.

rtk0 at cardbus1 dev 0 function 0: Corega FEther CB-TXD 10/100BaseTX
rtk0: Ethernet address 00:90:99:48:51:f5
ukphy0 at rtk0 phy 7: Generic IEEE 802.3u media interface
ukphy0: OUI 0x000000, model 0x0000, rev. 0
ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
boot device: wd0
root on wd0a dumps on wd0b
root file system type: ffs
rtk0: interrupting at 11
rtk0: watchdog timeout
rtk0: watchdog timeout

[kana@kana1]% netstat -ni | grep rtk
rtk0  1500  <Link>        00:90:99:48:51:f5     1608     0     3136    23     0
rtk0  1500  192.168.1     192.168.1.5           1608     0     3136    23     0
rtk0  1500  fe80::/64     fe80::290:99ff:fe     1608     0     3136    23     0

It seemed that Underrun error occurred.
Referring Linux driver and tlp driver,I tried to make next patch.
Next patch seemed fix this problem.

I think Initial early TX threshold may be bigger than 256 bytes.

Any comments.
Regards!
---
 Masanori Kanaoka	kanaoka@ann.hi-ho.ne.jp

Index: sys/dev/ic/rtl81x9.c
===================================================================
RCS file: /ftp/cvs/syssrc/sys/dev/ic/rtl81x9.c,v
retrieving revision 1.35
diff -u -r1.35 rtl81x9.c
--- sys/dev/ic/rtl81x9.c	2001/07/19 16:25:26	1.35
+++ sys/dev/ic/rtl81x9.c	2001/07/24 09:09:48
@@ -704,6 +704,9 @@
 	 */
 	sc->sc_flags |= RTK_ATTACHED;
 
+	/* Init Early TX threshold. */
+	sc->sc_txthresh = TXTH_256; 
+
 	/* Reset the adapter. */
 	rtk_reset(sc);
 
@@ -1190,6 +1193,14 @@
 			ifp->if_opackets++;
 		else {
 			ifp->if_oerrors++;
+
+			/*
+			 * Increase Early TX threshold if underrun occurred.
+			 * Increase step 64 bytes.
+			 */
+			if ((txstat & RTK_TXSTAT_TX_UNDERRUN) &&
+				(sc->sc_txthresh < TXTH_MAX))
+				sc->sc_txthresh += 2;
 			if (txstat & (RTK_TXSTAT_TXABRT|RTK_TXSTAT_OUTOFWIN))
 				CSR_WRITE_4(sc, RTK_TXCFG, RTK_TXCFG_CONFIG);
 		}
@@ -1334,7 +1345,7 @@
 
 		CSR_WRITE_4(sc, txd->txd_txaddr,
 		    txd->txd_dmamap->dm_segs[0].ds_addr);
-		CSR_WRITE_4(sc, txd->txd_txstat, RTK_TX_EARLYTHRESH | len);
+		CSR_WRITE_4(sc, txd->txd_txstat, RTK_TX_THRESH(sc) | len);
 	}
 
 	/*
@@ -1379,6 +1390,8 @@
 	/* Init TX descriptors. */
 	rtk_list_tx_init(sc);
 
+	/* Init Early TX threshold. */
+	sc->sc_txthresh = TXTH_256;
 	/*
 	 * Enable transmit and receive.
 	 */
Index: sys/dev/ic/rtl81x9var.h
===================================================================
RCS file: /ftp/cvs/syssrc/sys/dev/ic/rtl81x9var.h,v
retrieving revision 1.9
diff -u -r1.9 rtl81x9var.h
--- sys/dev/ic/rtl81x9var.h	2001/02/02 04:34:19	1.9
+++ sys/dev/ic/rtl81x9var.h	2001/07/24 08:33:54
@@ -92,6 +92,8 @@
 	SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_dirty;
 
 	int			sc_flags;	/* misc flags */
+	int			sc_txthresh;	/* Early tx threshold */
+
 	void	*sc_sdhook;			/* shutdown hook */
 	void	*sc_powerhook;			/* power management hook */
 
@@ -105,6 +107,11 @@
 #define RTK_ENABLED  0x00000002 /* chip is enabled	*/
 
 #define RTK_IS_ENABLED(sc)	((sc)->sc_flags & RTK_ENABLED)
+#define RTK_TX_THRESH(sc)	(((sc)->sc_txthresh << 16) & 0x003F0000)
+
+#define TXTH_256	8
+#define TXTH_MAX	48
+
 /*
  * register space access macros
  */