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)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 18 Feb 2016 18:34:05 +0000 (10:34 -0800)
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>
drivers/net/ethernet/intel/i40e/i40e_txrx.c
drivers/net/ethernet/intel/i40evf/i40e_txrx.c

index 5e825893f20334562b40dc53802282165aa00cb7..ce0234e67cc58e81ee35b469e051e02fe7eaa212 100644 (file)
@@ -2269,9 +2269,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)
@@ -2286,24 +2289,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 c5f98cba648ab07753397e585017852b1e9a7052..881d0ada99fcc2e5afec5e9e180ef71435fcc6dd 100644 (file)
@@ -1529,9 +1529,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)
@@ -1546,24 +1549,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;
This page took 0.028302 seconds and 5 git commands to generate.