This project is mirrored from https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git. Pull mirroring updated .
  1. 08 Sep, 2021 2 commits
    • Takashi Iwai's avatar
      ALSA: usb-audio: Work around for XRUN with low latency playback · 8ab355d6
      Takashi Iwai authored
      commit 4267c5a8 upstream.
      
      The recent change for low latency playback works in most of test cases
      but it turned out still to hit errors on some use cases, most notably
      with JACK with small buffer sizes.  This is because USB-audio driver
      fills up and submits full URBs at the beginning, while the URBs would
      return immediately and try to fill more -- that can easily trigger
      XRUN.  It was more or less expected, but in the small buffer size, the
      problem became pretty obvious.
      
      Fixing this behavior properly would require the change of the
      fundamental driver design, so it's no trivial task, unfortunately.
      Instead, here we work around the problem just by switching back to the
      old method when the given configuration is too fragile with the low
      latency stream handling.  As a threshold, we calculate the total
      buffer bytes in all plus one URBs, and check whether it's beyond the
      PCM buffer bytes.  The one extra URB is needed because XRUN happens at
      the next submission after the first round.
      
      Fixes: 307cc9ba ("ALSA: usb-audio: Reduce latency at playback start, take#2")
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210827203311.5987-1-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ab355d6
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix regression on Sony WALKMAN NW-A45 DAC · 476081ac
      Takashi Iwai authored
      commit 7af5a143 upstream.
      
      We've got a regression report for USB-audio with Sony WALKMAN NW-A45
      DAC device where no sound is audible on recent kernel.  The bisection
      resulted in the code change wrt endpoint management, and the further
      debug session revealed that it was caused by the order of the USB
      audio interface.  In the earlier code, we always set up the USB
      interface at first before other setups, but it was changed to be done
      at the last for UAC2/3, which is more standard way, while keeping the
      old way for UAC1.  OTOH, this device seems requiring the setup of the
      interface at first just like UAC1.
      
      This patch works around the regression by applying the interface setup
      specifically for the WALKMAN at the beginning of the endpoint setup
      procedure.  This change is written straightforwardly to be easily
      backported in old kernels.  A further cleanup to move the workaround
      into a generic quirk section will follow in a later patch.
      
      Fixes: bf6313a0 ("ALSA: usb-audio: Refactor endpoint management")
      Cc: <stable@vger.kernel.org>
      BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=214105
      Link: https://lore.kernel.org/r/20210824054700.8236-1-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      476081ac
  2. 05 Jul, 2021 1 commit
  3. 02 Jun, 2021 1 commit
    • Takashi Iwai's avatar
      ALSA: usb-audio: Refactoring delay account code · e8a8f09c
      Takashi Iwai authored
      The PCM delay accounting in USB-audio driver is a bit complex to
      follow, and this is an attempt to improve the readability and provide
      some potential fix.
      
      Basically, the PCM position delay is calculated from two factors: the
      in-flight data on URBs and the USB frame counter.  For the playback
      stream, we advance the hwptr already at submitting URBs.  Those
      "in-flight" data amount is now tracked, and this is used as the base
      value for the PCM delay correction.  The in-flight data is decreased
      again at URB completion in return.  For the capture stream, OTOH,
      there is no in-flight data, hence the delay base is zero.
      
      The USB frame counter is used in addition for correcting the current
      position.  The reference frame counter is updated at each submission
      and receiving time, and the difference from the current counter value
      is taken into account.
      
      In this patch, each in-flight data bytes is recorded in the new
      snd_usb_ctx.queued field, and the total in-flight amount is tracked in
      snd_usb_substream.inflight_bytes field, as the replacement of
      last_delay field.
      
      Note that updating the hwptr after URB completion doesn't work for
      PulseAudio who tries to scratch the buffer on the fly; USB-audio is
      basically a double-buffer implementation, hence the scratching the
      buffer can't work for the already submitted data.  So we always update
      hwptr beforehand.  It's not ideal, but the delay account should give
      enough correctness.
      
      Link: https://lore.kernel.org/r/20210601162457.4877-4-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      e8a8f09c
  4. 26 Apr, 2021 1 commit
  5. 14 Apr, 2021 1 commit
    • Takashi Iwai's avatar
      ALSA: usb-audio: Apply implicit feedback mode for BOSS devices · ebe8dc5a
      Takashi Iwai authored
      During the recent rewrite of the implicit feedback support, we've
      tested to apply the implicit fb on BOSS devices, but it failed, as the
      capture stream didn't start without the playback.  As the end result,
      it got another type of quirk for tying both streams but starts
      playback always (commit 6234fdc1
      
       "ALSA: usb-audio: Quirk for BOSS
      GT-001").
      
      Meanwhile, Mike Oliphant has tested the real implicit feedback mode
      for the playback again with the latest code, and found out that it
      actually works if the initial feedback sync is skipped; that is, on
      those BOSS devices, the playback stream has to be started at first
      without waiting for the capture URB completions.  Otherwise it gets
      stuck.  In the rest operations after the capture stream processed, we
      can take them as the implicit feedback source.
      
      This patch is an attempt to improve the support for BOSS devices with
      the implicit feedback mode in the way described above.  It adds a new
      flag to snd_usb_audio, playback_first, indicating that the playback
      stream starts without sync with the initial capture completion.  This
      flag is set in the quirk table with the new IMPLICIT_FB_BOTH type.
      Reported-and-tested-by: default avatarMike Oliphant <oliphant@nostatic.org>
      Link: https://lore.kernel.org/r/20210414083255.9527-1-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      ebe8dc5a
  6. 08 Feb, 2021 3 commits
  7. 05 Feb, 2021 1 commit
  8. 18 Jan, 2021 1 commit
  9. 08 Jan, 2021 2 commits
    • Takashi Iwai's avatar
      ALSA: usb-audio: Annotate the endpoint index in audioformat · eae4d054
      Takashi Iwai authored
      There are devices that have multiple endpoints sharing the same
      iface/altset not only for sync but also for the actual streams, and
      the audioformat for such an endpoint needs to be handled with the
      proper endpoint index; otherwise it confuses the endpoint management.
      
      This patch extends the audioformat to annotate the endpoint index, and
      put the proper ep_idx=1 to Pioneer device quirk entries accordingly.
      
      Fixes: bf6313a0 ("ALSA: usb-audio: Refactor endpoint management")
      Link: https://lore.kernel.org/r/20210108075219.21463-5-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      eae4d054
    • Takashi Iwai's avatar
      ALSA: usb-audio: Avoid unnecessary interface re-setup · 00272c61
      Takashi Iwai authored
      The current endpoint handling assumed (more or less) a unique 1:1
      relation between the endpoint and the iface/altset.  The exception was
      the sync EP without the implicit feedback which has usually the
      secondary EP of the same altset.  This works fine for most devices,
      but it turned out that some unusual devices like Pinoeer's ones have
      both playback and capture endpoints in the same iface/altsetting and
      use both for the implicit feedback mode.  For handling such a case, we
      need to extend the endpoint management to take the shared interface
      into account.
      
      This patch does that: it adds a new object snd_usb_iface_ref for
      managing the reference counts of the each USB interface that is used
      by each endpoint.  The interface setup is performed only once for the
      (sharing) endpoints, and the doubly initialization is avoided.
      
      Along with this, the resource release of endpoints and interface
      refcounts are put into a single function, snd_usb_endpoint_free_all()
      instead of looping in the caller side.
      
      Fixes: bf6313a0 ("ALSA: usb-audio: Refactor endpoint management")
      Link: https://lore.kernel.org/r/20210108075219.21463-4-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      00272c61
  10. 23 Nov, 2020 14 commits
  11. 06 Oct, 2020 1 commit
  12. 27 Jul, 2020 1 commit
  13. 16 Jul, 2020 1 commit
  14. 30 Jun, 2020 2 commits
  15. 15 May, 2020 1 commit
  16. 24 Apr, 2020 2 commits
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix racy list management in output queue · 5b6cc38f
      Takashi Iwai authored
      The linked list entry from FIFO is peeked at
      queue_pending_output_urbs() but the actual element pop-out is
      performed outside the spinlock, and it's potentially racy.
      
      Do delete the link at the right place inside the spinlock.
      
      Fixes: 8fdff6a3 ("ALSA: snd-usb: implement new endpoint streaming model")
      Link: https://lore.kernel.org/r/20200424074016.14301-1-tiwai@suse.de
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      5b6cc38f
    • Alexander Tsoy's avatar
      ALSA: usb-audio: Improve frames size computation · f0bd62b6
      Alexander Tsoy authored
      
      
      For computation of the the next frame size current value of fs/fps and
      accumulated fractional parts of fs/fps are used, where values are stored
      in Q16.16 format. This is quite natural for computing frame size for
      asynchronous endpoints driven by explicit feedback, since in this case
      fs/fps is a value provided by the feedback endpoint and it's already in
      the Q format. If an error is accumulated over time, the device can
      adjust fs/fps value to prevent buffer overruns/underruns.
      
      But for synchronous endpoints the accuracy provided by these computations
      is not enough. Due to accumulated error the driver periodically produces
      frames with incorrect size (+/- 1 audio sample).
      
      This patch fixes this issue by implementing a different algorithm for
      frame size computation. It is based on accumulating of the remainders
      from division fs/fps and it doesn't accumulate errors over time. This
      new method is enabled for synchronous and adaptive playback endpoints.
      Signed-off-by: default avatarAlexander Tsoy <alexander@tsoy.me>
      Link: https://lore.kernel.org/r/20200424022449.14972-1-alexander@tsoy.me
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      f0bd62b6
  17. 13 Nov, 2019 1 commit
    • Henry Lin's avatar
      ALSA: usb-audio: not submit urb for stopped endpoint · 52869931
      Henry Lin authored
      
      
      While output urb's snd_complete_urb() is executing, calling
      prepare_outbound_urb() may cause endpoint stopped before
      prepare_outbound_urb() returns and result in next urb submitted
      to stopped endpoint. usb-audio driver cannot re-use it afterwards as
      the urb is still hold by usb stack.
      
      This change checks EP_FLAG_RUNNING flag after prepare_outbound_urb() again
      to let snd_complete_urb() know the endpoint already stopped and does not
      submit next urb. Below kind of error will be fixed:
      
      [  213.153103] usb 1-2: timeout: still 1 active urbs on EP #1
      [  213.164121] usb 1-2: cannot submit urb 0, error -16: unknown error
      Signed-off-by: default avatarHenry Lin <henryl@nvidia.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191113021420.13377-1-henryl@nvidia.com
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      52869931
  18. 30 May, 2019 1 commit
  19. 01 Aug, 2018 1 commit
  20. 05 Jan, 2017 2 commits
    • Ioan-Adrian Ratiu's avatar
      ALSA: usb-audio: test EP_FLAG_RUNNING at urb completion · 13a6c832
      Ioan-Adrian Ratiu authored
      
      
      Testing EP_FLAG_RUNNING in snd_complete_urb() before running the completion
      logic allows us to save a few cpu cycles by returning early, skipping the
      pending urb in case the stream was stopped; the stop logic handles the urb
      and sets the completion callbacks to NULL.
      Signed-off-by: default avatarIoan-Adrian Ratiu <adi@adirat.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      13a6c832
    • Ioan-Adrian Ratiu's avatar
      ALSA: usb-audio: Fix irq/process data synchronization · 1d0f9530
      Ioan-Adrian Ratiu authored
      Commit 16200948 ("ALSA: usb-audio: Fix race at stopping the stream") was
      incomplete causing another more severe kernel panic, so it got reverted.
      This fixes both the original problem and its fallout kernel race/crash.
      
      The original fix is to move the endpoint member NULL clearing logic inside
      wait_clear_urbs() so the irq triggering the urb completion doesn't call
      retire_capture/playback_urb() after the NULL clearing and generate a panic.
      
      However this creates a new race between snd_usb_endpoint_start()'s call
      to wait_clear_urbs() and the irq urb completion handler which again calls
      retire_capture/playback_urb() leading to a new NULL dereference.
      
      We keep the EP deactivation code in snd_usb_endpoint_start() because
      removing it will break the EP reference counting (see [1] [2] for info),
      however we don't need the "can_sleep" mechanism anymore because a new
      function was introduced (snd_usb_endpoint_sync_pending_stop()) which
      synchronizes pending stops and gets called inside the pcm prepare callback.
      
      It also makes sense to remove can_sleep because it was also removed from
      deactivate_urbs() signature in [3] so we benefit from more simplification.
      
      [1] commit 015618b9 ("ALSA: snd-usb: Fix URB cancellation at stream start")
      [2] commit e9ba389c ("ALSA: usb-audio: Fix scheduling-while-atomic bug in PCM capture stream")
      [3] commit ccc1696d ("ALSA: usb-audio: simplify endpoint deactivation code")
      
      Fixes: f8114f85
      
       ("Revert "ALSA: usb-audio: Fix race at stopping the stream"")
      Signed-off-by: default avatarIoan-Adrian Ratiu <adi@adirat.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      1d0f9530