Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Pull across xhci(4) improvemnts from nick-nhusb



details:   https://anonhg.NetBSD.org/src/rev/84ece86e4b49
branches:  trunk
changeset: 821004:84ece86e4b49
user:      skrll <skrll%NetBSD.org@localhost>
date:      Thu Jan 19 16:05:00 2017 +0000

description:
Pull across xhci(4) improvemnts from nick-nhusb

diffstat:

 sys/dev/pci/xhci_pci.c |   10 +-
 sys/dev/usb/usb.c      |   20 +-
 sys/dev/usb/usb.h      |    8 +-
 sys/dev/usb/usb_subr.c |   46 ++++--
 sys/dev/usb/usbdivar.h |   14 +-
 sys/dev/usb/xhci.c     |  324 +++++++++++++++++++++++++++++++++++-------------
 sys/dev/usb/xhcireg.h  |   47 ++++--
 sys/dev/usb/xhcivar.h  |   29 ++-
 8 files changed, 354 insertions(+), 144 deletions(-)

diffs (truncated from 1137 to 300 lines):

diff -r e8f5f9223dd6 -r 84ece86e4b49 sys/dev/pci/xhci_pci.c
--- a/sys/dev/pci/xhci_pci.c    Thu Jan 19 11:24:05 2017 +0000
+++ b/sys/dev/pci/xhci_pci.c    Thu Jan 19 16:05:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci_pci.c,v 1.7 2016/10/13 20:05:06 jdolecek Exp $    */
+/*     $NetBSD: xhci_pci.c,v 1.8 2017/01/19 16:05:00 skrll 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.7 2016/10/13 20:05:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.8 2017/01/19 16:05:00 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -126,7 +126,6 @@
        char intrbuf[PCI_INTRSTR_LEN];
 
        sc->sc_dev = self;
-       sc->sc_bus.ub_hcpriv = sc;
 
        pci_aprint_devinfo(pa, "USB Controller");
 
@@ -219,8 +218,11 @@
                                  xhci_shutdown))
                aprint_error_dev(self, "couldn't establish power handler\n");
 
-       /* Attach usb device. */
+       /* Attach usb buses. */
        sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
+
+       sc->sc_child2 = config_found(self, &sc->sc_bus2, usbctlprint);
+
        return;
 
 fail:
diff -r e8f5f9223dd6 -r 84ece86e4b49 sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Thu Jan 19 11:24:05 2017 +0000
+++ b/sys/dev/usb/usb.c Thu Jan 19 16:05:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.c,v 1.164 2016/08/14 14:42:22 skrll Exp $  */
+/*     $NetBSD: usb.c,v 1.165 2017/01/19 16:05:00 skrll Exp $  */
 
 /*
  * Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.164 2016/08/14 14:42:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.165 2017/01/19 16:05:00 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -727,8 +727,12 @@
                        error = EINVAL;
                        goto fail;
                }
-               if (addr < 0 || addr >= USB_MAX_DEVICES ||
-                   sc->sc_bus->ub_devices[addr] == NULL) {
+               if (addr < 0 || addr >= USB_MAX_DEVICES) {
+                       error = EINVAL;
+                       goto fail;
+               }
+               size_t dindex = usb_addr2dindex(addr);
+               if (sc->sc_bus->ub_devices[dindex] == NULL) {
                        error = EINVAL;
                        goto fail;
                }
@@ -750,7 +754,7 @@
                                        goto ret;
                        }
                }
-               err = usbd_do_request_flags(sc->sc_bus->ub_devices[addr],
+               err = usbd_do_request_flags(sc->sc_bus->ub_devices[dindex],
                          &ur->ucr_request, ptr, ur->ucr_flags, &ur->ucr_actlen,
                          USBD_DEFAULT_TIMEOUT);
                if (err) {
@@ -783,7 +787,8 @@
                        error = EINVAL;
                        goto fail;
                }
-               if ((dev = sc->sc_bus->ub_devices[addr]) == NULL) {
+               size_t dindex = usb_addr2dindex(addr);
+               if ((dev = sc->sc_bus->ub_devices[dindex]) == NULL) {
                        error = ENXIO;
                        goto fail;
                }
@@ -802,7 +807,8 @@
                        error = EINVAL;
                        goto fail;
                }
-               if ((dev = sc->sc_bus->ub_devices[addr]) == NULL) {
+               size_t dindex = usb_addr2dindex(addr);
+               if ((dev = sc->sc_bus->ub_devices[dindex]) == NULL) {
                        error = ENXIO;
                        goto fail;
                }
diff -r e8f5f9223dd6 -r 84ece86e4b49 sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h Thu Jan 19 11:24:05 2017 +0000
+++ b/sys/dev/usb/usb.h Thu Jan 19 16:05:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.h,v 1.114 2016/09/17 06:29:50 skrll Exp $  */
+/*     $NetBSD: usb.h,v 1.115 2017/01/19 16:05:00 skrll Exp $  */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -53,9 +53,9 @@
 
 #define USB_STACK_VERSION 2
 
