diff --git a/sys/dev/usb/controller/usb_controller.c b/sys/dev/usb/controller/usb_controller.c index 959f54a4583f..783c9c32dab2 100644 --- a/sys/dev/usb/controller/usb_controller.c +++ b/sys/dev/usb/controller/usb_controller.c @@ -1,1037 +1,1037 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef USB_GLOBAL_INCLUDE_FILE #include USB_GLOBAL_INCLUDE_FILE #else #include "opt_ddb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define USB_DEBUG_VAR usb_ctrl_debug #include #include #include #include #include #include #include #include #include #include #include #include "usb_if.h" #endif /* USB_GLOBAL_INCLUDE_FILE */ /* function prototypes */ static device_probe_t usb_probe; static device_attach_t usb_attach; static device_detach_t usb_detach; static device_suspend_t usb_suspend; static device_resume_t usb_resume; static device_shutdown_t usb_shutdown; static void usb_attach_sub(device_t, struct usb_bus *); /* static variables */ #ifdef USB_DEBUG static int usb_ctrl_debug = 0; static SYSCTL_NODE(_hw_usb, OID_AUTO, ctrl, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "USB controller"); SYSCTL_INT(_hw_usb_ctrl, OID_AUTO, debug, CTLFLAG_RWTUN, &usb_ctrl_debug, 0, "Debug level"); #endif #if USB_HAVE_ROOT_MOUNT_HOLD static int usb_no_boot_wait = 0; SYSCTL_INT(_hw_usb, OID_AUTO, no_boot_wait, CTLFLAG_RDTUN, &usb_no_boot_wait, 0, "No USB device enumerate waiting at boot."); #endif static int usb_no_suspend_wait = 0; SYSCTL_INT(_hw_usb, OID_AUTO, no_suspend_wait, CTLFLAG_RWTUN, &usb_no_suspend_wait, 0, "No USB device waiting at system suspend."); static int usb_no_shutdown_wait = 0; SYSCTL_INT(_hw_usb, OID_AUTO, no_shutdown_wait, CTLFLAG_RWTUN, &usb_no_shutdown_wait, 0, "No USB device waiting at system shutdown."); static device_method_t usb_methods[] = { DEVMETHOD(device_probe, usb_probe), DEVMETHOD(device_attach, usb_attach), DEVMETHOD(device_detach, usb_detach), DEVMETHOD(device_suspend, usb_suspend), DEVMETHOD(device_resume, usb_resume), DEVMETHOD(device_shutdown, usb_shutdown), DEVMETHOD_END }; static driver_t usb_driver = { .name = "usbus", .methods = usb_methods, .size = 0, }; /* Host Only Drivers */ DRIVER_MODULE(usbus, ohci, usb_driver, 0, 0); DRIVER_MODULE(usbus, uhci, usb_driver, 0, 0); DRIVER_MODULE(usbus, ehci, usb_driver, 0, 0); DRIVER_MODULE(usbus, xhci, usb_driver, 0, 0); /* Device Only Drivers */ DRIVER_MODULE(usbus, musbotg, usb_driver, 0, 0); DRIVER_MODULE(usbus, uss820dci, usb_driver, 0, 0); DRIVER_MODULE(usbus, octusb, usb_driver, 0, 0); /* Dual Mode Drivers */ DRIVER_MODULE(usbus, dwcotg, usb_driver, 0, 0); DRIVER_MODULE(usbus, saf1761otg, usb_driver, 0, 0); /*------------------------------------------------------------------------* * usb_probe * * This function is called from "{ehci,ohci,uhci}_pci_attach()". *------------------------------------------------------------------------*/ static int usb_probe(device_t dev) { DPRINTF("\n"); return (0); } #if USB_HAVE_ROOT_MOUNT_HOLD static void usb_root_mount_rel(struct usb_bus *bus) { if (bus->bus_roothold != NULL) { DPRINTF("Releasing root mount hold %p\n", bus->bus_roothold); root_mount_rel(bus->bus_roothold); bus->bus_roothold = NULL; } } #endif /*------------------------------------------------------------------------* * usb_attach *------------------------------------------------------------------------*/ static int usb_attach(device_t dev) { struct usb_bus *bus = device_get_ivars(dev); DPRINTF("\n"); if (bus == NULL) { device_printf(dev, "USB device has no ivars\n"); return (ENXIO); } #if USB_HAVE_ROOT_MOUNT_HOLD if (usb_no_boot_wait == 0) { /* delay vfs_mountroot until the bus is explored */ bus->bus_roothold = root_mount_hold(device_get_nameunit(dev)); } #endif usb_attach_sub(dev, bus); return (0); /* return success */ } /*------------------------------------------------------------------------* * usb_detach *------------------------------------------------------------------------*/ static int usb_detach(device_t dev) { struct usb_bus *bus = device_get_softc(dev); DPRINTF("\n"); if (bus == NULL) { /* was never setup properly */ return (0); } /* Stop power watchdog */ usb_callout_drain(&bus->power_wdog); #if USB_HAVE_ROOT_MOUNT_HOLD /* Let the USB explore process detach all devices. */ usb_root_mount_rel(bus); #endif USB_BUS_LOCK(bus); /* Queue detach job */ usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->detach_msg[0], &bus->detach_msg[1]); /* Wait for detach to complete */ usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->detach_msg[0], &bus->detach_msg[1]); #if USB_HAVE_UGEN /* Wait for cleanup to complete */ usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->cleanup_msg[0], &bus->cleanup_msg[1]); #endif USB_BUS_UNLOCK(bus); #if USB_HAVE_PER_BUS_PROCESS /* Get rid of USB callback processes */ usb_proc_free(USB_BUS_GIANT_PROC(bus)); usb_proc_free(USB_BUS_NON_GIANT_ISOC_PROC(bus)); usb_proc_free(USB_BUS_NON_GIANT_BULK_PROC(bus)); /* Get rid of USB explore process */ usb_proc_free(USB_BUS_EXPLORE_PROC(bus)); /* Get rid of control transfer process */ usb_proc_free(USB_BUS_CONTROL_XFER_PROC(bus)); #endif #if USB_HAVE_PF usbpf_detach(bus); #endif return (0); } /*------------------------------------------------------------------------* * usb_suspend *------------------------------------------------------------------------*/ static int usb_suspend(device_t dev) { struct usb_bus *bus = device_get_softc(dev); DPRINTF("\n"); if (bus == NULL) { /* was never setup properly */ return (0); } USB_BUS_LOCK(bus); usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->suspend_msg[0], &bus->suspend_msg[1]); if (usb_no_suspend_wait == 0) { /* wait for suspend callback to be executed */ usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->suspend_msg[0], &bus->suspend_msg[1]); } USB_BUS_UNLOCK(bus); return (0); } /*------------------------------------------------------------------------* * usb_resume *------------------------------------------------------------------------*/ static int usb_resume(device_t dev) { struct usb_bus *bus = device_get_softc(dev); DPRINTF("\n"); if (bus == NULL) { /* was never setup properly */ return (0); } USB_BUS_LOCK(bus); usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->resume_msg[0], &bus->resume_msg[1]); USB_BUS_UNLOCK(bus); return (0); } /*------------------------------------------------------------------------* * usb_bus_reset_async_locked *------------------------------------------------------------------------*/ void usb_bus_reset_async_locked(struct usb_bus *bus) { USB_BUS_LOCK_ASSERT(bus, MA_OWNED); DPRINTF("\n"); if (bus->reset_msg[0].hdr.pm_qentry.tqe_prev != NULL || bus->reset_msg[1].hdr.pm_qentry.tqe_prev != NULL) { DPRINTF("Reset already pending\n"); return; } device_printf(bus->parent, "Resetting controller\n"); usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->reset_msg[0], &bus->reset_msg[1]); } /*------------------------------------------------------------------------* * usb_shutdown *------------------------------------------------------------------------*/ static int usb_shutdown(device_t dev) { struct usb_bus *bus = device_get_softc(dev); DPRINTF("\n"); if (bus == NULL) { /* was never setup properly */ return (0); } DPRINTF("%s: Controller shutdown\n", device_get_nameunit(bus->bdev)); USB_BUS_LOCK(bus); usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->shutdown_msg[0], &bus->shutdown_msg[1]); if (usb_no_shutdown_wait == 0) { /* wait for shutdown callback to be executed */ usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->shutdown_msg[0], &bus->shutdown_msg[1]); } USB_BUS_UNLOCK(bus); DPRINTF("%s: Controller shutdown complete\n", device_get_nameunit(bus->bdev)); return (0); } /*------------------------------------------------------------------------* * usb_bus_explore * * This function is used to explore the device tree from the root. *------------------------------------------------------------------------*/ static void usb_bus_explore(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *udev; bus = ((struct usb_bus_msg *)pm)->bus; udev = bus->devices[USB_ROOT_HUB_ADDR]; if (bus->no_explore != 0) return; if (udev != NULL) { USB_BUS_UNLOCK(bus); uhub_explore_handle_re_enumerate(udev); USB_BUS_LOCK(bus); } if (udev != NULL && udev->hub != NULL) { if (bus->do_probe) { bus->do_probe = 0; bus->driver_added_refcount++; } if (bus->driver_added_refcount == 0) { /* avoid zero, hence that is memory default */ bus->driver_added_refcount = 1; } #ifdef DDB /* * The following three lines of code are only here to * recover from DDB: */ usb_proc_rewakeup(USB_BUS_CONTROL_XFER_PROC(bus)); usb_proc_rewakeup(USB_BUS_GIANT_PROC(bus)); usb_proc_rewakeup(USB_BUS_NON_GIANT_ISOC_PROC(bus)); usb_proc_rewakeup(USB_BUS_NON_GIANT_BULK_PROC(bus)); #endif USB_BUS_UNLOCK(bus); #if USB_HAVE_POWERD /* * First update the USB power state! */ usb_bus_powerd(bus); #endif /* Explore the Root USB HUB. */ (udev->hub->explore) (udev); USB_BUS_LOCK(bus); } #if USB_HAVE_ROOT_MOUNT_HOLD usb_root_mount_rel(bus); #endif /* Nice the enumeration a bit, to avoid looping too fast. */ - usb_pause_mtx(&bus->bus_mtx, USB_MS_TO_TICKS(16)); + usb_pause_mtx(&bus->bus_mtx, USB_MS_TO_TICKS(usb_enum_nice_time)); } /*------------------------------------------------------------------------* * usb_bus_detach * * This function is used to detach the device tree from the root. *------------------------------------------------------------------------*/ static void usb_bus_detach(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *udev; device_t dev; bus = ((struct usb_bus_msg *)pm)->bus; udev = bus->devices[USB_ROOT_HUB_ADDR]; dev = bus->bdev; /* clear the softc */ device_set_softc(dev, NULL); USB_BUS_UNLOCK(bus); /* detach children first */ bus_topo_lock(); bus_generic_detach(dev); bus_topo_unlock(); /* * Free USB device and all subdevices, if any. */ usb_free_device(udev, 0); USB_BUS_LOCK(bus); /* clear bdev variable last */ bus->bdev = NULL; } /*------------------------------------------------------------------------* * usb_bus_suspend * * This function is used to suspend the USB controller. *------------------------------------------------------------------------*/ static void usb_bus_suspend(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *udev; usb_error_t err; uint8_t do_unlock; DPRINTF("\n"); bus = ((struct usb_bus_msg *)pm)->bus; udev = bus->devices[USB_ROOT_HUB_ADDR]; if (udev == NULL || bus->bdev == NULL) return; USB_BUS_UNLOCK(bus); /* * We use the shutdown event here because the suspend and * resume events are reserved for the USB port suspend and * resume. The USB system suspend is implemented like full * shutdown and all connected USB devices will be disconnected * subsequently. At resume all USB devices will be * re-connected again. */ bus_generic_shutdown(bus->bdev); do_unlock = usbd_enum_lock(udev); err = usbd_set_config_index(udev, USB_UNCONFIG_INDEX); if (err) device_printf(bus->bdev, "Could not unconfigure root HUB\n"); USB_BUS_LOCK(bus); bus->hw_power_state = 0; bus->no_explore = 1; USB_BUS_UNLOCK(bus); if (bus->methods->set_hw_power != NULL) (bus->methods->set_hw_power) (bus); if (bus->methods->set_hw_power_sleep != NULL) (bus->methods->set_hw_power_sleep) (bus, USB_HW_POWER_SUSPEND); if (do_unlock) usbd_enum_unlock(udev); USB_BUS_LOCK(bus); } /*------------------------------------------------------------------------* * usb_bus_resume * * This function is used to resume the USB controller. *------------------------------------------------------------------------*/ static void usb_bus_resume(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *udev; usb_error_t err; uint8_t do_unlock; DPRINTF("\n"); bus = ((struct usb_bus_msg *)pm)->bus; udev = bus->devices[USB_ROOT_HUB_ADDR]; if (udev == NULL || bus->bdev == NULL) return; USB_BUS_UNLOCK(bus); do_unlock = usbd_enum_lock(udev); #if 0 DEVMETHOD(usb_take_controller, NULL); /* dummy */ #endif USB_TAKE_CONTROLLER(device_get_parent(bus->bdev)); USB_BUS_LOCK(bus); bus->hw_power_state = USB_HW_POWER_CONTROL | USB_HW_POWER_BULK | USB_HW_POWER_INTERRUPT | USB_HW_POWER_ISOC | USB_HW_POWER_NON_ROOT_HUB; bus->no_explore = 0; USB_BUS_UNLOCK(bus); if (bus->methods->set_hw_power_sleep != NULL) (bus->methods->set_hw_power_sleep) (bus, USB_HW_POWER_RESUME); if (bus->methods->set_hw_power != NULL) (bus->methods->set_hw_power) (bus); /* restore USB configuration to index 0 */ err = usbd_set_config_index(udev, 0); if (err) device_printf(bus->bdev, "Could not configure root HUB\n"); /* probe and attach */ err = usb_probe_and_attach(udev, USB_IFACE_INDEX_ANY); if (err) { device_printf(bus->bdev, "Could not probe and " "attach root HUB\n"); } if (do_unlock) usbd_enum_unlock(udev); USB_BUS_LOCK(bus); } /*------------------------------------------------------------------------* * usb_bus_reset * * This function is used to reset the USB controller. *------------------------------------------------------------------------*/ static void usb_bus_reset(struct usb_proc_msg *pm) { struct usb_bus *bus; DPRINTF("\n"); bus = ((struct usb_bus_msg *)pm)->bus; if (bus->bdev == NULL || bus->no_explore != 0) return; /* a suspend and resume will reset the USB controller */ usb_bus_suspend(pm); usb_bus_resume(pm); } /*------------------------------------------------------------------------* * usb_bus_shutdown * * This function is used to shutdown the USB controller. *------------------------------------------------------------------------*/ static void usb_bus_shutdown(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *udev; usb_error_t err; uint8_t do_unlock; bus = ((struct usb_bus_msg *)pm)->bus; udev = bus->devices[USB_ROOT_HUB_ADDR]; if (udev == NULL || bus->bdev == NULL) return; USB_BUS_UNLOCK(bus); bus_generic_shutdown(bus->bdev); do_unlock = usbd_enum_lock(udev); err = usbd_set_config_index(udev, USB_UNCONFIG_INDEX); if (err) device_printf(bus->bdev, "Could not unconfigure root HUB\n"); USB_BUS_LOCK(bus); bus->hw_power_state = 0; bus->no_explore = 1; USB_BUS_UNLOCK(bus); if (bus->methods->set_hw_power != NULL) (bus->methods->set_hw_power) (bus); if (bus->methods->set_hw_power_sleep != NULL) (bus->methods->set_hw_power_sleep) (bus, USB_HW_POWER_SHUTDOWN); if (do_unlock) usbd_enum_unlock(udev); USB_BUS_LOCK(bus); } /*------------------------------------------------------------------------* * usb_bus_cleanup * * This function is used to cleanup leftover USB character devices. *------------------------------------------------------------------------*/ #if USB_HAVE_UGEN static void usb_bus_cleanup(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_fs_privdata *pd; bus = ((struct usb_bus_msg *)pm)->bus; while ((pd = LIST_FIRST(&bus->pd_cleanup_list)) != NULL) { LIST_REMOVE(pd, pd_next); USB_BUS_UNLOCK(bus); usb_destroy_dev_sync(pd); USB_BUS_LOCK(bus); } } #endif static void usb_power_wdog(void *arg) { struct usb_bus *bus = arg; USB_BUS_LOCK_ASSERT(bus, MA_OWNED); usb_callout_reset(&bus->power_wdog, 4 * hz, usb_power_wdog, arg); #ifdef DDB /* * The following line of code is only here to recover from * DDB: */ usb_proc_rewakeup(USB_BUS_EXPLORE_PROC(bus)); /* recover from DDB */ #endif #if USB_HAVE_POWERD USB_BUS_UNLOCK(bus); usb_bus_power_update(bus); USB_BUS_LOCK(bus); #endif } /*------------------------------------------------------------------------* * usb_bus_attach * * This function attaches USB in context of the explore thread. *------------------------------------------------------------------------*/ static void usb_bus_attach(struct usb_proc_msg *pm) { struct usb_bus *bus; struct usb_device *child; device_t dev; usb_error_t err; enum usb_dev_speed speed; bus = ((struct usb_bus_msg *)pm)->bus; dev = bus->bdev; DPRINTF("\n"); switch (bus->usbrev) { case USB_REV_1_0: speed = USB_SPEED_FULL; device_printf(bus->bdev, "12Mbps Full Speed USB v1.0\n"); break; case USB_REV_1_1: speed = USB_SPEED_FULL; device_printf(bus->bdev, "12Mbps Full Speed USB v1.1\n"); break; case USB_REV_2_0: speed = USB_SPEED_HIGH; device_printf(bus->bdev, "480Mbps High Speed USB v2.0\n"); break; case USB_REV_2_5: speed = USB_SPEED_VARIABLE; device_printf(bus->bdev, "480Mbps Wireless USB v2.5\n"); break; case USB_REV_3_0: speed = USB_SPEED_SUPER; device_printf(bus->bdev, "5.0Gbps Super Speed USB v3.0\n"); break; default: device_printf(bus->bdev, "Unsupported USB revision\n"); #if USB_HAVE_ROOT_MOUNT_HOLD usb_root_mount_rel(bus); #endif return; } /* default power_mask value */ bus->hw_power_state = USB_HW_POWER_CONTROL | USB_HW_POWER_BULK | USB_HW_POWER_INTERRUPT | USB_HW_POWER_ISOC | USB_HW_POWER_NON_ROOT_HUB; USB_BUS_UNLOCK(bus); /* make sure power is set at least once */ if (bus->methods->set_hw_power != NULL) { (bus->methods->set_hw_power) (bus); } /* allocate the Root USB device */ child = usb_alloc_device(bus->bdev, bus, NULL, 0, 0, 1, speed, USB_MODE_HOST); if (child) { err = usb_probe_and_attach(child, USB_IFACE_INDEX_ANY); if (!err) { if ((bus->devices[USB_ROOT_HUB_ADDR] == NULL) || (bus->devices[USB_ROOT_HUB_ADDR]->hub == NULL)) { err = USB_ERR_NO_ROOT_HUB; } } } else { err = USB_ERR_NOMEM; } USB_BUS_LOCK(bus); if (err) { device_printf(bus->bdev, "Root HUB problem, error=%s\n", usbd_errstr(err)); #if USB_HAVE_ROOT_MOUNT_HOLD usb_root_mount_rel(bus); #endif } /* set softc - we are ready */ device_set_softc(dev, bus); /* start watchdog */ usb_power_wdog(bus); } /*------------------------------------------------------------------------* * usb_attach_sub * * This function creates a thread which runs the USB attach code. *------------------------------------------------------------------------*/ static void usb_attach_sub(device_t dev, struct usb_bus *bus) { bus_topo_lock(); if (usb_devclass_ptr == NULL) usb_devclass_ptr = devclass_find("usbus"); bus_topo_unlock(); #if USB_HAVE_PF usbpf_attach(bus); #endif /* Initialise USB process messages */ bus->explore_msg[0].hdr.pm_callback = &usb_bus_explore; bus->explore_msg[0].bus = bus; bus->explore_msg[1].hdr.pm_callback = &usb_bus_explore; bus->explore_msg[1].bus = bus; bus->detach_msg[0].hdr.pm_callback = &usb_bus_detach; bus->detach_msg[0].bus = bus; bus->detach_msg[1].hdr.pm_callback = &usb_bus_detach; bus->detach_msg[1].bus = bus; bus->attach_msg[0].hdr.pm_callback = &usb_bus_attach; bus->attach_msg[0].bus = bus; bus->attach_msg[1].hdr.pm_callback = &usb_bus_attach; bus->attach_msg[1].bus = bus; bus->suspend_msg[0].hdr.pm_callback = &usb_bus_suspend; bus->suspend_msg[0].bus = bus; bus->suspend_msg[1].hdr.pm_callback = &usb_bus_suspend; bus->suspend_msg[1].bus = bus; bus->resume_msg[0].hdr.pm_callback = &usb_bus_resume; bus->resume_msg[0].bus = bus; bus->resume_msg[1].hdr.pm_callback = &usb_bus_resume; bus->resume_msg[1].bus = bus; bus->reset_msg[0].hdr.pm_callback = &usb_bus_reset; bus->reset_msg[0].bus = bus; bus->reset_msg[1].hdr.pm_callback = &usb_bus_reset; bus->reset_msg[1].bus = bus; bus->shutdown_msg[0].hdr.pm_callback = &usb_bus_shutdown; bus->shutdown_msg[0].bus = bus; bus->shutdown_msg[1].hdr.pm_callback = &usb_bus_shutdown; bus->shutdown_msg[1].bus = bus; #if USB_HAVE_UGEN LIST_INIT(&bus->pd_cleanup_list); bus->cleanup_msg[0].hdr.pm_callback = &usb_bus_cleanup; bus->cleanup_msg[0].bus = bus; bus->cleanup_msg[1].hdr.pm_callback = &usb_bus_cleanup; bus->cleanup_msg[1].bus = bus; #endif #if USB_HAVE_PER_BUS_PROCESS /* Create USB explore and callback processes */ if (usb_proc_create(USB_BUS_GIANT_PROC(bus), &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB Giant " "callback process failed.\n"); } else if (usb_proc_create(USB_BUS_NON_GIANT_ISOC_PROC(bus), &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_HIGHEST)) { device_printf(dev, "WARNING: Creation of USB non-Giant ISOC " "callback process failed.\n"); } else if (usb_proc_create(USB_BUS_NON_GIANT_BULK_PROC(bus), &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_HIGH)) { device_printf(dev, "WARNING: Creation of USB non-Giant BULK " "callback process failed.\n"); } else if (usb_proc_create(USB_BUS_EXPLORE_PROC(bus), &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB explore " "process failed.\n"); } else if (usb_proc_create(USB_BUS_CONTROL_XFER_PROC(bus), &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB control transfer " "process failed.\n"); } else #endif { /* Get final attach going */ USB_BUS_LOCK(bus); usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->attach_msg[0], &bus->attach_msg[1]); USB_BUS_UNLOCK(bus); /* Do initial explore */ usb_needs_explore(bus, 1); } } SYSUNINIT(usb_bus_unload, SI_SUB_KLD, SI_ORDER_ANY, usb_bus_unload, NULL); /*------------------------------------------------------------------------* * usb_bus_mem_flush_all_cb *------------------------------------------------------------------------*/ #if USB_HAVE_BUSDMA static void usb_bus_mem_flush_all_cb(struct usb_bus *bus, struct usb_page_cache *pc, struct usb_page *pg, usb_size_t size, usb_size_t align) { usb_pc_cpu_flush(pc); } #endif /*------------------------------------------------------------------------* * usb_bus_mem_flush_all - factored out code *------------------------------------------------------------------------*/ #if USB_HAVE_BUSDMA void usb_bus_mem_flush_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb) { if (cb) { cb(bus, &usb_bus_mem_flush_all_cb); } } #endif /*------------------------------------------------------------------------* * usb_bus_mem_alloc_all_cb *------------------------------------------------------------------------*/ #if USB_HAVE_BUSDMA static void usb_bus_mem_alloc_all_cb(struct usb_bus *bus, struct usb_page_cache *pc, struct usb_page *pg, usb_size_t size, usb_size_t align) { /* need to initialize the page cache */ pc->tag_parent = bus->dma_parent_tag; if (usb_pc_alloc_mem(pc, pg, size, align)) { bus->alloc_failed = 1; } } #endif /*------------------------------------------------------------------------* * usb_bus_mem_alloc_all - factored out code * * Returns: * 0: Success * Else: Failure *------------------------------------------------------------------------*/ uint8_t usb_bus_mem_alloc_all(struct usb_bus *bus, bus_dma_tag_t dmat, usb_bus_mem_cb_t *cb) { bus->alloc_failed = 0; mtx_init(&bus->bus_mtx, device_get_nameunit(bus->parent), "usb_def_mtx", MTX_DEF | MTX_RECURSE); mtx_init(&bus->bus_spin_lock, device_get_nameunit(bus->parent), "usb_spin_mtx", MTX_SPIN | MTX_RECURSE); usb_callout_init_mtx(&bus->power_wdog, &bus->bus_mtx, 0); TAILQ_INIT(&bus->intr_q.head); #if USB_HAVE_BUSDMA usb_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags, dmat, &bus->bus_mtx, NULL, bus->dma_bits, USB_BUS_DMA_TAG_MAX); #endif if ((bus->devices_max > USB_MAX_DEVICES) || (bus->devices_max < USB_MIN_DEVICES) || (bus->devices == NULL)) { DPRINTFN(0, "Devices field has not been " "initialised properly\n"); bus->alloc_failed = 1; /* failure */ } #if USB_HAVE_BUSDMA if (cb) { cb(bus, &usb_bus_mem_alloc_all_cb); } #endif if (bus->alloc_failed) { usb_bus_mem_free_all(bus, cb); } return (bus->alloc_failed); } /*------------------------------------------------------------------------* * usb_bus_mem_free_all_cb *------------------------------------------------------------------------*/ #if USB_HAVE_BUSDMA static void usb_bus_mem_free_all_cb(struct usb_bus *bus, struct usb_page_cache *pc, struct usb_page *pg, usb_size_t size, usb_size_t align) { usb_pc_free_mem(pc); } #endif /*------------------------------------------------------------------------* * usb_bus_mem_free_all - factored out code *------------------------------------------------------------------------*/ void usb_bus_mem_free_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb) { #if USB_HAVE_BUSDMA if (cb) { cb(bus, &usb_bus_mem_free_all_cb); } usb_dma_tag_unsetup(bus->dma_parent_tag); #endif mtx_destroy(&bus->bus_mtx); mtx_destroy(&bus->bus_spin_lock); } /* convenience wrappers */ void usb_proc_explore_mwait(struct usb_device *udev, void *pm1, void *pm2) { usb_proc_mwait(USB_BUS_EXPLORE_PROC(udev->bus), pm1, pm2); } void * usb_proc_explore_msignal(struct usb_device *udev, void *pm1, void *pm2) { return (usb_proc_msignal(USB_BUS_EXPLORE_PROC(udev->bus), pm1, pm2)); } void usb_proc_explore_lock(struct usb_device *udev) { USB_BUS_LOCK(udev->bus); } void usb_proc_explore_unlock(struct usb_device *udev) { USB_BUS_UNLOCK(udev->bus); } diff --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h index ad0381366f98..0bef7a10bc6c 100644 --- a/sys/dev/usb/usb.h +++ b/sys/dev/usb/usb.h @@ -1,810 +1,811 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. * Copyright (c) 1998 Lennart Augustsson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This file contains standard definitions for the following USB * protocol versions: * * USB v1.0 * USB v1.1 * USB v2.0 * USB v3.0 */ #ifndef _USB_STANDARD_H_ #define _USB_STANDARD_H_ #if defined(_KERNEL) || defined(_STANDALONE) #ifndef USB_GLOBAL_INCLUDE_FILE #include "opt_usb.h" #endif /* Declare parent SYSCTL USB node. */ #ifdef SYSCTL_DECL SYSCTL_DECL(_hw_usb); #endif #ifndef USB_GLOBAL_INCLUDE_FILE #include #endif MALLOC_DECLARE(M_USB); MALLOC_DECLARE(M_USBDEV); #endif /* _KERNEL || _STANDALONE */ #ifndef USB_GLOBAL_INCLUDE_FILE #include #include #endif #define USB_STACK_VERSION 2000 /* 2.0 */ /* Definition of some hardcoded USB constants. */ #define USB_MAX_IPACKET 8 /* initial USB packet size */ #define USB_EP_MAX (2*16) /* hardcoded */ #define USB_ROOT_HUB_ADDR 1 /* index */ #define USB_MIN_DEVICES 2 /* unused + root HUB */ #define USB_UNCONFIG_INDEX 0xFF /* internal use only */ #define USB_IFACE_INDEX_ANY 0xFF /* internal use only */ #define USB_START_ADDR 0 /* default USB device BUS address * after USB bus reset */ #define USB_CONTROL_ENDPOINT 0 /* default control endpoint */ #define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */ #define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */ #define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */ #define USB_HS_MICRO_FRAMES_MAX 8 /* units */ #define USB_ISOC_TIME_MAX 128 /* ms */ /* * Minimum time a device needs to be powered down to go through a * power cycle. These values are not in the USB specification. */ #define USB_POWER_DOWN_TIME 200 /* ms */ #define USB_PORT_POWER_DOWN_TIME 100 /* ms */ /* Definition of software USB power modes */ #define USB_POWER_MODE_OFF 0 /* turn off device */ #define USB_POWER_MODE_ON 1 /* always on */ #define USB_POWER_MODE_SAVE 2 /* automatic suspend and resume */ #define USB_POWER_MODE_SUSPEND 3 /* force suspend */ #define USB_POWER_MODE_RESUME 4 /* force resume */ /* These are the values from the USB specification. */ #define USB_PORT_RESET_DELAY_SPEC 10 /* ms */ #define USB_PORT_ROOT_RESET_DELAY_SPEC 50 /* ms */ #define USB_PORT_RESET_RECOVERY_SPEC 10 /* ms */ #define USB_PORT_POWERUP_DELAY_SPEC 100 /* ms */ #define USB_PORT_RESUME_DELAY_SPEC 20 /* ms */ #define USB_SET_ADDRESS_SETTLE_SPEC 2 /* ms */ #define USB_RESUME_DELAY_SPEC (20*5) /* ms */ #define USB_RESUME_WAIT_SPEC 10 /* ms */ #define USB_RESUME_RECOVERY_SPEC 10 /* ms */ #define USB_EXTRA_POWER_UP_TIME_SPEC 0 /* ms */ /* Allow for marginal and non-conforming devices. */ #define USB_PORT_RESET_DELAY 50 /* ms */ #define USB_PORT_ROOT_RESET_DELAY 200 /* ms */ #define USB_PORT_RESET_RECOVERY 10 /* ms */ #define USB_PORT_POWERUP_DELAY 300 /* ms */ #define USB_PORT_RESUME_DELAY (20*2) /* ms */ #define USB_SET_ADDRESS_SETTLE 10 /* ms */ #define USB_RESUME_DELAY (50*5) /* ms */ #define USB_RESUME_WAIT 50 /* ms */ #define USB_RESUME_RECOVERY 50 /* ms */ #define USB_EXTRA_POWER_UP_TIME 20 /* ms */ +#define USB_ENUM_NICE_TIME 16 /* ms */ #define USB_MIN_POWER 100 /* mA */ #define USB_MAX_POWER 500 /* mA */ #define USB_BUS_RESET_DELAY 100 /* ms */ /* * USB record layout in memory: * * - USB config 0 * - USB interfaces * - USB alternative interfaces * - USB endpoints * * - USB config 1 * - USB interfaces * - USB alternative interfaces * - USB endpoints */ /* Declaration of USB records */ struct usb_device_request { uByte bmRequestType; uByte bRequest; uWord wValue; uWord wIndex; uWord wLength; } __packed; typedef struct usb_device_request usb_device_request_t; #define UT_WRITE 0x00 #define UT_READ 0x80 #define UT_STANDARD 0x00 #define UT_CLASS 0x20 #define UT_VENDOR 0x40 #define UT_DEVICE 0x00 #define UT_INTERFACE 0x01 #define UT_ENDPOINT 0x02 #define UT_OTHER 0x03 #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE) #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE) #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT) #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE) #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE) #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT) #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE) #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE) #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER) #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT) #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE) #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE) #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER) #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT) #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE) #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE) #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER) #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT) #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE) #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE) #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER) #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT) /* Requests */ #define UR_GET_STATUS 0x00 #define UR_CLEAR_FEATURE 0x01 #define UR_SET_FEATURE 0x03 #define UR_SET_ADDRESS 0x05 #define UR_GET_DESCRIPTOR 0x06 #define UDESC_DEVICE 0x01 #define UDESC_CONFIG 0x02 #define UDESC_STRING 0x03 #define USB_LANGUAGE_TABLE 0x00 /* language ID string index */ #define UDESC_INTERFACE 0x04 #define UDESC_ENDPOINT 0x05 #define UDESC_DEVICE_QUALIFIER 0x06 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07 #define UDESC_INTERFACE_POWER 0x08 #define UDESC_OTG 0x09 #define UDESC_DEBUG 0x0A #define UDESC_IFACE_ASSOC 0x0B /* interface association */ #define UDESC_BOS 0x0F /* binary object store */ #define UDESC_DEVICE_CAPABILITY 0x10 #define UDESC_CS_DEVICE 0x21 /* class specific */ #define UDESC_CS_CONFIG 0x22 #define UDESC_CS_STRING 0x23 #define UDESC_CS_INTERFACE 0x24 #define UDESC_CS_ENDPOINT 0x25 #define UDESC_HUB 0x29 #define UDESC_SS_HUB 0x2A /* super speed */ #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */ #define UR_SET_DESCRIPTOR 0x07 #define UR_GET_CONFIG 0x08 #define UR_SET_CONFIG 0x09 #define UR_GET_INTERFACE 0x0a #define UR_SET_INTERFACE 0x0b #define UR_SYNCH_FRAME 0x0c #define UR_SET_SEL 0x30 #define UR_ISOCH_DELAY 0x31 /* HUB specific request */ #define UR_GET_BUS_STATE 0x02 #define UR_CLEAR_TT_BUFFER 0x08 #define UR_RESET_TT 0x09 #define UR_GET_TT_STATE 0x0a #define UR_STOP_TT 0x0b #define UR_SET_AND_TEST 0x0c /* USB 2.0 only */ #define UR_SET_HUB_DEPTH 0x0c /* USB 3.0 only */ #define USB_SS_HUB_DEPTH_MAX 5 #define UR_GET_PORT_ERR_COUNT 0x0d /* Feature numbers */ #define UF_ENDPOINT_HALT 0 #define UF_DEVICE_REMOTE_WAKEUP 1 #define UF_TEST_MODE 2 #define UF_U1_ENABLE 0x30 #define UF_U2_ENABLE 0x31 #define UF_LTM_ENABLE 0x32 /* HUB specific features */ #define UHF_C_HUB_LOCAL_POWER 0 #define UHF_C_HUB_OVER_CURRENT 1 #define UHF_PORT_CONNECTION 0 #define UHF_PORT_ENABLE 1 #define UHF_PORT_SUSPEND 2 #define UHF_PORT_OVER_CURRENT 3 #define UHF_PORT_RESET 4 #define UHF_PORT_LINK_STATE 5 #define UHF_PORT_POWER 8 #define UHF_PORT_LOW_SPEED 9 #define UHF_PORT_L1 10 #define UHF_C_PORT_CONNECTION 16 #define UHF_C_PORT_ENABLE 17 #define UHF_C_PORT_SUSPEND 18 #define UHF_C_PORT_OVER_CURRENT 19 #define UHF_C_PORT_RESET 20 #define UHF_PORT_TEST 21 #define UHF_PORT_INDICATOR 22 #define UHF_C_PORT_L1 23 /* SuperSpeed HUB specific features */ #define UHF_PORT_U1_TIMEOUT 23 #define UHF_PORT_U2_TIMEOUT 24 #define UHF_C_PORT_LINK_STATE 25 #define UHF_C_PORT_CONFIG_ERROR 26 #define UHF_PORT_REMOTE_WAKE_MASK 27 #define UHF_BH_PORT_RESET 28 #define UHF_C_BH_PORT_RESET 29 #define UHF_FORCE_LINKPM_ACCEPT 30 /* SuperSpeed suspend support */ #define USB_INTERFACE_FUNC_SUSPEND 0 #define USB_INTERFACE_FUNC_SUSPEND_LP (1 << 8) #define USB_INTERFACE_FUNC_SUSPEND_RW (1 << 9) struct usb_descriptor { uByte bLength; uByte bDescriptorType; uByte bDescriptorSubtype; } __packed; typedef struct usb_descriptor usb_descriptor_t; struct usb_device_descriptor { uByte bLength; uByte bDescriptorType; uWord bcdUSB; #define UD_USB_2_0 0x0200 #define UD_USB_3_0 0x0300 #define UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02) #define UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03) uByte bDeviceClass; uByte bDeviceSubClass; uByte bDeviceProtocol; uByte bMaxPacketSize; /* The fields below are not part of the initial descriptor. */ uWord idVendor; uWord idProduct; uWord bcdDevice; uByte iManufacturer; uByte iProduct; uByte iSerialNumber; uByte bNumConfigurations; } __packed; typedef struct usb_device_descriptor usb_device_descriptor_t; /* Binary Device Object Store (BOS) */ struct usb_bos_descriptor { uByte bLength; uByte bDescriptorType; uWord wTotalLength; uByte bNumDeviceCaps; } __packed; typedef struct usb_bos_descriptor usb_bos_descriptor_t; /* Binary Device Object Store Capability */ struct usb_bos_cap_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; #define USB_DEVCAP_RESERVED 0x00 #define USB_DEVCAP_WUSB 0x01 #define USB_DEVCAP_USB2EXT 0x02 #define USB_DEVCAP_SUPER_SPEED 0x03 #define USB_DEVCAP_CONTAINER_ID 0x04 /* data ... */ } __packed; typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t; struct usb_devcap_usb2ext_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uDWord bmAttributes; #define USB_V2EXT_LPM (1U << 1) #define USB_V2EXT_BESL_SUPPORTED (1U << 2) #define USB_V2EXT_BESL_BASELINE_VALID (1U << 3) #define USB_V2EXT_BESL_DEEP_VALID (1U << 4) #define USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF) #define USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF) } __packed; typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t; struct usb_devcap_ss_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uByte bmAttributes; uWord wSpeedsSupported; uByte bFunctionalitySupport; uByte bU1DevExitLat; uWord wU2DevExitLat; } __packed; typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t; struct usb_devcap_container_id_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uByte bReserved; uByte bContainerID; } __packed; typedef struct usb_devcap_container_id_descriptor usb_devcap_container_id_descriptor_t; /* Device class codes */ #define UDCLASS_IN_INTERFACE 0x00 #define UDCLASS_COMM 0x02 #define UDCLASS_HUB 0x09 #define UDSUBCLASS_HUB 0x00 #define UDPROTO_FSHUB 0x00 #define UDPROTO_HSHUBSTT 0x01 #define UDPROTO_HSHUBMTT 0x02 #define UDPROTO_SSHUB 0x03 #define UDCLASS_DIAGNOSTIC 0xdc #define UDCLASS_WIRELESS 0xe0 #define UDSUBCLASS_RF 0x01 #define UDPROTO_BLUETOOTH 0x01 #define UDCLASS_VENDOR 0xff struct usb_config_descriptor { uByte bLength; uByte bDescriptorType; uWord wTotalLength; uByte bNumInterface; uByte bConfigurationValue; #define USB_UNCONFIG_NO 0 uByte iConfiguration; uByte bmAttributes; #define UC_BUS_POWERED 0x80 #define UC_SELF_POWERED 0x40 #define UC_REMOTE_WAKEUP 0x20 uByte bMaxPower; /* max current in 2 mA units */ #define UC_POWER_FACTOR 2 } __packed; typedef struct usb_config_descriptor usb_config_descriptor_t; struct usb_interface_descriptor { uByte bLength; uByte bDescriptorType; uByte bInterfaceNumber; uByte bAlternateSetting; uByte bNumEndpoints; uByte bInterfaceClass; uByte bInterfaceSubClass; uByte bInterfaceProtocol; uByte iInterface; } __packed; typedef struct usb_interface_descriptor usb_interface_descriptor_t; struct usb_interface_assoc_descriptor { uByte bLength; uByte bDescriptorType; uByte bFirstInterface; uByte bInterfaceCount; uByte bFunctionClass; uByte bFunctionSubClass; uByte bFunctionProtocol; uByte iFunction; } __packed; typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t; /* Interface class codes */ #define UICLASS_UNSPEC 0x00 #define UICLASS_AUDIO 0x01 /* audio */ #define UISUBCLASS_AUDIOCONTROL 1 #define UISUBCLASS_AUDIOSTREAM 2 #define UISUBCLASS_MIDISTREAM 3 #define UICLASS_CDC 0x02 /* communication */ #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4 #define UISUBCLASS_CAPI_CONTROLMODEL 5 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7 #define UISUBCLASS_WIRELESS_HANDSET_CM 8 #define UISUBCLASS_DEVICE_MGMT 9 #define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10 #define UISUBCLASS_OBEX 11 #define UISUBCLASS_ETHERNET_EMULATION_MODEL 12 #define UISUBCLASS_NETWORK_CONTROL_MODEL 13 #define UIPROTO_CDC_NONE 0 #define UIPROTO_CDC_AT 1 #define UIPROTO_CDC_EEM 7 #define UICLASS_HID 0x03 #define UISUBCLASS_BOOT 1 #define UIPROTO_BOOT_KEYBOARD 1 #define UIPROTO_MOUSE 2 #define UICLASS_PHYSICAL 0x05 #define UICLASS_IMAGE 0x06 #define UISUBCLASS_SIC 1 /* still image class */ #define UICLASS_PRINTER 0x07 #define UISUBCLASS_PRINTER 1 #define UIPROTO_PRINTER_UNI 1 #define UIPROTO_PRINTER_BI 2 #define UIPROTO_PRINTER_1284 3 #define UICLASS_MASS 0x08 #define UISUBCLASS_RBC 1 #define UISUBCLASS_SFF8020I 2 #define UISUBCLASS_QIC157 3 #define UISUBCLASS_UFI 4 #define UISUBCLASS_SFF8070I 5 #define UISUBCLASS_SCSI 6 #define UIPROTO_MASS_CBI_I 0 #define UIPROTO_MASS_CBI 1 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */ #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */ #define UICLASS_HUB 0x09 #define UISUBCLASS_HUB 0 #define UIPROTO_FSHUB 0 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */ #define UIPROTO_HSHUBMTT 1 #define UICLASS_CDC_DATA 0x0a #define UISUBCLASS_DATA 0x00 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */ #define UIPROTO_DATA_HDLC 0x31 /* HDLC */ #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */ #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */ #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */ #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */ #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */ #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */ #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */ #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */ #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */ #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */ #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */ #define UIPROTO_DATA_NCM 0x01 /* Network Control Model */ #define UICLASS_SMARTCARD 0x0b #define UICLASS_FIRM_UPD 0x0c #define UICLASS_SECURITY 0x0d #define UICLASS_DIAGNOSTIC 0xdc #define UICLASS_WIRELESS 0xe0 #define UISUBCLASS_RF 0x01 #define UIPROTO_BLUETOOTH 0x01 #define UIPROTO_RNDIS 0x03 #define UICLASS_IAD 0xEF /* Interface Association Descriptor */ #define UISUBCLASS_SYNC 0x01 #define UIPROTO_ACTIVESYNC 0x01 #define UICLASS_APPL_SPEC 0xfe #define UISUBCLASS_FIRMWARE_DOWNLOAD 1 #define UISUBCLASS_IRDA 2 #define UIPROTO_IRDA 0 #define UICLASS_VENDOR 0xff #define UISUBCLASS_XBOX360_CONTROLLER 0x5d #define UISUBCLASS_VENDOR 0xff #define UIPROTO_XBOX360_GAMEPAD 0x01 struct usb_endpoint_descriptor { uByte bLength; uByte bDescriptorType; uByte bEndpointAddress; #define UE_GET_DIR(a) ((a) & 0x80) #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7)) #define UE_DIR_IN 0x80 /* IN-token endpoint, fixed */ #define UE_DIR_OUT 0x00 /* OUT-token endpoint, fixed */ #define UE_DIR_RX 0xfd /* for internal use only! */ #define UE_DIR_TX 0xfe /* for internal use only! */ #define UE_DIR_ANY 0xff /* for internal use only! */ #define UE_ADDR 0x0f #define UE_ADDR_ANY 0xff /* for internal use only! */ #define UE_GET_ADDR(a) ((a) & UE_ADDR) uByte bmAttributes; #define UE_XFERTYPE 0x03 #define UE_CONTROL 0x00 #define UE_ISOCHRONOUS 0x01 #define UE_BULK 0x02 #define UE_INTERRUPT 0x03 #define UE_BULK_INTR 0xfe /* for internal use only! */ #define UE_TYPE_ANY 0xff /* for internal use only! */ #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE) #define UE_ISO_TYPE 0x0c #define UE_ISO_ASYNC 0x04 #define UE_ISO_ADAPT 0x08 #define UE_ISO_SYNC 0x0c #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE) #define UE_ISO_USAGE 0x30 #define UE_ISO_USAGE_DATA 0x00 #define UE_ISO_USAGE_FEEDBACK 0x10 #define UE_ISO_USAGE_IMPLICT_FB 0x20 #define UE_GET_ISO_USAGE(a) ((a) & UE_ISO_USAGE) uWord wMaxPacketSize; #define UE_ZERO_MPS 0xFFFF /* for internal use only */ uByte bInterval; } __packed; typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t; struct usb_endpoint_ss_comp_descriptor { uByte bLength; uByte bDescriptorType; uByte bMaxBurst; uByte bmAttributes; #define UE_GET_BULK_STREAMS(x) ((x) & 0x0F) #define UE_GET_SS_ISO_MULT(x) ((x) & 0x03) uWord wBytesPerInterval; } __packed; typedef struct usb_endpoint_ss_comp_descriptor usb_endpoint_ss_comp_descriptor_t; struct usb_string_descriptor { uByte bLength; uByte bDescriptorType; uWord bString[126]; uByte bUnused; } __packed; typedef struct usb_string_descriptor usb_string_descriptor_t; #define USB_MAKE_STRING_DESC(m,name) \ static const struct { \ uByte bLength; \ uByte bDescriptorType; \ uByte bData[sizeof((uint8_t []){m})]; \ } __packed name = { \ .bLength = sizeof(name), \ .bDescriptorType = UDESC_STRING, \ .bData = { m }, \ } struct usb_string_lang { uByte bLength; uByte bDescriptorType; uByte bData[2]; } __packed; typedef struct usb_string_lang usb_string_lang_t; struct usb_hub_descriptor { uByte bDescLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; #define UHD_PWR 0x0003 #define UHD_PWR_GANGED 0x0000 #define UHD_PWR_INDIVIDUAL 0x0001 #define UHD_PWR_NO_SWITCH 0x0002 #define UHD_COMPOUND 0x0004 #define UHD_OC 0x0018 #define UHD_OC_GLOBAL 0x0000 #define UHD_OC_INDIVIDUAL 0x0008 #define UHD_OC_NONE 0x0010 #define UHD_TT_THINK 0x0060 #define UHD_TT_THINK_8 0x0000 #define UHD_TT_THINK_16 0x0020 #define UHD_TT_THINK_24 0x0040 #define UHD_TT_THINK_32 0x0060 #define UHD_PORT_IND 0x0080 uByte bPwrOn2PwrGood; /* delay in 2 ms units */ #define UHD_PWRON_FACTOR 2 uByte bHubContrCurrent; uByte DeviceRemovable[32]; /* max 255 ports */ #define UHD_NOT_REMOV(desc, i) \ (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1) uByte PortPowerCtrlMask[1]; /* deprecated */ } __packed; typedef struct usb_hub_descriptor usb_hub_descriptor_t; struct usb_hub_ss_descriptor { uByte bLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; uByte bPwrOn2PwrGood; /* delay in 2 ms units */ uByte bHubContrCurrent; uByte bHubHdrDecLat; uWord wHubDelay; uByte DeviceRemovable[32]; /* max 255 ports */ } __packed; typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t; /* minimum HUB descriptor (8-ports maximum) */ struct usb_hub_descriptor_min { uByte bDescLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; uByte bPwrOn2PwrGood; uByte bHubContrCurrent; uByte DeviceRemovable[1]; uByte PortPowerCtrlMask[1]; } __packed; typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t; struct usb_device_qualifier { uByte bLength; uByte bDescriptorType; uWord bcdUSB; uByte bDeviceClass; uByte bDeviceSubClass; uByte bDeviceProtocol; uByte bMaxPacketSize0; uByte bNumConfigurations; uByte bReserved; } __packed; typedef struct usb_device_qualifier usb_device_qualifier_t; struct usb_otg_descriptor { uByte bLength; uByte bDescriptorType; uByte bmAttributes; #define UOTG_SRP 0x01 #define UOTG_HNP 0x02 } __packed; typedef struct usb_otg_descriptor usb_otg_descriptor_t; /* OTG feature selectors */ #define UOTG_B_HNP_ENABLE 3 #define UOTG_A_HNP_SUPPORT 4 #define UOTG_A_ALT_HNP_SUPPORT 5 struct usb_status { uWord wStatus; /* Device status flags */ #define UDS_SELF_POWERED 0x0001 #define UDS_REMOTE_WAKEUP 0x0002 /* Endpoint status flags */ #define UES_HALT 0x0001 } __packed; typedef struct usb_status usb_status_t; struct usb_hub_status { uWord wHubStatus; #define UHS_LOCAL_POWER 0x0001 #define UHS_OVER_CURRENT 0x0002 uWord wHubChange; } __packed; typedef struct usb_hub_status usb_hub_status_t; struct usb_port_status { uWord wPortStatus; #define UPS_CURRENT_CONNECT_STATUS 0x0001 #define UPS_PORT_ENABLED 0x0002 #define UPS_SUSPEND 0x0004 #define UPS_OVERCURRENT_INDICATOR 0x0008 #define UPS_RESET 0x0010 #define UPS_PORT_L1 0x0020 /* USB 2.0 only */ /* The link-state bits are valid for Super-Speed USB HUBs */ #define UPS_PORT_LINK_STATE_GET(x) (((x) >> 5) & 0xF) #define UPS_PORT_LINK_STATE_SET(x) (((x) & 0xF) << 5) #define UPS_PORT_LS_U0 0x00 #define UPS_PORT_LS_U1 0x01 #define UPS_PORT_LS_U2 0x02 #define UPS_PORT_LS_U3 0x03 #define UPS_PORT_LS_SS_DIS 0x04 #define UPS_PORT_LS_RX_DET 0x05 #define UPS_PORT_LS_SS_INA 0x06 #define UPS_PORT_LS_POLL 0x07 #define UPS_PORT_LS_RECOVER 0x08 #define UPS_PORT_LS_HOT_RST 0x09 #define UPS_PORT_LS_COMP_MODE 0x0A #define UPS_PORT_LS_LOOPBACK 0x0B #define UPS_PORT_LS_RESUME 0x0F #define UPS_PORT_POWER 0x0100 #define UPS_PORT_POWER_SS 0x0200 /* super-speed only */ #define UPS_LOW_SPEED 0x0200 #define UPS_HIGH_SPEED 0x0400 #define UPS_OTHER_SPEED 0x0600 /* currently FreeBSD specific */ #define UPS_PORT_TEST 0x0800 #define UPS_PORT_INDICATOR 0x1000 #define UPS_PORT_MODE_DEVICE 0x8000 /* currently FreeBSD specific */ uWord wPortChange; #define UPS_C_CONNECT_STATUS 0x0001 #define UPS_C_PORT_ENABLED 0x0002 #define UPS_C_SUSPEND 0x0004 #define UPS_C_OVERCURRENT_INDICATOR 0x0008 #define UPS_C_PORT_RESET 0x0010 #define UPS_C_PORT_L1 0x0020 /* USB 2.0 only */ #define UPS_C_BH_PORT_RESET 0x0020 /* USB 3.0 only */ #define UPS_C_PORT_LINK_STATE 0x0040 #define UPS_C_PORT_CONFIG_ERROR 0x0080 } __packed; typedef struct usb_port_status usb_port_status_t; /* * The "USB_SPEED" macros defines all the supported USB speeds. */ enum usb_dev_speed { USB_SPEED_VARIABLE, USB_SPEED_LOW, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_SUPER, }; #define USB_SPEED_MAX (USB_SPEED_SUPER+1) /* * The "USB_REV" macros defines all the supported USB revisions. */ enum usb_revision { USB_REV_UNKNOWN, USB_REV_PRE_1_0, USB_REV_1_0, USB_REV_1_1, USB_REV_2_0, USB_REV_2_5, USB_REV_3_0 }; #define USB_REV_MAX (USB_REV_3_0+1) /* * Supported host controller modes. */ enum usb_hc_mode { USB_MODE_HOST, /* initiates transfers */ USB_MODE_DEVICE, /* bus transfer target */ USB_MODE_DUAL /* can be host or device */ }; #define USB_MODE_MAX (USB_MODE_DUAL+1) /* * The "USB_STATE" enums define all the supported device states. */ enum usb_dev_state { USB_STATE_DETACHED, USB_STATE_ATTACHED, USB_STATE_POWERED, USB_STATE_ADDRESSED, USB_STATE_CONFIGURED, }; #define USB_STATE_MAX (USB_STATE_CONFIGURED+1) /* * The "USB_EP_MODE" macros define all the currently supported * endpoint modes. */ enum usb_ep_mode { USB_EP_MODE_DEFAULT, USB_EP_MODE_STREAMS, /* USB3.0 specific */ USB_EP_MODE_HW_MASS_STORAGE, USB_EP_MODE_HW_SERIAL, USB_EP_MODE_HW_ETHERNET_CDC, USB_EP_MODE_HW_ETHERNET_NCM, USB_EP_MODE_MAX }; #endif /* _USB_STANDARD_H_ */ diff --git a/sys/dev/usb/usb_debug.c b/sys/dev/usb/usb_debug.c index 5e521f7ec3a5..6ad8dce9a037 100644 --- a/sys/dev/usb/usb_debug.c +++ b/sys/dev/usb/usb_debug.c @@ -1,288 +1,293 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * - * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2008-2022 Hans Petter Selasky * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifdef USB_GLOBAL_INCLUDE_FILE #include USB_GLOBAL_INCLUDE_FILE #else #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* USB_GLOBAL_INCLUDE_FILE */ /* * Define this unconditionally in case a kernel module is loaded that * has been compiled with debugging options. */ int usb_debug = 0; SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "USB debugging"); SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RWTUN, &usb_debug, 0, "Debug level"); #ifdef USB_DEBUG /* * Sysctls to modify timings/delays */ static SYSCTL_NODE(_hw_usb, OID_AUTO, timings, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Timings"); static int usb_timings_sysctl_handler(SYSCTL_HANDLER_ARGS); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, port_reset_delay, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_port_reset_delay, sizeof(usb_port_reset_delay), usb_timings_sysctl_handler, "IU", "Port Reset Delay"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, port_root_reset_delay, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_port_root_reset_delay, sizeof(usb_port_root_reset_delay), usb_timings_sysctl_handler, "IU", "Root Port Reset Delay"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, port_reset_recovery, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_port_reset_recovery, sizeof(usb_port_reset_recovery), usb_timings_sysctl_handler, "IU", "Port Reset Recovery"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, port_powerup_delay, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_port_powerup_delay, sizeof(usb_port_powerup_delay), usb_timings_sysctl_handler, "IU", "Port PowerUp Delay"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, port_resume_delay, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_port_resume_delay, sizeof(usb_port_resume_delay), usb_timings_sysctl_handler, "IU", "Port Resume Delay"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, set_address_settle, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_set_address_settle, sizeof(usb_set_address_settle), usb_timings_sysctl_handler, "IU", "Set Address Settle"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, resume_delay, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_resume_delay, sizeof(usb_resume_delay), usb_timings_sysctl_handler, "IU", "Resume Delay"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, resume_wait, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_resume_wait, sizeof(usb_resume_wait), usb_timings_sysctl_handler, "IU", "Resume Wait"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, resume_recovery, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_resume_recovery, sizeof(usb_resume_recovery), usb_timings_sysctl_handler, "IU", "Resume Recovery"); SYSCTL_PROC(_hw_usb_timings, OID_AUTO, extra_power_up_time, CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_extra_power_up_time, sizeof(usb_extra_power_up_time), usb_timings_sysctl_handler, "IU", "Extra PowerUp Time"); +SYSCTL_PROC(_hw_usb_timings, OID_AUTO, enum_nice_time, + CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &usb_enum_nice_time, + sizeof(usb_enum_nice_time), usb_timings_sysctl_handler, "IU", + "Enumeration thread nice time"); #endif /*------------------------------------------------------------------------* * usb_dump_iface * * This function dumps information about an USB interface. *------------------------------------------------------------------------*/ void usb_dump_iface(struct usb_interface *iface) { printf("usb_dump_iface: iface=%p\n", iface); if (iface == NULL) { return; } printf(" iface=%p idesc=%p altindex=%d\n", iface, iface->idesc, iface->alt_index); } /*------------------------------------------------------------------------* * usb_dump_device * * This function dumps information about an USB device. *------------------------------------------------------------------------*/ void usb_dump_device(struct usb_device *udev) { printf("usb_dump_device: dev=%p\n", udev); if (udev == NULL) { return; } printf(" bus=%p \n" " address=%d config=%d depth=%d speed=%d self_powered=%d\n" " power=%d langid=%d\n", udev->bus, udev->address, udev->curr_config_no, udev->depth, udev->speed, udev->flags.self_powered, udev->power, udev->langid); } /*------------------------------------------------------------------------* * usb_dump_queue * * This function dumps the USB transfer that are queued up on an USB endpoint. *------------------------------------------------------------------------*/ void usb_dump_queue(struct usb_endpoint *ep) { struct usb_xfer *xfer; usb_stream_t x; printf("usb_dump_queue: endpoint=%p xfer: ", ep); for (x = 0; x != USB_MAX_EP_STREAMS; x++) { TAILQ_FOREACH(xfer, &ep->endpoint_q[x].head, wait_entry) printf(" %p", xfer); } printf("\n"); } /*------------------------------------------------------------------------* * usb_dump_endpoint * * This function dumps information about an USB endpoint. *------------------------------------------------------------------------*/ void usb_dump_endpoint(struct usb_endpoint *ep) { if (ep) { printf("usb_dump_endpoint: endpoint=%p", ep); printf(" edesc=%p isoc_next=%d toggle_next=%d", ep->edesc, ep->isoc_next, ep->toggle_next); if (ep->edesc) { printf(" bEndpointAddress=0x%02x", ep->edesc->bEndpointAddress); } printf("\n"); usb_dump_queue(ep); } else { printf("usb_dump_endpoint: endpoint=NULL\n"); } } /*------------------------------------------------------------------------* * usb_dump_xfer * * This function dumps information about an USB transfer. *------------------------------------------------------------------------*/ void usb_dump_xfer(struct usb_xfer *xfer) { struct usb_device *udev; printf("usb_dump_xfer: xfer=%p\n", xfer); if (xfer == NULL) { return; } if (xfer->endpoint == NULL) { printf("xfer %p: endpoint=NULL\n", xfer); return; } udev = xfer->xroot->udev; printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d " "endpoint=%p ep=0x%02x attr=0x%02x\n", xfer, udev, UGETW(udev->ddesc.idVendor), UGETW(udev->ddesc.idProduct), udev->address, xfer->endpoint, xfer->endpoint->edesc->bEndpointAddress, xfer->endpoint->edesc->bmAttributes); } #ifdef USB_DEBUG unsigned int usb_port_reset_delay = USB_PORT_RESET_DELAY; unsigned int usb_port_root_reset_delay = USB_PORT_ROOT_RESET_DELAY; unsigned int usb_port_reset_recovery = USB_PORT_RESET_RECOVERY; unsigned int usb_port_powerup_delay = USB_PORT_POWERUP_DELAY; unsigned int usb_port_resume_delay = USB_PORT_RESUME_DELAY; unsigned int usb_set_address_settle = USB_SET_ADDRESS_SETTLE; unsigned int usb_resume_delay = USB_RESUME_DELAY; unsigned int usb_resume_wait = USB_RESUME_WAIT; unsigned int usb_resume_recovery = USB_RESUME_RECOVERY; unsigned int usb_extra_power_up_time = USB_EXTRA_POWER_UP_TIME; +unsigned int usb_enum_nice_time = USB_ENUM_NICE_TIME; /*------------------------------------------------------------------------* * usb_timings_sysctl_handler * * This function is used to update USB timing variables. *------------------------------------------------------------------------*/ static int usb_timings_sysctl_handler(SYSCTL_HANDLER_ARGS) { int error = 0; unsigned val; /* * Attempt to get a coherent snapshot by making a copy of the data. */ if (arg1) val = *(unsigned *)arg1; else val = arg2; error = SYSCTL_OUT(req, &val, sizeof(unsigned)); if (error || !req->newptr) return (error); if (!arg1) return (EPERM); error = SYSCTL_IN(req, &val, sizeof(unsigned)); if (error) return (error); /* * Make sure the specified value is not too big. Accept any * value from 0 milliseconds to 2 seconds inclusivly for all * parameters. */ if (val > 2000) return (EINVAL); *(unsigned *)arg1 = val; return (0); } #endif diff --git a/sys/dev/usb/usb_debug.h b/sys/dev/usb/usb_debug.h index 9bcbaec70ef4..c9df04111b60 100644 --- a/sys/dev/usb/usb_debug.h +++ b/sys/dev/usb/usb_debug.h @@ -1,90 +1,92 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* This file contains various factored out debug macros. */ #ifndef _USB_DEBUG_H_ #define _USB_DEBUG_H_ /* Declare global USB debug variable. */ extern int usb_debug; /* Check if USB debugging is enabled. */ #ifdef USB_DEBUG_VAR #ifdef USB_DEBUG #define DPRINTFN(n,fmt,...) do { \ if ((USB_DEBUG_VAR) >= (n)) { \ printf("%s: " fmt, \ __FUNCTION__ ,##__VA_ARGS__); \ } \ } while (0) #define DPRINTF(...) DPRINTFN(1, __VA_ARGS__) #define __usbdebug_used #else #define DPRINTF(...) do { } while (0) #define DPRINTFN(...) do { } while (0) #define __usbdebug_used __unused #endif #endif struct usb_interface; struct usb_device; struct usb_endpoint; struct usb_xfer; void usb_dump_iface(struct usb_interface *iface); void usb_dump_device(struct usb_device *udev); void usb_dump_queue(struct usb_endpoint *ep); void usb_dump_endpoint(struct usb_endpoint *ep); void usb_dump_xfer(struct usb_xfer *xfer); #ifdef USB_DEBUG extern unsigned int usb_port_reset_delay; extern unsigned int usb_port_root_reset_delay; extern unsigned int usb_port_reset_recovery; extern unsigned int usb_port_powerup_delay; extern unsigned int usb_port_resume_delay; extern unsigned int usb_set_address_settle; extern unsigned int usb_resume_delay; extern unsigned int usb_resume_wait; extern unsigned int usb_resume_recovery; extern unsigned int usb_extra_power_up_time; +extern unsigned int usb_enum_nice_time; #else #define usb_port_reset_delay USB_PORT_RESET_DELAY #define usb_port_root_reset_delay USB_PORT_ROOT_RESET_DELAY #define usb_port_reset_recovery USB_PORT_RESET_RECOVERY #define usb_port_powerup_delay USB_PORT_POWERUP_DELAY #define usb_port_resume_delay USB_PORT_RESUME_DELAY #define usb_set_address_settle USB_SET_ADDRESS_SETTLE #define usb_resume_delay USB_RESUME_DELAY #define usb_resume_wait USB_RESUME_WAIT #define usb_resume_recovery USB_RESUME_RECOVERY #define usb_extra_power_up_time USB_EXTRA_POWER_UP_TIME +#define usb_enum_nice_time USB_ENUM_NICE_TIME #endif #endif /* _USB_DEBUG_H_ */