Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/xen/xen add support for skipping IPv4 checksums



details:   https://anonhg.NetBSD.org/src/rev/2f09b57b074d
branches:  trunk
changeset: 970290:2f09b57b074d
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Thu Mar 19 10:53:43 2020 +0000

description:
add support for skipping IPv4 checksums

diffstat:

 sys/arch/xen/xen/if_xennet_xenbus.c |   9 +++++----
 sys/arch/xen/xen/xennet_checksum.c  |  21 +++++++++++++++++----
 2 files changed, 22 insertions(+), 8 deletions(-)

diffs (93 lines):

diff -r d7f90f65d1be -r 2f09b57b074d sys/arch/xen/xen/if_xennet_xenbus.c
--- a/sys/arch/xen/xen/if_xennet_xenbus.c       Thu Mar 19 08:33:04 2020 +0000
+++ b/sys/arch/xen/xen/if_xennet_xenbus.c       Thu Mar 19 10:53:43 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_xennet_xenbus.c,v 1.91 2020/03/18 19:23:13 jdolecek Exp $      */
+/*      $NetBSD: if_xennet_xenbus.c,v 1.92 2020/03/19 10:53:43 jdolecek Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -84,7 +84,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.91 2020/03/18 19:23:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.92 2020/03/19 10:53:43 jdolecek Exp $");
 
 #include "opt_xen.h"
 #include "opt_nfs_boot.h"
@@ -387,7 +387,8 @@
        ifp->if_timer = 0;
        ifp->if_snd.ifq_maxlen = uimax(ifqmaxlen, NET_TX_RING_SIZE * 2);
        ifp->if_capabilities =
-               IFCAP_CSUM_UDPv4_Rx | IFCAP_CSUM_UDPv4_Tx
+               IFCAP_CSUM_IPv4_Rx | IFCAP_CSUM_IPv4_Tx
+               | IFCAP_CSUM_UDPv4_Rx | IFCAP_CSUM_UDPv4_Tx
                | IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_TCPv4_Tx;
        IFQ_SET_READY(&ifp->if_snd);
        if_attach(ifp);
@@ -1229,7 +1230,7 @@
                }
 
                if ((m->m_pkthdr.csum_flags &
-                   (M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) {
+                   (M_CSUM_TCPv4 | M_CSUM_UDPv4 | M_CSUM_IPv4)) != 0) {
                        txflags = NETTXF_csum_blank;
                } else {
                        txflags = NETTXF_data_validated;
diff -r d7f90f65d1be -r 2f09b57b074d sys/arch/xen/xen/xennet_checksum.c
--- a/sys/arch/xen/xen/xennet_checksum.c        Thu Mar 19 08:33:04 2020 +0000
+++ b/sys/arch/xen/xen/xennet_checksum.c        Thu Mar 19 10:53:43 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xennet_checksum.c,v 1.7 2020/03/18 19:23:13 jdolecek Exp $     */
+/*     $NetBSD: xennet_checksum.c,v 1.8 2020/03/19 10:53:43 jdolecek Exp $     */
 
 /*-
  * Copyright (c)2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.7 2020/03/18 19:23:13 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xennet_checksum.c,v 1.8 2020/03/19 10:53:43 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -126,15 +126,20 @@
 
        switch (nxt) {
        case IPPROTO_UDP:
-               m->m_pkthdr.csum_flags = M_CSUM_UDPv4;
+               m->m_pkthdr.csum_flags = M_CSUM_UDPv4 | M_CSUM_IPv4;
                m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
                m->m_pkthdr.csum_data |= iphlen << 16;
                break;
        case IPPROTO_TCP:
-               m->m_pkthdr.csum_flags = M_CSUM_TCPv4;
+               m->m_pkthdr.csum_flags = M_CSUM_TCPv4 | M_CSUM_IPv4;
                m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
                m->m_pkthdr.csum_data |= iphlen << 16;
                break;
+       case IPPROTO_ICMP:
+       case IPPROTO_IGMP:
+               m->m_pkthdr.csum_flags = M_CSUM_IPv4;
+               m->m_pkthdr.csum_data = iphlen << 16;
+               break;
        default:
            {
                static struct timeval lasttime;
@@ -153,6 +158,14 @@
                 */
                sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_rx;
 
+               /*
+                * Always initialize the sum to 0!  Some HW assisted
+                * checksumming requires this. in_undefer_cksum()
+                * also needs it to be zero.
+                */
+               if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
+                       iph->ip_sum = 0;
+
                if (sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4)) {
                        in_undefer_cksum(m, ehlen,
                            sw_csum & (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4));



Home | Main Index | Thread Index | Old Index