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

« back to all changes in this revision

Viewing changes to drivers/net/myri10ge/myri10ge.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:
65
65
#include <linux/io.h>
66
66
#include <linux/log2.h>
67
67
#include <linux/slab.h>
 
68
#include <linux/prefetch.h>
68
69
#include <net/checksum.h>
69
70
#include <net/ip.h>
70
71
#include <net/tcp.h>
205
206
        int tx_boundary;        /* boundary transmits cannot cross */
206
207
        int num_slices;
207
208
        int running;            /* running?             */
208
 
        int csum_flag;          /* rx_csums?            */
209
209
        int small_bytes;
210
210
        int big_bytes;
211
211
        int max_intr_slots;
253
253
        unsigned long serial_number;
254
254
        int vendor_specific_offset;
255
255
        int fw_multicast_support;
256
 
        unsigned long features;
 
256
        u32 features;
257
257
        u32 max_tso6;
258
258
        u32 read_dma;
259
259
        u32 write_dma;
1312
1312
                                 * page into an skb */
1313
1313
 
1314
1314
static inline int
1315
 
myri10ge_rx_done(struct myri10ge_slice_state *ss, struct myri10ge_rx_buf *rx,
1316
 
                 int bytes, int len, __wsum csum)
 
1315
myri10ge_rx_done(struct myri10ge_slice_state *ss, int len, __wsum csum,
 
1316
                 int lro_enabled)
1317
1317
{
1318
1318
        struct myri10ge_priv *mgp = ss->mgp;
1319
1319
        struct sk_buff *skb;
1320
1320
        struct skb_frag_struct rx_frags[MYRI10GE_MAX_FRAGS_PER_FRAME];
1321
 
        int i, idx, hlen, remainder;
 
1321
        struct myri10ge_rx_buf *rx;
 
1322
        int i, idx, hlen, remainder, bytes;
1322
1323
        struct pci_dev *pdev = mgp->pdev;
1323
1324
        struct net_device *dev = mgp->dev;
1324
1325
        u8 *va;
1325
1326
 
 
1327
        if (len <= mgp->small_bytes) {
 
1328
                rx = &ss->rx_small;
 
1329
                bytes = mgp->small_bytes;
 
1330
        } else {
 
1331
                rx = &ss->rx_big;
 
1332
                bytes = mgp->big_bytes;
 
1333
        }
 
1334
 
1326
1335
        len += MXGEFW_PAD;
1327
1336
        idx = rx->cnt & rx->mask;
1328
1337
        va = page_address(rx->info[idx].page) + rx->info[idx].page_offset;
1341
1350
                remainder -= MYRI10GE_ALLOC_SIZE;
1342
1351
        }
1343
1352
 
