1. 09 1月, 2020 1 次提交
  2. 05 12月, 2019 1 次提交
  3. 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
  4. 10 10月, 2019 1 次提交
  5. 04 7月, 2019 1 次提交
  6. 20 6月, 2019 1 次提交
  7. 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
  8. 21 5月, 2019 2 次提交
  9. 03 5月, 2019 1 次提交
  10. 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
  11. 16 4月, 2019 1 次提交
  12. 08 2月, 2019 1 次提交
  13. 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
  14. 06 12月, 2018 1 次提交
  15. 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
  16. 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
  17. 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
  18. 09 10月, 2018 1 次提交
  19. 03 10月, 2018 1 次提交
  20. 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
  21. 21 7月, 2018 1 次提交
  22. 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
  23. 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
  24. 31 5月, 2018 2 次提交
  25. 25 4月, 2018 1 次提交
  26. 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
  27. 25 3月, 2018 1 次提交
  28. 23 3月, 2018 1 次提交
  29. 22 3月, 2018 1 次提交
    • R
      usb: core: introduce per-port over-current counters · 1cbd53c8
      Richard Leitner 提交于
      For some userspace applications information on the number of
      over-current conditions at specific USB hub ports is relevant.
      
      In our case we have a series of USB hardware (using the cp210x driver)
      which communicates using a proprietary protocol. These devices sometimes
      trigger an over-current situation on some hubs. In case of such an
      over-current situation the USB devices offer an interface for reducing
      the max used power. As these conditions are quite rare and imply
      performance reductions of the device we don't want to reduce the max
      power always.
      
      Therefore give user-space applications the possibility to react
      adequately by introducing an over_current_counter in the usb port struct
      which is exported via sysfs.
      Signed-off-by: NRichard Leitner <richard.leitner@skidata.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1cbd53c8
  30. 10 3月, 2018 1 次提交
    • M
      usb: Don't disable Latency tolerance Messaging (LTM) before port reset · 57edd462
      Mathias Nyman 提交于
      Disabing Latency Tolerance Messaging before port reset is unnecessary.
      LTM is automatically disabled at port reset.
      
      If host can't communicate with the device the LTM message will fail, and
      the hub driver will unnecessarily do a logical disconnect.
      Broken communication is ofter the reason for a reset in the first place.
      
      Additionally we can't guarantee device is in a configured state,
      epecially in reset-resume case when root hub lost power.
      LTM can't be modified unless device is in a configured state.
      
      Just remove LTM disabling before port reset.
      
      Details about LTM and port reset in USB 3 specification:
      
      USB 3 spec section 9.4.5
      "The LTM Enable field can be modified by the SetFeature() and
      ClearFeature() requests using the LTM_ENABLE feature selector.
      This field is reset to zero when the device is reset."
      
      USB 3 spec section 9.4.1
      "The device shall process a Clear Feature (U1_Enable or U2_Enable or
      LTM_Enable) only if the device is in the configured state."
      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>
      57edd462
  31. 16 12月, 2017 1 次提交
  32. 06 12月, 2017 1 次提交