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
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 | 84 +++++++++++++-------------
14 1 files changed, 41 insertions(+), 43 deletions(-)
16 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
17 +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
18 @@ -784,10 +784,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 @@ -795,40 +793,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, 0,
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 - dev_info(kdev, "attached PHY at address %d [%s]\n",
61 - phydev->addr, phydev->drv->name);
65 priv->old_duplex = -1;
67 - priv->phydev = phydev;
70 /* mask all interrupts and request them */
71 @@ -838,7 +806,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, IRQF_DISABLED,
80 @@ -1025,9 +993,6 @@ out_freeirq_rx:
82 free_irq(dev->irq, dev);
85 - phy_disconnect(priv->phydev);
90 @@ -1132,12 +1097,6 @@ static int bcm_enet_stop(struct net_devi
91 free_irq(priv->irq_rx, dev);
92 free_irq(dev->irq, dev);
95 - if (priv->has_phy) {
96 - phy_disconnect(priv->phydev);
97 - priv->phydev = NULL;
103 @@ -1714,6 +1673,8 @@ static int __devinit bcm_enet_probe(stru
105 /* MII bus registration */
107 + struct phy_device *phydev;
108 + char phy_id[MII_BUS_ID_SIZE + 3];
110 priv->mii_bus = mdiobus_alloc();
111 if (!priv->mii_bus) {
112 @@ -1750,6 +1711,38 @@ static int __devinit bcm_enet_probe(stru
113 dev_err(&pdev->dev, "unable to register mdio bus\n");
117 + /* connect to PHY */
118 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
119 + priv->mii_bus->id, priv->phy_id);
121 + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link, 0,
122 + PHY_INTERFACE_MODE_MII);
124 + if (IS_ERR(phydev)) {
125 + dev_err(&pdev->dev, "could not attach to PHY\n");
126 + goto out_unregister_mdio;
129 + /* mask with MAC supported features */
130 + phydev->supported &= (SUPPORTED_10baseT_Half |
131 + SUPPORTED_10baseT_Full |
132 + SUPPORTED_100baseT_Half |
133 + SUPPORTED_100baseT_Full |
134 + SUPPORTED_Autoneg |
137 + phydev->advertising = phydev->supported;
139 + if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
140 + phydev->advertising |= SUPPORTED_Pause;
142 + phydev->advertising &= ~SUPPORTED_Pause;
144 + dev_info(&pdev->dev, "attached PHY at address %d [%s]\n",
145 + phydev->addr, phydev->drv->name);
147 + priv->phydev = phydev;
150 /* run platform code to initialize PHY device */
151 @@ -1795,6 +1788,9 @@ static int __devinit bcm_enet_probe(stru
156 + phy_disconnect(priv->phydev);
159 mdiobus_unregister(priv->mii_bus);
160 kfree(priv->mii_bus->irq);
161 @@ -1845,6 +1841,8 @@ static int __devexit bcm_enet_remove(str
162 enet_writel(priv, 0, ENET_MIISC_REG);
165 + phy_disconnect(priv->phydev);
166 + priv->phydev = NULL;
167 mdiobus_unregister(priv->mii_bus);
168 kfree(priv->mii_bus->irq);
169 mdiobus_free(priv->mii_bus);