Source-Changes-HG archive

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

[src/trunk]: src/sys consolidate the handling of polling across HC drivers, a...



details:   https://anonhg.NetBSD.org/src/rev/fa8ad8d953f6
branches:  trunk
changeset: 433487:fa8ad8d953f6
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Sep 16 20:21:56 2018 +0000

description:
consolidate the handling of polling across HC drivers, and generic USB:
- don't take mutexes if polling
- normalise the code across all drivers
- add some not yet code to block discovery to/from polling
- minor CSE
- adjust comment for usbd_set_polling() to reality now i properly
  understand what it is used for and why.

this, with a hack to make RB_ASKNAME to wait 5 seconds allows boot -a
work with USB keyboards.  there are still multiple issues remaining:
- discovery and polling need to be mutually exclusive
- attachment of ukbd and wskbd is not handled by config_pending, and
  the 5 second delay isn't going to always be enough.

diffstat:

 sys/dev/usb/ehci.c           |  32 +++++++++++++++++++--------
 sys/dev/usb/ohci.c           |  34 ++++++++++++++++++++---------
 sys/dev/usb/uhci.c           |  29 ++++++++++++++++---------
 sys/dev/usb/usb.c            |  49 ++++++++++++++++++++++++++++---------------
 sys/dev/usb/usbdi.c          |  23 ++++++++++---------
 sys/dev/usb/xhci.c           |  25 +++++++++++++++-------
 sys/external/bsd/dwc2/dwc2.c |  25 +++++++++++++++-------
 7 files changed, 141 insertions(+), 76 deletions(-)

diffs (truncated from 707 to 300 lines):

diff -r ceabe6f9716c -r fa8ad8d953f6 sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c        Sun Sep 16 15:40:36 2018 +0000
+++ b/sys/dev/usb/ehci.c        Sun Sep 16 20:21:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ehci.c,v 1.263 2018/09/16 09:25:47 skrll Exp $ */
+/*     $NetBSD: ehci.c,v 1.264 2018/09/16 20:21:56 mrg Exp $ */
 
 /*
  * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.263 2018/09/16 09:25:47 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.264 2018/09/16 20:21:56 mrg Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -2637,13 +2637,16 @@
 ehci_root_intr_start(struct usbd_xfer *xfer)
 {
        ehci_softc_t *sc = EHCI_XFER2SC(xfer);
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        if (sc->sc_dying)
                return USBD_IOERROR;
 
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
        sc->sc_intrxfer = xfer;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
        return USBD_IN_PROGRESS;
 }
@@ -3538,6 +3541,7 @@
        ehci_softc_t *sc = EHCI_XFER2SC(xfer);
        ehci_soft_qtd_t *setup, *status, *next;
        ehci_soft_qh_t *sqh;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        EHCIHIST_FUNC(); EHCIHIST_CALLED();
 
@@ -3657,7 +3661,8 @@
        DPRINTFN(5, "--- dump end ---", 0, 0, 0, 0);
 #endif
 
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        /* Insert qTD in QH list - also does usb_syncmem(sqh) */
        ehci_set_qh_qtd(sqh, setup);
@@ -3667,7 +3672,8 @@
        }
        ehci_add_intr_list(sc, exfer);
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
 #if 0
 #ifdef EHCI_DEBUG
@@ -3814,6 +3820,7 @@
        ehci_soft_qh_t *sqh;
        ehci_soft_qtd_t *end;
        int len, isread, endpt;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        EHCIHIST_FUNC(); EHCIHIST_CALLED();
 
@@ -3837,7 +3844,8 @@
 #endif
 
        /* Take lock here to protect nexttoggle */
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        ehci_reset_sqtd_chain(sc, xfer, len, isread, &epipe->nexttoggle, &end);
 
@@ -3864,7 +3872,8 @@
        }
        ehci_add_intr_list(sc, exfer);
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
 #if 0
 #ifdef EHCI_DEBUG
@@ -4029,6 +4038,7 @@
        ehci_soft_qtd_t *end;
        ehci_soft_qh_t *sqh;
        int len, isread, endpt;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        EHCIHIST_FUNC(); EHCIHIST_CALLED();
 
@@ -4052,7 +4062,8 @@
 #endif
 
        /* Take lock to protect nexttoggle */
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        ehci_reset_sqtd_chain(sc, xfer, len, isread, &epipe->nexttoggle, &end);
 
@@ -4079,7 +4090,8 @@
        }
        ehci_add_intr_list(sc, exfer);
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
 #if 0
 #ifdef EHCI_DEBUG
