Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: usb-audio: Fix max bytes-per-interval calculation

The maxpacksize field in struct audioformat represents the maximum number
of bytes per isochronous interval. The current implementation only
special-cases high-speed endpoints and does not account for the different
computations required for SuperSpeed, SuperSpeedPlus, or eUSB2. As a
result, USB audio class devices operating at these speeds may fail to
stream correctly. The issue was observed on a MOTU 16A (2025) interface,
which requires more than 1024 bytes per interval at SuperSpeed.

This patch replaces the existing logic with a helper that computes the
correct maximum bytes-per-interval for all USB speeds, borrowing the logic
used in drivers/usb/core/urb.c.

Signed-off-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://patch.msgid.link/20251124210518.90054-1-dylan_robinson@motu.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Dylan Robinson and committed by
Takashi Iwai
a748e1db 9ef1203f

+32 -4
+32 -4
sound/usb/stream.c
··· 684 684 return NULL; 685 685 } 686 686 687 + static unsigned int 688 + snd_usb_max_bytes_per_interval(struct snd_usb_audio *chip, 689 + struct usb_host_interface *alts) 690 + { 691 + struct usb_host_endpoint *ep = &alts->endpoint[0]; 692 + unsigned int max_bytes = usb_endpoint_maxp(&ep->desc); 693 + 694 + /* SuperSpeed isoc endpoints have up to 16 bursts of up to 3 packets each */ 695 + if (snd_usb_get_speed(chip->dev) >= USB_SPEED_SUPER) { 696 + int burst = 1 + ep->ss_ep_comp.bMaxBurst; 697 + int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); 698 + max_bytes *= burst; 699 + max_bytes *= mult; 700 + } 701 + 702 + if (snd_usb_get_speed(chip->dev) == USB_SPEED_SUPER_PLUS && 703 + USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) { 704 + max_bytes = le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); 705 + } 706 + 707 + /* High speed, 1-3 packets/uframe, max 6 for eUSB2 double bw */ 708 + if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH) { 709 + if (usb_endpoint_is_hs_isoc_double(chip->dev, ep)) 710 + max_bytes = le32_to_cpu(ep->eusb2_isoc_ep_comp.dwBytesPerInterval); 711 + else 712 + max_bytes *= usb_endpoint_maxp_mult(&ep->desc); 713 + } 714 + 715 + return max_bytes; 716 + } 717 + 687 718 static struct audioformat * 688 719 audio_format_alloc_init(struct snd_usb_audio *chip, 689 720 struct usb_host_interface *alts, ··· 734 703 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 735 704 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 736 705 fp->protocol = protocol; 737 - fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 706 + fp->maxpacksize = snd_usb_max_bytes_per_interval(chip, alts); 738 707 fp->channels = num_channels; 739 - if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH) 740 - fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) 741 - * (fp->maxpacksize & 0x7ff); 742 708 fp->clock = clock; 743 709 INIT_LIST_HEAD(&fp->list); 744 710