-#define USB_MAX_DEVICES 128
-#define USB_MIN_DEVICES 2               /* unused + root HUB */
-#define USB_START_ADDR 0
+#define USB_MAX_DEVICES                128             /* 0, 1-127 */
+#define USB_MIN_DEVICES                2               /* unused + root HUB */
+#define USB_START_ADDR         0
 
 #define USB_CONTROL_ENDPOINT 0
 #define USB_MAX_ENDPOINTS 16
diff -r e8f5f9223dd6 -r 84ece86e4b49 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Thu Jan 19 11:24:05 2017 +0000
+++ b/sys/dev/usb/usb_subr.c    Thu Jan 19 16:05:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.217 2016/12/04 10:12:35 skrll Exp $     */
+/*     $NetBSD: usb_subr.c,v 1.218 2017/01/19 16:05:00 skrll Exp $     */
 /*     $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $   */
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.217 2016/12/04 10:12:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.218 2017/01/19 16:05:00 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -801,7 +801,7 @@
        if (err) {
                DPRINTF("endpoint=0x%x failed, error=%d",
                    ep->ue_edesc->bEndpointAddress, err, 0, 0);
-               kmem_intr_free(p, dev->ud_bus->ub_pipesize);
+               kmem_free(p, dev->ud_bus->ub_pipesize);
                return err;
        }
 
@@ -832,9 +832,11 @@
 {
        int addr;
 
-       for (addr = 1; addr < USB_MAX_DEVICES; addr++)
-               if (bus->ub_devices[addr] == NULL)
+       for (addr = 1; addr < USB_MAX_DEVICES; addr++) {
+               size_t dindex = usb_addr2dindex(addr);
+               if (bus->ub_devices[dindex] == NULL)
                        return addr;
+       }
        return -1;
 }
 
@@ -1160,8 +1162,8 @@
  * and attach a driver.
  */
 usbd_status
-usbd_new_device(device_t parent, struct usbd_bus* bus, int depth,
-                int speed, int port, struct usbd_port *up)
+usbd_new_device(device_t parent, struct usbd_bus *bus, int depth, int speed,
+    int port, struct usbd_port *up)
 {
        USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
        struct usbd_device *dev, *adev;
@@ -1248,7 +1250,7 @@
 
        /* Establish the default pipe. */
        err = usbd_setup_pipe_flags(dev, 0, &dev->ud_ep0, USBD_DEFAULT_INTERVAL,
-                             &dev->ud_pipe0, USBD_MPSAFE);
+           &dev->ud_pipe0, USBD_MPSAFE);
        if (err) {
                usbd_remove_device(dev, up);
                return err;
@@ -1261,6 +1263,11 @@
                err = usbd_get_initial_ddesc(dev, dd);
                if (!err)
                        break;
+               /*
+                * The root hub can never fail to give the initial descriptor,
+                * but assert it just in case.
+                */
+               KASSERT(up->up_parent);
                usbd_delay_ms(dev, 200);
                if ((i & 3) == 3)
                        usbd_reset_port(up->up_parent, port, &ps);
@@ -1331,7 +1338,7 @@
        /* Allow device time to set new address */
        usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
        dev->ud_addr = addr;    /* new device address now */
-       bus->ub_devices[addr] = dev;
+       bus->ub_devices[usb_addr2dindex(addr)] = dev;
 
        /* Re-establish the default pipe with the new address. */
        usbd_kill_pipe(dev->ud_pipe0);
@@ -1423,7 +1430,7 @@
        if (dev->ud_pipe0 != NULL)
                usbd_kill_pipe(dev->ud_pipe0);
        up->up_dev = NULL;
-       dev->ud_bus->ub_devices[dev->ud_addr] = NULL;
+       dev->ud_bus->ub_devices[usb_addr2dindex(dev->ud_addr)] = NULL;
 
        kmem_free(dev, sizeof(*dev));
 }
