Lines Matching refs:dev

115 usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid,  in usbd_get_string_desc()  argument
127 err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK, in usbd_get_string_desc()
136 err = usbd_do_request_flags(dev, &req, sdesc, USBD_SHORT_XFER_OK, in usbd_get_string_desc()
151 usbd_get_string(struct usbd_device *dev, int si, char *buf, size_t buflen) in usbd_get_string() argument
153 int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE; in usbd_get_string()
163 if (dev->quirks->uq_flags & UQ_NO_STRINGS) in usbd_get_string()
165 if (dev->langid == USBD_NOLANG) { in usbd_get_string()
167 err = usbd_get_string_desc(dev, USB_LANGUAGE_TABLE, 0, &us, in usbd_get_string()
170 dev->langid = 0; /* Well, just pick English then */ in usbd_get_string()
173 dev->langid = UGETW(us.bString[0]); in usbd_get_string()
176 err = usbd_get_string_desc(dev, si, dev->langid, &us, &size); in usbd_get_string()
213 usbd_cache_devinfo(struct usbd_device *dev) in usbd_cache_devinfo() argument
215 usb_device_descriptor_t *udd = &dev->ddesc; in usbd_cache_devinfo()
217 dev->serial = malloc(USB_MAX_STRING_LEN, M_USB, M_NOWAIT); in usbd_cache_devinfo()
218 if (dev->serial == NULL) in usbd_cache_devinfo()
221 if (usbd_get_string(dev, udd->iSerialNumber, dev->serial, USB_MAX_STRING_LEN) != NULL) { in usbd_cache_devinfo()
222 usbd_trim_spaces(dev->serial); in usbd_cache_devinfo()
224 free(dev->serial, M_USB, USB_MAX_STRING_LEN); in usbd_cache_devinfo()
225 dev->serial = NULL; in usbd_cache_devinfo()
228 dev->vendor = malloc(USB_MAX_STRING_LEN, M_USB, M_NOWAIT); in usbd_cache_devinfo()
229 if (dev->vendor == NULL) in usbd_cache_devinfo()
232 if (usbd_get_string(dev, udd->iManufacturer, dev->vendor, USB_MAX_STRING_LEN) != NULL) { in usbd_cache_devinfo()
233 usbd_trim_spaces(dev->vendor); in usbd_cache_devinfo()
240 strlcpy(dev->vendor, ukv->vendorname, in usbd_cache_devinfo()
247 snprintf(dev->vendor, USB_MAX_STRING_LEN, "vendor 0x%04x", in usbd_cache_devinfo()
251 dev->product = malloc(USB_MAX_STRING_LEN, M_USB, M_NOWAIT); in usbd_cache_devinfo()
252 if (dev->product == NULL) in usbd_cache_devinfo()
255 if (usbd_get_string(dev, udd->iProduct, dev->product, USB_MAX_STRING_LEN) != NULL) { in usbd_cache_devinfo()
256 usbd_trim_spaces(dev->product); in usbd_cache_devinfo()
264 strlcpy(dev->product, ukp->productname, in usbd_cache_devinfo()
271 snprintf(dev->product, USB_MAX_STRING_LEN, "product 0x%04x", in usbd_cache_devinfo()
292 usbd_devinfo(struct usbd_device *dev, int showclass, char *base, size_t len) in usbd_devinfo() argument
294 usb_device_descriptor_t *udd = &dev->ddesc; in usbd_devinfo()
298 snprintf(cp, len, "\"%s %s\"", dev->vendor, dev->product); in usbd_devinfo()
315 snprintf(cp, base + len - cp, " addr %d", dev->address); in usbd_devinfo()
333 usbd_delay_ms(struct usbd_device *dev, u_int ms) in usbd_delay_ms() argument
335 if (usbd_is_dying(dev)) in usbd_delay_ms()
338 usb_delay_ms(dev->bus, ms); in usbd_delay_ms()
342 usbd_port_disown_to_1_1(struct usbd_device *dev, int port) in usbd_port_disown_to_1_1() argument
348 err = usbd_set_port_feature(dev, port, UHF_PORT_DISOWN_TO_1_1); in usbd_port_disown_to_1_1()
356 usbd_delay_ms(dev, USB_PORT_RESET_DELAY); in usbd_port_disown_to_1_1()
357 err = usbd_get_port_status(dev, port, &ps); in usbd_port_disown_to_1_1()
373 usbd_reset_port(struct usbd_device *dev, int port) in usbd_reset_port() argument
378 if (usbd_set_port_feature(dev, port, UHF_PORT_RESET)) in usbd_reset_port()
384 usbd_delay_ms(dev, USB_PORT_RESET_DELAY); in usbd_reset_port()
385 if (usbd_get_port_status(dev, port, &ps)) { in usbd_reset_port()
395 if (usbd_clear_port_feature(dev, port, UHF_C_PORT_RESET)) { in usbd_reset_port()
404 usbd_delay_ms(dev, USB_PORT_RESET_RECOVERY); in usbd_reset_port()
473 usbd_fill_iface_data(struct usbd_device *dev, int ifaceno, int altno) in usbd_fill_iface_data() argument
475 struct usbd_interface *ifc = &dev->ifaces[ifaceno]; in usbd_fill_iface_data()
481 idesc = usbd_find_idesc(dev->cdesc, ifaceno, altno); in usbd_fill_iface_data()
488 ifc->device = dev; in usbd_fill_iface_data()
504 if (usbd_parse_idesc(dev, ifc)) { in usbd_fill_iface_data()
514 usbd_parse_idesc(struct usbd_device *dev, struct usbd_interface *ifc) in usbd_parse_idesc() argument
521 end = (char *)dev->cdesc + UGETW(dev->cdesc->wTotalLength); in usbd_parse_idesc()
537 if (dev->speed == USB_SPEED_HIGH) { in usbd_parse_idesc()
570 usbd_free_iface_data(struct usbd_device *dev, int ifcno) in usbd_free_iface_data() argument
572 struct usbd_interface *ifc = &dev->ifaces[ifcno]; in usbd_free_iface_data()
579 usbd_set_config(struct usbd_device *dev, int conf) in usbd_set_config() argument
588 return (usbd_do_request(dev, &req, 0)); in usbd_set_config()
592 usbd_set_config_no(struct usbd_device *dev, int no, int msg) in usbd_set_config_no() argument
600 for (index = 0; index < dev->ddesc.bNumConfigurations; index++) { in usbd_set_config_no()
601 err = usbd_get_desc(dev, UDESC_CONFIG, index, in usbd_set_config_no()
606 return (usbd_set_config_index(dev, index, msg)); in usbd_set_config_no()
612 usbd_set_config_index(struct usbd_device *dev, int index, int msg) in usbd_set_config_index() argument
619 DPRINTFN(5,("%s: dev=%p index=%d\n", __func__, dev, index)); in usbd_set_config_index()
622 if (dev->config != USB_UNCONFIG_NO) { in usbd_set_config_index()
625 nifc = dev->cdesc->bNumInterfaces; in usbd_set_config_index()
627 usbd_free_iface_data(dev, ifcidx); in usbd_set_config_index()
628 free(dev->ifaces, M_USB, nifc * sizeof(*dev->ifaces)); in usbd_set_config_index()
629 free(dev->cdesc, M_USB, UGETW(dev->cdesc->wTotalLength)); in usbd_set_config_index()
630 dev->ifaces = NULL; in usbd_set_config_index()
631 dev->cdesc = NULL; in usbd_set_config_index()
632 dev->config = USB_UNCONFIG_NO; in usbd_set_config_index()
638 err = usbd_set_config(dev, USB_UNCONFIG_NO); in usbd_set_config_index()
646 err = usbd_get_desc(dev, UDESC_CONFIG, index, in usbd_set_config_index()
658 err = usbd_get_desc(dev, UDESC_CONFIG, index, cdplen, cdp); in usbd_set_config_index()
661 usbd_delay_ms(dev, 200); in usbd_set_config_index()
675 if (!(dev->quirks->uq_flags & UQ_BUS_POWERED) && in usbd_set_config_index()
680 if (dev->quirks->uq_flags & UQ_POWER_CLAIM) { in usbd_set_config_index()
693 err = usbd_do_request(dev, &req, &hd); in usbd_set_config_index()
702 err = usbd_get_device_status(dev, &ds); in usbd_set_config_index()
714 __func__, dev->address, cdp->bConfigurationValue, cdp->bmAttributes, in usbd_set_config_index()
719 if (dev->powersrc == NULL) { in usbd_set_config_index()
726 if (power > dev->powersrc->power) { in usbd_set_config_index()
727 DPRINTF(("power exceeded %d %d\n", power,dev->powersrc->power)); in usbd_set_config_index()
732 dev->bus->bdev.dv_xname, dev->address, in usbd_set_config_index()
734 power, dev->powersrc->power); in usbd_set_config_index()
738 dev->power = power; in usbd_set_config_index()
739 dev->self_powered = selfpowered; in usbd_set_config_index()
743 err = usbd_set_config(dev, cdp->bConfigurationValue); in usbd_set_config_index()
752 dev->ifaces = mallocarray(nifc, sizeof(*dev->ifaces), M_USB, in usbd_set_config_index()
754 if (dev->ifaces == NULL) { in usbd_set_config_index()
758 DPRINTFN(5,("%s: dev=%p cdesc=%p\n", __func__, dev, cdp)); in usbd_set_config_index()
759 dev->cdesc = cdp; in usbd_set_config_index()
760 dev->config = cdp->bConfigurationValue; in usbd_set_config_index()
762 err = usbd_fill_iface_data(dev, ifcidx, 0); in usbd_set_config_index()
777 usbd_setup_pipe(struct usbd_device *dev, struct usbd_interface *iface, in usbd_setup_pipe() argument
784 dev, iface, ep, pipe)); in usbd_setup_pipe()
785 p = malloc(dev->bus->pipe_size, M_USB, M_NOWAIT|M_ZERO); in usbd_setup_pipe()
788 p->pipe_size = dev->bus->pipe_size; in usbd_setup_pipe()
789 p->device = dev; in usbd_setup_pipe()
795 err = dev->bus->methods->open_pipe(p); in usbd_setup_pipe()
799 free(p, M_USB, dev->bus->pipe_size); in usbd_setup_pipe()
807 usbd_set_address(struct usbd_device *dev, int addr) in usbd_set_address() argument
816 if (usbd_do_request(dev, &req, 0)) in usbd_set_address()
820 usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE); in usbd_set_address()
837 usbd_probe_and_attach(struct device *parent, struct usbd_device *dev, int port, in usbd_probe_and_attach() argument
846 usb_device_descriptor_t *dd = &dev->ddesc; in usbd_probe_and_attach()
855 uaa.device = dev; in usbd_probe_and_attach()
872 dev->subdevs = mallocarray(2, sizeof dv, M_USB, M_NOWAIT); in usbd_probe_and_attach()
873 if (dev->subdevs == NULL) { in usbd_probe_and_attach()
877 dev->nsubdev = 2; in usbd_probe_and_attach()
878 dev->subdevs[dev->ndevs++] = dv; in usbd_probe_and_attach()
879 dev->subdevs[dev->ndevs] = 0; in usbd_probe_and_attach()
892 err = usbd_set_config_index(dev, confi, 1); in usbd_probe_and_attach()
905 nifaces = dev->cdesc->bNumInterfaces; in usbd_probe_and_attach()
906 uaa.configno = dev->cdesc->bConfigurationValue; in usbd_probe_and_attach()
913 ifaces[i] = &dev->ifaces[i]; in usbd_probe_and_attach()
918 dev->subdevs = mallocarray(nifaces + 2, sizeof(dv), M_USB, in usbd_probe_and_attach()
920 if (dev->subdevs == NULL) { in usbd_probe_and_attach()
925 dev->nsubdev = nifaces + 2; in usbd_probe_and_attach()
928 if (usbd_iface_claimed(dev, i)) in usbd_probe_and_attach()
934 dev->subdevs[dev->ndevs++] = dv; in usbd_probe_and_attach()
935 usbd_claim_iface(dev, i); in usbd_probe_and_attach()
940 if (dev->ndevs > 0) { in usbd_probe_and_attach()
942 if (!usbd_iface_claimed(dev, i)) in usbd_probe_and_attach()
951 free(dev->subdevs, M_USB, dev->nsubdev * sizeof(*dev->subdevs)); in usbd_probe_and_attach()
952 dev->subdevs = NULL; in usbd_probe_and_attach()
953 dev->nsubdev = 0; in usbd_probe_and_attach()
958 usbd_set_config_index(dev, 0, 0); in usbd_probe_and_attach()
966 uaa.configno = dev->ndevs == 0 ? UHUB_UNK_CONFIGURATION : in usbd_probe_and_attach()
967 dev->cdesc->bConfigurationValue; in usbd_probe_and_attach()
971 if (dev->ndevs == 0) { in usbd_probe_and_attach()
972 dev->subdevs = mallocarray(2, sizeof dv, M_USB, M_NOWAIT); in usbd_probe_and_attach()
973 if (dev->subdevs == NULL) { in usbd_probe_and_attach()
977 dev->nsubdev = 2; in usbd_probe_and_attach()
979 dev->subdevs[dev->ndevs++] = dv; in usbd_probe_and_attach()
980 dev->subdevs[dev->ndevs] = 0; in usbd_probe_and_attach()
1008 struct usbd_device *dev, *adev, *hub; in usbd_new_device() local
1043 dev = malloc(sizeof *dev, M_USB, M_NOWAIT | M_ZERO); in usbd_new_device()
1044 if (dev == NULL) in usbd_new_device()
1047 dev->bus = bus; in usbd_new_device()
1050 dev->def_ep.edesc = &dev->def_ep_desc; in usbd_new_device()
1053 dev->def_ep_desc.bLength = USB_ENDPOINT_DESCRIPTOR_SIZE; in usbd_new_device()
1054 dev->def_ep_desc.bDescriptorType = UDESC_ENDPOINT; in usbd_new_device()
1055 dev->def_ep_desc.bEndpointAddress = USB_CONTROL_ENDPOINT; in usbd_new_device()
1056 dev->def_ep_desc.bmAttributes = UE_CONTROL; in usbd_new_device()
1057 dev->def_ep_desc.bInterval = 0; in usbd_new_device()
1058 USETW(dev->def_ep_desc.wMaxPacketSize, mps0); in usbd_new_device()
1060 dev->quirks = &usbd_no_quirk; in usbd_new_device()
1061 dev->address = USB_START_ADDR; in usbd_new_device()
1062 dev->ddesc.bMaxPacketSize = 0; in usbd_new_device()
1063 dev->depth = depth; in usbd_new_device()
1064 dev->powersrc = up; in usbd_new_device()
1065 dev->myhub = up->parent; in usbd_new_device()
1066 dev->speed = speed; in usbd_new_device()
1067 dev->langid = USBD_NOLANG; in usbd_new_device()
1069 up->device = dev; in usbd_new_device()
1072 for (adev = dev, hub = up->parent; in usbd_new_device()
1079 dev->myhsport = &hub->hub->ports[p]; in usbd_new_device()
1087 dev->myhsport = NULL; in usbd_new_device()
1091 err = usbd_setup_pipe(dev, 0, &dev->def_ep, USBD_DEFAULT_INTERVAL, in usbd_new_device()
1092 &dev->default_pipe); in usbd_new_device()
1096 dd = &dev->ddesc; in usbd_new_device()
1108 err = usbd_get_desc(dev, UDESC_DEVICE, 0, USB_MAX_IPACKET, dd); in usbd_new_device()
1113 usbd_delay_ms(dev, 100+50*i); in usbd_new_device()
1118 USETW(dev->def_ep_desc.wMaxPacketSize, in usbd_new_device()
1122 err = usbd_get_desc(dev, UDESC_DEVICE, 0, in usbd_new_device()
1128 usbd_delay_ms(dev, 100+50*i); in usbd_new_device()
1134 USETW(dev->def_ep_desc.wMaxPacketSize, USB_MAX_IPACKET); in usbd_new_device()
1136 usbd_delay_ms(dev, 500); in usbd_new_device()
1137 err = usbd_get_desc(dev, UDESC_DEVICE, 0, in usbd_new_device()
1148 dev->speed)); in usbd_new_device()
1170 USETW(dev->def_ep_desc.wMaxPacketSize, mps); in usbd_new_device()
1176 bus->methods->dev_setaddr(dev, addr)) { in usbd_new_device()
1182 usbd_delay_ms(dev, 10); in usbd_new_device()
1188 dev->address = addr; in usbd_new_device()
1190 err = usbd_reload_device_desc(dev); in usbd_new_device()
1195 if (dev->quirks->uq_flags & UQ_EHCI_NEEDTO_DISOWN) { in usbd_new_device()
1197 if (dev->bus->usbrev == USBREV_2_0) { in usbd_new_device()
1199 __func__, dev)); in usbd_new_device()
1200 usbd_port_disown_to_1_1(dev->myhub, port); in usbd_new_device()
1202 usbd_reset_port(dev->myhub, port); in usbd_new_device()
1208 dev->power = USB_MIN_POWER; in usbd_new_device()
1209 dev->self_powered = 0; in usbd_new_device()
1212 addr, dev, parent)); in usbd_new_device()
1215 err = usbd_cache_devinfo(dev); in usbd_new_device()
1219 bus->devices[addr] = dev; in usbd_new_device()
1221 err = usbd_probe_and_attach(parent, dev, port, addr); in usbd_new_device()
1228 usb_free_device(dev); in usbd_new_device()
1234 usbd_reload_device_desc(struct usbd_device *dev) in usbd_reload_device_desc() argument
1239 err = usbd_get_desc(dev, UDESC_DEVICE, 0, in usbd_reload_device_desc()
1240 USB_DEVICE_DESCRIPTOR_SIZE, &dev->ddesc); in usbd_reload_device_desc()
1245 dev->quirks = usbd_find_quirk(&dev->ddesc); in usbd_reload_device_desc()
1281 usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di) in usbd_fill_deviceinfo() argument
1286 di->udi_bus = dev->bus->usbctl->dv_unit; in usbd_fill_deviceinfo()
1287 di->udi_addr = dev->address; in usbd_fill_deviceinfo()
1288 strlcpy(di->udi_vendor, dev->vendor, sizeof(di->udi_vendor)); in usbd_fill_deviceinfo()
1289 strlcpy(di->udi_product, dev->product, sizeof(di->udi_product)); in usbd_fill_deviceinfo()
1291 UGETW(dev->ddesc.bcdDevice)); in usbd_fill_deviceinfo()
1292 di->udi_vendorNo = UGETW(dev->ddesc.idVendor); in usbd_fill_deviceinfo()
1293 di->udi_productNo = UGETW(dev->ddesc.idProduct); in usbd_fill_deviceinfo()
1294 di->udi_releaseNo = UGETW(dev->ddesc.bcdDevice); in usbd_fill_deviceinfo()
1295 di->udi_class = dev->ddesc.bDeviceClass; in usbd_fill_deviceinfo()
1296 di->udi_subclass = dev->ddesc.bDeviceSubClass; in usbd_fill_deviceinfo()
1297 di->udi_protocol = dev->ddesc.bDeviceProtocol; in usbd_fill_deviceinfo()
1298 di->udi_config = dev->config; in usbd_fill_deviceinfo()
1299 di->udi_power = dev->self_powered ? 0 : dev->power; in usbd_fill_deviceinfo()
1300 di->udi_speed = dev->speed; in usbd_fill_deviceinfo()
1301 di->udi_port = dev->powersrc ? dev->powersrc->portno : 0; in usbd_fill_deviceinfo()
1303 if (dev->subdevs != NULL) { in usbd_fill_deviceinfo()
1304 for (i = 0; dev->subdevs[i] && i < USB_MAX_DEVNAMES; i++) { in usbd_fill_deviceinfo()
1306 dev->subdevs[i]->dv_xname, USB_MAX_DEVNAMELEN); in usbd_fill_deviceinfo()
1315 if (dev->hub) { in usbd_fill_deviceinfo()
1317 i < nitems(di->udi_ports) && i < dev->hub->nports; i++) { in usbd_fill_deviceinfo()
1318 p = &dev->hub->ports[i]; in usbd_fill_deviceinfo()
1322 di->udi_nports = dev->hub->nports; in usbd_fill_deviceinfo()
1327 if (dev->serial != NULL) in usbd_fill_deviceinfo()
1328 strlcpy(di->udi_serial, dev->serial, in usbd_fill_deviceinfo()
1333 usbd_get_routestring(struct usbd_device *dev, uint32_t *route) in usbd_get_routestring() argument
1344 r = dev->powersrc ? dev->powersrc->portno : 0; in usbd_get_routestring()
1345 for (hub = dev->myhub; hub && hub->depth > 1; hub = hub->myhub) { in usbd_get_routestring()
1363 usbd_get_location(struct usbd_device *dev, struct usbd_interface *iface, in usbd_get_location() argument
1369 if (dev == NULL || usbd_is_dying(dev) || in usbd_get_location()
1370 dev->cdesc == NULL || in usbd_get_location()
1371 dev->cdesc->bNumInterfaces == 0 || in usbd_get_location()
1372 dev->bus == NULL || in usbd_get_location()
1373 dev->bus->usbctl == NULL || in usbd_get_location()
1374 dev->myhub == NULL || in usbd_get_location()
1375 dev->powersrc == NULL) in usbd_get_location()
1378 for(i = 0; i < dev->cdesc->bNumInterfaces; i++) { in usbd_get_location()
1379 if (iface == &dev->ifaces[i]) { in usbd_get_location()
1380 *bus = dev->bus->usbctl->dv_unit; in usbd_get_location()
1381 *route = (usbd_get_routestring(dev, &r)) ? 0 : r; in usbd_get_location()
1392 usbd_get_cdesc(struct usbd_device *dev, int index, u_int *lenp) in usbd_get_cdesc() argument
1399 tdesc = usbd_get_config_descriptor(dev); in usbd_get_cdesc()
1409 err = usbd_get_desc(dev, UDESC_CONFIG, index, in usbd_get_cdesc()
1418 err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdesc); in usbd_get_cdesc()
1428 usb_free_device(struct usbd_device *dev) in usb_free_device() argument
1432 DPRINTF(("%s: %p\n", __func__, dev)); in usb_free_device()
1434 if (dev->default_pipe != NULL) in usb_free_device()
1435 usbd_close_pipe(dev->default_pipe); in usb_free_device()
1436 if (dev->ifaces != NULL) { in usb_free_device()
1437 nifc = dev->cdesc->bNumInterfaces; in usb_free_device()
1439 usbd_free_iface_data(dev, ifcidx); in usb_free_device()
1440 free(dev->ifaces, M_USB, nifc * sizeof(*dev->ifaces)); in usb_free_device()
1442 if (dev->cdesc != NULL) in usb_free_device()
1443 free(dev->cdesc, M_USB, UGETW(dev->cdesc->wTotalLength)); in usb_free_device()
1444 free(dev->subdevs, M_USB, dev->nsubdev * sizeof(*dev->subdevs)); in usb_free_device()
1445 dev->bus->devices[dev->address] = NULL; in usb_free_device()
1447 if (dev->vendor != NULL) in usb_free_device()
1448 free(dev->vendor, M_USB, USB_MAX_STRING_LEN); in usb_free_device()
1449 if (dev->product != NULL) in usb_free_device()
1450 free(dev->product, M_USB, USB_MAX_STRING_LEN); in usb_free_device()
1451 if (dev->serial != NULL) in usb_free_device()
1452 free(dev->serial, M_USB, USB_MAX_STRING_LEN); in usb_free_device()
1454 free(dev, M_USB, sizeof *dev); in usb_free_device()
1462 usbd_detach(struct usbd_device *dev, struct device *parent) in usbd_detach() argument
1466 usbd_deactivate(dev); in usbd_detach()
1468 if (dev->ndevs > 0) { in usbd_detach()
1469 for (i = 0; dev->subdevs[i] != NULL; i++) in usbd_detach()
1470 rv |= config_detach(dev->subdevs[i], DETACH_FORCE); in usbd_detach()
1474 usb_free_device(dev); in usbd_detach()