Lines Matching +full:endpoint +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0
3 * message.c - synchronous message handling
37 struct api_context *ctx = urb->context; in usb_api_blocking_completion()
39 ctx->status = urb->status; in usb_api_blocking_completion()
40 complete(&ctx->done); in usb_api_blocking_completion()
57 urb->context = &ctx; in usb_start_wait_urb()
58 urb->actual_length = 0; in usb_start_wait_urb()
66 retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); in usb_start_wait_urb()
68 dev_dbg(&urb->dev->dev, in usb_start_wait_urb()
70 current->comm, in usb_start_wait_urb()
71 usb_endpoint_num(&urb->ep->desc), in usb_start_wait_urb()
73 urb->actual_length, in usb_start_wait_urb()
74 urb->transfer_buffer_length); in usb_start_wait_urb()
79 *actual_length = urb->actual_length; in usb_start_wait_urb()
85 /*-------------------------------------------------------------------*/
98 return -ENOMEM; in usb_internal_control_msg()
111 * usb_control_msg - Builds a control urb, sends it off and waits for completion
113 * @pipe: endpoint "pipe" to send the message to
125 * This function sends a simple control message to a specified endpoint and
146 return -ENOMEM; in usb_control_msg()
148 dr->bRequestType = requesttype; in usb_control_msg()
149 dr->bRequest = request; in usb_control_msg()
150 dr->wValue = cpu_to_le16(value); in usb_control_msg()
151 dr->wIndex = cpu_to_le16(index); in usb_control_msg()
152 dr->wLength = cpu_to_le16(size); in usb_control_msg()
157 if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG) in usb_control_msg()
167 * usb_control_msg_send - Builds a control "send" message, sends it off and waits for completion
169 * @endpoint: endpoint to send the message to
182 * This function sends a control message to a specified endpoint that is not
199 int usb_control_msg_send(struct usb_device *dev, __u8 endpoint, __u8 request, in usb_control_msg_send() argument
204 unsigned int pipe = usb_sndctrlpipe(dev, endpoint); in usb_control_msg_send()
211 return -ENOMEM; in usb_control_msg_send()
226 * usb_control_msg_recv - Builds a control "receive" message, sends it off and waits for completion
228 * @endpoint: endpoint to send the message to
241 * This function sends a control message to a specified endpoint that is
264 int usb_control_msg_recv(struct usb_device *dev, __u8 endpoint, __u8 request, in usb_control_msg_recv() argument
269 unsigned int pipe = usb_rcvctrlpipe(dev, endpoint); in usb_control_msg_recv()
274 return -EINVAL; in usb_control_msg_recv()
278 return -ENOMEM; in usb_control_msg_recv()
290 ret = -EREMOTEIO; in usb_control_msg_recv()
300 * usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion
302 * @pipe: endpoint "pipe" to send the message to
312 * This function sends a simple interrupt message to a specified endpoint and
333 * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
335 * @pipe: endpoint "pipe" to send the message to
345 * This function sends a simple bulk message to a specified endpoint
357 * (with the default interval) if the target is an interrupt endpoint.
372 return -EINVAL; in usb_bulk_msg()
376 return -ENOMEM; in usb_bulk_msg()
378 if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == in usb_bulk_msg()
383 ep->desc.bInterval); in usb_bulk_msg()
392 /*-------------------------------------------------------------------*/
396 if (io->urbs) { in sg_clean()
397 while (io->entries--) in sg_clean()
398 usb_free_urb(io->urbs[io->entries]); in sg_clean()
399 kfree(io->urbs); in sg_clean()
400 io->urbs = NULL; in sg_clean()
402 io->dev = NULL; in sg_clean()
408 struct usb_sg_request *io = urb->context; in sg_complete()
409 int status = urb->status; in sg_complete()
411 spin_lock_irqsave(&io->lock, flags); in sg_complete()
413 /* In 2.5 we require hcds' endpoint queues not to progress after fault in sg_complete()
423 if (io->status in sg_complete()
424 && (io->status != -ECONNRESET in sg_complete()
425 || status != -ECONNRESET) in sg_complete()
426 && urb->actual_length) { in sg_complete()
427 dev_err(io->dev->bus->controller, in sg_complete()
429 io->dev->devpath, in sg_complete()
430 usb_endpoint_num(&urb->ep->desc), in sg_complete()
432 status, io->status); in sg_complete()
436 if (io->status == 0 && status && status != -ECONNRESET) { in sg_complete()
439 io->status = status; in sg_complete()
445 spin_unlock_irqrestore(&io->lock, flags); in sg_complete()
446 for (i = 0, found = 0; i < io->entries; i++) { in sg_complete()
447 if (!io->urbs[i]) in sg_complete()
450 usb_block_urb(io->urbs[i]); in sg_complete()
451 retval = usb_unlink_urb(io->urbs[i]); in sg_complete()
452 if (retval != -EINPROGRESS && in sg_complete()
453 retval != -ENODEV && in sg_complete()
454 retval != -EBUSY && in sg_complete()
455 retval != -EIDRM) in sg_complete()
456 dev_err(&io->dev->dev, in sg_complete()
457 "%s, unlink --> %d\n", in sg_complete()
459 } else if (urb == io->urbs[i]) in sg_complete()
462 spin_lock_irqsave(&io->lock, flags); in sg_complete()
466 io->bytes += urb->actual_length; in sg_complete()
467 io->count--; in sg_complete()
468 if (!io->count) in sg_complete()
469 complete(&io->complete); in sg_complete()
471 spin_unlock_irqrestore(&io->lock, flags); in sg_complete()
476 * usb_sg_init - initializes scatterlist-based bulk/interrupt I/O request
480 * @pipe: endpoint "pipe" used to transfer the data
514 return -EINVAL; in usb_sg_init()
516 spin_lock_init(&io->lock); in usb_sg_init()
517 io->dev = dev; in usb_sg_init()
518 io->pipe = pipe; in usb_sg_init()
520 if (dev->bus->sg_tablesize > 0) { in usb_sg_init()
522 io->entries = 1; in usb_sg_init()
525 io->entries = nents; in usb_sg_init()
529 io->urbs = kmalloc_array(io->entries, sizeof(*io->urbs), mem_flags); in usb_sg_init()
530 if (!io->urbs) in usb_sg_init()
537 for_each_sg(sg, sg, io->entries, i) { in usb_sg_init()
543 io->entries = i; in usb_sg_init()
546 io->urbs[i] = urb; in usb_sg_init()
548 urb->dev = NULL; in usb_sg_init()
549 urb->pipe = pipe; in usb_sg_init()
550 urb->interval = period; in usb_sg_init()
551 urb->transfer_flags = urb_flags; in usb_sg_init()
552 urb->complete = sg_complete; in usb_sg_init()
553 urb->context = io; in usb_sg_init()
554 urb->sg = sg; in usb_sg_init()
558 urb->transfer_buffer = NULL; in usb_sg_init()
559 urb->num_sgs = nents; in usb_sg_init()
568 len += sg2->length; in usb_sg_init()
577 urb->transfer_buffer = sg_virt(sg); in usb_sg_init()
579 urb->transfer_buffer = NULL; in usb_sg_init()
581 len = sg->length; in usb_sg_init()
584 length -= len; in usb_sg_init()
586 io->entries = i + 1; in usb_sg_init()
589 urb->transfer_buffer_length = len; in usb_sg_init()
591 io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; in usb_sg_init()
594 io->count = io->entries; in usb_sg_init()
595 io->status = 0; in usb_sg_init()
596 io->bytes = 0; in usb_sg_init()
597 init_completion(&io->complete); in usb_sg_init()
602 return -ENOMEM; in usb_sg_init()
607 * usb_sg_wait - synchronously execute scatter/gather request
620 * (1) success, where io->status is zero. The number of io->bytes
622 * (2) error, where io->status is a negative errno value. The number
623 * of io->bytes transferred before the error is usually less
625 * (3) cancellation, a type of error with status -ECONNRESET that
654 int entries = io->entries; in usb_sg_wait()
657 spin_lock_irq(&io->lock); in usb_sg_wait()
659 while (i < entries && !io->status) { in usb_sg_wait()
662 io->urbs[i]->dev = io->dev; in usb_sg_wait()
663 spin_unlock_irq(&io->lock); in usb_sg_wait()
665 retval = usb_submit_urb(io->urbs[i], GFP_NOIO); in usb_sg_wait()
669 case -ENXIO: /* hc didn't queue this one */ in usb_sg_wait()
670 case -EAGAIN: in usb_sg_wait()
671 case -ENOMEM: in usb_sg_wait()
689 io->urbs[i]->status = retval; in usb_sg_wait()
690 dev_dbg(&io->dev->dev, "%s, submit --> %d\n", in usb_sg_wait()
694 spin_lock_irq(&io->lock); in usb_sg_wait()
695 if (retval && (io->status == 0 || io->status == -ECONNRESET)) in usb_sg_wait()
696 io->status = retval; in usb_sg_wait()
698 io->count -= entries - i; in usb_sg_wait()
699 if (io->count == 0) in usb_sg_wait()
700 complete(&io->complete); in usb_sg_wait()
701 spin_unlock_irq(&io->lock); in usb_sg_wait()
703 /* OK, yes, this could be packaged as non-blocking. in usb_sg_wait()
707 wait_for_completion(&io->complete); in usb_sg_wait()
714 * usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait()
726 spin_lock_irqsave(&io->lock, flags); in usb_sg_cancel()
727 if (io->status || io->count == 0) { in usb_sg_cancel()
728 spin_unlock_irqrestore(&io->lock, flags); in usb_sg_cancel()
732 io->status = -ECONNRESET; in usb_sg_cancel()
733 io->count++; /* Keep the request alive until we're done */ in usb_sg_cancel()
734 spin_unlock_irqrestore(&io->lock, flags); in usb_sg_cancel()
736 for (i = io->entries - 1; i >= 0; --i) { in usb_sg_cancel()
737 usb_block_urb(io->urbs[i]); in usb_sg_cancel()
739 retval = usb_unlink_urb(io->urbs[i]); in usb_sg_cancel()
740 if (retval != -EINPROGRESS in usb_sg_cancel()
741 && retval != -ENODEV in usb_sg_cancel()
742 && retval != -EBUSY in usb_sg_cancel()
743 && retval != -EIDRM) in usb_sg_cancel()
744 dev_warn(&io->dev->dev, "%s, unlink --> %d\n", in usb_sg_cancel()
748 spin_lock_irqsave(&io->lock, flags); in usb_sg_cancel()
749 io->count--; in usb_sg_cancel()
750 if (!io->count) in usb_sg_cancel()
751 complete(&io->complete); in usb_sg_cancel()
752 spin_unlock_irqrestore(&io->lock, flags); in usb_sg_cancel()
756 /*-------------------------------------------------------------------*/
759 * usb_get_descriptor - issues a generic GET_DESCRIPTOR request
773 * In addition to a number of USB-standard descriptors, some
774 * devices also use class-specific or vendor-specific descriptors.
788 return -EINVAL; in usb_get_descriptor()
798 if (result <= 0 && result != -ETIMEDOUT) in usb_get_descriptor()
801 result = -ENODATA; in usb_get_descriptor()
811 * usb_get_string - gets a string descriptor
820 * Retrieves a string, encoded using UTF-16LE (Unicode, 16 bits per character,
821 * in little-endian byte order).
823 * these strings into kernel-printable form.
826 * descriptors, and could also be used in vendor-specific ways.
840 return -EINVAL; in usb_get_string()
848 if (result == 0 || result == -EPIPE) in usb_get_string()
851 result = -ENODATA; in usb_get_string()
880 if (dev->quirks & USB_QUIRK_STRING_FETCH_255) in usb_string_sub()
881 rc = -EIO; in usb_string_sub()
901 rc = rc - (rc & 1); /* force a multiple of two */ in usb_string_sub()
905 rc = (rc < 0 ? rc : -EINVAL); in usb_string_sub()
914 if (dev->have_langid) in usb_get_langid()
917 if (dev->string_langid < 0) in usb_get_langid()
918 return -EPIPE; in usb_get_langid()
924 if (err == -ENODATA || (err > 0 && err < 4)) { in usb_get_langid()
925 dev->string_langid = 0x0409; in usb_get_langid()
926 dev->have_langid = 1; in usb_get_langid()
927 dev_err(&dev->dev, in usb_get_langid()
933 * deal with strings at all. Set string_langid to -1 in order to in usb_get_langid()
936 dev_info(&dev->dev, "string descriptor 0 read error: %d\n", in usb_get_langid()
938 dev->string_langid = -1; in usb_get_langid()
939 return -EPIPE; in usb_get_langid()
943 dev->string_langid = tbuf[2] | (tbuf[3] << 8); in usb_get_langid()
944 dev->have_langid = 1; in usb_get_langid()
945 dev_dbg(&dev->dev, "default language 0x%04x\n", in usb_get_langid()
946 dev->string_langid); in usb_get_langid()
951 * usb_string - returns UTF-8 version of a string descriptor
959 * This converts the UTF-16LE encoded strings returned by devices, from
960 * usb_get_string_descriptor(), to null-terminated UTF-8 encoded ones
973 if (dev->state == USB_STATE_SUSPENDED) in usb_string()
974 return -EHOSTUNREACH; in usb_string()
976 return -EINVAL; in usb_string()
979 return -EINVAL; in usb_string()
982 return -ENOMEM; in usb_string()
988 err = usb_string_sub(dev, dev->string_langid, index, tbuf); in usb_string()
992 size--; /* leave room for trailing NULL char in output buffer */ in usb_string()
993 err = utf16s_to_utf8s((wchar_t *) &tbuf[2], (err - 2) / 2, in usb_string()
998 dev_dbg(&dev->dev, in usb_string()
1008 /* one UTF-8-encoded 16-bit character has at most three bytes */
1012 * usb_cache_string - read a string descriptor and cache it for later use
1044 * usb_get_device_descriptor - read the device descriptor
1063 return ERR_PTR(-ENOMEM); in usb_get_device_descriptor()
1070 ret = -EMSGSIZE; in usb_get_device_descriptor()
1076 * usb_set_isoch_delay - informs the device of the packet transmit delay
1085 if (dev->descriptor.bDeviceClass == USB_CLASS_HUB) in usb_set_isoch_delay()
1088 /* skip non-SS/non-SSP devices */ in usb_set_isoch_delay()
1089 if (dev->speed < USB_SPEED_SUPER) in usb_set_isoch_delay()
1095 dev->hub_delay, 0, NULL, 0, in usb_set_isoch_delay()
1101 * usb_get_status - issues a GET_STATUS call
1103 * @recip: USB_RECIP_*; for device, interface, or endpoint
1105 * @target: zero (for device), else interface or endpoint number
1110 * Returns device, interface, or endpoint status. Normally only of
1112 * remote wakeup facility; or whether a bulk or interrupt endpoint
1137 return -EINVAL; in usb_get_status()
1142 return -EINVAL; in usb_get_status()
1147 return -ENOMEM; in usb_get_status()
1156 ret = -EIO; in usb_get_status()
1165 ret = -EIO; in usb_get_status()
1173 ret = -EIO; in usb_get_status()
1182 * usb_clear_halt - tells device to clear endpoint halt/stall condition
1183 * @dev: device whose endpoint is halted
1184 * @pipe: endpoint "pipe" being cleared
1192 * queued for such an endpoint should normally be unlinked by the driver
1224 /* don't un-halt or force to DATA0 except on success */ in usb_clear_halt()
1233 * the copy in usb-storage, for as long as we need two copies. in usb_clear_halt()
1245 struct usb_host_interface *alt = intf->cur_altsetting; in create_intf_ep_devs()
1248 if (intf->ep_devs_created || intf->unregistering) in create_intf_ep_devs()
1251 for (i = 0; i < alt->desc.bNumEndpoints; ++i) in create_intf_ep_devs()
1252 (void) usb_create_ep_devs(&intf->dev, &alt->endpoint[i], udev); in create_intf_ep_devs()
1253 intf->ep_devs_created = 1; in create_intf_ep_devs()
1259 struct usb_host_interface *alt = intf->cur_altsetting; in remove_intf_ep_devs()
1262 if (!intf->ep_devs_created) in remove_intf_ep_devs()
1265 for (i = 0; i < alt->desc.bNumEndpoints; ++i) in remove_intf_ep_devs()
1266 usb_remove_ep_devs(&alt->endpoint[i]); in remove_intf_ep_devs()
1267 intf->ep_devs_created = 0; in remove_intf_ep_devs()
1271 * usb_disable_endpoint -- Disable an endpoint by address
1272 * @dev: the device whose endpoint is being disabled
1273 * @epaddr: the endpoint's address. Endpoint number for output,
1274 * endpoint number + USB_DIR_IN for input
1275 * @reset_hardware: flag to erase any endpoint state stored in the
1278 * Disables the endpoint for URB submission and nukes all pending URBs.
1280 * for the endpoint.
1292 ep = dev->ep_out[epnum]; in usb_disable_endpoint()
1294 dev->ep_out[epnum] = NULL; in usb_disable_endpoint()
1296 ep = dev->ep_in[epnum]; in usb_disable_endpoint()
1298 dev->ep_in[epnum] = NULL; in usb_disable_endpoint()
1301 ep->enabled = 0; in usb_disable_endpoint()
1309 * usb_reset_endpoint - Reset an endpoint's state.
1310 * @dev: the device whose endpoint is to be reset
1311 * @epaddr: the endpoint's address. Endpoint number for output,
1312 * endpoint number + USB_DIR_IN for input
1314 * Resets any host-side endpoint state such as the toggle bit,
1323 ep = dev->ep_out[epnum]; in usb_reset_endpoint()
1325 ep = dev->ep_in[epnum]; in usb_reset_endpoint()
1333 * usb_disable_interface -- Disable all endpoints for an interface
1336 * @reset_hardware: flag to erase any endpoint state stored in the
1344 struct usb_host_interface *alt = intf->cur_altsetting; in usb_disable_interface()
1347 for (i = 0; i < alt->desc.bNumEndpoints; ++i) { in usb_disable_interface()
1349 alt->endpoint[i].desc.bEndpointAddress, in usb_disable_interface()
1355 * usb_disable_device_endpoints -- Disable all endpoints for a device
1357 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
1361 struct usb_hcd *hcd = bus_to_hcd(dev->bus); in usb_disable_device_endpoints()
1364 if (hcd->driver->check_bandwidth) { in usb_disable_device_endpoints()
1365 /* First pass: Cancel URBs, leave endpoint pointers intact. */ in usb_disable_device_endpoints()
1371 mutex_lock(hcd->bandwidth_mutex); in usb_disable_device_endpoints()
1373 mutex_unlock(hcd->bandwidth_mutex); in usb_disable_device_endpoints()
1375 /* Second pass: remove endpoint pointers */ in usb_disable_device_endpoints()
1383 * usb_disable_device - Disable all the endpoints for a USB device
1385 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
1387 * Disables all the device's endpoints, potentially including endpoint 0.
1399 if (dev->actconfig) { in usb_disable_device()
1401 * FIXME: In order to avoid self-deadlock involving the in usb_disable_device()
1405 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) in usb_disable_device()
1406 dev->actconfig->interface[i]->unregistering = 1; in usb_disable_device()
1408 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { in usb_disable_device()
1412 interface = dev->actconfig->interface[i]; in usb_disable_device()
1413 if (!device_is_registered(&interface->dev)) in usb_disable_device()
1415 dev_dbg(&dev->dev, "unregistering interface %s\n", in usb_disable_device()
1416 dev_name(&interface->dev)); in usb_disable_device()
1418 device_del(&interface->dev); in usb_disable_device()
1424 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { in usb_disable_device()
1425 put_device(&dev->actconfig->interface[i]->dev); in usb_disable_device()
1426 dev->actconfig->interface[i] = NULL; in usb_disable_device()
1433 dev->actconfig = NULL; in usb_disable_device()
1434 if (dev->state == USB_STATE_CONFIGURED) in usb_disable_device()
1438 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__, in usb_disable_device()
1439 skip_ep0 ? "non-ep0" : "all"); in usb_disable_device()
1445 * usb_enable_endpoint - Enable an endpoint for USB communications
1447 * @ep: the endpoint
1448 * @reset_ep: flag to reset the endpoint state
1450 * Resets the endpoint state if asked, and sets dev->ep_{in,out} pointers.
1456 int epnum = usb_endpoint_num(&ep->desc); in usb_enable_endpoint()
1457 int is_out = usb_endpoint_dir_out(&ep->desc); in usb_enable_endpoint()
1458 int is_control = usb_endpoint_xfer_control(&ep->desc); in usb_enable_endpoint()
1463 dev->ep_out[epnum] = ep; in usb_enable_endpoint()
1465 dev->ep_in[epnum] = ep; in usb_enable_endpoint()
1466 ep->enabled = 1; in usb_enable_endpoint()
1470 * usb_enable_interface - Enable all the endpoints for an interface
1480 struct usb_host_interface *alt = intf->cur_altsetting; in usb_enable_interface()
1483 for (i = 0; i < alt->desc.bNumEndpoints; ++i) in usb_enable_interface()
1484 usb_enable_endpoint(dev, &alt->endpoint[i], reset_eps); in usb_enable_interface()
1488 * usb_set_interface - Makes a particular alternate setting be current
1502 * speed interrupt endpoint may not send more than 64 bytes per microframe,
1509 * an endpoint in a given alternate setting is not reserved until an URB
1531 struct usb_hcd *hcd = bus_to_hcd(dev->bus); in usb_set_interface()
1536 if (dev->state == USB_STATE_SUSPENDED) in usb_set_interface()
1537 return -EHOSTUNREACH; in usb_set_interface()
1541 dev_dbg(&dev->dev, "selecting invalid interface %d\n", in usb_set_interface()
1543 return -EINVAL; in usb_set_interface()
1545 if (iface->unregistering) in usb_set_interface()
1546 return -ENODEV; in usb_set_interface()
1550 dev_warn(&dev->dev, "selecting invalid altsetting %d\n", in usb_set_interface()
1552 return -EINVAL; in usb_set_interface()
1556 * including freeing dropped endpoint ring buffers. in usb_set_interface()
1564 mutex_lock(hcd->bandwidth_mutex); in usb_set_interface()
1565 /* Disable LPM, and re-enable it once the new alt setting is installed, in usb_set_interface()
1569 dev_err(&iface->dev, "%s Failed to disable LPM\n", __func__); in usb_set_interface()
1570 mutex_unlock(hcd->bandwidth_mutex); in usb_set_interface()
1571 return -ENOMEM; in usb_set_interface()
1573 /* Changing alt-setting also frees any allocated streams */ in usb_set_interface()
1574 for (i = 0; i < iface->cur_altsetting->desc.bNumEndpoints; i++) in usb_set_interface()
1575 iface->cur_altsetting->endpoint[i].streams = 0; in usb_set_interface()
1577 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); in usb_set_interface()
1579 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", in usb_set_interface()
1582 mutex_unlock(hcd->bandwidth_mutex); in usb_set_interface()
1586 if (dev->quirks & USB_QUIRK_NO_SET_INTF) in usb_set_interface()
1587 ret = -EPIPE; in usb_set_interface()
1598 if (ret == -EPIPE && iface->num_altsetting == 1) { in usb_set_interface()
1599 dev_dbg(&dev->dev, in usb_set_interface()
1604 /* Re-instate the old alt setting */ in usb_set_interface()
1605 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); in usb_set_interface()
1607 mutex_unlock(hcd->bandwidth_mutex); in usb_set_interface()
1610 mutex_unlock(hcd->bandwidth_mutex); in usb_set_interface()
1613 * when they implement async or easily-killable versions of this or in usb_set_interface()
1614 * other "should-be-internal" functions (like clear_halt). in usb_set_interface()
1618 /* prevent submissions using previous endpoint settings */ in usb_set_interface()
1619 if (iface->cur_altsetting != alt) { in usb_set_interface()
1625 iface->cur_altsetting = alt; in usb_set_interface()
1627 /* Now that the interface is installed, re-enable LPM. */ in usb_set_interface()
1632 * by manually clearing the HALT feature for each endpoint in the in usb_set_interface()
1636 for (i = 0; i < alt->desc.bNumEndpoints; i++) { in usb_set_interface()
1637 epaddr = alt->endpoint[i].desc.bEndpointAddress; in usb_set_interface()
1654 * However, EP0 toggles are re-synced for every individual transfer in usb_set_interface()
1655 * during the SETUP stage - hence EP0 toggles are "don't care" here. in usb_set_interface()
1659 if (device_is_registered(&iface->dev)) { in usb_set_interface()
1668 * usb_reset_configuration - lightweight device reset
1672 * the current configuration. The effect is to reset most USB-related
1674 * endpoint halts (cleared), and endpoint state (only for bulk and interrupt
1679 * (multi-interface) devices. Instead, the driver for each interface may
1682 * reset all the interface state (notably endpoint state). Resetting the whole
1695 struct usb_host_config *config; in usb_reset_configuration() local
1696 struct usb_hcd *hcd = bus_to_hcd(dev->bus); in usb_reset_configuration()
1698 if (dev->state == USB_STATE_SUSPENDED) in usb_reset_configuration()
1699 return -EHOSTUNREACH; in usb_reset_configuration()
1708 config = dev->actconfig; in usb_reset_configuration()
1710 mutex_lock(hcd->bandwidth_mutex); in usb_reset_configuration()
1711 /* Disable LPM, and re-enable it once the configuration is reset, so in usb_reset_configuration()
1715 dev_err(&dev->dev, "%s Failed to disable LPM\n", __func__); in usb_reset_configuration()
1716 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_configuration()
1717 return -ENOMEM; in usb_reset_configuration()
1721 retval = usb_hcd_alloc_bandwidth(dev, config, NULL, NULL); in usb_reset_configuration()
1724 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_configuration()
1728 config->desc.bConfigurationValue, 0, in usb_reset_configuration()
1734 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_configuration()
1737 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_configuration()
1739 /* re-init hc/hcd interface/endpoint state */ in usb_reset_configuration()
1740 for (i = 0; i < config->desc.bNumInterfaces; i++) { in usb_reset_configuration()
1741 struct usb_interface *intf = config->interface[i]; in usb_reset_configuration()
1748 * so non-compliant that it doesn't have altsetting 0 in usb_reset_configuration()
1752 alt = &intf->altsetting[0]; in usb_reset_configuration()
1754 if (alt != intf->cur_altsetting) { in usb_reset_configuration()
1758 intf->cur_altsetting = alt; in usb_reset_configuration()
1760 if (device_is_registered(&intf->dev)) { in usb_reset_configuration()
1765 /* Now that the interfaces are installed, re-enable LPM. */ in usb_reset_configuration()
1775 altsetting_to_usb_interface_cache(intf->altsetting); in usb_release_interface()
1777 kref_put(&intfc->ref, usb_release_interface_cache); in usb_release_interface()
1779 of_node_put(dev->of_node); in usb_release_interface()
1784 * usb_deauthorize_interface - deauthorize an USB interface
1790 struct device *dev = &intf->dev; in usb_deauthorize_interface()
1792 device_lock(dev->parent); in usb_deauthorize_interface()
1794 if (intf->authorized) { in usb_deauthorize_interface()
1796 intf->authorized = 0; in usb_deauthorize_interface()
1802 device_unlock(dev->parent); in usb_deauthorize_interface()
1806 * usb_authorize_interface - authorize an USB interface
1812 struct device *dev = &intf->dev; in usb_authorize_interface()
1814 if (!intf->authorized) { in usb_authorize_interface()
1816 intf->authorized = 1; /* authorize interface */ in usb_authorize_interface()
1829 alt = intf->cur_altsetting; in usb_if_uevent()
1832 alt->desc.bInterfaceClass, in usb_if_uevent()
1833 alt->desc.bInterfaceSubClass, in usb_if_uevent()
1834 alt->desc.bInterfaceProtocol)) in usb_if_uevent()
1835 return -ENOMEM; in usb_if_uevent()
1840 le16_to_cpu(usb_dev->descriptor.idVendor), in usb_if_uevent()
1841 le16_to_cpu(usb_dev->descriptor.idProduct), in usb_if_uevent()
1842 le16_to_cpu(usb_dev->descriptor.bcdDevice), in usb_if_uevent()
1843 usb_dev->descriptor.bDeviceClass, in usb_if_uevent()
1844 usb_dev->descriptor.bDeviceSubClass, in usb_if_uevent()
1845 usb_dev->descriptor.bDeviceProtocol, in usb_if_uevent()
1846 alt->desc.bInterfaceClass, in usb_if_uevent()
1847 alt->desc.bInterfaceSubClass, in usb_if_uevent()
1848 alt->desc.bInterfaceProtocol, in usb_if_uevent()
1849 alt->desc.bInterfaceNumber)) in usb_if_uevent()
1850 return -ENOMEM; in usb_if_uevent()
1862 struct usb_host_config *config, in find_iad() argument
1871 for (i = 0; (i < USB_MAXIADS && config->intf_assoc[i]); i++) { in find_iad()
1872 intf_assoc = config->intf_assoc[i]; in find_iad()
1873 if (intf_assoc->bInterfaceCount == 0) in find_iad()
1876 first_intf = intf_assoc->bFirstInterface; in find_iad()
1877 last_intf = first_intf + (intf_assoc->bInterfaceCount - 1); in find_iad()
1882 dev_err(&dev->dev, "Interface #%d referenced" in find_iad()
1919 device_lock(iface->dev.parent); in __usb_wireless_status_intf()
1920 if (iface->sysfs_files_created) in __usb_wireless_status_intf()
1922 device_unlock(iface->dev.parent); in __usb_wireless_status_intf()
1927 * usb_set_wireless_status - sets the wireless_status struct member
1934 * Returns: 0 on success, -EALREADY if already set.
1939 if (iface->wireless_status == status) in usb_set_wireless_status()
1940 return -EALREADY; in usb_set_wireless_status()
1943 iface->wireless_status = status; in usb_set_wireless_status()
1944 schedule_work(&iface->wireless_status_work); in usb_set_wireless_status()
1951 * usb_set_configuration - Makes a particular device setting be current
1957 * This is used to enable non-default device modes. Not all devices
1963 * must be non-zero; a value of zero indicates that the device in
1966 * accept @configuration = -1 as indicating the device should be put in
1974 * non-default device configuration. Other device modes may also be
1979 * Note that a non-authorized device (dev->authorized == 0) will only
2001 struct usb_hcd *hcd = bus_to_hcd(dev->bus); in usb_set_configuration()
2004 if (dev->authorized == 0 || configuration == -1) in usb_set_configuration()
2007 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { in usb_set_configuration()
2008 if (dev->config[i].desc.bConfigurationValue == in usb_set_configuration()
2010 cp = &dev->config[i]; in usb_set_configuration()
2016 return -EINVAL; in usb_set_configuration()
2021 * Use -1 if you really want to unconfigure the device. in usb_set_configuration()
2024 dev_warn(&dev->dev, "config 0 descriptor??\n"); in usb_set_configuration()
2030 nintf = cp->desc.bNumInterfaces; in usb_set_configuration()
2034 return -ENOMEM; in usb_set_configuration()
2041 ret = -ENOMEM; in usb_set_configuration()
2043 while (--n >= 0) in usb_set_configuration()
2050 i = dev->bus_mA - usb_get_max_power(dev, cp); in usb_set_configuration()
2052 dev_warn(&dev->dev, "new config #%d exceeds power " in usb_set_configuration()
2054 configuration, -i); in usb_set_configuration()
2057 /* Wake up the device so we can send it the Set-Config request */ in usb_set_configuration()
2065 if (dev->state != USB_STATE_ADDRESS) in usb_set_configuration()
2068 /* Get rid of pending async Set-Config requests for this device */ in usb_set_configuration()
2077 mutex_lock(hcd->bandwidth_mutex); in usb_set_configuration()
2078 /* Disable LPM, and re-enable it once the new configuration is in usb_set_configuration()
2082 if (dev->actconfig && usb_disable_lpm(dev)) { in usb_set_configuration()
2083 dev_err(&dev->dev, "%s Failed to disable LPM\n", __func__); in usb_set_configuration()
2084 mutex_unlock(hcd->bandwidth_mutex); in usb_set_configuration()
2085 ret = -ENOMEM; in usb_set_configuration()
2090 if (dev->actconfig) in usb_set_configuration()
2092 mutex_unlock(hcd->bandwidth_mutex); in usb_set_configuration()
2099 * hc/hcd/usbcore interface/endpoint state. in usb_set_configuration()
2107 cp->interface[i] = intf = new_interfaces[i]; in usb_set_configuration()
2108 intfc = cp->intf_cache[i]; in usb_set_configuration()
2109 intf->altsetting = intfc->altsetting; in usb_set_configuration()
2110 intf->num_altsetting = intfc->num_altsetting; in usb_set_configuration()
2111 intf->authorized = !!HCD_INTF_AUTHORIZED(hcd); in usb_set_configuration()
2112 kref_get(&intfc->ref); in usb_set_configuration()
2118 * so non-compliant that it doesn't have altsetting 0 in usb_set_configuration()
2122 alt = &intf->altsetting[0]; in usb_set_configuration()
2124 ifnum = alt->desc.bInterfaceNumber; in usb_set_configuration()
2125 intf->intf_assoc = find_iad(dev, cp, ifnum); in usb_set_configuration()
2126 intf->cur_altsetting = alt; in usb_set_configuration()
2128 intf->dev.parent = &dev->dev; in usb_set_configuration()
2130 device_set_of_node_from_dev(&intf->dev, &dev->dev); in usb_set_configuration()
2132 intf->dev.of_node = usb_of_get_interface_node(dev, in usb_set_configuration()
2135 ACPI_COMPANION_SET(&intf->dev, ACPI_COMPANION(&dev->dev)); in usb_set_configuration()
2136 intf->dev.driver = NULL; in usb_set_configuration()
2137 intf->dev.bus = &usb_bus_type; in usb_set_configuration()
2138 intf->dev.type = &usb_if_device_type; in usb_set_configuration()
2139 intf->dev.groups = usb_interface_groups; in usb_set_configuration()
2140 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); in usb_set_configuration()
2141 INIT_WORK(&intf->wireless_status_work, __usb_wireless_status_intf); in usb_set_configuration()
2142 intf->minor = -1; in usb_set_configuration()
2143 device_initialize(&intf->dev); in usb_set_configuration()
2144 pm_runtime_no_callbacks(&intf->dev); in usb_set_configuration()
2145 dev_set_name(&intf->dev, "%d-%s:%d.%d", dev->bus->busnum, in usb_set_configuration()
2146 dev->devpath, configuration, ifnum); in usb_set_configuration()
2161 usb_disable_interface(dev, cp->interface[i], true); in usb_set_configuration()
2162 put_device(&cp->interface[i]->dev); in usb_set_configuration()
2163 cp->interface[i] = NULL; in usb_set_configuration()
2168 dev->actconfig = cp; in usb_set_configuration()
2169 mutex_unlock(hcd->bandwidth_mutex); in usb_set_configuration()
2180 if (cp->string == NULL && in usb_set_configuration()
2181 !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS)) in usb_set_configuration()
2182 cp->string = usb_cache_string(dev, cp->desc.iConfiguration); in usb_set_configuration()
2184 /* Now that the interfaces are installed, re-enable LPM. */ in usb_set_configuration()
2196 struct usb_interface *intf = cp->interface[i]; in usb_set_configuration()
2198 if (intf->dev.of_node && in usb_set_configuration()
2199 !of_device_is_available(intf->dev.of_node)) { in usb_set_configuration()
2200 dev_info(&dev->dev, "skipping disabled interface %d\n", in usb_set_configuration()
2201 intf->cur_altsetting->desc.bInterfaceNumber); in usb_set_configuration()
2205 dev_dbg(&dev->dev, in usb_set_configuration()
2206 "adding %s (config #%d, interface %d)\n", in usb_set_configuration()
2207 dev_name(&intf->dev), configuration, in usb_set_configuration()
2208 intf->cur_altsetting->desc.bInterfaceNumber); in usb_set_configuration()
2209 device_enable_async_suspend(&intf->dev); in usb_set_configuration()
2210 ret = device_add(&intf->dev); in usb_set_configuration()
2212 dev_err(&dev->dev, "device_add(%s) --> %d\n", in usb_set_configuration()
2213 dev_name(&intf->dev), ret); in usb_set_configuration()
2229 int config; member
2239 struct usb_device *udev = req->udev; in driver_set_config_work()
2243 list_del(&req->node); in driver_set_config_work()
2246 if (req->config >= -1) /* Is req still valid? */ in driver_set_config_work()
2247 usb_set_configuration(udev, req->config); in driver_set_config_work()
2253 /* Cancel pending Set-Config requests for a device whose configuration
2262 if (req->udev == udev) in cancel_async_set_config()
2263 req->config = -999; /* Mark as cancelled */ in cancel_async_set_config()
2269 * usb_driver_set_configuration - Provide a way for drivers to change device configurations
2271 * @config: the configuration being chosen.
2276 * driver is bound to and create new ones; it would be like a floppy-disk
2277 * driver telling the computer to replace the floppy-disk drive with a
2282 * submit the change-config request.
2288 int usb_driver_set_configuration(struct usb_device *udev, int config) in usb_driver_set_configuration() argument
2294 return -ENOMEM; in usb_driver_set_configuration()
2295 req->udev = udev; in usb_driver_set_configuration()
2296 req->config = config; in usb_driver_set_configuration()
2297 INIT_WORK(&req->work, driver_set_config_work); in usb_driver_set_configuration()
2300 list_add(&req->node, &set_config_list); in usb_driver_set_configuration()
2304 schedule_work(&req->work); in usb_driver_set_configuration()
2310 * cdc_parse_cdc_header - parse the extra headers present in CDC devices
2320 * Return: number of descriptors parsed or -EINVAL
2342 hdr->phonet_magic_present = false; in cdc_parse_cdc_header()
2346 dev_err(&intf->dev, "skipping garbage byte\n"); in cdc_parse_cdc_header()
2351 dev_err(&intf->dev, "invalid descriptor buffer length\n"); in cdc_parse_cdc_header()
2355 dev_err(&intf->dev, "skipping garbage\n"); in cdc_parse_cdc_header()
2364 dev_err(&intf->dev, "More than one union descriptor, skipping ...\n"); in cdc_parse_cdc_header()
2372 hdr->usb_cdc_country_functional_desc = in cdc_parse_cdc_header()
2379 return -EINVAL; in cdc_parse_cdc_header()
2385 hdr->usb_cdc_acm_descriptor = in cdc_parse_cdc_header()
2392 return -EINVAL; in cdc_parse_cdc_header()
2398 hdr->usb_cdc_call_mgmt_descriptor = in cdc_parse_cdc_header()
2404 hdr->usb_cdc_dmm_desc = in cdc_parse_cdc_header()
2411 return -EINVAL; in cdc_parse_cdc_header()
2418 return -EINVAL; in cdc_parse_cdc_header()
2424 hdr->usb_cdc_ncm_desc = (struct usb_cdc_ncm_desc *)buffer; in cdc_parse_cdc_header()
2430 hdr->usb_cdc_mbim_desc = (struct usb_cdc_mbim_desc *)buffer; in cdc_parse_cdc_header()
2435 hdr->usb_cdc_mbim_extended_desc = in cdc_parse_cdc_header()
2439 hdr->phonet_magic_present = true; in cdc_parse_cdc_header()
2446 dev_dbg(&intf->dev, "Ignoring descriptor: type %02x, length %ud\n", in cdc_parse_cdc_header()
2452 buflen -= elength; in cdc_parse_cdc_header()
2455 hdr->usb_cdc_union_desc = union_header; in cdc_parse_cdc_header()
2456 hdr->usb_cdc_header_desc = header; in cdc_parse_cdc_header()
2457 hdr->usb_cdc_mdlm_detail_desc = detail; in cdc_parse_cdc_header()
2458 hdr->usb_cdc_mdlm_desc = desc; in cdc_parse_cdc_header()
2459 hdr->usb_cdc_ether_desc = ether; in cdc_parse_cdc_header()