~ubuntu-branches/ubuntu/lucid/linux-rt/lucid

« back to all changes in this revision

Viewing changes to drivers/net/gianfar.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-08-05 23:00:52 UTC
  • Revision ID: james.westby@ubuntu.com-20090805230052-7xedvqcyk9dnnxb2
Tags: 2.6.31-1.1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
#include <linux/if_vlan.h>
76
76
#include <linux/spinlock.h>
77
77
#include <linux/mm.h>
 
78
#include <linux/of_mdio.h>
78
79
#include <linux/of_platform.h>
79
80
#include <linux/ip.h>
80
81
#include <linux/tcp.h>
93
94
#include <linux/of.h>
94
95
 
95
96
#include "gianfar.h"
96
 
#include "gianfar_mii.h"
 
97
#include "fsl_pq_mdio.h"
97
98
 
98
99
#define TX_TIMEOUT      (1*HZ)
99
100
#undef BRIEF_GFAR_ERRORS
140
141
void gfar_start(struct net_device *dev);
141
142
static void gfar_clear_exact_match(struct net_device *dev);
142
143
static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
143
 
 
144
 
extern const struct ethtool_ops gfar_ethtool_ops;
 
144
static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
145
145
 
146
146
MODULE_AUTHOR("Freescale Semiconductor, Inc");
147
147
MODULE_DESCRIPTION("Gianfar Ethernet Driver");
148
148
MODULE_LICENSE("GPL");
149
149
 
 
150
static const struct net_device_ops gfar_netdev_ops = {
 
151
        .ndo_open = gfar_enet_open,
 
152
        .ndo_start_xmit = gfar_start_xmit,
 
153
        .ndo_stop = gfar_close,
 
154
        .ndo_change_mtu = gfar_change_mtu,
 
155
        .ndo_set_multicast_list = gfar_set_multi,
 
156
        .ndo_tx_timeout = gfar_timeout,
 
157
        .ndo_do_ioctl = gfar_ioctl,
 
158
        .ndo_vlan_rx_register = gfar_vlan_rx_register,
 
159
        .ndo_set_mac_address = eth_mac_addr,
 
160
        .ndo_validate_addr = eth_validate_addr,
 
161
#ifdef CONFIG_NET_POLL_CONTROLLER
 
162
        .ndo_poll_controller = gfar_netpoll,
 
163
#endif
 
164
};
 
165
 
150
166
/* Returns 1 if incoming frames use an FCB */
151
167
static inline int gfar_uses_fcb(struct gfar_private *priv)
152
168
{
155
171
 
156
172
static int gfar_of_init(struct net_device *dev)
157
173
{
158
 
        struct device_node *phy, *mdio;
159
 
        const unsigned int *id;
160
174
        const char *model;
161
175
        const char *ctype;
162
176
        const void *mac_addr;
163
 
        const phandle *ph;
164
177
        u64 addr, size;
165
178
        int err = 0;
166
179
        struct gfar_private *priv = netdev_priv(dev);
167
180
        struct device_node *np = priv->node;
168
 
        char bus_name[MII_BUS_ID_SIZE];
 
181
        const u32 *stash;
 
182
        const u32 *stash_len;
 
183
        const u32 *stash_idx;
169
184
 
170
185
        if (!np || !of_device_is_available(np))
171
186
                return -ENODEV;
195
210
                }
196
211
        }
197
212
 
 
213
        stash = of_get_property(np, "bd-stash", NULL);
 
214
 
 
215
        if(stash) {
 
216
                priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
 
217
                priv->bd_stash_en = 1;
 
218
        }
 
219
 
 
220
        stash_len = of_get_property(np, "rx-stash-len", NULL);
 
221
 
 
222
        if (stash_len)
 
223
                priv->rx_stash_size = *stash_len;
 
224
 
 
225
        stash_idx = of_get_property(np, "rx-stash-idx", NULL);
 
226
 
 
227
        if (stash_idx)
 
