CVS commit: src/sys/net

2021-12-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Dec 21 04:09:32 UTC 2021

Modified Files:
src/sys/net: pktqueue.c

Log Message:
Fix net.*.rps_hash=toeplitz-othercpus on one CPU systems.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net/pktqueue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/pktqueue.c
diff -u src/sys/net/pktqueue.c:1.15 src/sys/net/pktqueue.c:1.16
--- src/sys/net/pktqueue.c:1.15	Wed Dec 15 07:47:22 2021
+++ src/sys/net/pktqueue.c	Tue Dec 21 04:09:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pktqueue.c,v 1.15 2021/12/15 07:47:22 knakahara Exp $	*/
+/*	$NetBSD: pktqueue.c,v 1.16 2021/12/21 04:09:32 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.15 2021/12/15 07:47:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.16 2021/12/21 04:09:32 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -284,6 +284,9 @@ pktq_rps_hash_toeplitz_othercpus(const s
 {
 	uint32_t hash;
 
+	if (ncpu == 1)
+		return 0;
+
 	hash = pktq_rps_hash_toeplitz(m);
 	hash %= ncpu - 1;
 	if (hash >= cpu_index(curcpu()))



CVS commit: src/sys/net

2021-12-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Dec 21 04:09:32 UTC 2021

Modified Files:
src/sys/net: pktqueue.c

Log Message:
Fix net.*.rps_hash=toeplitz-othercpus on one CPU systems.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net/pktqueue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2021-12-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec 17 08:27:06 UTC 2021

Modified Files:
src/sys/dev/pci: files.pci

Log Message:
Add missing WM_TX_{,INTR_}PROCESS_LIMIT_DEFAULT options same as RX side.


To generate a diff of this commit:
cvs rdiff -u -r1.439 -r1.440 src/sys/dev/pci/files.pci

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.439 src/sys/dev/pci/files.pci:1.440
--- src/sys/dev/pci/files.pci:1.439	Fri Nov 12 06:51:04 2021
+++ src/sys/dev/pci/files.pci	Fri Dec 17 08:27:06 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.439 2021/11/12 06:51:04 skrll Exp $
+#	$NetBSD: files.pci,v 1.440 2021/12/17 08:27:06 knakahara Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -677,6 +677,8 @@ file	dev/pci/if_wm.c			wm
 defflag	opt_if_wm.h	WM_EVENT_COUNTERS WM_DISABLE_EVENT_COUNTERS
 defparam opt_if_wm.h	WM_RX_PROCESS_LIMIT_DEFAULT
 			WM_RX_INTR_PROCESS_LIMIT_DEFAULT
+			WM_TX_PROCESS_LIMIT_DEFAULT
+			WM_TX_INTR_PROCESS_LIMIT_DEFAULT
 			WM_DISABLE_MSI
 			WM_DISABLE_MSIX
 



CVS commit: src/sys/dev/pci

2021-12-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec 17 08:27:06 UTC 2021

Modified Files:
src/sys/dev/pci: files.pci

Log Message:
Add missing WM_TX_{,INTR_}PROCESS_LIMIT_DEFAULT options same as RX side.


To generate a diff of this commit:
cvs rdiff -u -r1.439 -r1.440 src/sys/dev/pci/files.pci

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-12-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 15 07:47:22 UTC 2021

Modified Files:
src/sys/net: pktqueue.c

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/net/pktqueue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/pktqueue.c
diff -u src/sys/net/pktqueue.c:1.14 src/sys/net/pktqueue.c:1.15
--- src/sys/net/pktqueue.c:1.14	Mon Oct 11 05:13:11 2021
+++ src/sys/net/pktqueue.c	Wed Dec 15 07:47:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pktqueue.c,v 1.14 2021/10/11 05:13:11 knakahara Exp $	*/
+/*	$NetBSD: pktqueue.c,v 1.15 2021/12/15 07:47:22 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.14 2021/10/11 05:13:11 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.15 2021/12/15 07:47:22 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -276,8 +276,8 @@ pktq_rps_hash_toeplitz(const struct mbuf
 }
 
 /*
- * topelitz without curcpu.
- * Generally, this has better performance than topelitz.
+ * toeplitz without curcpu.
+ * Generally, this has better performance than toeplitz.
  */
 static uint32_t
 pktq_rps_hash_toeplitz_othercpus(const struct mbuf *m)



CVS commit: src/sys/net

2021-12-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 15 07:47:22 UTC 2021

Modified Files:
src/sys/net: pktqueue.c

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/net/pktqueue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-10-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 25 02:10:56 UTC 2021

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
kpreempt_disable() before sppp_get_{ip,ip6}_addrs() are unnecessary now.


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/net/if_spppsubr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.260 src/sys/net/if_spppsubr.c:1.261
--- src/sys/net/if_spppsubr.c:1.260	Mon Oct 25 02:06:29 2021
+++ src/sys/net/if_spppsubr.c	Mon Oct 25 02:10:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.260 2021/10/25 02:06:29 knakahara Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.261 2021/10/25 02:10:56 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.260 2021/10/25 02:06:29 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.261 2021/10/25 02:10:56 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3413,9 +3413,7 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	memset(>dns_addrs, 0, sizeof sp->dns_addrs);
 
 #ifdef INET
-	kpreempt_disable();
 	sppp_get_ip_addrs(sp, , , 0);
-	kpreempt_enable();
 #else
 	myaddr = hisaddr = 0;
 #endif
@@ -3967,9 +3965,7 @@ sppp_ipcp_scr(struct sppp *sp)
 		if (sp->ipcp.flags & IPCP_MYADDR_SEEN) {
 			ouraddr = sp->ipcp.req_myaddr;	/* not sure if this can ever happen */
 		} else {
-			kpreempt_disable();
 			sppp_get_ip_addrs(sp, , 0, 0);
-			kpreempt_enable();
 		}
 		opt[i++] = IPCP_OPT_ADDRESS;
 		opt[i++] = 6;
@@ -4039,9 +4035,7 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	sp->ipv6cp.flags &= ~IPV6CP_MYIFID_SEEN;
 #endif
 
-	kpreempt_disable();
 	sppp_get_ip6_addrs(sp, , , 0);
-	kpreempt_enable();
 	/*
 	 * If we don't have our address, this probably means our
 	 * interface doesn't want to talk IPv6 at all.  (This could
@@ -4508,9 +4502,7 @@ sppp_ipv6cp_scr(struct sppp *sp)
 	KASSERT(SPPP_WLOCKED(sp));
 
 	if (ISSET(sp->ipv6cp.opts, SPPP_IPV6CP_OPT_IFID)) {
-		kpreempt_disable();
 		sppp_get_ip6_addrs(sp, , 0, 0);
-		kpreempt_enable();
 
 		opt[i++] = IPV6CP_OPT_IFID;
 		opt[i++] = 10;
@@ -6268,9 +6260,7 @@ sppp_params(struct sppp *sp, u_long cmd,
 		status->state = sp->scp[IDX_IPCP].state;
 		status->opts = sp->ipcp.opts;
 #ifdef INET
-		kpreempt_disable();
 		sppp_get_ip_addrs(sp, , 0, 0);
-		kpreempt_enable();
 #else
 		myaddr = 0;
 #endif



CVS commit: src/sys/net

2021-10-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 25 02:10:56 UTC 2021

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
kpreempt_disable() before sppp_get_{ip,ip6}_addrs() are unnecessary now.


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/net/if_spppsubr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-10-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 25 02:06:29 UTC 2021

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
Fix missing curlwp_bind() for ifa_release(), ok'ed by yamaguchi@n.o.

This causes the following KASSERT failure in pppoe server.
- sppp_rcr_event()
  - sppp_ipcp_confreq()
- sppp_get_ip_addrs()
  - psref_release()

After if_spppsubr.c:1.227, sppp_ipcp_confreq() is done in workqueue
instead of softint.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/sys/net/if_spppsubr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.259 src/sys/net/if_spppsubr.c:1.260
--- src/sys/net/if_spppsubr.c:1.259	Mon Oct 11 05:13:11 2021
+++ src/sys/net/if_spppsubr.c	Mon Oct 25 02:06:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.259 2021/10/11 05:13:11 knakahara Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.260 2021/10/25 02:06:29 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.259 2021/10/11 05:13:11 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.260 2021/10/25 02:06:29 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -5591,7 +5591,7 @@ sppp_get_ip_addrs(struct sppp *sp, uint3
 	struct ifaddr *ifa;
 	struct sockaddr_in *si, *sm;
 	uint32_t ssrc, ddst;
-	int s;
+	int bound, s;
 	struct psref psref;
 
 	sm = NULL;
@@ -5601,6 +5601,7 @@ sppp_get_ip_addrs(struct sppp *sp, uint3
 	 * aliases don't make any sense on a p2p link anyway.
 	 */
 	si = 0;
