1 From 7fa63fdde703aaabaa7199ae879219737a98a3f3 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] NET: bcm63xx_enet: move phy_(dis)connect into probe/remove
6 Only connect/disconnect the phy during probe and remove, not during any
7 open/close. The phy seldom changes during the runtime, and disconnecting
8 the phy during close will prevent it from keeping any configuration over
11 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
13 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 158 +++++++++++++--------------
14 1 file changed, 78 insertions(+), 80 deletions(-)
16 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
17 +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
18 @@ -870,10 +870,8 @@ static int bcm_enet_open(struct net_devi
19 struct bcm_enet_priv *priv;
22 - struct phy_device *phydev;
25 - char phy_id[MII_BUS_ID_SIZE + 3];
29 @@ -881,40 +879,10 @@ static int bcm_enet_open(struct net_devi
30 kdev = &priv->pdev->dev;
33 - /* connect to PHY */
34 - snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
35 - priv->mii_bus->id, priv->phy_id);
37 - phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
38 - PHY_INTERFACE_MODE_MII);
40 - if (IS_ERR(phydev)) {
41 - dev_err(kdev, "could not attach to PHY\n");
42 - return PTR_ERR(phydev);
45 - /* mask with MAC supported features */
46 - phydev->supported &= (SUPPORTED_10baseT_Half |
47 - SUPPORTED_10baseT_Full |
48 - SUPPORTED_100baseT_Half |
49 - SUPPORTED_100baseT_Full |
53 - phydev->advertising = phydev->supported;
55 - if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
56 - phydev->advertising |= SUPPORTED_Pause;
58 - phydev->advertising &= ~SUPPORTED_Pause;
60 - phy_attached_info(phydev);
64 priv->old_duplex = -1;
70 /* mask all interrupts and request them */
71 @@ -924,7 +892,7 @@ static int bcm_enet_open(struct net_devi
73 ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
75 - goto out_phy_disconnect;
78 ret = request_irq(priv->irq_rx, bcm_enet_isr_dma, 0,
80 @@ -1086,8 +1054,8 @@ static int bcm_enet_open(struct net_devi
81 enet_dmac_writel(priv, priv->dma_chan_int_mask,
82 ENETDMAC_IRMASK, priv->tx_chan);
87 + phy_start(dev->phydev);
89 bcm_enet_adjust_link(dev);
91 @@ -1128,10 +1096,6 @@ out_freeirq_rx:
93 free_irq(dev->irq, dev);
97 - phy_disconnect(phydev);
102 @@ -1236,10 +1200,6 @@ static int bcm_enet_stop(struct net_devi
103 free_irq(priv->irq_rx, dev);
104 free_irq(dev->irq, dev);
108 - phy_disconnect(dev->phydev);
113 @@ -1805,14 +1765,49 @@ static int bcm_enet_probe(struct platfor
115 /* do minimal hardware init to be able to probe mii bus */
116 bcm_enet_hw_preinit(priv);
117 + spin_lock_init(&priv->rx_lock);
119 + /* init rx timeout (used for oom) */
120 + init_timer(&priv->rx_timeout);
121 + priv->rx_timeout.function = bcm_enet_refill_rx_timer;
122 + priv->rx_timeout.data = (unsigned long)dev;
124 + /* init the mib update lock&work */
125 + mutex_init(&priv->mib_update_lock);
126 + INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
128 + /* zero mib counters */
129 + for (i = 0; i < ENET_MIB_REG_COUNT; i++)
130 + enet_writel(priv, 0, ENET_MIB_REG(i));
132 + /* register netdevice */
133 + dev->netdev_ops = &bcm_enet_ops;
134 + netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
136 + dev->ethtool_ops = &bcm_enet_ethtool_ops;
137 + /* MTU range: 46 - 2028 */
138 + dev->min_mtu = ETH_ZLEN - ETH_HLEN;
139 + dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
140 + SET_NETDEV_DEV(dev, &pdev->dev);
142 + ret = register_netdev(dev);
144 + goto out_uninit_hw;
146 + netif_carrier_off(dev);
147 + platform_set_drvdata(pdev, dev);
149 + priv->net_dev = dev;
151 /* MII bus registration */
153 + struct phy_device *phydev;
154 + char phy_id[MII_BUS_ID_SIZE + 3];
156 priv->mii_bus = mdiobus_alloc();
157 if (!priv->mii_bus) {
159 - goto out_uninit_hw;
160 + goto out_unregister_netdev;
164 @@ -1836,6 +1831,35 @@ static int bcm_enet_probe(struct platfor
165 dev_err(&pdev->dev, "unable to register mdio bus\n");
169 + /* connect to PHY */
170 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
171 + priv->mii_bus->id, priv->phy_id);
173 + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
174 + PHY_INTERFACE_MODE_MII);
176 + if (IS_ERR(phydev)) {
177 + dev_err(&pdev->dev, "could not attach to PHY\n");
178 + goto out_unregister_mdio;
181 + /* mask with MAC supported features */
182 + phydev->supported &= (SUPPORTED_10baseT_Half |
183 + SUPPORTED_10baseT_Full |
184 + SUPPORTED_100baseT_Half |
185 + SUPPORTED_100baseT_Full |
186 + SUPPORTED_Autoneg |
189 + phydev->advertising = phydev->supported;
191 + if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
192 + phydev->advertising |= SUPPORTED_Pause;
194 + phydev->advertising &= ~SUPPORTED_Pause;
196 + phy_attached_info(phydev);
199 /* run platform code to initialize PHY device */
200 @@ -1843,47 +1867,16 @@ static int bcm_enet_probe(struct platfor
201 pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
202 bcm_enet_mdio_write_mii)) {
203 dev_err(&pdev->dev, "unable to configure mdio bus\n");
204 - goto out_uninit_hw;
205 + goto out_unregister_netdev;
209 - spin_lock_init(&priv->rx_lock);
211 - /* init rx timeout (used for oom) */
212 - init_timer(&priv->rx_timeout);
213 - priv->rx_timeout.function = bcm_enet_refill_rx_timer;
214 - priv->rx_timeout.data = (unsigned long)dev;
216 - /* init the mib update lock&work */
217 - mutex_init(&priv->mib_update_lock);
218 - INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
220 - /* zero mib counters */
221 - for (i = 0; i < ENET_MIB_REG_COUNT; i++)
222 - enet_writel(priv, 0, ENET_MIB_REG(i));
224 - /* register netdevice */
225 - dev->netdev_ops = &bcm_enet_ops;
226 - netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
228 - dev->ethtool_ops = &bcm_enet_ethtool_ops;
229 - /* MTU range: 46 - 2028 */
230 - dev->min_mtu = ETH_ZLEN - ETH_HLEN;
231 - dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
232 - SET_NETDEV_DEV(dev, &pdev->dev);
234 - ret = register_netdev(dev);
236 - goto out_unregister_mdio;
238 - netif_carrier_off(dev);
239 - platform_set_drvdata(pdev, dev);
241 - priv->net_dev = dev;
247 + phy_disconnect(dev->phydev);
250 mdiobus_unregister(priv->mii_bus);
252 @@ -1891,6 +1884,9 @@ out_free_mdio:
254 mdiobus_free(priv->mii_bus);
256 +out_unregister_netdev:
257 + unregister_netdev(dev);
260 /* turn off mdc clock */
261 enet_writel(priv, 0, ENET_MIISC_REG);
262 @@ -1921,6 +1917,7 @@ static int bcm_enet_remove(struct platfo
263 enet_writel(priv, 0, ENET_MIISC_REG);
266 + phy_disconnect(dev->phydev);
267 mdiobus_unregister(priv->mii_bus);
268 mdiobus_free(priv->mii_bus);