Skip to content
  1. Oct 02, 2020
    • Thierry Reding's avatar
      usb: gadget: tegra-xudc: Properly align parameters · 230c1aa3
      Thierry Reding authored
      
      
      Align parameters on subsequent lines with the parameters on the first
      line for consistency.
      
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      230c1aa3
    • Colin Ian King's avatar
      usb: gadget: fix spelling mistake "Dectected" -> "Detected" · 2003a419
      Colin Ian King authored
      
      
      There is a spelling mistake in a literal string. Fix it.
      
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      2003a419
    • Thierry Reding's avatar
      usb: gadget: tegra-xudc: Use consistent spelling and formatting · de21e728
      Thierry Reding authored
      
      
      Make sure to use consistent spelling and formatting in error messages.
      
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      de21e728
    • Christophe JAILLET's avatar
      usb: gadget: tegra-xudc: Avoid GFP_ATOMIC where it is not needed · 6c2a754a
      Christophe JAILLET authored
      
      
      There is no need to use GFP_ATOMIC here. It is a probe function, no
      spinlock is taken.
      
      Reviewed-by: default avatarJC Kuo <jckuo@nvidia.com>
      Acked-by: default avatarThierry Reding <treding@nvidia.com>
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      6c2a754a
    • Peter Chen's avatar
      usb: gadget: core: do not try to disconnect gadget if it is not connected · 5a1da544
      Peter Chen authored
      
      
      Current UDC core connects gadget during the loading gadget flow
      (udc_bind_to_driver->usb_udc_connect_control), but for
      platforms which do not connect gadget if the VBUS is not there,
      they call usb_gadget_disconnect, but the gadget is not connected
      at this time, notify disconnecton for the gadget driver is meaningless
      at this situation.
      
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      5a1da544
    • Thinh Nguyen's avatar
      usb: dwc3: gadget: Refactor ep command completion · 8266b08e
      Thinh Nguyen authored
      
      
      Refactor END_TRANSFER command completion handling and move it outside of
      the switch statement to its own function. This makes it cleaner and
      consistent with other event handler functions. No functional change
      here.
      
      Signed-off-by: default avatarThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      8266b08e
    • Krzysztof Kozlowski's avatar
      usb: gadget: s3c: Remove unused 'udc' variable · de56298f
      Krzysztof Kozlowski authored
      
      
      Remove unused 'udc' variable to fix compile warnings:
      
          drivers/usb/gadget/udc/s3c2410_udc.c: In function 's3c2410_udc_dequeue':
          drivers/usb/gadget/udc/s3c2410_udc.c:1268:22: warning: variable 'udc' set but not used [-Wunused-but-set-variable]
      
      Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      de56298f
    • Li Jun's avatar
      usb: dwc3: debugfs: do not queue work if try to change mode on non-drd · 5bde3f02
      Li Jun authored
      
      
      Do not try to queue a drd work for change mode if the port is not a drd,
      this is to avoid below kernel dump:
      [   60.115529] ------------[ cut here ]------------
      [   60.120166] WARNING: CPU: 1 PID: 627 at kernel/workqueue.c:1473
      __queue_work+0x46c/0x520
      [   60.128254] Modules linked in:
      [   60.131313] CPU: 1 PID: 627 Comm: sh Not tainted
      5.7.0-rc4-00022-g914a586-dirty #135
      [   60.139054] Hardware name: NXP i.MX8MQ EVK (DT)
      [   60.143585] pstate: a0000085 (NzCv daIf -PAN -UAO)
      [   60.148376] pc : __queue_work+0x46c/0x520
      [   60.152385] lr : __queue_work+0x314/0x520
      [   60.156393] sp : ffff8000124ebc40
      [   60.159705] x29: ffff8000124ebc40 x28: ffff800011808018
      [   60.165018] x27: ffff800011819ef8 x26: ffff800011d39980
      [   60.170331] x25: ffff800011808018 x24: 0000000000000100
      [   60.175643] x23: 0000000000000013 x22: 0000000000000001
      [   60.180955] x21: ffff0000b7c08e00 x20: ffff0000b6c31080
      [   60.186267] x19: ffff0000bb99bc00 x18: 0000000000000000
      [   60.191579] x17: 0000000000000000 x16: 0000000000000000
      [   60.196891] x15: 0000000000000000 x14: 0000000000000000
      [   60.202202] x13: 0000000000000000 x12: 0000000000000000
      [   60.207515] x11: 0000000000000000 x10: 0000000000000040
      [   60.212827] x9 : ffff800011d55460 x8 : ffff800011d55458
      [   60.218138] x7 : ffff0000b7800028 x6 : 0000000000000000
      [   60.223450] x5 : ffff0000b7800000 x4 : 0000000000000000
      [   60.228762] x3 : ffff0000bb997cc0 x2 : 0000000000000001
      [   60.234074] x1 : 0000000000000000 x0 : ffff0000b6c31088
      [   60.239386] Call trace:
      [   60.241834]  __queue_work+0x46c/0x520
      [   60.245496]  queue_work_on+0x6c/0x90
      [   60.249075]  dwc3_set_mode+0x48/0x58
      [   60.252651]  dwc3_mode_write+0xf8/0x150
      [   60.256489]  full_proxy_write+0x5c/0xa8
      [   60.260327]  __vfs_write+0x18/0x40
      [   60.263729]  vfs_write+0xdc/0x1c8
      [   60.267045]  ksys_write+0x68/0xf0
      [   60.270360]  __arm64_sys_write+0x18/0x20
      [   60.274286]  el0_svc_common.constprop.0+0x68/0x160
      [   60.279077]  do_el0_svc+0x20/0x80
      [   60.282394]  el0_sync_handler+0x10c/0x178
      [   60.286403]  el0_sync+0x140/0x180
      [   60.289716] ---[ end trace 70b155582e2b7988 ]---
      
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      5bde3f02
    • Li Jun's avatar
      usb: dwc3: core: add phy cleanup for probe error handling · 03c1fd62
      Li Jun authored
      Add the phy cleanup if dwc3 mode init fail, which is the missing part of
      de-init for dwc3 core init.
      
      Fixes: c499ff71
      
       ("usb: dwc3: core: re-factor init and exit paths")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      03c1fd62
    • Li Jun's avatar
      usb: dwc3: core: don't trigger runtime pm when remove driver · 266d0493
      Li Jun authored
      No need to trigger runtime pm in driver removal, otherwise if user
      disable auto suspend via sys file, runtime suspend may be entered,
      which will call dwc3_core_exit() again and there will be clock disable
      not balance warning:
      
      [ 2026.820154] xhci-hcd xhci-hcd.0.auto: remove, state 4
      [ 2026.825268] usb usb2: USB disconnect, device number 1
      [ 2026.831017] xhci-hcd xhci-hcd.0.auto: USB bus 2 deregistered
      [ 2026.836806] xhci-hcd xhci-hcd.0.auto: remove, state 4
      [ 2026.842029] usb usb1: USB disconnect, device number 1
      [ 2026.848029] xhci-hcd xhci-hcd.0.auto: USB bus 1 deregistered
      [ 2026.865889] ------------[ cut here ]------------
      [ 2026.870506] usb2_ctrl_root_clk already disabled
      [ 2026.875082] WARNING: CPU: 0 PID: 731 at drivers/clk/clk.c:958
      clk_core_disable+0xa0/0xa8
      [ 2026.883170] Modules linked in: dwc3(-) phy_fsl_imx8mq_usb [last
      unloaded: dwc3]
      [ 2026.890488] CPU: 0 PID: 731 Comm: rmmod Not tainted
      5.8.0-rc7-00280-g9d08cca-dirty #245
      [ 2026.898489] Hardware name: NXP i.MX8MQ EVK (DT)
      [ 2026.903020] pstate: 20000085 (nzCv daIf -PAN -UAO BTYPE=--)
      [ 2026.908594] pc : clk_core_disable+0xa0/0xa8
      [ 2026.912777] lr : clk_core_disable+0xa0/0xa8
      [ 2026.916958] sp : ffff8000121b39a0
      [ 2026.920271] x29: ffff8000121b39a0 x28: ffff0000b11f3700
      [ 2026.925583] x27: 0000000000000000 x26: ffff0000b539c700
      [ 2026.930895] x25: 000001d7e44e1232 x24: ffff0000b76fa800
      [ 2026.936208] x23: ffff0000b76fa6f8 x22: ffff800008d01040
      [ 2026.941520] x21: ffff0000b539ce00 x20: ffff0000b7105000
      [ 2026.946832] x19: ffff0000b7105000 x18: 0000000000000010
      [ 2026.952144] x17: 0000000000000001 x16: 0000000000000000
      [ 2026.957456] x15: ffff0000b11f3b70 x14: ffffffffffffffff
      [ 2026.962768] x13: ffff8000921b36f7 x12: ffff8000121b36ff
      [ 2026.968080] x11: ffff8000119e1000 x10: ffff800011bf26d0
      [ 2026.973392] x9 : 0000000000000000 x8 : ffff800011bf3000
      [ 2026.978704] x7 : ffff800010695d68 x6 : 0000000000000252
      [ 2026.984016] x5 : ffff0000bb9881f0 x4 : 0000000000000000
      [ 2026.989327] x3 : 0000000000000027 x2 : 0000000000000023
      [ 2026.994639] x1 : ac2fa471aa7cab00 x0 : 0000000000000000
      [ 2026.999951] Call trace:
      [ 2027.002401]  clk_core_disable+0xa0/0xa8
      [ 2027.006238]  clk_core_disable_lock+0x20/0x38
      [ 2027.010508]  clk_disable+0x1c/0x28
      [ 2027.013911]  clk_bulk_disable+0x34/0x50
      [ 2027.017758]  dwc3_core_exit+0xec/0x110 [dwc3]
      [ 2027.022122]  dwc3_suspend_common+0x84/0x188 [dwc3]
      [ 2027.026919]  dwc3_runtime_suspend+0x74/0x9c [dwc3]
      [ 2027.031712]  pm_generic_runtime_suspend+0x28/0x40
      [ 2027.036419]  genpd_runtime_suspend+0xa0/0x258
      [ 2027.040777]  __rpm_callback+0x88/0x140
      [ 2027.044526]  rpm_callback+0x20/0x80
      [ 2027.048015]  rpm_suspend+0xd0/0x418
      [ 2027.051503]  __pm_runtime_suspend+0x58/0xa0
      [ 2027.055693]  dwc3_runtime_idle+0x7c/0x90 [dwc3]
      [ 2027.060224]  __rpm_callback+0x88/0x140
      [ 2027.063973]  rpm_idle+0x78/0x150
      [ 2027.067201]  __pm_runtime_idle+0x58/0xa0
      [ 2027.071130]  dwc3_remove+0x64/0xc0 [dwc3]
      [ 2027.075140]  platform_drv_remove+0x28/0x48
      [ 2027.079239]  device_release_driver_internal+0xf4/0x1c0
      [ 2027.084377]  driver_detach+0x4c/0xd8
      [ 2027.087954]  bus_remove_driver+0x54/0xa8
      [ 2027.091877]  driver_unregister+0x2c/0x58
      [ 2027.095799]  platform_driver_unregister+0x10/0x18
      [ 2027.100509]  dwc3_driver_exit+0x14/0x1408 [dwc3]
      [ 2027.105129]  __arm64_sys_delete_module+0x178/0x218
      [ 2027.109922]  el0_svc_common.constprop.0+0x68/0x160
      [ 2027.114714]  do_el0_svc+0x20/0x80
      [ 2027.118031]  el0_sync_handler+0x88/0x190
      [ 2027.121953]  el0_sync+0x140/0x180
      [ 2027.125267] ---[ end trace 027f4f8189958f1f ]---
      [ 2027.129976] ------------[ cut here ]------------
      
      Fixes: fc8bb91b
      
       ("usb: dwc3: implement runtime PM")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarLi Jun <jun.li@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      266d0493
    • Peter Chen's avatar
      Revert "usb: udc: allow adding and removing the same gadget device" · 7595c38b
      Peter Chen authored
      We have already allocated gadget structure dynamically at UDC (dwc3)
      driver, so commit fac32347
      
       ("usb: udc: allow adding and removing
      the same gadget device")could be reverted.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      7595c38b
    • Peter Chen's avatar
      usb: dwc3: allocate gadget structure dynamically · e81a7018
      Peter Chen authored
      The current code uses commit fac32347
      
       ("usb: udc: allow adding
      and removing the same gadget device") as the workaround to let
      the gadget device is re-used, but it is not allowed from driver
      core point. In this commit, we allocate gadget structure dynamically,
      and free it at its release function. Since the gadget device's
      driver_data has already occupied by usb_composite_dev structure, we have
      to use gadget device's platform data to store dwc3 structure.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      e81a7018
    • Peter Chen's avatar
      usb: cdns3: gadget: fix possible memory leak · 6b777892
      Peter Chen authored
      
      
      If cdns3_gadget_start is failed, it never frees cdns3_device structure.
      Meanwhile, there is no release function for gadget device, it causes
      there is no sync with driver core.
      
      To fix this, we add release function for gadget device, and free
      cdns3_device structure at there. Meanwhile, With the new UDC core
      APIs, we could work with driver core better to handle memory leak
      issue.
      
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      6b777892
    • Alan Stern's avatar
      USB: UDC: net2272: Fix memory leaks · 9b719c71
      Alan Stern authored
      
      
      Like net2280 (on which it was based), the net2272 UDC driver has a
      problem with leaking memory along some of its failure pathways.  It
      also has another problem, not previously noted, in that some of the
      failure pathways will call usb_del_gadget_udc() without first calling
      usb_add_gadget_udc_release().  And it leaks memory by calling kfree()
      when it should call put_device().
      
      Until now it has been impossible to handle the memory leaks, because of
      lack of support in the UDC core for separately initializing and adding
      gadgets, or for separately deleting and freeing gadgets.  An earlier
      patch in this series adds the necessary support, making it possible to
      fix the outstanding problems properly.
      
      This patch adds an "added" flag to the net2272 structure to indicate
      whether or not the gadget has been registered (and thus whether or not
      to call usb_del_gadget()), and it fixes the deallocation issues by
      calling usb_put_gadget() at the appropriate places.
      
      A similar memory leak issue, apparently never before recognized, stems
      from the fact that the driver never initializes the drvdata field in
      the gadget's embedded struct device!  Evidently this wasn't noticed
      because the pointer is only ever used as an argument to kfree(), which
      doesn't mind getting called with a NULL pointer. In fact, the drvdata
      for gadget device will be written by usb_composite_dev structure if
      any gadget class is loaded, so it needs to use usb_gadget structure
      to get net2280 private data.
      
      CC: Anton Vasilyev <vasilyev@ispras.ru>
      CC: Evgeny Novikov <novikov@ispras.ru>
      CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      9b719c71
    • Alan Stern's avatar
      USB: UDC: net2280: Fix memory leaks · f770fbec
      Alan Stern authored
      
      
      As Anton and Evgeny have noted, the net2280 UDC driver has a problem
      with leaking memory along some of its failure pathways.  It also has
      another problem, not previously noted, in that some of the failure
      pathways will call usb_del_gadget_udc() without first calling
      usb_add_gadget_udc_release().  And it leaks memory by calling kfree()
      when it should call put_device().
      
      Previous attempts to fix the problems have failed because of lack of
      support in the UDC core for separately initializing and adding
      gadgets, or for separately deleting and freeing gadgets.  The previous
      patch in this series adds the necessary support, making it possible to
      fix the outstanding problems properly.
      
      This patch adds an "added" flag to the net2280 structure to indicate
      whether or not the gadget has been registered (and thus whether or not
      to call usb_del_gadget()), and it fixes the deallocation issues by
      calling usb_put_gadget() at the appropriate point.
      
      A similar memory leak issue, apparently never before recognized, stems
      from the fact that the driver never initializes the drvdata field in
      the gadget's embedded struct device!  Evidently this wasn't noticed
      because the pointer is only ever used as an argument to kfree(), which
      doesn't mind getting called with a NULL pointer. In fact, the drvdata
      for gadget device will be written by usb_composite_dev structure if
      any gadget class is loaded, so it needs to use usb_gadget structure
      to get net2280 private data.
      
      CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Reported-by: default avatarAnton Vasilyev <vasilyev@ispras.ru>
      Reported-by: default avatarEvgeny Novikov <novikov@ispras.ru>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      f770fbec
    • Alan Stern's avatar
      USB: UDC: Expand device model API interface · 3301c215
      Alan Stern authored
      
      
      The routines used by the UDC core to interface with the kernel's
      device model, namely usb_add_gadget_udc(),
      usb_add_gadget_udc_release(), and usb_del_gadget_udc(), provide access
      to only a subset of the device model's full API.  They include
      functionality equivalent to device_register() and device_unregister()
      for gadgets, but they omit device_initialize(), device_add(),
      device_del(), get_device(), and put_device().
      
      This patch expands the UDC API by adding usb_initialize_gadget(),
      usb_add_gadget(), usb_del_gadget(), usb_get_gadget(), and
      usb_put_gadget() to fill in the gap.  It rewrites the existing
      routines to call the new ones.
      
      CC: Anton Vasilyev <vasilyev@ispras.ru>
      CC: Evgeny Novikov <novikov@ispras.ru>
      CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      3301c215
    • Peter Chen's avatar
      usb: cdns3: gadget: fix some endian issues · 8dafb3c0
      Peter Chen authored
      
      
      It is found by sparse.
      
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      8dafb3c0
    • Ye Bin's avatar
      usb: gadget: fsl: Fix unsigned expression compared with zero in fsl_udc_probe · 87a2dfb1
      Ye Bin authored
      
      
      udc_controller->irq is "unsigned int" always >= 0, but platform_get_irq may
      return little than zero. So "dc_controller->irq < 0" condition is never
      accessible.
      
      Acked-by: default avatarLi Yang <leoyang.li@nxp.com>
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      87a2dfb1
    • Lorenzo Colitti's avatar
      usb: gadget: u_ether: enable qmult on SuperSpeed Plus as well · 4eea21dc
      Lorenzo Colitti authored
      The u_ether driver has a qmult setting that multiplies the
      transmit queue length (which by default is 2).
      
      The intent is that it should be enabled at high/super speed, but
      because the code does not explicitly check for USB_SUPER_PLUS,
      it is disabled at that speed.
      
      Fix this by ensuring that the queue multiplier is enabled for any
      wired link at high speed or above. Using >= for USB_SPEED_*
      constants seems correct because it is what the gadget_is_xxxspeed
      functions do.
      
      The queue multiplier substantially helps performance at higher
      speeds. On a direct SuperSpeed Plus link to a Linux laptop,
      iperf3 single TCP stream:
      
      Before (qmult=1): 1.3 Gbps
      After  (qmult=5): 3.2 Gbps
      
      Fixes: 04617db7
      
       ("usb: gadget: add SS descriptors to Ethernet gadget")
      Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      4eea21dc
    • Yoshihiro Shimoda's avatar
      usb: gadget: u_serial: clear suspended flag when disconnecting · d98ef43b
      Yoshihiro Shimoda authored
      The commit aba3a8d0 ("usb: gadget: u_serial: add suspend resume
      callbacks") set/cleared the suspended flag in USB bus suspend/resume
      only. But, when a USB cable is disconnected in the suspend, since some
      controllers will not detect USB bus resume, the suspended flag is not
      cleared. After that, user cannot send any data. To fix the issue,
      clears the suspended flag in the gserial_disconnect().
      
      Fixes: aba3a8d0
      
       ("usb: gadget: u_serial: add suspend resume callbacks")
      Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Tested-by: default avatarLinh Phung <linh.phung.jy@renesas.com>
      Tested-by: default avatarTam Nguyen <tam.nguyen.xa@renesas.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      d98ef43b
    • Randy Dunlap's avatar
      usb: phy: phy-ab8500-usb: fix spello of "function" · 897b8138
      Randy Dunlap authored
      
      
      Fix typo/spello of "function".
      
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: linux-usb@vger.kernel.org
      Cc: Jiri Kosina <trivial@kernel.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      897b8138
    • Lorenzo Colitti's avatar
      usb: gadget: f_ncm: allow using NCM in SuperSpeed Plus gadgets. · 7974ecd7
      Lorenzo Colitti authored
      
      
      Currently, enabling f_ncm at SuperSpeed Plus speeds results in an
      oops in config_ep_by_speed because ncm_set_alt passes in NULL
      ssp_descriptors. Fix this by re-using the SuperSpeed descriptors.
      This is safe because usb_assign_descriptors calls
      usb_copy_descriptors.
      
      Tested: enabled f_ncm on a dwc3 gadget and 10Gbps link, ran iperf
      Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      7974ecd7
    • Lorenzo Colitti's avatar
      usb: gadget: f_ncm: set SuperSpeed bulk descriptor bMaxBurst to 15 · a176b1a2
      Lorenzo Colitti authored
      
      
      This improves performance on fast connections. When directly
      connecting to a Linux laptop running 5.6, single-stream iperf3
      goes from ~1.7Gbps to ~2.3Gbps out, and from ~620Mbps to ~720Mbps
      in.
      
      Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      a176b1a2
    • Lorenzo Colitti's avatar
      usb: gadget: f_ncm: fix ncm_bitrate for SuperSpeed and above. · 986499b1
      Lorenzo Colitti authored
      Currently, SuperSpeed NCM gadgets report a speed of 851 Mbps
      in USB_CDC_NOTIFY_SPEED_CHANGE. But the calculation appears to
      assume 16 packets per microframe, and USB 3 and above no longer
      use microframes.
      
      Maximum speed is actually much higher. On a direct connection,
      theoretical throughput is at most 3.86 Gbps for gen1x1 and
      9.36 Gbps for gen2x1, and I have seen gadget->host iperf
      throughput of >2 Gbps for gen1x1 and >4 Gbps for gen2x1.
      
      Unfortunately the ConnectionSpeedChange defined in the CDC spec
      only uses 32-bit values, so we can't report accurate numbers for
      10Gbps and above. So, report 3.75Gbps for SuperSpeed (which is
      roughly maximum theoretical performance) and 4.25Gbps for
      SuperSpeed Plus (which is close to the maximum that we can report
      in a 32-bit unsigned integer).
      
      This results in:
      
      [50879.191272] cdc_ncm 2-2:1.0 enx228b127e050c: renamed from usb0
      [50879.234778] cdc_ncm 2-2:1.0 enx228b127e050c: 3750 mbit/s downlink 3750 mbit/s uplink
      
      on SuperSpeed and:
      
      [50798.434527] cdc_ncm 8-2:1.0 enx228b127e050c: renamed from usb0
      [50798.524278] cdc_ncm 8-2:1.0 enx228b127e050c: 4250 mbit/s downlink 4250 mbit/s uplink
      
      on SuperSpeed Plus.
      
      Fixes: 16501138
      
       ("usb: gadget: f_ncm: add SuperSpeed descriptors for CDC NCM")
      Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      986499b1
    • Peter Chen's avatar
      usb: cdns3: gadget: move wait configuration operation · b21cf937
      Peter Chen authored
      After commit f4cfe5ce
      
       ("usb: cdns3: gadget: improve the
      set_configuration handling"), the software will inform the
      hardware the request has finished at cdns3_ep0_complete_setup.
      The configuration set bit is only set after request has finished,
      so it needs to move waiting operation after that. Meanwhile,
      if it is timeout, it will show warning message and return error.
      
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      b21cf937
    • Peter Chen's avatar
      usb: cdns3: drd: call PHY .set_mode accordingly · 9f650135
      Peter Chen authored
      
      
      Some PHYs may need to enter related mode, and do some settings.
      
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      9f650135
    • Peter Chen's avatar
      usb: cdns3: gadget: clear the interrupt status when disconnect the host · 0eeda059
      Peter Chen authored
      
      
      It is meaningless to handle any interrupts after disconnecting
      with host
      
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      0eeda059
    • Peter Chen's avatar
      usb: cdns3: gadget: set fast access bit · b5148d94
      Peter Chen authored
      
      
      Below is the recommendation from Cadence designer:
      	Using this bit to be sure that PHY clock is keeping up in active
      	state. It's good to keep Fast Access bit enabled as long as there
      	is any access to USB register.
      
      It is used to fix the potential ARM core hang when visit controller
      register after DEVDS (.pullup is cleared) is set, the threaded irq
      may be scheduled at that time.
      
      Cc: Pawel Laszczak <pawell@cadence.com>
      Reviewed-by: default avatarJun Li <jun.li@nxp.com>
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      b5148d94
    • Peter Chen's avatar
      usb: cdns3: core: quit if it uses role switch class · 50642709
      Peter Chen authored
      
      
      If the board uses role switch class for switching the role, it should
      not depends on SoC OTG hardware siginal any more, so quit early.
      
      Signed-off-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      50642709
    • Raymond Tan's avatar
      usb: dwc3: pci: Allow Elkhart Lake to utilize DSM method for PM functionality · a609ce2a
      Raymond Tan authored
      Similar to some other IA platforms, Elkhart Lake too depends on the
      PMU register write to request transition of Dx power state.
      
      Thus, we add the PCI_DEVICE_ID_INTEL_EHLLP to the list of devices that
      shall execute the ACPI _DSM method during D0/D3 sequence.
      
      [heikki.krogerus@linux.intel.com: included Fixes tag]
      
      Fixes: dbb0569d
      
       ("usb: dwc3: pci: Add Support for Intel Elkhart Lake Devices")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarRaymond Tan <raymond.tan@intel.com>
      Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      a609ce2a
    • Marc Zyngier's avatar
      usb: dwc2: Always disable regulators on driver teardown · 54c19606
      Marc Zyngier authored
      
      
      If the dwc2 driver fails to probe after having enabled the regulators,
      it ends up being unregistered with regulators enabled, something the
      core regulator code is legitimately upset about:
      
         dwc2 ff400000.usb: supply vusb_d not found, using dummy regulator
         dwc2 ff400000.usb: supply vusb_a not found, using dummy regulator
         dwc2 ff400000.usb: dwc2_core_reset: HANG! AHB Idle timeout GRSTCTL GRSTCTL_AHBIDLE
         WARNING: CPU: 2 PID: 112 at drivers/regulator/core.c:2074 _regulator_put.part.0+0x16c/0x174
         Modules linked in: dwc2(E+) dwc3(E) udc_core(E) rtc_hym8563(E) dwmac_generic(E) ulpi(E) usbcore(E) dwc3_meson_g12a(E) roles(E) meson_gx_mmc(E+) i2c_meson(E) mdio_mux_meson_g12a(E) mdio_mux(E) dwmac_meson8b(E) stmmac_platform(E) stmmac(E) mdio_xpcs(E) phylink(E) of_mdio(E) fixed_phy(E) libphy(E) pwm_regulator(E) fixed(E)
         CPU: 2 PID: 112 Comm: systemd-udevd Tainted: G            E     5.9.0-rc4-00102-g423583bc8cf9 #1840
         Hardware name: amlogic w400/w400, BIOS 2020.04 05/22/2020
         pstate: 80400009 (Nzcv daif +PAN -UAO BTYPE=--)
         pc : _regulator_put.part.0+0x16c/0x174
         lr : regulator_bulk_free+0x6c/0x9c
         sp : ffffffc012353820
         x29: ffffffc012353820 x28: ffffff805a4b7000
         x27: ffffff8059c2eac0 x26: ffffff8059c2e810
         x25: ffffff805a4b7d00 x24: ffffffc008cf3028
         x23: ffffffc011729ef8 x22: ffffff807e2761d8
         x21: ffffffc01171df78 x20: ffffff805a4b7700
         x19: ffffff805a4b7700 x18: 0000000000000030
         x17: 0000000000000000 x16: 0000000000000000
         x15: ffffff807ea8d178 x14: 3935312820435455
         x13: 2038323a36313a37 x12: ffffffffffffffff
         x11: 0000000000000040 x10: 0000000000000007
         x9 : ffffffc0106f77d0 x8 : ffffffffffffffe0
         x7 : ffffffffffffffff x6 : 0000000000017702
         x5 : ffffff805a4b7400 x4 : 0000000000000000
         x3 : ffffffc01171df78 x2 : ffffff807ea8cc40
         x1 : 0000000000000000 x0 : 0000000000000001
         Call trace:
          _regulator_put.part.0+0x16c/0x174
          regulator_bulk_free+0x6c/0x9c
          devm_regulator_bulk_release+0x28/0x3c
          release_nodes+0x1c8/0x2c0
          devres_release_all+0x44/0x6c
          really_probe+0x1ec/0x504
          driver_probe_device+0x100/0x170
          device_driver_attach+0xcc/0xd4
          __driver_attach+0xb0/0x17c
          bus_for_each_dev+0x7c/0xd4
          driver_attach+0x30/0x3c
          bus_add_driver+0x154/0x250
          driver_register+0x84/0x140
          __platform_driver_register+0x54/0x60
          dwc2_platform_driver_init+0x2c/0x1000 [dwc2]
          do_one_initcall+0x54/0x2d0
          do_init_module+0x68/0x29c
      
      In order to fix this, tie the regulator disabling to the teardown
      process by registering a devm action callback. This makes sure that
      the regulators are disabled at the right time (just before they are
      released).
      
      Cc: Minas Harutyunyan <hminas@synopsys.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      54c19606
    • Pawel Laszczak's avatar
      usb: gadget: config_ep_by_speed_and_alt instead of config_ep_by_speed · 864bc7e7
      Pawel Laszczak authored
      
      
      This patch replace config_ep_by_speed with config_ep_by_speed_and_alt.
      This change allows to select proper usb_ss_ep_comp_descriptor for each
      stream capable endpoints.
      
      f_tcm function for SS use array of headers for both BOT/UAS alternate
      setting:
      
      static struct usb_descriptor_header *uasp_ss_function_desc[] = {
              (struct usb_descriptor_header *) &bot_intf_desc,
              (struct usb_descriptor_header *) &uasp_ss_bi_desc,
              (struct usb_descriptor_header *) &bot_bi_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_ss_bo_desc,
              (struct usb_descriptor_header *) &bot_bo_ep_comp_desc,
      
              (struct usb_descriptor_header *) &uasp_intf_desc,
              (struct usb_descriptor_header *) &uasp_ss_bi_desc,
              (struct usb_descriptor_header *) &uasp_bi_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_bi_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_bo_desc,
              (struct usb_descriptor_header *) &uasp_bo_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_bo_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_status_desc,
              (struct usb_descriptor_header *) &uasp_status_in_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_status_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_cmd_desc,
              (struct usb_descriptor_header *) &uasp_cmd_comp_desc,
              (struct usb_descriptor_header *) &uasp_cmd_pipe_desc,
              NULL,
      };
      
      The first 5 descriptors are associated with BOT alternate setting,
      and others are associated with UAS.
      
      During handling UAS alternate setting f_tcm driver invokes
      config_ep_by_speed and this function sets incorrect companion endpoint
      descriptor in usb_ep object.
      
      Instead setting ep->comp_desc to uasp_bi_ep_comp_desc function in this
      case set ep->comp_desc to bot_uasp_ss_bi_desc.
      
      And in result it uses the descriptor from BOT alternate setting
      instead UAS.
      
      Finally, it causes that controller driver during enabling endpoints
      detect that just enabled endpoint for bot.
      
      Signed-off-by: default avatarJayshri Pawar <jpawar@cadence.com>
      Signed-off-by: default avatarPawel Laszczak <pawell@cadence.com>
      Reviewed-by: default avatarPeter Chen <peter.chen@nxp.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      864bc7e7
    • Qinglang Miao's avatar
      usb: gadget: lpc32xx_udc: Convert to DEFINE_SHOW_ATTRIBUTE · 5bb1d119
      Qinglang Miao authored
      
      
      Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
      
      Acked-by: default avatarVladimir Zapolskiy <vz@mleia.com>
      Signed-off-by: default avatarQinglang Miao <miaoqinglang@huawei.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      5bb1d119
    • Christian Lamparter's avatar
      usb: dwc2: add support for APM82181 USB OTG · 0abe3863
      Christian Lamparter authored
      
      
      adds the specific compatible string for the DWC2 IP found in the APM82181
      SoCs. The IP is setup correctly through the auto detection... With the
      exception of the AHB Burst Size. The default of GAHBCFG_HBSTLEN_INCR4 of
      the "snps,dwc2" can cause a system hang when the USB and SATA is used
      concurrently. Because the predecessor (PPC460EX (Canyonlands)) already
      had the same problem, this SoC can make use of the existing
      dwc2_set_amcc_params() function.
      
      Signed-off-by: default avatarChristian Lamparter <chunkeey@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      0abe3863
    • Christian Lamparter's avatar
      dt-bindings: usb: dwc2: add support for APM82181 SoCs USB OTG HS and FS · 704c70fa
      Christian Lamparter authored
      
      
      adds the specific compatible string for the DWC2 IP found in the APM82181
      SoCs. The APM82181's USB-OTG seems like it was taken from its direct
      predecessor: the PPC460EX (canyonlands).
      
      Signed-off-by: default avatarChristian Lamparter <chunkeey@gmail.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      704c70fa
    • Bryan O'Donoghue's avatar
      USB: gadget: f_ncm: Fix NDP16 datagram validation · 028296e4
      Bryan O'Donoghue authored
      commit 2b74b0a0 ("USB: gadget: f_ncm: add bounds checks to ncm_unwrap_ntb()")
      adds important bounds checking however it unfortunately also introduces  a
      bug with respect to section 3.3.1 of the NCM specification.
      
      wDatagramIndex[1] : "Byte index, in little endian, of the second datagram
      described by this NDP16. If zero, then this marks the end of the sequence
      of datagrams in this NDP16."
      
      wDatagramLength[1]: "Byte length, in little endian, of the second datagram
      described by this NDP16. If zero, then this marks the end of the sequence
      of datagrams in this NDP16."
      
      wDatagramIndex[1] and wDatagramLength[1] respectively then may be zero but
      that does not mean we should throw away the data referenced by
      wDatagramIndex[0] and wDatagramLength[0] as is currently the case.
      
      Breaking the loop on (index2 == 0 || dg_len2 == 0) should come at the end
      as was previously the case and checks for index2 and dg_len2 should be
      removed since zero is valid.
      
      I'm not sure how much testing the above patch received but for me right now
      after enumeration ping doesn't work. Reverting the commit restores ping,
      scp, etc.
      
      The extra validation associated with wDatagramIndex[0] and
      wDatagramLength[0] appears to be valid so, this change removes the incorrect
      restriction on wDatagramIndex[1] and wDatagramLength[1] restoring data
      processing between host and device.
      
      Fixes: 2b74b0a0
      
       ("USB: gadget: f_ncm: add bounds checks to ncm_unwrap_ntb()")
      Cc: Ilja Van Sprundel <ivansprundel@ioactive.com>
      Cc: Brooke Basile <brookebasile@gmail.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarBryan O'Donoghue <bryan.odonoghue@linaro.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      028296e4
    • Pawel Laszczak's avatar
      usb: cdns3: Enable workaround for USB2.0 PHY Rx compliance test PHY lockup · 2eae2dfd
      Pawel Laszczak authored
      
      
      USB2.0 PHY hangs in Rx Compliance test when the incoming packet
      amplitude is varied below and above the Squelch Level of
      Receiver during the active packet multiple times.
      
      Version 1 of the controller allows PHY to be reset when RX fail condition
      is detected to work around the above issue. This feature is
      disabled by default and needs to be enabled using a bit from
      the newly added PHYRST_CFG register. This patch enables the workaround.
      
      There is no way to know controller version before device controller
      is started and the workaround needs to be applied for both host and
      device modes, so we rely on a DT property do decide when to
      apply the workaround.
      
      Signed-off-by: default avatarPawel Laszczak <pawell@cadence.com>
      Signed-off-by: default avatarRoger Quadros <rogerq@ti.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      2eae2dfd
    • Roger Quadros's avatar
      dt-bindings: usb: cdns,usb3: Add cdns,phyrst-a-enable property · 5261e48f
      Roger Quadros authored
      
      
      Controller version 0x0002450D has USB2 PHY RX sensitivity issues
      that needs to be worked around by enabling phyrst-a-enable bit
      in PHYRST_CFG register.
      
      There is no way to know controller version before device controller
      is started and the workaround needs to be applied for both host and
      device modes, so we add this DT property.
      
      Signed-off-by: default avatarRoger Quadros <rogerq@ti.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      5261e48f
    • Roger Quadros's avatar
      dt-bindings: usb: Convert cdns-usb3.txt to YAML schema · 68989fe1
      Roger Quadros authored
      
      
      Converts cdns-usb3.txt to YAML schema cdns,usb3.yaml
      
      Reviewed-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarRoger Quadros <rogerq@ti.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      68989fe1
    • Neil Armstrong's avatar
      usb: dwc-meson-g12a: Add support for USB on AXG SoCs · 65f3d449
      Neil Armstrong authored
      
      
      The Amlogic AXG is close to the GXL Glue but with a single OTG PHY.
      
      It needs the same init sequence as GXL & GXM, but it seems it doesn't need
      the host disconnect bit.
      
      Reviewed-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
      Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
      Reviewed-by: default avatarKevin Hilman <khilman@baylibre.com>
      Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
      65f3d449