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 @@ -854,10 +854,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 @@ -865,31 +863,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 - phy_support_sym_pause(phydev);
47 - phy_set_max_speed(phydev, SPEED_100);
48 - phy_set_sym_pause(phydev, priv->pause_rx, priv->pause_rx,
51 - phy_attached_info(phydev);
55 priv->old_duplex = -1;
61 /* mask all interrupts and request them */
62 @@ -899,7 +876,7 @@ static int bcm_enet_open(struct net_devi
64 ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
66 - goto out_phy_disconnect;
69 ret = request_irq(priv->irq_rx, bcm_enet_isr_dma, 0,
71 @@ -1061,8 +1038,8 @@ static int bcm_enet_open(struct net_devi
72 enet_dmac_writel(priv, priv->dma_chan_int_mask,
73 ENETDMAC_IRMASK, priv->tx_chan);
78 + phy_start(dev->phydev);
80 bcm_enet_adjust_link(dev);
82 @@ -1103,10 +1080,6 @@ out_freeirq_rx:
84 free_irq(dev->irq, dev);
88 - phy_disconnect(phydev);
93 @@ -1211,10 +1184,6 @@ static int bcm_enet_stop(struct net_devi
94 free_irq(priv->irq_rx, dev);
95 free_irq(dev->irq, dev);
99 - phy_disconnect(dev->phydev);
104 @@ -1779,14 +1748,47 @@ static int bcm_enet_probe(struct platfor
106 /* do minimal hardware init to be able to probe mii bus */
107 bcm_enet_hw_preinit(priv);
108 + spin_lock_init(&priv->rx_lock);
110 + /* init rx timeout (used for oom) */
111 + timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
113 + /* init the mib update lock&work */
114 + mutex_init(&priv->mib_update_lock);
115 + INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
117 + /* zero mib counters */
118 + for (i = 0; i < ENET_MIB_REG_COUNT; i++)
119 + enet_writel(priv, 0, ENET_MIB_REG(i));
121 + /* register netdevice */
122 + dev->netdev_ops = &bcm_enet_ops;
123 + netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
125 + dev->ethtool_ops = &bcm_enet_ethtool_ops;
126 + /* MTU range: 46 - 2028 */
127 + dev->min_mtu = ETH_ZLEN - ETH_HLEN;
128 + dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
129 + SET_NETDEV_DEV(dev, &pdev->dev);
131 + ret = register_netdev(dev);
133 + goto out_uninit_hw;
135 + netif_carrier_off(dev);
136 + platform_set_drvdata(pdev, dev);
138 + priv->net_dev = dev;
140 /* MII bus registration */
142 + struct phy_device *phydev;
143 + char phy_id[MII_BUS_ID_SIZE + 3];
145 priv->mii_bus = mdiobus_alloc();
146 if (!priv->mii_bus) {
148 - goto out_uninit_hw;
149 + goto out_unregister_netdev;
153 @@ -1810,6 +1812,26 @@ static int bcm_enet_probe(struct platfor
154 dev_err(&pdev->dev, "unable to register mdio bus\n");
158 + /* connect to PHY */
159 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
160 + priv->mii_bus->id, priv->phy_id);
162 + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
163 + PHY_INTERFACE_MODE_MII);
165 + if (IS_ERR(phydev)) {
166 + dev_err(&pdev->dev, "could not attach to PHY\n");
167 + goto out_unregister_mdio;
170 + /* mask with MAC supported features */
171 + phy_support_sym_pause(phydev);
172 + phy_set_max_speed(phydev, SPEED_100);
173 + phy_set_sym_pause(phydev, priv->pause_rx, priv->pause_rx,
176 + phy_attached_info(phydev);
179 /* run platform code to initialize PHY device */
180 @@ -1817,45 +1839,16 @@ static int bcm_enet_probe(struct platfor
181 pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
182 bcm_enet_mdio_write_mii)) {
183 dev_err(&pdev->dev, "unable to configure mdio bus\n");
184 - goto out_uninit_hw;
185 + goto out_unregister_netdev;
189 - spin_lock_init(&priv->rx_lock);
191 - /* init rx timeout (used for oom) */
192 - timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
194 - /* init the mib update lock&work */
195 - mutex_init(&priv->mib_update_lock);
196 - INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
198 - /* zero mib counters */
199 - for (i = 0; i < ENET_MIB_REG_COUNT; i++)
200 - enet_writel(priv, 0, ENET_MIB_REG(i));
202 - /* register netdevice */
203 - dev->netdev_ops = &bcm_enet_ops;
204 - netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
206 - dev->ethtool_ops = &bcm_enet_ethtool_ops;
207 - /* MTU range: 46 - 2028 */
208 - dev->min_mtu = ETH_ZLEN - ETH_HLEN;
209 - dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
210 - SET_NETDEV_DEV(dev, &pdev->dev);
212 - ret = register_netdev(dev);
214 - goto out_unregister_mdio;
216 - netif_carrier_off(dev);
217 - platform_set_drvdata(pdev, dev);
219 - priv->net_dev = dev;
225 + phy_disconnect(dev->phydev);
228 mdiobus_unregister(priv->mii_bus);
230 @@ -1863,6 +1856,9 @@ out_free_mdio:
232 mdiobus_free(priv->mii_bus);
234 +out_unregister_netdev:
235 + unregister_netdev(dev);
238 /* turn off mdc clock */
239 enet_writel(priv, 0, ENET_MIISC_REG);
240 @@ -1893,6 +1889,7 @@ static int bcm_enet_remove(struct platfo
241 enet_writel(priv, 0, ENET_MIISC_REG);
244 + phy_disconnect(dev->phydev);
245 mdiobus_unregister(priv->mii_bus);
246 mdiobus_free(priv->mii_bus);