Lines Matching +full:endpoint +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0
37 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2) in find_next_descriptor()
39 buffer += h->bLength; in find_next_descriptor()
40 size -= h->bLength; in find_next_descriptor()
48 return buffer - buffer0; in find_next_descriptor()
58 * The SuperSpeedPlus Isoc endpoint companion descriptor immediately in usb_parse_ssp_isoc_endpoint_companion()
59 * follows the SuperSpeed Endpoint Companion descriptor in usb_parse_ssp_isoc_endpoint_companion()
62 if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP || in usb_parse_ssp_isoc_endpoint_companion()
64 dev_notice(ddev, "Invalid SuperSpeedPlus isoc endpoint companion" in usb_parse_ssp_isoc_endpoint_companion()
65 "for config %d interface %d altsetting %d ep %d.\n", in usb_parse_ssp_isoc_endpoint_companion()
66 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ssp_isoc_endpoint_companion()
69 memcpy(&ep->ssp_isoc_ep_comp, desc, USB_DT_SSP_ISOC_EP_COMP_SIZE); in usb_parse_ssp_isoc_endpoint_companion()
79 /* The SuperSpeed endpoint companion descriptor is supposed to in usb_parse_ss_endpoint_companion()
80 * be the first thing immediately following the endpoint descriptor. in usb_parse_ss_endpoint_companion()
84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP || in usb_parse_ss_endpoint_companion()
86 dev_notice(ddev, "No SuperSpeed endpoint companion for config %d " in usb_parse_ss_endpoint_companion()
89 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
95 * amount of data moved per endpoint service interval is one in usb_parse_ss_endpoint_companion()
98 ep->ss_ep_comp.bLength = USB_DT_SS_EP_COMP_SIZE; in usb_parse_ss_endpoint_companion()
99 ep->ss_ep_comp.bDescriptorType = USB_DT_SS_ENDPOINT_COMP; in usb_parse_ss_endpoint_companion()
100 if (usb_endpoint_xfer_isoc(&ep->desc) || in usb_parse_ss_endpoint_companion()
101 usb_endpoint_xfer_int(&ep->desc)) in usb_parse_ss_endpoint_companion()
102 ep->ss_ep_comp.wBytesPerInterval = in usb_parse_ss_endpoint_companion()
103 ep->desc.wMaxPacketSize; in usb_parse_ss_endpoint_companion()
106 buffer += desc->bLength; in usb_parse_ss_endpoint_companion()
107 size -= desc->bLength; in usb_parse_ss_endpoint_companion()
108 memcpy(&ep->ss_ep_comp, desc, USB_DT_SS_EP_COMP_SIZE); in usb_parse_ss_endpoint_companion()
111 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) { in usb_parse_ss_endpoint_companion()
112 dev_notice(ddev, "Control endpoint with bMaxBurst = %d in " in usb_parse_ss_endpoint_companion()
113 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
114 "setting to zero\n", desc->bMaxBurst, in usb_parse_ss_endpoint_companion()
115 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
116 ep->ss_ep_comp.bMaxBurst = 0; in usb_parse_ss_endpoint_companion()
117 } else if (desc->bMaxBurst > 15) { in usb_parse_ss_endpoint_companion()
118 dev_notice(ddev, "Endpoint with bMaxBurst = %d in " in usb_parse_ss_endpoint_companion()
119 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
120 "setting to 15\n", desc->bMaxBurst, in usb_parse_ss_endpoint_companion()
121 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
122 ep->ss_ep_comp.bMaxBurst = 15; in usb_parse_ss_endpoint_companion()
125 if ((usb_endpoint_xfer_control(&ep->desc) || in usb_parse_ss_endpoint_companion()
126 usb_endpoint_xfer_int(&ep->desc)) && in usb_parse_ss_endpoint_companion()
127 desc->bmAttributes != 0) { in usb_parse_ss_endpoint_companion()
128 dev_notice(ddev, "%s endpoint with bmAttributes = %d in " in usb_parse_ss_endpoint_companion()
129 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
131 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk", in usb_parse_ss_endpoint_companion()
132 desc->bmAttributes, in usb_parse_ss_endpoint_companion()
133 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
134 ep->ss_ep_comp.bmAttributes = 0; in usb_parse_ss_endpoint_companion()
135 } else if (usb_endpoint_xfer_bulk(&ep->desc) && in usb_parse_ss_endpoint_companion()
136 desc->bmAttributes > 16) { in usb_parse_ss_endpoint_companion()
137 dev_notice(ddev, "Bulk endpoint with more than 65536 streams in " in usb_parse_ss_endpoint_companion()
138 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
140 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
141 ep->ss_ep_comp.bmAttributes = 16; in usb_parse_ss_endpoint_companion()
142 } else if (usb_endpoint_xfer_isoc(&ep->desc) && in usb_parse_ss_endpoint_companion()
143 !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) && in usb_parse_ss_endpoint_companion()
144 USB_SS_MULT(desc->bmAttributes) > 3) { in usb_parse_ss_endpoint_companion()
145 dev_notice(ddev, "Isoc endpoint has Mult of %d in " in usb_parse_ss_endpoint_companion()
146 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
148 USB_SS_MULT(desc->bmAttributes), in usb_parse_ss_endpoint_companion()
149 cfgno, inum, asnum, ep->desc.bEndpointAddress); in usb_parse_ss_endpoint_companion()
150 ep->ss_ep_comp.bmAttributes = 2; in usb_parse_ss_endpoint_companion()
153 if (usb_endpoint_xfer_isoc(&ep->desc)) in usb_parse_ss_endpoint_companion()
154 max_tx = (desc->bMaxBurst + 1) * in usb_parse_ss_endpoint_companion()
155 (USB_SS_MULT(desc->bmAttributes)) * in usb_parse_ss_endpoint_companion()
156 usb_endpoint_maxp(&ep->desc); in usb_parse_ss_endpoint_companion()
157 else if (usb_endpoint_xfer_int(&ep->desc)) in usb_parse_ss_endpoint_companion()
158 max_tx = usb_endpoint_maxp(&ep->desc) * in usb_parse_ss_endpoint_companion()
159 (desc->bMaxBurst + 1); in usb_parse_ss_endpoint_companion()
162 if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) { in usb_parse_ss_endpoint_companion()
163 dev_notice(ddev, "%s endpoint with wBytesPerInterval of %d in " in usb_parse_ss_endpoint_companion()
164 "config %d interface %d altsetting %d ep %d: " in usb_parse_ss_endpoint_companion()
166 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int", in usb_parse_ss_endpoint_companion()
167 le16_to_cpu(desc->wBytesPerInterval), in usb_parse_ss_endpoint_companion()
168 cfgno, inum, asnum, ep->desc.bEndpointAddress, in usb_parse_ss_endpoint_companion()
170 ep->ss_ep_comp.wBytesPerInterval = cpu_to_le16(max_tx); in usb_parse_ss_endpoint_companion()
173 if (usb_endpoint_xfer_isoc(&ep->desc) && in usb_parse_ss_endpoint_companion()
174 USB_SS_SSP_ISOC_COMP(desc->bmAttributes)) in usb_parse_ss_endpoint_companion()
209 if (e1->bEndpointAddress == e2->bEndpointAddress) in endpoint_is_duplicate()
221 * Check for duplicate endpoint addresses in other interfaces and in the
224 static bool config_endpoint_is_duplicate(struct usb_host_config *config, in config_endpoint_is_duplicate() argument
232 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in config_endpoint_is_duplicate()
233 intfc = config->intf_cache[i]; in config_endpoint_is_duplicate()
235 for (j = 0; j < intfc->num_altsetting; ++j) { in config_endpoint_is_duplicate()
236 alt = &intfc->altsetting[j]; in config_endpoint_is_duplicate()
238 if (alt->desc.bInterfaceNumber == inum && in config_endpoint_is_duplicate()
239 alt->desc.bAlternateSetting != asnum) in config_endpoint_is_duplicate()
242 for (k = 0; k < alt->desc.bNumEndpoints; ++k) { in config_endpoint_is_duplicate()
243 epd = &alt->endpoint[k].desc; in config_endpoint_is_duplicate()
255 struct usb_host_config *config, int inum, int asnum, in usb_parse_endpoint() argument
262 struct usb_host_endpoint *endpoint; in usb_parse_endpoint() local
268 buffer += d->bLength; in usb_parse_endpoint()
269 size -= d->bLength; in usb_parse_endpoint()
271 if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE) in usb_parse_endpoint()
273 else if (d->bLength >= USB_DT_ENDPOINT_SIZE) in usb_parse_endpoint()
276 dev_notice(ddev, "config %d interface %d altsetting %d has an " in usb_parse_endpoint()
277 "invalid endpoint descriptor of length %d, skipping\n", in usb_parse_endpoint()
278 cfgno, inum, asnum, d->bLength); in usb_parse_endpoint()
282 i = d->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; in usb_parse_endpoint()
284 dev_notice(ddev, "config %d interface %d altsetting %d has an " in usb_parse_endpoint()
285 "invalid descriptor for endpoint zero, skipping\n", in usb_parse_endpoint()
291 if (ifp->desc.bNumEndpoints >= num_ep) in usb_parse_endpoint()
295 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints]; in usb_parse_endpoint()
296 memcpy(&endpoint->desc, d, n); in usb_parse_endpoint()
297 d = &endpoint->desc; in usb_parse_endpoint()
300 i = d->bEndpointAddress & in usb_parse_endpoint()
302 if (i != d->bEndpointAddress) { in usb_parse_endpoint()
303 …dev_notice(ddev, "config %d interface %d altsetting %d has an endpoint descriptor with address 0x%… in usb_parse_endpoint()
304 cfgno, inum, asnum, d->bEndpointAddress, i); in usb_parse_endpoint()
305 endpoint->desc.bEndpointAddress = i; in usb_parse_endpoint()
308 /* Check for duplicate endpoint addresses */ in usb_parse_endpoint()
309 if (config_endpoint_is_duplicate(config, inum, asnum, d)) { in usb_parse_endpoint()
310 …dev_notice(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X,… in usb_parse_endpoint()
311 cfgno, inum, asnum, d->bEndpointAddress); in usb_parse_endpoint()
316 if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) { in usb_parse_endpoint()
318 …dev_notice(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, … in usb_parse_endpoint()
320 d->bEndpointAddress); in usb_parse_endpoint()
325 /* Accept this endpoint */ in usb_parse_endpoint()
326 ++ifp->desc.bNumEndpoints; in usb_parse_endpoint()
327 INIT_LIST_HEAD(&endpoint->urb_list); in usb_parse_endpoint()
337 switch (udev->speed) { in usb_parse_endpoint()
342 * Many device manufacturers are using full-speed in usb_parse_endpoint()
343 * bInterval values in high-speed interrupt endpoint in usb_parse_endpoint()
345 * 8-ms default value otherwise. in usb_parse_endpoint()
347 n = fls(d->bInterval*8); in usb_parse_endpoint()
349 n = 7; /* 8 ms = 2^(7-1) uframes */ in usb_parse_endpoint()
358 if (udev->quirks & USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL) { in usb_parse_endpoint()
359 n = clamp(fls(d->bInterval) + 3, i, j); in usb_parse_endpoint()
366 if (udev->quirks & USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL) { in usb_parse_endpoint()
367 n = clamp(fls(d->bInterval), i, j); in usb_parse_endpoint()
373 * For low-speed, 10 ms is the official minimum. in usb_parse_endpoint()
383 switch (udev->speed) { in usb_parse_endpoint()
385 n = 7; /* 8 ms = 2^(7-1) uframes */ in usb_parse_endpoint()
388 n = 4; /* 8 ms = 2^(4-1) frames */ in usb_parse_endpoint()
392 if (d->bInterval < i || d->bInterval > j) { in usb_parse_endpoint()
393 dev_notice(ddev, "config %d interface %d altsetting %d " in usb_parse_endpoint()
394 "endpoint 0x%X has an invalid bInterval %d, " in usb_parse_endpoint()
397 d->bEndpointAddress, d->bInterval, n); in usb_parse_endpoint()
398 endpoint->desc.bInterval = n; in usb_parse_endpoint()
401 /* Some buggy low-speed devices have Bulk endpoints, which is in usb_parse_endpoint()
405 if (udev->speed == USB_SPEED_LOW && usb_endpoint_xfer_bulk(d)) { in usb_parse_endpoint()
406 dev_notice(ddev, "config %d interface %d altsetting %d " in usb_parse_endpoint()
407 "endpoint 0x%X is Bulk; changing to Interrupt\n", in usb_parse_endpoint()
408 cfgno, inum, asnum, d->bEndpointAddress); in usb_parse_endpoint()
409 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT; in usb_parse_endpoint()
410 endpoint->desc.bInterval = 1; in usb_parse_endpoint()
411 if (usb_endpoint_maxp(&endpoint->desc) > 8) in usb_parse_endpoint()
412 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); in usb_parse_endpoint()
418 * the USB-2 spec requires such endpoints to have wMaxPacketSize = 0 in usb_parse_endpoint()
421 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize); in usb_parse_endpoint()
423 …dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\… in usb_parse_endpoint()
424 cfgno, inum, asnum, d->bEndpointAddress); in usb_parse_endpoint()
427 /* Find the highest legal maxpacket size for this endpoint */ in usb_parse_endpoint()
429 switch (udev->speed) { in usb_parse_endpoint()
437 /* Multiple-transactions bits are allowed only for HS periodic endpoints */ in usb_parse_endpoint()
451 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)]; in usb_parse_endpoint()
454 …dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, set… in usb_parse_endpoint()
455 cfgno, inum, asnum, d->bEndpointAddress, maxp, j); in usb_parse_endpoint()
457 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp); in usb_parse_endpoint()
465 if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) { in usb_parse_endpoint()
467 dev_notice(ddev, "config %d interface %d altsetting %d " in usb_parse_endpoint()
468 "bulk endpoint 0x%X has invalid maxpacket %d\n", in usb_parse_endpoint()
469 cfgno, inum, asnum, d->bEndpointAddress, in usb_parse_endpoint()
473 /* Parse a possible SuperSpeed endpoint companion descriptor */ in usb_parse_endpoint()
474 if (udev->speed >= USB_SPEED_SUPER) in usb_parse_endpoint()
476 inum, asnum, endpoint, buffer, size); in usb_parse_endpoint()
479 * find the next endpoint or interface descriptor */ in usb_parse_endpoint()
480 endpoint->extra = buffer; in usb_parse_endpoint()
483 endpoint->extralen = i; in usb_parse_endpoint()
484 retval = buffer - buffer0 + i; in usb_parse_endpoint()
487 n, plural(n), "endpoint"); in usb_parse_endpoint()
493 return buffer - buffer0 + i; in usb_parse_endpoint()
501 for (j = 0; j < intfc->num_altsetting; j++) { in usb_release_interface_cache()
502 struct usb_host_interface *alt = &intfc->altsetting[j]; in usb_release_interface_cache()
504 kfree(alt->endpoint); in usb_release_interface_cache()
505 kfree(alt->string); in usb_release_interface_cache()
511 struct usb_host_config *config, unsigned char *buffer, int size, in usb_parse_interface() argument
524 buffer += d->bLength; in usb_parse_interface()
525 size -= d->bLength; in usb_parse_interface()
527 if (d->bLength < USB_DT_INTERFACE_SIZE) in usb_parse_interface()
532 inum = d->bInterfaceNumber; in usb_parse_interface()
533 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_parse_interface()
535 intfc = config->intf_cache[i]; in usb_parse_interface()
539 if (!intfc || intfc->num_altsetting >= nalts[i]) in usb_parse_interface()
543 asnum = d->bAlternateSetting; in usb_parse_interface()
544 for ((i = 0, alt = &intfc->altsetting[0]); in usb_parse_interface()
545 i < intfc->num_altsetting; in usb_parse_interface()
547 if (alt->desc.bAlternateSetting == asnum) { in usb_parse_interface()
548 dev_notice(ddev, "Duplicate descriptor for config %d " in usb_parse_interface()
555 ++intfc->num_altsetting; in usb_parse_interface()
556 memcpy(&alt->desc, d, USB_DT_INTERFACE_SIZE); in usb_parse_interface()
559 * find the first endpoint or interface descriptor */ in usb_parse_interface()
560 alt->extra = buffer; in usb_parse_interface()
563 alt->extralen = i; in usb_parse_interface()
568 size -= i; in usb_parse_interface()
571 num_ep = num_ep_orig = alt->desc.bNumEndpoints; in usb_parse_interface()
572 alt->desc.bNumEndpoints = 0; /* Use as a counter */ in usb_parse_interface()
574 dev_notice(ddev, "too many endpoints for config %d interface %d " in usb_parse_interface()
583 alt->endpoint = kzalloc(len, GFP_KERNEL); in usb_parse_interface()
584 if (!alt->endpoint) in usb_parse_interface()
585 return -ENOMEM; in usb_parse_interface()
588 /* Parse all the endpoint descriptors */ in usb_parse_interface()
591 if (((struct usb_descriptor_header *) buffer)->bDescriptorType in usb_parse_interface()
594 retval = usb_parse_endpoint(ddev, cfgno, config, inum, asnum, in usb_parse_interface()
601 size -= retval; in usb_parse_interface()
605 dev_notice(ddev, "config %d interface %d altsetting %d has %d " in usb_parse_interface()
606 "endpoint descriptor%s, different from the interface " in usb_parse_interface()
609 return buffer - buffer0; in usb_parse_interface()
614 return buffer - buffer0 + i; in usb_parse_interface()
618 struct usb_host_config *config, unsigned char *buffer, int size) in usb_parse_configuration() argument
620 struct device *ddev = &dev->dev; in usb_parse_configuration()
633 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE); in usb_parse_configuration()
634 nintf = nintf_orig = config->desc.bNumInterfaces; in usb_parse_configuration()
635 config->desc.bNumInterfaces = 0; // Adjusted later in usb_parse_configuration()
637 if (config->desc.bDescriptorType != USB_DT_CONFIG || in usb_parse_configuration()
638 config->desc.bLength < USB_DT_CONFIG_SIZE || in usb_parse_configuration()
639 config->desc.bLength > size) { in usb_parse_configuration()
640 dev_notice(ddev, "invalid descriptor for config index %d: " in usb_parse_configuration()
642 config->desc.bDescriptorType, config->desc.bLength); in usb_parse_configuration()
643 return -EINVAL; in usb_parse_configuration()
645 cfgno = config->desc.bConfigurationValue; in usb_parse_configuration()
647 buffer += config->desc.bLength; in usb_parse_configuration()
648 size -= config->desc.bLength; in usb_parse_configuration()
651 dev_notice(ddev, "config %d has too many interfaces: %d, " in usb_parse_configuration()
662 (buffer2 += header->bLength, size2 -= header->bLength)) { in usb_parse_configuration()
665 dev_notice(ddev, "config %d descriptor has %d excess " in usb_parse_configuration()
672 if ((header->bLength > size2) || (header->bLength < 2)) { in usb_parse_configuration()
673 dev_notice(ddev, "config %d has an invalid descriptor " in usb_parse_configuration()
674 "of length %d, skipping remainder of the config\n", in usb_parse_configuration()
675 cfgno, header->bLength); in usb_parse_configuration()
679 if (header->bDescriptorType == USB_DT_INTERFACE) { in usb_parse_configuration()
684 if (d->bLength < USB_DT_INTERFACE_SIZE) { in usb_parse_configuration()
685 dev_notice(ddev, "config %d has an invalid " in usb_parse_configuration()
687 "skipping\n", cfgno, d->bLength); in usb_parse_configuration()
691 inum = d->bInterfaceNumber; in usb_parse_configuration()
693 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) && in usb_parse_configuration()
695 dev_notice(ddev, "config %d has more interface " in usb_parse_configuration()
703 dev_notice(ddev, "config %d has an invalid " in usb_parse_configuration()
705 cfgno, inum, nintf_orig - 1); in usb_parse_configuration()
722 } else if (header->bDescriptorType == in usb_parse_configuration()
727 if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) { in usb_parse_configuration()
729 "config %d has an invalid interface association descriptor of length %d, skipping\n", in usb_parse_configuration()
730 cfgno, d->bLength); in usb_parse_configuration()
740 config->intf_assoc[iad_num] = d; in usb_parse_configuration()
744 } else if (header->bDescriptorType == USB_DT_DEVICE || in usb_parse_configuration()
745 header->bDescriptorType == USB_DT_CONFIG) in usb_parse_configuration()
746 dev_notice(ddev, "config %d contains an unexpected " in usb_parse_configuration()
748 cfgno, header->bDescriptorType); in usb_parse_configuration()
751 size = buffer2 - buffer; in usb_parse_configuration()
752 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0); in usb_parse_configuration()
755 dev_notice(ddev, "config %d has %d interface%s, different from " in usb_parse_configuration()
759 dev_notice(ddev, "config %d has no interfaces?\n", cfgno); in usb_parse_configuration()
760 config->desc.bNumInterfaces = nintf = n; in usb_parse_configuration()
769 dev_notice(ddev, "config %d has no interface number " in usb_parse_configuration()
778 "config %d interface %d: %d, " in usb_parse_configuration()
785 config->intf_cache[i] = intfc; in usb_parse_configuration()
787 return -ENOMEM; in usb_parse_configuration()
788 kref_init(&intfc->ref); in usb_parse_configuration()
795 config->extra = buffer; in usb_parse_configuration()
798 config->extralen = i; in usb_parse_configuration()
803 size -= i; in usb_parse_configuration()
807 retval = usb_parse_interface(ddev, cfgno, config, in usb_parse_configuration()
813 size -= retval; in usb_parse_configuration()
818 intfc = config->intf_cache[i]; in usb_parse_configuration()
819 for (j = 0; j < intfc->num_altsetting; ++j) { in usb_parse_configuration()
820 for (n = 0; n < intfc->num_altsetting; ++n) { in usb_parse_configuration()
821 if (intfc->altsetting[n].desc. in usb_parse_configuration()
825 if (n >= intfc->num_altsetting) in usb_parse_configuration()
826 dev_notice(ddev, "config %d interface %d has no " in usb_parse_configuration()
834 /* hub-only!! ... and only exported for reset/reinit path.
841 if (!dev->config) in usb_destroy_configuration()
844 if (dev->rawdescriptors) { in usb_destroy_configuration()
845 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) in usb_destroy_configuration()
846 kfree(dev->rawdescriptors[i]); in usb_destroy_configuration()
848 kfree(dev->rawdescriptors); in usb_destroy_configuration()
849 dev->rawdescriptors = NULL; in usb_destroy_configuration()
852 for (c = 0; c < dev->descriptor.bNumConfigurations; c++) { in usb_destroy_configuration()
853 struct usb_host_config *cf = &dev->config[c]; in usb_destroy_configuration()
855 kfree(cf->string); in usb_destroy_configuration()
856 for (i = 0; i < cf->desc.bNumInterfaces; i++) { in usb_destroy_configuration()
857 if (cf->intf_cache[i]) in usb_destroy_configuration()
858 kref_put(&cf->intf_cache[i]->ref, in usb_destroy_configuration()
862 kfree(dev->config); in usb_destroy_configuration()
863 dev->config = NULL; in usb_destroy_configuration()
868 * Get the USB config descriptors, cache and parse'em
870 * hub-only!! ... and only in reset path, or usb_new_device()
875 struct device *ddev = &dev->dev; in usb_get_configuration()
876 int ncfg = dev->descriptor.bNumConfigurations; in usb_get_configuration()
885 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG; in usb_get_configuration()
890 return -EINVAL; in usb_get_configuration()
894 dev->config = kzalloc(length, GFP_KERNEL); in usb_get_configuration()
895 if (!dev->config) in usb_get_configuration()
896 return -ENOMEM; in usb_get_configuration()
899 dev->rawdescriptors = kzalloc(length, GFP_KERNEL); in usb_get_configuration()
900 if (!dev->rawdescriptors) in usb_get_configuration()
901 return -ENOMEM; in usb_get_configuration()
905 return -ENOMEM; in usb_get_configuration()
913 dev_err(ddev, "unable to read config index %d " in usb_get_configuration()
915 if (result != -EPIPE) in usb_get_configuration()
917 dev_notice(ddev, "chopping to %d config(s)\n", cfgno); in usb_get_configuration()
918 dev->descriptor.bNumConfigurations = cfgno; in usb_get_configuration()
921 dev_err(ddev, "config index %d descriptor too short " in usb_get_configuration()
924 result = -EINVAL; in usb_get_configuration()
927 length = max((int) le16_to_cpu(desc->wTotalLength), in usb_get_configuration()
933 result = -ENOMEM; in usb_get_configuration()
937 if (dev->quirks & USB_QUIRK_DELAY_INIT) in usb_get_configuration()
943 dev_err(ddev, "unable to read config index %d " in usb_get_configuration()
949 dev_notice(ddev, "config index %d descriptor too short " in usb_get_configuration()
954 dev->rawdescriptors[cfgno] = bigbuffer; in usb_get_configuration()
957 &dev->config[cfgno], bigbuffer, length); in usb_get_configuration()
966 dev->descriptor.bNumConfigurations = cfgno; in usb_get_configuration()
973 if (dev->bos) { in usb_release_bos_descriptor()
974 kfree(dev->bos->desc); in usb_release_bos_descriptor()
975 kfree(dev->bos); in usb_release_bos_descriptor()
976 dev->bos = NULL; in usb_release_bos_descriptor()
992 struct device *ddev = &dev->dev; in usb_get_bos_descriptor()
1003 return -ENOMEM; in usb_get_bos_descriptor()
1007 if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) { in usb_get_bos_descriptor()
1010 ret = -ENOMSG; in usb_get_bos_descriptor()
1015 length = bos->bLength; in usb_get_bos_descriptor()
1016 total_len = le16_to_cpu(bos->wTotalLength); in usb_get_bos_descriptor()
1017 num = bos->bNumDeviceCaps; in usb_get_bos_descriptor()
1020 return -EINVAL; in usb_get_bos_descriptor()
1022 dev->bos = kzalloc(sizeof(*dev->bos), GFP_KERNEL); in usb_get_bos_descriptor()
1023 if (!dev->bos) in usb_get_bos_descriptor()
1024 return -ENOMEM; in usb_get_bos_descriptor()
1029 ret = -ENOMEM; in usb_get_bos_descriptor()
1032 dev->bos->desc = (struct usb_bos_descriptor *)buffer; in usb_get_bos_descriptor()
1038 ret = -ENOMSG; in usb_get_bos_descriptor()
1043 total_len -= length; in usb_get_bos_descriptor()
1049 if (total_len < sizeof(*cap) || total_len < cap->bLength) { in usb_get_bos_descriptor()
1050 dev->bos->desc->bNumDeviceCaps = i; in usb_get_bos_descriptor()
1053 cap_type = cap->bDevCapabilityType; in usb_get_bos_descriptor()
1054 length = cap->bLength; in usb_get_bos_descriptor()
1056 dev->bos->desc->bNumDeviceCaps = i; in usb_get_bos_descriptor()
1060 if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) { in usb_get_bos_descriptor()
1067 dev->bos->ext_cap = in usb_get_bos_descriptor()
1071 dev->bos->ss_cap = in usb_get_bos_descriptor()
1076 ssac = (le32_to_cpu(ssp_cap->bmAttributes) & in usb_get_bos_descriptor()
1079 dev->bos->ssp_cap = ssp_cap; in usb_get_bos_descriptor()
1082 dev->bos->ss_id = in usb_get_bos_descriptor()
1086 dev->bos->ptm_cap = in usb_get_bos_descriptor()
1094 total_len -= length; in usb_get_bos_descriptor()
1097 dev->bos->desc->wTotalLength = cpu_to_le16(buffer - buffer0); in usb_get_bos_descriptor()