1. 23 4月, 2020 1 次提交
    • A
      USB: hub: Fix handling of connect changes during sleep · 9f952e26
      Alan Stern 提交于
      Commit 8099f58f ("USB: hub: Don't record a connect-change event
      during reset-resume") wasn't very well conceived.  The problem it
      tried to fix was that if a connect-change event occurred while the
      system was asleep (such as a device disconnecting itself from the bus
      when it is suspended and then reconnecting when it resumes)
      requiring a reset-resume during the system wakeup transition, the hub
      port's change_bit entry would remain set afterward.  This would cause
      the hub driver to believe another connect-change event had occurred
      after the reset-resume, which was wrong and would lead the driver to
      send unnecessary requests to the device (which could interfere with a
      firmware update).
      
      The commit tried to fix this by not setting the change_bit during the
      wakeup.  But this was the wrong thing to do; it means that when a
      device is unplugged while the system is asleep, the hub driver doesn't
      realize anything has happened: The change_bit flag which would tell it
      to handle the disconnect event is clear.
      
      The commit needs to be reverted and the problem fixed in a different
      way.  Fortunately an alternative solution was noted in the commit's
      Changelog: We can continue to set the change_bit entry in
      hub_activate() but then clear it when a reset-resume occurs.  That way
      the the hub driver will see the change_bit when a device is
      disconnected but won't see it when the device is still present.
      
      That's what this patch does.
      Reported-and-tested-by: NPeter Chen <peter.chen@nxp.com>
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Fixes: 8099f58f ("USB: hub: Don't record a connect-change event during reset-resume")
      Tested-by: NPaul Zimmerman <pauldzim@gmail.com>
      CC: <stable@vger.kernel.org>
      
      Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.2004221602480.11262-100000@iolanthe.rowland.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f952e26
  2. 04 3月, 2020 2 次提交
  3. 11 2月, 2020 2 次提交
    • A
      USB: hub: Don't record a connect-change event during reset-resume · 8099f58f
      Alan Stern 提交于
      Paul Zimmerman reports that his USB Bluetooth adapter sometimes
      crashes following system resume, when it receives a
      Get-Device-Descriptor request while it is busy doing something else.
      
      Such a request was added by commit a4f55d8b ("usb: hub: Check
      device descriptor before resusciation").  It gets sent when the hub
      driver's work thread checks whether a connect-change event on an
      enabled port really indicates a new device has been connected, as
      opposed to an old device momentarily disconnecting and then
      reconnecting (which can happen with xHCI host controllers, since they
      automatically enable connected ports).
      
      The same kind of thing occurs when a port's power session is lost
      during system suspend.  When the system wakes up it sees a
      connect-change event on the port, and if the child device's
      persist_enabled flag was set then hub_activate() sets the device's
      reset_resume flag as well as the port's bit in hub->change_bits.  The
      reset-resume code then takes responsibility for checking that the same
      device is still attached to the port, and it does this as part of the
      device's resume pathway.  By the time the hub driver's work thread
      starts up again, the device has already been fully reinitialized and
      is busy doing its own thing.  There's no need for the work thread to
      do the same check a second time, and in fact this unnecessary check is
      what caused the problem that Paul observed.
      
      Note that performing the unnecessary check is not actually a bug.
      Devices are supposed to be able to send descriptors back to the host
      even when they are busy doing something else.  The underlying cause of
      Paul's problem lies in his Bluetooth adapter.  Nevertheless, we
      shouldn't perform the same check twice in a row -- and as a nice side
      benefit, removing the extra check allows the Bluetooth adapter to work
      more reliably.
      
      The work thread performs its check when it sees that the port's bit is
      set in hub->change_bits.  In this situation that bit is interpreted as
      though a connect-change event had occurred on the port _after_ the
      reset-resume, which is not what actually happened.
      
      One possible fix would be to make the reset-resume code clear the
      port's bit in hub->change_bits.  But it seems simpler to just avoid
      setting the bit during hub_activate() in the first place.  That's what
      this patch does.
      
      (Proving that the patch is correct when CONFIG_PM is disabled requires
      a little thought.  In that setting hub_activate() will be called only
      for initialization and resets, since there won't be any resumes or
      reset-resumes.  During initialization and hub resets the hub doesn't
      have any child devices, and so this code path never gets executed.)
      Reported-and-tested-by: NPaul Zimmerman <pauldzim@gmail.com>
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Link: https://marc.info/?t=157949360700001&r=1&w=2
      CC: David Heinzelmann <heinzelmann.david@gmail.com>
      CC: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.2001311037460.1577-100000@iolanthe.rowland.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8099f58f
    • H
      USB: hub: Fix the broken detection of USB3 device in SMSC hub · 1208f9e1
      Hardik Gajjar 提交于
      Renesas R-Car H3ULCB + Kingfisher Infotainment Board is either not able
      to detect the USB3.0 mass storage devices or is detecting those as
      USB2.0 high speed devices.
      
      The explanation given by Renesas is that, due to a HW issue, the XHCI
      driver does not wake up after going to sleep on connecting a USB3.0
      device.
      
      In order to mitigate that, disable the auto-suspend feature
      specifically for SMSC hubs from hub_probe() function, as a quirk.
      
      Renesas Kingfisher Infotainment Board has two USB3.0 ports (CN2) which
      are connected via USB5534B 4-port SuperSpeed/Hi-Speed, low-power,
      configurable hub controller.
      
      [1] SanDisk USB 3.0 device detected as USB-2.0 before the patch
       [   74.036390] usb 5-1.1: new high-speed USB device number 4 using xhci-hcd
       [   74.061598] usb 5-1.1: New USB device found, idVendor=0781, idProduct=5581, bcdDevice= 1.00
       [   74.069976] usb 5-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
       [   74.077303] usb 5-1.1: Product: Ultra
       [   74.080980] usb 5-1.1: Manufacturer: SanDisk
       [   74.085263] usb 5-1.1: SerialNumber: 4C530001110208116550
      
      [2] SanDisk USB 3.0 device detected as USB-3.0 after the patch
       [   34.565078] usb 6-1.1: new SuperSpeed Gen 1 USB device number 3 using xhci-hcd
       [   34.588719] usb 6-1.1: New USB device found, idVendor=0781, idProduct=5581, bcdDevice= 1.00
       [   34.597098] usb 6-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
       [   34.604430] usb 6-1.1: Product: Ultra
       [   34.608110] usb 6-1.1: Manufacturer: SanDisk
       [   34.612397] usb 6-1.1: SerialNumber: 4C530001110208116550
      Suggested-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NHardik Gajjar <hgajjar@de.adit-jv.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Tested-by: NEugeniu Rosca <erosca@de.adit-jv.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/1580989763-32291-1-git-send-email-hgajjar@de.adit-jv.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1208f9e1
  4. 15 1月, 2020 1 次提交
    • K
      usb: core: hub: Improved device recognition on remote wakeup · 9c06ac4c
      Keiya Nobuta 提交于
      If hub_activate() is called before D+ has stabilized after remote
      wakeup, the following situation might occur:
      
               __      ___________________
              /  \    /
      D+   __/    \__/
      
      Hub  _______________________________
                |  ^   ^           ^
                |  |   |           |
      Host _____v__|___|___________|______
                |  |   |           |
                |  |   |           \-- Interrupt Transfer (*3)
                |  |    \-- ClearPortFeature (*2)
                |   \-- GetPortStatus (*1)
                \-- Host detects remote wakeup
      
      - D+ goes high, Host starts running by remote wakeup
      - D+ is not stable, goes low
      - Host requests GetPortStatus at (*1) and gets the following hub status:
        - Current Connect Status bit is 0
        - Connect Status Change bit is 1
      - D+ stabilizes, goes high
      - Host requests ClearPortFeature and thus Connect Status Change bit is
        cleared at (*2)
      - After waiting 100 ms, Host starts the Interrupt Transfer at (*3)
      - Since the Connect Status Change bit is 0, Hub returns NAK.
      
      In this case, port_event() is not called in hub_event() and Host cannot
      recognize device. To solve this issue, flag change_bits even if only
      Connect Status Change bit is 1 when got in the first GetPortStatus.
      
      This issue occurs rarely because it only if D+ changes during a very
      short time between GetPortStatus and ClearPortFeature. However, it is
      fatal if it occurs in embedded system.
      Signed-off-by: NKeiya Nobuta <nobuta.keiya@fujitsu.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/20200109051448.28150-1-nobuta.keiya@fujitsu.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9c06ac4c
  5. 09 1月, 2020 1 次提交
  6. 05 12月, 2019 1 次提交
  7. 07 11月, 2019 1 次提交
    • K
      usb: Allow USB device to be warm reset in suspended state · e76b3bf7
      Kai-Heng Feng 提交于
      On Dell WD15 dock, sometimes USB ethernet cannot be detected after plugging
      cable to the ethernet port, the hub and roothub get runtime resumed and
      runtime suspended immediately:
      ...
      [  433.315169] xhci_hcd 0000:3a:00.0: hcd_pci_runtime_resume: 0
      [  433.315204] usb usb4: usb auto-resume
      [  433.315226] hub 4-0:1.0: hub_resume
      [  433.315239] xhci_hcd 0000:3a:00.0: Get port status 4-1 read: 0x10202e2, return 0x10343
      [  433.315264] usb usb4-port1: status 0343 change 0001
      [  433.315279] xhci_hcd 0000:3a:00.0: clear port1 connect change, portsc: 0x10002e2
      [  433.315293] xhci_hcd 0000:3a:00.0: Get port status 4-2 read: 0x2a0, return 0x2a0
      [  433.317012] xhci_hcd 0000:3a:00.0: xhci_hub_status_data: stopping port polling.
      [  433.422282] xhci_hcd 0000:3a:00.0: Get port status 4-1 read: 0x10002e2, return 0x343
      [  433.422307] usb usb4-port1: do warm reset
      [  433.422311] usb 4-1: device reset not allowed in state 8
      [  433.422339] hub 4-0:1.0: state 7 ports 2 chg 0002 evt 0000
      [  433.422346] xhci_hcd 0000:3a:00.0: Get port status 4-1 read: 0x10002e2, return 0x343
      [  433.422356] usb usb4-port1: do warm reset
      [  433.422358] usb 4-1: device reset not allowed in state 8
      [  433.422428] xhci_hcd 0000:3a:00.0: set port remote wake mask, actual port 0 status  = 0xf0002e2
      [  433.422455] xhci_hcd 0000:3a:00.0: set port remote wake mask, actual port 1 status  = 0xe0002a0
      [  433.422465] hub 4-0:1.0: hub_suspend
      [  433.422475] usb usb4: bus auto-suspend, wakeup 1
      [  433.426161] xhci_hcd 0000:3a:00.0: xhci_hub_status_data: stopping port polling.
      [  433.466209] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.510204] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.554051] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.598235] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.642154] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.686204] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.730205] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.774203] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.818207] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.862040] xhci_hcd 0000:3a:00.0: port 0 polling in bus suspend, waiting
      [  433.862053] xhci_hcd 0000:3a:00.0: xhci_hub_status_data: stopping port polling.
      [  433.862077] xhci_hcd 0000:3a:00.0: xhci_suspend: stopping port polling.
      [  433.862096] xhci_hcd 0000:3a:00.0: // Setting command ring address to 0x8578fc001
      [  433.862312] xhci_hcd 0000:3a:00.0: hcd_pci_runtime_suspend: 0
      [  433.862445] xhci_hcd 0000:3a:00.0: PME# enabled
      [  433.902376] xhci_hcd 0000:3a:00.0: restoring config space at offset 0xc (was 0x0, writing 0x20)
      [  433.902395] xhci_hcd 0000:3a:00.0: restoring config space at offset 0x4 (was 0x100000, writing 0x100403)
      [  433.902490] xhci_hcd 0000:3a:00.0: PME# disabled
      [  433.902504] xhci_hcd 0000:3a:00.0: enabling bus mastering
      [  433.902547] xhci_hcd 0000:3a:00.0: // Setting command ring address to 0x8578fc001
      [  433.902649] pcieport 0000:00:1b.0: PME: Spurious native interrupt!
      [  433.902839] xhci_hcd 0000:3a:00.0: Port change event, 4-1, id 3, portsc: 0xb0202e2
      [  433.902842] xhci_hcd 0000:3a:00.0: resume root hub
      [  433.902845] xhci_hcd 0000:3a:00.0: handle_port_status: starting port polling.
      [  433.902877] xhci_hcd 0000:3a:00.0: xhci_resume: starting port polling.
      [  433.902889] xhci_hcd 0000:3a:00.0: xhci_hub_status_data: stopping port polling.
      [  433.902891] xhci_hcd 0000:3a:00.0: hcd_pci_runtime_resume: 0
      [  433.902919] usb usb4: usb wakeup-resume
      [  433.902942] usb usb4: usb auto-resume
      [  433.902966] hub 4-0:1.0: hub_resume
      ...
      
      As Mathias pointed out, the hub enters Cold Attach Status state and
      requires a warm reset. However usb_reset_device() bails out early when
      the device is in suspended state, as its callers port_event() and
      hub_event() don't always resume the device.
      
      Since there's nothing wrong to reset a suspended device, allow
      usb_reset_device() to do so to solve the issue.
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20191106062710.29880-1-kai.heng.feng@canonical.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e76b3bf7
  8. 10 10月, 2019 1 次提交
  9. 04 7月, 2019 1 次提交
  10. 20 6月, 2019 1 次提交
  11. 05 6月, 2019 1 次提交
    • J
      usb: Add devaddr in struct usb_device · 4998f1ef
      Jim Lin 提交于
      The Clear_TT_Buffer request sent to the hub includes the address of
      the LS/FS child device in wValue field. usb_hub_clear_tt_buffer()
      uses udev->devnum to set the address wValue. This won't work for
      devices connected to xHC.
      
      For other host controllers udev->devnum is the same as the address of
      the usb device, chosen and set by usb core. With xHC the controller
      hardware assigns the address, and won't be the same as devnum.
      
      Here we add devaddr in "struct usb_device" for
      usb_hub_clear_tt_buffer() to use.
      Signed-off-by: NJim Lin <jilin@nvidia.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4998f1ef
  12. 21 5月, 2019 2 次提交
  13. 03 5月, 2019 1 次提交
  14. 17 4月, 2019 1 次提交
    • A
      USB: core: Don't unbind interfaces following device reset failure · 381419fa
      Alan Stern 提交于
      The SCSI core does not like to have devices or hosts unregistered
      while error recovery is in progress.  Trying to do so can lead to
      self-deadlock: Part of the removal code tries to obtain a lock already
      held by the error handler.
      
      This can cause problems for the usb-storage and uas drivers, because
      their error handler routines perform a USB reset, and if the reset
      fails then the USB core automatically goes on to unbind all drivers
      from the device's interfaces -- all while still in the context of the
      SCSI error handler.
      
      As it turns out, practically all the scenarios leading to a USB reset
      failure end up causing a device disconnect (the main error pathway in
      usb_reset_and_verify_device(), at the end of the routine, calls
      hub_port_logical_disconnect() before returning).  As a result, the
      hub_wq thread will soon become aware of the problem and will unbind
      all the device's drivers in its own context, not in the
      error-handler's context.
      
      This means that usb_reset_device() does not need to call
      usb_unbind_and_rebind_marked_interfaces() in cases where
      usb_reset_and_verify_device() has returned an error, because hub_wq
      will take care of everything anyway.
      
      This particular problem was observed in somewhat artificial
      circumstances, by using usbfs to tell a hub to power-down a port
      connected to a USB-3 mass storage device using the UAS protocol.  With
      the port turned off, the currently executing command timed out and the
      error handler started running.  The USB reset naturally failed,
      because the hub port was off, and the error handler deadlocked as
      described above.  Not carrying out the call to
      usb_unbind_and_rebind_marked_interfaces() fixes this issue.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: NKento Kobayashi <Kento.A.Kobayashi@sony.com>
      Tested-by: NKento Kobayashi <Kento.A.Kobayashi@sony.com>
      CC: Bart Van Assche <bvanassche@acm.org>
      CC: Martin K. Petersen <martin.petersen@oracle.com>
      CC: Jacky Cao <Jacky.Cao@sony.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      381419fa
  15. 16 4月, 2019 1 次提交
  16. 08 2月, 2019 1 次提交
  17. 18 1月, 2019 3 次提交
    • K
      USB: Consolidate LPM checks to avoid enabling LPM twice · d7a6c0ce
      Kai-Heng Feng 提交于
      USB Bluetooth controller QCA ROME (0cf3:e007) sometimes stops working
      after S3:
      [ 165.110742] Bluetooth: hci0: using NVM file: qca/nvm_usb_00000302.bin
      [ 168.432065] Bluetooth: hci0: Failed to send body at 4 of 1953 (-110)
      
      After some experiments, I found that disabling LPM can workaround the
      issue.
      
      On some platforms, the USB power is cut during S3, so the driver uses
      reset-resume to resume the device. During port resume, LPM gets enabled
      twice, by usb_reset_and_verify_device() and usb_port_resume().
      
      Consolidate all checks into new LPM helpers to make sure LPM only gets
      enabled once.
      
      Fixes: de68bab4 ("usb: Don't enable USB 2.0 Link PM by default.”)
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org> # after much soaking
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d7a6c0ce
    • K
      USB: Add new USB LPM helpers · 7529b257
      Kai-Heng Feng 提交于
      Use new helpers to make LPM enabling/disabling more clear.
      
      This is a preparation to subsequent patch.
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org> # after much soaking
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7529b257
    • N
      usb: hub: add retry routine after intr URB submit error · 8eb58994
      Nicolas Saenz Julienne 提交于
      The hub sends hot-plug events to the host trough it's interrupt URB. The
      driver takes care of completing the URB and re-submitting it. Completion
      errors are handled in the hub_event() work, yet submission errors are
      ignored, rendering the device unresponsive. All further events are lost.
      
      It is fairly hard to find this issue in the wild, since you have to time
      the USB hot-plug event with the URB submission failure. For instance it
      could be the system running out of memory or some malfunction in the USB
      controller driver. Nevertheless, it's pretty reasonable to think it'll
      happen sometime. One can trigger this issue using eBPF's function
      override feature (see BCC's inject.py script).
      
      This patch adds a retry routine to the event of a submission error. The
      HUB driver will try to re-submit the URB once every second until it's
      successful or the HUB is disconnected.
      
      As some USB subsystems already take care of this issue, the
      implementation was inspired from usbhid/hid_core.c's.
      Signed-off-by: NNicolas Saenz Julienne <nsaenzjulienne@suse.de>
      Reviewed-by: NOliver Neukum <oneukum@suse.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8eb58994
  18. 06 12月, 2018 1 次提交
  19. 05 12月, 2018 2 次提交
    • A
      USB: Fix invalid-free bug in port_over_current_notify() · d81bb019
      Alan Stern 提交于
      Syzbot and KASAN found the following invalid-free bug in
      port_over_current_notify():
      
      --------------------------------------------------------------------------
      BUG: KASAN: double-free or invalid-free in port_over_current_notify
      drivers/usb/core/hub.c:5192 [inline]
      BUG: KASAN: double-free or invalid-free in port_event
      drivers/usb/core/hub.c:5241 [inline]
      BUG: KASAN: double-free or invalid-free in hub_event+0xd97/0x4140
      drivers/usb/core/hub.c:5384
      
      CPU: 1 PID: 32710 Comm: kworker/1:3 Not tainted 4.20.0-rc3+ #129
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      Workqueue: usb_hub_wq hub_event
      Call Trace:
        __dump_stack lib/dump_stack.c:77 [inline]
        dump_stack+0x244/0x39d lib/dump_stack.c:113
        print_address_description.cold.7+0x9/0x1ff mm/kasan/report.c:256
        kasan_report_invalid_free+0x64/0xa0 mm/kasan/report.c:336
        __kasan_slab_free+0x13a/0x150 mm/kasan/kasan.c:501
        kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
        __cache_free mm/slab.c:3498 [inline]
        kfree+0xcf/0x230 mm/slab.c:3817
        port_over_current_notify drivers/usb/core/hub.c:5192 [inline]
        port_event drivers/usb/core/hub.c:5241 [inline]
        hub_event+0xd97/0x4140 drivers/usb/core/hub.c:5384
        process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
        worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
        kthread+0x35a/0x440 kernel/kthread.c:246
        ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
      --------------------------------------------------------------------------
      
      The problem is caused by use of a static array to store
      environment-string pointers.  When the routine is called by multiple
      threads concurrently, the pointers from one thread can overwrite those
      from another.
      
      The solution is to use an ordinary automatic array instead of a static
      array.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: syzbot+98881958e1410ec7e53c@syzkaller.appspotmail.com
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d81bb019
    • M
      usb: hub: delay hub autosuspend if USB3 port is still link training · e8610894
      Mathias Nyman 提交于
      When initializing a hub we want to give a USB3 port in link training
      the same debounce delay time before autosuspening the hub as already
      trained, connected enabled ports.
      
      USB3 ports won't reach the enabled state with "current connect status" and
      "connect status change" bits set until the USB3 link training finishes.
      
      Catching the port in link training (polling) and adding the debounce delay
      prevents unnecessary failed attempts to autosuspend the hub.
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e8610894
  20. 15 11月, 2018 1 次提交
    • D
      usb: core: Fix hub port connection events lost · 22454b79
      Dennis Wassenberg 提交于
      This will clear the USB_PORT_FEAT_C_CONNECTION bit in case of a hub port reset
      only if a device is was attached to the hub port before resetting the hub port.
      
      Using a Lenovo T480s attached to the ultra dock it was not possible to detect
      some usb-c devices at the dock usb-c ports because the hub_port_reset code
      will clear the USB_PORT_FEAT_C_CONNECTION bit after the actual hub port reset.
      Using this device combo the USB_PORT_FEAT_C_CONNECTION bit was set between the
      actual hub port reset and the clear of the USB_PORT_FEAT_C_CONNECTION bit.
      This ends up with clearing the USB_PORT_FEAT_C_CONNECTION bit after the
      new device was attached such that it was not detected.
      
      This patch will not clear the USB_PORT_FEAT_C_CONNECTION bit if there is
      currently no device attached to the port before the hub port reset.
      This will avoid clearing the connection bit for new attached devices.
      Signed-off-by: NDennis Wassenberg <dennis.wassenberg@secunet.com>
      Acked-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      22454b79
  21. 07 11月, 2018 1 次提交
    • K
      USB: Wait for extra delay time after USB_PORT_FEAT_RESET for quirky hub · 781f0766
      Kai-Heng Feng 提交于
      Devices connected under Terminus Technology Inc. Hub (1a40:0101) may
      fail to work after the system resumes from suspend:
      [  206.063325] usb 3-2.4: reset full-speed USB device number 4 using xhci_hcd
      [  206.143691] usb 3-2.4: device descriptor read/64, error -32
      [  206.351671] usb 3-2.4: device descriptor read/64, error -32
      
      Info for this hub:
      T:  Bus=03 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  2 Spd=480 MxCh= 4
      D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=01 MxPS=64 #Cfgs=  1
      P:  Vendor=1a40 ProdID=0101 Rev=01.11
      S:  Product=USB 2.0 Hub
      C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA
      I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
      
      Some expirements indicate that the USB devices connected to the hub are
      innocent, it's the hub itself is to blame. The hub needs extra delay
      time after it resets its port.
      
      Hence wait for extra delay, if the device is connected to this quirky
      hub.
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      781f0766
  22. 09 10月, 2018 1 次提交
  23. 03 10月, 2018 1 次提交
  24. 28 9月, 2018 1 次提交
    • J
      usb: core: added uevent for over-current · 201af55d
      Jon Flatley 提交于
      After commit 1cbd53c8 ("usb: core: introduce per-port over-current
      counters") usb ports expose a sysfs value 'over_current_count'
      to user space. This value on its own is not very useful as it requires
      manual polling.
      
      As a solution, fire a udev event from the usb hub device that specifies
      the values 'OVER_CURRENT_PORT' and 'OVER_CURRENT_COUNT' that indicate
      the path of the usb port where the over-current event occurred and the
      value of 'over_current_count' in sysfs. Additionally, call
      sysfs_notify() so the sysfs value supports poll().
      Signed-off-by: NJon Flatley <jflat@chromium.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      201af55d
  25. 21 7月, 2018 1 次提交
  26. 25 6月, 2018 1 次提交
    • A
      USB: Report wakeup events on root-hub ports · 379cacc5
      Alan Stern 提交于
      When a USB device attached to a root-hub port sends a wakeup request
      to a sleeping system, we do not report the wakeup event to the PM
      core.  This is because a system resume involves waking up all
      suspended USB ports as quickly as possible; without the normal
      USB_RESUME_TIMEOUT delay, the host controller driver doesn't set the
      USB_PORT_STAT_C_SUSPEND flag and so usb_port_resume() doesn't realize
      that a wakeup request was received.
      
      However, some environments (such as Chrome OS) want to have all wakeup
      events reported so they can be ascribed to the appropriate device.  To
      accommodate these environments, this patch adds a new routine to the
      hub driver and a corresponding new HCD method to be used when a root
      hub resumes.  The HCD method returns a bitmap of ports that have
      initiated a wakeup signal but not yet completed resuming.  The hub
      driver can then report to the PM core that the child devices attached
      to these ports initiated a wakeup event.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Suggested-by: NAnshuman Gupta <anshuman.gupta@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      379cacc5
  27. 13 6月, 2018 1 次提交
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
  28. 31 5月, 2018 2 次提交
  29. 25 4月, 2018 1 次提交
  30. 22 4月, 2018 4 次提交
    • M
      USB: show USB 3.2 Dual-lane devices as Gen Xx2 during device enumeration · 45455e4d
      Mathias Nyman 提交于
      USB 3.2 specification adds a Gen XxY notion for USB3 devices where
      X is the signaling rate on the wire. Gen 1xY is 5Gbps Superspeed
      and Gen 2xY is 10Gbps SuperSpeedPlus. Y is the lane count.
      
      For normal, non inter-chip (SSIC) devies the rx and tx lane count is
      symmetric, and the maximum lane count for USB 3.2 devices is 2 (dual-lane).
      
      SSIC devices may have asymmetric lane counts, with up to four
      lanes per direction. The USB 3.2 specification doesn't point out
      how to use the Gen XxY notion for these devices, so we limit the Gen Xx2
      notion to symmertic Dual lane devies.
      For other devices just show Gen1 or Gen2
      
      Gen 1 5Gbps
      Gen 2 10Gbps
      Gen 1x2 10Gbps Dual-lane  (USB 3.2)
      Gen 2x2 20Gbps Dual-lane  (USB 3.2)
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      45455e4d
    • M
      USB: Add support to store lane count used by USB 3.2 · 013eedb8
      Mathias Nyman 提交于
      USB 3.2 specification adds Dual-lane support, doubling the maximum
      SuperSpeedPlus data rate from 10Gbps to 20Gbps.
      
      Dual-lane takes into use a second set of rx and tx wires/pins in the
      Type-C cable and connector.
      
      Add "rx_lanes" and "tx_lanes" variables to struct usb_device to store
      the numer of lanes in use. Number of lanes can be read using the extended
      port status hub request that was introduced in USB 3.1.
      
      Extended port status rx and tx lane count are zero based, maximum
      lanes supported by non inter-chip (SSIC) USB 3.2 is 2 (dual lane) with
      rx and tx lane count symmetric. SSIC devices support asymmetric lanes
      up to 4 lanes per direction.
      
      If extended port status is not available then default to one lane.
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      013eedb8
    • D
      usb: hub: Don't wait for connect state at resume for powered-off ports · 5d111f51
      Dominik Bozek 提交于
      wait_for_connected() wait till a port change status to
      USB_PORT_STAT_CONNECTION, but this is not possible if
      the port is unpowered. The loop will only exit at timeout.
      
      Such case take place if an over-current incident happen
      while system is in S3. Then during resume wait_for_connected()
      will wait 2s, which may be noticeable by the user.
      Signed-off-by: NDominik Bozek <dominikx.bozek@intel.com>
      Signed-off-by: NKuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5d111f51
    • R
      USB: Increment wakeup count on remote wakeup. · 83a62c51
      Ravi Chandra Sadineni 提交于
      On chromebooks we depend on wakeup count to identify the wakeup source.
      But currently USB devices do not increment the wakeup count when they
      trigger the remote wake. This patch addresses the same.
      
      Resume condition is reported differently on USB 2.0 and USB 3.0 devices.
      
      On USB 2.0 devices, a wake capable device, if wake enabled, drives
      resume signal to indicate a remote wake (USB 2.0 spec section 7.1.7.7).
      The upstream facing port then sets C_PORT_SUSPEND bit and reports a
      port change event (USB 2.0 spec section 11.24.2.7.2.3). Thus if a port
      has resumed before driving the resume signal from the host and
      C_PORT_SUSPEND is set, then the device attached to the given port might
      be the reason for the last system wakeup. Increment the wakeup count for
      the same.
      
      On USB 3.0 devices, a function may signal that it wants to exit from device
      suspend by sending a Function Wake Device Notification to the host (USB3.0
      spec section 8.5.6.4) Thus on receiving the Function Wake, increment the
      wakeup count.
      Signed-off-by: NRavi Chandra Sadineni <ravisadineni@chromium.org>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      83a62c51