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

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

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

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

sys/dev/usb/usbdi.h: revision 1.97 (via patch)
sys/dev/usb/usbdi.c: revision 1.186 (via patch)
sys/dev/usb/usb_subr.c: revision 1.239 (via patch)

add new usbd_do_request_len() that can allocate a larger than
request size buffer.  reimplement usbd_do_request_flags() in
terms of this.  use this for fetching string descriptors.

fixes a very strange problem where an axe(4) attaching (either
has ugen(4) or axe(4)) would ask for 2 bytes, usb_mem.c would
allocate a 2 byte fragment, perform the operation, and sometime
shortly afterwards (usually by the time the next allocation
is made for this fragment), would become corrupted (usually
two bytes were written with 0x0304.)
(initial request of 4 bytes also avoids the problem on this
device.  it really seems like a HC problem -- host should not
allow the device to write more than req.wLength!  nor should
it allow this write to happen after completion.)

avoid an (almost) always double-log in usbd_transfer().


To generate a diff of this commit:
cvs rdiff -u -r1.196.4.5 -r1.196.4.6 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.161.2.4 -r1.161.2.5 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.90.2.2 -r1.90.2.3 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/usb_subr.c
diff -u src/sys/dev/usb/usb_subr.c:1.196.4.5 src/sys/dev/usb/usb_subr.c:1.196.4.6
--- src/sys/dev/usb/usb_subr.c:1.196.4.5	Wed Aug  8 10:17:11 2018
+++ src/sys/dev/usb/usb_subr.c	Sat Nov 16 16:13:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: usb_subr.c,v 1.196.4.5 2018/08/08 10:17:11 martin Exp $	*/
+/*	$NetBSD: usb_subr.c,v 1.196.4.6 2019/11/16 16:13:56 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.196.4.5 2018/08/08 10:17:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196.4.6 2019/11/16 16:13:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -157,13 +157,20 @@ usbd_get_string_desc(struct usbd_device 
 	usbd_status err;
 	int actlen;
 
+	/*
+	 * Pass a full-sized buffer to usbd_do_request_len().  At least
+	 * one device has been seen returning additional data beyond the
+	 * provided buffers (2-bytes written shortly after the request
+	 * claims to have completed and returned the 2 byte header,
+	 * corrupting other memory.)
+	 */
 	req.bmRequestType = UT_READ_DEVICE;
 	req.bRequest = UR_GET_DESCRIPTOR;
 	USETW2(req.wValue, UDESC_STRING, sindex);
 	USETW(req.wIndex, langid);
 	USETW(req.wLength, 2);	/* only size byte first */
-	err = usbd_do_request_flags(dev, , sdesc, USBD_SHORT_XFER_OK,
-		, USBD_DEFAULT_TIMEOUT);
+	err = usbd_do_request_len(dev, , sizeof(*sdesc), sdesc,
+	USBD_SHORT_XFER_OK, , USBD_DEFAULT_TIMEOUT);
 	if (err)
 		return err;
 
