]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
i40e/i40evf: Factor out L4 header and checksum from L3 bits in TSO path
authorAlexander Duyck <aduyck@mirantis.com>
Mon, 25 Jan 2016 05:16:28 +0000 (21:16 -0800)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 10 Mar 2016 16:37:35 +0000 (08:37 -0800)
Orabug: 22342532

This patch makes it so that the L4 header offsets and such can be ignored
when dealing with the L3 checksum and length update.  This is done making
use of two things.

First we can just use the offset from the L4 header to the start of the
packet to determine the L4 offset, and from that we can then make use of
the data offset to determine the full length of the headers.

As far as adjusting the checksum to remove the length we can simply add the
inverse of the length instead of having to recompute the entire
pseudo-header without the length.  In the case of an IPv6 header this
should be significantly cheaper since we can make use of a value we already
needed instead of having to read the source and destination address out of
the packet.

Signed-off-by: Alexander Duyck <aduyck@mirantis.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
(cherry picked from commit c49a7bc3308099a8d5f9e2e38adfc5ab969804aa)
Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/net/ethernet/intel/i40e/i40e_txrx.c
drivers/net/ethernet/intel/i40evf/i40e_txrx.c

index ead6d55e673ec43a8722d1fb9af6c24f444568fd..2b97b0756cdedbc6ab11f7993e39925311f39bc8 100644 (file)
@@ -2268,9 +2268,12 @@ static int i40e_tso(struct i40e_ring *tx_ring, struct sk_buff *skb,
 {
        u64 cd_cmd, cd_tso_len, cd_mss;
        struct ipv6hdr *ipv6h;
-       struct tcphdr *tcph;
        struct iphdr *iph;
-       u32 l4len;
+       union {
+               struct tcphdr *tcp;
+               unsigned char *hdr;
+       } l4;
+       u32 paylen, l4_offset;
        int err;
 
        if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -2285,24 +2288,26 @@ static int i40e_tso(struct i40e_ring *tx_ring, struct sk_buff *skb,
 
        iph = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb);
        ipv6h = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
+       l4.hdr = skb->encapsulation ? skb_inner_transport_header(skb) :
+                                     skb_transport_header(skb);
 
        if (iph->version == 4) {
-               tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
                iph->tot_len = 0;
                iph->check = 0;
-               tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
-                                                0, IPPROTO_TCP, 0);
-       } else if (ipv6h->version == 6) {
-               tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
+       } else {
                ipv6h->payload_len = 0;
-               tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
-                                              0, IPPROTO_TCP, 0);
        }
 
-       l4len = skb->encapsulation ? inner_tcp_hdrlen(skb) : tcp_hdrlen(skb);
-       *hdr_len = (skb->encapsulation
-                   ? (skb_inner_transport_header(skb) - skb->data)
-                   : skb_transport_offset(skb)) + l4len;
+       /* determine offset of inner transport header */
+       l4_offset = l4.hdr - skb->data;
+
+       /* remove payload length from inner checksum */
+       paylen = (__force u16)l4.tcp->check;
+       paylen += ntohs(1) * (u16)~(skb->len - l4_offset);
+       l4.tcp->check = ~csum_fold((__force __wsum)paylen);
+
+       /* compute length of segmentation header */
+       *hdr_len = (l4.tcp->doff * 4) + l4_offset;
 
        /* find the field values */
        cd_cmd = I40E_TX_CTX_DESC_TSO;
index 8c3d70d9698c6b0e933dc6735796f789e70ea733..0f207a158955a96e54c1b98589697b197441ef5d 100644 (file)
@@ -1528,9 +1528,12 @@ static int i40e_tso(struct i40e_ring *tx_ring, struct sk_buff *skb,
 {
        u64 cd_cmd, cd_tso_len, cd_mss;
        struct ipv6hdr *ipv6h;
-       struct tcphdr *tcph;
        struct iphdr *iph;
-       u32 l4len;
+       union {
+               struct tcphdr *tcp;
+               unsigned char *hdr;
+       } l4;
+       u32 paylen, l4_offset;
        int err;
 
        if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -1545,24 +1548,26 @@ static int i40e_tso(struct i40e_ring *tx_ring, struct sk_buff *skb,
 
        iph = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb);
        ipv6h = skb->encapsulation ? inner_ipv6_hdr(skb) : ipv6_hdr(skb);
+       l4.hdr = skb->encapsulation ? skb_inner_transport_header(skb) :
+                                     skb_transport_header(skb);
 
        if (iph->version == 4) {
-               tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
                iph->tot_len = 0;
                iph->check = 0;
-               tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
-                                                0, IPPROTO_TCP, 0);
-       } else if (ipv6h->version == 6) {
-               tcph = skb->encapsulation ? inner_tcp_hdr(skb) : tcp_hdr(skb);
+       } else {
                ipv6h->payload_len = 0;
-               tcph->check = ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
-                                              0, IPPROTO_TCP, 0);
        }
 
-       l4len = skb->encapsulation ? inner_tcp_hdrlen(skb) : tcp_hdrlen(skb);
-       *hdr_len = (skb->encapsulation
-                   ? (skb_inner_transport_header(skb) - skb->data)
-                   : skb_transport_offset(skb)) + l4len;
+       /* determine offset of inner transport header */
+       l4_offset = l4.hdr - skb->data;
+
+       /* remove payload length from inner checksum */
+       paylen = (__force u16)l4.tcp->check;
+       paylen += ntohs(1) * (u16)~(skb->len - l4_offset);
+       l4.tcp->check = ~csum_fold((__force __wsum)paylen);
+
+       /* compute length of segmentation header */
+       *hdr_len = (l4.tcp->doff * 4) + l4_offset;
 
        /* find the field values */
        cd_cmd = I40E_TX_CTX_DESC_TSO;