CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-11-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Nov 16 16:53:13 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: msipic.c

Log Message:
Pull up following revision(s) (requested by hikaru in ticket #429):

sys/arch/x86/pci/msipic.c: revision 1.19

Disable MSI-X before writing the MSI-X table.

That fixes MSI-X interrupt lost on VMware ESXi 6.7 PCI passthrough devices.

ok knakahara@


To generate a diff of this commit:
cvs rdiff -u -r1.17.2.1 -r1.17.2.2 src/sys/arch/x86/pci/msipic.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/msipic.c
diff -u src/sys/arch/x86/pci/msipic.c:1.17.2.1 src/sys/arch/x86/pci/msipic.c:1.17.2.2
--- src/sys/arch/x86/pci/msipic.c:1.17.2.1	Tue Oct 15 18:08:31 2019
+++ src/sys/arch/x86/pci/msipic.c	Sat Nov 16 16:53:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msipic.c,v 1.17.2.1 2019/10/15 18:08:31 martin Exp $	*/
+/*	$NetBSD: msipic.c,v 1.17.2.2 2019/11/16 16:53:13 martin Exp $	*/
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.17.2.1 2019/10/15 18:08:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.17.2.2 2019/11/16 16:53:13 martin Exp $");
 
 #include "opt_intrdebug.h"
 
@@ -548,6 +548,11 @@ msix_addroute(struct pic *pic, struct cp
 	err = pci_get_capability(pc, tag, PCI_CAP_MSIX, , NULL);
 	KASSERT(err != 0);
 
+	/* Disable MSI-X before writing MSI-X table */
+	ctl = pci_conf_read(pc, tag, off + PCI_MSIX_CTL);
+	ctl &= ~PCI_MSIX_CTL_ENABLE;
+	pci_conf_write(pc, tag, off + PCI_MSIX_CTL, ctl);
+
 	entry_base = PCI_MSIX_TABLE_ENTRY_SIZE * msix_vec;
 
 	/*



CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-11-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Nov 16 16:53:13 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: msipic.c

Log Message:
Pull up following revision(s) (requested by hikaru in ticket #429):

sys/arch/x86/pci/msipic.c: revision 1.19

Disable MSI-X before writing the MSI-X table.

That fixes MSI-X interrupt lost on VMware ESXi 6.7 PCI passthrough devices.

ok knakahara@


To generate a diff of this commit:
cvs rdiff -u -r1.17.2.1 -r1.17.2.2 src/sys/arch/x86/pci/msipic.c

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



CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-10-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct 15 18:08:31 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: msipic.c

Log Message:
Pull up following revision(s) (requested by tnn in ticket #305):

sys/arch/x86/pci/msipic.c: revision 1.18

change bus_space_map to _x86_memio_map

Resolves bus space reservation conflict between MI and MD code.

Discussion:
http://mail-index.netbsd.org/port-amd64/2019/09/28/msg003014.html


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/arch/x86/pci/msipic.c

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



CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-10-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct 15 18:08:31 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: msipic.c

Log Message:
Pull up following revision(s) (requested by tnn in ticket #305):

sys/arch/x86/pci/msipic.c: revision 1.18

change bus_space_map to _x86_memio_map

Resolves bus space reservation conflict between MI and MD code.

Discussion:
http://mail-index.netbsd.org/port-amd64/2019/09/28/msg003014.html


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/arch/x86/pci/msipic.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/msipic.c
diff -u src/sys/arch/x86/pci/msipic.c:1.17 src/sys/arch/x86/pci/msipic.c:1.17.2.1
--- src/sys/arch/x86/pci/msipic.c:1.17	Wed Jun 26 10:20:06 2019
+++ src/sys/arch/x86/pci/msipic.c	Tue Oct 15 18:08:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msipic.c,v 1.17 2019/06/26 10:20:06 knakahara Exp $	*/
+/*	$NetBSD: msipic.c,v 1.17.2.1 2019/10/15 18:08:31 martin Exp $	*/
 
 /*
  * Copyright (c) 2015 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.17 2019/06/26 10:20:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msipic.c,v 1.17.2.1 2019/10/15 18:08:31 martin Exp $");
 
 #include "opt_intrdebug.h"
 
@@ -711,7 +711,7 @@ msipic_construct_msix_pic(const struct p
 		flags &= ~BUS_SPACE_MAP_PREFETCHABLE;
 	}
 	bssize = roundup(table_size, PAGE_SIZE);
-	err = bus_space_map(pa->pa_memt, memaddr + table_offset, bssize, flags,
+	err = _x86_memio_map(pa->pa_memt, memaddr + table_offset, bssize, flags,
 	);
 	bstag = pa->pa_memt;
 #endif
@@ -739,8 +739,8 @@ msipic_destruct_msix_pic(struct pic *msi
 	KASSERT(msix_pic->pic_type == PIC_MSIX);
 
 	msipic = msix_pic->pic_msipic;
-	bus_space_unmap(msipic->mp_bstag, msipic->mp_bshandle,
-	msipic->mp_bssize);
+	_x86_memio_unmap(msipic->mp_bstag, msipic->mp_bshandle,
+	msipic->mp_bssize, NULL);
 
 	msipic_destruct_common_msi_pic(msix_pic);
 }



CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-10-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 10 17:32:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #298):

sys/arch/x86/pci/if_vmx.c: revision 1.51

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


To generate a diff of this commit:
cvs rdiff -u -r1.45.2.3 -r1.45.2.4 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: [netbsd-9] src/sys/arch/x86/pci

2019-10-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 10 17:32:15 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #298):

sys/arch/x86/pci/if_vmx.c: revision 1.51

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


To generate a diff of this commit:
cvs rdiff -u -r1.45.2.3 -r1.45.2.4 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.45.2.3 src/sys/arch/x86/pci/if_vmx.c:1.45.2.4
--- src/sys/arch/x86/pci/if_vmx.c:1.45.2.3	Mon Sep 30 15:42:03 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Thu Oct 10 17:32:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.45.2.3 2019/09/30 15:42:03 martin Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45.2.4 2019/10/10 17:32:15 martin 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.45.2.3 2019/09/30 15:42:03 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45.2.4 2019/10/10 17:32:15 martin 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: [netbsd-9] src/sys/arch/x86/pci

2019-09-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Sep 30 15:42:03 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #268):

sys/arch/x86/pci/if_vmx.c: revision 1.50

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.45.2.2 -r1.45.2.3 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.45.2.2 src/sys/arch/x86/pci/if_vmx.c:1.45.2.3
--- src/sys/arch/x86/pci/if_vmx.c:1.45.2.2	Sun Sep  1 13:52:53 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Mon Sep 30 15:42:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.45.2.2 2019/09/01 13:52:53 martin Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45.2.3 2019/09/30 15:42:03 martin 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.45.2.2 2019/09/01 13:52:53 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45.2.3 2019/09/30 15:42:03 martin 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: [netbsd-9] src/sys/arch/x86/pci

2019-09-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Sep 30 15:42:03 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #268):

sys/arch/x86/pci/if_vmx.c: revision 1.50

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.45.2.2 -r1.45.2.3 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: [netbsd-9] src/sys/arch/x86/pci

2019-09-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep  1 13:52:53 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #143):

sys/arch/x86/pci/if_vmx.c: revision 1.49

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.45.2.1 -r1.45.2.2 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: [netbsd-9] src/sys/arch/x86/pci

2019-09-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep  1 13:52:53 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #143):

sys/arch/x86/pci/if_vmx.c: revision 1.49

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.45.2.1 -r1.45.2.2 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.45.2.1 src/sys/arch/x86/pci/if_vmx.c:1.45.2.2
--- src/sys/arch/x86/pci/if_vmx.c:1.45.2.1	Tue Aug 20 11:31:46 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Sun Sep  1 13:52:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.45.2.1 2019/08/20 11:31:46 martin Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45.2.2 2019/09/01 13:52:53 martin 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.45.2.1 2019/08/20 11:31:46 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45.2.2 2019/09/01 13:52:53 martin 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) {
-		

CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-08-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug 20 11:31:46 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #99):

sys/arch/x86/pci/if_vmx.c: revision 1.46
sys/arch/x86/pci/if_vmx.c: revision 1.47
sys/arch/x86/pci/if_vmx.c: revision 1.48

vmx(4) uses interrupt distribution for each queue like ixg(4).

fix panic when vmx(4) is detached.

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.45 -r1.45.2.1 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.45 src/sys/arch/x86/pci/if_vmx.c:1.45.2.1
--- src/sys/arch/x86/pci/if_vmx.c:1.45	Tue Jul 30 11:16:15 2019
+++ src/sys/arch/x86/pci/if_vmx.c	Tue Aug 20 11:31:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.45 2019/07/30 11:16:15 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.45.2.1 2019/08/20 11:31:46 martin 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.45 2019/07/30 11:16:15 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.45.2.1 2019/08/20 11:31:46 martin Exp $");
 
 #include 
 #include 
@@ -31,6 +31,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -199,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 {
@@ -218,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 {
@@ -270,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;
@@ -348,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 *);
@@ -630,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;
 }
 
@@ -654,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);
@@ -858,11 +884,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);
@@ -876,6 +904,7 @@ vmxnet3_setup_msix_interrupts(struct vmx
 	pci_intr_handle_t *intr;
 	void **ihs;
 	int intr_idx, i, use_queues, error;
+	kcpuset_t *affinity;
 	const char *intrstr;
 	char intrbuf[PCI_INTRSTR_LEN];
 	char xnamebuf[32];
@@ -903,6 +932,16 @@ vmxnet3_setup_msix_interrupts(struct vmx
 		}
 		aprint_normal_dev(sc->vmx_dev, "txrx interrupting at %s\n", intrstr);
 
+		kcpuset_create(, true);
+		kcpuset_set(affinity, intr_idx % ncpu);
+		error = interrupt_distribute(*ihs, affinity, NULL);
+		if (error) {
+			aprint_normal_dev(sc->vmx_dev,
+			"%s cannot be changed affinity, use default CPU\n",
+			intrstr);
+		}
+		kcpuset_destroy(affinity);
+
 		vmxq->vxq_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 		vmxnet3_handle_queue, vmxq);
 		if (vmxq->vxq_si == NULL) {
@@ -1909,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,
+		   

CVS commit: [netbsd-9] src/sys/arch/x86/pci

2019-08-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug 20 11:31:46 UTC 2019

Modified Files:
src/sys/arch/x86/pci [netbsd-9]: if_vmx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #99):

sys/arch/x86/pci/if_vmx.c: revision 1.46
sys/arch/x86/pci/if_vmx.c: revision 1.47
sys/arch/x86/pci/if_vmx.c: revision 1.48

vmx(4) uses interrupt distribution for each queue like ixg(4).

fix panic when vmx(4) is detached.

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.45 -r1.45.2.1 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.