Source-Changes-HG archive

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

[src/netbsd-7]: src/sys/dev/usb Pull up following revision(s) (requested by s...



details:   https://anonhg.NetBSD.org/src/rev/49c79e028da9
branches:  netbsd-7
changeset: 799780:49c79e028da9
user:      snj <snj%NetBSD.org@localhost>
date:      Sat Feb 06 20:58:13 2016 +0000

description:
Pull up following revision(s) (requested by skrll in ticket #1097):
        sys/dev/usb/usb.c: revision 1.161
        sys/dev/usb/usb_subr.c: revisions 1.207, 1.208
        sys/dev/usb/usbdivar.h: revision 1.111
        sys/dev/usb/xhci.c: revision 1.33
Get the iManufacturer, iProduct, and iSerialNumber strings before probing
for drivers and cache them for later use.  This reduces bus transactions
and fixes attachment for at least two of my umass(4)s.
--
Need sys/kmem.h

diffstat:

 sys/dev/usb/usb.c      |   6 +-
 sys/dev/usb/usb_subr.c |  84 +++++++++++++++++++++++++++++++++++++++----------
 sys/dev/usb/usbdivar.h |   7 +++-
 sys/dev/usb/xhci.c     |   6 ++-
 4 files changed, 79 insertions(+), 24 deletions(-)

diffs (238 lines):

diff -r fd114598756f -r 49c79e028da9 sys/dev/usb/usb.c
--- a/sys/dev/usb/usb.c Sat Feb 06 20:52:36 2016 +0000
+++ b/sys/dev/usb/usb.c Sat Feb 06 20:58:13 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.c,v 1.154 2014/07/25 08:10:39 dholland Exp $       */
+/*     $NetBSD: usb.c,v 1.154.2.1 2016/02/06 20:58:13 snj 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.154 2014/07/25 08:10:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.154.2.1 2016/02/06 20:58:13 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -899,7 +899,7 @@
 {
        struct usb_event *ue = usb_alloc_event();
 
-       usbd_fill_deviceinfo(udev, &ue->u.ue_device, USB_EVENT_IS_ATTACH(type));
+       usbd_fill_deviceinfo(udev, &ue->u.ue_device, false);
        usb_add_event(type, ue);
 }
 
diff -r fd114598756f -r 49c79e028da9 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c    Sat Feb 06 20:52:36 2016 +0000
+++ b/sys/dev/usb/usb_subr.c    Sat Feb 06 20:58:13 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_subr.c,v 1.196.4.1 2015/11/16 14:45:03 msaitoh Exp $       */
+/*     $NetBSD: usb_subr.c,v 1.196.4.2 2016/02/06 20:58:13 snj 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.196.4.1 2015/11/16 14:45:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.196.4.2 2016/02/06 20:58:13 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -42,6 +42,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
+#include <sys/kmem.h>
 #include <sys/malloc.h>
 #include <sys/device.h>
 #include <sys/select.h>
@@ -206,6 +207,33 @@
        *e = '\0';                      /* kill trailing spaces */
 }
 
+static void
+usbd_get_device_string(struct usbd_device *ud, uByte index, char **buf)
+{
+       char *b = kmem_alloc(USB_MAX_ENCODED_STRING_LEN, KM_SLEEP);
+       if (b) {
+               usbd_status err = usbd_get_string0(ud, index, b, true);
+               if (err != USBD_NORMAL_COMPLETION) {
+                       kmem_free(b, USB_MAX_ENCODED_STRING_LEN);
+                       b = NULL;
+               } else {
+                       usbd_trim_spaces(b);
+               }
+       }
+       *buf = b;
+}
+
+void
+usbd_get_device_strings(struct usbd_device *ud)
+{
+       usb_device_descriptor_t *udd = &ud->ddesc;
+
+       usbd_get_device_string(ud, udd->iManufacturer, &ud->ud_vendor);
+       usbd_get_device_string(ud, udd->iProduct, &ud->ud_product);
+       usbd_get_device_string(ud, udd->iSerialNumber, &ud->ud_serial);
+}
+
+
 Static void
 usbd_devinfo_vp(usbd_device_handle dev, char *v, size_t vl, char *p,
     size_t pl, int usedev, int useencoded)
@@ -223,6 +251,13 @@
                if (usbd_get_string0(dev, udd->iProduct, p, useencoded) ==
                    USBD_NORMAL_COMPLETION)
                        usbd_trim_spaces(p);
+       } else {
+               if (dev->ud_vendor) {
+                       strlcpy(v, dev->ud_vendor, vl);
+               }
+               if (dev->ud_product) {
+                       strlcpy(p, dev->ud_product, pl);
+               }
        }
        if (v[0] == '\0')
                get_usb_vendor(v, vl, UGETW(udd->idVendor));
