Skip to contentSkip to conversation

drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

PATCH New Michael Zaidman 2 participants 5 messages Mar 24, 2009 – Mar 26, 2009 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

In the case when the MIIM_STATUS_LINK is 0 i.e. link is down and this is the situation immediately after power up,
the code of awaiting for auto-negotiation completion now will be executed.

---
 drivers/net/tsec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/tsec.c +1 -1
index 399116f..54279ca 100644
@@ -363,7 +363,7 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
         * (ie - we're capable and it's not done)
         */
        mii_reg = read_phy_reg(priv, MIIM_STATUS);
-       if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+       if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
            && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
                int i = 0;
#1 lore raw

PATCH 1/1 drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

Hi Michael,

Quoted 17 lines · Michael Zaidman

drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

In the case when the MIIM_STATUS_LINK is 0 i.e. link is down and this is the situation immediately after power up,
the code of awaiting for auto-negotiation completion now will be executed.

---
 drivers/net/tsec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/tsec.c +0 -0
index 399116f..54279ca 100644

drivers/net/tsec.c uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) · line 368

Quoted 7 lines
drivers/net/tsec.c +1 -1
@@ -363,7 +363,7 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
         * (ie - we're capable and it's not done)
         */
        mii_reg = read_phy_reg(priv, MIIM_STATUS);
-       if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+       if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
            && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
                int i = 0;

This issue has been brought up once before:
http://lists.denx.de/pipermail/u-boot/2009-February/046829.html

There was some concern about adding delay to the boot process in the case that the primary ethernet port(s) did not achieve link.

There had also been some discussion about performing PHY auto-negotiation in parallel, but this seems like a much larger can of worms.

I had proposed this:
http://lists.denx.de/pipermail/u-boot/2009-February/048489.html

Andy/Ben, any feedback on getting a patch such as Michael's or mine merged in?

Thanks,
Peter

#2 lore raw

PATCH 1/1 drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

Quoted 38 lines · Peter Tyser

Hi Michael,

Quoted 18 lines · Michael Zaidman

drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

In the case when the MIIM_STATUS_LINK is 0 i.e. link is down and this is the situation immediately after power up,
the code of awaiting for auto-negotiation completion now will be executed.

---
?drivers/net/tsec.c | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

drivers/net/tsec.c +0 -0
index 399116f..54279ca 100644
@@ -363,7 +363,7 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
 ? ? ? ? ?* (ie - we're capable and it's not done)
Quoted 6 lines

? ? ? ? ?*/
? ? ? ? mii_reg = read_phy_reg(priv, MIIM_STATUS);
- ? ? ? if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+ ? ? ? if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE) ? ? ? ? ? ? && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
? ? ? ? ? ? ? ? int i = 0;

This issue has been brought up once before:
http://lists.denx.de/pipermail/u-boot/2009-February/046829.html

There was some concern about adding delay to the boot process in the case that the primary ethernet port(s) did not achieve link.

There had also been some discussion about performing PHY auto-negotiation in parallel, but this seems like a much larger can of worms.

Quoted 10 lines

I had proposed this:
http://lists.denx.de/pipermail/u-boot/2009-February/048489.html

Andy/Ben, any feedback on getting a patch such as Michael's or mine merged in?

Thanks,
Peter

Hi Peter,

Thanks for the reference. I found this thread very interesting.

Before I submitted the patch I also wondered if it is possible for the link status to be OK while auto-negotiation has not been completed yet. So I dived into the IEEE-802.3 spec (Clause 28) and figured out that according to the Arbitration state diagram (Figure 28-16) the
auto-negotiation
completed indication is asserted after the link status became OK. It contradicts with Marvell?s 88E1111 phy behavior on my mpc8349 based board where link status OK (register 1.2) always comes at least with 1 tbclk delay after auto-negotiation completion indication (register 1.5).
It probably explains why the delay of 500 ms ?results in faster booting? as stated in the code - without this delay the CPU leaves the routine with MIIM_STATUS_LINK still being in the down state.
By replacing the PHY_BMSR_AUTN_CMP with MIIM_STATUS_LINK in loop exiting condition we eliminate the 500 ms delay.

