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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. From 7fa63fdde703aaabaa7199ae879219737a98a3f3 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <[email protected]>
  3. Date: Fri, 6 Jan 2012 12:24:18 +0100
  4. Subject: [PATCH] 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 <[email protected]>
  10. ---
  11. drivers/net/ethernet/broadcom/bcm63xx_enet.c | 158 +++++++++++++--------------
  12. 1 file changed, 78 insertions(+), 80 deletions(-)
  13. --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
  14. +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
  15. @@ -870,10 +870,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. @@ -881,40 +879,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. - phy_attached_info(phydev);
  56. -
  57. + /* Reset state */
  58. priv->old_link = 0;
  59. priv->old_duplex = -1;
  60. priv->old_pause = -1;
  61. - } else {
  62. - phydev = NULL;
  63. }
  64. /* mask all interrupts and request them */
  65. @@ -924,7 +892,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. @@ -1086,8 +1054,8 @@ static int bcm_enet_open(struct net_devi
  73. enet_dmac_writel(priv, priv->dma_chan_int_mask,
  74. ENETDMAC_IRMASK, priv->tx_chan);
  75. - if (phydev)
  76. - phy_start(phydev);
  77. + if (priv->has_phy)
  78. + phy_start(dev->phydev);
  79. else
  80. bcm_enet_adjust_link(dev);
  81. @@ -1128,10 +1096,6 @@ out_freeirq_rx:
  82. out_freeirq:
  83. free_irq(dev->irq, dev);
  84. -out_phy_disconnect:
  85. - if (phydev)
  86. - phy_disconnect(phydev);
  87. -
  88. return ret;
  89. }
  90. @@ -1236,10 +1200,6 @@ static int bcm_enet_stop(struct net_devi
  91. free_irq(priv->irq_rx, dev);
  92. free_irq(dev->irq, dev);
  93. - /* release phy */
  94. - if (priv->has_phy)
  95. - phy_disconnect(dev->phydev);
  96. -
  97. return 0;
  98. }
  99. @@ -1821,14 +1781,46 @@ static int bcm_enet_probe(struct platfor
  100. /* do minimal hardware init to be able to probe mii bus */
  101. bcm_enet_hw_preinit(priv);
  102. + spin_lock_init(&priv->rx_lock);
  103. +
  104. + /* init rx timeout (used for oom) */
  105. + init_timer(&priv->rx_timeout);
  106. + priv->rx_timeout.function = bcm_enet_refill_rx_timer;
  107. + priv->rx_timeout.data = (unsigned long)dev;
  108. +
  109. + /* init the mib update lock&work */
  110. + mutex_init(&priv->mib_update_lock);
  111. + INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
  112. +
  113. + /* zero mib counters */
  114. + for (i = 0; i < ENET_MIB_REG_COUNT; i++)
  115. + enet_writel(priv, 0, ENET_MIB_REG(i));
  116. +
  117. + /* register netdevice */
  118. + dev->netdev_ops = &bcm_enet_ops;
  119. + netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
  120. +
  121. + dev->ethtool_ops = &bcm_enet_ethtool_ops;
  122. + SET_NETDEV_DEV(dev, &pdev->dev);
  123. +
  124. + ret = register_netdev(dev);
  125. + if (ret)
  126. + goto out_uninit_hw;
  127. +
  128. + netif_carrier_off(dev);
  129. + platform_set_drvdata(pdev, dev);
  130. + priv->pdev = pdev;
  131. + priv->net_dev = dev;
  132. /* MII bus registration */
  133. if (priv->has_phy) {
  134. + struct phy_device *phydev;
  135. + char phy_id[MII_BUS_ID_SIZE + 3];
  136. priv->mii_bus = mdiobus_alloc();
  137. if (!priv->mii_bus) {
  138. ret = -ENOMEM;
  139. - goto out_uninit_hw;
  140. + goto out_unregister_netdev;
  141. }
  142. bus = priv->mii_bus;
  143. @@ -1852,6 +1844,35 @@ static int bcm_enet_probe(struct platfor
  144. dev_err(&pdev->dev, "unable to register mdio bus\n");
  145. goto out_free_mdio;
  146. }
  147. +
  148. + /* connect to PHY */
  149. + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
  150. + priv->mii_bus->id, priv->phy_id);
  151. +
  152. + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
  153. + PHY_INTERFACE_MODE_MII);
  154. +
  155. + if (IS_ERR(phydev)) {
  156. + dev_err(&pdev->dev, "could not attach to PHY\n");
  157. + goto out_unregister_mdio;
  158. + }
  159. +
  160. + /* mask with MAC supported features */
  161. + phydev->supported &= (SUPPORTED_10baseT_Half |
  162. + SUPPORTED_10baseT_Full |
  163. + SUPPORTED_100baseT_Half |
  164. + SUPPORTED_100baseT_Full |
  165. + SUPPORTED_Autoneg |
  166. + SUPPORTED_Pause |
  167. + SUPPORTED_MII);
  168. + phydev->advertising = phydev->supported;
  169. +
  170. + if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
  171. + phydev->advertising |= SUPPORTED_Pause;
  172. + else
  173. + phydev->advertising &= ~SUPPORTED_Pause;
  174. +
  175. + phy_attached_info(phydev);
  176. } else {
  177. /* run platform code to initialize PHY device */
  178. @@ -1859,44 +1880,16 @@ static int bcm_enet_probe(struct platfor
  179. pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
  180. bcm_enet_mdio_write_mii)) {
  181. dev_err(&pdev->dev, "unable to configure mdio bus\n");
  182. - goto out_uninit_hw;
  183. + goto out_unregister_netdev;
  184. }
  185. }
  186. - spin_lock_init(&priv->rx_lock);
  187. -
  188. - /* init rx timeout (used for oom) */
  189. - init_timer(&priv->rx_timeout);
  190. - priv->rx_timeout.function = bcm_enet_refill_rx_timer;
  191. - priv->rx_timeout.data = (unsigned long)dev;
  192. -
  193. - /* init the mib update lock&work */
  194. - mutex_init(&priv->mib_update_lock);
  195. - INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
  196. -
  197. - /* zero mib counters */
  198. - for (i = 0; i < ENET_MIB_REG_COUNT; i++)
  199. - enet_writel(priv, 0, ENET_MIB_REG(i));
  200. -
  201. - /* register netdevice */
  202. - dev->netdev_ops = &bcm_enet_ops;
  203. - netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
  204. -
  205. - dev->ethtool_ops = &bcm_enet_ethtool_ops;
  206. - SET_NETDEV_DEV(dev, &pdev->dev);
  207. -
  208. - ret = register_netdev(dev);
  209. - if (ret)
  210. - goto out_unregister_mdio;
  211. -
  212. - netif_carrier_off(dev);
  213. - platform_set_drvdata(pdev, dev);
  214. - priv->pdev = pdev;
  215. - priv->net_dev = dev;
  216. -
  217. return 0;
  218. out_unregister_mdio:
  219. + if (dev->phydev)
  220. + phy_disconnect(dev->phydev);
  221. +
  222. if (priv->mii_bus)
  223. mdiobus_unregister(priv->mii_bus);
  224. @@ -1904,6 +1897,9 @@ out_free_mdio:
  225. if (priv->mii_bus)
  226. mdiobus_free(priv->mii_bus);
  227. +out_unregister_netdev:
  228. + unregister_netdev(dev);
  229. +
  230. out_uninit_hw:
  231. /* turn off mdc clock */
  232. enet_writel(priv, 0, ENET_MIISC_REG);
  233. @@ -1934,6 +1930,7 @@ static int bcm_enet_remove(struct platfo
  234. enet_writel(priv, 0, ENET_MIISC_REG);
  235. if (priv->has_phy) {
  236. + phy_disconnect(dev->phydev);
  237. mdiobus_unregister(priv->mii_bus);
  238. mdiobus_free(priv->mii_bus);
  239. } else {