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 1c84bc8..ef1f940 100644 (file)
@@ -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);
@@ -978,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,
@@ -2525,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);
@@ -2549,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: