Skip to contentSkip to conversation

mii: Add test for GigE support

PATCH Applied Dale Farnsworth 3 participants 7 messages Mar 22, 2005 – Aug 22, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mii: Add test for GigE support

This patch adds the ability to test a PHY for GigE support

drivers/net/mii.c +15 -0
Index: linux-2.5-enet/drivers/net/mii.c
===================================================================
@@ -207,6 +207,21 @@
 	return 0;
 }
 
+int mii_check_gmii_support(struct mii_if_info *mii)
+{
+	int reg;
+
+	reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+	if (reg & BMSR_HAS_EXTSTAT1000) {
+		reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
+		if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
+			   ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+			return 1;
+	}
+
+	return 0;
+}
+
 int mii_link_ok (struct mii_if_info *mii)
 {
 	/* first, a dummy read, needed to latch some MII phys */
include/linux/mii.h +10 -1
Index: linux-2.5-enet/include/linux/mii.h
===================================================================
@@ -22,6 +22,7 @@
 #define MII_EXPANSION       0x06        /* Expansion register          */
 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
+#define MII_EXTSTAT1000     0x0f	/* 1000BASE-XX extended status */
 #define MII_DCOUNTER        0x12        /* Disconnect counter          */
 #define MII_FCSCOUNTER      0x13        /* False carrier counter       */
 #define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
@@ -54,7 +55,8 @@
 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
 #define BMSR_RFAULT             0x0010  /* Remote fault detected       */
 #define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
-#define BMSR_RESV               0x07c0  /* Unused...                   */
+#define BMSR_HAS_EXTSTAT1000    0x0100  /* Has 1000BASE extended status*/
+#define BMSR_RESV               0x06c0  /* Unused...                   */
 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
@@ -121,6 +123,12 @@
 #define LPA_1000FULL            0x0800  /* Link partner 1000BASE-T full duplex */
 #define LPA_1000HALF            0x0400  /* Link partner 1000BASE-T half duplex */
 
+/* 1000BASE Ext Status register */
+#define ESR_1000_BASE_X_FD      0x8000
+#define ESR_1000_BASE_X_HD      0x4000
+#define ESR_1000_BASE_T_FD      0x2000
+#define ESR_1000_BASE_T_HD      0x1000
+
 struct mii_if_info {
 	int phy_id;
 	int advertising;
@@ -143,6 +151,7 @@
 extern int mii_nway_restart (struct mii_if_info *mii);
 extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
 extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
+extern int mii_check_gmii_support(struct mii_if_info *mii);
 extern void mii_check_link (struct mii_if_info *mii);
 extern unsigned int mii_check_media (struct mii_if_info *mii,
 				     unsigned int ok_to_print,
#1 lore raw
Quoted 15 lines · Dale Farnsworth

This patch adds the ability to test a PHY for GigE support

Index: linux-2.5-enet/drivers/net/mii.c
===================================================================

drivers/net/mii.c +3 -0
@@ -207,6 +207,21 @@
 	return 0;
 }
 
+int mii_check_gmii_support(struct mii_if_info *mii)
+{
+	int reg;

drivers/net/mii.c line 222

Quoted 10 lines
drivers/net/mii.c +10 -0
+
+	reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+	if (reg & BMSR_HAS_EXTSTAT1000) {
+		reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
+		if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
+			   ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+			return 1;
+	}
+
+	return 0;

Two comments:

1) you need to add EXPORT_SYMBOL() when adding new API functions (see the bottom of the file).

2) Reading a non-existent register will return all 1's in most cases, so I am not sure if this is the best test.

Jeff

#2 lore raw
Quoted 7 lines · Jeff Garzik
Quoted 7 lines

+int mii_check_gmii_support(struct mii_if_info *mii)

drivers/net/mii.c +6 -0
+{
+	int reg;
+
+	reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+	if (reg & BMSR_HAS_EXTSTAT1000) {
+		reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
Quoted 8 lines

drivers/net/mii.c line 222

Quoted 6 lines
drivers/net/mii.c +6 -0
+		if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
+			   ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+			return 1;
+	}
+
+	return 0;

2) Reading a non-existent register will return all 1's in most cases, so I am not sure if this is the best test.

He reads a standard register (BMSR) to determine whether or not EXTSTAT1000 exists. This is part of the 802.3 standard, so it should work.

Andy

Andy Fleming

#3 lore raw
Quoted 21 lines · Andy Fleming
Quoted 8 lines · Jeff Garzik
Quoted 8 lines

+int mii_check_gmii_support(struct mii_if_info *mii)

drivers/net/mii.c +7 -0
+{
+    int reg;
+
+    reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+    if (reg & BMSR_HAS_EXTSTAT1000) {
+        reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
+        if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
Quoted 8 lines

drivers/net/mii.c line 222

Quoted 5 lines
drivers/net/mii.c +5 -0
+               ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+            return 1;
+    }
+
+    return 0;

2) Reading a non-existent register will return all 1's in most cases, so I am not sure if this is the best test.

Quoted 1 line

He reads a standard register (BMSR) to determine whether or not EXTSTAT1000 exists. This is part of the 802.3 standard, so it should work.

Whoops, I read the patch incorrectly, and thought he read an extended register.

Objection removed. Still need an EXPORT_SYMBOL() though.

Jeff

#4 lore raw
drivers/net/mii.c +16 -0
Index: linux-2.5-enet/drivers/net/mii.c
===================================================================
@@ -207,6 +207,21 @@
 	return 0;
 }
 