228
                priv->rx_stash_index = *stash_idx;
 
229
 
 
230
        if (stash_len || stash_idx)
 
231
                priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
 
232
 
198
233
        mac_addr = of_get_mac_address(np);
199
234
        if (mac_addr)
200
235
                memcpy(dev->dev_addr, mac_addr, MAC_ADDR_LEN);
228
263
        if (of_get_property(np, "fsl,magic-packet", NULL))
229
264
                priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
230
265
 
231
 
        ph = of_get_property(np, "phy-handle", NULL);
232
 
        if (ph == NULL) {
 
266
        priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
 
267
        if (!priv->phy_node) {
233
268
                u32 *fixed_link;
234
269
 
235
270
                fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
237
272
                        err = -ENODEV;
238
273
                        goto err_out;
239
274
                }
240
 
 
241
 
                snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id),
242
 
                                PHY_ID_FMT, "0", fixed_link[0]);
243
 
        } else {
244
 
                phy = of_find_node_by_phandle(*ph);
245
 
 
246
 
                if (phy == NULL) {
247
 
                        err = -ENODEV;
248
 
                        goto err_out;
249
 
                }
250
 
 
251
 
                mdio = of_get_parent(phy);
252
 
 
253
 
                id = of_get_property(phy, "reg", NULL);
254
 
 
255
 
                of_node_put(phy);
256
 
                of_node_put(mdio);
257
 
 
258
 
                gfar_mdio_bus_name(bus_name, mdio);
259
 
                snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id), "%s:%02x",
260
 
                                bus_name, *id);
261
275
        }
262
276
 
263
277
        /* Find the TBI PHY.  If it's not there, we don't support SGMII */
264
 
        ph = of_get_property(np, "tbi-handle", NULL);
265
 
        if (ph) {
266
 
                struct device_node *tbi = of_find_node_by_phandle(*ph);
267
 
                struct of_device *ofdev;
268
 
                struct mii_bus *bus;
269
 
 
270
 
                if (!tbi)
271
 
                        return 0;
272
 
 
273
 
                mdio = of_get_parent(tbi);
274
 
                if (!mdio)
275
 
                        return 0;
276
 
 
277
 
                ofdev = of_find_device_by_node(mdio);
278
 
 
279
 
                of_node_put(mdio);
280
 
 
281
 
                id = of_get_property(tbi, "reg", NULL);
282
 
                if (!id)
283
 
                        return 0;
284
 
 
285
 
                of_node_put(tbi);
286
 
 
287
 
                bus = dev_get_drvdata(&ofdev->dev);
288
 
 
289
 
                priv->tbiphy = bus->phy_map[*id];
290
 
        }
 
278
        priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
291
279
 
292
280
        return 0;
293
281
 
329
317
                return -ENOMEM;
330
318
 
331
319
        priv = netdev_priv(dev);
332
 
        priv->dev = dev;
 
320
        priv->ndev = dev;
 
321
        priv->ofdev = ofdev;
333
322
        priv->node = ofdev->node;
 
323
        SET_NETDEV_DEV(dev, &ofdev->dev);
334
324
 
335
325
        err = gfar_of_init(dev);
336
326
 
369
359
        SET_NETDEV_DEV(dev, &ofdev->dev);
370
360
 
371
361
        /* Fill in the dev structure */
372
 
        dev->open = gfar_enet_open;
373
 
        dev->hard_start_xmit = gfar_start_xmit;
374
 
        dev->tx_timeout = gfar_timeout;
375
362
        dev->watchdog_timeo = TX_TIMEOUT;
376
363
        netif_napi_add(dev, &priv->napi, gfar_poll, GFAR_DEV_WEIGHT);
377
 
#ifdef CONFIG_NET_POLL_CONTROLLER
378
 
        dev->poll_controller = gfar_netpoll;
379
 
#endif
380
 
        dev->stop = gfar_close;
381
 
        dev->change_mtu = gfar_change_mtu;
382
364
        dev->mtu = 1500;
383
 
        dev->set_multicast_list = gfar_set_multi;
384
365
 
 
366
        dev->netdev_ops = &gfar_netdev_ops;
385
367
        dev->ethtool_ops = &gfar_ethtool_ops;
386
 
        dev->do_ioctl = gfar_ioctl;
387
368
 
388
369
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
389
370
                priv->rx_csum_enable = 1;
393
374
 
394
375
        priv->vlgrp = NULL;
395
376
 
396
 
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
397
 
                dev->vlan_rx_register = gfar_vlan_rx_register;
398
 
 
 
377
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN)
399
378
                dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
400
 
        }
401
379
 
402
380
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
403
381
                priv->extended_hash = 1;
425
403
                priv->hash_width = 8;
426
404
 
427
405
                priv->hash_regs[0] = &priv->regs->gaddr0;
428
 
                priv->hash_regs[1] = &priv->regs->gaddr1;
 
406
                priv->hash_regs[1] = &priv->regs->gaddr1;
429
407
                priv->hash_regs[2] = &priv->regs->gaddr2;
430
408
                priv->hash_regs[3] = &priv->regs->gaddr3;
431
409
                priv->hash_regs[4] = &priv->regs->gaddr4;
466
444
                goto register_fail;
467
445
        }
