CVS commit: [netbsd-7] src/sys/external/bsd/dwc2

2019-12-05 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Dec  5 16:30:17 UTC 2019

Modified Files:
src/sys/external/bsd/dwc2 [netbsd-7]: dwc2.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #1716):
sys/external/bsd/dwc2/dwc2.c: revision 1.60
sys/external/bsd/dwc2/dwc2.c: revision 1.61
sys/external/bsd/dwc2/dwc2.c: revision 1.62
sys/external/bsd/dwc2/dwc2.c: revision 1.63
sys/external/bsd/dwc2/dwc2.c: revision 1.64
sys/external/bsd/dwc2/dwc2.c: revision 1.65
sys/external/bsd/dwc2/dwc2.c: revision 1.66
KNF
Make dwc2debug sysctl'able
Need  for previous
Use size_t for loop count variable
Calulate the right lenght for isoc transfer and the usb_syncmem
PR/54696: Kernel panic in bus_dma.c on Raspberry Pi 3B/3B+
build fix
Consistency.


To generate a diff of this commit:
cvs rdiff -u -r1.31.2.4 -r1.31.2.5 src/sys/external/bsd/dwc2/dwc2.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/external/bsd/dwc2/dwc2.c
diff -u src/sys/external/bsd/dwc2/dwc2.c:1.31.2.4 src/sys/external/bsd/dwc2/dwc2.c:1.31.2.5
--- src/sys/external/bsd/dwc2/dwc2.c:1.31.2.4	Sat Aug 25 14:57:35 2018
+++ src/sys/external/bsd/dwc2/dwc2.c	Thu Dec  5 16:30:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2.c,v 1.31.2.4 2018/08/25 14:57:35 martin Exp $	*/
+/*	$NetBSD: dwc2.c,v 1.31.2.5 2019/12/05 16:30:17 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,19 +30,21 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.31.2.4 2018/08/25 14:57:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.31.2.5 2019/12/05 16:30:17 bouyer Exp $");
 
 #include "opt_usb.h"
 
 #include 
-#include 
-#include 
-#include 
+
+#include 
 #include 
-#include 
+#include 
+#include 
 #include 
 #include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 
@@ -74,6 +76,33 @@ __KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.3
 } while (0)
 #define	DPRINTF(...)	DPRINTFN(1, __VA_ARGS__)
 int dwc2debug = 0;
+
+SYSCTL_SETUP(sysctl_hw_dwc2_setup, "sysctl hw.dwc2 setup")
+{
+	int err;
+	const struct sysctlnode *rnode;
+	const struct sysctlnode *cnode;
+
+	err = sysctl_createv(clog, 0, NULL, ,
+	CTLFLAG_PERMANENT, CTLTYPE_NODE, "dwc2",
+	SYSCTL_DESCR("dwc2 global controls"),
+	NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
+
+	if (err)
+		goto fail;
+
+	/* control debugging printfs */
+	err = sysctl_createv(clog, 0, , ,
+	CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
+	"debug", SYSCTL_DESCR("Enable debugging output"),
+	NULL, 0, , sizeof(dwc2debug), CTL_CREATE, CTL_EOL);
+	if (err)
+		goto fail;
+
+	return;
+fail:
+	aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err);
+}
 #else
 #define	DPRINTF(...) do { } while (0)
 #define	DPRINTFN(...) do { } while (0)
