Lines Matching refs:udev
139 struct usb_device *udev; in usb_trigger_reprobe_on_off() local
155 udev = bus->devices[USB_ROOT_HUB_ADDR]; in usb_trigger_reprobe_on_off()
157 if (udev->refcount == USB_DEV_REF_MAX) { in usb_trigger_reprobe_on_off()
162 udev->refcount++; in usb_trigger_reprobe_on_off()
165 do_unlock = usbd_enum_lock(udev); in usb_trigger_reprobe_on_off()
171 err = usbd_req_get_port_status(udev, NULL, &ps, 1); in usb_trigger_reprobe_on_off()
182 err = usbd_req_set_port_feature(udev, NULL, 1, in usb_trigger_reprobe_on_off()
189 err = usbd_req_clear_port_feature(udev, NULL, 1, in usb_trigger_reprobe_on_off()
200 usbd_enum_unlock(udev); in usb_trigger_reprobe_on_off()
201 if (--(udev->refcount) == 0) in usb_trigger_reprobe_on_off()
202 cv_broadcast(&udev->ref_cv); in usb_trigger_reprobe_on_off()
280 usb_get_manufacturer(struct usb_device *udev) in usb_get_manufacturer() argument
282 return (udev->manufacturer ? udev->manufacturer : "Unknown"); in usb_get_manufacturer()
286 usb_get_product(struct usb_device *udev) in usb_get_product() argument
288 return (udev->product ? udev->product : ""); in usb_get_product()
292 usb_get_serial(struct usb_device *udev) in usb_get_serial() argument
294 return (udev->serial ? udev->serial : ""); in usb_get_serial()
308 usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val) in usbd_get_ep_by_addr() argument
310 struct usb_endpoint *ep = udev->endpoints; in usbd_get_ep_by_addr()
311 struct usb_endpoint *ep_end = udev->endpoints + udev->endpoints_max; in usbd_get_ep_by_addr()
339 if ((udev->ctrl_ep.edesc != NULL) && in usbd_get_ep_by_addr()
340 ((udev->ctrl_ep.edesc->bEndpointAddress & EA_MASK) == ea_val)) { in usbd_get_ep_by_addr()
341 ep = &udev->ctrl_ep; in usbd_get_ep_by_addr()
361 usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index, in usbd_get_endpoint() argument
364 struct usb_endpoint *ep = udev->endpoints; in usbd_get_endpoint()
365 struct usb_endpoint *ep_end = udev->endpoints + udev->endpoints_max; in usbd_get_endpoint()
374 udev, iface_index, setup->endpoint, in usbd_get_endpoint()
380 udev->flags.usb_mode != setup->usb_mode) { in usbd_get_endpoint()
389 ea_val = (udev->flags.usb_mode == USB_MODE_DEVICE) ? in usbd_get_endpoint()
393 ea_val = (udev->flags.usb_mode == USB_MODE_DEVICE) ? in usbd_get_endpoint()
456 if ((udev->ctrl_ep.edesc != NULL) && in usbd_get_endpoint()
457 ((udev->ctrl_ep.edesc->bEndpointAddress & ea_mask) == ea_val) && in usbd_get_endpoint()
458 ((udev->ctrl_ep.edesc->bmAttributes & type_mask) == type_val) && in usbd_get_endpoint()
460 ep = &udev->ctrl_ep; in usbd_get_endpoint()
481 usbd_interface_count(struct usb_device *udev, uint8_t *count) in usbd_interface_count() argument
483 if (udev->cdesc == NULL) { in usbd_interface_count()
487 *count = udev->ifaces_max; in usbd_interface_count()
499 usb_init_endpoint(struct usb_device *udev, uint8_t iface_index, in usb_init_endpoint() argument
507 methods = udev->bus->methods; in usb_init_endpoint()
509 (methods->endpoint_init) (udev, edesc, ep); in usb_init_endpoint()
527 if (udev->speed == USB_SPEED_SUPER && ecomp != NULL && in usb_init_endpoint()
530 usbd_set_endpoint_mode(udev, ep, USB_EP_MODE_STREAMS); in usb_init_endpoint()
532 usbd_set_endpoint_mode(udev, ep, USB_EP_MODE_DEFAULT); in usb_init_endpoint()
537 USB_BUS_LOCK(udev->bus); in usb_init_endpoint()
538 (methods->clear_stall) (udev, ep); in usb_init_endpoint()
539 USB_BUS_UNLOCK(udev->bus); in usb_init_endpoint()
554 usb_endpoint_foreach(struct usb_device *udev, struct usb_endpoint *ep) in usb_endpoint_foreach() argument
559 if (udev == NULL) in usb_endpoint_foreach()
562 ep_end = udev->endpoints + udev->endpoints_max; in usb_endpoint_foreach()
566 ep = udev->endpoints; in usb_endpoint_foreach()
586 usb_wait_pending_refs(struct usb_device *udev) in usb_wait_pending_refs() argument
589 DPRINTF("Refcount = %d\n", (int)udev->refcount); in usb_wait_pending_refs()
592 udev->refcount--; in usb_wait_pending_refs()
595 if (udev->refcount == 0) { in usb_wait_pending_refs()
597 udev->refcount = USB_DEV_REF_MAX; in usb_wait_pending_refs()
600 cv_wait(&udev->ref_cv, &usb_ref_lock); in usb_wait_pending_refs()
615 usb_unconfigure(struct usb_device *udev, uint8_t flag) in usb_unconfigure() argument
620 do_unlock = usbd_enum_lock(udev); in usb_unconfigure()
623 usb_detach_device(udev, USB_IFACE_INDEX_ANY, flag); in usb_unconfigure()
627 usb_fifo_free_wrap(udev, USB_IFACE_INDEX_ANY, flag); in usb_unconfigure()
632 usb_cdev_free(udev); in usb_unconfigure()
637 if (udev->linux_endpoint_start != NULL) { in usb_unconfigure()
638 usb_linux_free_device_p(udev); in usb_unconfigure()
639 udev->linux_endpoint_start = NULL; in usb_unconfigure()
643 usb_config_parse(udev, USB_IFACE_INDEX_ANY, USB_CFG_FREE); in usb_unconfigure()
646 if (udev->cdesc != NULL) { in usb_unconfigure()
647 if (udev->flags.usb_mode != USB_MODE_DEVICE) in usb_unconfigure()
648 usbd_free_config_desc(udev, udev->cdesc); in usb_unconfigure()
649 udev->cdesc = NULL; in usb_unconfigure()
652 udev->curr_config_no = USB_UNCONFIG_NO; in usb_unconfigure()
653 udev->curr_config_index = USB_UNCONFIG_INDEX; in usb_unconfigure()
656 usbd_enum_unlock(udev); in usb_unconfigure()
671 usbd_set_config_index(struct usb_device *udev, uint8_t index) in usbd_set_config_index() argument
681 DPRINTFN(6, "udev=%p index=%d\n", udev, index); in usbd_set_config_index()
684 do_unlock = usbd_enum_lock(udev); in usbd_set_config_index()
686 usb_unconfigure(udev, 0); in usbd_set_config_index()
694 err = usbd_req_set_config(udev, NULL, USB_UNCONFIG_NO); in usbd_set_config_index()
695 if (udev->state == USB_STATE_CONFIGURED) in usbd_set_config_index()
696 usb_set_device_state(udev, USB_STATE_ADDRESSED); in usbd_set_config_index()
700 if (udev->flags.usb_mode == USB_MODE_DEVICE) { in usbd_set_config_index()
702 err = usbd_req_get_descriptor_ptr(udev, &cdp, in usbd_set_config_index()
706 err = usbd_req_get_config_desc_full(udev, in usbd_set_config_index()
714 udev->cdesc = cdp; in usbd_set_config_index()
718 if ((!udev->flags.uq_bus_powered) && in usbd_set_config_index()
720 (udev->flags.usb_mode == USB_MODE_HOST)) { in usbd_set_config_index()
724 err = usbd_req_get_device_status(udev, NULL, &ds); in usbd_set_config_index()
739 udev, cdp, in usbd_set_config_index()
740 udev->address, cdp->bConfigurationValue, cdp->bmAttributes, in usbd_set_config_index()
746 if (udev->parent_hub) { in usbd_set_config_index()
747 max_power = udev->parent_hub->hub->portpower; in usbd_set_config_index()
758 if (udev->flags.usb_mode == USB_MODE_HOST) { in usbd_set_config_index()
759 udev->flags.self_powered = selfpowered; in usbd_set_config_index()
761 udev->power = power; in usbd_set_config_index()
762 udev->curr_config_no = cdp->bConfigurationValue; in usbd_set_config_index()
763 udev->curr_config_index = index; in usbd_set_config_index()
764 usb_set_device_state(udev, USB_STATE_CONFIGURED); in usbd_set_config_index()
767 err = usbd_req_set_config(udev, NULL, cdp->bConfigurationValue); in usbd_set_config_index()
772 err = usb_config_parse(udev, USB_IFACE_INDEX_ANY, USB_CFG_ALLOC); in usbd_set_config_index()
777 err = usb_config_parse(udev, USB_IFACE_INDEX_ANY, USB_CFG_INIT); in usbd_set_config_index()
784 usb_cdev_create(udev); in usbd_set_config_index()
790 usb_unconfigure(udev, 0); in usbd_set_config_index()
793 usbd_enum_unlock(udev); in usbd_set_config_index()
815 usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd) in usb_config_parse() argument
844 sx_assert(&udev->enum_sx, SA_LOCKED); in usb_config_parse()
849 ep = udev->endpoints; in usb_config_parse()
850 ep_max = udev->endpoints_max; in usb_config_parse()
862 ep = udev->endpoints; in usb_config_parse()
863 ep_max = udev->endpoints_max; in usb_config_parse()
878 udev->bus->methods->endpoint_uninit != NULL) in usb_config_parse()
879 udev->bus->methods->endpoint_uninit(udev, ep); in usb_config_parse()
898 while ((id = usb_idesc_foreach(udev->cdesc, &ips))) { in usb_config_parse()
899 iface = udev->ifaces + ips.iface_index; in usb_config_parse()
947 while ((ed = usb_edesc_foreach(udev->cdesc, ed))) { in usb_config_parse()
954 ep = udev->endpoints + temp; in usb_config_parse()
959 ecomp = usb_ed_comp_foreach(udev->cdesc, (void *)ed); in usb_config_parse()
963 usb_init_endpoint(udev, in usb_config_parse()
978 udev->ifaces_max = ips.iface_index; in usb_config_parse()
980 udev->ifaces = NULL; in usb_config_parse()
981 if (udev->ifaces_max != 0) { in usb_config_parse()
982 udev->ifaces = malloc(sizeof(*iface) * udev->ifaces_max, in usb_config_parse()
984 if (udev->ifaces == NULL) { in usb_config_parse()
992 udev->endpoints = malloc(sizeof(*ep) * ep_max, in usb_config_parse()
994 if (udev->endpoints == NULL) { in usb_config_parse()
999 udev->endpoints = NULL; in usb_config_parse()
1002 USB_BUS_LOCK(udev->bus); in usb_config_parse()
1003 udev->endpoints_max = ep_max; in usb_config_parse()
1005 udev->ep_curr = NULL; in usb_config_parse()
1006 USB_BUS_UNLOCK(udev->bus); in usb_config_parse()
1014 USB_BUS_LOCK(udev->bus); in usb_config_parse()
1015 udev->endpoints_max = 0; in usb_config_parse()
1017 udev->ep_curr = NULL; in usb_config_parse()
1018 USB_BUS_UNLOCK(udev->bus); in usb_config_parse()
1021 free(udev->ifaces, M_USB); in usb_config_parse()
1022 udev->ifaces = NULL; in usb_config_parse()
1025 free(udev->endpoints, M_USB); in usb_config_parse()
1026 udev->endpoints = NULL; in usb_config_parse()
1028 udev->ifaces_max = 0; in usb_config_parse()
1049 usbd_set_alt_interface_index(struct usb_device *udev, in usbd_set_alt_interface_index() argument
1052 struct usb_interface *iface = usbd_get_iface(udev, iface_index); in usbd_set_alt_interface_index()
1057 do_unlock = usbd_enum_lock(udev); in usbd_set_alt_interface_index()
1076 usb_fifo_free_wrap(udev, iface_index, 0); in usbd_set_alt_interface_index()
1079 err = usb_config_parse(udev, iface_index, alt_index); in usbd_set_alt_interface_index()
1089 err = usbd_req_set_alt_interface_no(udev, NULL, iface_index, in usbd_set_alt_interface_index()
1094 usbd_enum_unlock(udev); in usbd_set_alt_interface_index()
1109 usbd_set_endpoint_stall(struct usb_device *udev, struct usb_endpoint *ep, in usbd_set_endpoint_stall() argument
1139 USB_BUS_LOCK(udev->bus); in usbd_set_endpoint_stall()
1147 USB_BUS_UNLOCK(udev->bus); in usbd_set_endpoint_stall()
1167 (udev->bus->methods->xfer_stall) (xfer); in usbd_set_endpoint_stall()
1171 (udev->bus->methods->set_stall) (udev, ep, &do_stall); in usbd_set_endpoint_stall()
1177 (udev->bus->methods->clear_stall) (udev, ep); in usbd_set_endpoint_stall()
1185 USB_BUS_UNLOCK(udev->bus); in usbd_set_endpoint_stall()
1193 usb_reset_iface_endpoints(struct usb_device *udev, uint8_t iface_index) in usb_reset_iface_endpoints() argument
1198 ep = udev->endpoints; in usb_reset_iface_endpoints()
1199 ep_end = udev->endpoints + udev->endpoints_max; in usb_reset_iface_endpoints()
1207 usbd_set_endpoint_stall(udev, ep, 0); in usb_reset_iface_endpoints()
1221 usb_detach_device_sub(struct usb_device *udev, device_t *ppdev, in usb_detach_device_sub() argument
1240 device_get_nameunit(udev->parent_dev), in usb_detach_device_sub()
1241 udev->port_no, udev->address); in usb_detach_device_sub()
1245 if (udev->flags.peer_suspended) { in usb_detach_device_sub()
1253 if (device_delete_child(udev->parent_dev, dev)) { in usb_detach_device_sub()
1279 usb_detach_device(struct usb_device *udev, uint8_t iface_index, in usb_detach_device() argument
1285 if (udev == NULL) { in usb_detach_device()
1289 DPRINTFN(4, "udev=%p\n", udev); in usb_detach_device()
1291 sx_assert(&udev->enum_sx, SA_LOCKED); in usb_detach_device()
1310 iface = usbd_get_iface(udev, i); in usb_detach_device()
1315 usb_detach_device_sub(udev, &iface->subdev, in usb_detach_device()
1328 usb_probe_and_attach_sub(struct usb_device *udev, in usb_probe_and_attach_sub() argument
1352 if (device_delete_child(udev->parent_dev, dev)) { in usb_probe_and_attach_sub()
1363 uaa->temp_dev = device_add_child(udev->parent_dev, NULL, DEVICE_UNIT_ANY); in usb_probe_and_attach_sub()
1365 device_printf(udev->parent_dev, in usb_probe_and_attach_sub()
1386 if (udev->flags.peer_suspended) { in usb_probe_and_attach_sub()
1410 usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, in usbd_set_parent_iface() argument
1415 if (udev == NULL || iface_index == parent_index) { in usbd_set_parent_iface()
1419 iface = usbd_get_iface(udev, iface_index); in usbd_set_parent_iface()
1425 usb_init_attach_arg(struct usb_device *udev, in usb_init_attach_arg() argument
1430 uaa->device = udev; in usb_init_attach_arg()
1431 uaa->usb_mode = udev->flags.usb_mode; in usb_init_attach_arg()
1432 uaa->port = udev->port_no; in usb_init_attach_arg()
1435 uaa->info.idVendor = UGETW(udev->ddesc.idVendor); in usb_init_attach_arg()
1436 uaa->info.idProduct = UGETW(udev->ddesc.idProduct); in usb_init_attach_arg()
1437 uaa->info.bcdDevice = UGETW(udev->ddesc.bcdDevice); in usb_init_attach_arg()
1438 uaa->info.bDeviceClass = udev->ddesc.bDeviceClass; in usb_init_attach_arg()
1439 uaa->info.bDeviceSubClass = udev->ddesc.bDeviceSubClass; in usb_init_attach_arg()
1440 uaa->info.bDeviceProtocol = udev->ddesc.bDeviceProtocol; in usb_init_attach_arg()
1441 uaa->info.bConfigIndex = udev->curr_config_index; in usb_init_attach_arg()
1442 uaa->info.bConfigNum = udev->curr_config_no; in usb_init_attach_arg()
1456 usb_probe_and_attach(struct usb_device *udev, uint8_t iface_index) in usb_probe_and_attach() argument
1464 if (udev == NULL) { in usb_probe_and_attach()
1469 do_unlock = usbd_enum_lock(udev); in usb_probe_and_attach()
1471 if (udev->curr_config_index == USB_UNCONFIG_INDEX) { in usb_probe_and_attach()
1477 usb_init_attach_arg(udev, &uaa); in usb_probe_and_attach()
1485 usb_dymo_eject(udev, 0) == 0) { in usb_probe_and_attach()
1490 EVENTHANDLER_INVOKE(usb_dev_configured, udev, &uaa); in usb_probe_and_attach()
1494 usb_unconfigure(udev, 0); in usb_probe_and_attach()
1510 iface = usbd_get_iface(udev, i); in usb_probe_and_attach()
1544 usb_probe_and_attach_sub(udev, &uaa); in usb_probe_and_attach()
1553 if (device_delete_child(udev->parent_dev, uaa.temp_dev)) in usb_probe_and_attach()
1559 usbd_enum_unlock(udev); in usb_probe_and_attach()
1570 usb_suspend_resume_sub(struct usb_device *udev, device_t dev, uint8_t do_suspend) in usb_suspend_resume_sub() argument
1601 usb_suspend_resume(struct usb_device *udev, uint8_t do_suspend) in usb_suspend_resume() argument
1606 if (udev == NULL) { in usb_suspend_resume()
1610 DPRINTFN(4, "udev=%p do_suspend=%d\n", udev, do_suspend); in usb_suspend_resume()
1612 sx_assert(&udev->sr_sx, SA_LOCKED); in usb_suspend_resume()
1614 USB_BUS_LOCK(udev->bus); in usb_suspend_resume()
1616 if (udev->flags.peer_suspended == do_suspend) { in usb_suspend_resume()
1617 USB_BUS_UNLOCK(udev->bus); in usb_suspend_resume()
1621 udev->flags.peer_suspended = do_suspend; in usb_suspend_resume()
1622 USB_BUS_UNLOCK(udev->bus); in usb_suspend_resume()
1627 iface = usbd_get_iface(udev, i); in usb_suspend_resume()
1632 usb_suspend_resume_sub(udev, iface->subdev, do_suspend); in usb_suspend_resume()
1646 struct usb_device *udev = pm->udev; in usbd_clear_stall_proc() local
1649 USB_BUS_UNLOCK(udev->bus); in usbd_clear_stall_proc()
1650 USB_MTX_LOCK(&udev->device_mtx); in usbd_clear_stall_proc()
1653 usbd_transfer_start(udev->ctrl_xfer[1]); in usbd_clear_stall_proc()
1656 USB_MTX_UNLOCK(&udev->device_mtx); in usbd_clear_stall_proc()
1657 USB_BUS_LOCK(udev->bus); in usbd_clear_stall_proc()
1666 usb_get_langid(struct usb_device *udev) in usb_get_langid() argument
1685 do_unlock = usbd_ctrl_lock(udev); in usb_get_langid()
1687 scratch_ptr = udev->scratch.data; in usb_get_langid()
1689 if (udev->flags.no_strings) { in usb_get_langid()
1691 } else if (udev->ddesc.iManufacturer || in usb_get_langid()
1692 udev->ddesc.iProduct || in usb_get_langid()
1693 udev->ddesc.iSerialNumber) { in usb_get_langid()
1695 err = usbd_req_get_string_desc(udev, NULL, in usb_get_langid()
1702 udev->flags.no_strings = 1; in usb_get_langid()
1732 udev->langid = langid; in usb_get_langid()
1736 usbd_ctrl_unlock(udev); in usb_get_langid()
1757 struct usb_device *udev; in usb_alloc_device() local
1794 udev = malloc(sizeof(*udev), M_USB, M_WAITOK | M_ZERO); in usb_alloc_device()
1796 if (udev == NULL) { in usb_alloc_device()
1801 sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK); in usb_alloc_device()
1802 sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_NOWITNESS); in usb_alloc_device()
1803 sx_init_flags(&udev->ctrl_sx, "USB control transfer SX lock", SX_DUPOK); in usb_alloc_device()
1805 cv_init(&udev->ctrlreq_cv, "WCTRL"); in usb_alloc_device()
1806 cv_init(&udev->ref_cv, "UGONE"); in usb_alloc_device()
1809 mtx_init(&udev->device_mtx, "USB device mutex", NULL, MTX_DEF); in usb_alloc_device()
1812 udev->cs_msg[0].hdr.pm_callback = &usbd_clear_stall_proc; in usb_alloc_device()
1813 udev->cs_msg[0].udev = udev; in usb_alloc_device()
1814 udev->cs_msg[1].hdr.pm_callback = &usbd_clear_stall_proc; in usb_alloc_device()
1815 udev->cs_msg[1].udev = udev; in usb_alloc_device()
1818 udev->parent_hub = parent_hub; in usb_alloc_device()
1819 udev->parent_dev = parent_dev; in usb_alloc_device()
1820 udev->port_index = port_index; in usb_alloc_device()
1821 udev->port_no = port_no; in usb_alloc_device()
1822 udev->depth = depth; in usb_alloc_device()
1823 udev->bus = bus; in usb_alloc_device()
1824 udev->address = USB_START_ADDR; /* default value */ in usb_alloc_device()
1825 udev->plugtime = (usb_ticks_t)ticks; in usb_alloc_device()
1831 udev->power_mode = usbd_filter_power_mode(udev, USB_POWER_MODE_ON); in usb_alloc_device()
1832 udev->pwr_save.last_xfer_time = ticks; in usb_alloc_device()
1834 udev->refcount = 1; in usb_alloc_device()
1837 udev->ctrl_ep_desc.bLength = sizeof(udev->ctrl_ep_desc); in usb_alloc_device()
1838 udev->ctrl_ep_desc.bDescriptorType = UDESC_ENDPOINT; in usb_alloc_device()
1839 udev->ctrl_ep_desc.bEndpointAddress = USB_CONTROL_ENDPOINT; in usb_alloc_device()
1840 udev->ctrl_ep_desc.bmAttributes = UE_CONTROL; in usb_alloc_device()
1841 udev->ctrl_ep_desc.wMaxPacketSize[0] = USB_MAX_IPACKET; in usb_alloc_device()
1842 udev->ctrl_ep_desc.wMaxPacketSize[1] = 0; in usb_alloc_device()
1843 udev->ctrl_ep_desc.bInterval = 0; in usb_alloc_device()
1846 udev->ctrl_ep_comp_desc.bLength = sizeof(udev->ctrl_ep_comp_desc); in usb_alloc_device()
1847 udev->ctrl_ep_comp_desc.bDescriptorType = UDESC_ENDPOINT_SS_COMP; in usb_alloc_device()
1849 udev->ddesc.bMaxPacketSize = USB_MAX_IPACKET; in usb_alloc_device()
1851 udev->speed = speed; in usb_alloc_device()
1852 udev->flags.usb_mode = mode; in usb_alloc_device()
1856 adev = udev; in usb_alloc_device()
1857 hub = udev->parent_hub; in usb_alloc_device()
1861 udev->hs_hub_addr = hub->address; in usb_alloc_device()
1862 udev->parent_hs_hub = hub; in usb_alloc_device()
1863 udev->hs_port_no = adev->port_no; in usb_alloc_device()
1871 usb_init_endpoint(udev, 0, in usb_alloc_device()
1872 &udev->ctrl_ep_desc, in usb_alloc_device()
1873 &udev->ctrl_ep_comp_desc, in usb_alloc_device()
1874 &udev->ctrl_ep); in usb_alloc_device()
1877 udev->device_index = device_index; in usb_alloc_device()
1881 snprintf(udev->ugen_name, sizeof(udev->ugen_name), in usb_alloc_device()
1884 SLIST_INIT(&udev->pd_list); in usb_alloc_device()
1887 udev->ctrl_dev = usb_make_dev(udev, NULL, 0, 0, in usb_alloc_device()
1891 if (udev->ctrl_dev != NULL) in usb_alloc_device()
1892 make_dev_alias(udev->ctrl_dev->cdev, "%s", udev->ugen_name); in usb_alloc_device()
1896 err = (bus->methods->device_init) (udev); in usb_alloc_device()
1905 usb_set_device_state(udev, USB_STATE_POWERED); in usb_alloc_device()
1907 if (udev->flags.usb_mode == USB_MODE_HOST) { in usb_alloc_device()
1908 err = usbd_req_set_address(udev, NULL, device_index); in usb_alloc_device()
1914 if (udev->address == USB_START_ADDR) in usb_alloc_device()
1915 udev->address = device_index; in usb_alloc_device()
1928 "(%s, ignored)\n", udev->address, in usb_alloc_device()
1933 udev->flags.self_powered = 0; in usb_alloc_device()
1936 udev->curr_config_no = USB_UNCONFIG_NO; in usb_alloc_device()
1937 udev->curr_config_index = USB_UNCONFIG_INDEX; in usb_alloc_device()
1940 err = (usb_temp_setup_by_index_p) (udev, usb_template); in usb_alloc_device()
1947 usb_set_device_state(udev, USB_STATE_ADDRESSED); in usb_alloc_device()
1950 err = usbd_setup_device_desc(udev, NULL); in usb_alloc_device()
1954 err = usbd_req_re_enumerate(udev, NULL); in usb_alloc_device()
1956 err = usbd_req_re_enumerate(udev, NULL); in usb_alloc_device()
1967 usb_init_attach_arg(udev, &uaa); in usb_alloc_device()
1970 udev->flags.uq_bus_powered = 1; in usb_alloc_device()
1973 udev->flags.no_strings = 1; in usb_alloc_device()
1976 usb_get_langid(udev); in usb_alloc_device()
1979 udev->power = USB_MIN_POWER; in usb_alloc_device()
1981 usb_set_device_strings(udev); in usb_alloc_device()
1983 if (udev->flags.usb_mode == USB_MODE_DEVICE) { in usb_alloc_device()
2019 err = usbd_set_config_index(udev, config_index); in usb_alloc_device()
2021 if (udev->ddesc.bNumConfigurations != 0) { in usb_alloc_device()
2025 err = usbd_req_re_enumerate(udev, NULL); in usb_alloc_device()
2031 config_index, usbd_errstr(err), udev->port_no, in usb_alloc_device()
2032 udev->address); in usb_alloc_device()
2041 if (!config_quirk && config_index + 1 < udev->ddesc.bNumConfigurations) { in usb_alloc_device()
2042 if ((udev->cdesc->bNumInterface < 2) && in usb_alloc_device()
2043 usbd_get_no_descriptors(udev->cdesc, UDESC_ENDPOINT) == 0) { in usb_alloc_device()
2055 if (usb_iface_is_cdrom(udev, 0)) { in usb_alloc_device()
2076 err = usb_msc_auto_quirk(udev, 0, &uaa); in usb_alloc_device()
2087 udev->address, udev, udev->parent_hub); in usb_alloc_device()
2091 parent_hub->hub->ports + port_index : NULL, udev, device_index); in usb_alloc_device()
2095 udev->ugen_symlink = usb_alloc_symlink(udev->ugen_name); in usb_alloc_device()
2098 printf("%s: <%s %s> at %s\n", udev->ugen_name, in usb_alloc_device()
2099 usb_get_manufacturer(udev), usb_get_product(udev), in usb_alloc_device()
2100 device_get_nameunit(udev->bus->bdev)); in usb_alloc_device()
2104 usb_notify_addq("ATTACH", udev); in usb_alloc_device()
2111 usb_free_device(udev, 0); in usb_alloc_device()
2112 udev = NULL; in usb_alloc_device()
2114 return (udev); in usb_alloc_device()
2119 usb_make_dev(struct usb_device *udev, const char *devname, int ep, in usb_make_dev() argument
2129 pd->bus_index = device_get_unit(udev->bus->bdev); in usb_make_dev()
2130 pd->dev_index = udev->device_index; in usb_make_dev()
2202 usb_cdev_create(struct usb_device *udev) in usb_cdev_create() argument
2211 KASSERT(SLIST_FIRST(&udev->pd_list) == NULL, ("stale cdev entries")); in usb_cdev_create()
2215 if (usbd_get_mode(udev) == USB_MODE_DEVICE) { in usb_cdev_create()
2231 cd = usbd_get_config_descriptor(udev); in usb_cdev_create()
2254 pd = usb_make_dev(udev, NULL, ep, 0, in usb_cdev_create()
2258 SLIST_INSERT_HEAD(&udev->pd_list, pd, pd_next); in usb_cdev_create()
2263 usb_cdev_free(struct usb_device *udev) in usb_cdev_free() argument
2269 while ((pd = SLIST_FIRST(&udev->pd_list)) != NULL) { in usb_cdev_free()
2272 SLIST_REMOVE(&udev->pd_list, pd, usb_fs_privdata, pd_next); in usb_cdev_free()
2288 usb_free_device(struct usb_device *udev, uint8_t flag) in usb_free_device() argument
2292 if (udev == NULL) in usb_free_device()
2295 DPRINTFN(4, "udev=%p port=%d\n", udev, udev->port_no); in usb_free_device()
2297 bus = udev->bus; in usb_free_device()
2300 usb_set_device_state(udev, USB_STATE_DETACHED); in usb_free_device()
2303 usb_notify_addq("DETACH", udev); in usb_free_device()
2308 printf("%s: <%s %s> at %s (disconnected)\n", udev->ugen_name, in usb_free_device()
2309 usb_get_manufacturer(udev), usb_get_product(udev), in usb_free_device()
2314 if (udev->ugen_symlink) { in usb_free_device()
2315 usb_free_symlink(udev->ugen_symlink); in usb_free_device()
2316 udev->ugen_symlink = NULL; in usb_free_device()
2319 usb_destroy_dev(udev->ctrl_dev); in usb_free_device()
2322 if (udev->flags.usb_mode == USB_MODE_DEVICE) { in usb_free_device()
2324 usbd_transfer_unsetup(udev->ctrl_xfer, USB_CTRL_XFER_MAX); in usb_free_device()
2328 usb_unconfigure(udev, USB_UNCFG_FLAG_FREE_EP0); in usb_free_device()
2331 usb_bus_port_set_device(bus, udev->parent_hub ? in usb_free_device()
2332 udev->parent_hub->hub->ports + udev->port_index : NULL, in usb_free_device()
2336 usbd_transfer_unsetup(udev->ctrl_xfer, USB_CTRL_XFER_MAX); in usb_free_device()
2339 (usb_temp_unsetup_p) (udev); in usb_free_device()
2345 USB_BUS_LOCK(udev->bus); in usb_free_device()
2346 usb_proc_mwait(USB_BUS_CS_PROC(udev->bus), in usb_free_device()
2347 &udev->cs_msg[0], &udev->cs_msg[1]); in usb_free_device()
2348 USB_BUS_UNLOCK(udev->bus); in usb_free_device()
2351 usb_wait_pending_refs(udev); in usb_free_device()
2353 sx_destroy(&udev->enum_sx); in usb_free_device()
2354 sx_destroy(&udev->sr_sx); in usb_free_device()
2355 sx_destroy(&udev->ctrl_sx); in usb_free_device()
2357 cv_destroy(&udev->ctrlreq_cv); in usb_free_device()
2358 cv_destroy(&udev->ref_cv); in usb_free_device()
2360 mtx_destroy(&udev->device_mtx); in usb_free_device()
2362 KASSERT(SLIST_FIRST(&udev->pd_list) == NULL, ("leaked cdev entries")); in usb_free_device()
2367 (bus->methods->device_uninit) (udev); in usb_free_device()
2370 free(udev->serial, M_USB); in usb_free_device()
2371 free(udev->manufacturer, M_USB); in usb_free_device()
2372 free(udev->product, M_USB); in usb_free_device()
2373 free(udev, M_USB); in usb_free_device()
2387 usbd_get_iface(struct usb_device *udev, uint8_t iface_index) in usbd_get_iface() argument
2389 struct usb_interface *iface = udev->ifaces + iface_index; in usbd_get_iface()
2391 if (iface_index >= udev->ifaces_max) in usbd_get_iface()
2412 usbd_find_descriptor(struct usb_device *udev, void *id, uint8_t iface_index, in usbd_find_descriptor() argument
2420 cd = usbd_get_config_descriptor(udev); in usbd_find_descriptor()
2425 iface = usbd_get_iface(udev, iface_index); in usbd_find_descriptor()
2457 usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len) in usb_devinfo() argument
2459 struct usb_device_descriptor *udd = &udev->ddesc; in usb_devinfo()
2469 usb_get_manufacturer(udev), in usb_devinfo()
2470 usb_get_product(udev), in usb_devinfo()
2474 udev->address); in usb_devinfo()
2478 usb_get_manufacturer(udev), in usb_devinfo()
2479 usb_get_product(udev), in usb_devinfo()
2482 udev->address); in usb_devinfo()
2505 usb_set_device_strings(struct usb_device *udev) in usb_set_device_strings() argument
2507 struct usb_device_descriptor *udd = &udev->ddesc; in usb_set_device_strings()
2518 do_unlock = usbd_ctrl_lock(udev); in usb_set_device_strings()
2520 temp_ptr = (char *)udev->scratch.data; in usb_set_device_strings()
2521 temp_size = sizeof(udev->scratch.data); in usb_set_device_strings()
2527 free(udev->serial, M_USB); in usb_set_device_strings()
2528 free(udev->manufacturer, M_USB); in usb_set_device_strings()
2529 free(udev->product, M_USB); in usb_set_device_strings()
2532 udev->serial = NULL; in usb_set_device_strings()
2533 udev->manufacturer = NULL; in usb_set_device_strings()
2534 udev->product = NULL; in usb_set_device_strings()
2537 usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, in usb_set_device_strings()
2538 udev->ddesc.iSerialNumber); in usb_set_device_strings()
2539 udev->serial = strdup(temp_ptr, M_USB); in usb_set_device_strings()
2542 usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, in usb_set_device_strings()
2543 udev->ddesc.iManufacturer); in usb_set_device_strings()
2546 udev->manufacturer = strdup(temp_ptr, M_USB); in usb_set_device_strings()
2549 usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size, in usb_set_device_strings()
2550 udev->ddesc.iProduct); in usb_set_device_strings()
2553 udev->product = strdup(temp_ptr, M_USB); in usb_set_device_strings()
2556 if (udev->manufacturer == NULL || udev->product == NULL) { in usb_set_device_strings()
2565 if (udev->manufacturer == NULL) { in usb_set_device_strings()
2566 udev->manufacturer = strdup(kdp->vendorname, in usb_set_device_strings()
2569 if (udev->product == NULL && in usb_set_device_strings()
2571 udev->product = strdup(kdp->productname, in usb_set_device_strings()
2578 if (udev->manufacturer == NULL) { in usb_set_device_strings()
2580 udev->manufacturer = strdup(temp_ptr, M_USB); in usb_set_device_strings()
2582 if (udev->product == NULL) { in usb_set_device_strings()
2584 udev->product = strdup(temp_ptr, M_USB); in usb_set_device_strings()
2588 usbd_ctrl_unlock(udev); in usb_set_device_strings()
2596 usbd_get_mode(struct usb_device *udev) in usbd_get_mode() argument
2598 return (udev->flags.usb_mode); in usbd_get_mode()
2606 usbd_get_speed(struct usb_device *udev) in usbd_get_speed() argument
2608 return (udev->speed); in usbd_get_speed()
2612 usbd_get_isoc_fps(struct usb_device *udev) in usbd_get_isoc_fps() argument
2615 switch (udev->speed) { in usbd_get_isoc_fps()
2625 usbd_get_device_descriptor(struct usb_device *udev) in usbd_get_device_descriptor() argument
2627 if (udev == NULL) in usbd_get_device_descriptor()
2629 return (&udev->ddesc); in usbd_get_device_descriptor()
2633 usbd_get_config_descriptor(struct usb_device *udev) in usbd_get_config_descriptor() argument
2635 if (udev == NULL) in usbd_get_config_descriptor()
2637 return (udev->cdesc); in usbd_get_config_descriptor()
2685 usbd_get_bus_index(struct usb_device *udev) in usbd_get_bus_index() argument
2687 return ((uint8_t)device_get_unit(udev->bus->bdev)); in usbd_get_bus_index()
2691 usbd_get_device_index(struct usb_device *udev) in usbd_get_device_index() argument
2693 return (udev->device_index); in usbd_get_device_index()
2698 usb_notify_addq(const char *type, struct usb_device *udev) in usb_notify_addq() argument
2724 udev->ugen_name, in usb_notify_addq()
2725 udev->ugen_name, in usb_notify_addq()
2727 UGETW(udev->ddesc.idVendor), in usb_notify_addq()
2728 UGETW(udev->ddesc.idProduct), in usb_notify_addq()
2729 udev->ddesc.bDeviceClass, in usb_notify_addq()
2730 udev->ddesc.bDeviceSubClass, in usb_notify_addq()
2731 usb_get_serial(udev), in usb_notify_addq()
2732 UGETW(udev->ddesc.bcdDevice), in usb_notify_addq()
2733 (udev->flags.usb_mode == USB_MODE_HOST) ? "host" : "device", in usb_notify_addq()
2734 udev->port_no in usb_notify_addq()
2736 , udev->parent_hub != NULL ? in usb_notify_addq()
2737 udev->parent_hub->ugen_name : in usb_notify_addq()
2738 device_get_nameunit(device_get_parent(udev->bus->bdev)) in usb_notify_addq()
2747 iface = usbd_get_iface(udev, i); in usb_notify_addq()
2772 udev->ugen_name, in usb_notify_addq()
2773 udev->ugen_name, in usb_notify_addq()
2775 UGETW(udev->ddesc.idVendor), in usb_notify_addq()
2776 UGETW(udev->ddesc.idProduct), in usb_notify_addq()
2777 udev->ddesc.bDeviceClass, in usb_notify_addq()
2778 udev->ddesc.bDeviceSubClass, in usb_notify_addq()
2779 usb_get_serial(udev), in usb_notify_addq()
2780 UGETW(udev->ddesc.bcdDevice), in usb_notify_addq()
2781 (udev->flags.usb_mode == USB_MODE_HOST) ? "host" : "device", in usb_notify_addq()
2808 usb_fifo_free_wrap(struct usb_device *udev, in usb_fifo_free_wrap() argument
2818 f = udev->fifo[i]; in usb_fifo_free_wrap()
2862 usb_peer_can_wakeup(struct usb_device *udev) in usb_peer_can_wakeup() argument
2866 cdp = udev->cdesc; in usb_peer_can_wakeup()
2867 if ((cdp != NULL) && (udev->flags.usb_mode == USB_MODE_HOST)) { in usb_peer_can_wakeup()
2874 usb_set_device_state(struct usb_device *udev, enum usb_dev_state state) in usb_set_device_state() argument
2879 DPRINTF("udev %p state %s -> %s\n", udev, in usb_set_device_state()
2880 usb_statestr(udev->state), usb_statestr(state)); in usb_set_device_state()
2885 udev->state = state; in usb_set_device_state()
2889 if (udev->bus->methods->device_state_change != NULL) in usb_set_device_state()
2890 (udev->bus->methods->device_state_change) (udev); in usb_set_device_state()
2894 usb_get_device_state(struct usb_device *udev) in usb_get_device_state() argument
2896 if (udev == NULL) in usb_get_device_state()
2898 return (udev->state); in usb_get_device_state()
2902 usbd_device_attached(struct usb_device *udev) in usbd_device_attached() argument
2904 return (udev->state > USB_STATE_DETACHED); in usbd_device_attached()
2913 usbd_enum_lock(struct usb_device *udev) in usbd_enum_lock() argument
2915 if (sx_xlocked(&udev->enum_sx)) in usbd_enum_lock()
2918 sx_xlock(&udev->enum_sx); in usbd_enum_lock()
2919 sx_xlock(&udev->sr_sx); in usbd_enum_lock()
2935 usbd_enum_lock_sig(struct usb_device *udev) in usbd_enum_lock_sig() argument
2937 if (sx_xlocked(&udev->enum_sx)) in usbd_enum_lock_sig()
2939 if (sx_xlock_sig(&udev->enum_sx)) in usbd_enum_lock_sig()
2941 if (sx_xlock_sig(&udev->sr_sx)) { in usbd_enum_lock_sig()
2942 sx_xunlock(&udev->enum_sx); in usbd_enum_lock_sig()
2953 usbd_enum_unlock(struct usb_device *udev) in usbd_enum_unlock() argument
2956 sx_xunlock(&udev->enum_sx); in usbd_enum_unlock()
2957 sx_xunlock(&udev->sr_sx); in usbd_enum_unlock()
2963 usbd_sr_lock(struct usb_device *udev) in usbd_sr_lock() argument
2965 sx_xlock(&udev->sr_sx); in usbd_sr_lock()
2977 usbd_sr_unlock(struct usb_device *udev) in usbd_sr_unlock() argument
2980 sx_xunlock(&udev->sr_sx); in usbd_sr_unlock()
2989 usbd_enum_is_locked(struct usb_device *udev) in usbd_enum_is_locked() argument
2991 return (sx_xlocked(&udev->enum_sx)); in usbd_enum_is_locked()
3000 usbd_ctrl_lock(struct usb_device *udev) in usbd_ctrl_lock() argument
3002 if (sx_xlocked(&udev->ctrl_sx)) in usbd_ctrl_lock()
3004 sx_xlock(&udev->ctrl_sx); in usbd_ctrl_lock()
3010 if (usbd_enum_is_locked(udev)) in usbd_ctrl_lock()
3011 usbd_sr_unlock(udev); in usbd_ctrl_lock()
3016 usbd_ctrl_unlock(struct usb_device *udev) in usbd_ctrl_unlock() argument
3018 sx_xunlock(&udev->ctrl_sx); in usbd_ctrl_unlock()
3024 if (usbd_enum_is_locked(udev)) in usbd_ctrl_unlock()
3025 usbd_sr_lock(udev); in usbd_ctrl_unlock()
3038 usbd_set_pnpinfo(struct usb_device *udev, uint8_t iface_index, const char *pnpinfo) in usbd_set_pnpinfo() argument
3042 iface = usbd_get_iface(udev, iface_index); in usbd_set_pnpinfo()
3062 usbd_add_dynamic_quirk(struct usb_device *udev, uint16_t quirk) in usbd_add_dynamic_quirk() argument
3067 if (udev->autoQuirk[x] == 0 || in usbd_add_dynamic_quirk()
3068 udev->autoQuirk[x] == quirk) { in usbd_add_dynamic_quirk()
3069 udev->autoQuirk[x] = quirk; in usbd_add_dynamic_quirk()
3082 usbd_set_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep, in usbd_set_endpoint_mode() argument
3089 do_unlock = usbd_enum_lock(udev); in usbd_set_endpoint_mode()
3091 if (udev->bus->methods->set_endpoint_mode != NULL) { in usbd_set_endpoint_mode()
3092 error = (udev->bus->methods->set_endpoint_mode) ( in usbd_set_endpoint_mode()
3093 udev, ep, ep_mode); in usbd_set_endpoint_mode()
3104 usbd_enum_unlock(udev); in usbd_set_endpoint_mode()
3109 usbd_get_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep) in usbd_get_endpoint_mode() argument