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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2008-2020 Hans Petter Selasky. All rights reserved.
109 .bus_index = -1,
110 .dev_index = -1,
111 .bmRequestType_value = -1,
112 .bRequest_value = -1,
132 /*------------------------------------------------------------------------*
136 *------------------------------------------------------------------------*/
153 dbg->ds_delay = temp; in usbd_get_debug_bits()
163 dbg->ss_delay = temp; in usbd_get_debug_bits()
175 if ((temp != req->bmRequestType) && (temp >= 0) && (temp <= 255)) in usbd_get_debug_bits()
180 if ((temp != req->bRequest) && (temp >= 0) && (temp <= 255)) in usbd_get_debug_bits()
185 dbg->ds_fail = 1; in usbd_get_debug_bits()
189 dbg->ss_fail = 1; in usbd_get_debug_bits()
191 dbg->enabled = 1; in usbd_get_debug_bits()
196 /*------------------------------------------------------------------------*
201 *------------------------------------------------------------------------*/
214 cv_signal(&xfer->xroot->udev->ctrlreq_cv); in usbd_do_request_callback()
219 /*------------------------------------------------------------------------*
223 *------------------------------------------------------------------------*/
235 udev = xfer->xroot->udev; in usb_do_clear_stall_callback()
237 USB_BUS_LOCK(udev->bus); in usb_do_clear_stall_callback()
241 ep = udev->ep_curr; in usb_do_clear_stall_callback()
242 ep_end = udev->endpoints + udev->endpoints_max; in usb_do_clear_stall_callback()
243 ep_first = udev->endpoints; in usb_do_clear_stall_callback()
244 to = udev->endpoints_max; in usb_do_clear_stall_callback()
250 udev->clear_stall_errors = 0; in usb_do_clear_stall_callback()
254 if (ep->edesc && in usb_do_clear_stall_callback()
255 ep->is_stalled) { in usb_do_clear_stall_callback()
256 ep->toggle_next = 0; in usb_do_clear_stall_callback()
257 ep->is_stalled = 0; in usb_do_clear_stall_callback()
262 usb_command_wrapper(&ep->endpoint_q[x], in usb_do_clear_stall_callback()
263 ep->endpoint_q[x].curr); in usb_do_clear_stall_callback()
271 break; /* no endpoints - nothing to do */ in usb_do_clear_stall_callback()
274 if (ep->edesc && in usb_do_clear_stall_callback()
275 ep->is_stalled) { in usb_do_clear_stall_callback()
276 /* setup a clear-stall packet */ in usb_do_clear_stall_callback()
281 req.wIndex[0] = ep->edesc->bEndpointAddress; in usb_do_clear_stall_callback()
287 usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req)); in usb_do_clear_stall_callback()
291 xfer->nframes = 1; in usb_do_clear_stall_callback()
292 USB_BUS_UNLOCK(udev->bus); in usb_do_clear_stall_callback()
296 USB_BUS_LOCK(udev->bus); in usb_do_clear_stall_callback()
300 to--; in usb_do_clear_stall_callback()
311 * clear-stall which we sometimes should just ignore. in usb_do_clear_stall_callback()
317 * Some non-compliant USB devices do not implement the in usb_do_clear_stall_callback()
325 if (udev->clear_stall_errors == USB_CS_RESET_LIMIT) in usb_do_clear_stall_callback()
329 udev->clear_stall_errors = USB_CS_RESET_LIMIT; in usb_do_clear_stall_callback()
330 DPRINTF("Trying to re-enumerate.\n"); in usb_do_clear_stall_callback()
333 udev->clear_stall_errors++; in usb_do_clear_stall_callback()
334 if (udev->clear_stall_errors == USB_CS_RESET_LIMIT) { in usb_do_clear_stall_callback()
335 DPRINTF("Trying to re-enumerate.\n"); in usb_do_clear_stall_callback()
343 udev->ep_curr = ep; in usb_do_clear_stall_callback()
344 USB_BUS_UNLOCK(udev->bus); in usb_do_clear_stall_callback()
351 if (udev->flags.usb_mode == USB_MODE_DEVICE) in usbd_get_hr_func()
353 else if (udev->parent_hub == NULL) in usbd_get_hr_func()
354 return (udev->bus->methods->roothub_exec); in usbd_get_hr_func()
359 /*------------------------------------------------------------------------*
364 * "udev" - this is the "usb_device" structure pointer on which the
368 * "mtx" - if this argument is non-NULL the mutex pointed to by it
373 * "req" - this argument must always be non-NULL and points to an
374 * 8-byte structure holding the USB request to be done. The USB
378 * "data" - if the "wLength" part of the structure pointed to by "req"
379 * is non-zero this argument must point to a valid kernel buffer which
383 * "flags" - here is a list of valid flags:
395 * "actlen" - if non-NULL the actual transfer length will be stored in
396 * the 16-bit unsigned integer pointed to by "actlen". This
400 * "timeout" - gives the timeout for the control transfer in
412 *------------------------------------------------------------------------*/
441 length = UGETW(req->wLength); in usbd_do_request_flags()
445 udev, req->bmRequestType, req->bRequest, in usbd_do_request_flags()
446 req->wValue[1], req->wValue[0], in usbd_do_request_flags()
447 req->wIndex[1], req->wIndex[0], in usbd_do_request_flags()
448 req->wLength[1], req->wLength[0]); in usbd_do_request_flags()
451 if (udev->state < USB_STATE_POWERED) { in usbd_do_request_flags()
485 if (!(req->bmRequestType & UT_READ)) { in usbd_do_request_flags()
496 USB_BUS_LOCK(udev->bus); in usbd_do_request_flags()
498 USB_BUS_UNLOCK(udev->bus); in usbd_do_request_flags()
532 xfer = udev->ctrl_xfer[0]; in usbd_do_request_flags()
550 xfer->flags.manual_status = 1; in usbd_do_request_flags()
552 xfer->flags.manual_status = 0; in usbd_do_request_flags()
555 xfer->flags.short_xfer_ok = 1; in usbd_do_request_flags()
557 xfer->flags.short_xfer_ok = 0; in usbd_do_request_flags()
559 xfer->timeout = timeout; in usbd_do_request_flags()
565 usbd_copy_in(xfer->frbuffers, 0, req, sizeof(*req)); in usbd_do_request_flags()
575 if (xfer->flags.manual_status) { in usbd_do_request_flags()
586 xfer->xroot->xfer_mtx, in usbd_do_request_flags()
597 if (!(req->bmRequestType & UT_READ)) { in usbd_do_request_flags()
601 err = usbd_copy_in_user(xfer->frbuffers + 1, in usbd_do_request_flags()
610 usbd_copy_in(xfer->frbuffers + 1, in usbd_do_request_flags()
616 if (xfer->flags.manual_status) { in usbd_do_request_flags()
624 xfer->xroot->xfer_mtx, in usbd_do_request_flags()
630 xfer->flags.manual_status = 0; in usbd_do_request_flags()
641 cv_wait(&udev->ctrlreq_cv, in usbd_do_request_flags()
642 xfer->xroot->xfer_mtx); in usbd_do_request_flags()
645 err = xfer->error; in usbd_do_request_flags()
653 if (xfer->aframes < 2) { in usbd_do_request_flags()
666 if (req->bmRequestType & UT_READ) { in usbd_do_request_flags()
670 err = usbd_copy_out_user(xfer->frbuffers + 1, in usbd_do_request_flags()
679 usbd_copy_out(xfer->frbuffers + 1, in usbd_do_request_flags()
690 length -= temp; in usbd_do_request_flags()
698 delta_ticks = ticks - start_ticks; in usbd_do_request_flags()
712 * blocked in case of a non-transfer related error: in usbd_do_request_flags()
732 DPRINTF("error=%s - waiting a bit for TT cleanup\n", in usbd_do_request_flags()
734 usb_pause_mtx(mtx, hz / 16); in usbd_do_request_flags()
740 /*------------------------------------------------------------------------*
741 * usbd_do_request_proc - factored out code
749 *------------------------------------------------------------------------*/
759 len = UGETW(req->wLength); in usbd_do_request_proc()
768 err = usbd_do_request_flags(udev, pproc->up_mtx, in usbd_do_request_proc()
774 if ((len != 0) && (req->bmRequestType & UE_DIR_IN)) { in usbd_do_request_proc()
778 memset(((uint8_t *)data) + *actlen, 0, len - *actlen); in usbd_do_request_proc()
783 /*------------------------------------------------------------------------*
793 *------------------------------------------------------------------------*/
871 /*------------------------------------------------------------------------*
876 * mandatory for LOW-, FULL- and HIGH-speed USB HUBs and is targeted
877 * for SUPER-speed USB HUBs.
883 *------------------------------------------------------------------------*/
970 /*------------------------------------------------------------------------*
981 * pointer is non-NULL, the actual length of the transfer will get
982 * stored in the 16-bit unsigned integer which it is pointing to. The
993 *------------------------------------------------------------------------*/
1053 retries--; in usbd_req_get_desc()
1055 usb_pause_mtx(mtx, hz / 5); in usbd_req_get_desc()
1078 min_len--; in usbd_req_get_desc()
1096 /*------------------------------------------------------------------------*
1107 *------------------------------------------------------------------------*/
1129 if (udev->flags.no_strings) { in usbd_req_get_string_any()
1134 (udev, mtx, buf, len, udev->langid, string_index); in usbd_req_get_string_any()
1147 len--; in usbd_req_get_string_any()
1151 n = (temp[0] / 2) - 1; in usbd_req_get_string_any()
1180 * Filter by default - We only allow alphanumerical in usbd_req_get_string_any()
1186 *s == '-' || in usbd_req_get_string_any()
1204 /*------------------------------------------------------------------------*
1213 *------------------------------------------------------------------------*/
1223 /*------------------------------------------------------------------------*
1233 *------------------------------------------------------------------------*/
1258 USB_BUS_LOCK(udev->bus); in usbd_req_get_descriptor_ptr()
1260 USB_BUS_UNLOCK(udev->bus); in usbd_req_get_descriptor_ptr()
1273 /*------------------------------------------------------------------------*
1279 *------------------------------------------------------------------------*/
1294 if (UGETW(d->wTotalLength) < (uint16_t)sizeof(*d)) { in usbd_req_get_config_desc()
1301 /*------------------------------------------------------------------------*
1310 *------------------------------------------------------------------------*/
1321 memset(udev->config_data, 0, sizeof(udev->config_data)); in usbd_alloc_config_desc()
1322 return (udev->config_data); in usbd_alloc_config_desc()
1326 /*------------------------------------------------------------------------*
1330 *------------------------------------------------------------------------*/
1339 /*------------------------------------------------------------------------*
1349 *------------------------------------------------------------------------*/
1386 USETW(cdesc->wTotalLength, len); in usbd_req_get_config_desc_full()
1393 /*------------------------------------------------------------------------*
1399 *------------------------------------------------------------------------*/
1409 /*------------------------------------------------------------------------*
1415 *------------------------------------------------------------------------*/
1423 if ((iface == NULL) || (iface->idesc == NULL)) in usbd_req_get_alt_interface_no()
1429 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_get_alt_interface_no()
1435 /*------------------------------------------------------------------------*
1441 *------------------------------------------------------------------------*/
1450 if ((iface == NULL) || (iface->idesc == NULL)) in usbd_req_set_alt_interface_no()
1457 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_set_alt_interface_no()
1461 if (err == USB_ERR_STALLED && iface->num_altsetting == 1) { in usbd_req_set_alt_interface_no()
1473 /*------------------------------------------------------------------------*
1479 *------------------------------------------------------------------------*/
1494 /*------------------------------------------------------------------------*
1500 *------------------------------------------------------------------------*/
1516 /*------------------------------------------------------------------------*
1522 *------------------------------------------------------------------------*/
1528 uint16_t len = sizeof(*hd) - 32 + 1 + ((nports + 7) / 8); in usbd_req_get_ss_hub_descriptor()
1538 /*------------------------------------------------------------------------*
1544 *------------------------------------------------------------------------*/
1559 /*------------------------------------------------------------------------*
1568 *------------------------------------------------------------------------*/
1586 if (udev->bus->methods->set_address != NULL) in usbd_req_set_address()
1587 err = (udev->bus->methods->set_address) (udev, mtx, addr); in usbd_req_set_address()
1604 /*------------------------------------------------------------------------*
1610 *------------------------------------------------------------------------*/
1627 /*------------------------------------------------------------------------*
1633 *------------------------------------------------------------------------*/
1648 /*------------------------------------------------------------------------*
1654 *------------------------------------------------------------------------*/
1669 /*------------------------------------------------------------------------*
1675 *------------------------------------------------------------------------*/
1691 /*------------------------------------------------------------------------*
1697 *------------------------------------------------------------------------*/
1713 /*------------------------------------------------------------------------*
1719 *------------------------------------------------------------------------*/
1734 /*------------------------------------------------------------------------*
1740 *------------------------------------------------------------------------*/
1756 /*------------------------------------------------------------------------*
1762 *------------------------------------------------------------------------*/
1778 /*------------------------------------------------------------------------*
1784 *------------------------------------------------------------------------*/
1787 uint8_t iface_index, uint16_t report) in usbd_req_set_protocol() argument
1792 if ((iface == NULL) || (iface->idesc == NULL)) { in usbd_req_set_protocol()
1795 DPRINTFN(5, "iface=%p, report=%d, endpt=%d\n", in usbd_req_set_protocol()
1796 iface, report, iface->idesc->bInterfaceNumber); in usbd_req_set_protocol()
1800 USETW(req.wValue, report); in usbd_req_set_protocol()
1801 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_set_protocol()
1807 /*------------------------------------------------------------------------*
1813 *------------------------------------------------------------------------*/
1821 if ((iface == NULL) || (iface->idesc == NULL)) { in usbd_req_set_report()
1829 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_set_report()
1835 /*------------------------------------------------------------------------*
1841 *------------------------------------------------------------------------*/
1849 if ((iface == NULL) || (iface->idesc == NULL)) { in usbd_req_get_report()
1857 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_get_report()
1863 /*------------------------------------------------------------------------*
1869 *------------------------------------------------------------------------*/
1877 if ((iface == NULL) || (iface->idesc == NULL)) { in usbd_req_set_idle()
1885 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_set_idle()
1891 /*------------------------------------------------------------------------*
1897 *------------------------------------------------------------------------*/
1905 if ((iface == NULL) || (iface->idesc == NULL)) { in usbd_req_get_report_descriptor()
1910 USETW2(req.wValue, UDESC_REPORT, 0); /* report id should be 0 */ in usbd_req_get_report_descriptor()
1911 req.wIndex[0] = iface->idesc->bInterfaceNumber; in usbd_req_get_report_descriptor()
1917 /*------------------------------------------------------------------------*
1927 *------------------------------------------------------------------------*/
1946 /*------------------------------------------------------------------------*
1952 *------------------------------------------------------------------------*/
1966 /*------------------------------------------------------------------------*
1968 *------------------------------------------------------------------------*/
1984 switch (udev->speed) { in usbd_setup_device_desc()
1988 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
1994 err = usbd_req_get_desc(udev, mtx, NULL, &udev->ddesc, in usbd_setup_device_desc()
1999 udev->ddesc.bMaxPacketSize = 8; in usbd_setup_device_desc()
2001 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
2005 udev->ddesc.bMaxPacketSize = 16; in usbd_setup_device_desc()
2007 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
2011 udev->ddesc.bMaxPacketSize = 32; in usbd_setup_device_desc()
2014 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
2023 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
2027 err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc); in usbd_setup_device_desc()
2033 "at addr %d failed, %s\n", udev->address, in usbd_setup_device_desc()
2039 "subclass=%d, protocol=%d, maxpacket=%d, len=%d, speed=%d\n", in usbd_setup_device_desc()
2040 udev->address, UGETW(udev->ddesc.bcdUSB), in usbd_setup_device_desc()
2041 udev->ddesc.bDeviceClass, in usbd_setup_device_desc()
2042 udev->ddesc.bDeviceSubClass, in usbd_setup_device_desc()
2043 udev->ddesc.bDeviceProtocol, in usbd_setup_device_desc()
2044 udev->ddesc.bMaxPacketSize, in usbd_setup_device_desc()
2045 udev->ddesc.bLength, in usbd_setup_device_desc()
2046 udev->speed); in usbd_setup_device_desc()
2051 /*------------------------------------------------------------------------*
2061 *------------------------------------------------------------------------*/
2070 if (udev->flags.usb_mode != USB_MODE_HOST) { in usbd_req_re_enumerate()
2073 old_addr = udev->address; in usbd_req_re_enumerate()
2074 parent_hub = udev->parent_hub; in usbd_req_re_enumerate()
2081 * Try to reset the High Speed parent HUB of a LOW- or FULL- in usbd_req_re_enumerate()
2082 * speed device, if any. in usbd_req_re_enumerate()
2084 if (udev->parent_hs_hub != NULL && in usbd_req_re_enumerate()
2085 udev->speed != USB_SPEED_HIGH) { in usbd_req_re_enumerate()
2086 DPRINTF("Trying to reset parent High Speed TT.\n"); in usbd_req_re_enumerate()
2087 if (udev->parent_hs_hub == parent_hub && in usbd_req_re_enumerate()
2092 udev->hs_port_no); in usbd_req_re_enumerate()
2095 err = usbd_req_clear_tt_buffer(udev->parent_hs_hub, NULL, in usbd_req_re_enumerate()
2096 udev->hs_port_no, old_addr, UE_CONTROL, 0); in usbd_req_re_enumerate()
2100 "Speed TT failed (%s).\n", in usbd_req_re_enumerate()
2106 if (parent_hub->speed == USB_SPEED_SUPER) in usbd_req_re_enumerate()
2107 usbd_req_warm_reset_port(parent_hub, mtx, udev->port_no); in usbd_req_re_enumerate()
2110 err = usbd_req_reset_port(parent_hub, mtx, udev->port_no); in usbd_req_re_enumerate()
2121 udev->address = USB_START_ADDR; in usbd_req_re_enumerate()
2124 udev->ddesc.bMaxPacketSize = USB_MAX_IPACKET; in usbd_req_re_enumerate()
2142 if (udev->address == USB_START_ADDR) in usbd_req_re_enumerate()
2143 udev->address = old_addr; in usbd_req_re_enumerate()
2151 usb_pause_mtx(mtx, hz / 2); in usbd_req_re_enumerate()
2158 if (udev->address == USB_START_ADDR) in usbd_req_re_enumerate()
2159 udev->address = old_addr; in usbd_req_re_enumerate()
2166 /*------------------------------------------------------------------------*
2172 *------------------------------------------------------------------------*/
2187 /*------------------------------------------------------------------------*
2193 *------------------------------------------------------------------------*/
2208 /*------------------------------------------------------------------------*
2214 *------------------------------------------------------------------------*/
2223 if (udev->ddesc.bDeviceClass == UDCLASS_HUB && in usbd_req_reset_tt()
2224 udev->ddesc.bDeviceProtocol == UDPROTO_HSHUBSTT) in usbd_req_reset_tt()
2236 /*------------------------------------------------------------------------*
2244 *------------------------------------------------------------------------*/
2254 if (udev->ddesc.bDeviceClass == UDCLASS_HUB && in usbd_req_clear_tt_buffer()
2255 udev->ddesc.bDeviceProtocol == UDPROTO_HSHUBSTT) in usbd_req_clear_tt_buffer()
2270 /*------------------------------------------------------------------------*
2278 *------------------------------------------------------------------------*/
2294 /*------------------------------------------------------------------------*
2305 *------------------------------------------------------------------------*/