brcm47xx: rename target to bcm47xx
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.19 / 404-NET-bcm63xx_enet-move-phy_-dis-connect-into-probe-re.patch
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
5
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
9 a down/up cycle.
10
11 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
12 ---
13 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 158 +++++++++++++--------------
14 1 file changed, 78 insertions(+), 80 deletions(-)
15
16 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
17 +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
18 @@ -867,10 +867,8 @@ static int bcm_enet_open(struct net_devi
19 struct bcm_enet_priv *priv;
20 struct sockaddr addr;
21 struct device *kdev;
22 - struct phy_device *phydev;
23 int i, ret;
24 unsigned int size;
25 - char phy_id[MII_BUS_ID_SIZE + 3];
26 void *p;
27 u32 val;
28
29 @@ -878,40 +876,10 @@ static int bcm_enet_open(struct net_devi
30 kdev = &priv->pdev->dev;
31
32 if (priv->has_phy) {
33 - /* connect to PHY */
34 - snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
35 - priv->mii_bus->id, priv->phy_id);
36 -
37 - phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
38 - PHY_INTERFACE_MODE_MII);
39 -
40 - if (IS_ERR(phydev)) {
41 - dev_err(kdev, "could not attach to PHY\n");
42 - return PTR_ERR(phydev);
43 - }
44 -
45 - /* mask with MAC supported features */
46 - phydev->supported &= (SUPPORTED_10baseT_Half |
47 - SUPPORTED_10baseT_Full |
48 - SUPPORTED_100baseT_Half |
49 - SUPPORTED_100baseT_Full |
50 - SUPPORTED_Autoneg |
51 - SUPPORTED_Pause |
52 - SUPPORTED_MII);
53 - phydev->advertising = phydev->supported;
54 -
55 - if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
56 - phydev->advertising |= SUPPORTED_Pause;
57 - else
58 - phydev->advertising &= ~SUPPORTED_Pause;
59 -
60 - phy_attached_info(phydev);
61 -
62 + /* Reset state */
63 priv->old_link = 0;
64 priv->old_duplex = -1;
65 priv->old_pause = -1;
66 - } else {
67 - phydev = NULL;
68 }
69
70 /* mask all interrupts and request them */
71 @@ -921,7 +889,7 @@ static int bcm_enet_open(struct net_devi
72
73 ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
74 if (ret)
75 - goto out_phy_disconnect;
76 + return ret;
77
78 ret = request_irq(priv->irq_rx, bcm_enet_isr_dma, 0,
79 dev->name, dev);
80 @@ -1083,8 +1051,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);
83
84 - if (phydev)
85 - phy_start(phydev);
86 + if (priv->has_phy)
87 + phy_start(dev->phydev);
88 else
89 bcm_enet_adjust_link(dev);
90
91 @@ -1125,10 +1093,6 @@ out_freeirq_rx:
92 out_freeirq:
93 free_irq(dev->irq, dev);
94
95 -out_phy_disconnect:
96 - if (phydev)
97 - phy_disconnect(phydev);
98 -
99 return ret;
100 }
101
102 @@ -1233,10 +1197,6 @@ static int bcm_enet_stop(struct net_devi
103 free_irq(priv->irq_rx, dev);
104 free_irq(dev->irq, dev);
105
106 - /* release phy */
107 - if (priv->has_phy)
108 - phy_disconnect(dev->phydev);
109 -
110 return 0;
111 }
112
113 @@ -1802,14 +1762,47 @@ static int bcm_enet_probe(struct platfor
114
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);
118 +
119 + /* init rx timeout (used for oom) */
120 + timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
121 +
122 + /* init the mib update lock&work */
123 + mutex_init(&priv->mib_update_lock);
124 + INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
125 +
126 + /* zero mib counters */
127 + for (i = 0; i < ENET_MIB_REG_COUNT; i++)
128 + enet_writel(priv, 0, ENET_MIB_REG(i));
129 +
130 + /* register netdevice */
131 + dev->netdev_ops = &bcm_enet_ops;
132 + netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
133 +
134 + dev->ethtool_ops = &bcm_enet_ethtool_ops;
135 + /* MTU range: 46 - 2028 */
136 + dev->min_mtu = ETH_ZLEN - ETH_HLEN;
137 + dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
138 + SET_NETDEV_DEV(dev, &pdev->dev);
139 +
140 + ret = register_netdev(dev);
141 + if (ret)
142 + goto out_uninit_hw;
143 +
144 + netif_carrier_off(dev);
145 + platform_set_drvdata(pdev, dev);
146 + priv->pdev = pdev;
147 + priv->net_dev = dev;
148
149 /* MII bus registration */
150 if (priv->has_phy) {
151 + struct phy_device *phydev;
152 + char phy_id[MII_BUS_ID_SIZE + 3];
153
154 priv->mii_bus = mdiobus_alloc();
155 if (!priv->mii_bus) {
156 ret = -ENOMEM;
157 - goto out_uninit_hw;
158 + goto out_unregister_netdev;
159 }
160
161 bus = priv->mii_bus;
162 @@ -1833,6 +1826,35 @@ static int bcm_enet_probe(struct platfor
163 dev_err(&pdev->dev, "unable to register mdio bus\n");
164 goto out_free_mdio;
165 }
166 +
167 + /* connect to PHY */
168 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
169 + priv->mii_bus->id, priv->phy_id);
170 +
171 + phydev = phy_connect(dev, phy_id, bcm_enet_adjust_phy_link,
172 + PHY_INTERFACE_MODE_MII);
173 +
174 + if (IS_ERR(phydev)) {
175 + dev_err(&pdev->dev, "could not attach to PHY\n");
176 + goto out_unregister_mdio;
177 + }
178 +
179 + /* mask with MAC supported features */
180 + phydev->supported &= (SUPPORTED_10baseT_Half |
181 + SUPPORTED_10baseT_Full |
182 + SUPPORTED_100baseT_Half |
183 + SUPPORTED_100baseT_Full |
184 + SUPPORTED_Autoneg |
185 + SUPPORTED_Pause |
186 + SUPPORTED_MII);
187 + phydev->advertising = phydev->supported;
188 +
189 + if (priv->pause_auto && priv->pause_rx && priv->pause_tx)
190 + phydev->advertising |= SUPPORTED_Pause;
191 + else
192 + phydev->advertising &= ~SUPPORTED_Pause;
193 +
194 + phy_attached_info(phydev);
195 } else {
196
197 /* run platform code to initialize PHY device */
198 @@ -1840,45 +1862,16 @@ static int bcm_enet_probe(struct platfor
199 pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
200 bcm_enet_mdio_write_mii)) {
201 dev_err(&pdev->dev, "unable to configure mdio bus\n");
202 - goto out_uninit_hw;
203 + goto out_unregister_netdev;
204 }
205 }
206
207 - spin_lock_init(&priv->rx_lock);
208 -
209 - /* init rx timeout (used for oom) */
210 - timer_setup(&priv->rx_timeout, bcm_enet_refill_rx_timer, 0);
211 -
212 - /* init the mib update lock&work */
213 - mutex_init(&priv->mib_update_lock);
214 - INIT_WORK(&priv->mib_update_task, bcm_enet_update_mib_counters_defer);
215 -
216 - /* zero mib counters */
217 - for (i = 0; i < ENET_MIB_REG_COUNT; i++)
218 - enet_writel(priv, 0, ENET_MIB_REG(i));
219 -
220 - /* register netdevice */
221 - dev->netdev_ops = &bcm_enet_ops;
222 - netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
223 -
224 - dev->ethtool_ops = &bcm_enet_ethtool_ops;
225 - /* MTU range: 46 - 2028 */
226 - dev->min_mtu = ETH_ZLEN - ETH_HLEN;
227 - dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
228 - SET_NETDEV_DEV(dev, &pdev->dev);
229 -
230 - ret = register_netdev(dev);
231 - if (ret)
232 - goto out_unregister_mdio;
233 -
234 - netif_carrier_off(dev);
235 - platform_set_drvdata(pdev, dev);
236 - priv->pdev = pdev;
237 - priv->net_dev = dev;
238 -
239 return 0;
240
241 out_unregister_mdio:
242 + if (dev->phydev)
243 + phy_disconnect(dev->phydev);
244 +
245 if (priv->mii_bus)
246 mdiobus_unregister(priv->mii_bus);
247
248 @@ -1886,6 +1879,9 @@ out_free_mdio:
249 if (priv->mii_bus)
250 mdiobus_free(priv->mii_bus);
251
252 +out_unregister_netdev:
253 + unregister_netdev(dev);
254 +
255 out_uninit_hw:
256 /* turn off mdc clock */
257 enet_writel(priv, 0, ENET_MIISC_REG);
258 @@ -1916,6 +1912,7 @@ static int bcm_enet_remove(struct platfo
259 enet_writel(priv, 0, ENET_MIISC_REG);
260
261 if (priv->has_phy) {
262 + phy_disconnect(dev->phydev);
263 mdiobus_unregister(priv->mii_bus);
264 mdiobus_free(priv->mii_bus);
265 } else {