Skip to content
Snippets Groups Projects
  1. Dec 26, 2022
  2. Dec 22, 2022
  3. Dec 07, 2022
  4. Dec 05, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Workaround for XRUN at prepare · 198dde08
      Takashi Iwai authored
      
      Under certain situations (typically in the implicit feedback mode),
      USB-audio driver starts a playback stream already at PCM prepare call
      even before the actual PCM trigger-START call.  For implicit feedback
      mode, this effectively starts two streams for data and sync
      endpoints, and if a coupled sync stream gets XRUN at this point, it
      results in an error -EPIPE.
      
      The problem is that currently we return -EPIPE error as is from the
      prepare.  Then application tries to recover again via the prepare
      call, but it'll fail again because the sync-stop is missing.  The
      sync-stop is missing because it's an internal trigger call (hence the
      PCM core isn't involved).
      
      Since we'll need to re-issue the prepare in anyway when trapped into
      this pitfall, this patch attempts to address it in a bit different
      way; namely, the driver tries to prepare once again after syncing the
      stop manually by itself -- so applications don't see the internal
      error.  At the second failure, we report the error as is, but this
      shouldn't happen in normal situations.
      
      Reported-and-tested-by: default avatarCarl Hetherington <lists@carlh.net>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/b4e71631-4a94-613-27b2-fb595792630@carlh.net
      Link: https://lore.kernel.org/r/20221205132124.11585-4-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      198dde08
  5. Nov 29, 2022
    • John Keeping's avatar
      ALSA: usb-audio: Add quirk for Tascam Model 12 · 67df411d
      John Keeping authored and Takashi Iwai's avatar Takashi Iwai committed
      
      Tascam's Model 12 is a mixer which can also operate as a USB audio
      interface.  The audio interface uses explicit feedback but it seems that
      it does not correctly handle missing isochronous frames.
      
      When injecting an xrun (or doing anything else that pauses the playback
      stream) the feedback rate climbs (for example, at 44,100Hz nominal, I
      see a stable rate around 44,099 but xrun injection sees this peak at
      around 44,135 in most cases) and glitches are heard in the audio stream
      for several seconds - this is significantly worse than the single glitch
      expected for an underrun.
      
      While the stream does normally recover and the feedback rate returns to
      a stable value, I have seen some occurrences where this does not happen
      and the rate continues to increase while no audio is heard from the
      output.  I have not found a solid reproduction for this.
      
      This misbehaviour can be avoided by totally resetting the stream state
      by switching the interface to alt 0 and back before restarting the
      playback stream.
      
      Add a new quirk flag which forces the endpoint and interface to be
      reconfigured whenever the stream is stopped, and use this for the Tascam
      Model 12.
      
      Separate interfaces are used for the playback and capture endpoints, so
      resetting the playback interface here will not affect the capture stream
      if it is running.  While there are two endpoints on the interface,
      these are the OUT data endpoint and the IN explicit feedback endpoint
      corresponding to it and these are always stopped and started together.
      
      Signed-off-by: default avatarJohn Keeping <john@metanate.com>
      Link: https://lore.kernel.org/r/20221129130100.1257904-1-john@metanate.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      67df411d
  6. Nov 12, 2022
  7. Nov 10, 2022
  8. Nov 09, 2022
  9. Nov 08, 2022
  10. Oct 21, 2022
  11. Oct 09, 2022
  12. Sep 30, 2022
  13. Sep 27, 2022
  14. Sep 20, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Properly refcounting clock rate · 9a737e7f
      Takashi Iwai authored
      We fixed the bug introduced by the patch for managing the shared
      clocks at the commit 809f44a0 ("ALSA: usb-audio: Clear fixed clock
      rate at closing EP"), but it was merely a workaround.  By this change,
      the clock reference rate is cleared at each EP close, hence the still
      remaining EP may need a re-setup of rate unnecessarily.
      
      This patch introduces the proper refcounting for the clock reference
      object so that the clock setup is done only when needed.
      
      Fixes: 809f44a0 ("ALSA: usb-audio: Clear fixed clock rate at closing EP")
      Fixes: c11117b6 ("ALSA: usb-audio: Refcount multiple accesses on the single clock")
      Link: https://lore.kernel.org/r/20220920181126.4912-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      9a737e7f
    • Takashi Iwai's avatar
      ALSA: usb-audio: Split endpoint setups for hw_params and prepare (take#2) · 2be79d58
      Takashi Iwai authored
      
      This is a second attempt to fix the bug appearing on Android with the
      recent kernel; the first try was ff878b40 and reverted at commit
      79764ec7.
      
      The details taken from the v1 patch:
      
      One of the former changes for the endpoint management was the more
      consistent setup of endpoints at hw_params.
      snd_usb_endpoint_configure() is a single function that does the full
      setup, and it's called from both PCM hw_params and prepare callbacks.
      Although the EP setup at the prepare phase is usually skipped (by
      checking need_setup flag), it may be still effective in some cases
      like suspend/resume that requires the interface setup again.
      
      As it's a full and single setup, the invocation of
      snd_usb_endpoint_configure() includes not only the USB interface setup
      but also the buffer release and allocation.  OTOH, doing the buffer
      release and re-allocation at PCM prepare phase is rather superfluous,
      and better to be done only in the hw_params phase.
      
      For those optimizations, this patch splits the endpoint setup to two
      phases: snd_usb_endpoint_set_params() and snd_usb_endpoint_prepare(),
      to be called from hw_params and from prepare, respectively.
      
      Note that this patch changes the driver operation slightly,
      effectively moving the USB interface setup again to PCM prepare stage
      instead of hw_params stage, while the buffer allocation and such
      initializations are still done at hw_params stage.
      
      And, the change of the USB interface setup timing (moving to prepare)
      gave an interesting "fix", too: it was reported that the recent
      kernels caused silent output at the beginning on playbacks on some
      devices on Android, and this change casually fixed the regression.
      It seems that those devices are picky about the sample rate change (or
      the interface change?), and don't follow the too immediate rate
      changes.
      
      Meanwhile, Android operates the PCM in the following order:
      - open, then hw_params with the possibly highest sample rate
      - close without prepare
      - re-open, hw_params with the normal sample rate
      - prepare, and start streaming
      This procedure ended up the hw_params twice with different rates, and
      because the recent kernel did set up the sample rate twice one and
      after, it screwed up the device.  OTOH, the earlier kernels didn't set
      up the USB interface at hw_params, hence this problem didn't appear.
      
      Now, with this patch, the USB interface setup is again back to the
      prepare phase, and it works around the problem automagically.
      Although we should address the sample rate problem in a more solid
      way in future, let's keep things working as before for now.
      
      ***
      
      What's new in the take#2 patch:
      - The regression caused by the v1 patch (bko#216500) was due to the
        missing check of need_setup flag at hw_params.  Now the check is
        added, and the snd_usb_endpoint_set_params() call is skipped when
        the running EP is re-opened.
      
      - There was another bug in v1 where the clock reference rate wasn't
        updated at hw_params phase, which may lead to a lack of the proper
        hw constraints when an application doesn't issue the prepare but
        only the hw_params call.  This patch fixes it as well by tracking
        the clock rate change in the prepare callback with a new flag
        "need_update" for the clock reference object, just like others.
      
      - The configure_endpoints() are simplified and folded back into
        snd_usb_pcm_prepare().
      
      Fixes: bf6313a0 ("ALSA: usb-audio: Refactor endpoint management")
      Fixes: ff878b40 ("ALSA: usb-audio: Split endpoint setups for hw_params and prepare")
      Reported-by: default avatarchihhao chen <chihhao.chen@mediatek.com>
      Link: https://lore.kernel.org/r/87e6d6ae69d68dc588ac9acc8c0f24d6188375c3.camel@mediatek.com
      Link: https://lore.kernel.org/r/20220901124136.4984-1-tiwai@suse.de
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216500
      Link: https://lore.kernel.org/r/20220920181106.4894-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      2be79d58
    • Takashi Iwai's avatar
      Revert "ALSA: usb-audio: Clean up endpoint setups at PCM prepare" · 01a72aef
      Takashi Iwai authored
      
      This reverts commit 32eeeed9.
      
      As the fix for endpoint configuration split is reverted at next, do
      another revert here for a clean patch application.
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      01a72aef
    • Takashi Iwai's avatar
      Revert "ALSA: usb-audio: Split endpoint setups for hw_params and prepare" · 79764ec7
      Takashi Iwai authored
      This reverts commit ff878b40.
      
      Unfortunately the recent fix seems bringing another regressions with
      PulseAudio / pipewire, at least for Steinberg and MOTU devices.
      
      As a temporary solution, do a straight revert.  The issue for Android
      will be revisited again later by another different fix (if any).
      
      Fixes: ff878b40 ("ALSA: usb-audio: Split endpoint setups for hw_params and prepare")
      Cc: <stable@vger.kernel.org>
      BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=216500
      Link: https://lore.kernel.org/r/20220920113929.25162-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      79764ec7
  15. Sep 15, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix last interface check for registration · 39efc9c8
      Takashi Iwai authored
      The recent fix in commit 6392dcd1 ("ALSA: usb-audio: Register card
      at the last interface") tried to delay the card registration until the
      last found interface is probed.  It assumed that the probe callback
      gets called for those later interfaces, but it's not always true; as
      the driver loops over the descriptor and probes the matching ones,
      it's not separately called via multiple probe calls.  This results in
      the missing card registration, i.e. no sound device.
      
      For addressing this problem, replace the check whether the last
      interface is processed with usb_interface_claimed() instead of the
      comparison with the probe interface number.
      
      Fixes: 6392dcd1 ("ALSA: usb-audio: Register card at the last interface")
      Link: https://lore.kernel.org/r/20220915085947.7922-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      39efc9c8
  16. Sep 09, 2022
  17. Sep 07, 2022
  18. Sep 06, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Register card at the last interface · 6392dcd1
      Takashi Iwai authored
      The USB-audio driver matches per interface, and as default, it
      registers the card instance at the very first instance.  This can be a
      problem for the devices that have multiple interfaces to be probed, as
      the udev rule isn't applied properly for the later appearing
      interfaces.  Although we introduced the delayed_register option and
      the quirks for covering those shortcomings, it's nothing but a
      workaround for specific devices.
      
      This patch is an another attempt to fix the problem in a more generic
      way.  Now the driver checks the whole USB device descriptor at the
      very first time when an interface is attached to a sound card.  It
      looks at each matching interface in the descriptor and remembers the
      last matching one.  The snd_card_register() is invoked only when this
      last interface is probed.
      
      After this change, the quirks for the delayed registration become
      superfluous, hence they are removed along with the patch.  OTOH, the
      delayed_register option is still kept, as it might be useful for some
      corner cases (e.g. a special driver overtakes the interface probe from
      the standard driver, and the last interface probe may miss).
      
      Link: https://lore.kernel.org/r/20220904161247.16461-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      6392dcd1
    • Dongxiang Ke's avatar
      ALSA: usb-audio: Fix an out-of-bounds bug in __snd_usb_parse_audio_interface() · e53f47f6
      Dongxiang Ke authored and Takashi Iwai's avatar Takashi Iwai committed
      
      There may be a bad USB audio device with a USB ID of (0x04fa, 0x4201) and
      the number of it's interfaces less than 4, an out-of-bounds read bug occurs
      when parsing the interface descriptor for this device.
      
      Fix this by checking the number of interfaces.
      
      Signed-off-by: default avatarDongxiang Ke <kdx.glider@gmail.com>
      Link: https://lore.kernel.org/r/20220906024928.10951-1-kdx.glider@gmail.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      e53f47f6
  19. Sep 01, 2022
    • Takashi Iwai's avatar
      ALSA: usb-audio: Clean up endpoint setups at PCM prepare · 32eeeed9
      Takashi Iwai authored
      This patch cleans up the superfluous checks and calls for setting up
      the endpoints at PCM prepare callback:
      
      - Drop stop_endpoints() and sync_pending_stops() calls; the stream is
        guaranteed to have been already stopped and synced at each PCM
        prepare call by ALSA PCM core
      
      - Call snd_usb_endpoint_prepare() unconditionally;
        the check for endpoint->need_setup is done in
        snd_pcm_hw_endpoint_prepare() itself
      
      - Apply snd_usb_set_format_quirk() only when the endpoint is actually
        set up (i.e. the return code from snd_usb_endpoint_prepare() > 0)
      
      - Move a few lines back into snd_usb_pcm_prepare();
        it's even easier to follow than a small useless function
      
      Link: https://lore.kernel.org/r/20220901130831.6136-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      32eeeed9
    • Takashi Iwai's avatar
      ALSA: usb-audio: Split endpoint setups for hw_params and prepare · ff878b40
      Takashi Iwai authored
      
      One of the former changes for the endpoint management was the more
      consistent setup of endpoints at hw_params.
      snd_usb_endpoint_configure() is a single function that does the full
      setup, and it's called from both PCM hw_params and prepare callbacks.
      Although the EP setup at the prepare phase is usually skipped (by
      checking need_setup flag), it may be still effective in some cases
      like suspend/resume that requires the interface setup again.
      
      As it's a full and single setup, the invocation of
      snd_usb_endpoint_configure() includes not only the USB interface setup
      but also the buffer release and allocation.  OTOH, doing the buffer
      release and re-allocation at PCM prepare phase is rather superfluous,
      and better to be done only in the hw_params phase.
      
      For those optimizations, this patch splits the endpoint setup to two
      phases: snd_usb_endpoint_set_params() and snd_usb_endpoint_prepare(),
      to be called from hw_params and from prepare, respectively.
      
      Note that this patch changes the driver operation slightly,
      effectively moving the USB interface setup again to PCM prepare stage
      instead of hw_params stage, while the buffer allocation and such
      initializations are still done at hw_params stage.
      
      And, the change of the USB interface setup timing (moving to prepare)
      gave an interesting "fix", too: it was reported that the recent
      kernels caused silent output at the beginning on playbacks on some
      devices on Android, and this change casually fixed the regression.
      It seems that those devices are picky about the sample rate change (or
      the interface change?), and don't follow the too immediate rate
      changes.
      
      Meanwhile, Android operates the PCM in the following order:
      - open, then hw_params with the possibly highest sample rate
      - close without prepare
      - re-open, hw_params with the normal sample rate
      - prepare, and start streaming
      This procedure ended up the hw_params twice with different rates, and
      because the recent kernel did set up the sample rate twice one and
      after, it screwed up the device.  OTOH, the earlier kernels didn't set
      up the USB interface at hw_params, hence this problem didn't appear.
      
      Now, with this patch, the USB interface setup is again back to the
      prepare phase, and it works around the problem automagically.
      Although we should address the sample rate problem in a more solid
      way in future, let's keep things working as before for now.
      
      Fixes: bf6313a0 ("ALSA: usb-audio: Refactor endpoint management")
      Cc: <stable@vger.kernel.org>
      Reported-by: default avatarchihhao chen <chihhao.chen@mediatek.com>
      Link: https://lore.kernel.org/r/87e6d6ae69d68dc588ac9acc8c0f24d6188375c3.camel@mediatek.com
      Link: https://lore.kernel.org/r/20220901124136.4984-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      ff878b40
    • Takashi Iwai's avatar
      ALSA: usb-audio: Drop superfluous interface setup at parsing · ac5e2fb4
      Takashi Iwai authored
      We reset each interface that is being parsed for each stream, but this
      is superfluous and even can lead to spurious errors.  Since the
      interface is set up properly at opening the endpoint for each actual
      stream operation, let's drop the superfluous one.
      
      Link: https://lore.kernel.org/r/20220831130021.4762-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      ac5e2fb4
    • Takashi Iwai's avatar
      ALSA: usb-audio: Register card again for iface over delayed_register option · 2027f114
      Takashi Iwai authored
      When the delayed registration is specified via either delayed_register
      option or the quirk, we delay the invocation of snd_card_register()
      until the given interface.  But if a wrong value has been set there
      and there are more interfaces over the given interface number,
      snd_card_register() call would be missing for those interfaces.
      
      This patch catches up those missing calls by fixing the comparison of
      the interface number.  Now the call is skipped only if the processed
      interface is less than the given interface, instead of the exact
      match.
      
      Fixes: b70038ef ("ALSA: usb-audio: Add delayed_register option")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216082
      Link: https://lore.kernel.org/r/20220831125901.4660-2-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      2027f114
    • Takashi Iwai's avatar
      ALSA: usb-audio: Inform the delayed registration more properly · 7e1afce5
      Takashi Iwai authored
      The info message that was added in the commit a4aad563 ("ALSA:
      usb-audio: Inform devices that need delayed registration") is actually
      useful to know the need for the delayed registration.  However, it
      turned out that this doesn't catch the all cases; namely, this warned
      only when a PCM stream is attached onto the existing PCM instance, but
      it doesn't count for a newly created PCM instance.  This made
      confusion as if there were no further delayed registration.
      
      This patch moves the check to the code path for either adding a stream
      or creating a PCM instance.  Also, make it simpler by checking the
      card->registered flag instead of querying each snd_device state.
      
      Fixes: a4aad563 ("ALSA: usb-audio: Inform devices that need delayed registration")
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=216082
      Link: https://lore.kernel.org/r/20220831125901.4660-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      7e1afce5
  20. Aug 28, 2022
  21. Aug 22, 2022
  22. Aug 10, 2022
  23. Aug 09, 2022
Loading