Skip to content

Commit 862b3d2

Browse files
Salildavem330
authored andcommitted
net: hns: Fix to conditionally convey RX checksum flag to stack
This patch introduces the RX checksum function to check the status of the hardware calculated checksum and its error and appropriately convey status to the upper stack in skb->ip_summed field. In hardware, we only support checksum for the following protocols: 1) IPv4, 2) TCP(over IPv4 or IPv6), 3) UDP(over IPv4 or IPv6), 4) SCTP(over IPv4 or IPv6) but we support many L3(IPv4, IPv6, MPLS, PPPoE etc) and L4(TCP, UDP, GRE, SCTP, IGMP, ICMP etc.) protocols. Hardware limitation: Our present hardware RX Descriptor lacks L3/L4 checksum "Status & Error" bit (which usually can be used to indicate whether checksum was calculated by the hardware and if there was any error encountered during checksum calculation). Software workaround: We do get info within the RX descriptor about the kind of L3/L4 protocol coming in the packet and the error status. These errors might not just be checksum errors but could be related to version, length of IPv4, UDP, TCP etc. Because there is no-way of knowing if it is a L3/L4 error due to bad checksum or any other L3/L4 error, we will not (cannot) convey hardware checksum status(CHECKSUM_UNNECESSARY) for such cases to upper stack and will not maintain the RX L3/L4 checksum counters as well. Signed-off-by: Salil Mehta <salil.mehta@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 48e0a83 commit 862b3d2

2 files changed

Lines changed: 71 additions & 7 deletions

File tree

‎drivers/net/ethernet/hisilicon/hns/hnae.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ enum hnae_led_state {
9999
#define HNS_RX_FLAG_L3ID_IPV6 0x1
100100
#define HNS_RX_FLAG_L4ID_UDP 0x0
101101
#define HNS_RX_FLAG_L4ID_TCP 0x1
102+
#define HNS_RX_FLAG_L4ID_SCTP 0x3
103+
102104

103105
#define HNS_TXD_ASID_S 0
104106
#define HNS_TXD_ASID_M (0xff << HNS_TXD_ASID_S)

‎drivers/net/ethernet/hisilicon/hns/hns_enet.c‎

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,71 @@ static void get_rx_desc_bnum(u32 bnum_flag, int *out_bnum)
566566
HNS_RXD_BUFNUM_M, HNS_RXD_BUFNUM_S);
567567
}
568568

569+
static void hns_nic_rx_checksum(struct hns_nic_ring_data *ring_data,
570+
struct sk_buff *skb, u32 flag)
571+
{
572+
struct net_device *netdev = ring_data->napi.dev;
573+
u32 l3id;
574+
u32 l4id;
575+
576+
/* check if RX checksum offload is enabled */
577+
if (unlikely(!(netdev->features & NETIF_F_RXCSUM)))
578+
return;
579+
580+
/* In hardware, we only support checksum for the following protocols:
581+
* 1) IPv4,
582+
* 2) TCP(over IPv4 or IPv6),
583+
* 3) UDP(over IPv4 or IPv6),
584+
* 4) SCTP(over IPv4 or IPv6)
585+
* but we support many L3(IPv4, IPv6, MPLS, PPPoE etc) and L4(TCP,
586+
* UDP, GRE, SCTP, IGMP, ICMP etc.) protocols.
587+
*
588+
* Hardware limitation:
589+
* Our present hardware RX Descriptor lacks L3/L4 checksum "Status &
590+
* Error" bit (which usually can be used to indicate whether checksum
591+
* was calculated by the hardware and if there was any error encountered
592+
* during checksum calculation).
593+
*
594+
* Software workaround:
595+
* We do get info within the RX descriptor about the kind of L3/L4
596+
* protocol coming in the packet and the error status. These errors
597+
* might not just be checksum errors but could be related to version,
598+
* length of IPv4, UDP, TCP etc.
599+
* Because there is no-way of knowing if it is a L3/L4 error due to bad
600+
* checksum or any other L3/L4 error, we will not (cannot) convey
601+
* checksum status for such cases to upper stack and will not maintain
602+
* the RX L3/L4 checksum counters as well.
603+
*/
604+
605+
l3id = hnae_get_field(flag, HNS_RXD_L3ID_M, HNS_RXD_L3ID_S);
606+
l4id = hnae_get_field(flag, HNS_RXD_L4ID_M, HNS_RXD_L4ID_S);
607+
608+
/* check L3 protocol for which checksum is supported */
609+
if ((l3id != HNS_RX_FLAG_L3ID_IPV4) && (l3id != HNS_RX_FLAG_L3ID_IPV6))
610+
return;
611+
612+
/* check for any(not just checksum)flagged L3 protocol errors */
613+
if (unlikely(hnae_get_bit(flag, HNS_RXD_L3E_B)))
614+
return;
615+
616+
/* we do not support checksum of fragmented packets */
617+
if (unlikely(hnae_get_bit(flag, HNS_RXD_FRAG_B)))
618+
return;
619+
620+
/* check L4 protocol for which checksum is supported */
621+
if ((l4id != HNS_RX_FLAG_L4ID_TCP) &&
622+
(l4id != HNS_RX_FLAG_L4ID_UDP) &&
623+
(l4id != HNS_RX_FLAG_L4ID_SCTP))
624+
return;
625+
626+
/* check for any(not just checksum)flagged L4 protocol errors */
627+
if (unlikely(hnae_get_bit(flag, HNS_RXD_L4E_B)))
628+
return;
629+
630+
/* now, this has to be a packet with valid RX checksum */
631+
skb->ip_summed = CHECKSUM_UNNECESSARY;
632+
}
633+
569634
static int hns_nic_poll_rx_skb(struct hns_nic_ring_data *ring_data,
570635
struct sk_buff **out_skb, int *out_bnum)
571636
{
@@ -684,13 +749,10 @@ static int hns_nic_poll_rx_skb(struct hns_nic_ring_data *ring_data,
684749
ring->stats.rx_pkts++;
685750
ring->stats.rx_bytes += skb->len;
686751

687-
if (unlikely(hnae_get_bit(bnum_flag, HNS_RXD_L3E_B) ||
688-
hnae_get_bit(bnum_flag, HNS_RXD_L4E_B))) {
689-
ring->stats.l3l4_csum_err++;
690-
return 0;
691-
}
692-
693-
skb->ip_summed = CHECKSUM_UNNECESSARY;
752+
/* indicate to upper stack if our hardware has already calculated
753+
* the RX checksum
754+
*/
755+
hns_nic_rx_checksum(ring_data, skb, bnum_flag);
694756

695757
return 0;
696758
}

0 commit comments

Comments
 (0)