Subject: kern/8382: MII based real 21140's fail under new tlp driver
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dave@dtsp.co.nz>
List: netbsd-bugs
Date: 09/12/1999 07:44:56
>Number:         8382
>Category:       kern
>Synopsis:       MII based real 21140's fail under new tlp driver
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 12 07:05:01 1999
>Last-Modified:
>Originator:     Dave Sainty
>Organization:
Dynamic Technology Services and Products Ltd (NZ)
>Release:        19990912
>Environment:
>Description:
	The new driver support for PHYs on the SIO on a real DEC 21140 (and
	others) is incorrect.  The main problem is that the direction bit is
	generally inverted, but also the timing seems to be slightly incorrect
	based on the DP83840 data sheets.

>How-To-Repeat:
	Hack around on the new driver.  Frown as the driver appears to have no
	knowledge of the cards PHY.

>Fix:
	Apply this patch, after which the driver correctly detects my nsphy
	and in fact the network card becomes functional!  (relies on other
	changes not included here, and the extent of the functionalty is not
	well tested)

--- tulip.c.orig	Sun Sep 12 13:35:56 1999
+++ tulip.c	Mon Sep 13 01:22:37 1999
@@ -2349,7 +2349,7 @@
 	u_int32_t miirom;
 	int i;
 
-	miirom = MIIROM_MIIDIR|MIIROM_MDO;
+	miirom = MIIROM_MDO;
 
 	MII_EMIT(sc, miirom);
 	for (i = 0; i < 32; i++) {
@@ -2371,7 +2371,7 @@
 {
 	u_int32_t miirom, i;
 
-	miirom = MIIROM_MIIDIR;
+	miirom = 0;
 	MII_EMIT(sc, miirom);
 
 	for (i = 1 << (nbits - 1); i != 0; i >>= 1) {
@@ -2405,25 +2405,27 @@
 	tlp_sio_mii_sendbits(sc, phy, 5);
 	tlp_sio_mii_sendbits(sc, reg, 5);
 
-	MII_EMIT(sc, MIIROM_MIIDIR);
-	MII_EMIT(sc, MIIROM_MIIDIR|MIIROM_MDC);
+	MII_EMIT(sc, MIIROM_MIIDIR); /* Direction is input, no clock transition */
 
-	MII_EMIT(sc, 0);
-	MII_EMIT(sc, MIIROM_MDC);
+	MII_EMIT(sc, MIIROM_MIIDIR|MIIROM_MDC);
+	MII_EMIT(sc, MIIROM_MIIDIR);
 
 	err = TULIP_ISSET(sc, CSR_MIIROM, MIIROM_MDI);
 
-	MII_EMIT(sc, 0);
-	MII_EMIT(sc, MIIROM_MDC);
+	MII_EMIT(sc, MIIROM_MIIDIR|MIIROM_MDC);
+	MII_EMIT(sc, MIIROM_MIIDIR);
 
 	for (i = 0; i < 16; i++) {
 		val <<= 1;
-		MII_EMIT(sc, 0);
+		/* Read data prior to clock low-high transition */
 		if (err == 0 && TULIP_ISSET(sc, CSR_MIIROM, MIIROM_MDI))
 			val |= 1;
-		MII_EMIT(sc, MIIROM_MDC);
+
+		MII_EMIT(sc, MIIROM_MIIDIR|MIIROM_MDC);
+		MII_EMIT(sc, MIIROM_MIIDIR);
 	}
 
+	/* Direction is output, no clock transition */
 	MII_EMIT(sc, 0);
 
 	return (err ? 0 : val);
>Audit-Trail:
>Unformatted:
System: NetBSD tequila.dave.dtsp.co.nz 1.4K NetBSD 1.4K (TEQUILA) #6: Sat Sep 4 14:24:13 NZST 1999 dave@tequila.dave.dtsp.co.nz:/vol/tequila/userB/u2/NetBSD-current/src/sys/arch/i386/compile/TEQUILA i386