404-NET-bcm63xx_enet-move-phy_-dis-connect-into-probe-re.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. From b11218c750ab92cfab4408a0328f1b36ceec3f33 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jonas.gorski@gmail.com>
  3. Date: Fri, 6 Jan 2012 12:24:18 +0100
  4. Subject: [PATCH 19/63] NET: bcm63xx_enet: move phy_(dis)connect into probe/remove
  5. Only connect/disconnect the phy during probe and remove, not during any
  6. open/close. The phy seldom changes during the runtime, and disconnecting
  7. the phy during close will prevent it from keeping any configuration over
  8. a down/up cycle.
  9. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
  10. ---
  11. drivers/net/ethernet/broadcom/bcm63xx_enet.c | 84 +++++++++++++-------------
  12. 1 files changed, 41 insertions(+), 43 deletions(-)
  13. --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
  14. +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
  15. @@ -871,10 +871,8 @@ static int bcm_enet_open(struct net_devi
  16. struct bcm_enet_priv *priv;
  17. struct sockaddr addr;
  18. struct device *kdev;
  19. - struct phy_device *phydev;
  20. int i, ret;
  21. unsigned int size;
  22. - char phy_id[MII_BUS_ID_SIZE + 3];
  23. void *p;
  24. u32 val;
  25. @@ -882,40 +880,10 @@ static int bcm_enet_open(struct net_devi
  26. kdev = &priv->pdev->dev;
  27. if (priv->has_phy) {
  28. - /* connect to PHY */
  29. - snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
  30. - priv->mii_bus->id, priv->phy_id);
  31. -
  32. - phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
  33. - PHY_INTERFACE_MODE_MII);
  34. -
  35. - if (IS_ERR(phydev)) {
  36. - dev_err(kdev, "could not attach to PHY\n");
  37. - return PTR_ERR(phydev);
  38. - }
  39. -
  40. - /* mask with MAC supported features */
  41. - phydev->supported &= (SUPPORTED_10baseT_Half |
  42. - SUPPORTED_10baseT_Full |
  43. - SUPPORTED_100baseT_Half |
  44. - SUPPORTED_100baseT_Full |
  45. - SUPPORTED_Autoneg |
  46. - SUPPORTED_Pause |
  47. - SUPPORTED_MII);
  48. - phydev->advertising = phydev->supported;
  49. -
  50. - if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
  51. - phydev->advertising |= SUPPORTED_Pause;
  52. - else
  53. - phydev->advertising &= ~SUPPORTED_Pause;
  54. -
  55. - dev_info(kdev, "attached PHY at address %d [%s]\n",
  56. - phydev->addr, phydev->drv->name);
  57. -
  58. + /* Reset state */
  59. priv->old_link = 0;
  60. priv->old_duplex = -1;
  61. priv->old_pause = -1;
  62. - priv->phydev = phydev;
  63. }
  64. /* mask all interrupts and request them */
  65. @@ -925,7 +893,7 @@ static int bcm_enet_open(struct net_devi
  66. ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
  67. if (ret)
  68. - goto out_phy_disconnect;
  69. + return ret;
  70. ret = request_irq(priv->irq_rx, bcm_enet_isr_dma, 0,
  71. dev->name, dev);
  72. @@ -1128,9 +1096,6 @@ out_freeirq_rx:
  73. out_freeirq:
  74. free_irq(dev->irq, dev);
  75. -out_phy_disconnect:
  76. - phy_disconnect(priv->phydev);
  77. -
  78. return ret;
  79. }
  80. @@ -1235,12 +1200,6 @@ static int bcm_enet_stop(struct net_devi
  81. free_irq(priv->irq_rx, dev);
  82. free_irq(dev->irq, dev);
  83. - /* release phy */
  84. - if (priv->has_phy) {
  85. - phy_disconnect(priv->phydev);
  86. - priv->phydev = NULL;
  87. - }
  88. -
  89. return 0;
  90. }
  91. @@ -1831,6 +1790,8 @@ static int bcm_enet_probe(struct platfor
  92. /* MII bus registration */
  93. if (priv->has_phy) {
  94. + struct phy_device *phydev;
  95. + char phy_id[MII_BUS_ID_SIZE + 3];
  96. priv->mii_bus = mdiobus_alloc();
  97. if (!priv->mii_bus) {
  98. @@ -1868,6 +1829,38 @@ static int bcm_enet_probe(struct platfor
  99. dev_err(&pdev->dev, "unable to register mdio bus\n");
  100. goto out_free_mdio;
  101. }
  102. +
  103. + /* connect to PHY */
  104. + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
  105. + priv->mii_bus->id, priv->phy_id);
  106. +
  107. + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
  108. + PHY_INTERFACE_MODE_MII);
  109. +
  110. + if (IS_ERR(phydev)) {
  111. + dev_err(&pdev->dev, "could not attach to PHY\n");
  112. + goto out_unregister_mdio;
  113. + }
  114. +
  115. + /* mask with MAC supported features */
  116. + phydev->supported &= (SUPPORTED_10baseT_Half |
  117. + SUPPORTED_10baseT_Full |
  118. + SUPPORTED_100baseT_Half |
  119. + SUPPORTED_100baseT_Full |
  120. + SUPPORTED_Autoneg |
  121. + SUPPORTED_Pause |
  122. + SUPPORTED_MII);
  123. + phydev->advertising = phydev->supported;
  124. +
  125. + if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
  126. + phydev->advertising |= SUPPORTED_Pause;
  127. + else
  128. + phydev->advertising &= ~SUPPORTED_Pause;
  129. +
  130. + dev_info(&pdev->dev, "attached PHY at address %d [%s]\n",
  131. + phydev->addr, phydev->drv->name);
  132. +
  133. + priv->phydev = phydev;
  134. } else {
  135. /* run platform code to initialize PHY device */
  136. @@ -1913,6 +1906,9 @@ static int bcm_enet_probe(struct platfor
  137. return 0;
  138. out_unregister_mdio:
  139. + if (priv->phydev)
  140. + phy_disconnect(priv->phydev);
  141. +
  142. if (priv->mii_bus)
  143. mdiobus_unregister(priv->mii_bus);
  144. @@ -1954,6 +1950,8 @@ static int bcm_enet_remove(struct platfo
  145. enet_writel(priv, 0, ENET_MIISC_REG);
  146. if (priv->has_phy) {
  147. + phy_disconnect(priv->phydev);
  148. + priv->phydev = NULL;
  149. mdiobus_unregister(priv->mii_bus);
  150. mdiobus_free(priv->mii_bus);
  151. } else {