@@ -1553,7 +1560,8 @@
                if (p->up_dev)
                        err = p->up_dev->ud_addr;
                else {
-                       int s = UGETW(p->up_status.wPortStatus);
+                       const int s = UGETW(p->up_status.wPortStatus);
+                       const bool sshub_p = USB_IS_SS(dev->ud_speed);
                        if (s & UPS_PORT_ENABLED)
                                err = USB_PORT_ENABLED;
                        else if (s & UPS_SUSPEND)
@@ -1563,10 +1571,9 @@
                         * on 3.x, and UPS_PORT_POWER is available
                         * only on 2.0 or 1.1.
                         */
-                       else if (USB_IS_SS(dev->ud_speed) &&
-                           (s & UPS_PORT_POWER_SS))
+                       else if (sshub_p && (s & UPS_PORT_POWER_SS))
                                err = USB_PORT_POWERED;
-                       else if (s & UPS_PORT_POWER)
+                       else if (!sshub_p && (s & UPS_PORT_POWER))
                                err = USB_PORT_POWERED;
                        else
                                err = USB_PORT_DISABLED;
@@ -1629,7 +1636,7 @@
                if (p->up_dev)
                        err = p->up_dev->ud_addr;
                else {
-                       int s = UGETW(p->up_status.wPortStatus);
+                       const int s = UGETW(p->up_status.wPortStatus);
                        if (s & UPS_PORT_ENABLED)
                                err = USB_PORT_ENABLED;
                        else if (s & UPS_SUSPEND)
@@ -1731,9 +1738,14 @@
                KASSERT(!dev->ud_nifaces_claimed);
        }
 
+       mutex_enter(dev->ud_bus->ub_lock);
+       dev->ud_bus->ub_devices[usb_addr2dindex(dev->ud_addr)] = NULL;
+       up->up_dev = NULL;
+       mutex_exit(dev->ud_bus->ub_lock);
+
        usbd_add_dev_event(USB_EVENT_DEVICE_DETACH, dev);
-       dev->ud_bus->ub_devices[dev->ud_addr] = NULL;
-       up->up_dev = NULL;
+
        usb_free_device(dev);
+
        return 0;
 }
diff -r e8f5f9223dd6 -r 84ece86e4b49 sys/dev/usb/usbdivar.h
--- a/sys/dev/usb/usbdivar.h    Thu Jan 19 11:24:05 2017 +0000
+++ b/sys/dev/usb/usbdivar.h    Thu Jan 19 16:05:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdivar.h,v 1.113 2016/04/23 10:15:32 skrll Exp $     */
+/*     $NetBSD: usbdivar.h,v 1.114 2017/01/19 16:05:00 skrll Exp $     */
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -139,6 +139,9 @@
 };
 
 /*****/
+/* 0, root, and 1->127 */
+#define USB_ROOTHUB_INDEX      1
+#define USB_TOTAL_DEVICES      (USB_MAX_DEVICES + 1)
 
 struct usbd_bus {
        /* Filled by HC driver */
@@ -164,7 +167,7 @@
        struct usbd_device     *ub_roothub;
        uint8_t                 ub_rhaddr;      /* roothub address */
        uint8_t                 ub_rhconf;      /* roothub configuration */
-       struct usbd_device     *ub_devices[USB_MAX_DEVICES];
+       struct usbd_device     *ub_devices[USB_TOTAL_DEVICES];
        kcondvar_t              ub_needsexplore_cv;
        char                    ub_needsexplore;/* a hub a signalled a change */
        char                    ub_usepolling;
@@ -352,6 +355,13 @@
           UE_DIR_IN;
 }
 
+static inline size_t
+usb_addr2dindex(int addr)
+{
+
+       return USB_ROOTHUB_INDEX + addr;



Home | Main Index | Thread Index | Old Index