+int mii_check_gmii_support(struct mii_if_info *mii)
+{
+	int reg;
+
+	reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+	if (reg & BMSR_HAS_EXTSTAT1000) {
+		reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
+		if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
+			   ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+			return 1;
+	}
+
+	return 0;
+}
+
 int mii_link_ok (struct mii_if_info *mii)
 {
 	/* first, a dummy read, needed to latch some MII phys */
@@ -394,5 +409,6 @@
 EXPORT_SYMBOL(mii_ethtool_sset);
 EXPORT_SYMBOL(mii_check_link);
 EXPORT_SYMBOL(mii_check_media);
+EXPORT_SYMBOL(mii_check_gmii_support);
 EXPORT_SYMBOL(generic_mii_ioctl);
 
include/linux/mii.h +10 -1
Index: linux-2.5-enet/include/linux/mii.h
===================================================================
@@ -22,6 +22,7 @@
 #define MII_EXPANSION       0x06        /* Expansion register          */
 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
+#define MII_EXTSTAT1000     0x0f	/* 1000BASE-XX extended status */
 #define MII_DCOUNTER        0x12        /* Disconnect counter          */
 #define MII_FCSCOUNTER      0x13        /* False carrier counter       */
 #define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
@@ -54,7 +55,8 @@
 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
 #define BMSR_RFAULT             0x0010  /* Remote fault detected       */
 #define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
-#define BMSR_RESV               0x07c0  /* Unused...                   */
+#define BMSR_HAS_EXTSTAT1000    0x0100  /* Has 1000BASE extended status*/
+#define BMSR_RESV               0x06c0  /* Unused...                   */
 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
@@ -121,6 +123,12 @@
 #define LPA_1000FULL            0x0800  /* Link partner 1000BASE-T full duplex */
 #define LPA_1000HALF            0x0400  /* Link partner 1000BASE-T half duplex */
 
+/* 1000BASE Ext Status register */
+#define ESR_1000_BASE_X_FD      0x8000
+#define ESR_1000_BASE_X_HD      0x4000
+#define ESR_1000_BASE_T_FD      0x2000
+#define ESR_1000_BASE_T_HD      0x1000
+
 struct mii_if_info {
 	int phy_id;
 	int advertising;
@@ -143,6 +151,7 @@
 extern int mii_nway_restart (struct mii_if_info *mii);
 extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
 extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
+extern int mii_check_gmii_support(struct mii_if_info *mii);
 extern void mii_check_link (struct mii_if_info *mii);
 extern unsigned int mii_check_media (struct mii_if_info *mii,
 				     unsigned int ok_to_print,
#6 lore raw

PATCH 1/1 mii: Add test for GigE support

In reply to Dale Farnsworth

[This patch was submitted on 22Mar2005 and jgarzik said, "applied, thanks", but it may have been lost in the git transition. I've updated it to current offsets.]

drivers/net/mii.c +16 -0
Index: netdev-2.6-mv643xx-enet/drivers/net/mii.c
===================================================================
@@ -207,6 +207,21 @@
 	return 0;
 }
 
+int mii_check_gmii_support(struct mii_if_info *mii)
+{
+	int reg;
+
+	reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
+	if (reg & BMSR_HAS_EXTSTAT1000) {
+		reg = mii->mdio_read(mii->dev, mii->phy_id, MII_EXTSTAT1000);
+		if (reg & (ESR_1000_BASE_X_FD | ESR_1000_BASE_T_FD |
+			   ESR_1000_BASE_X_HD | ESR_1000_BASE_T_HD))
+			return 1;
+	}
+
+	return 0;
+}
+
 int mii_link_ok (struct mii_if_info *mii)
 {
 	/* first, a dummy read, needed to latch some MII phys */
@@ -394,5 +409,6 @@
 EXPORT_SYMBOL(mii_ethtool_sset);
 EXPORT_SYMBOL(mii_check_link);
 EXPORT_SYMBOL(mii_check_media);
+EXPORT_SYMBOL(mii_check_gmii_support);
 EXPORT_SYMBOL(generic_mii_ioctl);
 
include/linux/mii.h +10 -1
Index: netdev-2.6-mv643xx-enet/include/linux/mii.h
===================================================================
@@ -22,6 +22,7 @@
 #define MII_EXPANSION       0x06        /* Expansion register          */
 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
+#define MII_EXTSTAT1000     0x0f	/* 1000BASE-XX extended status */
 #define MII_DCOUNTER        0x12        /* Disconnect counter          */
 #define MII_FCSCOUNTER      0x13        /* False carrier counter       */
 #define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
@@ -54,7 +55,8 @@
 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
 #define BMSR_RFAULT             0x0010  /* Remote fault detected       */
 #define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
-#define BMSR_RESV               0x07c0  /* Unused...                   */
+#define BMSR_HAS_EXTSTAT1000    0x0100  /* Has 1000BASE extended status*/
+#define BMSR_RESV               0x06c0  /* Unused...                   */
 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
@@ -129,6 +131,12 @@
 #define LPA_1000FULL            0x0800  /* Link partner 1000BASE-T full duplex */
 #define LPA_1000HALF            0x0400  /* Link partner 1000BASE-T half duplex */
 
+/* 1000BASE Ext Status register */
+#define ESR_1000_BASE_X_FD      0x8000
+#define ESR_1000_BASE_X_HD      0x4000
+#define ESR_1000_BASE_T_FD      0x2000
+#define ESR_1000_BASE_T_HD      0x1000
+
 struct mii_if_info {
 	int phy_id;
 	int advertising;
@@ -151,6 +159,7 @@
 extern int mii_nway_restart (struct mii_if_info *mii);
 extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
 extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd);
+extern int mii_check_gmii_support(struct mii_if_info *mii);
 extern void mii_check_link (struct mii_if_info *mii);
 extern unsigned int mii_check_media (struct mii_if_info *mii,
 				     unsigned int ok_to_print,