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

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

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

Log Message:
Regen for ticket #1667 (BELKIN F5D7050E fix)


To generate a diff of this commit:
cvs rdiff -u -r1.727.2.6 -r1.727.2.7 src/sys/dev/usb/usbdevs.h
cvs rdiff -u -r1.728.2.6 -r1.728.2.7 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.727.2.6 src/sys/dev/usb/usbdevs.h:1.727.2.7
--- src/sys/dev/usb/usbdevs.h:1.727.2.6	Thu Feb 27 14:34:11 2020
+++ src/sys/dev/usb/usbdevs.h	Sat Mar 27 13:10:43 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.727.2.6 2020/02/27 14:34:11 martin Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.727.2.7 2021/03/27 13:10:43 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.7 2021/03/27 13:09:46 martin Exp
  */
 
 /*-
@@ -1087,7 +1087,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.728.2.6 src/sys/dev/usb/usbdevs_data.h:1.728.2.7
--- src/sys/dev/usb/usbdevs_data.h:1.728.2.6	Thu Feb 27 14:34:11 2020
+++ src/sys/dev/usb/usbdevs_data.h	Sat Mar 27 13:10:43 2021
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.728.2.6 2020/02/27 14:34:11 martin Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.728.2.7 2021/03/27 13:10:43 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.7 2021/03/27 13:09:46 martin Exp
  */
 
 /*-



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

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

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

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

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.736.2.6 -r1.736.2.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/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.736.2.6 src/sys/dev/usb/usbdevs:1.736.2.7
--- src/sys/dev/usb/usbdevs:1.736.2.6	Thu Feb 27 14:32:31 2020
+++ src/sys/dev/usb/usbdevs	Sat Mar 27 13:09:46 2021
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp $
+$NetBSD: usbdevs,v 1.736.2.7 2021/03/27 13:09:46 martin Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1080,7 +1080,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-8] src/sys/dev/usb

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

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

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

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.273.6.6 -r1.273.6.7 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.58.10.1 -r1.58.10.2 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.273.6.6 src/sys/dev/usb/ohci.c:1.273.6.7
--- src/sys/dev/usb/ohci.c:1.273.6.6	Tue Feb 25 18:52:44 2020
+++ src/sys/dev/usb/ohci.c	Sat Dec 12 20:30:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ohci.c,v 1.273.6.6 2020/02/25 18:52:44 martin Exp $	*/
+/*	$NetBSD: ohci.c,v 1.273.6.7 2020/12/12 20:30:57 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.273.6.6 2020/02/25 18:52:44 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.273.6.7 2020/12/12 20:30:57 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -390,6 +390,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;
 }
@@ -492,6 +493,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;
 }
@@ -539,14 +541,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;
@@ -797,6 +802,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);
 
@@ -1313,6 +1321,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) {
 /* 1 argument, but zero format strings */
 		DPRINTFN(5, "resume detect", (uintptr_t)sc, 0, 0, 0);
@@ -1391,12 +1414,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);
@@ -1449,11 +1482,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 hcpriv=%#jx", 

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

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

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

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

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.118.8.4 -r1.118.8.5 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.118.8.4 src/sys/dev/usb/ucom.c:1.118.8.5
--- src/sys/dev/usb/ucom.c:1.118.8.4	Tue May  7 18:47:01 2019
+++ src/sys/dev/usb/ucom.c	Sat Dec 12 12:58:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.118.8.4 2019/05/07 18:47:01 martin Exp $	*/
+/*	$NetBSD: ucom.c,v 1.118.8.5 2020/12/12 12:58:51 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.4 2019/05/07 18:47:01 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.5 2020/12/12 12:58:51 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -431,7 +431,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-8] src/sys/dev/usb

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

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

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

sys/dev/hid/hidkbdmap.c: revision 1.11 (patch)
(applied to sys/dev/usb/ukbdmap.c)

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.31 -r1.31.10.1 src/sys/dev/usb/ukbdmap.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/ukbdmap.c
diff -u src/sys/dev/usb/ukbdmap.c:1.31 src/sys/dev/usb/ukbdmap.c:1.31.10.1
--- src/sys/dev/usb/ukbdmap.c:1.31	Sat Apr 23 10:15:32 2016
+++ src/sys/dev/usb/ukbdmap.c	Sat Sep 19 12:20:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ukbdmap.c,v 1.31 2016/04/23 10:15:32 skrll Exp $	*/
+/*	$NetBSD: ukbdmap.c,v 1.31.10.1 2020/09/19 12:20:36 martin Exp $	*/
 
 /*
  * Copyright (c) 1999,2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbdmap.c,v 1.31 2016/04/23 10:15:32 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbdmap.c,v 1.31.10.1 2020/09/19 12:20:36 martin Exp $");
 
 #include 
 #include 
@@ -171,7 +171,8 @@ Static const keysym_t ukbd_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-8] src/sys/dev/usb

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

Modified Files:
src/sys/dev/usb [netbsd-8]: if_atu.c if_axe.c if_axen.c

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

sys/dev/usb/if_atu.c: revision 1.73
sys/dev/usb/if_axe.c: apply patch
sys/dev/usb/if_axen.c: apply patch

atu(4): Reject packets larger than MCLBYTES.


To generate a diff of this commit:
cvs rdiff -u -r1.55.8.3 -r1.55.8.4 src/sys/dev/usb/if_atu.c
cvs rdiff -u -r1.82.6.4 -r1.82.6.5 src/sys/dev/usb/if_axe.c
cvs rdiff -u -r1.11.8.8 -r1.11.8.9 src/sys/dev/usb/if_axen.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.55.8.3 src/sys/dev/usb/if_atu.c:1.55.8.4
--- src/sys/dev/usb/if_atu.c:1.55.8.3	Wed Aug  8 10:28:35 2018
+++ src/sys/dev/usb/if_atu.c	Fri Aug 28 19:44:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_atu.c,v 1.55.8.3 2018/08/08 10:28:35 martin Exp $ */
+/*	$NetBSD: if_atu.c,v 1.55.8.4 2020/08/28 19:44:22 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.55.8.3 2018/08/08 10:28:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.55.8.4 2020/08/28 19:44:22 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1687,6 +1687,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/if_axe.c
diff -u src/sys/dev/usb/if_axe.c:1.82.6.4 src/sys/dev/usb/if_axe.c:1.82.6.5
--- src/sys/dev/usb/if_axe.c:1.82.6.4	Wed Aug  8 10:28:35 2018
+++ src/sys/dev/usb/if_axe.c	Fri Aug 28 19:44:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axe.c,v 1.82.6.4 2018/08/08 10:28:35 martin Exp $	*/
+/*	$NetBSD: if_axe.c,v 1.82.6.5 2020/08/28 19:44:22 martin Exp $	*/
 /*	$OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.82.6.4 2018/08/08 10:28:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.82.6.5 2020/08/28 19:44:22 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1382,7 +1382,8 @@ axe_rxeof(struct usbd_xfer *xfer, void *
 		}
 
 		if (pktlen > MHLEN - ETHER_ALIGN) {
-			MCLGET(m, M_DONTWAIT);
+			if (pktlen <= MCLBYTES)
+MCLGET(m, M_DONTWAIT);
 			if ((m->m_flags & M_EXT) == 0) {
 m_freem(m);
 ifp->if_ierrors++;

Index: src/sys/dev/usb/if_axen.c
diff -u src/sys/dev/usb/if_axen.c:1.11.8.8 src/sys/dev/usb/if_axen.c:1.11.8.9
--- src/sys/dev/usb/if_axen.c:1.11.8.8	Mon May 13 12:40:13 2019
+++ src/sys/dev/usb/if_axen.c	Fri Aug 28 19:44:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axen.c,v 1.11.8.8 2019/05/13 12:40:13 martin Exp $	*/
+/*	$NetBSD: if_axen.c,v 1.11.8.9 2020/08/28 19:44:22 martin Exp $	*/
 /*	$OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.8 2019/05/13 12:40:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.9 2020/08/28 19:44:22 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1097,6 +1097,12 @@ axen_rxeof(struct usbd_xfer *xfer, void 
 			pkt_count));
 			goto nextpkt;
 		}
+		if (pkt_len > MCLBYTES) {
+			ifp->if_ierrors++;
+			DPRINTF(("%s: oversize frame %d\n",
+			device_xname(sc->axen_dev), pkt_len));
+			goto nextpkt;
+		}
 
 		/* process each packet */
 		/* allocate mbuf */



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

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

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

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

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.6.8.1 -r1.6.8.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.6.8.1 src/sys/dev/usb/ualea.c:1.6.8.2
--- src/sys/dev/usb/ualea.c:1.6.8.1	Wed Jan 31 18:01:54 2018
+++ src/sys/dev/usb/ualea.c	Mon Jul 13 14:35:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ualea.c,v 1.6.8.1 2018/01/31 18:01:54 martin Exp $	*/
+/*	$NetBSD: ualea.c,v 1.6.8.2 2020/07/13 14:35:29 martin Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.6.8.1 2018/01/31 18:01:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ualea.c,v 1.6.8.2 2020/07/13 14:35:29 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-8] src/sys/dev/usb

2020-06-16 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jun 16 10:28:29 UTC 2020

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

Log Message:
Pull up following revision(s) (requested by martin in ticket #1559):
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.22.2.2 -r1.22.2.3 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.22.2.2 src/sys/dev/usb/if_run.c:1.22.2.3
--- src/sys/dev/usb/if_run.c:1.22.2.2	Wed Aug  8 10:28:35 2018
+++ src/sys/dev/usb/if_run.c	Tue Jun 16 10:28:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_run.c,v 1.22.2.2 2018/08/08 10:28:35 martin Exp $	*/
+/*	$NetBSD: if_run.c,v 1.22.2.3 2020/06/16 10:28:29 bouyer 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.22.2.2 2018/08/08 10:28:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.22.2.3 2020/06/16 10:28:29 bouyer 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-8] src/sys/dev/usb

2020-06-16 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jun 16 10:27:04 UTC 2020

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

Log Message:
Pull up following revision(s) (requested by martin in ticket #1558):
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.31.2.2 -r1.31.2.3 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.31.2.2 src/sys/dev/usb/if_otus.c:1.31.2.3
--- src/sys/dev/usb/if_otus.c:1.31.2.2	Wed Aug  8 10:28:35 2018
+++ src/sys/dev/usb/if_otus.c	Tue Jun 16 10:27:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_otus.c,v 1.31.2.2 2018/08/08 10:28:35 martin Exp $	*/
+/*	$NetBSD: if_otus.c,v 1.31.2.3 2020/06/16 10:27:03 bouyer 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.31.2.2 2018/08/08 10:28:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.31.2.3 2020/06/16 10:27:03 bouyer 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-8] src/sys/dev/usb

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

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

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

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.165.6.5 -r1.165.6.6 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.165.6.5 src/sys/dev/usb/usb.c:1.165.6.6
--- src/sys/dev/usb/usb.c:1.165.6.5	Sat Nov 16 16:30:09 2019
+++ src/sys/dev/usb/usb.c	Sun May 31 10:27:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.165.6.5 2019/11/16 16:30:09 martin Exp $	*/
+/*	$NetBSD: usb.c,v 1.165.6.6 2020/05/31 10:27:26 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.165.6.5 2019/11/16 16:30:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.165.6.6 2020/05/31 10:27:26 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -179,6 +179,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;
@@ -331,6 +336,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;
 
@@ -639,6 +647,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-8] src/sys/dev/usb

2020-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb 27 14:34:13 UTC 2020

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

Log Message:
regen (for ticket #1508)


To generate a diff of this commit:
cvs rdiff -u -r1.727.2.5 -r1.727.2.6 src/sys/dev/usb/usbdevs.h
cvs rdiff -u -r1.728.2.5 -r1.728.2.6 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.727.2.5 src/sys/dev/usb/usbdevs.h:1.727.2.6
--- src/sys/dev/usb/usbdevs.h:1.727.2.5	Thu Aug  1 13:41:54 2019
+++ src/sys/dev/usb/usbdevs.h	Thu Feb 27 14:34:11 2020
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.727.2.5 2019/08/01 13:41:54 martin Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.727.2.6 2020/02/27 14:34:11 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.5 2019/08/01 13:40:54 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp
  */
 
 /*-
@@ -1432,8 +1432,10 @@
 #define	USB_PRODUCT_DLINK_DSB650TX3	0x400b		/* 10/100 ethernet adapter */
 #define	USB_PRODUCT_DLINK_DSB650TX2	0x4102		/* 10/100 ethernet adapter */
 #define	USB_PRODUCT_DLINK_DSB650	0xabc1		/* 10/100 ethernet adapter */
+#define	USB_PRODUCT_DLINK_DWM157E_CD	0xa407		/* DWM-157 CD-ROM Mode */
 #define	USB_PRODUCT_DLINK_DWM157_CD	0xa707		/* DWM-157 CD-ROM Mode */
 #define	USB_PRODUCT_DLINK_DWM157	0x7d02		/* DWM-157 LTE */
+#define	USB_PRODUCT_DLINK_DWM157E	0x7d0e		/* DWM-157 LTE */
 #define	USB_PRODUCT_DLINK_DWM222_CD	0xab00		/* DWM-222 CD-ROM Mode */
 #define	USB_PRODUCT_DLINK_DWM222	0x7e35		/* DWM-222 LTE */
 #define	USB_PRODUCT_DLINK_DWR510_CD	0xa805		/* DWR-510 CD-ROM Mode */

Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.728.2.5 src/sys/dev/usb/usbdevs_data.h:1.728.2.6
--- src/sys/dev/usb/usbdevs_data.h:1.728.2.5	Thu Aug  1 13:41:54 2019
+++ src/sys/dev/usb/usbdevs_data.h	Thu Feb 27 14:34:11 2020
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.728.2.5 2019/08/01 13:41:54 martin Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.728.2.6 2020/02/27 14:34:11 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.5 2019/08/01 13:40:54 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp
  */
 
 /*-
@@ -1796,10 +1796,14 @@ static const uint16_t usb_products[] = {
 	6668, 5155, 4911, 0,
 	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, 
 	6668, 5155, 4911, 0,
+	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157E_CD, 
+	9312, 9320, 9327, 0,
 	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157_CD, 
 	9312, 9320, 9327, 0,
 	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157, 
 	9312, 9332, 0,
+	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157E, 
+	9312, 9332, 0,
 	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM222_CD, 
 	9336, 9320, 9327, 0,
 	USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM222, 
@@ -6171,10 +6175,10 @@ static const char usb_words[] = { "." 
 	"B2\0" /* 1 refs @ 9293 */
 	"DWA-127\0" /* 1 refs @ 9296 */
 	"DWA-162\0" /* 1 refs @ 9304 */
-	"DWM-157\0" /* 2 refs @ 9312 */
-	"CD-ROM\0" /* 4 refs @ 9320 */
-	"Mode\0" /* 3 refs @ 9327 */
-	"LTE\0" /* 3 refs @ 9332 */
+	"DWM-157\0" /* 4 refs @ 9312 */
+	"CD-ROM\0" /* 5 refs @ 9320 */
+	"Mode\0" /* 4 refs @ 9327 */
+	"LTE\0" /* 4 refs @ 9332 */
 	"DWM-222\0" /* 2 refs @ 9336 */
 	"DWR-510\0" /* 2 refs @ 9344 */
 	"A1\0" /* 3 refs @ 9352 */



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

2020-02-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Feb 27 14:32:31 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-8]: u3g.c umodeswitch.c usbdevs

Log Message:
Pull up following revision(s) (requested by manu in ticket #1508):

sys/dev/usb/usbdevs: revision 1.776
sys/dev/usb/u3g.c: revision 1.40
sys/dev/usb/umodeswitch.c: revision 1.5

Add UE version of D-Link DWM-157
 -
Add support for D-Link DWM-157 3G USB modem


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.34.2.1 src/sys/dev/usb/u3g.c
cvs rdiff -u -r1.1 -r1.1.2.1 src/sys/dev/usb/umodeswitch.c
cvs rdiff -u -r1.736.2.5 -r1.736.2.6 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/u3g.c
diff -u src/sys/dev/usb/u3g.c:1.34 src/sys/dev/usb/u3g.c:1.34.2.1
--- src/sys/dev/usb/u3g.c:1.34	Wed May 24 20:23:58 2017
+++ src/sys/dev/usb/u3g.c	Thu Feb 27 14:32:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: u3g.c,v 1.34 2017/05/24 20:23:58 christos Exp $	*/
+/*	$NetBSD: u3g.c,v 1.34.2.1 2020/02/27 14:32:31 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.34 2017/05/24 20:23:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.34.2.1 2020/02/27 14:32:31 martin Exp $");
 
 #include 
 #include 
@@ -258,6 +258,10 @@ static const struct usb_devno u3g_devs[]
 	/* 4G Systems */
 	{ USB_VENDOR_4GSYSTEMS, USB_PRODUCT_4GSYSTEMS_XSSTICK_P14 },
 	{ USB_VENDOR_4GSYSTEMS, USB_PRODUCT_4GSYSTEMS_XSSTICK_W14 },
+
+	/* DLink */
+	{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157 },
+	{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DWM157E },
 };
 
 /*

Index: src/sys/dev/usb/umodeswitch.c
diff -u src/sys/dev/usb/umodeswitch.c:1.1 src/sys/dev/usb/umodeswitch.c:1.1.2.1
--- src/sys/dev/usb/umodeswitch.c:1.1	Wed May 24 20:23:58 2017
+++ src/sys/dev/usb/umodeswitch.c	Thu Feb 27 14:32:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: umodeswitch.c,v 1.1 2017/05/24 20:23:58 christos Exp $	*/
+/*	$NetBSD: umodeswitch.c,v 1.1.2.1 2020/02/27 14:32:31 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umodeswitch.c,v 1.1 2017/05/24 20:23:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umodeswitch.c,v 1.1.2.1 2020/02/27 14:32:31 martin Exp $");
 
 #include 
 #include 
@@ -428,6 +428,17 @@ umodeswitch_match(device_t parent, cfdat
 			return u3g_4gsystems_reinit(uaa->uaa_device);
 		break;
 
+	case USB_VENDOR_DLINK:
+		switch (uaa->uaa_product) {
+		case USB_PRODUCT_DLINK_DWM157E_CD:
+		case USB_PRODUCT_DLINK_DWM157_CD:
+			(void)u3g_bulk_ata_eject(uaa->uaa_device);
+			(void)u3g_bulk_scsi_eject(uaa->uaa_device);
+			return UMATCH_HIGHEST;
+		default:
+			break;
+		}
+
 	default:
 		break;
 	}

Index: src/sys/dev/usb/usbdevs
diff -u src/sys/dev/usb/usbdevs:1.736.2.5 src/sys/dev/usb/usbdevs:1.736.2.6
--- src/sys/dev/usb/usbdevs:1.736.2.5	Thu Aug  1 13:40:54 2019
+++ src/sys/dev/usb/usbdevs	Thu Feb 27 14:32:31 2020
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.736.2.5 2019/08/01 13:40:54 martin Exp $
+$NetBSD: usbdevs,v 1.736.2.6 2020/02/27 14:32:31 martin Exp $
 
 /*-
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1425,8 +1425,10 @@ product DLINK DSB650TX_PNA	0x4003	1/10/1
 product DLINK DSB650TX3		0x400b	10/100 ethernet adapter
 product DLINK DSB650TX2		0x4102	10/100 ethernet adapter
 product DLINK DSB650		0xabc1	10/100 ethernet adapter
+product DLINK DWM157E_CD	0xa407	DWM-157 CD-ROM Mode
 product DLINK DWM157_CD		0xa707	DWM-157 CD-ROM Mode
 product DLINK DWM157		0x7d02	DWM-157 LTE
+product DLINK DWM157E		0x7d0e	DWM-157 LTE
 product DLINK DWM222_CD		0xab00	DWM-222 CD-ROM Mode
 product DLINK DWM222		0x7e35	DWM-222 LTE
 product DLINK DWR510_CD		0xa805	DWR-510 CD-ROM Mode



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

2020-01-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan 31 10:55:37 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-8]: if_urlreg.h

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

sys/dev/usb/if_urlreg.h: revision 1.16

URL_TCR_IFG0 is not bit 4 but bit3. From OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.11.10.1 src/sys/dev/usb/if_urlreg.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/if_urlreg.h
diff -u src/sys/dev/usb/if_urlreg.h:1.11 src/sys/dev/usb/if_urlreg.h:1.11.10.1
--- src/sys/dev/usb/if_urlreg.h:1.11	Sat Apr 23 10:15:31 2016
+++ src/sys/dev/usb/if_urlreg.h	Fri Jan 31 10:55:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urlreg.h,v 1.11 2016/04/23 10:15:31 skrll Exp $	*/
+/*	$NetBSD: if_urlreg.h,v 1.11.10.1 2020/01/31 10:55:37 martin Exp $	*/
 /*
  * Copyright (c) 2001, 2002
  * Shingo WATANABE .  All rights reserved.
@@ -84,7 +84,7 @@
 #define	 URL_TCR_TXRR1		(1<<7) /* TX Retry Count */
 #define	 URL_TCR_TXRR0		(1<<6) /* TX Retry Count */
 #define	 URL_TCR_IFG1		(1<<4) /* Interframe Gap Time */