+	bound = curlwp_bind();
 	s = pserialize_read_enter();
 	IFADDR_READER_FOREACH(ifa, ifp) {
 		if (ifa->ifa_addr->sa_family == AF_INET) {
@@ -5625,6 +5626,7 @@ sppp_get_ip_addrs(struct sppp *sp, uint3
 			ddst = si->sin_addr.s_addr;
 		ifa_release(ifa, );
 	}
+	curlwp_bindx(bound);
 
 	if (dst) *dst = ntohl(ddst);
 	if (src) *src = ntohl(ssrc);
@@ -5783,7 +5785,7 @@ sppp_get_ip6_addrs(struct sppp *sp, stru
 	struct ifaddr *ifa;
 	struct sockaddr_in6 *si, *sm;
 	struct in6_addr ssrc, ddst;
-	int s;
+	int bound, s;
 	struct psref psref;
 
 	sm = NULL;
@@ -5794,6 +5796,7 @@ sppp_get_ip6_addrs(struct sppp *sp, stru
 	 * aliases don't make any sense on a p2p link anyway.
 	 */
 	si = 0;
+	bound = curlwp_bind();
 	s = pserialize_read_enter();
 	IFADDR_READER_FOREACH(ifa, ifp) {
 		if (ifa->ifa_addr->sa_family == AF_INET6) {
@@ -5821,6 +5824,7 @@ sppp_get_ip6_addrs(struct sppp *sp, stru
 			memcpy(, >sin6_addr, sizeof(ddst));
 		ifa_release(ifa, );
 	}
+	curlwp_bindx(bound);
 
 	if (dst)
 		memcpy(dst, , sizeof(*dst));



CVS commit: src/sys/net

2021-10-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 25 02:06:29 UTC 2021

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
Fix missing curlwp_bind() for ifa_release(), ok'ed by yamaguchi@n.o.

This causes the following KASSERT failure in pppoe server.
- sppp_rcr_event()
  - sppp_ipcp_confreq()
- sppp_get_ip_addrs()
  - psref_release()

After if_spppsubr.c:1.227, sppp_ipcp_confreq() is done in workqueue
instead of softint.


To generate a diff of this commit:
cvs rdiff -u -r1.259 -r1.260 src/sys/net/if_spppsubr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/doc

2021-10-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 21 02:47:17 UTC 2021

Modified Files:
src/doc: CHANGES

Log Message:
doc: pktq_rps_hash() changes.


To generate a diff of this commit:
cvs rdiff -u -r1.2841 -r1.2842 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2841 src/doc/CHANGES:1.2842
--- src/doc/CHANGES:1.2841	Thu Oct 14 21:18:07 2021
+++ src/doc/CHANGES	Thu Oct 21 02:47:17 2021
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2841 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2842 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -437,6 +437,8 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 	tzdata partly updated to 2021b [kre 20211001] 
 	sht4xtemp(4): Driver for the Sensirion SHT40/SHT41/SHT45 temperature
 		and humidity sensor [brad 20211003]
+	network: Make pktq_rps_hash() pluggable for each interface type.
+		[knakahara 20211011]
 	wm(4): Add Tiger Lake and newer devices (I219V 15-V9 and LM 16-19).
 		[msaitoh 20211013]
 	sgp40mox(4): Driver for the Sensirion SGP40 MOx gas sensor for air quality



CVS commit: src/doc

2021-10-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 21 02:47:17 UTC 2021

Modified Files:
src/doc: CHANGES

Log Message:
doc: pktq_rps_hash() changes.


To generate a diff of this commit:
cvs rdiff -u -r1.2841 -r1.2842 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2021-10-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 07:04:28 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix return value of interrupt handler, pointed out by msaitoh@n.o.

Even if stopping flag is set (and handler do nothing), the interrupt
itself should be assume to be processed when ICR is not zero.  If not,
interrupt count is not incremented correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.711 -r1.712 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.711 src/sys/dev/pci/if_wm.c:1.712
--- src/sys/dev/pci/if_wm.c:1.711	Wed Oct 20 02:12:36 2021
+++ src/sys/dev/pci/if_wm.c	Wed Oct 20 07:04:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.711 2021/10/20 02:12:36 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.712 2021/10/20 07:04:28 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.711 2021/10/20 02:12:36 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.712 2021/10/20 07:04:28 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -9853,7 +9853,7 @@ wm_intr_legacy(void *arg)
 
 	if (rxq->rxq_stopping) {
 		mutex_exit(rxq->rxq_lock);
-		return 0;
+		return 1;
 	}
 
 #if defined(WM_DEBUG) || defined(WM_EVENT_COUNTERS)
@@ -9877,7 +9877,7 @@ wm_intr_legacy(void *arg)
 
 	if (txq->txq_stopping) {
 		mutex_exit(txq->txq_lock);
-		return 0;
+		return 1;
 	}
 
 #if defined(WM_DEBUG) || defined(WM_EVENT_COUNTERS)
@@ -9897,7 +9897,7 @@ wm_intr_legacy(void *arg)
 
 	if (sc->sc_core_stopping) {
 		WM_CORE_UNLOCK(sc);
-		return 0;
+		return 1;
 	}
 
 	if (icr & (ICR_LSC | ICR_RXSEQ)) {
@@ -9997,7 +9997,7 @@ wm_txrxintr_msix(void *arg)
 
 	if (txq->txq_stopping) {
 		mutex_exit(txq->txq_lock);
-		return 0;
+		return 1;
 	}
 
 	WM_Q_EVCNT_INCR(txq, txdw);
@@ -10011,7 +10011,7 @@ wm_txrxintr_msix(void *arg)
 
 	if (rxq->rxq_stopping) {
 		mutex_exit(rxq->rxq_lock);
-		return 0;
+		return 1;
 	}
 
 	WM_Q_EVCNT_INCR(rxq, intr);



CVS commit: src/sys/dev/pci

2021-10-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 07:04:28 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix return value of interrupt handler, pointed out by msaitoh@n.o.

Even if stopping flag is set (and handler do nothing), the interrupt
itself should be assume to be processed when ICR is not zero.  If not,
interrupt count is not incremented correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.711 -r1.712 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2021-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 02:12:37 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Uniform INTx/MSI handler's Tx/Rx behavior to MSI-X's one.

Because the difference has caused INTx/MSI own bugs.


To generate a diff of this commit:
cvs rdiff -u -r1.710 -r1.711 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.710 src/sys/dev/pci/if_wm.c:1.711
--- src/sys/dev/pci/if_wm.c:1.710	Wed Oct 20 02:05:15 2021
+++ src/sys/dev/pci/if_wm.c	Wed Oct 20 02:12:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.710 2021/10/20 02:05:15 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.711 2021/10/20 02:12:36 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.710 2021/10/20 02:05:15 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.711 2021/10/20 02:12:36 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -9835,88 +9835,85 @@ wm_intr_legacy(void *arg)
 	struct wm_queue *wmq = >sc_queue[0];
 	struct wm_txqueue *txq = >wmq_txq;
 	struct wm_rxqueue *rxq = >wmq_rxq;
+	u_int txlimit = sc->sc_tx_intr_process_limit;
+	u_int rxlimit = sc->sc_rx_intr_process_limit;
 	uint32_t icr, rndval = 0;
-	int handled = 0;
 	bool more = false;
 
-	while (1 /* CONSTCOND */) {
-		icr = CSR_READ(sc, WMREG_ICR);
-		if ((icr & sc->sc_icr) == 0)
-			break;
-		if (handled == 0)
-			DPRINTF(sc, WM_DEBUG_TX,
-			("%s: INTx: got intr\n",device_xname(sc->sc_dev)));
-		if (rndval == 0)
-			rndval = icr;
+	icr = CSR_READ(sc, WMREG_ICR);
+	if ((icr & sc->sc_icr) == 0)
+		return 0;
 
-		mutex_enter(rxq->rxq_lock);
+	DPRINTF(sc, WM_DEBUG_TX,
+	("%s: INTx: got intr\n",device_xname(sc->sc_dev)));
+	if (rndval == 0)
+		rndval = icr;
 
-		if (rxq->rxq_stopping) {
-			mutex_exit(rxq->rxq_lock);
-			break;
-		}
+	mutex_enter(rxq->rxq_lock);
 
-		handled = 1;
+	if (rxq->rxq_stopping) {
+		mutex_exit(rxq->rxq_lock);
+		return 0;
+	}
 
 #if defined(WM_DEBUG) || defined(WM_EVENT_COUNTERS)
-		if (icr & (ICR_RXDMT0 | ICR_RXT0)) {
-			DPRINTF(sc, WM_DEBUG_RX,
-			("%s: RX: got Rx intr 0x%08x\n",
-device_xname(sc->sc_dev),
-icr & (ICR_RXDMT0 | ICR_RXT0)));
-			WM_Q_EVCNT_INCR(rxq, intr);
-		}
+	if (icr & (ICR_RXDMT0 | ICR_RXT0)) {
+		DPRINTF(sc, WM_DEBUG_RX,
+		("%s: RX: got Rx intr 0x%08x\n",
+			device_xname(sc->sc_dev),
+			icr & (ICR_RXDMT0 | ICR_RXT0)));
+		WM_Q_EVCNT_INCR(rxq, intr);
+	}
 #endif
-		/*
-		 * wm_rxeof() does *not* call upper layer functions directly,
-		 * as if_percpuq_enqueue() just call softint_schedule().
-		 * So, we can call wm_rxeof() in interrupt context.
-		 */
-		more = wm_rxeof(rxq, UINT_MAX);
+	/*
+	 * wm_rxeof() does *not* call upper layer functions directly,
+	 * as if_percpuq_enqueue() just call softint_schedule().
+	 * So, we can call wm_rxeof() in interrupt context.
+	 */
+	more = wm_rxeof(rxq, rxlimit);
 
-		mutex_exit(rxq->rxq_lock);
-		mutex_enter(txq->txq_lock);
+	mutex_exit(rxq->rxq_lock);
+	mutex_enter(txq->txq_lock);
 
-		if (txq->txq_stopping) {
-			mutex_exit(txq->txq_lock);
-			break;
-		}
+	if (txq->txq_stopping) {
+		mutex_exit(txq->txq_lock);
+		return 0;
+	}
 
 #if defined(WM_DEBUG) || defined(WM_EVENT_COUNTERS)
-		if (icr & ICR_TXDW) {
-			DPRINTF(sc, WM_DEBUG_TX,
-			("%s: TX: got TXDW interrupt\n",
-device_xname(sc->sc_dev)));
-			WM_Q_EVCNT_INCR(txq, txdw);
-		}
+	if (icr & ICR_TXDW) {
+		DPRINTF(sc, WM_DEBUG_TX,
+		("%s: TX: got TXDW interrupt\n",
+			device_xname(sc->sc_dev)));
+		WM_Q_EVCNT_INCR(txq, txdw);
+	}
 #endif
-		more |= wm_txeof(txq, UINT_MAX);
-		if (!IF_IS_EMPTY(>if_snd))
-			more = true;
+	more |= wm_txeof(txq, txlimit);
+	if (!IF_IS_EMPTY(>if_snd))
+		more = true;
 
-		mutex_exit(txq->txq_lock);
-		WM_CORE_LOCK(sc);
+	mutex_exit(txq->txq_lock);
+	WM_CORE_LOCK(sc);
 
-		if (sc->sc_core_stopping) {
-			WM_CORE_UNLOCK(sc);
-			break;
-		}
+	if (sc->sc_core_stopping) {
+		WM_CORE_UNLOCK(sc);
+		return 0;
+	}
 
-		if (icr & (ICR_LSC | ICR_RXSEQ)) {
-			WM_EVCNT_INCR(>sc_ev_linkintr);
-			wm_linkintr(sc, icr);
-		}
-		if ((icr & ICR_GPI(0)) != 0)
-			device_printf(sc->sc_dev, "got module interrupt\n");
+	if (icr & (ICR_LSC | ICR_RXSEQ)) {
+		WM_EVCNT_INCR(>sc_ev_linkintr);
+		wm_linkintr(sc, icr);
+	}
+	if ((icr & ICR_GPI(0)) != 0)
+		device_printf(sc->sc_dev, "got module interrupt\n");
 
-		WM_CORE_UNLOCK(sc);
+	WM_CORE_UNLOCK(sc);
 
-		if (icr & ICR_RXO) {
+	if (icr & ICR_RXO) {
 #if defined(WM_DEBUG)
-			log(LOG_WARNING, "%s: Receive overrun\n",
-			device_xname(sc->sc_dev));
+		log(LOG_WARNING, "%s: Receive overrun\n",
+		device_xname(sc->sc_dev));
 #endif /* defined(WM_DEBUG) */
-		}
 	}
 
 	rnd_add_uint32(>rnd_source, rndval);
@@ -9928,7 +9925,7 @@ wm_intr_legacy(void *arg)
 		

CVS commit: src/sys/dev/pci

2021-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 02:12:37 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Uniform INTx/MSI handler's Tx/Rx behavior to MSI-X's one.

Because the difference has caused INTx/MSI own bugs.


To generate a diff of this commit:
cvs rdiff -u -r1.710 -r1.711 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci

2021-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 02:05:15 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix Tx stall, reported and implemented original patch by chs@n.o, thanks.

Check if_snd queue because if.c::if_transmit() doesn't call ifp->if_start()
when IFQ_ENQUEUE failed.

Reviewed and tested by chs@n.o and msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.709 -r1.710 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.709 src/sys/dev/pci/if_wm.c:1.710
--- src/sys/dev/pci/if_wm.c:1.709	Mon Oct 18 11:36:11 2021
+++ src/sys/dev/pci/if_wm.c	Wed Oct 20 02:05:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.709 2021/10/18 11:36:11 jmcneill Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.710 2021/10/20 02:05:15 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.709 2021/10/18 11:36:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.710 2021/10/20 02:05:15 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -9831,6 +9831,7 @@ static int
 wm_intr_legacy(void *arg)
 {
 	struct wm_softc *sc = arg;
+	struct ifnet *ifp = >sc_ethercom.ec_if;
 	struct wm_queue *wmq = >sc_queue[0];
 	struct wm_txqueue *txq = >wmq_txq;
 	struct wm_rxqueue *rxq = >wmq_rxq;
@@ -9890,6 +9891,8 @@ wm_intr_legacy(void *arg)
 		}
 #endif
 		more |= wm_txeof(txq, UINT_MAX);
+		if (!IF_IS_EMPTY(>if_snd))
+			more = true;
 
 		mutex_exit(txq->txq_lock);
 		WM_CORE_LOCK(sc);



CVS commit: src/sys/dev/pci

2021-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 20 02:05:15 UTC 2021

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix Tx stall, reported and implemented original patch by chs@n.o, thanks.

Check if_snd queue because if.c::if_transmit() doesn't call ifp->if_start()
when IFQ_ENQUEUE failed.

Reviewed and tested by chs@n.o and msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.709 -r1.710 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/dev/pci

2021-10-18 Thread Kengo NAKAHARA

Hi,

Thank you for your quick commit!


Thanks,

On 2021/10/18 17:15, Juergen Hannken-Illjes wrote:

Module Name:src
Committed By:   hannken
Date:   Mon Oct 18 08:15:00 UTC 2021

Modified Files:
src/sys/dev/pci: xmm7360.c

Log Message:
Use a local static variable to hold "pktq_rps_hash_default"
like the other devices do.

Kernel ALL/amd64 compiles again.

OK: Kengo NAKAHARA 


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pci/xmm7360.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Division,
Technology Unit

Kengo NAKAHARA 




CVS commit: src/sys/dev/pci

2021-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 13 01:11:30 UTC 2021

Modified Files:
src/sys/dev/pci: if_vmx.c

Log Message:
Fix vmx(4) receive workqueue problem on qemu, reported by ozaki-r@n.o, thanks.

ESXi stops interrupt by vmxnet3_disable_intr() immediately.  In contrast, qemu
does not stop interrupt soon.  Hmm, qemu's behavior seems not to be correct,
however, there is no explicit specification of vmxnet3.  So, we have to accept
that behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_vmx.c
diff -u src/sys/dev/pci/if_vmx.c:1.4 src/sys/dev/pci/if_vmx.c:1.5
--- src/sys/dev/pci/if_vmx.c:1.4	Thu Oct 15 04:37:48 2020
+++ src/sys/dev/pci/if_vmx.c	Wed Oct 13 01:11:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.4 2020/10/15 04:37:48 ryo Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.5 2021/10/13 01:11:29 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.4 2020/10/15 04:37:48 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.5 2021/10/13 01:11:29 knakahara Exp $");
 
 #include 
 #include 
@@ -253,6 +253,7 @@ struct vmxnet3_queue {
 
 	void *vxq_si;
 	bool vxq_workqueue;
+	bool vxq_wq_enqueued;
 	struct work vxq_wq_cookie;
 };
 
@@ -2484,8 +2485,15 @@ vmxnet3_sched_handle_queue(struct vmxnet
 {
 
 	if (vmxq->vxq_workqueue) {
-		workqueue_enqueue(sc->vmx_queue_wq, >vxq_wq_cookie,
-		curcpu());
+		/*
+		 * When this function is called, "vmxq" is owned by one CPU.
+		 * so, atomic operation is not required here.
+		 */
+		if (!vmxq->vxq_wq_enqueued) {
+			vmxq->vxq_wq_enqueued = true;
+			workqueue_enqueue(sc->vmx_queue_wq,
+			>vxq_wq_cookie, curcpu());
+		}
 	} else {
 		softint_schedule(vmxq->vxq_si);
 	}
@@ -2625,6 +2633,7 @@ vmxnet3_handle_queue_work(struct work *w
 	struct vmxnet3_queue *vmxq;
 
 	vmxq = container_of(wk, struct vmxnet3_queue, vxq_wq_cookie);
+	vmxq->vxq_wq_enqueued = false;
 	vmxnet3_handle_queue(vmxq);
 }
 



CVS commit: src/sys/dev/pci

2021-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 13 01:11:30 UTC 2021

Modified Files:
src/sys/dev/pci: if_vmx.c

Log Message:
Fix vmx(4) receive workqueue problem on qemu, reported by ozaki-r@n.o, thanks.

ESXi stops interrupt by vmxnet3_disable_intr() immediately.  In contrast, qemu
does not stop interrupt soon.  Hmm, qemu's behavior seems not to be correct,
however, there is no explicit specification of vmxnet3.  So, we have to accept
that behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2021-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 11 05:13:11 UTC 2021

Modified Files:
src/sys/dev/pci: xmm7360.c
src/sys/net: if_ethersubr.c if_gif.c if_ipsec.c if_pppoe.c
if_spppsubr.c pktqueue.c pktqueue.h
src/sys/rump/librump/rumpnet: Makefile.rumpnet

Log Message:
Make pktq_rps_hash() pluggable for each interface type.  Reviewed by gdt@n.o, 
thorpej@n.o, and riastradh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/xmm7360.c
cvs rdiff -u -r1.300 -r1.301 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.155 -r1.156 src/sys/net/if_gif.c
cvs rdiff -u -r1.30 -r1.31 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.177 -r1.178 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.258 -r1.259 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/pktqueue.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/pktqueue.h
cvs rdiff -u -r1.23 -r1.24 src/sys/rump/librump/rumpnet/Makefile.rumpnet

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/xmm7360.c
diff -u src/sys/dev/pci/xmm7360.c:1.11 src/sys/dev/pci/xmm7360.c:1.12
--- src/sys/dev/pci/xmm7360.c:1.11	Mon Oct 11 01:07:36 2021
+++ src/sys/dev/pci/xmm7360.c	Mon Oct 11 05:13:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xmm7360.c,v 1.11 2021/10/11 01:07:36 thorpej Exp $	*/
+/*	$NetBSD: xmm7360.c,v 1.12 2021/10/11 05:13:10 knakahara Exp $	*/
 
 /*
  * Device driver for Intel XMM7360 LTE modems, eg. Fibocom L850-GL.
@@ -75,7 +75,7 @@ MODULE_DEVICE_TABLE(pci, xmm7360_ids);
 #include "opt_gateway.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.11 2021/10/11 01:07:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.12 2021/10/11 05:13:10 knakahara Exp $");
 #endif
 
 #include 
@@ -3110,11 +3110,7 @@ wwan_if_input(struct ifnet *ifp, struct 
 	/* No errors.  Receive the packet. */
 	m_set_rcvif(m, ifp);
 
-#ifdef NET_MPSAFE
-	const u_int h = curcpu()->ci_index;
-#else
-	const uint32_t h = pktq_rps_hash(m);
-#endif
+	const uint32_t h = pktq_rps_hash(_rps_hash_default, m);
 	if (__predict_false(!pktq_enqueue(pktq, m, h))) {
 		m_freem(m);
 	}

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.300 src/sys/net/if_ethersubr.c:1.301
--- src/sys/net/if_ethersubr.c:1.300	Thu Sep 30 04:29:16 2021
+++ src/sys/net/if_ethersubr.c	Mon Oct 11 05:13:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.300 2021/09/30 04:29:16 yamaguchi Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.301 2021/10/11 05:13:11 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.300 2021/09/30 04:29:16 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.301 2021/10/11 05:13:11 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -183,6 +183,8 @@ const uint8_t ethermulticastaddr_slowpro
 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x02 };
 #define senderr(e) { error = (e); goto bad;}
 
+static pktq_rps_hash_func_t ether_pktq_rps_hash_p;
+
 /* if_lagg(4) support */
 struct mbuf *(*lagg_input_ethernet_p)(struct ifnet *, struct mbuf *);
 
@@ -955,11 +957,7 @@ ether_input(struct ifnet *ifp, struct mb
 	}
 
 	if (__predict_true(pktq)) {
-#ifdef NET_MPSAFE
-		const u_int h = curcpu()->ci_index;
-#else
-		const uint32_t h = pktq_rps_hash(m);
-#endif
+		const uint32_t h = pktq_rps_hash(_pktq_rps_hash_p, m);
 		if (__predict_false(!pktq_enqueue(pktq, m, h))) {
 			m_freem(m);
 		}
@@ -1766,6 +1764,14 @@ ether_sysctl_setup(struct sysctllog **cl
 		   SYSCTL_DESCR("multicast addresses"),
 		   ether_multicast_sysctl, 0, NULL, 0,
 		   CTL_CREATE, CTL_EOL);
+
+	sysctl_createv(clog, 0, , NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_STRING, "rps_hash",
+		   SYSCTL_DESCR("Interface rps hash function control"),
+		   sysctl_pktq_rps_hash_handler, 0, (void *)_pktq_rps_hash_p,
+		   PKTQ_RPS_HASH_NAME_LEN,
+		   CTL_CREATE, CTL_EOL);
 }
 
 void
@@ -1775,5 +1781,6 @@ etherinit(void)
 #ifdef DIAGNOSTIC
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NET);
 #endif
+	ether_pktq_rps_hash_p = pktq_rps_hash_default;
 	ether_sysctl_setup(NULL);
 }

Index: src/sys/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.155 src/sys/net/if_gif.c:1.156
--- src/sys/net/if_gif.c:1.155	Wed Jun 16 00:21:19 2021
+++ src/sys/net/if_gif.c	Mon Oct 11 05:13:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.155 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.156 2021/10/11 05:13:11 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.155 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.156 2021/10/11 05:13:11 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -105,6 +105,8 @@ static struct {
 
 struct 

CVS commit: src/sys

2021-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 11 05:13:11 UTC 2021

Modified Files:
src/sys/dev/pci: xmm7360.c
src/sys/net: if_ethersubr.c if_gif.c if_ipsec.c if_pppoe.c
if_spppsubr.c pktqueue.c pktqueue.h
src/sys/rump/librump/rumpnet: Makefile.rumpnet

Log Message:
Make pktq_rps_hash() pluggable for each interface type.  Reviewed by gdt@n.o, 
thorpej@n.o, and riastradh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/xmm7360.c
cvs rdiff -u -r1.300 -r1.301 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.155 -r1.156 src/sys/net/if_gif.c
cvs rdiff -u -r1.30 -r1.31 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.177 -r1.178 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.258 -r1.259 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.13 -r1.14 src/sys/net/pktqueue.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/pktqueue.h
cvs rdiff -u -r1.23 -r1.24 src/sys/rump/librump/rumpnet/Makefile.rumpnet

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-09-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 08:40:35 UTC 2021

Modified Files:
src/sys/net: toeplitz.c

Log Message:
Add copyright for no-memcpy toeplitz hash, pointed out by wiz@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/net/toeplitz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/toeplitz.c
diff -u src/sys/net/toeplitz.c:1.3 src/sys/net/toeplitz.c:1.4
--- src/sys/net/toeplitz.c:1.3	Fri Sep 24 04:09:32 2021
+++ src/sys/net/toeplitz.c	Fri Sep 24 08:40:35 2021
@@ -51,6 +51,32 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+/*-
+ * Copyright (c) 2019 Ryo Shimizu 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #include 
 #include 
 #include 



CVS commit: src/sys/net

2021-09-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 08:40:35 UTC 2021

Modified Files:
src/sys/net: toeplitz.c

Log Message:
Add copyright for no-memcpy toeplitz hash, pointed out by wiz@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/net/toeplitz.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 05:26:06 UTC 2021

Modified Files:
src/sys/net: files.net

Log Message:
Fix build failure for i386 INSTALL_XEN3PAE_DOMU, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/files.net

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 05:26:06 UTC 2021

Modified Files:
src/sys/net: files.net

Log Message:
Fix build failure for i386 INSTALL_XEN3PAE_DOMU, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/files.net

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/files.net
diff -u src/sys/net/files.net:1.31 src/sys/net/files.net:1.32
--- src/sys/net/files.net:1.31	Mon May 17 04:07:43 2021
+++ src/sys/net/files.net	Fri Sep 24 05:26:06 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.net,v 1.31 2021/05/17 04:07:43 yamaguchi Exp $
+#	$NetBSD: files.net,v 1.32 2021/09/24 05:26:06 knakahara Exp $
 
 # XXX CLEANUP
 define	net
@@ -49,7 +49,7 @@ file	net/rss_config.c		net
 file	net/rtbl.c			net
 file	net/rtsock.c			net
 file	net/slcompress.c		sl | ppp | (irip & irip_vj)
-file	net/toeplitz.c			toeplitz
+file	net/toeplitz.c			toeplitz | net
 file	net/zlib.c			(ppp & ppp_deflate) | swcrypto | vnd_compression
 file	netinet/accf_data.c		accf_data
 file	netinet/accf_http.c		accf_http



CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 04:11:02 UTC 2021

Modified Files:
src/sys/net: rss_config.c rss_config.h

Log Message:
Add RSS toeplitz hash functions which calculate from mbuf.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/rss_config.c
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/rss_config.c
diff -u src/sys/net/rss_config.c:1.2 src/sys/net/rss_config.c:1.3
--- src/sys/net/rss_config.c:1.2	Wed Nov 20 08:17:01 2019
+++ src/sys/net/rss_config.c	Fri Sep 24 04:11:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $  */
+/*	$NetBSD: rss_config.c,v 1.3 2021/09/24 04:11:02 knakahara Exp $  */
 
 /*
  * Copyright (c) 2018 Internet Initiative Japan Inc.
@@ -27,13 +27,21 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.3 2021/09/24 04:11:02 knakahara Exp $");
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
 
 /*
  * Same as FreeBSD.
@@ -75,3 +83,201 @@ rss_getkey(uint8_t *key)
 
 	memcpy(key, rss_default_key, sizeof(rss_default_key));
 }
+
+/*
+ * Calculate rss hash value from IPv4 mbuf.
+ * This function should be called before ip_input().
+ */
+uint32_t
+rss_toeplitz_hash_from_mbuf_ipv4(const struct mbuf *m, u_int flag)
+{
+	struct ip *ip;
+	int hlen;
+	uint8_t key[RSS_KEYSIZE];
+
+	KASSERT((m->m_flags & M_PKTHDR) != 0);
+	KASSERT(m->m_len >= sizeof (struct ip));
+
+	ip = mtod(m, struct ip *);
+	KASSERT(ip->ip_v == IPVERSION);
+
+	hlen = ip->ip_hl << 2;
+	if (hlen < sizeof(struct ip))
+		return 0;
+
+	rss_getkey(key);
+
+	switch (ip->ip_p) {
+	case IPPROTO_TCP:
+	{
+		if ((flag & RSS_TOEPLITZ_USE_TCP_PORT) != 0) {
+			if (m->m_len >= hlen + sizeof(struct tcphdr)) {
+struct tcphdr *th;
+
+th = (struct tcphdr *)(mtod(m, char *) + hlen);
+return toeplitz_vhash(key, sizeof(key),
+/* ip_src and ip_dst in struct ip must be sequential */
+>ip_src, sizeof(ip->ip_src) * 2,
+/* th_sport and th_dport in tcphdr must be sequential */
+>th_sport, sizeof(th->th_sport) * 2,
+NULL);
+			} else if (m->m_pkthdr.len >= hlen + sizeof(struct tcphdr)) {
+uint16_t ports[2];
+
+/* ditto */
+m_copydata(__UNCONST(m), hlen + offsetof(struct tcphdr, th_sport),
+sizeof(ports), ports);
+return toeplitz_vhash(key, sizeof(key),
+>ip_src, sizeof(ip->ip_src) * 2,
+ports, sizeof(ports),
+NULL);
+			}
+		}
+		/*
+		 * Treat as raw packet.
+		 */
+		return toeplitz_vhash(key, sizeof(key),
+		/* ditto */
+		>ip_src, sizeof(ip->ip_src) * 2,
+		NULL);
+	}
+	case IPPROTO_UDP:
+	{
+		if ((flag & RSS_TOEPLITZ_USE_UDP_PORT) != 0) {
+			if (m->m_len >= hlen + sizeof(struct udphdr)) {
+struct udphdr *uh;
+
+uh = (struct udphdr *)(mtod(m, char *) + hlen);
+return toeplitz_vhash(key, sizeof(key),
+/* ip_src and ip_dst in struct ip must sequential */
+>ip_src, sizeof(ip->ip_src) * 2,
+/* uh_sport and uh_dport in udphdr must be sequential */
+>uh_sport, sizeof(uh->uh_sport) * 2,
+NULL);
+			} else if (m->m_pkthdr.len >= hlen + sizeof(struct udphdr)) {
+uint16_t ports[2];
+
+/* ditto */
+m_copydata(__UNCONST(m), hlen + offsetof(struct udphdr, uh_sport),
+sizeof(ports), ports);
+return toeplitz_vhash(key, sizeof(key),
+>ip_src, sizeof(ip->ip_src) * 2,
+ports, sizeof(ports),
+NULL);
+			}
+		}
+		/*
+		 * Treat as raw packet.
+		 */
+		return toeplitz_vhash(key, sizeof(key),
+		/* ditto */
+		>ip_src, sizeof(ip->ip_src) * 2,
+		NULL);
+	}
+	/*
+	 * Other protocols are treated as raw packets to apply RPS.
+	 */
+	default:
+		return toeplitz_vhash(key, sizeof(key),
+		/* ditto */
+		>ip_src, sizeof(ip->ip_src) * 2,
+		NULL);
+	}
+}
+
+/*
+ * Calculate rss hash value from IPv6 mbuf.
+ * This function should be called before ip6_input().
+ */
+uint32_t
+rss_toeplitz_hash_from_mbuf_ipv6(const struct mbuf *m, u_int flag)
+{
+	struct ip6_hdr *ip6;
+	int hlen;
+	uint8_t key[RSS_KEYSIZE];
+
+	KASSERT((m->m_flags & M_PKTHDR) != 0);
+	KASSERT(m->m_len >= sizeof (struct ip6_hdr));
+
+	ip6 = mtod(m, struct ip6_hdr *);
+	KASSERT((ip6->ip6_vfc & IPV6_VERSION_MASK) == IPV6_VERSION);
+
+	hlen = sizeof(struct ip6_hdr);
+	rss_getkey(key);
+
+	switch (ip6->ip6_nxt) {
+	case IPPROTO_TCP:
+	{
+		if ((flag & RSS_TOEPLITZ_USE_TCP_PORT) != 0) {
+			if (m->m_len >= hlen + sizeof(struct tcphdr)) {
+struct tcphdr *th;
+
+th = (struct tcphdr *)(mtod(m, char *) + hlen);
+return toeplitz_vhash(key, sizeof(key),
+/* ip6_src and ip6_dst in ip6_hdr must be sequential */
+>ip6_src, 

CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 04:11:02 UTC 2021

Modified Files:
src/sys/net: rss_config.c rss_config.h

Log Message:
Add RSS toeplitz hash functions which calculate from mbuf.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/rss_config.c
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 04:09:32 UTC 2021

Modified Files:
src/sys/net: toeplitz.c toeplitz.h

Log Message:
Import asymmetric toeplitz hash without memcpy implemented by ryo@n.o.

This implementation has better performance than memcpy'ed one.
(30%-60% improvement in micro benchmark)

import from
https://github.com/ryo/l2pkt/blob/master/l2pkt/toeplitz_hash.c


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/toeplitz.c src/sys/net/toeplitz.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/toeplitz.c
diff -u src/sys/net/toeplitz.c:1.2 src/sys/net/toeplitz.c:1.3
--- src/sys/net/toeplitz.c:1.2	Mon Apr  5 06:56:47 2021
+++ src/sys/net/toeplitz.c	Fri Sep 24 04:09:32 2021
@@ -202,3 +202,87 @@ stoeplitz_to_key(void *key, size_t klen)
 		k[i + 1] = skey;
 	}
 }
+
+/*
+ * e.g.)
+ *
+ * struct in_addr src, dst;
+ * uint16_t srcport, dstport;
+ * toeplitz_vhash(rsskey[], sizeof(rsskey),
+ *, sizeof(src),
+ *, sizeof(dst),
+ *, sizeof(srcport),
+ *, sizeof(dstport),
+ *NULL);
+ *
+ * struct in6_addr src6, dst6;
+ * toeplitz_vhash(rsskey[], sizeof(rsskey),
+ *, sizeof(src6),
+ *, sizeof(dst6),
+ *NULL);
+ *
+ * struct ip *ip;
+ * struct tcphdr *tcp;
+ * toeplitz_vhash(rsskey[], sizeof(rsskey),
+ *>ip_src, sizeof(ip->ip_src),
+ *>ip_dst, sizeof(ip->ip_dst),
+ *>th_sport, sizeof(tcp->th_sport),
+ *>th_dport, sizeof(tcp->th_dport),
+ *NULL);
+ *
+ */
+uint32_t
+toeplitz_vhash(const uint8_t *keyp, size_t keylen, ...)
+{
+	va_list ap;
+	uint32_t hash, v;
+	size_t datalen;
+	uint8_t *datap, key, data;
+	const uint8_t *keyend;
+
+	keyend = keyp + keylen;
+
+	/* first 32bit is initial vector */
+	v = *keyp++;
+	v <<= 8;
+	v |= *keyp++;
+	v <<= 8;
+	v |= *keyp++;
+	v <<= 8;
+	v |= *keyp++;
+
+	hash = 0;
+	va_start(ap, keylen);
+
+	while ((datap = va_arg(ap, uint8_t *)) != NULL) {
+		for (datalen = va_arg(ap, size_t); datalen > 0; datalen--) {
+			/* fetch key and input data by 8bit */
+			if (keyp < keyend)
+key = *keyp++;
+			else
+key = 0;
+			data = *datap++;
+
+#define XOR_AND_FETCH_BIT(x)			\
+			if (data & __BIT(x))		\
+hash ^= v;		\
+			v <<= 1;			\
+			if (key & __BIT(x))		\
+v |= 1;
+
+			XOR_AND_FETCH_BIT(7);
+			XOR_AND_FETCH_BIT(6);
+			XOR_AND_FETCH_BIT(5);
+			XOR_AND_FETCH_BIT(4);
+			XOR_AND_FETCH_BIT(3);
+			XOR_AND_FETCH_BIT(2);
+			XOR_AND_FETCH_BIT(1);
+			XOR_AND_FETCH_BIT(0);
+
+#undef XOR_AND_FETCH_BIT
+		}
+	}
+	va_end(ap);
+
+	return hash;
+}
Index: src/sys/net/toeplitz.h
diff -u src/sys/net/toeplitz.h:1.2 src/sys/net/toeplitz.h:1.3
--- src/sys/net/toeplitz.h:1.2	Mon Apr  5 06:53:45 2021
+++ src/sys/net/toeplitz.h	Fri Sep 24 04:09:32 2021
@@ -120,4 +120,10 @@ extern const struct stoeplitz_cache *con
 	stoeplitz_hash_ip6port(stoeplitz_cache, (_sa6), (_da6), (_sp), (_dp))
 #endif
 
+/*
+ * system also provided asymmetric toeplitz
+ */
+
+uint32_t	toeplitz_vhash(const uint8_t *, size_t, ...);
+
 #endif /* _SYS_NET_TOEPLITZ_H_ */



CVS commit: src/sys/net

2021-09-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 24 04:09:32 UTC 2021

Modified Files:
src/sys/net: toeplitz.c toeplitz.h

Log Message:
Import asymmetric toeplitz hash without memcpy implemented by ryo@n.o.

This implementation has better performance than memcpy'ed one.
(30%-60% improvement in micro benchmark)

import from
https://github.com/ryo/l2pkt/blob/master/l2pkt/toeplitz_hash.c


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/toeplitz.c src/sys/net/toeplitz.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/arch/arm/xscale

2021-08-06 Thread Kengo NAKAHARA

Hi,

On 2021/08/06 17:58, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Fri Aug  6 08:58:42 UTC 2021

Modified Files:
src/sys/arch/arm/xscale: i80321_intr.h

Log Message:
Do *NOT* lower IPL in i80321_splraise().

Fix various strange crashes for DIAGNOSTIC kernel on evbarm/HDL_G,
including one worked around by if_wm.c rev 1.706:

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/pci/if_wm.c#rev1.706


if_wm.c:r1.706 also fixes a potential bug which causes infinite loop
when do "sysctl -w hw.wmX.txrx_workqueue=1" on single processor system.
So, I leave the code.


Thanks,


--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Division,
Technology Unit

Kengo NAKAHARA 




Re: CVS import: src/external/bsd/tmux/dist

2021-05-09 Thread Kengo NAKAHARA

Hi,

Thank yo for your commit!

On 2021/05/07 20:11, Christos Zoulas wrote:

Fixed, thanks!

christos


On May 6, 2021, at 10:09 PM, Kengo NAKAHARA  wrote:

Hi,

After this commit, tmux(1) crashes when "choose-window" command is used.
Could you apply the following patch to fix that?

--- a/external/bsd/tmux/dist/mode-tree.c
+++ b/external/bsd/tmux/dist/mode-tree.c
@@ -139,7 +139,7 @@ mode_tree_free_item(struct mode_tree_item *mti)
mode_tree_free_items(>children);
 free(__UNCONST(mti->name));
-   free(__UNCONST(mti->name));
+   free(__UNCONST(mti->text));
free(__UNCONST(mti->keystr));
 free(mti);



Thanks,

On 2021/04/18 4:42, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Sat Apr 17 19:42:05 UTC 2021
Update of /cvsroot/src/external/bsd/tmux/dist
In directory ivanova.netbsd.org:/tmp/cvs-serv5745
Log Message:
CHANGES FROM 3.1c TO 3.2
* Add a flag to disable keys to close a message.
* Permit shortcut keys in buffer, client, tree modes to be configured with a
   format (-K flag to choose-buffer, choose-client, choose-tree).
* Add a current_file format for the config file being parsed.
* When display-message used in config file, show the message after the config
   file finishes.
* Add client-detached notification in control mode.
* Improve performance of format evaluation.
* Make jump command support UTF-8 in copy mode.
* Support X11 colour names and other colour formats for OSC 10 and 11.
* Add "pipe" variants of "copy-pipe" commands which do not copy.
* Include "focused" in client flags.
* Send Unicode directional isolate characters around horizontal pane borders if
   the terminal supports UTF-8 and an extension terminfo(5) capability "Bidi" is
   present.
* Add a -S flag to new-window to make it select the existing window if one
   with the given name already exists rather than failing with an error.
* Addd a format modifier to check if a window or session name exists (N/w or
   N/s).
* Add compat clock_gettime for older macOS.
* Add a no-detached choice to detach-on-destroy which detaches only if there
   are no other detached sessions to switch to.
* Add rectangle-on and rectangle-off copy mode commands.
* Change so that window_flags escapes # automatically. A new format
   window_raw_flags contains the old unescaped version.
* Add -N flag to never start server even if command would normally do so.
* With incremental search, start empty and only repeat the previous search if
   the user tries to search again with an empty prompt.
* Add a value for remain-on-exit that only keeps the pane if the program
   failed.
* Add a -C flag to run-shell to use a tmux command rather than a shell command.
* Do not list user options with show-hooks.
* Remove current match indicator in copy mode which can't work anymore since we
   only search the visible region.
* Make synchronize-panes a pane option and add -U flag to set-option to unset
   an option on all panes.
* Make replacement of ##s consistent when drawing formats, whether followed by
   [ or not. Add a flag (e) to the q: format modifier to double up #s
* Add -N flag to display-panes to ignore keys.
* Change how escaping is processed for formats so that ## and # can be used in
   styles.
* Add a 'w' format modifier for string width.
* Add support for Haiku.
* Expand menu and popup -x and -y as formats.
* Add numeric comparisons for formats.
* Fire focus events even when the pane is in a mode.
* Add -O flag to display-menu to not automatically close when all mouse buttons
   are released.
* Allow fnmatch(3) wildcards in update-environment.
* Disable nested job expansion so that the result of #() is not expanded again.
* Use the setal capability as well as (tmux's) Setulc.
* Add -q flag to unbind-key to hide errors.
* Allow -N without a command to change or add a note to an existing key.
* Add a -w flag to set- and load-buffer to send to clipboard using OSC 52.
* Add -F to set-environment and source-file.
* Allow colour to be spelt as color in various places.
* Add n: modifier to get length of a format.
* Respond to OSC colour requests if a colour is available.
* Add a -d option to display-message to set delay.
* Add a way for control mode clients to subscribe to a format and be notified
   of changes rather than having to poll.
* Add some formats for search in copy mode (search_present, search_match).
* Do not wait on shutdown for commands started with run -b.
* Add -b flags to insert a window before (like the existing -a for after) to
   break-pane, move-window, new-window.
* Make paste -p the default for ].
* Add support for pausing a pane when the output buffered for a control mode
   client gets too far behind. The pause-after flag with a time is set on the
   pane with refresh-client -f and a paused pane may be resumed with
   refresh-client -A.
* Allow strings in configu

Re: CVS import: src/external/bsd/tmux/dist

2021-05-06 Thread Kengo NAKAHARA
/////
Internet Initiative Japan Inc.

Device Engineering Section,
Product Division,
Technology Unit

Kengo NAKAHARA 




Re: CVS commit: src/sys/net

2021-01-31 Thread Kengo NAKAHARA

Hi,

I have one question about the following commit.

Why stoeplitz_hash_ip4() and stoeplitz_hash_ip4port() argument types
are different between toeplitz.c and toeplitz.h?  They have in_addr_t
and in_port_t argument types in toeplitz.c, howerver uint32_t and
uint16_t in toeplitz.h.

On 2021/01/31 6:23, Jared D. McNeill wrote:

Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 30 21:23:08 UTC 2021

Modified Files:
src/sys/net: files.net
Added Files:
src/sys/net: toeplitz.c toeplitz.h

Log Message:
Add symmetric toeplitz implementation with integration for NICs, from OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/files.net
cvs rdiff -u -r0 -r1.1 src/sys/net/toeplitz.c src/sys/net/toeplitz.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Thanks,


--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


Re: CVS commit: src/sys/arch/x86/x86

2020-04-02 Thread Kengo NAKAHARA

Hi,

Hmm, but TSC drift is still observed on recent (high clock) CPUs.
I will have researched and fix later.

On 2020/04/03 12:05, Kengo NAKAHARA wrote:

Module Name:src
Committed By:   knakahara
Date:   Fri Apr  3 03:05:39 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
Fix TSC drift is observed almost every time wrongly.

Ths "TSC drift" in tsc_tc_init() means the cpu_cc_skew delta between
first measurement (in cpu_start_secondary) and second measurement
(in cpu_boot_secondary), that is, the TSC drift is expected to be
almost zero.  However, the second measument in current implementation
is added extra cpu_cc_skew accidentally, so current delta value means
almost cpu_cc_skew wrongly.

tsc_sync_bp and tsc_sync_ap should use rdtsc() to get raw values.

Advised by nonaka@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/x86/tsc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

Modified Files:
src/sys/net: rss_config.c

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/rss_config.c
diff -u src/sys/net/rss_config.c:1.1 src/sys/net/rss_config.c:1.2
--- src/sys/net/rss_config.c:1.1	Fri Feb 16 04:48:32 2018
+++ src/sys/net/rss_config.c	Wed Nov 20 08:17:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $  */
+/*	$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $  */
 
 /*
  * Copyright (c) 2018 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $");
 
 #include 
 #include 
@@ -62,6 +62,7 @@ static uint8_t rss_symmetric_key[RSS_KEY
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
 };
 #endif
 



CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

Modified Files:
src/sys/net: rss_config.c

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netipsec

2019-11-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 14 03:17:08 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Reduce load for IKE negotiations when the system has many IPv6 addresses.

e.g. the system has many vlan(4), gif(4) or ipsecif(4) with link local address.


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netipsec/key.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netipsec

2019-11-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 14 03:17:08 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Reduce load for IKE negotiations when the system has many IPv6 addresses.

e.g. the system has many vlan(4), gif(4) or ipsecif(4) with link local address.


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netipsec/key.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.268 src/sys/netipsec/key.c:1.269
--- src/sys/netipsec/key.c:1.268	Tue Nov 12 05:13:29 2019
+++ src/sys/netipsec/key.c	Thu Nov 14 03:17:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.269 2019/11/14 03:17:08 knakahara Exp $	*/
 /*	$FreeBSD: key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.269 2019/11/14 03:17:08 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -4502,30 +4502,34 @@ key_ismyaddr6(const struct sockaddr_in6 
 	bound = curlwp_bind();
 	s = pserialize_read_enter();
 	IN6_ADDRLIST_READER_FOREACH(ia) {
-		bool ingroup;
-
 		if (key_sockaddr_match((const struct sockaddr *),
 		(const struct sockaddr *)>ia_addr, 0)) {
 			pserialize_read_exit(s);
 			goto ours;
 		}
-		ia6_acquire(ia, );
-		pserialize_read_exit(s);
 
-		/*
-		 * XXX Multicast
-		 * XXX why do we care about multlicast here while we don't care
-		 * about IPv4 multicast??
-		 * XXX scope
-		 */
-		ingroup = in6_multi_group(>sin6_addr, ia->ia_ifp);
-		if (ingroup) {
+		if (IN6_IS_ADDR_MULTICAST(>sin6_addr)) {
+			bool ingroup;
+
+			ia6_acquire(ia, );
+			pserialize_read_exit(s);
+
+			/*
+			 * XXX Multicast
+			 * XXX why do we care about multlicast here while we don't care
+			 * about IPv4 multicast??
+			 * XXX scope
+			 */
+			ingroup = in6_multi_group(>sin6_addr, ia->ia_ifp);
+			if (ingroup) {
+ia6_release(ia, );
+goto ours;
+			}
+
+			s = pserialize_read_enter();
 			ia6_release(ia, );
-			goto ours;
 		}
 
-		s = pserialize_read_enter();
-		ia6_release(ia, );
 	}
 	pserialize_read_exit(s);
 



CVS commit: src/sys/netipsec

2019-11-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Nov 12 05:13:29 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Fix SA can be expaired wrongly when there are many SPs.

When key_timehandler_spd() spent over one second, the "now" argument of
key_timehandler_sad() could be older than sav->created. That caused SA
was expired immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netipsec/key.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netipsec

2019-11-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Nov 12 05:13:29 UTC 2019

Modified Files:
src/sys/netipsec: key.c

Log Message:
Fix SA can be expaired wrongly when there are many SPs.

When key_timehandler_spd() spent over one second, the "now" argument of
key_timehandler_sad() could be older than sav->created. That caused SA
was expired immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netipsec/key.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.267 src/sys/netipsec/key.c:1.268
--- src/sys/netipsec/key.c:1.267	Wed Sep 25 09:53:38 2019
+++ src/sys/netipsec/key.c	Tue Nov 12 05:13:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.267 2019/09/25 09:53:38 ozaki-r Exp $	*/
+/*	$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $	*/
 /*	$FreeBSD: key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.267 2019/09/25 09:53:38 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.268 2019/11/12 05:13:29 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -4883,14 +4883,20 @@ key_bb_match_withmask(const void *a1, co
 }
 
 static void
-key_timehandler_spd(time_t now)
+key_timehandler_spd(void)
 {
 	u_int dir;
 	struct secpolicy *sp;
+	volatile time_t now;
 
 	for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
 	retry:
 		mutex_enter(_spd.lock);
+		/*
+		 * To avoid for sp->created to overtake "now" because of
+		 * wating mutex, set time_uptime here.
+		 */
+		now = time_uptime;
 		SPLIST_WRITER_FOREACH(sp, dir) {
 			KASSERTMSG(sp->state != IPSEC_SPSTATE_DEAD,
 			"sp->state=%u", sp->state);
@@ -4925,10 +4931,11 @@ key_timehandler_spd(time_t now)
 }
 
 static void
-key_timehandler_sad(time_t now)
+key_timehandler_sad(void)
 {
 	struct secashead *sah;
 	int s;
+	volatile time_t now;
 
 restart:
 	mutex_enter(_sad.lock);
@@ -4954,6 +4961,10 @@ restart:
 		/* if LARVAL entry doesn't become MATURE, delete it. */
 		mutex_enter(_sad.lock);
 	restart_sav_LARVAL:
+		/*
+		 * Same as key_timehandler_spd(), set time_uptime here.
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_LARVAL) {
 			if (now - sav->created > key_larval_lifetime) {
 key_sa_chgstate(sav, SADB_SASTATE_DEAD);
@@ -4968,6 +4979,10 @@ restart:
 		 */
 	restart_sav_MATURE:
 		mutex_enter(_sad.lock);
+		/*
+		 * ditto
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_MATURE) {
 			/* we don't need to check. */
 			if (sav->lft_s == NULL)
@@ -5032,6 +5047,10 @@ restart:
 		/* check DYING entry to change status to DEAD. */
 		mutex_enter(_sad.lock);
 	restart_sav_DYING:
+		/*
+		 * ditto
+		 */
+		now = time_uptime;
 		SAVLIST_WRITER_FOREACH(sav, sah, SADB_SASTATE_DYING) {
 			/* we don't need to check. */
 			if (sav->lft_h == NULL)
@@ -5098,13 +5117,18 @@ restart:
 }
 
 static void
-key_timehandler_acq(time_t now)
+key_timehandler_acq(void)
 {
 #ifndef IPSEC_NONBLOCK_ACQUIRE
 	struct secacq *acq, *nextacq;
+	volatile time_t now;
 
 restart:
 	mutex_enter(_misc.lock);
+	/*
+	 * Same as key_timehandler_spd(), set time_uptime here.
+	 */
+	now = time_uptime;
 	LIST_FOREACH_SAFE(acq, _misc.acqlist, chain, nextacq) {
 		if (now - acq->created > key_blockacq_lifetime) {
 			LIST_REMOVE(acq, chain);
@@ -5118,10 +5142,11 @@ key_timehandler_acq(time_t now)
 }
 
 static void
-key_timehandler_spacq(time_t now)
+key_timehandler_spacq(void)
 {
 #ifdef notyet
 	struct secspacq *acq, *nextacq;
+	time_t now = time_uptime;
 
 	LIST_FOREACH_SAFE(acq, _misc.spacqlist, chain, nextacq) {
 		if (now - acq->created > key_blockacq_lifetime) {
@@ -5143,15 +5168,14 @@ static unsigned int key_timehandler_work
 static void
 key_timehandler_work(struct work *wk, void *arg)
 {
-	time_t now = time_uptime;
 
 	/* We can allow enqueuing another work at this point */
 	atomic_swap_uint(_timehandler_work_enqueued, 0);
 
-	key_timehandler_spd(now);
-	key_timehandler_sad(now);
-	key_timehandler_acq(now);
-	key_timehandler_spacq(now);
+	key_timehandler_spd();
+	key_timehandler_sad();
+	key_timehandler_acq();
+	key_timehandler_spacq();
 
 	key_acquire_sendup_pending_mbuf();
 



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:28:14 UTC 2019

Modified Files:
src/sys/net: if_ipsec.c if_ipsec.h
src/sys/netinet6: in6.h
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
Make global and per-interface ipsecif(4) pmtu tunable like gif(4).

And make hop limit tunable same as gif(4).

See http://mail-index.netbsd.org/source-changes/2019/10/30/msg110426.html


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/in6.h
cvs rdiff -u -r1.17 -r1.18 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netipsec/ipsecif.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:28:14 UTC 2019

Modified Files:
src/sys/net: if_ipsec.c if_ipsec.h
src/sys/netinet6: in6.h
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
Make global and per-interface ipsecif(4) pmtu tunable like gif(4).

And make hop limit tunable same as gif(4).

See http://mail-index.netbsd.org/source-changes/2019/10/30/msg110426.html


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/in6.h
cvs rdiff -u -r1.17 -r1.18 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netipsec/ipsecif.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.24 src/sys/net/if_ipsec.c:1.25
--- src/sys/net/if_ipsec.c:1.24	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_ipsec.c	Fri Nov  1 04:28:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.24 2019/09/19 06:07:24 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.24 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.25 2019/11/01 04:28:14 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -48,6 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -147,6 +148,138 @@ struct if_clone ipsec_cloner =
 IF_CLONE_INITIALIZER("ipsec", if_ipsec_clone_create, if_ipsec_clone_destroy);
 static int max_ipsec_nesting = MAX_IPSEC_NEST;
 
+static struct sysctllog *if_ipsec_sysctl;
+
+#ifdef INET6
+static int
+sysctl_if_ipsec_pmtu_global(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+
+	pmtu = ip6_ipsec_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case IPSEC_PMTU_MINMTU:
+	case IPSEC_PMTU_OUTERMTU:
+		ip6_ipsec_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+sysctl_if_ipsec_pmtu_perif(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+	struct ipsec_softc *sc = (struct ipsec_softc *)node.sysctl_data;
+
+	pmtu = sc->ipsec_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case IPSEC_PMTU_SYSDEFAULT:
+	case IPSEC_PMTU_MINMTU:
+	case IPSEC_PMTU_OUTERMTU:
+		sc->ipsec_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+#endif
+
+static void
+if_ipsec_sysctl_setup(void)
+{
+	if_ipsec_sysctl = NULL;
+
+#ifdef INET6
+	/*
+	 * Previously create "net.inet6.ip6" entry to avoid sysctl_createv error.
+	 */
+	sysctl_createv(NULL, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "inet6",
+		   SYSCTL_DESCR("PF_INET6 related settings"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, PF_INET6, CTL_EOL);
+	sysctl_createv(NULL, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "ip6",
+		   SYSCTL_DESCR("IPv6 related settings"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
+
+	sysctl_createv(_ipsec_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "ipsecifhlim",
+		   SYSCTL_DESCR("Default hop limit for a ipsec tunnel datagram"),
+		   NULL, 0, _ipsec_hlim, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_IPSEC_HLIM, CTL_EOL);
+
+	sysctl_createv(_ipsec_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "ipsecifpmtu",
+		   SYSCTL_DESCR("Default Path MTU setting for ipsec tunnels"),
+		   sysctl_if_ipsec_pmtu_global, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_IPSEC_PMTU, CTL_EOL);
+#endif
+}
+
+static void
+if_ipsec_perif_sysctl_setup(struct sysctllog **clog, struct ipsec_softc *sc)
+{
+#ifdef INET6
+	const struct sysctlnode *cnode, *rnode;
+	struct ifnet *ifp = >ipsec_if;
+	const char *ifname = ifp->if_xname;
+	int rv;
+
+	/*
+	 * Already created in sysctl_sndq_setup().
+	 */
+	sysctl_createv(clog, 0, NULL, ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "interfaces",
+		   SYSCTL_DESCR("Per-interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, , ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, ifname,
+		   SYSCTL_DESCR("Interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_CREATE, CTL_EOL);
+
+	rv = sysctl_createv(clog, 0, , ,
+			CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+			CTLTYPE_INT, "pmtu",
+			SYSCTL_DESCR("Path MTU setting for this ipsec 

CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:23:21 UTC 2019

Modified Files:
src/sys/netinet6: ip6_forward.c ip6_output.c
src/sys/netipsec: ipsec.h ipsec6.h ipsec_output.c xform.h xform_ah.c
xform_esp.c xform_ipcomp.c xform_ipip.c xform_tcp.c

Log Message:
Fix ipsecif(4) IPV6_MINMTU does not work correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.220 -r1.221 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.88 -r1.89 src/sys/netipsec/ipsec.h
cvs rdiff -u -r1.29 -r1.30 src/sys/netipsec/ipsec6.h
cvs rdiff -u -r1.83 -r1.84 src/sys/netipsec/ipsec_output.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/xform.h
cvs rdiff -u -r1.108 -r1.109 src/sys/netipsec/xform_ah.c
cvs rdiff -u -r1.98 -r1.99 src/sys/netipsec/xform_esp.c
cvs rdiff -u -r1.68 -r1.69 src/sys/netipsec/xform_ipcomp.c
cvs rdiff -u -r1.76 -r1.77 src/sys/netipsec/xform_ipip.c
cvs rdiff -u -r1.23 -r1.24 src/sys/netipsec/xform_tcp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-10-31 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov  1 04:23:21 UTC 2019

Modified Files:
src/sys/netinet6: ip6_forward.c ip6_output.c
src/sys/netipsec: ipsec.h ipsec6.h ipsec_output.c xform.h xform_ah.c
xform_esp.c xform_ipcomp.c xform_ipip.c xform_tcp.c

Log Message:
Fix ipsecif(4) IPV6_MINMTU does not work correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.220 -r1.221 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.88 -r1.89 src/sys/netipsec/ipsec.h
cvs rdiff -u -r1.29 -r1.30 src/sys/netipsec/ipsec6.h
cvs rdiff -u -r1.83 -r1.84 src/sys/netipsec/ipsec_output.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/xform.h
cvs rdiff -u -r1.108 -r1.109 src/sys/netipsec/xform_ah.c
cvs rdiff -u -r1.98 -r1.99 src/sys/netipsec/xform_esp.c
cvs rdiff -u -r1.68 -r1.69 src/sys/netipsec/xform_ipcomp.c
cvs rdiff -u -r1.76 -r1.77 src/sys/netipsec/xform_ipip.c
cvs rdiff -u -r1.23 -r1.24 src/sys/netipsec/xform_tcp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet6/ip6_forward.c
diff -u src/sys/netinet6/ip6_forward.c:1.97 src/sys/netinet6/ip6_forward.c:1.98
--- src/sys/netinet6/ip6_forward.c:1.97	Thu Sep 19 04:08:29 2019
+++ src/sys/netinet6/ip6_forward.c	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_forward.c,v 1.97 2019/09/19 04:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_forward.c,v 1.98 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.97 2019/09/19 04:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.98 2019/11/01 04:23:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -261,7 +261,7 @@ ip6_forward(struct mbuf *m, int srcrt)
 	 */
 	if (needipsec) {
 		int s = splsoftnet();
-		error = ipsec6_process_packet(m, sp->req);
+		error = ipsec6_process_packet(m, sp->req, 0);
 		splx(s);
 		/* m is freed */
 		if (mcopy)

Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.220 src/sys/netinet6/ip6_output.c:1.221
--- src/sys/netinet6/ip6_output.c:1.220	Wed May 15 02:59:18 2019
+++ src/sys/netinet6/ip6_output.c	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.220 2019/05/15 02:59:18 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.220 2019/05/15 02:59:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -477,7 +477,7 @@ ip6_output(
 #ifdef IPSEC
 	if (needipsec) {
 		int s = splsoftnet();
-		error = ipsec6_process_packet(m, sp->req);
+		error = ipsec6_process_packet(m, sp->req, flags);
 		splx(s);
 
 		/*

Index: src/sys/netipsec/ipsec.h
diff -u src/sys/netipsec/ipsec.h:1.88 src/sys/netipsec/ipsec.h:1.89
--- src/sys/netipsec/ipsec.h:1.88	Wed Jun 12 22:23:50 2019
+++ src/sys/netipsec/ipsec.h	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.h,v 1.88 2019/06/12 22:23:50 christos Exp $	*/
+/*	$NetBSD: ipsec.h,v 1.89 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$FreeBSD: ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
 
@@ -318,7 +318,7 @@ void ipsec4_common_input(struct mbuf *m,
 int ipsec4_common_input_cb(struct mbuf *, struct secasvar *, int, int);
 int ipsec4_process_packet(struct mbuf *, const struct ipsecrequest *, u_long *);
 int ipsec_process_done(struct mbuf *, const struct ipsecrequest *,
-struct secasvar *);
+struct secasvar *, int);
 
 struct mbuf *m_clone(struct mbuf *);
 struct mbuf *m_makespace(struct mbuf *, int, int, int *);

Index: src/sys/netipsec/ipsec6.h
diff -u src/sys/netipsec/ipsec6.h:1.29 src/sys/netipsec/ipsec6.h:1.30
--- src/sys/netipsec/ipsec6.h:1.29	Mon May 14 17:34:26 2018
+++ src/sys/netipsec/ipsec6.h	Fri Nov  1 04:23:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec6.h,v 1.29 2018/05/14 17:34:26 maxv Exp $	*/
+/*	$NetBSD: ipsec6.h,v 1.30 2019/11/01 04:23:21 knakahara Exp $	*/
 /*	$FreeBSD: ipsec6.h,v 1.1.4.1 2003/01/24 05:11:35 sam Exp $	*/
 /*	$KAME: ipsec.h,v 1.44 2001/03/23 08:08:47 itojun Exp $	*/
 
@@ -59,7 +59,7 @@ void *ah6_ctlinput(int, const struct soc
 struct m_tag;
 int ipsec6_common_input(struct mbuf **, int *, int);
 int ipsec6_common_input_cb(struct mbuf *, struct secasvar *, int, int);
-int ipsec6_process_packet(struct mbuf *, const struct ipsecrequest *);
+int ipsec6_process_packet(struct mbuf *, const struct ipsecrequest *, int);
 #endif /*_KERNEL*/
 
 #endif /* !_NETIPSEC_IPSEC6_H_ */

Index: src/sys/netipsec/ipsec_output.c
diff -u 

CVS commit: src/sys

2019-10-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 30 03:45:59 UTC 2019

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet6: in6.h in6_gif.c in6_gif.h

Log Message:
Add sysctl nodes to control fragmentation with IPv[46] over IPv6 gif(4).

New sysctl node "net.inet6.ip6.gifpmtu" means
- 0 (default)
  Fragment by IPV6_MMTU. All packets reach the destination certainly,
  however the long packet performance is poor.
  This is same behavior as before.
- 1
  Fragment by outer interface's MTU. The long packet performance would
  be good, however the packets may be dropped in some network paths
  whose path MTU less than the interface's MTU.
- others
  undefined yet

New sysctl node "net.interfaces.gif*.pmtu" means
- -1 (default)
  Use system default value (net.inet6.ip6.gifpmtu).
- 0
  Fragment by IPV6_MMTU for this gif(4) tunnel.
- 1
  Fragment by outer interface's MTU for this gif(4) tunnel.
- others
  undefined yet

See RFC4459 for more information and other solutions.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/net/if_gif.c
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_gif.h
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet6/in6.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_gif.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.149 src/sys/net/if_gif.c:1.150
--- src/sys/net/if_gif.c:1.149	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_gif.c	Wed Oct 30 03:45:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.149 2019/09/19 06:07:24 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.150 2019/10/30 03:45:59 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.149 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.150 2019/10/30 03:45:59 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -142,6 +142,58 @@ static int max_gif_nesting = MAX_GIF_NES
 
 static struct sysctllog *gif_sysctl;
 
+#ifdef INET6
+static int
+sysctl_gif_pmtu_global(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+
+	pmtu = ip6_gif_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case GIF_PMTU_MINMTU:
+	case GIF_PMTU_OUTERMTU:
+		ip6_gif_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+sysctl_gif_pmtu_perif(SYSCTLFN_ARGS)
+{
+	int error, pmtu;
+	struct sysctlnode node = *rnode;
+	struct gif_softc *sc = (struct gif_softc *)node.sysctl_data;
+
+	pmtu = sc->gif_pmtu;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	switch (pmtu) {
+	case GIF_PMTU_SYSDEFAULT:
+	case GIF_PMTU_MINMTU:
+	case GIF_PMTU_OUTERMTU:
+		sc->gif_pmtu = pmtu;
+		break;
+	default:
+		return EINVAL;
+	}
+
+	return 0;
+}
+#endif
+
 static void
 gif_sysctl_setup(void)
 {
@@ -196,6 +248,52 @@ gif_sysctl_setup(void)
 		   NULL, 0, _gif_hlim, 0,
 		   CTL_NET, PF_INET6, IPPROTO_IPV6,
 		   IPV6CTL_GIF_HLIM, CTL_EOL);
+
+	sysctl_createv(_sysctl, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "gifpmtu",
+		   SYSCTL_DESCR("Default Path MTU setting for gif tunnels"),
+		   sysctl_gif_pmtu_global, 0, NULL, 0,
+		   CTL_NET, PF_INET6, IPPROTO_IPV6,
+		   IPV6CTL_GIF_PMTU, CTL_EOL);
+#endif
+}
+
+static void
+gif_perif_sysctl_setup(struct sysctllog **clog, struct gif_softc *sc)
+{
+#ifdef INET6
+	const struct sysctlnode *cnode, *rnode;
+	struct ifnet *ifp = >gif_if;
+	const char *ifname = ifp->if_xname;
+	int rv;
+
+	/*
+	 * Already created in sysctl_sndq_setup().
+	 */
+	sysctl_createv(clog, 0, NULL, ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, "interfaces",
+		   SYSCTL_DESCR("Per-interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, , ,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, ifname,
+		   SYSCTL_DESCR("Interface controls"),
+		   NULL, 0, NULL, 0,
+		   CTL_CREATE, CTL_EOL);
+
+	rv = sysctl_createv(clog, 0, , ,
+			CTLFLAG_PERMANENT,
+			CTLTYPE_INT, "pmtu",
+			SYSCTL_DESCR("Path MTU setting for this gif tunnel"),
+			sysctl_gif_pmtu_perif, 0, (void *)sc, 0,
+			CTL_CREATE, CTL_EOL);
+	if (rv != 0)
+		log(LOG_WARNING, "%s: could not attach sysctl node pmtu\n", ifname);
+
+	sc->gif_pmtu = GIF_PMTU_SYSDEFAULT;
 #endif
 }
 
@@ -248,6 +346,7 @@ gif_clone_create(struct if_clone *ifc, i
 {
 	struct gif_softc *sc;
 	struct gif_variant *var;
+	struct ifnet *ifp;
 	int rv;
 
 	sc = kmem_zalloc(sizeof(struct 

CVS commit: src/sys

2019-10-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 30 03:45:59 UTC 2019

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet6: in6.h in6_gif.c in6_gif.h

Log Message:
Add sysctl nodes to control fragmentation with IPv[46] over IPv6 gif(4).

New sysctl node "net.inet6.ip6.gifpmtu" means
- 0 (default)
  Fragment by IPV6_MMTU. All packets reach the destination certainly,
  however the long packet performance is poor.
  This is same behavior as before.
- 1
  Fragment by outer interface's MTU. The long packet performance would
  be good, however the packets may be dropped in some network paths
  whose path MTU less than the interface's MTU.
- others
  undefined yet

New sysctl node "net.interfaces.gif*.pmtu" means
- -1 (default)
  Use system default value (net.inet6.ip6.gifpmtu).
- 0
  Fragment by IPV6_MMTU for this gif(4) tunnel.
- 1
  Fragment by outer interface's MTU for this gif(4) tunnel.
- others
  undefined yet

See RFC4459 for more information and other solutions.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/net/if_gif.c
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_gif.h
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet6/in6.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_gif.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:53:34 UTC 2019

Modified Files:
src/sys/net: if_gre.c if_l2tp.c if_tap.c

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/net/if_gre.c
cvs rdiff -u -r1.39 -r1.40 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.113 -r1.114 src/sys/net/if_tap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_gre.c
diff -u src/sys/net/if_gre.c:1.175 src/sys/net/if_gre.c:1.176
--- src/sys/net/if_gre.c:1.175	Fri Apr 26 11:51:56 2019
+++ src/sys/net/if_gre.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $ */
+/*	$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -964,8 +964,11 @@ gre_output(struct ifnet *ifp, struct mbu
 	if ((error = gre_bufq_enqueue(>sc_snd, m)) != 0) {
 		sc->sc_oflow_ev.ev_count++;
 		m_freem(m);
-	} else
+	} else {
+		kpreempt_disable();
 		softint_schedule(sc->sc_si);
+		kpreempt_enable();
+	}
 
 end:
 	if (error)

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.39 src/sys/net/if_l2tp.c:1.40
--- src/sys/net/if_l2tp.c:1.39	Thu Sep 19 06:09:52 2019
+++ src/sys/net/if_l2tp.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -673,7 +673,9 @@ l2tp_start(struct ifnet *ifp)
 	if (var->lv_psrc == NULL || var->lv_pdst == NULL)
 		return;
 
+	kpreempt_disable();
 	softint_schedule(sc->l2tp_si);
+	kpreempt_enable();
 	l2tp_putref_variant(var, );
 }
 

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.113 src/sys/net/if_tap.c:1.114
--- src/sys/net/if_tap.c:1.113	Wed May 29 10:07:30 2019
+++ src/sys/net/if_tap.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -533,8 +533,11 @@ tap_start(struct ifnet *ifp)
 		ifp->if_flags |= IFF_OACTIVE;
 		cv_broadcast(>sc_cv);
 		selnotify(>sc_rsel, 0, 1);
-		if (sc->sc_flags & TAP_ASYNCIO)
+		if (sc->sc_flags & TAP_ASYNCIO) {
+			kpreempt_disable();
 			softint_schedule(sc->sc_sih);
+			kpreempt_enable();
+		}
 	}
 done:
 	mutex_exit(>sc_lock);
@@ -643,8 +646,11 @@ tap_stop(struct ifnet *ifp, int disable)
 	ifp->if_flags &= ~IFF_RUNNING;
 	cv_broadcast(>sc_cv);
 	selnotify(>sc_rsel, 0, 1);
-	if (sc->sc_flags & TAP_ASYNCIO)
+	if (sc->sc_flags & TAP_ASYNCIO) {
+		kpreempt_disable();
 		softint_schedule(sc->sc_sih);
+		kpreempt_enable();
+	}
 	mutex_exit(>sc_lock);
 }
 



CVS commit: src/sys/dev/pci/ixgbe

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:36:00 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/pci/ixgbe/ix_txrx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci/ixgbe

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:36:00 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/pci/ixgbe/ix_txrx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.55 src/sys/dev/pci/ixgbe/ix_txrx.c:1.56
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.55	Wed Sep  4 07:29:34 2019
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Wed Oct 16 06:36:00 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.55 2019/09/04 07:29:34 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.56 2019/10/16 06:36:00 knakahara Exp $ */
 
 /**
 
@@ -266,8 +266,11 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 >wq_cookie, curcpu());
 			} else
 percpu_putref(adapter->txr_wq_enqueued);
-		} else
+		} else {
+			kpreempt_disable();
 			softint_schedule(txr->txr_si);
+			kpreempt_enable();
+		}
 	}
 
 	return (0);



CVS commit: src/sys/arch/x86/pci

2019-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 10 08:55:08 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix kassert failure in vmxnet3_transmit(). Pointed out by ryo@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-10-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 10 08:55:08 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix kassert failure in vmxnet3_transmit(). Pointed out by ryo@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.50 src/sys/arch/x86/pci/if_vmx.c:1.51
--- src/sys/arch/x86/pci/if_vmx.c:1.50	Mon Sep 30 07:13:54 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Thu Oct 10 08:55:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.51 2019/10/10 08:55:08 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.51 2019/10/10 08:55:08 knakahara Exp $");
 
 #include 
 #include 
@@ -3276,7 +3276,9 @@ vmxnet3_transmit(struct ifnet *ifp, stru
 		vmxnet3_transmit_locked(ifp, txq);
 		VMXNET3_TXQ_UNLOCK(txq);
 	} else {
+		kpreempt_disable();
 		softint_schedule(txq->vxtxq_si);
+		kpreempt_enable();
 	}
 
 	return 0;



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

Modified Files:
src/sys/net: route.c

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.224 src/sys/net/route.c:1.225
--- src/sys/net/route.c:1.224	Mon Sep 30 10:22:14 2019
+++ src/sys/net/route.c	Thu Oct  3 03:10:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,11 +1400,8 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL) {
-			ifa_release(ifa, psref);
-			ifa = NULL;
-			goto next;
-		}
+		info->rti_info[RTAX_GATEWAY] == NULL)
+			goto out;
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

Modified Files:
src/sys/net: route.c

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

Modified Files:
src/sys/net: route.c

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

Modified Files:
src/sys/net: route.c

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.223 src/sys/net/route.c:1.224
--- src/sys/net/route.c:1.223	Wed Sep 25 09:53:37 2019
+++ src/sys/net/route.c	Mon Sep 30 10:22:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,8 +1400,11 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL)
+		info->rti_info[RTAX_GATEWAY] == NULL) {
+			ifa_release(ifa, psref);
+			ifa = NULL;
 			goto next;
+		}
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/arch/x86/pci

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 07:13:54 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix typo in vmxnet3_legacy_intr().

That causes sysctl hw.vmx*.{rx,tx} effect inversely when vmx(4) uses
INTx or MSI.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.49 src/sys/arch/x86/pci/if_vmx.c:1.50
--- src/sys/arch/x86/pci/if_vmx.c:1.49	Fri Aug 30 05:03:32 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Sep 30 07:13:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.50 2019/09/30 07:13:54 knakahara Exp $");
 
 #include 
 #include 
@@ -2513,11 +2513,11 @@ vmxnet3_legacy_intr(void *xsc)
 		vmxnet3_evintr(sc);
 
 	VMXNET3_RXQ_LOCK(rxq);
-	rxmore = vmxnet3_rxq_eof(rxq, txlimit);
+	rxmore = vmxnet3_rxq_eof(rxq, rxlimit);
 	VMXNET3_RXQ_UNLOCK(rxq);
 
 	VMXNET3_TXQ_LOCK(txq);
-	txmore = vmxnet3_txq_eof(txq, rxlimit);
+	txmore = vmxnet3_txq_eof(txq, txlimit);
 	VMXNET3_TXQ_UNLOCK(txq);
 
 	if (txmore || rxmore) {



CVS commit: src/sys/arch/x86/pci

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 07:13:54 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix typo in vmxnet3_legacy_intr().

That causes sysctl hw.vmx*.{rx,tx} effect inversely when vmx(4) uses
INTx or MSI.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_l2tp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_l2tp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.38 src/sys/net/if_l2tp.c:1.39
--- src/sys/net/if_l2tp.c:1.38	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 06:09:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -116,6 +116,7 @@ pserialize_t l2tp_psz __read_mostly;
 struct psref_class *lv_psref_class __read_mostly;
 
 static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+static void	l2tp_ifq_fini_pc(void *, void *, struct cpu_info *);
 
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
@@ -151,6 +152,20 @@ static void	l2tp_set_state(struct l2tp_s
 static int	l2tp_encap_attach(struct l2tp_variant *);
 static int	l2tp_encap_detach(struct l2tp_variant *);
 
+static inline struct ifqueue *
+l2tp_ifq_percpu_getref(percpu_t *pc)
+{
+
+	return *(struct ifqueue **)percpu_getref(pc);
+}
+
+static inline void
+l2tp_ifq_percpu_putref(percpu_t *pc)
+{
+
+	percpu_putref(pc);
+}
+
 #ifndef MAX_L2TP_NEST
 /*
  * This macro controls the upper limitation on nesting of l2tp tunnels.
@@ -252,7 +267,7 @@ l2tp_clone_create(struct if_clone *ifc, 
 
 	sc->l2tp_ro_percpu = if_tunnel_alloc_ro_percpu();
 
-	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue));
+	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue *));
 	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_init_pc, NULL);
 	sc->l2tp_si = softint_establish(si_flags, l2tpintr_softint, sc);
 
@@ -319,10 +334,18 @@ l2tpattach0(struct l2tp_softc *sc)
 void
 l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
 {
-	struct ifqueue *ifq = p;
+	struct ifqueue **ifqp = p;
 
-	memset(ifq, 0, sizeof(*ifq));
-	ifq->ifq_maxlen = IFQ_MAXLEN;
+	*ifqp = kmem_zalloc(sizeof(**ifqp), KM_SLEEP);
+	(*ifqp)->ifq_maxlen = IFQ_MAXLEN;
+}
+
+void
+l2tp_ifq_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue **ifqp = p;
+
+	kmem_free(*ifqp, sizeof(**ifqp));
 }
 
 static int
@@ -344,7 +367,8 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	mutex_exit(>l2tp_lock);
 
 	softint_disestablish(sc->l2tp_si);
-	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_fini_pc, NULL);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue *));
 
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
@@ -378,10 +402,10 @@ l2tp_tx_enqueue(struct l2tp_variant *var
 	ifp = >l2tp_ec.ec_if;
 
 	s = splsoftnet();
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	if (IF_QFULL(ifq)) {
 		ifp->if_oerrors++;
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		splx(s);
 		m_freem(m);
 		return ENOBUFS;
@@ -503,16 +527,16 @@ l2tpintr(struct l2tp_variant *var)
 
 	/* output processing */
 	if (var->lv_my_sess_id == 0 || var->lv_peer_sess_id == 0) {
-		ifq = percpu_getref(sc->l2tp_ifq_percpu);
+		ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 		IF_PURGE(ifq);
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		if (cpuid == 0)
 			IFQ_PURGE(>if_snd);
 		return;
 	}
 
 	/* Currently, l2tpintr() is always called in softint context. */
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	for (;;) {
 		IF_DEQUEUE(ifq, m);
 		if (m != NULL)
@@ -520,7 +544,7 @@ l2tpintr(struct l2tp_variant *var)
 		else
 			break;
 	

CVS commit: src/sys

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:07:25 UTC 2019

Modified Files:
src/sys/net: if.c if.h if_gif.c if_gif.h if_ipsec.c if_ipsec.h
if_l2tp.c if_l2tp.h
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
Avoid having a rtcache directly in a percpu storage for tunnel protocols.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.460 -r1.461 src/sys/net/if.c
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if.h
cvs rdiff -u -r1.148 -r1.149 src/sys/net/if_gif.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_gif.h
cvs rdiff -u -r1.23 -r1.24 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.37 -r1.38 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_l2tp.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.93 -r1.94 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netipsec/ipsecif.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.460 src/sys/net/if.c:1.461
--- src/sys/net/if.c:1.460	Fri Sep 13 07:55:07 2019
+++ src/sys/net/if.c	Thu Sep 19 06:07:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.460 2019/09/13 07:55:07 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.461 2019/09/19 06:07:24 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.460 2019/09/13 07:55:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.461 2019/09/19 06:07:24 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2906,6 +2906,63 @@ if_tunnel_check_nesting(struct ifnet *if
 	return 0;
 }
 
+static void
+if_tunnel_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	tro->tr_ro = kmem_zalloc(sizeof(*tro->tr_ro), KM_SLEEP);
+	tro->tr_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
+}
+
+percpu_t *
+if_tunnel_alloc_ro_percpu(void)
+{
+	percpu_t *ro_percpu;
+
+	ro_percpu = percpu_alloc(sizeof(struct tunnel_ro));
+	percpu_foreach(ro_percpu, if_tunnel_ro_init_pc, NULL);
+
+	return ro_percpu;
+}
+
+static void
+if_tunnel_ro_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	rtcache_free(tro->tr_ro);
+	kmem_free(tro->tr_ro, sizeof(*tro->tr_ro));
+
+	mutex_obj_free(tro->tr_lock);
+}
+
+void
+if_tunnel_free_ro_percpu(percpu_t *ro_percpu)
+{
+
+	percpu_foreach(ro_percpu, if_tunnel_ro_fini_pc, NULL);
+	percpu_free(ro_percpu, sizeof(struct tunnel_ro));
+}
+
+
+static void
+if_tunnel_rtcache_free_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct tunnel_ro *tro = p;
+
+	mutex_enter(tro->tr_lock);
+	rtcache_free(tro->tr_ro);
+	mutex_exit(tro->tr_lock);
+}
+
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *ro_percpu)
+{
+
+	percpu_foreach(ro_percpu, if_tunnel_rtcache_free_pc, NULL);
+}
+
+
 /* common */
 int
 ifioctl_common(struct ifnet *ifp, u_long cmd, void *data)

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.276 src/sys/net/if.h:1.277
--- src/sys/net/if.h:1.276	Fri Sep 13 07:55:07 2019
+++ src/sys/net/if.h	Thu Sep 19 06:07:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.276 2019/09/13 07:55:07 msaitoh Exp $	*/
+/*	$NetBSD: if.h,v 1.277 2019/09/19 06:07:24 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1122,6 +1122,33 @@ void	if_acquire(struct ifnet *, struct p
 #define	if_release	if_put
 
 int if_tunnel_check_nesting(struct ifnet *, struct mbuf *, int);
+percpu_t *if_tunnel_alloc_ro_percpu(void);
+void if_tunnel_free_ro_percpu(percpu_t *);
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *);
+
+struct tunnel_ro {
+	struct route *tr_ro;
+	kmutex_t *tr_lock;
+};
+
+static inline void
+if_tunnel_get_ro(percpu_t *ro_percpu, struct route **ro, kmutex_t **lock)
+{
+	struct tunnel_ro *tro;
+
+	tro = percpu_getref(ro_percpu);
+	*ro = tro->tr_ro;
+	*lock = tro->tr_lock;
+	

CVS commit: src/sys

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:07:25 UTC 2019

Modified Files:
src/sys/net: if.c if.h if_gif.c if_gif.h if_ipsec.c if_ipsec.h
if_l2tp.c if_l2tp.h
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
Avoid having a rtcache directly in a percpu storage for tunnel protocols.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.460 -r1.461 src/sys/net/if.c
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if.h
cvs rdiff -u -r1.148 -r1.149 src/sys/net/if_gif.c
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_gif.h
cvs rdiff -u -r1.23 -r1.24 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_ipsec.h
cvs rdiff -u -r1.37 -r1.38 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_l2tp.h
cvs rdiff -u -r1.94 -r1.95 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.93 -r1.94 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netipsec/ipsecif.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c if_l2tp.h

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_l2tp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-09-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

Modified Files:
src/sys/net: if_l2tp.c if_l2tp.h

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_l2tp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.36 src/sys/net/if_l2tp.c:1.37
--- src/sys/net/if_l2tp.c:1.36	Mon Aug 19 03:24:05 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 04:59:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -118,15 +118,20 @@ struct psref_class *lv_psref_class __rea
 static void	l2tp_ro_init_pc(void *, void *, struct cpu_info *);
 static void	l2tp_ro_fini_pc(void *, void *, struct cpu_info *);
 
+static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
 
 struct if_clone l2tp_cloner =
 IF_CLONE_INITIALIZER("l2tp", l2tp_clone_create, l2tp_clone_destroy);
 
+static int	l2tp_tx_enqueue(struct l2tp_variant *, struct mbuf *);
 static int	l2tp_output(struct ifnet *, struct mbuf *,
 		const struct sockaddr *, const struct rtentry *);
+static void	l2tp_sendit(struct l2tp_variant *, struct mbuf *);
 static void	l2tpintr(struct l2tp_variant *);
+static void	l2tpintr_softint(void *);
 
 static void	l2tp_hash_init(void);
 static int	l2tp_hash_fini(void);
@@ -225,7 +230,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	struct l2tp_softc *sc;
 	struct l2tp_variant *var;
 	int rv;
-
+	u_int si_flags = SOFTINT_NET;
+#ifdef NET_MPSAFE
+	si_flags |= SOFTINT_MPSAFE;
+#endif
 	sc = kmem_zalloc(sizeof(struct l2tp_softc), KM_SLEEP);
 	if_initname(>l2tp_ec.ec_if, ifc->ifc_name, unit);
 	rv = l2tpattach0(sc);
@@ -248,6 +256,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
 	percpu_foreach(sc->l2tp_ro_percpu, l2tp_ro_init_pc, NULL);
 
+	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue));
+	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_init_pc, NULL);
+	sc->l2tp_si = softint_establish(si_flags, l2tpintr_softint, sc);
+
 	mutex_enter(_softcs.lock);
 	LIST_INSERT_HEAD(_softcs.list, sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -326,6 +338,15 @@ l2tp_ro_fini_pc(void *p, void *arg __unu
 	mutex_obj_free(lro->lr_lock);
 }
 
+void
+l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue *ifq = p;
+
+	memset(ifq, 0, sizeof(*ifq));
+	ifq->ifq_maxlen = IFQ_MAXLEN;
+}
+
 static int
 l2tp_clone_destroy(struct ifnet *ifp)
 {
@@ -336,13 +357,17 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	l2tp_clear_session(sc);
 	l2tp_delete_tunnel(>l2tp_ec.ec_if);
 	/*
-	 * To avoid for l2tp_transmit() to access sc->l2tp_var after free it.
+	 * To avoid for l2tp_transmit() and l2tpintr_softint() to access
+	 * sc->l2tp_var after free it.
 	 */
 	mutex_enter(>l2tp_lock);
 	var = sc->l2tp_var;
 	l2tp_variant_update(sc, NULL);
 	mutex_exit(>l2tp_lock);
 
+	softint_disestablish(sc->l2tp_si);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -363,6 +388,37 @@ l2tp_clone_destroy(struct ifnet *ifp)
 }
 
 static int
+l2tp_tx_enqueue(struct l2tp_variant *var, struct mbuf *m)
+{
+	struct l2tp_softc *sc;
+	struct ifnet *ifp;
+	struct ifqueue *ifq;
+	int s;
+
+	KASSERT(psref_held(>lv_psref, lv_psref_class));
+
+	sc = var->lv_softc;
+	ifp = >l2tp_ec.ec_if;
+
+	s = splsoftnet();
+	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	if (IF_QFULL(ifq)) {
+		ifp->if_oerrors++;
+		percpu_putref(sc->l2tp_ifq_percpu);
+		splx(s);
+		m_freem(m);
+		return ENOBUFS;
+	}
+
+	IF_ENQUEUE(ifq, m);
+	percpu_putref(sc->l2tp_ifq_percpu);
+	softint_schedule(sc->l2tp_si);
+	/* counter is incremented in l2tpintr() */
+	splx(s);
+	return 0;
+}
+
+static int
 l2tp_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 const struct rtentry *rt)
 {
@@ -404,17 +460,7 @@ l2tp_output(struct ifnet *ifp, struct mb
 	}
 	*mtod(m, int *) = dst->sa_family;
 
-	IFQ_ENQUEUE(>if_snd, m, error);
-	if (error)
-		goto end;
-
-	/*
-	 * direct call to avoid infinite 

CVS commit: src/sys/arch/x86/pci

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 30 05:03:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmxnet3_softc.vmx_stats should not count globally. pointed out by hikaru@n.o

divide vmxnet3_softc.vmx_stats to each vmxnet3_txqueue and vmxnet3_rxqueue,
furthermore make them evcnt.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.48 src/sys/arch/x86/pci/if_vmx.c:1.49
--- src/sys/arch/x86/pci/if_vmx.c:1.48	Mon Aug 19 05:25:38 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Aug 30 05:03:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.49 2019/08/30 05:03:32 knakahara Exp $");
 
 #include 
 #include 
@@ -207,6 +207,8 @@ struct vmxnet3_txqueue {
 	struct evcnt vxtxq_pcqdrop;
 	struct evcnt vxtxq_transmitdef;
 	struct evcnt vxtxq_watchdogto;
+	struct evcnt vxtxq_defragged;
+	struct evcnt vxtxq_defrag_failed;
 };
 
 struct vmxnet3_rxq_stats {
@@ -230,6 +232,8 @@ struct vmxnet3_rxqueue {
 	struct evcnt vxrxq_intr;
 	struct evcnt vxrxq_defer;
 	struct evcnt vxrxq_deferreq;
+	struct evcnt vxrxq_mgetcl_failed;
+	struct evcnt vxrxq_mbuf_load_failed;
 };
 
 struct vmxnet3_queue {
@@ -244,13 +248,6 @@ struct vmxnet3_queue {
 	struct work vxq_wq_cookie;
 };
 
-struct vmxnet3_statistics {
-	uint32_t vmst_defragged;
-	uint32_t vmst_defrag_failed;
-	uint32_t vmst_mgetcl_failed;
-	uint32_t vmst_mbuf_load_failed;
-};
-
 struct vmxnet3_softc {
 	device_t vmx_dev;
 	struct ethercom vmx_ethercom;
@@ -281,7 +278,6 @@ struct vmxnet3_softc {
 	int vmx_nrxdescs;
 	int vmx_max_rxsegs;
 
-	struct vmxnet3_statistics vmx_stats;
 	struct evcnt vmx_event_intr;
 	struct evcnt vmx_event_link;
 	struct evcnt vmx_event_txqerror;
@@ -395,7 +391,8 @@ int vmxnet3_setup_interface(struct vmxne
 
 void vmxnet3_evintr(struct vmxnet3_softc *);
 bool vmxnet3_txq_eof(struct vmxnet3_txqueue *, u_int);
-int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxring *);
+int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxqueue *,
+struct vmxnet3_rxring *);
 void vmxnet3_rxq_eof_discard(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxring *, int);
 void vmxnet3_rxq_discard_chain(struct vmxnet3_rxqueue *);
@@ -1971,6 +1968,10 @@ vmxnet3_setup_stats(struct vmxnet3_softc
 		NULL, txq->vxtxq_name, "Deferred transmit");
 		evcnt_attach_dynamic(>vxtxq_watchdogto, EVCNT_TYPE_MISC,
 		NULL, txq->vxtxq_name, "Watchdog timeount");
+		evcnt_attach_dynamic(>vxtxq_defragged, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "m_defrag sucessed");
+		evcnt_attach_dynamic(>vxtxq_defrag_failed, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "m_defrag failed");
 	}
 
 	for (i = 0; i < sc->vmx_nrxqueues; i++) {
@@ -1982,6 +1983,10 @@ vmxnet3_setup_stats(struct vmxnet3_softc
 		NULL, rxq->vxrxq_name, "Handled queue in softint/workqueue");
 		evcnt_attach_dynamic(>vxrxq_deferreq, EVCNT_TYPE_MISC,
 		NULL, rxq->vxrxq_name, "Requested in softint/workqueue");
+		evcnt_attach_dynamic(>vxrxq_mgetcl_failed, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "MCLGET failed");
+		evcnt_attach_dynamic(>vxrxq_mbuf_load_failed, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "bus_dmamap_load_mbuf failed");
 	}
 
 	evcnt_attach_dynamic(>vmx_event_intr, EVCNT_TYPE_INTR,
@@ -2017,6 +2022,8 @@ vmxnet3_teardown_stats(struct vmxnet3_so
 		evcnt_detach(>vxtxq_pcqdrop);
 		evcnt_detach(>vxtxq_transmitdef);
 		evcnt_detach(>vxtxq_watchdogto);
+		evcnt_detach(>vxtxq_defragged);
+		evcnt_detach(>vxtxq_defrag_failed);
 	}
 
 	for (i = 0; i < sc->vmx_nrxqueues; i++) {
@@ -2025,6 +2032,8 @@ vmxnet3_teardown_stats(struct vmxnet3_so
 		evcnt_detach(>vxrxq_intr);
 		evcnt_detach(>vxrxq_defer);
 		evcnt_detach(>vxrxq_deferreq);
+		evcnt_detach(>vxrxq_mgetcl_failed);
+		evcnt_detach(>vxrxq_mbuf_load_failed);
 	}
 
 	evcnt_detach(>vmx_event_intr);
@@ -2154,7 +2163,8 @@ vmxnet3_txq_eof(struct vmxnet3_txqueue *
 }
 
 int
-vmxnet3_newbuf(struct vmxnet3_softc *sc, struct vmxnet3_rxring *rxr)
+vmxnet3_newbuf(struct vmxnet3_softc *sc, struct vmxnet3_rxqueue *rxq,
+struct vmxnet3_rxring *rxr)
 {
 	struct mbuf *m;
 	struct vmxnet3_rxdesc *rxd;
@@ -2180,7 +2190,7 @@ vmxnet3_newbuf(struct vmxnet3_softc *sc,
 
 	MCLGET(m, M_DONTWAIT);
 	if ((m->m_flags & M_EXT) == 0) {
-		sc->vmx_stats.vmst_mgetcl_failed++;
+		rxq->vxrxq_mgetcl_failed.ev_count++;
 		m_freem(m);
 		return (ENOBUFS);
 	}
@@ -2191,7 +2201,7 @@ vmxnet3_newbuf(struct vmxnet3_softc *sc,
 	

CVS commit: src/sys/arch/x86/pci

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 30 05:03:32 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmxnet3_softc.vmx_stats should not count globally. pointed out by hikaru@n.o

divide vmxnet3_softc.vmx_stats to each vmxnet3_txqueue and vmxnet3_rxqueue,
furthermore make them evcnt.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:45:22 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix panic when ncpu == 1 && sysctl -w hw.ixg0.txrx_workqueue=1. Reported by 
nonaka@n.o.

ok by msaitoh@n.o and nonaka@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/pci/ixgbe/ixgbe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.205 src/sys/dev/pci/ixgbe/ixgbe.c:1.206
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.205	Thu Aug 29 09:35:18 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Aug 29 09:45:22 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.205 2019/08/29 09:35:18 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.206 2019/08/29 09:45:22 knakahara Exp $ */
 
 /**
 
@@ -6467,7 +6467,9 @@ ixgbe_allocate_legacy(struct adapter *ad
 	int		counts[PCI_INTR_TYPE_SIZE];
 	pci_intr_type_t intr_type, max_type;
 	char		intrbuf[PCI_INTRSTR_LEN];
+	char		wqname[MAXCOMLEN];
 	const char	*intrstr = NULL;
+	int defertx_error = 0, error;
 
 	/* We allocate a single interrupt resource */
 	max_type = PCI_INTR_TYPE_MSI;
@@ -6529,15 +6531,27 @@ alloc_retry:
 	 * Try allocating a fast interrupt and the associated deferred
 	 * processing contexts.
 	 */
-	if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX))
+	if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)) {
 		txr->txr_si =
 		softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
 			ixgbe_deferred_mq_start, txr);
+
+		snprintf(wqname, sizeof(wqname), "%sdeferTx", device_xname(dev));
+		defertx_error = workqueue_create(>txr_wq, wqname,
+		ixgbe_deferred_mq_start_work, adapter, IXGBE_WORKQUEUE_PRI,
+		IPL_NET, IXGBE_WORKQUEUE_FLAGS);
+		adapter->txr_wq_enqueued = percpu_alloc(sizeof(u_int));
+	}
 	que->que_si = softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
 	ixgbe_handle_que, que);
+	snprintf(wqname, sizeof(wqname), "%sTxRx", device_xname(dev));
+	error = workqueue_create(>que_wq, wqname,
+	ixgbe_handle_que_work, adapter, IXGBE_WORKQUEUE_PRI, IPL_NET,
+	IXGBE_WORKQUEUE_FLAGS);
 
 	if ((!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)
-		&& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
+		&& ((txr->txr_si == NULL) || defertx_error != 0))
+	|| (que->que_si == NULL) || error != 0) {
 		aprint_error_dev(dev,
 		"could not establish software interrupts\n");
 



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:45:22 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix panic when ncpu == 1 && sysctl -w hw.ixg0.txrx_workqueue=1. Reported by 
nonaka@n.o.

ok by msaitoh@n.o and nonaka@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/pci/ixgbe/ixgbe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:35:18 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
fix typo in error handling of ixgbe_allocate_legacy().

ok by msaitoh@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/dev/pci/ixgbe/ixgbe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.204 src/sys/dev/pci/ixgbe/ixgbe.c:1.205
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.204	Wed Aug 28 08:54:21 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Aug 29 09:35:18 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.204 2019/08/28 08:54:21 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.205 2019/08/29 09:35:18 knakahara Exp $ */
 
 /**
 
@@ -6537,7 +6537,7 @@ alloc_retry:
 	ixgbe_handle_que, que);
 
 	if ((!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)
-		& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
+		&& (txr->txr_si == NULL)) || (que->que_si == NULL)) {
 		aprint_error_dev(dev,
 		"could not establish software interrupts\n");
 



CVS commit: src/sys/dev/pci/ixgbe

2019-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 29 09:35:18 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
fix typo in error handling of ixgbe_allocate_legacy().

ok by msaitoh@n.o

pullup-8, pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 src/sys/dev/pci/ixgbe/ixgbe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA

Hi,

On 2019/08/19 14:25, Kengo NAKAHARA wrote:

Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


I have finished my task for vmx(4), so I think if_vmx.c can be moved
to sys/dev/pci/ directory as pointed out by mrg@n.o.

However, it would require some htole* codes to become MI correctly.
cf. 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/vmxnet3/vmxnet3_drv.c?h=v5.3-rc5=115924b6bdc7cc6bf7da5b933b09281e1f4e17a9


It would be required to test on big endian architectures before moving
to sys/dev/pci directory.


Thanks,

--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.47 src/sys/arch/x86/pci/if_vmx.c:1.48
--- src/sys/arch/x86/pci/if_vmx.c:1.47	Mon Aug 19 05:23:50 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Aug 19 05:25:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.48 2019/08/19 05:25:38 knakahara Exp $");
 
 #include 
 #include 
@@ -200,6 +200,13 @@ struct vmxnet3_txqueue {
 	char vxtxq_name[16];
 
 	void *vxtxq_si;
+
+	struct evcnt vxtxq_intr;
+	struct evcnt vxtxq_defer;
+	struct evcnt vxtxq_deferreq;
+	struct evcnt vxtxq_pcqdrop;
+	struct evcnt vxtxq_transmitdef;
+	struct evcnt vxtxq_watchdogto;
 };
 
 struct vmxnet3_rxq_stats {
@@ -219,6 +226,10 @@ struct vmxnet3_rxqueue {
 	struct vmxnet3_rxq_stats vxrxq_stats;
 	struct vmxnet3_rxq_shared *vxrxq_rs;
 	char vxrxq_name[16];
+
+	struct evcnt vxrxq_intr;
+	struct evcnt vxrxq_defer;
+	struct evcnt vxrxq_deferreq;
 };
 
 struct vmxnet3_queue {
@@ -271,6 +282,12 @@ struct vmxnet3_softc {
 	int vmx_max_rxsegs;
 
 	struct vmxnet3_statistics vmx_stats;
+	struct evcnt vmx_event_intr;
+	struct evcnt vmx_event_link;
+	struct evcnt vmx_event_txqerror;
+	struct evcnt vmx_event_rxqerror;
+	struct evcnt vmx_event_dic;
+	struct evcnt vmx_event_debug;
 
 	int vmx_intr_type;
 	int vmx_intr_mask_mode;
@@ -349,6 +366,9 @@ void vmxnet3_set_interrupt_idx(struct vm
 int vmxnet3_setup_interrupts(struct vmxnet3_softc *);
 int vmxnet3_setup_sysctl(struct vmxnet3_softc *);
 
+int vmxnet3_setup_stats(struct vmxnet3_softc *);
+void vmxnet3_teardown_stats(struct vmxnet3_softc *);
+
 int vmxnet3_init_rxq(struct vmxnet3_softc *, int);
 int vmxnet3_init_txq(struct vmxnet3_softc *, int);
 int vmxnet3_alloc_rxtx_queues(struct vmxnet3_softc *);
@@ -631,6 +651,10 @@ vmxnet3_attach(device_t parent, device_t
 	if (error)
 		return;
 
+	error = vmxnet3_setup_stats(sc);
+	if (error)
+		return;
+
 	sc->vmx_flags |= VMXNET3_FLAG_ATTACHED;
 }
 
@@ -655,6 +679,7 @@ vmxnet3_detach(device_t self, int flags)
 		if_detach(ifp);
 	}
 
+	vmxnet3_teardown_stats(sc);
 	sysctl_teardown(>vmx_sysctllog);
 
 	vmxnet3_free_interrupts(sc);
@@ -1923,6 +1948,93 @@ out:
 	return error;
 }
 
+int
+vmxnet3_setup_stats(struct vmxnet3_softc *sc)
+{
+	struct vmxnet3_queue *vmxq;
+	struct vmxnet3_txqueue *txq;
+	struct vmxnet3_rxqueue *rxq;
+	int i;
+
+	for (i = 0; i < sc->vmx_ntxqueues; i++) {
+		vmxq = >vmx_queue[i];
+		txq = >vxq_txqueue;
+		evcnt_attach_dynamic(>vxtxq_intr, EVCNT_TYPE_INTR,
+		NULL, txq->vxtxq_name, "Interrupt on queue");
+		evcnt_attach_dynamic(>vxtxq_defer, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Handled queue in softint/workqueue");
+		evcnt_attach_dynamic(>vxtxq_deferreq, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Requested in softint/workqueue");
+		evcnt_attach_dynamic(>vxtxq_pcqdrop, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Dropped in pcq");
+		evcnt_attach_dynamic(>vxtxq_transmitdef, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Deferred transmit");
+		evcnt_attach_dynamic(>vxtxq_watchdogto, EVCNT_TYPE_MISC,
+		NULL, txq->vxtxq_name, "Watchdog timeount");
+	}
+
+	for (i = 0; i < sc->vmx_nrxqueues; i++) {
+		vmxq = >vmx_queue[i];
+		rxq = >vxq_rxqueue;
+		evcnt_attach_dynamic(>vxrxq_intr, EVCNT_TYPE_INTR,
+		NULL, rxq->vxrxq_name, "Interrupt on queue");
+		evcnt_attach_dynamic(>vxrxq_defer, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "Handled queue in softint/workqueue");
+		evcnt_attach_dynamic(>vxrxq_deferreq, EVCNT_TYPE_MISC,
+		NULL, rxq->vxrxq_name, "Requested in softint/workqueue");
+	}
+
+	evcnt_attach_dynamic(>vmx_event_intr, EVCNT_TYPE_INTR,
+	NULL, device_xname(sc->vmx_dev), "Interrupt for other events");
+	evcnt_attach_dynamic(>vmx_event_link, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Link status event");
+	evcnt_attach_dynamic(>vmx_event_txqerror, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Tx queue error event");
+	evcnt_attach_dynamic(>vmx_event_rxqerror, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Rx queue error event");
+	evcnt_attach_dynamic(>vmx_event_dic, EVCNT_TYPE_MISC,
+	NULL, device_xname(sc->vmx_dev), "Device impl change event");
+	

CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:25:38 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
add vmx(4) basic statistics counters.

Sorry, I have forgotten this TODO in r1.40 commit message.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:23:50 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
fix panic when vmx(4) is detached.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.46 src/sys/arch/x86/pci/if_vmx.c:1.47
--- src/sys/arch/x86/pci/if_vmx.c:1.46	Thu Aug  1 09:37:34 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Aug 19 05:23:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.46 2019/08/01 09:37:34 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.46 2019/08/01 09:37:34 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.47 2019/08/19 05:23:50 knakahara Exp $");
 
 #include 
 #include 
@@ -859,11 +859,13 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	int i;
 
 	workqueue_destroy(sc->vmx_queue_wq);
-	for (i = 0; i < sc->vmx_nintrs; i++) {
+	for (i = 0; i < sc->vmx_ntxqueues; i++) {
 		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
 
 		softint_disestablish(vmxq->vxq_si);
 		vmxq->vxq_si = NULL;
+	}
+	for (i = 0; i < sc->vmx_nintrs; i++) {
 		pci_intr_disestablish(pc, sc->vmx_ihs[i]);
 	}
 	pci_intr_release(pc, sc->vmx_intrs, sc->vmx_nintrs);



CVS commit: src/sys/arch/x86/pci

2019-08-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 19 05:23:50 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
fix panic when vmx(4) is detached.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netipsec

2019-08-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Aug  7 10:10:00 UTC 2019

Modified Files:
src/sys/netipsec: ipsec.c

Log Message:
ipsec_getpolicybysock() should also call key_havesp() like 
ipsec_getpolicybyaddr().

That can reduce KEYDEBUG messages.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/netipsec/ipsec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netipsec

2019-08-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Aug  7 10:10:00 UTC 2019

Modified Files:
src/sys/netipsec: ipsec.c

Log Message:
ipsec_getpolicybysock() should also call key_havesp() like 
ipsec_getpolicybyaddr().

That can reduce KEYDEBUG messages.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/netipsec/ipsec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netipsec/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.169 src/sys/netipsec/ipsec.c:1.170
--- src/sys/netipsec/ipsec.c:1.169	Tue Jul  9 16:56:24 2019
+++ src/sys/netipsec/ipsec.c	Wed Aug  7 10:10:00 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.169 2019/07/09 16:56:24 maxv Exp $ */
+/* $NetBSD: ipsec.c,v 1.170 2019/08/07 10:10:00 knakahara Exp $ */
 /* $FreeBSD: ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $ */
 /* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.169 2019/07/09 16:56:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.170 2019/08/07 10:10:00 knakahara Exp $");
 
 /*
  * IPsec controller part.
@@ -466,7 +466,10 @@ ipsec_getpolicybysock(struct mbuf *m, u_
 
 		case IPSEC_POLICY_ENTRUST:
 			/* look for a policy in SPD */
-			sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+			if (key_havesp(dir))
+sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+			else
+sp = NULL;
 			if (sp == NULL)		/* no SP found */
 sp = KEY_GET_DEFAULT_SP(af);
 			break;
@@ -478,7 +481,10 @@ ipsec_getpolicybysock(struct mbuf *m, u_
 			return NULL;
 		}
 	} else {/* unpriv, SPD has policy */
-		sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+		if (key_havesp(dir))
+			sp = KEY_LOOKUP_SP_BYSPIDX(>spidx, dir);
+		else
+			sp = NULL;
 		if (sp == NULL) {		/* no SP found */
 			switch (currsp->policy) {
 			case IPSEC_POLICY_BYPASS:



CVS commit: src/sys/arch/x86/pci

2019-07-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 30 11:16:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can select workqueue for packet processing like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 30 11:16:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can select workqueue for packet processing like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.44 src/sys/arch/x86/pci/if_vmx.c:1.45
--- src/sys/arch/x86/pci/if_vmx.c:1.44	Mon Jul 29 10:28:57 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 30 11:16:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45 2019/07/30 11:16:15 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45 2019/07/30 11:16:15 knakahara Exp $");
 
 #include 
 #include 
@@ -30,6 +30,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -96,6 +97,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #define VMXNET3_RX_PROCESS_LIMIT 256
 #define VMXNET3_TX_PROCESS_LIMIT 256
 
+#define VMXNET3_WORKQUEUE_PRI PRI_SOFTNET
+
 /*
  * IP protocols that we can perform Tx checksum offloading of.
  */
@@ -225,6 +228,8 @@ struct vmxnet3_queue {
 	struct vmxnet3_rxqueue vxq_rxqueue;
 
 	void *vxq_si;
+	bool vxq_workqueue;
+	struct work vxq_wq_cookie;
 };
 
 struct vmxnet3_statistics {
@@ -291,8 +296,10 @@ struct vmxnet3_softc {
 	u_int vmx_tx_intr_process_limit;
 	u_int vmx_rx_process_limit;
 	u_int vmx_tx_process_limit;
-
 	struct sysctllog *vmx_sysctllog;
+
+	bool vmx_txrx_workqueue;
+	struct workqueue *vmx_queue_wq;
 };
 
 #define VMXNET3_STAT
@@ -378,6 +385,7 @@ bool vmxnet3_rxq_eof(struct vmxnet3_rxqu
 int vmxnet3_legacy_intr(void *);
 int vmxnet3_txrxq_intr(void *);
 void vmxnet3_handle_queue(void *);
+void vmxnet3_handle_queue_work(struct work *, void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -849,6 +857,7 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	pci_chipset_tag_t pc = sc->vmx_pc;
 	int i;
 
+	workqueue_destroy(sc->vmx_queue_wq);
 	for (i = 0; i < sc->vmx_nintrs; i++) {
 		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
 
@@ -866,7 +875,7 @@ vmxnet3_setup_msix_interrupts(struct vmx
 	struct vmxnet3_queue *vmxq;
 	pci_intr_handle_t *intr;
 	void **ihs;
-	int intr_idx, i, use_queues;
+	int intr_idx, i, use_queues, error;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
 	char xnamebuf[32];
@@ -904,6 +913,15 @@ vmxnet3_setup_msix_interrupts(struct vmx
 
 		vmxq->vxq_intr_idx = intr_idx;
 	}
+	snprintf(xnamebuf, MAXCOMLEN, "%s_tx_rx", device_xname(sc->vmx_dev));
+	error = workqueue_create(>vmx_queue_wq, xnamebuf,
+	vmxnet3_handle_queue_work, sc, VMXNET3_WORKQUEUE_PRI, IPL_NET,
+	WQ_PERCPU | WQ_MPSAFE);
+	if (error) {
+		aprint_error_dev(sc->vmx_dev, "workqueue_create failed\n");
+		return (-1);
+	}
+	sc->vmx_txrx_workqueue = false;
 
 	intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
@@ -1839,6 +1857,12 @@ vmxnet3_setup_sysctl(struct vmxnet3_soft
 	NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
 	if (error)
 		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_BOOL, "txrx_workqueue",
+	SYSCTL_DESCR("Use workqueue for packet processing"),
+	NULL, 0, >vmx_txrx_workqueue, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
 
 	error = sysctl_createv(log, 0, , ,
 	0, CTLTYPE_NODE, "rx",
@@ -2305,6 +2329,18 @@ nextp:
 	return more;
 }
 
+static inline void
+vmxnet3_sched_handle_queue(struct vmxnet3_softc *sc, struct vmxnet3_queue *vmxq)
+{
+
+	if (vmxq->vxq_workqueue) {
+		workqueue_enqueue(sc->vmx_queue_wq, >vxq_wq_cookie,
+		curcpu());
+	} else {
+		softint_schedule(vmxq->vxq_si);
+	}
+}
+
 int
 vmxnet3_legacy_intr(void *xsc)
 {
@@ -2339,7 +2375,7 @@ vmxnet3_legacy_intr(void *xsc)
 	VMXNET3_TXQ_UNLOCK(txq);
 
 	if (txmore || rxmore) {
-		softint_schedule(sc->vmx_queue[0].vxq_si);
+		vmxnet3_sched_handle_queue(sc, >vmx_queue[0]);
 	} else {
 		if_schedule_deferred_start(>vmx_ethercom.ec_if);
 		vmxnet3_enable_all_intrs(sc);
@@ -2363,6 +2399,7 @@ vmxnet3_txrxq_intr(void *xvmxq)
 	sc = txq->vxtxq_sc;
 	txlimit = sc->vmx_tx_intr_process_limit;
 	rxlimit = sc->vmx_rx_intr_process_limit;
+	vmxq->vxq_workqueue = sc->vmx_txrx_workqueue;
 
 	if (sc->vmx_intr_mask_mode == VMXNET3_IMM_ACTIVE)
 		vmxnet3_disable_intr(sc, vmxq->vxq_intr_idx);
@@ -2376,7 +2413,7 @@ vmxnet3_txrxq_intr(void *xvmxq)
 	VMXNET3_RXQ_UNLOCK(rxq);
 
 	if (txmore || rxmore) {
-		softint_schedule(vmxq->vxq_si);
+		vmxnet3_sched_handle_queue(sc, vmxq);
 	} else {
 		/* for ALTQ */
 		if (vmxq->vxq_id 

CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:28:58 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
make vmx(4)'s *_process_limit tunable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:28:58 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
make vmx(4)'s *_process_limit tunable.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.43 src/sys/arch/x86/pci/if_vmx.c:1.44
--- src/sys/arch/x86/pci/if_vmx.c:1.43	Mon Jul 29 10:24:18 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 10:28:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.44 2019/07/29 10:28:57 knakahara Exp $");
 
 #include 
 #include 
@@ -291,6 +291,8 @@ struct vmxnet3_softc {
 	u_int vmx_tx_intr_process_limit;
 	u_int vmx_rx_process_limit;
 	u_int vmx_tx_process_limit;
+
+	struct sysctllog *vmx_sysctllog;
 };
 
 #define VMXNET3_STAT
@@ -337,6 +339,7 @@ int vmxnet3_setup_msi_interrupt(struct v
 int vmxnet3_setup_legacy_interrupt(struct vmxnet3_softc *);
 void vmxnet3_set_interrupt_idx(struct vmxnet3_softc *);
 int vmxnet3_setup_interrupts(struct vmxnet3_softc *);
+int vmxnet3_setup_sysctl(struct vmxnet3_softc *);
 
 int vmxnet3_init_rxq(struct vmxnet3_softc *, int);
 int vmxnet3_init_txq(struct vmxnet3_softc *, int);
@@ -615,6 +618,10 @@ vmxnet3_attach(device_t parent, device_t
 	if (error)
 		return;
 
+	error = vmxnet3_setup_sysctl(sc);
+	if (error)
+		return;
+
 	sc->vmx_flags |= VMXNET3_FLAG_ATTACHED;
 }
 
@@ -639,6 +646,8 @@ vmxnet3_detach(device_t self, int flags)
 		if_detach(ifp);
 	}
 
+	sysctl_teardown(>vmx_sysctllog);
+
 	vmxnet3_free_interrupts(sc);
 
 	vmxnet3_free_data(sc);
@@ -1813,6 +1822,69 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	return (0);
 }
 
+int
+vmxnet3_setup_sysctl(struct vmxnet3_softc *sc)
+{
+	const char *devname;
+	struct sysctllog **log;
+	const struct sysctlnode *rnode, *rxnode, *txnode;
+	int error;
+
+	log = >vmx_sysctllog;
+	devname = device_xname(sc->vmx_dev);
+
+	error = sysctl_createv(log, 0, NULL, ,
+	0, CTLTYPE_NODE, devname,
+	SYSCTL_DESCR("vmxnet3 information and settings"),
+	NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+
+	error = sysctl_createv(log, 0, , ,
+	0, CTLTYPE_NODE, "rx",
+	SYSCTL_DESCR("vmxnet3 information and settings for Rx"),
+	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
+	SYSCTL_DESCR("max number of Rx packets to process for interrupt processing"),
+	NULL, 0, >vmx_rx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
+	SYSCTL_DESCR("max number of Rx packets to process for deferred processing"),
+	NULL, 0, >vmx_rx_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+
+	error = sysctl_createv(log, 0, , ,
+	0, CTLTYPE_NODE, "tx",
+	SYSCTL_DESCR("vmxnet3 information and settings for Tx"),
+	NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "intr_process_limit",
+	SYSCTL_DESCR("max number of Tx packets to process for interrupt processing"),
+	NULL, 0, >vmx_tx_intr_process_limit, 0, CTL_CREATE, CTL_EOL);
+	if (error)
+		goto out;
+	error = sysctl_createv(log, 0, , NULL,
+	CTLFLAG_READWRITE, CTLTYPE_INT, "process_limit",
+	SYSCTL_DESCR("max number of Tx packets to process for deferred processing"),
+	NULL, 0, >vmx_tx_process_limit, 0, CTL_CREATE, CTL_EOL);
+
+out:
+	if (error) {
+		aprint_error_dev(sc->vmx_dev,
+		"unable to create sysctl node\n");
+		sysctl_teardown(log);
+	}
+	return error;
+}
+
 void
 vmxnet3_evintr(struct vmxnet3_softc *sc)
 {



CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:24:18 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) uses deferred interrupt handlering like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.42 src/sys/arch/x86/pci/if_vmx.c:1.43
--- src/sys/arch/x86/pci/if_vmx.c:1.42	Mon Jul 29 09:45:16 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 10:24:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.43 2019/07/29 10:24:18 knakahara Exp $");
 
 #include 
 #include 
@@ -83,6 +83,20 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #define VMXNET3_WATCHDOG_TIMEOUT	5
 
 /*
+ * Default value for vmx_intr_{rx,tx}_process_limit which is used for
+ * max number of packets to process for interrupt handler
+ */
+#define VMXNET3_RX_INTR_PROCESS_LIMIT 0U
+#define VMXNET3_TX_INTR_PROCESS_LIMIT 256
+
+/*
+ * Default value for vmx_{rx,tx}_process_limit which is used for
+ * max number of packets to process for deferred processing
+ */
+#define VMXNET3_RX_PROCESS_LIMIT 256
+#define VMXNET3_TX_PROCESS_LIMIT 256
+
+/*
  * IP protocols that we can perform Tx checksum offloading of.
  */
 #define VMXNET3_CSUM_OFFLOAD \
@@ -209,6 +223,8 @@ struct vmxnet3_queue {
 
 	struct vmxnet3_txqueue vxq_txqueue;
 	struct vmxnet3_rxqueue vxq_rxqueue;
+
+	void *vxq_si;
 };
 
 struct vmxnet3_statistics {
@@ -270,6 +286,11 @@ struct vmxnet3_softc {
 	int vmx_max_ntxqueues;
 	int vmx_max_nrxqueues;
 	uint8_t vmx_lladdr[ETHER_ADDR_LEN];
+
+	u_int vmx_rx_intr_process_limit;
+	u_int vmx_tx_intr_process_limit;
+	u_int vmx_rx_process_limit;
+	u_int vmx_tx_process_limit;
 };
 
 #define VMXNET3_STAT
@@ -342,7 +363,7 @@ void vmxnet3_free_data(struct vmxnet3_so
 int vmxnet3_setup_interface(struct vmxnet3_softc *);
 
 void vmxnet3_evintr(struct vmxnet3_softc *);
-void vmxnet3_txq_eof(struct vmxnet3_txqueue *);
+bool vmxnet3_txq_eof(struct vmxnet3_txqueue *, u_int);
 int vmxnet3_newbuf(struct vmxnet3_softc *, struct vmxnet3_rxring *);
 void vmxnet3_rxq_eof_discard(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxring *, int);
@@ -350,9 +371,10 @@ void vmxnet3_rxq_discard_chain(struct vm
 void vmxnet3_rx_csum(struct vmxnet3_rxcompdesc *, struct mbuf *);
 void vmxnet3_rxq_input(struct vmxnet3_rxqueue *,
 struct vmxnet3_rxcompdesc *, struct mbuf *);
-void vmxnet3_rxq_eof(struct vmxnet3_rxqueue *);
+bool vmxnet3_rxq_eof(struct vmxnet3_rxqueue *, u_int);
 int vmxnet3_legacy_intr(void *);
 int vmxnet3_txrxq_intr(void *);
+void vmxnet3_handle_queue(void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -819,6 +841,10 @@ vmxnet3_free_interrupts(struct vmxnet3_s
 	int i;
 
 	for (i = 0; i < sc->vmx_nintrs; i++) {
+		struct vmxnet3_queue *vmxq =  >vmx_queue[i];
+
+		softint_disestablish(vmxq->vxq_si);
+		vmxq->vxq_si = NULL;
 		pci_intr_disestablish(pc, sc->vmx_ihs[i]);
 	}
 	pci_intr_release(pc, sc->vmx_intrs, sc->vmx_nintrs);
@@ -859,6 +885,14 @@ vmxnet3_setup_msix_interrupts(struct vmx
 		}
 		aprint_normal_dev(sc->vmx_dev, "txrx interrupting at %s\n", intrstr);
 
+		vmxq->vxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+		vmxnet3_handle_queue, vmxq);
+		if (vmxq->vxq_si == NULL) {
+			aprint_error_dev(sc->vmx_dev,
+			"softint_establish for vxq_si failed\n");
+			return (-1);
+		}
+
 		vmxq->vxq_intr_idx = intr_idx;
 	}
 
@@ -886,6 +920,7 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
 	pci_intr_handle_t *intr;
 	void **ihs;
+	struct vmxnet3_queue *vmxq;
 	int i;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
@@ -893,6 +928,7 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 
 	intr = >vmx_intrs[0];
 	ihs = sc->vmx_ihs;
+	vmxq = >vmx_queue[0];
 
 	intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
@@ -907,6 +943,14 @@ vmxnet3_setup_msi_interrupt(struct vmxne
 	}
 	aprint_normal_dev(sc->vmx_dev, "interrupting at %s\n", intrstr);
 
+	vmxq->vxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+	vmxnet3_handle_queue, vmxq);
+	if (vmxq->vxq_si == NULL) {
+		aprint_error_dev(sc->vmx_dev,
+		"softint_establish for vxq_si failed\n");
+		return (-1);
+	}
+
 	for (i = 0; i < MIN(sc->vmx_nrxqueues, sc->vmx_nrxqueues); i++)
 		sc->vmx_queue[i].vxq_intr_idx = 0;
 	sc->vmx_event_intr_idx = 0;
@@ -920,6 +964,7 @@ vmxnet3_setup_legacy_interrupt(struct vm
 	pci_chipset_tag_t pc = 

CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 10:24:18 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) uses deferred interrupt handlering like ixg(4).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 09:45:16 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix missing NULL check after softint_establish().


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 09:45:16 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Fix missing NULL check after softint_establish().


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.41 src/sys/arch/x86/pci/if_vmx.c:1.42
--- src/sys/arch/x86/pci/if_vmx.c:1.41	Mon Jul 29 02:20:59 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 09:45:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.42 2019/07/29 09:45:16 knakahara Exp $");
 
 #include 
 #include 
@@ -1046,6 +1046,12 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 
 	txq->vxtxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 	vmxnet3_deferred_transmit, txq);
+	if (txq->vxtxq_si == NULL) {
+		mutex_obj_free(txq->vxtxq_mtx);
+		aprint_error_dev(sc->vmx_dev,
+		"softint_establish for vxtxq_si failed\n");
+		return ENOMEM;
+	}
 
 	txr->vxtxr_ndesc = sc->vmx_ntxdescs;
 	txr->vxtxr_txbuf = kmem_zalloc(txr->vxtxr_ndesc *



CVS commit: src/sys/arch/x86/pci

2019-07-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 02:20:59 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Join Tx interrupt handler and Rx interrupt handler of vmx(4).

That can reduce interrupt resources.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.40 src/sys/arch/x86/pci/if_vmx.c:1.41
--- src/sys/arch/x86/pci/if_vmx.c:1.40	Wed Jul 24 10:17:52 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 29 02:20:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.40 2019/07/24 10:17:52 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.40 2019/07/24 10:17:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.41 2019/07/29 02:20:59 knakahara Exp $");
 
 #include 
 #include 
@@ -173,8 +173,6 @@ struct vmxnet3_txq_stats {
 struct vmxnet3_txqueue {
 	kmutex_t *vxtxq_mtx;
 	struct vmxnet3_softc *vxtxq_sc;
-	int vxtxq_id;
-	int vxtxq_intr_idx;
 	int vxtxq_watchdog;
 	pcq_t *vxtxq_interq;
 	struct vmxnet3_txring vxtxq_cmd_ring;
@@ -196,8 +194,6 @@ struct vmxnet3_rxq_stats {
 struct vmxnet3_rxqueue {
 	kmutex_t *vxrxq_mtx;
 	struct vmxnet3_softc *vxrxq_sc;
-	int vxrxq_id;
-	int vxrxq_intr_idx;
 	struct mbuf *vxrxq_mhead;
 	struct mbuf *vxrxq_mtail;
 	struct vmxnet3_rxring vxrxq_cmd_ring[VMXNET3_RXRINGS_PERQ];
@@ -207,6 +203,14 @@ struct vmxnet3_rxqueue {
 	char vxrxq_name[16];
 };
 
+struct vmxnet3_queue {
+	int vxq_id;
+	int vxq_intr_idx;
+
+	struct vmxnet3_txqueue vxq_txqueue;
+	struct vmxnet3_rxqueue vxq_rxqueue;
+};
+
 struct vmxnet3_statistics {
 	uint32_t vmst_defragged;
 	uint32_t vmst_defrag_failed;
@@ -224,8 +228,7 @@ struct vmxnet3_softc {
 #define VMXNET3_FLAG_RSS	(1 << 1)
 #define VMXNET3_FLAG_ATTACHED	(1 << 2)
 
-	struct vmxnet3_txqueue *vmx_txq;
-	struct vmxnet3_rxqueue *vmx_rxq;
+	struct vmxnet3_queue *vmx_queue;
 
 	struct pci_attach_args *vmx_pa;
 	pci_chipset_tag_t vmx_pc;
@@ -349,8 +352,7 @@ void vmxnet3_rxq_input(struct vmxnet3_rx
 struct vmxnet3_rxcompdesc *, struct mbuf *);
 void vmxnet3_rxq_eof(struct vmxnet3_rxqueue *);
 int vmxnet3_legacy_intr(void *);
-int vmxnet3_txq_intr(void *);
-int vmxnet3_rxq_intr(void *);
+int vmxnet3_txrxq_intr(void *);
 int vmxnet3_event_intr(void *);
 
 void vmxnet3_txstop(struct vmxnet3_softc *, struct vmxnet3_txqueue *);
@@ -534,6 +536,7 @@ vmxnet3_attach(device_t parent, device_t
 	struct pci_attach_args *pa = aux;
 	pcireg_t preg;
 	int error;
+	int candidate;
 
 	sc->vmx_dev = self;
 	sc->vmx_pa = pa;
@@ -552,10 +555,10 @@ vmxnet3_attach(device_t parent, device_t
 	sc->vmx_mtx = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
 	callout_init(>vmx_tick, CALLOUT_MPSAFE);
 
-	sc->vmx_max_ntxqueues =
-	vmxnet3_calc_queue_size(MIN(VMXNET3_MAX_TX_QUEUES, ncpu));
-	sc->vmx_max_nrxqueues =
-	vmxnet3_calc_queue_size(MIN(VMXNET3_MAX_RX_QUEUES, ncpu));
+	candidate = MIN(MIN(VMXNET3_MAX_TX_QUEUES, VMXNET3_MAX_RX_QUEUES),
+	ncpu);
+	sc->vmx_max_ntxqueues = sc->vmx_max_nrxqueues =
+	vmxnet3_calc_queue_size(candidate);
 	sc->vmx_ntxdescs = 512;
 	sc->vmx_nrxdescs = 256;
 	sc->vmx_max_rxsegs = VMXNET3_MAX_RX_SEGS;
@@ -723,7 +726,7 @@ vmxnet3_alloc_msix_interrupts(struct vmx
 		return (1);
 
 	/* Allocate an additional vector for the events interrupt. */
-	required = sc->vmx_max_nrxqueues + sc->vmx_max_ntxqueues + 1;
+	required = MIN(sc->vmx_max_ntxqueues, sc->vmx_max_nrxqueues) + 1;
 
 	if (pci_msix_count(pa->pa_pc, pa->pa_tag) < required)
 		return (1);
@@ -825,11 +828,10 @@ int
 vmxnet3_setup_msix_interrupts(struct vmxnet3_softc *sc)
 {
 	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
-	struct vmxnet3_txqueue *txq;
-	struct vmxnet3_rxqueue *rxq;
+	struct vmxnet3_queue *vmxq;
 	pci_intr_handle_t *intr;
 	void **ihs;
-	int intr_idx, i;
+	int intr_idx, i, use_queues;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
 	char xnamebuf[32];
@@ -838,44 +840,26 @@ vmxnet3_setup_msix_interrupts(struct vmx
 	intr_idx = 0;
 	ihs = sc->vmx_ihs;
 
-	for (i = 0; i < sc->vmx_ntxqueues; i++, intr++, ihs++, intr_idx++) {
-		snprintf(xnamebuf, 32, "%s: tx %d", device_xname(sc->vmx_dev), i);
+	/* See vmxnet3_alloc_msix_interrupts() */
+	use_queues = MIN(sc->vmx_max_ntxqueues, sc->vmx_max_nrxqueues);
+	for (i = 0; i < use_queues; i++, intr++, ihs++, intr_idx++) {
+		snprintf(xnamebuf, 32, "%s: txrx %d", device_xname(sc->vmx_dev), i);
 
-		txq = >vmx_txq[i];
+		vmxq = >vmx_queue[i];
 
 		intrstr = pci_intr_string(pc, *intr, intrbuf, sizeof(intrbuf));
 
 		pci_intr_setattr(pc, intr, PCI_INTR_MPSAFE, true);
 		*ihs = pci_intr_establish_xname(pc, *intr, IPL_NET,
-		vmxnet3_txq_intr, txq, 

CVS commit: src/sys/arch/x86/pci

2019-07-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 29 02:20:59 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
Join Tx interrupt handler and Rx interrupt handler of vmx(4).

That can reduce interrupt resources.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

Modified Files:
src/sys/net: if.c

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/net

2019-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

Modified Files:
src/sys/net: if.c

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.456 src/sys/net/if.c:1.457
--- src/sys/net/if.c:1.456	Thu Jul  4 02:44:25 2019
+++ src/sys/net/if.c	Thu Jul 25 07:45:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1043,9 +1043,9 @@ static inline bool
 if_snd_is_used(struct ifnet *ifp)
 {
 
-	return ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit ||
-	ifp->if_transmit == if_transmit ||
-	ALTQ_IS_ENABLED(>if_snd);
+	return ALTQ_IS_ENABLED(>if_snd) ||
+		ifp->if_transmit == if_transmit ||
+		ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit;
 }
 
 /*



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:17:52 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (2/2).

Fix Tx interrupt handler. I tested on ESXi 5.5.

TODO: add statistics counters


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:15:23 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
refactor: unify vmxnet3_start_locked and vmxnet_transmit_locked


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:15:23 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
refactor: unify vmxnet3_start_locked and vmxnet_transmit_locked


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.38 src/sys/arch/x86/pci/if_vmx.c:1.39
--- src/sys/arch/x86/pci/if_vmx.c:1.38	Wed Jul 24 10:13:14 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Wed Jul 24 10:15:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.39 2019/07/24 10:15:23 knakahara Exp $");
 
 #include 
 #include 
@@ -2756,17 +2756,17 @@ vmxnet3_txq_encap(struct vmxnet3_txqueue
 	return (0);
 }
 
-void
-vmxnet3_start_locked(struct ifnet *ifp)
+#define VMXNET3_TX_START 1
+#define VMXNET3_TX_TRANSMIT 2
+static inline void
+vmxnet3_tx_common_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq, int txtype)
 {
 	struct vmxnet3_softc *sc;
-	struct vmxnet3_txqueue *txq;
 	struct vmxnet3_txring *txr;
 	struct mbuf *m_head;
 	int tx;
 
 	sc = ifp->if_softc;
-	txq = >vmx_txq[0];
 	txr = >vxtxq_cmd_ring;
 	tx = 0;
 
@@ -2777,14 +2777,20 @@ vmxnet3_start_locked(struct ifnet *ifp)
 		return;
 
 	for (;;) {
-		IFQ_POLL(>if_snd, m_head);
+		if (txtype == VMXNET3_TX_START)
+			IFQ_POLL(>if_snd, m_head);
+		else
+			m_head = pcq_peek(txq->vxtxq_interq);
 		if (m_head == NULL)
 			break;
 
 		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
 			break;
 
-		IFQ_DEQUEUE(>if_snd, m_head);
+		if (txtype == VMXNET3_TX_START)
+			IFQ_DEQUEUE(>if_snd, m_head);
+		else
+			m_head = pcq_get(txq->vxtxq_interq);
 		if (m_head == NULL)
 			break;
 
@@ -2802,6 +2808,18 @@ vmxnet3_start_locked(struct ifnet *ifp)
 		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
 }
 
+void
+vmxnet3_start_locked(struct ifnet *ifp)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txqueue *txq;
+
+	sc = ifp->if_softc;
+	txq = >vmx_txq[0];
+
+	vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_START);
+}
+
 
 void
 vmxnet3_start(struct ifnet *ifp)
@@ -2842,45 +2860,8 @@ vmxnet3_select_txqueue(struct ifnet *ifp
 void
 vmxnet3_transmit_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq)
 {
-	struct vmxnet3_softc *sc;
-	struct vmxnet3_txring *txr;
-	struct mbuf *m_head;
-	int tx;
-
-	sc = ifp->if_softc;
-	txr = >vxtxq_cmd_ring;
-	tx = 0;
-
-	VMXNET3_TXQ_LOCK_ASSERT(txq);
-
-	if ((ifp->if_flags & IFF_RUNNING) == 0 ||
-	sc->vmx_link_active == 0)
-		return;
-
-	for (;;) {
-		m_head = pcq_peek(txq->vxtxq_interq);
-		if (m_head == NULL)
-			break;
 
-		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
-			break;
-
-		m_head = pcq_get(txq->vxtxq_interq);
-		if (m_head == NULL)
-			break;
-
-		if (vmxnet3_txq_encap(txq, _head) != 0) {
-			if (m_head != NULL)
-m_freem(m_head);
-			break;
-		}
-
-		tx++;
-		bpf_mtap(ifp, m_head, BPF_D_OUT);
-	}
-
-	if (tx > 0)
-		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
+	vmxnet3_tx_common_locked(ifp, txq, VMXNET3_TX_TRANSMIT);
 }
 
 int



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:13:14 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (1/2)

Implemented Tx processing only. Fix Tx interrupt handler later.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-24 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jul 24 10:13:14 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) support if_transmit and Tx multiqueue (1/2)

Implemented Tx processing only. Fix Tx interrupt handler later.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.37 src/sys/arch/x86/pci/if_vmx.c:1.38
--- src/sys/arch/x86/pci/if_vmx.c:1.37	Tue Jul 23 04:50:05 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Wed Jul 24 10:13:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.38 2019/07/24 10:13:14 knakahara Exp $");
 
 #include 
 #include 
@@ -29,6 +29,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -174,6 +175,7 @@ struct vmxnet3_txqueue {
 	int vxtxq_id;
 	int vxtxq_intr_idx;
 	int vxtxq_watchdog;
+	pcq_t *vxtxq_interq;
 	struct vmxnet3_txring vxtxq_cmd_ring;
 	struct vmxnet3_comp_ring vxtxq_comp_ring;
 	struct vmxnet3_txq_stats vxtxq_stats;
@@ -371,6 +373,8 @@ void vmxnet3_txq_unload_mbuf(struct vmxn
 int vmxnet3_txq_encap(struct vmxnet3_txqueue *, struct mbuf **);
 void vmxnet3_start_locked(struct ifnet *);
 void vmxnet3_start(struct ifnet *);
+void vmxnet3_transmit_locked(struct ifnet *, struct vmxnet3_txqueue *);
+int vmxnet3_transmit(struct ifnet *, struct mbuf *);
 
 void vmxnet3_set_rxfilter(struct vmxnet3_softc *);
 int vmxnet3_ioctl(struct ifnet *, u_long, void *);
@@ -1061,6 +1065,8 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 
 	txq->vxtxq_comp_ring.vxcr_ndesc = sc->vmx_ntxdescs;
 
+	txq->vxtxq_interq = pcq_create(sc->vmx_ntxdescs, KM_SLEEP);
+
 	return (0);
 }
 
@@ -1134,12 +1140,17 @@ void
 vmxnet3_destroy_txq(struct vmxnet3_txqueue *txq)
 {
 	struct vmxnet3_txring *txr;
+	struct mbuf *m;
 
 	txr = >vxtxq_cmd_ring;
 
 	txq->vxtxq_sc = NULL;
 	txq->vxtxq_id = -1;
 
+	while ((m = pcq_get(txq->vxtxq_interq)) != NULL)
+		m_freem(m);
+	pcq_destroy(txq->vxtxq_interq);
+
 	if (txr->vxtxr_txbuf != NULL) {
 		kmem_free(txr->vxtxr_txbuf,
 		txr->vxtxr_ndesc * sizeof(struct vmxnet3_txbuf));
@@ -1704,6 +1715,7 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = vmxnet3_ioctl;
 	ifp->if_start = vmxnet3_start;
+	ifp->if_transmit = vmxnet3_transmit;
 	ifp->if_watchdog = NULL;
 	ifp->if_init = vmxnet3_init;
 	ifp->if_stop = vmxnet3_stop;
@@ -2805,6 +2817,95 @@ vmxnet3_start(struct ifnet *ifp)
 	VMXNET3_TXQ_UNLOCK(txq);
 }
 
+static int
+vmxnet3_select_txqueue(struct ifnet *ifp, struct mbuf *m __unused)
+{
+	struct vmxnet3_softc *sc;
+	u_int cpuid;
+
+	sc = ifp->if_softc;
+	cpuid = cpu_index(curcpu());
+	/*
+	 * Furure work
+	 * We should select txqueue to even up the load even if ncpu is
+	 * different from sc->vmx_ntxqueues. Currently, the load is not
+	 * even, that is, when ncpu is six and ntxqueues is four, the load
+	 * of vmx_txq[0] and vmx_txq[1] is higher than vmx_txq[2] and
+	 * vmx_txq[3] because CPU#4 always uses vmx_txq[0] and CPU#5 always
+	 * uses vmx_txq[1].
+	 * Furthermore, we should not use random value to select txqueue to
+	 * avoid reordering. We should use flow information of mbuf.
+	 */
+	return cpuid % sc->vmx_ntxqueues;
+}
+
+void
+vmxnet3_transmit_locked(struct ifnet *ifp, struct vmxnet3_txqueue *txq)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txring *txr;
+	struct mbuf *m_head;
+	int tx;
+
+	sc = ifp->if_softc;
+	txr = >vxtxq_cmd_ring;
+	tx = 0;
+
+	VMXNET3_TXQ_LOCK_ASSERT(txq);
+
+	if ((ifp->if_flags & IFF_RUNNING) == 0 ||
+	sc->vmx_link_active == 0)
+		return;
+
+	for (;;) {
+		m_head = pcq_peek(txq->vxtxq_interq);
+		if (m_head == NULL)
+			break;
+
+		if (vmxnet3_txring_avail(txr) < VMXNET3_TX_MAXSEGS)
+			break;
+
+		m_head = pcq_get(txq->vxtxq_interq);
+		if (m_head == NULL)
+			break;
+
+		if (vmxnet3_txq_encap(txq, _head) != 0) {
+			if (m_head != NULL)
+m_freem(m_head);
+			break;
+		}
+
+		tx++;
+		bpf_mtap(ifp, m_head, BPF_D_OUT);
+	}
+
+	if (tx > 0)
+		txq->vxtxq_watchdog = VMXNET3_WATCHDOG_TIMEOUT;
+}
+
+int
+vmxnet3_transmit(struct ifnet *ifp, struct mbuf *m)
+{
+	struct vmxnet3_softc *sc;
+	struct vmxnet3_txqueue *txq;
+	int qid;
+
+	qid = vmxnet3_select_txqueue(ifp, m);
+	sc = ifp->if_softc;
+	txq = >vmx_txq[qid];
+
+	if (__predict_false(!pcq_put(txq->vxtxq_interq, m))) {
+		m_freem(m);
+		return ENOBUFS;
+	}
+
+	VMXNET3_TXQ_LOCK(txq);
+	vmxnet3_transmit_locked(ifp, txq);
+	VMXNET3_TXQ_UNLOCK(txq);
+
+	

CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 23 04:50:05 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be detached now.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jul 23 04:50:05 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be detached now.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.36 src/sys/arch/x86/pci/if_vmx.c:1.37
--- src/sys/arch/x86/pci/if_vmx.c:1.36	Mon Jul 22 06:52:06 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Jul 23 04:50:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.37 2019/07/23 04:50:05 knakahara Exp $");
 
 #include 
 #include 
@@ -223,6 +223,7 @@ struct vmxnet3_softc {
 	struct vmxnet3_rxqueue *vmx_rxq;
 
 	struct pci_attach_args *vmx_pa;
+	pci_chipset_tag_t vmx_pc;
 
 	bus_space_tag_t vmx_iot0;
 	bus_space_tag_t vmx_iot1;
@@ -528,6 +529,7 @@ vmxnet3_attach(device_t parent, device_t
 
 	sc->vmx_dev = self;
 	sc->vmx_pa = pa;
+	sc->vmx_pc = pa->pa_pc;
 	if (pci_dma64_available(pa))
 		sc->vmx_dmat = pa->pa_dmat64;
 	else
@@ -802,7 +804,7 @@ vmxnet3_alloc_interrupts(struct vmxnet3_
 void
 vmxnet3_free_interrupts(struct vmxnet3_softc *sc)
 {
-	pci_chipset_tag_t pc = sc->vmx_pa->pa_pc;
+	pci_chipset_tag_t pc = sc->vmx_pc;
 	int i;
 
 	for (i = 0; i < sc->vmx_nintrs; i++) {



CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 22 06:52:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
remove unnecessary NULL check after kmem_zalloc(KM_SLEEP)


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.35 src/sys/arch/x86/pci/if_vmx.c:1.36
--- src/sys/arch/x86/pci/if_vmx.c:1.35	Fri Jul 19 08:49:44 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Jul 22 06:52:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.36 2019/07/22 06:52:06 knakahara Exp $");
 
 #include 
 #include 
@@ -1030,8 +1030,6 @@ vmxnet3_init_rxq(struct vmxnet3_softc *s
 		rxr->vxrxr_ndesc = sc->vmx_nrxdescs;
 		rxr->vxrxr_rxbuf = kmem_zalloc(rxr->vxrxr_ndesc *
 		sizeof(struct vmxnet3_rxbuf), KM_SLEEP);
-		if (rxr->vxrxr_rxbuf == NULL)
-			return (ENOMEM);
 
 		rxq->vxrxq_comp_ring.vxcr_ndesc += sc->vmx_nrxdescs;
 	}
@@ -1058,8 +1056,6 @@ vmxnet3_init_txq(struct vmxnet3_softc *s
 	txr->vxtxr_ndesc = sc->vmx_ntxdescs;
 	txr->vxtxr_txbuf = kmem_zalloc(txr->vxtxr_ndesc *
 	sizeof(struct vmxnet3_txbuf), KM_SLEEP);
-	if (txr->vxtxr_txbuf == NULL)
-		return (ENOMEM);
 
 	txq->vxtxq_comp_ring.vxcr_ndesc = sc->vmx_ntxdescs;
 
@@ -1093,8 +1089,6 @@ vmxnet3_alloc_rxtx_queues(struct vmxnet3
 	sizeof(struct vmxnet3_rxqueue) * sc->vmx_max_nrxqueues, KM_SLEEP);
 	sc->vmx_txq = kmem_zalloc(
 	sizeof(struct vmxnet3_txqueue) * sc->vmx_max_ntxqueues, KM_SLEEP);
-	if (sc->vmx_rxq == NULL || sc->vmx_txq == NULL)
-		return (ENOMEM);
 
 	for (i = 0; i < sc->vmx_max_nrxqueues; i++) {
 		error = vmxnet3_init_rxq(sc, i);



CVS commit: src/sys/arch/x86/pci

2019-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jul 22 06:52:06 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
remove unnecessary NULL check after kmem_zalloc(KM_SLEEP)


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/pci

2019-07-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 19 08:49:44 UTC 2019

Modified Files:
src/sys/arch/x86/pci: if_vmx.c

Log Message:
vmx(4) can be set IFEF_MPSAFE now.

I tested bidirectional forwarding with some ioctls.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/x86/pci/if_vmx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.34 src/sys/arch/x86/pci/if_vmx.c:1.35
--- src/sys/arch/x86/pci/if_vmx.c:1.34	Fri Jul 19 08:46:32 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Fri Jul 19 08:49:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.34 2019/07/19 08:46:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.35 2019/07/19 08:49:44 knakahara Exp $");
 
 #include 
 #include 
@@ -1705,6 +1705,7 @@ vmxnet3_setup_interface(struct vmxnet3_s
 	strlcpy(ifp->if_xname, device_xname(sc->vmx_dev), IFNAMSIZ);
 	ifp->if_softc = sc;
 	ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX;
+	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = vmxnet3_ioctl;
 	ifp->if_start = vmxnet3_start;
 	ifp->if_watchdog = NULL;



  1   2   >