Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by mrg in ticket...



details:   https://anonhg.NetBSD.org/src/rev/2c626145ef23
branches:  netbsd-8
changeset: 435277:2c626145ef23
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Sep 27 14:52:26 2018 +0000

description:
Pull up following revision(s) (requested by mrg in ticket #1037):

        sys/dev/usb/uhub.c: revision 1.139
        sys/external/bsd/dwc2/dwc2.c: revision 1.55
        sys/ddb/db_output.c: revision 1.34
        sys/ddb/db_command.c: revision 1.160
        sys/dev/usb/ehci.c: revision 1.264
        sys/dev/usb/xhci.c: revision 1.99
        sys/dev/usb/ehci.c: revision 1.265
        sys/kern/subr_userconf.c: revision 1.27
        sys/dev/usb/ehcivar.h: revision 1.46
        sys/dev/usb/ohci.c: revision 1.287
        sys/dev/usb/uhci.c: revision 1.284
        sys/dev/usb/usbdi.c: revision 1.178
        sys/dev/usb/usb.c: revision 1.172
        sys/dev/pci/xhci_pci.c: revision 1.14
        sys/dev/usb/usb.c: revision 1.173
        sys/dev/usb/usb.c: revision 1.174
        share/man/man4/usb.4: revision 1.110
        sys/ddb/db_command.c: revision 1.159
        sys/dev/usb/usb_subr.c: revision 1.227
        sys/dev/usb/uhcivar.h: revision 1.56
        (all via patch)

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.

call cnpollc(1) and cnpollc(0) around cngetc().
(christos has a good idea to add a function that does all 3,
and we should switch all the callers in this sequence to use
it (and fix the MD ones missing it still).  not all can, as
eg, line-grabbing functions can use cngetsn(), which only
calls cnpollc() twice.)


When this file is used when not building the kernel (eg: /usr/sbin/crash)
make cnpollc() go away.


reorder some struct members to remove holes.


add config_pending usage to uhub and general USB device attachment.
- call config_pending_incr() and config_pending_decr() around attaching
  devices against "usbdevif" attribute.

uhub:
- convert sc_explorepending and sc_running to bool.  add new sc_first_explore.
- call config_pending_incr() at the start of uhub_attach().  dropped in
  uhub_explore(), if this is the first explore.


implement a gross hack to fix "boot -a" on systems with usb keyboards on
systems with ehci handover to uhci (and maybe ohci), and fix a similar
problem for "boot -s".

there is effort to ensure that all devices attached via USB are probed
before RB_ASKNAME or RB_SINGLE attempts to ask any questions on the console,
and largely this works, often by chance, today, for USB disks and root.
i've recently pushed this more into uhub and general USB device attachment
as well, and kept a config_pending reference across the first explore of
a bus.  these fix many issues with directly attached hubs.

however, on systems where devices connected to ehci ports are handed over
to a companion uhci or ohci port, it may not be the first, or even second,
bus explore that finds the device finally before attachment, and at this
point all config_pending references are dropped.

there is no direct communication between drivers, the potentials are
looked up but their device_t is only used for generic things like the name,
so informing the correct companion to expect a device and deal with the
config_pending references is not possible without some fairly ugly layer
violations or multi-level callbacks (eg, we have "ehci0", and usually an
the relevant companion, eg, "uhci2", but it is the uhub that uhci2 has
attached that will deal with the device attachment.)

with the above fixes to generic USB code, the disown happens during the
first explore.  the hack works by, at this point, checking if (a) root
is not mounted, (b) single user or ask name are set, and (c) if the hack
as not been triggered already.  if all 3 conditions are true, then a
config_pending_incr() is called and a callback is triggered for (default)
5 seconds to call config_pending_decr().  ehci detach pauses waiting for
this callback if scheduled.

this allows enough time for the uhub and the ukbd/wskbd to attach before
the RK_ASKROOT prompts appear.  testing shows it takes between 1.5 and
2 seconds for the keyboard to appear after the disown occurs.

Index: dev/usb/ehcivar.c
- new sc_compcallout, sc_compcallout, sc_complock, and a state for th
  handover hack.

Index: dev/usb/ehci.c
ehci_init():
- use aprint_normal_dev() instead of manual device_xname().
- initialise sc_compcallout, sc_compcallout, sc_complock, and sc_comp_state.
ehci_detach():
- if there are companion controllers, tear own the above, including waiting
  if there is a callback scheduled.
ehci_disown_callback():
- new callout to call config_pending_decr() in the the future.
  schedule this ca
ehci_disown_sched_callback():
- if booting to single user or asking names, call config_pending_incr() and
  schedule the callout above, default 5 second delay.
ehci_disown():
- if disowning a port call ehci_disown_sched_callback().
deal with partial attach failures in usb_attach vs usb_detach aka PR 53598.
- make sure xhci's sc->sc_ios is NULL if failure happens.
- rearrange usb_attach() / usb_doattach() to make it simpler to clean up.
- move usb_async_intr softint into usb_once_init().  previously, each USB
  controller would start a new one, and leave the old one leaked.
- handle controller interrupts without a bus attached


remove usb(4)'s "flags 1" code.  it has been dead for a while,
as it runs during the interrupts part of configuration now,
and all the devices try attach as early as possible, including
any root or boot required disk or keyboard device, which is
what this flag was for.

diffstat:

 share/man/man4/usb.4         |  30 ++-------------
 sys/ddb/db_command.c         |  19 +++++++--
 sys/ddb/db_output.c          |   6 +-
 sys/dev/pci/xhci_pci.c       |   6 ++-
 sys/dev/usb/ehci.c           |  32 +++++++++++-----
 sys/dev/usb/ohci.c           |  34 ++++++++++++-----
 sys/dev/usb/uhci.c           |  29 ++++++++++-----
 sys/dev/usb/uhcivar.h        |   4 +-
 sys/dev/usb/uhub.c           |  35 +++++++++++-------
 sys/dev/usb/usb.c            |  82 ++++++++++++++++++++++++++-----------------
 sys/dev/usb/usb_subr.c       |   6 ++-
 sys/dev/usb/usbdi.c          |  23 ++++++-----
 sys/dev/usb/xhci.c           |  25 +++++++++----
 sys/external/bsd/dwc2/dwc2.c |  25 +++++++++----
 sys/kern/subr_userconf.c     |   8 +++-
 15 files changed, 219 insertions(+), 145 deletions(-)

diffs (truncated from 1176 to 300 lines):

diff -r 875c0d04d60b -r 2c626145ef23 share/man/man4/usb.4
--- a/share/man/man4/usb.4      Thu Sep 27 14:38:56 2018 +0000
+++ b/share/man/man4/usb.4      Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: usb.4,v 1.105 2017/01/21 20:30:29 jdolecek Exp $
+.\" $NetBSD: usb.4,v 1.105.4.1 2018/09/27 14:52:27 martin Exp $
 .\"
 .\" Copyright (c) 1999-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -43,10 +43,10 @@
 .Cd "slhci*  at pcmcia? function ?"
 .Cd "uhci*   at cardbus? function ?"
 .Cd "uhci*   at pci? dev ? function ?"
-.Cd "usb*    at ehci? flags X"
-.Cd "usb*    at ohci? flags X"
-.Cd "usb*    at uhci? flags X"
-.Cd "usb*    at slhci? flags X"
+.Cd "usb*    at ehci?"
+.Cd "usb*    at ohci?"
+.Cd "usb*    at uhci?"
+.Cd "usb*    at slhci?"
 .Cd "uhub*   at usb?"
 .Cd "uhub*   at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
 .Cd "XX*     at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
@@ -92,26 +92,6 @@
 .Tn USB
 system.
 .Pp
-The
-.Va flags
-argument to the
-.Va usb
-device affects the order in which the device detection happens
-during cold boot.
-Normally, only the USB host controller and the
-.Va usb
-device are detected during the autoconfiguration when the
-machine is booted.
-The rest of the devices are detected once
-the system becomes functional and the kernel thread for the
-.Va usb
-device is started.
-Sometimes it is desirable to have a device detected early in the
-boot process, e.g., the console keyboard.
-To achieve this use a
-.Va flags
-value of 1.
-.Pp
 .Nx
 supports the following machine-independent
 .Tn USB
diff -r 875c0d04d60b -r 2c626145ef23 sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Thu Sep 27 14:38:56 2018 +0000
+++ b/sys/ddb/db_command.c      Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.148.8.4 2018/09/23 17:28:25 martin Exp $      */
+/*     $NetBSD: db_command.c,v 1.148.8.5 2018/09/27 14:52:26 martin Exp $      */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.148.8.4 2018/09/23 17:28:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.148.8.5 2018/09/27 14:52:26 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -90,9 +90,9 @@
 #include <sys/module.h>
 #include <sys/kernhist.h>
 #include <sys/socketvar.h>
+#include <sys/queue.h>
 
-/*include queue macros*/
-#include <sys/queue.h>
+#include <dev/cons.h>
 
 #include <ddb/ddb.h>
 
@@ -541,7 +541,14 @@
        return ENOENT;
 }
 
