be2net: Fix to trim skb for padded vlan packets to workaround an ASIC Bug
[linux-2.6.git] / drivers / net / ethernet / emulex / benet / be_main.c
index 050e3eb..ef1f940 100644 (file)
@@ -235,7 +235,7 @@ static int be_mac_addr_set(struct net_device *netdev, void *p)
        struct sockaddr *addr = p;
        int status = 0;
        u8 current_mac[ETH_ALEN];
-       u32 pmac_id = adapter->pmac_id;
+       u32 pmac_id = adapter->pmac_id[0];
 
        if (!is_valid_ether_addr(addr->sa_data))
                return -EADDRNOTAVAIL;
@@ -248,7 +248,7 @@ static int be_mac_addr_set(struct net_device *netdev, void *p)
 
        if (memcmp(addr->sa_data, current_mac, ETH_ALEN)) {
                status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
-                               adapter->if_handle, &adapter->pmac_id, 0);
+                               adapter->if_handle, &adapter->pmac_id[0], 0);
                if (status)
                        goto err;
 
@@ -571,6 +571,11 @@ static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter,
        return vlan_tag;
 }
 
+static int be_vlan_tag_chk(struct be_adapter *adapter, struct sk_buff *skb)
+{
+       return vlan_tx_tag_present(skb) || adapter->pvid;
+}
+
 static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr,
                struct sk_buff *skb, u32 wrb_cnt, u32 len)
 {
@@ -698,39 +703,64 @@ dma_err:
        return 0;
 }
 
+static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
+                                            struct sk_buff *skb)
+{
+       u16 vlan_tag = 0;
+
+       skb = skb_share_check(skb, GFP_ATOMIC);
+       if (unlikely(!skb))
+               return skb;
+
+       if (vlan_tx_tag_present(skb)) {
+               vlan_tag = be_get_tx_vlan_tag(adapter, skb);
+               __vlan_put_tag(skb, vlan_tag);
+               skb->vlan_tci = 0;
+       }
+
+       return skb;
+}
+
 static netdev_tx_t be_xmit(struct sk_buff *skb,
                        struct net_device *netdev)
 {
        struct be_adapter *adapter = netdev_priv(netdev);
        struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)];
        struct be_queue_info *txq = &txo->q;
+       struct iphdr *ip = NULL;
        u32 wrb_cnt = 0, copied = 0;
-       u32 start = txq->head;
+       u32 start = txq->head, eth_hdr_len;
        bool dummy_wrb, stopped = false;
 
-       /* For vlan tagged pkts, BE
-        * 1) calculates checksum even when CSO is not requested
-        * 2) calculates checksum wrongly for padded pkt less than
-        * 60 bytes long.
-        * As a workaround disable TX vlan offloading in such cases.
+       eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ?
+               VLAN_ETH_HLEN : ETH_HLEN;
+
+       /* HW has a bug which considers padding bytes as legal
+        * and modifies the IPv4 hdr's 'tot_len' field
         */
-       if (unlikely(vlan_tx_tag_present(skb) &&
-                    (skb->ip_summed != CHECKSUM_PARTIAL || skb->len <= 60))) {
-               skb = skb_share_check(skb, GFP_ATOMIC);
-               if (unlikely(!skb))
-                       goto tx_drop;
+       if (skb->len <= 60 && be_vlan_tag_chk(adapter, skb) &&
+                       is_ipv4_pkt(skb)) {
+               ip = (struct iphdr *)ip_hdr(skb);
+               pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len));
+       }
 
