~ubuntu-branches/ubuntu/precise/linux-lowlatency/precise-proposed

« back to all changes in this revision

Viewing changes to drivers/net/ethernet/emulex/benet/be_main.c

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich, Luke Yelavich, Upstream Kernel Changes
  • Date: 2012-04-04 18:49:36 UTC
  • Revision ID: package-import@ubuntu.com-20120404184936-tqu735914muv4wpg
Tags: 3.2.0-22.30
[ Luke Yelavich ]

* [Config] Update configs after rebase against Ubuntu-3.2.0-22.35

[ Upstream Kernel Changes ]

* Low-latency: Rebase against Ubuntu-3.2.0-22.35

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
MODULE_AUTHOR("ServerEngines Corporation");
28
28
MODULE_LICENSE("GPL");
29
29
 
 
30
static unsigned int num_vfs;
 
31
module_param(num_vfs, uint, S_IRUGO);
 
32
MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize");
 
33
 
30
34
static ushort rx_frag_size = 2048;
31
 
static unsigned int num_vfs;
32
35
module_param(rx_frag_size, ushort, S_IRUGO);
33
 
module_param(num_vfs, uint, S_IRUGO);
34
36
MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data.");
35
 
MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize");
36
37
 
37
38
static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = {
38
39
        { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
41
42
        { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
42
43
        { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)},
43
44
        { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)},
 
45
        { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID5)},
44
46
        { 0 }
45
47
};
46
48
MODULE_DEVICE_TABLE(pci, be_dev_ids);
237
239
                return -EADDRNOTAVAIL;
238
240
 
239
241
        status = be_cmd_mac_addr_query(adapter, current_mac,
240
 
                        MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle);
 
242
                                MAC_ADDRESS_TYPE_NETWORK, false,
 
243
                                adapter->if_handle, 0);
241
244
        if (status)
242
245
                goto err;
243
246
 
315
318
        struct be_drv_stats *drvs = &adapter->drv_stats;
316
319
 
317
320
        be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats));
 
321
        drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop;
 
322
        drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames;
318
323
        drvs->rx_pause_frames = port_stats->rx_pause_frames;
319
324
        drvs->rx_crc_errors = port_stats->rx_crc_errors;
320
325
        drvs->rx_control_frames = port_stats->rx_control_frames;
491
496
        return stats;
492
497
}
493
498
 
494
 
void be_link_status_update(struct be_adapter *adapter, u32 link_status)
 
499
void be_link_status_update(struct be_adapter *adapter, u8 link_status)
495
500
{
496
501
        struct net_device *netdev = adapter->netdev;
497
502
 
498
 
        /* when link status changes, link speed must be re-queried from card */
499
 
        adapter->link_speed = -1;
500
 
        if ((link_status & LINK_STATUS_MASK) == LINK_UP) {
 
503
        if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) {
 
504
                netif_carrier_off(netdev);
 
505
                adapter->flags |= BE_FLAGS_LINK_STATUS_INIT;
 
506
        }
 
507
 
 
508
        if ((link_status & LINK_STATUS_MASK) == LINK_UP)
501
509
                netif_carrier_on(netdev);
502
 
                dev_info(&adapter->pdev->dev, "%s: Link up\n", netdev->name);
503
 
        } else {
 
510
        else
504
511
                netif_carrier_off(netdev);
505
 
                dev_info(&adapter->pdev->dev, "%s: Link down\n", netdev->name);
506
 
        }
507
512
}
508
513
 
509
514
static void be_tx_stats_update(struct be_tx_obj *txo,
549
554
        wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK;
550
555
}
551
556
 
 
557
static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter,
 
558
                                        struct sk_buff *skb)
 
559
{
 
560
        u8 vlan_prio;
 
561
        u16 vlan_tag;
 
562
 
 
563
        vlan_tag = vlan_tx_tag_get(skb);
 
564
        vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
 
565
        /* If vlan priority provided by OS is NOT in available bmap */
 
566
        if (!(adapter->vlan_prio_bmap & (1 << vlan_prio)))
 
567
                vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) |
 
568
                                adapter->recommended_prio;
 
569
 
 
570
        return vlan_tag;
 
571
}
 
572
 
552
573
static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr,
553
574
                struct sk_buff *skb, u32 wrb_cnt, u32 len)
554
575
{
555
 
        u8 vlan_prio = 0;
556
 
        u16 vlan_tag = 0;
 
576
        u16 vlan_tag;
557
577
 
558
578
        memset(hdr, 0, sizeof(*hdr));
559
579
 
584
604
 
585
605
        if (vlan_tx_tag_present(skb)) {
586
606
                AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1);
587
 
                vlan_tag = vlan_tx_tag_get(skb);
588
 
                vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
589
 
                /* If vlan priority provided by OS is NOT in available bmap */
590
 
                if (!(adapter->vlan_prio_bmap & (1 << vlan_prio)))
591
 
                        vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) |
592
 
                                        adapter->recommended_prio;
 
607
                vlan_tag = be_get_tx_vlan_tag(adapter, skb);
593
608
                AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag, hdr, vlan_tag);
594
609
        }
595
610
 
692
707
        u32 start = txq->head;
693
708
        bool dummy_wrb, stopped = false;
694
709
 
 
710
        /* For vlan tagged pkts, BE
 
711
         * 1) calculates checksum even when CSO is not requested
 
712
         * 2) calculates checksum wrongly for padded pkt less than
 
713
         * 60 bytes long.
 
714
         * As a workaround disable TX vlan offloading in such cases.
 
715
         */
 
