1 --- a/drivers/net/bcm63xx_enet.c 2009-07-31 22:06:20.000000000 +0200
2 +++ b/drivers/net/bcm63xx_enet.c 2009-08-05 10:02:28.000000000 +0200
4 #include <linux/dma-mapping.h>
5 #include <linux/platform_device.h>
6 #include <linux/if_vlan.h>
7 -#include <linux/version.h>
9 #include <bcm63xx_dev_enet.h>
10 #include "bcm63xx_enet.h"
12 if (len < copybreak) {
15 - nskb = netdev_alloc_skb(dev, len + 2);
16 + nskb = netdev_alloc_skb(dev, len + NET_IP_ALIGN);
18 /* forget packet, just rearm desc */
19 priv->stats.rx_dropped++;
22 /* no more packet in rx/tx queue, remove device from poll
24 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
25 - netif_rx_complete(dev, napi);
30 /* restore rx/tx interrupt */
31 enet_dma_writel(priv, ENETDMA_IR_PKTDONE_MASK,
33 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->rx_chan));
34 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->tx_chan));
36 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
37 - netif_rx_schedule(dev, &priv->napi);
39 napi_schedule(&priv->napi);
45 pr_info("%s: link %s", dev->name, phydev->link ?
48 - printk(" - %d/%s - flow control %s", phydev->speed,
49 + pr_cont(" - %d/%s - flow control %s", phydev->speed,
50 DUPLEX_FULL == phydev->duplex ? "full" : "half",
51 phydev->pause == 1 ? "rx&tx" : "off");
59 priv = netdev_priv(dev);
60 bcm_enet_set_duplex(priv, priv->force_duplex_full);
61 bcm_enet_set_flow(priv, priv->pause_rx, priv->pause_tx);
62 + netif_carrier_on(dev);
64 pr_info("%s: link forced UP - %d/%s - flow control %s/%s\n",
69 struct phy_device *phydev;
70 - int irq_requested, i, ret;
73 - char phy_id[BUS_ID_SIZE];
74 + char phy_id[MII_BUS_ID_SIZE + 3];
78 priv = netdev_priv(dev);
79 - priv->rx_desc_cpu = priv->tx_desc_cpu = NULL;
80 - priv->rx_skb = priv->tx_skb = NULL;
82 kdev = &priv->pdev->dev;
86 - snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT,
87 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
88 priv->mac_id ? "1" : "0", priv->phy_id);
90 phydev = phy_connect(dev, phy_id, &bcm_enet_adjust_phy_link, 0,
92 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->rx_chan));
93 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->tx_chan));
96 ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
100 + goto out_phy_disconnect;
102 ret = request_irq(priv->irq_rx, bcm_enet_isr_dma,
103 IRQF_SAMPLE_RANDOM | IRQF_DISABLED, dev->name, dev);
109 ret = request_irq(priv->irq_tx, bcm_enet_isr_dma,
110 IRQF_DISABLED, dev->name, dev);
114 + goto out_freeirq_rx;
116 /* initialize perfect match registers */
117 for (i = 0; i < 4; i++) {
120 dev_err(kdev, "cannot allocate rx ring %u\n", size);
123 + goto out_freeirq_tx;
129 dev_err(kdev, "cannot allocate tx ring\n");
132 + goto out_free_rx_ring;
138 dev_err(kdev, "cannot allocate rx skb queue\n");
141 + goto out_free_tx_ring;
144 priv->tx_desc_count = priv->tx_ring_size;
147 dev_err(kdev, "cannot allocate rx skb queue\n");
150 + goto out_free_tx_skb;
153 priv->rx_desc_count = 0;
154 @@ -1012,13 +997,6 @@
158 - phy_disconnect(priv->phydev);
159 - if (irq_requested > 2)
160 - free_irq(priv->irq_tx, dev);
161 - if (irq_requested > 1)
162 - free_irq(priv->irq_rx, dev);
163 - if (irq_requested > 0)
164 - free_irq(dev->irq, dev);
165 for (i = 0; i < priv->rx_ring_size; i++) {
166 struct bcm_enet_desc *desc;
168 @@ -1030,14 +1008,31 @@
170 kfree_skb(priv->rx_skb[i]);
172 - if (priv->rx_desc_cpu)
173 - dma_free_coherent(kdev, priv->rx_desc_alloc_size,
174 - priv->rx_desc_cpu, priv->rx_desc_dma);
175 - if (priv->tx_desc_cpu)
176 - dma_free_coherent(kdev, priv->tx_desc_alloc_size,
177 - priv->tx_desc_cpu, priv->tx_desc_dma);
184 + dma_free_coherent(kdev, priv->tx_desc_alloc_size,
185 + priv->tx_desc_cpu, priv->tx_desc_dma);
188 + dma_free_coherent(kdev, priv->rx_desc_alloc_size,
189 + priv->rx_desc_cpu, priv->rx_desc_dma);
192 + free_irq(priv->irq_tx, dev);
195 + free_irq(priv->irq_rx, dev);
198 + free_irq(dev->irq, dev);
201 + phy_disconnect(priv->phydev);
206 @@ -1606,6 +1601,20 @@
207 enet_writel(priv, val, ENET_MIBCTL_REG);
210 +static const struct net_device_ops bcm_enet_ops = {
211 + .ndo_open = bcm_enet_open,
212 + .ndo_stop = bcm_enet_stop,
213 + .ndo_start_xmit = bcm_enet_start_xmit,
214 + .ndo_get_stats = bcm_enet_get_stats,
215 + .ndo_set_mac_address = bcm_enet_set_mac_address,
216 + .ndo_set_multicast_list = bcm_enet_set_multicast_list,
217 + .ndo_do_ioctl = bcm_enet_ioctl,
218 + .ndo_change_mtu = bcm_enet_change_mtu,
219 +#ifdef CONFIG_NET_POLL_CONTROLLER
220 + .ndo_poll_controller = bcm_enet_netpoll,
225 * allocate netdevice, request register memory and register device.
227 @@ -1618,15 +1627,13 @@
229 const char *clk_name;
230 unsigned int iomem_size;
231 - int i, ret, mdio_registered, mem_requested;
234 /* stop if shared driver failed, assume driver->probe will be
235 * called in the same order we register devices (correct ?) */
236 if (!bcm_enet_shared_base)
239 - mdio_registered = mem_requested = 0;
241 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
242 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
243 res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
244 @@ -1648,14 +1655,13 @@
245 iomem_size = res_mem->end - res_mem->start + 1;
246 if (!request_mem_region(res_mem->start, iomem_size, "bcm63xx_enet")) {
253 priv->base = ioremap(res_mem->start, iomem_size);
254 if (priv->base == NULL) {
257 + goto out_release_mem;
259 dev->irq = priv->irq = res_irq->start;
260 priv->irq_rx = res_irq_rx->start;
261 @@ -1676,8 +1682,7 @@
262 priv->mac_clk = clk_get(&pdev->dev, clk_name);
263 if (IS_ERR(priv->mac_clk)) {
264 ret = PTR_ERR(priv->mac_clk);
265 - priv->mac_clk = NULL;
269 clk_enable(priv->mac_clk);
271 @@ -1706,7 +1711,7 @@
272 if (IS_ERR(priv->phy_clk)) {
273 ret = PTR_ERR(priv->phy_clk);
274 priv->phy_clk = NULL;
276 + goto out_put_clk_mac;
278 clk_enable(priv->phy_clk);
280 @@ -1716,13 +1721,16 @@
282 /* MII bus registration */
284 - bus = &priv->mii_bus;
286 + priv->mii_bus = mdiobus_alloc();
287 + if (!priv->mii_bus) {
289 + goto out_uninit_hw;
292 + bus = priv->mii_bus;
293 bus->name = "bcm63xx_enet MII bus";
294 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
295 - bus->dev = &pdev->dev;
297 bus->parent = &pdev->dev;
300 bus->read = bcm_enet_mdio_read_phylib;
301 bus->write = bcm_enet_mdio_write_phylib;
302 @@ -1736,7 +1744,7 @@
303 bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
307 + goto out_free_mdio;
310 if (priv->has_phy_interrupt)
311 @@ -1747,9 +1755,8 @@
312 ret = mdiobus_register(bus);
314 dev_err(&pdev->dev, "unable to register mdio bus\n");
316 + goto out_free_mdio;
318 - mdio_registered = 1;
321 /* run platform code to initialize PHY device */
322 @@ -1757,7 +1764,7 @@
323 pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
324 bcm_enet_mdio_write_mii)) {
325 dev_err(&pdev->dev, "unable to configure mdio bus\n");
327 + goto out_uninit_hw;
331 @@ -1777,51 +1784,50 @@
332 enet_writel(priv, 0, ENET_MIB_REG(i));
334 /* register netdevice */
335 - dev->open = bcm_enet_open;
336 - dev->stop = bcm_enet_stop;
337 - dev->hard_start_xmit = bcm_enet_start_xmit;
338 - dev->get_stats = bcm_enet_get_stats;
339 - dev->set_mac_address = bcm_enet_set_mac_address;
340 - dev->set_multicast_list = bcm_enet_set_multicast_list;
341 + dev->netdev_ops = &bcm_enet_ops;
342 netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
343 - dev->do_ioctl = bcm_enet_ioctl;
344 -#ifdef CONFIG_NET_POLL_CONTROLLER
345 - dev->poll_controller = bcm_enet_netpoll;
347 - dev->change_mtu = bcm_enet_change_mtu;
349 SET_ETHTOOL_OPS(dev, &bcm_enet_ethtool_ops);
350 - SET_NETDEV_DEV(dev, &pdev->dev);
352 ret = register_netdev(dev);
355 + goto out_unregister_mdio;
357 + netif_carrier_off(dev);
358 platform_set_drvdata(pdev, dev);
361 + SET_NETDEV_DEV(dev, &pdev->dev);
367 - release_mem_region(res_mem->start, iomem_size);
368 - if (mdio_registered)
369 - mdiobus_unregister(&priv->mii_bus);
370 - kfree(priv->mii_bus.irq);
371 - if (priv->mac_clk) {
372 - clk_disable(priv->mac_clk);
373 - clk_put(priv->mac_clk);
374 +out_unregister_mdio:
375 + if (priv->mii_bus) {
376 + mdiobus_unregister(priv->mii_bus);
377 + kfree(priv->mii_bus->irq);
382 + mdiobus_free(priv->mii_bus);
385 + /* turn off mdc clock */
386 + enet_writel(priv, 0, ENET_MIISC_REG);
388 clk_disable(priv->phy_clk);
389 clk_put(priv->phy_clk);
392 - /* turn off mdc clock */
393 - enet_writel(priv, 0, ENET_MIISC_REG);
394 - iounmap(priv->base);
398 + clk_disable(priv->mac_clk);
399 + clk_put(priv->mac_clk);
402 + iounmap(priv->base);
405 + release_mem_region(res_mem->start, iomem_size);
409 @@ -1846,8 +1852,9 @@
410 enet_writel(priv, 0, ENET_MIISC_REG);
413 - mdiobus_unregister(&priv->mii_bus);
414 - kfree(priv->mii_bus.irq);
415 + mdiobus_unregister(priv->mii_bus);
416 + kfree(priv->mii_bus->irq);
417 + mdiobus_free(priv->mii_bus);
419 struct bcm63xx_enet_platform_data *pd;
421 @@ -1870,7 +1877,6 @@
422 clk_disable(priv->mac_clk);
423 clk_put(priv->mac_clk);
425 - platform_set_drvdata(pdev, NULL);
429 --- a/drivers/net/bcm63xx_enet.h 2009-06-07 11:25:51.000000000 +0200
430 +++ b/drivers/net/bcm63xx_enet.h 2009-08-05 10:02:28.000000000 +0200
434 /* used when a phy is connected (phylib used) */
435 - struct mii_bus mii_bus;
436 + struct mii_bus *mii_bus;
437 struct phy_device *phydev;