-               skb = __vlan_put_tag(skb, be_get_tx_vlan_tag(adapter, skb));
+       /* HW has a bug wherein it will calculate CSUM for VLAN
+        * pkts even though it is disabled.
+        * Manually insert VLAN in pkt.
+        */
+       if (skb->ip_summed != CHECKSUM_PARTIAL &&
+                       be_vlan_tag_chk(adapter, skb)) {
+               skb = be_insert_vlan_in_pkt(adapter, skb);
                if (unlikely(!skb))
                        goto tx_drop;
-
-               skb->vlan_tci = 0;
        }
 
        wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb);
 
        copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb);
        if (copied) {
+               int gso_segs = skb_shinfo(skb)->gso_segs;
+
                /* record the sent skb in the sent_skb table */
                BUG_ON(txo->sent_skb_list[start]);
                txo->sent_skb_list[start] = skb;
@@ -748,8 +778,7 @@ static netdev_tx_t be_xmit(struct sk_buff *skb,
 
                be_txq_notify(adapter, txq->id, wrb_cnt);
 
-               be_tx_stats_update(txo, wrb_cnt, copied,
-                               skb_shinfo(skb)->gso_segs, stopped);
+               be_tx_stats_update(txo, wrb_cnt, copied, gso_segs, stopped);
        } else {
                txq->head = start;
                dev_kfree_skb_any(skb);
@@ -885,6 +914,29 @@ static void be_set_rx_mode(struct net_device *netdev)
                goto done;
        }
 
+       if (netdev_uc_count(netdev) != adapter->uc_macs) {
+               struct netdev_hw_addr *ha;
+               int i = 1; /* First slot is claimed by the Primary MAC */
+
+               for (; adapter->uc_macs > 0; adapter->uc_macs--, i++) {
+                       be_cmd_pmac_del(adapter, adapter->if_handle,
+                                       adapter->pmac_id[i], 0);
+               }
+
+               if (netdev_uc_count(netdev) > adapter->max_pmac_cnt) {
+                       be_cmd_rx_filter(adapter, IFF_PROMISC, ON);
+                       adapter->promiscuous = true;
+                       goto done;
+               }
+
+               netdev_for_each_uc_addr(ha, adapter->netdev) {
+                       adapter->uc_macs++; /* First slot is for Primary MAC */
+                       be_cmd_pmac_add(adapter, (u8 *)ha->addr,
+                                       adapter->if_handle,
+                                       &adapter->pmac_id[adapter->uc_macs], 0);
+               }
+       }
+
        be_cmd_rx_filter(adapter, IFF_MULTICAST, ON);
 done:
        return;
@@ -955,14 +1007,21 @@ static int be_set_vf_vlan(struct net_device *netdev,
                return -EINVAL;
 
        if (vlan) {
-               adapter->vf_cfg[vf].vlan_tag = vlan;
-               adapter->vlans_added++;
+               if (adapter->vf_cfg[vf].vlan_tag != vlan) {
+                       /* If this is new value, program it. Else skip. */
+                       adapter->vf_cfg[vf].vlan_tag = vlan;
+
+                       status = be_cmd_set_hsw_config(adapter, vlan,
+                               vf + 1, adapter->vf_cfg[vf].if_handle);
+               }
        } else {
+               /* Reset Transparent Vlan Tagging. */
                adapter->vf_cfg[vf].vlan_tag = 0;
-               adapter->vlans_added--;
+               vlan = adapter->vf_cfg[vf].def_vid;
+               status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
+                       adapter->vf_cfg[vf].if_handle);
        }
 
-       status = be_vid_config(adapter, true, vf);
 
        if (status)
                dev_info(&adapter->pdev->dev,
@@ -2458,6 +2517,8 @@ static void be_vf_clear(struct be_adapter *adapter)
 
 static int be_clear(struct be_adapter *adapter)
 {
+       int i = 1;
+
        if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) {
                cancel_delayed_work_sync(&adapter->work);
                adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED;
@@ -2466,6 +2527,10 @@ static int be_clear(struct be_adapter *adapter)
        if (sriov_enabled(adapter))
                be_vf_clear(adapter);
 
+       for (; adapter->uc_macs > 0; adapter->uc_macs--, i++)
+               be_cmd_pmac_del(adapter, adapter->if_handle,
+                       adapter->pmac_id[i], 0);
+
        be_cmd_if_destroy(adapter, adapter->if_handle,  0);
 
        be_mcc_queues_destroy(adapter);
@@ -2477,6 +2542,7 @@ static int be_clear(struct be_adapter *adapter)
        be_cmd_fw_clean(adapter);
 
        be_msix_disable(adapter);
+       kfree(adapter->pmac_id);
        return 0;
 }
 
@@ -2495,7 +2561,7 @@ static int be_vf_setup(struct be_adapter *adapter)
 {
        struct be_vf_cfg *vf_cfg;
        u32 cap_flags, en_flags, vf;
-       u16 lnk_speed;
+       u16 def_vlan, lnk_speed;
        int status;
 
        be_vf_setup_init(adapter);
@@ -2519,6 +2585,12 @@ static int be_vf_setup(struct be_adapter *adapter)
                if (status)
                        goto err;
                vf_cfg->tx_rate = lnk_speed * 10;
+
+               status = be_cmd_get_hsw_config(adapter, &def_vlan,
+                               vf + 1, vf_cfg->if_handle);
+               if (status)
+                       goto err;
+               vf_cfg->def_vid = def_vlan;
        }
        return 0;
 err:
@@ -2552,10 +2624,10 @@ static int be_add_mac_from_list(struct be_adapter *adapter, u8 *mac)
                                false, adapter->if_handle, pmac_id);
 
                if (!status)
-                       adapter->pmac_id = pmac_id;
+                       adapter->pmac_id[0] = pmac_id;
        } else {
                status = be_cmd_pmac_add(adapter, mac,
-                               adapter->if_handle, &adapter->pmac_id, 0);
+                               adapter->if_handle, &adapter->pmac_id[0], 0);
        }
 do_none:
        return status;
@@ -2610,7 +2682,7 @@ static int be_setup(struct be_adapter *adapter)
        }
        status = be_cmd_if_create(adapter, cap_flags, en_flags,
                        netdev->dev_addr, &adapter->if_handle,
-                       &adapter->pmac_id, 0);
+                       &adapter->pmac_id[0], 0);
        if (status != 0)
                goto err;
 
@@ -3059,6 +3131,8 @@ static void be_netdev_init(struct net_device *netdev)
        netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 |
                NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 
+       netdev->priv_flags |= IFF_UNICAST_FLT;
+
        netdev->flags |= IFF_MULTICAST;
 
        netif_set_gso_max_size(netdev, 65535);
@@ -3260,10 +3334,21 @@ static int be_get_config(struct be_adapter *adapter)
                return status;
 
        if (adapter->function_mode & FLEX10_MODE)
-               adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/4;
+               adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/8;
        else
                adapter->max_vlans = BE_NUM_VLANS_SUPPORTED;
 
+       if (be_physfn(adapter))
+               adapter->max_pmac_cnt = BE_UC_PMAC_COUNT;
+       else
+               adapter->max_pmac_cnt = BE_VF_UC_PMAC_COUNT;
+
+       /* primary mac needs 1 pmac entry */
+       adapter->pmac_id = kcalloc(adapter->max_pmac_cnt + 1,
+                                 sizeof(u32), GFP_KERNEL);
+       if (!adapter->pmac_id)
+               return -ENOMEM;
+
        status = be_cmd_get_cntl_attributes(adapter);
        if (status)
                return status;