716
        if (unlikely(vlan_tx_tag_present(skb) &&
 
717
                     (skb->ip_summed != CHECKSUM_PARTIAL || skb->len <= 60))) {
 
718
                skb = skb_share_check(skb, GFP_ATOMIC);
 
719
                if (unlikely(!skb))
 
720
                        goto tx_drop;
 
721
 
 
722
                skb = __vlan_put_tag(skb, be_get_tx_vlan_tag(adapter, skb));
 
723
                if (unlikely(!skb))
 
724
                        goto tx_drop;
 
725
 
 
726
                skb->vlan_tci = 0;
 
727
        }
 
728
 
695
729
        wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb);
696
730
 
697
731
        copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb);
719
753
                txq->head = start;
720
754
                dev_kfree_skb_any(skb);
721
755
        }
 
756
tx_drop:
722
757
        return NETDEV_TX_OK;
723
758
}
724
759
 
746
781
 */
747
782
static int be_vid_config(struct be_adapter *adapter, bool vf, u32 vf_num)
748
783
{
 
784
        struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf_num];
749
785
        u16 vtag[BE_NUM_VLANS_SUPPORTED];
750
786
        u16 ntags = 0, i;
751
787
        int status = 0;
752
 
        u32 if_handle;
753
788
 
754
789
        if (vf) {
755
 
                if_handle = adapter->vf_cfg[vf_num].vf_if_handle;
756
 
                vtag[0] = cpu_to_le16(adapter->vf_cfg[vf_num].vf_vlan_tag);
757
 
                status = be_cmd_vlan_config(adapter, if_handle, vtag, 1, 1, 0);
 
790
                vtag[0] = cpu_to_le16(vf_cfg->vlan_tag);
 
791
                status = be_cmd_vlan_config(adapter, vf_cfg->if_handle, vtag,
 
792
                                            1, 1, 0);
758
793
        }
759
794
 
760
795
        /* No need to further configure vids if in promiscuous mode */
840
875
static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
841
876
{
842
877
        struct be_adapter *adapter = netdev_priv(netdev);
 
878
        struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf];
843
879
        int status;
844
880
 
845
 
        if (!adapter->sriov_enabled)
 
881
        if (!sriov_enabled(adapter))
846
882
                return -EPERM;
847
883
 
848
 
        if (!is_valid_ether_addr(mac) || (vf >= num_vfs))
 
884
        if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs)
849
885
                return -EINVAL;
850
886
 
851
 
        if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID)
852
 
                status = be_cmd_pmac_del(adapter,
853
 
                                        adapter->vf_cfg[vf].vf_if_handle,
854
 
                                        adapter->vf_cfg[vf].vf_pmac_id, vf + 1);
 
887
        if (lancer_chip(adapter)) {
 
888
                status = be_cmd_set_mac_list(adapter,  mac, 1, vf + 1);
 
889
        } else {
 
890
                status = be_cmd_pmac_del(adapter, vf_cfg->if_handle,
 
891
                                         vf_cfg->pmac_id, vf + 1);
855
892
 
856
 
        status = be_cmd_pmac_add(adapter, mac,
857
 
                                adapter->vf_cfg[vf].vf_if_handle,
858
 
                                &adapter->vf_cfg[vf].vf_pmac_id, vf + 1);
 
893
                status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle,
 
894
                                         &vf_cfg->pmac_id, vf + 1);
 
895
        }
859
896
 
860
897
        if (status)
861
898
                dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n",
862
899
                                mac, vf);
863
900
        else
864
 
                memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN);
 
901
                memcpy(vf_cfg->mac_addr, mac, ETH_ALEN);
865
902
 
866
903
        return status;
867
904
}
870
907
                        struct ifla_vf_info *vi)
871
908
{
872
909
        struct be_adapter *adapter = netdev_priv(netdev);
 
910
        struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf];
873
911
 
874
 
        if (!adapter->sriov_enabled)
 
912
        if (!sriov_enabled(adapter))
875
913
                return -EPERM;
876
914
 
877
 
        if (vf >= num_vfs)
 
915
        if (vf >= adapter->num_vfs)
878
916
                return -EINVAL;
879
917
 
880
918
        vi->vf = vf;
881
 
        vi->tx_rate = adapter->vf_cfg[vf].vf_tx_rate;
882
 
        vi->vlan = adapter->vf_cfg[vf].vf_vlan_tag;
 
919
        vi->tx_rate = vf_cfg->tx_rate;
 
920
        vi->vlan = vf_cfg->vlan_tag;
883
921
        vi->qos = 0;
884
 
        memcpy(&vi->mac, adapter->vf_cfg[vf].vf_mac_addr, ETH_ALEN);
 
922
        memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN);
885
923
 
886
924
        return 0;
887
925
}
892
930
        struct be_adapter *adapter = netdev_priv(netdev);
893
931
        int status = 0;
894
932
 
895
 
        if (!adapter->sriov_enabled)
 
933
        if (!sriov_enabled(adapter))
896
934
                return -EPERM;
897
935
 
898
 
        if ((vf >= num_vfs) || (vlan > 4095))
 
936
        if (vf >= adapter->num_vfs || vlan > 4095)
899
937
                return -EINVAL;
900
938
 
901
939
        if (vlan) {
902
 
                adapter->vf_cfg[vf].vf_vlan_tag = vlan;
 
940
                adapter->vf_cfg[vf].vlan_tag = vlan;
903
941
                adapter->vlans_added++;
904
942
        } else {
905
 
                adapter->vf_cfg[vf].vf_vlan_tag = 0;
 
943
                adapter->vf_cfg[vf].vlan_tag = 0;
906
944
                adapter->vlans_added--;
907
945
        }
