Skip to contentSkip to conversation

Fixes for ULi5261 (tulip driver)

RFC/PATCH Jiri Benc 6 participants 18 messages Apr 27, 2005 – Aug 28, 2006 Network drivers

lore
Share & tools
lore

Jiri Benc

author
#0 lore raw

With integrated ALi/ULi M5261 ethernet controller using tulip driver, autonegotation doesn't work and card is forced to 10 Mbps half-duplex mode.

I found two problems with tulip driver regarding ULi5261.

1. In tulip_up() media selection does not work properly. No media from EEPROM media list is set as default in ULi's EEPROM. In such case tulip driver searches for first non-fullduplex media.

I have no idea why the search is not performed for MII capable media first. Maybe because of problems with some other cards?

EEPROM media list is reported to be as follows:

tulip0:  EEPROM default media type Autosense.
tulip0:  MII interface PHY 1, setup/reset sequences 0/2 long, capabilities 00 01.
tulip0:  Index #0 - Media MII (#11) described by a 21140 MII PHY (1) block.
tulip0:  Index #1 - Media 10baseT (#0) described by a <unknown> (128) block.
tulip0:  Index #2 - Media 10baseT (#0) described by a 21140 non-MII (0) block.
tulip0:  Index #3 - Media 10base2 (#1) described by a 21140 non-MII (0) block.
tulip0:  Index #4 - Media 10baseT-FDX (#4) described by a 21140 non-MII (0) block.
tulip0:  Index #5 - Media 100baseTx-FDX (#5) described by a 21140 non-MII (0) block.

I added code that performs search for MII capable media in case of ULi5261 card. Shouldn't it be performed generally?

2. PHY chip DM9161E used on my M5261 seems to claim (in BMCR register) that autonegotiation is enabled after initialization, but it needs to set BMCR_ANRESTART for autonegotiation to work. Without forcing of restart of autonegotiation, MII_LPA returns always 0.

Is there any way to detect that DM9161E is used? It may be used with another ethernet cards (and there may be another PHY used in M5261 as well), so restarting autonegotiation in case of ULi5261 doesn't seem to be a solution.

The only way I see is to always restart autonegotiation in tulip_find_mii(). It probably has the side-effect that other cards with autonegotiation enabled by default will perform autonegotiation twice.

Thanks for your suggestions.

