Change XHCI_CMD_TIMEOUT to be in nanoseconds, using the MSEC_TO_NSEC()
macro to implicitly document that USB timeouts are expressed in msec.

Then convert all tsleep(9) to tsleep_nsec(9), ok?

Index: xhci.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/xhci.c,v
retrieving revision 1.105
diff -u -p -r1.105 xhci.c
--- xhci.c      13 Jun 2019 21:03:48 -0000      1.105
+++ xhci.c      5 Oct 2019 09:18:24 -0000
@@ -1804,8 +1804,7 @@ xhci_command_submit(struct xhci_softc *s
        s = splusb();
        sc->sc_cmd_trb = trb;
        XDWRITE4(sc, XHCI_DOORBELL(0), 0);
-       error = tsleep(&sc->sc_cmd_trb, PZERO, "xhcicmd",
-           (timeout*hz+999)/ 1000 + 1);
+       error = tsleep_nsec(&sc->sc_cmd_trb, PZERO, "xhcicmd", timeout);
        if (error) {
 #ifdef XHCI_DEBUG
                printf("%s: tsleep() = %d\n", __func__, error);
@@ -2219,7 +2218,7 @@ xhci_abort_xfer(struct usbd_xfer *xfer, 
         */
        xhci_cmd_set_tr_deq_async(sc, xp->slot, xp->dci,
            DEQPTR(xp->ring) | xp->ring.toggle);
-       error = tsleep(xp, PZERO, "xhciab", (XHCI_CMD_TIMEOUT*hz+999)/1000 + 1);
+       error = tsleep_nsec(xp, PZERO, "xhciab", XHCI_CMD_TIMEOUT);
        if (error)
                printf("%s: timeout aborting transfer\n", DEVNAME(sc));
 }
Index: xhcivar.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/xhcivar.h,v
retrieving revision 1.10
diff -u -p -r1.10 xhcivar.h
--- xhcivar.h   5 Sep 2018 14:03:28 -0000       1.10
+++ xhcivar.h   5 Oct 2019 09:17:41 -0000
@@ -20,7 +20,7 @@
 #define        _XHCIVAR_H_
 
 /* Default command execution time (implementation defined). */
-#define        XHCI_CMD_TIMEOUT        500     /* ms */
+#define        XHCI_CMD_TIMEOUT        MSEC_TO_NSEC(500)
 
 #define        XHCI_MAX_CMDS           (16 * 1)
 #define        XHCI_MAX_EVTS           (16 * 13)

Reply via email to