908
946
 
920
958
        struct be_adapter *adapter = netdev_priv(netdev);
921
959
        int status = 0;
922
960
 
923
 
        if (!adapter->sriov_enabled)
 
961
        if (!sriov_enabled(adapter))
924
962
                return -EPERM;
925
963
 
926
 
        if ((vf >= num_vfs) || (rate < 0))
927
 
                return -EINVAL;
928
 
 
929
 
        if (rate > 10000)
930
 
                rate = 10000;
931
 
 
932
 
        adapter->vf_cfg[vf].vf_tx_rate = rate;
 
964
        if (vf >= adapter->num_vfs)
 
965
                return -EINVAL;
 
966
 
 
967
        if (rate < 100 || rate > 10000) {
 
968
                dev_err(&adapter->pdev->dev,
 
969
                        "tx rate must be between 100 and 10000 Mbps\n");
 
970
                return -EINVAL;
 
971
        }
 
972
 
933
973
        status = be_cmd_set_qos(adapter, rate / 10, vf + 1);
934
974
 
935
975
        if (status)
936
 
                dev_info(&adapter->pdev->dev,
 
976
                dev_err(&adapter->pdev->dev,
937
977
                                "tx rate %d on VF %d failed\n", rate, vf);
 
978
        else
 
979
                adapter->vf_cfg[vf].tx_rate = rate;
938
980
        return status;
939
981
}
940
982
 
1645
1687
 
1646
1688
static int be_num_txqs_want(struct be_adapter *adapter)
1647
1689
{
1648
 
        if ((num_vfs && adapter->sriov_enabled) ||
1649
 
                be_is_mc(adapter) ||
 
1690
        if (sriov_enabled(adapter) || be_is_mc(adapter) ||
1650
1691
                lancer_chip(adapter) || !be_physfn(adapter) ||
1651
1692
                adapter->generation == BE_GEN2)
1652
1693
                return 1;
1662
1703
        u8 i;
1663
1704
 
1664
1705
        adapter->num_tx_qs = be_num_txqs_want(adapter);
1665
 
        if (adapter->num_tx_qs != MAX_TX_QS)
 
1706
        if (adapter->num_tx_qs != MAX_TX_QS) {
 
1707
                rtnl_lock();
1666
1708
                netif_set_real_num_tx_queues(adapter->netdev,
1667
1709
                        adapter->num_tx_qs);
 
1710
                rtnl_unlock();
 
1711
        }
1668
1712
 
1669
1713
        adapter->tx_eq.max_eqd = 0;
1670
1714
        adapter->tx_eq.min_eqd = 0;
1693
1737
                if (be_queue_alloc(adapter, q, TX_Q_LEN,
1694
1738
                        sizeof(struct be_eth_wrb)))
1695
1739
                        goto err;
1696
 
 
1697
 
                if (be_cmd_txq_create(adapter, q, cq))
1698
 
                        goto err;
1699
1740
        }
1700
1741
        return 0;
1701
1742
 
1728
1769
static u32 be_num_rxqs_want(struct be_adapter *adapter)
1729
1770
{
1730
1771
        if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) &&
1731
 
                !adapter->sriov_enabled && be_physfn(adapter) &&
1732
 
                !be_is_mc(adapter)) {
 
1772
             !sriov_enabled(adapter) && be_physfn(adapter)) {
1733
1773
                return 1 + MAX_RSS_QS; /* one default non-RSS queue */
1734
1774
        } else {
1735
1775
                dev_warn(&adapter->pdev->dev,
1929
1969
        struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi);
1930
1970
        struct be_adapter *adapter =
1931
1971
                container_of(tx_eq, struct be_adapter, tx_eq);
 
1972
        struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
1932
1973
        struct be_tx_obj *txo;
1933
1974
        struct be_eth_tx_compl *txcp;
1934
1975
        int tx_compl, mcc_compl, status = 0;
1965
2006
        mcc_compl = be_process_mcc(adapter, &status);
1966
2007
 
1967
2008
        if (mcc_compl) {
1968
 
                struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
1969
2009
                be_cq_notify(adapter, mcc_obj->cq.id, true, mcc_compl);
1970
2010
        }
1971
2011
 
1972
2012
        napi_complete(napi);
1973
2013
 
 
2014
        /* Arm CQ again to regenerate EQEs for Lancer in INTx mode */
 
2015
        if (lancer_chip(adapter) && !msix_enabled(adapter)) {
 
2016
                for_all_tx_queues(adapter, txo, i)
 
2017
                        be_cq_notify(adapter, txo->cq.id, true, 0);
 
2018
 
 
2019
                be_cq_notify(adapter, mcc_obj->cq.id, true, 0);
 
2020
        }
 
2021
 
1974
2022
        be_eq_notify(adapter, tx_eq->q.id, true, false, 0);
1975
2023
        adapter->drv_stats.tx_events++;
1976
2024
        return 1;
1982
2030
        u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
1983
2031
        u32 i;
1984
2032
 
 
2033
        if (adapter->eeh_err || adapter->ue_detected)
 
2034
                return;
 
2035
 
1985
2036
        if (lancer_chip(adapter)) {
1986
2037
                sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
1987
2038
                if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
2008
2059
                sliport_status & SLIPORT_STATUS_ERR_MASK) {
2009
2060
                adapter->ue_detected = true;
2010
2061
                adapter->eeh_err = true;
2011
 
                dev_err(&adapter->pdev->dev, "UE Detected!!\n");
 
2062
                dev_err(&adapter->pdev->dev,
 
2063
                        "Unrecoverable error in the card\n");
2012
2064
        }
2013
2065
 
2014
2066
        if (ue_lo) {
2036
2088
        }
2037
2089
}
2038
2090
 
