CVS commit: [netbsd-9] src/sys/dev/audio

2021-07-28 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Wed Jul 28 14:59:02 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1325):
sys/dev/audio/audio.c: revision 1.105
AUDIO_SETINFO: fix a bug that the gain and the balance could not be set
at the same time.  Fix PR kern/56308.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.22 -r1.28.2.23 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.22 src/sys/dev/audio/audio.c:1.28.2.23
--- src/sys/dev/audio/audio.c:1.28.2.22	Wed May  5 17:01:41 2021
+++ src/sys/dev/audio/audio.c	Wed Jul 28 14:59:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.23 2021/07/28 14:59:02 snj Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.23 2021/07/28 14:59:02 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -7381,59 +7381,46 @@ audio_hw_setinfo(struct audio_softc *sc,
 		}
 	}
 
-	/* Backup play.{gain,balance} */
+	/* play.{gain,balance} */
 	if (SPECIFIED(newpi->gain) || SPECIFIED_CH(newpi->balance)) {
 		au_get_gain(sc, >sc_outports, , );
 		if (oldai) {
 			oldpi->gain = pgain;
 			oldpi->balance = pbalance;
 		}
+
+		if (SPECIFIED(newpi->gain))
+			pgain = newpi->gain;
+		if (SPECIFIED_CH(newpi->balance))
+			pbalance = newpi->balance;
+		error = au_set_gain(sc, >sc_outports, pgain, pbalance);
+		if (error) {
+			audio_printf(sc,
+			"setting play.gain=%d/balance=%d failed: "
+			"errno=%d\n",
+			pgain, pbalance, error);
+			goto abort;
+		}
 	}
-	/* Backup record.{gain,balance} */
+
+	/* record.{gain,balance} */
 	if (SPECIFIED(newri->gain) || SPECIFIED_CH(newri->balance)) {
 		au_get_gain(sc, >sc_inports, , );
 		if (oldai) {
 			oldri->gain = rgain;
 			oldri->balance = rbalance;
 		}
-	}
-	if (SPECIFIED(newpi->gain)) {
-		error = au_set_gain(sc, >sc_outports,
-		newpi->gain, pbalance);
-		if (error) {
-			audio_printf(sc,
-			"setting play.gain=%d failed: errno=%d\n",
-			newpi->gain, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED(newri->gain)) {
-		error = au_set_gain(sc, >sc_inports,
-		newri->gain, rbalance);
-		if (error) {
-			audio_printf(sc,
-			"setting record.gain=%d failed: errno=%d\n",
-			newri->gain, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED_CH(newpi->balance)) {
-		error = au_set_gain(sc, >sc_outports,
-		pgain, newpi->balance);
-		if (error) {
-			audio_printf(sc,
-			"setting play.balance=%d failed: errno=%d\n",
-			newpi->balance, error);
-			goto abort;
-		}
-	}
-	if (SPECIFIED_CH(newri->balance)) {
-		error = au_set_gain(sc, >sc_inports,
-		rgain, newri->balance);
+
+		if (SPECIFIED(newri->gain))
+			rgain = newri->gain;
+		if (SPECIFIED_CH(newri->balance))
+			rbalance = newri->balance;
+		error = au_set_gain(sc, >sc_inports, rgain, rbalance);
 		if (error) {
 			audio_printf(sc,
-			"setting record.balance=%d failed: errno=%d\n",
-			newri->balance, error);
+			"setting record.gain=%d/balance=%d failed: "
+			"errno=%d\n",
+			rgain, rbalance, error);
 			goto abort;
 		}
 	}



CVS commit: [netbsd-9] src/sys/dev/ic

2021-07-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jul  3 10:18:16 UTC 2021

Modified Files:
src/sys/dev/ic [netbsd-9]: ax88190.c dl10019.c dp8390.c

Log Message:
Pull up following revision(s) (requested by thorpej in ticket #1311):

sys/dev/ic/dp8390.c: revision 1.99
sys/dev/ic/dl10019.c: revision 1.17
sys/dev/ic/ax88190.c: revision 1.18

Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work.  Problem reported by Bj�rn Johannesson
on current-users@.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.15.2.1 src/sys/dev/ic/ax88190.c
cvs rdiff -u -r1.14 -r1.14.2.1 src/sys/dev/ic/dl10019.c
cvs rdiff -u -r1.95 -r1.95.2.1 src/sys/dev/ic/dp8390.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/ic/ax88190.c
diff -u src/sys/dev/ic/ax88190.c:1.15 src/sys/dev/ic/ax88190.c:1.15.2.1
--- src/sys/dev/ic/ax88190.c:1.15	Wed May 29 06:17:28 2019
+++ src/sys/dev/ic/ax88190.c	Sat Jul  3 10:18:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ax88190.c,v 1.15 2019/05/29 06:17:28 msaitoh Exp $	*/
+/*	$NetBSD: ax88190.c,v 1.15.2.1 2021/07/03 10:18:16 martin Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.15 2019/05/29 06:17:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.15.2.1 2021/07/03 10:18:16 martin Exp $");
 
 #include 
 #include 
@@ -86,6 +86,8 @@ ax88190_media_init(struct dp8390_softc *
 	struct ifnet *ifp = >sc_ec.ec_if;
 	struct mii_data *mii = >sc_mii;
 
+	sc->sc_ec.ec_mii = mii;
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = ax88190_mii_readreg;
 	mii->mii_writereg = ax88190_mii_writereg;

Index: src/sys/dev/ic/dl10019.c
diff -u src/sys/dev/ic/dl10019.c:1.14 src/sys/dev/ic/dl10019.c:1.14.2.1
--- src/sys/dev/ic/dl10019.c:1.14	Wed May 29 06:17:28 2019
+++ src/sys/dev/ic/dl10019.c	Sat Jul  3 10:18:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dl10019.c,v 1.14 2019/05/29 06:17:28 msaitoh Exp $	*/
+/*	$NetBSD: dl10019.c,v 1.14.2.1 2021/07/03 10:18:16 martin Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.14 2019/05/29 06:17:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.14.2.1 2021/07/03 10:18:16 martin Exp $");
 
 #include 
 #include 
@@ -119,6 +119,8 @@ dl10019_media_init(struct dp8390_softc *
 	struct ifnet *ifp = >sc_ec.ec_if;
 	struct mii_data *mii = >sc_mii;
 
+	sc->sc_ec.ec_mii = mii;
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = dl10019_mii_readreg;
 	mii->mii_writereg = dl10019_mii_writereg;

Index: src/sys/dev/ic/dp8390.c
diff -u src/sys/dev/ic/dp8390.c:1.95 src/sys/dev/ic/dp8390.c:1.95.2.1
--- src/sys/dev/ic/dp8390.c:1.95	Wed May 29 10:07:29 2019
+++ src/sys/dev/ic/dp8390.c	Sat Jul  3 10:18:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dp8390.c,v 1.95 2019/05/29 10:07:29 msaitoh Exp $	*/
+/*	$NetBSD: dp8390.c,v 1.95.2.1 2021/07/03 10:18:16 martin Exp $	*/
 
 /*
  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@@ -14,7 +14,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.95 2019/05/29 10:07:29 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.95.2.1 2021/07/03 10:18:16 martin Exp $");
 
 #include "opt_inet.h"
 
@@ -66,7 +66,6 @@ void
 dp8390_media_init(struct dp8390_softc *sc)
 {
 
-	sc->sc_ec.ec_ifmedia = >sc_media;
 	ifmedia_init(>sc_media, 0, dp8390_mediachange, dp8390_mediastatus);
 	ifmedia_add(>sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL);
 	ifmedia_set(>sc_media, IFM_ETHER | IFM_MANUAL);
@@ -131,7 +130,13 @@ dp8390_config(struct dp8390_softc *sc)
 	aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n",
 	ether_sprintf(sc->sc_enaddr));
 
-	/* Initialize media goo. */
+	/*
+	 * Initialize media structures.  We'll default to pointing ec_ifmedia
+	 * at our embedded media structure.  A card front-end can initialize
+	 * ec_mii if it has an MII interface.  (Note that sc_media is an
+	 * alias of sc_mii.mii_media in dp8390_softc.)
+	 */
+	sc->sc_ec.ec_ifmedia = >sc_media;
 	(*sc->sc_media_init)(sc);
 
 	/* We can support 802.1Q VLAN-sized frames. */



CVS commit: [netbsd-9] src/sys/dev/usb

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 22 05:10:50 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: xhci.c xhcireg.h xhcivar.h

Log Message:
Fix pullup #1302 by adapting the changes to this branch
(there was a misunderstanding in the ticket handling)


To generate a diff of this commit:
cvs rdiff -u -r1.107.2.8 -r1.107.2.9 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.13.2.1 -r1.13.2.2 src/sys/dev/usb/xhcireg.h
cvs rdiff -u -r1.11.4.1 -r1.11.4.2 src/sys/dev/usb/xhcivar.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/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.107.2.8 src/sys/dev/usb/xhci.c:1.107.2.9
--- src/sys/dev/usb/xhci.c:1.107.2.8	Mon Jun 21 17:11:46 2021
+++ src/sys/dev/usb/xhci.c	Tue Jun 22 05:10:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.107.2.8 2021/06/21 17:11:46 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.107.2.9 2021/06/22 05:10:50 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.8 2021/06/21 17:11:46 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.9 2021/06/22 05:10:50 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -724,7 +724,7 @@ xhci_suspend(device_t self, const pmf_qu
 		if (xs->xs_idx == 0)
 			continue;
 
-		for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) {
+		for (dci = 0; dci < 32; dci++) {
 			/* Skip if the endpoint is not Running.  */
 			/* XXX What about Busy?  */
 			if (xhci_get_epstate(sc, xs, dci) !=
@@ -951,7 +951,7 @@ xhci_resume(device_t self, const pmf_qua
 	 *
 	 * XXX Hope just zeroing it is good enough!
 	 */
-	xhci_host_dequeue(sc->sc_cr);
+	xhci_host_dequeue(>sc_cr);
 
 	/*
 	 * `7. Write the CRCR with the address and RCS value of the
@@ -959,8 +959,8 @@ xhci_resume(device_t self, const pmf_qua
 	 * cause the Command Ring to restart at the address
 	 * specified by the CRCR.'
 	 */
-	xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(sc->sc_cr, 0) |
-	sc->sc_cr->xr_cs);
+	xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(>sc_cr, 0) |
+	sc->sc_cr.xr_cs);
 
 	/*
 	 * `8. Enable the controller by setting Run/Stop (R/S) =
@@ -1049,7 +1049,7 @@ xhci_resume(device_t self, const pmf_qua
 		if (xs->xs_idx == 0)
 			continue;
 
-		for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) {
+		for (dci = 0; dci < 32; dci++) {
 			/* Skip if the endpoint is not Running.  */
 			if (xhci_get_epstate(sc, xs, dci) !=
 			XHCI_EPSTATE_RUNNING)

Index: src/sys/dev/usb/xhcireg.h
diff -u src/sys/dev/usb/xhcireg.h:1.13.2.1 src/sys/dev/usb/xhcireg.h:1.13.2.2
--- src/sys/dev/usb/xhcireg.h:1.13.2.1	Mon Jun 21 17:11:46 2021
+++ src/sys/dev/usb/xhcireg.h	Tue Jun 22 05:10:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: xhcireg.h,v 1.13.2.1 2021/06/21 17:11:46 martin Exp $ */
+/* $NetBSD: xhcireg.h,v 1.13.2.2 2021/06/22 05:10:50 martin Exp $ */
 
 /*-
  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
@@ -162,8 +162,31 @@
 #define	 XHCI_PS_PED		0x0002	/* RW - port enabled / disabled */
 #define	 XHCI_PS_OCA		0x0008	/* RO - over current active */
 #define	 XHCI_PS_PR		0x0010	/* RW - port reset */
+#define	 XHCI_PS_PLS_MASK	__BITS(8, 5)
 #define	 XHCI_PS_PLS_GET(x)	(((x) >> 5) & 0xF)	/* RW - port link state */
 #define	 XHCI_PS_PLS_SET(x)	(((x) & 0xF) << 5)	/* RW - port link state */
+
+#define  XHCI_PS_PLS_SETU0	0
+#define  XHCI_PS_PLS_SETU2	2
+#define  XHCI_PS_PLS_SETU3	3
+#define  XHCI_PS_PLS_SETDISC	5
+#define  XHCI_PS_PLS_SETCOMP	10
+#define  XHCI_PS_PLS_SETRESUME	15
+
+#define  XHCI_PS_PLS_U0		0
+#define  XHCI_PS_PLS_U1		1
+#define  XHCI_PS_PLS_U2		2
+#define  XHCI_PS_PLS_U3		3
+#define  XHCI_PS_PLS_DISABLED	4
+#define  XHCI_PS_PLS_RXDETECT	5
+#define  XHCI_PS_PLS_INACTIVE	6
+#define  XHCI_PS_PLS_POLLING	7
+#define  XHCI_PS_PLS_RECOVERY	8
+#define  XHCI_PS_PLS_HOTRESET	9
+#define  XHCI_PS_PLS_COMPLIANCE	10
+#define  XHCI_PS_PLS_TEST	11
+#define  XHCI_PS_PLS_RESUME	15
+
 #define	 XHCI_PS_PP		0x0200	/* RW - port power */
 #define	 XHCI_PS_SPEED_GET(x)	(((x) >> 10) & 0xF)	/* RO - port speed */
 #define	 XHCI_PS_SPEED_FS	1

Index: src/sys/dev/usb/xhcivar.h
diff -u src/sys/dev/usb/xhcivar.h:1.11.4.1 src/sys/dev/usb/xhcivar.h:1.11.4.2
--- src/sys/dev/usb/xhcivar.h:1.11.4.1	Mon Jun 21 17:11:46 2021
+++ src/sys/dev/usb/xhcivar.h	Tue Jun 22 05:10:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhcivar.h,v 1.11.4.1 2021/06/21 17:11:46 martin Exp $	*/
+/*	$NetBSD: xhcivar.h,v 1.11.4.2 2021/06/22 05:10:50 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch



CVS commit: [netbsd-9] src/sys/dev/usb

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 17:27:57 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: umass.c umass_scsipi.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1306):

sys/dev/usb/umass.c: revision 1.185
sys/dev/usb/umass_scsipi.c: revision 1.68

umass(4): Use an empty function callback, not null pointer.

This stupid bug, with an `XXX Broken!' comment right above, has been
preventing NetBSD from suspend/resume with a USB drive plugged in for
longer than I want to even think about admitting.  *sigh*
umass(4): Assert that we got a cb up front.

Avoids jump to zero waaay down the line where we've forgotten why
we wanted to jump into oblivion.


To generate a diff of this commit:
cvs rdiff -u -r1.175.2.1 -r1.175.2.2 src/sys/dev/usb/umass.c
cvs rdiff -u -r1.62 -r1.62.2.1 src/sys/dev/usb/umass_scsipi.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/usb/umass.c
diff -u src/sys/dev/usb/umass.c:1.175.2.1 src/sys/dev/usb/umass.c:1.175.2.2
--- src/sys/dev/usb/umass.c:1.175.2.1	Sun Mar  1 12:38:59 2020
+++ src/sys/dev/usb/umass.c	Mon Jun 21 17:27:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass.c,v 1.175.2.1 2020/03/01 12:38:59 martin Exp $	*/
+/*	$NetBSD: umass.c,v 1.175.2.2 2021/06/21 17:27:57 martin Exp $	*/
 
 /*
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.175.2.1 2020/03/01 12:38:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.175.2.2 2021/06/21 17:27:57 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1105,6 +1105,7 @@ umass_bbb_transfer(struct umass_softc *s
 	UMASSHIST_FUNC(); UMASSHIST_CALLED();
 	static int dCBWtag = 42;	/* unique for CBW of transfer */
 
+	KASSERT(cb);
 	DPRINTFM(UDMASS_BBB, "sc %#jx cmd=0x%02jx", (uintptr_t)sc,
 	*(u_char *)cmd, 0, 0);
 
@@ -1629,6 +1630,7 @@ umass_cbi_transfer(struct umass_softc *s
 	DPRINTFM(UDMASS_CBI, "sc %#jx: cmd=0x%02jx, len=%jd",
 	 (uintptr_t)sc, *(u_char *)cmd, datalen, 0);
 
+	KASSERT(cb);
 	KASSERTMSG(sc->sc_wire & (UMASS_WPROTO_CBI|UMASS_WPROTO_CBI_I),
 		   "sc->sc_wire == 0x%02x wrong for umass_cbi_transfer\n",
 		   sc->sc_wire);

Index: src/sys/dev/usb/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.62 src/sys/dev/usb/umass_scsipi.c:1.62.2.1
--- src/sys/dev/usb/umass_scsipi.c:1.62	Thu May 30 21:44:49 2019
+++ src/sys/dev/usb/umass_scsipi.c	Mon Jun 21 17:27:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_scsipi.c,v 1.62 2019/05/30 21:44:49 mlelstv Exp $	*/
+/*	$NetBSD: umass_scsipi.c,v 1.62.2.1 2021/06/21 17:27:57 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2003, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.62 2019/05/30 21:44:49 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.62.2.1 2021/06/21 17:27:57 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -101,6 +101,8 @@ Static int umass_scsipi_ioctl(struct scs
 Static int umass_scsipi_getgeom(struct scsipi_periph *,
 struct disk_parms *, u_long);
 
+Static void umass_null_cb(struct umass_softc *, void *,
+			  int, int);
 Static void umass_scsipi_cb(struct umass_softc *, void *,
 			int, int);
 Static void umass_scsipi_sense_cb(struct umass_softc *, void *,
@@ -319,7 +321,7 @@ umass_scsipi_request(struct scsipi_chann
 		  cmdlen, xs->data,
 		  xs->datalen, dir,
 		  xs->timeout, USBD_SYNCHRONOUS,
-		  0, xs);
+		  umass_null_cb, xs);
 			DPRINTFM(UDMASS_SCSI, "done err=%jd",
 			scbus->sc_sync_status, 0, 0, 0);
 			switch (scbus->sc_sync_status) {
@@ -419,6 +421,12 @@ umass_scsipi_getgeom(struct scsipi_perip
 }
 
 Static void
+umass_null_cb(struct umass_softc *sc, void *priv, int residue, int status)
+{
+	UMASSHIST_FUNC(); UMASSHIST_CALLED();
+}
+
+Static void
 umass_scsipi_cb(struct umass_softc *sc, void *priv, int residue, int status)
 {
 	UMASSHIST_FUNC(); UMASSHIST_CALLED();



CVS commit: [netbsd-9] src/sys/dev

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 17:25:48 UTC 2021

Modified Files:
src/sys/dev/ic [netbsd-9]: nvme.c nvmevar.h
src/sys/dev/pci [netbsd-9]: nvme_pci.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1305):

sys/dev/ic/nvmevar.h: revision 1.22
sys/dev/ic/nvme.c: revision 1.56
sys/dev/ic/nvme.c: revision 1.57
sys/dev/pci/nvme_pci.c: revision 1.30

nvme(4): Add suspend/resume, derived from OpenBSD.

nvme(4): Move disestablishment of admin q interrupt to nvme_detach.

Nothing re-established this after suspend/resume, so attempting
suspend/resume/suspend would crash, and presumably we would miss
interrupts after resume.  This keeps the establish/disestablish more
symmetric in attach/detach.


To generate a diff of this commit:
cvs rdiff -u -r1.44.2.5 -r1.44.2.6 src/sys/dev/ic/nvme.c
cvs rdiff -u -r1.20 -r1.20.2.1 src/sys/dev/ic/nvmevar.h
cvs rdiff -u -r1.26 -r1.26.4.1 src/sys/dev/pci/nvme_pci.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.44.2.5 src/sys/dev/ic/nvme.c:1.44.2.6
--- src/sys/dev/ic/nvme.c:1.44.2.5	Mon Dec  7 20:04:07 2020
+++ src/sys/dev/ic/nvme.c	Mon Jun 21 17:25:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.44.2.5 2020/12/07 20:04:07 martin Exp $	*/
+/*	$NetBSD: nvme.c,v 1.44.2.6 2021/06/21 17:25:48 martin Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.5 2020/12/07 20:04:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.6 2021/06/21 17:25:48 martin Exp $");
 
 #include 
 #include 
@@ -81,6 +81,7 @@ static void	nvme_empty_done(struct nvme_
 static struct nvme_queue *
 		nvme_q_alloc(struct nvme_softc *, uint16_t, u_int, u_int);
 static int	nvme_q_create(struct nvme_softc *, struct nvme_queue *);
+static void	nvme_q_reset(struct nvme_softc *, struct nvme_queue *);
 static int	nvme_q_delete(struct nvme_softc *, struct nvme_queue *);
 static void	nvme_q_submit(struct nvme_softc *, struct nvme_queue *,
 		struct nvme_ccb *, void (*)(struct nvme_queue *,
@@ -338,7 +339,6 @@ nvme_attach(struct nvme_softc *sc)
 {
 	uint64_t cap;
 	uint32_t reg;
-	u_int dstrd;
 	u_int mps = PAGE_SHIFT;
 	u_int ncq, nsq;
 	uint16_t adminq_entries = nvme_adminq_size;
@@ -359,7 +359,7 @@ nvme_attach(struct nvme_softc *sc)
 		NVME_VS_MNR(reg), NVME_VS_TER(reg));
 
 	cap = nvme_read8(sc, NVME_CAP);
-	dstrd = NVME_CAP_DSTRD(cap);
+	sc->sc_dstrd = NVME_CAP_DSTRD(cap);
 	if (NVME_CAP_MPSMIN(cap) > PAGE_SHIFT) {
 		aprint_error_dev(sc->sc_dev, "NVMe minimum page size %u "
 		"is greater than CPU page size %u\n",
@@ -382,7 +382,8 @@ nvme_attach(struct nvme_softc *sc)
 		return 1;
 	}
 
-	sc->sc_admin_q = nvme_q_alloc(sc, NVME_ADMIN_Q, adminq_entries, dstrd);
+	sc->sc_admin_q = nvme_q_alloc(sc, NVME_ADMIN_Q, adminq_entries,
+	sc->sc_dstrd);
 	if (sc->sc_admin_q == NULL) {
 		aprint_error_dev(sc->sc_dev,
 		"unable to allocate admin queue\n");
@@ -427,7 +428,8 @@ nvme_attach(struct nvme_softc *sc)
 
 	sc->sc_q = kmem_zalloc(sizeof(*sc->sc_q) * sc->sc_nq, KM_SLEEP);
 	for (i = 0; i < sc->sc_nq; i++) {
-		sc->sc_q[i] = nvme_q_alloc(sc, i + 1, ioq_entries, dstrd);
+		sc->sc_q[i] = nvme_q_alloc(sc, i + 1, ioq_entries,
+		sc->sc_dstrd);
 		if (sc->sc_q[i] == NULL) {
 			aprint_error_dev(sc->sc_dev,
 			"unable to allocate io queue\n");
@@ -550,6 +552,7 @@ nvme_detach(struct nvme_softc *sc, int f
 		return error;
 
 	/* from now on we are committed to detach, following will never fail */
+	sc->sc_intr_disestablish(sc, NVME_ADMIN_Q);
 	for (i = 0; i < sc->sc_nq; i++)
 		nvme_q_free(sc, sc->sc_q[i]);
 	kmem_free(sc->sc_q, sizeof(*sc->sc_q) * sc->sc_nq);
@@ -558,6 +561,68 @@ nvme_detach(struct nvme_softc *sc, int f
 	return 0;
 }
 
+int
+nvme_suspend(struct nvme_softc *sc)
+{
+
+	return nvme_shutdown(sc);
+}
+
+int
+nvme_resume(struct nvme_softc *sc)
+{
+	int ioq_entries = nvme_ioq_size;
+	uint64_t cap;
+	int i, error;
+
+	error = nvme_disable(sc);
+	if (error) {
+		device_printf(sc->sc_dev, "unable to disable controller\n");
+		return error;
+	}
+
+	nvme_q_reset(sc, sc->sc_admin_q);
+
+	error = nvme_enable(sc, ffs(sc->sc_mps) - 1);
+	if (error) {
+		device_printf(sc->sc_dev, "unable to enable controller\n");
+		return error;
+	}
+
+	for (i = 0; i < sc->sc_nq; i++) {
+		cap = nvme_read8(sc, NVME_CAP);
+		if (ioq_entries > NVME_CAP_MQES(cap))
+			ioq_entries = NVME_CAP_MQES(cap);
+		sc->sc_q[i] = nvme_q_alloc(sc, i + 1, ioq_entries,
+		sc->sc_dstrd);
+		if (sc->sc_q[i] == NULL) {
+			error = ENOMEM;
+			device_printf(sc->sc_dev, "unable to allocate io q %d"
+			"\n", i);
+			goto disable;
+		}
+		if (nvme_q_create(sc, sc->sc_q[i]) != 0) {
+			error = EIO;
+			device_printf(sc->sc_dev, "unable to create io q %d"
+			"\n", 

CVS commit: [netbsd-9] src/sys/dev

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 17:23:13 UTC 2021

Modified Files:
src/sys/dev [netbsd-9]: ld.c ldvar.h

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1304):

sys/dev/ldvar.h: revision 1.35
sys/dev/ld.c: revision 1.112

ld(4): Block requests while suspended until resumed.

Otherwise nothing stops us from continuing to feed I/O to the disk
controller when it expects that the queues are quiesced as it pokes
registers to change its power states.  Fixes resume during disk
activity on my T480 with nvme.


To generate a diff of this commit:
cvs rdiff -u -r1.106.4.2 -r1.106.4.3 src/sys/dev/ld.c
cvs rdiff -u -r1.33 -r1.33.4.1 src/sys/dev/ldvar.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/dev/ld.c
diff -u src/sys/dev/ld.c:1.106.4.2 src/sys/dev/ld.c:1.106.4.3
--- src/sys/dev/ld.c:1.106.4.2	Sat Mar 21 15:52:09 2020
+++ src/sys/dev/ld.c	Mon Jun 21 17:23:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld.c,v 1.106.4.2 2020/03/21 15:52:09 martin Exp $	*/
+/*	$NetBSD: ld.c,v 1.106.4.3 2021/06/21 17:23:13 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.106.4.2 2020/03/21 15:52:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.106.4.3 2021/06/21 17:23:13 martin Exp $");
 
 #include 
 #include 
@@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.106
 
 static void	ldminphys(struct buf *bp);
 static bool	ld_suspend(device_t, const pmf_qual_t *);
+static bool	ld_resume(device_t, const pmf_qual_t *);
 static bool	ld_shutdown(device_t, int);
 static int	ld_diskstart(device_t, struct buf *bp);
 static void	ld_iosize(device_t, int *);
@@ -160,7 +161,8 @@ ldattach(struct ld_softc *sc, const char
 	bufq_alloc(>sc_bufq, default_strategy, BUFQ_SORT_RAWBLOCK);
 
 	/* Register with PMF */
-	if (!pmf_device_register1(dksc->sc_dev, ld_suspend, NULL, ld_shutdown))
+	if (!pmf_device_register1(dksc->sc_dev, ld_suspend, ld_resume,
+		ld_shutdown))
 		aprint_error_dev(dksc->sc_dev,
 		"couldn't establish power handler\n");
 
@@ -266,7 +268,55 @@ ldenddetach(struct ld_softc *sc)
 static bool
 ld_suspend(device_t dev, const pmf_qual_t *qual)
 {
-	return ld_shutdown(dev, 0);
+	struct ld_softc *sc = device_private(dev);
+	int queuecnt;
+	bool ok = false;
+
+	/* Block new requests and wait for outstanding requests to drain.  */
+	mutex_enter(>sc_mutex);
+	KASSERT((sc->sc_flags & LDF_SUSPEND) == 0);
+	sc->sc_flags |= LDF_SUSPEND;
+	while ((queuecnt = sc->sc_queuecnt) > 0) {
+		if (cv_timedwait(>sc_drain, >sc_mutex, 30 * hz))
+			break;
+	}
+	mutex_exit(>sc_mutex);
+
+	/* Block suspend if we couldn't drain everything in 30sec.  */
+	if (queuecnt > 0) {
+		device_printf(dev, "timeout draining buffers\n");
+		goto out;
+	}
+
+	/* Flush cache before we lose power.  If we can't, block suspend.  */
+	if (ld_flush(dev, /*poll*/false) != 0) {
+		device_printf(dev, "failed to flush cache\n");
+		goto out;
+	}
+
+	/* Success!  */
+	ok = true;
+
+out:	if (!ok)
+		(void)ld_resume(dev, qual);
+	return ok;
+}
+
+static bool
+ld_resume(device_t dev, const pmf_qual_t *qual)
+{
+	struct ld_softc *sc = device_private(dev);
+
+	/* Allow new requests to come in.  */
+	mutex_enter(>sc_mutex);
+	KASSERT(sc->sc_flags & LDF_SUSPEND);
+	sc->sc_flags &= ~LDF_SUSPEND;
+	mutex_exit(>sc_mutex);
+
+	/* Restart any pending queued requests.  */
+	dk_start(>sc_dksc, NULL);
+
+	return true;
 }
 
 /* ARGSUSED */
@@ -428,17 +478,24 @@ ld_diskstart(device_t dev, struct buf *b
 	struct ld_softc *sc = device_private(dev);
 	int error;
 
-	if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
+	if (sc->sc_queuecnt >= sc->sc_maxqueuecnt ||
+	sc->sc_flags & LDF_SUSPEND) {
+		if (sc->sc_flags & LDF_SUSPEND)
+			aprint_debug_dev(dev, "i/o blocked while suspended\n");
 		return EAGAIN;
+	}
 
 	if ((sc->sc_flags & LDF_MPSAFE) == 0)
 		KERNEL_LOCK(1, curlwp);
 
 	mutex_enter(>sc_mutex);
 
-	if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
+	if (sc->sc_queuecnt >= sc->sc_maxqueuecnt ||
+	sc->sc_flags & LDF_SUSPEND) {
+		if (sc->sc_flags & LDF_SUSPEND)
+			aprint_debug_dev(dev, "i/o blocked while suspended\n");
 		error = EAGAIN;
-	else {
+	} else {
 		error = (*sc->sc_start)(sc, bp);
 		if (error == 0)
 			sc->sc_queuecnt++;

Index: src/sys/dev/ldvar.h
diff -u src/sys/dev/ldvar.h:1.33 src/sys/dev/ldvar.h:1.33.4.1
--- src/sys/dev/ldvar.h:1.33	Tue Mar 19 07:01:14 2019
+++ src/sys/dev/ldvar.h	Mon Jun 21 17:23:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ldvar.h,v 1.33 2019/03/19 07:01:14 mlelstv Exp $	*/
+/*	$NetBSD: ldvar.h,v 1.33.4.1 2021/06/21 17:23:13 martin Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -70,6 +70,7 @@ struct ld_softc {
 #define	LDF_DRAIN	0x020		/* maxqueuecnt has changed; drain */
 #define	LDF_NO_RND	0x040		/* do not attach rnd source */
 #define	LDF_MPSAFE	0x080		/* 

CVS commit: [netbsd-9] src/sys/dev/usb

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 17:15:38 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: ualea.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1302):

sys/dev/usb/ualea.c: revision 1.13

ualea(4): Null suspend/resume handler.


To generate a diff of this commit:
cvs rdiff -u -r1.9.10.2 -r1.9.10.3 src/sys/dev/usb/ualea.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/usb/ualea.c
diff -u src/sys/dev/usb/ualea.c:1.9.10.2 src/sys/dev/usb/ualea.c:1.9.10.3
--- src/sys/dev/usb/ualea.c:1.9.10.2	Wed Jul 15 13:52:05 2020
+++ src/sys/dev/usb/ualea.c	Mon Jun 21 17:15:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ualea.c,v 1.9.10.2 2020/07/15 13:52:05 martin Exp $	*/
+/*	$NetBSD: ualea.c,v 1.9.10.3 2021/06/21 17:15:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9.10.2 2020/07/15 13:52:05 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9.10.3 2021/06/21 17:15:38 martin Exp $");
 
 #include 
 #include 
@@ -144,6 +144,10 @@ ualea_attach(device_t parent, device_t s
 		return;
 	}
 
+	if (!pmf_device_register(self, NULL, NULL))
+		aprint_error_dev(sc->sc_dev, "failed to register power handler"
+		"\n");
+
 	/* Success!  We are ready to run.  */
 	mutex_enter(>sc_lock);
 	sc->sc_attached = true;



CVS commit: [netbsd-9] src/sys/dev/usb

2021-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jun 21 17:11:46 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: xhci.c xhcireg.h xhcivar.h

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1301):

sys/dev/usb/xhci.c: revision 1.140
sys/dev/usb/xhci.c: revision 1.141
sys/dev/usb/xhci.c: revision 1.143
sys/dev/usb/xhcivar.h: revision 1.18
sys/dev/usb/xhcivar.h: revision 1.19
sys/dev/usb/xhcireg.h: revision 1.19
sys/dev/usb/xhci.c: revision 1.139

xhci(4): Draft suspend/resume.

Work almost entirely done and tested by maya@ based on xhci 1.2 spec;
tidied up and tweaked by me.

Not sure about issuing Stop Endpoint commands or ensuring the Command
Ring is in the Stopped or Idle state, but this seems to work as is,
so it's already an improvement over what we had before which was no
xhci suspend/resume at all.

In particular, it's not clear to us:
- if we don't have any pending USB activity whether we need to issue
  the Stop Endpoints or quiesce the command ring; but
- if we do have any pending USB activity whether issuing Stop
  Endpoint is enough or whether we also need to do anything to
  synchronize with other software logic to quiesce it too.

xhci(4): Block commands and issue Stop Endpoint on suspend.

xhci: Fix logic in waiting for command queue access.
_Either_ an existing command in progress, _or_ an existing suspend in
progress that is not done by us, should block us; the logic I wrote
previously erroneously blocked only if both conditions happened at
the same time.

Should fix issue reported by Andrius V in the PR kern/56050 followup
discussion.

xhci(4): Wait USB_RESUME_WAIT ms, not 20 ms.
Better to use the named constant, and although the spec says 20 ms is
enough, apparently for some devices it's not.


To generate a diff of this commit:
cvs rdiff -u -r1.107.2.7 -r1.107.2.8 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.13 -r1.13.2.1 src/sys/dev/usb/xhcireg.h
cvs rdiff -u -r1.11 -r1.11.4.1 src/sys/dev/usb/xhcivar.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/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.107.2.7 src/sys/dev/usb/xhci.c:1.107.2.8
--- src/sys/dev/usb/xhci.c:1.107.2.7	Wed Dec 23 12:34:38 2020
+++ src/sys/dev/usb/xhci.c	Mon Jun 21 17:11:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.107.2.7 2020/12/23 12:34:38 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.107.2.8 2021/06/21 17:11:46 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.7 2020/12/23 12:34:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.8 2021/06/21 17:11:46 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -154,6 +154,8 @@ static int xhci_roothub_ctrl(struct usbd
 static usbd_status xhci_configure_endpoint(struct usbd_pipe *);
 //static usbd_status xhci_unconfigure_endpoint(struct usbd_pipe *);
 static usbd_status xhci_reset_endpoint(struct usbd_pipe *);
+static usbd_status xhci_stop_endpoint_cmd(struct xhci_softc *,
+struct xhci_slot *, u_int, uint32_t);
 static usbd_status xhci_stop_endpoint(struct usbd_pipe *);
 
 static void xhci_host_dequeue(struct xhci_ring * const);
@@ -369,7 +371,6 @@ xhci_rt_write_4(const struct xhci_softc 
 	bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value);
 }
 
-#if 0 /* unused */
 static inline uint64_t
 xhci_rt_read_8(const struct xhci_softc * const sc, bus_size_t offset)
 {
@@ -389,7 +390,6 @@ xhci_rt_read_8(const struct xhci_softc *
 
 	return value;
 }
-#endif /* unused */
 
 static inline void
 xhci_rt_write_8(const struct xhci_softc * const sc, bus_size_t offset,
@@ -678,15 +678,408 @@ xhci_activate(device_t self, enum devact
 }
 
 bool
-xhci_suspend(device_t dv, const pmf_qual_t *qual)
+xhci_suspend(device_t self, const pmf_qual_t *qual)
 {
-	return false;
+	struct xhci_softc * const sc = device_private(self);
+	size_t i, j, bn, dci;
+	int port;
+	uint32_t v;
+	usbd_status err;
+	bool ok = false;
+
+	XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
+	mutex_enter(>sc_lock);
+
+	/*
+	 * Block issuance of new commands, and wait for all pending
+	 * commands to complete.
+	 */
+	KASSERT(sc->sc_suspender == NULL);
+	sc->sc_suspender = curlwp;
+	while (sc->sc_command_addr != 0)
+		cv_wait(>sc_cmdbusy_cv, >sc_lock);
+
+	/*
+	 * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
+	 * xHCI Power Management, p. 342
+	 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
+	 */
+
+	/*
+	 * `1. Stop all USB activity by issuing Stop Endpoint Commands
+	 * for Busy endpoints in the Running state.  If the Force
+	 * Save Context Capability (FSC = ``0'') is not supported,
+	 * then Stop Endpoint Commands shall be issued for all idle
+	 * endpoints in the Running 

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

2021-06-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jun  5 10:51:41 UTC 2021

Modified Files:
src/sys/dev/pci [netbsd-9]: if_iwmreg.h

Log Message:
Pull up following revision(s) (requested by nia in ticket #1282):

sys/dev/pci/if_iwmreg.h: revision 1.8

Can't left shift a signed int by 31. Found by kubsan.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.8.1 src/sys/dev/pci/if_iwmreg.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/dev/pci/if_iwmreg.h
diff -u src/sys/dev/pci/if_iwmreg.h:1.7 src/sys/dev/pci/if_iwmreg.h:1.7.8.1
--- src/sys/dev/pci/if_iwmreg.h:1.7	Thu Apr 19 21:50:09 2018
+++ src/sys/dev/pci/if_iwmreg.h	Sat Jun  5 10:51:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_iwmreg.h,v 1.7 2018/04/19 21:50:09 christos Exp $	*/
+/*	$NetBSD: if_iwmreg.h,v 1.7.8.1 2021/06/05 10:51:41 martin Exp $	*/
 /*	OpenBSD: if_iwmreg.h,v 1.19 2016/09/20 11:46:09 stsp Exp 	*/
 
 /*-
@@ -191,7 +191,7 @@
 
 /* interrupt flags in INTA, set by uCode or hardware (e.g. dma),
  * acknowledged (reset) by host writing "1" to flagged bits. */
-#define IWM_CSR_INT_BIT_FH_RX	(1 << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */
+#define IWM_CSR_INT_BIT_FH_RX	(1U << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */
 #define IWM_CSR_INT_BIT_HW_ERR	(1 << 29) /* DMA hardware error FH_INT[31] */
 #define IWM_CSR_INT_BIT_RX_PERIODIC	(1 << 28) /* Rx periodic */
 #define IWM_CSR_INT_BIT_FH_TX	(1 << 27) /* Tx DMA FH_INT[1:0] */
@@ -214,7 +214,7 @@
  IWM_CSR_INT_BIT_RX_PERIODIC)
 
 /* interrupt flags in FH (flow handler) (PCI busmaster DMA) */
-#define IWM_CSR_FH_INT_BIT_ERR   (1 << 31) /* Error */
+#define IWM_CSR_FH_INT_BIT_ERR   (1U << 31) /* Error */
 #define IWM_CSR_FH_INT_BIT_HI_PRIOR  (1 << 30) /* High priority Rx, bypass coalescing */
 #define IWM_CSR_FH_INT_BIT_RX_CHNL1  (1 << 17) /* Rx channel 1 */
 #define IWM_CSR_FH_INT_BIT_RX_CHNL0  (1 << 16) /* Rx channel 0 */
@@ -405,7 +405,7 @@
 #define IWM_CSR_DBG_HPET_MEM_REG_VAL	(0x)
 
 /* DRAM INT TABLE */
-#define IWM_CSR_DRAM_INT_TBL_ENABLE		(1 << 31)
+#define IWM_CSR_DRAM_INT_TBL_ENABLE		(1U << 31)
 #define IWM_CSR_DRAM_INIT_TBL_WRITE_POINTER	(1 << 28)
 #define IWM_CSR_DRAM_INIT_TBL_WRAP_CHECK	(1 << 27)
 
@@ -558,7 +558,7 @@ enum iwm_secure_load_status_reg {
 #define IWM_HOST_INT_TIMEOUT_MAX	(0xFF)
 #define IWM_HOST_INT_TIMEOUT_DEF	(0x40)
 #define IWM_HOST_INT_TIMEOUT_MIN	(0x0)
-#define IWM_HOST_INT_OPER_MODE		(1 << 31)
+#define IWM_HOST_INT_OPER_MODE		(1U << 31)
 
 /*
  *7000/3000 series SHR DTS addresses *
@@ -643,7 +643,7 @@ enum iwm_ucode_tlv_flag {
 	IWM_UCODE_TLV_FLAGS_P2P_PS_UAPSD	= (1 << 26),
 	IWM_UCODE_TLV_FLAGS_BCAST_FILTERING	= (1 << 29),
 	IWM_UCODE_TLV_FLAGS_GO_UAPSD		= (1 << 30),
-	IWM_UCODE_TLV_FLAGS_LTE_COEX		= (1 << 31),
+	IWM_UCODE_TLV_FLAGS_LTE_COEX		= (1U << 31),
 };
 #define IWM_UCODE_TLV_FLAG_BITS \
 	"\020\1PAN\2NEWSCAN\3MFP\4P2P\5DW_BC_TABLE\6NEWBT_COEX\7PM_CMD\10SHORT_BL\11RX_ENERGY\12TIME_EVENT_V2\13D3_6_IPV6\14BF_UPDATED\15NO_BASIC_SSID\17D3_CONTINUITY\20NEW_NSOFFL_S\21NEW_NSOFFL_L\22SCHED_SCAN\24STA_KEY_CMD\25DEVICE_PS_CMD\26P2P_PS\27P2P_PS_DCM\30P2P_PS_SCM\31UAPSD_SUPPORT\32EBS\33P2P_PS_UAPSD\36BCAST_FILTERING\37GO_UAPSD\40LTE_COEX"
@@ -4369,7 +4369,7 @@ enum iwm_tx_flags {
 	IWM_TX_CMD_FLG_FW_DROP		= (1 << 26),
 	IWM_TX_CMD_FLG_EXEC_PAPD	= (1 << 27),
 	IWM_TX_CMD_FLG_PAPD_TYPE	= (1 << 28),
-	IWM_TX_CMD_FLG_HCCA_CHUNK	= (1 << 31)
+	IWM_TX_CMD_FLG_HCCA_CHUNK	= (1U << 31)
 }; /* IWM_TX_FLAGS_BITS_API_S_VER_1 */
 
 /**



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

2021-05-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 17 15:50:35 UTC 2021

Modified Files:
src/sys/dev/pci [netbsd-9]: xhci_pci.c

Log Message:
Pull up following revision(s) (requested by jakllsch in ticket #1273):

sys/dev/pci/xhci_pci.c: revision 1.26

xhci_pci: avoid potential double free of interrupt handles

Found by Kouichi Hashikawa in PR 55855.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.4.1 src/sys/dev/pci/xhci_pci.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/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.21 src/sys/dev/pci/xhci_pci.c:1.21.4.1
--- src/sys/dev/pci/xhci_pci.c:1.21	Wed Jan 23 06:56:19 2019
+++ src/sys/dev/pci/xhci_pci.c	Mon May 17 15:50:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci_pci.c,v 1.21 2019/01/23 06:56:19 msaitoh Exp $	*/
+/*	$NetBSD: xhci_pci.c,v 1.21.4.1 2021/05/17 15:50:35 martin Exp $	*/
 /*	OpenBSD: xhci_pci.c,v 1.4 2014/07/12 17:38:51 yuo Exp	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.21 2019/01/23 06:56:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.21.4.1 2021/05/17 15:50:35 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xhci_pci.h"
@@ -213,7 +213,7 @@ xhci_pci_attach(device_t parent, device_
 	xhci_intr, sc, device_xname(sc->sc_dev));
 	if (psc->sc_ih == NULL) {
 		pci_intr_release(pc, psc->sc_pihp, 1);
-		psc->sc_ih = NULL;
+		psc->sc_pihp = NULL;
 		aprint_error_dev(self, "couldn't establish interrupt");
 		if (intrstr != NULL)
 			aprint_error(" at %s", intrstr);



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

2021-05-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May  9 07:09:27 UTC 2021

Modified Files:
src/sys/dev/pci [netbsd-9]: siisata_pci.c

Log Message:
Pull up following revision(s) (requested by dolecek in ticket #1270):

sys/dev/pci/siisata_pci.c: revision 1.21

disable MSI for SiI3124 - interrupts don't seem to work on this old board
when MSI is enabled, maybe because it's behind a PCI bridge

PR kern/55115 by John D. Baker


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.20.4.1 src/sys/dev/pci/siisata_pci.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/siisata_pci.c
diff -u src/sys/dev/pci/siisata_pci.c:1.20 src/sys/dev/pci/siisata_pci.c:1.20.4.1
--- src/sys/dev/pci/siisata_pci.c:1.20	Thu Oct 25 21:03:19 2018
+++ src/sys/dev/pci/siisata_pci.c	Sun May  9 07:09:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata_pci.c,v 1.20 2018/10/25 21:03:19 jdolecek Exp $ */
+/* $NetBSD: siisata_pci.c,v 1.20.4.1 2021/05/09 07:09:27 martin Exp $ */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -51,7 +51,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata_pci.c,v 1.20 2018/10/25 21:03:19 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata_pci.c,v 1.20.4.1 2021/05/09 07:09:27 martin Exp $");
 
 #include 
 #include 
@@ -82,14 +82,22 @@ struct siisata_pci_board {
 	pci_product_id_t	spb_prod;
 	uint16_t		spb_port;
 	uint16_t		spb_chip;
+	uint8_t			sbp_flags;
 };
 
+#define SIISATA_BROKEN_MSI		0x01
+
 static const struct siisata_pci_board siisata_pci_boards[] = {
 	{
 		.spb_vend = PCI_VENDOR_CMDTECH,
 		.spb_prod = PCI_PRODUCT_CMDTECH_3124,
 		.spb_port = 4,
 		.spb_chip = 3124,
+		/*
+		 * SiI3124 seems to be PCI/PCI-X chip behind PCI-e bridge,
+		 * claims MSI support but interrups don't work with MSI on.
+		 */
+		.sbp_flags = SIISATA_BROKEN_MSI,
 	},
 	{
 		.spb_vend = PCI_VENDOR_CMDTECH,
@@ -157,6 +165,9 @@ siisata_pci_attach(device_t parent, devi
 	bus_size_t grsize, prsize;
 	char intrbuf[PCI_INTRSTR_LEN];
 
+	spbp = siisata_pci_lookup(pa);
+	KASSERT(spbp != NULL);
+
 	sc->sc_atac.atac_dev = self;
 
 	psc->sc_pc = pa->pa_pc;
@@ -210,8 +221,19 @@ siisata_pci_attach(device_t parent, devi
 	else
 		sc->sc_dmat = pa->pa_dmat;
 
+	int counts[PCI_INTR_TYPE_SIZE] = {
+ 		[PCI_INTR_TYPE_INTX] = 1,
+ 		[PCI_INTR_TYPE_MSI] = 1,
+ 		[PCI_INTR_TYPE_MSIX] = 1,
+ 	};
+	int max_type = PCI_INTR_TYPE_MSIX;
+
+	if (spbp->sbp_flags & SIISATA_BROKEN_MSI) {
+		max_type = PCI_INTR_TYPE_INTX;
+	}
+
 	/* map interrupt */
-	if (pci_intr_alloc(pa, >sc_pihp, NULL, 0) != 0) {
+	if (pci_intr_alloc(pa, >sc_pihp, counts, max_type) != 0) {
 		bus_space_unmap(sc->sc_grt, sc->sc_grh, grsize);
 		bus_space_unmap(sc->sc_prt, sc->sc_prh, prsize);
 		aprint_error_dev(self, "couldn't map interrupt\n");
@@ -235,8 +257,6 @@ siisata_pci_attach(device_t parent, devi
 		intrstr ? intrstr : "unknown interrupt");
 
 	/* fill in number of ports on this device */
-	spbp = siisata_pci_lookup(pa);
-	KASSERT(spbp != NULL);
 	sc->sc_atac.atac_nchannels = spbp->spb_port;
 
 	/* set the necessary bits in case the firmware didn't */



CVS commit: [netbsd-9] src/sys/dev/audio

2021-05-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed May  5 17:01:41 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by nia in ticket #1268):

sys/dev/audio/audio.c: revision 1.95

audio: Only score hardware formats by channel count at count<=2

Scoring by channel count makes sense when you are using hardware that
supports mono and stereo formats. However, if your hardware also supports
surround formats, defaulting to those might be confusing. So, don't
prefer them.

Problem reported and fix tested by tcmart14 with a 2015 model Macbook Pro.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.21 -r1.28.2.22 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.21 src/sys/dev/audio/audio.c:1.28.2.22
--- src/sys/dev/audio/audio.c:1.28.2.21	Mon Mar  1 16:00:08 2021
+++ src/sys/dev/audio/audio.c	Wed May  5 17:01:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.22 2021/05/05 17:01:41 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -6566,7 +6566,10 @@ audio_hw_probe(struct audio_softc *sc, a
 		query.fmt.precision == AUDIO_INTERNAL_BITS) {
 			score += 0x10;
 		}
-		score += query.fmt.channels;
+
+		/* Do not prefer surround formats */
+		if (query.fmt.channels <= 2)
+			score += query.fmt.channels;
 
 		if (score < cand_score) {
 			DPRINTF(1, "fmt[%d] skip; score 0x%x < 0x%x\n", i,



CVS commit: [netbsd-9] src/sys/dev/audio

2021-04-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr  6 17:44:29 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audiobell.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1241):

sys/dev/audio/audiobell.c: revision 1.4

Fix and improve the buffer length calculation to avoid zero length
even if blk_ms is small.

This fixes PR kern/56059.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.2.1 src/sys/dev/audio/audiobell.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/audio/audiobell.c
diff -u src/sys/dev/audio/audiobell.c:1.3 src/sys/dev/audio/audiobell.c:1.3.2.1
--- src/sys/dev/audio/audiobell.c:1.3	Wed Jun 26 06:57:45 2019
+++ src/sys/dev/audio/audiobell.c	Tue Apr  6 17:44:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $	*/
+/*	$NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $	*/
 
 /*
  * Copyright (c) 1999 Richard Earnshaw
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3 2019/06/26 06:57:45 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audiobell.c,v 1.3.2.1 2021/04/06 17:44:29 martin Exp $");
 
 #include 
 #include 
@@ -81,6 +81,13 @@ static const int32_t sinewave[] = {
 #undef A
 
 /*
+ * The minimum and the maximum buffer sizes must be a multiple of 32
+ * (32 = countof(sinewave) * sizeof(uint16_t)).
+ */
+#define MINBUFSIZE	(1024)
+#define MAXBUFSIZE	(4096)
+
+/*
  * dev is a device_t for the audio device to use.
  * pitch is the pitch of the bell in Hz,
  * period is the length in ms,
@@ -102,7 +109,7 @@ audiobell(void *dev, u_int pitch, u_int 
 	u_int remainbytes;
 	u_int wave1count;
 	u_int wave1bytes;
-	u_int blkbytes;
+	u_int bufbytes;
 	u_int len;
 	u_int step;
 	u_int offset;
@@ -111,6 +118,10 @@ audiobell(void *dev, u_int pitch, u_int 
 
 	KASSERT(volume <= 100);
 
+	/* Playing for 0msec does nothing. */
+	if (period == 0)
+		return;
+
 	/* The audio system isn't built for polling. */
 	if (poll)
 		return;
@@ -158,16 +169,23 @@ audiobell(void *dev, u_int pitch, u_int 
 	remainbytes = remaincount * sizeof(int16_t);
 	wave1bytes = wave1count * sizeof(int16_t);
 
-	blkbytes = ptrack->usrbuf_blksize;
-	blkbytes = rounddown(blkbytes, wave1bytes);
-	blkbytes = uimin(blkbytes, remainbytes);
-	buf = malloc(blkbytes, M_TEMP, M_WAITOK);
+	/* Based on 3*usrbuf_blksize, but not too small or too large */
+	bufbytes = ptrack->usrbuf_blksize * NBLKHW;
+	if (bufbytes < MINBUFSIZE)
+		bufbytes = MINBUFSIZE;
+	else if (bufbytes > MAXBUFSIZE)
+		bufbytes = MAXBUFSIZE;
+	else
+		bufbytes = roundup(bufbytes, wave1bytes);
+	bufbytes = uimin(bufbytes, remainbytes);
+	KASSERT(bufbytes != 0);
+	buf = malloc(bufbytes, M_TEMP, M_WAITOK);
 	if (buf == NULL)
 		goto out;
 
 	/* Generate sinewave with specified volume */
 	j = offset;
-	for (i = 0; i < blkbytes / sizeof(int16_t); i++) {
+	for (i = 0; i < bufbytes / sizeof(int16_t); i++) {
 		/* XXX audio already has track volume feature though #if 0 */
 		buf[i] = AUDIO_SCALEDOWN(sinewave[j] * (int)volume, 16);
 		j += step;
@@ -177,7 +195,7 @@ audiobell(void *dev, u_int pitch, u_int 
 	/* Write while paused to avoid inserting silence. */
 	ptrack->is_pause = true;
 	for (; remainbytes > 0; remainbytes -= len) {
-		len = uimin(remainbytes, blkbytes);
+		len = uimin(remainbytes, bufbytes);
 		aiov.iov_base = (void *)buf;
 		aiov.iov_len = len;
 		auio.uio_iov = 



CVS commit: [netbsd-9] src/sys/dev/usb

2021-03-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 27 13:02:00 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: usbdevs.h usbdevs_data.h

Log Message:
regen for ticket #1236 (BELKIN F5D7050E fix)


To generate a diff of this commit:
cvs rdiff -u -r1.760.4.7 -r1.760.4.8 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/dev/usb/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.760.4.7 src/sys/dev/usb/usbdevs.h:1.760.4.8
--- src/sys/dev/usb/usbdevs.h:1.760.4.7	Thu Feb  4 19:23:59 2021
+++ src/sys/dev/usb/usbdevs.h	Sat Mar 27 13:01:58 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.760.4.7 2021/02/04 19:23:59 martin Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.760.4.8 2021/03/27 13:01:58 martin Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp
+ *	NetBSD: usbdevs,v 1.770.4.8 2021/03/27 13:00:45 martin Exp
  */
 
 /*-
@@ -1086,7 +1086,7 @@
 #define	USB_PRODUCT_BELKIN_F5D7051	0x7051		/* F5D7051 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_F5D7050A	0x705a		/* F5D705A 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_F5D7050C	0x705c		/* F5D705C 54g USB Network Adapter */
-#define	USB_PRODUCT_BELKIN_F5D7050E	0x705c		/* F5D705E 54g USB Network Adapter */
+#define	USB_PRODUCT_BELKIN_F5D7050E	0x705e		/* F5D705E 54g USB Network Adapter */
 #define	USB_PRODUCT_BELKIN_RT2870_1	0x8053		/* RT2870 */
 #define	USB_PRODUCT_BELKIN_RT2870_2	0x805c		/* RT2870 */
 #define	USB_PRODUCT_BELKIN_F5D8053V3	0x815c		/* F5D8053 v3 */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.760.4.7 src/sys/dev/usb/usbdevs_data.h:1.760.4.8
--- src/sys/dev/usb/usbdevs_data.h:1.760.4.7	Thu Feb  4 19:23:59 2021
+++ src/sys/dev/usb/usbdevs_data.h	Sat Mar 27 13:01:58 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.760.4.7 2021/02/04 19:23:59 martin Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.760.4.8 2021/03/27 13:01:58 martin Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp
+ *	NetBSD: usbdevs,v 1.770.4.8 2021/03/27 13:00:45 martin Exp
  */
 
 /*-



CVS commit: [netbsd-9] src/sys/dev/usb

2021-03-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 27 13:00:45 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: usbdevs

Log Message:
Pull up following revision(s) (requested by nia in ticket #1236):

sys/dev/usb/usbdevs: revision 1.793

correct usb device id for BELKIN F5D7050E

matches freebsd / openbsd (sources of urtw driver), various online
sources

PR kern/56056


To generate a diff of this commit:
cvs rdiff -u -r1.770.4.7 -r1.770.4.8 src/sys/dev/usb/usbdevs

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/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.770.4.7 src/sys/dev/usb/usbdevs:1.770.4.8
--- src/sys/dev/usb/usbdevs:1.770.4.7	Thu Feb  4 19:23:10 2021
+++ src/sys/dev/usb/usbdevs	Sat Mar 27 13:00:45 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp $
+$NetBSD: usbdevs,v 1.770.4.8 2021/03/27 13:00:45 martin Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1079,7 +1079,7 @@ product BELKIN F5D7050		0x7050	F5D7050 5
 product BELKIN F5D7051		0x7051	F5D7051 54g USB Network Adapter
 product BELKIN F5D7050A		0x705a	F5D705A 54g USB Network Adapter
 product BELKIN F5D7050C		0x705c	F5D705C 54g USB Network Adapter
-product BELKIN F5D7050E		0x705c	F5D705E 54g USB Network Adapter
+product BELKIN F5D7050E		0x705e	F5D705E 54g USB Network Adapter
 product BELKIN RT2870_1		0x8053	RT2870
 product BELKIN RT2870_2		0x805c	RT2870
 product BELKIN F5D8053V3	0x815c	F5D8053 v3



CVS commit: [netbsd-9] src/sys/dev/usb

2021-03-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar 22 18:20:38 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: if_urtwn.c

Log Message:
Pull up following revision(s) (requested by nat in ticket #1234),
all via patch:

sys/dev/usb/if_urtwn.c: revision 1.93
sys/dev/usb/if_urtwn.c: revision 1.95
sys/dev/usb/if_urtwn.c: revision 1.96

if_urtwn.c: Plug a few leaks
Can be a cause of PR/55968

Also free assocated mbufs.

OppsRemove irrelavent debug code and don't free_m before IFQ_DEQUEUE().
Identified and reported by Patrick Welche and remedy found by Martin Husemann.


To generate a diff of this commit:
cvs rdiff -u -r1.71.2.4 -r1.71.2.5 src/sys/dev/usb/if_urtwn.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/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.71.2.4 src/sys/dev/usb/if_urtwn.c:1.71.2.5
--- src/sys/dev/usb/if_urtwn.c:1.71.2.4	Thu Feb  4 19:23:10 2021
+++ src/sys/dev/usb/if_urtwn.c	Mon Mar 22 18:20:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.71.2.4 2021/02/04 19:23:10 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.71.2.5 2021/03/22 18:20:38 martin Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.71.2.4 2021/02/04 19:23:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.71.2.5 2021/03/22 18:20:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2563,6 +2563,17 @@ urtwn_rxeof(struct usbd_xfer *xfer, void
 }
 
 static void
+urtwn_put_tx_data(struct urtwn_softc *sc, struct urtwn_tx_data *data)
+{
+	size_t pidx = data->pidx;
+
+	mutex_enter(>sc_tx_mtx);
+	/* Put this Tx buffer back to our free list. */
+	TAILQ_INSERT_TAIL(>tx_free_list[pidx], data, next);
+	mutex_exit(>sc_tx_mtx);
+}
+
+static void
 urtwn_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
 	struct urtwn_tx_data *data = priv;
@@ -2574,10 +2585,7 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 	DPRINTFN(DBG_FN|DBG_TX, ("%s: %s: status=%d\n",
 	device_xname(sc->sc_dev), __func__, status));
 
-	mutex_enter(>sc_tx_mtx);
-	/* Put this Tx buffer back to our free list. */
-	TAILQ_INSERT_TAIL(>tx_free_list[pidx], data, next);
-	mutex_exit(>sc_tx_mtx);
+	urtwn_put_tx_data(sc, data);
 
 	s = splnet();
 	sc->tx_timer = 0;
@@ -2626,8 +2634,11 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 
 	if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
 		k = ieee80211_crypto_encap(ic, ni, m);
-		if (k == NULL)
+		if (k == NULL) {
+			urtwn_put_tx_data(sc, data);
+			m_free(m);
 			return ENOBUFS;
+		}
 
 		/* packet header may have moved, reset our local pointer */
 		wh = mtod(m, struct ieee80211_frame *);
@@ -2890,14 +2901,17 @@ urtwn_start(struct ifnet *ifp)
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
 			printf("ERROR6\n");
 			ifp->if_oerrors++;
+			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
 		ni = ieee80211_find_txnode(ic, eh->ether_dhost);
 		if (ni == NULL) {
-			m_freem(m);
 			printf("ERROR5\n");
 			ifp->if_oerrors++;
+			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 
@@ -2907,6 +2921,8 @@ urtwn_start(struct ifnet *ifp)
 			ieee80211_free_node(ni);
 			printf("ERROR4\n");
 			ifp->if_oerrors++;
+			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
  sendit:



CVS commit: [netbsd-9] src/sys/dev/ic

2021-03-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  9 15:47:07 UTC 2021

Modified Files:
src/sys/dev/ic [netbsd-9]: mb89352.c

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1228):

sys/dev/ic/mb89352.c: revision 1.58

Fix a possible race condition in spc_msgin() in NO_MANUAL_XFER case.

To avoid the race, check SSTS and INTS after XFR command as
spc_pio_datain() does.

Reported from isaki@, observed on nono emulator.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.57.4.1 src/sys/dev/ic/mb89352.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/ic/mb89352.c
diff -u src/sys/dev/ic/mb89352.c:1.57 src/sys/dev/ic/mb89352.c:1.57.4.1
--- src/sys/dev/ic/mb89352.c:1.57	Mon Sep  3 16:29:31 2018
+++ src/sys/dev/ic/mb89352.c	Tue Mar  9 15:47:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $	*/
+/*	$NetBSD: mb89352.c,v 1.57.4.1 2021/03/09 15:47:07 martin Exp $	*/
 /*	NecBSD: mb89352.c,v 1.4 1998/03/14 07:31:20 kmatsuda Exp	*/
 
 /*-
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.57.4.1 2021/03/09 15:47:07 martin Exp $");
 
 #ifdef DDB
 #define	integrate
@@ -932,6 +932,7 @@ nextbyte:
 	 */
 	for (;;) {
 #ifdef NO_MANUAL_XFER /* XXX */
+		uint8_t intstat;
 		if (bus_space_read_1(iot, ioh, INTS) != 0) {
 			/*
 			 * Target left MESSAGE IN, probably because it
@@ -960,12 +961,18 @@ nextbyte:
 #else
 		bus_space_write_1(iot, ioh, SCMD, SCMD_XFR | SCMD_PROG_XFR);
 #endif
+		intstat = 0;
 		for (;;) {
 			if ((bus_space_read_1(iot, ioh, SSTS) &
 			SSTS_DREG_EMPTY) == 0)
 break;
-			if (bus_space_read_1(iot, ioh, INTS) != 0)
+			/*
+			 * We have to read INTS before checking SSTS to avoid
+			 * race between SSTS_DREG_EMPTY and INTS_CMD_DONE.
+			 */
+			if (intstat != 0)
 goto out;
+			intstat = bus_space_read_1(iot, ioh, INTS);
 		}
 		msg = bus_space_read_1(iot, ioh, DREG);
 #else



CVS commit: [netbsd-9] src/sys/dev/usb

2021-03-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar  7 18:43:25 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: uaudio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1225):

sys/dev/usb/uaudio.c: revision 1.169

Fix my copy-and-paste bug in rev1.160.

This fixes recording sample dropout.


To generate a diff of this commit:
cvs rdiff -u -r1.161.2.1 -r1.161.2.2 src/sys/dev/usb/uaudio.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/usb/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.161.2.1 src/sys/dev/usb/uaudio.c:1.161.2.2
--- src/sys/dev/usb/uaudio.c:1.161.2.1	Tue Nov 19 12:56:48 2019
+++ src/sys/dev/usb/uaudio.c	Sun Mar  7 18:43:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.161.2.1 2019/11/19 12:56:48 martin Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.161.2.2 2021/03/07 18:43:25 martin Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.161.2.1 2019/11/19 12:56:48 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.161.2.2 2021/03/07 18:43:25 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3003,7 +3003,8 @@ uaudio_set_format(void *addr, int setmod
 		raltidx = audio_indexof_format(sc->sc_formats, sc->sc_nformats,
 		AUMODE_RECORD, rec);
 		/* Transfer should have halted */
-		uaudio_chan_init(>sc_recchan, raltidx, rec, 0);
+		uaudio_chan_init(>sc_recchan, raltidx, rec,
+		UGETW(sc->sc_alts[raltidx].edesc->wMaxPacketSize));
 	}
 
 	if ((setmode & AUMODE_PLAY) && sc->sc_playchan.altidx != -1) {



CVS commit: [netbsd-9] src/sys/dev/audio

2021-03-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Mar  1 16:00:08 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1219):

sys/dev/audio/audio.c: revision 1.89
sys/dev/audio/audio.c: revision 1.90
sys/dev/audio/audio.c: revision 1.91

Change the lock conditions to call audio_unlink().

This can remove a different copy of audio_exlock_enter() in audio_unlink()
and can use normal one.  Also, in audiodetach(), this can set the exlock
at more natual order (before calling audio_unlink()).

No noticeable functional changes are intended.
Thanks for comments, riastradh@.

Protect also audioopen() and audiobellopen() from audiodetach() with
psref(9), as well as others(audioread, audiowrite, etc..).
- Rename audio_file_enter to audio_sc_acquire_fromfile, audio_file_exit
  to audio_sc_release, for clarify.  These are the reference counter for
  this sc.
- Introduce audio_sc_acquire_foropen for audio{,bell}open.
- audio_open needs to examine sc_dying again before inserting it into
  sc_files, in order to keep sc_files consistency.

The race between audiodetach and audioopen is pointed out by riastradh@.
Thank you for many advices.

Add missing curlwp_bindx() corresponding to curlwp_bind().
Pointed out by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.20 -r1.28.2.21 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.20 src/sys/dev/audio/audio.c:1.28.2.21
--- src/sys/dev/audio/audio.c:1.28.2.20	Sun Feb 28 07:07:38 2021
+++ src/sys/dev/audio/audio.c	Mon Mar  1 16:00:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.21 2021/03/01 16:00:08 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -524,8 +524,10 @@ static int audio_exlock_mutex_enter(stru
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
 static void audio_exlock_exit(struct audio_softc *);
-static struct audio_softc *audio_file_enter(audio_file_t *, struct psref *);
-static void audio_file_exit(struct audio_softc *, struct psref *);
+static void audio_sc_acquire_foropen(struct audio_softc *, struct psref *);
+static struct audio_softc *audio_sc_acquire_fromfile(audio_file_t *,
+	struct psref *);
+static void audio_sc_release(struct audio_softc *, struct psref *);
 static int audio_track_waitio(struct audio_softc *, audio_track_t *);
 
 static int audioclose(struct file *);
@@ -1295,7 +1297,10 @@ audiodetach(device_t self, int flags)
 	if (error)
 		return error;
 
-	/* delete sysctl nodes */
+	/*
+	 * This waits currently running sysctls to finish if exists.
+	 * After this, no more new sysctls will come.
+	 */
 	sysctl_teardown(>sc_log);
 
 	mutex_enter(sc->sc_lock);
@@ -1327,9 +1332,10 @@ audiodetach(device_t self, int flags)
 	 * that hold sc, and any new calls with files that were for sc will
 	 * fail.  Thus, we now have exclusive access to the softc.
 	 */
+	sc->sc_exlock = 1;
 
 	/*
-	 * Nuke all open instances.
+	 * Clean up all open instances.
 	 * Here, we no longer need any locks to traverse sc_files.
 	 */
 	while ((file = SLIST_FIRST(>sc_files)) != NULL) {
@@ -1352,7 +1358,6 @@ audiodetach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	/* Free resources */
-	sc->sc_exlock = 1;
 	if (sc->sc_pmixer) {
 		audio_mixer_destroy(sc, sc->sc_pmixer);
 		kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));
@@ -1524,18 +1529,41 @@ audio_exlock_exit(struct audio_softc *sc
 }
 
 /*
- * Acquire sc from file, and increment the psref count.
+ * Increment reference counter for this sc.
+ * This is intended to be used for open.
+ */
+void
+audio_sc_acquire_foropen(struct audio_softc *sc, struct psref *refp)
+{
+	int s;
+
+	/* Block audiodetach while we acquire a reference */
+	s = pserialize_read_enter();
+
+	/*
+	 * We don't examine sc_dying here.  However, all open methods
+	 * call audio_exlock_enter() right after this, so we can examine
+	 * sc_dying in it.
+	 */
+
+	/* Acquire a reference */
+	psref_acquire(refp, >sc_psref, audio_psref_class);
+
+	/* Now sc won't go away until we drop the reference count */
+	pserialize_read_exit(s);
+}
+
+/*
+ * Get sc from file, and increment reference counter for this sc.
+ * This is intended to be used for methods other than open.
  * If successful, returns sc.  Otherwise returns NULL.
  */
 struct audio_softc *
-audio_file_enter(audio_file_t *file, struct psref *refp)

CVS commit: [netbsd-9] src/sys/dev/audio

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:07:38 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1218):

sys/dev/audio/audio.c: revision 1.84

Fix a return value of audiopoll().
fo_poll is expected to return revents rather than errno on error.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.19 -r1.28.2.20 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.19 src/sys/dev/audio/audio.c:1.28.2.20
--- src/sys/dev/audio/audio.c:1.28.2.19	Sun Feb 28 07:05:14 2021
+++ src/sys/dev/audio/audio.c	Sun Feb 28 07:07:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.20 2021/02/28 07:07:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1885,7 +1885,7 @@ audiopoll(struct file *fp, int events)
 
 	sc = audio_file_enter(file, _ref);
 	if (sc == NULL)
-		return EIO;
+		return POLLERR;
 
 	switch (AUDIODEV(dev)) {
 	case SOUND_DEVICE:



CVS commit: [netbsd-9] src/sys/dev/audio

2021-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Feb 28 07:05:14 UTC 2021

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1217):

sys/dev/audio/audio.c: revision 1.46
sys/dev/audio/audio.c: revision 1.82
sys/dev/audio/audio.c: revision 1.85
sys/dev/audio/audio.c: revision 1.87
sys/dev/audio/audio.c: revision 1.88

Change two aprint_error_dev() to device_printf() (and improve messages).
This is also called from other than boot.

Add missing newline.

Revise comments.

Change (harmless) zero-length debug messages.
sys/modules is compiled with -Wzero-length-format and this
makes sys/modules compilable even if AUDIO_DEBUG is defined.

Improve error messages.
- prefix MD device name if it's considered to be related to the MD driver.
- revise some messages.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.18 -r1.28.2.19 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.18 src/sys/dev/audio/audio.c:1.28.2.19
--- src/sys/dev/audio/audio.c:1.28.2.18	Sat Dec 19 13:54:56 2020
+++ src/sys/dev/audio/audio.c	Sun Feb 28 07:05:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.19 2021/02/28 07:05:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -518,6 +518,8 @@ static void audio_mixer_restore(struct a
 static void audio_softintr_rd(void *);
 static void audio_softintr_wr(void *);
 
+static void audio_printf(struct audio_softc *, const char *, ...)
+	__printflike(2, 3);
 static int audio_exlock_mutex_enter(struct audio_softc *);
 static void audio_exlock_mutex_exit(struct audio_softc *);
 static int audio_exlock_enter(struct audio_softc *);
@@ -965,19 +967,20 @@ audioattach(device_t parent, device_t se
 		perror = audio_hw_probe(sc, , AUMODE_PLAY);
 		rerror = audio_hw_probe(sc, , AUMODE_RECORD);
 		if (perror && rerror) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			"perror = %d, rerror = %d\n", perror, rerror);
+			aprint_error_dev(self,
+			"audio_hw_probe failed: perror=%d, rerror=%d\n",
+			perror, rerror);
 			goto bad;
 		}
 		if (perror) {
 			mode &= ~AUMODE_PLAY;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			"%d, playback disabled\n", perror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			"errno=%d, playback disabled\n", perror);
 		}
 		if (rerror) {
 			mode &= ~AUMODE_RECORD;
-			aprint_error_dev(self, "audio_hw_probe failed with "
-			"%d, capture disabled\n", rerror);
+			aprint_error_dev(self, "audio_hw_probe failed: "
+			"errno=%d, capture disabled\n", rerror);
 		}
 	} else {
 		/*
@@ -987,8 +990,8 @@ audioattach(device_t parent, device_t se
 		audio_format2_t *fmt = has_playback ?  : 
 		error = audio_hw_probe(sc, fmt, mode);
 		if (error) {
-			aprint_error_dev(self, "audio_hw_probe failed, "
-			"error = %d\n", error);
+			aprint_error_dev(self,
+			"audio_hw_probe failed: errno=%d\n", error);
 			goto bad;
 		}
 		if (has_playback && has_capture)
@@ -999,8 +1002,8 @@ audioattach(device_t parent, device_t se
 	/* hw_probe() also validates [pr]hwfmt.  */
 	error = audio_hw_set_format(sc, mode, , , , );
 	if (error) {
-		aprint_error_dev(self, "audio_hw_set_format failed, "
-		"error = %d\n", error);
+		aprint_error_dev(self,
+		"audio_hw_set_format failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1010,8 +1013,8 @@ audioattach(device_t parent, device_t se
 	 */
 	error = audio_mixers_init(sc, mode, , , , );
 	if (sc->sc_pmixer == NULL && sc->sc_rmixer == NULL) {
-		aprint_error_dev(self, "audio_mixers_init failed, "
-		"error = %d\n", error);
+		aprint_error_dev(self,
+		"audio_mixers_init failed: errno=%d\n", error);
 		goto bad;
 	}
 
@@ -1429,6 +1432,22 @@ audio_attach_mi(const struct audio_hw_if
 }
 
 /*
+ * audio_printf() outputs fmt... with the audio device name and MD device
+ * name prefixed.  If the message is considered to be related to the MD
+ * driver, use this one instead of device_printf().
+ */
+static void
+audio_printf(struct audio_softc *sc, const char *fmt, ...)
+{
+	va_list ap;
+
+	printf("%s(%s): ", device_xname(sc->sc_dev), device_xname(sc->hw_dev));
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+}
+
+/*
  * Enter critical section and also keep sc_lock.
  * If successful, returns 0 with sc_lock held.  Otherwise returns errno.
  * Must be called without sc_lock held.
@@ -1574,7 +1593,7 @@ 

CVS commit: [netbsd-9] src/sys/dev/raidframe

2021-02-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb 17 09:34:20 UTC 2021

Modified Files:
src/sys/dev/raidframe [netbsd-9]: rf_reconstruct.c

Log Message:
Pull up following revision(s) (requested by oster in ticket #1206):

sys/dev/raidframe/rf_reconstruct.c: revision 1.125

Fix a long long-standing off-by-one error in computing lastPSID.

SUsPerPU is only really supported for a value of 1, and since the
first PSID is 0, the last will be numStripe-1.  Also update the
setting of pending_writes to reflect the change to lastPSID.

Needs pullups to -8 and -9.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.122.4.1 src/sys/dev/raidframe/rf_reconstruct.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/raidframe/rf_reconstruct.c
diff -u src/sys/dev/raidframe/rf_reconstruct.c:1.122 src/sys/dev/raidframe/rf_reconstruct.c:1.122.4.1
--- src/sys/dev/raidframe/rf_reconstruct.c:1.122	Sat Feb  9 03:34:00 2019
+++ src/sys/dev/raidframe/rf_reconstruct.c	Wed Feb 17 09:34:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rf_reconstruct.c,v 1.122 2019/02/09 03:34:00 christos Exp $	*/
+/*	$NetBSD: rf_reconstruct.c,v 1.122.4.1 2021/02/17 09:34:20 martin Exp $	*/
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
  * All rights reserved.
@@ -33,7 +33,7 @@
  /
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.122 2019/02/09 03:34:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_reconstruct.c,v 1.122.4.1 2021/02/17 09:34:20 martin Exp $");
 
 #include 
 #include 
@@ -616,7 +616,7 @@ rf_ContinueReconstructFailedDisk(RF_Raid
 	mapPtr = raidPtr->reconControl->reconMap;
 
 	incPSID = RF_RECONMAP_SIZE;
-	lastPSID = raidPtr->Layout.numStripe / raidPtr->Layout.SUsPerPU;
+	lastPSID = raidPtr->Layout.numStripe / raidPtr->Layout.SUsPerPU - 1;
 	RUsPerPU = raidPtr->Layout.SUsPerPU / raidPtr->Layout.SUsPerRU;
 	recon_error = 0;
 	write_error = 0;
@@ -631,7 +631,7 @@ rf_ContinueReconstructFailedDisk(RF_Raid
 		raidPtr->reconControl->lastPSID = lastPSID;
 
 	if (pending_writes > lastPSID)
-		pending_writes = lastPSID;
+		pending_writes = lastPSID + 1;
 
 	/* start the actual reconstruction */
 
@@ -796,7 +796,6 @@ rf_ContinueReconstructFailedDisk(RF_Raid
 			pending_writes = lastPSID - prev;
 			raidPtr->reconControl->lastPSID = lastPSID;
 		}
-		
 		/* back down curPSID to get ready for the next round... */
 		for (i = 0; i < raidPtr->numCol; i++) {
 			if (i != col) {



CVS commit: [netbsd-9] src/sys/dev/scsipi

2021-02-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb 11 12:53:28 UTC 2021

Modified Files:
src/sys/dev/scsipi [netbsd-9]: cd.c sd.c

Log Message:
Pull up following revision(s) (requested by ryoon in ticket #1203):

sys/dev/scsipi/cd.c: revision 1.350
sys/dev/scsipi/sd.c: revision 1.331

PR 55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
consistent by also using __BIT()


To generate a diff of this commit:
cvs rdiff -u -r1.342.4.1 -r1.342.4.2 src/sys/dev/scsipi/cd.c
cvs rdiff -u -r1.327.4.1 -r1.327.4.2 src/sys/dev/scsipi/sd.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/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.342.4.1 src/sys/dev/scsipi/cd.c:1.342.4.2
--- src/sys/dev/scsipi/cd.c:1.342.4.1	Thu Apr  2 19:15:35 2020
+++ src/sys/dev/scsipi/cd.c	Thu Feb 11 12:53:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.342.4.1 2020/04/02 19:15:35 martin Exp $	*/
+/*	$NetBSD: cd.c,v 1.342.4.2 2021/02/11 12:53:28 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.342.4.1 2020/04/02 19:15:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.342.4.2 2021/02/11 12:53:28 martin Exp $");
 
 #include 
 #include 
@@ -1378,7 +1378,7 @@ cdioctl(dev_t dev, u_long cmd, void *add
 		XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE));
 	case DIOCEJECT:
 		if (*(int *)addr == 0) {
-			int pmask = 1 << part;
+			int pmask = __BIT(part);
 			/*
 			 * Don't force eject: check that we are the only
 			 * partition open. If so, unlock it.

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.327.4.1 src/sys/dev/scsipi/sd.c:1.327.4.2
--- src/sys/dev/scsipi/sd.c:1.327.4.1	Sat Mar 21 15:52:09 2020
+++ src/sys/dev/scsipi/sd.c	Thu Feb 11 12:53:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.327.4.1 2020/03/21 15:52:09 martin Exp $	*/
+/*	$NetBSD: sd.c,v 1.327.4.2 2021/02/11 12:53:28 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.327.4.1 2020/03/21 15:52:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.327.4.2 2021/02/11 12:53:28 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -954,11 +954,12 @@ sdioctl(dev_t dev, u_long cmd, void *add
 		if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
 			return (ENOTTY);
 		if (*(int *)addr == 0) {
+			int pmask = __BIT(part);
 			/*
 			 * Don't force eject: check that we are the only
 			 * partition open. If so, unlock it.
 			 */
-			if (DK_BUSY(dksc, part) == 0) {
+			if (DK_BUSY(dksc, pmask) == 0) {
 error = scsipi_prevent(periph, SPAMR_ALLOW,
 XS_CTL_IGNORE_NOT_READY);
 if (error)



CVS commit: [netbsd-9] src/sys/dev/usb

2021-02-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb  4 19:24:01 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: usbdevs.h usbdevs_data.h

Log Message:
regen (for ticket #1197)


To generate a diff of this commit:
cvs rdiff -u -r1.760.4.6 -r1.760.4.7 src/sys/dev/usb/usbdevs.h \
src/sys/dev/usb/usbdevs_data.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/dev/usb/usbdevs.h
diff -u src/sys/dev/usb/usbdevs.h:1.760.4.6 src/sys/dev/usb/usbdevs.h:1.760.4.7
--- src/sys/dev/usb/usbdevs.h:1.760.4.6	Wed Apr 29 13:54:48 2020
+++ src/sys/dev/usb/usbdevs.h	Thu Feb  4 19:23:59 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.760.4.6 2020/04/29 13:54:48 martin Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.760.4.7 2021/02/04 19:23:59 martin Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.770.4.6 2020/04/29 13:53:51 martin Exp
+ *	NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp
  */
 
 /*-
@@ -3391,7 +3391,9 @@
 
 /* TP-Link products */
 #define	USB_PRODUCT_TPLINK_RTL8192CU	0x0100		/* RTL8192CU */
-#define	USB_PRODUCT_TPLINK_RTL8192EU	0x0109		/* RTL8192EU */
+#define	USB_PRODUCT_TPLINK_WN821NV5	0x0107		/* TL-WN821N v5 */
+#define	USB_PRODUCT_TPLINK_WN822NV4	0x0108		/* TL-WN822N v4 */
+#define	USB_PRODUCT_TPLINK_WN823NV2	0x0109		/* TL-WN823N v2 */
 #define	USB_PRODUCT_TPLINK_RTL8188EU	0x010c		/* RTL8188EU */
 
 /* Trek Technology products */
Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.760.4.6 src/sys/dev/usb/usbdevs_data.h:1.760.4.7
--- src/sys/dev/usb/usbdevs_data.h:1.760.4.6	Wed Apr 29 13:54:48 2020
+++ src/sys/dev/usb/usbdevs_data.h	Thu Feb  4 19:23:59 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.760.4.6 2020/04/29 13:54:48 martin Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.760.4.7 2021/02/04 19:23:59 martin Exp $	*/
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.770.4.6 2020/04/29 13:53:51 martin Exp
+ *	NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp
  */
 
 /*-
@@ -4644,64 +4644,68 @@ static const uint16_t usb_products[] = {
 	8669, 6484, 5028, 5798, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192CU, 
 	5207, 0,
-	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8192EU, 
-	17050, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN821NV5, 
+	19515, 19525, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN822NV4, 
+	19528, 18404, 0,
+	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_WN823NV2, 
+	19538, 7496, 0,
 	USB_VENDOR_TPLINK, USB_PRODUCT_TPLINK_RTL8188EU, 
 	5217, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE, 
-	19515, 0,
+	19548, 0,
 	USB_VENDOR_TREK, USB_PRODUCT_TREK_THUMBDRIVE_8MB, 
-	19515, 19526, 0,
+	19548, 19559, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8192CU, 
 	5207, 0,
 	USB_VENDOR_TRENDNET, USB_PRODUCT_TRENDNET_RTL8188CU, 
 	5227, 0,
 	USB_VENDOR_TRIPPLITE, USB_PRODUCT_TRIPPLITE_U209, 
-	19530, 6908, 4932, 0,
+	19563, 6908, 4932, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_UPS, 
 	3179, 3185, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_SMARTLCD, 
-	19535, 480, 0,
+	19568, 480, 0,
 	USB_VENDOR_TRIPPLITE2, USB_PRODUCT_TRIPPLITE2_AVR550U, 
-	3179, 3185, 19544, 0,
+	3179, 3185, 19577, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_T33521, 
-	19552, 19560, 0,
+	19585, 19593, 0,
 	USB_VENDOR_TRUMPION, USB_PRODUCT_TRUMPION_XXX1100, 
-	15921, 19568, 0,
+	15921, 19601, 0,
 	USB_VENDOR_TSUNAMI, USB_PRODUCT_TSUNAMI_SM2000, 
-	19573, 0,
+	19606, 0,
 	USB_VENDOR_TWINMOS, USB_PRODUCT_TWINMOS_G240, 
-	19581, 0,
+	19614, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_1200UBPLUS, 
 	11239, 14841, 11129, 7209, 0,
 	USB_VENDOR_ULTIMA, USB_PRODUCT_ULTIMA_T14BR, 
-	19586, 19592, 6818, 0,
+	19619, 19625, 6818, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1236U, 
-	19598, 5714, 19604, 0,
+	19631, 5714, 19637, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA1220U, 
-	19598, 19612, 19604, 0,
+	19631, 19645, 19637, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2000U, 
-	19598, 19618, 19604, 0,
+	19631, 19651, 19637, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA3400, 
-	19598, 19624, 19604, 0,
+	19631, 19657, 19637, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2100U, 
-	19598, 19629, 19604, 0,
+	19631, 19662, 19637, 0,
 	USB_VENDOR_UMAX, USB_PRODUCT_UMAX_ASTRA2200U, 
-	19598, 19635, 19604, 0,
+	19631, 19668, 19637, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UB_A, 
-	19641, 0,
+	19674, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UB, 
-	19653, 0,
+	19686, 0,
 	USB_VENDOR_UMEDIA, USB_PRODUCT_UMEDIA_TEW429UBC1, 
-	   

CVS commit: [netbsd-9] src/sys/dev/usb

2021-02-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb  4 19:23:10 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: if_urtwn.c usbdevs

Log Message:
Pull up following revision(s) (requested by nia in ticket #1197):

sys/dev/usb/if_urtwn.c: revision 1.89,1.90
sys/dev/usb/usbdevs: revision 1.788,1.789

urtwn(4): add TPLINK WN821N to the list of USB device ids
reported by kfmut on the unitedbsd forums.

add another TPLINK RTL8192EU variant
to avoid confusion use TP-Link's names for these variants, matching
FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.71.2.3 -r1.71.2.4 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.770.4.6 -r1.770.4.7 src/sys/dev/usb/usbdevs

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/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.71.2.3 src/sys/dev/usb/if_urtwn.c:1.71.2.4
--- src/sys/dev/usb/if_urtwn.c:1.71.2.3	Fri Apr 24 17:28:21 2020
+++ src/sys/dev/usb/if_urtwn.c	Thu Feb  4 19:23:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.71.2.3 2020/04/24 17:28:21 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.71.2.4 2021/02/04 19:23:10 martin Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.71.2.3 2020/04/24 17:28:21 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.71.2.4 2021/02/04 19:23:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -199,7 +199,9 @@ static const struct urtwn_dev {
 	/* URTWN_RTL8192EU */
 	URTWN_RTL8192EU_DEV(DLINK,	DWA131E),
 	URTWN_RTL8192EU_DEV(REALTEK,	RTL8192EU),
-	URTWN_RTL8192EU_DEV(TPLINK,	RTL8192EU),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN821NV5),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN822NV4),
+	URTWN_RTL8192EU_DEV(TPLINK,	WN823NV2),
 };
 #undef URTWN_DEV
 #undef URTWN_RTL8188E_DEV

Index: src/sys/dev/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.770.4.6 src/sys/dev/usb/usbdevs:1.770.4.7
--- src/sys/dev/usb/usbdevs:1.770.4.6	Wed Apr 29 13:53:51 2020
+++ src/sys/dev/usb/usbdevs	Thu Feb  4 19:23:10 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.770.4.6 2020/04/29 13:53:51 martin Exp $
+$NetBSD: usbdevs,v 1.770.4.7 2021/02/04 19:23:10 martin Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -3384,7 +3384,9 @@ product TOSHIBA HSDPA_MODEM_EU870DT1	0x1
 
 /* TP-Link products */
 product TPLINK RTL8192CU	0x0100	RTL8192CU
-product TPLINK RTL8192EU	0x0109	RTL8192EU
+product	TPLINK WN821NV5		0x0107	TL-WN821N v5
+product	TPLINK WN822NV4		0x0108	TL-WN822N v4
+product	TPLINK WN823NV2		0x0109	TL-WN823N v2
 product TPLINK RTL8188EU	0x010c	RTL8188EU
 
 /* Trek Technology products */



CVS commit: [netbsd-9] src/sys/dev/usb

2021-02-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb  4 19:16:02 UTC 2021

Modified Files:
src/sys/dev/usb [netbsd-9]: uhid.c uhidev.c uhidev.h

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1196):

sys/dev/usb/uhid.c: revision 1.115
sys/dev/usb/uhidev.h: revision 1.21
sys/dev/usb/uhidev.c: revision 1.79
(all via patch)

usb: Overhaul uhid(4) and uhidev(4) locking.

- uhidev API rules:
  1. Call uhidev_open when you want exclusive use of a report id.
 After it succeeds, you will get interrupts.
  2. Call uhidev_close when done with exclusive use of a report id.
 After it returns, you will no longer get interrupts.
 => uhidev_open/close do not nest.
  3. uhidev_write no longer requires the caller to have exclusive
 access -- if there is a write in progress, it will block
 interruptibly until done.  This way drivers for individual
 report ids need not work separately to coordinate their writes.
  4. You must uhidev_stop to abort any pending writes on the same
 report id.  (uhidev_stop no longer does anything else -- to
 ensure no more interrupts, just use uhidev_close.)
- Fix uhidev_open/close locking -- uhidev now has an interruptible
  config lock held only on first open and last close by any report id
  in the device, to serialize the transition between zero and nonzero
  numbers of references which requires opening/closing pipes and
  allocating/freeing buffers.
- Make /dev/uhidN selnotify(POLLHUP) when the device is yanked.
- Factor uhid device lookup and reference counting and dying
  detection and so on into uhid_enter/exit.
- Nix struct uhid_softc::sc_access_lock.  This served no purpose but
  to confuse me when trying to understand the logic of this beast
  (and to ensure uhidev_write exclusion, but it was uninterruptible,
  which is wrong for something that implements userland operations,
  and didn't actually work because uhidev_write did nothing to
  coordinate between different report ids).
- Fix locking in select/poll.
- Use atomics to manage UHID_IMMED to keep it simple.  (sc_lock would
  be fine too but it makes the code more verbose.)
- Omit needless UHID_ASLP -- cv_broadcast already has this
  micro-optimization.

With these changes, my Pinebook survives

for i in `jot 100`; do
echo '###' $i
for j in `jot 16`; do
usbhidctl -rf /dev/uhid$j >/dev/null &
done
wait
done

while plugging and unplugging uhid(4) devices (U2F keys), and the U2F
keys still work as U2F keys.

ok nick, mrg

XXX pullup-9
XXX pullup-8?

Note on ABI and pullups: This changes the layout of struct
uhidev_softc, but with the sole exception of ucycom(4) -- which at
the moment is completely broken and unusable -- the only members that
USB HID drivers use are sc_udev and sc_iface, which haven't changed.
The layout of struct uhidev, which is allocated by each USB HID
driver in its own softc structure, is unchanged.


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.2 -r1.108.2.3 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.75 -r1.75.2.1 src/sys/dev/usb/uhidev.c
cvs rdiff -u -r1.20 -r1.20.4.1 src/sys/dev/usb/uhidev.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/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.108.2.2 src/sys/dev/usb/uhid.c:1.108.2.3
--- src/sys/dev/usb/uhid.c:1.108.2.2	Wed Jul 15 14:09:04 2020
+++ src/sys/dev/usb/uhid.c	Thu Feb  4 19:16:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $	*/
+/*	$NetBSD: uhid.c,v 1.108.2.3 2021/02/04 19:16:01 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.3 2021/02/04 19:16:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -43,21 +43,24 @@ __KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.1
 #endif
 
 #include 
-#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
-#include 
-#include 
-#include 
+#include 
 #include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-#include 
 
 #include 
 #include 
@@ -84,8 +87,7 @@ int	uhiddebug = 0;
 struct uhid_softc {
 	struct uhidev sc_hdev;
 
-	kmutex_t sc_access_lock; /* serialises syscall accesses */
-	kmutex_t sc_lock;	/* protects refcnt, others */
+	kmutex_t sc_lock;
 	kcondvar_t sc_cv;
 	kcondvar_t sc_detach_cv;
 
@@ -99,12 +101,12 @@ struct uhid_softc {
 	struct selinfo sc_rsel;
 	proc_t *sc_async;	/* process that wants SIGIO */
 	void *sc_sih;
-	u_char sc_state;	/* driver state */
-#define	UHID_ASLP	0x01	/* waiting for device data */
+	volatile uint32_t sc_state;	/* driver state */
 

CVS commit: [netbsd-9] src/sys/dev/hyperv

2021-02-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb  4 17:04:14 UTC 2021

Modified Files:
src/sys/dev/hyperv [netbsd-9]: hvkbd.c if_hvn.c vmbus.c

Log Message:
Pull up following revision(s) (requested by nonaka in ticket #1192):

sys/dev/hyperv/if_hvn.c: revision 1.20 (via patch)
sys/dev/hyperv/hvkbd.c: revision 1.7 (via patch)
sys/dev/hyperv/vmbus.c: revision 1.12 (via patch)

hvkbd(4): Don't wait forever.
vmbus(4): Don't wait forever.
hvn(4): Don't wait forever.


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/hyperv/hvkbd.c
cvs rdiff -u -r1.4.2.6 -r1.4.2.7 src/sys/dev/hyperv/if_hvn.c
cvs rdiff -u -r1.4.2.1 -r1.4.2.2 src/sys/dev/hyperv/vmbus.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/hyperv/hvkbd.c
diff -u src/sys/dev/hyperv/hvkbd.c:1.2.2.2 src/sys/dev/hyperv/hvkbd.c:1.2.2.3
--- src/sys/dev/hyperv/hvkbd.c:1.2.2.2	Sun Nov 24 08:13:07 2019
+++ src/sys/dev/hyperv/hvkbd.c	Thu Feb  4 17:04:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hvkbd.c,v 1.2.2.2 2019/11/24 08:13:07 martin Exp $	*/
+/*	$NetBSD: hvkbd.c,v 1.2.2.3 2021/02/04 17:04:14 martin Exp $	*/
 
 /*-
  * Copyright (c) 2017 Microsoft Corp.
@@ -36,7 +36,7 @@
 #endif /* _KERNEL_OPT */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hvkbd.c,v 1.2.2.2 2019/11/24 08:13:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hvkbd.c,v 1.2.2.3 2021/02/04 17:04:14 martin Exp $");
 
 #include 
 #include 
@@ -365,7 +365,8 @@ hvkbd_connect(struct hvkbd_softc *sc)
 			hvkbd_intr(sc);
 			splx(s);
 		} else
-			tsleep(sc, PRIBIO | PCATCH, "hvkbdcon", mstohz(1));
+			tsleep(sc, PRIBIO | PCATCH, "hvkbdcon",
+			uimax(1, mstohz(1)));
 	} while (--timo > 0 && sc->sc_connected == 0);
 
 	if (timo == 0 && sc->sc_connected == 0) {

Index: src/sys/dev/hyperv/if_hvn.c
diff -u src/sys/dev/hyperv/if_hvn.c:1.4.2.6 src/sys/dev/hyperv/if_hvn.c:1.4.2.7
--- src/sys/dev/hyperv/if_hvn.c:1.4.2.6	Fri Dec 11 15:43:16 2020
+++ src/sys/dev/hyperv/if_hvn.c	Thu Feb  4 17:04:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_hvn.c,v 1.4.2.6 2020/12/11 15:43:16 martin Exp $	*/
+/*	$NetBSD: if_hvn.c,v 1.4.2.7 2021/02/04 17:04:14 martin Exp $	*/
 /*	$OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $	*/
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.4.2.6 2020/12/11 15:43:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.4.2.7 2021/02/04 17:04:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1054,7 +1054,8 @@ hvn_nvs_cmd(struct hvn_softc *sc, void *
 			if (cold)
 delay(1000);
 			else
-tsleep(cmd, PRIBIO, "nvsout", mstohz(1));
+tsleep(cmd, PRIBIO, "nvsout",
+uimax(1, mstohz(1)));
 		} else if (rv) {
 			DPRINTF("%s: NVSP operation %u send error %d\n",
 			device_xname(sc->sc_dev), hdr->nvs_type, rv);
@@ -1079,7 +1080,7 @@ hvn_nvs_cmd(struct hvn_softc *sc, void *
 			splx(s);
 		} else
 			tsleep(sc->sc_nvsrsp, PRIBIO | PCATCH, "nvscmd",
-			mstohz(1));
+			uimax(1, mstohz(1)));
 	} while (--timo > 0 && sc->sc_nvsdone != 1);
 
 	if (timo == 0 && sc->sc_nvsdone != 1) {
@@ -1377,7 +1378,8 @@ hvn_rndis_cmd(struct hvn_softc *sc, stru
 			if (cold)
 delay(1000);
 			else
-tsleep(rc, PRIBIO, "rndisout", mstohz(1));
+tsleep(rc, PRIBIO, "rndisout",
+uimax(1, mstohz(1)));
 		} else if (rv) {
 			DPRINTF("%s: RNDIS operation %u send error %d\n",
 			device_xname(sc->sc_dev), hdr->rm_type, rv);
@@ -1402,7 +1404,8 @@ hvn_rndis_cmd(struct hvn_softc *sc, stru
 			hvn_nvs_intr(sc);
 			splx(s);
 		} else
-			tsleep(rc, PRIBIO | PCATCH, "rndiscmd", mstohz(1));
+			tsleep(rc, PRIBIO | PCATCH, "rndiscmd",
+			uimax(1, mstohz(1)));
 	} while (--timo > 0 && rc->rc_done != 1);
 
 	bus_dmamap_sync(sc->sc_dmat, rc->rc_dmap, 0, PAGE_SIZE,

Index: src/sys/dev/hyperv/vmbus.c
diff -u src/sys/dev/hyperv/vmbus.c:1.4.2.1 src/sys/dev/hyperv/vmbus.c:1.4.2.2
--- src/sys/dev/hyperv/vmbus.c:1.4.2.1	Sun Nov 24 08:13:07 2019
+++ src/sys/dev/hyperv/vmbus.c	Thu Feb  4 17:04:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmbus.c,v 1.4.2.1 2019/11/24 08:13:07 martin Exp $	*/
+/*	$NetBSD: vmbus.c,v 1.4.2.2 2021/02/04 17:04:14 martin Exp $	*/
 /*	$OpenBSD: hyperv.c,v 1.43 2017/06/27 13:56:15 mikeb Exp $	*/
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.4.2.1 2019/11/24 08:13:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus.c,v 1.4.2.2 2021/02/04 17:04:14 martin Exp $");
 
 #include 
 #include 
@@ -604,7 +604,8 @@ vmbus_start(struct vmbus_softc *sc, stru
 			hyperv_intr();
 			splx(s);
 		} else
-			tsleep(wchan, PRIBIO, wchan, mstohz(delays[i]));
+			tsleep(wchan, PRIBIO, wchan,
+			uimax(1, mstohz(delays[i] / 1000)));
 	}
 	if (status != HYPERCALL_STATUS_SUCCESS) {
 		device_printf(sc->sc_dev,
@@ -667,7 +668,7 @@ vmbus_wait(struct vmbus_softc *sc,
 			splx(s);
 		} else
 			tsleep(wchan, PRIBIO, wmsg ? wmsg : 

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

2021-01-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jan 23 13:01:10 UTC 2021

Modified Files:
src/sys/dev/pci [netbsd-9]: if_ena.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1186):

sys/dev/pci/if_ena.c: revision 1.27

PR kern/55942: destroyed ena(4) evcnts cause panic

Fix event counter teardown code. From KUSABA Takeshi


To generate a diff of this commit:
cvs rdiff -u -r1.15.2.3 -r1.15.2.4 src/sys/dev/pci/if_ena.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_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.15.2.3 src/sys/dev/pci/if_ena.c:1.15.2.4
--- src/sys/dev/pci/if_ena.c:1.15.2.3	Wed Aug  5 14:59:41 2020
+++ src/sys/dev/pci/if_ena.c	Sat Jan 23 13:01:10 2021
@@ -36,7 +36,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15.2.3 2020/08/05 14:59:41 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15.2.4 2021/01/23 13:01:10 martin Exp $");
 
 #include 
 #include 
@@ -470,18 +470,20 @@ ena_alloc_counters_hwstats(struct ena_hw
 	+ sizeof(st->rx_drops) == sizeof(*st));
 }
 static inline void
-ena_free_counters(struct evcnt *begin, int size)
+ena_free_counters(struct evcnt *begin, int size, int offset)
 {
 	struct evcnt *end = (struct evcnt *)((char *)begin + size);
+	begin = (struct evcnt *)((char *)begin + offset);
 
 	for (; begin < end; ++begin)
 		counter_u64_free(*begin);
 }
 
 static inline void
-ena_reset_counters(struct evcnt *begin, int size)
+ena_reset_counters(struct evcnt *begin, int size, int offset)
 {
 	struct evcnt *end = (struct evcnt *)((char *)begin + size);
+	begin = (struct evcnt *)((char *)begin + offset);
 
 	for (; begin < end; ++begin)
 		counter_u64_zero(*begin);
@@ -566,9 +568,9 @@ ena_free_io_ring_resources(struct ena_ad
 	struct ena_ring *rxr = >rx_ring[qid];
 
 	ena_free_counters((struct evcnt *)>tx_stats,
-	sizeof(txr->tx_stats));
+	sizeof(txr->tx_stats), offsetof(struct ena_stats_tx, cnt));
 	ena_free_counters((struct evcnt *)>rx_stats,
-	sizeof(rxr->rx_stats));
+	sizeof(rxr->rx_stats), offsetof(struct ena_stats_rx, cnt));
 
 	ENA_RING_MTX_LOCK(txr);
 	drbr_free(txr->br, M_DEVBUF);
@@ -670,7 +672,8 @@ ena_setup_tx_resources(struct ena_adapte
 
 	/* Reset TX statistics. */
 	ena_reset_counters((struct evcnt *)_ring->tx_stats,
-	sizeof(tx_ring->tx_stats));
+	sizeof(tx_ring->tx_stats),
+	offsetof(struct ena_stats_tx, cnt));
 
 	tx_ring->next_to_use = 0;
 	tx_ring->next_to_clean = 0;
@@ -867,7 +870,8 @@ ena_setup_rx_resources(struct ena_adapte
 
 	/* Reset RX statistics. */
 	ena_reset_counters((struct evcnt *)_ring->rx_stats,
-	sizeof(rx_ring->rx_stats));
+	sizeof(rx_ring->rx_stats),
+	offsetof(struct ena_stats_rx, cnt));
 
 	rx_ring->next_to_clean = 0;
 	rx_ring->next_to_use = 0;
@@ -2210,7 +2214,8 @@ ena_up_complete(struct ena_adapter *adap
 
 	ena_refill_all_rx_bufs(adapter);
 	ena_reset_counters((struct evcnt *)>hw_stats,
-	sizeof(adapter->hw_stats));
+	sizeof(adapter->hw_stats),
+	offsetof(struct ena_hw_stats, rx_packets));
 
 	return (0);
 }
@@ -3905,9 +3910,11 @@ ena_detach(device_t pdev, int flags)
 	ena_free_all_io_rings_resources(adapter);
 
 	ena_free_counters((struct evcnt *)>hw_stats,
-	sizeof(struct ena_hw_stats));
+	sizeof(struct ena_hw_stats),
+	offsetof(struct ena_hw_stats, rx_packets));
 	ena_free_counters((struct evcnt *)>dev_stats,
-	sizeof(struct ena_stats_dev));
+	sizeof(struct ena_stats_dev),
+offsetof(struct ena_stats_dev, wd_expired));
 
 	if (likely(adapter->rss_support))
 		ena_com_rss_destroy(ena_dev);



CVS commit: [netbsd-9] src/sys/dev/hdaudio

2020-12-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Dec 28 20:21:55 UTC 2020

Modified Files:
src/sys/dev/hdaudio [netbsd-9]: hdaudio.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1166):

sys/dev/hdaudio/hdaudio.c: revision 1.13

If the Subordinate Node Count returns 0 nodes, complain and return instead
of trying to kmem_zalloc 0 bytes later on.


To generate a diff of this commit:
cvs rdiff -u -r1.9.2.1 -r1.9.2.2 src/sys/dev/hdaudio/hdaudio.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/hdaudio/hdaudio.c
diff -u src/sys/dev/hdaudio/hdaudio.c:1.9.2.1 src/sys/dev/hdaudio/hdaudio.c:1.9.2.2
--- src/sys/dev/hdaudio/hdaudio.c:1.9.2.1	Mon Dec 28 20:18:09 2020
+++ src/sys/dev/hdaudio/hdaudio.c	Mon Dec 28 20:21:54 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.9.2.1 2020/12/28 20:18:09 martin Exp $ */
+/* $NetBSD: hdaudio.c,v 1.9.2.2 2020/12/28 20:21:54 martin Exp $ */
 
 /*
  * Copyright (c) 2009 Precedence Technologies Ltd 
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.9.2.1 2020/12/28 20:18:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.9.2.2 2020/12/28 20:21:54 martin Exp $");
 
 #include 
 #include 
@@ -713,6 +713,7 @@ hdaudio_attach_fg(struct hdaudio_functio
 static void
 hdaudio_codec_attach(struct hdaudio_codec *co)
 {
+	struct hdaudio_softc *sc = co->co_host;
 	struct hdaudio_function_group *fg;
 	uint32_t vid, snc, fgrp;
 	int starting_node, num_nodes, nid;
@@ -729,7 +730,6 @@ hdaudio_codec_attach(struct hdaudio_code
 		return;
 
 #ifdef HDAUDIO_DEBUG
-	struct hdaudio_softc *sc = co->co_host;
 	uint32_t rid = hdaudio_command(co, 0, CORB_GET_PARAMETER,
 	COP_REVISION_ID);
 	hda_print(sc, "Codec%02X: %04X:%04X HDA %d.%d rev %d stepping %d\n",
@@ -740,6 +740,16 @@ hdaudio_codec_attach(struct hdaudio_code
 	starting_node = (snc >> 16) & 0xff;
 	num_nodes = snc & 0xff;
 
+	/*
+	 * If the total number of nodes is 0, there's nothing we can do.
+	 * This shouldn't happen, so complain about it.
+	 */
+	if (num_nodes == 0) {
+		hda_error(sc, "Codec%02X: No subordinate nodes found (%08x)\n",
+		co->co_addr, snc);
+		return;
+	}
+
 	co->co_nfg = num_nodes;
 	co->co_fg = kmem_zalloc(co->co_nfg * sizeof(*co->co_fg), KM_SLEEP);
 



CVS commit: [netbsd-9] src/sys/dev/hdaudio

2020-12-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Dec 28 20:18:09 UTC 2020

Modified Files:
src/sys/dev/hdaudio [netbsd-9]: hdaudio.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1165):

sys/dev/hdaudio/hdaudio.c: revision 1.12

Initialize DMA memory when allocating it. Should fix PR# 51734 (hdaudio
"RIRB timeout" on boot).


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.2.1 src/sys/dev/hdaudio/hdaudio.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/hdaudio/hdaudio.c
diff -u src/sys/dev/hdaudio/hdaudio.c:1.9 src/sys/dev/hdaudio/hdaudio.c:1.9.2.1
--- src/sys/dev/hdaudio/hdaudio.c:1.9	Fri Jul 26 11:13:46 2019
+++ src/sys/dev/hdaudio/hdaudio.c	Mon Dec 28 20:18:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.9 2019/07/26 11:13:46 jmcneill Exp $ */
+/* $NetBSD: hdaudio.c,v 1.9.2.1 2020/12/28 20:18:09 martin Exp $ */
 
 /*
  * Copyright (c) 2009 Precedence Technologies Ltd 
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.9 2019/07/26 11:13:46 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.9.2.1 2020/12/28 20:18:09 martin Exp $");
 
 #include 
 #include 
@@ -194,6 +194,10 @@ hdaudio_dma_alloc(struct hdaudio_softc *
 	if (err)
 		goto destroy;
 
+	memset(dma->dma_addr, 0, dma->dma_size);
+	bus_dmamap_sync(sc->sc_dmat, dma->dma_map, 0, dma->dma_size,
+	BUS_DMASYNC_PREWRITE);
+
 	dma->dma_valid = true;
 	return 0;
 



CVS commit: [netbsd-9] src/sys/dev/audio

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:54:56 UTC 2020

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1158):

sys/dev/audio/audio.c: revision 1.83

Avoid a dead lock in audiodetach, since rev 1.63.
audio_unlink() must be called without exlock held (and
audio_mixer_destroy() must be called with exlock held).

This makes unplugging during playing/recording work (again).

Reported by Julian Coleman on current-users:
 http://mail-index.netbsd.org/current-users/2020/12/10/msg040050.html


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.17 -r1.28.2.18 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.17 src/sys/dev/audio/audio.c:1.28.2.18
--- src/sys/dev/audio/audio.c:1.28.2.17	Sat Dec 19 13:48:27 2020
+++ src/sys/dev/audio/audio.c	Sat Dec 19 13:54:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.18 2020/12/19 13:54:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1324,7 +1324,6 @@ audiodetach(device_t self, int flags)
 	 * that hold sc, and any new calls with files that were for sc will
 	 * fail.  Thus, we now have exclusive access to the softc.
 	 */
-	sc->sc_exlock = 1;
 
 	/*
 	 * Nuke all open instances.
@@ -1350,6 +1349,7 @@ audiodetach(device_t self, int flags)
 	pmf_device_deregister(self);
 
 	/* Free resources */
+	sc->sc_exlock = 1;
 	if (sc->sc_pmixer) {
 		audio_mixer_destroy(sc, sc->sc_pmixer);
 		kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer));



CVS commit: [netbsd-9] src/sys/dev/audio

2020-12-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 19 13:48:27 UTC 2020

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #1156):

sys/dev/audio/audio.c: revision 1.80
sys/dev/audio/audio.c: revision 1.81

Fix that audio_open() didn't halt the recording mixer correctly
if fd_allocfile() failed, since rev 1.65.

Will fix PR kern/55848.

 -

Rewrite error handling on audio_open().
This also fixes a few resource leaks on error case.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.16 -r1.28.2.17 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.16 src/sys/dev/audio/audio.c:1.28.2.17
--- src/sys/dev/audio/audio.c:1.28.2.16	Sun Jun  7 19:04:00 2020
+++ src/sys/dev/audio/audio.c	Sat Dec 19 13:48:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.17 2020/12/19 13:48:27 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2075,6 +2075,9 @@ audio_open(dev_t dev, struct audio_softc
 	audio_file_t *af;
 	audio_ring_t *hwbuf;
 	bool fullduplex;
+	bool cred_held;
+	bool hw_opened;
+	bool rmixer_started;
 	int fd;
 	int error;
 
@@ -2085,6 +2088,11 @@ audio_open(dev_t dev, struct audio_softc
 	ISDEVSOUND(dev) ? "sound" : "audio",
 	flags, sc->sc_popens, sc->sc_ropens);
 
+	fp = NULL;
+	cred_held = false;
+	hw_opened = false;
+	rmixer_started = false;
+
 	af = kmem_zalloc(sizeof(audio_file_t), KM_SLEEP);
 	af->sc = sc;
 	af->dev = dev;
@@ -2094,7 +2102,7 @@ audio_open(dev_t dev, struct audio_softc
 		af->mode |= AUMODE_RECORD;
 	if (af->mode == 0) {
 		error = ENXIO;
-		goto bad1;
+		goto bad;
 	}
 
 	fullduplex = (sc->sc_props & AUDIO_PROP_FULLDUPLEX);
@@ -2110,7 +2118,7 @@ audio_open(dev_t dev, struct audio_softc
 			if (sc->sc_ropens != 0) {
 TRACE(1, "record track already exists");
 error = ENODEV;
-goto bad1;
+goto bad;
 			}
 			/* Play takes precedence */
 			af->mode &= ~AUMODE_RECORD;
@@ -2119,7 +2127,7 @@ audio_open(dev_t dev, struct audio_softc
 			if (sc->sc_popens != 0) {
 TRACE(1, "play track already exists");
 error = ENODEV;
-goto bad1;
+goto bad;
 			}
 		}
 	}
@@ -2166,13 +2174,14 @@ audio_open(dev_t dev, struct audio_softc
 	}
 	error = audio_file_setinfo(sc, af, );
 	if (error)
-		goto bad2;
+		goto bad;
 
 	if (sc->sc_popens + sc->sc_ropens == 0) {
 		/* First open */
 
 		sc->sc_cred = kauth_cred_get();
 		kauth_cred_hold(sc->sc_cred);
+		cred_held = true;
 
 		if (sc->hw_if->open) {
 			int hwflags;
@@ -2205,8 +2214,16 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad2;
+goto bad;
 		}
+		/*
+		 * Regardless of whether we called hw_if->open (whether
+		 * hw_if->open exists) or not, we move to the Opened phase
+		 * here.  Therefore from this point, we have to call
+		 * hw_if->close (if exists) whenever abort.
+		 * Note that both of hw_if->{open,close} are optional.
+		 */
+		hw_opened = true;
 
 		/*
 		 * Set speaker mode when a half duplex.
@@ -2226,14 +2243,14 @@ audio_open(dev_t dev, struct audio_softc
 mutex_exit(sc->sc_intr_lock);
 mutex_exit(sc->sc_lock);
 if (error)
-	goto bad3;
+	goto bad;
 			}
 		}
 	} else if (sc->sc_multiuser == false) {
 		uid_t euid = kauth_cred_geteuid(kauth_cred_get());
 		if (euid != 0 && euid != kauth_cred_geteuid(sc->sc_cred)) {
 			error = EPERM;
-			goto bad2;
+			goto bad;
 		}
 	}
 
@@ -2250,7 +2267,7 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad3;
+goto bad;
 		}
 	}
 	/*
@@ -2269,18 +2286,24 @@ audio_open(dev_t dev, struct audio_softc
 			mutex_exit(sc->sc_intr_lock);
 			mutex_exit(sc->sc_lock);
 			if (error)
-goto bad3;
+goto bad;
 		}
 
 		mutex_enter(sc->sc_lock);
 		audio_rmixer_start(sc);
 		mutex_exit(sc->sc_lock);
+		rmixer_started = true;
 	}
 
-	if (bellfile == NULL) {
+	if (bellfile) {
+		*bellfile = af;
+	} else {
 		error = fd_allocfile(, );
 		if (error)
-			goto bad3;
+			goto bad;
+
+		error = fd_clone(fp, fd, flags, _fileops, af);
+		KASSERTMSG(error == EMOVEFD, "error=%d", error);
 	}
 
 	/*
@@ -2297,22 +2320,21 @@ audio_open(dev_t dev, struct audio_softc
 	mutex_exit(sc->sc_intr_lock);
 	mutex_exit(sc->sc_lock);
 
-	if (bellfile) {
-		*bellfile = af;
-	} else {
-		error = fd_clone(fp, fd, flags, _fileops, af);
-		KASSERTMSG(error == EMOVEFD, 

CVS commit: [netbsd-9] src/sys/dev/usb

2020-12-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 12 20:29:11 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ohci.c ohcivar.h

Log Message:
Pull up following revision(s) (requested by skrll in ticket #1150):

sys/dev/usb/ohci.c: revision 1.311
sys/dev/usb/ohci.c: revision 1.312
sys/dev/usb/ohcivar.h: revision 1.62

Restructure the abort code for TD based transfers (ctrl, bulk, intr).

In PR kern/22646 some TDs can be on the done queue when the abort start
and, if this is the case, they need to processed after the WDH interrupt.
Instead of waiting for WDH we release TDs that have been touched by the
HC and replace them with new ones.  Once WDH happens the floating TDs
will be returned to the free list.

Also addresses the issue seen in PR kern/55835

Thanks to both Andreas Gustafsson and Edgar Fu=C3=9F for testing.  Apologi=
es to
Andreas Gustafsson for not committing this to HEAD for 4y6m.w

Remove leading space that crept in in the last change


To generate a diff of this commit:
cvs rdiff -u -r1.289.4.5 -r1.289.4.6 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.60 -r1.60.6.1 src/sys/dev/usb/ohcivar.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/dev/usb/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.289.4.5 src/sys/dev/usb/ohci.c:1.289.4.6
--- src/sys/dev/usb/ohci.c:1.289.4.5	Sun Mar  1 12:35:16 2020
+++ src/sys/dev/usb/ohci.c	Sat Dec 12 20:29:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.289.4.5 2020/03/01 12:35:16 martin Exp $	*/
+/*	$NetBSD: ohci.c,v 1.289.4.6 2020/12/12 20:29:11 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.289.4.5 2020/03/01 12:35:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.289.4.6 2020/12/12 20:29:11 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -389,6 +389,7 @@ ohci_detach(struct ohci_softc *sc, int f
 	if (sc->sc_hcca != NULL)
 		usb_freemem(>sc_bus, >sc_hccadma);
 	pool_cache_destroy(sc->sc_xferpool);
+	cv_destroy(>sc_abort_cv);
 
 	return rv;
 }
@@ -491,6 +492,7 @@ ohci_alloc_std(ohci_softc_t *sc)
 	memset(>td, 0, sizeof(ohci_td_t));
 	std->nexttd = NULL;
 	std->xfer = NULL;
+	std->held = NULL;
 
 	return std;
 }
@@ -538,14 +540,17 @@ ohci_alloc_std_chain(ohci_softc_t *sc, s
 
 	DPRINTFN(8, "xfer %#jx nstd %jd", (uintptr_t)xfer, nstd, 0, 0);
 
-	for (size_t j = 0; j < ox->ox_nstd;) {
+	for (size_t j = 0; j < ox->ox_nstd; j++) {
 		ohci_soft_td_t *cur = ohci_alloc_std(sc);
 		if (cur == NULL)
 			goto nomem;
 
-		ox->ox_stds[j++] = cur;
+		ox->ox_stds[j] = cur;
+		cur->held = >ox_stds[j];
 		cur->xfer = xfer;
 		cur->flags = 0;
+		DPRINTFN(10, "xfer=%#jx new std=%#jx held at %#jx", (uintptr_t)ox,
+		(uintptr_t)cur, (uintptr_t)cur->held, 0);
 	}
 
 	return 0;
@@ -796,6 +801,9 @@ ohci_init(ohci_softc_t *sc)
 	for (i = 0; i < OHCI_HASH_SIZE; i++)
 		LIST_INIT(>sc_hash_itds[i]);
 
+	TAILQ_INIT(>sc_abortingxfers);
+	cv_init(>sc_abort_cv, "ohciabt");
+
 	sc->sc_xferpool = pool_cache_init(sizeof(struct ohci_xfer), 0, 0, 0,
 	"ohcixfer", NULL, IPL_USB, NULL, NULL, NULL);
 
@@ -1319,6 +1327,21 @@ ohci_intr1(ohci_softc_t *sc)
 		 */
 		usb_schedsoftintr(>sc_bus);
 	}
+	if (eintrs & OHCI_SF) {
+		struct ohci_xfer *ox, *tmp;
+		TAILQ_FOREACH_SAFE(ox, >sc_abortingxfers, ox_abnext, tmp) {
+			DPRINTFN(10, "SF %#jx xfer %#jx", (uintptr_t)sc,
+			(uintptr_t)ox, 0, 0);
+			ox->ox_abintrs &= ~OHCI_SF;
+			KASSERT(ox->ox_abintrs == 0);
+			TAILQ_REMOVE(>sc_abortingxfers, ox, ox_abnext);
+		}
+		cv_broadcast(>sc_abort_cv);
+
+		KASSERT(TAILQ_EMPTY(>sc_abortingxfers));
+		DPRINTFN(10, "end SOF %#jx", (uintptr_t)sc, 0, 0, 0);
+		/* Don't remove OHIC_SF from eintrs so it is blocked below */
+	}
 	if (eintrs & OHCI_RD) {
 		DPRINTFN(5, "resume detect sc=%#jx", (uintptr_t)sc, 0, 0, 0);
 		printf("%s: resume detect\n", device_xname(sc->sc_dev));
@@ -1395,12 +1418,22 @@ ohci_softintr(void *v)
 	struct ohci_pipe *opipe;
 	int len, cc;
 	int i, j, actlen, iframes, uedir;
-	ohci_physaddr_t done;
+	ohci_physaddr_t done = 0;
 
 	KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(>sc_lock));
 
 	OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
+	/*
+	 * Only read hccadone if WDH is set - we might get here from places
+	 * other than an interrupt
+	 */
+	if (!(OREAD4(sc, OHCI_INTERRUPT_STATUS) & OHCI_WDH)) {
+		DPRINTFN(10, "no WDH %#jx", (uintptr_t)sc, 0, 0, 0);
+		return;
+	}
+
+	DPRINTFN(10, "WDH %#jx", (uintptr_t)sc, 0, 0, 0);
 	usb_syncmem(>sc_hccadma, offsetof(struct ohci_hcca, hcca_done_head),
 	sizeof(sc->sc_hcca->hcca_done_head),
 	BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
@@ -1453,11 +1486,19 @@ ohci_softintr(void *v)
 	DPRINTFN(10, "--- TD dump end ---", 0, 0, 0, 0);
 
 	for (std = sdone; std; std = stdnext) {
-		xfer = std->xfer;
 		stdnext = std->dnext;
-		DPRINTFN(10, "std=%#jx xfer=%#jx 

CVS commit: [netbsd-9] src/sys/dev/fdt

2020-12-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 12 13:03:47 UTC 2020

Modified Files:
src/sys/dev/fdt [netbsd-9]: pwm_backlight.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1149):

sys/dev/fdt/pwm_backlight.c: revision 1.7

save the new current level when set by the user.

stops PBP display from going back to default brightness after
dpms, etc.

ok jmcneill.


To generate a diff of this commit:
cvs rdiff -u -r1.4.10.1 -r1.4.10.2 src/sys/dev/fdt/pwm_backlight.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/fdt/pwm_backlight.c
diff -u src/sys/dev/fdt/pwm_backlight.c:1.4.10.1 src/sys/dev/fdt/pwm_backlight.c:1.4.10.2
--- src/sys/dev/fdt/pwm_backlight.c:1.4.10.1	Tue Jan 21 10:39:58 2020
+++ src/sys/dev/fdt/pwm_backlight.c	Sat Dec 12 13:03:46 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: pwm_backlight.c,v 1.4.10.1 2020/01/21 10:39:58 martin Exp $ */
+/* $NetBSD: pwm_backlight.c,v 1.4.10.2 2020/12/12 13:03:46 martin Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.4.10.1 2020/01/21 10:39:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pwm_backlight.c,v 1.4.10.2 2020/12/12 13:03:46 martin Exp $");
 
 #include 
 #include 
@@ -60,7 +60,7 @@ static void	pwm_backlight_attach(device_
 
 static void	pwm_backlight_sysctl_init(struct pwm_backlight_softc *);
 static void	pwm_backlight_pmf_init(struct pwm_backlight_softc *);
-static void	pwm_backlight_set(struct pwm_backlight_softc *, u_int);
+static void	pwm_backlight_set(struct pwm_backlight_softc *, u_int, bool);
 static u_int	pwm_backlight_get(struct pwm_backlight_softc *);
 
 static const char *compatible[] = {
@@ -129,7 +129,7 @@ pwm_backlight_attach(device_t parent, de
 
 	if (of_getprop_uint32(phandle, "default-brightness-level", _level) == 0) {
 		/* set the default level now */
-		pwm_backlight_set(sc, default_level);
+		pwm_backlight_set(sc, default_level, true);
 	}
 
 	sc->sc_curlevel = pwm_backlight_get(sc);
@@ -139,7 +139,7 @@ pwm_backlight_attach(device_t parent, de
 }
 
 static void
-pwm_backlight_set(struct pwm_backlight_softc *sc, u_int index)
+pwm_backlight_set(struct pwm_backlight_softc *sc, u_int index, bool set_cur)
 {
 	struct pwm_config conf;
 
@@ -153,6 +153,9 @@ pwm_backlight_set(struct pwm_backlight_s
 	conf.duty_cycle = (conf.period * sc->sc_levels[index]) / sc->sc_levels[sc->sc_nlevels - 1];
 	pwm_set_config(sc->sc_pwm, );
 	pwm_enable(sc->sc_pwm);
+
+	if (set_cur)
+		sc->sc_curlevel = index;
 }
 
 static u_int
@@ -193,7 +196,7 @@ pwm_backlight_sysctl_helper(SYSCTLFN_ARG
 
 	for (n = 0; n < sc->sc_nlevels; n++) {
 		if (sc->sc_levels[n] == level) {
-			pwm_backlight_set(sc, n);
+			pwm_backlight_set(sc, n, true);
 			return 0;
 		}
 	}
@@ -255,7 +258,7 @@ pwm_backlight_enable(struct pwm_backligh
 	if (sc->sc_pin)
 		fdtbus_gpio_write(sc->sc_pin, enable);
 	else
-		pwm_backlight_set(sc, enable ? sc->sc_curlevel : 0);
+		pwm_backlight_set(sc, enable ? sc->sc_curlevel : 0, false);
 }
 
 static void
@@ -303,7 +306,7 @@ pwm_backlight_display_brightness_up(devi
 
 	n = pwm_backlight_get(sc);
 	if (n < sc->sc_nlevels - 1)
-		pwm_backlight_set(sc, n + 1);
+		pwm_backlight_set(sc, n + 1, true);
 }
 
 static void
@@ -314,7 +317,7 @@ pwm_backlight_display_brightness_down(de
 
 	n = pwm_backlight_get(sc);
 	if (n > 0)
-		pwm_backlight_set(sc, n - 1);
+		pwm_backlight_set(sc, n - 1, true);
 }
 
 static void



CVS commit: [netbsd-9] src/sys/dev/usb

2020-12-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 12 12:56:40 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ucom.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1147):

sys/dev/usb/ucom.c: revision 1.128

properly wait for refcounts to drain.
fixes panic at detach that jmnceill saw.

XXX: pullup-[89].


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.125.2.1 src/sys/dev/usb/ucom.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/usb/ucom.c
diff -u src/sys/dev/usb/ucom.c:1.125 src/sys/dev/usb/ucom.c:1.125.2.1
--- src/sys/dev/usb/ucom.c:1.125	Thu May  9 02:43:35 2019
+++ src/sys/dev/usb/ucom.c	Sat Dec 12 12:56:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.125 2019/05/09 02:43:35 mrg Exp $	*/
+/*	$NetBSD: ucom.c,v 1.125.2.1 2020/12/12 12:56:40 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.125 2019/05/09 02:43:35 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.125.2.1 2020/12/12 12:56:40 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -434,7 +434,7 @@ ucom_detach(device_t self, int flags)
 	}
 
 	sc->sc_refcnt--;
-	while (sc->sc_refcnt > 0) {
+	while (sc->sc_refcnt >= 0) {
 		/* Wake up anyone waiting */
 		if (tp != NULL) {
 			mutex_spin_enter(_lock);



CVS commit: [netbsd-9] src/sys/dev/hyperv

2020-12-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Dec 11 15:43:16 UTC 2020

Modified Files:
src/sys/dev/hyperv [netbsd-9]: if_hvn.c

Log Message:
Pull up following revision(s) (requested by nonaka in ticket #1146):

sys/dev/hyperv/if_hvn.c: revision 1.19

hvn(4): fix unable to ifconfig up/down.


To generate a diff of this commit:
cvs rdiff -u -r1.4.2.5 -r1.4.2.6 src/sys/dev/hyperv/if_hvn.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/hyperv/if_hvn.c
diff -u src/sys/dev/hyperv/if_hvn.c:1.4.2.5 src/sys/dev/hyperv/if_hvn.c:1.4.2.6
--- src/sys/dev/hyperv/if_hvn.c:1.4.2.5	Tue Nov 26 08:22:51 2019
+++ src/sys/dev/hyperv/if_hvn.c	Fri Dec 11 15:43:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_hvn.c,v 1.4.2.5 2019/11/26 08:22:51 martin Exp $	*/
+/*	$NetBSD: if_hvn.c,v 1.4.2.6 2020/12/11 15:43:16 martin Exp $	*/
 /*	$OpenBSD: if_hvn.c,v 1.39 2018/03/11 14:31:34 mikeb Exp $	*/
 
 /*-
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.4.2.5 2019/11/26 08:22:51 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hvn.c,v 1.4.2.6 2020/12/11 15:43:16 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -376,26 +376,7 @@ hvn_ioctl(struct ifnet *ifp, u_long comm
 
 	s = splnet();
 
-	switch (command) {
-	case SIOCSIFFLAGS:
-		if (ifp->if_flags & IFF_UP) {
-			if (ifp->if_flags & IFF_RUNNING)
-error = ENETRESET;
-			else {
-error = hvn_init(ifp);
-if (error)
-	ifp->if_flags &= ~IFF_UP;
-			}
-		} else {
-			if (ifp->if_flags & IFF_RUNNING)
-hvn_stop(ifp, 1);
-		}
-		break;
-	default:
-		error = ether_ioctl(ifp, command, data);
-		break;
-	}
-
+	error = ether_ioctl(ifp, command, data);
 	if (error == ENETRESET) {
 		if (ifp->if_flags & IFF_RUNNING)
 			hvn_iff(sc);



CVS commit: [netbsd-9] src/sys/dev/ic

2020-12-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Dec  7 20:04:07 UTC 2020

Modified Files:
src/sys/dev/ic [netbsd-9]: nvme.c

Log Message:
Pull up following revision(s) (requested by kardel in ticket #1144):

sys/dev/ic/nvme.c: revision 1.53

PR kern/55839:

handle multiple nvme_rescan()s correctly by doing the
name-space identify only once per nsid.
fixes issue where modloading triggers multiple
rescans.


To generate a diff of this commit:
cvs rdiff -u -r1.44.2.4 -r1.44.2.5 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.44.2.4 src/sys/dev/ic/nvme.c:1.44.2.5
--- src/sys/dev/ic/nvme.c:1.44.2.4	Sun Sep 27 10:30:16 2020
+++ src/sys/dev/ic/nvme.c	Mon Dec  7 20:04:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.44.2.4 2020/09/27 10:30:16 martin Exp $	*/
+/*	$NetBSD: nvme.c,v 1.44.2.5 2020/12/07 20:04:07 martin Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.4 2020/09/27 10:30:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.5 2020/12/07 20:04:07 martin Exp $");
 
 #include 
 #include 
@@ -628,6 +628,12 @@ nvme_ns_identify(struct nvme_softc *sc, 
 
 	KASSERT(nsid > 0);
 
+	ns = nvme_ns_get(sc, nsid);
+	KASSERT(ns);
+
+	if (ns->ident != NULL)
+		return 0;
+
 	ccb = nvme_ccb_get(sc->sc_admin_q, false);
 	KASSERT(ccb != NULL); /* it's a bug if we don't have spare ccb here */
 
@@ -665,9 +671,6 @@ nvme_ns_identify(struct nvme_softc *sc, 
 	/* Convert data to host endian */
 	nvme_identify_namespace_swapbytes(identify);
 
-	ns = nvme_ns_get(sc, nsid);
-	KASSERT(ns);
-	KASSERT(ns->ident == NULL);
 	ns->ident = identify;
 
 done:



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

2020-11-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 16 18:21:45 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_wm.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1133):

sys/dev/pci/if_wm.c: revision 1.696

Fix little-endian dependence in wm_rxeof(), by which packets cannot be
received by 82574 and successors on big-endian machines.

Tested by aarch64eb with I210-T1 on ROCKPro64.

Thanks msaitoh for discussion!
XXX
pullup to netbsd-9 and netbsd-8


To generate a diff of this commit:
cvs rdiff -u -r1.645.2.9 -r1.645.2.10 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.645.2.9 src/sys/dev/pci/if_wm.c:1.645.2.10
--- src/sys/dev/pci/if_wm.c:1.645.2.9	Wed Nov  4 11:48:26 2020
+++ src/sys/dev/pci/if_wm.c	Mon Nov 16 18:21:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.645.2.9 2020/11/04 11:48:26 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.645.2.10 2020/11/16 18:21:45 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.9 2020/11/04 11:48:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.10 2020/11/16 18:21:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8875,9 +8875,11 @@ wm_rxdesc_get_status(struct wm_rxqueue *
 	struct wm_softc *sc = rxq->rxq_sc;
 
 	if (sc->sc_type == WM_T_82574)
-		return EXTRXC_STATUS(rxq->rxq_ext_descs[idx].erx_ctx.erxc_err_stat);
+		return EXTRXC_STATUS(
+		le32toh(rxq->rxq_ext_descs[idx].erx_ctx.erxc_err_stat));
 	else if ((sc->sc_flags & WM_F_NEWQUEUE) != 0)
-		return NQRXC_STATUS(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_err_stat);
+		return NQRXC_STATUS(
+		le32toh(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_err_stat));
 	else
 		return rxq->rxq_descs[idx].wrx_status;
 }
@@ -,9 +8890,11 @@ wm_rxdesc_get_errors(struct wm_rxqueue *
 	struct wm_softc *sc = rxq->rxq_sc;
 
 	if (sc->sc_type == WM_T_82574)
-		return EXTRXC_ERROR(rxq->rxq_ext_descs[idx].erx_ctx.erxc_err_stat);
+		return EXTRXC_ERROR(
+		le32toh(rxq->rxq_ext_descs[idx].erx_ctx.erxc_err_stat));
 	else if ((sc->sc_flags & WM_F_NEWQUEUE) != 0)
-		return NQRXC_ERROR(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_err_stat);
+		return NQRXC_ERROR(
+		le32toh(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_err_stat));
 	else
 		return rxq->rxq_descs[idx].wrx_errors;
 }



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

2020-11-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Nov  4 11:48:26 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_wm.c if_wmvar.h

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

sys/dev/pci/if_wm.c: revision 1.694
sys/dev/pci/if_wm.c: revision 1.695 (via patch)
sys/dev/pci/if_wmvar.h: revision 1.47

Add WMPHY_I350. Not used yet.

Workaround for ihphy and atphy(ICH*/PCH*, 82580 and I350).
These phys stop DMA while link is down which causes device timeout.
Fix PR/kern 40981
Reviewed and tested by msaitoh@n.o, thanks.
XXX pullup-[89]


To generate a diff of this commit:
cvs rdiff -u -r1.645.2.8 -r1.645.2.9 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.44.4.2 -r1.44.4.3 src/sys/dev/pci/if_wmvar.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.645.2.8 src/sys/dev/pci/if_wm.c:1.645.2.9
--- src/sys/dev/pci/if_wm.c:1.645.2.8	Fri Oct 16 08:03:36 2020
+++ src/sys/dev/pci/if_wm.c	Wed Nov  4 11:48:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.645.2.8 2020/10/16 08:03:36 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.645.2.9 2020/11/04 11:48:26 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.8 2020/10/16 08:03:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.9 2020/11/04 11:48:26 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -375,7 +375,8 @@ struct wm_txqueue {
 	 * to manage Tx H/W queue's busy flag.
 	 */
 	int txq_flags;			/* flags for H/W queue, see below */
-#define	WM_TXQ_NO_SPACE	0x1
+#define	WM_TXQ_NO_SPACE		0x1
+#define	WM_TXQ_LINKDOWN_DISCARD	0x2
 
 	bool txq_stopping;
 
@@ -1031,6 +1032,9 @@ static void	wm_toggle_lanphypc_pch_lpt(s
 static int	wm_platform_pm_pch_lpt(struct wm_softc *, bool);
 static int	wm_pll_workaround_i210(struct wm_softc *);
 static void	wm_legacy_irq_quirk_spt(struct wm_softc *);
+static bool	wm_phy_need_linkdown_discard(struct wm_softc *);
+static void	wm_set_linkdown_discard(struct wm_softc *);
+static void	wm_clear_linkdown_discard(struct wm_softc *);
 
 CFATTACH_DECL3_NEW(wm, sizeof(struct wm_softc),
 wm_match, wm_attach, wm_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
@@ -3077,6 +3081,9 @@ alloc_retry:
 
 	sc->sc_txrx_use_workqueue = false;
 
+	if (wm_phy_need_linkdown_discard(sc))
+		wm_set_linkdown_discard(sc);
+
 	wm_init_sysctls(sc);
 
 	if (pmf_device_register(self, wm_suspend, wm_resume))
@@ -3455,6 +3462,49 @@ out:
 	return rc;
 }
 
+static bool
+wm_phy_need_linkdown_discard(struct wm_softc *sc)
+{
+
+	switch(sc->sc_phytype) {
+	case WMPHY_82577: /* ihphy */
+	case WMPHY_82578: /* atphy */
+	case WMPHY_82579: /* ihphy */
+	case WMPHY_I217: /* ihphy */
+	case WMPHY_82580: /* ihphy */
+	case WMPHY_I350: /* ihphy */
+		return true;
+	default:
+		return false;
+	}
+}
+
+static void
+wm_set_linkdown_discard(struct wm_softc *sc)
+{
+
+	for (int i = 0; i < sc->sc_nqueues; i++) {
+		struct wm_txqueue *txq = >sc_queue[i].wmq_txq;
+
+		mutex_enter(txq->txq_lock);
+		txq->txq_flags |= WM_TXQ_LINKDOWN_DISCARD;
+		mutex_exit(txq->txq_lock);
+	}
+}
+
+static void
+wm_clear_linkdown_discard(struct wm_softc *sc)
+{
+
+	for (int i = 0; i < sc->sc_nqueues; i++) {
+		struct wm_txqueue *txq = >sc_queue[i].wmq_txq;
+
+		mutex_enter(txq->txq_lock);
+		txq->txq_flags &= ~WM_TXQ_LINKDOWN_DISCARD;
+		mutex_exit(txq->txq_lock);
+	}
+}
+
 /*
  * wm_ioctl:		[ifnet interface function]
  *
@@ -3498,6 +3548,12 @@ wm_ioctl(struct ifnet *ifp, u_long cmd, 
 #ifdef WM_MPSAFE
 		splx(s);
 #endif
+		if (error == 0 && wm_phy_need_linkdown_discard(sc)) {
+			if (IFM_SUBTYPE(ifr->ifr_media) == IFM_NONE)
+wm_set_linkdown_discard(sc);
+			else
+wm_clear_linkdown_discard(sc);
+		}
 		break;
 	case SIOCINITIFADDR:
 		WM_CORE_LOCK(sc);
@@ -3512,8 +3568,17 @@ wm_ioctl(struct ifnet *ifp, u_long cmd, 
 			break;
 		}
 		WM_CORE_UNLOCK(sc);
+		if (((ifp->if_flags & IFF_UP) == 0) && wm_phy_need_linkdown_discard(sc))
+			wm_clear_linkdown_discard(sc);
 		/*FALLTHROUGH*/
 	default:
+		if (cmd == SIOCSIFFLAGS && wm_phy_need_linkdown_discard(sc)) {
+			if (((ifp->if_flags & IFF_UP) == 0) && ((ifr->ifr_flags & IFF_UP) != 0)) {
+wm_clear_linkdown_discard(sc);
+			} else if (((ifp->if_flags & IFF_UP) != 0) && ((ifr->ifr_flags & IFF_UP) == 0)) {
+wm_set_linkdown_discard(sc);
+			}
+		}
 #ifdef WM_MPSAFE
 		s = splnet();
 #endif
@@ -7627,6 +7692,16 @@ wm_select_txqueue(struct ifnet *ifp, str
 	return ((cpuid + ncpu - sc->sc_affinity_offset) % ncpu) % sc->sc_nqueues;
 }
 
+static inline bool
+wm_linkdown_discard(struct wm_txqueue *txq)
+{
+
+	if ((txq->txq_flags & WM_TXQ_LINKDOWN_DISCARD) != 0)
+		return true;
+
+	return false;
+}
+
 /*
  * wm_start:		[ifnet interface function]
  *
@@ -7721,6 +7796,23 @@ 

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

2020-10-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Oct 16 08:03:36 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_wm.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1114):

sys/dev/pci/if_wm.c: revision 1.691

  Fixes a problem that the attach function reported
"wm_gmii_setup_phytype: Unknown PHY model. OUI=00, model=" and
"PHY type is still unknown." Don't call wm_gmii_setup_phytype() three times if
the interface uses SGMII with internal MDIO.

  Tested with I354(Rangeley(SGMII(MDIO))) and I350(SERDES(SFP), SGMII(SFP)).


To generate a diff of this commit:
cvs rdiff -u -r1.645.2.7 -r1.645.2.8 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.645.2.7 src/sys/dev/pci/if_wm.c:1.645.2.8
--- src/sys/dev/pci/if_wm.c:1.645.2.7	Wed Sep 23 08:46:54 2020
+++ src/sys/dev/pci/if_wm.c	Fri Oct 16 08:03:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.645.2.7 2020/09/23 08:46:54 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.645.2.8 2020/10/16 08:03:36 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.7 2020/09/23 08:46:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.8 2020/10/16 08:03:36 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2860,7 +2860,8 @@ alloc_retry:
 			reg &= ~CTRL_EXT_I2C_ENA;
 		CSR_WRITE(sc, WMREG_CTRL_EXT, reg);
 		if ((sc->sc_flags & WM_F_SGMII) != 0) {
-			wm_gmii_setup_phytype(sc, 0, 0);
+			if (!wm_sgmii_uses_mdio(sc))
+wm_gmii_setup_phytype(sc, 0, 0);
 			wm_reset_mdicnfg_82580(sc);
 		}
 	} else if (sc->sc_type < WM_T_82543 ||



CVS commit: [netbsd-9] src/sys/dev/usb

2020-10-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 15 12:03:23 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ums.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1112):

sys/dev/usb/ums.c: revision 1.94
sys/dev/usb/ums.c: revision 1.99

Initialize tcpalib for ums devices.

In r1.3 of src/sys/dev/hid/hidms.c, tpcalib is used for any hidms
device reporting absolute coordinates. So ums devices reporting
absolute coordinates also need to initialize tcpalib - do it for
all ums devices. An uninitialized tcpalib stops a mouse with
absolute coordinates from "moving".

For absolute pointers, report min/max X and Y values using
WSMOUSEIO_[SG]CALIBCOORDS ioctl.


To generate a diff of this commit:
cvs rdiff -u -r1.93.2.3 -r1.93.2.4 src/sys/dev/usb/ums.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/usb/ums.c
diff -u src/sys/dev/usb/ums.c:1.93.2.3 src/sys/dev/usb/ums.c:1.93.2.4
--- src/sys/dev/usb/ums.c:1.93.2.3	Tue Jan 21 19:54:55 2020
+++ src/sys/dev/usb/ums.c	Thu Oct 15 12:03:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ums.c,v 1.93.2.3 2020/01/21 19:54:55 martin Exp $	*/
+/*	$NetBSD: ums.c,v 1.93.2.4 2020/10/15 12:03:23 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.93.2.3 2020/01/21 19:54:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.93.2.4 2020/10/15 12:03:23 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -137,6 +137,8 @@ ums_attach(device_t parent, device_t sel
 {
 	struct ums_softc *sc = device_private(self);
 	struct uhidev_attach_arg *uha = aux;
+	struct hid_data *d;
+	struct hid_item item;
 	int size, error;
 	void *desc;
 	uint32_t quirks;
@@ -203,6 +205,36 @@ ums_attach(device_t parent, device_t sel
 		sc->sc_alwayson = true;
 	}
 
+	tpcalib_init(>sc_ms.sc_tpcalib);
+
+	/* calibrate the pointer if it reports absolute events */
+	if (sc->sc_ms.flags & HIDMS_ABS) {
+		memset(>sc_ms.sc_calibcoords, 0, sizeof(sc->sc_ms.sc_calibcoords));
+		sc->sc_ms.sc_calibcoords.maxx = 0;
+		sc->sc_ms.sc_calibcoords.maxy = 0;
+		sc->sc_ms.sc_calibcoords.samplelen = WSMOUSE_CALIBCOORDS_RESET;
+		d = hid_start_parse(desc, size, hid_input);
+		if (d != NULL) {
+			while (hid_get_item(d, )) {
+if (item.kind != hid_input
+|| HID_GET_USAGE_PAGE(item.usage) != HUP_GENERIC_DESKTOP
+|| item.report_ID != sc->sc_hdev.sc_report_id)
+	continue;
+if (HID_GET_USAGE(item.usage) == HUG_X) {
+	sc->sc_ms.sc_calibcoords.minx = item.logical_minimum;
+	sc->sc_ms.sc_calibcoords.maxx = item.logical_maximum;
+}
+if (HID_GET_USAGE(item.usage) == HUG_Y) {
+	sc->sc_ms.sc_calibcoords.miny = item.logical_minimum;
+	sc->sc_ms.sc_calibcoords.maxy = item.logical_maximum;
+}
+			}
+			hid_end_parse(d);
+		}
+	tpcalib_ioctl(>sc_ms.sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
+	(void *)>sc_ms.sc_calibcoords, 0, 0);
+	}
+
 	hidms_attach(self, >sc_ms, _accessops);
 
 	if (sc->sc_alwayson) {
@@ -315,10 +347,18 @@ ums_disable(void *v)
 
 Static int
 ums_ioctl(void *v, u_long cmd, void *data, int flag,
-struct lwp * p)
+struct lwp *l)
 
 {
 	struct ums_softc *sc = v;
+	int error;
+
+	if (sc->sc_ms.flags & HIDMS_ABS) {
+		error = tpcalib_ioctl(>sc_ms.sc_tpcalib, cmd, data,
+		flag, l);
+		if (error != EPASSTHROUGH)
+			return error;
+	}
 
 	switch (cmd) {
 	case WSMOUSEIO_GTYPE:



CVS commit: [netbsd-9] src/sys/dev/fdt

2020-10-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Oct  4 18:22:00 UTC 2020

Modified Files:
src/sys/dev/fdt [netbsd-9]: dw_apb_uart.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1096):

sys/dev/fdt/dw_apb_uart.c: revision 1.8

Revert rev 1.5:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/fdt/dw_apb_uart.c#rev1.5

The device is capable to recognize break signal actually.
Reset cnmagic from + to default.

Pointed out by jakllsch. Thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.2.1 src/sys/dev/fdt/dw_apb_uart.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/fdt/dw_apb_uart.c
diff -u src/sys/dev/fdt/dw_apb_uart.c:1.5 src/sys/dev/fdt/dw_apb_uart.c:1.5.2.1
--- src/sys/dev/fdt/dw_apb_uart.c:1.5	Sun Jul 21 15:57:23 2019
+++ src/sys/dev/fdt/dw_apb_uart.c	Sun Oct  4 18:22:00 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dw_apb_uart.c,v 1.5 2019/07/21 15:57:23 rin Exp $ */
+/* $NetBSD: dw_apb_uart.c,v 1.5.2.1 2020/10/04 18:22:00 martin Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.5 2019/07/21 15:57:23 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dw_apb_uart.c,v 1.5.2.1 2020/10/04 18:22:00 martin Exp $");
 
 #include 
 #include 
@@ -182,8 +182,6 @@ dw_apb_uart_console_consinit(struct fdt_
 
 	if (comcnattach(bst, addr, speed, uart_freq, COM_TYPE_DW_APB, flags))
 		panic("Cannot initialize dw-apb-uart console");
-
-	cn_set_magic("+");
 }
 
 static const struct fdt_console dw_apb_uart_console = {



CVS commit: [netbsd-9] src/sys/dev/ic

2020-09-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 27 10:30:16 UTC 2020

Modified Files:
src/sys/dev/ic [netbsd-9]: ld_nvme.c nvme.c

Log Message:
Pull up following revision(s) (requested by kardel in ticket #1094):

sys/dev/ic/ld_nvme.c: revision 1.24
sys/dev/ic/nvme.c: revision 1.50

PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.1 -r1.22.2.2 src/sys/dev/ic/ld_nvme.c
cvs rdiff -u -r1.44.2.3 -r1.44.2.4 src/sys/dev/ic/nvme.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/ic/ld_nvme.c
diff -u src/sys/dev/ic/ld_nvme.c:1.22.2.1 src/sys/dev/ic/ld_nvme.c:1.22.2.2
--- src/sys/dev/ic/ld_nvme.c:1.22.2.1	Mon Oct 28 18:30:43 2019
+++ src/sys/dev/ic/ld_nvme.c	Sun Sep 27 10:30:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_nvme.c,v 1.22.2.1 2019/10/28 18:30:43 martin Exp $	*/
+/*	$NetBSD: ld_nvme.c,v 1.22.2.2 2020/09/27 10:30:16 martin Exp $	*/
 
 /*-
  * Copyright (C) 2016 NONAKA Kimihiro 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.22.2.1 2019/10/28 18:30:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.22.2.2 2020/09/27 10:30:16 martin Exp $");
 
 #include 
 #include 
@@ -86,7 +86,6 @@ ld_nvme_attach(device_t parent, device_t
 	struct nvme_attach_args *naa = aux;
 	struct nvme_namespace *ns;
 	struct nvm_namespace_format *f;
-	int error;
 
 	ld->sc_dv = self;
 	sc->sc_nvme = nsc;
@@ -95,28 +94,11 @@ ld_nvme_attach(device_t parent, device_t
 	aprint_naive("\n");
 	aprint_normal("\n");
 
-	error = nvme_ns_identify(sc->sc_nvme, sc->sc_nsid);
-	if (error) {
-		aprint_error_dev(self, "couldn't identify namespace\n");
-		return;
-	}
-
 	ns = nvme_ns_get(sc->sc_nvme, sc->sc_nsid);
 	KASSERT(ns);
-	f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
 
-	/*
-	 * NVME1.0e 6.11 Identify command
-	 *
-	 * LBADS values smaller than 9 are not supported, a value
-	 * of zero means that the format is not used.
-	 */
-	if (f->lbads < 9) {
-		if (f->lbads > 0)
-			aprint_error_dev(self,
-			"unsupported logical data size %u\n", f->lbads);
-		return;
-	}
+	f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
+	KASSERT(f->lbads >= 9); /* only valid LBS data sizes allowed here */
 
 	ld->sc_secsize = 1 << f->lbads;
 	ld->sc_secperunit = ns->ident->nsze;

Index: src/sys/dev/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.44.2.3 src/sys/dev/ic/nvme.c:1.44.2.4
--- src/sys/dev/ic/nvme.c:1.44.2.3	Mon Nov 11 17:15:42 2019
+++ src/sys/dev/ic/nvme.c	Sun Sep 27 10:30:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.44.2.3 2019/11/11 17:15:42 martin Exp $	*/
+/*	$NetBSD: nvme.c,v 1.44.2.4 2020/09/27 10:30:16 martin Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.3 2019/11/11 17:15:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.44.2.4 2020/09/27 10:30:16 martin Exp $");
 
 #include 
 #include 
@@ -471,23 +471,52 @@ nvme_rescan(device_t self, const char *a
 {
 	struct nvme_softc *sc = device_private(self);
 	struct nvme_attach_args naa;
+	struct nvm_namespace_format *f;
+	struct nvme_namespace *ns;
 	uint64_t cap;
 	int ioq_entries = nvme_ioq_size;
 	int i;
+	int error;
 
 	cap = nvme_read8(sc, NVME_CAP);
 	if (ioq_entries > NVME_CAP_MQES(cap))
 		ioq_entries = NVME_CAP_MQES(cap);
 
-	for (i = 0; i < sc->sc_nn; i++) {
-		if (sc->sc_namespaces[i].dev)
+	for (i = 1; i <= sc->sc_nn; i++) {
+		if (sc->sc_namespaces[i - 1].dev)
+			continue;
+
+		/* identify to check for availability */
+		error = nvme_ns_identify(sc, i);
+		if (error) {
+			aprint_error_dev(self, "couldn't identify namespace #%d\n", i);
+			continue;
+		}
+
+		ns = nvme_ns_get(sc, i);
+		KASSERT(ns);
+
+		f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
+
+		/*
+		 * NVME1.0e 6.11 Identify command
+		 *
+		 * LBADS values smaller than 9 are not supported, a value
+		 * of zero means that the format is not used.
+		 */
+		if (f->lbads < 9) {
+			if (f->lbads > 0)
+aprint_error_dev(self,
+		 "unsupported logical data size %u\n", f->lbads);
 			continue;
+		}
+
 		memset(, 0, sizeof(naa));
-		naa.naa_nsid = i + 1;
+		naa.naa_nsid = i;
 		naa.naa_qentries = (ioq_entries - 1) * sc->sc_nq;
 		naa.naa_maxphys = sc->sc_mdts;
 		naa.naa_typename = sc->sc_modelname;
-		sc->sc_namespaces[i].dev = config_found(sc->sc_dev, ,
+		sc->sc_namespaces[i - 1].dev = config_found(sc->sc_dev, ,
 		nvme_print);
 	}
 	return 0;



CVS commit: [netbsd-9] src/sys/dev

2020-09-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep 23 08:46:54 UTC 2020

Modified Files:
src/sys/dev/mii [netbsd-9]: inbmphyreg.h
src/sys/dev/pci [netbsd-9]: if_wm.c if_wmreg.h if_wmvar.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1093):

sys/dev/pci/if_wmreg.h: revision 1.120
sys/dev/pci/if_wmvar.h: revision 1.46
sys/dev/pci/if_wm.c: revision 1.686
sys/dev/pci/if_wm.c: revision 1.687
sys/dev/mii/inbmphyreg.h: revision 1.20
sys/dev/pci/if_wm.c: revision 1.688
sys/dev/pci/if_wm.c: revision 1.689

s/ressource/resource/. Found by knakahara.

  Add new flag named WM_F_CRC_STRIP and use it. No functional change.

  This change also sets the RCTL_SECRC bit on I211 but it doesn't change
the behavior because I211 always strips CRC like I35[04] and I210.

  Add a workaround for jumbo frame on PCH2 and newer. Tested by chs@.

- Add wm_lv_jumbo_workaround_ich8lan() and use it. From FreeBSD.
   XXX For KUMCTRLSTA_OFFSET_HD_CTRL register modification, it's doubtful.
   FreeBSD and Linux do the same thing that they set the same value on both
   jumbo frame's enable case and the disable case. It seems the default value
   is 0x0b0c and it's not changed on the enable case, so it might be a bug
   on the enable case or the modification is not required.
- Rename I219_UNKNOWN1 to I82579_UNKNOWN1.
  Use 12K for packet buffer for jumbo frame on PCH2 and newer.

XXX Note that Linux Use 14K.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.18.4.1 src/sys/dev/mii/inbmphyreg.h
cvs rdiff -u -r1.645.2.6 -r1.645.2.7 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.115.2.2 -r1.115.2.3 src/sys/dev/pci/if_wmreg.h
cvs rdiff -u -r1.44.4.1 -r1.44.4.2 src/sys/dev/pci/if_wmvar.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/dev/mii/inbmphyreg.h
diff -u src/sys/dev/mii/inbmphyreg.h:1.18 src/sys/dev/mii/inbmphyreg.h:1.18.4.1
--- src/sys/dev/mii/inbmphyreg.h:1.18	Thu Jan 31 15:30:23 2019
+++ src/sys/dev/mii/inbmphyreg.h	Wed Sep 23 08:46:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inbmphyreg.h,v 1.18 2019/01/31 15:30:23 msaitoh Exp $	*/
+/*	$NetBSD: inbmphyreg.h,v 1.18.4.1 2020/09/23 08:46:54 martin Exp $	*/
 /***
 Copyright (c) 2001-2015, Intel Corporation 
 All rights reserved.
@@ -136,6 +136,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define	BM_PORT_GEN_CFG		BME1000_REG(BM_PORT_CTRL_PAGE, 17)
 
+#define	I82579_DFT_CTRL		BME1000_REG(BM_PORT_CTRL_PAGE, 20)
+
 #define	CV_SMB_CTRL		BME1000_REG(BM_PORT_CTRL_PAGE, 23)
 #define	CV_SMB_CTRL_FORCE_SMBUS	__BIT(0)
 
@@ -180,7 +182,8 @@ POSSIBILITY OF SUCH DAMAGE.
 #define HV_MUX_DATA_CTRL_FORCE_SPEED	(1 << 2)
 #define HV_MUX_DATA_CTRL_GEN_TO_MAC	(1 << 10)
 
-#define I219_UNKNOWN1		BME1000_REG(776, 20)
+#define I82579_UNKNOWN1		BME1000_REG(776, 20)
+#define I82579_TX_PTR_GAP	0x1f
 
 #define I218_ULP_CONFIG1	BME1000_REG(779, 16)
 #define I218_ULP_CONFIG1_START		__BIT(0)

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.645.2.6 src/sys/dev/pci/if_wm.c:1.645.2.7
--- src/sys/dev/pci/if_wm.c:1.645.2.6	Wed Aug  5 15:14:18 2020
+++ src/sys/dev/pci/if_wm.c	Wed Sep 23 08:46:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.645.2.6 2020/08/05 15:14:18 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.645.2.7 2020/09/23 08:46:54 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.6 2020/08/05 15:14:18 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.7 2020/09/23 08:46:54 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1015,6 +1015,8 @@ static int	wm_kmrn_lock_loss_workaround_
 static void	wm_gig_downshift_workaround_ich8lan(struct wm_softc *);
 static int	wm_hv_phy_workarounds_ich8lan(struct wm_softc *);
 static void	wm_copy_rx_addrs_to_phy_ich8lan(struct wm_softc *);
+static void	wm_copy_rx_addrs_to_phy_ich8lan_locked(struct wm_softc *);
+static int	wm_lv_jumbo_workaround_ich8lan(struct wm_softc *, bool);
 static int	wm_lv_phy_workarounds_ich8lan(struct wm_softc *);
 static int	wm_k1_workaround_lpt_lp(struct wm_softc *, bool);
 static int	wm_k1_gig_workaround_hv(struct wm_softc *, int);
@@ -2885,6 +2887,14 @@ alloc_retry:
 			sc->sc_flags |= WM_F_EEE;
 	}
 
+	/*
+	 * The I350 has a bug where it always strips the CRC whether
+	 * asked to or not. So ask for stripped CRC here and cope in rxeof
+	 */
+	if ((sc->sc_type == WM_T_I350) || (sc->sc_type == WM_T_I354)
+	|| (sc->sc_type == WM_T_I210) || (sc->sc_type == WM_T_I211))
+		sc->sc_flags |= WM_F_CRC_STRIP;
+
 	/* Set device properties (macflags) */
 	prop_dictionary_set_uint32(dict, "macflags", sc->sc_flags);
 
@@ -3791,7 +3801,7 @@ wm_set_filter(struct wm_softc *sc)
 	struct ether_multistep step;
 	bus_addr_t mta_reg;
 	

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

2020-09-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 20 10:16:50 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: virtio_pci.c

Log Message:
Pull up following revision(s) (requested by jakllsch in ticket #1090):

sys/dev/pci/virtio_pci.c: revision 1.13

Ensure MSI-X is disabled if allocation of MSI-X interrupts fail.

The virtio device config space moves out from under us when MSI-X
remains enabled, and/or INTx interrupts are masked if we don't ensure
this.

This un-breaks virtio devices that run out of MSI-X interrupts.
Particularly a problem on uniproc x86, where there are only 8 or 9
vectors available, allowing for only about 4 virtio devices to use
MSI-X.


To generate a diff of this commit:
cvs rdiff -u -r1.7.4.1 -r1.7.4.2 src/sys/dev/pci/virtio_pci.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/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.7.4.1 src/sys/dev/pci/virtio_pci.c:1.7.4.2
--- src/sys/dev/pci/virtio_pci.c:1.7.4.1	Sun Sep 20 10:03:11 2020
+++ src/sys/dev/pci/virtio_pci.c	Sun Sep 20 10:16:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.7.4.1 2020/09/20 10:03:11 martin Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.7.4.2 2020/09/20 10:16:50 martin Exp $ */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.7.4.1 2020/09/20 10:03:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.7.4.2 2020/09/20 10:16:50 martin Exp $");
 
 #include 
 #include 
@@ -662,10 +662,13 @@ virtio_pci_setup_interrupts(struct virti
 	struct virtio_pci_softc * const psc = (struct virtio_pci_softc *)sc;
 	device_t self = sc->sc_dev;
 	pci_chipset_tag_t pc = psc->sc_pa.pa_pc;
+	pcitag_t tag = psc->sc_pa.pa_tag;
 	int error;
 	int nmsix;
+	int off;
 	int counts[PCI_INTR_TYPE_SIZE];
 	pci_intr_type_t max_type;
+	pcireg_t ctl;
 
 	nmsix = pci_msix_count(psc->sc_pa.pa_pc, psc->sc_pa.pa_tag);
 	aprint_debug_dev(self, "pci_msix_count=%d\n", nmsix);
@@ -726,6 +729,13 @@ retry:
 
 		psc->sc_ihs_num = 1;
 		psc->sc_config_offset = VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI;
+
+	error = pci_get_capability(pc, tag, PCI_CAP_MSIX, , NULL);
+		if (error != 0) {
+			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);
+		}
 	}
 
 	return 0;



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

2020-09-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 20 10:03:11 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: virtio_pci.c

Log Message:
Pull up following revision(s) (requested by jakllsch in ticket #1089):

sys/dev/pci/virtio_pci.c: revision 1.12

Ensure interrupt handles buffer is zeroed on allocation
Prevents crashes trying to deallocate interrupts at shutdown.

Found by kim and mlelstv, confirmed by me


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/dev/pci/virtio_pci.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/virtio_pci.c
diff -u src/sys/dev/pci/virtio_pci.c:1.7 src/sys/dev/pci/virtio_pci.c:1.7.4.1
--- src/sys/dev/pci/virtio_pci.c:1.7	Sun Jan 27 02:08:42 2019
+++ src/sys/dev/pci/virtio_pci.c	Sun Sep 20 10:03:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.7 2019/01/27 02:08:42 pgoyette Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.7.4.1 2020/09/20 10:03:11 martin Exp $ */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.7 2019/01/27 02:08:42 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.7.4.1 2020/09/20 10:03:11 martin Exp $");
 
 #include 
 #include 
@@ -697,7 +697,7 @@ retry:
 	}
 
 	if (pci_intr_type(pc, psc->sc_ihp[0]) == PCI_INTR_TYPE_MSIX) {
-		psc->sc_ihs = kmem_alloc(sizeof(*psc->sc_ihs) * nmsix,
+		psc->sc_ihs = kmem_zalloc(sizeof(*psc->sc_ihs) * nmsix,
 		KM_SLEEP);
 
 		error = virtio_pci_setup_msix_interrupts(sc, >sc_pa);
@@ -714,7 +714,7 @@ retry:
 		psc->sc_ihs_num = nmsix;
 		psc->sc_config_offset = VIRTIO_CONFIG_DEVICE_CONFIG_MSI;
 	} else if (pci_intr_type(pc, psc->sc_ihp[0]) == PCI_INTR_TYPE_INTX) {
-		psc->sc_ihs = kmem_alloc(sizeof(*psc->sc_ihs) * 1,
+		psc->sc_ihs = kmem_zalloc(sizeof(*psc->sc_ihs) * 1,
 		KM_SLEEP);
 
 		error = virtio_pci_setup_intx_interrupt(sc, >sc_pa);



CVS commit: [netbsd-9] src/sys/dev/hid

2020-09-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Sep 19 12:16:14 UTC 2020

Modified Files:
src/sys/dev/hid [netbsd-9]: hidkbdmap.c

Log Message:
Pull up following revision(s) (requested by nonaka in ticket #1086):

sys/dev/hid/hidkbdmap.c: revision 1.11

for jp keymap map also scan code 49 to right bracket to handle ARCHISS model
PR kern/55608 by Shinichi Doyashiki


To generate a diff of this commit:
cvs rdiff -u -r1.1.10.2 -r1.1.10.3 src/sys/dev/hid/hidkbdmap.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/hid/hidkbdmap.c
diff -u src/sys/dev/hid/hidkbdmap.c:1.1.10.2 src/sys/dev/hid/hidkbdmap.c:1.1.10.3
--- src/sys/dev/hid/hidkbdmap.c:1.1.10.2	Mon Jul 13 14:22:47 2020
+++ src/sys/dev/hid/hidkbdmap.c	Sat Sep 19 12:16:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hidkbdmap.c,v 1.1.10.2 2020/07/13 14:22:47 martin Exp $	*/
+/*	$NetBSD: hidkbdmap.c,v 1.1.10.3 2020/09/19 12:16:14 martin Exp $	*/
 
 /*
  * Copyright (c) 1999,2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hidkbdmap.c,v 1.1.10.2 2020/07/13 14:22:47 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hidkbdmap.c,v 1.1.10.3 2020/09/19 12:16:14 martin Exp $");
 
 #include 
 #include 
@@ -171,7 +171,8 @@ Static const keysym_t hidkbd_keydesc_jp[
 KC(46),			KS_asciicircum,		KS_asciitilde,
 KC(47),			KS_at,			KS_grave,
 KC(48),			KS_bracketleft,		KS_braceleft,
-KC(50),			KS_bracketright,	KS_braceright,
+KC(49), /* ARCHISS */	KS_bracketright,	KS_braceright,
+KC(50), /* other model */	KS_bracketright,	KS_braceright,
 KC(51),			KS_semicolon,		KS_plus,
 KC(52),			KS_colon,		KS_asterisk,
 KC(53), 			KS_Zenkaku_Hankaku, /* replace grave/tilde */



CVS commit: [netbsd-9] src/sys/dev/ic

2020-09-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep 16 13:29:53 UTC 2020

Modified Files:
src/sys/dev/ic [netbsd-9]: mpt_netbsd.c

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #1085):

sys/dev/ic/mpt_netbsd.c: revision 1.37

max_devices is a 8bit value and zero is interpreted as 256. This value
can be reported by an mpt device emulated by VMware ESXi.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.36.2.1 src/sys/dev/ic/mpt_netbsd.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/ic/mpt_netbsd.c
diff -u src/sys/dev/ic/mpt_netbsd.c:1.36 src/sys/dev/ic/mpt_netbsd.c:1.36.2.1
--- src/sys/dev/ic/mpt_netbsd.c:1.36	Wed May  8 06:32:01 2019
+++ src/sys/dev/ic/mpt_netbsd.c	Wed Sep 16 13:29:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpt_netbsd.c,v 1.36 2019/05/08 06:32:01 cnst Exp $	*/
+/*	$NetBSD: mpt_netbsd.c,v 1.36.2.1 2020/09/16 13:29:53 martin Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.36 2019/05/08 06:32:01 cnst Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.36.2.1 2020/09/16 13:29:53 martin Exp $");
 
 #include "bio.h"
 
@@ -150,7 +150,7 @@ mpt_scsipi_attach(mpt_softc_t *mpt)
 	chan->chan_channel = 0;
 	chan->chan_flags = 0;
 	chan->chan_nluns = 8;
-	chan->chan_ntargets = mpt->mpt_max_devices;
+	chan->chan_ntargets = mpt->mpt_max_devices ? mpt->mpt_max_devices : 256;
 	chan->chan_id = mpt->mpt_ini_id;
 
 	/*



CVS commit: [netbsd-9] src/sys/dev/nvmm/x86

2020-09-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 13 11:56:44 UTC 2020

Modified Files:
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1078):

sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.73
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.73
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.74

nvmm-x86-vmx: improve the handling of CR4
 - Filter out certain features we don't want the guest to enable. This is
   for general correctness, and future-proofness.
 - Flush the guest TLB when certain flags change.

nvmm-x86: improve the handling of RFLAGS.RF
 - When injecting certain exceptions, set RF. For us to have an up-to-date
   view of RFLAGS, we commit the state before the event.
 - When advancing RIP, clear RF.


To generate a diff of this commit:
cvs rdiff -u -r1.46.4.12 -r1.46.4.13 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.36.2.14 -r1.36.2.15 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.12 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.13
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.12	Sun Sep 13 11:54:10 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Sun Sep 13 11:56:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.12 2020/09/13 11:54:10 martin Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.13 2020/09/13 11:56:44 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.12 2020/09/13 11:54:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.13 2020/09/13 11:56:44 martin Exp $");
 
 #include 
 #include 
@@ -666,8 +666,22 @@ svm_event_waitexit_disable(struct nvmm_c
 	svm_vmcb_cache_flush(vmcb, VMCB_CTRL_VMCB_CLEAN_I);
 }
 
+static inline bool
+svm_excp_has_rf(uint8_t vector)
+{
+	switch (vector) {
+	case 1:		/* #DB */
+	case 4:		/* #OF */
+	case 8:		/* #DF */
+	case 18:	/* #MC */
+		return false;
+	default:
+		return true;
+	}
+}
+
 static inline int
-svm_event_has_error(uint8_t vector)
+svm_excp_has_error(uint8_t vector)
 {
 	switch (vector) {
 	case 8:		/* #DF */
@@ -707,7 +721,10 @@ svm_vcpu_inject(struct nvmm_cpu *vcpu)
 			return EINVAL;
 		if (vector == 3 || vector == 0)
 			return EINVAL;
-		err = svm_event_has_error(vector);
+		if (svm_excp_has_rf(vector)) {
+			vmcb->state.rflags |= PSL_RF;
+		}
+		err = svm_excp_has_error(vector);
 		break;
 	case NVMM_VCPU_EVENT_INTR:
 		type = SVM_EVENT_TYPE_HW_INT;
@@ -780,6 +797,7 @@ svm_inkernel_advance(struct vmcb *vmcb)
 	 * debugger.
 	 */
 	vmcb->state.rip = vmcb->ctrl.nrip;
+	vmcb->state.rflags &= ~PSL_RF;
 	vmcb->ctrl.intr &= ~VMCB_CTRL_INTR_SHADOW;
 }
 
@@ -1472,11 +1490,12 @@ svm_vcpu_run(struct nvmm_machine *mach, 
 	uint64_t machgen;
 	int hcpu, s;
 
+	svm_vcpu_state_commit(vcpu);
+	comm->state_cached = 0;
+
 	if (__predict_false(svm_vcpu_event_commit(vcpu) != 0)) {
 		return EINVAL;
 	}
-	svm_vcpu_state_commit(vcpu);
-	comm->state_cached = 0;
 
 	kpreempt_disable();
 	hcpu = cpu_number();

Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.14 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.15
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.14	Sun Sep 13 11:54:10 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Sun Sep 13 11:56:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_vmx.c,v 1.36.2.14 2020/09/13 11:54:10 martin Exp $	*/
+/*	$NetBSD: nvmm_x86_vmx.c,v 1.36.2.15 2020/09/13 11:56:44 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.36.2.14 2020/09/13 11:54:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.36.2.15 2020/09/13 11:56:44 martin Exp $");
 
 #include 
 #include 
@@ -717,6 +717,33 @@ static uint64_t vmx_xcr0_mask __read_mos
 #define MSRBM_NPAGES	1
 #define MSRBM_SIZE	(MSRBM_NPAGES * PAGE_SIZE)
 
+#define CR4_VALID \
+	(CR4_VME |			\
+	 CR4_PVI |			\
+	 CR4_TSD |			\
+	 CR4_DE |			\
+	 CR4_PSE |			\
+	 CR4_PAE |			\
+	 CR4_MCE |			\
+	 CR4_PGE |			\
+	 CR4_PCE |			\
+	 CR4_OSFXSR |			\
+	 CR4_OSXMMEXCPT |		\
+	 CR4_UMIP |			\
+	 /* CR4_LA57 excluded */	\
+	 /* CR4_VMXE excluded */	\
+	 /* CR4_SMXE excluded */	\
+	 CR4_FSGSBASE |			\
+	 CR4_PCIDE |			\
+	 CR4_OSXSAVE |			\
+	 CR4_SMEP |			\
+	 CR4_SMAP			\
+	 /* CR4_PKE excluded */		\
+	 /* CR4_CET excluded */		\
+	 /* CR4_PKS excluded */)
+#define CR4_INVALID \
+	(0xULL & ~CR4_VALID)
+
 #define EFER_TLB_FLUSH \
 	(EFER_NXE|EFER_LMA|EFER_LME)
 #define CR0_TLB_FLUSH \
@@ -1001,8 +1028,22 @@ vmx_event_waitexit_disable(struct nvmm_c
 	vmx_vmwrite(VMCS_PROCBASED_CTLS, ctls1);
 }
 
+static inline bool
+vmx_excp_has_rf(uint8_t vector)
+{

CVS commit: [netbsd-9] src/sys/dev/nvmm/x86

2020-09-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 13 11:54:10 UTC 2020

Modified Files:
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86.c nvmm_x86_svm.c
nvmm_x86_vmx.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1077):

sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.68
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.74
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.16

Improve emulation of MSR_IA32_ARCH_CAPABILITIES: publish only the *_NO
bits. Initially they were the only ones there, but Intel then added other
bits we aren't interested in, and they must be filtered out.

nvmm-x86-svm: improve the handling of MSR_EFER

Intercept reads of it as well, just to mask EFER_SVME, which the guest
doesn't need to see.

nvmm-x86: improve the CPUID emulation

 - Mask DTES64, DS_CPL, CID, SDBG, xTPR, PN.
 - B10, B20 and IA64 do not exist, so just remove them.


To generate a diff of this commit:
cvs rdiff -u -r1.7.4.5 -r1.7.4.6 src/sys/dev/nvmm/x86/nvmm_x86.c
cvs rdiff -u -r1.46.4.11 -r1.46.4.12 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.36.2.13 -r1.36.2.14 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/x86/nvmm_x86.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.5 src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.6
--- src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.5	Sat Aug 29 17:00:28 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86.c	Sun Sep 13 11:54:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86.c,v 1.7.4.5 2020/08/29 17:00:28 martin Exp $	*/
+/*	$NetBSD: nvmm_x86.c,v 1.7.4.6 2020/09/13 11:54:10 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.7.4.5 2020/08/29 17:00:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.7.4.6 2020/09/13 11:54:10 martin Exp $");
 
 #include 
 #include 
@@ -235,19 +235,19 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	.ecx =
 	CPUID2_SSE3 |
 	CPUID2_PCLMUL |
-	CPUID2_DTES64 |
+	/* CPUID2_DTES64 excluded */
 	/* CPUID2_MONITOR excluded */
-	CPUID2_DS_CPL |
+	/* CPUID2_DS_CPL excluded */
 	/* CPUID2_VMX excluded */
 	/* CPUID2_SMX excluded */
 	/* CPUID2_EST excluded */
 	/* CPUID2_TM2 excluded */
 	CPUID2_SSSE3 |
-	CPUID2_CID |
-	CPUID2_SDBG |
+	/* CPUID2_CID excluded */
+	/* CPUID2_SDBG excluded */
 	CPUID2_FMA |
 	CPUID2_CX16 |
-	CPUID2_xTPR |
+	/* CPUID2_xTPR excluded */
 	/* CPUID2_PDCM excluded */
 	/* CPUID2_PCID excluded, but re-included in VMX */
 	/* CPUID2_DCA excluded */
@@ -275,7 +275,6 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	/* CPUID_MCE excluded */
 	CPUID_CX8 |
 	CPUID_APIC |
-	CPUID_B10 |	
 	CPUID_SEP |
 	/* CPUID_MTRR excluded */
 	CPUID_PGE |
@@ -283,9 +282,8 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	CPUID_CMOV |
 	CPUID_PAT |
 	CPUID_PSE36 |
-	CPUID_PN |
+	/* CPUID_PN excluded */
 	CPUID_CFLUSH |
-	CPUID_B20 |
 	/* CPUID_DS excluded */
 	/* CPUID_ACPI excluded */
 	CPUID_MMX |
@@ -295,7 +293,6 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	CPUID_SS |
 	CPUID_HTT |
 	/* CPUID_TM excluded */
-	CPUID_IA64 |
 	CPUID_SBF
 };
 

Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.11 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.12
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.11	Fri Sep  4 18:53:43 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Sun Sep 13 11:54:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.11 2020/09/04 18:53:43 martin Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.12 2020/09/13 11:54:10 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.11 2020/09/04 18:53:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.12 2020/09/13 11:54:10 martin Exp $");
 
 #include 
 #include 
@@ -1142,6 +1142,12 @@ svm_inkernel_handle_msr(struct nvmm_mach
 	size_t i;
 
 	if (exit->reason == NVMM_VCPU_EXIT_RDMSR) {
+		if (exit->u.rdmsr.msr == MSR_EFER) {
+			val = vmcb->state.efer & ~EFER_SVME;
+			vmcb->state.rax = (val & 0x);
+			cpudata->gprs[NVMM_X64_GPR_RDX] = (val >> 32);
+			goto handled;
+		}
 		if (exit->u.rdmsr.msr == MSR_NB_CFG) {
 			val = NB_CFG_INITAPICCPUIDLO;
 			vmcb->state.rax = (val & 0x);
@@ -2169,7 +2175,6 @@ svm_vcpu_init(struct nvmm_machine *mach,
 
 	/* Allow direct access to certain MSRs. */
 	memset(cpudata->msrbm, 0xFF, MSRBM_SIZE);
-	svm_vcpu_msr_allow(cpudata->msrbm, MSR_EFER, true, false);
 	svm_vcpu_msr_allow(cpudata->msrbm, MSR_STAR, true, true);
 	svm_vcpu_msr_allow(cpudata->msrbm, MSR_LSTAR, true, true);
 	svm_vcpu_msr_allow(cpudata->msrbm, MSR_CSTAR, 

CVS commit: [netbsd-9] src/sys/dev/pci/ixgbe

2020-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  2 12:34:55 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-9]: if_bypass.c ixgbe.c ixgbe_common.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1070):

sys/dev/pci/ixgbe/if_bypass.c: revision 1.6
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.28
sys/dev/pci/ixgbe/ixgbe.c: revision 1.246

Fix checking return value of atomic_cas_uint().

This change fixes a bug that extra delay() is called only once even if
atomic_cas_uint() isn't failed or delay() isn't called when atomic_cas_uint()
failed.

The reason of this bug was that I simply converted FreeBSD' atomic_cmpset_int()
to atomic_cas_uint(). The return value's semantics is different.

 -

Minor change.
  - Print "X550EM X" instead of "X550EM" for Xeon D devices.
  - Fix typo in comment. Same as FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.4.8.1 -r1.4.8.2 src/sys/dev/pci/ixgbe/if_bypass.c
cvs rdiff -u -r1.199.2.11 -r1.199.2.12 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.25.2.2 -r1.25.2.3 src/sys/dev/pci/ixgbe/ixgbe_common.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/if_bypass.c
diff -u src/sys/dev/pci/ixgbe/if_bypass.c:1.4.8.1 src/sys/dev/pci/ixgbe/if_bypass.c:1.4.8.2
--- src/sys/dev/pci/ixgbe/if_bypass.c:1.4.8.1	Sun Jan 26 11:03:17 2020
+++ src/sys/dev/pci/ixgbe/if_bypass.c	Wed Sep  2 12:34:55 2020
@@ -45,9 +45,9 @@
 static void
 ixgbe_bypass_mutex_enter(struct adapter *adapter)
 {
-	while (atomic_cas_uint(>bypass.low, 0, 1) == 0)
+	while (atomic_cas_uint(>bypass.low, 0, 1) != 0)
 		usec_delay(3000);
-	while (atomic_cas_uint(>bypass.high, 0, 1) == 0)
+	while (atomic_cas_uint(>bypass.high, 0, 1) != 0)
 		usec_delay(3000);
 	return;
 } /* ixgbe_bypass_mutex_enter */
@@ -58,9 +58,9 @@ ixgbe_bypass_mutex_enter(struct adapter 
 static void
 ixgbe_bypass_mutex_clear(struct adapter *adapter)
 {
-	while (atomic_cas_uint(>bypass.high, 1, 0) == 0)
+	while (atomic_cas_uint(>bypass.high, 1, 0) != 1)
 		usec_delay(6000);
-	while (atomic_cas_uint(>bypass.low, 1, 0) == 0)
+	while (atomic_cas_uint(>bypass.low, 1, 0) != 1)
 		usec_delay(6000);
 	return;
 } /* ixgbe_bypass_mutex_clear */
@@ -73,7 +73,7 @@ ixgbe_bypass_mutex_clear(struct adapter 
 static void
 ixgbe_bypass_wd_mutex_enter(struct adapter *adapter)
 {
-	while (atomic_cas_uint(>bypass.high, 0, 1) == 0)
+	while (atomic_cas_uint(>bypass.high, 0, 1) != 0)
 		usec_delay(3000);
 	return;
 } /* ixgbe_bypass_wd_mutex_enter */
@@ -84,7 +84,7 @@ ixgbe_bypass_wd_mutex_enter(struct adapt
 static void
 ixgbe_bypass_wd_mutex_clear(struct adapter *adapter)
 {
-	while (atomic_cas_uint(>bypass.high, 1, 0) == 0)
+	while (atomic_cas_uint(>bypass.high, 1, 0) != 1)
 		usec_delay(6000);
 	return;
 } /* ixgbe_bypass_wd_mutex_clear */
@@ -585,7 +585,7 @@ ixgbe_bp_log(SYSCTLFN_ARGS)
 		return (error);
 
 	/* Keep the log display single-threaded */
-	while (atomic_cas_uint(>bypass.log, 0, 1) == 0)
+	while (atomic_cas_uint(>bypass.log, 0, 1) != 0)
 		usec_delay(3000);
 
 	ixgbe_bypass_mutex_enter(adapter);
@@ -713,14 +713,14 @@ ixgbe_bp_log(SYSCTLFN_ARGS)
 
 	status = 0; /* reset */
 	/* Another log command can now run */
-	while (atomic_cas_uint(>bypass.log, 1, 0) == 0)
+	while (atomic_cas_uint(>bypass.log, 1, 0) != 1)
 		usec_delay(3000);
 	return (error);
 
 unlock_err:
 	ixgbe_bypass_mutex_clear(adapter);
 	status = 0; /* reset */
-	while (atomic_cas_uint(>bypass.log, 1, 0) == 0)
+	while (atomic_cas_uint(>bypass.log, 1, 0) != 1)
 		usec_delay(3000);
 	return (EINVAL);
 } /* ixgbe_bp_log */

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.11 src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.12
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.11	Fri Jul 10 11:35:51 2020
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Sep  2 12:34:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.199.2.11 2020/07/10 11:35:51 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.199.2.12 2020/09/02 12:34:55 martin Exp $ */
 
 /**
 
@@ -861,7 +861,7 @@ ixgbe_attach(device_t parent, device_t d
 		str = "X550";
 		break;
 	case ixgbe_mac_X550EM_x:
-		str = "X550EM";
+		str = "X550EM X";
 		break;
 	case ixgbe_mac_X550EM_a:
 		str = "X550EM A";

Index: src/sys/dev/pci/ixgbe/ixgbe_common.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_common.c:1.25.2.2 src/sys/dev/pci/ixgbe/ixgbe_common.c:1.25.2.3
--- src/sys/dev/pci/ixgbe/ixgbe_common.c:1.25.2.2	Fri Jul 10 11:35:51 2020
+++ src/sys/dev/pci/ixgbe/ixgbe_common.c	Wed Sep  2 12:34:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_common.c,v 1.25.2.2 2020/07/10 11:35:51 martin Exp $ */
+/* $NetBSD: ixgbe_common.c,v 1.25.2.3 2020/09/02 12:34:55 martin Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -5234,7 

CVS commit: [netbsd-9] src/sys/dev/nvmm

2020-08-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Aug 29 17:00:28 UTC 2020

Modified Files:
src/sys/dev/nvmm [netbsd-9]: nvmm.c nvmm_ioctl.h
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86.c nvmm_x86_svm.c
nvmm_x86_svmfunc.S nvmm_x86_vmx.c nvmm_x86_vmxfunc.S

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1068):

sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.71
sys/dev/nvmm/nvmm.c: revision 1.34
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.72
sys/dev/nvmm/nvmm.c: revision 1.35
sys/dev/nvmm/nvmm.c: revision 1.36
sys/dev/nvmm/x86/nvmm_x86_svmfunc.S: revision 1.5
sys/dev/nvmm/nvmm.c: revision 1.37
sys/dev/nvmm/x86/nvmm_x86_vmxfunc.S: revision 1.5
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.70
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.68
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.15
sys/dev/nvmm/nvmm_ioctl.h: revision 1.10

Micro-optimize: use pushq instead of pushw. To avoid LCP stalls and
unaligned stack accesses.

nvmm-x86: also flush the guest TLB when CR4.{PCIDE,SMEP} changes

nvmm: localify a variable that doesn't need to be global

nvmm: use relaxed atomics to read nmachines

nvmm-x86-svm: dedup code

nvmm-x86: hide more CPUID flags, mostly related to perf monitors

nvmm: misc improvements
 - use mach->ncpus to get the number of vcpus, now that we have it
 - don't forget to decrement mach->ncpus when a machine gets killed
 - add more __predict_false()

nvmm-x86-svm: don't forget to intercept INVD
INVD executed in the guest can be dangerous for the host, due to CPU
caches being flushed without write-back.

nvmm: slightly clarify

nvmm: explicitly include atomic.h


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.6 -r1.22.2.7 src/sys/dev/nvmm/nvmm.c
cvs rdiff -u -r1.7.4.1 -r1.7.4.2 src/sys/dev/nvmm/nvmm_ioctl.h
cvs rdiff -u -r1.7.4.4 -r1.7.4.5 src/sys/dev/nvmm/x86/nvmm_x86.c
cvs rdiff -u -r1.46.4.9 -r1.46.4.10 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.3 -r1.3.4.1 src/sys/dev/nvmm/x86/nvmm_x86_svmfunc.S \
src/sys/dev/nvmm/x86/nvmm_x86_vmxfunc.S
cvs rdiff -u -r1.36.2.11 -r1.36.2.12 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/nvmm.c
diff -u src/sys/dev/nvmm/nvmm.c:1.22.2.6 src/sys/dev/nvmm/nvmm.c:1.22.2.7
--- src/sys/dev/nvmm/nvmm.c:1.22.2.6	Tue Aug 18 09:29:52 2020
+++ src/sys/dev/nvmm/nvmm.c	Sat Aug 29 17:00:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.c,v 1.22.2.6 2020/08/18 09:29:52 martin Exp $	*/
+/*	$NetBSD: nvmm.c,v 1.22.2.7 2020/08/29 17:00:28 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.22.2.6 2020/08/18 09:29:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.22.2.7 2020/08/29 17:00:28 martin Exp $");
 
 #include 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -112,17 +113,17 @@ nvmm_machine_get(struct nvmm_owner *owne
 	struct nvmm_machine *mach;
 	krw_t op = writer ? RW_WRITER : RW_READER;
 
-	if (machid >= NVMM_MAX_MACHINES) {
+	if (__predict_false(machid >= NVMM_MAX_MACHINES)) {
 		return EINVAL;
 	}
 	mach = [machid];
 
 	rw_enter(>lock, op);
-	if (!mach->present) {
+	if (__predict_false(!mach->present)) {
 		rw_exit(>lock);
 		return ENOENT;
 	}
-	if (owner != _owner && mach->owner != owner) {
+	if (__predict_false(mach->owner != owner && owner != _owner)) {
 		rw_exit(>lock);
 		return EPERM;
 	}
@@ -179,13 +180,13 @@ nvmm_vcpu_get(struct nvmm_machine *mach,
 {
 	struct nvmm_cpu *vcpu;
 
-	if (cpuid >= NVMM_MAX_VCPUS) {
+	if (__predict_false(cpuid >= NVMM_MAX_VCPUS)) {
 		return EINVAL;
 	}
 	vcpu = >cpus[cpuid];
 
 	mutex_enter(>lock);
-	if (!vcpu->present) {
+	if (__predict_false(!vcpu->present)) {
 		mutex_exit(>lock);
 		return ENOENT;
 	}
@@ -227,6 +228,7 @@ nvmm_kill_machines(struct nvmm_owner *ow
 			(*nvmm_impl->vcpu_destroy)(mach, vcpu);
 			nvmm_vcpu_free(mach, vcpu);
 			nvmm_vcpu_put(vcpu);
+			atomic_dec_uint(>ncpus);
 		}
 		(*nvmm_impl->machine_destroy)(mach);
 		uvmspace_free(mach->vm);
@@ -314,6 +316,7 @@ nvmm_machine_destroy(struct nvmm_owner *
 		(*nvmm_impl->vcpu_destroy)(mach, vcpu);
 		nvmm_vcpu_free(mach, vcpu);
 		nvmm_vcpu_put(vcpu);
+		atomic_dec_uint(>ncpus);
 	}
 
 	(*nvmm_impl->machine_destroy)(mach);
@@ -414,7 +417,6 @@ nvmm_vcpu_create(struct nvmm_owner *owne
 	}
 
 	nvmm_vcpu_put(vcpu);
-
 	atomic_inc_uint(>ncpus);
 
 out:
@@ -440,7 +442,6 @@ nvmm_vcpu_destroy(struct nvmm_owner *own
 	(*nvmm_impl->vcpu_destroy)(mach, vcpu);
 	nvmm_vcpu_free(mach, vcpu);
 	nvmm_vcpu_put(vcpu);
-
 	atomic_dec_uint(>ncpus);
 
 out:
@@ -907,7 +908,6 @@ nvmm_ctl_mach_info(struct nvmm_owner *ow
 {
 	struct nvmm_ctl_mach_info ctl;
 	struct nvmm_machine *mach;
-	struct nvmm_cpu *vcpu;
 	int error;
 	size_t i;
 
@@ -921,14 +921,7 

CVS commit: [netbsd-9] src/sys/dev/usb

2020-08-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug 28 19:36:34 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: if_atu.c usbnet.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1067):

sys/dev/usb/usbnet.c: revision 1.39
sys/dev/usb/if_atu.c: revision 1.73

usbnet: Reject buflen>MCLBYTES in usbnet_newbuf.
atu(4): Reject packets larger than MCLBYTES.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.65.2.1 src/sys/dev/usb/if_atu.c
cvs rdiff -u -r1.25.2.4 -r1.25.2.5 src/sys/dev/usb/usbnet.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/usb/if_atu.c
diff -u src/sys/dev/usb/if_atu.c:1.65 src/sys/dev/usb/if_atu.c:1.65.2.1
--- src/sys/dev/usb/if_atu.c:1.65	Sun May  5 03:17:54 2019
+++ src/sys/dev/usb/if_atu.c	Fri Aug 28 19:36:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_atu.c,v 1.65 2019/05/05 03:17:54 mrg Exp $ */
+/*	$NetBSD: if_atu.c,v 1.65.2.1 2020/08/28 19:36:34 martin Exp $ */
 /*	$OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */
 /*
  * Copyright (c) 2003, 2004
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.65 2019/05/05 03:17:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.65.2.1 2020/08/28 19:36:34 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1680,6 +1680,10 @@ atu_rxeof(struct usbd_xfer *xfer, void *
 		DPRINTF(("%s: atu_rxeof: too short\n",
 		device_xname(sc->atu_dev)));
 		goto done;
+	} else if (len > MCLBYTES) {
+		DPRINTF(("%s: atu_rxeof: too long\n",
+		device_xname(sc->atu_dev)));
+		goto done;
 	}
 
 	h = (struct atu_rx_hdr *)c->atu_buf;

Index: src/sys/dev/usb/usbnet.c
diff -u src/sys/dev/usb/usbnet.c:1.25.2.4 src/sys/dev/usb/usbnet.c:1.25.2.5
--- src/sys/dev/usb/usbnet.c:1.25.2.4	Tue Dec 17 12:55:10 2019
+++ src/sys/dev/usb/usbnet.c	Fri Aug 28 19:36:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.25.2.4 2019/12/17 12:55:10 martin Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.25.2.5 2020/08/28 19:36:34 martin Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.4 2019/12/17 12:55:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.5 2020/08/28 19:36:34 martin Exp $");
 
 #include 
 #include 
@@ -227,6 +227,9 @@ usbnet_newbuf(size_t buflen)
 {
 	struct mbuf *m;
 
+	if (buflen > MCLBYTES)
+		return NULL;
+
 	MGETHDR(m, M_DONTWAIT, MT_DATA);
 	if (m == NULL)
 		return NULL;



CVS commit: [netbsd-9] src/sys/dev/usb

2020-08-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Aug 27 14:13:18 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ugen.c usbdevices.config

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1065):

sys/dev/usb/usbdevices.config: revision 1.41 (patch)
sys/dev/usb/ugen.c: revision 1.152
sys/dev/usb/ugen.c: revision 1.153
sys/dev/usb/ugen.c: revision 1.154
sys/dev/usb/ugen.c: revision 1.155 (patch)
sys/dev/usb/ugen.c: revision 1.156
sys/dev/usb/ugen.c: revision 1.157

Remove UGEN_ASLP microoptimization.
cv_signal already has this microoptimization.
While here, make the lock cover the relevant things we're issuing
cv_signal about -- progress toward real MP-safety.

Hold the lock over access to the data structures it covers.
Still not MPSAFE, but progress.

Convert DIAGNOSTIC prints to KASSERTs.

Share unit numbering for ugen and ugenif.
This way putting ugenif in kernel config actually works to wire it to
the /dev/ugenN.MM device nodes in userland.

Not a fully fleshed out solution to the ugen problem -- there's no
way for a userland driver to kick out a kernel driver and take over,
but this will let us, e.g., use uhidev(4) for Yubikey OTP/U2F/FIDO2
but ugen(4), with pcscd(8), for Yubikey CCID.

Fix various MP-safety issues while here (still not MPSAFE, but more
progress).

Expose Yubikey CCID interface to userland via ugenif.

Fix sloppy mistakes in previous.
1. Give the offset of the rbnode, not some other random members to
   overwrite with garbage.
2. Don't try to unlock a mutex at NULL.
3. Make sure all paths out after ugenif_acquire go via
   ugenif_release.

Fix ugen detach after partial attach.

While here, register null pmf handler even for partially attached
devices so they don't needlessly interfere with suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.146.2.1 -r1.146.2.2 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.35.4.1 -r1.35.4.2 src/sys/dev/usb/usbdevices.config

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/usb/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.146.2.1 src/sys/dev/usb/ugen.c:1.146.2.2
--- src/sys/dev/usb/ugen.c:1.146.2.1	Wed Dec 11 14:56:36 2019
+++ src/sys/dev/usb/ugen.c	Thu Aug 27 14:13:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.146.2.1 2019/12/11 14:56:36 martin Exp $	*/
+/*	$NetBSD: ugen.c,v 1.146.2.2 2020/08/27 14:13:18 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.146.2.1 2019/12/11 14:56:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.146.2.2 2020/08/27 14:13:18 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -58,6 +58,8 @@ __KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.1
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -97,7 +99,6 @@ struct ugen_endpoint {
 	usb_endpoint_descriptor_t *edesc;
 	struct usbd_interface *iface;
 	int state;
-#define	UGEN_ASLP	0x02	/* waiting for data */
 #define UGEN_SHORT_OK	0x04	/* short xfers are OK */
 #define UGEN_BULK_RA	0x08	/* in bulk read-ahead mode */
 #define UGEN_BULK_WB	0x10	/* in bulk write-behind mode */
@@ -124,6 +125,8 @@ struct ugen_endpoint {
 struct ugen_softc {
 	device_t sc_dev;		/* base device */
 	struct usbd_device *sc_udev;
+	struct rb_node sc_node;
+	unsigned sc_unit;
 
 	kmutex_t		sc_lock;
 	kcondvar_t		sc_detach_cv;
@@ -136,8 +139,109 @@ struct ugen_softc {
 	int sc_refcnt;
 	char sc_buffer[UGEN_BBSIZE];
 	u_char sc_dying;
+	u_char sc_attached;
 };
 
+static struct {
+	kmutex_t	lock;
+	rb_tree_t	tree;
+} ugenif __cacheline_aligned;
+
+static int
+compare_ugen(void *cookie, const void *vsca, const void *vscb)
+{
+	const struct ugen_softc *sca = vsca;
+	const struct ugen_softc *scb = vscb;
+
+	if (sca->sc_unit < scb->sc_unit)
+		return -1;
+	if (sca->sc_unit > scb->sc_unit)
+		return +1;
+	return 0;
+}
+
+static int
+compare_ugen_key(void *cookie, const void *vsc, const void *vk)
+{
+	const struct ugen_softc *sc = vsc;
+	const unsigned *k = vk;
+
+	if (sc->sc_unit < *k)
+		return -1;
+	if (sc->sc_unit > *k)
+		return +1;
+	return 0;
+}
+
+static const rb_tree_ops_t ugenif_tree_ops = {
+	.rbto_compare_nodes = compare_ugen,
+	.rbto_compare_key = compare_ugen_key,
+	.rbto_node_offset = offsetof(struct ugen_softc, sc_node),
+};
+
+static void
+ugenif_get_unit(struct ugen_softc *sc)
+{
+	struct ugen_softc *sc0;
+	unsigned i;
+
+	mutex_enter();
+	for (i = 0, sc0 = RB_TREE_MIN();
+	 sc0 != NULL && i == sc0->sc_unit;
+	 i++, sc0 = RB_TREE_NEXT(, sc0))
+		KASSERT(i < UINT_MAX);
+	KASSERT(rb_tree_find_node(, ) == NULL);
+	sc->sc_unit = i;
+	sc0 = rb_tree_insert_node(, sc);
+	KASSERT(sc0 == sc);
+	KASSERT(rb_tree_find_node(, ) == sc);
+	mutex_exit();
+}
+
+static void
+ugenif_put_unit(struct ugen_softc *sc)
+{
+
+	mutex_enter();
+	

CVS commit: [netbsd-9] src/sys/dev/nvmm/x86

2020-08-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug 26 17:55:49 UTC 2020

Modified Files:
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86.c nvmm_x86.h nvmm_x86_svm.c
nvmm_x86_vmx.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1058):

sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.70
sys/dev/nvmm/x86/nvmm_x86.h: revision 1.19
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.69
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.71
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.69
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.11
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.12
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.13
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.14

Improve the CPUID emulation:
 - Hide SGX*, PKU, WAITPKG, and SKINIT, because they are not supported.
 - Hide HLE and RTM, part of TSX. Because TSX is just too buggy and we
   cannot guarantee that it remains enabled in the guest (if for example
   the host disables TSX while the guest is running). Nobody wants this
   crap anyway, so bye-bye.
 - Advertise FSREP_MOV, because no reason to hide it.

Hide OSPKE. NFC since the host never uses PKU, but still.

Improve the CPUID emulation on nvmm-intel:
 - Limit the highest extended leaf.
 - Limit 0x0007 to ECX=0, for future-proofness.

nvmm-x86-svm: improve the CPUID emulation

Limit the hypervisor range, and properly handle each basic leaf until 0xD.

nvmm-x86: advertise the SERIALIZE instruction, available on future CPUs

nvmm-x86: improve the CPUID emulation
 - x86-svm: explicitly handle 0x8007 and 0x8008. The latter
   contains extended features we must filter out. Apply the same in
   x86-vmx for symmetry.
 - x86-svm: explicitly handle extended leaves until 0x801F, and
   truncate to it.


To generate a diff of this commit:
cvs rdiff -u -r1.7.4.3 -r1.7.4.4 src/sys/dev/nvmm/x86/nvmm_x86.c
cvs rdiff -u -r1.15.4.1 -r1.15.4.2 src/sys/dev/nvmm/x86/nvmm_x86.h
cvs rdiff -u -r1.46.4.8 -r1.46.4.9 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.36.2.10 -r1.36.2.11 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/x86/nvmm_x86.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.3 src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.4
--- src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.3	Tue Aug 18 09:29:52 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86.c	Wed Aug 26 17:55:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86.c,v 1.7.4.3 2020/08/18 09:29:52 martin Exp $	*/
+/*	$NetBSD: nvmm_x86.c,v 1.7.4.4 2020/08/26 17:55:49 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.7.4.3 2020/08/18 09:29:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.7.4.4 2020/08/26 17:55:49 martin Exp $");
 
 #include 
 #include 
@@ -304,16 +304,16 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	.ebx =
 	CPUID_SEF_FSGSBASE |
 	/* CPUID_SEF_TSC_ADJUST excluded */
-	CPUID_SEF_SGX |
+	/* CPUID_SEF_SGX excluded */
 	CPUID_SEF_BMI1 |
-	CPUID_SEF_HLE |
+	/* CPUID_SEF_HLE excluded */
 	/* CPUID_SEF_AVX2 excluded */
 	CPUID_SEF_FDPEXONLY |
 	CPUID_SEF_SMEP |
 	CPUID_SEF_BMI2 |
 	CPUID_SEF_ERMS |
 	/* CPUID_SEF_INVPCID excluded, but re-included in VMX */
-	CPUID_SEF_RTM |
+	/* CPUID_SEF_RTM excluded */
 	/* CPUID_SEF_QM excluded */
 	CPUID_SEF_FPUCSDS |
 	/* CPUID_SEF_MPX excluded */
@@ -337,9 +337,9 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	CPUID_SEF_PREFETCHWT1 |
 	/* CPUID_SEF_AVX512_VBMI excluded */
 	CPUID_SEF_UMIP |
-	CPUID_SEF_PKU |
-	CPUID_SEF_OSPKE |
-	CPUID_SEF_WAITPKG |
+	/* CPUID_SEF_PKU excluded */
+	/* CPUID_SEF_OSPKE excluded */
+	/* CPUID_SEF_WAITPKG excluded */
 	/* CPUID_SEF_AVX512_VBMI2 excluded */
 	/* CPUID_SEF_CET_SS excluded */
 	CPUID_SEF_GFNI |
@@ -352,18 +352,18 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	/* CPUID_SEF_RDPID excluded */
 	CPUID_SEF_CLDEMOTE |
 	CPUID_SEF_MOVDIRI |
-	CPUID_SEF_MOVDIR64B |
-	CPUID_SEF_SGXLC,
+	CPUID_SEF_MOVDIR64B,
+	/* CPUID_SEF_SGXLC excluded */
 	/* CPUID_SEF_PKS excluded */
 	.edx =
 	/* CPUID_SEF_AVX512_4VNNIW excluded */
 	/* CPUID_SEF_AVX512_4FMAPS excluded */
-	/* CPUID_SEF_FSREP_MOV excluded */
+	CPUID_SEF_FSREP_MOV |
 	/* CPUID_SEF_AVX512_VP2INTERSECT excluded */
 	/* CPUID_SEF_SRBDS_CTRL excluded */
 	CPUID_SEF_MD_CLEAR |
 	/* CPUID_SEF_TSX_FORCE_ABORT excluded */
-	/* CPUID_SEF_SERIALIZE excluded */
+	CPUID_SEF_SERIALIZE |
 	/* CPUID_SEF_HYBRID excluded */
 	/* CPUID_SEF_TSXLDTRK excluded */
 	/* CPUID_SEF_CET_IBT excluded */
@@ -391,7 +391,7 @@ const struct nvmm_x86_cpuid_mask nvmm_cp
 	/* CPUID_OSVW excluded */
 	CPUID_IBS |
 	

CVS commit: [netbsd-9] src/sys/dev

2020-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug 18 09:36:36 UTC 2020

Modified Files:
src/sys/dev [netbsd-9]: ipmi.c

Log Message:
Pull up following revision(s) (requested by nonaka in ticket #1056):

sys/dev/ipmi.c: revision 1.5

ipmi(4): Fixed a bug that incorrect condition is notified.

When the value obtained from the sensor is below the lower limit of
the critical threshold, it is notified that the value is below the lower
limit of the warning threshold.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/dev/ipmi.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/ipmi.c
diff -u src/sys/dev/ipmi.c:1.4 src/sys/dev/ipmi.c:1.4.4.1
--- src/sys/dev/ipmi.c:1.4	Sat May 18 08:38:00 2019
+++ src/sys/dev/ipmi.c	Tue Aug 18 09:36:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipmi.c,v 1.4 2019/05/18 08:38:00 mlelstv Exp $ */
+/*	$NetBSD: ipmi.c,v 1.4.4.1 2020/08/18 09:36:36 martin Exp $ */
 
 /*
  * Copyright (c) 2019 Michael van Elst
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.4 2019/05/18 08:38:00 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipmi.c,v 1.4.4.1 2020/08/18 09:36:36 martin Exp $");
 
 #include 
 #include 
@@ -1632,14 +1632,14 @@ ipmi_sensor_status(struct ipmi_softc *sc
 		edata->value_cur > psensor->i_limits.sel_warnmax)
 			return ENVSYS_SWARNOVER;
 
-		if (psensor->i_props & PROP_WARNMIN &&
-		edata->value_cur < psensor->i_limits.sel_warnmin)
-			return ENVSYS_SWARNUNDER;
-
 		if (psensor->i_props & PROP_CRITMIN &&
 		edata->value_cur < psensor->i_limits.sel_critmin)
 			return ENVSYS_SCRITUNDER;
 
+		if (psensor->i_props & PROP_WARNMIN &&
+		edata->value_cur < psensor->i_limits.sel_warnmin)
+			return ENVSYS_SWARNUNDER;
+
 		break;
 
 	case IPMI_SENSOR_TYPE_INTRUSION:



CVS commit: [netbsd-9] src/sys/dev/nvmm

2020-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug 18 09:29:52 UTC 2020

Modified Files:
src/sys/dev/nvmm [netbsd-9]: nvmm.c nvmm.h nvmm_internal.h
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86.c nvmm_x86_svm.c
nvmm_x86_vmx.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1055):

sys/dev/nvmm/nvmm.h: revision 1.13
sys/dev/nvmm/nvmm.h: revision 1.14
sys/dev/nvmm/nvmm.c: revision 1.33
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.67
sys/dev/nvmm/nvmm_internal.h: revision 1.17
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.67
sys/dev/nvmm/x86/nvmm_x86.c: revision 1.10

Put the few x86-specific structures under #ifdef __x86_64__, for clarity.

Make it easier to understand what's going on, no functional change.

Add new field definitions.

Add new field definitions, and intercept everything, for future-proofness.

Add CTASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.5 -r1.22.2.6 src/sys/dev/nvmm/nvmm.c
cvs rdiff -u -r1.10.4.1 -r1.10.4.2 src/sys/dev/nvmm/nvmm.h
cvs rdiff -u -r1.12.2.4 -r1.12.2.5 src/sys/dev/nvmm/nvmm_internal.h
cvs rdiff -u -r1.7.4.2 -r1.7.4.3 src/sys/dev/nvmm/x86/nvmm_x86.c
cvs rdiff -u -r1.46.4.7 -r1.46.4.8 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.36.2.9 -r1.36.2.10 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/nvmm.c
diff -u src/sys/dev/nvmm/nvmm.c:1.22.2.5 src/sys/dev/nvmm/nvmm.c:1.22.2.6
--- src/sys/dev/nvmm/nvmm.c:1.22.2.5	Sun Aug  2 08:49:08 2020
+++ src/sys/dev/nvmm/nvmm.c	Tue Aug 18 09:29:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.c,v 1.22.2.5 2020/08/02 08:49:08 martin Exp $	*/
+/*	$NetBSD: nvmm.c,v 1.22.2.6 2020/08/18 09:29:52 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.22.2.5 2020/08/02 08:49:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.22.2.6 2020/08/18 09:29:52 martin Exp $");
 
 #include 
 #include 
@@ -59,8 +59,10 @@ static struct nvmm_machine machines[NVMM
 static volatile unsigned int nmachines __cacheline_aligned;
 
 static const struct nvmm_impl *nvmm_impl_list[] = {
+#if defined(__x86_64__)
 	_x86_svm,	/* x86 AMD SVM */
 	_x86_vmx	/* x86 Intel VMX */
+#endif
 };
 
 static const struct nvmm_impl *nvmm_impl = NULL;

Index: src/sys/dev/nvmm/nvmm.h
diff -u src/sys/dev/nvmm/nvmm.h:1.10.4.1 src/sys/dev/nvmm/nvmm.h:1.10.4.2
--- src/sys/dev/nvmm/nvmm.h:1.10.4.1	Sun Nov 10 12:58:30 2019
+++ src/sys/dev/nvmm/nvmm.h	Tue Aug 18 09:29:52 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: nvmm.h,v 1.10.4.1 2019/11/10 12:58:30 martin Exp $	*/
+/*	$NetBSD: nvmm.h,v 1.10.4.2 2020/08/18 09:29:52 martin Exp $	*/
 
 /*
- * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -44,7 +44,7 @@ typedef uint64_t	gvaddr_t;
 typedef uint32_t	nvmm_machid_t;
 typedef uint32_t	nvmm_cpuid_t;
 
-#ifdef __x86_64__
+#if defined(__x86_64__)
 #include 
 #endif
 
@@ -96,4 +96,9 @@ struct nvmm_comm_page {
 #define NVMM_COMM_CPUID(off)		\
 	((off >> 12) & 0xFF)
 
+#ifdef _KERNEL
+/* At most one page, for the NVMM_COMM_* macros. */
+CTASSERT(sizeof(struct nvmm_comm_page) <= PAGE_SIZE);
+#endif
+
 #endif

Index: src/sys/dev/nvmm/nvmm_internal.h
diff -u src/sys/dev/nvmm/nvmm_internal.h:1.12.2.4 src/sys/dev/nvmm/nvmm_internal.h:1.12.2.5
--- src/sys/dev/nvmm/nvmm_internal.h:1.12.2.4	Sun Aug  2 11:19:09 2020
+++ src/sys/dev/nvmm/nvmm_internal.h	Tue Aug 18 09:29:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_internal.h,v 1.12.2.4 2020/08/02 11:19:09 martin Exp $	*/
+/*	$NetBSD: nvmm_internal.h,v 1.12.2.5 2020/08/18 09:29:52 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -119,8 +119,10 @@ struct nvmm_impl {
 	struct nvmm_vcpu_exit *);
 };
 
+#if defined(__x86_64__)
 extern const struct nvmm_impl nvmm_x86_svm;
 extern const struct nvmm_impl nvmm_x86_vmx;
+#endif
 
 static inline bool
 nvmm_return_needed(void)

Index: src/sys/dev/nvmm/x86/nvmm_x86.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.2 src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.3
--- src/sys/dev/nvmm/x86/nvmm_x86.c:1.7.4.2	Thu May 21 10:52:58 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86.c	Tue Aug 18 09:29:52 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: nvmm_x86.c,v 1.7.4.2 2020/05/21 10:52:58 martin Exp $	*/
+/*	$NetBSD: nvmm_x86.c,v 1.7.4.3 2020/08/18 09:29:52 martin Exp $	*/
 
 /*
- * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86.c,v 1.7.4.2 2020/05/21 10:52:58 

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

2020-08-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug 17 11:29:31 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: cmdide.c

Log Message:
Pull up following revision(s) (requested by jdolecek in ticket #1054):

sys/dev/pci/cmdide.c: revision 1.46

remove explicit irqack() call for unexpected interrupt; this happens
normally during boot when running identify for the drive as polled
command, and fixes hard hang caused by the irqack() on a sun machine
the unexpected interrupt happens because cmdide doesn't respect
WDCTL_IDS bit and triggers interrupt also for polled commands

also reclassify the "bogus intr" as aprint_verbose() to avoid noise
on boot

discussed and tested by Martin Husemann


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.43.10.1 src/sys/dev/pci/cmdide.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/cmdide.c
diff -u src/sys/dev/pci/cmdide.c:1.43 src/sys/dev/pci/cmdide.c:1.43.10.1
--- src/sys/dev/pci/cmdide.c:1.43	Sun Oct 22 13:13:55 2017
+++ src/sys/dev/pci/cmdide.c	Mon Aug 17 11:29:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmdide.c,v 1.43 2017/10/22 13:13:55 jdolecek Exp $	*/
+/*	$NetBSD: cmdide.c,v 1.43.10.1 2020/08/17 11:29:31 martin Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cmdide.c,v 1.43 2017/10/22 13:13:55 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cmdide.c,v 1.43.10.1 2020/08/17 11:29:31 martin Exp $");
 
 #include 
 #include 
@@ -245,10 +245,9 @@ cmd_pci_intr(void *arg)
 		(i == 1 && (secirq & CMD_ARTTIM23_IRQ))) {
 			crv = wdcintr(wdc_cp);
 			if (crv == 0) {
-aprint_error("%s:%d: bogus intr\n",
+aprint_verbose("%s:%d: bogus intr\n",
 device_xname(
   sc->sc_wdcdev.sc_atac.atac_dev), i);
-sc->sc_wdcdev.irqack(wdc_cp);
 			} else
 rv = 1;
 		}



CVS commit: [netbsd-9] src/sys/dev

2020-08-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Aug 17 11:22:45 UTC 2020

Modified Files:
src/sys/dev/ic [netbsd-9]: bwfm.c bwfmreg.h bwfmvar.h
src/sys/dev/sdmmc [netbsd-9]: if_bwfm_sdio.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1052):

sys/dev/ic/bwfm.c: revision 1.28
sys/dev/ic/bwfm.c: revision 1.29
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.22
sys/dev/ic/bwfmreg.h: revision 1.7
sys/dev/ic/bwfmvar.h: revision 1.11
sys/dev/ic/bwfmvar.h: revision 1.12
(all via patch)

Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.

Need  for kmem_*.

Currently accidentally side-loaded by .

bwfm: Switch from pcq to pool_cache.
pcq_get is required to be serialized, but it's far from clear that it
is serialized here.


To generate a diff of this commit:
cvs rdiff -u -r1.14.6.2 -r1.14.6.3 src/sys/dev/ic/bwfm.c
cvs rdiff -u -r1.3.10.1 -r1.3.10.2 src/sys/dev/ic/bwfmreg.h
cvs rdiff -u -r1.3.6.1 -r1.3.6.2 src/sys/dev/ic/bwfmvar.h
cvs rdiff -u -r1.3.8.3 -r1.3.8.4 src/sys/dev/sdmmc/if_bwfm_sdio.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.14.6.2 src/sys/dev/ic/bwfm.c:1.14.6.3
--- src/sys/dev/ic/bwfm.c:1.14.6.2	Sun Aug  9 14:03:08 2020
+++ src/sys/dev/ic/bwfm.c	Mon Aug 17 11:22:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.14.6.2 2020/08/09 14:03:08 martin Exp $ */
+/* $NetBSD: bwfm.c,v 1.14.6.3 2020/08/17 11:22:45 martin Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -139,7 +139,6 @@ bwfm_attach(struct bwfm_softc *sc)
 {
 	struct ieee80211com *ic = >sc_ic;
 	struct ifnet *ifp = >sc_if;
-	struct bwfm_task *t;
 	char fw_version[BWFM_DCMD_SMLEN];
 	uint32_t bandlist[3];
 	uint32_t tmp;
@@ -151,12 +150,10 @@ bwfm_attach(struct bwfm_softc *sc)
 		printf("%s: could not create workqueue\n", DEVNAME(sc));
 		return;
 	}
-	sc->sc_freetask = pcq_create(BWFM_TASK_COUNT, KM_SLEEP);
-	for (i = 0; i < BWFM_TASK_COUNT; i++) {
-		t = >sc_task[i];
-		t->t_sc = sc;
-		pcq_put(sc->sc_freetask, t);
-	}
+	sc->sc_freetask = pool_cache_init(sizeof(struct bwfm_task), 0, 0, 0,
+	"bwfmtask", NULL, IPL_NET /* XXX IPL_SOFTNET? */,
+	NULL, NULL, NULL);
+	pool_prime(>sc_freetask->pc_pool, BWFM_TASK_COUNT);
 
 	/* Stop the device in case it was previously initialized */
 	bwfm_fwvar_cmd_set_int(sc, BWFM_C_DOWN, 1);
@@ -249,7 +246,7 @@ bwfm_attach(struct bwfm_softc *sc)
 	error = if_initialize(ifp);
 	if (error != 0) {
 		printf("%s: if_initialize failed(%d)\n", DEVNAME(sc), error);
-		pcq_destroy(sc->sc_freetask);
+		pool_cache_destroy(sc->sc_freetask);
 		workqueue_destroy(sc->sc_taskq);
 
 		return; /* Error */
@@ -289,7 +286,7 @@ bwfm_detach(struct bwfm_softc *sc, int f
 	if (sc->sc_taskq)
 		workqueue_destroy(sc->sc_taskq);
 	if (sc->sc_freetask)
-		pcq_destroy(sc->sc_freetask);
+		pool_cache_destroy(sc->sc_freetask);
 
 	return 0;
 }
@@ -600,12 +597,13 @@ bwfm_key_set(struct ieee80211com *ic, co
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return 0;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_KEY_SET;
 	t->t_key.key = wk;
 	memcpy(t->t_key.mac, mac, sizeof(t->t_key.mac));
@@ -691,12 +689,13 @@ bwfm_key_delete(struct ieee80211com *ic,
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return 0;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_KEY_DELETE;
 	t->t_key.key = wk;
 	memset(t->t_key.mac, 0, sizeof(t->t_key.mac));
@@ -725,12 +724,13 @@ bwfm_newstate(struct ieee80211com *ic, e
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return EIO;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_NEWSTATE;
 	t->t_newstate.state = nstate;
 	t->t_newstate.arg = arg;
@@ -808,7 +808,7 @@ bwfm_task(struct work *wk, void *arg)
 		panic("bwfm: unknown task command %d", t->t_cmd);
 	}
 
-	pcq_put(sc->sc_freetask, t);
+	pool_cache_put(sc->sc_freetask, t);
 }
 
 int
@@ -1906,13 +1906,14 @@ bwfm_rx_event(struct bwfm_softc *sc, str
 {
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		m_freem(m);
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return;
 	}
 
+	t->t_sc = sc;
 	

CVS commit: [netbsd-9] src/sys/dev

2020-08-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug 11 17:06:18 UTC 2020

Modified Files:
src/sys/dev [netbsd-9]: dev_verbose.h

Log Message:
Additionally pull up following revision(s) (requested by uwe in ticket #1037):

sys/dev/dev_verbose.h: revision 1.4

DEV_VERBOSE_DEFINE - use MODULE_CLASS_DRIVER to match the definition.
Catch up with previous to unbreak autoloading of verbose modules.
PR kern/55535


To generate a diff of this commit:
cvs rdiff -u -r1.2.26.1 -r1.2.26.2 src/sys/dev/dev_verbose.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/dev/dev_verbose.h
diff -u src/sys/dev/dev_verbose.h:1.2.26.1 src/sys/dev/dev_verbose.h:1.2.26.2
--- src/sys/dev/dev_verbose.h:1.2.26.1	Wed Aug  5 14:47:04 2020
+++ src/sys/dev/dev_verbose.h	Tue Aug 11 17:06:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dev_verbose.h,v 1.2.26.1 2020/08/05 14:47:04 martin Exp $ */
+/*	$NetBSD: dev_verbose.h,v 1.2.26.2 2020/08/11 17:06:18 martin Exp $ */
 
 /*
  * Redistribution and use in source and binary forms, with or without
@@ -96,7 +96,7 @@ tag ## _load_verbose(void)		\
 {	\
 	\
 	if (tag ## verbose_loaded == 0)	\
-		module_autoload(# tag "verbose", MODULE_CLASS_MISC);	\
+		module_autoload(# tag "verbose", MODULE_CLASS_DRIVER);	\
 }	\
 	\
 static const char *			\



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

2020-08-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  9 14:14:34 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: mpii.c

Log Message:
Pull up following revision(s) (requested by jnemeth in ticket #1044):

sys/dev/pci/mpii.c: revision 1.25

make this compile without bio(4)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.22.4.1 src/sys/dev/pci/mpii.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/mpii.c
diff -u src/sys/dev/pci/mpii.c:1.22 src/sys/dev/pci/mpii.c:1.22.4.1
--- src/sys/dev/pci/mpii.c:1.22	Mon Mar 11 14:35:22 2019
+++ src/sys/dev/pci/mpii.c	Sun Aug  9 14:14:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: mpii.c,v 1.22 2019/03/11 14:35:22 kardel Exp $ */
+/* $NetBSD: mpii.c,v 1.22.4.1 2020/08/09 14:14:34 martin Exp $ */
 /*	$OpenBSD: mpii.c,v 1.115 2018/08/14 05:22:21 jmatthew Exp $	*/
 /*
  * Copyright (c) 2010, 2012 Mike Belopuhov
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.22 2019/03/11 14:35:22 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpii.c,v 1.22.4.1 2020/08/09 14:14:34 martin Exp $");
 
 #include "bio.h"
 
@@ -244,8 +244,10 @@ struct mpii_softc {
 	struct workqueue	*sc_evt_ack_wq;
 	struct work		sc_evt_ack_work;
 
+#if NBIO > 0
 	struct sysmon_envsys	*sc_sme;
 	envsys_data_t		*sc_sensors;
+#endif
 };
 
 int	mpii_match(device_t, cfdata_t, void *);



CVS commit: [netbsd-9] src/sys/dev

2020-08-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  9 14:03:08 UTC 2020

Modified Files:
src/sys/dev/ic [netbsd-9]: bwfm.c
src/sys/dev/sdmmc [netbsd-9]: if_bwfm_sdio.c ld_sdmmc.c sdmmc.c
sdmmc_io.c sdmmc_ioreg.h sdmmc_mem.c sdmmcvar.h

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1042):

sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.19
sys/dev/sdmmc/ld_sdmmc.c: revision 1.38
sys/dev/sdmmc/sdmmcvar.h: revision 1.35
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.5
sys/dev/ic/bwfm.c: revision 1.26
sys/dev/ic/bwfm.c: revision 1.27
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.20
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.21
sys/dev/sdmmc/sdmmc_io.c: revision 1.20
sys/dev/sdmmc/sdmmc_mem.c: revision 1.72
sys/dev/sdmmc/sdmmc.c: revision 1.40
sys/dev/sdmmc/sdmmc_ioreg.h: revision 1.6
sys/dev/sdmmc/if_bwfm_sdio.c: revision 1.16

Don't pass empty mbufs to the network stack.

Avoid changing signedness bit with << in sdmmc_ioreg.h
Reported by 

If the controller doesn't support switch func (opcode 6) then skip
setting this but continue with other settings.  This allows us to use
a card, albeit at a lower speed.

Fix races in sdmmc tasks and teach ld@sdmmc to abort xfers on detach.
- Teach sdmmc_add_task to queue it only if not already queued.
- Remove now-redundant logic to avoid repeated queueing elsewhere.
- Teach sdmmc_del_task to wait until task has completed.
- Call sdmmc_del_task in various needful places.
- Replace abuse of pcq by a lock and a tailq.
  (pcq is multi-producer, _single_-consumer, but there are potentially
  multiple consumers here and really only one producer.)
- Teach ld_sdmmc to abort xfers on detach.
  (Mechanism is kinda kludgey but it'll do for now; any effort one is
  tempted to spend overhauling this should be spent overhauling sdmmc
  to support proper asynchronous commands.)
- Make sure ld_sdmmc_discard either returns failure or eventually calls
  ldenddiscard.

XXX Currently ld_sdmmc_detach aborts xfers _before_ ldbegindetach has
has committed to detaching or not.  This is currently necessary to
avoid a deadlock because ldbegindetach waits for xfers to drain --
which strikes me as wrong; ldbegindetach shouldn't wait for anything,
and should only make the decision to commit to detaching or not so
the caller can decide whether to abort xfers before we actually wait
for them in ldenddetach.

XXX pullup -- although this changes some kernel symbols (sdmmc_add_task
and sdmmc_del_task), it shouldn't affect any existing modules; the only
module that uses sdmmc is ld_sdmmc.kmod, which is `.if 0' in the build
so there shouldn't be any of them floating around.

Make this work on big endian machines

move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().
may fix panic i saw in after restarting wpa_supplicant.
from mlelstv.

only ask for SDPCMD_INTSTATUS_HMB_SW_MASK and SDPCMD_INTSTATUS_CHIPACTIVE
interrupts, not all of them.  we only ack these ones.
mostly fixes pinebookpro wifi hard hangs.  still is problematic and can
trigger interrupt storm that appears as a hard hang without NET_MPSAFE,
and a follow up, less clearly right, change will reduce that to a soft
hang of the interface that can be cleared with 'ifconfig bwfm0 down up',
and even often recovers itself now.

clear all interrupts, not just those we expect from the hostintmask.
this removes the final hard hang i have seen in pinebookpro wifi,
though one may still need to 'ifconfig bwfm0 down up' occasionally,
so we still have bugs to fix here (the hang is usually associated
with 'checksum error' from bwfm/sdio.)

Sort #includes.  Nix trailing whitespace.
No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.14.6.1 -r1.14.6.2 src/sys/dev/ic/bwfm.c
cvs rdiff -u -r1.3.8.2 -r1.3.8.3 src/sys/dev/sdmmc/if_bwfm_sdio.c
cvs rdiff -u -r1.36 -r1.36.4.1 src/sys/dev/sdmmc/ld_sdmmc.c
cvs rdiff -u -r1.36.4.1 -r1.36.4.2 src/sys/dev/sdmmc/sdmmc.c
cvs rdiff -u -r1.14.4.1 -r1.14.4.2 src/sys/dev/sdmmc/sdmmc_io.c
cvs rdiff -u -r1.3.2.1 -r1.3.2.2 src/sys/dev/sdmmc/sdmmc_ioreg.h
cvs rdiff -u -r1.68.2.1 -r1.68.2.2 src/sys/dev/sdmmc/sdmmc_mem.c
cvs rdiff -u -r1.30.4.1 -r1.30.4.2 src/sys/dev/sdmmc/sdmmcvar.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/dev/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.14.6.1 src/sys/dev/ic/bwfm.c:1.14.6.2
--- src/sys/dev/ic/bwfm.c:1.14.6.1	Tue Feb 25 18:40:43 2020
+++ src/sys/dev/ic/bwfm.c	Sun Aug  9 14:03:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.14.6.1 2020/02/25 18:40:43 martin Exp $ */
+/* $NetBSD: bwfm.c,v 1.14.6.2 2020/08/09 14:03:08 martin Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -18,21 

CVS commit: [netbsd-9] src/sys/dev/nvmm/x86

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 15:18:24 UTC 2020

Modified Files:
src/sys/dev/nvmm/x86 [netbsd-9]: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1041):

sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.66
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.50
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.66
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.46
sys/dev/nvmm/x86/nvmm_x86_vmx.c: revision 1.49
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.55
sys/dev/nvmm/x86/nvmm_x86_svm.c: revision 1.56

pg->phys_addr > VM_PAGE_TO_PHYS(pg)

Explicitly cast pointers to uintptr_t before casting to enums. They are
not necessarily the same size. Don't cast pointers to bool, check for
NULL instead.

vmx_vmptrst(): only used when DIAGNOSTIC

Simplify, remove unnecessary #ifdef DIAGNOSTIC around KASSERTs.

Use ULL, to make it clear we are unsigned.


To generate a diff of this commit:
cvs rdiff -u -r1.46.4.6 -r1.46.4.7 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.36.2.8 -r1.36.2.9 src/sys/dev/nvmm/x86/nvmm_x86_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/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.6 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.7
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.46.4.6	Sun Aug  2 08:49:08 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Wed Aug  5 15:18:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.6 2020/08/02 08:49:08 martin Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.46.4.7 2020/08/05 15:18:24 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.6 2020/08/02 08:49:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.46.4.7 2020/08/05 15:18:24 martin Exp $");
 
 #include 
 #include 
@@ -225,7 +225,7 @@ int svm_vmrun(paddr_t, uint64_t *);
 #define VMCB_EXITCODE_AVIC_INCOMP_IPI	0x0401
 #define VMCB_EXITCODE_AVIC_NOACCEL	0x0402
 #define VMCB_EXITCODE_VMGEXIT		0x0403
-#define VMCB_EXITCODE_INVALID		-1
+#define VMCB_EXITCODE_INVALID		-1ULL
 
 /* -- */
 
@@ -1507,7 +1507,7 @@ svm_memalloc(paddr_t *pa, vaddr_t *va, s
 	, 1, 0);
 	if (ret != 0)
 		return ENOMEM;
-	_pa = TAILQ_FIRST()->phys_addr;
+	_pa = VM_PAGE_TO_PHYS(TAILQ_FIRST());
 	_va = uvm_km_alloc(kernel_map, npages * PAGE_SIZE, 0,
 	UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
 	if (_va == 0)
@@ -2337,7 +2337,7 @@ svm_init_asid(uint32_t maxasid)
 static void
 svm_change_cpu(void *arg1, void *arg2)
 {
-	bool enable = (bool)arg1;
+	bool enable = arg1 != NULL;
 	uint64_t msr;
 
 	msr = rdmsr(MSR_VMCR);

Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.8 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.9
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.36.2.8	Sun Aug  2 08:49:08 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Wed Aug  5 15:18:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_vmx.c,v 1.36.2.8 2020/08/02 08:49:08 martin Exp $	*/
+/*	$NetBSD: nvmm_x86_vmx.c,v 1.36.2.9 2020/08/05 15:18:24 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.36.2.8 2020/08/02 08:49:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.36.2.9 2020/08/05 15:18:24 martin Exp $");
 
 #include 
 #include 
@@ -135,6 +135,7 @@ vmx_vmwrite(uint64_t field, uint64_t val
 	);
 }
 
+#ifdef DIAGNOSTIC
 static inline paddr_t
 vmx_vmptrst(void)
 {
@@ -149,6 +150,7 @@ vmx_vmptrst(void)
 
 	return pa;
 }
+#endif
 
 static inline void
 vmx_vmptrld(paddr_t *pa)
@@ -871,15 +873,11 @@ vmx_vmcs_enter(struct nvmm_cpu *vcpu)
 {
 	struct vmx_cpudata *cpudata = vcpu->cpudata;
 	struct cpu_info *vmcs_ci;
-	paddr_t oldpa __diagused;
 
 	cpudata->vmcs_refcnt++;
 	if (cpudata->vmcs_refcnt > 1) {
-#ifdef DIAGNOSTIC
 		KASSERT(kpreempt_disabled());
-		oldpa = vmx_vmptrst();
-		KASSERT(oldpa == cpudata->vmcs_pa);
-#endif
+		KASSERT(vmx_vmptrst() == cpudata->vmcs_pa);
 		return;
 	}
 
@@ -909,9 +907,7 @@ vmx_vmcs_leave(struct nvmm_cpu *vcpu)
 	struct vmx_cpudata *cpudata = vcpu->cpudata;
 
 	KASSERT(kpreempt_disabled());
-#ifdef DIAGNOSTIC
 	KASSERT(vmx_vmptrst() == cpudata->vmcs_pa);
-#endif
 	KASSERT(cpudata->vmcs_refcnt > 0);
 	cpudata->vmcs_refcnt--;
 
@@ -929,9 +925,7 @@ vmx_vmcs_destroy(struct nvmm_cpu *vcpu)
 	struct vmx_cpudata *cpudata = vcpu->cpudata;
 
 	KASSERT(kpreempt_disabled());
-#ifdef DIAGNOSTIC
 	KASSERT(vmx_vmptrst() == cpudata->vmcs_pa);
-#endif
 	KASSERT(cpudata->vmcs_refcnt == 1);
 	cpudata->vmcs_refcnt--;
 
@@ -2230,7 +2224,7 @@ vmx_memalloc(paddr_t *pa, vaddr_t *va, s
 	, 1, 0);
 	if (ret != 0)
 		return ENOMEM;
-	_pa = 

CVS commit: [netbsd-9] src/sys/dev

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 15:14:18 UTC 2020

Modified Files:
src/sys/dev/mii [netbsd-9]: igphy.c igphyreg.h makphy.c makphyreg.h
src/sys/dev/pci [netbsd-9]: if_wm.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1040):

sys/dev/mii/igphy.c: revision 1.35
sys/dev/mii/igphy.c: revision 1.36
sys/dev/mii/igphyreg.h: revision 1.12
sys/dev/mii/igphyreg.h: revision 1.13
sys/dev/mii/makphyreg.h: revision 1.11
sys/dev/pci/if_wm.c: revision 1.682
sys/dev/pci/if_wm.c: revision 1.683
sys/dev/pci/if_wm.c: revision 1.684
sys/dev/pci/if_wm.c: revision 1.685
sys/dev/mii/makphy.c: revision 1.66

s/MII_IGPHY_/IGPHY_/. No functional change.

Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.

  Setup PCS and SGMII for SFP correctly. It still doesn't support SFP
insertion/removal.

Copper:
wm2: SGMII(SFP)
wm2: 0x1043c440
makphy0 at wm2 phy 6: Marvell 88E Gigabit PHY, rev. 1

Fiber:
wm3: SERDES(SFP)
wm3: 0x10034440
wm3: 1000baseSX, 1000baseSX-FDX, auto

  Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID. Found by kUBSan.

  Set if_baudrate for non-MII device. Before this commit, it was 0.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.31.4.1 src/sys/dev/mii/igphy.c
cvs rdiff -u -r1.11 -r1.11.4.1 src/sys/dev/mii/igphyreg.h
cvs rdiff -u -r1.60.2.1 -r1.60.2.2 src/sys/dev/mii/makphy.c
cvs rdiff -u -r1.9.6.1 -r1.9.6.2 src/sys/dev/mii/makphyreg.h
cvs rdiff -u -r1.645.2.5 -r1.645.2.6 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/mii/igphy.c
diff -u src/sys/dev/mii/igphy.c:1.31 src/sys/dev/mii/igphy.c:1.31.4.1
--- src/sys/dev/mii/igphy.c:1.31	Mon Mar 25 07:34:13 2019
+++ src/sys/dev/mii/igphy.c	Wed Aug  5 15:14:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: igphy.c,v 1.31 2019/03/25 07:34:13 msaitoh Exp $	*/
+/*	$NetBSD: igphy.c,v 1.31.4.1 2020/08/05 15:14:18 martin Exp $	*/
 
 /*
  * The Intel copyright applies to the analog register setup, and the
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: igphy.c,v 1.31 2019/03/25 07:34:13 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igphy.c,v 1.31.4.1 2020/08/05 15:14:18 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mii.h"
@@ -270,7 +270,7 @@ igphy_load_dspcode(struct mii_softc *sc)
 
 	delay(2);
 
-	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT, 0x);
+	PHY_WRITE(sc, IGPHY_PAGE_SELECT, 0x);
 	PHY_WRITE(sc, 0x, 0x0140);
 
 	delay(5000);
@@ -278,7 +278,7 @@ igphy_load_dspcode(struct mii_softc *sc)
 	for (i = 0; !((code[i].reg == 0) && (code[i].val == 0)); i++)
 		IGPHY_WRITE(sc, code[i].reg, code[i].val);
 
-	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT, 0x);
+	PHY_WRITE(sc, IGPHY_PAGE_SELECT, 0x);
 	PHY_WRITE(sc, 0x, 0x3300);
 
 	delay(2);
@@ -323,9 +323,9 @@ igphy_reset(struct mii_softc *sc)
 	}
 
 	if (igsc->sc_mactype == WM_T_82547) {
-		IGPHY_READ(sc, MII_IGPHY_ANALOG_SPARE_FUSE_STATUS, );
+		IGPHY_READ(sc, IGPHY_ANALOG_SPARE_FUSE_STATUS, );
 		if ((fused & ANALOG_SPARE_FUSE_ENABLED) == 0) {
-			IGPHY_READ(sc, MII_IGPHY_ANALOG_FUSE_STATUS, );
+			IGPHY_READ(sc, IGPHY_ANALOG_FUSE_STATUS, );
 
 			fine = fused & ANALOG_FUSE_FINE_MASK;
 			coarse = fused & ANALOG_FUSE_COARSE_MASK;
@@ -340,12 +340,12 @@ igphy_reset(struct mii_softc *sc)
 			(fine & ANALOG_FUSE_FINE_MASK) |
 			(coarse & ANALOG_FUSE_COARSE_MASK);
 
-			IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_CONTROL, fused);
-			IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_BYPASS,
+			IGPHY_WRITE(sc, IGPHY_ANALOG_FUSE_CONTROL, fused);
+			IGPHY_WRITE(sc, IGPHY_ANALOG_FUSE_BYPASS,
 			ANALOG_FUSE_ENABLE_SW_CONTROL);
 		}
 	}
-	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT, 0x);
+	PHY_WRITE(sc, IGPHY_PAGE_SELECT, 0x);
 }
 
 
@@ -377,14 +377,14 @@ igphy_service(struct mii_softc *sc, stru
 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
 			break;
 
-		PHY_READ(sc, MII_IGPHY_PORT_CTRL, );
+		PHY_READ(sc, IGPHY_PORT_CTRL, );
 		if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
 			reg |= PSCR_AUTO_MDIX;
 			reg &= ~PSCR_FORCE_MDI_MDIX;
-			PHY_WRITE(sc, MII_IGPHY_PORT_CTRL, reg);
+			PHY_WRITE(sc, IGPHY_PORT_CTRL, reg);
 		} else {
 			reg &= ~(PSCR_AUTO_MDIX | PSCR_FORCE_MDI_MDIX);
-			PHY_WRITE(sc, MII_IGPHY_PORT_CTRL, reg);
+			PHY_WRITE(sc, IGPHY_PORT_CTRL, reg);
 		}
 
 		mii_phy_setmedia(sc);
@@ -425,9 +425,9 @@ igphy_status(struct mii_softc *sc)
 	mii->mii_media_status = IFM_AVALID;
 	mii->mii_media_active = IFM_ETHER;
 
-	PHY_READ(sc, MII_IGPHY_PORT_STATUS, );
+	PHY_READ(sc, IGPHY_PORT_STATUS, );
 
-	if (pssr & PSSR_LINK_UP)
+	if (pssr & IGPHY_PSSR_LINK_UP)
 		mii->mii_media_status |= IFM_ACTIVE;
 
 	PHY_READ(sc, MII_BMCR, );
@@ -449,19 +449,19 @@ igphy_status(struct mii_softc *sc)
 			mii->mii_media_active |= IFM_NONE;
 	

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

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 14:59:42 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_ena.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1038):

sys/dev/pci/if_ena.c: revision 1.25

PR port-arm/55532: kernel panic with ena on AWS a1.2xlarge

Do not mark callout and workqueues as mpsafe unless the NET_MPSAFE option
is present.


To generate a diff of this commit:
cvs rdiff -u -r1.15.2.2 -r1.15.2.3 src/sys/dev/pci/if_ena.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_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.15.2.2 src/sys/dev/pci/if_ena.c:1.15.2.3
--- src/sys/dev/pci/if_ena.c:1.15.2.2	Sun Mar  8 14:44:06 2020
+++ src/sys/dev/pci/if_ena.c	Wed Aug  5 14:59:41 2020
@@ -27,11 +27,16 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+#ifdef _KERNEL_OPT
+#include "opt_net_mpsafe.h"
+#endif
+
 #include 
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15.2.2 2020/03/08 14:44:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15.2.3 2020/08/05 14:59:41 martin Exp $");
 
 #include 
 #include 
@@ -56,6 +61,14 @@ __KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1
 
 #include 
 
+#ifdef NET_MPSAFE
+#define	WQ_FLAGS	WQ_MPSAFE
+#define	CALLOUT_FLAGS	CALLOUT_MPSAFE
+#else
+#define	WQ_FLAGS	0
+#define	CALLOUT_FLAGS	0
+#endif
+
 /*
  *  Function prototypes
  */
@@ -682,7 +695,7 @@ ena_setup_tx_resources(struct ena_adapte
 
 	/* Allocate workqueues */
 	int rc = workqueue_create(_ring->enqueue_tq, "ena_tx_enq",
-	ena_deferred_mq_start, tx_ring, 0, IPL_NET, WQ_PERCPU | WQ_MPSAFE);
+	ena_deferred_mq_start, tx_ring, 0, IPL_NET, WQ_PERCPU | WQ_FLAGS);
 	if (unlikely(rc != 0)) {
 		ena_trace(ENA_ALERT,
 		"Unable to create workqueue for enqueue task\n");
@@ -889,7 +902,7 @@ ena_setup_rx_resources(struct ena_adapte
 
 	/* Allocate workqueues */
 	int rc = workqueue_create(_ring->cmpl_tq, "ena_rx_comp",
-	ena_deferred_rx_cleanup, rx_ring, 0, IPL_NET, WQ_PERCPU | WQ_MPSAFE);
+	ena_deferred_rx_cleanup, rx_ring, 0, IPL_NET, WQ_PERCPU | WQ_FLAGS);
 	if (unlikely(rc != 0)) {
 		ena_trace(ENA_ALERT,
 		"Unable to create workqueue for RX completion task\n");
@@ -3807,11 +3820,11 @@ ena_attach(device_t parent, device_t sel
 		goto err_ifp_free;
 	}
 
-	callout_init(>timer_service, CALLOUT_MPSAFE);
+	callout_init(>timer_service, CALLOUT_FLAGS);
 
 	/* Initialize reset task queue */
 	rc = workqueue_create(>reset_tq, "ena_reset_enq",
-	ena_reset_task, adapter, 0, IPL_NET, WQ_PERCPU | WQ_MPSAFE);
+	ena_reset_task, adapter, 0, IPL_NET, WQ_PERCPU | WQ_FLAGS);
 	if (unlikely(rc != 0)) {
 		ena_trace(ENA_ALERT,
 		"Unable to create workqueue for reset task\n");



CVS commit: [netbsd-9] src/sys/dev

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 14:47:04 UTC 2020

Modified Files:
src/sys/dev [netbsd-9]: dev_verbose.h

Log Message:
Pull up following revision(s) (requested by uwe in ticket #1037):

sys/dev/dev_verbose.h: revision 1.3

DEV_VERBOSE_MODULE_DEFINE - use MODULE_CLASS_DRIVER.

This makes built-in verbose modules available before the start of the
autoconfiguration, when they are needed.  From pgoyette@

PR kern/55535


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.26.1 src/sys/dev/dev_verbose.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/dev/dev_verbose.h
diff -u src/sys/dev/dev_verbose.h:1.2 src/sys/dev/dev_verbose.h:1.2.26.1
--- src/sys/dev/dev_verbose.h:1.2	Fri Nov 13 01:37:19 2015
+++ src/sys/dev/dev_verbose.h	Wed Aug  5 14:47:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dev_verbose.h,v 1.2 2015/11/13 01:37:19 christos Exp $ */
+/*	$NetBSD: dev_verbose.h,v 1.2.26.1 2020/08/05 14:47:04 martin Exp $ */
 
 /*
  * Redistribution and use in source and binary forms, with or without
@@ -79,7 +79,7 @@ tag ## verbose_modcmd(modcmd_t cmd, void
 		return ENOTTY;		\
 	}\
 }	\
-MODULE(MODULE_CLASS_MISC, tag ## verbose, deps)
+MODULE(MODULE_CLASS_DRIVER, tag ## verbose, deps)
 
 #endif /* KERNEL */
 



CVS commit: [netbsd-9] src/sys/dev/nvmm

2020-08-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug  2 11:19:09 UTC 2020

Modified Files:
src/sys/dev/nvmm [netbsd-9]: nvmm_internal.h

Log Message:
Open code preempt_needed() which is not available on this branch.
Fixes build fallout from ticket #1032.


To generate a diff of this commit:
cvs rdiff -u -r1.12.2.3 -r1.12.2.4 src/sys/dev/nvmm/nvmm_internal.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/dev/nvmm/nvmm_internal.h
diff -u src/sys/dev/nvmm/nvmm_internal.h:1.12.2.3 src/sys/dev/nvmm/nvmm_internal.h:1.12.2.4
--- src/sys/dev/nvmm/nvmm_internal.h:1.12.2.3	Sun Aug  2 08:49:08 2020
+++ src/sys/dev/nvmm/nvmm_internal.h	Sun Aug  2 11:19:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_internal.h,v 1.12.2.3 2020/08/02 08:49:08 martin Exp $	*/
+/*	$NetBSD: nvmm_internal.h,v 1.12.2.4 2020/08/02 11:19:09 martin Exp $	*/
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -125,7 +125,13 @@ extern const struct nvmm_impl nvmm_x86_v
 static inline bool
 nvmm_return_needed(void)
 {
-	if (preempt_needed()) {
+	lwp_t *l = curlwp;
+	int needed;
+
+	KPREEMPT_DISABLE(l);
+	needed = l->l_cpu->ci_want_resched;
+	KPREEMPT_ENABLE(l);
+	if (needed) {
 		return true;
 	}
 	if (curlwp->l_flag & LW_USERRET) {



CVS commit: [netbsd-9] src/sys/dev/wsfb

2020-07-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jul 26 10:47:25 UTC 2020

Modified Files:
src/sys/dev/wsfb [netbsd-9]: genfb.c

Log Message:
Pull up following revision(s) (requested by jdolecek in ticket #1025):

sys/dev/wsfb/genfb.c: revision 1.73

reduce stack usage in genfb_calc_hsize()


To generate a diff of this commit:
cvs rdiff -u -r1.67.2.2 -r1.67.2.3 src/sys/dev/wsfb/genfb.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/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.67.2.2 src/sys/dev/wsfb/genfb.c:1.67.2.3
--- src/sys/dev/wsfb/genfb.c:1.67.2.2	Wed Apr 15 14:15:17 2020
+++ src/sys/dev/wsfb/genfb.c	Sun Jul 26 10:47:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.67.2.2 2020/04/15 14:15:17 martin Exp $ */
+/*	$NetBSD: genfb.c,v 1.67.2.3 2020/07/26 10:47:25 martin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.67.2.2 2020/04/15 14:15:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.67.2.3 2020/07/26 10:47:25 martin Exp $");
 
 #include 
 #include 
@@ -632,18 +632,25 @@ genfb_calc_hsize(struct genfb_softc *sc)
 	device_t dev = sc->sc_dev;
 	prop_dictionary_t dict = device_properties(dev);
 	prop_data_t edid_data;
-	struct edid_info edid;
+	struct edid_info *edid;
 	const char *edid_ptr;
+	int hsize;
 
 	edid_data = prop_dictionary_get(dict, "EDID");
 	if (edid_data == NULL || prop_data_size(edid_data) < 128)
 		return 0;
 
+	edid = kmem_alloc(sizeof(*edid), KM_SLEEP);
+
 	edid_ptr = prop_data_data_nocopy(edid_data);
-	if (edid_parse(__UNCONST(edid_ptr), ) != 0)
-		return 0;
+	if (edid_parse(__UNCONST(edid_ptr), edid) == 0)
+		hsize = (int)edid->edid_max_hsize * 10;
+	else
+		hsize = 0;
+
+	kmem_free(edid, sizeof(*edid));
 
-	return (int)edid.edid_max_hsize * 10;
+	return hsize;
 }
 
 /* Return the minimum number of character columns based on DPI */



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

2020-07-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jul 26 10:46:14 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: pci_subr.c

Log Message:
Pull up following revision(s) (requested by jdolecek in ticket #1024):

sys/dev/pci/pci_subr.c: revision 1.224

change pci_conf_print() to allocate memory for the regs dynamically
instead of on-stack


To generate a diff of this commit:
cvs rdiff -u -r1.215.2.3 -r1.215.2.4 src/sys/dev/pci/pci_subr.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/pci_subr.c
diff -u src/sys/dev/pci/pci_subr.c:1.215.2.3 src/sys/dev/pci/pci_subr.c:1.215.2.4
--- src/sys/dev/pci/pci_subr.c:1.215.2.3	Thu Mar 19 19:05:34 2020
+++ src/sys/dev/pci/pci_subr.c	Sun Jul 26 10:46:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_subr.c,v 1.215.2.3 2020/03/19 19:05:34 martin Exp $	*/
+/*	$NetBSD: pci_subr.c,v 1.215.2.4 2020/07/26 10:46:14 martin Exp $	*/
 
 /*
  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.215.2.3 2020/03/19 19:05:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.215.2.4 2020/07/26 10:46:14 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -52,6 +52,11 @@ __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v
 #include 
 #include 
 #include 
+#include 
+
+#define MALLOC(sz)	kmem_alloc(sz, KM_SLEEP)
+#define FREE(p, sz)	kmem_free(p, sz)
+
 #else
 #include 
 #include 
@@ -59,6 +64,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v
 #include 
 #include 
 #include 
+
+#define MALLOC(sz)	malloc(sz)
+#define FREE(p, sz)	free(p)
+
 #endif
 
 #include 
@@ -4811,7 +4820,7 @@ pci_conf_print(
 #endif
 )
 {
-	pcireg_t regs[o2i(PCI_EXTCONF_SIZE)];
+	pcireg_t *regs;
 	int off, capoff, endoff, hdrtype;
 	const char *type_name;
 #ifdef _KERNEL
@@ -4820,6 +4829,8 @@ pci_conf_print(
 	void (*type_printfn)(const pcireg_t *);
 #endif
 
+	regs = MALLOC(PCI_EXTCONF_SIZE);
+
 	printf("PCI configuration registers:\n");
 
 	for (off = 0; off < PCI_EXTCONF_SIZE; off += 4) {
@@ -4916,7 +4927,7 @@ pci_conf_print(
 
 	if (regs[o2i(PCI_EXTCAPLIST_BASE)] == 0x ||
 	regs[o2i(PCI_EXTCAPLIST_BASE)] == 0)
-		return;
+		goto out;
 
 	printf("\n");
 #ifdef _KERNEL
@@ -4929,4 +4940,7 @@ pci_conf_print(
 	/* Extended Configuration Space, if present */
 	printf("  Extended Configuration Space:\n");
 	pci_conf_print_regs(regs, PCI_EXTCAPLIST_BASE, PCI_EXTCONF_SIZE);
+
+out:
+	FREE(regs, PCI_EXTCONF_SIZE);
 }



CVS commit: [netbsd-9] src/sys/dev/sdmmc

2020-07-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 20 18:15:43 UTC 2020

Modified Files:
src/sys/dev/sdmmc [netbsd-9]: sdhc.c sdhcreg.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1021):

sys/dev/sdmmc/sdhc.c: revision 1.107
sys/dev/sdmmc/sdhcreg.h: revision 1.21

Identify SDHC 4.1 and 4.2. From {DragonFly,Free}BSD.


To generate a diff of this commit:
cvs rdiff -u -r1.103.2.1 -r1.103.2.2 src/sys/dev/sdmmc/sdhc.c
cvs rdiff -u -r1.19 -r1.19.12.1 src/sys/dev/sdmmc/sdhcreg.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/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.103.2.1 src/sys/dev/sdmmc/sdhc.c:1.103.2.2
--- src/sys/dev/sdmmc/sdhc.c:1.103.2.1	Tue Feb 25 18:40:43 2020
+++ src/sys/dev/sdmmc/sdhc.c	Mon Jul 20 18:15:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.103.2.1 2020/02/25 18:40:43 martin Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.103.2.2 2020/07/20 18:15:43 martin Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.103.2.1 2020/02/25 18:40:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.103.2.2 2020/07/20 18:15:43 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -324,6 +324,12 @@ sdhc_host_found(struct sdhc_softc *sc, b
 	case SDHC_SPEC_VERS_400:
 		aprint_normal("4.0");
 		break;
+	case SDHC_SPEC_VERS_410:
+		aprint_normal("4.1");
+		break;
+	case SDHC_SPEC_VERS_420:
+		aprint_normal("4.2");
+		break;
 	case SDHC_SPEC_NOVERS:
 		hp->specver = -1;
 		aprint_normal("NO-VERS");

Index: src/sys/dev/sdmmc/sdhcreg.h
diff -u src/sys/dev/sdmmc/sdhcreg.h:1.19 src/sys/dev/sdmmc/sdhcreg.h:1.19.12.1
--- src/sys/dev/sdmmc/sdhcreg.h:1.19	Fri Jun 23 08:43:59 2017
+++ src/sys/dev/sdmmc/sdhcreg.h	Mon Jul 20 18:15:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhcreg.h,v 1.19 2017/06/23 08:43:59 ryo Exp $	*/
+/*	$NetBSD: sdhcreg.h,v 1.19.12.1 2020/07/20 18:15:43 martin Exp $	*/
 /*	$OpenBSD: sdhcreg.h,v 1.4 2006/07/30 17:20:40 fgsch Exp $	*/
 
 /*
@@ -246,6 +246,8 @@
 #define SDHC_SPEC_VERS_200		0x01
 #define SDHC_SPEC_VERS_300		0x02
 #define SDHC_SPEC_VERS_400		0x03
+#define SDHC_SPEC_VERS_410		0x04
+#define SDHC_SPEC_VERS_420		0x05
 #define SDHC_SPEC_NOVERS		0xff	/* dummy */
 
 /* SDHC_CAPABILITIES decoding */



CVS commit: [netbsd-9] src/sys/dev/usb

2020-07-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jul 18 15:09:29 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: usbdi.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1020):

sys/dev/usb/usbdi.c: revision 1.203

for both usbd_transfer() and usbd_ar_pipe() be sure to reset the
xfer ux_state to XFER_BUSY when removing from the queue.
seems to fix an occasional panic i was seeing on pinebook and
pinebookpro lately with axen(4).

from riastradh@.

XXX: pullup-9.


To generate a diff of this commit:
cvs rdiff -u -r1.182.4.4 -r1.182.4.5 src/sys/dev/usb/usbdi.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/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.182.4.4 src/sys/dev/usb/usbdi.c:1.182.4.5
--- src/sys/dev/usb/usbdi.c:1.182.4.4	Fri Apr  3 12:27:55 2020
+++ src/sys/dev/usb/usbdi.c	Sat Jul 18 15:09:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.182.4.4 2020/04/03 12:27:55 martin Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.182.4.5 2020/07/18 15:09:28 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.182.4.4 2020/04/03 12:27:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.182.4.5 2020/07/18 15:09:28 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -337,6 +337,9 @@ usbd_transfer(struct usbd_xfer *xfer)
 		USBHIST_LOG(usbdebug, "xfer failed: %s, reinserting",
 		err, 0, 0, 0);
 		usbd_lock_pipe(pipe);
+#ifdef DIAGNOSTIC
+		xfer->ux_state = XFER_BUSY;
+#endif
 		SIMPLEQ_REMOVE_HEAD(>up_queue, ux_next);
 		if (pipe->up_serialise)
 			usbd_start_next(pipe);
@@ -892,6 +895,9 @@ usbd_ar_pipe(struct usbd_pipe *pipe)
 		"(methods = %#jx)", (uintptr_t)pipe, (uintptr_t)xfer,
 		(uintptr_t)pipe->up_methods, 0);
 		if (xfer->ux_status == USBD_NOT_STARTED) {
+#ifdef DIAGNOSTIC
+			xfer->ux_state = XFER_BUSY;
+#endif
 			SIMPLEQ_REMOVE_HEAD(>up_queue, ux_next);
 		} else {
 			/* Make the HC abort it (and invoke the callback). */



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

2020-07-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 17 15:30:26 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: radeonfb.c radeonfbvar.h

Log Message:
Pull up following revision(s) (requested by macallan in ticket #1019):

sys/dev/pci/radeonfbvar.h: revision 1.21
sys/dev/pci/radeonfb.c: revision 1.107

reduce stack usage in radeonfb_pickres() and radeonfb_set_cursor()

forgot to commit a header change, again...


To generate a diff of this commit:
cvs rdiff -u -r1.104.4.1 -r1.104.4.2 src/sys/dev/pci/radeonfb.c
cvs rdiff -u -r1.20 -r1.20.26.1 src/sys/dev/pci/radeonfbvar.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/dev/pci/radeonfb.c
diff -u src/sys/dev/pci/radeonfb.c:1.104.4.1 src/sys/dev/pci/radeonfb.c:1.104.4.2
--- src/sys/dev/pci/radeonfb.c:1.104.4.1	Sun Aug 18 09:58:49 2019
+++ src/sys/dev/pci/radeonfb.c	Fri Jul 17 15:30:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeonfb.c,v 1.104.4.1 2019/08/18 09:58:49 martin Exp $ */
+/*	$NetBSD: radeonfb.c,v 1.104.4.2 2020/07/17 15:30:26 martin Exp $ */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.104.4.1 2019/08/18 09:58:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.104.4.2 2020/07/17 15:30:26 martin Exp $");
 
 #include 
 #include 
@@ -80,6 +80,7 @@ __KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -3691,12 +3692,12 @@ radeonfb_set_cursor(struct radeonfb_disp
 	unsigned	index, count;
 	int		i, err;
 	int		pitch, size;
-	struct radeonfb_cursor	nc;
+	struct radeonfb_cursor	*nc = >rd_tempcursor;
 
 	flags = wc->which;
 
 	/* copy old values */
-	nc = dp->rd_cursor;
+	memcpy(nc, >rd_cursor, sizeof(struct radeonfb_cursor));
 
 	if (flags & WSDISPLAY_CURSOR_DOCMAP) {
 		index = wc->cmap.index;
@@ -3716,7 +3717,7 @@ radeonfb_set_cursor(struct radeonfb_disp
 			return err;
 
 		for (i = index; i < index + count; i++) {
-			nc.rc_cmap[i] =
+			nc->rc_cmap[i] =
 			(r[i] << 16) + (g[i] << 8) + (b[i] << 0);
 		}
 	}
@@ -3731,46 +3732,46 @@ radeonfb_set_cursor(struct radeonfb_disp
 		size = pitch * wc->size.y;
 
 		/* clear the old cursor and mask */
-		memset(nc.rc_image, 0, 512);
-		memset(nc.rc_mask, 0, 512);
+		memset(nc->rc_image, 0, 512);
+		memset(nc->rc_mask, 0, 512);
 
-		nc.rc_size = wc->size;
+		nc->rc_size = wc->size;
 
-		if ((err = copyin(wc->image, nc.rc_image, size)) != 0)
+		if ((err = copyin(wc->image, nc->rc_image, size)) != 0)
 			return err;
 
-		if ((err = copyin(wc->mask, nc.rc_mask, size)) != 0)
+		if ((err = copyin(wc->mask, nc->rc_mask, size)) != 0)
 			return err;
 	}
 
 	if (flags & WSDISPLAY_CURSOR_DOHOT) {
-		nc.rc_hot = wc->hot;
-		if (nc.rc_hot.x >= nc.rc_size.x)
-			nc.rc_hot.x = nc.rc_size.x - 1;
-		if (nc.rc_hot.y >= nc.rc_size.y)
-			nc.rc_hot.y = nc.rc_size.y - 1;
+		nc->rc_hot = wc->hot;
+		if (nc->rc_hot.x >= nc->rc_size.x)
+			nc->rc_hot.x = nc->rc_size.x - 1;
+		if (nc->rc_hot.y >= nc->rc_size.y)
+			nc->rc_hot.y = nc->rc_size.y - 1;
 	}
 
 	if (flags & WSDISPLAY_CURSOR_DOPOS) {
-		nc.rc_pos = wc->pos;
-		if (nc.rc_pos.x >= dp->rd_virtx)
-			nc.rc_pos.x = dp->rd_virtx - 1;
+		nc->rc_pos = wc->pos;
+		if (nc->rc_pos.x >= dp->rd_virtx)
+			nc->rc_pos.x = dp->rd_virtx - 1;
 #if 0
-		if (nc.rc_pos.x < 0)
-			nc.rc_pos.x = 0;
+		if (nc->rc_pos.x < 0)
+			nc->rc_pos.x = 0;
 #endif
-		if (nc.rc_pos.y >= dp->rd_virty)
-			nc.rc_pos.y = dp->rd_virty - 1;
+		if (nc->rc_pos.y >= dp->rd_virty)
+			nc->rc_pos.y = dp->rd_virty - 1;
 #if 0
-		if (nc.rc_pos.y < 0)
-			nc.rc_pos.y = 0;
+		if (nc->rc_pos.y < 0)
+			nc->rc_pos.y = 0;
 #endif
 	}
 	if (flags & WSDISPLAY_CURSOR_DOCUR) {
-		nc.rc_visible = wc->enable;
+		nc->rc_visible = wc->enable;
 	}
 
-	dp->rd_cursor = nc;
+	memcpy(>rd_cursor, nc, sizeof(struct radeonfb_cursor));
 	radeonfb_cursor_update(dp, wc->which);
 
 	return 0;
@@ -4171,10 +4172,14 @@ radeonfb_pickres(struct radeonfb_display
 		}
 
 	} else {
-		struct videomode	modes[64];
+		struct videomode	*modes;
+		size_t			smodes;
 		int			nmodes = 0;
 		int			valid = 0;
 
+		smodes = sizeof(struct videomode) * 64;
+		modes = kmem_alloc(smodes, KM_SLEEP);
+
 		for (i = 0; i < dp->rd_ncrtcs; i++) {
 			/*
 			 * pick the largest resolution in common.
@@ -4243,6 +4248,8 @@ radeonfb_pickres(struct radeonfb_display
 *y = modes[i].vdisplay;
 			}
 		}
+		kmem_free(modes, smodes);
+
 	}
 
 	if ((*x == 0) || (*y == 0)) {

Index: src/sys/dev/pci/radeonfbvar.h
diff -u src/sys/dev/pci/radeonfbvar.h:1.20 src/sys/dev/pci/radeonfbvar.h:1.20.26.1
--- src/sys/dev/pci/radeonfbvar.h:1.20	Wed Nov  5 19:39:17 2014
+++ src/sys/dev/pci/radeonfbvar.h	Fri Jul 17 15:30:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: radeonfbvar.h,v 1.20 2014/11/05 19:39:17 macallan Exp $ */
+/* $NetBSD: radeonfbvar.h,v 1.20.26.1 2020/07/17 15:30:26 martin Exp $ */
 
 /*-
  * Copyright (c) 

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

2020-07-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jul 16 12:39:11 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: piixpm.c piixpmreg.h

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #1017:

sys/dev/pci/piixpm.c1.57-1.59, 1.61-1.63 via patch
sys/dev/pci/piixpmreg.h 1.9-1.12

- Fix number of port for Hudson rev. 0x1f and newer.
- Read SB800_SMB_HOSTC correctly. This register is not in the PCI
  config space but in the I/O space.
- The bit 0 of SB800_SMB_HOSTC is 0 on SMI and 1 on IRQ, so invert the
  check.
- Don't force using SMBUS0SEL register.
- Acquire/release host semaphore to share SMBus between the host and
  the embedded controller (IMC). Without this change, "shutdown -r"
  does power off and not boot on some machines.
- Save/restore port number before selecting port.
- Modify comment.
- Whitespace fix.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.54.2.1 src/sys/dev/pci/piixpm.c
cvs rdiff -u -r1.8 -r1.8.2.1 src/sys/dev/pci/piixpmreg.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/dev/pci/piixpm.c
diff -u src/sys/dev/pci/piixpm.c:1.54 src/sys/dev/pci/piixpm.c:1.54.2.1
--- src/sys/dev/pci/piixpm.c:1.54	Sat Jul 13 09:24:17 2019
+++ src/sys/dev/pci/piixpm.c	Thu Jul 16 12:39:11 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: piixpm.c,v 1.54 2019/07/13 09:24:17 msaitoh Exp $ */
+/* $NetBSD: piixpm.c,v 1.54.2.1 2020/07/16 12:39:11 martin Exp $ */
 /*	$OpenBSD: piixpm.c,v 1.39 2013/10/01 20:06:02 sf Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.54 2019/07/13 09:24:17 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.54.2.1 2020/07/16 12:39:11 martin Exp $");
 
 #include 
 #include 
@@ -70,8 +70,11 @@ __KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1
 
 #define PIIXPM_IS_FCHGRP(sc)	(PIIXPM_IS_HUDSON(sc) || PIIXPM_IS_KERNCZ(sc))
 
+#define PIIX_SB800_TIMEOUT 500
+
 struct piixpm_smbus {
 	int			sda;
+	int			sda_save;
 	struct			piixpm_softc *softc;
 };
 
@@ -86,6 +89,7 @@ struct piixpm_softc {
 	bus_space_handle_t	sc_smb_ioh;
 	void *			sc_smb_ih;
 	int			sc_poll;
+	bool			sc_sb800_selen; /* Use SMBUS0SEL */
 
 	pci_chipset_tag_t	sc_pc;
 	pcitag_t		sc_pcitag;
@@ -119,8 +123,8 @@ static bool	piixpm_resume(device_t, cons
 
 static int	piixpm_sb800_init(struct piixpm_softc *);
 static void	piixpm_csb5_reset(void *);
-static int	piixpm_i2c_acquire_bus(void *, int);
-static void	piixpm_i2c_release_bus(void *, int);
+static int	piixpm_i2c_sb800_acquire_bus(void *, int);
+static void	piixpm_i2c_sb800_release_bus(void *, int);
 static int	piixpm_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *,
 size_t, void *, size_t, int);
 
@@ -231,15 +235,10 @@ nopowermanagement:
 	/* SB800 rev 0x40+, AMD HUDSON and newer need special initialization */
 	if (PIIXPM_IS_FCHGRP(sc) || PIIXPM_IS_SB800GRP(sc)) {
 		if (piixpm_sb800_init(sc) == 0) {
-			sc->sc_numbusses = 4;
-
 			/* Read configuration */
-			conf = pci_conf_read(pa->pa_pc, pa->pa_tag,
-			SB800_SMB_HOSTC);
-			DPRINTF(("%s: conf 0x%08x\n", device_xname(self),
-conf));
-
-			usesmi = conf & SB800_SMB_HOSTC_SMI;
+			conf = bus_space_read_1(sc->sc_iot,
+			sc->sc_smb_ioh, SB800_SMB_HOSTC);
+			usesmi = ((conf & SB800_SMB_HOSTC_IRQ) == 0);
 			goto setintr;
 		}
 		aprint_normal_dev(self, "SMBus initialization failed\n");
@@ -328,17 +327,24 @@ piixpm_rescan(device_t self, const char 
 	/* Attach I2C bus */
 
 	for (i = 0; i < sc->sc_numbusses; i++) {
+		struct i2c_controller *tag = >sc_i2c_tags[i];
+
 		if (sc->sc_i2c_device[i])
 			continue;
 		sc->sc_busses[i].sda = i;
 		sc->sc_busses[i].softc = sc;
-		sc->sc_i2c_tags[i].ic_cookie = >sc_busses[i];
-		sc->sc_i2c_tags[i].ic_acquire_bus = piixpm_i2c_acquire_bus;
-		sc->sc_i2c_tags[i].ic_release_bus = piixpm_i2c_release_bus;
-		sc->sc_i2c_tags[i].ic_exec = piixpm_i2c_exec;
+		tag->ic_cookie = >sc_busses[i];
+		if (PIIXPM_IS_SB800GRP(sc) || PIIXPM_IS_FCHGRP(sc)) {
+			tag->ic_acquire_bus = piixpm_i2c_sb800_acquire_bus;
+			tag->ic_release_bus = piixpm_i2c_sb800_release_bus;
+		} else {
+			tag->ic_acquire_bus = NULL;
+			tag->ic_release_bus = NULL;
+		}
+		tag->ic_exec = piixpm_i2c_exec;
 		memset(, 0, sizeof(iba));
 		iba.iba_type = I2C_TYPE_SMBUS;
-		iba.iba_tag = >sc_i2c_tags[i];
+		iba.iba_tag = tag;
 		sc->sc_i2c_device[i] = config_found_ia(self, ifattr, ,
 		piixpm_iicbus_print);
 	}
@@ -401,6 +407,12 @@ piixpm_sb800_init(struct piixpm_softc *s
 	uint16_t val, base_addr;
 	bool enabled;
 
+	if (PIIXPM_IS_KERNCZ(sc) ||
+	(PIIXPM_IS_HUDSON(sc) && (sc->sc_rev >= 0x1f)))
+		sc->sc_numbusses = 2;
+	else
+		sc->sc_numbusses = 4;
+
 	/* Fetch SMB base address */
 	if (bus_space_map(iot,
 	SB800_INDIRECTIO_BASE, SB800_INDIRECTIO_SIZE, 0, )) {
@@ -420,6 +432,8 @@ piixpm_sb800_init(struct piixpm_softc *s
 		val = bus_space_read_1(iot, ioh, 

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

2020-07-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 15 17:16:59 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_ti.c if_tireg.h

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #1014:

sys/dev/pci/if_ti.c 1.116-1.120 via patch
sys/dev/pci/if_tireg.h  1.26

- Don't clear CFI and priority bit to pass them to the upper layer.
- Add support for Farallon PN9000SX from FreeBSD.
- Fix typo in comment.
- Style fix.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.112.2.1 src/sys/dev/pci/if_ti.c
cvs rdiff -u -r1.21 -r1.21.4.1 src/sys/dev/pci/if_tireg.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/dev/pci/if_ti.c
diff -u src/sys/dev/pci/if_ti.c:1.112 src/sys/dev/pci/if_ti.c:1.112.2.1
--- src/sys/dev/pci/if_ti.c:1.112	Tue Jul  9 08:46:59 2019
+++ src/sys/dev/pci/if_ti.c	Wed Jul 15 17:16:59 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.112 2019/07/09 08:46:59 msaitoh Exp $ */
+/* $NetBSD: if_ti.c,v 1.112.2.1 2020/07/15 17:16:59 martin Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -81,7 +81,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.112 2019/07/09 08:46:59 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ti.c,v 1.112.2.1 2020/07/15 17:16:59 martin Exp $");
 
 #include "opt_inet.h"
 
@@ -140,6 +140,8 @@ static const struct ti_type ti_devs[] = 
 		"Netgear GA620 1000BASE-T Ethernet" },
 	{ PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON,
 		"Silicon Graphics Gigabit Ethernet" },
+	{ PCI_VENDOR_DEC, PCI_PRODUCT_DEC_PN9000SX,
+		"Farallon PN9000SX Gigabit Ethernet" },
 	{ 0, 0, NULL }
 };
 
@@ -216,7 +218,7 @@ ti_eeprom_putbyte(struct ti_softc *sc, i
 	TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN);
 
 	/*
-	 * Feed in each bit and stobe the clock.
+	 * Feed in each bit and strobe the clock.
 	 */
 	for (i = 0x80; i; i >>= 1) {
 		if (byte & i) {
@@ -762,7 +764,7 @@ ti_newbuf_std(struct ti_softc *sc, int i
 }
 
 /*
- * Intialize a mini receive ring descriptor. This only applies to
+ * Initialize a mini receive ring descriptor. This only applies to
  * the Tigon 2.
  */
 static int
@@ -903,7 +905,7 @@ ti_init_rx_ring_std(struct ti_softc *sc)
 	for (i = 0; i < TI_SSLOTS; i++) {
 		if (ti_newbuf_std(sc, i, NULL, 0) == ENOBUFS)
 			return (ENOBUFS);
-	};
+	}
 
 	TI_UPDATE_STDPROD(sc, i - 1);
 	sc->ti_std = i - 1;
@@ -941,7 +943,7 @@ ti_init_rx_ring_jumbo(struct ti_softc *s
 	for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) {
 		if (ti_newbuf_jumbo(sc, i, NULL) == ENOBUFS)
 			return (ENOBUFS);
-	};
+	}
 
 	TI_UPDATE_JUMBOPROD(sc, i - 1);
 	sc->ti_jumbo = i - 1;
@@ -974,7 +976,7 @@ ti_init_rx_ring_mini(struct ti_softc *sc
 	for (i = 0; i < TI_MSLOTS; i++) {
 		if (ti_newbuf_mini(sc, i, NULL, 0) == ENOBUFS)
 			return (ENOBUFS);
-	};
+	}
 
 	TI_UPDATE_MINIPROD(sc, i - 1);
 	sc->ti_mini = i - 1;
@@ -2026,10 +2028,8 @@ ti_rxeof(struct ti_softc *sc)
 			break;
 		}
 
-		if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
-			/* ti_vlan_tag also has the priority, trim it */
-			vlan_set_tag(m, cur_rx->ti_vlan_tag & 0x0fff);
-		}
+		if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG)
+			vlan_set_tag(m, cur_rx->ti_vlan_tag);
 
 		if_percpuq_enqueue(ifp->if_percpuq, m);
 	}
@@ -2205,7 +2205,7 @@ ti_stats_update(struct ti_softc *sc)
 }
 
 /*
- * Encapsulate an mbuf chain in the tx ring  by coupling the mbuf data
+ * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data
  * pointers to descriptors.
  */
 static int
@@ -2684,7 +2684,7 @@ ti_ifmedia_sts(struct ifnet *ifp, struct
 static int
 ti_ether_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
-	struct ifaddr *ifa = (struct ifaddr *) data;
+	struct ifaddr *ifa = (struct ifaddr *)data;
 	struct ti_softc *sc = ifp->if_softc;
 
 	if ((ifp->if_flags & IFF_UP) == 0) {
@@ -2717,7 +2717,7 @@ static int
 ti_ioctl(struct ifnet *ifp, u_long command, void *data)
 {
 	struct ti_softc		*sc = ifp->if_softc;
-	struct ifreq		*ifr = (struct ifreq *) data;
+	struct ifreq		*ifr = (struct ifreq *)data;
 	int			s, error = 0;
 	struct ti_cmd_desc	cmd;
 

Index: src/sys/dev/pci/if_tireg.h
diff -u src/sys/dev/pci/if_tireg.h:1.21 src/sys/dev/pci/if_tireg.h:1.21.4.1
--- src/sys/dev/pci/if_tireg.h:1.21	Tue Mar  5 08:25:02 2019
+++ src/sys/dev/pci/if_tireg.h	Wed Jul 15 17:16:59 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: if_tireg.h,v 1.21 2019/03/05 08:25:02 msaitoh Exp $ */
+/* $NetBSD: if_tireg.h,v 1.21.4.1 2020/07/15 17:16:59 martin Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -39,7 +39,7 @@
  * which can be accessed with the CSR_READ_4()/CSR_WRITE_4() macros.
  * Each register must be accessed using 32 bit operations.
  *
- * All reegisters are accessed through a 16K shared memory block.
+ * All registers are accessed through a 16K shared memory block.
  * The first group of registers are actually copies of the PCI
  * configuration space registers.
  */



CVS commit: [netbsd-9] src/sys/dev

2020-07-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 15 14:09:04 UTC 2020

Modified Files:
src/sys/dev/hid [netbsd-9]: hid.h
src/sys/dev/usb [netbsd-9]: uhid.c usbhid.h

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1010):

sys/dev/usb/uhid.c: revision 1.112
sys/dev/usb/uhid.c: revision 1.113
sys/dev/hid/hid.h: revision 1.4
sys/dev/hid/hid.h: revision 1.5
sys/dev/usb/usbhid.h: revision 1.19

Add fido constants, and turn hid "raw" mode for fido devices.

Add ioctls to get and set raw mode.

Use unsigned to avoid undefined behavior. Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.4.1 src/sys/dev/hid/hid.h
cvs rdiff -u -r1.108.2.1 -r1.108.2.2 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.18 -r1.18.6.1 src/sys/dev/usb/usbhid.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/dev/hid/hid.h
diff -u src/sys/dev/hid/hid.h:1.3 src/sys/dev/hid/hid.h:1.3.4.1
--- src/sys/dev/hid/hid.h:1.3	Thu Nov 15 23:01:45 2018
+++ src/sys/dev/hid/hid.h	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hid.h,v 1.3 2018/11/15 23:01:45 jakllsch Exp $	*/
+/*	$NetBSD: hid.h,v 1.3.4.1 2020/07/15 14:09:04 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/hid.h,v 1.7 1999/11/17 22:33:40 n_hibma Exp $ */
 
 /*
@@ -123,7 +123,8 @@ int hid_is_collection(const void *, int,
 #define HUP_CAMERA_CONTROL	0x0090
 #define HUP_ARCADE		0x0091
 #define HUP_VENDOR		0x00ff
-#define HUP_MICROSOFT		0xff00
+#define HUP_FIDO		0xf1d0U
+#define HUP_MICROSOFT		0xff00U
 /* XXX compat */
 #define HUP_APPLE		0x00ff
 #define HUP_WACOM		0xff00
@@ -396,6 +397,9 @@ int hid_is_collection(const void *, int,
 /* Usages, Consumer */
 #define HUC_AC_PAN		0x0238
 
+/* Usages, FIDO */
+#define HUF_U2FHID		0x0001
+
 #define HID_USAGE2(p, u) (((p) << 16) | u)
 #define HID_GET_USAGE(u) ((u) & 0x)
 #define HID_GET_USAGE_PAGE(u) (((u) >> 16) & 0x)

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.108.2.1 src/sys/dev/usb/uhid.c:1.108.2.2
--- src/sys/dev/usb/uhid.c:1.108.2.1	Thu Jan  2 09:42:06 2020
+++ src/sys/dev/usb/uhid.c	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.108.2.1 2020/01/02 09:42:06 martin Exp $	*/
+/*	$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2008, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.1 2020/01/02 09:42:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.108.2.2 2020/07/15 14:09:04 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -104,6 +104,7 @@ struct uhid_softc {
 #define UHID_IMMED	0x02	/* return read data immediately */
 
 	int sc_refcnt;
+	int sc_raw;
 	u_char sc_dying;
 };
 
@@ -184,6 +185,8 @@ uhid_attach(device_t parent, device_t se
 	sc->sc_isize = hid_report_size(desc, size, hid_input,   repid);
 	sc->sc_osize = hid_report_size(desc, size, hid_output,  repid);
 	sc->sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+	sc->sc_raw =  hid_is_collection(desc, size, uha->reportid,
+	HID_USAGE2(HUP_FIDO, HUF_U2FHID));
 
 	aprint_naive("\n");
 	aprint_normal(": input=%d, output=%d, feature=%d\n",
@@ -482,15 +485,32 @@ uhid_do_write(struct uhid_softc *sc, str
 		return EIO;
 
 	size = sc->sc_osize;
-	error = 0;
 	if (uio->uio_resid != size || size == 0)
 		return EINVAL;
 	error = uiomove(sc->sc_obuf, size, uio);
+#ifdef UHID_DEBUG
+	if (uhiddebug > 5) {
+		uint32_t i;
+
+		DPRINTF(("%s: outdata[%d] =", device_xname(sc->sc_hdev.sc_dev),
+		error));
+		for (i = 0; i < size; i++)
+			DPRINTF((" %02x", sc->sc_obuf[i]));
+		DPRINTF(("\n"));
+	}
+#endif
 	if (!error) {
-		err = uhidev_set_report(>sc_hdev, UHID_OUTPUT_REPORT,
-	sc->sc_obuf, size);
-		if (err)
+		if (sc->sc_raw)
+			err = uhidev_write(sc->sc_hdev.sc_parent, sc->sc_obuf,
+			size);
+		else
+			err = uhidev_set_report(>sc_hdev,
+			UHID_OUTPUT_REPORT, sc->sc_obuf, size);
+		if (err) {
+			DPRINTF(("%s: err = %d\n",
+			device_xname(sc->sc_hdev.sc_dev), err));
 			error = EIO;
+		}
 	}
 
 	return error;
@@ -582,6 +602,14 @@ uhid_do_ioctl(struct uhid_softc *sc, u_l
 		mutex_exit(proc_lock);
 		break;
 
+	case USB_HID_GET_RAW:
+		*(int *)addr = sc->sc_raw;
+		break;
+
+	case USB_HID_SET_RAW:
+		sc->sc_raw = *(int *)addr;
+		break;
+
 	case USB_GET_REPORT_DESC:
 		uhidev_get_report_desc(sc->sc_hdev.sc_parent, , );
 		rd = (struct usb_ctl_report_desc *)addr;

Index: src/sys/dev/usb/usbhid.h
diff -u src/sys/dev/usb/usbhid.h:1.18 src/sys/dev/usb/usbhid.h:1.18.6.1
--- src/sys/dev/usb/usbhid.h:1.18	Sun Jul 15 18:36:51 2018
+++ src/sys/dev/usb/usbhid.h	Wed Jul 15 14:09:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbhid.h,v 1.18 2018/07/15 18:36:51 maya Exp $	*/
+/*	$NetBSD: usbhid.h,v 1.18.6.1 2020/07/15 14:09:04 martin Exp $	*/
 /*	$FreeBSD: 

CVS commit: [netbsd-9] src/sys/dev/usb

2020-07-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 15 13:52:05 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ualea.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1008):

sys/dev/usb/ualea.c: revision 1.10

Turn XXX comment into KASSERT.


To generate a diff of this commit:
cvs rdiff -u -r1.9.10.1 -r1.9.10.2 src/sys/dev/usb/ualea.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/usb/ualea.c
diff -u src/sys/dev/usb/ualea.c:1.9.10.1 src/sys/dev/usb/ualea.c:1.9.10.2
--- src/sys/dev/usb/ualea.c:1.9.10.1	Mon Jul 13 14:32:20 2020
+++ src/sys/dev/usb/ualea.c	Wed Jul 15 13:52:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ualea.c,v 1.9.10.1 2020/07/13 14:32:20 martin Exp $	*/
+/*	$NetBSD: ualea.c,v 1.9.10.2 2020/07/15 13:52:05 martin Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9.10.1 2020/07/13 14:32:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9.10.2 2020/07/15 13:52:05 martin Exp $");
 
 #include 
 #include 
@@ -198,12 +198,9 @@ ualea_xfer(struct ualea_softc *sc)
 	ualea_xfer_done);
 
 	/* Issue xfer or complain if we can't.  */
-	/*
-	 * XXX Does USBD_NORMAL_COMPLETION (= 0) make sense here?  The
-	 * xfer can't complete synchronously because of the lock.
-	 */
 	status = usbd_transfer(sc->sc_xfer);
-	if (status && status != USBD_IN_PROGRESS) {
+	KASSERT(status != USBD_NORMAL_COMPLETION); /* asynchronous xfer */
+	if (status != USBD_IN_PROGRESS) {
 		aprint_error_dev(sc->sc_dev, "failed to issue xfer: %d\n",
 		status);
 		/* We failed -- let someone else have a go.  */



CVS commit: [netbsd-9] src/sys/dev/usb

2020-07-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 13 14:32:20 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: ualea.c

Log Message:
Pull up following revision(s) (requested by simonb in ticket #1003):

sys/dev/usb/ualea.c: revision 1.12

Set up the USB xfer for every transfer, not just once in the attach
function.  Caught by DIAGNOSTIC on a similar driver.  Thanks to mrg@
for USB xfer clue and martin@ for testing.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.10.1 src/sys/dev/usb/ualea.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/usb/ualea.c
diff -u src/sys/dev/usb/ualea.c:1.9 src/sys/dev/usb/ualea.c:1.9.10.1
--- src/sys/dev/usb/ualea.c:1.9	Sun Jan 21 13:57:12 2018
+++ src/sys/dev/usb/ualea.c	Mon Jul 13 14:32:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ualea.c,v 1.9 2018/01/21 13:57:12 skrll Exp $	*/
+/*	$NetBSD: ualea.c,v 1.9.10.1 2020/07/13 14:32:20 martin Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9 2018/01/21 13:57:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.9.10.1 2020/07/13 14:32:20 martin Exp $");
 
 #include 
 #include 
@@ -144,11 +144,6 @@ ualea_attach(device_t parent, device_t s
 		return;
 	}
 
-	/* Setup the xfer to call ualea_xfer_done with sc.  */
-	usbd_setup_xfer(sc->sc_xfer, sc, usbd_get_buffer(sc->sc_xfer),
-	sc->sc_maxpktsize, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT,
-	ualea_xfer_done);
-
 	/* Success!  We are ready to run.  */
 	mutex_enter(>sc_lock);
 	sc->sc_attached = true;
@@ -197,6 +192,11 @@ ualea_xfer(struct ualea_softc *sc)
 	if (sc->sc_needed == 0)
 		return;
 
+	/* Setup the xfer to call ualea_xfer_done with sc.  */
+	usbd_setup_xfer(sc->sc_xfer, sc, usbd_get_buffer(sc->sc_xfer),
+	sc->sc_maxpktsize, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT,
+	ualea_xfer_done);
+
 	/* Issue xfer or complain if we can't.  */
 	/*
 	 * XXX Does USBD_NORMAL_COMPLETION (= 0) make sense here?  The



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

2020-07-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 13 14:11:55 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: vioscsi.c

Log Message:
Pull up following revision(s) (requested by kim in ticket #1001):

sys/dev/pci/vioscsi.c: revision 1.22

Fix off-by-one SCSI target reporting

Use max_target as the controller ID instead of zero, so that the device
located at SCSI ID zero (e.g. a disk) is not obscured through not being
probed by scsi_probe_bus() (which skips the controller ID).

Copy the target requested onto the wire without decrementing it by one.

ok christos@


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.4.1 src/sys/dev/pci/vioscsi.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/vioscsi.c
diff -u src/sys/dev/pci/vioscsi.c:1.21 src/sys/dev/pci/vioscsi.c:1.21.4.1
--- src/sys/dev/pci/vioscsi.c:1.21	Sat Apr 13 06:17:33 2019
+++ src/sys/dev/pci/vioscsi.c	Mon Jul 13 14:11:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vioscsi.c,v 1.21 2019/04/13 06:17:33 maxv Exp $	*/
+/*	$NetBSD: vioscsi.c,v 1.21.4.1 2020/07/13 14:11:55 martin Exp $	*/
 /*	$OpenBSD: vioscsi.c,v 1.3 2015/03/14 03:38:49 jsg Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.21 2019/04/13 06:17:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.21.4.1 2020/07/13 14:11:55 martin Exp $");
 
 #include 
 #include 
@@ -194,7 +194,7 @@ vioscsi_attach(device_t parent, device_t
 	chan->chan_channel = 0;
 	chan->chan_ntargets = MIN(max_target, 16);	/* cap reasonably */
 	chan->chan_nluns = MIN(max_lun, 1024);		/* cap reasonably */
-	chan->chan_id = 0;
+	chan->chan_id = max_target;
 	chan->chan_flags = SCSIPI_CHAN_NOSETTLE;
 
 	config_found(self, >sc_channel, scsiprint);
@@ -318,7 +318,7 @@ vioscsi_scsipi_request(struct scsipi_cha
 	}
 
 	req->lun[0] = 1;
-	req->lun[1] = periph->periph_target - 1;
+	req->lun[1] = periph->periph_target;
 	req->lun[2] = 0x40 | ((periph->periph_lun >> 8) & 0x3F);
 	req->lun[3] = periph->periph_lun & 0xFF;
 	memset(req->lun + 4, 0, 4);



CVS commit: [netbsd-9] src/sys/dev/scsipi

2020-07-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jul 13 14:09:10 UTC 2020

Modified Files:
src/sys/dev/scsipi [netbsd-9]: scsiconf.c

Log Message:
Pull up following revision(s) (requested by kim in ticket #1000):

sys/dev/scsipi/scsiconf.c: revision 1.288

Continue scanning a SCSI bus when a LUN is reported not present

This fixes disk attachment under Qemu when there is no disk on LUN 0 on
a SCSI bus but there is a disk on LUN 1. The inquiry for LUN 0 returns
SID_QUAL_LU_NOTPRESENT & T_NODEVICE.  Quirks are only checked if neither
one of those are set, so cannot use a quirk entry.

Use case 1: Proxmox 6 configures each disk on its own bus when using
the "Virtio SCSI single" SCSI controller. However, while the "scsi0"
disk is on LUN 0, the "scsi1" disk is on LUN 1.

Use case 2: A Linode boot profile with multiple disks results in
the first disk ("sda") on LUN 1, while the second disk ("sdb") is
on LUN 0, each on their own bus.


To generate a diff of this commit:
cvs rdiff -u -r1.284.4.1 -r1.284.4.2 src/sys/dev/scsipi/scsiconf.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/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.284.4.1 src/sys/dev/scsipi/scsiconf.c:1.284.4.2
--- src/sys/dev/scsipi/scsiconf.c:1.284.4.1	Mon May  4 13:50:07 2020
+++ src/sys/dev/scsipi/scsiconf.c	Mon Jul 13 14:09:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.284.4.1 2020/05/04 13:50:07 martin Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.284.4.2 2020/07/13 14:09:10 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.284.4.1 2020/05/04 13:50:07 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.284.4.2 2020/07/13 14:09:10 martin Exp $");
 
 #include 
 #include 
@@ -887,6 +887,8 @@ scsi_probe_device(struct scsibus_softc *
 		break;
 
 	case SID_QUAL_LU_NOTPRESENT:
+		docontinue = 1;
+		/* FALLTHROUGH */
 	case SID_QUAL_reserved:
 	case SID_QUAL_LU_NOT_SUPP:
 		goto bad;



CVS commit: [netbsd-9] src/sys/dev/pci/ixgbe

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 11:35:51 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-9]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_82598.c ixgbe_common.c ixgbe_netbsd.c ixgbe_osdep.h
ixgbe_phy.c ixgbe_vf.c ixgbe_x550.c ixv.c

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #997:

sys/dev/pci/ixgbe/ix_txrx.c 1.62-1.63 via patch
sys/dev/pci/ixgbe/ixgbe.c   1.225, 1.228-1.229,
1.232 via patch
sys/dev/pci/ixgbe/ixgbe.h   1.64, 1.66
sys/dev/pci/ixgbe/ixv.c 1.146, 1.148-1.150
sys/dev/pci/ixgbe/ixgbe_common.c1.27
sys/dev/pci/ixgbe/ixgbe_vf.c1.23
sys/dev/pci/ixgbe/ixgbe_82598.c 1.15
sys/dev/pci/ixgbe/ixgbe_x550.c  1.18
sys/dev/pci/ixgbe/ixgbe_netbsd.c1.14
sys/dev/pci/ixgbe/ixgbe_phy.c   1.21
sys/dev/pci/ixgbe/ixgbe_osdep.h 1.26

- Fix IXGBE_LE32_TO_CPUS() macro for big endian machine. This problem
  was only on X550*.
- Add debug printf()s.
- Use unsigned to avoid undefined behavior in
  ixgbe_fc_enable_generic().
- Modify a little to reduce diff between ixgbe.c and ixv.c.
  No functional change.
- Modify comment.
- Remove unused macros.
- Whitespace fix.
- Fix typos.


To generate a diff of this commit:
cvs rdiff -u -r1.54.2.3 -r1.54.2.4 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.199.2.10 -r1.199.2.11 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.56.2.2 -r1.56.2.3 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.12.8.2 -r1.12.8.3 src/sys/dev/pci/ixgbe/ixgbe_82598.c
cvs rdiff -u -r1.25.2.1 -r1.25.2.2 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.9.4.2 -r1.9.4.3 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c
cvs rdiff -u -r1.23.6.2 -r1.23.6.3 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
cvs rdiff -u -r1.18.4.2 -r1.18.4.3 src/sys/dev/pci/ixgbe/ixgbe_phy.c
cvs rdiff -u -r1.18.2.1 -r1.18.2.2 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.15.2.2 -r1.15.2.3 src/sys/dev/pci/ixgbe/ixgbe_x550.c
cvs rdiff -u -r1.125.2.9 -r1.125.2.10 src/sys/dev/pci/ixgbe/ixv.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.54.2.3 src/sys/dev/pci/ixgbe/ix_txrx.c:1.54.2.4
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.54.2.3	Sun Jan 26 11:03:17 2020
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Jul 10 11:35:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.54.2.3 2020/01/26 11:03:17 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.54.2.4 2020/07/10 11:35:51 martin Exp $ */
 
 /**
 
@@ -926,7 +926,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
 	vlan_macip_lens |= ip_hlen;
 
 	/* No support for offloads for non-L4 next headers */
- 	switch (ipproto) {
+	switch (ipproto) {
 	case IPPROTO_TCP:
 		if (mp->m_pkthdr.csum_flags &
 		(M_CSUM_TCPv4 | M_CSUM_TCPv6))
@@ -1569,7 +1569,6 @@ ixgbe_setup_receive_ring(struct rx_ring 
 		rxbuf->addr = htole64(rxbuf->pmap->dm_segs[0].ds_addr);
 	}
 
-
 	/* Setup our descriptor indices */
 	rxr->next_to_check = 0;
 	rxr->next_to_refresh = 0;
@@ -1625,6 +1624,7 @@ ixgbe_setup_receive_structures(struct ad
 	struct rx_ring *rxr = adapter->rx_rings;
 	intj;
 
+	INIT_DEBUGOUT("ixgbe_setup_receive_structures");
 	for (j = 0; j < adapter->num_queues; j++, rxr++)
 		if (ixgbe_setup_receive_ring(rxr))
 			goto fail;
@@ -2233,7 +2233,7 @@ ixgbe_allocate_queues(struct adapter *ad
 
 	/* First, allocate the top level queue structs */
 	adapter->queues = (struct ix_queue *)malloc(sizeof(struct ix_queue) *
-adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO);
+	adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO);
 if (adapter->queues == NULL) {
 		aprint_error_dev(dev, "Unable to allocate queue memory\n");
 error = ENOMEM;
@@ -2300,7 +2300,7 @@ ixgbe_allocate_queues(struct adapter *ad
 			"Critical Failure setting up transmit buffers\n");
 			error = ENOMEM;
 			goto err_tx_desc;
-	}
+		}
 		if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)) {
 			/* Allocate a buf ring */
 			txr->txr_interq = pcq_create(IXGBE_BR_SIZE, KM_SLEEP);

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.10 src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.11
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.199.2.10	Tue Jan 28 11:09:27 2020
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Jul 10 11:35:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.199.2.10 2020/01/28 11:09:27 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.199.2.11 2020/07/10 11:35:51 martin Exp $ */
 
 

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

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 11:31:59 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: ichsmb.c

Log Message:
Pull up the following revisions, via patch, requested by msaitoh in
ticket #996:

sys/dev/pci/ichsmb.c1.62, 1.66-1.68

- Fix LOCKDEBUG panic on detach when attach failed.
- Add Comet Lake, Whiskey Lake U and Amber Lake Y support.
- Whitespace fix.


To generate a diff of this commit:
cvs rdiff -u -r1.60.4.1 -r1.60.4.2 src/sys/dev/pci/ichsmb.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/ichsmb.c
diff -u src/sys/dev/pci/ichsmb.c:1.60.4.1 src/sys/dev/pci/ichsmb.c:1.60.4.2
--- src/sys/dev/pci/ichsmb.c:1.60.4.1	Sun Mar  1 12:48:25 2020
+++ src/sys/dev/pci/ichsmb.c	Fri Jul 10 11:31:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ichsmb.c,v 1.60.4.1 2020/03/01 12:48:25 martin Exp $	*/
+/*	$NetBSD: ichsmb.c,v 1.60.4.2 2020/07/10 11:31:59 martin Exp $	*/
 /*	$OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.60.4.1 2020/03/01 12:48:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.60.4.2 2020/07/10 11:31:59 martin Exp $");
 
 #include 
 #include 
@@ -125,8 +125,10 @@ ichsmb_match(device_t parent, cfdata_t m
 		case PCI_PRODUCT_INTEL_100SERIES_LP_SMB:
 		case PCI_PRODUCT_INTEL_2HS_SMB:
 		case PCI_PRODUCT_INTEL_3HS_SMB:
+		case PCI_PRODUCT_INTEL_3HS_U_SMB:
 		case PCI_PRODUCT_INTEL_CORE4G_M_SMB:
 		case PCI_PRODUCT_INTEL_CORE5G_M_SMB:
+		case PCI_PRODUCT_INTEL_CMTLK_SMB:
 		case PCI_PRODUCT_INTEL_BAYTRAIL_PCU_SMB:
 		case PCI_PRODUCT_INTEL_BSW_PCU_SMB:
 		case PCI_PRODUCT_INTEL_APL_SMB:
@@ -163,6 +165,7 @@ ichsmb_attach(device_t parent, device_t 
 	sc->sc_pc = pa->pa_pc;
 
 	pci_aprint_devinfo(pa, NULL);
+	mutex_init(>sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
 
 	/* Read configuration */
 	conf = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_SMB_HOSTC);
@@ -208,7 +211,6 @@ ichsmb_attach(device_t parent, device_t 
 
 	sc->sc_i2c_device = NULL;
 	flags = 0;
-	mutex_init(>sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
 	ichsmb_rescan(self, "i2cbus", );
 
 out:	if (!pmf_device_register(self, NULL, NULL))
@@ -322,7 +324,7 @@ ichsmb_i2c_exec(void *cookie, i2c_op_t o
 	LPCIB_SMB_HS_INTR | LPCIB_SMB_HS_DEVERR |
 	LPCIB_SMB_HS_BUSERR | LPCIB_SMB_HS_FAILED);
 	bus_space_barrier(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS, 1,
-	BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);  
+	BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
 
 	/* Wait for bus to be idle */
 	for (retries = 100; retries > 0; retries--) {



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

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:45:56 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_wm.c if_wmreg.h if_wmvar.h

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #994:

sys/dev/pci/if_wm.c 1.655-1.658, 1.660, 1.662, 1.664-1.668,
1.671-1.674, 1.678,1.680-1.681 via patch
sys/dev/pci/if_wmreg.c  1.118-1.119
sys/dev/pci/if_wmvar.c  1.45

- Add SFP support. Module insertion/removal is not supported yet.
  Currently, SFP detection is only done in the driver's attach phase.
- Detect the Media Auto Sense feature. Not supported yet.
- Fix SFF_SFP_ETH_FLAGS_100FX. It's not 0x10 but 0x20.
- Add extra delay in wm_serdes_power_up_link_82575().
- Add Intel I219 LM10-LM15 and V10-V14.
- wm(4) can use workqueue as deferred Rx/Tx handler.
  Set hw.wm*.txrx_workqueue=1 to use workqueue instead of softint.
  The default value of hw.wm*.txrx_workqueue is 0 which use softint
  as before.
- Unset RSS UDP flags like ixg(4) and other OSes. To handle IP
  fragmented UDP, first packet and second packet should be processed
  in the same Rx queue.
- It's useless to not to set PCI_PMCSR_PME_STS bit when writing because
  the bit is W1C. Instead, always write PCI_PMCSR_PME_STS bit to clear
  in case it's already set.
- Actually writing always the checksum offload context descriptor
  makes the HW do extra processing, avoid doing that if possible.
- Fix a bug that the WMREG_EEARBC_I210 register is incorrectly set if
  the system uses iNVM.
- "wmX: 0" on 82542 is difficult to understand, so don't print it.
- Rename some macros and function.
- KNF. Add comment.


To generate a diff of this commit:
cvs rdiff -u -r1.645.2.4 -r1.645.2.5 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.115.2.1 -r1.115.2.2 src/sys/dev/pci/if_wmreg.h
cvs rdiff -u -r1.44 -r1.44.4.1 src/sys/dev/pci/if_wmvar.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.645.2.4 src/sys/dev/pci/if_wm.c:1.645.2.5
--- src/sys/dev/pci/if_wm.c:1.645.2.4	Sun Jan 26 11:13:27 2020
+++ src/sys/dev/pci/if_wm.c	Fri Jul 10 10:45:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.645.2.4 2020/01/26 11:13:27 martin Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.645.2.5 2020/07/10 10:45:56 martin Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.4 2020/01/26 11:13:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.645.2.5 2020/07/10 10:45:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -105,6 +105,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -156,7 +158,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.
 #define	WM_DEBUG_LOCK		__BIT(7)
 int	wm_debug = WM_DEBUG_TX | WM_DEBUG_RX | WM_DEBUG_LINK | WM_DEBUG_GMII
 | WM_DEBUG_MANAGE | WM_DEBUG_NVM | WM_DEBUG_INIT | WM_DEBUG_LOCK;
-
 #define	DPRINTF(x, y)	do { if (wm_debug & (x)) printf y; } while (0)
 #else
 #define	DPRINTF(x, y)	__nothing
@@ -164,11 +165,17 @@ int	wm_debug = WM_DEBUG_TX | WM_DEBUG_RX
 
 #ifdef NET_MPSAFE
 #define WM_MPSAFE	1
-#define CALLOUT_FLAGS	CALLOUT_MPSAFE
+#define WM_CALLOUT_FLAGS	CALLOUT_MPSAFE
+#define WM_SOFTINT_FLAGS	SOFTINT_MPSAFE
+#define WM_WORKQUEUE_FLAGS	WQ_PERCPU | WQ_MPSAFE
 #else
-#define CALLOUT_FLAGS	0
+#define WM_CALLOUT_FLAGS	0
+#define WM_SOFTINT_FLAGS	0
+#define WM_WORKQUEUE_FLAGS	WQ_PERCPU
 #endif
 
+#define WM_WORKQUEUE_PRI PRI_SOFTNET
+
 /*
  * This device driver's max interrupt numbers.
  */
@@ -374,6 +381,12 @@ struct wm_txqueue {
 	bool txq_sending;
 	time_t txq_lastsent;
 
+	/* Checksum flags used for previous packet */
+	uint32_t 	txq_last_hw_cmd;
+	uint8_t 	txq_last_hw_fields;
+	uint16_t	txq_last_hw_ipcs;
+	uint16_t	txq_last_hw_tucs;
+
 	uint32_t txq_packets;		/* for AIM */
 	uint32_t txq_bytes;		/* for AIM */
 #ifdef WM_EVENT_COUNTERS
@@ -398,6 +411,7 @@ struct wm_txqueue {
 	WM_Q_EVCNT_DEFINE(txq, toomanyseg)  /* Pkt dropped(toomany DMA segs) */
 	WM_Q_EVCNT_DEFINE(txq, defrag)	/* m_defrag() */
 	WM_Q_EVCNT_DEFINE(txq, underrun)/* Tx underrun */
+	WM_Q_EVCNT_DEFINE(txq, skipcontext) /* Tx skip wring cksum context */
 
 	char txq_txseg_evcnt_names[WM_NTXSEGS][sizeof("txqXXtxsegXXX")];
 	struct evcnt txq_ev_txseg[WM_NTXSEGS]; /* Tx packets w/ N segments */
@@ -457,6 +471,8 @@ struct wm_queue {
 	struct wm_txqueue wmq_txq;
 	struct wm_rxqueue wmq_rxq;
 
+	bool wmq_txrx_use_workqueue;
+	struct work wmq_cookie;
 	void *wmq_si;
 	krndsource_t rnd_source;	/* random source */
 };
@@ -467,6 +483,7 @@ struct wm_phyop {
 	int (*readreg_locked)(device_t, int, int, uint16_t *);
 	int (*writereg_locked)(device_t, int, int, uint16_t);
 	int reset_delay_us;
+	bool no_errprint;
 };
 
 struct 

CVS commit: [netbsd-9] src/sys/dev/i2c

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:33:38 UTC 2020

Modified Files:
src/sys/dev/i2c [netbsd-9]: sdtemp.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #992):

sys/dev/i2c/sdtemp.c: revision 1.37
sys/dev/i2c/sdtemp.c: revision 1.38
sys/dev/i2c/sdtemp.c: revision 1.39

KNF. No functional change.

  Check the return value of iic_acquire_bus(). This function may fail.

  One of the case is driver's detaching phase on shutdown. mutex_tryenter()
might fail and return with EBUSY. To avoid calling iic_release_bus() without
taking lock, check the return value of iic_acquire_bus().

  If an error occurred in sme_refresh function, pass ENVSYS_SINVALID.
OK'd by pgoyette.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.35.4.1 src/sys/dev/i2c/sdtemp.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/i2c/sdtemp.c
diff -u src/sys/dev/i2c/sdtemp.c:1.35 src/sys/dev/i2c/sdtemp.c:1.35.4.1
--- src/sys/dev/i2c/sdtemp.c:1.35	Thu Feb 28 16:56:35 2019
+++ src/sys/dev/i2c/sdtemp.c	Fri Jul 10 10:33:38 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: sdtemp.c,v 1.35 2019/02/28 16:56:35 khorben Exp $*/
+/*  $NetBSD: sdtemp.c,v 1.35.4.1 2020/07/10 10:33:38 martin Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.35 2019/02/28 16:56:35 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.35.4.1 2020/07/10 10:33:38 martin Exp $");
 
 #include 
 #include 
@@ -214,8 +214,13 @@ sdtemp_match(device_t parent, cfdata_t c
 	if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR)
 		return 0;
 
-	/* Verify that we can read the manufacturer ID, Device ID and the capability */
-	iic_acquire_bus(sc.sc_tag, 0);
+	/*
+	 * Verify that we can read the manufacturer ID, Device ID and the
+	 * capability
+	 */
+	error = iic_acquire_bus(sc.sc_tag, 0);
+	if (error)
+		return 0;
 	error = sdtemp_read_16(, SDTEMP_REG_MFG_ID,  ) |
 		sdtemp_read_16(, SDTEMP_REG_DEV_REV, ) |
 		sdtemp_read_16(, SDTEMP_REG_CAPABILITY, );
@@ -234,8 +239,8 @@ sdtemp_match(device_t parent, cfdata_t c
 	}
 
 	/*
-	 * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm
-	 * capability, too.
+	 * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the
+	 * alarm capability, too.
 	 */
 	if ((cap & SDTEMP_CAP_HAS_ALARM) == 0)
 		return 0;
@@ -255,7 +260,10 @@ sdtemp_attach(device_t parent, device_t 
 	sc->sc_address = ia->ia_addr;
 	sc->sc_dev = self;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error)
+		return;
+
 	if ((error = sdtemp_read_16(sc, SDTEMP_REG_MFG_ID,  )) != 0 ||
 	(error = sdtemp_read_16(sc, SDTEMP_REG_DEV_REV, )) != 0) {
 		iic_release_bus(sc->sc_tag, 0);
@@ -428,7 +436,9 @@ sdtemp_get_limits(struct sysmon_envsys *
 	uint16_t lim;
 
 	*props = 0;
-	iic_acquire_bus(sc->sc_tag, 0);
+	if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+		return;
+
 	if (sdtemp_read_16(sc, SDTEMP_REG_LOWER_LIM, ) == 0 && lim != 0) {
 		limits->sel_warnmin = sdtemp_decode_temp(sc, lim);
 		*props |= PROP_WARNMIN;
@@ -458,7 +468,9 @@ sdtemp_set_limits(struct sysmon_envsys *
 		limits = >sc_deflims;
 		props  = >sc_defprops;
 	}
-	iic_acquire_bus(sc->sc_tag, 0);
+	if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+		return;
+
 	if (*props & PROP_WARNMIN) {
 		val = __UK2C(limits->sel_warnmin);
 		(void)sdtemp_write_16(sc, SDTEMP_REG_LOWER_LIM,
@@ -570,7 +582,12 @@ sdtemp_refresh(struct sysmon_envsys *sme
 	uint16_t val;
 	int error;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error) {
+		edata->state = ENVSYS_SINVALID;
+		return;
+	}
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_AMBIENT_TEMP, );
 	iic_release_bus(sc->sc_tag, 0);
 
@@ -598,7 +615,7 @@ sdtemp_refresh(struct sysmon_envsys *sme
 }
 
 /*
- * power management functions
+ * Power management functions
  *
  * We go into "shutdown" mode at suspend time, and return to normal
  * mode upon resume.  This reduces power consumption by disabling
@@ -612,7 +629,10 @@ sdtemp_pmf_suspend(device_t dev, const p
 	int error;
 	uint16_t config;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error != 0)
+		return false;
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, );
 	if (error == 0) {
 		config |= SDTEMP_CONFIG_SHUTDOWN_MODE;
@@ -629,7 +649,10 @@ sdtemp_pmf_resume(device_t dev, const pm
 	int error;
 	uint16_t config;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	error = iic_acquire_bus(sc->sc_tag, 0);
+	if (error != 0)
+		return false;
+
 	error = sdtemp_read_16(sc, SDTEMP_REG_CONFIG, );
 	if (error == 0) {
 		config &= ~SDTEMP_CONFIG_SHUTDOWN_MODE;



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

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:25:25 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: pcidevs.h pcidevs_data.h

Log Message:
Regen for ticket #991


To generate a diff of this commit:
cvs rdiff -u -r1.1371.2.8 -r1.1371.2.9 src/sys/dev/pci/pcidevs.h
cvs rdiff -u -r1.1370.2.8 -r1.1370.2.9 src/sys/dev/pci/pcidevs_data.h

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

diffs are larger than 1MB and have been omitted


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

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:23:57 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: pcidevs

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #991:

sys/dev/pci/pcidevs 1.1403-1.1407, 1.1409, 1.1412-1.1418 via patch

- Add NVIDIA Quadro NVS 295.
- Add more RDC products from Andrius V.
- Add some Intel UHD Graphics devices. Mainly taken from OpenBSD.
- Add Intel Comet Lake, Whiskey Lake U and Amber Lake Y devices.
- Modify description of Intel 0x591e from HD Graphics to UHD Graphics.
- Add Intel XMM 7360 LTE Modem.
- Add Western Digital WD Blue SN550 NVMe SSD.
- Add ATI Radeon R5/R6/R7 Graphics.
- Add IDs for Ampere eMAG PCIe Root Ports.
- Add RTL8192EE Wireless LAN 802.11n PCI-E NIC.
- Add ASIX AX99100 Multi I/O (Serial,Parallel,I2C,SPI,LocalBus,GPIO)
  Controller.
- Add a couple of additional device IDs for the AMD Cryptographic
  Coprocessor.
- Remove duplicated entries.


To generate a diff of this commit:
cvs rdiff -u -r1.1383.2.8 -r1.1383.2.9 src/sys/dev/pci/pcidevs

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/pcidevs
diff -u src/sys/dev/pci/pcidevs:1.1383.2.8 src/sys/dev/pci/pcidevs:1.1383.2.9
--- src/sys/dev/pci/pcidevs:1.1383.2.8	Tue Jul  7 10:29:05 2020
+++ src/sys/dev/pci/pcidevs	Fri Jul 10 10:23:57 2020
@@ -1,4 +1,4 @@
-$NetBSD: pcidevs,v 1.1383.2.8 2020/07/07 10:29:05 martin Exp $
+$NetBSD: pcidevs,v 1.1383.2.9 2020/07/10 10:23:57 martin Exp $
 
 /*
  * Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -654,6 +654,7 @@ vendor AMAZON		0x1d0f	Amazon.com, Inc.
 vendor AQUANTIA		0x1d6a	Aquantia
 vendor ROCKCHIP		0x1d87	Rockchip
 vendor TEKRAM2		0x1de1	Tekram Technology (2nd PCI Vendor ID)
+vendor AMPERE		0x1def	Ampere Computing
 vendor SUNIX2		0x1fd4	SUNIX Co
 vendor HINT		0x3388	HiNT
 vendor 3DLABS		0x3d3d	3D Labs
@@ -1024,11 +1025,13 @@ product AMD F17_DF_5		0x1464	Family17h D
 product AMD F17_DF_6		0x1465	Family17h Data Fabric
 product AMD F17_DF_7		0x1466	Family17h Data Fabric
 product AMD F17_DF_8		0x1467	Family17h Data Fabric
+product AMD F17_CCP_2		0x1468	Family17h Crypto
 product AMD F17_PCIE_4		0x1470	Family17h PCIe
 product AMD F17_PCIE_5		0x1471	Family17h PCIe
 product AMD F17_7X_RC		0x1480	Family17h/7xh Root Complex
 product AMD F17_7X_IOMMU	0x1481	Family17h/7xh IOMMU
 product AMD F17_7X_RESV_SPP	0x1485	Family17h/7xh Reserved SPP
+product AMD F17_7X_CCP		0x1486	Family17h/7xh Crypto
 product AMD F17_7X_USB3		0x149c	Family17h/7xh USB 3.0 Host Controller
 product AMD F14_RC		0x1510	Family14h Root Complex
 product AMD F14_PCIE_1		0x1512	Family14h PCIe
@@ -1219,6 +1222,16 @@ product AMI MEGARAID3		0x1960	MegaRAID 3
 product AMI MEGARAID		0x9010	MegaRAID
 product AMI MEGARAID2		0x9060	MegaRAID 2
 
+/* Ampere Computing products */
+product AMPERE EMAG_PCIE_0	0xe005	eMAG PCIe Root Port 0
+product AMPERE EMAG_PCIE_1	0xe006	eMAG PCIe Root Port 1
+product AMPERE EMAG_PCIE_2	0xe007	eMAG PCIe Root Port 2
+product AMPERE EMAG_PCIE_3	0xe008	eMAG PCIe Root Port 3
+product AMPERE EMAG_PCIE_4	0xe009	eMAG PCIe Root Port 4
+product AMPERE EMAG_PCIE_5	0xe00a	eMAG PCIe Root Port 5
+product AMPERE EMAG_PCIE_6	0xe00b	eMAG PCIe Root Port 6
+product AMPERE EMAG_PCIE_7	0xe00c	eMAG PCIe Root Port 7
+
 /* Analog Devices products */
 product ANALOG AD1889	0x1889	AD1889 PCI SoundMAX Controller
 product ANALOG SAFENET	0x2f44	SafeNet Crypto Accelerator ADSP-2141
@@ -1293,7 +1306,6 @@ product AQUANTIA AQC100		0x00b1	AQC100 1
 product AQUANTIA AQC107		0x07b1	AQC107 10 Gigabit Network Adapter
 product AQUANTIA AQC108		0x08b1	AQC108 5 Gigabit Network Adapter
 product AQUANTIA AQC109		0x09b1	AQC109 2.5 Gigabit Network Adapter
-product AQUANTIA AQC100		0x00b1	AQC100 10 Gigabit Network Adapter
 product AQUANTIA AQC111		0x11b1	AQC111 5 Gigabit Network Adapter
 product AQUANTIA AQC112		0x12b1	AQC112 2.5 Gigabit Network Adapter
 product AQUANTIA AQC100S	0x80b1	AQC100S 10 Gigabit Network Adapter
@@ -1336,6 +1348,7 @@ product ARECA ARC1880 		0x1880	ARC-1880
 
 /* ASIX Electronics products */
 product ASIX AX88140A	0x1400	AX88140A 10/100 Ethernet
+product ASIX AX99100	0x9100	AX99100 Multi I/O Controller
 
 /* ASMedia products */
 product ASMEDIA ASM1061_01	0x0601	ASM1061 AHCI SATA III Controller
@@ -1786,6 +1799,7 @@ product ATI RADEON_HD6320	0x9806	Radeon 
 product ATI RADEON_HD7340	0x9808	Radeon HD7340 Graphics
 product ATI RADEON_HDMI_DP_AUDIO	0x9840	HDMI/DP Audio
 product ATI RADEON_R2_R3_R3E_R4	0x9854	Radeon R2/R3/R4 Graphics
+product ATI RADEON_R5_R6_R7	0x9874	Radeon R5/R6/R7 Graphics
 product ATI RADEON_HD2900_HDA	0xaa00	Radeon HD 2900 HD Audio Controller
 product ATI RADEON_HD3650_HDA	0xaa01	Radeon HD 3650/3730/3750 HD Audio Controller
 product ATI RADEON_HD2600_HDA	0xaa08	Radeon HD 2600 HD Audio Controller
@@ -3085,6 +3099,41 @@ product INTEL IVYBRIDGE_PCIE_3	0x015d	Iv
 product INTEL IVYBRIDGE_IGD_1	0x0162	Ivy Bridge 

CVS commit: [netbsd-9] src/sys/dev/mii

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:18:32 UTC 2020

Modified Files:
src/sys/dev/mii [netbsd-9]: miidevs.h miidevs_data.h

Log Message:
Regen for ticket #990


To generate a diff of this commit:
cvs rdiff -u -r1.151.2.7 -r1.151.2.8 src/sys/dev/mii/miidevs.h
cvs rdiff -u -r1.139.2.7 -r1.139.2.8 src/sys/dev/mii/miidevs_data.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/dev/mii/miidevs.h
diff -u src/sys/dev/mii/miidevs.h:1.151.2.7 src/sys/dev/mii/miidevs.h:1.151.2.8
--- src/sys/dev/mii/miidevs.h:1.151.2.7	Tue Apr 14 16:44:10 2020
+++ src/sys/dev/mii/miidevs.h	Fri Jul 10 10:18:32 2020
@@ -1,10 +1,10 @@
-/*	$NetBSD: miidevs.h,v 1.151.2.7 2020/04/14 16:44:10 martin Exp $	*/
+/*	$NetBSD: miidevs.h,v 1.151.2.8 2020/07/10 10:18:32 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: miidevs,v 1.153.2.6 2020/04/14 16:43:12 martin Exp
+ *	NetBSD: miidevs,v 1.153.2.7 2020/07/10 10:18:01 martin Exp
  */
 
 /*-
@@ -630,8 +630,28 @@
 #define	MII_STR_xxVITESSE_VSC8601	"VSC8601 10/100/1000 PHY"
 #define	MII_MODEL_xxVITESSE_VSC8641	0x0003
 #define	MII_STR_xxVITESSE_VSC8641	"Vitesse VSC8641 10/100/1000TX PHY"
+#define	MII_MODEL_xxVITESSE_VSC8504	0x000c
+#define	MII_STR_xxVITESSE_VSC8504	"Vitesse VSC8504 quad 10/100/1000TX PHY"
+#define	MII_MODEL_xxVITESSE_VSC8552	0x000e
+#define	MII_STR_xxVITESSE_VSC8552	"Vitesse VSC8552 dual 10/100/1000TX PHY"
+#define	MII_MODEL_xxVITESSE_VSC8502	0x0012
+#define	MII_STR_xxVITESSE_VSC8502	"Vitesse VSC8502 dual 10/100/1000TX PHY"
 #define	MII_MODEL_xxVITESSE_VSC8501	0x0013
 #define	MII_STR_xxVITESSE_VSC8501	"Vitesse VSC8501 10/100/1000TX PHY"
+#define	MII_MODEL_xxVITESSE_VSC8531	0x0017
+#define	MII_STR_xxVITESSE_VSC8531	"Vitesse VSC8531 10/100/1000TX PHY"
+#define	MII_MODEL_xxVITESSE_VSC8662	0x0026
+#define	MII_STR_xxVITESSE_VSC8662	"Vitesse VSC866[24] dual/quad 1000T 100FX 1000X PHY"
+#define	MII_MODEL_xxVITESSE_VSC8514	0x0027
+#define	MII_STR_xxVITESSE_VSC8514	"Vitesse VSC8514 quad 1000T PHY"
+#define	MII_MODEL_xxVITESSE_VSC8512	0x002e
+#define	MII_STR_xxVITESSE_VSC8512	"Vitesse VSC8512 12port 1000T PHY"
+#define	MII_MODEL_xxVITESSE_VSC8522	0x002f
+#define	MII_STR_xxVITESSE_VSC8522	"Vitesse VSC8522 12port 1000T PHY"
+#define	MII_MODEL_xxVITESSE_VSC8658	0x0035
+#define	MII_STR_xxVITESSE_VSC8658	"Vitesse VSC8658 octal 1000T 100FX 1000X PHY"
+#define	MII_MODEL_xxVITESSE_VSC8541	0x0037
+#define	MII_STR_xxVITESSE_VSC8541	"Vitesse VSC8541 1000T PHY"
 
 /* XaQti Corp. PHYs */
 #define	MII_MODEL_xxXAQTI_XMACII	0x

Index: src/sys/dev/mii/miidevs_data.h
diff -u src/sys/dev/mii/miidevs_data.h:1.139.2.7 src/sys/dev/mii/miidevs_data.h:1.139.2.8
--- src/sys/dev/mii/miidevs_data.h:1.139.2.7	Tue Apr 14 16:44:10 2020
+++ src/sys/dev/mii/miidevs_data.h	Fri Jul 10 10:18:32 2020
@@ -1,10 +1,10 @@
-/*	$NetBSD: miidevs_data.h,v 1.139.2.7 2020/04/14 16:44:10 martin Exp $	*/
+/*	$NetBSD: miidevs_data.h,v 1.139.2.8 2020/07/10 10:18:32 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: miidevs,v 1.153.2.6 2020/04/14 16:43:12 martin Exp
+ *	NetBSD: miidevs,v 1.153.2.7 2020/07/10 10:18:01 martin Exp
  */
 
 /*-
@@ -258,7 +258,17 @@ struct mii_knowndev mii_knowndevs[] = {
  { MII_OUI_xxVIA, MII_MODEL_xxVIA_VT6103_2, MII_STR_xxVIA_VT6103_2 },
  { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8601, MII_STR_xxVITESSE_VSC8601 },
  { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8641, MII_STR_xxVITESSE_VSC8641 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8504, MII_STR_xxVITESSE_VSC8504 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8552, MII_STR_xxVITESSE_VSC8552 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8502, MII_STR_xxVITESSE_VSC8502 },
  { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8501, MII_STR_xxVITESSE_VSC8501 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8531, MII_STR_xxVITESSE_VSC8531 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8662, MII_STR_xxVITESSE_VSC8662 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8514, MII_STR_xxVITESSE_VSC8514 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8512, MII_STR_xxVITESSE_VSC8512 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8522, MII_STR_xxVITESSE_VSC8522 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8658, MII_STR_xxVITESSE_VSC8658 },
+ { MII_OUI_xxVITESSE, MII_MODEL_xxVITESSE_VSC8541, MII_STR_xxVITESSE_VSC8541 },
  { MII_OUI_xxXAQTI, MII_MODEL_xxXAQTI_XMACII, MII_STR_xxXAQTI_XMACII },
  { 0, 0, NULL }
 };



CVS commit: [netbsd-9] src/sys/dev/mii

2020-07-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jul 10 10:18:01 UTC 2020

Modified Files:
src/sys/dev/mii [netbsd-9]: miidevs

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #990):

sys/dev/mii/miidevs: revision 1.168

  Add some Microsemi (Vitesse) devices.


To generate a diff of this commit:
cvs rdiff -u -r1.153.2.6 -r1.153.2.7 src/sys/dev/mii/miidevs

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/mii/miidevs
diff -u src/sys/dev/mii/miidevs:1.153.2.6 src/sys/dev/mii/miidevs:1.153.2.7
--- src/sys/dev/mii/miidevs:1.153.2.6	Tue Apr 14 16:43:12 2020
+++ src/sys/dev/mii/miidevs	Fri Jul 10 10:18:01 2020
@@ -1,4 +1,4 @@
-$NetBSD: miidevs,v 1.153.2.6 2020/04/14 16:43:12 martin Exp $
+$NetBSD: miidevs,v 1.153.2.7 2020/07/10 10:18:01 martin Exp $
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -407,7 +407,17 @@ model xxVIA VT6103_2		0x0034	VT6103 10/1
 /* Vitesse PHYs (Now Microsemi) */
 model xxVITESSE VSC8601		0x0002 VSC8601 10/100/1000 PHY
 model xxVITESSE VSC8641		0x0003 Vitesse VSC8641 10/100/1000TX PHY
+model xxVITESSE VSC8504		0x000c Vitesse VSC8504 quad 10/100/1000TX PHY
+model xxVITESSE VSC8552		0x000e Vitesse VSC8552 dual 10/100/1000TX PHY
+model xxVITESSE VSC8502		0x0012 Vitesse VSC8502 dual 10/100/1000TX PHY
 model xxVITESSE VSC8501		0x0013 Vitesse VSC8501 10/100/1000TX PHY
+model xxVITESSE VSC8531		0x0017 Vitesse VSC8531 10/100/1000TX PHY
+model xxVITESSE VSC8662		0x0026 Vitesse VSC866[24] dual/quad 1000T 100FX 1000X PHY
+model xxVITESSE VSC8514		0x0027 Vitesse VSC8514 quad 1000T PHY
+model xxVITESSE VSC8512		0x002e Vitesse VSC8512 12port 1000T PHY
+model xxVITESSE VSC8522		0x002f Vitesse VSC8522 12port 1000T PHY
+model xxVITESSE VSC8658		0x0035 Vitesse VSC8658 octal 1000T 100FX 1000X PHY
+model xxVITESSE VSC8541		0x0037 Vitesse VSC8541 1000T PHY
 
 /* XaQti Corp. PHYs */
 model xxXAQTI XMACII		0x XaQti Corp. XMAC II gigabit interface



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

2020-07-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jul  7 12:02:29 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: if_aq.c

Log Message:
Also pull up more cosmetic revisions to minimize diffs with HEAD, requested
by jmcneill in ticket #980:

sys/dev/pci/if_aq.c 1.8,1.17

constify, remove duplicate ;


To generate a diff of this commit:
cvs rdiff -u -r1.17.2.2 -r1.17.2.3 src/sys/dev/pci/if_aq.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_aq.c
diff -u src/sys/dev/pci/if_aq.c:1.17.2.2 src/sys/dev/pci/if_aq.c:1.17.2.3
--- src/sys/dev/pci/if_aq.c:1.17.2.2	Tue Jul  7 10:29:05 2020
+++ src/sys/dev/pci/if_aq.c	Tue Jul  7 12:02:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_aq.c,v 1.17.2.2 2020/07/07 10:29:05 martin Exp $	*/
+/*	$NetBSD: if_aq.c,v 1.17.2.3 2020/07/07 12:02:29 martin Exp $	*/
 
 /**
  * aQuantia Corporation Network Driver
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.17.2.2 2020/07/07 10:29:05 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.17.2.3 2020/07/07 12:02:29 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_if_aq.h"
@@ -952,7 +952,7 @@ struct aq_softc {
 	bus_space_tag_t sc_iot;
 	bus_space_handle_t sc_ioh;
 	bus_size_t sc_iosize;
-	bus_dma_tag_t sc_dmat;;
+	bus_dma_tag_t sc_dmat;
 
 	void *sc_ihs[AQ_NINTR_MAX];
 	pci_intr_handle_t *sc_intrs;
@@ -985,7 +985,7 @@ struct aq_softc {
 	kmutex_t sc_mutex;
 	kmutex_t sc_mpi_mutex;
 
-	struct aq_firmware_ops *sc_fw_ops;
+	const struct aq_firmware_ops *sc_fw_ops;
 	uint64_t sc_fw_caps;
 	enum aq_media_type sc_media_type;
 	aq_link_speed_t sc_available_rates;
@@ -1124,7 +1124,7 @@ static int fw2x_get_stats(struct aq_soft
 static int fw2x_get_temperature(struct aq_softc *, uint32_t *);
 #endif
 
-static struct aq_firmware_ops aq_fw1x_ops = {
+static const struct aq_firmware_ops aq_fw1x_ops = {
 	.reset = fw1x_reset,
 	.set_mode = fw1x_set_mode,
 	.get_mode = fw1x_get_mode,
@@ -1134,7 +1134,7 @@ static struct aq_firmware_ops aq_fw1x_op
 #endif
 };
 
-static struct aq_firmware_ops aq_fw2x_ops = {
+static const struct aq_firmware_ops aq_fw2x_ops = {
 	.reset = fw2x_reset,
 	.set_mode = fw2x_set_mode,
 	.get_mode = fw2x_get_mode,



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

2020-07-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jul  7 10:46:27 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: auixp.c

Log Message:
Pull up following revision(s) (requested by isaki in ticket #983):

sys/dev/pci/auixp.c: revision 1.50

Fix an argument passes to auixp_intr().

This is rest of rev 1.39 (split device_t/softc) in 2012.
Problem reported and tested by Riccardo Mottola.


To generate a diff of this commit:
cvs rdiff -u -r1.47.2.1 -r1.47.2.2 src/sys/dev/pci/auixp.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/auixp.c
diff -u src/sys/dev/pci/auixp.c:1.47.2.1 src/sys/dev/pci/auixp.c:1.47.2.2
--- src/sys/dev/pci/auixp.c:1.47.2.1	Sat Mar 21 15:31:50 2020
+++ src/sys/dev/pci/auixp.c	Tue Jul  7 10:46:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: auixp.c,v 1.47.2.1 2020/03/21 15:31:50 martin Exp $ */
+/* $NetBSD: auixp.c,v 1.47.2.2 2020/07/07 10:46:27 martin Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Reinoud Zandijk 
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.47.2.1 2020/03/21 15:31:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auixp.c,v 1.47.2.2 2020/07/07 10:46:27 martin Exp $");
 
 #include 
 #include 
@@ -1123,7 +1123,7 @@ auixp_attach(device_t parent, device_t s
 
 	/* establish interrupt routine hookup at IPL_AUDIO level */
 	sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_AUDIO, auixp_intr,
-	self, device_xname(self));
+	sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(sc->sc_dev, "can't establish interrupt");
 		if (intrstr != NULL)



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

2020-07-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jul  7 10:31:09 UTC 2020

Modified Files:
src/sys/dev/pci [netbsd-9]: pcidevs.h pcidevs_data.h

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.1371.2.7 -r1.1371.2.8 src/sys/dev/pci/pcidevs.h
cvs rdiff -u -r1.1370.2.7 -r1.1370.2.8 src/sys/dev/pci/pcidevs_data.h

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

diffs are larger than 1MB and have been omitted


CVS commit: [netbsd-9] src/sys/dev/acpi

2020-06-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 30 18:45:18 UTC 2020

Modified Files:
src/sys/dev/acpi [netbsd-9]: acpi_display.c

Log Message:
Pull up following revision(s) (requested by sborrill in ticket #978):

sys/dev/acpi/acpi_display.c: revision 1.18

Only need to set brightness if reading the initial state fails
to sync firmware and the driver. Avoids black screen at boot time.

Thanks to jmcneill@


To generate a diff of this commit:
cvs rdiff -u -r1.16.16.1 -r1.16.16.2 src/sys/dev/acpi/acpi_display.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/acpi/acpi_display.c
diff -u src/sys/dev/acpi/acpi_display.c:1.16.16.1 src/sys/dev/acpi/acpi_display.c:1.16.16.2
--- src/sys/dev/acpi/acpi_display.c:1.16.16.1	Wed Apr 29 13:36:57 2020
+++ src/sys/dev/acpi/acpi_display.c	Tue Jun 30 18:45:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.16.16.1 2020/04/29 13:36:57 martin Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.16.16.2 2020/06/30 18:45:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.16.16.1 2020/04/29 13:36:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.16.16.2 2020/06/30 18:45:18 martin Exp $");
 
 #include 
 #include 
@@ -647,8 +647,8 @@ acpidisp_out_attach(device_t parent, dev
 		 * Synchronize ACPI and driver brightness levels, and
 		 * check that brightness control is working.
 		 */
-		(void)acpidisp_get_brightness(osc, >bc_current);
-		if (acpidisp_set_brightness(osc, bc->bc_current)) {
+		if (acpidisp_get_brightness(osc, >bc_current) &&
+		acpidisp_set_brightness(osc, bc->bc_current)) {
 			kmem_free(bc->bc_level,
 			bc->bc_level_count * sizeof(*bc->bc_level));
 			kmem_free(bc, sizeof(*bc));



CVS commit: [netbsd-9] src/sys/dev/acpi

2020-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jun 20 15:52:50 UTC 2020

Modified Files:
src/sys/dev/acpi [netbsd-9]: acpi_ec.c

Log Message:
Pull up following revision(s) (requested by jdolecek in ticket #959):

sys/dev/acpi/acpi_ec.c: revision 1.84

only install space handler and enable interrupt for EC if ACPI

claims the device is actually present, it's not enough when there
is entry for it in the ACPI tables
fixes interrupt storm triggered on Dell PowerEdge R220 by enabling
GPE interrupt on a non-enabled EC (for which _REG call later
fails), reported and fix tested by Dima Veselov:
http://mail-index.netbsd.org/netbsd-users/2020/03/02/msg024166.html

XXX pullup netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.75.20.3 -r1.75.20.4 src/sys/dev/acpi/acpi_ec.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/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.75.20.3 src/sys/dev/acpi/acpi_ec.c:1.75.20.4
--- src/sys/dev/acpi/acpi_ec.c:1.75.20.3	Wed Apr 29 13:33:35 2020
+++ src/sys/dev/acpi/acpi_ec.c	Sat Jun 20 15:52:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.75.20.3 2020/04/29 13:33:35 martin Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.75.20.4 2020/06/20 15:52:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.75.20.3 2020/04/29 13:33:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.75.20.4 2020/06/20 15:52:50 martin Exp $");
 
 #include 
 #include 
@@ -268,6 +268,11 @@ acpiec_attach(device_t parent, device_t 
 		goto fail0;
 	}
 
+	if (!acpi_device_present(aa->aa_node->ad_handle)) {
+		aprint_normal(": not present\n");
+		goto fail0;
+	}
+
 	if (!acpiec_parse_gpe_package(self, aa->aa_node->ad_handle,
   _handle, ))
 		goto fail0;



CVS commit: [netbsd-9] src/sys/dev/pckbport

2020-06-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jun 20 13:53:14 UTC 2020

Modified Files:
src/sys/dev/pckbport [netbsd-9]: synaptics.c

Log Message:
Pull up following revision(s) (requested by nia in ticket #954):

sys/dev/pckbport/synaptics.c: revision 1.67

synaptics: Don't reset the device multiple times in succession
Cherrypicked from a patch from an anonymous contributor.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.5 -r1.50.2.6 src/sys/dev/pckbport/synaptics.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/pckbport/synaptics.c
diff -u src/sys/dev/pckbport/synaptics.c:1.50.2.5 src/sys/dev/pckbport/synaptics.c:1.50.2.6
--- src/sys/dev/pckbport/synaptics.c:1.50.2.5	Wed Apr 29 13:25:42 2020
+++ src/sys/dev/pckbport/synaptics.c	Sat Jun 20 13:53:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: synaptics.c,v 1.50.2.5 2020/04/29 13:25:42 martin Exp $	*/
+/*	$NetBSD: synaptics.c,v 1.50.2.6 2020/06/20 13:53:14 martin Exp $	*/
 
 /*
  * Copyright (c) 2005, Steve C. Woodford
@@ -48,7 +48,7 @@
 #include "opt_pms.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.50.2.5 2020/04/29 13:25:42 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.50.2.6 2020/06/20 13:53:14 martin Exp $");
 
 #include 
 #include 
@@ -1191,7 +1191,7 @@ pms_synaptics_input(void *vsc, int data)
 
 	getmicrouptime(>current);
 
-	if (psc->inputstate != 0) {
+	if (psc->inputstate > 0) {
 		timersub(>current, >last, );
 		if (diff.tv_sec > 0 || diff.tv_usec >= 4) {
 			aprint_debug_dev(psc->sc_dev,



CVS commit: [netbsd-9] src/sys/dev/usb

2020-06-11 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Thu Jun 11 11:03:22 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: if_run.c

Log Message:
Pull up following revision (requested by martin in ticket #958):

src/sys/dev/usb/if_run.c: revision 1.41

Better bounds checking for oversized packets, to avoid kernel memory
corruption. Pointed out by Ilja Van Sprundel.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.32.4.1 src/sys/dev/usb/if_run.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/usb/if_run.c
diff -u src/sys/dev/usb/if_run.c:1.32 src/sys/dev/usb/if_run.c:1.32.4.1
--- src/sys/dev/usb/if_run.c:1.32	Tue Jan 22 06:47:20 2019
+++ src/sys/dev/usb/if_run.c	Thu Jun 11 11:03:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_run.c,v 1.32 2019/01/22 06:47:20 skrll Exp $	*/
+/*	$NetBSD: if_run.c,v 1.32.4.1 2020/06/11 11:03:22 jdc Exp $	*/
 /*	$OpenBSD: if_run.c,v 1.90 2012/03/24 15:11:04 jsg Exp $	*/
 
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.32 2019/01/22 06:47:20 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.32.4.1 2020/06/11 11:03:22 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2255,7 +2255,8 @@ run_rx_frame(struct run_softc *sc, uint8
 		return;
 	}
 	if (len > MHLEN) {
-		MCLGET(m, M_DONTWAIT);
+		if (__predict_true(len <= MCLBYTES))
+			MCLGET(m, M_DONTWAIT);
 		if (__predict_false(!(m->m_flags & M_EXT))) {
 			ifp->if_ierrors++;
 			m_freem(m);



CVS commit: [netbsd-9] src/sys/dev/usb

2020-06-11 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Thu Jun 11 11:01:20 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: if_otus.c

Log Message:
Pull up following revision (requested by martin in ticket #957):

src/sys/dev/usb/if_otus.c: revision 1.45 (via patch)

Stricter bounds check for some packet length we get from the usb chip,
to make sure we do not corrupt kernel memory.
Pointed out by Ilja Van Sprundel.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.38.2.1 src/sys/dev/usb/if_otus.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/usb/if_otus.c
diff -u src/sys/dev/usb/if_otus.c:1.38 src/sys/dev/usb/if_otus.c:1.38.2.1
--- src/sys/dev/usb/if_otus.c:1.38	Tue May 28 07:41:50 2019
+++ src/sys/dev/usb/if_otus.c	Thu Jun 11 11:01:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_otus.c,v 1.38 2019/05/28 07:41:50 msaitoh Exp $	*/
+/*	$NetBSD: if_otus.c,v 1.38.2.1 2020/06/11 11:01:20 jdc Exp $	*/
 /*	$OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $	*/
 
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.38 2019/05/28 07:41:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.38.2.1 2020/06/11 11:01:20 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1745,6 +1745,10 @@ otus_sub_rxeof(struct otus_softc *sc, ui
 	}
 	/* Compute MPDU's length. */
 	mlen = len - AR_PLCP_HDR_LEN - sizeof(*tail);
+	if (__predict_false(mlen < IEEE80211_CRC_LEN)) {
+		ifp->if_ierrors++;
+		return;
+	}
 	mlen -= IEEE80211_CRC_LEN;	/* strip 802.11 FCS */
 	/* Make sure there's room for an 802.11 header. */
 	/*
@@ -1765,7 +1769,8 @@ otus_sub_rxeof(struct otus_softc *sc, ui
 		return;
 	}
 	if (align + mlen > MHLEN) {
-		MCLGET(m, M_DONTWAIT);
+		if (__predict_true(align + mlen <= MCLBYTES))
+			MCLGET(m, M_DONTWAIT);
 		if (__predict_false(!(m->m_flags & M_EXT))) {
 			ifp->if_ierrors++;
 			m_freem(m);



CVS commit: [netbsd-9] src/sys/dev/audio

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 19:04:00 UTC 2020

Modified Files:
src/sys/dev/audio [netbsd-9]: audio.c audiovar.h

Log Message:
Pull up following revision(s) (requested by isaki in ticket #950):

sys/dev/audio/audio.c: revision 1.71
sys/dev/audio/audio.c: revision 1.73
sys/dev/audio/audio.c: revision 1.74
sys/dev/audio/audio.c: revision 1.75
sys/dev/audio/audiovar.h: revision 1.12

audio: Fix logic for resuming when the device is in use.

audio_[r/p]mixer_start should never be called when the device is
marked busy.

Resolves a panic on resume when audio is playing, PR kern/55301

audio: remove comment that is no longer valid

audio: Only restart recording mixer on resume if it's already been started

Fix suspend/resume.
- Revert temporary usage of sc_[pr]busy during suspend.  These indicate
  whether the mixer needs to be restarted or not.
- Avoid timeout error when about to suspend.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.15 -r1.28.2.16 src/sys/dev/audio/audio.c
cvs rdiff -u -r1.4.2.3 -r1.4.2.4 src/sys/dev/audio/audiovar.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/dev/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.28.2.15 src/sys/dev/audio/audio.c:1.28.2.16
--- src/sys/dev/audio/audio.c:1.28.2.15	Mon May 18 18:12:24 2020
+++ src/sys/dev/audio/audio.c	Sun Jun  7 19:04:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.28.2.15 2020/05/18 18:12:24 martin Exp $	*/
+/*	$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.15 2020/05/18 18:12:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.28.2.16 2020/06/07 19:04:00 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1561,6 +1561,13 @@ audio_track_waitio(struct audio_softc *s
 	/* Wait for pending I/O to complete. */
 	error = cv_timedwait_sig(>mixer->outcv, sc->sc_lock,
 	mstohz(AUDIO_TIMEOUT));
+	if (sc->sc_suspending) {
+		/* If it's about to suspend, ignore timeout error. */
+		if (error == EWOULDBLOCK) {
+			TRACET(2, track, "timeout (suspending)");
+			return 0;
+		}
+	}
 	if (sc->sc_dying) {
 		error = EIO;
 	}
@@ -7748,15 +7755,17 @@ audio_suspend(device_t dv, const pmf_qua
 	error = audio_exlock_mutex_enter(sc);
 	if (error)
 		return error;
+	sc->sc_suspending = true;
 	audio_mixer_capture(sc);
 
-	/* Halts mixers but don't clear busy flag for resume */
 	if (sc->sc_pbusy) {
 		audio_pmixer_halt(sc);
+		/* Reuse this as need-to-restart flag while suspending */
 		sc->sc_pbusy = true;
 	}
 	if (sc->sc_rbusy) {
 		audio_rmixer_halt(sc);
+		/* Reuse this as need-to-restart flag while suspending */
 		sc->sc_rbusy = true;
 	}
 
@@ -7779,15 +7788,28 @@ audio_resume(device_t dv, const pmf_qual
 	if (error)
 		return error;
 
+	sc->sc_suspending = false;
 	audio_mixer_restore(sc);
 	/* XXX ? */
 	AUDIO_INITINFO();
 	audio_hw_setinfo(sc, , NULL);
 
-	if (sc->sc_pbusy)
+	/*
+	 * During from suspend to resume here, sc_[pr]busy is used as
+	 * need-to-restart flag temporarily.  After this point,
+	 * sc_[pr]busy is returned to its original usage (busy flag).
+	 * And note that sc_[pr]busy must be false to call [pr]mixer_start().
+	 */
+	if (sc->sc_pbusy) {
+		/* pmixer_start() requires pbusy is false */
+		sc->sc_pbusy = false;
 		audio_pmixer_start(sc, true);
-	if (sc->sc_rbusy)
+	}
+	if (sc->sc_rbusy) {
+		/* rmixer_start() requires rbusy is false */
+		sc->sc_rbusy = false;
 		audio_rmixer_start(sc);
+	}
 
 	audio_exlock_mutex_exit(sc);
 

Index: src/sys/dev/audio/audiovar.h
diff -u src/sys/dev/audio/audiovar.h:1.4.2.3 src/sys/dev/audio/audiovar.h:1.4.2.4
--- src/sys/dev/audio/audiovar.h:1.4.2.3	Thu Apr 30 16:05:18 2020
+++ src/sys/dev/audio/audiovar.h	Sun Jun  7 19:04:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: audiovar.h,v 1.4.2.3 2020/04/30 16:05:18 martin Exp $	*/
+/*	$NetBSD: audiovar.h,v 1.4.2.4 2020/06/07 19:04:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -243,6 +243,12 @@ struct audio_softc {
 	bool		sc_dying;
 
 	/*
+	 * Indicates that about to suspend.
+	 * Must be protected by sc_lock.
+	 */
+	bool		sc_suspending;
+
+	/*
 	 * If multiuser is false, other users who have different euid
 	 * than the first user cannot open this device.
 	 * Must be protected by sc_exlock.



CVS commit: [netbsd-9] src/sys/dev/usb

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 17:03:11 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: u3g.c ugensa.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #948):

sys/dev/usb/ugensa.c: revision 1.42
sys/dev/usb/u3g.c: revision 1.41

Remove duplicated USB_VENDOR_SIERRA USB_PRODUCT_SIERRA_USB305 entry
PR kern/55329

Replace calls to usbd_device2interface_handle in u3g_match() and
u3g_attach() with the interface already passed in uiaa->uiaa_iface and
store the interface in sc->sc_iface for later use by u3g_open()/

Also skip Direct IP interfaces in u3g_match() to avoid potential side
effects.

PR kern/55330


To generate a diff of this commit:
cvs rdiff -u -r1.37.2.1 -r1.37.2.2 src/sys/dev/usb/u3g.c
cvs rdiff -u -r1.39 -r1.39.2.1 src/sys/dev/usb/ugensa.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/usb/u3g.c
diff -u src/sys/dev/usb/u3g.c:1.37.2.1 src/sys/dev/usb/u3g.c:1.37.2.2
--- src/sys/dev/usb/u3g.c:1.37.2.1	Thu Feb 27 17:22:56 2020
+++ src/sys/dev/usb/u3g.c	Sun Jun  7 17:03:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: u3g.c,v 1.37.2.1 2020/02/27 17:22:56 martin Exp $	*/
+/*	$NetBSD: u3g.c,v 1.37.2.2 2020/06/07 17:03:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.37.2.1 2020/02/27 17:22:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.37.2.2 2020/06/07 17:03:11 martin Exp $");
 
 #include 
 #include 
@@ -114,6 +114,7 @@ struct u3g_softc {
 	struct usbd_device *	sc_udev;
 	bool			sc_dying;	/* We're going away */
 	int			sc_ifaceno;	/* Device interface number */
+	struct usbd_interface	*sc_iface;	/* Device interface */
 
 	struct u3g_com {
 		device_t	c_dev;		/* Child ucom(4) handle */
@@ -271,21 +272,12 @@ static int
 u3g_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct usbif_attach_arg *uiaa = aux;
-	struct usbd_interface *iface;
+	struct usbd_interface *iface = uiaa->uiaa_iface;
 	usb_interface_descriptor_t *id;
-	usbd_status error;
 
 	if (!usb_lookup(u3g_devs, uiaa->uiaa_vendor, uiaa->uiaa_product))
 		return UMATCH_NONE;
 
-	error = usbd_device2interface_handle(uiaa->uiaa_device,
-	uiaa->uiaa_ifaceno, );
-	if (error) {
-		printf("u3g_match: failed to get interface, err=%s\n",
-		usbd_errstr(error));
-		return UMATCH_NONE;
-	}
-
 	id = usbd_get_interface_descriptor(iface);
 	if (id == NULL) {
 		printf("u3g_match: failed to get interface descriptor\n");
@@ -302,6 +294,16 @@ u3g_match(device_t parent, cfdata_t matc
 		return UMATCH_NONE;
 
 	/*
+	 * Sierra Wireless modems use the vendor-specific class also for
+	 * Direct IP or QMI interfaces, which we should avoid attaching to.
+	 */
+	if (uiaa->uiaa_vendor == USB_VENDOR_SIERRA &&
+	id->bInterfaceClass == UICLASS_VENDOR &&
+	uiaa->uiaa_product == USB_PRODUCT_SIERRA_USB305 &&
+	 uiaa->uiaa_ifaceno >= 7)
+		return UMATCH_NONE;
+
+	/*
 	 * 3G modems generally report vendor-specific class
 	 *
 	 * XXX: this may be too generalised.
@@ -316,7 +318,7 @@ u3g_attach(device_t parent, device_t sel
 	struct u3g_softc *sc = device_private(self);
 	struct usbif_attach_arg *uiaa = aux;
 	struct usbd_device *dev = uiaa->uiaa_device;
-	struct usbd_interface *iface;
+	struct usbd_interface *iface = uiaa->uiaa_iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
 	struct ucom_attach_args ucaa;
@@ -330,13 +332,6 @@ u3g_attach(device_t parent, device_t sel
 	sc->sc_dying = false;
 	sc->sc_udev = dev;
 
-	error = usbd_device2interface_handle(dev, uiaa->uiaa_ifaceno, );
-	if (error) {
-		aprint_error_dev(self, "failed to get interface, err=%s\n",
-		usbd_errstr(error));
-		return;
-	}
-
 	id = usbd_get_interface_descriptor(iface);
 
 	ucaa.ucaa_info = "3G Modem";
@@ -352,6 +347,7 @@ u3g_attach(device_t parent, device_t sel
 	ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
 
 	sc->sc_ifaceno = uiaa->uiaa_ifaceno;
+	sc->sc_iface = uiaa->uiaa_iface;
 	intr_address = -1;
 	intr_size = 0;
 
@@ -578,7 +574,6 @@ u3g_open(void *arg, int portno)
 	usb_device_request_t req;
 	usb_endpoint_descriptor_t *ed;
 	usb_interface_descriptor_t *id;
-	struct usbd_interface *ih;
 	usbd_status err;
 	struct u3g_com *com = >sc_com[portno];
 	int i, nin;
@@ -586,14 +581,10 @@ u3g_open(void *arg, int portno)
 	if (sc->sc_dying)
  		return EIO;
 
-	err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, );
-	if (err)
-		return EIO;
-
-	id = usbd_get_interface_descriptor(ih);
+	id = usbd_get_interface_descriptor(sc->sc_iface);
 
 	for (nin = i = 0; i < id->bNumEndpoints; i++) {
-		ed = usbd_interface2endpoint_descriptor(ih, i);
+		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
 		if (ed == NULL)
 			return EIO;
 

Index: src/sys/dev/usb/ugensa.c
diff -u src/sys/dev/usb/ugensa.c:1.39 src/sys/dev/usb/ugensa.c:1.39.2.1
--- 

CVS commit: [netbsd-9] src/sys/dev/sysmon

2020-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  7 16:40:00 UTC 2020

Modified Files:
src/sys/dev/sysmon [netbsd-9]: sysmon_envsys.c

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #946):

sys/dev/sysmon/sysmon_envsys.c: revision 1.145

Don't queue sysmon refresh until the rndsource is attached.

Using the rndsource, as refreshing the sensors will do, is not
allowed until _after_ rnd_source_attach.

XXX pullup-7
XXX pullup-8
XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.144.4.1 src/sys/dev/sysmon/sysmon_envsys.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/sysmon/sysmon_envsys.c
diff -u src/sys/dev/sysmon/sysmon_envsys.c:1.144 src/sys/dev/sysmon/sysmon_envsys.c:1.144.4.1
--- src/sys/dev/sysmon/sysmon_envsys.c:1.144	Tue Mar 26 15:50:23 2019
+++ src/sys/dev/sysmon/sysmon_envsys.c	Sun Jun  7 16:40:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.144 2019/03/26 15:50:23 bad Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.144.4.1 2020/06/07 16:40:00 martin Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.144 2019/03/26 15:50:23 bad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.144.4.1 2020/06/07 16:40:00 martin Exp $");
 
 #include 
 #include 
@@ -824,16 +824,6 @@ out:
 	if (error == 0) {
 		nevent = 0;
 
-		if (sme->sme_flags & SME_INIT_REFRESH) {
-			sysmon_task_queue_sched(0, sme_initial_refresh, sme);
-			DPRINTF(("%s: scheduled initial refresh for '%s'\n",
-__func__, sme->sme_name));
-		}
-		SLIST_FOREACH(evdv, _evdrv_list, evdrv_head) {
-			sysmon_task_queue_sched(0,
-			sme_event_drvadd, evdv->evdrv);
-			nevent++;
-		}
 		/*
 		 * Hook the sensor into rnd(4) entropy pool if requested
 		 */
@@ -889,6 +879,17 @@ out:
 rnd_type, rnd_flag);
 			}
 		}
+
+		if (sme->sme_flags & SME_INIT_REFRESH) {
+			sysmon_task_queue_sched(0, sme_initial_refresh, sme);
+			DPRINTF(("%s: scheduled initial refresh for '%s'\n",
+__func__, sme->sme_name));
+		}
+		SLIST_FOREACH(evdv, _evdrv_list, evdrv_head) {
+			sysmon_task_queue_sched(0,
+			sme_event_drvadd, evdv->evdrv);
+			nevent++;
+		}
 		DPRINTF(("%s: driver '%s' registered (nsens=%d nevent=%d)\n",
 		__func__, sme->sme_name, sme->sme_nsensors, nevent));
 	}



CVS commit: [netbsd-9] src/sys/dev/usb

2020-05-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun May 31 10:25:58 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: usb.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #934):

sys/dev/usb/usb.c: revision 1.187

Don't allow open of /dev/usb if there are no attached busses.
PR kern/55303 mutex_vector_enter,512: uninitialized lock


To generate a diff of this commit:
cvs rdiff -u -r1.179.2.2 -r1.179.2.3 src/sys/dev/usb/usb.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/usb/usb.c
diff -u src/sys/dev/usb/usb.c:1.179.2.2 src/sys/dev/usb/usb.c:1.179.2.3
--- src/sys/dev/usb/usb.c:1.179.2.2	Sun Mar  1 12:35:16 2020
+++ src/sys/dev/usb/usb.c	Sun May 31 10:25:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.179.2.2 2020/03/01 12:35:16 martin Exp $	*/
+/*	$NetBSD: usb.c,v 1.179.2.3 2020/05/31 10:25:58 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.179.2.2 2020/03/01 12:35:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.179.2.3 2020/05/31 10:25:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -182,6 +182,11 @@ Static void	usb_create_event_thread(devi
 Static void	usb_event_thread(void *);
 Static void	usb_task_thread(void *);
 
+/*
+ * Count of USB busses
+ */
+int nusbbusses = 0;
+
 #define USB_MAX_EVENTS 100
 struct usb_event_q {
 	struct usb_event ue;
@@ -330,6 +335,9 @@ usb_doattach(device_t self)
 
 	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
 
+	/* Protected by KERNEL_LOCK */
+	nusbbusses++;
+
 	sc->sc_bus->ub_usbctl = self;
 	sc->sc_port.up_power = USB_MAX_POWER;
 
@@ -660,6 +668,9 @@ usbopen(dev_t dev, int flag, int mode, s
 	int unit = minor(dev);
 	struct usb_softc *sc;
 
+	if (nusbbusses == 0)
+		return ENXIO;
+
 	if (unit == USB_DEV_MINOR) {
 		if (usb_dev_open)
 			return EBUSY;



CVS commit: [netbsd-9] src/sys/dev/usb

2020-05-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May 25 15:31:45 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-9]: xhci.c

Log Message:
Pull up following revision(s) (requested by jakllsch in ticket #921):

sys/dev/usb/xhci.c: revision 1.129

xhci(4): only usbd_xfer_trycomplete() if certain to usb_transfer_complete()

Previously we'd cancel the timeout after the data stage of control xfers, and
then hope that the status stage would eventually interrupt.


To generate a diff of this commit:
cvs rdiff -u -r1.107.2.5 -r1.107.2.6 src/sys/dev/usb/xhci.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/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.107.2.5 src/sys/dev/usb/xhci.c:1.107.2.6
--- src/sys/dev/usb/xhci.c:1.107.2.5	Sun Mar  1 12:35:16 2020
+++ src/sys/dev/usb/xhci.c	Mon May 25 15:31:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.107.2.5 2020/03/01 12:35:16 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.107.2.6 2020/05/25 15:31:45 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.5 2020/03/01 12:35:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.107.2.6 2020/05/25 15:31:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1969,13 +1969,6 @@ xhci_event_transfer(struct xhci_softc * 
 		return;
 	}
 
-	/*
-	 * Try to claim this xfer for completion.  If it has already
-	 * completed or aborted, drop it on the floor.
-	 */
-	if (!usbd_xfer_trycomplete(xfer))
-		return;
-
 	/* 4.11.5.2 Event Data TRB */
 	if ((trb_3 & XHCI_TRB_3_ED_BIT) != 0) {
 		DPRINTFN(14, "transfer Event Data: 0x%016jx 0x%08jx"
@@ -2031,6 +2024,13 @@ xhci_event_transfer(struct xhci_softc * 
 		DPRINTFN(1, "ERR %ju slot %ju dci %ju", trbcode, slot, dci, 0);
 		xr->is_halted = true;
 		/*
+		 * Try to claim this xfer for completion.  If it has already
+		 * completed or aborted, drop it on the floor.
+		 */
+		if (!usbd_xfer_trycomplete(xfer))
+			return;
+
+		/*
 		 * Stalled endpoints can be recoverd by issuing
 		 * command TRB TYPE_RESET_EP on xHCI instead of
 		 * issuing request CLEAR_FEATURE UF_ENDPOINT_HALT
@@ -2055,6 +2055,13 @@ xhci_event_transfer(struct xhci_softc * 
 		break;
 	}
 
+	/*
+	 * Try to claim this xfer for completion.  If it has already
+	 * completed or aborted, drop it on the floor.
+	 */
+	if (!usbd_xfer_trycomplete(xfer))
+		return;
+
 	/* Set the status.  */
 	xfer->ux_status = err;
 



  1   2   3   >