Skip to content

Commit 93040ae

Browse files
Somnath Koturdavem330
authored andcommitted
be2net: Fix to trim skb for padded vlan packets to workaround an ASIC Bug
Fixed spelling error in a comment as pointed out by DaveM. Also refactored existing code a bit to provide placeholders for another ASIC Bug workaround that will be checked-in soon after this. Signed-off-by: Somnath Kotur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 525b807 commit 93040ae

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

drivers/net/ethernet/emulex/benet/be.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ static inline u8 is_udp_pkt(struct sk_buff *skb)
573573
return val;
574574
}
575575

576+
static inline bool is_ipv4_pkt(struct sk_buff *skb)
577+
{
578+
return skb->protocol == ntohs(ETH_P_IP) && ip_hdr(skb)->version == 4;
579+
}
580+
576581
static inline void be_vf_eth_addr_generate(struct be_adapter *adapter, u8 *mac)
577582
{
578583
u32 addr;

drivers/net/ethernet/emulex/benet/be_main.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,11 @@ static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter,
577577
return vlan_tag;
578578
}
579579

580+
static int be_vlan_tag_chk(struct be_adapter *adapter, struct sk_buff *skb)
581+
{
582+
return vlan_tx_tag_present(skb) || adapter->pvid;
583+
}
584+
580585
static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr,
581586
struct sk_buff *skb, u32 wrb_cnt, u32 len)
582587
{
@@ -704,33 +709,56 @@ static int make_tx_wrbs(struct be_adapter *adapter, struct be_queue_info *txq,
704709
return 0;
705710
}
706711

712+
static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
713+
struct sk_buff *skb)
714+
{
715+
u16 vlan_tag = 0;
716+
717+
skb = skb_share_check(skb, GFP_ATOMIC);
718+
if (unlikely(!skb))
719+
return skb;
720+
721+
if (vlan_tx_tag_present(skb)) {
722+
vlan_tag = be_get_tx_vlan_tag(adapter, skb);
723+
__vlan_put_tag(skb, vlan_tag);
724+
skb->vlan_tci = 0;
725+
}
726+
727+
return skb;
728+
}
729+
707730
static netdev_tx_t be_xmit(struct sk_buff *skb,
708731
struct net_device *netdev)
709732
{
710733
struct be_adapter *adapter = netdev_priv(netdev);
711734
struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)];
712735
struct be_queue_info *txq = &txo->q;
736+
struct iphdr *ip = NULL;
713737
u32 wrb_cnt = 0, copied = 0;
714-
u32 start = txq->head;
738+
u32 start = txq->head, eth_hdr_len;
715739
bool dummy_wrb, stopped = false;
716740

717-
/* For vlan tagged pkts, BE
718-
* 1) calculates checksum even when CSO is not requested
719-
* 2) calculates checksum wrongly for padded pkt less than
720-
* 60 bytes long.
721-
* As a workaround disable TX vlan offloading in such cases.
741+
eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ?
742+
VLAN_ETH_HLEN : ETH_HLEN;
743+
744+
/* HW has a bug which considers padding bytes as legal
745+
* and modifies the IPv4 hdr's 'tot_len' field
722746
*/
723-
if (vlan_tx_tag_present(skb) &&
724-
(skb->ip_summed != CHECKSUM_PARTIAL || skb->len <= 60)) {
725-
skb = skb_share_check(skb, GFP_ATOMIC);
726-
if (unlikely(!skb))
727-
goto tx_drop;
747+
if (skb->len <= 60 && be_vlan_tag_chk(adapter, skb) &&
748+
is_ipv4_pkt(skb)) {
749+
ip = (struct iphdr *)ip_hdr(skb);
750+
pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len));
751+
}
728752

729-
skb = __vlan_put_tag(skb, be_get_tx_vlan_tag(adapter, skb));
753+
/* HW has a bug wherein it will calculate CSUM for VLAN
754+
* pkts even though it is disabled.
755+
* Manually insert VLAN in pkt.
756+
*/
757+
if (skb->ip_summed != CHECKSUM_PARTIAL &&
758+
be_vlan_tag_chk(adapter, skb)) {
759+
skb = be_insert_vlan_in_pkt(adapter, skb);
730760
if (unlikely(!skb))
731761
goto tx_drop;
732-
733-
skb->vlan_tci = 0;
734762
}
735763

736764
wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb);

0 commit comments

Comments
 (0)