468
446
 
 
447
        device_init_wakeup(&dev->dev,
 
448
                priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
 
449
 
469
450
        /* fill out IRQ number and name fields */
470
451
        len_devname = strlen(dev->name);
471
452
        strncpy(&priv->int_name_tx[0], dev->name, len_devname);
500
481
register_fail:
501
482
        iounmap(priv->regs);
502
483
regs_fail:
 
484
        if (priv->phy_node)
 
485
                of_node_put(priv->phy_node);
 
486
        if (priv->tbi_node)
 
487
                of_node_put(priv->tbi_node);
503
488
        free_netdev(dev);
504
489
        return err;
505
490
}
508
493
{
509
494
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
510
495
 
 
496
        if (priv->phy_node)
 
497
                of_node_put(priv->phy_node);
 
498
        if (priv->tbi_node)
 
499
                of_node_put(priv->tbi_node);
 
500
 
511
501
        dev_set_drvdata(&ofdev->dev, NULL);
512
502
 
513
503
        iounmap(priv->regs);
514
 
        free_netdev(priv->dev);
 
504
        free_netdev(priv->ndev);
515
505
 
516
506
        return 0;
517
507
}
520
510
static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
521
511
{
522
512
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
523
 
        struct net_device *dev = priv->dev;
 
513
        struct net_device *dev = priv->ndev;
524
514
        unsigned long flags;
525
515
        u32 tempval;
526
516
 
569
559
static int gfar_resume(struct of_device *ofdev)
570
560
{
571
561
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
572
 
        struct net_device *dev = priv->dev;
 
562
        struct net_device *dev = priv->ndev;
573
563
        unsigned long flags;
574
564
        u32 tempval;
575
565
        int magic_packet = priv->wol_en &&
661
651
        uint gigabit_support =
662
652
                priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
663
653
                SUPPORTED_1000baseT_Full : 0;
664
 
        struct phy_device *phydev;
665
654
        phy_interface_t interface;
666
655
 
667
656
        priv->oldlink = 0;
670
659
 
671
660
        interface = gfar_get_interface(dev);
672
661
 
673
 
        phydev = phy_connect(dev, priv->phy_bus_id, &adjust_link, 0, interface);
 
662
        if (priv->phy_node) {
 
663
                priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link,
 
664
                                              0, interface);
 
665
                if (!priv->phydev) {
 
666
                        dev_err(&dev->dev, "error: Could not attach to PHY\n");
 
667
                        return -ENODEV;
 
668
                }
 
669
        }
674
670
 
675
671
        if (interface == PHY_INTERFACE_MODE_SGMII)
676
672
                gfar_configure_serdes(dev);
677
673
 
678
 
        if (IS_ERR(phydev)) {
679
 
                printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
680
 
                return PTR_ERR(phydev);
681
 
        }
682
 
 
683
674
        /* Remove any features not supported by the controller */
684
 
        phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
685
 
        phydev->advertising = phydev->supported;
686
 
 
687
 
        priv->phydev = phydev;
 
675
        priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
 
676
        priv->phydev->advertising = priv->phydev->supported;
688
677
 
689
678
        return 0;
690
679
}
701
690
static void gfar_configure_serdes(struct net_device *dev)
702
691
{
703
692
        struct gfar_private *priv = netdev_priv(dev);
704
 
 
705
 
        if (!priv->tbiphy) {
706
 
                printk(KERN_WARNING "SGMII mode requires that the device "
707
 
                                "tree specify a tbi-handle\n");
 
693
        struct phy_device *tbiphy;
 
694
 
 
695
        if (!priv->tbi_node) {
 
696
                dev_warn(&dev->dev, "error: SGMII mode requires that the "
 
697
                                    "device tree specify a tbi-handle\n");
 
698
                return;
 
699
        }
 
700
 
 
701
        tbiphy = of_phy_find_device(priv->tbi_node);
 
702
        if (!tbiphy) {
 
703
                dev_err(&dev->dev, "error: Could not get TBI device\n");
708
704
                return;
709
705
        }
710
706
 
714
710
         * everything for us?  Resetting it takes the link down and requires
715
711
         * several seconds for it to come back.
716
712
         */
717
 
        if (phy_read(priv->tbiphy, MII_BMSR) & BMSR_LSTATUS)
 
713
        if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
718
714
                return;
719
715
 
720
716
        /* Single clk mode, mii mode off(for serdes communication) */
721
 
        phy_write(priv->tbiphy, MII_TBICON, TBICON_CLK_SELECT);
 
717
        phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
722
718
 
723
 
        phy_write(priv->tbiphy, MII_ADVERTISE,
 
719
        phy_write(tbiphy, MII_ADVERTISE,
724
720
                        ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
725
721
                        ADVERTISE_1000XPSE_ASYM);
726
722
 
727
 
        phy_write(priv->tbiphy, MII_BMCR, BMCR_ANENABLE |
 
723
        phy_write(tbiphy, MII_BMCR, BMCR_ANENABLE |
728
724
                        BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
729
725
}
730
726
 
838
834
                free_irq(priv->interruptTransmit, dev);
839
835
                free_irq(priv->interruptReceive, dev);
840
836
        } else {
841
 
                free_irq(priv->interruptTransmit, dev);
 
837
                free_irq(priv->interruptTransmit, dev);
842
838
        }
843
839
 
844
840
        free_skb_resources(priv);
845
841
 
846
 
        dma_free_coherent(&dev->dev,
 
842
        dma_free_coherent(&priv->ofdev->dev,
847
843
                        sizeof(struct txbd8)*priv->tx_ring_size
848
844
                        + sizeof(struct rxbd8)*priv->rx_ring_size,
849
845
                        priv->tx_bd_base,
865
861
                if (!priv->tx_skbuff[i])
866
862
                        continue;
867
863
 
868
 
                dma_unmap_single(&priv->dev->dev, txbdp->bufPtr,
 
864
                dma_unmap_single(&priv->ofdev->dev, txbdp->bufPtr,
869
865
                                txbdp->length, DMA_TO_DEVICE);
870
866
                txbdp->lstatus = 0;
871
867
                for (j = 0; j < skb_shinfo(priv->tx_skbuff[i])->nr_frags; j++) {
872
868
                        txbdp++;
873
 
                        dma_unmap_page(&priv->dev->dev, txbdp->bufPtr,
 
869
                        dma_unmap_page(&priv->ofdev->dev, txbdp->bufPtr,
874
870
                                        txbdp->length, DMA_TO_DEVICE);
875
871
                }
876
872
                txbdp++;
887
883
        if(priv->rx_skbuff != NULL) {
888
884
                for (i = 0; i < priv->rx_ring_size; i++) {
889
885
                        if (priv->rx_skbuff[i]) {
890
 
                                dma_unmap_single(&priv->dev->dev, rxbdp->bufPtr,
 
886
                                dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
891
887
                                                priv->rx_buffer_size,
892
888
                                                DMA_FROM_DEVICE);
893
889
 
953
949
        gfar_write(&regs->imask, IMASK_INIT_CLEAR);
954
950
 
955
951
        /* Allocate memory for the buffer descriptors */
956
 
        vaddr = (unsigned long) dma_alloc_coherent(&dev->dev,
 
952
        vaddr = (unsigned long) dma_alloc_coherent(&priv->ofdev->dev,
957
953
                        sizeof (struct txbd8) * priv->tx_ring_size +
958
954
                        sizeof (struct rxbd8) * priv->rx_ring_size,
959
955
                        &addr, GFP_KERNEL);
1165
1161
rx_skb_fail:
1166
1162
        free_skb_resources(priv);
1167
1163
tx_skb_fail:
1168
 
        dma_free_coherent(&dev->dev,
 
1164
        dma_free_coherent(&priv->ofdev->dev,
1169
1165
                        sizeof(struct txbd8)*priv->tx_ring_size
1170
1166
                        + sizeof(struct rxbd8)*priv->rx_ring_size,
1171
1167
                        priv->tx_bd_base,
1183
1179
 
1184
1180
        napi_enable(&priv->napi);
1185
1181
 
 
1182
        skb_queue_head_init(&priv->rx_recycle);
 
1183
 
1186
1184
        /* Initialize a bunch of registers */
1187
1185
        init_registers(dev);
1188
1186
 
1203
1201
 
1204
1202
        netif_start_queue(dev);
1205
1203
 
 
1204
        device_set_wakeup_enable(&dev->dev, priv->wol_en);
 
1205
 
1206
1206
        return err;
1207
1207
}
1208
1208
 
1209
1209
static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
1210
1210
{
1211
 
        struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
 
1211
        struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
1212
1212
 
1213
 
        cacheable_memzero(fcb, GMAC_FCB_LEN);
 
1213
        memset(fcb, 0, GMAC_FCB_LEN);
1214
1214
 
1215
1215
        return fcb;
1216
1216
}
1278
1278
 
1279
1279
        base = priv->tx_bd_base;
1280
1280
 
 
1281
        /* make space for additional header when fcb is needed */
 
1282
        if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
 
1283
                        (priv->vlgrp && vlan_tx_tag_present(skb))) &&
 
1284
                        (skb_headroom(skb) < GMAC_FCB_LEN)) {
 
1285
                struct sk_buff *skb_new;
 
1286
 
 
1287
                skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
 
1288
                if (!skb_new) {
 
1289
                        dev->stats.tx_errors++;
 
1290
                        kfree_skb(skb);
 
1291
                        return NETDEV_TX_OK;
 
1292
                }
 
1293
                kfree_skb(skb);
 
1294
                skb = skb_new;
 
1295
        }
 
1296
 
1281
1297
        /* total number of fragments in the SKB */
1282
1298
        nr_frags = skb_shinfo(skb)->nr_frags;
1283
1299
 
1314
1330
                        if (i == nr_frags - 1)
1315
1331
                                lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
1316
1332
 
1317
 
                        bufaddr = dma_map_page(&dev->dev,
 
1333
                        bufaddr = dma_map_page(&priv->ofdev->dev,
1318
1334
                                        skb_shinfo(skb)->frags[i].page,
1319
1335
                                        skb_shinfo(skb)->frags[i].page_offset,
1320
1336
                                        length,
1346
1362
 
1347
1363
        /* setup the TxBD length and buffer pointer for the first BD */
1348
1364
        priv->tx_skbuff[priv->skb_curtx] = skb;
1349
 
        txbdp_start->bufPtr = dma_map_single(&dev->dev, skb->data,
 
1365
        txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
1350
1366
                        skb_headlen(skb), DMA_TO_DEVICE);
1351
1367
 
1352
1368
        lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
1389
1405
        /* Unlock priv */
1390
1406
        spin_unlock_irqrestore(&priv->txlock, flags);
1391
1407
 
1392
 
        return 0;
 
1408
        return NETDEV_TX_OK;
1393
1409
}
1394
1410
 
1395
1411
/* Stops the kernel queue, and halts the controller */
1399
1415
 
1400
1416
        napi_disable(&priv->napi);
1401
1417
 
 
1418
        skb_queue_purge(&priv->rx_recycle);
1402
1419
        cancel_work_sync(&priv->reset_task);
1403
1420
        stop_gfar(dev);
1404
1421
 
1531
1548
{
1532
1549
        struct gfar_private *priv = container_of(work, struct gfar_private,
1533
1550
                        reset_task);
1534
 
        struct net_device *dev = priv->dev;
 
1551
        struct net_device *dev = priv->ndev;
1535
1552
 
1536
1553
        if (dev->flags & IFF_UP) {
 
1554
                netif_stop_queue(dev);
1537
1555
                stop_gfar(dev);
1538
1556
                startup_gfar(dev);
 
1557
                netif_start_queue(dev);
1539
1558
        }
1540
1559
 
1541
1560
        netif_tx_schedule_all(dev);
1578
1597
                                (lstatus & BD_LENGTH_MASK))
1579
1598
                        break;
1580
1599
 
1581
 
                dma_unmap_single(&dev->dev,
 
1600
                dma_unmap_single(&priv->ofdev->dev,
1582
1601
                                bdp->bufPtr,
1583
1602
                                bdp->length,
1584
1603
                                DMA_TO_DEVICE);
1587
1606
                bdp = next_txbd(bdp, base, tx_ring_size);
1588
1607
 
1589
1608
                for (i = 0; i < frags; i++) {
1590
 
                        dma_unmap_page(&dev->dev,
 
1609
                        dma_unmap_page(&priv->ofdev->dev,
1591
1610
                                        bdp->bufPtr,
1592
1611
                                        bdp->length,
1593
1612
                                        DMA_TO_DEVICE);
1595
1614
                        bdp = next_txbd(bdp, base, tx_ring_size);
1596
1615
                }
1597
1616
 
1598
 
                dev_kfree_skb_any(skb);
 
1617
                /*
 
1618
                 * If there's room in the queue (limit it to rx_buffer_size)
 
1619
                 * we add this skb back into the pool, if it's the right size
 
1620
                 */
 
1621
                if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
 
1622
                                skb_recycle_check(skb, priv->rx_buffer_size +
 
1623
                                        RXBUF_ALIGNMENT))
 
1624
                        __skb_queue_head(&priv->rx_recycle, skb);
 
1625
                else
 
1626
                        dev_kfree_skb_any(skb);
 
1627
 
1599
1628
                priv->tx_skbuff[skb_dirtytx] = NULL;
1600
1629
 
1601
1630
                skb_dirtytx = (skb_dirtytx + 1) &
1626
1655
        spin_lock_irqsave(&priv->txlock, flags);
1627
1656
        spin_lock(&priv->rxlock);
1628
1657
 
1629
 
        if (netif_rx_schedule_prep(&priv->napi)) {
 
1658
        if (napi_schedule_prep(&priv->napi)) {
1630
1659
                gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
1631
 
                __netif_rx_schedule(&priv->napi);
 
1660
                __napi_schedule(&priv->napi);
1632
1661
        } else {
1633
1662
                /*
1634
1663
                 * Clear IEVENT, so interrupts aren't called again
1654
1683
        struct gfar_private *priv = netdev_priv(dev);
1655
1684
        u32 lstatus;
1656
1685
 
1657
 
        bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
 
1686
        bdp->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
1658
1687
                        priv->rx_buffer_size, DMA_FROM_DEVICE);
1659
1688
 
1660
1689
        lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
1674
1703
        struct gfar_private *priv = netdev_priv(dev);
1675
1704
        struct sk_buff *skb = NULL;
1676
1705
 
1677
 
        /* We have to allocate the skb, so keep trying till we succeed */
1678
 
        skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
 
1706
        skb = __skb_dequeue(&priv->rx_recycle);
 
1707
        if (!skb)
 
1708
                skb = netdev_alloc_skb(dev,
 
1709
                                priv->rx_buffer_size + RXBUF_ALIGNMENT);
1679
1710
 
1680
1711
        if (!skb)
1681
1712
                return NULL;
1812
1843
 
1813
1844
                skb = priv->rx_skbuff[priv->skb_currx];
1814
1845
 
1815
 
                dma_unmap_single(&priv->dev->dev, bdp->bufPtr,
 
1846
                dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
1816
1847
                                priv->rx_buffer_size, DMA_FROM_DEVICE);
1817
1848
 
1818
1849
                /* We drop the frame if we failed to allocate a new buffer */
1822
1853
 
1823
1854
                        if (unlikely(!newskb))
1824
1855
                                newskb = skb;
1825
 
                        else if (skb)
1826
 
                                dev_kfree_skb_any(skb);
 
1856
                        else if (skb) {
 
1857
                                /*
 
1858
                                 * We need to reset ->data to what it
 
1859
                                 * was before gfar_new_skb() re-aligned
 
1860
                                 * it to an RXBUF_ALIGNMENT boundary
 
1861
                                 * before we put the skb back on the
 
1862
                                 * recycle list.
 
1863
                                 */
 
1864
                                skb->data = skb->head + NET_SKB_PAD;
 
1865
                                __skb_queue_head(&priv->rx_recycle, skb);
 
1866
                        }
1827
1867
                } else {
1828
1868
                        /* Increment the number of packets */
1829
1869
                        dev->stats.rx_packets++;
1835
1875
                                skb_put(skb, pkt_len);
1836
1876
                                dev->stats.rx_bytes += pkt_len;
1837
1877
 
 
1878
                                if (in_irq() || irqs_disabled())
 
1879
                                        printk("Interrupt problem!\n");
1838
1880
                                gfar_process_frame(dev, skb, amount_pull);
1839
1881
 
1840
1882
                        } else {
1870
1912
static int gfar_poll(struct napi_struct *napi, int budget)
1871
1913
{
1872
1914
        struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
1873
 
        struct net_device *dev = priv->dev;
 
1915
        struct net_device *dev = priv->ndev;
1874
1916
        int tx_cleaned = 0;
1875
1917
        int rx_cleaned = 0;
1876
1918
        unsigned long flags;
1891
1933
                return budget;
1892
1934
 
1893
1935
        if (rx_cleaned < budget) {
1894
 
                netif_rx_complete(napi);
 
1936
                napi_complete(napi);
1895
1937
 
1896
1938
                /* Clear the halt bit in RSTAT */
1897
1939
                gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
2308
2350
 
2309
2351
static int __init gfar_init(void)
2310
2352
{
2311
 
        int err = gfar_mdio_init();
2312
 
 
2313
 
        if (err)
2314
 
                return err;
2315
 
 
2316
 
        err = of_register_platform_driver(&gfar_driver);
2317
 
 
2318
 
        if (err)
2319
 
                gfar_mdio_exit();
2320
 
 
2321
 
        return err;
 
2353
        return of_register_platform_driver(&gfar_driver);
2322
2354
}
2323
2355
 
2324
2356
static void __exit gfar_exit(void)
2325
2357
{
2326
2358
        of_unregister_platform_driver(&gfar_driver);
2327
 
        gfar_mdio_exit();
2328
2359
}
2329
2360
 
2330
2361
module_init(gfar_init);