drivers/net/tulip/media.c +5 -4
@@ -517,10 +517,11 @@ void __devinit tulip_find_mii (struct ne
 		/* Enable autonegotiation: some boards default to off. */
 		if (tp->default_port == 0) {
 			new_bmcr = mii_reg0 | BMCR_ANENABLE;
-			if (new_bmcr != mii_reg0) {
-				new_bmcr |= BMCR_ANRESTART;
-				ane_switch = 1;
-			}
+			/* DM9161E PHY seems to need to restart
+			 * autonegotiation even if it defaults to enabled.
+			 */
+			new_bmcr |= BMCR_ANRESTART;
+			ane_switch = 1;
 		}
 		/* ...or disable nway, if forcing media */
 		else {
drivers/net/tulip/tulip_core.c +5 -0
@@ -383,6 +383,11 @@ static void tulip_up(struct net_device *
 				goto media_picked;
 			}
 	}
+	if (tp->chip_id == ULI526X) {
+		for (i = tp->mtable->leafcount - 1; i >= 0; i--)
+			if (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaIsMII)
+				goto media_picked;
+	}
 	/* Start sensing first non-full-duplex media. */
 	for (i = tp->mtable->leafcount - 1;
 		 (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)

--
Jiri Benc
SUSE Labs

#1 lore raw

Hi!

Recently I had similar problems as you described below, that's how I found your email. (My exact problem is that there's no link when I plug in a cable, reloading the driver a few times usually helps.) The problem is, that since you made the patch, the uli526x driver has been split out from the tulip driver.
Do you know anything about the current state of the uli526x driver regarding the problems you tried patch?

Thanks in advance,
Balazs Pozsar

Quoted 85 lines · Jiri Benc

With integrated ALi/ULi M5261 ethernet controller using tulip driver, autonegotation doesn't work and card is forced to 10 Mbps half-duplex mode.

I found two problems with tulip driver regarding ULi5261.

1. In tulip_up() media selection does not work properly. No media from EEPROM media list is set as default in ULi's EEPROM. In such case tulip driver searches for first non-fullduplex media.

I have no idea why the search is not performed for MII capable media first. Maybe because of problems with some other cards?

EEPROM media list is reported to be as follows:

tulip0:  EEPROM default media type Autosense.
tulip0:  MII interface PHY 1, setup/reset sequences 0/2 long, capabilities 00 01.
tulip0:  Index #0 - Media MII (#11) described by a 21140 MII PHY (1) block.
tulip0:  Index #1 - Media 10baseT (#0) described by a <unknown> (128) block.
tulip0:  Index #2 - Media 10baseT (#0) described by a 21140 non-MII (0) block.
tulip0:  Index #3 - Media 10base2 (#1) described by a 21140 non-MII (0) block.
tulip0:  Index #4 - Media 10baseT-FDX (#4) described by a 21140 non-MII (0) block.
tulip0:  Index #5 - Media 100baseTx-FDX (#5) described by a 21140 non-MII (0) block.

I added code that performs search for MII capable media in case of ULi5261 card. Shouldn't it be performed generally?

2. PHY chip DM9161E used on my M5261 seems to claim (in BMCR register) that autonegotiation is enabled after initialization, but it needs to set BMCR_ANRESTART for autonegotiation to work. Without forcing of restart of autonegotiation, MII_LPA returns always 0.

Is there any way to detect that DM9161E is used? It may be used with another ethernet cards (and there may be another PHY used in M5261 as well), so restarting autonegotiation in case of ULi5261 doesn't seem to be a solution.

The only way I see is to always restart autonegotiation in tulip_find_mii(). It probably has the side-effect that other cards with autonegotiation enabled by default will perform autonegotiation twice.

Thanks for your suggestions.

drivers/net/tulip/media.c +5 -4
@@ -517,10 +517,11 @@ void __devinit tulip_find_mii (struct ne
 		/* Enable autonegotiation: some boards default to off. */
 		if (tp->default_port == 0) {
 			new_bmcr = mii_reg0 | BMCR_ANENABLE;
-			if (new_bmcr != mii_reg0) {
-				new_bmcr |= BMCR_ANRESTART;
-				ane_switch = 1;
-			}
+			/* DM9161E PHY seems to need to restart
+			 * autonegotiation even if it defaults to enabled.
+			 */
+			new_bmcr |= BMCR_ANRESTART;
+			ane_switch = 1;
 		}
 		/* ...or disable nway, if forcing media */
 		else {
drivers/net/tulip/tulip_core.c +5 -1
@@ -383,6 +383,11 @@ static void tulip_up(struct net_device *
 				goto media_picked;
 			}
 	}
+	if (tp->chip_id == ULI526X) {
+		for (i = tp->mtable->leafcount - 1; i >= 0; i--)
+			if (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaIsMII)
+				goto media_picked;
+	}
 	/* Start sensing first non-full-duplex media. */
 	for (i = tp->mtable->leafcount - 1;
 		 (tulip_media_cap[tp->mtable->mleaf[i].media] & MediaAlwaysFD) && i > 0; i--)
 
 
--

Jiri Benc
SUSE Labs
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
pozsy
author
#2 lore raw
Quoted 7 lines · Pozsar Balazs

Recently I had similar problems as you described below, that's how I found your email. (My exact problem is that there's no link when I plug in a cable, reloading the driver a few times usually helps.) The problem is, that since you made the patch, the uli526x driver has been split out from the tulip driver.
Do you know anything about the current state of the uli526x driver regarding the problems you tried patch?

I use the card with new (split out) uli526x driver with no problem. Your problems are probably unrelated.

Jiri

Signature · 2 lines
Jiri Benc
SUSE Labs
#3 lore raw
Quoted 11 lines · Jiri Benc
Quoted 7 lines · Pozsar Balazs

Recently I had similar problems as you described below, that's how I found your email. (My exact problem is that there's no link when I plug in a cable, reloading the driver a few times usually helps.) The problem is, that since you made the patch, the uli526x driver has been split out from the tulip driver.
Do you know anything about the current state of the uli526x driver regarding the problems you tried patch?

I use the card with new (split out) uli526x driver with no problem. Your problems are probably unrelated.

So, just to make it clear: if you boot without cable plugged in, let the driver load, and then plug the cable in, do you have link? For me, it does not have link until I rmmod the module.

