~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/stmmac/stmmac_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include <linux/if_vlan.h>
46
46
#include <linux/dma-mapping.h>
47
47
#include <linux/slab.h>
 
48
#include <linux/prefetch.h>
48
49
#include "stmmac.h"
49
50
 
50
51
#define STMMAC_RESOURCE_NAME    "stmmaceth"
116
117
module_param(tc, int, S_IRUGO | S_IWUSR);
117
118
MODULE_PARM_DESC(tc, "DMA threshold control value");
118
119
 
119
 
#define RX_NO_COALESCE  1       /* Always interrupt on completion */
120
 
#define TX_NO_COALESCE  -1      /* No moderation by default */
121
 
 
122
120
/* Pay attention to tune this parameter; take care of both
123
121
 * hardware capability and network stabitily/performance impact.
124
122
 * Many tests showed that ~4ms latency seems to be good enough. */
139
137
                                      NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
140
138
 
141
139
static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
142
 
static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev);
143
140
 
144
141
/**
145
142
 * stmmac_verify_args - verify the driver parameters.
750
747
                        priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
751
748
                        priv->xstats.threshold = tc;
752
749
                }
753
 
                stmmac_tx_err(priv);
754
750
        } else if (unlikely(status == tx_hard_error))
755
751
                stmmac_tx_err(priv);
756
752
}
781
777
 
782
778
        stmmac_verify_args();
783
779
 
784
 
        ret = stmmac_init_phy(dev);
785
 
        if (unlikely(ret)) {
786
 
                pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
787
 
                return ret;
788
 
        }
789
 
 
790
 
        /* Request the IRQ lines */
791
 
        ret = request_irq(dev->irq, stmmac_interrupt,
792
 
                          IRQF_SHARED, dev->name, dev);
793
 
        if (unlikely(ret < 0)) {
794
 
                pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
795
 
                       __func__, dev->irq, ret);
796
 
                return ret;
797
 
        }
798
 
 
799
780
#ifdef CONFIG_STMMAC_TIMER
800
781
        priv->tm = kzalloc(sizeof(struct stmmac_timer *), GFP_KERNEL);
801
782
        if (unlikely(priv->tm == NULL)) {
814
795
        } else
815
796
                priv->tm->enable = 1;
816
797
#endif
 
798
        ret = stmmac_init_phy(dev);
 
799
        if (unlikely(ret)) {
 
800
                pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
 
801
                goto open_error;
 
802
        }
817
803
 
818
804
        /* Create and initialize the TX/RX descriptors chains. */
819
805
        priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
822
808
        init_dma_desc_rings(dev);
823
809
 
824
810
        /* DMA initialization and SW reset */
825
 
        if (unlikely(priv->hw->dma->init(priv->ioaddr, priv->plat->pbl,
826
 
                                         priv->dma_tx_phy,
827
 
                                         priv->dma_rx_phy) < 0)) {
828
 
 
 
811
        ret = priv->hw->dma->init(priv->ioaddr, priv->plat->pbl,
 
812
                                  priv->dma_tx_phy, priv->dma_rx_phy);
 
813
        if (ret < 0) {
829
814
                pr_err("%s: DMA initialization failed\n", __func__);
830
 
                return -1;
 
815
                goto open_error;
831
816
        }
832
817
 
833
818
        /* Copy the MAC addr into the HW  */
843
828
                pr_info("stmmac: Rx Checksum Offload Engine supported\n");
844
829
        if (priv->plat->tx_coe)
845
830
                pr_info("\tTX Checksum insertion supported\n");
 
831
        netdev_update_features(dev);
846
832
 
847
833
        /* Initialise the MMC (if present) to disable all interrupts. */
848
834
        writel(0xffffffff, priv->ioaddr + MMC_HIGH_INTR_MASK);
849
835
        writel(0xffffffff, priv->ioaddr + MMC_LOW_INTR_MASK);
850
836
 
 
837
        /* Request the IRQ lines */
 
838
        ret = request_irq(dev->irq, stmmac_interrupt,
 
839
                         IRQF_SHARED, dev->name, dev);
 
840
        if (unlikely(ret < 0)) {
 
841
                pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
 
842
                       __func__, dev->irq, ret);
 
843
                goto open_error;
 
844
        }
 
845
 
851
846
        /* Enable the MAC Rx/Tx */
852
847
        stmmac_enable_mac(priv->ioaddr);
853
848
 
878
873
        napi_enable(&priv->napi);
879
874
        skb_queue_head_init(&priv->rx_recycle);
880
875
        netif_start_queue(dev);
 
876
 
881
877
        return 0;
 
878
 
 
879
open_error:
 
880
#ifdef CONFIG_STMMAC_TIMER
 
881
        kfree(priv->tm);
 
882
#endif
 
883
        if (priv->phydev)
 
884
                phy_disconnect(priv->phydev);
 
885
 
 
886
        return ret;
882
887
}
883
888
 
884
889
/**
927
932
        return 0;
928
933
}
929
934
 
930
 
/*
931
 
 * To perform emulated hardware segmentation on skb.
932
 
 */
933
 
static int stmmac_sw_tso(struct stmmac_priv *priv, struct sk_buff *skb)
934
 
