Skip to content
Snippets Groups Projects
  1. Nov 16, 2024
  2. Nov 15, 2024
  3. Nov 14, 2024
  4. Nov 13, 2024
  5. Nov 12, 2024
  6. Nov 10, 2024
  7. Nov 07, 2024
  8. Nov 06, 2024
    • Jan Kiszka's avatar
      USB: serial: pl2303: account for deficits of clones · 40827729
      Jan Kiszka authored
      
      There are apparently incomplete clones of the HXD type chip in use.
      Those return -EPIPE on GET_LINE_REQUEST and BREAK_REQUEST. Avoid
      flooding the kernel log with those errors. Detect them during startup
      and then use the line_settings cache instead of GET_LINE_REQUEST. Signal
      missing break support via -ENOTTY.
      
      Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
      [ johan: fix macro prefix, drop oom error message ]
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      40827729
    • Michal Pecio's avatar
      usb: xhci: Avoid queuing redundant Stop Endpoint commands · 474538b8
      Michal Pecio authored
      
      Stop Endpoint command on an already stopped endpoint fails and may be
      misinterpreted as a known hardware bug by the completion handler. This
      results in an unnecessary delay with repeated retries of the command.
      
      Avoid queuing this command when endpoint state flags indicate that it's
      stopped or halted and the command will fail. If commands are pending on
      the endpoint, their completion handlers will process cancelled TDs so
      it's done. In case of waiting for external operations like clearing TT
      buffer, the endpoint is stopped and cancelled TDs can be processed now.
      
      This eliminates practically all unnecessary retries because an endpoint
      with pending URBs is maintained in Running state by the driver, unless
      aforementioned commands or other operations are pending on it. This is
      guaranteed by xhci_ring_ep_doorbell() and by the fact that it is called
      every time any of those operations completes.
      
      The only known exceptions are hardware bugs (the endpoint never starts
      at all) and Stream Protocol errors not associated with any TRB, which
      cause an endpoint reset not followed by restart. Sounds like a bug.
      
      Generally, these retries are only expected to happen when the endpoint
      fails to start for unknown/no reason, which is a worse problem itself,
      and fixing the bug eliminates the retries too.
      
      All cases were tested and found to work as expected. SET_DEQ_PENDING
      was produced by patching uvcvideo to unlink URBs in 100us intervals,
      which then runs into this case very often. EP_HALTED was produced by
      restarting 'cat /dev/ttyUSB0' on a serial dongle with broken cable.
      EP_CLEARING_TT by the same, with the dongle on an external hub.
      
      Fixes: fd9d55d1 ("xhci: retry Stop Endpoint on buggy NEC controllers")
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarMichal Pecio <michal.pecio@gmail.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-34-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      474538b8
    • Michal Pecio's avatar
      usb: xhci: Fix TD invalidation under pending Set TR Dequeue · 484c3bab
      Michal Pecio authored
      
      xhci_invalidate_cancelled_tds() may not work correctly if the hardware
      is modifying endpoint or stream contexts at the same time by executing
      a Set TR Dequeue command. And even if it worked, it would be unable to
      queue Set TR Dequeue for the next stream, failing to clear xHC cache.
      
      On stream endpoints, a chain of Set TR Dequeue commands may take some
      time to execute and we may want to cancel more TDs during this time.
      Currently this leads to Stop Endpoint completion handler calling this
      function without testing for SET_DEQ_PENDING, which will trigger the
      aforementioned problems when it happens.
      
      On all endpoints, a halt condition causes Reset Endpoint to be queued
      and an error status given to the class driver, which may unlink more
      URBs in response. Stop Endpoint is queued and its handler may execute
      concurrently with Set TR Dequeue queued by Reset Endpoint handler.
      
      (Reset Endpoint handler calls this function too, but there seems to
      be no possibility of it running concurrently with Set TR Dequeue).
      
      Fix xhci_invalidate_cancelled_tds() to work correctly under a pending
      Set TR Dequeue. Bail out of the function when SET_DEQ_PENDING is set,
      then make the completion handler call the function again and also call
      xhci_giveback_invalidated_tds(), which needs to be called next.
      
      This seems to fix another potential bug, where the handler would call
      xhci_invalidate_cancelled_tds(), which may clear some deferred TDs if
      a sanity check fails, and the TDs wouldn't be given back promptly.
      
      Said sanity check seems to be wrong and prone to false positives when
      the endpoint halts, but fixing it is beyond the scope of this change,
      besides ensuring that cleared TDs are given back properly.
      
      Fixes: 5ceac440 ("xhci: Handle TD clearing for multiple streams case")
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarMichal Pecio <michal.pecio@gmail.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-33-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      484c3bab
    • Michal Pecio's avatar
      usb: xhci: Limit Stop Endpoint retries · 42b75813
      Michal Pecio authored
      
      Some host controllers fail to atomically transition an endpoint to the
      Running state on a doorbell ring and enter a hidden "Restarting" state,
      which looks very much like Stopped, with the important difference that
      it will spontaneously transition to Running anytime soon.
      
      A Stop Endpoint command queued in the Restarting state typically fails
      with Context State Error and the completion handler sees the Endpoint
      Context State as either still Stopped or already Running. Even a case
      of Halted was observed, when an error occurred right after the restart.
      
      The Halted state is already recovered from by resetting the endpoint.
      The Running state is handled by retrying Stop Endpoint.
      
      The Stopped state was recognized as a problem on NEC controllers and
      worked around also by retrying, because the endpoint soon restarts and
      then stops for good. But there is a risk: the command may fail if the
      endpoint is "stopped for good" already, and retries will fail forever.
      
      The possibility of this was not realized at the time, but a number of
      cases were discovered later and reproduced. Some proved difficult to
      deal with, and it is outright impossible to predict if an endpoint may
      fail to ever start at all due to a hardware bug. One such bug (albeit
      on ASM3142, not on NEC) was found to be reliably triggered simply by
      toggling an AX88179 NIC up/down in a tight loop for a few seconds.
      
      An endless retries storm is quite nasty. Besides putting needless load
      on the xHC and CPU, it causes URBs never to be given back, paralyzing
      the device and connection/disconnection logic for the whole bus if the
      device is unplugged. User processes waiting for URBs become unkillable,
      drivers and kworker threads lock up and xhci_hcd cannot be reloaded.
      
      For peace of mind, impose a timeout on Stop Endpoint retries in this
      case. If they don't succeed in 100ms, consider the endpoint stopped
      permanently for some reason and just give back the unlinked URBs. This
      failure case is rare already and work is under way to make it rarer.
      
      Start this work today by also handling one simple case of race with
      Reset Endpoint, because it costs just two lines to implement.
      
      Fixes: fd9d55d1 ("xhci: retry Stop Endpoint on buggy NEC controllers")
      CC: stable@vger.kernel.org
      Signed-off-by: default avatarMichal Pecio <michal.pecio@gmail.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-32-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42b75813
    • Niklas Neronin's avatar
      usb: xhci: remove irrelevant comment · 804ef58a
      Niklas Neronin authored
      
      The code which it is referencing does not exist in the same function,
      or the file for that matter. Since it was added [1], the Interrupter
      Moderation Interval can be changed within xhci addon, e.g. PCI
      xhci_pci_setup().
      
      [1], commit 0ebbab37 ("USB: xhci: Ring allocation and initialization.")
      
      Signed-off-by: default avatarNiklas Neronin <niklas.neronin@linux.intel.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-31-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      804ef58a
    • Niklas Neronin's avatar
      usb: xhci: add help function xhci_dequeue_td() · ee8ebec3
      Niklas Neronin authored
      
      Add xhci_dequeue_td() helper function to reduce code duplication.
      
      Function xhci_dequeue_td() advances the dequeue pointer past the specified
      Transfer Descriptor (TD) and releases the TD.
      
      Signed-off-by: default avatarNiklas Neronin <niklas.neronin@linux.intel.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-30-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ee8ebec3
    • Niklas Neronin's avatar
      usb: xhci: refactor xhci_td_cleanup() to return void · 7acfea28
      Niklas Neronin authored
      
      The function is modified to return 'void' instead of an integer since it
      invariably returns '0'. Additionally, multiple functions which only
      return xhci_td_cleanup() are also refactored to return void.
      
      This change eliminates the need for callers to handle a return value that
      does not convey meaningful information and improve code readability, as it
      becomes immediately clear that the function does not produce a significant
      output.
      
      Signed-off-by: default avatarNiklas Neronin <niklas.neronin@linux.intel.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20241106101459.775897-29-mathias.nyman@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7acfea28
Loading