Do you have any idea what the problem could be, or could I send you any info that would help debug it?

Thanks,

Signature · 1 line
pozsy
#4 lore raw

Am Mittwoch 16 August 2006 19:43 schrieb Pozsar Balazs:

Quoted 10 lines · Jiri Benc
Quoted 9 lines · Pozsar Balazs
Quoted 7 lines

Recently I had similar problems as you described below, that's how I found your email. (My exact problem is that there's no link when I plug in a cable, reloading the driver a few times usually helps.) The problem is, that since you made the patch, the uli526x driver has been split out from the tulip driver.
Do you know anything about the current state of the uli526x driver regarding the problems you tried patch?

Quoted 6 lines
Quoted 2 lines

I use the card with new (split out) uli526x driver with no problem. Your problems are probably unrelated.

So, just to make it clear: if you boot without cable plugged in, let the driver load, and then plug the cable in, do you have link? For me, it does not have link until I rmmod the module.

Same here.

Quoted 2 lines

Do you have any idea what the problem could be, or could I send you any info that would help debug it?

I actually played a bit with the code and what fails is uli526x_sense_speed in that way that phy_mode & 024 is 0 (and stays 0). But I don't understand why...

Signature · 3 lines
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V
#5 lore raw
Quoted 11 lines · Prakash Punnoor

Am Mittwoch 16 August 2006 19:43 schrieb Pozsar Balazs:

Quoted 10 lines · Jiri Benc
Quoted 9 lines · Pozsar Balazs
Quoted 7 lines

Recently I had similar problems as you described below, that's how I found your email. (My exact problem is that there's no link when I plug in a cable, reloading the driver a few times usually helps.) The problem is, that since you made the patch, the uli526x driver has been split out from the tulip driver.
Do you know anything about the current state of the uli526x driver regarding the problems you tried patch?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I use the card with new (split out) uli526x driver with no problem. Your problems are probably unrelated.

So, just to make it clear: if you boot without cable plugged in, let the driver load, and then plug the cable in, do you have link? For me, it does not have link until I rmmod the module.

Same here.

The most weird thing is that, when I _rmmod_ the module, the link leds will show a link, _before_ I even re-modprobe it! So somehow the removal (or even an unbind via the sysfs interface) "resets" it.

Quoted 6 lines
Quoted 2 lines

Do you have any idea what the problem could be, or could I send you any info that would help debug it?

I actually played a bit with the code and what fails is uli526x_sense_speed in that way that phy_mode & 024 is 0 (and stays 0). But I don't understand why...

I made the same discovery. According to mii.h bit 0x20 would mean "Auto-negotiation complete" and bit 0x04 would mean "Link status".

Signature · 1 line
pozsy
#6 lore raw
Quoted 7 lines · Pozsar Balazs
Quoted 6 lines · Prakash Punnoor

Am Mittwoch 16 August 2006 19:43 schrieb Pozsar Balazs:

Quoted 3 lines

So, just to make it clear: if you boot without cable plugged in, let the driver load, and then plug the cable in, do you have link? For me, it does not have link until I rmmod the module.

Quoted 5 lines
Quoted 1 line

Same here.

The most weird thing is that, when I _rmmod_ the module, the link leds will show a link, _before_ I even re-modprobe it! So somehow the removal (or even an unbind via the sysfs interface) "resets" it.

Hey folks,

Added to my to-do list. Let me know if you figure out anything else.

-VAL

#7 lore raw
Quoted 10 lines · Valerie Henson
Quoted 9 lines · Pozsar Balazs
Quoted 7 lines · Prakash Punnoor

Am Mittwoch 16 August 2006 19:43 schrieb Pozsar Balazs:

Quoted 3 lines

So, just to make it clear: if you boot without cable plugged in, let the driver load, and then plug the cable in, do you have link? For me, it does not have link until I rmmod the module.

Same here.

Quoted 7 lines
Quoted 3 lines

The most weird thing is that, when I _rmmod_ the module, the link leds will show a link, _before_ I even re-modprobe it! So somehow the removal (or even an unbind via the sysfs interface) "resets" it.

Hey folks,

Added to my to-do list. Let me know if you figure out anything else.

Actually, I managed to fix it, here's the patch:

drivers/net/tulip/uli526x.c +2 -1
@@ -515,7 +515,8 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000)
+		udelay(500);
 
 	/* Process Phyxcer Media Mode */
 	uli526x_set_phyxcer(db);
