Subject: Re: re(4) causes stuck in boot
To: None <F.Lorenzen@gmx.de>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: current-users
Date: 01/28/2007 11:58:54
I wrote:

> F.Lorenzen@gmx.de wrote:

> > For me as programming novice it looks like there is a Problem reading
> > data from the Card/the Eprom.
 :
> How about the attached one? (untested though)

Hmm, it seems EEPROM on 8169S requires more delay.
How about this one? (tested on 8169S and 8139C, but not on 8139C-plus)
---
Izumi Tsutsui


Index: rtl8169.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl8169.c,v
retrieving revision 1.76
diff -u -r1.76 rtl8169.c
--- rtl8169.c	26 Dec 2006 13:45:43 -0000	1.76
+++ rtl8169.c	28 Jan 2007 02:43:20 -0000
@@ -574,6 +574,20 @@
 	/* Reset the adapter. */
 	re_reset(sc);
 
+	if (rtk_read_eeprom(sc, RTK_EE_ID, RTK_EEADDR_LEN1) == 0x8129)
+		addr_len = RTK_EEADDR_LEN1;
+	else
+		addr_len = RTK_EEADDR_LEN0;
+
+	/*
+	 * Get station address from the EEPROM.
+	 */
+	for (i = 0; i < 3; i++) {
+		val = rtk_read_eeprom(sc, RTK_EE_EADDR0 + i, addr_len);
+		eaddr[(i * 2) + 0] = val & 0xff;
+		eaddr[(i * 2) + 1] = val >> 8;
+	}
+
 	if (sc->rtk_type == RTK_8169) {
 		uint32_t hwrev;
 
@@ -589,46 +603,11 @@
 			sc->sc_rev = 1;
 
 		/* Set RX length mask */
-
 		sc->re_rxlenmask = RE_RDESC_STAT_GFRAGLEN;
-
-		/* Force station address autoload from the EEPROM */
-
-		CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_AUTOLOAD);
-		for (i = 0; i < RTK_TIMEOUT; i++) {
-			if ((CSR_READ_1(sc, RTK_EECMD) & RTK_EEMODE_AUTOLOAD)
-			    == 0)
-				break;
-			DELAY(100);
-		}
-		if (i == RTK_TIMEOUT)
-			aprint_error("%s: eeprom autoload timed out\n",
-			    sc->sc_dev.dv_xname);
-
-		for (i = 0; i < ETHER_ADDR_LEN; i++)
-			eaddr[i] = CSR_READ_1(sc, RTK_IDR0 + i);
-
 		sc->re_ldata.re_tx_desc_cnt = RE_TX_DESC_CNT_8169;
 	} else {
-
 		/* Set RX length mask */
-
 		sc->re_rxlenmask = RE_RDESC_STAT_FRAGLEN;
-
-		if (rtk_read_eeprom(sc, RTK_EE_ID, RTK_EEADDR_LEN1) == 0x8129)
-			addr_len = RTK_EEADDR_LEN1;
-		else
-			addr_len = RTK_EEADDR_LEN0;
-
-		/*
-		 * Get station address from the EEPROM.
-		 */
-		for (i = 0; i < 3; i++) {
-			val = rtk_read_eeprom(sc, RTK_EE_EADDR0 + i, addr_len);
-			eaddr[(i * 2) + 0] = val & 0xff;
-			eaddr[(i * 2) + 1] = val >> 8;
-		}
-
 		sc->re_ldata.re_tx_desc_cnt = RE_TX_DESC_CNT_8139;
 	}
 
Index: rtl81x9.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9.c,v
retrieving revision 1.66
diff -u -r1.66 rtl81x9.c
--- rtl81x9.c	16 Nov 2006 01:32:52 -0000	1.66
+++ rtl81x9.c	28 Jan 2007 02:43:21 -0000
@@ -169,6 +169,8 @@
 	CSR_WRITE_1(sc, RTK_EECMD,			\
 		CSR_READ_1(sc, RTK_EECMD) & ~(x))
 
+#define EE_DELAY()	DELAY(100)
+
 #define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
 
 /*
@@ -190,11 +192,11 @@
 		} else {
 			EE_CLR(RTK_EE_DATAIN);
 		}
-		DELAY(4);
+		EE_DELAY();
 		EE_SET(RTK_EE_CLK);
-		DELAY(4);
+		EE_DELAY();
 		EE_CLR(RTK_EE_CLK);
-		DELAY(4);
+		EE_DELAY();
 	}
 }
 
@@ -208,26 +210,26 @@
 	int i;
 
 	/* Enter EEPROM access mode. */
-	CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_PROGRAM|RTK_EE_SEL);
+	CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_PROGRAM);
+	EE_DELAY();
+	EE_SET(RTK_EE_SEL);
 
 	/*
 	 * Send address of word we want to read.
 	 */
 	rtk_eeprom_putbyte(sc, addr, addr_len);
 
-	CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_PROGRAM|RTK_EE_SEL);
-
 	/*
 	 * Start reading bits from EEPROM.
 	 */
 	word = 0;
 	for (i = 16; i > 0; i--) {
 		EE_SET(RTK_EE_CLK);
-		DELAY(4);
+		EE_DELAY();
 		if (CSR_READ_1(sc, RTK_EECMD) & RTK_EE_DATAOUT)
 			word |= 1 << (i - 1);
 		EE_CLR(RTK_EE_CLK);
-		DELAY(4);
+		EE_DELAY();
 	}
 
 	/* Turn off EEPROM access mode. */