2039
 
static void be_worker(struct work_struct *work)
2040
 
{
2041
 
        struct be_adapter *adapter =
2042
 
                container_of(work, struct be_adapter, work.work);
2043
 
        struct be_rx_obj *rxo;
2044
 
        int i;
2045
 
 
2046
 
        if (!adapter->ue_detected)
2047
 
                be_detect_dump_ue(adapter);
2048
 
 
2049
 
        /* when interrupts are not yet enabled, just reap any pending
2050
 
        * mcc completions */
2051
 
        if (!netif_running(adapter->netdev)) {
2052
 
                int mcc_compl, status = 0;
2053
 
 
2054
 
                mcc_compl = be_process_mcc(adapter, &status);
2055
 
 
2056
 
                if (mcc_compl) {
2057
 
                        struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
2058
 
                        be_cq_notify(adapter, mcc_obj->cq.id, false, mcc_compl);
2059
 
                }
2060
 
 
2061
 
                goto reschedule;
2062
 
        }
2063
 
 
2064
 
        if (!adapter->stats_cmd_sent) {
2065
 
                if (lancer_chip(adapter))
2066
 
                        lancer_cmd_get_pport_stats(adapter,
2067
 
                                                &adapter->stats_cmd);
2068
 
                else
2069
 
                        be_cmd_get_stats(adapter, &adapter->stats_cmd);
2070
 
        }
2071
 
 
2072
 
        for_all_rx_queues(adapter, rxo, i) {
2073
 
                be_rx_eqd_update(adapter, rxo);
2074
 
 
2075
 
                if (rxo->rx_post_starved) {
2076
 
                        rxo->rx_post_starved = false;
2077
 
                        be_post_rx_frags(rxo, GFP_KERNEL);
2078
 
                }
2079
 
        }
2080
 
 
2081
 
reschedule:
2082
 
        adapter->work_counter++;
2083
 
        schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
2084
 
}
2085
 
 
2086
2091
static void be_msix_disable(struct be_adapter *adapter)
2087
2092
{
2088
2093
        if (msix_enabled(adapter)) {
2119
2124
static int be_sriov_enable(struct be_adapter *adapter)
2120
2125
{
2121
2126
        be_check_sriov_fn_type(adapter);
 
2127
 
2122
2128
#ifdef CONFIG_PCI_IOV
2123
2129
        if (be_physfn(adapter) && num_vfs) {
2124
2130
                int status, pos;
2125
 
                u16 nvfs;
 
2131
                u16 dev_vfs;
2126
2132
 
2127
2133
                pos = pci_find_ext_capability(adapter->pdev,
2128
2134
                                                PCI_EXT_CAP_ID_SRIOV);
2129
2135
                pci_read_config_word(adapter->pdev,
2130
 
                                        pos + PCI_SRIOV_TOTAL_VF, &nvfs);
 
2136
                                     pos + PCI_SRIOV_TOTAL_VF, &dev_vfs);
2131
2137
 
2132
 
                if (num_vfs > nvfs) {
 
2138
                adapter->num_vfs = min_t(u16, num_vfs, dev_vfs);
 
2139
                if (adapter->num_vfs != num_vfs)
2133
2140
                        dev_info(&adapter->pdev->dev,
2134
 
                                        "Device supports %d VFs and not %d\n",
2135
 
                                        nvfs, num_vfs);
2136
 
                        num_vfs = nvfs;
2137
 
                }
2138
 
 
2139
 
                status = pci_enable_sriov(adapter->pdev, num_vfs);
2140
 
                adapter->sriov_enabled = status ? false : true;
2141
 
 
2142
 
                if (adapter->sriov_enabled) {
 
2141
                                 "Device supports %d VFs and not %d\n",
 
2142
                                 adapter->num_vfs, num_vfs);
 
2143
 
 
2144
                status = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
 
2145
                if (status)
 
2146
                        adapter->num_vfs = 0;
 
2147
 
 
2148
                if (adapter->num_vfs) {
2143
2149
                        adapter->vf_cfg = kcalloc(num_vfs,
2144
2150
                                                sizeof(struct be_vf_cfg),
2145
2151
                                                GFP_KERNEL);
2154
2160
static void be_sriov_disable(struct be_adapter *adapter)
2155
2161
{
2156
2162
#ifdef CONFIG_PCI_IOV
2157
 
        if (adapter->sriov_enabled) {
 
2163
        if (sriov_enabled(adapter)) {
2158
2164
                pci_disable_sriov(adapter->pdev);
2159
2165
                kfree(adapter->vf_cfg);
2160
 
                adapter->sriov_enabled = false;
 
2166
                adapter->num_vfs = 0;
2161
2167
        }
2162
2168
#endif
2163
2169
}
2351
2357
static int be_rx_queues_setup(struct be_adapter *adapter)
2352
2358
{
2353
2359
        struct be_rx_obj *rxo;
2354
 
        int rc, i;
2355
 
        u8 rsstable[MAX_RSS_QS];
 
2360
        int rc, i, j;
 
2361
        u8 rsstable[128];
2356
2362
 
2357
2363
        for_all_rx_queues(adapter, rxo, i) {
2358
2364
                rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id,
2364
2370
        }
2365
2371
 
2366
2372
        if (be_multi_rxq(adapter)) {
2367
 
                for_all_rss_queues(adapter, rxo, i)
2368
 
                        rsstable[i] = rxo->rss_id;
 
2373
                for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
 
2374
                        for_all_rss_queues(adapter, rxo, i) {
 
2375
                                if ((j + i) >= 128)
 
2376
                                        break;
 
2377
                                rsstable[j + i] = rxo->rss_id;
 
2378
                        }
 
2379
                }
 
2380
                rc = be_cmd_rss_config(adapter, rsstable, 128);
2369
2381
 
2370
 
                rc = be_cmd_rss_config(adapter, rsstable,
2371
 
                        adapter->num_rx_qs - 1);
2372
2382
                if (rc)
2373
2383
                        return rc;
2374
2384
        }
2386
2396
        struct be_adapter *adapter = netdev_priv(netdev);
2387
2397
        struct be_eq_obj *tx_eq = &adapter->tx_eq;
2388
2398
        struct be_rx_obj *rxo;
 
2399
        u8 link_status;
2389
2400
        int status, i;
2390
2401
 
2391
2402
        status = be_rx_queues_setup(adapter);
2409
2420
        /* Now that interrupts are on we can process async mcc */
2410
2421
        be_async_mcc_enable(adapter);
2411
2422
 
 
2423
        status = be_cmd_link_status_query(adapter, NULL, NULL,
 
2424
                                          &link_status, 0);
 
2425
        if (!status)
 
2426
                be_link_status_update(adapter, link_status);
 
2427
 
2412
2428
        return 0;
2413
2429
err:
2414
2430
        be_close(adapter->netdev);
2465
2481
        u32 vf;
2466
2482
        int status = 0;
2467
2483
        u8 mac[ETH_ALEN];
 
2484
        struct be_vf_cfg *vf_cfg;
2468
2485
 
2469
2486
        be_vf_eth_addr_generate(adapter, mac);
2470
2487
 
2471
 
        for (vf = 0; vf < num_vfs; vf++) {
2472
 
                status = be_cmd_pmac_add(adapter, mac,
2473
 
                                        adapter->vf_cfg[vf].vf_if_handle,
2474
 
                                        &adapter->vf_cfg[vf].vf_pmac_id,
2475
 
                                        vf + 1);
 
2488
        for_all_vfs(adapter, vf_cfg, vf) {
 
2489
                if (lancer_chip(adapter)) {
 
2490
                        status = be_cmd_set_mac_list(adapter,  mac, 1, vf + 1);
 
2491
                } else {
 
2492
                        status = be_cmd_pmac_add(adapter, mac,
 
2493
                                                 vf_cfg->if_handle,
 
2494
                                                 &vf_cfg->pmac_id, vf + 1);
 
2495
                }
 
2496
 
2476
2497
                if (status)
2477
2498
                        dev_err(&adapter->pdev->dev,
2478
 
                                "Mac address add failed for VF %d\n", vf);
 
2499
                        "Mac address assignment failed for VF %d\n", vf);
2479
2500
                else
2480
 
                        memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN);
 
2501
                        memcpy(vf_cfg->mac_addr, mac, ETH_ALEN);
2481
2502
 
2482
2503
                mac[5] += 1;
2483
2504
        }
2486
2507
 
2487
2508
static void be_vf_clear(struct be_adapter *adapter)
2488
2509
{
 
2510
        struct be_vf_cfg *vf_cfg;
2489
2511
        u32 vf;
2490
2512
 
2491
 
        for (vf = 0; vf < num_vfs; vf++) {
2492
 
                if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID)
2493
 
                        be_cmd_pmac_del(adapter,
2494
 
                                        adapter->vf_cfg[vf].vf_if_handle,
2495
 
                                        adapter->vf_cfg[vf].vf_pmac_id, vf + 1);
 
2513
        for_all_vfs(adapter, vf_cfg, vf) {
 
2514
                if (lancer_chip(adapter))
 
2515
                        be_cmd_set_mac_list(adapter, NULL, 0, vf + 1);
 
2516
                else
 
2517
                        be_cmd_pmac_del(adapter, vf_cfg->if_handle,
 
2518
                                        vf_cfg->pmac_id, vf + 1);
 
2519
 
 
2520
                be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1);
2496
2521
        }
2497
 
 
2498
 
        for (vf = 0; vf < num_vfs; vf++)
2499
 
                if (adapter->vf_cfg[vf].vf_if_handle)
2500
 
                        be_cmd_if_destroy(adapter,
2501
 
                                adapter->vf_cfg[vf].vf_if_handle, vf + 1);
2502
2522
}
2503
2523
 
2504
2524
static int be_clear(struct be_adapter *adapter)
2505
2525
{
2506
 
        if (be_physfn(adapter) && adapter->sriov_enabled)
 
2526
        if (sriov_enabled(adapter))
2507
2527
                be_vf_clear(adapter);
2508
2528
 
2509
2529
        be_cmd_if_destroy(adapter, adapter->if_handle,  0);
2511
2531
        be_mcc_queues_destroy(adapter);
2512
2532
        be_rx_queues_destroy(adapter);
2513
2533
        be_tx_queues_destroy(adapter);
2514
 
        adapter->eq_next_idx = 0;
2515
 
 
2516
 
        adapter->be3_native = false;
2517
 
        adapter->promiscuous = false;
2518
2534
 
2519
2535
        /* tell fw we're done with firing cmds */
2520
2536
        be_cmd_fw_clean(adapter);
2521
2537
        return 0;
2522
2538
}
2523
2539
 
 
2540
static void be_vf_setup_init(struct be_adapter *adapter)
 
2541
{
 
2542
        struct be_vf_cfg *vf_cfg;
 
2543
        int vf;
 
2544
 
 
2545
        for_all_vfs(adapter, vf_cfg, vf) {
 
2546
                vf_cfg->if_handle = -1;
 
2547
                vf_cfg->pmac_id = -1;
 
2548
        }
 
2549
}
 
2550
 
2524
2551
static int be_vf_setup(struct be_adapter *adapter)
2525
2552
{
 
2553
        struct be_vf_cfg *vf_cfg;
2526
2554
        u32 cap_flags, en_flags, vf;
2527
2555
        u16 lnk_speed;
2528
2556
        int status;
2529
2557
 
2530
 
        cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST;
2531
 
        for (vf = 0; vf < num_vfs; vf++) {
 
2558
        be_vf_setup_init(adapter);
 
2559
 
 
2560
        cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
 
2561
                                BE_IF_FLAGS_MULTICAST;
 
2562
        for_all_vfs(adapter, vf_cfg, vf) {
2532
2563
                status = be_cmd_if_create(adapter, cap_flags, en_flags, NULL,
2533
 
                                        &adapter->vf_cfg[vf].vf_if_handle,
2534
 
                                        NULL, vf+1);
2535
 
                if (status)
2536
 
                        goto err;
2537
 
                adapter->vf_cfg[vf].vf_pmac_id = BE_INVALID_PMAC_ID;
2538
 
        }
2539
 
 
2540
 
        if (!lancer_chip(adapter)) {
2541
 
                status = be_vf_eth_addr_config(adapter);
2542
 
                if (status)
2543
 
                        goto err;
2544
 
        }
2545
 
 
2546
 
        for (vf = 0; vf < num_vfs; vf++) {
 
2564
                                          &vf_cfg->if_handle, NULL, vf + 1);
 
2565
                if (status)
 
2566
                        goto err;
 
2567
        }
 
2568
 
 
2569
        status = be_vf_eth_addr_config(adapter);
 
2570
        if (status)
 
2571
                goto err;
 
2572
 
 
2573
        for_all_vfs(adapter, vf_cfg, vf) {
2547
2574
                status = be_cmd_link_status_query(adapter, NULL, &lnk_speed,
2548
 
                                vf + 1);
 
2575
                                                  NULL, vf + 1);
2549
2576
                if (status)
2550
2577
                        goto err;
2551
 
                adapter->vf_cfg[vf].vf_tx_rate = lnk_speed * 10;
 
2578
                vf_cfg->tx_rate = lnk_speed * 10;
2552
2579
        }
2553
2580
        return 0;
2554
2581
err:
2555
2582
        return status;
2556
2583
}
2557
2584
 
 
2585
static void be_setup_init(struct be_adapter *adapter)
 
2586
{
 
2587
        adapter->vlan_prio_bmap = 0xff;
 
2588
        adapter->link_speed = -1;
 
2589
        adapter->if_handle = -1;
 
2590
        adapter->be3_native = false;
 
2591
        adapter->promiscuous = false;
 
2592
        adapter->eq_next_idx = 0;
 
2593
}
 
2594
 
 
2595
static int be_configure_mac_from_list(struct be_adapter *adapter, u8 *mac)
 
2596
{
 
2597
        u32 pmac_id;
 
2598
        int status = be_cmd_get_mac_from_list(adapter, 0, &pmac_id);
 
2599
        if (status != 0)
 
2600
                goto do_none;
 
2601
        status = be_cmd_mac_addr_query(adapter, mac,
 
2602
                        MAC_ADDRESS_TYPE_NETWORK,
 
2603
                        false, adapter->if_handle, pmac_id);
 
2604
        if (status != 0)
 
2605
                goto do_none;
 
2606
        status = be_cmd_pmac_add(adapter, mac, adapter->if_handle,
 
2607
                        &adapter->pmac_id, 0);
 
2608
do_none:
 
2609
        return status;
 
2610
}
 
2611
 
2558
2612
static int be_setup(struct be_adapter *adapter)
2559
2613
{
2560
2614
        struct net_device *netdev = adapter->netdev;
2561
2615
        u32 cap_flags, en_flags;
2562
2616
        u32 tx_fc, rx_fc;
2563
 
        int status;
 
2617
        int status, i;
2564
2618
        u8 mac[ETH_ALEN];
 
2619
        struct be_tx_obj *txo;
2565
2620
 
2566
 
        /* Allow all priorities by default. A GRP5 evt may modify this */
2567
 
        adapter->vlan_prio_bmap = 0xff;
2568
 
        adapter->link_speed = -1;
 
2621
        be_setup_init(adapter);
2569
2622
 
2570
2623
        be_cmd_req_native_mode(adapter);
2571
2624
 
2583
2636
 
2584
2637
        memset(mac, 0, ETH_ALEN);
2585
2638
        status = be_cmd_mac_addr_query(adapter, mac, MAC_ADDRESS_TYPE_NETWORK,
2586
 
                        true /*permanent */, 0);
 
2639
                        true /*permanent */, 0, 0);
2587
2640
        if (status)
2588
2641
                return status;
2589
2642
        memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
2592
2645
        en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
2593
2646
                        BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS;
2594
2647
        cap_flags = en_flags | BE_IF_FLAGS_MCAST_PROMISCUOUS |
2595
 
                        BE_IF_FLAGS_PROMISCUOUS;
 
2648
                        BE_IF_FLAGS_VLAN_PROMISCUOUS | BE_IF_FLAGS_PROMISCUOUS;
 
2649
 
2596
2650
        if (adapter->function_caps & BE_FUNCTION_CAPS_RSS) {
2597
2651
                cap_flags |= BE_IF_FLAGS_RSS;
2598
2652
                en_flags |= BE_IF_FLAGS_RSS;
2603
2657
        if (status != 0)
2604
2658
                goto err;
2605
2659
 
2606
 
        /* For BEx, the VF's permanent mac queried from card is incorrect.
2607
 
         * Query the mac configued by the PF using if_handle
2608
 
         */
2609
 
        if (!be_physfn(adapter) && !lancer_chip(adapter)) {
2610
 
                status = be_cmd_mac_addr_query(adapter, mac,
2611
 
                        MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle);
 
2660
         for_all_tx_queues(adapter, txo, i) {
 
2661
                status = be_cmd_txq_create(adapter, &txo->q, &txo->cq);
 
2662
                if (status)
 
2663
                        goto err;
 
2664
        }
 
2665
 
 
2666
         /* The VF's permanent mac queried from card is incorrect.
 
2667
          * For BEx: Query the mac configued by the PF using if_handle
 
2668
          * For Lancer: Get and use mac_list to obtain mac address.
 
2669
          */
 
2670
        if (!be_physfn(adapter)) {
 
2671
                if (lancer_chip(adapter))
 
2672
                        status = be_configure_mac_from_list(adapter, mac);
 
2673
                else
 
2674
                        status = be_cmd_mac_addr_query(adapter, mac,
 
2675
                                        MAC_ADDRESS_TYPE_NETWORK, false,
 
2676
                                        adapter->if_handle, 0);
2612
2677
                if (!status) {
2613
2678
                        memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
2614
2679
                        memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
2624
2689
        be_set_rx_mode(adapter->netdev);
2625
2690
 
2626
2691
        status = be_cmd_get_flow_control(adapter, &tx_fc, &rx_fc);
2627
 
        if (status)
 
2692
        /* For Lancer: It is legal for this cmd to fail on VF */
 
2693
        if (status && (be_physfn(adapter) || !lancer_chip(adapter)))
2628
2694
                goto err;
 
2695
 
2629
2696
        if (rx_fc != adapter->rx_fc || tx_fc != adapter->tx_fc) {
2630
2697
                status = be_cmd_set_flow_control(adapter, adapter->tx_fc,
2631
2698
                                        adapter->rx_fc);
2632
 
                if (status)
 
2699
                /* For Lancer: It is legal for this cmd to fail on VF */
 
2700
                if (status && (be_physfn(adapter) || !lancer_chip(adapter)))
2633
2701
                        goto err;
2634
2702
        }
2635
2703
 
2636
2704
        pcie_set_readrq(adapter->pdev, 4096);
2637
2705
 
2638
 
        if (be_physfn(adapter) && adapter->sriov_enabled) {
 
2706
        if (sriov_enabled(adapter)) {
2639
2707
                status = be_vf_setup(adapter);
2640
2708
                if (status)
2641
2709
                        goto err;
2647
2715
        return status;
2648
2716
}
2649
2717
 
 
2718
#ifdef CONFIG_NET_POLL_CONTROLLER
 
2719
static void be_netpoll(struct net_device *netdev)
 
2720
{
 
2721
        struct be_adapter *adapter = netdev_priv(netdev);
 
2722
        struct be_rx_obj *rxo;
 
2723
        int i;
 
2724
 
 
2725
        event_handle(adapter, &adapter->tx_eq, false);
 
2726
        for_all_rx_queues(adapter, rxo, i)
 
2727
                event_handle(adapter, &rxo->rx_eq, true);
 
2728
}
 
2729
#endif
 
2730
 
2650
2731
#define FW_FILE_HDR_SIGN        "ServerEngines Corp. "
2651
2732
static bool be_flash_redboot(struct be_adapter *adapter,
2652
2733
                        const u8 *p, u32 img_start, int image_size,
2981
3062
        return status;
2982
3063
}
2983
3064
 
2984
 
static struct net_device_ops be_netdev_ops = {
 
3065
static const struct net_device_ops be_netdev_ops = {
2985
3066
        .ndo_open               = be_open,
2986
3067
        .ndo_stop               = be_close,
2987
3068
        .ndo_start_xmit         = be_xmit,
2995
3076
        .ndo_set_vf_mac         = be_set_vf_mac,
2996
3077
        .ndo_set_vf_vlan        = be_set_vf_vlan,
2997
3078
        .ndo_set_vf_tx_rate     = be_set_vf_tx_rate,
2998
 
        .ndo_get_vf_config      = be_get_vf_config
 
3079
        .ndo_get_vf_config      = be_get_vf_config,
 
3080
#ifdef CONFIG_NET_POLL_CONTROLLER
 
3081
        .ndo_poll_controller    = be_netpoll,
 
3082
#endif
2999
3083
};
3000
3084
 
3001
3085
static void be_netdev_init(struct net_device *netdev)
3242
3326
                break;
3243
3327
        case BE_DEVICE_ID2:
3244
3328
        case OC_DEVICE_ID2:
 
3329
        case OC_DEVICE_ID5:
3245
3330
                adapter->generation = BE_GEN3;
3246
3331
                break;
3247
3332
        case OC_DEVICE_ID3:
3267
3352
 
3268
3353
static int lancer_wait_ready(struct be_adapter *adapter)
3269
3354
{
3270
 
#define SLIPORT_READY_TIMEOUT 500
 
3355
#define SLIPORT_READY_TIMEOUT 30
3271
3356
        u32 sliport_status;
3272
3357
        int status = 0, i;
3273
3358
 
3276
3361
                if (sliport_status & SLIPORT_STATUS_RDY_MASK)
3277
3362
                        break;
3278
3363
 
3279
 
                msleep(20);
 
3364
                msleep(1000);
3280
3365
        }
3281
3366
 
3282
3367
        if (i == SLIPORT_READY_TIMEOUT)
3313
3398
        return status;
3314
3399
}
3315
3400
 
 
3401
static void lancer_test_and_recover_fn_err(struct be_adapter *adapter)
 
3402
{
 
3403
        int status;
 
3404
        u32 sliport_status;
 
3405
 
 
3406
        if (adapter->eeh_err || adapter->ue_detected)
 
3407
                return;
 
3408
 
 
3409
        sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
 
3410
 
 
3411
        if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
 
3412
                dev_err(&adapter->pdev->dev,
 
3413
                                "Adapter in error state."
 
3414
                                "Trying to recover.\n");
 
3415
 
 
3416
                status = lancer_test_and_set_rdy_state(adapter);
 
3417
                if (status)
 
3418
                        goto err;
 
3419
 
 
3420
                netif_device_detach(adapter->netdev);
 
3421
 
 
3422
                if (netif_running(adapter->netdev))
 
3423
                        be_close(adapter->netdev);
 
3424
 
 
3425
                be_clear(adapter);
 
3426
 
 
3427
                adapter->fw_timeout = false;
 
3428
 
 
3429
                status = be_setup(adapter);
 
3430
                if (status)
 
3431
                        goto err;
 
3432
 
 
3433
                if (netif_running(adapter->netdev)) {
 
3434
                        status = be_open(adapter->netdev);
 
3435
                        if (status)
 
3436
                                goto err;
 
3437
                }
 
3438
 
 
3439
                netif_device_attach(adapter->netdev);
 
3440
 
 
3441
                dev_err(&adapter->pdev->dev,
 
3442
                                "Adapter error recovery succeeded\n");
 
3443
        }
 
3444
        return;
 
3445
err:
 
3446
        dev_err(&adapter->pdev->dev,
 
3447
                        "Adapter error recovery failed\n");
 
3448
}
 
3449
 
 
3450
static void be_worker(struct work_struct *work)
 
3451
{
 
3452
        struct be_adapter *adapter =
 
3453
                container_of(work, struct be_adapter, work.work);
 
3454
        struct be_rx_obj *rxo;
 
3455
        int i;
 
3456
 
 
3457
        if (lancer_chip(adapter))
 
3458
                lancer_test_and_recover_fn_err(adapter);
 
3459
 
 
3460
        be_detect_dump_ue(adapter);
 
3461
 
 
3462
        /* when interrupts are not yet enabled, just reap any pending
 
3463
        * mcc completions */
 
3464
        if (!netif_running(adapter->netdev)) {
 
3465
                int mcc_compl, status = 0;
 
3466
 
 
3467
                mcc_compl = be_process_mcc(adapter, &status);
 
3468
 
 
3469
                if (mcc_compl) {
 
3470
                        struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
 
3471
                        be_cq_notify(adapter, mcc_obj->cq.id, false, mcc_compl);
 
3472
                }
 
3473
 
 
3474
                goto reschedule;
 
3475
        }
 
3476
 
 
3477
        if (!adapter->stats_cmd_sent) {
 
3478
                if (lancer_chip(adapter))
 
3479
                        lancer_cmd_get_pport_stats(adapter,
 
3480
                                                &adapter->stats_cmd);
 
3481
                else
 
3482
                        be_cmd_get_stats(adapter, &adapter->stats_cmd);
 
3483
        }
 
3484
 
 
3485
        for_all_rx_queues(adapter, rxo, i) {
 
3486
                be_rx_eqd_update(adapter, rxo);
 
3487
 
 
3488
                if (rxo->rx_post_starved) {
 
3489
                        rxo->rx_post_starved = false;
 
3490
                        be_post_rx_frags(rxo, GFP_KERNEL);
 
3491
                }
 
3492
        }
 
3493
 
 
3494
reschedule:
 
3495
        adapter->work_counter++;
 
3496
        schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
 
3497
}
 
3498
 
3316
3499
static int __devinit be_probe(struct pci_dev *pdev,
3317
3500
                        const struct pci_device_id *pdev_id)
3318
3501
{
3365
3548
                goto disable_sriov;
3366
3549
 
3367
3550
        if (lancer_chip(adapter)) {
3368
 
                status = lancer_test_and_set_rdy_state(adapter);
 
3551
                status = lancer_wait_ready(adapter);
 
3552
                if (!status) {
 
3553
                        iowrite32(SLI_PORT_CONTROL_IP_MASK,
 
3554
                                        adapter->db + SLIPORT_CONTROL_OFFSET);
 
3555
                        status = lancer_test_and_set_rdy_state(adapter);
 
3556
                }
3369
3557
                if (status) {
3370
3558
                        dev_err(&pdev->dev, "Adapter in non recoverable error\n");
3371
3559
                        goto ctrl_clean;
3559
3747
 
3560
3748
        dev_info(&adapter->pdev->dev, "EEH reset\n");
3561
3749
        adapter->eeh_err = false;
 
3750
        adapter->ue_detected = false;
 
3751
        adapter->fw_timeout = false;
3562
3752
 
3563
3753
        status = pci_enable_device(pdev);
3564
3754
        if (status)