Signature · 1 line
pozsy
#8 lore raw

drivers/net/tulip/uli526x.c line 519

Quoted 9 lines · Pozsar Balazs
drivers/net/tulip/uli526x.c +2 -1
@@ -515,7 +515,8 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000)
+		udelay(500);

You never want an infinite loop in a driver. If, for example, the hardware is wedged or removed, registers will return all 1's, leading this loop to never end.

Jeff

#9 lore raw
Quoted 14 lines · Jeff Garzik

drivers/net/tulip/uli526x.c line 519

Quoted 9 lines · Pozsar Balazs
drivers/net/tulip/uli526x.c +2 -1
@@ -515,7 +515,8 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000)
+		udelay(500);

You never want an infinite loop in a driver. If, for example, the hardware is wedged or removed, registers will return all 1's, leading this loop to never end.

Does this seem better?

Fix uli526x initialization

drivers/net/tulip/uli526x.c +6 -1
@@ -486,6 +486,7 @@
 	u8	phy_tmp;
 	u16	phy_value;
 	u16 phy_reg_reset;
+	int resetwait = 10;
 
 	ULI526X_DBUG(0, "uli526x_init()", 0);
 
@@ -515,7 +516,11 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (resetwait-- > 0) {
+		if (!(phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000))
+			break;
+		udelay(500);
+	}
 
 	/* Process Phyxcer Media Mode */
 	uli526x_set_phyxcer(db);
Signature · 1 line
pozsy
#10 lore raw

Hi Pozsar,

Quoted 21 lines · Pozsar Balazs

Does this seem better?

Fix uli526x initialization

drivers/net/tulip/uli526x.c +1 -0
@@ -486,6 +486,7 @@
 	u8	phy_tmp;
 	u16	phy_value;
 	u16 phy_reg_reset;
+	int resetwait = 10;
 
 	ULI526X_DBUG(0, "uli526x_init()", 0);
 
@@ -515,7 +516,11 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);

drivers/net/tulip/uli526x.c line 526

Quoted 10 lines
drivers/net/tulip/uli526x.c +5 -1
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (resetwait-- > 0) {
+		if (!(phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000))
+			break;
+		udelay(500);
+	}
 
 	/* Process Phyxcer Media Mode */
 	uli526x_set_phyxcer(db);

Thanks for writing up this patch. udelay(500) seems a touch heavyweight, however. Would you mind experimenting a bit to see what the delay typically ends up being? Just add a KERN_DEBUG message printing out resetwait and then fiddle with the udelay granularity.

-VAL

#11 lore raw
Quoted 32 lines · Valerie Henson

Hi Pozsar,

Quoted 29 lines · Pozsar Balazs

Does this seem better?

Fix uli526x initialization

drivers/net/tulip/uli526x.c +6 -1
@@ -486,6 +486,7 @@
 	u8	phy_tmp;
 	u16	phy_value;
 	u16 phy_reg_reset;
+	int resetwait = 10;
 
 	ULI526X_DBUG(0, "uli526x_init()", 0);
 
@@ -515,7 +516,11 @@
 	phy_reg_reset = phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id);
 	phy_reg_reset = (phy_reg_reset | 0x8000);
 	phy_write(db->ioaddr, db->phy_addr, 0, phy_reg_reset, db->chip_id);
-	udelay(500);
+	while (resetwait-- > 0) {
+		if (!(phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000))
+			break;
+		udelay(500);
+	}
 
Quoted 5 lines

drivers/net/tulip/uli526x.c line 526

Quoted 2 lines
drivers/net/tulip/uli526x.c +0 -0
 	/* Process Phyxcer Media Mode */
 	uli526x_set_phyxcer(db);

Thanks for writing up this patch. udelay(500) seems a touch heavyweight, however.

I don't really understand, 500 microsec is really not that much time...

Quoted 3 lines

Would you mind experimenting a bit to see what
the delay typically ends up being? Just add a KERN_DEBUG message printing out resetwait and then fiddle with the udelay granularity.

The funny thing is that it seems the _first_ phy_read call always returns only when the 0x8000 bit is gone (I got this while loop from the xircom_tulip driver).
I didn't have time yet to test how long it takes without the phy_read to make it work (ie if we would only raise udelay(500) to some bigger value).

