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 (enet_readl(priv, ENET_IR_REG) & ENET_IR_MII)
15 - } while (limit-- >= 0);
16 + } while (limit-- > 0);
18 return (limit < 0) ? 1 : 0;
21 if (len < copybreak) {
24 - nskb = netdev_alloc_skb(dev, len + 2);
25 + nskb = netdev_alloc_skb(dev, len + NET_IP_ALIGN);
27 /* forget packet, just rearm desc */
28 priv->stats.rx_dropped++;
31 /* no more packet in rx/tx queue, remove device from poll
33 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
34 - netif_rx_complete(dev, napi);
39 /* restore rx/tx interrupt */
40 enet_dma_writel(priv, ENETDMA_IR_PKTDONE_MASK,
42 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->rx_chan));
43 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->tx_chan));
45 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
46 - netif_rx_schedule(dev, &priv->napi);
48 napi_schedule(&priv->napi);
54 pr_info("%s: link %s", dev->name, phydev->link ?
57 - printk(" - %d/%s - flow control %s", phydev->speed,
58 + pr_cont(" - %d/%s - flow control %s", phydev->speed,
59 DUPLEX_FULL == phydev->duplex ? "full" : "half",
60 phydev->pause == 1 ? "rx&tx" : "off");
68 priv = netdev_priv(dev);
69 bcm_enet_set_duplex(priv, priv->force_duplex_full);
70 bcm_enet_set_flow(priv, priv->pause_rx, priv->pause_tx);
71 + netif_carrier_on(dev);
73 pr_info("%s: link forced UP - %d/%s - flow control %s/%s\n",
78 struct phy_device *phydev;
79 - int irq_requested, i, ret;
82 - char phy_id[BUS_ID_SIZE];
83 + char phy_id[MII_BUS_ID_SIZE + 3];
87 priv = netdev_priv(dev);
88 - priv->rx_desc_cpu = priv->tx_desc_cpu = NULL;
89 - priv->rx_skb = priv->tx_skb = NULL;
91 kdev = &priv->pdev->dev;
95 - snprintf(phy_id, BUS_ID_SIZE, PHY_ID_FMT,
96 + snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT,
97 priv->mac_id ? "1" : "0", priv->phy_id);
99 phydev = phy_connect(dev, phy_id, &bcm_enet_adjust_phy_link, 0,
100 @@ -854,23 +843,19 @@
101 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->rx_chan));
102 enet_dma_writel(priv, 0, ENETDMA_IRMASK_REG(priv->tx_chan));
105 ret = request_irq(dev->irq, bcm_enet_isr_mac, 0, dev->name, dev);
109 + goto out_phy_disconnect;
111 ret = request_irq(priv->irq_rx, bcm_enet_isr_dma,
112 IRQF_SAMPLE_RANDOM | IRQF_DISABLED, dev->name, dev);
118 ret = request_irq(priv->irq_tx, bcm_enet_isr_dma,
119 IRQF_DISABLED, dev->name, dev);
123 + goto out_freeirq_rx;
125 /* initialize perfect match registers */
126 for (i = 0; i < 4; i++) {
129 dev_err(kdev, "cannot allocate rx ring %u\n", size);
132 + goto out_freeirq_tx;
138 dev_err(kdev, "cannot allocate tx ring\n");
141 + goto out_free_rx_ring;
147 dev_err(kdev, "cannot allocate rx skb queue\n");
150 + goto out_free_tx_ring;
153 priv->tx_desc_count = priv->tx_ring_size;
156 dev_err(kdev, "cannot allocate rx skb queue\n");
159 + goto out_free_tx_skb;
162 priv->rx_desc_count = 0;
163 @@ -1012,13 +997,6 @@
167 - phy_disconnect(priv->phydev);
168 - if (irq_requested > 2)
169 - free_irq(priv->irq_tx, dev);
170 - if (irq_requested > 1)
171 - free_irq(priv->irq_rx, dev);
172 - if (irq_requested > 0)
173 - free_irq(dev->irq, dev);
174 for (i = 0; i < priv->rx_ring_size; i++) {
175 struct bcm_enet_desc *desc;
177 @@ -1030,14 +1008,31 @@
179 kfree_skb(priv->rx_skb[i]);
181 - if (priv->rx_desc_cpu)
182 - dma_free_coherent(kdev, priv->rx_desc_alloc_size,
183 - priv->rx_desc_cpu, priv->rx_desc_dma);
184 - if (priv->tx_desc_cpu)
185 - dma_free_coherent(kdev, priv->tx_desc_alloc_size,
186 - priv->tx_desc_cpu, priv->tx_desc_dma);
193 + dma_free_coherent(kdev, priv->tx_desc_alloc_size,
194 + priv->tx_desc_cpu, priv->tx_desc_dma);
197 + dma_free_coherent(kdev, priv->rx_desc_alloc_size,
198 + priv->rx_desc_cpu, priv->rx_desc_dma);
201 + free_irq(priv->irq_tx, dev);
204 + free_irq(priv->irq_rx, dev);
207 + free_irq(dev->irq, dev);
210 + phy_disconnect(priv->phydev);
215 @@ -1606,6 +1601,20 @@
216 enet_writel(priv, val, ENET_MIBCTL_REG);
219 +static const struct net_device_ops bcm_enet_ops = {
220 + .ndo_open = bcm_enet_open,
221 + .ndo_stop = bcm_enet_stop,
222 + .ndo_start_xmit = bcm_enet_start_xmit,
223 + .ndo_get_stats = bcm_enet_get_stats,
224 + .ndo_set_mac_address = bcm_enet_set_mac_address,
225 + .ndo_set_multicast_list = bcm_enet_set_multicast_list,
226 + .ndo_do_ioctl = bcm_enet_ioctl,
227 + .ndo_change_mtu = bcm_enet_change_mtu,
228 +#ifdef CONFIG_NET_POLL_CONTROLLER
229 + .ndo_poll_controller = bcm_enet_netpoll,
234 * allocate netdevice, request register memory and register device.
236 @@ -1618,15 +1627,13 @@
238 const char *clk_name;
239 unsigned int iomem_size;
240 - int i, ret, mdio_registered, mem_requested;
243 /* stop if shared driver failed, assume driver->probe will be
244 * called in the same order we register devices (correct ?) */
245 if (!bcm_enet_shared_base)
248 - mdio_registered = mem_requested = 0;
250 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
251 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
252 res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
253 @@ -1648,14 +1655,13 @@
254 iomem_size = res_mem->end - res_mem->start + 1;
255 if (!request_mem_region(res_mem->start, iomem_size, "bcm63xx_enet")) {
262 priv->base = ioremap(res_mem->start, iomem_size);
263 if (priv->base == NULL) {
266 + goto out_release_mem;
268 dev->irq = priv->irq = res_irq->start;
269 priv->irq_rx = res_irq_rx->start;
270 @@ -1676,8 +1682,7 @@
271 priv->mac_clk = clk_get(&pdev->dev, clk_name);
272 if (IS_ERR(priv->mac_clk)) {
273 ret = PTR_ERR(priv->mac_clk);
274 - priv->mac_clk = NULL;
278 clk_enable(priv->mac_clk);
280 @@ -1706,7 +1711,7 @@
281 if (IS_ERR(priv->phy_clk)) {
282 ret = PTR_ERR(priv->phy_clk);
283 priv->phy_clk = NULL;
285 + goto out_put_clk_mac;
287 clk_enable(priv->phy_clk);
289 @@ -1716,13 +1721,16 @@
291 /* MII bus registration */
293 - bus = &priv->mii_bus;
295 + priv->mii_bus = mdiobus_alloc();
296 + if (!priv->mii_bus) {
298 + goto out_uninit_hw;
301 + bus = priv->mii_bus;
302 bus->name = "bcm63xx_enet MII bus";
303 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
304 - bus->dev = &pdev->dev;
306 bus->parent = &pdev->dev;
309 bus->read = bcm_enet_mdio_read_phylib;
310 bus->write = bcm_enet_mdio_write_phylib;
311 @@ -1736,7 +1744,7 @@
312 bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
316 + goto out_free_mdio;
319 if (priv->has_phy_interrupt)
320 @@ -1747,9 +1755,8 @@
321 ret = mdiobus_register(bus);
323 dev_err(&pdev->dev, "unable to register mdio bus\n");
325 + goto out_free_mdio;
327 - mdio_registered = 1;
330 /* run platform code to initialize PHY device */
331 @@ -1757,7 +1764,7 @@
332 pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
333 bcm_enet_mdio_write_mii)) {
334 dev_err(&pdev->dev, "unable to configure mdio bus\n");
336 + goto out_uninit_hw;
340 @@ -1777,51 +1784,50 @@
341 enet_writel(priv, 0, ENET_MIB_REG(i));
343 /* register netdevice */
344 - dev->open = bcm_enet_open;
345 - dev->stop = bcm_enet_stop;
346 - dev->hard_start_xmit = bcm_enet_start_xmit;
347 - dev->get_stats = bcm_enet_get_stats;
348 - dev->set_mac_address = bcm_enet_set_mac_address;
349 - dev->set_multicast_list = bcm_enet_set_multicast_list;
350 + dev->netdev_ops = &bcm_enet_ops;
351 netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);
352 - dev->do_ioctl = bcm_enet_ioctl;
353 -#ifdef CONFIG_NET_POLL_CONTROLLER
354 - dev->poll_controller = bcm_enet_netpoll;
356 - dev->change_mtu = bcm_enet_change_mtu;
358 SET_ETHTOOL_OPS(dev, &bcm_enet_ethtool_ops);
359 - SET_NETDEV_DEV(dev, &pdev->dev);
361 ret = register_netdev(dev);
364 + goto out_unregister_mdio;
366 + netif_carrier_off(dev);
367 platform_set_drvdata(pdev, dev);
370 + SET_NETDEV_DEV(dev, &pdev->dev);
376 - release_mem_region(res_mem->start, iomem_size);
377 - if (mdio_registered)
378 - mdiobus_unregister(&priv->mii_bus);
379 - kfree(priv->mii_bus.irq);
380 - if (priv->mac_clk) {
381 - clk_disable(priv->mac_clk);
382 - clk_put(priv->mac_clk);
383 +out_unregister_mdio:
384 + if (priv->mii_bus) {
385 + mdiobus_unregister(priv->mii_bus);
386 + kfree(priv->mii_bus->irq);
391 + mdiobus_free(priv->mii_bus);
394 + /* turn off mdc clock */
395 + enet_writel(priv, 0, ENET_MIISC_REG);
397 clk_disable(priv->phy_clk);
398 clk_put(priv->phy_clk);
401 - /* turn off mdc clock */
402 - enet_writel(priv, 0, ENET_MIISC_REG);
403 - iounmap(priv->base);
407 + clk_disable(priv->mac_clk);
408 + clk_put(priv->mac_clk);
411 + iounmap(priv->base);
414 + release_mem_region(res_mem->start, iomem_size);
418 @@ -1846,8 +1852,9 @@
419 enet_writel(priv, 0, ENET_MIISC_REG);
422 - mdiobus_unregister(&priv->mii_bus);
423 - kfree(priv->mii_bus.irq);
424 + mdiobus_unregister(priv->mii_bus);
425 + kfree(priv->mii_bus->irq);
426 + mdiobus_free(priv->mii_bus);
428 struct bcm63xx_enet_platform_data *pd;
430 @@ -1870,7 +1877,6 @@
431 clk_disable(priv->mac_clk);
432 clk_put(priv->mac_clk);
434 - platform_set_drvdata(pdev, NULL);
438 --- a/drivers/net/bcm63xx_enet.h 2009-06-07 11:25:51.000000000 +0200
439 +++ b/drivers/net/bcm63xx_enet.h 2009-08-05 10:02:28.000000000 +0200
443 /* used when a phy is connected (phylib used) */
444 - struct mii_bus mii_bus;
445 + struct mii_bus *mii_bus;
446 struct phy_device *phydev;