{
935
 
        struct sk_buff *segs, *curr_skb;
936
 
        int gso_segs = skb_shinfo(skb)->gso_segs;
937
 
 
938
 
        /* Estimate the number of fragments in the worst case */
939
 
        if (unlikely(stmmac_tx_avail(priv) < gso_segs)) {
940
 
                netif_stop_queue(priv->dev);
941
 
                TX_DBG(KERN_ERR "%s: TSO BUG! Tx Ring full when queue awake\n",
942
 
                       __func__);
943
 
                if (stmmac_tx_avail(priv) < gso_segs)
944
 
                        return NETDEV_TX_BUSY;
945
 
 
946
 
                netif_wake_queue(priv->dev);
947
 
        }
948
 
        TX_DBG("\tstmmac_sw_tso: segmenting: skb %p (len %d)\n",
949
 
               skb, skb->len);
950
 
 
951
 
        segs = skb_gso_segment(skb, priv->dev->features & ~NETIF_F_TSO);
952
 
        if (IS_ERR(segs))
953
 
                goto sw_tso_end;
954
 
 
955
 
        do {
956
 
                curr_skb = segs;
957
 
                segs = segs->next;
958
 
                TX_DBG("\t\tcurrent skb->len: %d, *curr %p,"
959
 
                       "*next %p\n", curr_skb->len, curr_skb, segs);
960
 
                curr_skb->next = NULL;
961
 
                stmmac_xmit(curr_skb, priv->dev);
962
 
        } while (segs);
963
 
 
964
 
sw_tso_end:
965
 
        dev_kfree_skb(skb);
966
 
 
967
 
        return NETDEV_TX_OK;
968
 
}
969
 
 
970
935
static unsigned int stmmac_handle_jumbo_frames(struct sk_buff *skb,
971
936
                                               struct net_device *dev,
972
937
                                               int csum_insertion)
1044
1009
                       !skb_is_gso(skb) ? "isn't" : "is");
1045
1010
#endif
1046
1011
 
1047
 
        if (unlikely(skb_is_gso(skb)))
1048
 
                return stmmac_sw_tso(priv, skb);
1049
 
 
1050
 
        if (likely((skb->ip_summed == CHECKSUM_PARTIAL))) {
1051
 
                if (unlikely((!priv->plat->tx_coe) ||
1052
 
                             (priv->no_csum_insertion)))
1053
 
                        skb_checksum_help(skb);
1054
 
                else
1055
 
                        csum_insertion = 1;
1056
 
        }
 
1012
        csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
1057
1013
 
1058
1014
        desc = priv->dma_tx + entry;
1059
1015
        first = desc;
1373
1329
                return -EINVAL;
1374
1330
        }
1375
1331
 
 
1332
        dev->mtu = new_mtu;
 
1333
        netdev_update_features(dev);
 
1334
 
 
1335
        return 0;
 
1336
}
 
1337
 
 
1338
static u32 stmmac_fix_features(struct net_device *dev, u32 features)
 
1339
{
 
1340
        struct stmmac_priv *priv = netdev_priv(dev);
 
1341
 
 
1342
        if (!priv->rx_coe)
 
1343
                features &= ~NETIF_F_RXCSUM;
 
1344
        if (!priv->plat->tx_coe)
 
1345
                features &= ~NETIF_F_ALL_CSUM;
 
1346
 
1376
1347
        /* Some GMAC devices have a bugged Jumbo frame support that
1377
1348
         * needs to have the Tx COE disabled for oversized frames
1378
1349
         * (due to limited buffer sizes). In this case we disable
1379
1350
         * the TX csum insertionin the TDES and not use SF. */
1380
 
        if ((priv->plat->bugged_jumbo) && (priv->dev->mtu > ETH_DATA_LEN))
1381
 
                priv->no_csum_insertion = 1;
1382
 
        else
1383
 
                priv->no_csum_insertion = 0;
1384
 
 
1385
 
        dev->mtu = new_mtu;
1386
 
 
1387
 
        return 0;
 
1351
        if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
 
1352
                features &= ~NETIF_F_ALL_CSUM;
 
1353
 
 
1354
        return features;
1388
1355
}
1389
1356
 
1390
1357
static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
1464
1431
        .ndo_start_xmit = stmmac_xmit,
1465
1432
        .ndo_stop = stmmac_release,
1466
1433
        .ndo_change_mtu = stmmac_change_mtu,
 
1434
        .ndo_fix_features = stmmac_fix_features,
1467
1435
        .ndo_set_multicast_list = stmmac_multicast_list,
1468
1436
        .ndo_tx_timeout = stmmac_tx_timeout,
1469
1437
        .ndo_do_ioctl = stmmac_ioctl,
1494
1462
        dev->netdev_ops = &stmmac_netdev_ops;
1495
1463
        stmmac_set_ethtool_ops(dev);
1496
1464
 
1497
 
        dev->features |= NETIF_F_SG | NETIF_F_HIGHDMA |
1498
 
                NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 
1465
        dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 
1466
        dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
1499
1467
        dev->watchdog_timeo = msecs_to_jiffies(watchdog);
1500
1468
#ifdef STMMAC_VLAN_TAG_USED
1501
1469
        /* Both mac100 and gmac support receive VLAN tag detection */