Signature · 1 line
pozsy
#12 lore raw
Quoted 4 lines · Pozsar Balazs

The funny thing is that it seems the _first_ phy_read call always returns only when the 0x8000 bit is gone (I got this while loop from the xircom_tulip driver).

That's pretty much the answer I was suspecting. Sounds like the read is doing some sort of flush. Unfortunately I can't find any docs, so I'd rather keep things as close to the old code as possible to avoid breaking other cards. Does something like this also work?

	udelay(500); /* Paranoia - phy_read() may be sufficient */
	if (phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000)
		printk("some useful error message");

-VAL

#13 lore raw

Hi.

Quoted 6 lines · Valerie Henson
Quoted 4 lines · Pozsar Balazs

The funny thing is that it seems the _first_ phy_read call always returns only when the 0x8000 bit is gone (I got this while loop from the xircom_tulip driver).

Quoted 9 lines

That's pretty much the answer I was suspecting. Sounds like the read is doing some sort of flush. Unfortunately I can't find any docs, so I'd rather keep things as close to the old code as possible to avoid breaking other cards. Does something like this also work?

	udelay(500); /* Paranoia - phy_read() may be sufficient */
	if (phy_read(db->ioaddr, db->phy_addr, 0, db->chip_id) & 0x8000)
		printk("some useful error message");

I got docs from uli earlier in the year, I just never got around to using them to the extent I intended, and then I switched to working wirelessly most of the time. I didn't have to sign an NDA to get the PDF, so it should be okay for me to distribute it, right? If that's the case, then assuming LKML won't take a PDF, I'll reply again after giving people time to tell me I'm wrong, removing LKML and giving everyone directly emailed a copy (it's not huge).

Regards,

Nigel

#14 lore raw
In reply to Valerie Henson

Hi everyone.

I looked again at the PDF before sending it, and it does say "Preliminary, Confidential, Proprietary" in the header. I therefore also checked again all the email I received from Peer, and he made no mention of it having that status. I thought I'd mention that though: someone might see that too and have concerns.

To help clarify before I send it, I've added Peer to the ccs now so that he can at least have the opportunity to have input.

Peer: I don't know if you'll have seen the rest of the conversation, so let me fill you in: I never got the opportunity to finish the work on adding power management support, and other people are doing work on the driver now. Is it alright for me to forward the PDF datasheet you gave to me?)

Regards,

Nigel

#15 lore raw
In reply to Valerie Henson

Am Samstag 19 August 2006 02:16 schrieb Valerie Henson:

Quoted 3 lines

Hey folks,

Added to my to-do list. Let me know if you figure out anything else.

As it comes back to my mind: Last time I tested dhcpcd doesn't work. dhclient does, but takes a lot of time. (The dhcp server is debian based.) Other cards don't have a problem. They get their ip assigned fast and with either dhcpocd or dhclient.

Signature · 3 lines
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V
#16 lore raw
Quoted 9 lines · Prakash Punnoor

Am Samstag 19 August 2006 02:16 schrieb Valerie Henson:

Quoted 3 lines

Hey folks,

Added to my to-do list. Let me know if you figure out anything else.

As it comes back to my mind: Last time I tested dhcpcd doesn't work. dhclient does, but takes a lot of time. (The dhcp server is debian based.) Other cards don't have a problem. They get their ip assigned fast and with either dhcpocd or dhclient.

Tcpdump on client and server, please?

-VAL

#17 lore raw

Am Donnerstag 24 August 2006 19:23 schrieb Valerie Henson:

Quoted 12 lines · Prakash Punnoor
Quoted 9 lines

Am Samstag 19 August 2006 02:16 schrieb Valerie Henson:

Quoted 3 lines

Hey folks,

Added to my to-do list. Let me know if you figure out anything else.

As it comes back to my mind: Last time I tested dhcpcd doesn't work. dhclient does, but takes a lot of time. (The dhcp server is debian based.) Other cards don't have a problem. They get their ip assigned fast and with either dhcpocd or dhclient.

Tcpdump on client and server, please?

Hi, I couldn't try earlier. Since I noticed the server generates a very big log in short time, so I think the irrelevant infos should be filtered out - it is simply to big to post. As I never used tcpdump, could you give me an example how to accomplish this?

Thx,

Signature · 3 lines
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V