@@ -171,8 +178,8 @@ usbd_get_string_desc(struct usbd_device 
 		return USBD_SHORT_XFER;
 
 	USETW(req.wLength, sdesc->bLength);	/* the whole string */
-	err = usbd_do_request_flags(dev, , sdesc, USBD_SHORT_XFER_OK,
-		, USBD_DEFAULT_TIMEOUT);
+	err = usbd_do_request_len(dev, , sizeof(*sdesc), sdesc,
+	USBD_SHORT_XFER_OK, , USBD_DEFAULT_TIMEOUT);
 	if (err)
 		return err;
 
@@ -1192,7 +1199,7 @@ usbd_get_initial_ddesc(struct usbd_devic
 	req.bRequest = UR_GET_DESCRIPTOR;
 	USETW2(req.wValue, UDESC_DEVICE, 0);
 	USETW(req.wIndex, 0);
-	USETW(req.wLength, 64);
+	USETW(req.wLength, 8);
 	res = usbd_do_request_flags(dev, , buf, USBD_SHORT_XFER_OK,
 		, USBD_DEFAULT_TIMEOUT);
 	if (res)

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.161.2.4 src/sys/dev/usb/usbdi.c:1.161.2.5
--- src/sys/dev/usb/usbdi.c:1.161.2.4	Fri Jan 11 15:58:23 2019
+++ src/sys/dev/usb/usbdi.c	Sat Nov 16 16:13:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.161.2.4 2019/01/11 15:58:23 martin Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.161.2.5 2019/11/16 16:13:56 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.161.2.4 2019/01/11 15:58:23 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.161.2.5 2019/11/16 16:13:56 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -331,6 +331,8 @@ usbd_transfer(struct usbd_xfer *xfer)
 		 * accepted by the HCD for some reason.  It needs removing
 		 * from the pipe queue.
 		 */
+		USBHIST_LOG(usbdebug, "xfer failed: %s, reinserting",
+		err, 0, 0, 0);
 		usbd_lock_pipe(pipe);
 		SIMPLEQ_REMOVE_HEAD(>up_queue, ux_next);
 		if (pipe->up_serialise)
@@ -1072,13 +1074,23 @@ usbd_status
 usbd_do_request_flags(struct usbd_device *dev, usb_device_request_t 

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

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

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

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

sys/dev/usb/usbdi.h: revision 1.97 (via patch)
sys/dev/usb/usbdi.c: revision 1.186 (via patch)
sys/dev/usb/usb_subr.c: revision 1.239 (via patch)

add new usbd_do_request_len() that can allocate a larger than
request size buffer.  reimplement usbd_do_request_flags() in
terms of this.  use this for fetching string descriptors.

fixes a very strange problem where an axe(4) attaching (either
has ugen(4) or axe(4)) would ask for 2 bytes, usb_mem.c would
allocate a 2 byte fragment, perform the operation, and sometime
shortly afterwards (usually by the time the next allocation
is made for this fragment), would become corrupted (usually
two bytes were written with 0x0304.)
(initial request of 4 bytes also avoids the problem on this
device.  it really seems like a HC problem -- host should not
allow the device to write more than req.wLength!  nor should
it allow this write to happen after completion.)

avoid an (almost) always double-log in usbd_transfer().


To generate a diff of this commit:
cvs rdiff -u -r1.196.4.5 -r1.196.4.6 src/sys/dev/usb/usb_subr.c
cvs rdiff -u -r1.161.2.4 -r1.161.2.5 src/sys/dev/usb/usbdi.c
cvs rdiff -u -r1.90.2.2 -r1.90.2.3 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.



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

2019-09-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Sep 17 18:04:15 UTC 2019

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

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

sys/dev/usb/xhci.c: revision 1.113
sys/dev/usb/xhci.c: revision 1.109

match xhci version 3.10.  allows properly finding all the USB
busses on new ryzen 3 based systems.

unfortunately, the USB busses are still non-functional.

 -

fix ryzen usb issue: we set TD size to '1', where has xhci spec 4.11.2.4
says final TRB for a TD should have this set to '0'.  since we currently
only generate sinel TRB TDs, set this to 0.

XXX: pullup-all
from sc.dying


To generate a diff of this commit:
cvs rdiff -u -r1.23.2.8 -r1.23.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/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.23.2.8 src/sys/dev/usb/xhci.c:1.23.2.9
--- src/sys/dev/usb/xhci.c:1.23.2.8	Sat Aug 25 14:57:35 2018
+++ src/sys/dev/usb/xhci.c	Tue Sep 17 18:04:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.23.2.8 2018/08/25 14:57:35 martin Exp $	*/
+/*	$NetBSD: xhci.c,v 1.23.2.9 2019/09/17 18:04:15 martin Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.23.2.8 2018/08/25 14:57:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.23.2.9 2019/09/17 18:04:15 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -753,6 +753,8 @@ hexdump(const char *msg, const void *bas
 static void
 xhci_id_protocols(struct xhci_softc *sc, bus_size_t ecp)
 {
+	XHCIHIST_FUNC(); XHCIHIST_CALLED();
+
 	/* XXX Cache this lot */
 
 	const uint32_t w0 = xhci_read_4(sc, ecp);
@@ -776,6 +778,7 @@ xhci_id_protocols(struct xhci_softc *sc,
 	case 0x0200:
 	case 0x0300:
 	case 0x0301:
+	case 0x0310:
 		aprint_debug_dev(sc->sc_dev, " %s ports %d - %d\n",
 		major == 3 ? "ss" : "hs", cpo, cpo + cpc -1);
 		break;
@@ -3792,7 +3795,7 @@ xhci_device_ctrl_start(struct usbd_xfer 
 		parameter = DMAADDR(dma, 0);
 		KASSERTMSG(len <= 0x1, "len %d", len);
 		status = XHCI_TRB_2_IRQ_SET(0) |
-		XHCI_TRB_2_TDSZ_SET(1) |
+		XHCI_TRB_2_TDSZ_SET(0) |
 		XHCI_TRB_2_BYTES_SET(len);
 		control = (isread ? XHCI_TRB_3_DIR_IN : 0) |
 		XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_DATA_STAGE) |
@@ -3919,7 +3922,7 @@ xhci_device_bulk_start(struct usbd_xfer 
 	 */
 	KASSERTMSG(len <= 0x1, "len %d", len);
 	status = XHCI_TRB_2_IRQ_SET(0) |
-	XHCI_TRB_2_TDSZ_SET(1) |
+	XHCI_TRB_2_TDSZ_SET(0) |
 	XHCI_TRB_2_BYTES_SET(len);
 	control = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_NORMAL) |
 	(usbd_xfer_isread(xfer) ? XHCI_TRB_3_ISP_BIT : 0) |
@@ -4026,7 +4029,7 @@ xhci_device_intr_start(struct usbd_xfer 
 	parameter = DMAADDR(dma, 0);
 	KASSERTMSG(len <= 0x1, "len %d", len);
 	status = XHCI_TRB_2_IRQ_SET(0) |
-	XHCI_TRB_2_TDSZ_SET(1) |
+	XHCI_TRB_2_TDSZ_SET(0) |
 	XHCI_TRB_2_BYTES_SET(len);
 	control = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_NORMAL) |
 	(usbd_xfer_isread(xfer) ? XHCI_TRB_3_ISP_BIT : 0) |