-#define	 URL_TCR_IFG0		(1<<4) /* Interframe Gap Time */
+#define	 URL_TCR_IFG0		(1<<3) /* Interframe Gap Time */
 #define	 URL_TCR_NOCRC		(1<<0) /* no CRC Append */
 
 #define	URL_RCR			0x0130 /* Receive Configuration Register */



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

2020-01-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan  5 15:11:29 UTC 2020

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

Log Message:
use min() instead of uimin() - the latter does not exist on this branch.


To generate a diff of this commit:
cvs rdiff -u -r1.13.8.1 -r1.13.8.2 src/sys/dev/usb/uthum.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/uthum.c
diff -u src/sys/dev/usb/uthum.c:1.13.8.1 src/sys/dev/usb/uthum.c:1.13.8.2
--- src/sys/dev/usb/uthum.c:1.13.8.1	Thu Jan  2 09:43:56 2020
+++ src/sys/dev/usb/uthum.c	Sun Jan  5 15:11:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uthum.c,v 1.13.8.1 2020/01/02 09:43:56 martin Exp $   */
+/*	$NetBSD: uthum.c,v 1.13.8.2 2020/01/05 15:11:29 martin Exp $   */
 /*	$OpenBSD: uthum.c,v 1.6 2010/01/03 18:43:02 deraadt Exp $   */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.13.8.1 2020/01/02 09:43:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uthum.c,v 1.13.8.2 2020/01/05 15:11:29 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -267,7 +267,7 @@ uthum_read_data(struct uthum_softc *sc, 
 	if ((buf == NULL) || len == 0)
 		return 0;
 
-	olen = uimin(sc->sc_olen, sizeof(cmdbuf));
+	olen = min(sc->sc_olen, sizeof(cmdbuf));
 
 	/* issue query */
 	memset(cmdbuf, 0, sizeof(cmdbuf));
@@ -298,7 +298,7 @@ uthum_read_data(struct uthum_softc *sc, 
 		tsleep(>sc_sme, 0, "uthum", (need_delay*hz+999)/1000 + 1);
 
 	/* get answer */
-	flen = uimin(sc->sc_flen, sizeof(report));
+	flen = min(sc->sc_flen, sizeof(report));
 	if (uhidev_get_report(>sc_hdev, UHID_FEATURE_REPORT,
 	report, flen))
 		return EIO;



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

2020-01-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jan  2 09:43:56 UTC 2020

Modified Files:
src/sys/dev/usb [netbsd-8]: ucycom.c uhid.c uthum.c

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

sys/dev/usb/uthum.c: revision 1.18
sys/dev/usb/ucycom.c: revision 1.49
sys/dev/usb/uhid.c: revision 1.111

Fix buffer overflows. sc_{o,f}len are controlled by the USB device. By
crafting the former the device can leak stack data. By crafting the latter
the device can overwrite the stack. The combination of the two means the
device can ROP the kernel and obtain code execution (demonstrated with an
actual exploit over vHCI).

Truncate the lengths to the size of the buffers, and also drop sc_ilen
since it is unused. Patch tested with vHCI+kASan.

 -

Fix buffer overflows. Also add missing mutex_exit.

 -

Fix buffer overflows: validate the lengths at attach time, given that they
are apparently not supposed to be variable. Drop sc_ilen since it is
unused.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.45.8.1 src/sys/dev/usb/ucycom.c
cvs rdiff -u -r1.99 -r1.99.6.1 src/sys/dev/usb/uhid.c
cvs rdiff -u -r1.13 -r1.13.8.1 src/sys/dev/usb/uthum.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/ucycom.c
diff -u src/sys/dev/usb/ucycom.c:1.45 src/sys/dev/usb/ucycom.c:1.45.8.1
--- src/sys/dev/usb/ucycom.c:1.45	Fri Nov 25 12:56:29 2016
+++ src/sys/dev/usb/ucycom.c	Thu Jan  2 09:43:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucycom.c,v 1.45 2016/11/25 12:56:29 skrll Exp $	*/
+/*	$NetBSD: ucycom.c,v 1.45.8.1 2020/01/02 09:43:56 martin Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.45 2016/11/25 12:56:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.45.8.1 2020/01/02 09:43:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -121,11 +121,15 @@ struct ucycom_softc {
 
 	struct tty		*sc_tty;
 
+	enum {
+		UCYCOM_INIT_NONE,
+		UCYCOM_INIT_INITED
+	} sc_init_state;
+
 	kmutex_t sc_lock;	/* protects refcnt, others */
 
 	/* uhidev parameters */
 	size_t			sc_flen; /* feature report length */
-	size_t			sc_ilen; /* input report length */
 	size_t			sc_olen; /* output report length */
 
 	uint8_t			*sc_obuf;
@@ -219,13 +223,18 @@ ucycom_attach(device_t parent, device_t 
 	sc->sc_hdev.sc_intr = ucycom_intr;
 	sc->sc_hdev.sc_parent = uha->parent;
 	sc->sc_hdev.sc_report_id = uha->reportid;
+	sc->sc_init_state = UCYCOM_INIT_NONE;
 
 	uhidev_get_report_desc(uha->parent, , );
 	repid = uha->reportid;
-	sc->sc_ilen = hid_report_size(desc, size, hid_input, repid);
 	sc->sc_olen = hid_report_size(desc, size, hid_output, repid);
 	sc->sc_flen = hid_report_size(desc, size, hid_feature, repid);
 
+	if (sc->sc_olen != 8 && sc->sc_olen != 32)
+		return;
+	if (sc->sc_flen != 5)
+		return;
+
 	sc->sc_msr = sc->sc_mcr = 0;
 
 	/* set up tty */
@@ -238,6 +247,8 @@ ucycom_attach(device_t parent, device_t 
 
 	/* Nothing interesting to report */
 	aprint_normal("\n");
+
+	sc->sc_init_state = UCYCOM_INIT_INITED;
 }
 
 
@@ -334,10 +345,10 @@ ucycomopen(dev_t dev, int flag, int mode
 
 	if (sc == NULL)
 		return ENXIO;
-
 	if (sc->sc_dying)
 		return EIO;
-
+	if (sc->sc_init_state != UCYCOM_INIT_INITED)
+		return ENXIO;
 	if (!device_is_active(sc->sc_hdev.sc_dev))
 		return ENXIO;
 

Index: src/sys/dev/usb/uhid.c
diff -u src/sys/dev/usb/uhid.c:1.99 src/sys/dev/usb/uhid.c:1.99.6.1
--- src/sys/dev/usb/uhid.c:1.99	Sat Mar 11 12:41:14 2017
+++ src/sys/dev/usb/uhid.c	Thu Jan  2 09:43:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhid.c,v 1.99 2017/03/11 12:41:14 maya Exp $	*/
+/*	$NetBSD: uhid.c,v 1.99.6.1 2020/01/02 09:43:56 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.99 2017/03/11 12:41:14 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.99.6.1 2020/01/02 09:43:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -393,6 +393,8 @@ uhid_do_read(struct uhid_softc *sc, stru
 	if (sc->sc_state & UHID_IMMED) {
 		DPRINTFN(1, ("uhidread immed\n"));
 		extra = sc->sc_hdev.sc_report_id != 0;
+		if (sc->sc_isize + extra > sizeof(buffer))
+			return ENOBUFS;
 		err = uhidev_get_report(>sc_hdev, UHID_INPUT_REPORT,
 	buffer, sc->sc_isize + extra);
 		if (err)
@@ -536,8 +538,10 @@ uhid_do_ioctl(struct uhid_softc *sc, u_l
 	case FIOASYNC:
 		mutex_enter(proc_lock);
 		if (*(int *)addr) {
-			if (sc->sc_async != NULL)
+			if (sc->sc_async != NULL) {
+mutex_exit(proc_lock);
 return EBUSY;
+			}
 			sc->sc_async = l->l_proc;
 			DPRINTF(("uhid_do_ioctl: FIOASYNC %p\n", l->l_proc));
 		} else
@@ -584,6 +588,8 @@ uhid_do_ioctl(struct uhid_softc *sc, u_l
 	case USB_SET_IMMED:
 		if (*(int *)addr) {
 			extra = 

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

2019-12-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Dec 14 12:33:47 UTC 2019

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

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

sys/dev/usb/if_urtwn.c: revision 1.76

Reset MCU ready status before resetting the MCU.
Fixes PR kern/54728


To generate a diff of this commit:
cvs rdiff -u -r1.53.2.5 -r1.53.2.6 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.53.2.5 src/sys/dev/usb/if_urtwn.c:1.53.2.6
--- src/sys/dev/usb/if_urtwn.c:1.53.2.5	Tue Dec 18 18:32:00 2018
+++ src/sys/dev/usb/if_urtwn.c	Sat Dec 14 12:33:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.53.2.5 2018/12/18 18:32:00 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.53.2.6 2019/12/14 12:33:47 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.53.2.5 2018/12/18 18:32:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.53.2.6 2019/12/14 12:33:47 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3412,6 +3412,8 @@ urtwn_load_firmware(struct urtwn_softc *
 	}
 
 	if (urtwn_read_1(sc, R92C_MCUFWDL) & R92C_MCUFWDL_RAM_DL_SEL) {
+		/* Reset MCU ready status */
+		urtwn_write_1(sc, R92C_MCUFWDL, 0);
 		if (ISSET(sc->chip, URTWN_CHIP_88E) ||
 		ISSET(sc->chip, URTWN_CHIP_92EU))
 			urtwn_r88e_fw_reset(sc);



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

2019-05-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May  7 18:47:01 UTC 2019

Modified Files:
src/sys/dev/usb [netbsd-8]: ucom.c umodem_common.c umodemvar.h

Log Message:
Backout the following changes (requested by mrg in ticket #1240):

sys/dev/usb/umodem_common.c: revision 1.27
sys/dev/usb/umodemvar.h: revision 1.10
sys/dev/usb/ucom.c: revision 1.122

fix umodem(4) detach.
There are different fixes upcoming.


To generate a diff of this commit:
cvs rdiff -u -r1.118.8.3 -r1.118.8.4 src/sys/dev/usb/ucom.c
cvs rdiff -u -r1.25.8.1 -r1.25.8.2 src/sys/dev/usb/umodem_common.c
cvs rdiff -u -r1.9.10.1 -r1.9.10.2 src/sys/dev/usb/umodemvar.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/ucom.c
diff -u src/sys/dev/usb/ucom.c:1.118.8.3 src/sys/dev/usb/ucom.c:1.118.8.4
--- src/sys/dev/usb/ucom.c:1.118.8.3	Mon Apr 22 08:17:50 2019
+++ src/sys/dev/usb/ucom.c	Tue May  7 18:47:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.118.8.3 2019/04/22 08:17:50 martin Exp $	*/
+/*	$NetBSD: ucom.c,v 1.118.8.4 2019/05/07 18:47:01 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.3 2019/04/22 08:17:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.4 2019/05/07 18:47:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -441,8 +441,10 @@ ucom_detach(device_t self, int flags)
 			mutex_spin_exit(_lock);
 		}
 		/* Wait for processes to go away. */
-		if (cv_timedwait(>sc_detachcv, >sc_lock, hz * 60))
-			aprint_error_dev(self, ": didn't detach\n");
+		if (cv_timedwait(>sc_detachcv, >sc_lock, hz * 60)) {
+			printf("%s: %s didn't detach\n", __func__,
+			device_xname(sc->sc_dev));
+		}
 	}
 
 	softint_disestablish(sc->sc_si);
@@ -1269,9 +1271,7 @@ ucomhwiflow(struct tty *tp, int block)
 
 	if (old && !block) {
 		sc->sc_rx_unblock = 1;
-		kpreempt_disable();
 		softint_schedule(sc->sc_si);
-		kpreempt_enable();
 	}
 	mutex_exit(>sc_lock);
 
@@ -1339,9 +1339,7 @@ ucomstart(struct tty *tp)
 
 	SIMPLEQ_INSERT_TAIL(>sc_obuff_full, ub, ub_link);
 
-	kpreempt_disable();
 	softint_schedule(sc->sc_si);
-	kpreempt_enable();
 
  out:
 	DPRINTF("... done", 0, 0, 0, 0);
@@ -1383,9 +1381,7 @@ ucom_write_status(struct ucom_softc *sc,
 		break;
 	case USBD_STALLED:
 		ub->ub_index = 0;
-		kpreempt_disable();
 		softint_schedule(sc->sc_si);
-		kpreempt_enable();
 		break;
 	case USBD_NORMAL_COMPLETION:
 		usbd_get_xfer_status(ub->ub_xfer, NULL, NULL, , NULL);

Index: src/sys/dev/usb/umodem_common.c
diff -u src/sys/dev/usb/umodem_common.c:1.25.8.1 src/sys/dev/usb/umodem_common.c:1.25.8.2
--- src/sys/dev/usb/umodem_common.c:1.25.8.1	Mon Apr 22 08:17:50 2019
+++ src/sys/dev/usb/umodem_common.c	Tue May  7 18:47:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: umodem_common.c,v 1.25.8.1 2019/04/22 08:17:50 martin Exp $	*/
+/*	$NetBSD: umodem_common.c,v 1.25.8.2 2019/05/07 18:47:01 martin Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.25.8.1 2019/04/22 08:17:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.25.8.2 2019/05/07 18:47:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -94,16 +94,16 @@ int	umodemdebug = 0;
 #define UMODEMIBUFSIZE 4096
 #define UMODEMOBUFSIZE 4096
 
-static usbd_status umodem_set_comm_feature(struct umodem_softc *,
+Static usbd_status umodem_set_comm_feature(struct umodem_softc *,
 	   int, int);
-static usbd_status umodem_set_line_coding(struct umodem_softc *,
+Static usbd_status umodem_set_line_coding(struct umodem_softc *,
 	  usb_cdc_line_state_t *);
 
-static void	umodem_dtr(struct umodem_softc *, int);
-static void	umodem_rts(struct umodem_softc *, int);
-static void	umodem_break(struct umodem_softc *, int);
-static void	umodem_set_line_state(struct umodem_softc *);
-static void	umodem_intr(struct usbd_xfer *, void *, usbd_status);
+Static void	umodem_dtr(struct umodem_softc *, int);
+Static void	umodem_rts(struct umodem_softc *, int);
+Static void	umodem_break(struct umodem_softc *, int);
+Static void	umodem_set_line_state(struct umodem_softc *);
+Static void	umodem_intr(struct usbd_xfer *, void *, usbd_status);
 
 int
 umodem_common_attach(device_t self, struct umodem_softc *sc,
@@ -120,15 +120,10 @@ umodem_common_attach(device_t self, stru
 	sc->sc_dev = self;
 	sc->sc_udev = dev;
 	sc->sc_ctl_iface = uiaa->uiaa_iface;
-	sc->sc_refcnt = 0;
-	sc->sc_dying = false;
 
 	aprint_naive("\n");
 	aprint_normal("\n");
 
-	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
-	cv_init(>sc_detach_cv, "umodemdet");
-
 	id = usbd_get_interface_descriptor(sc->sc_ctl_iface);
 	devinfop = usbd_devinfo_alloc(uiaa->uiaa_device, 0);
 	aprint_normal_dev(self, "%s, iclass %d/%d\n",
@@ -261,7 +256,7 @@ 

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

2019-04-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr 22 08:17:50 UTC 2019

Modified Files:
src/sys/dev/usb [netbsd-8]: ucom.c umodem_common.c umodemvar.h

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

sys/dev/usb/umodem_common.c: revision 1.27
sys/dev/usb/umodemvar.h: revision 1.10
sys/dev/usb/ucom.c: revision 1.122

fix umodem(4) detach:

- ucom(4) needs kpreempt disabled around softint_schedule()
- switch a copied printf() to aprint_error_dev()
- use static normally in umodem_common.c
- remove unused sc_openings in softc, convert sc_dying to real bool
- add sc_refcnt, sc_lock and sc_detach_cv to softc.  usage is:
  - sc_dying is protected by sc_lock
  - sc_detach_cv is matched with sc_lock for cv operations
  - sc_refcnt is increased in open and decreased in close, any time
it is decreased, it is checked for less than zero, and a broadcast
performed on sc_detach_cv.  detach waits for sc_refcnt.
- umodem_param() and umodem_set() check for sc_dying

this fixes pullout out an open ucom@umodem.

@skrll.

XXX: pullup


To generate a diff of this commit:
cvs rdiff -u -r1.118.8.2 -r1.118.8.3 src/sys/dev/usb/ucom.c
cvs rdiff -u -r1.25 -r1.25.8.1 src/sys/dev/usb/umodem_common.c
cvs rdiff -u -r1.9 -r1.9.10.1 src/sys/dev/usb/umodemvar.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/ucom.c
diff -u src/sys/dev/usb/ucom.c:1.118.8.2 src/sys/dev/usb/ucom.c:1.118.8.3
--- src/sys/dev/usb/ucom.c:1.118.8.2	Wed Jan 31 18:01:54 2018
+++ src/sys/dev/usb/ucom.c	Mon Apr 22 08:17:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ucom.c,v 1.118.8.2 2018/01/31 18:01:54 martin Exp $	*/
+/*	$NetBSD: ucom.c,v 1.118.8.3 2019/04/22 08:17:50 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.2 2018/01/31 18:01:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.118.8.3 2019/04/22 08:17:50 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -441,10 +441,8 @@ ucom_detach(device_t self, int flags)
 			mutex_spin_exit(_lock);
 		}
 		/* Wait for processes to go away. */
-		if (cv_timedwait(>sc_detachcv, >sc_lock, hz * 60)) {
-			printf("%s: %s didn't detach\n", __func__,
-			device_xname(sc->sc_dev));
-		}
+		if (cv_timedwait(>sc_detachcv, >sc_lock, hz * 60))
+			aprint_error_dev(self, ": didn't detach\n");
 	}
 
 	softint_disestablish(sc->sc_si);
@@ -1271,7 +1269,9 @@ ucomhwiflow(struct tty *tp, int block)
 
 	if (old && !block) {
 		sc->sc_rx_unblock = 1;
+		kpreempt_disable();
 		softint_schedule(sc->sc_si);
+		kpreempt_enable();
 	}
 	mutex_exit(>sc_lock);
 
@@ -1339,7 +1339,9 @@ ucomstart(struct tty *tp)
 
 	SIMPLEQ_INSERT_TAIL(>sc_obuff_full, ub, ub_link);
 
+	kpreempt_disable();
 	softint_schedule(sc->sc_si);
+	kpreempt_enable();
 
  out:
 	DPRINTF("... done", 0, 0, 0, 0);
@@ -1381,7 +1383,9 @@ ucom_write_status(struct ucom_softc *sc,
 		break;
 	case USBD_STALLED:
 		ub->ub_index = 0;
+		kpreempt_disable();
 		softint_schedule(sc->sc_si);
+		kpreempt_enable();
 		break;
 	case USBD_NORMAL_COMPLETION:
 		usbd_get_xfer_status(ub->ub_xfer, NULL, NULL, , NULL);

Index: src/sys/dev/usb/umodem_common.c
diff -u src/sys/dev/usb/umodem_common.c:1.25 src/sys/dev/usb/umodem_common.c:1.25.8.1
--- src/sys/dev/usb/umodem_common.c:1.25	Fri Nov 25 12:56:29 2016
+++ src/sys/dev/usb/umodem_common.c	Mon Apr 22 08:17:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: umodem_common.c,v 1.25 2016/11/25 12:56:29 skrll Exp $	*/
+/*	$NetBSD: umodem_common.c,v 1.25.8.1 2019/04/22 08:17:50 martin Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.25 2016/11/25 12:56:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.25.8.1 2019/04/22 08:17:50 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -94,16 +94,16 @@ int	umodemdebug = 0;
 #define UMODEMIBUFSIZE 4096
 #define UMODEMOBUFSIZE 4096
 
-Static usbd_status umodem_set_comm_feature(struct umodem_softc *,
+static usbd_status umodem_set_comm_feature(struct umodem_softc *,
 	   int, int);
-Static usbd_status umodem_set_line_coding(struct umodem_softc *,
+static usbd_status umodem_set_line_coding(struct umodem_softc *,
 	  usb_cdc_line_state_t *);
 
-Static void	umodem_dtr(struct umodem_softc *, int);
-Static void	umodem_rts(struct umodem_softc *, int);
-Static void	umodem_break(struct umodem_softc *, int);
-Static void	umodem_set_line_state(struct umodem_softc *);
-Static void	umodem_intr(struct usbd_xfer *, void *, usbd_status);
+static void	umodem_dtr(struct umodem_softc *, int);
+static void	umodem_rts(struct umodem_softc *, int);
+static void	umodem_break(struct umodem_softc *, int);
+static void	umodem_set_line_state(struct umodem_softc *);
+static void	umodem_intr(struct 

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

2019-02-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb 20 09:49:49 UTC 2019

Modified Files:
src/sys/dev/usb [netbsd-8]: if_axen.c if_axenreg.h

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

sys/dev/usb/if_axen.c: revision 1.26
sys/dev/usb/if_axenreg.h: revision 1.7

Remove unused variable in axen_softc.

Drop AXEN_MEDIUM_ALWAYS_ONE (from Linux), which reduces drop erros in RX.


To generate a diff of this commit:
cvs rdiff -u -r1.11.8.6 -r1.11.8.7 src/sys/dev/usb/if_axen.c
cvs rdiff -u -r1.3.10.2 -r1.3.10.3 src/sys/dev/usb/if_axenreg.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/if_axen.c
diff -u src/sys/dev/usb/if_axen.c:1.11.8.6 src/sys/dev/usb/if_axen.c:1.11.8.7
--- src/sys/dev/usb/if_axen.c:1.11.8.6	Tue Feb 19 15:09:51 2019
+++ src/sys/dev/usb/if_axen.c	Wed Feb 20 09:49:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axen.c,v 1.11.8.6 2019/02/19 15:09:51 martin Exp $	*/
+/*	$NetBSD: if_axen.c,v 1.11.8.7 2019/02/20 09:49:48 martin Exp $	*/
 /*	$OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.6 2019/02/19 15:09:51 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.7 2019/02/20 09:49:48 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -271,9 +271,8 @@ axen_miibus_statchg(struct ifnet *ifp)
 	if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
 		val |= AXEN_MEDIUM_FDX;
 
-	val |= (AXEN_MEDIUM_RECV_EN | AXEN_MEDIUM_ALWAYS_ONE);
-	val |= (AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN);
-
+	val |= AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN |
+	AXEN_MEDIUM_RECV_EN;
 	switch (IFM_SUBTYPE(mii->mii_media_active)) {
 	case IFM_1000_T:
 		val |= AXEN_MEDIUM_GIGA | AXEN_MEDIUM_EN_125MHZ;
@@ -588,9 +587,9 @@ axen_ax88179_init(struct axen_softc *sc)
 	DPRINTF(("axen: Monitor mode = 0x%02x\n", val));
 
 	/* set medium type */
-	ctl = AXEN_MEDIUM_GIGA | AXEN_MEDIUM_FDX | AXEN_MEDIUM_ALWAYS_ONE |
-	  AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN;
-	ctl |= AXEN_MEDIUM_RECV_EN;
+	ctl = AXEN_MEDIUM_GIGA | AXEN_MEDIUM_FDX | AXEN_MEDIUM_EN_125MHZ |
+	AXEN_MEDIUM_RXFLOW_CTRL_EN | AXEN_MEDIUM_TXFLOW_CTRL_EN |
+	AXEN_MEDIUM_RECV_EN;
 	wval = htole16(ctl);
 	DPRINTF(("axen: set to medium mode: 0x%04x\n", ctl));
 	axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MEDIUM_STATUS, );

Index: src/sys/dev/usb/if_axenreg.h
diff -u src/sys/dev/usb/if_axenreg.h:1.3.10.2 src/sys/dev/usb/if_axenreg.h:1.3.10.3
--- src/sys/dev/usb/if_axenreg.h:1.3.10.2	Tue Feb 19 15:09:51 2019
+++ src/sys/dev/usb/if_axenreg.h	Wed Feb 20 09:49:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axenreg.h,v 1.3.10.2 2019/02/19 15:09:51 martin Exp $	*/
+/*	$NetBSD: if_axenreg.h,v 1.3.10.3 2019/02/20 09:49:48 martin Exp $	*/
 /*	$OpenBSD: if_axenreg.h,v 1.1 2013/10/07 05:37:41 yuo Exp $	*/
 
 /*
@@ -289,7 +289,6 @@ struct axen_softc {
 
 	int			axen_link;
 
-	uint8_t			axen_ipgs[3];
 	int			axen_phyno;
 	struct timeval		axen_rx_notice;
 	struct timeval		axen_tx_notice;



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

2019-02-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 19 15:09:52 UTC 2019

Modified Files:
src/sys/dev/usb [netbsd-8]: if_axen.c if_axenreg.h

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

sys/dev/usb/if_axen.c: revision 1.27
sys/dev/usb/if_axenreg.h: revision 1.6
sys/dev/usb/if_axen.c: revision 1.32
sys/dev/usb/if_axen.c: revision 1.35
sys/dev/usb/if_axen.c: revision 1.37
sys/dev/usb/if_axenreg.h: revision 1.10
sys/dev/usb/if_axenreg.h: revision 1.11
sys/dev/usb/if_axen.c: revision 1.24

Correct error bits in RX packet header:
- Drop error is bit 31.
- CRC error is bit 29.
- Distinguish the two errors in debug printf.

Cosmetic changes; no functional changes.

Add couple of error printf.

XXX We should not to use aprint_xxx() for non-autoconf staffs.

Add ratecheck for TX errors for axen(4) and mue(4).

Remove unused.


To generate a diff of this commit:
cvs rdiff -u -r1.11.8.5 -r1.11.8.6 src/sys/dev/usb/if_axen.c
cvs rdiff -u -r1.3.10.1 -r1.3.10.2 src/sys/dev/usb/if_axenreg.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/if_axen.c
diff -u src/sys/dev/usb/if_axen.c:1.11.8.5 src/sys/dev/usb/if_axen.c:1.11.8.6
--- src/sys/dev/usb/if_axen.c:1.11.8.5	Tue Feb 19 15:05:52 2019
+++ src/sys/dev/usb/if_axen.c	Tue Feb 19 15:09:51 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axen.c,v 1.11.8.5 2019/02/19 15:05:52 martin Exp $	*/
+/*	$NetBSD: if_axen.c,v 1.11.8.6 2019/02/19 15:09:51 martin Exp $	*/
 /*	$OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.5 2019/02/19 15:05:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.6 2019/02/19 15:09:51 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -950,7 +950,6 @@ axen_rx_list_init(struct axen_softc *sc)
 	for (i = 0; i < AXEN_RX_LIST_CNT; i++) {
 		c = >axen_rx_chain[i];
 		c->axen_sc = sc;
-		c->axen_idx = i;
 		if (c->axen_xfer == NULL) {
 			int err = usbd_create_xfer(sc->axen_ep[AXEN_ENDPT_RX],
 			sc->axen_rx_bufsz, 0, 0, >axen_xfer);
@@ -976,7 +975,6 @@ axen_tx_list_init(struct axen_softc *sc)
 	for (i = 0; i < AXEN_TX_LIST_CNT; i++) {
 		c = >axen_tx_chain[i];
 		c->axen_sc = sc;
-		c->axen_idx = i;
 		if (c->axen_xfer == NULL) {
 			int err = usbd_create_xfer(sc->axen_ep[AXEN_ENDPT_TX],
 			sc->axen_tx_bufsz, USBD_FORCE_SHORT_XFER, 0,
@@ -1021,10 +1019,9 @@ axen_rxeof(struct usbd_xfer *xfer, void 
 	if (status != USBD_NORMAL_COMPLETION) {
 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
 			return;
-		if (usbd_ratecheck(>axen_rx_notice)) {
+		if (usbd_ratecheck(>axen_rx_notice))
 			aprint_error_dev(sc->axen_dev, "usb errors on rx: %s\n",
 			usbd_errstr(status));
-		}
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->axen_ep[AXEN_ENDPT_RX]);
 		goto done;
@@ -1033,6 +1030,7 @@ axen_rxeof(struct usbd_xfer *xfer, void 
 	usbd_get_xfer_status(xfer, NULL, NULL, _len, NULL);
 
 	if (total_len < sizeof(pkt_hdr)) {
+		aprint_error_dev(sc->axen_dev, "rxeof: too short transfer\n");
 		ifp->if_ierrors++;
 		goto done;
 	}
@@ -1054,6 +1052,7 @@ axen_rxeof(struct usbd_xfer *xfer, void 
 
 	/* sanity check */
 	if (hdr_offset > total_len) {
+		aprint_error_dev(sc->axen_dev, "rxeof: invalid hdr offset\n");
 		ifp->if_ierrors++;
 		usbd_delay_ms(sc->axen_udev, 100);
 		goto done;
@@ -1090,12 +1089,13 @@ axen_rxeof(struct usbd_xfer *xfer, void 
 		("%s: rxeof: packet#%d, pkt_hdr 0x%08x, pkt_len %zu\n",
 		   device_xname(sc->axen_dev), pkt_count, pkt_hdr, pkt_len));
 
-		if ((pkt_hdr & AXEN_RXHDR_CRC_ERR) ||
-		(pkt_hdr & AXEN_RXHDR_DROP_ERR)) {
+		if (pkt_hdr & (AXEN_RXHDR_CRC_ERR | AXEN_RXHDR_DROP_ERR)) {
 			ifp->if_ierrors++;
 			/* move to next pkt header */
-			DPRINTF(("%s: crc err (pkt#%d)\n",
-			device_xname(sc->axen_dev), pkt_count));
+			DPRINTF(("%s: %s err (pkt#%d)\n",
+			device_xname(sc->axen_dev),
+			(pkt_hdr & AXEN_RXHDR_CRC_ERR) ? "crc" : "drop",
+			pkt_count));
 			goto nextpkt;
 		}
 
@@ -1208,8 +1208,9 @@ axen_txeof(struct usbd_xfer *xfer, void 
 			return;
 		}
 		ifp->if_oerrors++;
-		aprint_error_dev(sc->axen_dev, "usb error on tx: %s\n",
-		usbd_errstr(status));
+		if (usbd_ratecheck(>axen_tx_notice))
+			aprint_error_dev(sc->axen_dev, "usb error on tx: %s\n",
+			usbd_errstr(status));
 		if (status == USBD_STALLED)
 			usbd_clear_endpoint_stall_async(sc->axen_ep[AXEN_ENDPT_TX]);
 		splx(s);
@@ -1547,6 +1548,7 @@ static void
 axen_stop(struct ifnet *ifp, int disable)
 {
 	struct axen_softc *sc = ifp->if_softc;
+	struct axen_chain *c;
 	usbd_status err;
 	int i;
 	uint16_t rxmode, wval;
@@ -1595,17 +1597,19 @@ axen_stop(struct ifnet *ifp, int disable
 
 	/* Free RX resources. */
 	for (i = 0; i < AXEN_RX_LIST_CNT; i++) {
-		if 

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

2019-02-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 19 15:05:52 UTC 2019

Modified Files:
src/sys/dev/usb [netbsd-8]: if_axen.c if_axenreg.h

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

sys/dev/usb/if_axen.c: revision 1.28
sys/dev/usb/if_axen.c: revision 1.29
sys/dev/usb/if_axenreg.h: revision 1.4
sys/dev/usb/if_axenreg.h: revision 1.5
sys/dev/usb/if_axen.c: revision 1.19
sys/dev/usb/if_axenreg.h: revision 1.8
sys/dev/usb/if_axen.c: revision 1.30
sys/dev/usb/if_axen.c: revision 1.31
sys/dev/usb/if_axen.c: revision 1.36
sys/dev/usb/if_axen.c: revision 1.20
sys/dev/usb/if_axen.c: revision 1.23
sys/dev/usb/if_axen.c: revision 1.25

Fix HW checksum offloading.
- Enable ones specified in if_capenable and remove AXEN_TOE macro.
- Check correct bit and set appropriate csum_flags.
- Pass packets of wrong checksum to upper layer instead of dropping them.
- Fix value of AXEN_RXHDR_L3_TYPE_MASK.

Tested on ASIX Elec. Corp. (0xb95) AX88179 (0x1790).

Fix previous:
- axen_coe() should be called from axen_init(), not axen_ax88179_init().
- Simplify logic in axen_coe(); AXEN_[RT]XCOE_OFF = 0.

Enable hash-table-based multicast filter:
- Drop AXEN_RXCTL_ACPT_PHY_MCAST bit (neither Linux nor FreeBSD sets it).
- 0x0010 bit is not AXEN_RXCTL_ACPT_BCAST ("accept broadcast") but
   AXEN_RXCTL_ACPT_MCAST ("accept multicast (hash-table-based)").

Remove useless memset.

Fix padding for a full length USB packet in TX:
- Update boundary length for SS mode, taken from OpenBSD.
- Make sure everything passed to the adapter is little endian.
- Specify padding bits in a similar manner to Linux.

XXX I wonder whether this is really necessary...

Support TSOv4 (They call it LSOv1).
The adapter does not support TSOv6 (aka LSOv2).

Fix previous.

Oops, fix previous again. Really support TSOv4.

Use unsigned variables for buffer length to avoid compiler warnings.


To generate a diff of this commit:
cvs rdiff -u -r1.11.8.4 -r1.11.8.5 src/sys/dev/usb/if_axen.c
cvs rdiff -u -r1.3 -r1.3.10.1 src/sys/dev/usb/if_axenreg.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/if_axen.c
diff -u src/sys/dev/usb/if_axen.c:1.11.8.4 src/sys/dev/usb/if_axen.c:1.11.8.5
--- src/sys/dev/usb/if_axen.c:1.11.8.4	Tue Feb 19 14:51:24 2019
+++ src/sys/dev/usb/if_axen.c	Tue Feb 19 15:05:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axen.c,v 1.11.8.4 2019/02/19 14:51:24 martin Exp $	*/
+/*	$NetBSD: if_axen.c,v 1.11.8.5 2019/02/19 15:05:52 martin Exp $	*/
 /*	$OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.4 2019/02/19 14:51:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.5 2019/02/19 15:05:52 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -50,6 +50,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 
 
 #include 
 
+#include 		/* XXX for netinet/ip.h */
+#include 		/* XXX for IP_MAXPACKET */
+
 #include 
 #include 
 
@@ -70,8 +73,6 @@ int	axendebug = 0;
 #define DPRINTFN(n,x)
 #endif
 
-#define AXEN_TOE	/* enable checksum offload function */
-
 /*
  * Various supported device vendors/products.
  */
@@ -98,6 +99,7 @@ static int	axen_rx_list_init(struct axen
 static struct mbuf *axen_newbuf(void);
 static int	axen_encap(struct axen_softc *, struct mbuf *, int);
 static void	axen_rxeof(struct usbd_xfer *, void *, usbd_status);
+static int	axen_csum_flags_rx(struct ifnet *, uint32_t);
 static void	axen_txeof(struct usbd_xfer *, void *, usbd_status);
 static void	axen_tick(void *);
 static void	axen_tick_task(void *);
@@ -122,6 +124,7 @@ static void	axen_lock_mii(struct axen_so
 static void	axen_unlock_mii(struct axen_softc *);
 
 static void	axen_ax88179_init(struct axen_softc *);
+static void	axen_setcoe(struct axen_softc *);
 
 /* Get exclusive access to the MII registers */
 static void
@@ -353,32 +356,38 @@ axen_iff(struct axen_softc *sc)
 	axen_lock_mii(sc);
 	axen_cmd(sc, AXEN_CMD_MAC_READ2, 2, AXEN_MAC_RXCTL, );
 	rxmode = le16toh(wval);
-	rxmode &= ~(AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_ACPT_PHY_MCAST |
-		  AXEN_RXCTL_PROMISC);
+	rxmode &= ~(AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_PROMISC |
+	AXEN_RXCTL_ACPT_MCAST);
 	ifp->if_flags &= ~IFF_ALLMULTI;
 
-	/*
-	 * Always accept broadcast frames.
-	 * Always accept frames destined to our station address.
-	 */
-	rxmode |= AXEN_RXCTL_ACPT_BCAST;
-
-	if (ifp->if_flags & IFF_PROMISC || ec->ec_multicnt > 0 /* XXX */) {
-		ifp->if_flags |= IFF_ALLMULTI;
-		rxmode |= AXEN_RXCTL_ACPT_ALL_MCAST | AXEN_RXCTL_ACPT_PHY_MCAST;
-		if (ifp->if_flags & IFF_PROMISC)
-			rxmode |= AXEN_RXCTL_PROMISC;
+	if (ifp->if_flags & IFF_PROMISC) {
+		DPRINTF(("%s: promisc\n", device_xname(sc->axen_dev)));
+		rxmode |= AXEN_RXCTL_PROMISC;
+allmulti:	ifp->if_flags 

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

2019-02-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 19 14:51:25 UTC 2019

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

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

sys/dev/usb/if_axen.c: revision 1.21
sys/dev/usb/if_axen.c: revision 1.22

Enable AXEN_RXCTL_START bit only when RX is ready. Otherwise,
the adapter eventually falls into "no carrier" state while it
is not running.

In axen_tick_task(), call axen_miibus_statchg() when link is lost
(like other drivers). Otherwise, link can be lost forever, which
results in sysmtem freeze.

Drop AXEN_MEDIUM_ALWAYS_ONE (from Linux), which reduces drop erros in RX.


To generate a diff of this commit:
cvs rdiff -u -r1.11.8.3 -r1.11.8.4 src/sys/dev/usb/if_axen.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_axen.c
diff -u src/sys/dev/usb/if_axen.c:1.11.8.3 src/sys/dev/usb/if_axen.c:1.11.8.4
--- src/sys/dev/usb/if_axen.c:1.11.8.3	Thu Feb  7 06:14:34 2019
+++ src/sys/dev/usb/if_axen.c	Tue Feb 19 14:51:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axen.c,v 1.11.8.3 2019/02/07 06:14:34 msaitoh Exp $	*/
+/*	$NetBSD: if_axen.c,v 1.11.8.4 2019/02/19 14:51:24 martin Exp $	*/
 /*	$OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.3 2019/02/07 06:14:34 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.11.8.4 2019/02/19 14:51:24 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -587,7 +587,6 @@ axen_ax88179_init(struct axen_softc *sc)
 	/* Set RX control register */
 	ctl = AXEN_RXCTL_IPE | AXEN_RXCTL_DROPCRCERR | AXEN_RXCTL_AUTOB;
 	ctl |= AXEN_RXCTL_ACPT_PHY_MCAST | AXEN_RXCTL_ACPT_ALL_MCAST;
-	ctl |= AXEN_RXCTL_START;
 	wval = htole16(ctl);
 	axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MAC_RXCTL, );
 
@@ -1212,15 +1211,8 @@ axen_tick_task(void *xsc)
 	s = splnet();
 
 	mii_tick(mii);
-	if (sc->axen_link == 0 &&
-	(mii->mii_media_status & IFM_ACTIVE) != 0 &&
-	IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
-		DPRINTF(("%s: %s: got link\n", device_xname(sc->axen_dev),
-		__func__));
-		sc->axen_link++;
-		if (!IFQ_IS_EMPTY(>if_snd))
-			axen_start(ifp);
-	}
+	if (sc->axen_link == 0)
+		axen_miibus_statchg(ifp);
 
 	callout_schedule(>axen_stat_ch, hz);
 
@@ -1479,9 +1471,19 @@ axen_stop(struct ifnet *ifp, int disable
 	struct axen_softc *sc = ifp->if_softc;
 	usbd_status err;
 	int i;
+	uint16_t rxmode, wval;
 
 	axen_reset(sc);
 
+	/* Disable receiver, set RX mode */
+	axen_lock_mii(sc);
+	axen_cmd(sc, AXEN_CMD_MAC_READ2, 2, AXEN_MAC_RXCTL, );
+	rxmode = le16toh(wval);
+	rxmode &= ~AXEN_RXCTL_START;
+	wval = htole16(rxmode);
+	axen_cmd(sc, AXEN_CMD_MAC_WRITE2, 2, AXEN_MAC_RXCTL, );
+	axen_unlock_mii(sc);
+
 	ifp->if_timer = 0;
 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
 



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

2019-02-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Feb  7 06:13:26 UTC 2019

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

Log Message:
Pullup the following revision (requested by martin in ticket #1182):
sys/dev/usb/usbdevs 1.753

Andrius V in Pr kern/53461: add D-Link DUB-1312


To generate a diff of this commit:
cvs rdiff -u -r1.736.2.2 -r1.736.2.3 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.736.2.2 src/sys/dev/usb/usbdevs:1.736.2.3
--- src/sys/dev/usb/usbdevs:1.736.2.2	Mon Nov 12 16:01:35 2018
+++ src/sys/dev/usb/usbdevs	Thu Feb  7 06:13:26 2019
@@ -1,4 +1,4 @@
-$NetBSD: usbdevs,v 1.736.2.2 2018/11/12 16:01:35 martin Exp $
+$NetBSD: usbdevs,v 1.736.2.3 2019/02/07 06:13:26 msaitoh Exp $
 
 /*
  * Copyright (c) 1998-2004 The NetBSD Foundation, Inc.
@@ -1373,6 +1373,7 @@ product DISPLAYLINK FYDVI	0x8060	Display
 /*product DLINK DSBS25		0x0100	DSB-S25 serial adapter*/
 product DLINK DUBE100		0x1a00	10/100 ethernet adapter
 product DLINK DUBE100C1		0x1a02	DUB-E100 rev C1
+product DLINK DUB1312		0x4a00	DUB-1312
 product DLINK DSB650TX4		0x200c	10/100 ethernet adapter
 product DLINK DWL120E		0x3200	DWL-120 rev E
 product DLINK DWA130C		0x3301	DWA-130 rev C



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

2019-01-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan 11 15:52:24 UTC 2019

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

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

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

Avoid use after free when closing interrupt pipe transfer by calling
upm_close before destroying the interupt pipe xfer.

Found by kasan on wiz's machine.


To generate a diff of this commit:
cvs rdiff -u -r1.173.2.4 -r1.173.2.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.173.2.4 src/sys/dev/usb/usbdi.c:1.173.2.5
--- src/sys/dev/usb/usbdi.c:1.173.2.4	Tue Nov 20 16:05:38 2018
+++ src/sys/dev/usb/usbdi.c	Fri Jan 11 15:52:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.173.2.4 2018/11/20 16:05:38 martin Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.173.2.5 2019/01/11 15:52:24 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.173.2.4 2018/11/20 16:05:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.173.2.5 2019/01/11 15:52:24 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -257,13 +257,14 @@ usbd_close_pipe(struct usbd_pipe *pipe)
 	LIST_REMOVE(pipe, up_next);
 	pipe->up_endpoint->ue_refcnt--;
 
+	pipe->up_methods->upm_close(pipe);
+
 	if (pipe->up_intrxfer != NULL) {
 		usbd_unlock_pipe(pipe);
 		usbd_destroy_xfer(pipe->up_intrxfer);
 		usbd_lock_pipe(pipe);
 	}
 
-	pipe->up_methods->upm_close(pipe);
 	usbd_unlock_pipe(pipe);
 	kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
 



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

2019-01-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan  4 14:55:40 UTC 2019

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

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

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

use xhci_polling_p().  this might miss when bus2 is active.
XXX: pullup-7, pullup-8.


To generate a diff of this commit:
cvs rdiff -u -r1.72.2.9 -r1.72.2.10 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.72.2.9 src/sys/dev/usb/xhci.c:1.72.2.10
--- src/sys/dev/usb/xhci.c:1.72.2.9	Fri Sep 28 08:33:43 2018
+++ src/sys/dev/usb/xhci.c	Fri Jan  4 14:55:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.72.2.9 2018/09/28 08:33:43 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.72.2.10 2019/01/04 14:55:40 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.9 2018/09/28 08:33:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.10 2019/01/04 14:55:40 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3711,7 +3711,7 @@ xhci_root_intr_start(struct usbd_xfer *x
 {
 	struct xhci_softc * const sc = XHCI_XFER2SC(xfer);
 	const size_t bn = XHCI_XFER2BUS(xfer) == >sc_bus ? 0 : 1;
-	const bool polling = sc->sc_bus.ub_usepolling;
+	const bool polling = xhci_polling_p(sc);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
@@ -3803,7 +3803,7 @@ xhci_device_ctrl_start(struct usbd_xfer 
 	uint32_t status;
 	uint32_t control;
 	u_int i;
-	const bool polling = sc->sc_bus.ub_usepolling;
+	const bool polling = xhci_polling_p(sc);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 	DPRINTFN(12, "req: %04jx %04jx %04jx %04jx",
@@ -3937,7 +3937,7 @@ xhci_device_bulk_start(struct usbd_xfer 
 	uint32_t status;
 	uint32_t control;
 	u_int i = 0;
-	const bool polling = sc->sc_bus.ub_usepolling;
+	const bool polling = xhci_polling_p(sc);
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 



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

2018-11-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 20 16:05:38 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: usb_quirks.c usb_quirks.h usbdi.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1099):

sys/dev/usb/usb_quirks.c: revision 1.90
sys/dev/usb/usbdi.c: revision 1.179
sys/dev/usb/usb_quirks.h: revision 1.29
sys/dev/usb/usbdi.c: revision 1.180

Workaround NBP PN533 USB toggle bit bugs

The PN533 is known to mishandle the USB toggle bit, causing replies to
be filtered out by the host controller. As a result, the kernel sees
a timed out operation.

Vendor errata suggests that userland applications should detect the
situation on read timeout, and write a dumy frame to resync the toggle bit.
NFC Tools's libnfc does just that, but in order to succeed, the dummy
frame write must not be reported as timed out.

We therefore introduce a new USB quirk for devices known to miss output
acks. When that occur, we pretend that the operation succeeded, leaving
userland the duty to check that everything went okay.

This workaround lets libnfc recover from interrupted communications
without the need te reboot the system.

 -

Build fix
>From David H. Gutteridge


To generate a diff of this commit:
cvs rdiff -u -r1.86.8.1 -r1.86.8.2 src/sys/dev/usb/usb_quirks.c
cvs rdiff -u -r1.27.10.1 -r1.27.10.2 src/sys/dev/usb/usb_quirks.h
cvs rdiff -u -r1.173.2.3 -r1.173.2.4 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/usb_quirks.c
diff -u src/sys/dev/usb/usb_quirks.c:1.86.8.1 src/sys/dev/usb/usb_quirks.c:1.86.8.2
--- src/sys/dev/usb/usb_quirks.c:1.86.8.1	Mon Nov 12 16:01:35 2018
+++ src/sys/dev/usb/usb_quirks.c	Tue Nov 20 16:05:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.c,v 1.86.8.1 2018/11/12 16:01:35 martin Exp $	*/
+/*	$NetBSD: usb_quirks.c,v 1.86.8.2 2018/11/20 16:05:38 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.86.8.1 2018/11/12 16:01:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.86.8.2 2018/11/20 16:05:38 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -310,13 +310,24 @@ Static const struct usbd_quirk_entry {
  { USB_VENDOR_ZOOM,		USB_PRODUCT_ZOOM_3095,			ANY,
 	{ UQ_LOST_CS_DESC, NULL }},
 
- /* NXP PN533 corrupts its USB configuration descriptors */
+ /*
+  * NXP PN533 bugs
+  * 
+  * 1. It corrupts its USB descriptors. The quirk is to provide hardcoded
+  *descriptors instead of getting them from the device.
+  * 2. It mishandles the USB toggle bit. This causes some replies to be
+  *filered out by the USB host controller and be reported as timed out.
+  *NFC tool's libnfc workaround this bug by sending a dummy frame to
+  *resync the toggle bit, but in order to succeed, that operation must
+  *not be reported as failed. The quirk is therefore to pretend to 
+  *userland that output timeouts are successes.
+  */
  { USB_VENDOR_PHILIPSSEMI,	USB_PRODUCT_PHILIPSSEMI_PN533,		ANY,
-	{ UQ_DESC_CORRUPT, desc_pn533 }},
+	{ UQ_DESC_CORRUPT | UQ_MISS_OUT_ACK, desc_pn533 }},
  { USB_VENDOR_SHUTTLE,		USB_PRODUCT_SHUTTLE_SCL3711,		ANY,
-	{ UQ_DESC_CORRUPT, desc_pn533 }},
+	{ UQ_DESC_CORRUPT | UQ_MISS_OUT_ACK, desc_pn533 }},
  { USB_VENDOR_SHUTTLE,		USB_PRODUCT_SHUTTLE_SCL3712,		ANY,
-	{ UQ_DESC_CORRUPT, desc_pn533 }},
+	{ UQ_DESC_CORRUPT | UQ_MISS_OUT_ACK, desc_pn533 }},
  { 0, 0, 0, { 0, NULL } }
 };
 

Index: src/sys/dev/usb/usb_quirks.h
diff -u src/sys/dev/usb/usb_quirks.h:1.27.10.1 src/sys/dev/usb/usb_quirks.h:1.27.10.2
--- src/sys/dev/usb/usb_quirks.h:1.27.10.1	Mon Nov 12 16:01:35 2018
+++ src/sys/dev/usb/usb_quirks.h	Tue Nov 20 16:05:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.h,v 1.27.10.1 2018/11/12 16:01:35 martin Exp $	*/
+/*	$NetBSD: usb_quirks.h,v 1.27.10.2 2018/11/20 16:05:38 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.h,v 1.9 1999/11/12 23:31:03 n_hibma Exp $	*/
 
 /*
@@ -50,6 +50,7 @@ struct usbd_quirks {
 #define UQ_LOST_CS_DESC 0x1 /* look everywhere for the CS descriptors */
 #define UQ_APPLE_ISO	0x2	/* force ISO layout on Apple keyboards */
 #define UQ_DESC_CORRUPT	0x4	/* may corrupt its config descriptors */
+#define UQ_MISS_OUT_ACK	0x8	/* may fail to ack output */
 	const usb_descriptor_t **desc;	/* Replacement for UQ_DESC_CORRUPT */
 };
 

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.173.2.3 src/sys/dev/usb/usbdi.c:1.173.2.4
--- src/sys/dev/usb/usbdi.c:1.173.2.3	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/usbdi.c	Tue Nov 20 16:05:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.173.2.3 2018/09/27 14:52:26 martin Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.173.2.4 2018/11/20 16:05:38 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD 

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

2018-11-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 12 16:02:18 UTC 2018

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

Log Message:
regen for ticket #1091


To generate a diff of this commit:
cvs rdiff -u -r1.727.2.1 -r1.727.2.2 src/sys/dev/usb/usbdevs.h
cvs rdiff -u -r1.728.2.1 -r1.728.2.2 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.727.2.1 src/sys/dev/usb/usbdevs.h:1.727.2.2
--- src/sys/dev/usb/usbdevs.h:1.727.2.1	Wed Oct 31 09:32:21 2018
+++ src/sys/dev/usb/usbdevs.h	Mon Nov 12 16:02:17 2018
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs.h,v 1.727.2.1 2018/10/31 09:32:21 martin Exp $	*/
+/*	$NetBSD: usbdevs.h,v 1.727.2.2 2018/11/12 16:02:17 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.1 2018/10/31 09:30:10 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.2 2018/11/12 16:01:35 martin Exp
  */
 
 /*
@@ -2595,6 +2595,7 @@
 
 /* Philips Semiconductor products */
 #define	USB_PRODUCT_PHILIPSSEMI_HUB1122	0x1122		/* hub */
+#define	USB_PRODUCT_PHILIPSSEMI_PN533	0x2533		/* NFC PN533 */
 
 /* P.I. Engineering products */
 #define	USB_PRODUCT_PIENGINEERING_PS2USB	0x020b		/* PS2 to Mac USB Adapter */
@@ -2938,6 +2939,8 @@
 #define	USB_PRODUCT_SHUTTLE_CDRW	0x0101		/* CD-RW Device */
 #define	USB_PRODUCT_SHUTTLE_ORCA	0x0325		/* eUSB ORCA Quad Reader */
 #define	USB_PRODUCT_SHUTTLE_SCM	0x1010		/* SCM Micro */
+#define	USB_PRODUCT_SHUTTLE_SCL3711	0x5591		/* SCM Micro SCL3711-NFC */
+#define	USB_PRODUCT_SHUTTLE_SCL3712	0x5594		/* SCM Micro SCL3712-NFC */
 
 /* Siemens products */
 #define	USB_PRODUCT_SIEMENS_SPEEDSTREAM	0x1001		/* SpeedStream USB */

Index: src/sys/dev/usb/usbdevs_data.h
diff -u src/sys/dev/usb/usbdevs_data.h:1.728.2.1 src/sys/dev/usb/usbdevs_data.h:1.728.2.2
--- src/sys/dev/usb/usbdevs_data.h:1.728.2.1	Wed Oct 31 09:32:21 2018
+++ src/sys/dev/usb/usbdevs_data.h	Mon Nov 12 16:02:17 2018
@@ -1,10 +1,10 @@
-/*	$NetBSD: usbdevs_data.h,v 1.728.2.1 2018/10/31 09:32:21 martin Exp $	*/
+/*	$NetBSD: usbdevs_data.h,v 1.728.2.2 2018/11/12 16:02:17 martin Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	NetBSD: usbdevs,v 1.736.2.1 2018/10/31 09:30:10 martin Exp
+ *	NetBSD: usbdevs,v 1.736.2.2 2018/11/12 16:01:35 martin Exp
  */
 
 /*
@@ -3472,88 +3472,90 @@ static const uint16_t usb_products[] = {
 	4969, 0,
 	USB_VENDOR_PHILIPSSEMI, USB_PRODUCT_PHILIPSSEMI_HUB1122, 
 	6882, 0,
+	USB_VENDOR_PHILIPSSEMI, USB_PRODUCT_PHILIPSSEMI_PN533, 
+	15490, 15494, 0,
 	USB_VENDOR_PIENGINEERING, USB_PRODUCT_PIENGINEERING_PS2USB, 
 	8034, 5556, 9582, 4743, 4757, 0,
 	USB_VENDOR_PIENGINEERING, USB_PRODUCT_PIENGINEERING_XKEYS58, 
-	15490, 15496, 5759, 15509, 15513, 0,
+	15500, 15506, 5759, 15519, 15523, 0,
 	USB_VENDOR_PIENGINEERING, USB_PRODUCT_PIENGINEERING_XKEYS, 
-	15490, 15496, 5759, 0,
+	15500, 15506, 5759, 0,
 	USB_VENDOR_PILOTECH, USB_PRODUCT_PILOTECH_CRW600, 
-	15519, 14389, 10260, 0,
+	15529, 14389, 10260, 0,
 	USB_VENDOR_PINNACLE, USB_PRODUCT_PINNACLE_PCTV800E, 
-	15527, 15532, 0,
+	15537, 15542, 0,
 	USB_VENDOR_PINNACLE, USB_PRODUCT_PINNACLE_PCTVDVBTFLASH, 
-	4461, 15527, 6687, 11242, 0,
+	4461, 15537, 6687, 11242, 0,
 	USB_VENDOR_PINNACLE, USB_PRODUCT_PINNACLE_PCTV72E, 
-	4461, 15527, 15537, 0,
+	4461, 15537, 15547, 0,
 	USB_VENDOR_PINNACLE, USB_PRODUCT_PINNACLE_PCTV73E, 
-	4461, 15527, 15541, 0,
+	4461, 15537, 15551, 0,
 	USB_VENDOR_PLANEX, USB_PRODUCT_PLANEX_GW_US11H, 
-	15545, 5183, 0,
+	1, 5183, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_RTL8188CUS, 
 	7246, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GW_US11S, 
-	15554, 5183, 0,
+	15564, 5183, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_RTL8188CU_3, 
 	5110, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUSFANG300, 
-	15563, 0,
+	15573, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS54GXS, 
-	15576, 0,
+	15586, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GW_US300, 
-	15587, 0,
+	15597, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS54HP, 
-	15596, 0,
-	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS300MINIS, 
 	15606, 0,
+	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUS300MINIS, 
+	15616, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_RT3070, 
 	4976, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUSNANO, 
-	15620, 0,
-	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUSMICRO300, 
 	15630, 0,
+	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_GWUSMICRO300, 
+	15640, 0,
 	USB_VENDOR_PLANEX2, USB_PRODUCT_PLANEX2_RTL8188CU_1, 
-	15644, 0,
+	15654, 0,
 	USB_VENDOR_PLANEX2, 

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

2018-11-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 12 16:01:35 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: usb_quirks.c usb_quirks.h usbdevs
usbdi_util.c usbdi_util.h

Log Message:
Pull up following revision(s) (requested by manu in ticket #1091):

sys/dev/usb/usb_quirks.c: revision 1.88,1.89 (via patch)
sys/dev/usb/usbdi_util.c: revision 1.72 (via patch)
sys/dev/usb/usb_quirks.h: revision 1.28 (via patch)
sys/dev/usb/usbdi_util.h: revision 1.48
sys/dev/usb/usbdevs: revision 1.760,1.761 (via patch)

Add PN533 based NFC devices

 -

Workaround PN533 USB descriptor corruption

During normal operation, the PN533 chip may corrupt its USB configuration,
interface and endpoint descriptors. The device descriptor remains unaffected.

Since the descriptors are documented to be immutable, we can work around
the problem by providing hard-coded descriptors instead of pulling them
from the device.

Userland implementation such as NFC tools' libnfc use the same approach,
but this kernel quirk is still necessary so that the device can be
attached on reboot, after its USB descriptors got corrupted.

 -

Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.86.8.1 src/sys/dev/usb/usb_quirks.c
cvs rdiff -u -r1.27 -r1.27.10.1 src/sys/dev/usb/usb_quirks.h
cvs rdiff -u -r1.736.2.1 -r1.736.2.2 src/sys/dev/usb/usbdevs
cvs rdiff -u -r1.66.2.1 -r1.66.2.2 src/sys/dev/usb/usbdi_util.c
cvs rdiff -u -r1.47 -r1.47.10.1 src/sys/dev/usb/usbdi_util.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/usb_quirks.c
diff -u src/sys/dev/usb/usb_quirks.c:1.86 src/sys/dev/usb/usb_quirks.c:1.86.8.1
--- src/sys/dev/usb/usb_quirks.c:1.86	Sun Dec  4 10:12:35 2016
+++ src/sys/dev/usb/usb_quirks.c	Mon Nov 12 16:01:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_quirks.c,v 1.86 2016/12/04 10:12:35 skrll Exp $	*/
+/*	$NetBSD: usb_quirks.c,v 1.86.8.1 2018/11/12 16:01:35 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.86 2016/12/04 10:12:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_quirks.c,v 1.86.8.1 2018/11/12 16:01:35 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -43,13 +43,137 @@ __KERNEL_RCSID(0, "$NetBSD: usb_quirks.c
 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 
 #ifdef USB_DEBUG
 extern int usbdebug;
 #endif
 
+#define DPRINTF(FMT,A,B,C,D)USBHIST_LOG(usbdebug,FMT,A,B,C,D)
+
 #define ANY 0x
+#define _USETW(w) { (w) & 0x00ff, ((w) & 0xff00) >> 8 }
+
+/*
+ * NXP PN533 NFC chip descriptors
+ */
+static const usb_endpoint_descriptor_t desc_ep_pn533_in = {
+	/* bLength */		sizeof(desc_ep_pn533_in),
+	/* bDescriptorType */	UDESC_ENDPOINT,
+	/* bEndpointAddress */	UE_DIR_IN | 0x04,
+	/* bmAttributes */	UE_BULK,
+	/* wMaxPacketSize */	_USETW(0x0040),
+	/* bInterval */		0x04, /* 255ms */
+};
+
+static const usb_endpoint_descriptor_t desc_ep_pn533_out = {
+	/* bLength */		sizeof(desc_ep_pn533_in),
+	/* bDescriptorType */	UDESC_ENDPOINT,
+	/* bEndpointAddress */	UE_DIR_OUT | 0x04,
+	/* bmAttributes */	UE_BULK,
+	/* wMaxPacketSize */	_USETW(0x0040),
+	/* bInterval */		0x04, /* 255ms */
+};
+
+static const usb_interface_descriptor_t desc_iface_pn533 = {
+	/* bLength */		sizeof(desc_iface_pn533),
+	/* bDescriptorType */	 UDESC_INTERFACE,
+	/* bInterfaceNumber */	 0,
+	/* bAlternateSetting */	 0,
+	/* bNumEndpoints */	 2,
+	/* bInterfaceClass */	 0xff,
+	/* bInterfaceSubClass */ 0xff,
+	/* bInterfaceProtocol */ 0xff,
+	/* iInterface */	 0,
+};
+
+static const usb_config_descriptor_t desc_conf_pn533 = {
+	/* bLength */		 sizeof(desc_conf_pn533),
+	/* bDescriptorType */	 UDESC_CONFIG,
+	/* wTotalLength	 */	 _USETW(sizeof(desc_conf_pn533) +
+	sizeof(desc_iface_pn533) +
+	sizeof(desc_ep_pn533_in) +
+	sizeof(desc_ep_pn533_out)
+ ),
+	/* bNumInterfac	*/	 1,
+	/* bConfigurationValue */1,
+	/* iConfiguration */	 0,
+	/* bmAttributes	*/	 UC_ATTR_MBO,
+	/* bMaxPower */		 0x32, /* 100mA */
+};
+
+static const usb_descriptor_t *desc_pn533[] = {
+	(const usb_descriptor_t *)_conf_pn533,
+	(const usb_descriptor_t *)_iface_pn533,
+	(const usb_descriptor_t *)_ep_pn533_out,
+	(const usb_descriptor_t *)_ep_pn533_in,
+	NULL
+};
+
+
+usbd_status
+usbd_get_desc_fake(struct usbd_device *dev, int type, int index,
+		   int len, void *desc)
+{
+	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+#ifdef USB_DEBUG
+	const usb_device_descriptor_t *dd = usbd_get_device_descriptor(dev);
+#endif
+	const usb_descriptor_t *ub;
+	int i = 0;
+	int j = 0;
+	usbd_status err = USBD_INVAL;
+
+	if (dev->ud_quirks == NULL || dev->ud_quirks->desc == NULL) {
+		DPRINTF("%04x/%04x: no fake descriptors",
+		UGETW(dd->idVendor), UGETW(dd->idProduct), 0, 0);
+		goto out;
+	}
+
+	for (j = 0; 

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

2018-11-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 12 12:17:07 UTC 2018

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

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

sys/dev/usb/ugen.c: revision 1.141

Enfore USB timeout on ugen(4) write operations


To generate a diff of this commit:
cvs rdiff -u -r1.134.10.1 -r1.134.10.2 src/sys/dev/usb/ugen.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/ugen.c
diff -u src/sys/dev/usb/ugen.c:1.134.10.1 src/sys/dev/usb/ugen.c:1.134.10.2
--- src/sys/dev/usb/ugen.c:1.134.10.1	Wed Jan 31 18:01:55 2018
+++ src/sys/dev/usb/ugen.c	Mon Nov 12 12:17:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugen.c,v 1.134.10.1 2018/01/31 18:01:55 martin Exp $	*/
+/*	$NetBSD: ugen.c,v 1.134.10.2 2018/11/12 12:17:06 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.134.10.1 2018/01/31 18:01:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.134.10.2 2018/11/12 12:17:06 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1428,6 +1428,7 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 	uint8_t conf, alt;
 	int cdesclen;
 	int error;
+	int dir;
 
 	DPRINTFN(5, ("ugenioctl: cmd=%08lx\n", cmd));
 	if (sc->sc_dying)
@@ -1450,14 +1451,13 @@ ugen_do_ioctl(struct ugen_softc *sc, int
 			sce->state &= ~UGEN_SHORT_OK;
 		return 0;
 	case USB_SET_TIMEOUT:
-		sce = >sc_endpoints[endpt][IN];
-		if (sce == NULL
-		/* XXX this shouldn't happen, but the distinction between
-		   input and output pipes isn't clear enough.
-		   || sce->pipeh == NULL */
-			)
-			return EINVAL;
-		sce->timeout = *(int *)addr;
+		for (dir = OUT; dir <= IN; dir++) {
+			sce = >sc_endpoints[endpt][dir];
+			if (sce == NULL)
+return EINVAL;
+
+			sce->timeout = *(int *)addr;
+		}
 		return 0;
 	case USB_SET_BULK_RA:
 		if (endpt == USB_CONTROL_ENDPOINT)



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

2018-11-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Nov  4 11:08:10 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: uhub.c usb_subr.c

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

sys/dev/usb/uhub.c: revision 1.140
sys/dev/usb/uhub.c: revision 1.141
sys/dev/usb/usb_subr.c: revision 1.228

Make USB port numbers display consistent

Make sure USB ports numbers are displayed with the first one as number one
and not number zero when rescanning bus. The change makes the display
consistent with the display at boot time USB discovery.

While we are there, make port iteration consistent everywhere in the code,
always starting at one instead of zero.

 -

Make USB port iteration code consistent, always startint at port #1
This complements change in revision 1.140


To generate a diff of this commit:
cvs rdiff -u -r1.136.2.2 -r1.136.2.3 src/sys/dev/usb/uhub.c
cvs rdiff -u -r1.220.2.5 -r1.220.2.6 src/sys/dev/usb/usb_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/usb/uhub.c
diff -u src/sys/dev/usb/uhub.c:1.136.2.2 src/sys/dev/usb/uhub.c:1.136.2.3
--- src/sys/dev/usb/uhub.c:1.136.2.2	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/uhub.c	Sun Nov  4 11:08:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhub.c,v 1.136.2.2 2018/09/27 14:52:26 martin Exp $	*/
+/*	$NetBSD: uhub.c,v 1.136.2.3 2018/11/04 11:08:10 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $	*/
 /*	$OpenBSD: uhub.c,v 1.86 2015/06/29 18:27:40 mpi Exp $ */
 
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.136.2.2 2018/09/27 14:52:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.136.2.3 2018/11/04 11:08:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -412,11 +412,11 @@ uhub_attach(device_t parent, device_t se
 			 sizeof(struct usbd_tt), KM_SLEEP);
 	}
 	/* Set up data structures */
-	for (p = 0; p < nports; p++) {
-		struct usbd_port *up = >uh_ports[p];
+	for (p = 1; p <= nports; p++) {
+		struct usbd_port *up = >uh_ports[p - 1];
 		up->up_dev = NULL;
 		up->up_parent = dev;
-		up->up_portno = p + 1;
+		up->up_portno = p;
 		if (dev->ud_selfpowered)
 			/* Self powered hub, give ports maximum current. */
 			up->up_power = USB_MAX_POWER;
@@ -425,7 +425,7 @@ uhub_attach(device_t parent, device_t se
 		up->up_restartcnt = 0;
 		up->up_reattach = 0;
 		if (UHUB_IS_HIGH_SPEED(sc)) {
-			up->up_tt = [UHUB_IS_SINGLE_TT(sc) ? 0 : p];
+			up->up_tt = [UHUB_IS_SINGLE_TT(sc) ? 0 : p - 1];
 			up->up_tt->utt_hub = hub;
 		} else {
 			up->up_tt = NULL;
@@ -822,8 +822,8 @@ uhub_detach(device_t self, int flags)
 	KERNEL_LOCK(1, curlwp);
 
 	nports = hub->uh_hubdesc.bNbrPorts;
-	for (port = 0; port < nports; port++) {
-		rup = >uh_ports[port];
+	for (port = 1; port <= nports; port++) {
+		rup = >uh_ports[port - 1];
 		if (rup->up_dev == NULL)
 			continue;
 		if ((rc = usb_disconnect_port(rup, self, flags)) != 0) {
@@ -870,8 +870,8 @@ uhub_rescan(device_t self, const char *i
 	struct usbd_device *dev;
 	int port;
 
-	for (port = 0; port < hub->uh_hubdesc.bNbrPorts; port++) {
-		dev = hub->uh_ports[port].up_dev;
+	for (port = 1; port <= hub->uh_hubdesc.bNbrPorts; port++) {
+		dev = hub->uh_ports[port - 1].up_dev;
 		if (dev == NULL)
 			continue;
 		usbd_reattach_device(sc->sc_dev, dev, port, locators);
@@ -895,8 +895,8 @@ uhub_childdet(device_t self, device_t ch
 		panic("hub not fully initialised, but child deleted?");
 
 	nports = devhub->ud_hub->uh_hubdesc.bNbrPorts;
-	for (port = 0; port < nports; port++) {
-		dev = devhub->ud_hub->uh_ports[port].up_dev;
+	for (port = 1; port <= nports; port++) {
+		dev = devhub->ud_hub->uh_ports[port - 1].up_dev;
 		if (!dev || dev->ud_subdevlen == 0)
 			continue;
 		for (i = 0; i < dev->ud_subdevlen; i++) {

Index: src/sys/dev/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.220.2.5 src/sys/dev/usb/usb_subr.c:1.220.2.6
--- src/sys/dev/usb/usb_subr.c:1.220.2.5	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/usb_subr.c	Sun Nov  4 11:08:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.220.2.5 2018/09/27 14:52:26 martin Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.220.2.6 2018/11/04 11:08:10 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.5 2018/09/27 14:52:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.6 2018/11/04 11:08:10 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1230,9 +1230,10 @@ usbd_new_device(device_t parent, struct 
 	 adev = hub, hub = hub->ud_myhub)
 		;
 	if (hub) {
-		for (p = 0; p < hub->ud_hub->uh_hubdesc.bNbrPorts; p++) {
-			if (hub->ud_hub->uh_ports[p].up_dev == adev) {
-dev->ud_myhsport = >ud_hub->uh_ports[p];
+		for (p = 1; p <= 

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

2018-09-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep 28 08:33:43 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: ehci.c ehcivar.h xhci.c

Log Message:
Fixup for ticket #1037 - parts of the patch were accidently missing.


To generate a diff of this commit:
cvs rdiff -u -r1.254.8.5 -r1.254.8.6 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.43.10.1 -r1.43.10.2 src/sys/dev/usb/ehcivar.h
cvs rdiff -u -r1.72.2.8 -r1.72.2.9 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/ehci.c
diff -u src/sys/dev/usb/ehci.c:1.254.8.5 src/sys/dev/usb/ehci.c:1.254.8.6
--- src/sys/dev/usb/ehci.c:1.254.8.5	Thu Sep 27 14:52:26 2018
+++ src/sys/dev/usb/ehci.c	Fri Sep 28 08:33:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ehci.c,v 1.254.8.5 2018/09/27 14:52:26 martin Exp $ */
+/*	$NetBSD: ehci.c,v 1.254.8.6 2018/09/28 08:33:43 martin Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.254.8.5 2018/09/27 14:52:26 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.254.8.6 2018/09/28 08:33:43 martin Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.2
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -446,8 +447,9 @@ ehci_init(ehci_softc_t *sc)
 	}
 	if (sc->sc_ncomp > 0) {
 		KASSERT(!(sc->sc_flags & EHCIF_ETTF));
-		aprint_normal("%s: %d companion controller%s, %d port%s%s",
-		device_xname(sc->sc_dev), sc->sc_ncomp,
+		aprint_normal_dev(sc->sc_dev,
+		"%d companion controller%s, %d port%s%s",
+		sc->sc_ncomp,
 		sc->sc_ncomp!=1 ? "s" : "",
 		EHCI_HCS_N_PCC(sparams),
 		EHCI_HCS_N_PCC(sparams)!=1 ? "s" : "",
@@ -459,6 +461,11 @@ ehci_init(ehci_softc_t *sc)
 device_xname(sc->sc_comps[i]));
 		}
 		aprint_normal("\n");
+
+		mutex_init(>sc_complock, MUTEX_DEFAULT, IPL_USB);
+		callout_init(>sc_compcallout, CALLOUT_MPSAFE);
+		cv_init(>sc_compcv, "ehciccv");
+		sc->sc_comp_state = CO_EARLY;
 	}
 	sc->sc_noport = EHCI_HCS_N_PORTS(sparams);
 	sc->sc_hasppc = EHCI_HCS_PPC(sparams);
@@ -1337,6 +1344,19 @@ ehci_detach(struct ehci_softc *sc, int f
 	if (rv != 0)
 		return rv;
 
+	if (sc->sc_ncomp > 0) {
+		mutex_enter(>sc_complock);
+		/* XXX try to halt callout instead of waiting */
+		while (sc->sc_comp_state == CO_SCHED)
+			cv_wait(>sc_compcv, >sc_complock);
+		mutex_exit(>sc_complock);
+
+		callout_halt(>sc_compcallout, NULL);
+		callout_destroy(>sc_compcallout);
+		cv_destroy(>sc_compcv);
+		mutex_destroy(>sc_complock);
+	}
+
 	callout_halt(>sc_tmo_intrlist, NULL);
 	callout_destroy(>sc_tmo_intrlist);
 
@@ -2597,6 +2617,72 @@ ehci_roothub_ctrl(struct usbd_bus *bus, 
 	return totlen;
 }
 
+/*
+ * Handle ehci hand-off in early boot vs RB_ASKNAME/RB_SINGLE.
+ *
+ * This pile of garbage below works around the following problem without
+ * holding boots with no hand-over devices present, while penalising
+ * boots where the first ehci probe hands off devices with a 5 second
+ * delay, if RB_ASKNAME/RB_SINGLE is set.  This is typically not a problem
+ * for RB_SINGLE, but the same basic issue exists.
+ *
+ * The way ehci hand-off works, the companion controller does not get the
+ * device until after its' initial bus explore, so the reference dropped
+ * after the first explore is not enough.  5 seconds should be enough,
+ * and EHCI_DISOWN_DELAY_SECONDS can be set to another value.
+ *
+ * There are 3 states.  CO_EARLY is set during attach.  CO_SCHED is set
+ * if the callback is scheduled.  CO_DONE is set when the callout has
+ * called config_pending_decr().
+ *
+ * There's a mutex, a cv and a callout here, and we delay detach if the
+ * callout has been set.
+ */
+#ifndef EHCI_DISOWN_DELAY_SECONDS
+#define EHCI_DISOWN_DELAY_SECONDS 5
+#endif
+static int ehci_disown_delay_seconds = EHCI_DISOWN_DELAY_SECONDS;
+
+static void
+ehci_disown_callback(void *arg)
+{
+	ehci_softc_t *sc = arg;
+
+	config_pending_decr(sc->sc_dev);
+
+	mutex_enter(>sc_complock);
+	KASSERT(sc->sc_comp_state == CO_SCHED);
+	sc->sc_comp_state = CO_DONE;
+	cv_signal(>sc_compcv);
+	mutex_exit(>sc_complock);
+}
+
+static void
+ehci_disown_sched_callback(ehci_softc_t *sc)
+{
+	extern bool root_is_mounted;
+
+	mutex_enter(>sc_complock);
+
+	if (root_is_mounted ||
+	(boothowto & (RB_ASKNAME|RB_SINGLE)) == 0 ||
+	sc->sc_comp_state != CO_EARLY) {
+		mutex_exit(>sc_complock);
+		return;
+	}
+
+	callout_reset(>sc_compcallout, ehci_disown_delay_seconds * hz,
+	ehci_disown_callback, >sc_dev);
+	sc->sc_comp_state = CO_SCHED;
+
+	mutex_exit(>sc_complock);
+
+	config_pending_incr(sc->sc_dev);
+	aprint_normal("delaying %s by %u seconds due to USB owner change.",
+	(boothowto & RB_ASKNAME) == 0 ? "ask root" : "single user",
+	ehci_disown_delay_seconds);
+}
+
 Static void
 ehci_disown(ehci_softc_t *sc, int index, int lowspeed)
 {
@@ 

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

2018-08-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 26 08:05:16 UTC 2018

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

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

sys/dev/usb/usb_subr.c: revision 1.224

add missing KERNEL_LOCK protection around autoconf calls.

Also replace NULL argument with curlwp for style.


To generate a diff of this commit:
cvs rdiff -u -r1.220.2.3 -r1.220.2.4 src/sys/dev/usb/usb_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/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.220.2.3 src/sys/dev/usb/usb_subr.c:1.220.2.4
--- src/sys/dev/usb/usb_subr.c:1.220.2.3	Wed Aug  8 10:28:35 2018
+++ src/sys/dev/usb/usb_subr.c	Sun Aug 26 08:05:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.220.2.3 2018/08/08 10:28:35 martin Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.220.2.4 2018/08/26 08:05:16 martin Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.3 2018/08/08 10:28:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.4 2018/08/26 08:05:16 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -859,7 +859,9 @@ usbd_attach_roothub(device_t parent, str
 	uaa.uaa_subclass = dd->bDeviceSubClass;
 	uaa.uaa_proto = dd->bDeviceProtocol;
 
+	KERNEL_LOCK(1, curlwp);
 	dv = config_found_ia(parent, "usbroothubif", , 0);
+	KERNEL_UNLOCK_ONE(curlwp);
 	if (dv) {
 		dev->ud_subdevs = kmem_alloc(sizeof(dv), KM_SLEEP);
 		dev->ud_subdevs[0] = dv;
@@ -904,10 +906,10 @@ usbd_attachwholedevice(device_t parent, 
 	dlocs[USBDEVIFCF_CONFIGURATION] = -1;
 	dlocs[USBDEVIFCF_INTERFACE] = -1;
 
-	KERNEL_LOCK(1, NULL);
+	KERNEL_LOCK(1, curlwp);
 	dv = config_found_sm_loc(parent, "usbdevif", dlocs, , usbd_print,
  config_stdsubmatch);
-	KERNEL_UNLOCK_ONE(NULL);
+	KERNEL_UNLOCK_ONE(curlwp);
 	if (dv) {
 		dev->ud_subdevs = kmem_alloc(sizeof(dv), KM_SLEEP);
 		dev->ud_subdevs[0] = dv;
@@ -981,10 +983,10 @@ usbd_attachinterfaces(device_t parent, s
 			loc != uiaa.uiaa_ifaceno)
 continue;
 		}
-		KERNEL_LOCK(1, NULL);
+		KERNEL_LOCK(1, curlwp);
 		dv = config_found_sm_loc(parent, "usbifif", ilocs, ,
 	 usbd_ifprint, config_stdsubmatch);
-		KERNEL_UNLOCK_ONE(NULL);
+		KERNEL_UNLOCK_ONE(curlwp);
 		if (!dv)
 			continue;
 
@@ -1728,7 +1730,10 @@ usb_disconnect_port(struct usbd_port *up
 continue;
 			strlcpy(subdevname, device_xname(subdev),
 			sizeof(subdevname));
-			if ((rc = config_detach(subdev, flags)) != 0)
+			KERNEL_LOCK(1, curlwp);
+			rc = config_detach(subdev, flags);
+			KERNEL_UNLOCK_ONE(curlwp);
+			if (rc != 0)
 return rc;
 			printf("%s: at %s", subdevname, hubname);
 			if (up->up_portno != 0)



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

2018-08-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  8 10:28:35 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: if_athn_usb.c if_atu.c if_aue.c if_axe.c
if_axen.c if_cue.c if_otus.c if_rum.c if_run.c if_smsc.c if_udav.c
if_upgt.c if_ural.c if_url.c if_urtw.c if_urtwn.c if_zyd.c uatp.c
umcs.c usb.c usb_subr.c usbdi.h

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

sys/dev/usb/if_cue.c: revision 1.80
sys/dev/usb/umcs.c: revision 1.11
sys/dev/usb/umcs.c: revision 1.12
sys/dev/usb/if_ural.c: revision 1.56
sys/dev/usb/if_run.c: revision 1.28
sys/dev/usb/if_ural.c: revision 1.57
sys/dev/usb/if_run.c: revision 1.29
sys/dev/usb/uatp.c: revision 1.16
sys/dev/usb/uatp.c: revision 1.17
sys/dev/usb/if_axe.c: revision 1.91
sys/dev/usb/if_axe.c: revision 1.92
sys/dev/usb/if_zyd.c: revision 1.49
sys/dev/usb/if_axen.c: revision 1.15
sys/dev/usb/if_url.c: revision 1.60
sys/dev/usb/if_udav.c: revision 1.54
sys/dev/usb/if_axen.c: revision 1.16
sys/dev/usb/if_udav.c: revision 1.55
sys/dev/usb/if_athn_usb.c: revision 1.28
sys/dev/usb/if_athn_usb.c: revision 1.29
sys/dev/usb/if_urtw.c: revision 1.16
sys/dev/usb/if_urtw.c: revision 1.17
sys/dev/usb/if_cue.c: revision 1.79
sys/dev/usb/if_rum.c: revision 1.62
sys/dev/usb/if_urtwn.c: revision 1.61
sys/dev/usb/if_rum.c: revision 1.63
sys/dev/usb/if_urtwn.c: revision 1.63
sys/dev/usb/usb.c: revision 1.170
sys/dev/usb/usb.c: revision 1.171
sys/dev/usb/if_smsc.c: revision 1.35
sys/dev/usb/if_smsc.c: revision 1.36
sys/dev/usb/if_zyd.c: revision 1.50
sys/dev/usb/if_aue.c: revision 1.144
sys/dev/usb/if_aue.c: revision 1.145
sys/dev/usb/usb_subr.c: revision 1.225
sys/dev/usb/usb_subr.c: revision 1.226
sys/dev/usb/if_upgt.c: revision 1.21
sys/dev/usb/usbdi.h: revision 1.93
sys/dev/usb/if_upgt.c: revision 1.22
sys/dev/usb/if_url.c: revision 1.59
sys/dev/usb/usbdi.h: revision 1.95
sys/dev/usb/if_otus.c: revision 1.34
sys/dev/usb/if_atu.c: revision 1.62
sys/dev/usb/if_otus.c: revision 1.35
sys/dev/usb/if_atu.c: revision 1.63

New function usb_rem_task_wait(dev, task, queue).

If task is scheduled to run, removes it from the queue.  If it may
have already begun to run, waits for it to complete.  Caller must
guarantee it will not switch to another queue.  If caller guarantees
it will not be scheduled again, then usb_rem_task_wait guarantees it
is not running on return.

This will enable us to fix a litany of bugs in detach where we
currently fail to wait for a pending task.

Use usb_rem_task_wait in various drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.2 -r1.22.2.3 src/sys/dev/usb/if_athn_usb.c
cvs rdiff -u -r1.55.8.2 -r1.55.8.3 src/sys/dev/usb/if_atu.c
cvs rdiff -u -r1.141.8.1 -r1.141.8.2 src/sys/dev/usb/if_aue.c
cvs rdiff -u -r1.82.6.3 -r1.82.6.4 src/sys/dev/usb/if_axe.c
cvs rdiff -u -r1.11.8.1 -r1.11.8.2 src/sys/dev/usb/if_axen.c
cvs rdiff -u -r1.76.8.1 -r1.76.8.2 src/sys/dev/usb/if_cue.c
cvs rdiff -u -r1.31.2.1 -r1.31.2.2 src/sys/dev/usb/if_otus.c
cvs rdiff -u -r1.58.2.1 -r1.58.2.2 src/sys/dev/usb/if_rum.c
cvs rdiff -u -r1.22.2.1 -r1.22.2.2 src/sys/dev/usb/if_run.c
cvs rdiff -u -r1.30.8.1 -r1.30.8.2 src/sys/dev/usb/if_smsc.c
cvs rdiff -u -r1.51.8.1 -r1.51.8.2 src/sys/dev/usb/if_udav.c
cvs rdiff -u -r1.17.8.1 -r1.17.8.2 src/sys/dev/usb/if_upgt.c
cvs rdiff -u -r1.51.8.2 -r1.51.8.3 src/sys/dev/usb/if_ural.c
cvs rdiff -u -r1.56.8.1 -r1.56.8.2 src/sys/dev/usb/if_url.c
cvs rdiff -u -r1.13.8.1 -r1.13.8.2 src/sys/dev/usb/if_urtw.c
cvs rdiff -u -r1.53.2.3 -r1.53.2.4 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.44.2.1 -r1.44.2.2 src/sys/dev/usb/if_zyd.c
cvs rdiff -u -r1.14 -r1.14.6.1 src/sys/dev/usb/uatp.c
cvs rdiff -u -r1.10 -r1.10.10.1 src/sys/dev/usb/umcs.c
cvs rdiff -u -r1.165.6.2 -r1.165.6.3 src/sys/dev/usb/usb.c
cvs rdiff -u -r1.220.2.2 -r1.220.2.3 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.92 -r1.92.8.1 src/sys/dev/usb/usbdi.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/if_athn_usb.c
diff -u src/sys/dev/usb/if_athn_usb.c:1.22.2.2 src/sys/dev/usb/if_athn_usb.c:1.22.2.3
--- src/sys/dev/usb/if_athn_usb.c:1.22.2.2	Wed Jan 31 18:01:54 2018
+++ src/sys/dev/usb/if_athn_usb.c	Wed Aug  8 10:28:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_athn_usb.c,v 1.22.2.2 2018/01/31 18:01:54 martin Exp $	*/
+/*	$NetBSD: if_athn_usb.c,v 1.22.2.3 2018/08/08 10:28:35 martin Exp $	*/
 /*	$OpenBSD: if_athn_usb.c,v 1.12 2013/01/14 09:50:31 jsing Exp $	*/
 
 /*-
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.22.2.2 

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

2018-06-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun  7 18:16:43 UTC 2018

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

Log Message:
Pull up following revision(s) (requested by nat in ticket #847):

sys/dev/usb/if_urtwn.c: revision 1.58

Fix support for 8192eu, notably TPLINK TL-WN823NV2, by using the right
registers when setting receiver gain.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.53.2.2 -r1.53.2.3 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.53.2.2 src/sys/dev/usb/if_urtwn.c:1.53.2.3
--- src/sys/dev/usb/if_urtwn.c:1.53.2.2	Wed Jan 31 18:01:54 2018
+++ src/sys/dev/usb/if_urtwn.c	Thu Jun  7 18:16:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.53.2.2 2018/01/31 18:01:54 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.53.2.3 2018/06/07 18:16:43 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.53.2.2 2018/01/31 18:01:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.53.2.3 2018/06/07 18:16:43 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3799,12 +3799,19 @@ urtwn_bb_init(struct urtwn_softc *sc)
 		DELAY(1);
 		urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), 0x69553420);
 		DELAY(1);
+	}
 
-		if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
-			urtwn_write_2(sc, R92C_AFE_CTRL3, urtwn_read_2(sc,
-			R92C_AFE_CTRL3));
-		}
-
+	if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
+		crystalcap = sc->r88e_rom[0xb9];
+		if (crystalcap == 0x00)
+			crystalcap = 0x20;
+		crystalcap &= 0x3f;
+		reg = urtwn_bb_read(sc, R92C_AFE_CTRL3);
+		urtwn_bb_write(sc, R92C_AFE_CTRL3,
+		RW(reg, R92C_AFE_XTAL_CTRL_ADDR,
+		crystalcap | crystalcap << 6));
+		urtwn_write_4(sc, R92C_AFE_XTAL_CTRL, 0xf81fb);
+	} else if (ISSET(sc->chip, URTWN_CHIP_88E)) {
 		crystalcap = sc->r88e_rom[0xb9];
 		if (crystalcap == 0xff)
 			crystalcap = 0x20;



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

2018-05-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon May  7 13:26:03 UTC 2018

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

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

sys/dev/usb/if_axe.c: revision 1.85-1.89

propagate pullup-782 for NetBSD-8 to HEAD (gcc uninitialized)

It was not gcc's fault for correctly detecting an uninitialized variable.

Fix the uninitialized variable issues by error checking things.
downgrade error to debug.

merge duplicated code, back to logging error.

use the proper station nodeid read command.


To generate a diff of this commit:
cvs rdiff -u -r1.82.6.2 -r1.82.6.3 src/sys/dev/usb/if_axe.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_axe.c
diff -u src/sys/dev/usb/if_axe.c:1.82.6.2 src/sys/dev/usb/if_axe.c:1.82.6.3
--- src/sys/dev/usb/if_axe.c:1.82.6.2	Wed Jan 31 18:01:55 2018
+++ src/sys/dev/usb/if_axe.c	Mon May  7 13:26:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_axe.c,v 1.82.6.2 2018/01/31 18:01:55 martin Exp $	*/
+/*	$NetBSD: if_axe.c,v 1.82.6.3 2018/05/07 13:26:03 martin Exp $	*/
 /*	$OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.82.6.2 2018/01/31 18:01:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.82.6.3 2018/05/07 13:26:03 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -303,7 +303,7 @@ axe_cmd(struct axe_softc *sc, int cmd, i
 	KASSERT(mutex_owned(>axe_mii_lock));
 
 	if (sc->axe_dying)
-		return 0;
+		return -1;
 
 	DPRINTFN(20, "cmd %#jx index %#jx val %#jx", cmd, index, val, 0);
 
@@ -337,7 +337,7 @@ axe_miibus_readreg_locked(device_t dev, 
 
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
 
-	err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, (void *));
+	err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, );
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
 	if (err) {
 		aprint_error_dev(sc->axe_dev, "read PHY failed\n");
@@ -389,7 +389,7 @@ axe_miibus_writereg_locked(device_t dev,
 	val = htole16(aval);
 
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
-	err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *));
+	err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, );
 	axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
 
 	if (err) {
@@ -477,7 +477,11 @@ axe_setmulti(struct axe_softc *sc)
 		return;
 
 	axe_lock_mii(sc);
-	axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *));
+	if (axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, )) {
+		axe_unlock_mii(sc);
+		aprint_error_dev(sc->axe_dev, "can't read rxmode");
+		return;
+	}
 	rxmode = le16toh(rxmode);
 
 	rxmode &=
@@ -507,7 +511,7 @@ axe_setmulti(struct axe_softc *sc)
 	ifp->if_flags &= ~IFF_ALLMULTI;
 	rxmode |= AXE_RXCMD_MULTICAST;
 
-	axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *));
+	axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, hashtbl);
 	axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
 	axe_unlock_mii(sc);
 	return;
@@ -519,6 +523,30 @@ axe_setmulti(struct axe_softc *sc)
 	axe_unlock_mii(sc);
 }
 
+static void
+axe_ax_init(struct axe_softc *sc)
+{
+	int cmd = AXE_178_CMD_READ_NODEID;
+
+	if (sc->axe_flags & AX178) {
+		axe_ax88178_init(sc);
+	} else if (sc->axe_flags & AX772) {
+		axe_ax88772_init(sc);
+	} else if (sc->axe_flags & AX772A) {
+		axe_ax88772a_init(sc);
+	} else if (sc->axe_flags & AX772B) {
+		axe_ax88772b_init(sc);
+		return;
+	} else {
+		cmd = AXE_172_CMD_READ_NODEID;
+	}
+
+	if (axe_cmd(sc, cmd, 0, 0, sc->axe_enaddr)) {
+		aprint_error_dev(sc->axe_dev,
+		"failed to read ethernet address\n");
+	}
+}
+
 
 static void
 axe_reset(struct axe_softc *sc)
@@ -542,15 +570,8 @@ axe_reset(struct axe_softc *sc)
 #else
 	axe_lock_mii(sc);
 
-	if (sc->axe_flags & AX178) {
-		axe_ax88178_init(sc);
-	} else if (sc->axe_flags & AX772) {
-		axe_ax88772_init(sc);
-	} else if (sc->axe_flags & AX772A) {
-		axe_ax88772a_init(sc);
-	} else if (sc->axe_flags & AX772B) {
-		axe_ax88772b_init(sc);
-	}
+	axe_ax_init(sc);
+
 	axe_unlock_mii(sc);
 #endif
 }
@@ -594,7 +615,8 @@ axe_ax88178_init(struct axe_softc *sc)
 
 	axe_cmd(sc, AXE_CMD_SROM_WR_ENABLE, 0, 0, NULL);
 	/* XXX magic */
-	axe_cmd(sc, AXE_CMD_SROM_READ, 0, 0x0017, );
+	if (axe_cmd(sc, AXE_CMD_SROM_READ, 0, 0x0017, ) != 0)
+		eeprom = 0x;
 	axe_cmd(sc, AXE_CMD_SROM_WR_DISABLE, 0, 0, NULL);
 
 	eeprom = le16toh(eeprom);
@@ -752,8 +774,7 @@ axe_ax88772_phywake(struct axe_softc *sc
 	if (sc->axe_phyno == AXE_772_PHY_NO_EPHY) {
 		/* Manually select internal(embedded) PHY - MAC mode. */
 		axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0,
-		AXE_SW_PHY_SELECT_EMBEDDED,
-		NULL);
+		AXE_SW_PHY_SELECT_EMBEDDED, NULL);
 		usbd_delay_ms(sc->axe_udev, hztoms(hz / 32));
 	} else {
 		/*
@@ -815,7 +836,12 @@ axe_ax88772b_init(struct axe_softc *sc)
 	 * Save PHY power saving configuration(high byte) and
 	 * clear EEPROM checksum value(low byte).
 	 */
-	axe_cmd(sc, 

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

2018-05-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat May  5 15:05:39 UTC 2018

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

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

sys/dev/usb/xhci.c: revision 1.88-1.90
sys/dev/usb/xhcireg.h: revision 1.10

add KASSERT() that sc_child* is set to NULL after child detach; just for
readability, it's not immediatelly obvious this is done in xhci_childdet()
no functional changes

trigger the softint processing on that child bus which is not detached yet
fixes PR kern/53066 by Martin Husemann

enable code to only trigger usb processing when EINT is set, to
avoid misinterpreting shared interrupt for another device

when clearing USBSTS, actually preserve the bits which spec requires to
preserve, and actually clear bit 1, which should be actually always
cleared to zero by spec

also #ifdef XHCI_DEBUG some unnecessary register reads
this should finally resolve PR kern/53066 also for Martin


To generate a diff of this commit:
cvs rdiff -u -r1.72.2.5 -r1.72.2.6 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.9 -r1.9.6.1 src/sys/dev/usb/xhcireg.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.72.2.5 src/sys/dev/usb/xhci.c:1.72.2.6
--- src/sys/dev/usb/xhci.c:1.72.2.5	Thu Dec 21 21:53:31 2017
+++ src/sys/dev/usb/xhci.c	Sat May  5 15:05:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.72.2.5 2017/12/21 21:53:31 snj Exp $	*/
+/*	$NetBSD: xhci.c,v 1.72.2.6 2018/05/05 15:05:39 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.5 2017/12/21 21:53:31 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.6 2018/05/05 15:05:39 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -582,12 +582,14 @@ xhci_detach(struct xhci_softc *sc, int f
 		rv = config_detach(sc->sc_child2, flags);
 		if (rv != 0)
 			return rv;
+		KASSERT(sc->sc_child2 == NULL);
 	}
 
 	if (sc->sc_child != NULL) {
 		rv = config_detach(sc->sc_child, flags);
 		if (rv != 0)
 			return rv;
+		KASSERT(sc->sc_child == NULL);
 	}
 
 	/* XXX unconfigure/free slots */
@@ -1247,7 +1249,16 @@ xhci_intr(void *v)
 
 	ret = xhci_intr1(sc);
 	if (ret) {
-		usb_schedsoftintr(>sc_bus);
+		KASSERT(sc->sc_child || sc->sc_child2);
+
+		/*
+		 * One of child busses could be already detached. It doesn't
+		 * matter on which of the two the softintr is scheduled.
+		 */
+		if (sc->sc_child)
+			usb_schedsoftintr(>sc_bus);
+		else
+			usb_schedsoftintr(>sc_bus2);
 	}
 done:
 	mutex_spin_exit(>sc_intr_lock);
@@ -1264,24 +1275,36 @@ xhci_intr1(struct xhci_softc * const sc)
 
 	usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
 	DPRINTFN(16, "USBSTS %08jx", usbsts, 0, 0, 0);
-#if 0
-	if ((usbsts & (XHCI_STS_EINT|XHCI_STS_PCD)) == 0) {
+	if ((usbsts & (XHCI_STS_HSE | XHCI_STS_EINT | XHCI_STS_PCD |
+	XHCI_STS_HCE)) == 0) {
+		DPRINTFN(16, "ignored intr not for %s",
+		device_xname(sc->sc_dev), 0, 0, 0);
 		return 0;
 	}
-#endif
-	xhci_op_write_4(sc, XHCI_USBSTS,
-	usbsts & (2|XHCI_STS_EINT|XHCI_STS_PCD)); /* XXX */
+
+	/*
+	 * Clear EINT and other transient flags, to not misenterpret
+	 * next shared interrupt. Also, to avoid race, EINT must be cleared
+	 * before XHCI_IMAN_INTR_PEND is cleared.
+	 */
+	xhci_op_write_4(sc, XHCI_USBSTS, usbsts & XHCI_STS_RSVDP0);
+
+#ifdef XHCI_DEBUG
 	usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
 	DPRINTFN(16, "USBSTS %08jx", usbsts, 0, 0, 0);
+#endif
 
 	iman = xhci_rt_read_4(sc, XHCI_IMAN(0));
 	DPRINTFN(16, "IMAN0 %08jx", iman, 0, 0, 0);
 	iman |= XHCI_IMAN_INTR_PEND;
 	xhci_rt_write_4(sc, XHCI_IMAN(0), iman);
+
+#ifdef XHCI_DEBUG
 	iman = xhci_rt_read_4(sc, XHCI_IMAN(0));
 	DPRINTFN(16, "IMAN0 %08jx", iman, 0, 0, 0);
 	usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
 	DPRINTFN(16, "USBSTS %08jx", usbsts, 0, 0, 0);
+#endif
 
 	return 1;
 }

Index: src/sys/dev/usb/xhcireg.h
diff -u src/sys/dev/usb/xhcireg.h:1.9 src/sys/dev/usb/xhcireg.h:1.9.6.1
--- src/sys/dev/usb/xhcireg.h:1.9	Thu Jan 19 16:05:00 2017
+++ src/sys/dev/usb/xhcireg.h	Sat May  5 15:05:39 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: xhcireg.h,v 1.9 2017/01/19 16:05:00 skrll Exp $ */
+/* $NetBSD: xhcireg.h,v 1.9.6.1 2018/05/05 15:05:39 martin Exp $ */
 
 /*-
  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
@@ -106,14 +106,17 @@
 
 #define	XHCI_USBSTS		0x04	/* XHCI status */
 #define	 XHCI_STS_HCH		0x0001	/* RO - Host Controller Halted */
+#define	 XHCI_STS_RSVDZ0	0x0002	/* RsvdZ - 2:2 */
 #define	 XHCI_STS_HSE		0x0004	/* RW - Host System Error */
 #define	 XHCI_STS_EINT		0x0008	/* RW - Event Interrupt */
 #define	 XHCI_STS_PCD		0x0010	/* RW - Port Change Detect */
+#define	 XHCI_STS_RSVDZ1	__BITS(5, 7)	/* RsvdZ - 5:7 */
 #define	 XHCI_STS_SSS		0x0100	/* RO - Save State Status */
 #define	 

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

2018-01-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jan 31 18:01:55 UTC 2018

Modified Files:
src/sys/dev/usb [netbsd-8]: if_athn_usb.c if_atu.c if_aue.c if_axe.c
if_axen.c if_cdce.c if_cue.c if_kue.c if_otus.c if_rum.c if_run.c
if_smsc.c if_udav.c if_upgt.c if_upl.c if_ural.c if_url.c
if_urndis.c if_urtw.c if_urtwn.c if_zyd.c irmce.c pseye.c ualea.c
ubt.c ucom.c udsir.c ugen.c uhso.c uirda.c ulpt.c umass.c umidi.c
uscanner.c usscanner.c ustir.c utoppy.c uvideo.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #509):
sys/dev/usb/if_ural.c: revision 1.53
sys/dev/usb/if_run.c: revision 1.25
sys/dev/usb/ustir.c: revision 1.39
sys/dev/usb/irmce.c: revision 1.4
sys/dev/usb/if_urtwn.c: revision 1.56
sys/dev/usb/pseye.c: revision 1.24
sys/dev/usb/if_rum.c: revision 1.59
sys/dev/usb/if_upl.c: revision 1.61
sys/dev/usb/ucom.c: revision 1.120
sys/dev/usb/if_zyd.c: revision 1.45
sys/dev/usb/if_axen.c: revision 1.12
sys/dev/usb/umidi.c: revision 1.74
sys/dev/usb/if_udav.c: revision 1.52
sys/dev/usb/if_athn_usb.c: revision 1.25
sys/dev/usb/usscanner.c: revision 1.43
sys/dev/usb/ualea.c: revision 1.6 - 1.9
sys/dev/usb/if_upgt.c: revision 1.18
sys/dev/usb/if_atu.c: revision 1.56
sys/dev/usb/utoppy.c: revision 1.30
sys/dev/usb/ubt.c: revision 1.60
sys/dev/usb/if_urtw.c: revision 1.14
sys/dev/usb/uirda.c: revision 1.43
sys/dev/usb/umass.c: revision 1.163
sys/dev/usb/if_cdce.c: revision 1.45
sys/dev/usb/if_cue.c: revision 1.77
sys/dev/usb/if_kue.c: revision 1.91
sys/dev/usb/uvideo.c: revision 1.46
sys/dev/usb/uhso.c: revision 1.27
sys/dev/usb/if_smsc.c: revision 1.33
sys/dev/usb/ugen.c: revision 1.137
sys/dev/usb/if_axe.c: revision 1.84
sys/dev/usb/if_aue.c: revision 1.142
sys/dev/usb/uscanner.c: revision 1.82
sys/dev/usb/if_urndis.c: revision 1.17
sys/dev/usb/udsir.c: revision 1.6
sys/dev/usb/if_url.c: revision 1.57
sys/dev/usb/if_otus.c: revision 1.32
sys/dev/usb/ulpt.c: revision 1.99

PR kern/52931 Kernel panics with Atheros usb wireless interface
Audit the flags to usbd_create_xfer so that USBD_FORCE_SHORT_XFER is
supplied wherever such a transfer is setup.  We can drop
USBD_SHORT_XFER_OK as it has not bearing on number of TDs

ualea: Tidy up a bit.  Fulfil requests completely.
Don't subtract uninitialized pktsize in error path.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.1 -r1.22.2.2 src/sys/dev/usb/if_athn_usb.c
cvs rdiff -u -r1.55 -r1.55.8.1 src/sys/dev/usb/if_atu.c
cvs rdiff -u -r1.141 -r1.141.8.1 src/sys/dev/usb/if_aue.c
cvs rdiff -u -r1.82.6.1 -r1.82.6.2 src/sys/dev/usb/if_axe.c
cvs rdiff -u -r1.11 -r1.11.8.1 src/sys/dev/usb/if_axen.c
cvs rdiff -u -r1.44 -r1.44.8.1 src/sys/dev/usb/if_cdce.c
cvs rdiff -u -r1.76 -r1.76.8.1 src/sys/dev/usb/if_cue.c
cvs rdiff -u -r1.90 -r1.90.2.1 src/sys/dev/usb/if_kue.c
cvs rdiff -u -r1.31 -r1.31.2.1 src/sys/dev/usb/if_otus.c
cvs rdiff -u -r1.58 -r1.58.2.1 src/sys/dev/usb/if_rum.c
cvs rdiff -u -r1.22 -r1.22.2.1 src/sys/dev/usb/if_run.c
cvs rdiff -u -r1.30 -r1.30.8.1 src/sys/dev/usb/if_smsc.c
cvs rdiff -u -r1.51 -r1.51.8.1 src/sys/dev/usb/if_udav.c
cvs rdiff -u -r1.17 -r1.17.8.1 src/sys/dev/usb/if_upgt.c
cvs rdiff -u -r1.59.8.1 -r1.59.8.2 src/sys/dev/usb/if_upl.c
cvs rdiff -u -r1.51.8.1 -r1.51.8.2 src/sys/dev/usb/if_ural.c
cvs rdiff -u -r1.56 -r1.56.8.1 src/sys/dev/usb/if_url.c
cvs rdiff -u -r1.16 -r1.16.2.1 src/sys/dev/usb/if_urndis.c
cvs rdiff -u -r1.13 -r1.13.8.1 src/sys/dev/usb/if_urtw.c
cvs rdiff -u -r1.53.2.1 -r1.53.2.2 src/sys/dev/usb/if_urtwn.c
cvs rdiff -u -r1.44 -r1.44.2.1 src/sys/dev/usb/if_zyd.c \
src/sys/dev/usb/uvideo.c
cvs rdiff -u -r1.3 -r1.3.6.1 src/sys/dev/usb/irmce.c
cvs rdiff -u -r1.23 -r1.23.10.1 src/sys/dev/usb/pseye.c
cvs rdiff -u -r1.6 -r1.6.8.1 src/sys/dev/usb/ualea.c
cvs rdiff -u -r1.59 -r1.59.2.1 src/sys/dev/usb/ubt.c
cvs rdiff -u -r1.118.8.1 -r1.118.8.2 src/sys/dev/usb/ucom.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/sys/dev/usb/udsir.c
cvs rdiff -u -r1.134 -r1.134.10.1 src/sys/dev/usb/ugen.c
cvs rdiff -u -r1.25 -r1.25.8.1 src/sys/dev/usb/uhso.c
cvs rdiff -u -r1.41 -r1.41.8.1 src/sys/dev/usb/uirda.c
cvs rdiff -u -r1.98 -r1.98.8.1 src/sys/dev/usb/ulpt.c
cvs rdiff -u -r1.158.4.1 -r1.158.4.2 src/sys/dev/usb/umass.c
cvs rdiff -u -r1.73 -r1.73.2.1 src/sys/dev/usb/umidi.c
cvs rdiff -u -r1.80 -r1.80.8.1 src/sys/dev/usb/uscanner.c
cvs rdiff -u -r1.42 -r1.42.8.1 src/sys/dev/usb/usscanner.c
cvs rdiff -u -r1.37 -r1.37.2.1 src/sys/dev/usb/ustir.c
cvs rdiff -u -r1.29 -r1.29.2.1 src/sys/dev/usb/utoppy.c

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

Modified files:

Index: 

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

2017-12-21 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Dec 21 21:53:32 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #459):
sys/dev/usb/xhci.c: 1.78, 1.83
PR/52791: Robert Sprowson: avoid duplicate tests (use accessor variables)
--
Fix the logic around TT Hub Slot ID, TT Port Number and Multi-TT in
xhci_setup_tthub.  TT Hub/Port need to reference the upstream HS hub and
Multi-TT needs to reflect the capabilities of a HS hub itself or the same
upstream HS hub.


To generate a diff of this commit:
cvs rdiff -u -r1.72.2.4 -r1.72.2.5 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.72.2.4 src/sys/dev/usb/xhci.c:1.72.2.5
--- src/sys/dev/usb/xhci.c:1.72.2.4	Thu Nov 23 13:29:32 2017
+++ src/sys/dev/usb/xhci.c	Thu Dec 21 21:53:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.72.2.4 2017/11/23 13:29:32 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.72.2.5 2017/12/21 21:53:31 snj Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.4 2017/11/23 13:29:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.5 2017/12/21 21:53:31 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -3147,8 +3147,10 @@ static void
 xhci_setup_tthub(struct usbd_pipe *pipe, uint32_t *cp)
 {
 	struct usbd_device *dev = pipe->up_dev;
+	struct usbd_port *myhsport = dev->ud_myhsport;
 	usb_device_descriptor_t * const dd = >ud_ddesc;
 	uint32_t speed = dev->ud_speed;
+	uint8_t rhaddr = dev->ud_bus->ub_rhaddr;
 	uint8_t tthubslot, ttportnum;
 	bool ishub;
 	bool usemtt;
@@ -3170,19 +3172,17 @@ xhci_setup_tthub(struct usbd_pipe *pipe,
 	 *   parent hub is not HS hub ||
 	 *   attached to root hub.
 	 */
-	if (dev->ud_myhsport != NULL &&
-	dev->ud_myhub != NULL && dev->ud_myhub->ud_depth != 0 &&
-	(dev->ud_myhub != NULL &&
-	 dev->ud_myhub->ud_speed == USB_SPEED_HIGH) &&
+	if (myhsport &&
+	myhsport->up_parent->ud_addr != rhaddr &&
 	(speed == USB_SPEED_LOW || speed == USB_SPEED_FULL)) {
-		ttportnum = dev->ud_myhsport->up_portno;
-		tthubslot = dev->ud_myhsport->up_parent->ud_addr;
+		ttportnum = myhsport->up_portno;
+		tthubslot = myhsport->up_parent->ud_addr;
 	} else {
 		ttportnum = 0;
 		tthubslot = 0;
 	}
 	DPRINTFN(4, "myhsport %#jx ttportnum=%jd tthubslot=%jd",
-	(uintptr_t)dev->ud_myhsport, ttportnum, tthubslot, 0);
+	(uintptr_t)myhsport, ttportnum, tthubslot, 0);
 
 	/* ishub is valid after reading UDESC_DEVICE */
 	ishub = (dd->bDeviceClass == UDCLASS_HUB);
@@ -3198,33 +3198,30 @@ xhci_setup_tthub(struct usbd_pipe *pipe,
 		DPRINTFN(4, "nports=%jd ttt=%jd", hd->bNbrPorts, ttt, 0, 0);
 	}
 
-#define IS_TTHUB(dd) \
-((dd)->bDeviceProtocol == UDPROTO_HSHUBSTT || \
- (dd)->bDeviceProtocol == UDPROTO_HSHUBMTT)
+#define IS_MTTHUB(dd) \
+ ((dd)->bDeviceProtocol == UDPROTO_HSHUBMTT)
 
 	/*
 	 * MTT flag is set if
-	 * 1. this is HS hub && MTT is enabled
-	 *  or
-	 * 2. this is not hub && this is LS or FS device &&
-	 *MTT of parent HS hub (and its parent, too) is enabled
+	 * 1. this is HS hub && MTTs are supported and enabled;  or
+	 * 2. this is LS or FS device && there is a parent HS hub where MTTs
+	 *are supported and enabled.
+	 *
+	 * XXX enabled is not tested yet
 	 */
-	if (ishub && speed == USB_SPEED_HIGH && IS_TTHUB(dd))
+	if (ishub && speed == USB_SPEED_HIGH && IS_MTTHUB(dd))
 		usemtt = true;
-	else if (!ishub &&
-	 (speed == USB_SPEED_LOW || speed == USB_SPEED_FULL) &&
-	 dev->ud_myhub != NULL && dev->ud_myhub->ud_depth != 0 &&
-	 (dev->ud_myhub != NULL &&
-	  dev->ud_myhub->ud_speed == USB_SPEED_HIGH) &&
-	 dev->ud_myhsport != NULL &&
-	 IS_TTHUB(>ud_myhsport->up_parent->ud_ddesc))
+	else if ((speed == USB_SPEED_LOW || speed == USB_SPEED_FULL) &&
+	myhsport &&
+	myhsport->up_parent->ud_addr != rhaddr &&
+	IS_MTTHUB(>up_parent->ud_ddesc))
 		usemtt = true;
 	else
 		usemtt = false;
 	DPRINTFN(4, "class %ju proto %ju ishub %jd usemtt %jd",
 	dd->bDeviceClass, dd->bDeviceProtocol, ishub, usemtt);
 
-#undef IS_TTHUB
+#undef IS_MTTHUB
 
 	cp[0] |=
 	XHCI_SCTX_0_HUB_SET(ishub ? 1 : 0) |



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

2017-12-21 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Dec 21 21:32:10 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by khorben in ticket #447):
sys/dev/usb/usb_subr.c: revision 1.222
Be more defensive towards malicious USB devices
This avoids potential panics due to 0-sized memory allocation attempts,
which could be triggered by malicious USB devices.
Tested on NetBSD/amd64 with a Sony Xperia X (SailfishOS).
Based on an initial patch by Nick Hudson , thanks!
Fixes PR kern/52383.


To generate a diff of this commit:
cvs rdiff -u -r1.220.2.1 -r1.220.2.2 src/sys/dev/usb/usb_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/usb/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.220.2.1 src/sys/dev/usb/usb_subr.c:1.220.2.2
--- src/sys/dev/usb/usb_subr.c:1.220.2.1	Thu Nov  2 21:29:52 2017
+++ src/sys/dev/usb/usb_subr.c	Thu Dec 21 21:32:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.220.2.1 2017/11/02 21:29:52 snj Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.220.2.2 2017/12/21 21:32:10 snj Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.1 2017/11/02 21:29:52 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.220.2.2 2017/12/21 21:32:10 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -609,6 +609,10 @@ usbd_set_config_index(struct usbd_device
 		return err;
 	}
 	len = UGETW(cd.wTotalLength);
+	if (len == 0) {
+		DPRINTF("empty short descriptor", 0, 0, 0, 0);
+		return USBD_INVAL;
+	}
 	cdp = kmem_alloc(len, KM_SLEEP);
 
 	/* Get the full descriptor.  Try a few times for slow devices. */
@@ -635,6 +639,11 @@ usbd_set_config_index(struct usbd_device
 		err = usbd_get_bos_desc(dev, index, );
 		if (!err) {
 			int blen = UGETW(bd.wTotalLength);
+			if (blen == 0) {
+DPRINTF("empty bos descriptor", 0, 0, 0, 0);
+err = USBD_INVAL;
+goto bad;
+			}
 			bdp = kmem_alloc(blen, KM_SLEEP);
 
 			/* Get the full desc */
@@ -724,6 +733,11 @@ usbd_set_config_index(struct usbd_device
 
 	/* Allocate and fill interface data. */
 	nifc = cdp->bNumInterface;
+	if (nifc == 0) {
+		DPRINTF("no interfaces", 0, 0, 0, 0);
+		err = USBD_INVAL;
+		goto bad;
+	}
 	dev->ud_ifaces = kmem_alloc(nifc * sizeof(struct usbd_interface),
 	KM_SLEEP);
 	DPRINTFN(5, "dev=%#jx cdesc=%#jx", (uintptr_t)dev, (uintptr_t)cdp,



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

2017-11-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Nov 23 13:16:21 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #383):
sys/dev/usb/if_urtwn.c: revision 1.55
PR/52702 Malicious USB devices attaching as urtwn(4) can corrupt kernel memory
Patch from PR slighly updated by me


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.53.2.1 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.53 src/sys/dev/usb/if_urtwn.c:1.53.2.1
--- src/sys/dev/usb/if_urtwn.c:1.53	Wed May  3 15:34:05 2017
+++ src/sys/dev/usb/if_urtwn.c	Thu Nov 23 13:16:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.53 2017/05/03 15:34:05 jnemeth Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.53.2.1 2017/11/23 13:16:21 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.53 2017/05/03 15:34:05 jnemeth Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.53.2.1 2017/11/23 13:16:21 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -589,8 +589,8 @@ static int
 urtwn_open_pipes(struct urtwn_softc *sc)
 {
 	/* Bulk-out endpoints addresses (from highest to lowest prio). */
-	static uint8_t epaddr[3];
-	static uint8_t rxepaddr[3];
+	static uint8_t epaddr[R92C_MAX_EPOUT];
+	static uint8_t rxepaddr[R92C_MAX_EPIN];
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
 	size_t i, ntx = 0, nrx = 0;
@@ -602,26 +602,32 @@ urtwn_open_pipes(struct urtwn_softc *sc)
 	id = usbd_get_interface_descriptor(sc->sc_iface);
 	for (i = 0; i < id->bNumEndpoints; i++) {
 		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
-		if (ed != NULL &&
-		UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK &&
-		UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT) {
-			epaddr[ntx] = ed->bEndpointAddress;
+		if (ed == NULL || UE_GET_XFERTYPE(ed->bmAttributes) != UE_BULK) {
+			continue;
+		}
+		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT) {
+			if (ntx < sizeof(epaddr))
+epaddr[ntx] = ed->bEndpointAddress;
 			ntx++;
 		}
-		if (ed != NULL &&
-		UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK &&
-		UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) {
-			rxepaddr[nrx] = ed->bEndpointAddress;
+		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) {
+			if (nrx < sizeof(rxepaddr))
+rxepaddr[nrx] = ed->bEndpointAddress;
 			nrx++;
 		}
 	}
-	DPRINTFN(DBG_INIT, ("%s: %s: found %zd bulk-out pipes\n",
-	device_xname(sc->sc_dev), __func__, ntx));
+	if (nrx == 0 || nrx > R92C_MAX_EPIN) {
+		aprint_error_dev(sc->sc_dev,
+		"%zd: invalid number of Rx bulk pipes\n", nrx);
+		return EIO;
+	}
 	if (ntx == 0 || ntx > R92C_MAX_EPOUT) {
 		aprint_error_dev(sc->sc_dev,
 		"%zd: invalid number of Tx bulk pipes\n", ntx);
 		return EIO;
 	}
+	DPRINTFN(DBG_INIT, ("%s: %s: found %zd/%zd bulk-in/out pipes\n",
+	device_xname(sc->sc_dev), __func__, nrx, ntx));
 	sc->rx_npipe = nrx;
 	sc->tx_npipe = ntx;
 



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

2017-11-17 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Fri Nov 17 20:35:57 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #356):
sys/dev/usb/xhci.c: revision 1.76
Wait 1ms first. Existing Intel xHCI requies 1ms delay to prevent system hang
(Errata).


To generate a diff of this commit:
cvs rdiff -u -r1.72.2.2 -r1.72.2.3 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.72.2.2 src/sys/dev/usb/xhci.c:1.72.2.3
--- src/sys/dev/usb/xhci.c:1.72.2.2	Thu Nov  2 21:29:52 2017
+++ src/sys/dev/usb/xhci.c	Fri Nov 17 20:35:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.72.2.2 2017/11/02 21:29:52 snj Exp $	*/
+/*	$NetBSD: xhci.c,v 1.72.2.3 2017/11/17 20:35:57 snj Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.2 2017/11/02 21:29:52 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.3 2017/11/17 20:35:57 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -689,10 +689,14 @@ xhci_hc_reset(struct xhci_softc * const 
 	usbcmd = XHCI_CMD_HCRST;
 	xhci_op_write_4(sc, XHCI_USBCMD, usbcmd);
 	for (i = 0; i < XHCI_WAIT_HCRST; i++) {
+		/*
+		 * Wait 1ms first. Existing Intel xHCI requies 1ms delay to
+		 * prevent system hang (Errata).
+		 */
+		usb_delay_ms(>sc_bus, 1);
 		usbcmd = xhci_op_read_4(sc, XHCI_USBCMD);
 		if ((usbcmd & XHCI_CMD_HCRST) == 0)
 			break;
-		usb_delay_ms(>sc_bus, 1);
 	}
 	if (i >= XHCI_WAIT_HCRST) {
 		aprint_error_dev(sc->sc_dev, "host controller reset timeout\n");



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

2017-09-27 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Sep 28 01:18:55 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #293):
sys/dev/usb/if_athn_usb.c: revision 1.23
PR/52553 Panic on "ifconfig athn0 up"
Don't race for a transfer in athn_usb_init on the free list for beacons.
Instead pre-assign a transfer to beacons in athn_usb_alloc_tx_list


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.22.2.1 src/sys/dev/usb/if_athn_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/if_athn_usb.c
diff -u src/sys/dev/usb/if_athn_usb.c:1.22 src/sys/dev/usb/if_athn_usb.c:1.22.2.1
--- src/sys/dev/usb/if_athn_usb.c:1.22	Thu Jun  1 02:45:11 2017
+++ src/sys/dev/usb/if_athn_usb.c	Thu Sep 28 01:18:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_athn_usb.c,v 1.22 2017/06/01 02:45:11 chs Exp $	*/
+/*	$NetBSD: if_athn_usb.c,v 1.22.2.1 2017/09/28 01:18:55 snj Exp $	*/
 /*	$OpenBSD: if_athn_usb.c,v 1.12 2013/01/14 09:50:31 jsing Exp $	*/
 
 /*-
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.22 2017/06/01 02:45:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.22.2.1 2017/09/28 01:18:55 snj Exp $");
 
 #ifdef	_KERNEL_OPT
 #include "opt_inet.h"
@@ -728,9 +728,15 @@ athn_usb_alloc_tx_list(struct athn_usb_s
 		/* Append this Tx buffer to our free list. */
 		TAILQ_INSERT_TAIL(>usc_tx_free_list, data, next);
 	}
-	if (error != 0)
+	if (error == 0) {
+		/* Steal one buffer for beacons. */
+		usc->usc_tx_bcn = TAILQ_FIRST(>usc_tx_free_list);
+		TAILQ_REMOVE(>usc_tx_free_list, usc->usc_tx_bcn, next);
+	} else {
 		athn_usb_free_tx_list(usc);
+	}
 	mutex_exit(>usc_tx_mtx);
+
 	return error;
 }
 
@@ -749,6 +755,10 @@ athn_usb_free_tx_list(struct athn_usb_so
 		if (xfer != NULL)
 			usbd_destroy_xfer(xfer);
 	}
+	if (usc->usc_tx_bcn) {
+		usbd_destroy_xfer(usc->usc_tx_bcn->xfer);
+		usc->usc_tx_bcn = NULL;
+	}
 }
 
 Static int
@@ -2756,12 +2766,6 @@ athn_usb_init_locked(struct ifnet *ifp)
 	usc->usc_cmdq.cur = usc->usc_cmdq.next = usc->usc_cmdq.queued = 0;
 	mutex_spin_exit(>usc_task_mtx);
 
-	/* Steal one buffer for beacons. */
-	mutex_enter(>usc_tx_mtx);
-	usc->usc_tx_bcn = TAILQ_FIRST(>usc_tx_free_list);
-	TAILQ_REMOVE(>usc_tx_free_list, usc->usc_tx_bcn, next);
-	mutex_exit(>usc_tx_mtx);
-
 	curchan = ic->ic_curchan;
 	extchan = NULL;
 



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

2017-09-04 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon Sep  4 06:43:15 UTC 2017

Modified Files:
src/sys/dev/usb [netbsd-8]: uhidev.c ukbd.c

Log Message:
Pull up following revision(s) (requested by jakllsch in ticket #263):
sys/dev/usb/uhidev.c: revision 1.71
sys/dev/usb/ukbd.c: revision 1.137-1.138
Fix memory leak in report parsing error paths.
--
Support more varieties of USB keyboard reports.
The previous code asssumed reports would closely match the Bootstrap
Keyboard Protocol.  This is no longer always the case, particularly
with higher-end keyboards.
--
Always try to set USB HID devices into Report Protocol.  (Unless the
device is known to be quirky.)
Some of the most-widely-compatible methods of implementing USB Keyboard
NKRO depend on this Request to function as designed.
Issuing this Request is recommended by the HID 1.11 spec (7.2.6):
... "the host should not make any assumptions about the device's state
and should set the desired protocol whenever initializing a device."


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.70.2.1 src/sys/dev/usb/uhidev.c
cvs rdiff -u -r1.136 -r1.136.6.1 src/sys/dev/usb/ukbd.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/uhidev.c
diff -u src/sys/dev/usb/uhidev.c:1.70 src/sys/dev/usb/uhidev.c:1.70.2.1
--- src/sys/dev/usb/uhidev.c:1.70	Thu Jun  1 02:45:12 2017
+++ src/sys/dev/usb/uhidev.c	Mon Sep  4 06:43:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhidev.c,v 1.70 2017/06/01 02:45:12 chs Exp $	*/
+/*	$NetBSD: uhidev.c,v 1.70.2.1 2017/09/04 06:43:14 snj Exp $	*/
 
 /*
  * Copyright (c) 2001, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.70 2017/06/01 02:45:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.70.2.1 2017/09/04 06:43:14 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -153,12 +153,9 @@ uhidev_attach(device_t parent, device_t 
 		aprint_error_dev(self, "couldn't establish power handler\n");
 
 	(void)usbd_set_idle(iface, 0, 0);
-#if 0
 
-	if ((usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_NO_SET_PROTO) == 0 &&
-	id->bInterfaceSubClass != UISUBCLASS_BOOT)
+	if ((usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_NO_SET_PROTO) == 0)
 		(void)usbd_set_protocol(iface, 1);
-#endif
 
 	maxinpktsize = 0;
 	sc->sc_iep_addr = sc->sc_oep_addr = -1;

Index: src/sys/dev/usb/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.136 src/sys/dev/usb/ukbd.c:1.136.6.1
--- src/sys/dev/usb/ukbd.c:1.136	Fri Jan 20 02:25:24 2017
+++ src/sys/dev/usb/ukbd.c	Mon Sep  4 06:43:14 2017
@@ -1,4 +1,4 @@
-/*  $NetBSD: ukbd.c,v 1.136 2017/01/20 02:25:24 maya Exp $*/
+/*  $NetBSD: ukbd.c,v 1.136.6.1 2017/09/04 06:43:14 snj Exp $*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.136 2017/01/20 02:25:24 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.136.6.1 2017/09/04 06:43:14 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -83,12 +83,11 @@ int	ukbddebug = 0;
 #define DPRINTFN(n,x)
 #endif
 
-#define MAXKEYCODE 6
-#define MAXMOD 8		/* max 32 */
+#define MAXKEYCODE 32
+#define MAXKEYS 256
 
 struct ukbd_data {
-	uint32_t	modifiers;
-	uint8_t		keycode[MAXKEYCODE];
+	uint8_t		keys[MAXKEYS/NBBY];
 };
 
 #define PRESS0x000
@@ -234,19 +233,14 @@ Static const uint8_t ukbd_trtab[256] = {
 
 #define KEY_ERROR 0x01
 
-#define MAXKEYS (MAXMOD+2*MAXKEYCODE)
-
 struct ukbd_softc {
 	struct uhidev sc_hdev;
 
 	struct ukbd_data sc_ndata;
 	struct ukbd_data sc_odata;
-	struct hid_location sc_modloc[MAXMOD];
-	u_int sc_nmod;
-	struct {
-		uint32_t mask;
-		uint8_t key;
-	} sc_mods[MAXMOD];
+	struct hid_location sc_keyloc[MAXKEYS];
+	uint8_t sc_keyuse[MAXKEYS];
+	u_int sc_nkeyloc;
 
 	struct hid_location sc_keycodeloc;
 	u_int sc_nkeycode;
@@ -307,15 +301,17 @@ void ukbdtracedump(void);
 void
 ukbdtracedump(void)
 {
-	int i;
+	size_t i, j;
 	for (i = 0; i < UKBDTRACESIZE; i++) {
 		struct ukbdtraceinfo *p =
 		[(i+ukbdtraceindex)%UKBDTRACESIZE];
-		printf("%"PRIu64".%06"PRIu64": mod=0x%02x key0=0x%02x key1=0x%02x "
-		   "key2=0x%02x key3=0x%02x\n",
-		   p->tv.tv_sec, (uint64_t)p->tv.tv_usec,
-		   p->ud.modifiers, p->ud.keycode[0], p->ud.keycode[1],
-		   p->ud.keycode[2], p->ud.keycode[3]);
+		printf("%"PRIu64".%06"PRIu64":", p->tv.tv_sec,
+		(uint64_t)p->tv.tv_usec);
+		for (j = 0; j < MAXKEYS; j++) {
+			if (isset(p->ud.keys, j))
+printf(" %zu", j);
+		}
+		printf(".\n");
 	}
 }
 #endif
@@ -438,7 +434,7 @@ ukbd_attach(device_t parent, device_t se
 #endif
 
 #ifdef DIAGNOSTIC
-	aprint_normal(": %d modifier keys, %d key codes", sc->sc_nmod,
+	aprint_normal(": %d Variable keys, %d Array codes", sc->sc_nkeyloc,
 	   sc->sc_nkeycode);
 	if (sc->sc_flags & FLAG_APPLE_FN)
 		aprint_normal(", apple fn key");
@@ -595,21 +591,22 @@ 

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

2017-09-04 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon Sep  4 06:40:37 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #262):
sys/dev/usb/usb.c: revision 1.166
Add a missing break that should have been included in revision 1.163.
Spotted by "sc dying" and reported on current-users


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.165.6.1 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.165 src/sys/dev/usb/usb.c:1.165.6.1
--- src/sys/dev/usb/usb.c:1.165	Thu Jan 19 16:05:00 2017
+++ src/sys/dev/usb/usb.c	Mon Sep  4 06:40:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb.c,v 1.165 2017/01/19 16:05:00 skrll Exp $	*/
+/*	$NetBSD: usb.c,v 1.165.6.1 2017/09/04 06:40:37 snj Exp $	*/
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.165 2017/01/19 16:05:00 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.165.6.1 2017/09/04 06:40:37 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -775,6 +775,7 @@ usbioctl(dev_t devt, u_long cmd, void *d
 			len = UGETW(ur->ucr_request.wLength);
 			kmem_free(ptr, len);
 		}
+		break;
 	}
 
 	case USB_DEVICEINFO:



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

2017-08-24 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Fri Aug 25 05:44:48 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #226):
sys/dev/usb/xhci.c: revision 1.73
Check both buses for ub_usepolling and schedule the soft interrupt handler
or call it directly.  Fixes usb keyboard in ddb when attached to xhci.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.72.2.1 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.72 src/sys/dev/usb/xhci.c:1.72.2.1
--- src/sys/dev/usb/xhci.c:1.72	Thu Jun  1 02:45:12 2017
+++ src/sys/dev/usb/xhci.c	Fri Aug 25 05:44:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.72 2017/06/01 02:45:12 chs Exp $	*/
+/*	$NetBSD: xhci.c,v 1.72.2.1 2017/08/25 05:44:48 snj Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72 2017/06/01 02:45:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.72.2.1 2017/08/25 05:44:48 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1211,6 +1211,12 @@ xhci_init(struct xhci_softc *sc)
 	return rv;
 }
 
+static inline bool
+xhci_polling_p(struct xhci_softc * const sc)
+{
+	return sc->sc_bus.ub_usepolling || sc->sc_bus2.ub_usepolling;
+}
+
 int
 xhci_intr(void *v)
 {
@@ -1228,7 +1234,7 @@ xhci_intr(void *v)
 		goto done;
 
 	/* If we get an interrupt while polling, then just ignore it. */
-	if (sc->sc_bus.ub_usepolling) {
+	if (xhci_polling_p(sc)) {
 #ifdef DIAGNOSTIC
 		DPRINTFN(16, "ignored interrupt while polling", 0, 0, 0, 0);
 #endif
@@ -1236,6 +1242,9 @@ xhci_intr(void *v)
 	}
 
 	ret = xhci_intr1(sc);
+	if (ret) {
+		usb_schedsoftintr(>sc_bus);
+	}
 done:
 	mutex_spin_exit(>sc_intr_lock);
 	return ret;
@@ -1270,8 +1279,6 @@ xhci_intr1(struct xhci_softc * const sc)
 	usbsts = xhci_op_read_4(sc, XHCI_USBSTS);
 	DPRINTFN(16, "USBSTS %08x", usbsts, 0, 0, 0);
 
-	usb_schedsoftintr(>sc_bus);
-
 	return 1;
 }
 
@@ -2106,7 +2113,7 @@ xhci_softintr(void *v)
 
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
-	KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(>sc_lock));
+	KASSERT(xhci_polling_p(sc) || mutex_owned(>sc_lock));
 
 	i = er->xr_ep;
 	j = er->xr_cs;
@@ -2150,7 +2157,10 @@ xhci_poll(struct usbd_bus *bus)
 	XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
 	mutex_spin_enter(>sc_intr_lock);
-	xhci_intr1(sc);
+	int ret = xhci_intr1(sc);
+	if (ret) {
+		xhci_softintr(bus);
+	}
 	mutex_spin_exit(>sc_intr_lock);
 
 	return;
@@ -3771,7 +3781,7 @@ xhci_device_ctrl_start(struct usbd_xfer 
 
 	xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci);
 
-	if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
+	if (xfer->ux_timeout && !xhci_polling_p(sc)) {
 		callout_reset(>ux_callout, mstohz(xfer->ux_timeout),
 		xhci_timeout, xfer);
 	}
@@ -3887,7 +3897,7 @@ xhci_device_bulk_start(struct usbd_xfer 
 
 	xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci);
 
-	if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
+	if (xfer->ux_timeout && !xhci_polling_p(sc)) {
 		callout_reset(>ux_callout, mstohz(xfer->ux_timeout),
 		xhci_timeout, xfer);
 	}
@@ -3993,7 +4003,7 @@ xhci_device_intr_start(struct usbd_xfer 
 
 	xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci);
 
-	if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
+	if (xfer->ux_timeout && !xhci_polling_p(sc)) {
 		callout_reset(>ux_callout, mstohz(xfer->ux_timeout),
 		xhci_timeout, xfer);
 	}
@@ -4015,7 +4025,7 @@ xhci_device_intr_done(struct usbd_xfer *
 
 	DPRINTFN(15, "%p slot %u dci %u", xfer, xs->xs_idx, dci, 0);
 
-	KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(>sc_lock));
+	KASSERT(xhci_polling_p(sc) || mutex_owned(>sc_lock));
 
 	usb_syncmem(>ux_dmabuf, 0, xfer->ux_length,
 	isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);



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

2017-08-01 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Aug  1 23:28:41 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #169):
sys/dev/usb/if_ural.c: revision 1.52
Free the RX list if ural_alloc_rx_list fails part way through.
Reported by Ilja Van Sprundel.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.51.8.1 src/sys/dev/usb/if_ural.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_ural.c
diff -u src/sys/dev/usb/if_ural.c:1.51 src/sys/dev/usb/if_ural.c:1.51.8.1
--- src/sys/dev/usb/if_ural.c:1.51	Fri Nov 25 12:56:29 2016
+++ src/sys/dev/usb/if_ural.c	Tue Aug  1 23:28:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ural.c,v 1.51 2016/11/25 12:56:29 skrll Exp $ */
+/*	$NetBSD: if_ural.c,v 1.51.8.1 2017/08/01 23:28:41 snj Exp $ */
 /*	$FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/if_ural.c,v 1.40 2006/06/02 23:14:40 sam Exp $	*/
 
 /*-
@@ -24,7 +24,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.51 2016/11/25 12:56:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.51.8.1 2017/08/01 23:28:41 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -652,7 +652,7 @@ ural_alloc_rx_list(struct ural_softc *sc
 
 	return 0;
 
-fail:	ural_free_tx_list(sc);
+fail:	ural_free_rx_list(sc);
 	return error;
 }
 



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

2017-07-24 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jul 25 01:39:42 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by skrll in ticket #136):
sys/dev/usb/uhci.c: revision 1.276
Only call uhci_free_stds if there are TDs to free.
In uhci_alloc_std_chain ensure we fill the TD array correctly and note
the number of allocated TDs so that uhci_free_stds will do the right thing
Fixes a problem seen by anon


To generate a diff of this commit:
cvs rdiff -u -r1.275 -r1.275.2.1 src/sys/dev/usb/uhci.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/uhci.c
diff -u src/sys/dev/usb/uhci.c:1.275 src/sys/dev/usb/uhci.c:1.275.2.1
--- src/sys/dev/usb/uhci.c:1.275	Thu Jun  1 02:45:12 2017
+++ src/sys/dev/usb/uhci.c	Tue Jul 25 01:39:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uhci.c,v 1.275 2017/06/01 02:45:12 chs Exp $	*/
+/*	$NetBSD: uhci.c,v 1.275.2.1 2017/07/25 01:39:41 snj Exp $	*/
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.275 2017/06/01 02:45:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.275.2.1 2017/07/25 01:39:41 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1995,7 +1995,6 @@ uhci_alloc_std_chain(uhci_softc_t *sc, s
 
 	uxfer->ux_stds = NULL;
 	uxfer->ux_nstd = ntd;
-	p = NULL;
 	if (ntd == 0) {
 		*sp = NULL;
 		DPRINTF("ntd=0", 0, 0, 0, 0);
@@ -2004,11 +2003,13 @@ uhci_alloc_std_chain(uhci_softc_t *sc, s
 	uxfer->ux_stds = kmem_alloc(sizeof(uhci_soft_td_t *) * ntd,
 	KM_SLEEP);
 
-	ntd--;
-	for (int i = ntd; i >= 0; i--) {
+	for (int i = 0; i < ntd; i++) {
 		p = uhci_alloc_std(sc);
 		if (p == NULL) {
-			uhci_free_stds(sc, uxfer);
+			if (i != 0) {
+uxfer->ux_nstd = i;
+uhci_free_stds(sc, uxfer);
+			}
 			kmem_free(uxfer->ux_stds,
 			sizeof(uhci_soft_td_t *) * ntd);
 			return ENOMEM;
@@ -2212,9 +2213,10 @@ uhci_device_bulk_fini(struct usbd_xfer *
 
 	KASSERT(ux->ux_type == UX_BULK);
 
-	uhci_free_stds(sc, ux);
-	if (ux->ux_nstd)
+	if (ux->ux_nstd) {
+		uhci_free_stds(sc, ux);
 		kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+	}
 }
 
 usbd_status
@@ -2482,9 +2484,10 @@ uhci_device_ctrl_fini(struct usbd_xfer *
 
 	KASSERT(ux->ux_type == UX_CTRL);
 
-	uhci_free_stds(sc, ux);
-	if (ux->ux_nstd)
+	if (ux->ux_nstd) {
+		uhci_free_stds(sc, ux);
 		kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+	}
 }
 
 usbd_status
@@ -2687,9 +2690,10 @@ uhci_device_intr_fini(struct usbd_xfer *
 
 	KASSERT(ux->ux_type == UX_INTR);
 
-	uhci_free_stds(sc, ux);
-	if (ux->ux_nstd)
+	if (ux->ux_nstd) {
+		uhci_free_stds(sc, ux);
 		kmem_free(ux->ux_stds, sizeof(uhci_soft_td_t *) * ux->ux_nstd);
+	}
 }
 
 usbd_status



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

2017-06-10 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Jun 10 06:23:01 UTC 2017

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

Log Message:
Pull up following revision(s) (requested by nat in ticket #24):
sys/dev/usb/uaudio.c: revision 1.154
Start as half as many transfers for recording.  This fixes recording and
play back when uaudio is used in full duplex mode.
The transfer scheduling probably is to blame.
Ok skrll@.


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.153.2.1 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.153 src/sys/dev/usb/uaudio.c:1.153.2.1
--- src/sys/dev/usb/uaudio.c:1.153	Thu Jun  1 02:45:12 2017
+++ src/sys/dev/usb/uaudio.c	Sat Jun 10 06:23:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.153 2017/06/01 02:45:12 chs Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.153.2.1 2017/06/10 06:23:01 snj Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.153 2017/06/01 02:45:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.153.2.1 2017/06/10 06:23:01 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2610,8 +2610,11 @@ uaudio_trigger_input(void *addr, void *s
 	ch->intr = intr;
 	ch->arg = arg;
 
-	 /* XXX -1 shouldn't be needed */
-	for (i = 0; i < UAUDIO_NCHANBUFS - 1; i++) {
+	/*
+	 * Start as half as many channels for recording as for playback.
+	 * This stops playback from stuttering in full-duplex operation.
+	 */
+	for (i = 0; i < UAUDIO_NCHANBUFS / 2; i++) {
 		uaudio_chan_rtransfer(ch);
 	}
 
@@ -2663,8 +2666,7 @@ uaudio_trigger_output(void *addr, void *
 	ch->intr = intr;
 	ch->arg = arg;
 
-	/* XXX -1 shouldn't be needed */
-	for (i = 0; i < UAUDIO_NCHANBUFS - 1; i++)
+	for (i = 0; i < UAUDIO_NCHANBUFS; i++)
 		uaudio_chan_ptransfer(ch);
 	mutex_enter(>sc_lock);
 	mutex_enter(>sc_intr_lock);