-/* This function is called from machine trap code. */
+#ifndef _KERNEL
+#define        cnpollc(c)      __nothing
+#endif
+
+/*
+ * This function is called via db_trap() or directly from
+ * machine trap code.
+ */
 void
 db_command_loop(void)
 {
@@ -578,7 +585,9 @@
                if (db_print_position() != 0)
                        db_printf("\n");
                db_output_line = 0;
+               cnpollc(1);
                (void) db_read_line();
+               cnpollc(0);
                db_command(&db_last_command);
        }
 
diff -r 875c0d04d60b -r 2c626145ef23 sys/ddb/db_output.c
--- a/sys/ddb/db_output.c       Thu Sep 27 14:38:56 2018 +0000
+++ b/sys/ddb/db_output.c       Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_output.c,v 1.33 2012/09/01 01:13:51 matt Exp $      */
+/*     $NetBSD: db_output.c,v 1.33.32.1 2018/09/27 14:52:26 martin Exp $       */
 
 /*
  * Mach Operating System
@@ -35,7 +35,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.33 2012/09/01 01:13:51 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.33.32.1 2018/09/27 14:52:26 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -111,7 +111,7 @@
 
        for (p = "--db_more--"; *p; p++)
                cnputc(*p);
-       switch(cngetc()) {
+       switch (cngetc()) {
        case ' ':
                db_output_line = 0;
                break;
diff -r 875c0d04d60b -r 2c626145ef23 sys/dev/pci/xhci_pci.c
--- a/sys/dev/pci/xhci_pci.c    Thu Sep 27 14:38:56 2018 +0000
+++ b/sys/dev/pci/xhci_pci.c    Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci_pci.c,v 1.8 2017/01/19 16:05:00 skrll Exp $       */
+/*     $NetBSD: xhci_pci.c,v 1.8.6.1 2018/09/27 14:52:27 martin Exp $  */
 /*     OpenBSD: xhci_pci.c,v 1.4 2014/07/12 17:38:51 yuo Exp   */
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.8 2017/01/19 16:05:00 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.8.6.1 2018/09/27 14:52:27 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -138,6 +138,7 @@
        printf("%s: csr: %08x\n", __func__, csr);
 #endif
        if ((csr & PCI_COMMAND_MEM_ENABLE) == 0) {
+               sc->sc_ios = 0;
                aprint_error_dev(self, "memory access is disabled\n");
                return;
        }