1344
 
        if (dev->features & NETIF_F_LRO) {
 
1353
        if (lro_enabled) {
1345
1354
                rx_frags[0].page_offset += MXGEFW_PAD;
1346
1355
                rx_frags[0].size -= MXGEFW_PAD;
1347
1356
                len -= MXGEFW_PAD;
1377
1386
        skb->protocol = eth_type_trans(skb, dev);
1378
1387
        skb_record_rx_queue(skb, ss - &mgp->ss[0]);
1379
1388
 
1380
 
        if (mgp->csum_flag) {
 
1389
        if (dev->features & NETIF_F_RXCSUM) {
1381
1390
                if ((skb->protocol == htons(ETH_P_IP)) ||
1382
1391
                    (skb->protocol == htons(ETH_P_IPV6))) {
1383
1392
                        skb->csum = csum;
1463
1472
{
1464
1473
        struct myri10ge_rx_done *rx_done = &ss->rx_done;
1465
1474
        struct myri10ge_priv *mgp = ss->mgp;
1466
 
        struct net_device *netdev = mgp->dev;
 
1475
 
1467
1476
        unsigned long rx_bytes = 0;
1468
1477
        unsigned long rx_packets = 0;
1469
1478
        unsigned long rx_ok;
1474
1483
        u16 length;
1475
1484
        __wsum checksum;
1476
1485
 
 
1486
        /*
 
1487
         * Prevent compiler from generating more than one ->features memory
 
1488
         * access to avoid theoretical race condition with functions that
 
1489
         * change NETIF_F_LRO flag at runtime.
 
1490
         */
 
1491
        bool lro_enabled = ACCESS_ONCE(mgp->dev->features) & NETIF_F_LRO;
 
1492
 
1477
1493
        while (rx_done->entry[idx].length != 0 && work_done < budget) {
1478
1494
                length = ntohs(rx_done->entry[idx].length);
1479
1495
                rx_done->entry[idx].length = 0;
1480
1496
                checksum = csum_unfold(rx_done->entry[idx].checksum);
1481
 
                if (length <= mgp->small_bytes)
1482
 
                        rx_ok = myri10ge_rx_done(ss, &ss->rx_small,
1483
 
                                                 mgp->small_bytes,
1484
 
                                                 length, checksum);
1485
 
                else
1486
 
                        rx_ok = myri10ge_rx_done(ss, &ss->rx_big,
1487
 
                                                 mgp->big_bytes,
1488
 
                                                 length, checksum);
 
1497
                rx_ok = myri10ge_rx_done(ss, length, checksum, lro_enabled);
1489
1498
                rx_packets += rx_ok;
1490
1499
                rx_bytes += rx_ok * (unsigned long)length;
1491
1500
                cnt++;
1497
1506
        ss->stats.rx_packets += rx_packets;
1498
1507
        ss->stats.rx_bytes += rx_bytes;
1499
1508
 
1500
 
        if (netdev->features & NETIF_F_LRO)
 
1509
        if (lro_enabled)
1501
1510
                lro_flush_all(&rx_done->lro_mgr);
1502
1511
 
1503
1512
        /* restock receive rings if needed */
1636
1645
        int i;
1637
1646
 
1638
1647
        cmd->autoneg = AUTONEG_DISABLE;
1639
 
        cmd->speed = SPEED_10000;
 
1648
        ethtool_cmd_speed_set(cmd, SPEED_10000);
1640
1649
        cmd->duplex = DUPLEX_FULL;
1641
1650
 
1642
1651
        /*
1748
1757
        ring->tx_pending = ring->tx_max_pending;
1749
1758
}
1750
1759
 
1751
 
static u32 myri10ge_get_rx_csum(struct net_device *netdev)
1752
 
{
1753
 
        struct myri10ge_priv *mgp = netdev_priv(netdev);
1754
 
 
1755
 
        if (mgp->csum_flag)
1756
 
                return 1;
1757
 
        else
1758
 
                return 0;
1759
 
}
1760
 
 
1761
 
static int myri10ge_set_rx_csum(struct net_device *netdev, u32 csum_enabled)
1762
 
{
1763
 
        struct myri10ge_priv *mgp = netdev_priv(netdev);
1764
 
        int err = 0;
1765
 
 
1766
 
        if (csum_enabled)
1767
 
                mgp->csum_flag = MXGEFW_FLAGS_CKSUM;
1768
 
        else {
1769
 
                netdev->features &= ~NETIF_F_LRO;
1770
 
                mgp->csum_flag = 0;
1771
 
 
1772
 
        }
1773
 
        return err;
1774
 
}
1775
 
 
1776
 
static int myri10ge_set_tso(struct net_device *netdev, u32 tso_enabled)
1777
 
{
1778
 
        struct myri10ge_priv *mgp = netdev_priv(netdev);
1779
 
        unsigned long flags = mgp->features & (NETIF_F_TSO6 | NETIF_F_TSO);
1780
 
 
1781
 
        if (tso_enabled)
1782
 
                netdev->features |= flags;
1783
 
        else
1784
 
                netdev->features &= ~flags;
1785
 
        return 0;
1786
 
}
1787
 
 
1788
1760
static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
1789
1761
        "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
1790
1762
        "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
1935
1907
        return mgp->msg_enable;
1936
1908
}
1937
1909
 
1938
 
static int myri10ge_set_flags(struct net_device *netdev, u32 value)
1939
 
{
1940
 
        return ethtool_op_set_flags(netdev, value, ETH_FLAG_LRO);
1941
 
}
1942
 
 
1943
1910
static const struct ethtool_ops myri10ge_ethtool_ops = {
1944
1911
        .get_settings = myri10ge_get_settings,
1945
1912
        .get_drvinfo = myri10ge_get_drvinfo,
1948
1915
        .get_pauseparam = myri10ge_get_pauseparam,
1949
1916
        .set_pauseparam = myri10ge_set_pauseparam,
1950
1917
        .get_ringparam = myri10ge_get_ringparam,
1951
 
        .get_rx_csum = myri10ge_get_rx_csum,
1952
 
        .set_rx_csum = myri10ge_set_rx_csum,
1953
 
        .set_tx_csum = ethtool_op_set_tx_hw_csum,
1954
 
        .set_sg = ethtool_op_set_sg,
1955
 
        .set_tso = myri10ge_set_tso,
1956
1918
        .get_link = ethtool_op_get_link,
1957
1919
        .get_strings = myri10ge_get_strings,
1958
1920
        .get_sset_count = myri10ge_get_sset_count,
1959
1921
        .get_ethtool_stats = myri10ge_get_ethtool_stats,
1960
1922
        .set_msglevel = myri10ge_set_msglevel,
1961
1923
        .get_msglevel = myri10ge_get_msglevel,
1962
 
        .get_flags = ethtool_op_get_flags,
1963
 
        .set_flags = myri10ge_set_flags
1964
1924
};
1965
1925
 
1966
1926
static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss)
3127
3087
        return 0;
3128
3088
}
3129
3089
 
 
3090
static u32 myri10ge_fix_features(struct net_device *dev, u32 features)
 
3091
{
 
3092
        if (!(features & NETIF_F_RXCSUM))
 
3093
                features &= ~NETIF_F_LRO;
 
3094
 
 
3095
        return features;
 
3096
}
 
3097
 
3130
3098
static int myri10ge_change_mtu(struct net_device *dev, int new_mtu)
3131
3099
{
3132
3100
        struct myri10ge_priv *mgp = netdev_priv(dev);
3693
3661
 
3694
3662
/*
3695
3663
 * This function determines the number of slices supported.
3696
 
 * The number slices is the minumum of the number of CPUS,
 
3664
 * The number slices is the minimum of the number of CPUS,
3697
3665
 * the number of MSI-X irqs supported, the number of slices
3698
3666
 * supported by the firmware
3699
3667
 */
3825
3793
        .ndo_get_stats          = myri10ge_get_stats,
3826
3794
        .ndo_validate_addr      = eth_validate_addr,
3827
3795
        .ndo_change_mtu         = myri10ge_change_mtu,
 
3796
        .ndo_fix_features       = myri10ge_fix_features,
3828
3797
        .ndo_set_multicast_list = myri10ge_set_multicast_list,
3829
3798
        .ndo_set_mac_address    = myri10ge_set_mac_address,
3830
3799
};
3851
3820
        mgp = netdev_priv(netdev);
3852
3821
        mgp->dev = netdev;
3853
3822
        mgp->pdev = pdev;
3854
 
        mgp->csum_flag = MXGEFW_FLAGS_CKSUM;
3855
3823
        mgp->pause = myri10ge_flow_control;
3856
3824
        mgp->intr_coal_delay = myri10ge_intr_coal_delay;
3857
3825
        mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT);
3967
3935
        netdev->netdev_ops = &myri10ge_netdev_ops;
3968
3936
        netdev->mtu = myri10ge_initial_mtu;
3969
3937
        netdev->base_addr = mgp->iomem_base;
3970
 
        netdev->features = mgp->features;
 
3938
        netdev->hw_features = mgp->features | NETIF_F_LRO | NETIF_F_RXCSUM;
 
3939
        netdev->features = netdev->hw_features;
3971
3940
 
3972
3941
        if (dac_enabled)
3973
3942
                netdev->features |= NETIF_F_HIGHDMA;
3974
 
        netdev->features |= NETIF_F_LRO;
3975
3943
 
3976
3944
        netdev->vlan_features |= mgp->features;
3977
3945
        if (mgp->fw_ver_tiny < 37)