The spec also specifies auto-negotiation timeout in table 28-9. Its worst case value can be calculated as:

break_link_timer + autoneg_wait_timer + link_fai_inhibit_timer =
1500 ms + 1000 ms + 1000 ms = 3500 ms.

So I reduced the PHY_AUTONEGOTIATE_TIMEOUT to be 4000 ms.

Here is the updated patch

---

drivers/net/tsec.c +0 -0
index 399116f..28e9cc7 100644
@@ -363,12 +363,12 @@ uint mii_parse_sr(uint mii_reg, struct

tsec_private * priv)

         * (ie - we're capable and it's not done)
         */
        mii_reg = read_phy_reg(priv, MIIM_STATUS);
-       if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+       if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
            && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
                int i = 0;

                puts("Waiting for PHY auto negotiation to complete");
-               while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
+               while (!(mii_reg & MIIM_STATUS_LINK)) {
                        /*
                         * Timeout reached ?
                         */
@@ -386,7 +386,6 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
                }
                puts(" done\n");
                priv->link = 1;
-               udelay(500000); /* another 500 ms (results in faster booting) */
        } else {
                if (mii_reg & MIIM_STATUS_LINK)
                        priv->link = 1;
include/tsec.h +1 -1
index 7b52e06..ed4c855 100644
@@ -56,7 +56,7 @@
 #define TSEC_TIMEOUT 1000
 #define TOUT_LOOP      1000000
 
-#define PHY_AUTONEGOTIATE_TIMEOUT      5000 /* in ms */
+#define PHY_AUTONEGOTIATE_TIMEOUT      4000 /* in ms */
 
 /* TBI register addresses */
 #define TBI_CR                 0x00

Thanks,
Michael

#3 lore raw

PATCH 1/1 drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

Hi Michael,

Quoted 19 lines

Hi Peter,

Thanks for the reference. I found this thread very interesting.

Before I submitted the patch I also wondered if it is possible for the link status to be OK while auto-negotiation has not been completed yet. So I dived into the IEEE-802.3 spec (Clause 28) and figured out that according to the Arbitration state diagram (Figure 28-16) the
auto-negotiation
completed indication is asserted after the link status became OK. It contradicts with Marvell?s 88E1111 phy behavior on my mpc8349 based board where link status OK (register 1.2) always comes at least with 1 tbclk delay after auto-negotiation completion indication (register 1.5).
It probably explains why the delay of 500 ms ?results in faster booting? as stated in the code - without this delay the CPU leaves the routine with MIIM_STATUS_LINK still being in the down state.
By replacing the PHY_BMSR_AUTN_CMP with MIIM_STATUS_LINK in loop exiting condition we eliminate the 500 ms delay.

Quoted 5 lines

The spec also specifies auto-negotiation timeout in table 28-9. Its worst case value can be calculated as:

break_link_timer + autoneg_wait_timer + link_fai_inhibit_timer =
1500 ms + 1000 ms + 1000 ms = 3500 ms.

Thanks for the info. Any chance there's a public link to the IEEE spec you're referencing? I've looked for the info you provided relatively hard, it'd be great to finally lay my eyes on something concrete:)

Quoted 13 lines

So I reduced the PHY_AUTONEGOTIATE_TIMEOUT to be 4000 ms.

Here is the updated patch

---

drivers/net/tsec.c +0 -0
index 399116f..28e9cc7 100644
@@ -363,12 +363,12 @@ uint mii_parse_sr(uint mii_reg, struct
 tsec_private * priv)
         * (ie - we're capable and it's not done)

