20 Nov, 2018

2 commits

  • Like commit d144dfea8af7 ("usb: chipidea: otg: change workqueue
    ci_otg as freezable"), the power_lost work item may try to remove
    hcd if controller is powered off during the system suspend, and
    the similar deadlock happens, see below dumps.

    Meanwhile, with this change, we need to disable USB interrupt
    during the work item runs (after driver resume has finished),
    otherwise, USB transfer will be timeout (5s) due to USB interrupt
    is disabled and IAA watchdog is still not ready at that time.

    Workqueue: events ci_power_lost_work
    Call trace:
    [] __switch_to+0x8c/0xd0
    [] __schedule+0x19c/0x5d8
    [] schedule+0x38/0xa0
    [] schedule_timeout+0x19c/0x338
    [] wait_for_common+0xa0/0x148
    [] wait_for_completion+0x14/0x20
    [] flush_work+0xd8/0x1f0
    [] flush_delayed_work+0x3c/0x48
    [] wb_shutdown+0x90/0xd0
    [] bdi_unregister+0x58/0x1c0
    [] del_gendisk+0x218/0x228
    [] sd_remove+0x64/0xc0
    [] device_release_driver_internal+0x154/0x1f0
    [] device_release_driver+0x14/0x20
    [] bus_remove_device+0xc8/0x108
    [] device_del+0x1f8/0x300
    [] __scsi_remove_device+0xec/0x128
    [] scsi_forget_host+0x70/0x78
    [] scsi_remove_host+0xa0/0x140
    [] usb_stor_disconnect+0x50/0xc0
    [] usb_unbind_interface+0x78/0x280
    [] device_release_driver_internal+0x154/0x1f0
    [] device_release_driver+0x14/0x20
    [] bus_remove_device+0xc8/0x108
    [] device_del+0x1f8/0x300
    [] usb_disable_device+0xa4/0x210
    [] usb_disconnect+0x7c/0x240
    [] usb_disconnect+0x1c0/0x240
    [] usb_remove_hcd+0xc0/0x1d8
    [] host_stop+0x34/0x90
    [] ci_handle_id_switch+0x70/0x1d0
    [] ci_power_lost_work+0x90/0xa8
    [] process_one_work+0x1e0/0x340
    [] worker_thread+0x50/0x458
    [] kthread+0xfc/0x128
    [] ret_from_fork+0x10/0x18

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen
    (cherry picked from commit d217dacbe793641497b38f48d063a6332242e8a9)

    Peter Chen
     
  • At current code, it doesn't maintain ci->gadget.dev's runtime PM
    status well. Eg, after system resume, call pm_runtime_put_sync for
    ci->dev will cause ci->dev's runtime suspend is called if its
    power.usage is 0 even the power.usage is 1 for its child ci->gadget.dev.
    at that time. It causes the oops this ticket describes that visiting
    clock without AHB clock.

    To fix this issue, we use ci_hdrc device instead of ci->gadget.dev
    for runtime PM APIs at udc driver, in the way, we handle runtime
    PM APIs for single device structure.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen
    (cherry picked from commit d436b3a0a81b073b195d0ad29e7a4f39a1a532f3)

    Peter Chen
     

02 Nov, 2018

3 commits


30 Oct, 2018

1 commit


29 Oct, 2018

34 commits

  • For imx7d, no software operation is needed for HSIC controller, so delete
    related operation.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • imx7ulp uses different USB PHY with imx7d (MXS PHY vs PICO PHY), so the
    features are supported by non-core register are a little different.
    For example, autoresume feature is supported by all controllers for
    imx7ulp, but for imx7d, it is only supported by non-HSIC controller.

    Since imx7d has dedicated .init function, so the flag for imx7d PHY
    (picophy) can be deleted.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • Since the DP pullup can be finished at glue layer, we can delete
    it at common code, but we still need to keep DP pulldown operation
    since the DP may have already pulled up before.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • For Samsung PHY SoCs (imx7d/imx845), we used core register usbcmd.rs
    to pull up DP to finish the pre-condition for secondary USB charger
    detection before. In fact, there are some non-core registers can
    fulfill the same task, in that way, we could not touch the common
    chipidea registers.

    Meanwhile, we delete the secondary charger detection operation and
    clean up related code.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • Factor out the guts of usb charger initialization into usb_charger_init()
    function, to make the usb_add_extcon() only do the extcon related things.
    Meanwhile we also should initialize the USB charger before registering
    the extcon device, in case the extcon notification was issued earlier than
    usb charger initialization.

    Signed-off-by: Baolin Wang
    Signed-off-by: Felipe Balbi

    Baolin Wang
     
  • mxs_charger_secondary_detection() is only used in this file, so make
    it static.

    This fixes the following sparse warning:

    drivers/usb/phy/phy-mxs-usb.c:581:23: warning: symbol 'mxs_charger_secondary_detection' was not declared. Should it be static?

    Acked-by: Jun Li
    Signed-off-by: Fabio Estevam
    Signed-off-by: Felipe Balbi

    Fabio Estevam
     
  • Some platforms may want to use USB PHY charger detection function
    when VBUS is there, add one flag for it. The user can enable it
    at firmware.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • We can assign the charger detection results for common USB PHY
    structure directly now, so delete the imx usb charger structure.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • Some platforms (eg, imx6/imx7ulp/imx8qm) which implements charger
    detection at USB PHY driver can use framework directly. Other
    platforms (eg, imx7d/imx845) which do not implement charger detection
    at their USB PHY driver, just assign the charger detection results
    for usb_phy structure.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • The DCD is a hardware IP in USB PHY which is used for USB charger
    detection, we use polling method for charger detection in this
    design to avoid unknown USB PHY interrupt. Currently, the
    imx8qm, imx8qxp and imx7ulp have DCD module.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • mxs phy has data pin contact and usb charger detector blocks which
    can be controlled by software to detect charger type for SDP, CDP and
    DCP.

    Reviewed-by: Baolin Wang
    Signed-off-by: Li Jun
    Signed-off-by: Felipe Balbi
    Signed-off-by: Peter Chen

    Li Jun
     
  • At xhci removal the USB3 hcd (shared_hcd) is removed before the primary
    USB2 hcd. Interrupts for port status changes may still occur for USB3
    ports after the shared_hcd is freed, causing NULL pointer dereference.

    Check if xhci->shared_hcd is still valid before handing USB3 port events

    Cc:
    Reported-by: Peter Chen
    Tested-by: Jack Pham
    Signed-off-by: Mathias Nyman
    Signed-off-by: Peter Chen

    Mathias Nyman
     
  • (Merged upstream reviewing patch, and add cdns support -- Peter Chen)

    Ensure that the shared_hcd pointer is valid when calling usb_put_hcd()

    The shared_hcd is removed and freed in xhci by first calling
    usb_remove_hcd(xhci->shared_hcd), and later
    usb_put_hcd(xhci->shared_hcd)

    Afer commit fe190ed0d602 ("xhci: Do not halt the host until both HCD have
    disconnected their devices.") the shared_hcd was never properly put as
    xhci->shared_hcd was set to NULL before usb_put_hcd(xhci->shared_hcd) was
    called.

    shared_hcd (USB3) is removed before primary hcd (USB2).
    While removing the primary hcd we might need to handle xhci interrupts
    to cleanly remove last USB2 devices, therefore we need to set
    xhci->shared_hcd to NULL before removing the primary hcd to let xhci
    interrupt handler know shared_hcd is no longer available.

    xhci-plat.c, cdns/host.c first create both their hcd's before
    adding them. so to keep the correct reverse removal order use a temporary
    shared_hcd variable for them.
    For more details see commit 4ac53087d6d4 ("usb: xhci: plat: Create both
    HCDs before adding them")

    Fixes: fe190ed0d602 ("xhci: Do not halt the host until both
    HCD have disconnected their devices.")
    Cc: Joel Stanley
    Cc: Chunfeng Yun
    Cc: Thierry Reding
    Cc: Jianguo Sun
    Cc:
    Tested-by: Peter Chen
    Tested-by: Jack Pham
    Reported-by: Jack Pham
    Signed-off-by: Mathias Nyman
    Signed-off-by: Peter Chen

    Peter Chen
     
  • It may be used by xhci platform driver, fixed below error when
    building xhci as module.

    ERROR: "xhci_bus_suspend" [drivers/usb/cdns3/cdns3.ko] undefined!
    linux-imx/scripts/Makefile.modpost:92: recipe for target '__modpost' failed
    make[2]: *** [__modpost] Error 1
    linux-imx/Makefile:1231: recipe for target 'modules' failed
    make[1]: *** [modules] Error 2

    Reported-by: Bruce Zhang
    Signed-off-by: Peter Chen

    Peter Chen
     
  • The TPL support is used to identify targeted devices during
    EH2.0 and EH3.0 certification test.

    Acked-by: Jun Li
    Signed-off-by: Peter Chen
    (cherry picked from commit a2525e0c5f3ad5e07f91e65fef7eb02c32d69c70)

    Peter Chen
     
  • These two parameters are used to improve USB signal for board level,
    in this commit, we read it from the dtb, and write to related register
    during the initialization.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • To reflect it is a USB driver.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • When the USB port goes to suspend, PowerState should set to "D1"
    (the D2 and D3hot are not supported now); PowerState should set to
    "D0" when the USB port goes to resume.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • The controller needs to set CFG_RXDET_P3_EN within 100ms after
    USB3 port is set to U3, but when there is a USB3 HUB in port, the
    USB2 port bus suspend may take more than 100ms to finish, it causes
    disconnection and PHY can't enter low power mode in system suspend
    routine.

    To fix this issue, we implement the platform .bus_suspend, and set
    CFG_RXDET_P3_EN just after xhci_bus_suspend. The LPM_2_STB_SWITCH_EN
    only needs to be set one time, and OTG_STB_CLK_SWITCH_EN isn't needed
    to set for host/device mode according to IC engineer's sugguestion.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • Some platforms (eg: Cadence USB3) have special requirements to add
    platform USB register setting between xhci_bus_suspend and
    platform USB controller suspend routine. Eg, The Cadence USB3 needs
    RX detect clock switch from 24Mhz to 32Khz within 100ms after set
    port to U3, but sometimes, for USB3 HUB connection, the USB2
    bus suspend will cost more than 100ms, and introduce the disconnection
    before the PHY enters low power mode, then the state is in mess from
    controller side.

    So in this commit, we introduce .bus_suspend for xhci_driver_overrides
    for above use cases.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • Update gadget state to be USB_STATE_NOTATTACHED after stop gaget.

    Signed-off-by: Li Jun

    Li Jun
     
  • Current XHCI implementation does not consider completion interrupt
    for SETUP packet standalone, so it will show warning message
    and return error status for URB. In fact, it can support it. In
    this commit, we change warning message as debug message and set
    status as zero for URB.

    Support completion interrupt for SETUP packet is needed for USB EH2.0
    SINGLE_STEP_SET_FEATURE Test.

    Acked-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • During the USB certification CV9 test, if we report OTG descriptor
    to test suite, it will require doing OTG test, but in fact, it does
    not support OTG-compliance in dwc3 driver.

    For one Image configuration, it may choose CONFIG_USB_OTG, in order to
    skip OTG descriptor, we need to set gadget->is_otg as false for
    non OTG-compliance hardware. Due to dwc3 IP supports OTG-compliance,
    the user can add "hnp-disable", "srp-disable" and "adp-disable"
    at firmware to disable OTG features (skip OTG descriptor). This
    patch does NOT affect current configuration descriptors.

    Acked-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • The usb_add_hcd and usb_remove_hcd can't be called together, otherwise,
    there is oops like below. To fix it, we add mutex to avoid calling
    role_start and role_stop at the same time.

    [3.336786] Can't support > 32 bit dma.
    [3.340676] xhci-cdns3: xHCI Host Controller
    [3.345052] xhci-cdns3: new USB bus registered, assigned bus number 1
    [3.363462] xhci-cdns3: hcc params 0x200073c8 hci version 0x100 quirks 0x60010010
    [3.374555] hub 1-0:1.0: USB hub found
    [3.378349] hub 1-0:1.0: 1 port detected
    [3.382573] xhci-cdns3: xHCI Host Controller
    [3.386948] xhci-cdns3: new USB bus registered, assigned bus number 2
    [3.387707] cdns-usb3 5b110000.cdns3: current role is 0, switch to 1
    [3.387711] xhci-cdns3: remove, state 0
    [3.387721] Unable to handle kernel NULL pointer dereference at virtual address 000000d8
    [3.387723] pgd = ffff0000095f5000
    [3.387731] [000000d8] *pgd=00000008bfffe003, *pud=00000008bfffd003, *pmd=0000000000000000
    [3.387735] Internal error: Oops: 96000004 [#1] PREEMPT SMP
    [3.387739] Modules linked in:
    [3.387746] CPU: 0 PID: 745 Comm: kworker/0:1 Not tainted 4.9.88-05224-geb65e0981da1 #2087
    [3.387748] Hardware name: Freescale i.MX8QXP MEK (DT)
    [3.387765] Workqueue: events_freezable cdns3_role_switch
    [3.387768] task: ffff80083a1d7080 task.stack: ffff80083aa5c000
    [3.387775] PC is at sysfs_remove_group+0x18/0x98
    [3.387781] LR is at usb_remove_hcd+0x58/0x200
    [3.387784] pc : [] lr : [] pstate: 80000145
    [3.387786] sp : ffff80083aa5fc70
    [3.387791] x29: ffff80083aa5fc70 x28: 0000000000000000
    [3.387795] x27: 0000000000000000 x26: ffff0000093cb2a8
    [3.387800] x25: ffff000009506191 x24: ffff80083ff37280
    [3.387804] x23: ffff80083b1b0138 x22: ffff80083b238000
    [3.387809] x21: ffff80083b238000 x20: ffff0000094a1610
    [3.387813] x19: ffff80083b1b0000 x18: 0000000000000020
    [3.387817] x17: 0000000000000001 x16: 0000000000000019
    [3.387822] x15: ffffffffffffffff x14: 00000000fffffff0
    [3.387827] x13: ffff0000095a2068 x12: ffff0000093ce600
    [3.387831] x11: ffff0000093ce000 x10: ffff00000959f000
    [3.387836] x9 : 0000000000000000 x8 : ffff80083fe4244c
    [3.387840] x7 : 0000000000000000 x6 : 0000000007cb5702
    [3.387844] x5 : 00ffffffffffffff x4 : 0000000000000000
    [3.387848] x3 : 0000000000000140 x2 : 00000000000008a6
    [3.387852] x1 : 0000000000000000 x0 : 00000000000000a8
    [3.387853]
    [3.387856] Process kworker/0:1 (pid: 745, stack limit = 0xffff80083aa5c020)
    [3.387860] Stack: (0xffff80083aa5fc70 to 0xffff80083aa60000)
    [3.387865] fc60: ffff80083aa5fca0 ffff00000885ac28
    [3.387870] fc80: ffff80083b1b0000 ffff0000094a1000 ffff80083b238000 0000000000000000
    [3.387875] fca0: ffff80083aa5fcf0 ffff00000889c5c8 ffff80083b1bf400 ffff80083b23e018
    [3.387880] fcc0: ffff80083b238000 ffff80083b238000 ffff80083ff3bb00 ffff80083a1d7080
    [3.387885] fce0: ffff000008ccc25c 0000000000000000 ffff80083aa5fd20 ffff000008897130
    [3.387890] fd00: ffff80083b23e018 0000000000000001 0000000000000000 0000000000000000
    [3.387895] fd20: ffff80083aa5fd50 ffff0000088972ec ffff80083b23e0d0 0000000000000000
    [3.387901] fd40: ffff80083b23e018 ffff000008ccc25c ffff80083aa5fd80 ffff0000080dbc38
    [3.387906] fd60: 0000000000000000 ffff80083ac3a600 ffff80083b23e0d0 ffff0000093b6000
    [3.387911] fd80: ffff80083aa5fdc0 ffff0000080dbe40 ffff80083ac3a600 ffff80083ff37280
    [3.387916] fda0: ffff80083ff37280 ffff80083ac3a630 ffff80083ff372a0 ffff0000093b6000
    [3.387921] fdc0: ffff80083aa5fe20 ffff0000080e1c78 ffff80083a0fee80 ffff80083aa5c000
    [3.387926] fde0: ffff00000908e2c8 ffff80083ac3a600 ffff0000080dbdf0 0000000000000000
    [3.387931] fe00: 0000000000000000 0000000000000000 0000000000000000 ffff80083ac3a600
    [3.387936] fe20: 0000000000000000 ffff000008083820 ffff0000080e1b98 ffff80083a0fee80
    [3.387941] fe40: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387946] fe60: ffff80083aa5fea0 0000000000000000 ffff0000080e1b98 ffff80083ac3a600
    [3.387951] fe80: 0000000000000000 0000000000000000 ffff80083aa5fe90 ffff80083aa5fe90
    [3.387956] fea0: 0000000000000000 ffff000000000000 ffff80083aa5feb0 ffff80083aa5feb0
    [3.387960] fec0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387965] fee0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387970] ff00: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387974] ff20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387979] ff40: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387983] ff60: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387988] ff80: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387992] ffa0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    [3.387997] ffc0: 0000000000000000 0000000000000005 0000000000000000 0000000000000000
    [3.388002] ffe0: 0000000000000000 0000000000000000 fefffac7ef9fea6e f6ef6c26eeee7272
    [3.388004] Call trace:
    [3.388008] Exception stack(0xffff80083aa5faa0 to 0xffff80083aa5fbd0)
    [3.388013] faa0: ffff80083b1b0000 0000ffffffffffff ffff80083aa5fc70 ffff000008265688
    [3.388019] fac0: ffff80083b238000 ffff80083b238000 ffff80083b1b0138 ffff80083ff37280
    [3.388024] fae0: ffff000009506191 ffff0000093cb2a8 0000000000000000 ffff80083aa5fcb0
    [3.388029] fb00: ffff80083aa5fc20 ffff80083aa5fc20 ffff80083aa5fbf0 00000000ffffffd8
    [3.388034] fb20: ffff000009506191 ffff0000093cb2a8 0000000000000000 ffff80083a11f408
    [3.388038] fb40: 00000000000000a8 0000000000000000 00000000000008a6 0000000000000140
    [3.388043] fb60: 0000000000000000 00ffffffffffffff 0000000007cb5702 0000000000000000
    [3.388048] fb80: ffff80083fe4244c 0000000000000000 ffff00000959f000 ffff0000093ce000
    [3.388054] fba0: ffff0000093ce600 ffff0000095a2068 00000000fffffff0 ffffffffffffffff
    [3.388057] fbc0: 0000000000000019 0000000000000001
    [3.388061] [] sysfs_remove_group+0x18/0x98
    [3.388066] [] usb_remove_hcd+0x58/0x200
    [3.388072] [] cdns3_host_stop+0x38/0xa0
    [3.388077] [] cdns3_do_role_switch+0x58/0x188
    [3.388082] [] cdns3_role_switch+0x8c/0xa0
    [3.388089] [] process_one_work+0x1c8/0x380
    [3.388094] [] worker_thread+0x50/0x4c0
    [3.388099] [] kthread+0xe0/0xf8
    [3.388104] [] ret_from_fork+0x10/0x30

    Signed-off-by: Peter Chen

    Peter Chen
     
  • Current code does not support queuing multiple requests for ep0, return
    -EOPNOTSUPP if that happens.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • We only unmap the request which is demanded from the gadget driver.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • We need to prepare setup packet no matter configuration is set or
    not.

    Signed-off-by: Peter Chen

    Peter Chen
     
  • For CDNS3 gadget, there is NO setup status completion interrupt, but
    software has related request and completion handler for EP0 setup
    status. In previous design, it executes ->completion before .ep0_queue
    back, and causes cdev->setup_pending and cdev->os_desc_pending
    incorrect, the dequeue is executed wrongly.

    In this commit, we postpone ->comletion to workqueue or the next
    EP0 interrupt, it makes sure the ->completion is executed after
    .ep0_queue.

    [ 220.785184] android_work: did not send uevent (0 0 (null))
    [ 220.792651] Bad mode in Error handler detected on CPU2, code 0xbf000002 -- SError
    06-28 02:47:13.145 3946 3946 I zygote64: Deoptimizing void com.android.systemui.statusbar.stack.NotificationStackScrollLayout.updateContentHeight() due to JIT inline cache
    [ 220.815371] Internal error: Oops - bad mode: 0 [#1] PREEMPT SMP
    [ 220.821312] Modules linked in:
    [ 220.824389] CPU: 2 PID: 1 Comm: init Not tainted 4.9.105-644221-ga78d348 #8
    [ 220.831362] Hardware name: Freescale i.MX8QXP MEK (DT)
    [ 220.836504] task: ffff80083a0e0000 task.stack: ffff80083a0e8000
    [ 220.842431] PC is at 0x4ec908
    [ 220.845398] LR is at 0x454a30
    [ 220.848363] pc : [] lr : [] pstate: 40000000
    [ 220.855762] sp : 0000ffffe0c35ca0
    [ 220.859072] x29: 0000ffffe0c35cc0 x28: 00000000ffffffff
    [ 220.864397] x27: 00000000ffffffff x26: 0000000000000001
    [ 220.869722] x25: 0000ffff7f6446a9 x24: 000000000057da40
    [ 220.875047] x23: 0000000000088241 x22: 0000ffff7f6446c0
    [ 220.880373] x21: 0000ffff7f6446c1 x20: 0000000000000009
    [ 220.885698] x19: 0000000000000004 x18: 00000000020f06cc
    [ 220.891024] x17: aaaaaaaaaaaaaaab x16: 0000000000000000
    [ 220.896349] x15: 000000000000005c x14: 0000000000000000
    [ 220.901675] x13: 4344552f31672f74 x12: 0000ffffe0c35c88
    [ 220.907000] x11: 0000ffffe0c35cd0 x10: 0000000000000004
    [ 220.912325] x9 : 0000000000000000 x8 : 0000000000000040
    [ 220.917651] x7 : 7f7f7f7f7f7f7f7f x6 : 655e666d68736860
    [ 220.922976] x5 : 0000000000000000 x4 : 0000000000000000
    [ 220.928302] x3 : 0000000000000180 x2 : 0000000000000004
    [ 220.933627] x1 : 0000ffff7f6446c1 x0 : 0000000000000004
    [ 220.938952]
    [ 220.940440] Process init (pid: 1, stack limit = 0xffff80083a0e8000)

    Reported-by: Andy Tian
    Signed-off-by: Peter Chen

    Peter Chen
     
  • - The gadget speed should be reset to USB_SPEED_UNKNOWN at any de-init
    process
    - The TRB buffer should be free when the gadget is removed

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • Move all memory allocation to usb_ss_allocate_trb_pool and align with
    usb_ss_free_trb_pool.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • Some gadget drivers may dequeue its request very late, eg, after
    the controller is stopped, at this situation, visiting related
    register will cause abort. See below oops from android use case:

    [ 1676.773258] android_work: sent uevent USB_STATE=CONFIGURED
    [ 1676.788278] mtp_open
    [ 1850.542145] android_work: sent uevent USB_STATE=DISCONNECTED
    [ 1850.545311] mtp_release
    [ 1852.050358] init: processing action (sys.usb.config=none && sys.usb.configfs=1) from (init.freescale.usb.rc:45)
    [ 1852.061224] init: processing action (sys.usb.config=none && sys.usb.configfs=1) from (/init.usb.configfs.rc:1)
    [ 1852.074316] android_work: did not send uevent (0 0 (null))
    [ 1852.080893] Unhandled fault: synchronous external abort (0x96000210) at 0xffff000016a90028
    [ 1852.089186] Internal error: : 96000210 [#1] PREEMPT SMP
    [ 1852.094422] Modules linked in:
    [ 1852.097491] CPU: 0 PID: 1 Comm: init Not tainted 4.9.105-00010-g30f2a53-dirty #4
    [ 1852.104889] Hardware name: Freescale i.MX8QXP MEK (DT)
    [ 1852.110031] task: ffff80083a0e0000 task.stack: ffff80083a0e8000
    [ 1852.115966] PC is at wait_reg_bit.constprop.13+0x24/0xb4
    [ 1852.121286] LR is at usb_ss_gadget_ep_dequeue+0x110/0x164
    [ 1852.126685] pc : [] lr : [] pstate: a00001c5
    [ 1852.134085] sp : ffff80083a0ebc30
    [ 1852.137395] x29: ffff80083a0ebc30 x28: ffff80083a0e0000
    [ 1852.142720] x27: ffff000008ec3000 x26: 0000000000000000
    [ 1852.148046] x25: ffff80083a0ebeb0 x24: ffff80083b751000
    [ 1852.153371] x23: 0000000000000080 x22: 0000000000000000
    [ 1852.158696] x21: ffff000016a90028 x20: ffff80083b6e7e18
    [ 1852.164022] x19: ffff8000507fb580 x18: 000000000042d1e0
    [ 1852.169348] x17: aaaaaaaaaaaaaaab x16: ffff0000082678fc
    [ 1852.174673] x15: ffffffffffffffff x14: 2020202020202020
    [ 1852.179998] x13: 2020203020302820 x12: 746e657665752064
    [ 1852.185324] x11: ffff80083ff2ee40 x10: ffff80083b708870
    [ 1852.190649] x9 : 0000000040000000 x8 : 0000000000210d00
    [ 1852.195974] x7 : 0000000000000005 x6 : ffff80083b708871
    [ 1852.201300] x5 : ffff00000894c084 x4 : 0000000000000000
    [ 1852.206627] x3 : 0000000000000000 x2 : 0000000000000080
    [ 1852.211951] x1 : ffff000016a90028 x0 : ffff80083b751000
    [ 1852.217278]
    [ 1852.217278] SP: 0xffff80083a0ebbb0:
    [ 1852.222245] bbb0 00000000 00000000 00000080 00000000 3b751000 ffff8008 3a0ebeb0 ffff8008
    [ 1852.230498] bbd0 00000000 00000000 08ec3000 ffff0000 3a0e0000 ffff8008 3a0ebc30 ffff8008
    [ 1852.238751] bbf0 0894ccf4 ffff0000 3a0ebc30 ffff8008 0894c2d0 ffff0000 a00001c5 00000000
    [ 1852.247004] bc10 3a0ebeb0 ffff8008 3b6e6418 ffff8008 ffffffff 0000ffff 80080007 00000001
    [ 1852.255257] bc30 3a0ebc70 ffff8008 0894ccf4 ffff0000 507fb580 ffff8000 3b6e7e18 ffff8008
    [ 1852.263510] bc50 00000000 00000000 00000140 00000000 3b7517d0 ffff8008 3b751000 ffff8008
    [ 1852.271764] bc70 3a0ebcb0 ffff8008 0898ef58 ffff0000 3b537490 ffff8008 09a4a5a8 ffff0000
    [ 1852.280017] bc90 3b6e7e18 ffff8008 507fb580 ffff8000 00000004 00000000 aee44671 0000ffff
    [ 1852.288272]
    [ 1852.288272] X0: 0xffff80083b750f80:
    [ 1852.293240] 0f80 6cfdc6bf fee6fc67 76effaff d777e7fe 5ff67667 e7eef7ff 7fff75fc 6f7d7fff
    [ 1852.301492] 0fa0 7d7ef6f6 f23feefb 7ffff7ee f7de7e72 eeb47f7e 4bff73f4 fe367677 3ef573ed
    [ 1852.309745] 0fc0 674eb7e7 76f94767 f6ff66e7 eabe66ee fef663df fe7764e7 66ee2e64 febf7bcc
    [ 1852.317998] 0fe0 ef7f35ff f7ef6f6c 4cded7ee 76fffb77 f7f3765d ff8f7efb e5ee6ce7 bfe5e7ff
    [ 1852.326252] 1000 3a657c10 ffff8008 3b6e7f00 ffff8008 09341970 ffff0000 3b751388 ffff8008
    [ 1852.334505] 1020 3a657c28 ffff8008 3a657c20 ffff8008 3a1b8000 ffff8008 098f9d10 ffff0000
    [ 1852.342758] 1040 3b70b5a0 ffff8008 00000006 00000003 00000000 00000000 00000000 00000000
    [ 1852.351011] 1060 00000001 00000000 3b751068 ffff8008 3b751068 ffff8008 00000000 00000000
    [ 1852.359268]
    [ 1852.359268] X6: 0xffff80083b7087f1:
    [ 1852.364234] 87f0 00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000000
    [ 1852.372487] 8810 3b708810 ffff8008 3b708810 ffff8008 00000000 00000000 00000000 00000000
    [ 1852.380740] 8830 01ea01ea 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.388993] 8850 3b708850 ffff8008 3b708850 ffff8008 00000004 00000003 00000002 00000000
    [ 1852.397246] 8870 00000001 00010001 00000000 00000000 00320032 00000000 3b708888 ffff8008
    [ 1852.405499] 8890 3b708888 ffff8008 00000001 00000000 00000000 00000000 3bd5e300 ffff8008
    [ 1852.413752] 88b0 34157200 ffff8008 35173c00 ffff8008 35173c1c ffff8008 00000074 00000003
    [ 1852.422005] 88d0 00000003 00000005 00000001 00000000 00000000 00000000 3b76e5b0 ffff8008
    [ 1852.430258] 88f0 3b76e5b0 ffff8008 3b76e5b0 ffff8008 0000000f 00820100 00000000 00000000
    [ 1852.438514]
    [ 1852.438514] X10: 0xffff80083b7087f0:
    [ 1852.443570] 87f0 00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000000
    [ 1852.451821] 8810 3b708810 ffff8008 3b708810 ffff8008 00000000 00000000 00000000 00000000
    [ 1852.460074] 8830 01ea01ea 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.468327] 8850 3b708850 ffff8008 3b708850 ffff8008 00000004 00000003 00000002 00000000
    [ 1852.476580] 8870 00000001 00010001 00000000 00000000 00320032 00000000 3b708888 ffff8008
    [ 1852.484833] 8890 3b708888 ffff8008 00000001 00000000 00000000 00000000 3bd5e300 ffff8008
    [ 1852.493086] 88b0 34157200 ffff8008 35173c00 ffff8008 35173c1c ffff8008 00000074 00000003
    [ 1852.501340] 88d0 00000003 00000005 00000001 00000000 00000000 00000000 3b76e5b0 ffff8008
    [ 1852.509595]
    [ 1852.509595] X11: 0xffff80083ff2edc0:
    [ 1852.514649] edc0 00000000 00000000 00100000 00000000 00000000 00000000 0003b33d 00000000
    [ 1852.522902] ede0 000be6cc 00000000 00100000 00000000 00000000 00000000 00000001 00000001
    [ 1852.531155] ee00 00000000 00000000 caabd6a1 0000000c 00000000 00000000 00000000 00000000
    [ 1852.539408] ee20 3a0e0080 ffff8008 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.547661] ee40 392570e9 000001af 0239e900 00000000 0185fbb6 00000295 000002f9 00000000
    [ 1852.555914] ee60 00000211 00000000 0182c397 00000000 0000020d 00000000 00000000 00000000
    [ 1852.564167] ee80 00000001 00000000 00000052 00000000 0000001c 00000000 000002f9 00000000
    [ 1852.572421] eea0 0005eb9a 00000001 00000000 00000000 3ff2ed80 ffff8008 00000001 00000000
    [ 1852.580679]
    [ 1852.580679] X19: 0xffff8000507fb500:
    [ 1852.585730] b500 00000001 00000000 0994b2b0 ffff0000 00000000 00000000 00000000 00000000
    [ 1852.593983] b520 507fb520 ffff8000 507fb520 ffff8000 507fb560 ffff8000 00000002 00000000
    [ 1852.602236] b540 00002441 00000000 00000001 00000000 d54b3f06 00000175 00000000 00000000
    [ 1852.610489] b560 00010001 00000000 3b413200 ffff8008 0000c4f8 00000000 00000000 00000000
    [ 1852.618742] b580 3b76d800 ffff8008 00000000 00000000 fe5db800 00000000 00000000 00000000
    [ 1852.626995] b5a0 00000000 00000000 00000000 00000000 08989814 ffff0000 3b537430 ffff8008
    [ 1852.635249] b5c0 00000000 00000000 00000000 00000000 ffffff98 00000022 00000000 00000000
    [ 1852.643502] b5e0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.651758]
    [ 1852.651758] X20: 0xffff80083b6e7d98:
    [ 1852.656812] 7d98 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.665064] 7db8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.673317] 7dd8 00000000 00000000 00000000 00000000 00000000 00000000 316e6163 00000000
    [ 1852.681570] 7df8 00000000 00000000 3b6e7b00 ffff8008 3b7512a8 ffff8008 0874a428 ffff0000
    [ 1852.689823] 7e18 3b537430 ffff8008 3b6e7e98 ffff8008 08fe1788 ffff0000 00000000 00000000
    [ 1852.698077] 7e38 00000000 00000000 00000031 02000100 00000200 00000004 09917320 ffff0000
    [ 1852.706330] 7e58 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [ 1852.714583] 7e78 00000000 00000000 00000000 00000000 00000000 00000000 3b751000 ffff8008
    [ 1852.722839]
    [ 1852.722839] X24: 0xffff80083b750f80:
    [ 1852.727892] 0f80 6cfdc6bf fee6fc67 76effaff d777e7fe 5ff67667 e7eef7ff 7fff75fc 6f7d7fff
    [ 1852.736147] 0fa0 7d7ef6f6 f23feefb 7ffff7ee f7de7e72 eeb47f7e 4bff73f4 fe367677 3ef573ed
    [ 1852.744398] 0fc0 674eb7e7 76f94767 f6ff66e7 eabe66ee fef663df fe7764e7 66ee2e64 febf7bcc
    [ 1852.752652] 0fe0 ef7f35ff f7ef6f6c 4cded7ee 76fffb77 f7f3765d ff8f7efb e5ee6ce7 bfe5e7ff
    [ 1852.760905] 1000 3a657c10 ffff8008 3b6e7f00 ffff8008 09341970 ffff0000 3b751388 ffff8008
    [ 1852.769158] 1020 3a657c28 ffff8008 3a657c20 ffff8008 3a1b8000 ffff8008 098f9d10 ffff0000
    [ 1852.777411] 1040 3b70b5a0 ffff8008 00000006 00000003 00000000 000 00000000 00000000 00000000
    [ 1852.919573] 0040 00000001 00000000 00000034 00000000 0005eb90 00000001 3a905400 ffff8008
    52.949389] bbd0 00000000 00000000 08ec3000 ffff0000 3a0e0000 ffff8008 3a0ebc30 ffff8008
    [ 1852.957642] bbf0 0894ccf4 ffff3b6e7e18 ffff8008
    [ 1852.982401] bc50 00000000 00000000 00000140 00000000 3b7517d0 ffff8008 3b751000 ffff8008
    [ 1852.990600140
    [ 1853.036348] bc60: ffff80083b7517d0 ffff80083b751000 ffff80083a0ebcb0 ffff00000898ef58
    [ 1853.044183] bc80: ffff80083b537490 ffff000009a4a5a8 ffff80083b6e7e18 ffff8000507fb580
    [ 1853.052019] bca0: 0000000000000004 0000ffffaee44671 ffff80083a0ebce0 ffff00000898b4f0
    [ 1853.059855] bcc0: ffff80083b537490 ffff000009a4a5a8 ffff80083b537490 ffff80083b537430
    [ 1853.067691] bce0: ffff80083a0ebd10 ffff00000898d280 ffff80083b537430 ffff000009a4a5a8
    [ 1853.075528] bd00: ffff80083b751310 ffff00000991e000 ffff80083a0ebd40 ffff000008990b10
    [ 1853.083364] bd20: ffff80083b6fa000 ffff00000991ea48 ffff80083b537350 ffff00000991ea48
    [ 1853.091200] bd40: ffff80083a0ebd60 ffff000008990c00 ffff80083b6fa000 ffff00000898e86c
    [ 1853.099036] bd60: ffff80083a0ebd90 ffff00000898e8bc ffff800066af6f80 ffff80083b537000
    [ 1853.106872] bd80: 0000000000000000 ffff80083b5372a8 ffff80083a0ebdd0 ffff0000082db924
    [ 1853.114708] bda0: 0000000000000004 ffff800066af6d80 0000000000000000 ffff800066af6da0
    [ 1853.122544] bdc0: ffff8000674aeb00 0000000000000004 ffff80083a0ebe30 ffff0000082507c8
    [ 1853.130382] bde0: 0000000000000004 ffff8000674aeb00 0000000000000000 ffff80083a0ebeb0
    [ 1853.138216] be00: 0000ffffaee44671 0000000000000015 0000000000000123 0000000000000040
    [ 1853.146052] be20: 0000000000000004 0000000000000004 ffff80083a0ebe70 ffff000008251c7c
    [ 1853.153889] be40: ffff8000674aeb00 ffff8000674aeb00 ffff000009838000 00000000004ec908
    [ 1853.161724] be60: 0000000040000000 0000800836a09000 0000000000000000 ffff000008083780
    [ 1853.169561] be80: ffffffffffffff1d 0000800836a09000 ffffffffffffffff 00000000004ec908
    [ 1853.177396] bea0: 0000ffffaee44671 0000000000000004 0000000000000000 0000000000040969
    [ 1853.185233] bec0: 0000000000000009 0000ffffaee44671 0000000000000004 0000000000000180
    [ 1853.193069] bee0: 0000000000000000 0000000000000000 655e666d68736860 7f7f7f7f7f7f7f7f
    [ 1853.200905] bf00: 0000000000000040 0000000000000000 0000000000000004 0000ffffffa57620
    [ 1853.208742] bf20: 0000ffffffa575d8 4344552f31672f74 0000000000000000 000000000000005c
    [ 1853.216577] bf40: 0000000000000000 000000000000000d 0000000052841d82 0000000000000004
    [ 1853.224416] bf60: 0000000000000009 0000ffffaee44671 0000ffffaee44670 0000000000088241
    [ 1853.232250] bf80: 000000000057da40 0000ffffaee44659 0000000000000001 00000000ffffffff
    [ 1853.240086] bfa0: 00000000ffffffff 0000ffffffa57610 0000000000454a30 0000ffffffa575f0
    [ 1853.247922] bfc0: 00000000004ec908 0000000040000000 0000000000000009 0000000000000040
    [ 1853.255758] bfe0: 0000000000000000 0000000000000000 a62044020608c465 1224422020842444
    [ 1853.263592] Call trace:
    [ 1853.266035] Exception stack(0xffff80083a0eba40 to 0xffff80083a0ebb70)
    [ 1853.272482] ba40: ffff8000507fb580 0000ffffffffffff ffff80083a0ebc30 ffff00000894c2d0
    [ 1853.280320] ba60: 00000000a00001c5 ffff00000810a7dc ffff80083a0e0080 0000000000000007
    [ 1853.288154] ba80: ffff800800000000 ffff000016a90028 0000000000000000 ffff80083a001e00
    [ 1853.295990] baa0: ffff80083a0e0000 ffff80083a0e0000 000000018020001f 0000000100200020
    [ 1853.303828] bac0: ffff80083a0ebbe0 ffff00000822fda8 ffff7e00019dc9c0 ffff00000894c084
    [ 1853.311663] bae0: ffff80083a0ebc00 ffff00000822fda8 ffff7e000153f0c0 0000000000040969
    [ 1853.319498] bb00: ffff80083b751000 ffff000016a90028 0000000000000080 0000000000000000
    [ 1853.327334] bb20: 0000000000000000 ffff00000894c084 ffff80083b708871 0000000000000005
    [ 1853.335170] bb40: 0000000000210d00 0000000040000000 ffff80083b708870 ffff80083ff2ee40
    [ 1853.343005] bb60: 746e657665752064 2020203020302820
    [ 1853.347892] [] wait_reg_bit.constprop.13+0x24/0xb4
    [ 1853.354248] [] usb_ss_gadget_ep_dequeue+0x110/0x164
    [ 1853.360696] [] usb_ep_dequeue+0x24/0xd8
    [ 1853.366098] [] composite_dev_cleanup+0xe8/0x104
    [ 1853.372197] [] configfs_composite_unbind+0x3c/0x5c
    [ 1853.378556] [] usb_gadget_remove_driver+0x44/0x74
    [ 1853.384830] [] usb_gadget_unregister_driver+0xc0/0xf0

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • It is necessary to add ep0 request for its ep request list,
    ep0 request may need to be dequeued when remove gadget driver,
    see composite_dev_cleanup for detail.

    Reviewed-by: Jun Li
    Signed-off-by: Peter Chen

    Peter Chen
     
  • spin_unlock_irqrestore is missing if usb_gadget_map_request_by_dev
    fails.

    Acked-by: Peter Chen
    Signed-off-by: Li Jun

    Li Jun
     
  • In case a ZLP is required to finish the transfer, this patch implements it
    by adding a request with a preallocated buffer, which is shared with all
    EPs, please be noted this patch is only for non-EP0, ZLP for EP0 will be
    added later.

    Reported-by: Andy Tian
    Acked-by: Peter Chen
    Signed-off-by: Li Jun

    Li Jun