[PATCH] tulip 21143 MII media selection bugs

Eric D. Seppanen sepp@primenet.com
Mon Mar 1 13:02:10 1999


Hello all.  I've been poking around with the media selection in the tulip
driver and have found some... unusual behavior:  (1) when an MII media is
forced by the user, some 21143 registers are set up improperly, and (2)
when MII media selection is changed and the autonegotiation advertisement
is altered, autonegotiation is not restarted, when IMHO it should be.  If
anybody's interested in this I've included a patch which fixes this on my
board (21143-TD on motherboard with MII transceiver).

The first part of the patch (line numbers starting at 800) tries to take
care of (2) above, and the second part (line numbers around 1300) tries to
fix (1) above.

Disclaimer: I don't have a clue what I'm doing and this code is horribly
bug-ridden. ;) Use it at your own risk.

Eric Seppanen

--- tulip.c	Fri Feb 26 16:34:40 1999
+++ tulip.eds2	Mon Mar  1 10:08:50 1999
@@ -809,6 +809,7 @@
 		   but takes much time. */
 		for (phy = 0, phy_idx = 0; phy < 32 && phy_idx < sizeof(tp->phys);
 			 phy++) {
+		 	int mii_restart_neg = 0;
 			int mii_status = mdio_read(dev, phy, 1);
 			if (mii_status != 0xffff  &&  mii_status != 0x0000) {
 				int mii_reg0 = mdio_read(dev, phy, 0);
@@ -825,11 +826,13 @@
 						   " previously advertising %4.4x.\n",
 						   dev->name, reg4, phy, mii_advert);
 					mdio_write(dev, phy, 4, reg4);
+					mii_restart_neg=0x200;
 				}
 				/* Enable autonegotiation: some boards default to off. */
 				mdio_write(dev, phy, 0, mii_reg0 |
 						   (tp->full_duplex ? 0x1100 : 0x1000) |
-						   (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0));
+						   (media_cap[tp->default_port]&MediaIs100 ? 0x2000:0) |
+						   mii_restart_neg);
 			}
 		}
 		tp->mii_cnt = phy_idx;
@@ -1375,8 +1378,12 @@
 
 	tp->csr6 = 0;
 	tp->cur_index = i;
-	if (dev->if_port == 0  &&  tp->chip_id == DC21142) {
-		if (tp->mii_cnt) {
+	if (tp->chip_id == DC21142) {
+		
+		// use MII if one is present and:
+		//   a) there is no default port or
+		//   b) the user selected an MII media type
+		if ((tp->mii_cnt) && ((!dev->if_port) || (media_cap[dev->if_port] & MediaIsMII))) {
 			if (tulip_debug > 1)
 				printk(KERN_INFO "%s: Using MII transceiver %d, status "
 					   "%4.4x.\n",