Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet device independent part of ipv6 rx checksum offl...



details:   https://anonhg.NetBSD.org/src/rev/09b9997acd5c
branches:  trunk
changeset: 583517:09b9997acd5c
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Aug 10 13:05:16 2005 +0000

description:
device independent part of ipv6 rx checksum offloading.

diffstat:

 sys/netinet/tcp_input.c  |  44 +++++++++++++++++++++++++++++++----
 sys/netinet/tcp_subr.c   |  22 ++++++++++++++++-
 sys/netinet/udp_usrreq.c |  58 +++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 111 insertions(+), 13 deletions(-)

diffs (232 lines):

diff -r b3bd60bbb73d -r 09b9997acd5c sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Wed Aug 10 12:59:43 2005 +0000
+++ b/sys/netinet/tcp_input.c   Wed Aug 10 13:05:16 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.231 2005/07/19 17:00:02 christos Exp $ */
+/*     $NetBSD: tcp_input.c,v 1.232 2005/08/10 13:05:16 yamt Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -150,7 +150,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.231 2005/07/19 17:00:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.232 2005/08/10 13:05:16 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -321,10 +321,18 @@
 #ifdef TCP_CSUM_COUNTERS
 #include <sys/device.h>
 
+#if defined(INET)
 extern struct evcnt tcp_hwcsum_ok;
 extern struct evcnt tcp_hwcsum_bad;
 extern struct evcnt tcp_hwcsum_data;
 extern struct evcnt tcp_swcsum;
+#endif /* defined(INET) */
+#if defined(INET6)
+extern struct evcnt tcp6_hwcsum_ok;
+extern struct evcnt tcp6_hwcsum_bad;
+extern struct evcnt tcp6_hwcsum_data;
+extern struct evcnt tcp6_swcsum;
+#endif /* defined(INET6) */
 
 #define        TCP_CSUM_COUNTER_INCR(ev)       (ev)->ev_count++
 
@@ -895,10 +903,34 @@
 
 #ifdef INET6
        case AF_INET6:
-               if (__predict_true((m->m_flags & M_LOOP) == 0 ||
-                   tcp_do_loopback_cksum)) {
-                       if (in6_cksum(m, IPPROTO_TCP, toff, tlen + off) != 0)
-                               goto badcsum;
+               switch (m->m_pkthdr.csum_flags &
+                       ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_TCPv6) |
+                        M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {
+               case M_CSUM_TCPv6|M_CSUM_TCP_UDP_BAD:
+                       TCP_CSUM_COUNTER_INCR(&tcp6_hwcsum_bad);
+                       goto badcsum;
+
+#if 0 /* notyet */
+               case M_CSUM_TCPv6|M_CSUM_DATA:
+#endif
+
+               case M_CSUM_TCPv6:
+                       /* Checksum was okay. */
+                       TCP_CSUM_COUNTER_INCR(&tcp6_hwcsum_ok);
+                       break;
+
+               default:
+                       /*
+                        * Must compute it ourselves.  Maybe skip checksum
+                        * on loopback interfaces.
+                        */
+                       if (__predict_true((m->m_flags & M_LOOP) == 0 ||
+                           tcp_do_loopback_cksum)) {
+                               TCP_CSUM_COUNTER_INCR(&tcp6_swcsum);
+                               if (in6_cksum(m, IPPROTO_TCP, toff,
+                                   tlen + off) != 0)
+                                       goto badcsum;
+                       }
                }
                break;
 #endif /* INET6 */
diff -r b3bd60bbb73d -r 09b9997acd5c sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Wed Aug 10 12:59:43 2005 +0000
+++ b/sys/netinet/tcp_subr.c    Wed Aug 10 13:05:16 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.193 2005/07/20 08:05:43 he Exp $        */
+/*     $NetBSD: tcp_subr.c,v 1.194 2005/08/10 13:05:16 yamt Exp $      */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.193 2005/07/20 08:05:43 he Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.194 2005/08/10 13:05:16 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -237,6 +237,7 @@
 #ifdef TCP_CSUM_COUNTERS
 #include <sys/device.h>
 
+#if defined(INET)
 struct evcnt tcp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "tcp", "hwcsum bad");
 struct evcnt tcp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
@@ -250,6 +251,23 @@
 EVCNT_ATTACH_STATIC(tcp_hwcsum_ok);
 EVCNT_ATTACH_STATIC(tcp_hwcsum_data);
 EVCNT_ATTACH_STATIC(tcp_swcsum);
