703-net-emac-fix-reset-timeout-with-AR8035-phy.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From b2e79053e7456a961249c8865214a1e95b49c863 Mon Sep 17 00:00:00 2001
  2. From: Christian Lamparter <[email protected]>
  3. Date: Sat, 3 Jun 2017 18:16:19 +0200
  4. Subject: [PATCH] net: emac: fix reset timeout with AR8035 phy
  5. This patch fixes a problem where the AR8035 PHY can't be
  6. detected on an Cisco Meraki MR24, if the ethernet cable is
  7. not connected on boot.
  8. Russell Senior provided steps to reproduce the issue:
  9. |Disconnect ethernet cable, apply power, wait until device has booted,
  10. |plug in ethernet, check for interfaces, no eth0 is listed.
  11. |
  12. |This appears to be a problem during probing of the AR8035 Phy chip.
  13. |When ethernet has no link, the phy detection fails, and eth0 is not
  14. |created. Plugging ethernet later has no effect, because there is no
  15. |interface as far as the kernel is concerned. The relevant part of
  16. |the boot log looks like this:
  17. |this is the failing case:
  18. |
  19. |[ 0.876611] /plb/opb/emac-rgmii@ef601500: input 0 in RGMII mode
  20. |[ 0.882532] /plb/opb/ethernet@ef600c00: reset timeout
  21. |[ 0.888546] /plb/opb/ethernet@ef600c00: can't find PHY!
  22. |and the succeeding case:
  23. |
  24. |[ 0.876672] /plb/opb/emac-rgmii@ef601500: input 0 in RGMII mode
  25. |[ 0.883952] eth0: EMAC-0 /plb/opb/ethernet@ef600c00, MAC 00:01:..
  26. |[ 0.890822] eth0: found Atheros 8035 Gigabit Ethernet PHY (0x01)
  27. Based on the comment and the commit message of
  28. commit 23fbb5a87c56 ("emac: Fix EMAC soft reset on 460EX/GT").
  29. This is because the AR8035 PHY doesn't provide the TX Clock,
  30. if the ethernet cable is not attached. This causes the reset
  31. to timeout and the PHY detection code in emac_init_phy() is
  32. unable to detect the AR8035 PHY. As a result, the emac driver
  33. bails out early and the user left with no ethernet.
  34. In order to stay compatible with existing configurations, the driver
  35. tries the current reset approach at first. Only if the first attempt
  36. timed out, it does perform one more retry with the clock input
  37. temporarily switched to the internal clock source for just the
  38. duration of the reset.
  39. LEDE-Bug: #687 <https://bugs.lede-project.org/index.php?do=details&task_id=687>
  40. Cc: Chris Blake <[email protected]>
  41. Reported-by: Russell Senior <[email protected]>
  42. Fixes: 23fbb5a87c56e98 ("emac: Fix EMAC soft reset on 460EX/GT")
  43. Reviewed-by: Andrew Lunn <[email protected]>
  44. Signed-off-by: Christian Lamparter <[email protected]>
  45. ---
  46. drivers/net/ethernet/ibm/emac/core.c | 26 ++++++++++++++++++++++----
  47. 1 file changed, 22 insertions(+), 4 deletions(-)
  48. --- a/drivers/net/ethernet/ibm/emac/core.c
  49. +++ b/drivers/net/ethernet/ibm/emac/core.c
  50. @@ -352,6 +352,7 @@ static int emac_reset(struct emac_instan
  51. {
  52. struct emac_regs __iomem *p = dev->emacp;
  53. int n = 20;
  54. + bool __maybe_unused try_internal_clock = false;
  55. DBG(dev, "reset" NL);
  56. @@ -364,6 +365,7 @@ static int emac_reset(struct emac_instan
  57. }
  58. #ifdef CONFIG_PPC_DCR_NATIVE
  59. +do_retry:
  60. /*
  61. * PPC460EX/GT Embedded Processor Advanced User's Manual
  62. * section 28.10.1 Mode Register 0 (EMACx_MR0) states:
  63. @@ -371,10 +373,19 @@ static int emac_reset(struct emac_instan
  64. * of the EMAC. If none is present, select the internal clock
  65. * (SDR0_ETH_CFG[EMACx_PHY_CLK] = 1).
  66. * After a soft reset, select the external clock.
  67. + *
  68. + * The AR8035-A PHY Meraki MR24 does not provide a TX Clk if the
  69. + * ethernet cable is not attached. This causes the reset to timeout
  70. + * and the PHY detection code in emac_init_phy() is unable to
  71. + * communicate and detect the AR8035-A PHY. As a result, the emac
  72. + * driver bails out early and the user has no ethernet.
  73. + * In order to stay compatible with existing configurations, the
  74. + * driver will temporarily switch to the internal clock, after
  75. + * the first reset fails.
  76. */
  77. if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) {
  78. - if (dev->phy_address == 0xffffffff &&
  79. - dev->phy_map == 0xffffffff) {
  80. + if (try_internal_clock || (dev->phy_address == 0xffffffff &&
  81. + dev->phy_map == 0xffffffff)) {
  82. /* No PHY: select internal loop clock before reset */
  83. dcri_clrset(SDR0, SDR0_ETH_CFG,
  84. 0, SDR0_ETH_CFG_ECS << dev->cell_index);
  85. @@ -392,8 +403,15 @@ static int emac_reset(struct emac_instan
  86. #ifdef CONFIG_PPC_DCR_NATIVE
  87. if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) {
  88. - if (dev->phy_address == 0xffffffff &&
  89. - dev->phy_map == 0xffffffff) {
  90. + if (!n && !try_internal_clock) {
  91. + /* first attempt has timed out. */
  92. + n = 20;
  93. + try_internal_clock = true;
  94. + goto do_retry;
  95. + }
  96. +
  97. + if (try_internal_clock || (dev->phy_address == 0xffffffff &&
  98. + dev->phy_map == 0xffffffff)) {
  99. /* No PHY: restore external clock source after reset */
  100. dcri_clrset(SDR0, SDR0_ETH_CFG,
  101. SDR0_ETH_CFG_ECS << dev->cell_index, 0);