drivers/net/tsec.c uint mii_parse_sr(uint mii_reg, struct · line 372

Quoted 10 lines
drivers/net/tsec.c +2 -2
         */
        mii_reg = read_phy_reg(priv, MIIM_STATUS);
-       if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+       if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
            && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
                int i = 0;
 
                puts("Waiting for PHY auto negotiation to complete");
-               while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
+               while (!(mii_reg & MIIM_STATUS_LINK)) {

Won't this be a problem for PHYs which do adhere to the spec you mentioned above? If a PHY has achieved link, but auto-negotiation hasn't completed, we'll return from this function with auto-negotiation still not complete, which doesn't seem right. According to the spec, we shouldn't leave this loop until auto-negotiation is done.

It sounds like the reason that my original patch doesn't work for you is due to the fact that the 88e1111 PHY doesn't adhere to the spec as far as the ordering of "link up" and "auto-negotation complete"? If that's the case, perhaps we should either wait for both link up and auto-negotiation to complete, or the 88e1111 (or Marvel PHYs in general) should have its own mii_parse_sr()?

drivers/net/tsec.c uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) · line 389

Quoted 8 lines
drivers/net/tsec.c +0 -0
                        /*
                         * Timeout reached ?
                         */
drivers/net/tsec.c +0 -1
@@ -386,7 +386,6 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
                }
                puts(" done\n");
                priv->link = 1;
-               udelay(500000); /* another 500 ms (results in faster booting) */

Agreed that it would be great to get rid of this "magic" delay.

include/tsec.h line 59

Quoted 13 lines
drivers/net/tsec.c +0 -0
        } else {
                if (mii_reg & MIIM_STATUS_LINK)
                        priv->link = 1;
include/tsec.h +1 -1
index 7b52e06..ed4c855 100644
@@ -56,7 +56,7 @@
 #define TSEC_TIMEOUT 1000
 #define TOUT_LOOP      1000000
 
-#define PHY_AUTONEGOTIATE_TIMEOUT      5000 /* in ms */
+#define PHY_AUTONEGOTIATE_TIMEOUT      4000 /* in ms */

I'd vote for breaking this out into a separate patch with an explanation from the IEEE spec you referenced above.

Best,
Peter

#4 lore raw

PATCH 1/1 drivers/net/tsec.c - mii_parse_sr does not wait for auto-negotiation completion bug fix

Hi Peter,

Quoted 23 lines · Peter Tyser

Hi Michael,

Quoted 22 lines

Hi Peter,

Thanks for the reference. I found this thread very interesting.

? ? Before I submitted the patch I also wondered if it is possible for ? ? the link status to be OK while auto-negotiation has not been completed yet. ? ? So I dived into the IEEE-802.3 spec (Clause 28) and figured out that ? ? according to the Arbitration state diagram (Figure 28-16) the auto-negotiation
? ? completed indication is asserted after the link status became OK. ? ? It contradicts with Marvell?s 88E1111 phy behavior on my mpc8349 based board ? ? where link status OK (register 1.2) always comes at least with 1 tbclk delay ? ? after auto-negotiation completion indication (register 1.5).
? ? It probably explains why the delay of 500 ms ?results in faster booting? ? ? as stated in the code - without this delay the CPU leaves the routine with ? ? MIIM_STATUS_LINK still being in the down state.
? ? By replacing the PHY_BMSR_AUTN_CMP with MIIM_STATUS_LINK in loop exiting ? ? condition we eliminate the 500 ms delay.

? ? The spec also specifies auto-negotiation timeout in table 28-9. ? ? Its worst case value can be calculated as:

Quoted 6 lines
Quoted 2 lines

? ? break_link_timer + autoneg_wait_timer + link_fai_inhibit_timer = ? ? ? ? 1500 ms + 1000 ms + 1000 ms = 3500 ms.

Thanks for the info. ?Any chance there's a public link to the IEEE spec you're referencing? ?I've looked for the info you provided relatively hard, it'd be great to finally lay my eyes on something concrete:)

Sure, you can download it from http://standards.ieee.org/getieee802/802.3.html
All auto-negotiation stuff is located in the "IEEE 802.3-2005 -- Section Two"

Quoted 21 lines
Quoted 21 lines

? ? So I reduced the PHY_AUTONEGOTIATE_TIMEOUT to be 4000 ms.

? ? Here is the updated patch

---