+#endif /* defined(INET) */
+
+#if defined(INET6)
+struct evcnt tcp6_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "tcp6", "hwcsum bad");
+struct evcnt tcp6_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "tcp6", "hwcsum ok");
+struct evcnt tcp6_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "tcp6", "hwcsum data");
+struct evcnt tcp6_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "tcp6", "swcsum");
+
+EVCNT_ATTACH_STATIC(tcp6_hwcsum_bad);
+EVCNT_ATTACH_STATIC(tcp6_hwcsum_ok);
+EVCNT_ATTACH_STATIC(tcp6_hwcsum_data);
+EVCNT_ATTACH_STATIC(tcp6_swcsum);
+#endif /* defined(INET6) */
 #endif /* TCP_CSUM_COUNTERS */
 
 
diff -r b3bd60bbb73d -r 09b9997acd5c sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Wed Aug 10 12:59:43 2005 +0000
+++ b/sys/netinet/udp_usrreq.c  Wed Aug 10 13:05:16 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: udp_usrreq.c,v 1.139 2005/08/05 09:21:26 elad Exp $    */
+/*     $NetBSD: udp_usrreq.c,v 1.140 2005/08/10 13:05:17 yamt Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.139 2005/08/05 09:21:26 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.140 2005/08/10 13:05:17 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -186,6 +186,7 @@
 #ifdef UDP_CSUM_COUNTERS
 #include <sys/device.h>
 
+#if defined(INET)
 struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "udp", "hwcsum bad");
 struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
@@ -195,12 +196,29 @@
 struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "udp", "swcsum");
 
-#define        UDP_CSUM_COUNTER_INCR(ev)       (ev)->ev_count++
-
 EVCNT_ATTACH_STATIC(udp_hwcsum_bad);
 EVCNT_ATTACH_STATIC(udp_hwcsum_ok);
 EVCNT_ATTACH_STATIC(udp_hwcsum_data);
 EVCNT_ATTACH_STATIC(udp_swcsum);
+#endif /* defined(INET) */
+
+#if defined(INET6)
+struct evcnt udp6_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "udp6", "hwcsum bad");
+struct evcnt udp6_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "udp6", "hwcsum ok");
+struct evcnt udp6_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "udp6", "hwcsum data");
+struct evcnt udp6_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
+    NULL, "udp6", "swcsum");
+
+EVCNT_ATTACH_STATIC(udp6_hwcsum_bad);
+EVCNT_ATTACH_STATIC(udp6_hwcsum_ok);
+EVCNT_ATTACH_STATIC(udp6_hwcsum_data);
+EVCNT_ATTACH_STATIC(udp6_swcsum);
+#endif /* defined(INET6) */
+
+#define        UDP_CSUM_COUNTER_INCR(ev)       (ev)->ev_count++
 
 #else
 
@@ -442,6 +460,11 @@
 udp6_input_checksum(struct mbuf *m, const struct udphdr *uh, int off, int len)
 {
 
+       /*
+        * XXX it's better to record and check if this mbuf is
+        * already checked.
+        */
+
        if (__predict_false((m->m_flags & M_LOOP) && !udp_do_loopback_cksum)) {
                goto good;
        }
@@ -449,9 +472,34 @@
                udp6stat.udp6s_nosum++;
                goto bad;
        }
-       if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) {
+
+       switch (m->m_pkthdr.csum_flags &
+           ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv6) |
+           M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {
+       case M_CSUM_UDPv6|M_CSUM_TCP_UDP_BAD:
+               UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_bad);
                udp6stat.udp6s_badsum++;
                goto bad;
+
+#if 0 /* notyet */
+       case M_CSUM_UDPv6|M_CSUM_DATA:
+#endif
+
+       case M_CSUM_UDPv6:
+               /* Checksum was okay. */
+               UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_ok);
+               break;
+
+       default:
+               /*
+                * Need to compute it ourselves.  Maybe skip checksum
+                * on loopback interfaces.
+                */
+               UDP_CSUM_COUNTER_INCR(&udp6_swcsum);
+               if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) {
+                       udp6stat.udp6s_badsum++;
+                       goto bad;
+               }
        }
 
 good:



Home | Main Index | Thread Index | Old Index