Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb xhci(4): Serialize access to portsc registers.



details:   https://anonhg.NetBSD.org/src/rev/15338634c20c
branches:  trunk
changeset: 363471:15338634c20c
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Mar 13 11:30:04 2022 +0000

description:
xhci(4): Serialize access to portsc registers.

Both xhci_roothub_ctrl and xhci_suspend/resume do r/m/w on them, so
use a mutex to serialize access to avoid stomping on each other.

diffstat:

 sys/dev/usb/xhci.c    |  41 ++++++++++++++++++++++++++++++++++++-----
 sys/dev/usb/xhcivar.h |   3 ++-
 2 files changed, 38 insertions(+), 6 deletions(-)

diffs (128 lines):

diff -r 7aefead48ba1 -r 15338634c20c sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Sun Mar 13 11:29:55 2022 +0000
+++ b/sys/dev/usb/xhci.c        Sun Mar 13 11:30:04 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.161 2022/03/13 11:29:55 riastradh Exp $     */
+/*     $NetBSD: xhci.c,v 1.162 2022/03/13 11:30:04 riastradh Exp $     */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.161 2022/03/13 11:29:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.162 2022/03/13 11:30:04 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -709,6 +709,12 @@
        mutex_exit(&sc->sc_lock);
 
        /*
+        * Block roothub xfers which might touch portsc registers until
+        * we're done suspending.
+        */
+       mutex_enter(&sc->sc_rhlock);
+
+       /*
         * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
         * xHCI Power Management, p. 342
         * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342
@@ -889,7 +895,8 @@
        /* Success!  */
        ok = true;
 
-out:   return ok;
+out:   mutex_exit(&sc->sc_rhlock);
+       return ok;
 }
 
 bool
@@ -906,6 +913,12 @@
        KASSERT(sc->sc_suspender);
 
        /*
+        * Block roothub xfers which might touch portsc registers until
+        * we're done resuming.
+        */
+       mutex_enter(&sc->sc_rhlock);
+
+       /*
         * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2:
         * xHCI Power Management, p. 343
         * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=343
@@ -1089,7 +1102,8 @@
        /* Success!  */
        ok = true;
 
-out:   return ok;
+out:   mutex_exit(&sc->sc_rhlock);
+       return ok;
 }
 
 bool
@@ -1591,6 +1605,7 @@
 
        cv_init(&sc->sc_command_cv, "xhcicmd");
        cv_init(&sc->sc_cmdbusy_cv, "xhcicmdq");
+       mutex_init(&sc->sc_rhlock, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB);
        mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB);
 
@@ -3863,7 +3878,7 @@
  * Process root hub request.
  */
 static int
-xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
+xhci_roothub_ctrl_locked(struct usbd_bus *bus, usb_device_request_t *req,
     void *buf, int buflen)
 {
        struct xhci_softc * const sc = XHCI_BUS2SC(bus);
@@ -3875,6 +3890,8 @@
 
        XHCIHIST_FUNC();
 
+       KASSERT(mutex_owned(&sc->sc_rhlock));
+
        if (sc->sc_dying)
                return -1;
 
@@ -4127,6 +4144,20 @@
        return totlen;
 }
 
+static int
+xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
+    void *buf, int buflen)
+{
+       struct xhci_softc *sc = XHCI_BUS2SC(bus);
+       int actlen;
+
+       mutex_enter(&sc->sc_rhlock);
+       actlen = xhci_roothub_ctrl_locked(bus, req, buf, buflen);
+       mutex_exit(&sc->sc_rhlock);
+
+       return actlen;
+}
+
 /* root hub interrupt */
 
 static usbd_status
diff -r 7aefead48ba1 -r 15338634c20c sys/dev/usb/xhcivar.h
--- a/sys/dev/usb/xhcivar.h     Sun Mar 13 11:29:55 2022 +0000
+++ b/sys/dev/usb/xhcivar.h     Sun Mar 13 11:30:04 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhcivar.h,v 1.20 2022/03/03 06:09:03 riastradh Exp $   */
+/*     $NetBSD: xhcivar.h,v 1.21 2022/03/13 11:30:04 riastradh Exp $   */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -96,6 +96,7 @@
        struct usbd_bus sc_bus;         /* USB 3 bus */
        struct usbd_bus sc_bus2;        /* USB 2 bus */
 
+       kmutex_t sc_rhlock;
        kmutex_t sc_lock;
        kmutex_t sc_intr_lock;
 



Home | Main Index | Thread Index | Old Index