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);
144
extern const struct ethtool_ops gfar_ethtool_ops;
144
static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
146
146
MODULE_AUTHOR("Freescale Semiconductor, Inc");
147
147
MODULE_DESCRIPTION("Gianfar Ethernet Driver");
148
148
MODULE_LICENSE("GPL");
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,
150
166
/* Returns 1 if incoming frames use an FCB */
151
167
static inline int gfar_uses_fcb(struct gfar_private *priv)
156
172
static int gfar_of_init(struct net_device *dev)
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;
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];
182
const u32 *stash_len;
183
const u32 *stash_idx;
170
185
if (!np || !of_device_is_available(np))
213
stash = of_get_property(np, "bd-stash", NULL);
216
priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
217
priv->bd_stash_en = 1;
220
stash_len = of_get_property(np, "rx-stash-len", NULL);
223
priv->rx_stash_size = *stash_len;
225
stash_idx = of_get_property(np, "rx-stash-idx", NULL);
228
priv->rx_stash_index = *stash_idx;
230
if (stash_len || stash_idx)
231
priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
198
233
mac_addr = of_get_mac_address(np);
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;
231
ph = of_get_property(np, "phy-handle", NULL);
266
priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
267
if (!priv->phy_node) {
235
270
fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
241
snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id),
242
PHY_ID_FMT, "0", fixed_link[0]);
244
phy = of_find_node_by_phandle(*ph);
251
mdio = of_get_parent(phy);
253
id = of_get_property(phy, "reg", NULL);
258
gfar_mdio_bus_name(bus_name, mdio);
259
snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id), "%s:%02x",
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);
266
struct device_node *tbi = of_find_node_by_phandle(*ph);
267
struct of_device *ofdev;
273
mdio = of_get_parent(tbi);
277
ofdev = of_find_device_by_node(mdio);
281
id = of_get_property(tbi, "reg", NULL);
287
bus = dev_get_drvdata(&ofdev->dev);
289
priv->tbiphy = bus->phy_map[*id];
278
priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
369
359
SET_NETDEV_DEV(dev, &ofdev->dev);
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;
380
dev->stop = gfar_close;
381
dev->change_mtu = gfar_change_mtu;
383
dev->set_multicast_list = gfar_set_multi;
366
dev->netdev_ops = &gfar_netdev_ops;
385
367
dev->ethtool_ops = &gfar_ethtool_ops;
386
dev->do_ioctl = gfar_ioctl;
388
369
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
389
370
priv->rx_csum_enable = 1;
394
375
priv->vlgrp = NULL;
396
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
397
dev->vlan_rx_register = gfar_vlan_rx_register;
377
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN)
399
378
dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
402
380
if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
403
381
priv->extended_hash = 1;
425
403
priv->hash_width = 8;
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;
447
device_init_wakeup(&dev->dev,
448
priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
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);
509
494
struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
497
of_node_put(priv->phy_node);
499
of_node_put(priv->tbi_node);
511
501
dev_set_drvdata(&ofdev->dev, NULL);
513
503
iounmap(priv->regs);
514
free_netdev(priv->dev);
504
free_netdev(priv->ndev);
520
510
static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
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;
569
559
static int gfar_resume(struct of_device *ofdev)
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;
575
565
int magic_packet = priv->wol_en &&
671
660
interface = gfar_get_interface(dev);
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,
666
dev_err(&dev->dev, "error: Could not attach to PHY\n");
675
671
if (interface == PHY_INTERFACE_MODE_SGMII)
676
672
gfar_configure_serdes(dev);
678
if (IS_ERR(phydev)) {
679
printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
680
return PTR_ERR(phydev);
683
674
/* Remove any features not supported by the controller */
684
phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
685
phydev->advertising = phydev->supported;
687
priv->phydev = phydev;
675
priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
676
priv->phydev->advertising = priv->phydev->supported;
701
690
static void gfar_configure_serdes(struct net_device *dev)
703
692
struct gfar_private *priv = netdev_priv(dev);
706
printk(KERN_WARNING "SGMII mode requires that the device "
707
"tree specify a tbi-handle\n");
693
struct phy_device *tbiphy;
695
if (!priv->tbi_node) {
696
dev_warn(&dev->dev, "error: SGMII mode requires that the "
697
"device tree specify a tbi-handle\n");
701
tbiphy = of_phy_find_device(priv->tbi_node);
703
dev_err(&dev->dev, "error: Could not get TBI device\n");
714
710
* everything for us? Resetting it takes the link down and requires
715
711
* several seconds for it to come back.
717
if (phy_read(priv->tbiphy, MII_BMSR) & BMSR_LSTATUS)
713
if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
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);
723
phy_write(priv->tbiphy, MII_ADVERTISE,
719
phy_write(tbiphy, MII_ADVERTISE,
724
720
ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
725
721
ADVERTISE_1000XPSE_ASYM);
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);
838
834
free_irq(priv->interruptTransmit, dev);
839
835
free_irq(priv->interruptReceive, dev);
841
free_irq(priv->interruptTransmit, dev);
837
free_irq(priv->interruptTransmit, dev);
844
840
free_skb_resources(priv);
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])
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++) {
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);
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);
953
949
gfar_write(®s->imask, IMASK_INIT_CLEAR);
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);
1166
1162
free_skb_resources(priv);
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,
1204
1202
netif_start_queue(dev);
1204
device_set_wakeup_enable(&dev->dev, priv->wol_en);
1209
1209
static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
1211
struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
1211
struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
1213
cacheable_memzero(fcb, GMAC_FCB_LEN);
1213
memset(fcb, 0, GMAC_FCB_LEN);
1279
1279
base = priv->tx_bd_base;
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;
1287
skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
1289
dev->stats.tx_errors++;
1291
return NETDEV_TX_OK;
1281
1297
/* total number of fragments in the SKB */
1282
1298
nr_frags = skb_shinfo(skb)->nr_frags;
1314
1330
if (i == nr_frags - 1)
1315
1331
lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
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,
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);
1352
1368
lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
1532
1549
struct gfar_private *priv = container_of(work, struct gfar_private,
1534
struct net_device *dev = priv->dev;
1551
struct net_device *dev = priv->ndev;
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);
1541
1560
netif_tx_schedule_all(dev);
1587
1606
bdp = next_txbd(bdp, base, tx_ring_size);
1589
1608
for (i = 0; i < frags; i++) {
1590
dma_unmap_page(&dev->dev,
1609
dma_unmap_page(&priv->ofdev->dev,
1593
1612
DMA_TO_DEVICE);
1595
1614
bdp = next_txbd(bdp, base, tx_ring_size);
1598
dev_kfree_skb_any(skb);
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
1621
if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
1622
skb_recycle_check(skb, priv->rx_buffer_size +
1624
__skb_queue_head(&priv->rx_recycle, skb);
1626
dev_kfree_skb_any(skb);
1599
1628
priv->tx_skbuff[skb_dirtytx] = NULL;
1601
1630
skb_dirtytx = (skb_dirtytx + 1) &
1626
1655
spin_lock_irqsave(&priv->txlock, flags);
1627
1656
spin_lock(&priv->rxlock);
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);
1634
1663
* Clear IEVENT, so interrupts aren't called again
1654
1683
struct gfar_private *priv = netdev_priv(dev);
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);
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;
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);
1708
skb = netdev_alloc_skb(dev,
1709
priv->rx_buffer_size + RXBUF_ALIGNMENT);
1813
1844
skb = priv->rx_skbuff[priv->skb_currx];
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);
1818
1849
/* We drop the frame if we failed to allocate a new buffer */
1823
1854
if (unlikely(!newskb))
1826
dev_kfree_skb_any(skb);
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
1864
skb->data = skb->head + NET_SKB_PAD;
1865
__skb_queue_head(&priv->rx_recycle, skb);
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;
1878
if (in_irq() || irqs_disabled())
1879
printk("Interrupt problem!\n");
1838
1880
gfar_process_frame(dev, skb, amount_pull);
1870
1912
static int gfar_poll(struct napi_struct *napi, int budget)
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;
2309
2351
static int __init gfar_init(void)
2311
int err = gfar_mdio_init();
2316
err = of_register_platform_driver(&gfar_driver);
2353
return of_register_platform_driver(&gfar_driver);
2324
2356
static void __exit gfar_exit(void)
2326
2358
of_unregister_platform_driver(&gfar_driver);
2330
2361
module_init(gfar_init);