drivers/net/tsec.c +0 -0
index 399116f..28e9cc7 100644
@@ -363,12 +363,12 @@ uint mii_parse_sr(uint mii_reg, struct
 tsec_private * priv)
 ? ? ? ? ?* (ie - we're capable and it's not done)

? ? ? ? ?*/
? ? ? ? mii_reg = read_phy_reg(priv, MIIM_STATUS);
- ? ? ? if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
+ ? ? ? if (!(mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE) ? ? ? ? ? ? && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
? ? ? ? ? ? ? ? int i = 0;

Quoted 8 lines
Quoted 3 lines

? ? ? ? ? ? ? ? puts("Waiting for PHY auto negotiation to complete");
- ? ? ? ? ? ? ? while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
+ ? ? ? ? ? ? ? while (!(mii_reg & MIIM_STATUS_LINK)) {

Won't this be a problem for PHYs which do adhere to the spec you mentioned above? ?If a PHY has achieved link, but auto-negotiation hasn't completed, we'll return from this function with auto-negotiation still not complete, which doesn't seem right.

I am not sure if this is the possible situation.
As I understand the auto-negotiation process is prerequisite for the link state assignment.
And generally both indications should come closely coupled. Probably I miss-interpreted
the link_status primitive in the state diagram. It gets three values - FAIL, READY and OK,
whereas the Link status bit in the Status register (1.2) gets UP and Down. And timing
relationships between them are unclear. (See Figure 24?15 Link Monitor state diagram)

Quoted 2 lines

?According to the spec, we
shouldn't leave this loop until auto-negotiation is done.

We are interesting in the link status. This is what the routine returns. The link status UP indicates that a valid link is established and reliable reception of signals transmitted from the remote PHY is possible.

Quoted 4 lines

It sounds like the reason that my original patch doesn't work for you is due to the fact that the 88e1111 PHY doesn't adhere to the spec as far as the ordering of "link up" and "auto-negotation complete"?

I assume it would work also. I just did not try it because I was not aware about it. :-)

Quoted 3 lines

If that's the case, perhaps we should either wait for both link up and auto-negotiation to complete, or the 88e1111 (or Marvel PHYs in general) should have its own mii_parse_sr()?

It will be interesting to know an assertion order of link up and auto-negotiation
to complete for another PHY.

Quoted 23 lines

drivers/net/tsec.c uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) · line 389

Quoted 9 lines

? ? ? ? ? ? ? ? ? ? ? ? /*
? ? ? ? ? ? ? ? ? ? ? ? ?* Timeout reached ?
? ? ? ? ? ? ? ? ? ? ? ? ?*/

drivers/net/tsec.c +0 -1
@@ -386,7 +386,6 @@ uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
 ? ? ? ? ? ? ? ? }
 ? ? ? ? ? ? ? ? puts(" done\n");
 ? ? ? ? ? ? ? ? priv->link = 1;
- ? ? ? ? ? ? ? udelay(500000); /* another 500 ms (results in faster booting) */

Agreed that it would be great to get rid of this "magic" delay.

Quoted 11 lines
drivers/net/tsec.c +0 -0
 ? ? ? ? } else {
 ? ? ? ? ? ? ? ? if (mii_reg & MIIM_STATUS_LINK)
 ? ? ? ? ? ? ? ? ? ? ? ? priv->link = 1;
include/tsec.h +0 -0
index 7b52e06..ed4c855 100644
@@ -56,7 +56,7 @@

?#define TSEC_TIMEOUT 1000
?#define TOUT_LOOP ? ? ?1000000

Quoted 5 lines

include/tsec.h

Quoted 2 lines
include/tsec.h +1 -1
-#define PHY_AUTONEGOTIATE_TIMEOUT ? ? ?5000 /* in ms */
+#define PHY_AUTONEGOTIATE_TIMEOUT ? ? ?4000 /* in ms */

I'd vote for breaking this out into a separate patch with an explanation from the IEEE spec you referenced above.

Agree.

Quoted 6 lines

Best,
Peter

Thanks,
Michael