@@ -155,6 +156,7 @@
                }
                break;
        default:
+               sc->sc_ios = 0;
                aprint_error_dev(self, "BAR not 64 or 32-bit MMIO\n");
                return;
        }
diff -r 875c0d04d60b -r 2c626145ef23 sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c        Thu Sep 27 14:38:56 2018 +0000
+++ b/sys/dev/usb/ehci.c        Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ehci.c,v 1.254.8.4 2018/08/25 11:29:52 martin Exp $ */
+/*     $NetBSD: ehci.c,v 1.254.8.5 2018/09/27 14:52:26 martin 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.254.8.4 2018/08/25 11:29:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.254.8.5 2018/09/27 14:52:26 martin Exp $");
 
 #include "ohci.h"
 #include "uhci.h"
@@ -2650,13 +2650,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;
 }
@@ -3551,6 +3554,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();
 
@@ -3670,7 +3674,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);
@@ -3680,7 +3685,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
@@ -3827,6 +3833,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();
 
@@ -3850,7 +3857,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);
 
@@ -3877,7 +3885,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
@@ -4042,6 +4051,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();
 
@@ -4065,7 +4075,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);
 
@@ -4092,7 +4103,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 875c0d04d60b -r 2c626145ef23 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Thu Sep 27 14:38:56 2018 +0000
+++ b/sys/dev/usb/ohci.c        Thu Sep 27 14:52:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.273.6.3 2018/08/25 11:29:52 martin Exp $    */
+/*     $NetBSD: ohci.c,v 1.273.6.4 2018/09/27 14:52:26 martin Exp $    */
 
 /*
  * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */



Home | Main Index | Thread Index | Old Index