Lines Matching +full:report +full:- +full:speed +full:- +full:hz

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2008-2022 Hans Petter Selasky
108 #define UHUB_PROTO(sc) ((sc)->sc_udev->ddesc.bDeviceProtocol)
198 usb_needs_explore(sc->sc_udev->bus, 0); in uhub_intr_callback()
206 if (xfer->error != USB_ERR_CANCELLED) { in uhub_intr_callback()
208 * Do a clear-stall. The "stall_pipe" flag in uhub_intr_callback()
220 /*------------------------------------------------------------------------*
224 *------------------------------------------------------------------------*/
230 struct usb_device *udev = pm->udev; in uhub_reset_tt_proc()
234 hub = udev->hub; in uhub_reset_tt_proc()
237 sc = hub->hubsoftc; in uhub_reset_tt_proc()
242 USB_BUS_UNLOCK(udev->bus); in uhub_reset_tt_proc()
243 USB_MTX_LOCK(&sc->sc_mtx); in uhub_reset_tt_proc()
245 usbd_transfer_start(sc->sc_xfer[UHUB_RESET_TT_TRANSFER]); in uhub_reset_tt_proc()
247 USB_MTX_UNLOCK(&sc->sc_mtx); in uhub_reset_tt_proc()
248 USB_BUS_LOCK(udev->bus); in uhub_reset_tt_proc()
252 /*------------------------------------------------------------------------*
256 *------------------------------------------------------------------------*/
271 udev = child->parent_hs_hub; in uhub_tt_buffer_reset_async_locked()
272 port = child->hs_port_no; in uhub_tt_buffer_reset_async_locked()
277 hub = udev->hub; in uhub_tt_buffer_reset_async_locked()
279 (udev->speed != USB_SPEED_HIGH) || in uhub_tt_buffer_reset_async_locked()
280 (child->speed != USB_SPEED_LOW && in uhub_tt_buffer_reset_async_locked()
281 child->speed != USB_SPEED_FULL) || in uhub_tt_buffer_reset_async_locked()
282 (child->flags.usb_mode != USB_MODE_HOST) || in uhub_tt_buffer_reset_async_locked()
283 (port == 0) || (ep->edesc == NULL)) { in uhub_tt_buffer_reset_async_locked()
288 USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED); in uhub_tt_buffer_reset_async_locked()
290 up = hub->ports + port - 1; in uhub_tt_buffer_reset_async_locked()
292 if (udev->ddesc.bDeviceClass == UDCLASS_HUB && in uhub_tt_buffer_reset_async_locked()
293 udev->ddesc.bDeviceProtocol == UDPROTO_HSHUBSTT) in uhub_tt_buffer_reset_async_locked()
297 if (up->req_reset_tt.bRequest != 0) { in uhub_tt_buffer_reset_async_locked()
305 wValue = (ep->edesc->bEndpointAddress & 0xF) | in uhub_tt_buffer_reset_async_locked()
306 ((child->address & 0x7F) << 4) | in uhub_tt_buffer_reset_async_locked()
307 ((ep->edesc->bEndpointAddress & 0x80) << 8) | in uhub_tt_buffer_reset_async_locked()
308 ((ep->edesc->bmAttributes & 3) << 12); in uhub_tt_buffer_reset_async_locked()
317 up->req_reset_tt = req; in uhub_tt_buffer_reset_async_locked()
319 usb_proc_msignal(USB_BUS_TT_PROC(udev->bus), in uhub_tt_buffer_reset_async_locked()
320 &hub->tt_msg[0], &hub->tt_msg[1]); in uhub_tt_buffer_reset_async_locked()
336 udev = sc->sc_udev; in uhub_reset_tt_callback()
342 USB_BUS_LOCK(udev->bus); in uhub_reset_tt_callback()
344 for (x = 0; x != udev->hub->nports; x++) { in uhub_reset_tt_callback()
345 up = udev->hub->ports + x; in uhub_reset_tt_callback()
347 if (up->req_reset_tt.bRequest == 0) in uhub_reset_tt_callback()
351 usbd_copy_in(xfer->frbuffers, 0, &up->req_reset_tt, in uhub_reset_tt_callback()
352 sizeof(up->req_reset_tt)); in uhub_reset_tt_callback()
354 memset(&up->req_reset_tt, 0, sizeof(up->req_reset_tt)); in uhub_reset_tt_callback()
357 usbd_xfer_set_frame_len(xfer, 0, sizeof(up->req_reset_tt)); in uhub_reset_tt_callback()
358 xfer->nframes = 1; in uhub_reset_tt_callback()
359 USB_BUS_UNLOCK(udev->bus); in uhub_reset_tt_callback()
364 USB_BUS_UNLOCK(udev->bus); in uhub_reset_tt_callback()
377 /*------------------------------------------------------------------------*
380 * This function counts the number of active ports at the given speed.
381 *------------------------------------------------------------------------*/
383 uhub_count_active_host_ports(struct usb_device *udev, enum usb_dev_speed speed) in uhub_count_active_host_ports() argument
394 hub = udev->hub; in uhub_count_active_host_ports()
397 sc = hub->hubsoftc; in uhub_count_active_host_ports()
401 for (x = 0; x != hub->nports; x++) { in uhub_count_active_host_ports()
402 up = hub->ports + x; in uhub_count_active_host_ports()
403 child = usb_bus_port_get_device(udev->bus, up); in uhub_count_active_host_ports()
405 child->flags.usb_mode == USB_MODE_HOST && in uhub_count_active_host_ports()
406 child->speed == speed) in uhub_count_active_host_ports()
419 /* check if device should be re-enumerated */ in uhub_explore_handle_re_enumerate()
420 if (child->flags.usb_mode != USB_MODE_HOST) in uhub_explore_handle_re_enumerate()
424 switch (child->re_enumerate_wait) { in uhub_explore_handle_re_enumerate()
432 if (child->parent_hub == NULL) { in uhub_explore_handle_re_enumerate()
433 /* the root HUB cannot be re-enumerated */ in uhub_explore_handle_re_enumerate()
451 child->re_enumerate_wait = USB_RE_ENUM_DONE; in uhub_explore_handle_re_enumerate()
462 if (child->parent_hub == NULL) { in uhub_explore_handle_re_enumerate()
463 /* the root HUB cannot be re-enumerated */ in uhub_explore_handle_re_enumerate()
468 err = usbd_req_clear_port_feature(child->parent_hub, in uhub_explore_handle_re_enumerate()
469 NULL, child->port_no, UHF_PORT_ENABLE); in uhub_explore_handle_re_enumerate()
475 child->re_enumerate_wait = USB_RE_ENUM_DONE; in uhub_explore_handle_re_enumerate()
480 child->next_config_index); in uhub_explore_handle_re_enumerate()
488 child->re_enumerate_wait = USB_RE_ENUM_DONE; in uhub_explore_handle_re_enumerate()
492 child->re_enumerate_wait = USB_RE_ENUM_DONE; in uhub_explore_handle_re_enumerate()
499 /*------------------------------------------------------------------------*
500 * uhub_explore_sub - subroutine
505 *------------------------------------------------------------------------*/
514 bus = sc->sc_udev->bus; in uhub_explore_sub()
518 refcount = bus->driver_added_refcount; in uhub_explore_sub()
531 if (child->driver_added_refcount != refcount) { in uhub_explore_sub()
532 child->driver_added_refcount = refcount; in uhub_explore_sub()
541 if (child->flags.usb_mode == USB_MODE_DEVICE) in uhub_explore_sub()
546 if (child->hub) in uhub_explore_sub()
547 err = (child->hub->explore) (child); in uhub_explore_sub()
553 /*------------------------------------------------------------------------*
554 * uhub_read_port_status - factored out code
555 *------------------------------------------------------------------------*/
562 if (sc->sc_usb_port_errors >= UHUB_USB_PORT_ERRORS_MAX) { in uhub_read_port_status()
564 sc->sc_st.port_status = 0; in uhub_read_port_status()
565 sc->sc_st.port_change = 0; in uhub_read_port_status()
570 sc->sc_udev, NULL, &ps, portno); in uhub_read_port_status()
573 sc->sc_st.port_status = UGETW(ps.wPortStatus); in uhub_read_port_status()
574 sc->sc_st.port_change = UGETW(ps.wPortChange); in uhub_read_port_status()
575 sc->sc_usb_port_errors = 0; in uhub_read_port_status()
577 sc->sc_st.port_status = 0; in uhub_read_port_status()
578 sc->sc_st.port_change = 0; in uhub_read_port_status()
579 sc->sc_usb_port_errors++; in uhub_read_port_status()
586 portno, sc->sc_st.port_status, in uhub_read_port_status()
587 sc->sc_st.port_change, usbd_errstr(err)); in uhub_read_port_status()
591 /*------------------------------------------------------------------------*
597 *------------------------------------------------------------------------*/
603 enum usb_dev_speed speed; in uhub_reattach_port() local
612 udev = sc->sc_udev; in uhub_reattach_port()
613 child = usb_bus_port_get_device(udev->bus, in uhub_reattach_port()
614 udev->hub->ports + portno - 1); in uhub_reattach_port()
644 sc->sc_disable_enumeration != 0) { in uhub_reattach_port()
651 if (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS)) in uhub_reattach_port()
656 switch (udev->speed) { in uhub_reattach_port()
663 if (udev->parent_hub == NULL) in uhub_reattach_port()
672 if ((sc->sc_st.port_status & power_mask) != power_mask) { in uhub_reattach_port()
679 if (!(sc->sc_st.port_status & UPS_PORT_MODE_DEVICE)) { in uhub_reattach_port()
682 if (sc->sc_st.port_status & UPS_SUSPEND) { in uhub_reattach_port()
685 * mode, because the HUB should report this in uhub_reattach_port()
719 if ((sc->sc_st.port_change & UPS_C_CONNECT_STATUS) || in uhub_reattach_port()
720 (!(sc->sc_st.port_status & UPS_CURRENT_CONNECT_STATUS))) { in uhub_reattach_port()
722 DPRINTFN(1, "giving up port %d reset - " in uhub_reattach_port()
724 portno, sc->sc_st.port_change, in uhub_reattach_port()
725 sc->sc_st.port_status); in uhub_reattach_port()
736 * Figure out the device speed in uhub_reattach_port()
738 switch (udev->speed) { in uhub_reattach_port()
740 if (sc->sc_st.port_status & UPS_HIGH_SPEED) in uhub_reattach_port()
741 speed = USB_SPEED_HIGH; in uhub_reattach_port()
742 else if (sc->sc_st.port_status & UPS_LOW_SPEED) in uhub_reattach_port()
743 speed = USB_SPEED_LOW; in uhub_reattach_port()
745 speed = USB_SPEED_FULL; in uhub_reattach_port()
748 if (sc->sc_st.port_status & UPS_LOW_SPEED) in uhub_reattach_port()
749 speed = USB_SPEED_LOW; in uhub_reattach_port()
751 speed = USB_SPEED_FULL; in uhub_reattach_port()
754 speed = USB_SPEED_LOW; in uhub_reattach_port()
757 if (udev->parent_hub == NULL) { in uhub_reattach_port()
758 /* Root HUB - special case */ in uhub_reattach_port()
759 switch (sc->sc_st.port_status & UPS_OTHER_SPEED) { in uhub_reattach_port()
761 speed = USB_SPEED_FULL; in uhub_reattach_port()
764 speed = USB_SPEED_LOW; in uhub_reattach_port()
767 speed = USB_SPEED_HIGH; in uhub_reattach_port()
770 speed = USB_SPEED_SUPER; in uhub_reattach_port()
774 speed = USB_SPEED_SUPER; in uhub_reattach_port()
778 /* same speed like parent */ in uhub_reattach_port()
779 speed = udev->speed; in uhub_reattach_port()
782 if (speed == USB_SPEED_SUPER) { in uhub_reattach_port()
784 portno, 128 - (2 * udev->depth)); in uhub_reattach_port()
791 portno, 128 - (2 * udev->depth)); in uhub_reattach_port()
804 if (udev->parent_hub != NULL) { in uhub_reattach_port()
806 mode = udev->parent_hub->flags.usb_mode; in uhub_reattach_port()
807 } else if (sc->sc_st.port_status & UPS_PORT_MODE_DEVICE) in uhub_reattach_port()
813 child = usb_alloc_device(sc->sc_dev, udev->bus, udev, in uhub_reattach_port()
814 udev->depth + 1, portno - 1, portno, speed, mode); in uhub_reattach_port()
830 if (sc->sc_st.port_status & UPS_PORT_ENABLED) { in uhub_reattach_port()
832 sc->sc_udev, NULL, in uhub_reattach_port()
843 /*------------------------------------------------------------------------*
849 *------------------------------------------------------------------------*/
855 switch (udev->speed) { in usb_device_20_compatible()
865 /*------------------------------------------------------------------------*
871 *------------------------------------------------------------------------*/
882 udev = sc->sc_udev; in uhub_suspend_resume_port()
883 child = usb_bus_port_get_device(udev->bus, in uhub_suspend_resume_port()
884 udev->hub->ports + portno - 1); in uhub_suspend_resume_port()
910 if (sc->sc_st.port_status & UPS_SUSPEND) { in uhub_suspend_resume_port()
916 switch (UPS_PORT_LINK_STATE_GET(sc->sc_st.port_status)) { in uhub_suspend_resume_port()
936 * This code handle two cases: 1) Host Mode - we can only in uhub_suspend_resume_port()
937 * receive resume here 2) Device Mode - we can receive in uhub_suspend_resume_port()
942 else if (child->flags.usb_mode == USB_MODE_DEVICE) in uhub_suspend_resume_port()
949 /*------------------------------------------------------------------------*
955 *------------------------------------------------------------------------*/
967 switch (udev->speed) { in uhub_is_too_deep()
971 if (udev->depth > USB_HUB_MAX_DEPTH) in uhub_is_too_deep()
975 if (udev->depth > USB_SS_HUB_DEPTH_MAX) in uhub_is_too_deep()
984 /*------------------------------------------------------------------------*
990 *------------------------------------------------------------------------*/
1003 hub = udev->hub; in uhub_explore()
1004 sc = hub->hubsoftc; in uhub_explore()
1006 DPRINTFN(11, "udev=%p addr=%d\n", udev, udev->address); in uhub_explore()
1013 if (udev->flags.self_suspended) { in uhub_explore()
1020 * Make sure we don't race against user-space applications in uhub_explore()
1027 * Note that hub->nports cannot be zero. in uhub_explore()
1031 for (x = 0; x != hub->nports; x++) { in uhub_explore()
1032 up = hub->ports + x; in uhub_explore()
1039 if (sc->sc_st.port_change & UPS_C_OVERCURRENT_INDICATOR) { in uhub_explore()
1046 if (!(sc->sc_flags & UHUB_FLAG_DID_EXPLORE)) { in uhub_explore()
1051 sc->sc_st.port_change |= in uhub_explore()
1054 if (sc->sc_st.port_change & UPS_C_PORT_ENABLED) { in uhub_explore()
1059 if (sc->sc_st.port_change & UPS_C_CONNECT_STATUS) { in uhub_explore()
1064 } else if (sc->sc_st.port_status & UPS_PORT_ENABLED) { in uhub_explore()
1068 if (up->restartcnt == USB_RESTART_MAX) { in uhub_explore()
1069 /* XXX could try another speed ? */ in uhub_explore()
1073 sc->sc_st.port_change |= in uhub_explore()
1075 up->restartcnt++; in uhub_explore()
1079 if (sc->sc_st.port_change & UPS_C_CONNECT_STATUS) { in uhub_explore()
1084 if (sc->sc_st.port_change & (UPS_C_SUSPEND | in uhub_explore()
1090 if (udev->speed == USB_SPEED_SUPER && in uhub_explore()
1091 (sc->sc_st.port_change & UPS_C_BH_PORT_RESET) != 0) { in uhub_explore()
1098 if (sc->sc_st.port_change & UPS_C_PORT_RESET) { in uhub_explore()
1107 /* explore succeeded - reset restart counter */ in uhub_explore()
1108 up->restartcnt = 0; in uhub_explore()
1116 sc->sc_flags |= UHUB_FLAG_DID_EXPLORE; in uhub_explore()
1126 if (uaa->usb_mode != USB_MODE_HOST) in uhub_probe()
1133 if (uaa->info.bConfigIndex == 0 && in uhub_probe()
1134 uaa->info.bDeviceClass == UDCLASS_HUB) in uhub_probe()
1150 if (udev->ddesc.bDeviceClass != UDCLASS_HUB) in uhub_query_info()
1156 switch (udev->speed) { in uhub_query_info()
1171 if (udev->speed == USB_SPEED_HIGH) in uhub_query_info()
1206 struct usb_device *udev = uaa->device; in uhub_attach()
1207 struct usb_device *parent_hub = udev->parent_hub; in uhub_attach()
1223 sc->sc_udev = udev; in uhub_attach()
1224 sc->sc_dev = dev; in uhub_attach()
1226 mtx_init(&sc->sc_mtx, "USB HUB mutex", NULL, MTX_DEF); in uhub_attach()
1231 "parent->selfpowered=%d\n", in uhub_attach()
1232 udev->depth, in uhub_attach()
1233 udev->flags.self_powered, in uhub_attach()
1236 parent_hub->flags.self_powered : 0); in uhub_attach()
1240 "exceeds maximum. HUB ignored\n", (int)udev->depth); in uhub_attach()
1244 if (!udev->flags.self_powered && parent_hub && in uhub_attach()
1245 !parent_hub->flags.self_powered) { in uhub_attach()
1264 switch (udev->speed) { in uhub_attach()
1305 if (udev->parent_hub != NULL) { in uhub_attach()
1307 udev->depth - 1); in uhub_attach()
1330 if (nports > ((udev->parent_hub != NULL) ? 15 : 127)) { in uhub_attach()
1366 hub = malloc(sizeof(hub[0]) + (sizeof(hub->ports[0]) * nports), in uhub_attach()
1372 hub = &sc->sc_hub; in uhub_attach()
1374 udev->hub = hub; in uhub_attach()
1377 hub->hubsoftc = sc; in uhub_attach()
1378 hub->explore = &uhub_explore; in uhub_attach()
1379 hub->nports = nports; in uhub_attach()
1380 hub->hubudev = udev; in uhub_attach()
1382 hub->tt_msg[0].hdr.pm_callback = &uhub_reset_tt_proc; in uhub_attach()
1383 hub->tt_msg[0].udev = udev; in uhub_attach()
1384 hub->tt_msg[1].hdr.pm_callback = &uhub_reset_tt_proc; in uhub_attach()
1385 hub->tt_msg[1].udev = udev; in uhub_attach()
1388 if (udev->flags.self_powered) { in uhub_attach()
1389 hub->portpower = USB_MAX_POWER; in uhub_attach()
1391 hub->portpower = USB_MIN_POWER; in uhub_attach()
1396 if (udev->parent_hub == NULL) { in uhub_attach()
1401 err = usbd_transfer_setup(udev, &iface_index, sc->sc_xfer, in uhub_attach()
1402 uhub_config, UHUB_N_TRANSFER, sc, &sc->sc_mtx); in uhub_attach()
1421 &sc->sc_disable_enumeration, 0, in uhub_attach()
1426 &sc->sc_disable_port_power, 0, in uhub_attach()
1461 struct usb_port *up = hub->ports + x; in uhub_attach()
1463 up->device_index = 0; in uhub_attach()
1464 up->restartcnt = 0; in uhub_attach()
1468 switch (udev->speed) { in uhub_attach()
1488 sc->sc_disable_port_power != 0) { in uhub_attach()
1516 removable, udev->flags.self_powered ? "self" : "bus"); in uhub_attach()
1520 USB_MTX_LOCK(&sc->sc_mtx); in uhub_attach()
1521 usbd_transfer_start(sc->sc_xfer[UHUB_INTR_TRANSFER]); in uhub_attach()
1522 USB_MTX_UNLOCK(&sc->sc_mtx); in uhub_attach()
1531 usbd_transfer_unsetup(sc->sc_xfer, UHUB_N_TRANSFER); in uhub_attach()
1534 free(udev->hub, M_USBDEV); in uhub_attach()
1536 udev->hub = NULL; in uhub_attach()
1538 mtx_destroy(&sc->sc_mtx); in uhub_attach()
1551 struct usb_hub *hub = sc->sc_udev->hub; in uhub_detach()
1552 struct usb_bus *bus = sc->sc_udev->bus; in uhub_detach()
1560 usbd_transfer_unsetup(sc->sc_xfer, UHUB_N_TRANSFER); in uhub_detach()
1563 for (x = 0; x != hub->nports; x++) { in uhub_detach()
1564 child = usb_bus_port_get_device(bus, hub->ports + x); in uhub_detach()
1580 &hub->tt_msg[0], &hub->tt_msg[1]); in uhub_detach()
1587 sc->sc_udev->hub = NULL; in uhub_detach()
1589 mtx_destroy(&sc->sc_mtx); in uhub_detach()
1598 /* Sub-devices are not suspended here! */ in uhub_suspend()
1606 /* Sub-devices are not resumed here! */ in uhub_resume()
1626 nports = hub->nports; in uhub_find_iface_index()
1628 udev = usb_bus_port_get_device(hub->hubudev->bus, in uhub_find_iface_index()
1629 hub->ports + x); in uhub_find_iface_index()
1636 (iface->subdev == child)) { in uhub_find_iface_index()
1637 res->iface_index = i; in uhub_find_iface_index()
1638 res->udev = udev; in uhub_find_iface_index()
1639 res->portno = x + 1; in uhub_find_iface_index()
1644 res->iface_index = 0; in uhub_find_iface_index()
1645 res->udev = NULL; in uhub_find_iface_index()
1646 res->portno = 0; in uhub_find_iface_index()
1660 hub = sc->sc_udev->hub; in uhub_child_location()
1673 , device_get_unit(res.udev->bus->bdev) in uhub_child_location()
1674 , (res.udev->parent_hub != NULL) ? in uhub_child_location()
1675 res.udev->parent_hub->device_index : 0 in uhub_child_location()
1676 , res.portno, res.udev->device_index, res.iface_index in uhub_child_location()
1678 , res.udev->ugen_name in uhub_child_location()
1702 hub = sc->sc_udev->hub; in uhub_get_device_path()
1710 sbuf_printf(sb, "/USB(0x%x,0x%x)", res.portno - 1, res.iface_index); in uhub_get_device_path()
1733 hub = sc->sc_udev->hub; in uhub_child_pnpinfo()
1742 if (iface && iface->idesc) { in uhub_child_pnpinfo()
1754 UGETW(res.udev->ddesc.idVendor), in uhub_child_pnpinfo()
1755 UGETW(res.udev->ddesc.idProduct), in uhub_child_pnpinfo()
1756 res.udev->ddesc.bDeviceClass, in uhub_child_pnpinfo()
1757 res.udev->ddesc.bDeviceSubClass, in uhub_child_pnpinfo()
1758 res.udev->ddesc.bDeviceProtocol, in uhub_child_pnpinfo()
1760 UGETW(res.udev->ddesc.bcdDevice), in uhub_child_pnpinfo()
1761 (res.udev->flags.usb_mode == USB_MODE_HOST) ? "host" : "device", in uhub_child_pnpinfo()
1762 iface->idesc->bInterfaceClass, in uhub_child_pnpinfo()
1763 iface->idesc->bInterfaceSubClass, in uhub_child_pnpinfo()
1764 iface->idesc->bInterfaceProtocol, in uhub_child_pnpinfo()
1765 iface->pnpinfo ? " " : "", in uhub_child_pnpinfo()
1766 iface->pnpinfo ? iface->pnpinfo : ""); in uhub_child_pnpinfo()
1781 * When doing LOW- and FULL-speed USB transfers across a HIGH-speed
1793 * provides, only 6 are available for non-HIGH-speed devices. I have
1807 /*------------------------------------------------------------------------*
1812 *------------------------------------------------------------------------*/
1817 usb_size_t min = (usb_size_t)-1; in usb_intr_find_best_slot()
1832 if (mask & (1U << (z - x))) in usb_intr_find_best_slot()
1836 /* check if the current multi-slot is more optimal */ in usb_intr_find_best_slot()
1843 if (mask & (1U << (end - 1 - x))) in usb_intr_find_best_slot()
1849 /*------------------------------------------------------------------------*
1856 * bandwidth. The "mask" argument is used for multi-slot allocations.
1860 *------------------------------------------------------------------------*/
1865 struct usb_bus *bus = udev->bus; in usb_hs_bandwidth_adjust()
1867 enum usb_dev_speed speed; in usb_hs_bandwidth_adjust() local
1872 speed = usbd_get_speed(udev); in usb_hs_bandwidth_adjust()
1874 switch (speed) { in usb_hs_bandwidth_adjust()
1877 if (speed == USB_SPEED_LOW) { in usb_hs_bandwidth_adjust()
1887 hub = udev->parent_hs_hub->hub; in usb_hs_bandwidth_adjust()
1889 slot = usb_intr_find_best_slot(hub->uframe_usage, in usb_hs_bandwidth_adjust()
1893 if (mask & (1U << (x - slot))) { in usb_hs_bandwidth_adjust()
1894 hub->uframe_usage[x] += len; in usb_hs_bandwidth_adjust()
1895 bus->uframe_usage[x] += len; in usb_hs_bandwidth_adjust()
1901 slot = usb_intr_find_best_slot(bus->uframe_usage, 0, in usb_hs_bandwidth_adjust()
1905 if (mask & (1U << (x - slot))) { in usb_hs_bandwidth_adjust()
1906 bus->uframe_usage[x] += len; in usb_hs_bandwidth_adjust()
1914 /*------------------------------------------------------------------------*
1918 *------------------------------------------------------------------------*/
1925 uint8_t speed; in usb_hs_bandwidth_alloc() local
1927 udev = xfer->xroot->udev; in usb_hs_bandwidth_alloc()
1929 if (udev->flags.usb_mode != USB_MODE_HOST) in usb_hs_bandwidth_alloc()
1932 xfer->endpoint->refcount_bw++; in usb_hs_bandwidth_alloc()
1933 if (xfer->endpoint->refcount_bw != 1) in usb_hs_bandwidth_alloc()
1936 speed = usbd_get_speed(udev); in usb_hs_bandwidth_alloc()
1938 switch (xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) { in usb_hs_bandwidth_alloc()
1944 xfer->max_frame_size, USB_HS_MICRO_FRAMES_MAX, mask); in usb_hs_bandwidth_alloc()
1946 xfer->endpoint->usb_uframe = slot; in usb_hs_bandwidth_alloc()
1947 xfer->endpoint->usb_smask = mask << slot; in usb_hs_bandwidth_alloc()
1949 if ((speed != USB_SPEED_FULL) && in usb_hs_bandwidth_alloc()
1950 (speed != USB_SPEED_LOW)) { in usb_hs_bandwidth_alloc()
1951 xfer->endpoint->usb_cmask = 0x00 ; in usb_hs_bandwidth_alloc()
1953 xfer->endpoint->usb_cmask = (-(0x04 << slot)) & 0xFE; in usb_hs_bandwidth_alloc()
1973 /* allocate a microframe multi-slot */ in usb_hs_bandwidth_alloc()
1976 xfer->max_frame_size, USB_HS_MICRO_FRAMES_MAX, mask); in usb_hs_bandwidth_alloc()
1978 xfer->endpoint->usb_uframe = slot; in usb_hs_bandwidth_alloc()
1979 xfer->endpoint->usb_cmask = 0; in usb_hs_bandwidth_alloc()
1980 xfer->endpoint->usb_smask = mask << slot; in usb_hs_bandwidth_alloc()
1984 xfer->endpoint->usb_uframe = 0; in usb_hs_bandwidth_alloc()
1985 xfer->endpoint->usb_cmask = 0; in usb_hs_bandwidth_alloc()
1986 xfer->endpoint->usb_smask = 0; in usb_hs_bandwidth_alloc()
1991 xfer->endpoint->usb_uframe, in usb_hs_bandwidth_alloc()
1992 xfer->endpoint->usb_smask >> xfer->endpoint->usb_uframe); in usb_hs_bandwidth_alloc()
1995 /*------------------------------------------------------------------------*
1999 *------------------------------------------------------------------------*/
2007 udev = xfer->xroot->udev; in usb_hs_bandwidth_free()
2009 if (udev->flags.usb_mode != USB_MODE_HOST) in usb_hs_bandwidth_free()
2012 xfer->endpoint->refcount_bw--; in usb_hs_bandwidth_free()
2013 if (xfer->endpoint->refcount_bw != 0) in usb_hs_bandwidth_free()
2016 switch (xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) { in usb_hs_bandwidth_free()
2020 slot = xfer->endpoint->usb_uframe; in usb_hs_bandwidth_free()
2021 mask = xfer->endpoint->usb_smask; in usb_hs_bandwidth_free()
2025 -xfer->max_frame_size, slot, mask >> slot); in usb_hs_bandwidth_free()
2030 xfer->endpoint->usb_uframe = 0; in usb_hs_bandwidth_free()
2031 xfer->endpoint->usb_cmask = 0; in usb_hs_bandwidth_free()
2032 xfer->endpoint->usb_smask = 0; in usb_hs_bandwidth_free()
2040 /*------------------------------------------------------------------------*
2043 * This function will expand the time counter from 7-bit to 16-bit.
2046 * 16-bit isochronous time counter.
2047 *------------------------------------------------------------------------*/
2055 rem = bus->isoc_time_last & (USB_ISOC_TIME_MAX - 1); in usb_isoc_time_expand()
2057 isoc_time_curr &= (USB_ISOC_TIME_MAX - 1); in usb_isoc_time_expand()
2061 bus->isoc_time_last += USB_ISOC_TIME_MAX; in usb_isoc_time_expand()
2065 bus->isoc_time_last &= ~(USB_ISOC_TIME_MAX - 1); in usb_isoc_time_expand()
2066 bus->isoc_time_last |= isoc_time_curr; in usb_isoc_time_expand()
2068 return (bus->isoc_time_last); in usb_isoc_time_expand()
2071 /*------------------------------------------------------------------------*
2074 * This function will allocate bandwidth for an isochronous FULL speed
2075 * transaction in the FULL speed schedule.
2080 *------------------------------------------------------------------------*/
2097 bus = isoc_xfer->xroot->bus; in usbd_fs_isoc_schedule_alloc_slot()
2099 TAILQ_FOREACH(xfer, &bus->intr_q.head, wait_entry) { in usbd_fs_isoc_schedule_alloc_slot()
2107 if (xfer->xroot->udev->parent_hs_hub != in usbd_fs_isoc_schedule_alloc_slot()
2108 isoc_xfer->xroot->udev->parent_hs_hub) { in usbd_fs_isoc_schedule_alloc_slot()
2111 if ((isoc_xfer->xroot->udev->parent_hs_hub-> in usbd_fs_isoc_schedule_alloc_slot()
2113 (xfer->xroot->udev->hs_port_no != in usbd_fs_isoc_schedule_alloc_slot()
2114 isoc_xfer->xroot->udev->hs_port_no)) { in usbd_fs_isoc_schedule_alloc_slot()
2117 if (xfer->endpoint->methods != isoc_xfer->endpoint->methods) in usbd_fs_isoc_schedule_alloc_slot()
2122 delta = xfer->isoc_time_complete - isoc_time; in usbd_fs_isoc_schedule_alloc_slot()
2123 if (delta > 0 && delta <= xfer->nframes) { in usbd_fs_isoc_schedule_alloc_slot()
2124 delta = xfer->nframes - delta; in usbd_fs_isoc_schedule_alloc_slot()
2126 len = xfer->frlengths[delta]; in usbd_fs_isoc_schedule_alloc_slot()
2138 TAILQ_FOREACH(pipe_xfer, &xfer->endpoint->endpoint_q[0].head, in usbd_fs_isoc_schedule_alloc_slot()
2147 delta = pipe_xfer->isoc_time_complete - isoc_time; in usbd_fs_isoc_schedule_alloc_slot()
2148 if (delta > 0 && delta <= pipe_xfer->nframes) { in usbd_fs_isoc_schedule_alloc_slot()
2149 delta = pipe_xfer->nframes - delta; in usbd_fs_isoc_schedule_alloc_slot()
2151 len = pipe_xfer->frlengths[delta]; in usbd_fs_isoc_schedule_alloc_slot()
2162 data_len -= USB_FS_BYTES_PER_HS_UFRAME; in usbd_fs_isoc_schedule_alloc_slot()
2173 delta = isoc_xfer->isoc_time_complete - isoc_time; in usbd_fs_isoc_schedule_alloc_slot()
2174 if (delta > 0 && delta <= isoc_xfer->nframes) { in usbd_fs_isoc_schedule_alloc_slot()
2175 delta = isoc_xfer->nframes - delta; in usbd_fs_isoc_schedule_alloc_slot()
2177 len = isoc_xfer->frlengths[delta]; in usbd_fs_isoc_schedule_alloc_slot()
2186 data_len -= USB_FS_BYTES_PER_HS_UFRAME; in usbd_fs_isoc_schedule_alloc_slot()
2199 /*------------------------------------------------------------------------*
2203 *------------------------------------------------------------------------*/
2211 if (up->device_index == 0) { in usb_bus_port_get_device()
2215 return (bus->devices[up->device_index]); in usb_bus_port_get_device()
2218 /*------------------------------------------------------------------------*
2222 *------------------------------------------------------------------------*/
2237 up->device_index = device_index; in usb_bus_port_set_device()
2239 device_index = up->device_index; in usb_bus_port_set_device()
2240 up->device_index = 0; in usb_bus_port_set_device()
2250 bus->devices[device_index] = udev; in usb_bus_port_set_device()
2261 /*------------------------------------------------------------------------*
2265 *------------------------------------------------------------------------*/
2282 if ((bus->devices == NULL) || in usb_needs_explore()
2283 (bus->devices[USB_ROOT_HUB_ADDR] == NULL)) { in usb_needs_explore()
2287 if (mtx_owned(&bus->bus_mtx)) { in usb_needs_explore()
2294 bus->do_probe = 1; in usb_needs_explore()
2297 &bus->explore_msg[0], &bus->explore_msg[1])) { in usb_needs_explore()
2305 /*------------------------------------------------------------------------*
2309 * cause that all USB buses are re-explored.
2310 *------------------------------------------------------------------------*/
2338 max--; in usb_needs_explore_all()
2342 /*------------------------------------------------------------------------*
2347 *------------------------------------------------------------------------*/
2358 DPRINTFN(-1, "Cold variable is still set!\n"); in usb_needs_explore_init()
2362 /*------------------------------------------------------------------------*
2368 *------------------------------------------------------------------------*/
2377 /*------------------------------------------------------------------------*
2383 *------------------------------------------------------------------------*/
2399 udev = xfer->xroot->udev; in usbd_transfer_power_ref()
2401 if (udev->device_index == USB_ROOT_HUB_ADDR) { in usbd_transfer_power_ref()
2405 USB_BUS_LOCK(udev->bus); in usbd_transfer_power_ref()
2407 xfer_type = xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE; in usbd_transfer_power_ref()
2409 udev->pwr_save.last_xfer_time = ticks; in usbd_transfer_power_ref()
2410 udev->pwr_save.type_refs[xfer_type] += val; in usbd_transfer_power_ref()
2412 if (xfer->flags_int.control_xfr) { in usbd_transfer_power_ref()
2413 udev->pwr_save.read_refs += val; in usbd_transfer_power_ref()
2414 if (xfer->flags_int.usb_mode == USB_MODE_HOST) { in usbd_transfer_power_ref()
2419 udev->pwr_save.write_refs += val; in usbd_transfer_power_ref()
2422 udev->pwr_save.read_refs += val; in usbd_transfer_power_ref()
2424 udev->pwr_save.write_refs += val; in usbd_transfer_power_ref()
2428 if (udev->flags.self_suspended) in usbd_transfer_power_ref()
2433 if (!(udev->bus->hw_power_state & power_mask[xfer_type])) { in usbd_transfer_power_ref()
2435 udev->bus->hw_power_state |= power_mask[xfer_type]; in usbd_transfer_power_ref()
2445 USB_BUS_UNLOCK(udev->bus); in usbd_transfer_power_ref()
2449 usb_bus_power_update(udev->bus); in usbd_transfer_power_ref()
2452 if (udev->bus->methods->set_hw_power != NULL) { in usbd_transfer_power_ref()
2453 (udev->bus->methods->set_hw_power) (udev->bus); in usbd_transfer_power_ref()
2459 /*------------------------------------------------------------------------*
2462 * This function returns non-zero if the current device should wake up.
2463 *------------------------------------------------------------------------*/
2467 return (((udev->power_mode == USB_POWER_MODE_ON) && in usb_peer_should_wakeup()
2468 (udev->flags.usb_mode == USB_MODE_HOST)) || in usb_peer_should_wakeup()
2469 (udev->driver_added_refcount != udev->bus->driver_added_refcount) || in usb_peer_should_wakeup()
2470 (udev->re_enumerate_wait != USB_RE_ENUM_DONE) || in usb_peer_should_wakeup()
2471 (udev->pwr_save.type_refs[UE_ISOCHRONOUS] != 0) || in usb_peer_should_wakeup()
2472 (udev->pwr_save.write_refs != 0) || in usb_peer_should_wakeup()
2473 ((udev->pwr_save.read_refs != 0) && in usb_peer_should_wakeup()
2474 (udev->flags.usb_mode == USB_MODE_HOST) && in usb_peer_should_wakeup()
2478 /*------------------------------------------------------------------------*
2483 *------------------------------------------------------------------------*/
2497 limit = hz; in usb_bus_powerd()
2499 limit = 255 * hz; in usb_bus_powerd()
2501 limit = limit * hz; in usb_bus_powerd()
2512 x != bus->devices_max; x++) { in usb_bus_powerd()
2513 udev = bus->devices[x]; in usb_bus_powerd()
2517 temp = ticks - udev->pwr_save.last_xfer_time; in usb_bus_powerd()
2521 if (udev->flags.self_suspended != 0) { in usb_bus_powerd()
2527 (udev->flags.usb_mode == USB_MODE_HOST) && in usb_bus_powerd()
2528 (udev->flags.self_suspended == 0)) { in usb_bus_powerd()
2539 mintime = (usb_ticks_t)-1; in usb_bus_powerd()
2546 /* Re-loop all the devices to get the actual state */ in usb_bus_powerd()
2549 x != bus->devices_max; x++) { in usb_bus_powerd()
2550 udev = bus->devices[x]; in usb_bus_powerd()
2554 /* we found a non-Root-Hub USB device */ in usb_bus_powerd()
2558 temp = ticks - udev->pwr_save.last_xfer_time; in usb_bus_powerd()
2567 if (udev->flags.self_suspended == 0) { in usb_bus_powerd()
2568 type_refs[0] += udev->pwr_save.type_refs[0]; in usb_bus_powerd()
2569 type_refs[1] += udev->pwr_save.type_refs[1]; in usb_bus_powerd()
2570 type_refs[2] += udev->pwr_save.type_refs[2]; in usb_bus_powerd()
2571 type_refs[3] += udev->pwr_save.type_refs[3]; in usb_bus_powerd()
2575 if (mintime >= (usb_ticks_t)(1 * hz)) { in usb_bus_powerd()
2578 bus->hw_power_state = 0; in usb_bus_powerd()
2580 bus->hw_power_state |= USB_HW_POWER_CONTROL; in usb_bus_powerd()
2582 bus->hw_power_state |= USB_HW_POWER_BULK; in usb_bus_powerd()
2584 bus->hw_power_state |= USB_HW_POWER_INTERRUPT; in usb_bus_powerd()
2586 bus->hw_power_state |= USB_HW_POWER_ISOC; in usb_bus_powerd()
2588 bus->hw_power_state |= USB_HW_POWER_NON_ROOT_HUB; in usb_bus_powerd()
2592 if (bus->methods->set_hw_power != NULL) { in usb_bus_powerd()
2594 (bus->methods->set_hw_power) (bus); in usb_bus_powerd()
2644 /*------------------------------------------------------------------------*
2649 *------------------------------------------------------------------------*/
2661 if (udev->flags.self_suspended == 0) in usb_dev_resume_peer()
2665 if (udev->parent_hub == NULL) in usb_dev_resume_peer()
2670 if ((udev->flags.usb_mode == USB_MODE_DEVICE) && in usb_dev_resume_peer()
2671 (udev->flags.remote_wakeup == 0)) { in usb_dev_resume_peer()
2680 bus = udev->bus; in usb_dev_resume_peer()
2683 usb_dev_resume_peer(udev->parent_hub); in usb_dev_resume_peer()
2690 err = usbd_req_clear_port_feature(udev->parent_hub, in usb_dev_resume_peer()
2691 NULL, udev->port_no, UHF_PORT_SUSPEND); in usb_dev_resume_peer()
2694 err = usbd_req_set_port_link_state(udev->parent_hub, in usb_dev_resume_peer()
2695 NULL, udev->port_no, UPS_PORT_LS_U0); in usb_dev_resume_peer()
2706 if (bus->methods->device_resume != NULL) { in usb_dev_resume_peer()
2708 (bus->methods->device_resume) (udev); in usb_dev_resume_peer()
2712 udev->flags.self_suspended = 0; in usb_dev_resume_peer()
2715 udev->pwr_save.last_xfer_time = ticks; in usb_dev_resume_peer()
2718 if (udev->pwr_save.type_refs[UE_CONTROL] != 0) in usb_dev_resume_peer()
2719 bus->hw_power_state |= USB_HW_POWER_CONTROL; in usb_dev_resume_peer()
2720 if (udev->pwr_save.type_refs[UE_BULK] != 0) in usb_dev_resume_peer()
2721 bus->hw_power_state |= USB_HW_POWER_BULK; in usb_dev_resume_peer()
2722 if (udev->pwr_save.type_refs[UE_INTERRUPT] != 0) in usb_dev_resume_peer()
2723 bus->hw_power_state |= USB_HW_POWER_INTERRUPT; in usb_dev_resume_peer()
2724 if (udev->pwr_save.type_refs[UE_ISOCHRONOUS] != 0) in usb_dev_resume_peer()
2725 bus->hw_power_state |= USB_HW_POWER_ISOC; in usb_dev_resume_peer()
2729 if (bus->methods->set_hw_power != NULL) { in usb_dev_resume_peer()
2731 (bus->methods->set_hw_power) (bus); in usb_dev_resume_peer()
2736 /* notify all sub-devices about resume */ in usb_dev_resume_peer()
2753 /*------------------------------------------------------------------------*
2758 *------------------------------------------------------------------------*/
2773 if (udev->flags.self_suspended) in usb_dev_suspend_peer()
2777 if (udev->parent_hub == NULL) in usb_dev_suspend_peer()
2783 if (udev->hub != NULL) { in usb_dev_suspend_peer()
2784 nports = udev->hub->nports; in usb_dev_suspend_peer()
2788 child = usb_bus_port_get_device(udev->bus, in usb_dev_suspend_peer()
2789 udev->hub->ports + x); in usb_dev_suspend_peer()
2794 if (child->flags.self_suspended) in usb_dev_suspend_peer()
2805 * "udev->flags.self_suspended": in usb_dev_suspend_peer()
2816 USB_BUS_LOCK(udev->bus); in usb_dev_suspend_peer()
2828 udev->flags.self_suspended = 1; in usb_dev_suspend_peer()
2830 USB_BUS_UNLOCK(udev->bus); in usb_dev_suspend_peer()
2842 if (udev->flags.usb_mode == USB_MODE_DEVICE) { in usb_dev_suspend_peer()
2844 usb_dev_resume_peer(udev->parent_hub); in usb_dev_suspend_peer()
2850 err = usbd_req_clear_port_feature(udev->parent_hub, in usb_dev_suspend_peer()
2851 NULL, udev->port_no, UHF_PORT_SUSPEND); in usb_dev_suspend_peer()
2862 /* notify all sub-devices about suspend */ in usb_dev_suspend_peer()
2867 if (udev->bus->methods->device_suspend != NULL) { in usb_dev_suspend_peer()
2871 (udev->bus->methods->device_suspend) (udev); in usb_dev_suspend_peer()
2881 err = usbd_req_set_port_feature(udev->parent_hub, in usb_dev_suspend_peer()
2882 NULL, udev->port_no, UHF_PORT_SUSPEND); in usb_dev_suspend_peer()
2889 err = usbd_req_set_port_link_state(udev->parent_hub, in usb_dev_suspend_peer()
2890 NULL, udev->port_no, UPS_PORT_LS_U3); in usb_dev_suspend_peer()
2897 udev = udev->parent_hub; in usb_dev_suspend_peer()
2901 /*------------------------------------------------------------------------*
2906 *------------------------------------------------------------------------*/
2917 udev->power_mode = power_mode; /* update copy of power mode */ in usbd_set_power_mode()
2920 usb_bus_power_update(udev->bus); in usbd_set_power_mode()
2922 usb_needs_explore(udev->bus, 0 /* no probe */ ); in usbd_set_power_mode()
2926 /*------------------------------------------------------------------------*
2930 *------------------------------------------------------------------------*/
2937 mtod = udev->bus->methods; in usbd_filter_power_mode()
2938 temp = -1; in usbd_filter_power_mode()
2940 if (mtod->get_power_mode != NULL) in usbd_filter_power_mode()
2941 (mtod->get_power_mode) (udev, &temp); in usbd_filter_power_mode()
2951 /*------------------------------------------------------------------------*
2954 * This function starts re-enumeration of the given USB device. This
2955 * function does not need to be called BUS-locked. This function does
2956 * not wait until the re-enumeration is completed.
2957 *------------------------------------------------------------------------*/
2961 if (udev->re_enumerate_wait == USB_RE_ENUM_DONE) { in usbd_start_re_enumerate()
2962 udev->re_enumerate_wait = USB_RE_ENUM_START; in usbd_start_re_enumerate()
2963 usb_needs_explore(udev->bus, 0); in usbd_start_re_enumerate()
2967 /*-----------------------------------------------------------------------*
2971 * does not need to be called BUS-locked. This function does not wait
2973 *------------------------------------------------------------------------*/
2977 if (udev->re_enumerate_wait == USB_RE_ENUM_DONE) { in usbd_start_set_config()
2978 if (udev->curr_config_index == index) { in usbd_start_set_config()
2982 udev->next_config_index = index; in usbd_start_set_config()
2983 udev->re_enumerate_wait = USB_RE_ENUM_SET_CONFIG; in usbd_start_set_config()
2984 usb_needs_explore(udev->bus, 0); in usbd_start_set_config()
2986 } else if (udev->re_enumerate_wait == USB_RE_ENUM_SET_CONFIG) { in usbd_start_set_config()
2987 if (udev->next_config_index == index) { in usbd_start_set_config()