@@ -260,7 +295,7 @@
        ep = cp + l;
 
        usbd_devinfo_vp(dev, vendor, USB_MAX_ENCODED_STRING_LEN,
-           product, USB_MAX_ENCODED_STRING_LEN, 1, 1);
+           product, USB_MAX_ENCODED_STRING_LEN, 0, 1);
        cp += snprintf(cp, ep - cp, "%s %s", vendor, product);
        if (showclass)
                cp += snprintf(cp, ep - cp, ", class %d/%d",
@@ -831,19 +866,10 @@
 static void
 usbd_serialnumber(device_t dv, usbd_device_handle dev)
 {
-       usb_device_descriptor_t *dd = &dev->ddesc;
-       char *serialnumber;
-
-       serialnumber = malloc(USB_MAX_ENCODED_STRING_LEN, M_USB, M_NOWAIT);
-       if (serialnumber == NULL)
-               return;
-       serialnumber[0] = '\0';
-       (void)usbd_get_string(dev, dd->iSerialNumber, serialnumber);
-       if (serialnumber[0]) {
+       if (dev->ud_serial) {
                prop_dictionary_set_cstring(device_properties(dv),
-                   "serialnumber", serialnumber);
+                   "serialnumber", dev->ud_serial);
        }
-       free(serialnumber, M_USB);
 }
 
 static usbd_status
@@ -1309,6 +1335,8 @@
        DPRINTF(("usbd_new_device: new dev (addr %d), dev=%p, parent=%p\n",
                 addr, dev, parent));
 
+       usbd_get_device_strings(dev);
+
        usbd_add_dev_event(USB_EVENT_DEVICE_ATTACH, dev);
 
        if (port == 0) { /* root hub */
@@ -1430,10 +1458,21 @@
            di->udi_product, sizeof(di->udi_product), usedev, 1);
        usbd_printBCD(di->udi_release, sizeof(di->udi_release),
            UGETW(dev->ddesc.bcdDevice));
-       di->udi_serial[0] = 0;
-       if (usedev)
-               (void)usbd_get_string(dev, dev->ddesc.iSerialNumber,
-                                     di->udi_serial);
+       if (usedev) {
+               usbd_status uerr = usbd_get_string(dev,
+                   dev->ddesc.iSerialNumber, di->udi_serial);
+               if (uerr != USBD_NORMAL_COMPLETION) {
+                       di->udi_serial[0] = '\0';
+               } else {
+                       usbd_trim_spaces(di->udi_serial);
+               }
+       } else {
+               di->udi_serial[0] = '\0';
+               if (dev->ud_serial) {
+                       strlcpy(di->udi_serial, dev->ud_serial,
+                           sizeof(di->udi_serial));
+               }
+       }
        di->udi_vendorNo = UGETW(dev->ddesc.idVendor);
        di->udi_productNo = UGETW(dev->ddesc.idProduct);
        di->udi_releaseNo = UGETW(dev->ddesc.bcdDevice);
@@ -1574,6 +1613,15 @@
                free(dev->subdevs, M_USB);
                dev->subdevlen = 0;
        }
+       if (dev->ud_vendor) {
+               kmem_free(dev->ud_vendor, USB_MAX_ENCODED_STRING_LEN);
+       }
+       if (dev->ud_product) {
+               kmem_free(dev->ud_product, USB_MAX_ENCODED_STRING_LEN);
+       }
+       if (dev->ud_serial) {
+               kmem_free(dev->ud_serial, USB_MAX_ENCODED_STRING_LEN);
+       }
        free(dev, M_USB);
 }
 
diff -r fd114598756f -r 49c79e028da9 sys/dev/usb/usbdivar.h
--- a/sys/dev/usb/usbdivar.h    Sat Feb 06 20:52:36 2016 +0000
+++ b/sys/dev/usb/usbdivar.h    Sat Feb 06 20:58:13 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdivar.h,v 1.107 2013/10/03 19:04:00 skrll Exp $     */
+/*     $NetBSD: usbdivar.h,v 1.107.4.1 2016/02/06 20:58:13 snj Exp $   */
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -196,6 +196,10 @@
        device_t               *subdevs;       /* sub-devices */
        int                     nifaces_claimed; /* number of ifaces in use */
        void                   *hci_private;
+
+       char                   *ud_serial;      /* serial number, can be NULL */
+       char                   *ud_vendor;      /* vendor string, can be NULL */
+       char                   *ud_product;     /* product string can be NULL */
 };
 
 struct usbd_interface {
@@ -285,6 +289,7 @@
 
 /* Routines from usb_subr.c */
 int            usbctlprint(void *, const char *);
+void           usbd_get_device_strings(struct usbd_device *);
 void           usb_delay_ms_locked(usbd_bus_handle, u_int, kmutex_t *);
 void           usb_delay_ms(usbd_bus_handle, u_int);
 void           usbd_delay_ms_locked(usbd_device_handle, u_int, kmutex_t *);
diff -r fd114598756f -r 49c79e028da9 sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Sat Feb 06 20:52:36 2016 +0000
+++ b/sys/dev/usb/xhci.c        Sat Feb 06 20:58:13 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.23.2.3 2015/01/02 22:44:34 martin Exp $     */
+/*     $NetBSD: xhci.c,v 1.23.2.4 2016/02/06 20:58:13 snj Exp $        */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.23.2.3 2015/01/02 22:44:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.23.2.4 2016/02/06 20:58:13 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1562,6 +1562,8 @@
                 dd->bMaxPacketSize, dd->bLength, dd->bNumConfigurations,
                 dev->speed));
 
+       usbd_get_device_strings(dev);
+
        usbd_add_dev_event(USB_EVENT_DEVICE_ATTACH, dev);
 
        if ((depth == 0) && (port == 0)) {



Home | Main Index | Thread Index | Old Index