diff -r ceabe6f9716c -r fa8ad8d953f6 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Sun Sep 16 15:40:36 2018 +0000
+++ b/sys/dev/usb/ohci.c        Sun Sep 16 20:21:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.286 2018/09/16 10:29:39 mrg Exp $   */
+/*     $NetBSD: ohci.c,v 1.287 2018/09/16 20:21:56 mrg Exp $   */
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.286 2018/09/16 10:29:39 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.287 2018/09/16 20:21:56 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -2591,14 +2591,17 @@
 ohci_root_intr_start(struct usbd_xfer *xfer)
 {
        ohci_softc_t *sc = OHCI_XFER2SC(xfer);
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        if (sc->sc_dying)
                return USBD_IOERROR;
 
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
        KASSERT(sc->sc_intrxfer == NULL);
        sc->sc_intrxfer = xfer;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
        return USBD_IN_PROGRESS;
 }
@@ -2732,6 +2735,7 @@
        ohci_soft_ed_t *sed;
        int isread;
        int len;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
@@ -2750,7 +2754,8 @@
            UGETW(req->wIndex));
 
        /* Need to take lock here for pipe->tail.td */
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        /*
         * Use the pipe "tail" TD as our first and loan our first TD to the
@@ -2866,7 +2871,7 @@
            sizeof(sed->ed.ed_tailp),
            BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
        OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
-       if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
+       if (xfer->ux_timeout && !polling) {
                callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
                            ohci_timeout, xfer);
        }
@@ -2874,7 +2879,8 @@
        DPRINTF("done", 0, 0, 0, 0);
 
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
        return USBD_IN_PROGRESS;
 }
@@ -3001,6 +3007,7 @@
        ohci_soft_td_t *data, *tail, *tdp;
        ohci_soft_ed_t *sed;
        int len, isread, endpt;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
@@ -3018,7 +3025,8 @@
            len, isread, xfer->ux_flags);
        DPRINTFN(4, "endpt=%jd", endpt, 0, 0, 0);
 
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        /*
         * Use the pipe "tail" TD as our first and loan our first TD to the
@@ -3084,7 +3092,8 @@
        }
 
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
        return USBD_IN_PROGRESS;
 }
@@ -3203,6 +3212,7 @@
        ohci_soft_ed_t *sed = opipe->sed;
        ohci_soft_td_t *data, *last, *tail;
        int len, isread, endpt;
+       const bool polling = sc->sc_bus.ub_usepolling;
 
        OHCIHIST_FUNC(); OHCIHIST_CALLED();
 
@@ -3218,7 +3228,8 @@
        endpt = xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress;
        isread = UE_GET_DIR(endpt) == UE_DIR_IN;
 
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        /*
         * Use the pipe "tail" TD as our first and loan our first TD to the
@@ -3270,7 +3281,8 @@
            BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
 
        xfer->ux_status = USBD_IN_PROGRESS;
-       mutex_exit(&sc->sc_lock);
+       if (!polling)
+               mutex_exit(&sc->sc_lock);
 
        return USBD_IN_PROGRESS;
 }
diff -r ceabe6f9716c -r fa8ad8d953f6 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c        Sun Sep 16 15:40:36 2018 +0000
+++ b/sys/dev/usb/uhci.c        Sun Sep 16 20:21:56 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci.c,v 1.283 2018/09/03 16:29:34 riastradh Exp $     */
+/*     $NetBSD: uhci.c,v 1.284 2018/09/16 20:21:56 mrg Exp $   */
 
 /*
  * Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.283 2018/09/03 16:29:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.284 2018/09/16 20:21:56 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1555,7 +1555,7 @@
        struct uhci_pipe *upipe = UHCI_PIPE2UPIPE(xfer->ux_pipe);
        uhci_soft_td_t *std;
        uint32_t status = 0, nstatus;
-       bool polling __diagused = sc->sc_bus.ub_usepolling;
+       const bool polling __diagused = sc->sc_bus.ub_usepolling;
        int actlen;
 
        KASSERT(polling || mutex_owned(&sc->sc_lock));
@@ -2257,6 +2257,7 @@
        uhci_softc_t *sc = UHCI_XFER2SC(xfer);
        uhci_soft_td_t *data, *dataend;
        uhci_soft_qh_t *sqh;
+       const bool polling = sc->sc_bus.ub_usepolling;
        int len;
        int endpt;
        int isread;
@@ -2277,7 +2278,8 @@
        sqh = upipe->bulk.sqh;
 
        /* Take lock here to protect nexttoggle */
-       mutex_enter(&sc->sc_lock);
+       if (!polling)
+               mutex_enter(&sc->sc_lock);
 
        uhci_reset_std_chain(sc, xfer, len, isread, &upipe->nexttoggle,
            &dataend);
@@ -2311,12 +2313,13 @@
        uhci_add_bulk(sc, sqh);
        uhci_add_intr_list(sc, ux);



Home | Main Index | Thread Index | Old Index