Module Name:    src
Committed By:   skrll
Date:           Sat Sep  3 12:07:42 UTC 2016

Modified Files:
        src/sys/dev/usb: xhci.c

Log Message:
Fix "spurious event" when command ring rolls over.
When the enqueue pointer of command ring points at the last TRB,
address of Link TRB was stored in sc_command_addr.
It should be address of 0th TRB of ring.

>From t-hash


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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.66 src/sys/dev/usb/xhci.c:1.67
--- src/sys/dev/usb/xhci.c:1.66	Sat Sep  3 12:06:50 2016
+++ src/sys/dev/usb/xhci.c	Sat Sep  3 12:07:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.66 2016/09/03 12:06:50 skrll Exp $	*/
+/*	$NetBSD: xhci.c,v 1.67 2016/09/03 12:07:41 skrll Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.66 2016/09/03 12:06:50 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.67 2016/09/03 12:07:41 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2498,7 +2498,14 @@ xhci_do_command_locked(struct xhci_softc
 
 	/* XXX KASSERT may fire when cv_timedwait unlocks sc_lock */
 	KASSERT(sc->sc_command_addr == 0);
-	sc->sc_command_addr = xhci_ring_trbp(cr, cr->xr_ep);
+	/*
+	 * If enqueue pointer points at last of ring, it's Link TRB,
+	 * command TRB will be stored in 0th TRB.
+	 */
+	if (cr->xr_ep == cr->xr_ntrb - 1)
+		sc->sc_command_addr = xhci_ring_trbp(cr, 0);
+	else
+		sc->sc_command_addr = xhci_ring_trbp(cr, cr->xr_ep);
 
 	mutex_enter(&cr->xr_lock);
 	xhci_ring_put(sc, cr, NULL, trb, 1);

Reply via email to