linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Michal Pecio <michal.pecio@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	Dylan Robinson <dylan_robinson@motu.com>,
	linux-sound@vger.kernel.org, tiwai@suse.com, perex@perex.cz,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH] ALSA: usb-audio: Fix max bytes-per-interval calculation
Date: Sun, 30 Nov 2025 13:08:56 +0100	[thread overview]
Message-ID: <87h5ubd8o7.wl-tiwai@suse.de> (raw)
In-Reply-To: <20251130130035.6f44713e.michal.pecio@gmail.com>

On Sun, 30 Nov 2025 13:00:35 +0100,
Michal Pecio wrote:
> 
> On Sun, 30 Nov 2025 11:53:07 +0100, Takashi Iwai wrote:
> > On Sat, 29 Nov 2025 20:56:39 +0100,
> > Michal Pecio wrote:
> > > 
> > > On Mon, 24 Nov 2025 16:05:18 -0500, Dylan Robinson wrote:  
> > > > 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.  
> > > 
> > > Hi,
> > > 
> > > Since v6.18 we have usb_endpoint_max_periodic_payload(), which looks
> > > like the exact function you need. It is already used by uvcvideo and
> > > xhci_hcd, the latter being particularly important because it ensures
> > > that your endpoints will get the bandwidth allocation you expect.
> > > 
> > > The copy-pasta in urb.c should probably be cleaned up at this point,
> > > but that would be a separate and unrelated patch, of course.  
> > 
> > Thanks for the information!  So we can clean up a lot with this new
> > helper like below.
> 
> Yes, something like that.
> 
> Note that there is a small gotcha here: Dylan's patch and the original
> code, as well as usb_submit_urb(), didn't take wBytesPerInterval into
> account, while usb_endpoint_max_periodic_payload() and xhci_hcd do.
> 
> Odd SuperSpeed endpoints like those below will now be considered to
> have 512B/1536B capacity, not 1KB/2KB. Whether any such UAC devices
> exist (mine is UVC) I don't know. My only SuperSpeed UAC device uses
> one packet per interval and wMaxPacketSize == wBytesPerInterval.
> 
>         wMaxPacketSize     0x0400  1x 1024 bytes
>         bInterval               1
>         bMaxBurst               0
>         wBytesPerInterval     512
> 
>         wMaxPacketSize     0x0400  1x 1024 bytes
>         bInterval               1
>         bMaxBurst               1       /* two packets per interval */
>         wBytesPerInterval    1536
> 
> I also don't know whether this affects UAC operation in any way, but
> it's something to watch out for.
> 
> Ignoring wBytesPerInterval wasn't right either, because xhci_hcd would
> still reserve wBytesPerInterval bandwidth (as per spec) and URBs which
> exceed that could complete with an error.
> 
> If a device is found where wBytesPerInterval makes no sense and must be
> ignored, it needs to be ignored consistently across the kernel.

Agreed, it makes more sense to have the common criteria applied to all
places.

Dylan, could you check whether the cleanup is OK?
I'll apply it once after the confirmation.


thanks,

Takashi

  reply	other threads:[~2025-11-30 12:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251124210518.90054-1-dylan_robinson@motu.com>
2025-11-29 19:56 ` [PATCH] ALSA: usb-audio: Fix max bytes-per-interval calculation Michal Pecio
2025-11-30 10:53   ` Takashi Iwai
2025-11-30 12:00     ` Michal Pecio
2025-11-30 12:08       ` Takashi Iwai [this message]
2025-12-01 10:47         ` Michal Pecio
2025-12-01 23:10           ` Dylan Robinson
2025-12-02  7:08             ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h5ubd8o7.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=dylan_robinson@motu.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michal.pecio@gmail.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).