@@ -944,7 +973,6 @@ dwc2_device_start(struct usbd_xfer *xfer
 	uint32_t off = 0;
 	int retval, err;
 	int alloc_bandwidth = 0;
-	int i;
 
 	DPRINTFN(1, "xfer=%p pipe=%p\n", xfer, xfer->ux_pipe);
 
@@ -984,6 +1012,14 @@ dwc2_device_start(struct usbd_xfer *xfer
 		DPRINTFN(3, "req = %p dma = %" PRIxBUSADDR " len %d dir %s\n",
 		KERNADDR(>req_dma, 0), DMAADDR(>req_dma, 0),
 		len, dir == UE_DIR_IN ? "in" : "out");
+	} else if (xfertype == UE_ISOCHRONOUS) {
+		DPRINTFN(3, "xfer=%p nframes=%d flags=%d addr=%d endpt=%d,"
+		" mps=%d dir %s\n", xfer, xfer->ux_nframes, xfer->ux_flags, addr,
+		epnum, mps, dir == UT_READ ? "in" :"out");
+
+		len = 0;
+		for (size_t i = 0; i < xfer->ux_nframes; i++)
+			len += xfer->ux_frlengths[i];
 	} else {
 		DPRINTFN(3, "xfer=%p len=%d flags=%d addr=%d endpt=%d,"
 		" mps=%d dir %s\n", xfer, xfer->ux_length, xfer->ux_flags, addr,
@@ -1077,8 +1113,9 @@ dwc2_device_start(struct usbd_xfer *xfer
 	KASSERTMSG(xfer->ux_nframes == 0 || xfertype == UE_ISOCHRONOUS,
 	"nframes %d xfertype %d\n", xfer->ux_nframes, xfertype);
 
-	for (off = i = 0; i < xfer->ux_nframes; ++i) {
-		DPRINTFN(3, "xfer=%p frame=%d offset=%d length=%d\n", xfer, i,
+	off = 0;
+	for (size_t i = 0; i < xfer->ux_nframes; ++i) {
+		DPRINTFN(3, "xfer=%p frame=%zd offset=%d length=%d\n", xfer, i,
 		off, xfer->ux_frlengths[i]);
 
 		dwc2_hcd_urb_set_iso_desc_params(dwc2_urb, i, off,
@@ -1469,22 +1506,21 @@ void dwc2_host_complete(struct dwc2_hsot
 	DPRINTFN(3, "xfer=%p actlen=%d\n", xfer, xfer->ux_actlen);
 
 	if (xfertype == UE_ISOCHRONOUS) {
-		int i;
-
 		xfer->ux_actlen = 0;
-		for (i = 0; i < xfer->ux_nframes; ++i) {
+		for (size_t i = 0; i < xfer->ux_nframes; ++i) {
 			xfer->ux_frlengths[i] =
 dwc2_hcd_urb_get_iso_desc_actual_length(
 		urb, i);
+			DPRINTFN(1, "xfer=%p frame=%zu length=%d\n", xfer, i,
+			xfer->ux_frlengths[i]);
 			xfer->ux_actlen += xfer->ux_frlengths[i];
 		}
+		DPRINTFN(1, "xfer=%p actlen=%d (isoc)\n", xfer, xfer->ux_actlen);
 	}
 
 	if (xfertype == UE_ISOCHRONOUS && dbg_perio()) {
-		int i;
-
-		for (i = 

CVS commit: [netbsd-7] src/sys/external/bsd/dwc2/dist

2014-09-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  8 19:03:37 UTC 2014

Modified Files:
src/sys/external/bsd/dwc2/dist [netbsd-7]: dwc2_hcd.c dwc2_hcd.h
dwc2_hcdintr.c dwc2_hcdqueue.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #75):
sys/external/bsd/dwc2/dist/dwc2_hcd.c: revision 1.14
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: revision 1.11
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: revision 1.10
sys/external/bsd/dwc2/dist/dwc2_hcd.h: revision 1.9
Adapt the NAK holdoff scheme for FS/LS devices from the Raspberry Pi
Foundation driver.
Should fix PR/49019 - RPI: interrupt storm when url0 is up


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.13.2.1 src/sys/external/bsd/dwc2/dist/dwc2_hcd.c
cvs rdiff -u -r1.8 -r1.8.8.1 src/sys/external/bsd/dwc2/dist/dwc2_hcd.h
cvs rdiff -u -r1.9 -r1.9.2.1 src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c
cvs rdiff -u -r1.10 -r1.10.2.1 src/sys/external/bsd/dwc2/dist/dwc2_hcdqueue.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/external/bsd/dwc2/dist/dwc2_hcd.c
diff -u src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.13 src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.13.2.1
--- src/sys/external/bsd/dwc2/dist/dwc2_hcd.c:1.13	Thu Jul  3 07:18:42 2014
+++ src/sys/external/bsd/dwc2/dist/dwc2_hcd.c	Mon Sep  8 19:03:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2_hcd.c,v 1.13 2014/07/03 07:18:42 skrll Exp $	*/
+/*	$NetBSD: dwc2_hcd.c,v 1.13.2.1 2014/09/08 19:03:37 msaitoh Exp $	*/
 
 /*
  * hcd.c - DesignWare HS OTG Controller host-mode routines
@@ -42,7 +42,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: dwc2_hcd.c,v 1.13 2014/07/03 07:18:42 skrll Exp $);
+__KERNEL_RCSID(0, $NetBSD: dwc2_hcd.c,v 1.13.2.1 2014/09/08 19:03:37 msaitoh Exp $);
 
 #include sys/types.h
 #include sys/kmem.h
@@ -887,6 +887,23 @@ enum dwc2_transaction_type dwc2_hcd_sele
 		if (list_empty(hsotg-free_hc_list))
 			break;
 		qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry);
+
+		/*
+		 * Check to see if this is a NAK'd retransmit, in which case
+		 * ignore for retransmission. We hold off on bulk/control
+		 * retransmissions to reduce NAK interrupt overhead for
+		 * cheeky devices that just hold off using NAKs.
+		 */
+		if (qh-do_split 
+		qh-nak_frame != 0x 
+		dwc2_full_frame_num(qh-nak_frame) ==
+		dwc2_full_frame_num(dwc2_hcd_get_frame_number(hsotg))) {
+			qh_ptr = qh_ptr-next;
+			continue;
+		} else {
+			qh-nak_frame = 0x;
+		}
+
 		if (hsotg-core_params-uframe_sched  0) {
 			if (hsotg-available_host_channels  1)
 break;

Index: src/sys/external/bsd/dwc2/dist/dwc2_hcd.h
diff -u src/sys/external/bsd/dwc2/dist/dwc2_hcd.h:1.8 src/sys/external/bsd/dwc2/dist/dwc2_hcd.h:1.8.8.1
--- src/sys/external/bsd/dwc2/dist/dwc2_hcd.h:1.8	Thu Apr  3 06:34:58 2014
+++ src/sys/external/bsd/dwc2/dist/dwc2_hcd.h	Mon Sep  8 19:03:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2_hcd.h,v 1.8 2014/04/03 06:34:58 skrll Exp $	*/
+/*	$NetBSD: dwc2_hcd.h,v 1.8.8.1 2014/09/08 19:03:37 msaitoh Exp $	*/
 
 /*
  * hcd.h - DesignWare HS OTG Controller host-mode declarations
@@ -243,6 +243,7 @@ enum dwc2_transaction_type {
  * @interval:   Interval between transfers in (micro)frames
  * @sched_frame:(Micro)frame to initialize a periodic transfer.
  *  The transfer executes in the following (micro)frame.
+ * @nak_frame:  Internal variable used by the NAK holdoff code
  * @frame_usecs:Internal variable used by the microframe scheduler
  * @start_split_frame:  (Micro)frame at which last start split was initialized
  * @ntd:Actual number of transfer descriptors in a list
@@ -277,6 +278,7 @@ struct dwc2_qh {
 	u16 usecs;
 	u16 interval;
 	u16 sched_frame;
+	u16 nak_frame;
 	u16 frame_usecs[8];
 	u16 start_split_frame;
 	u16 ntd;

Index: src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c
diff -u src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.9 src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.9.2.1
--- src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.9	Sat Jul 26 09:18:53 2014
+++ src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c	Mon Sep  8 19:03:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: dwc2_hcdintr.c,v 1.9 2014/07/26 09:18:53 skrll Exp $	*/
+/*	$NetBSD: dwc2_hcdintr.c,v 1.9.2.1 2014/09/08 19:03:37 msaitoh Exp $	*/
 
 /*
  * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling
@@ -40,7 +40,7 @@
  * This file contains the interrupt handlers for Host mode
  */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: dwc2_hcdintr.c,v 1.9 2014/07/26 09:18:53 skrll Exp $);
+__KERNEL_RCSID(0, $NetBSD: dwc2_hcdintr.c,v 1.9.2.1 2014/09/08 19:03:37 msaitoh Exp $);
 
 #include sys/types.h
 #include sys/pool.h
@@ -1211,6 +1211,17 @@ static void dwc2_hc_nak_intr(struct dwc2
 			 chnum);
 
 	/*
+	 * When we get control/bulk NAKs then remember this so we holdoff