Subject: [PATCH 2.6.12-rc5 3/9] tg3: Add link test

From: "Michael Chan" <[email-masked]>
Date: Thu, 26 May 2005 10:57:20 -0700

Signed-off-by: Michael Chan <[email-masked]>
diff -Nru d2/drivers/net/tg3.c d3/drivers/net/tg3.c
--- d2/drivers/net/tg3.c	2005-05-25 12:59:00.000000000 -0700
+++ d3/drivers/net/tg3.c	2005-05-25 12:59:09.000000000 -0700
@@ -7281,6 +7281,32 @@
 	return err;
 }
 
+#define TG3_SERDES_TIMEOUT_SEC	2
+#define TG3_COPPER_TIMEOUT_SEC	6
+
+static int tg3_test_link(struct tg3 *tp)
+{
+	int i, max;
+
+	if (!netif_running(tp->dev))
+		return -ENODEV;
+
+	if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
+		max = TG3_SERDES_TIMEOUT_SEC;
+	else
+		max = TG3_COPPER_TIMEOUT_SEC;
+
+	for (i = 0; i < max; i++) {
+		if (netif_carrier_ok(tp->dev))
+			return 0;
+
+		if (msleep_interruptible(1000))
+			break;
+	}
+
+	return -EIO;
+}
+
 static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
 			  u64 *data)
 {
@@ -7292,6 +7318,10 @@
 		etest->flags |= ETH_TEST_FL_FAILED;
 		data[0] = 1;
 	}
+	if (tg3_test_link(tp) != 0) {
+		etest->flags |= ETH_TEST_FL_FAILED;
+		data[1] = 1;
+	}
 }
 
 static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)