1
0
Fork 0
Commit Graph

64 Commits (redonkable)

Author SHA1 Message Date
Peter Chen 0404e11ef5 MLK-19601-1 xhci: Fix leaking USB3 shared_hcd at xhci removal
(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 fe190ed0d6 ("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 4ac53087d6 ("usb: xhci: plat: Create both
HCDs before adding them")

Fixes: fe190ed0d6 ("xhci: Do not halt the host until both
	       	HCD have disconnected their devices.")
Cc: Joel Stanley <joel@jms.id.au>
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Jianguo Sun <sunjianguo1@huawei.com>
Cc: <stable@vger.kernel.org>
Tested-by: Peter Chen <peter.chen@nxp.com>
Tested-by: Jack Pham <jackp@codeaurora.org>
Reported-by: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 45b8ac18aa MLK-19258-3 usb: cdns3: core: change the MODULE_ALIAS
To reflect it is a USB driver.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 21c2676698 MLK-18794-3 usb: cdns3: change the definition of PowerState at XECP_PM_PMCSR
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@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 06607acba0 MLK-18794-2 usb: cdns: improve the suspend routine for xhci host
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@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 27a64bb9ca MLK-19254 usb: cdns3: gadget: set gadget state to be USB_STATE_NOTATTACHED after stop
Update gadget state to be USB_STATE_NOTATTACHED after stop gaget.

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen c8eb7d2dff MLK-18817 usb: cdns3: gadget: add mutex for role_start and role_stop
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 : [<ffff000008265688>] lr : [<ffff00000885ac28>] 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] [<ffff000008265688>] sysfs_remove_group+0x18/0x98
[3.388066] [<ffff00000885ac28>] usb_remove_hcd+0x58/0x200
[3.388072] [<ffff00000889c5c8>] cdns3_host_stop+0x38/0xa0
[3.388077] [<ffff000008897130>] cdns3_do_role_switch+0x58/0x188
[3.388082] [<ffff0000088972ec>] cdns3_role_switch+0x8c/0xa0
[3.388089] [<ffff0000080dbc38>] process_one_work+0x1c8/0x380
[3.388094] [<ffff0000080dbe40>] worker_thread+0x50/0x4c0
[3.388099] [<ffff0000080e1c78>] kthread+0xe0/0xf8
[3.388104] [<ffff000008083820>] ret_from_fork+0x10/0x30

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 4a4232458c MLK-18609-8 usb: cdns3: gadget: do not support multiple requests for ep0
Current code does not support queuing multiple requests for ep0, return
-EOPNOTSUPP if that happens.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 53585b704e MLK-18609-7 usb: cdns3: gadget: only unmap buffer for demand request
We only unmap the request which is demanded from the gadget driver.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 79589b75db MLK-18609-6 usb: cdns3: gadget: need to prepare setup packet after status
We need to prepare setup packet no matter configuration is set or
not.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen ffdb7a0aac MLK-18609-5 usb: cdns3: gadget: implement setup status completion properly
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 : [<00000000004ec908>] lr : [<0000000000454a30>] 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 <yang.tian@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 20e7a46875 MLK-18609-4 usb: cdns3: gadget: refine de-init process
- 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 <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f4e05469f6 MLK-18609-3 usb: cdns3: gadget: refine the memory allocation function
Move all memory allocation to usb_ss_allocate_trb_pool and align with
usb_ss_free_trb_pool.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen c0984db6da MLK-18609-2 usb: cdns3: gadget: flush fifo only controller is started
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 : [<ffff00000894c2d0>] lr : [<ffff00000894ccf4>] 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] [<ffff00000894c2d0>] wait_reg_bit.constprop.13+0x24/0xb4
[ 1853.354248] [<ffff00000894ccf4>] usb_ss_gadget_ep_dequeue+0x110/0x164
[ 1853.360696] [<ffff00000898ef58>] usb_ep_dequeue+0x24/0xd8
[ 1853.366098] [<ffff00000898b4f0>] composite_dev_cleanup+0xe8/0x104
[ 1853.372197] [<ffff00000898d280>] configfs_composite_unbind+0x3c/0x5c
[ 1853.378556] [<ffff000008990b10>] usb_gadget_remove_driver+0x44/0x74
[ 1853.384830] [<ffff000008990c00>] usb_gadget_unregister_driver+0xc0/0xf0

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen ffa2804f24 MLK-18609-1 usb: cdns3: gadget: add ep0 request to list
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 <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 8e1113d7d9 MLK-18685 usb: cdns3: gadget: balance spin lock if map request fails
spin_unlock_irqrestore is missing if usb_gadget_map_request_by_dev
fails.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 8ad43aefeb MLK-18656 usb: cdns3: gdaget: add hanlding of request->zero for non-EP0
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 <yang.tian@nxp.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2e8b0ad6d4 MLK-18319-3 usb: cdns3: gadget: Typo cleanup
Typo cleanup.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 7d1a94b690 MLK-18319-2 usb: cdns3: gadget: delete the unless code
Confirmed from CDNS, this code is from bare metal, and not needed
for Linux. Below are their response:

This is alternative deferred interrupt.
This is intended to be used in Bare Metal to not block system in
interrupt.
This was not fully checked in Linux, so we do not recommend to use it
there.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 65aed0a45f MLK-18319-1 usb: cdns3: gadget: improvement the handling for non-aligned buffer
If the user buffer is not 8-byte aligned, it needs to use debounce
buffer for DMA transfer, and in this commit, we do below two
improvements:
- Copy back the request buffer when the transfer has completed
- Using Macro for default debounce buffer size

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 535e967839 MLK-18206-5 usb: cdns3: gadget: change maxburst as numbered buffered packet
This value is suggested by CDNS IC engineer.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen cb5d0e8878 MLK-18206-4 usb: cdns3: gadget: fix can't do usbtest for same EP twice
When using usbtest <--> f_sourcesink to do usb test, the current
code can't do test on same EP twice (eg EP1OUT), the DMA engine
can't restarted for the second test, the real reason is unknown.
The workaround for this problem is reset EP at .ep_enable, and
this operation is reasonable since we can reset EP at its
initialized state before using it. The fail cause for current
code like below:
./testusb -a -t 1
/* do it again */
./testusb -a -t 1

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 094e384895 MLK-18206-3 usb: cdns3: gadget: add dflush for both .dequeue and .ep_disable
There are may active transfers when we would like dequeue request
or disable endpoint, so it needs to flush the on-chip buffer before
dequeue software request.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 39dd5f3eae MLK-18206-2 usb: cdns3: gadget: change infinite wait as wait-timeout
Add API pair wait_reg_bit_set/clear to replace infinite wait code.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e0555bde83 MLK-18206-1 usb: cdns3: gadget: show error message when onchip memory is full
For Cadence USB3 device mode, the onchip buffer size is fixed
(eg: 18KB at this version), and the software needs to judge
if the onchip buffer is full when tries to configure endpoint.
For IN endpoint, each endpoint has its own onchip buffer;
For OUT endpoint, all endpoints share the same onchip buffer.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 976acc53d1 MLK-18200 usb: cdns3: gadget: fix can't wait configurated with USB2
With Linux PC USB2 connection, if L1 enable bit is set during the
initialization, the usbsts.cfgsts can't be 1 (device is in the
configured state) after setting usbconf.cfgset, move L1 enable
after USB configuration done can workaround this issue.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 1473536864 MLK-17631-7 usb: cdns3: gadget: clear stalled_flag at .ep_enable
When the EP is going to enable, it should not be stalled, and the
software flag needs to be updated. It fixes the mass_storage gadget
can't work after re-plug in.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 37e1a8b1f7 MLK-17631-6 usb: cdns3: gadget: disable U1 and U2 for reset state
When we receive the bus reset, according to CH 9.4.5, the U1
and U2 should be reset to disabled status.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2975d76929 MLK-17631-5 usb: cdns3: gadget: set selfpower flag for usb_gadget
Implement selfpower setting between USB gadget core and
controller driver

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 8be8d50782 MLK-17631-4 usb: cdns3: gadget: support LPM for USB 2.0
Superspeed device should support USB 2.0 LPM feature.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen bf9a985249 MLK-17631-3 usb: cdns3: gadget: fix NULL pointer deference issue for usbtest
When running usbtest case 9, it meets below oops, the reason for this
issue is the EP2-IN is not enabled, but the related interrupt for it
occurs, the structure usb_request for it is NULL. The software should
make sure there is no oops even the hardware triggers wrong interrupt.

[  476.636715]  gadget-cdns3: EP_STS: 00000804
[  476.636726] Unable to handle kernel NULL pointer dereference at virtual address 00000002
[  476.636729] pgd = ffff0000095f1000
[  476.636736] [00000002] *pgd=00000008bfffe003, *pud=00000008bfffd003, *pmd=0000000000000000
[  476.636741] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[  476.636750] Modules linked in: g_zero vivante ipv6
[  476.636757] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.9.88-04771-g7b3994b #1669
[  476.636759] Hardware name: Freescale i.MX8QXP MEK (DT)
[  476.636762] task: ffff0000093c0780 task.stack: ffff0000093b0000
[  476.636774] PC is at single_td_ep_dequeue+0x50/0x180
[  476.636780] LR is at cdns_irq_handler_thread+0x21c/0x6c0
[  476.636783] pc : [<ffff0000088b6aa8>] lr : [<ffff0000088b6214>] pstate: 600001c5
[  476.636785] sp : ffff80083ff40e40
[  476.636790] x29: ffff80083ff40e40 x28: ffff80083ae0c418
[  476.636795] x27: 0000000000040000 x26: 0000000000000804
[  476.636800] x25: ffff0000095624f8 x24: ffff80083b1047a0
[  476.636804] x23: ffff000009187718 x22: ffff0000095619b8
[  476.636809] x21: ffff80083b104000 x20: ffff80083ae0c418
[  476.636813] x19: 0000000000000000 x18: 0000000000000010
[  476.636818] x17: 0000ffff968c5e30 x16: ffff000008b14998
[  476.636823] x15: 0000000000000008 x14: 00000000fffffff0
[  476.636827] x13: ffff0000095a0068 x12: ffff0000093ce600
[  476.636832] x11: ffff0000093ce000 x10: ffff00000959d6d8
[  476.636837] x9 : 0000000000000001 x8 : ffff80083c8eb43f
[  476.636841] x7 : 0000000000000000 x6 : 000000000811c50d
[  476.636845] x5 : 00ffffffffffffff x4 : 0000000000000000
[  476.636850] x3 : 00000000000001c0 x2 : 0000000000000000
[  476.636854] x1 : 0000000000000000 x0 : ffff80083a607410
[  476.636855]
[  476.636859] Process swapper/0 (pid: 0, stack limit = 0xffff0000093b0020)
[  476.636862] Stack: (0xffff80083ff40e40 to 0xffff0000093b4000)
[  476.636864] Call trace:
[  476.636869] Exception stack(0xffff80083ff40c70 to 0xffff80083ff40da0)
[  476.636874] 0c60:                                   0000000000000000 0000ffffffffffff
[  476.636879] 0c80: ffff80083ff40e40 ffff0000088b6aa8 ffff80083ff40db0 ffff80083ff40db0
[  476.636885] 0ca0: ffff80083ff40d80 00000000ffffffd8 ffff80083bb17500 0000000000000000
[  476.636889] 0cc0: ffff8008344f6a00 0000000000000000 0000000000000000 0000000000000000
[  476.636895] 0ce0: ffff80083ff40cf0 ffff0000088f8b9c ffff80083ff40d20 ffff0000088f9270
[  476.636900] 0d00: ffff80083bb17500 0000000000000000 ffff80083a607410 0000000000000000
[  476.636905] 0d20: 0000000000000000 00000000000001c0 0000000000000000 00ffffffffffffff
[  476.636910] 0d40: 000000000811c50d 0000000000000000 ffff80083c8eb43f 0000000000000001
[  476.636916] 0d60: ffff00000959d6d8 ffff0000093ce000 ffff0000093ce600 ffff0000095a0068
[  476.636921] 0d80: 00000000fffffff0 0000000000000008 ffff000008b14998 0000ffff968c5e30
[  476.636927] [<ffff0000088b6aa8>] single_td_ep_dequeue+0x50/0x180
[  476.636932] [<ffff0000088b6214>] cdns_irq_handler_thread+0x21c/0x6c0
[  476.636937] [<ffff0000088b1f0c>] cdns3_irq+0x44/0x98
[  476.636945] [<ffff00000810b0cc>] __handle_irq_event_percpu+0x9c/0x128
[  476.636950] [<ffff00000810b174>] handle_irq_event_percpu+0x1c/0x58
[  476.636955] [<ffff00000810b1f8>] handle_irq_event+0x48/0x78
[  476.636961] [<ffff00000810eb90>] handle_fasteoi_irq+0xb8/0x1b0
[  476.636967] [<ffff00000810a1b4>] generic_handle_irq+0x24/0x38
[  476.636972] [<ffff00000810a81c>] __handle_domain_irq+0x5c/0xb8
[  476.636978] [<ffff00000808180c>] gic_handle_irq+0xbc/0x168
[  476.636981] Exception stack(0xffff0000093b3de0 to 0xffff0000093b3f10)
[  476.636987] 3de0: 0000000000000000 0000000000000000 0000000000000001 0000000000000000
[  476.636992] 3e00: 00000000000001c0 0100000000000000 00000000eb3aea81 ffff80083ff47b38
[  476.636998] 3e20: ffff0000093c1060 ffff0000093b0000 0000000000000880 000000001469197d
[  476.637003] 3e40: 0000000000000018 0000000059362c44 000c28cb00000000 0000554bf0000000
[  476.637008] 3e60: ffff000008b14998 0000ffff968c5e30 0000000000000000 ffff0000093b72e8
[  476.637013] 3e80: ffff0000093b7258 0000000000000001 0000000000000000 0000000000000000
[  476.637019] 3ea0: ffff0000093b0000 ffff00000936da60 ffff000009506fd4 ffff0000093b7000
[  476.637024] 3ec0: ffff0000093b7000 ffff0000093b3f10 ffff00000808599c ffff0000093b3f10
[  476.637029] 3ee0: ffff0000080859a0 0000000000000145 ffff000008116ec4 0000000040000145
[  476.637033] 3f00: ffffffffffffffff 7fffffffffffffff
[  476.637038] [<ffff000008082eec>] el1_irq+0xac/0x120
[  476.637043] [<ffff0000080859a0>] arch_cpu_idle+0x10/0x18
[  476.637050] [<ffff0000080ff478>] cpu_startup_entry+0x118/0x1d8
[  476.637058] [<ffff000008cd54a0>] rest_init+0x80/0x90
[  476.637067] [<ffff000009290b40>] start_kernel+0x378/0x38c
[  476.637072] [<ffff0000092901d8>] __primary_switched+0x5c/0x64
[  476.637078] Code: d1010273 f9401e82 aa1303e1 f943dea0 (39400842)
[  476.637088] ---[ end trace 21e06658d7988711 ]---
[  476.637091] Kernel panic - not syncing: Fatal exception in interrupt
[  476.637094] SMP: stopping secondary CPUs
[  476.643852] Kernel Offset: disabled
[  476.643854] Memory Limit: none
[  477.339728] ---[ end Kernel panic - not syncing: Fatal exception in interrupt

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 997ccf4804 MLK-17631-2 usb: cdns3: gadget: fix the bug the non-ep0 can't work after disconnection
We add endpoints to ep_match_list when adding gadget module, but
we delete the endpoints from the ep_match_list before set configuration.
When the re-enumeration after the new connection, the ep_match_list
is empty, in that case, the non-ep0s have not configurated, the
transfer on them will be failed.

In this commit, we only delete the endpoints from the list when we
remove the gadget module.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 42a115ca20 MLK-17631-1 usb: cdns3: gadget: fix deadlock during remove gadget module
For mass_storage gadget, when we remove the module after disconnection,
the request->complete at .ep_dequeue can't be executed, then the
wakeup_thread for certain endpoints is not called, the sleep_thread
will be dead lock.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen a2d8b03ffe MLK-17323 usb: cdns3: fix the kernel dump during the reboot stress test
During the reboot stress test, there may "nobody cared irq" for CDNS3,
the interrupts are occurred during the controller is entering low power
mode. In fact, we do no expect interrupt during this period, so disable
controller interrupt for it. With this patch, the kernel dump does
not occur again during reboot stress test.

[   18.460516] irq 44: nobody cared (try booting with the "irqpoll" option)
[   18.467222] CPU: 0 PID: 112 Comm: kworker/0:1 Not tainted 4.9.51-04150-ge84b58d-dirty #1198
[   18.475573] Hardware name: Freescale i.MX8QXP MEK (DT)
[   18.480720] Workqueue: pm pm_runtime_work
[   18.484739] Call trace:
[   18.487186] [<ffff0000080884e0>] dump_backtrace+0x0/0x1e0
[   18.492588] [<ffff0000080886d4>] show_stack+0x14/0x20
[   18.497644] [<ffff0000083e571c>] dump_stack+0x94/0xb8
[   18.502701] [<ffff0000081062c0>] __report_bad_irq+0x38/0xe8
[   18.508276] [<ffff000008106644>] note_interrupt+0x20c/0x2e0
[   18.513853] [<ffff00000810386c>] handle_irq_event_percpu+0x44/0x58
[   18.520038] [<ffff0000081038c8>] handle_irq_event+0x48/0x78
[   18.525608] [<ffff000008107260>] handle_fasteoi_irq+0xb8/0x1b0
[   18.531445] [<ffff000008102894>] generic_handle_irq+0x24/0x38
[   18.537187] [<ffff000008102f04>] __handle_domain_irq+0x5c/0xb8
[   18.543017] [<ffff00000808163c>] gic_handle_irq+0xbc/0x168
[   18.548506] Exception stack(0xffff80083ff4ae00 to 0xffff80083ff4af30)
[   18.554946] ae00: ffff80083ff4ae30 0001000000000000 ffff80083ff4af60 ffff0000080c1fec
[   18.562781] ae20: 0000000040000145 ffff80083a474000 0000000000000000 0000000000000000
[   18.570617] ae40: 00000000fffeecc3 ffff000008a2d368 00000000020c49ba 0000000000000020
[   18.578454] ae60: 000000000f78257c 7fffffffffffffff 0000000000000020 ffff80083a403f00
[   18.586290] ae80: ffff80083ff51ab0 ffff000008cb0b68 00000000000003ef 0000000000000000
[   18.594125] aea0: 0000000000000011 00000000000003ef 0000000000000019 0000000000000001
[   18.601962] aec0: 0000000000000007 ffff0000092f9000 ffff0000092f5b08 0000000000000000
[   18.609798] aee0: ffff000009501180 ffff80083a002a80 ffff80083a474000 00000000fffeecc2
[   18.617634] af00: ffff80083ff4b090 ffff000009336000 0000000000000002 ffff80083ff4af60
[   18.625469] af20: ffff0000080c243c ffff80083ff4af60
[   18.630343] [<ffff0000080827b0>] el1_irq+0xb0/0x124
[   18.635220] [<ffff0000080c243c>] irq_exit+0xac/0xf0
[   18.640099] [<ffff000008102f08>] __handle_domain_irq+0x60/0xb8
[   18.645928] [<ffff00000808163c>] gic_handle_irq+0xbc/0x168
[   18.651409] Exception stack(0xffff80083a477ad0 to 0xffff80083a477c00)

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2a234e670e MLK-17380-7 usb: cdns3: add platform TPL support
The TPL support is used to identify targeted devices during
EH2.0 and EH3.0 certification test.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen d9f4303aa4 MLK-17366-2 usb: cdns3: decrease autosuspend timeout
Cadence3 low power sequence doesn't allow too much time gap
between xhci bus suspend and controller suspend,
otherwise, the disconnection will be seen between them.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 16ff593e31 MLK-17366-1 usb: cdns3: improve USB PHY operation
Improve USB PHY operation, and keep 32K clock for RX detection
all the time, it can fix SS connection can't be recognition
from U3.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 81f2e8c85f MLK-17312-5 usb: cdns3: improve the role switch process
Current design tries to switch role no matter it is a dual-role device
or a single-role device. It produces extra switch process, and have an
error message at console when tries to start a non-exist role.

In this commit, we do below changes
- The role switch work queue is only for dual-role or peripheral-only
device.
- For peripheral-only device, we need to switch role to CDNS3_ROLE_END
since we need to close vbus and turn off clocks at this role when the
cable is disconnected from the host; And we do noop when the external
cable indicates we are host.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 3974104571 MLK-17312-4 usb: cdns3: gadget: fix the recognition issue when connection before load module
At imx8qm/imx8qxp A0 chip, there is a vbus toggle issue, so we need to
force the vbus as high before connection, otherwise, there will be endless
connect/disconnect interrupts for USB2 and causes enumeration failure.
The current work flow only cover this during the role switch, but omit
it when the connection has established at module probe routine.

This patch fixes it by moving force vbus operation to cdns_set_role to
cover both static and dynamic recognition issue.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen a66e78d8fc MLK-17312-3 usb: cdns3: gadget: configure all endpoints before set configuration
Cadence IP has one limitation that all endpoints must be configured
(Type & MaxPacketSize) before setting configuration through hardware
register, it means we can't change endpoints configuration after
set_configuration.

In this patch, we add non-control endpoint through usb_ss->ep_match_list,
which is added when the gadget driver uses usb_ep_autoconfig to configure
specific endpoint; When the udc driver receives set_configurion request,
it goes through usb_ss->ep_match_list, and configure all endpoints
accordingly.

At usb_ep_ops.enable/disable, we only enable and disable endpoint through
ep_cfg register which can be changed after set_configuration, and do
some software operation accordingly.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen b4a2ce43a4 MLK-17312-2 usb: cdns3: gadget: improve comments
Fix typos and some error comments

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen bb95435c1d MLK-17312-1 usb: cdns3: gadget: prepare setup packet buffer before receiving it
At current setup packet handling flow, the setup packet buffer
is only prepared after the controller receives the setup packet,
then stores it at its internal buffer, and trigger DESCMIS interrupt
(Transfer descriptor missing) to prepare TRB for it.

The shortcoming of this design is there is an extra DESCMIS interrupt,
and consume more time on enumeration process. As an improvement,
we parepare setup buffer beforehand, it is prepared at below situations:
- After bus reset has finished.
- For non-data stage setup transfers, prepare it before sending ACK for
status stage.
- For data stage setup transfers, prepare it after data stage but
before sending ACK for status stage.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 683f828fa1 MLK-17261-1 usb: cdns3: gadget: fix the spinlock recursion problem when detach cable
The __cdns3_gadget_stop holds spinlock before calling
usb_ss->gadget_driver->disconnect which calls ep_disable,
and ep_disable tries to hold spinlock too.

To fix it, let spinlock only protect the variable and register access.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 6e4a670135 MLK-17062 usb: cdns3: gadget: add test mode support for USB2
Add USB2 device test mode support for CDNS3 IP

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 44a5052dc7 MLK-16976-4 usb: cdns3: add power management support
This patch set adds both runtime and system-level pm support.
For runtime-pm: both host and device wakeup events are supported.
For system-pm: only host wakeup events are supported, device wakeup
events are from other peripherals, and will support later.

BuildInfo:
- SCFW 245582b, IMX-MKIMAGE 0ad6069a, ATF 6bd98a3
- U-Boot 2017.03-imx_v2017.03+gfa65b0a

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f93edd0f08 MLK-16735 usb: host: add XHCI_CDNS_HOST flag
The NXP Cadence XHCI host has the same issue with Intel's,
it is triggered by reboot test, the test case is described
at this jira ticket.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 157f65cd5a MLK-16682 usb: cdns3: gadget: delete useless is_iso_flag
Since the runtime endpoint type is decided by device descriptors,
we delete useless is_iso_flag which is decided during the initialization.
It also fixed a bug the max_packet_size is determined wrongly for
high/full speed connection.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f78429aa5b MLK-16727-3 usb: cdns3: force vbus status accordingly
Since the controller doesn't know vbus status well due to IC limitation,
it needs to force vbus status for controller when the connection and
disconnection occur.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 13a9557db0 MLK-16727-1 usb: cdns3: needs to handle disconnection at device mode
The IP has some issues to detect vbus status correctly, we have to
force vbus status accordingly, so we need a status to indicate
vbus disconnection, and add some code to let control know vbus
removal, in that case, the controller's state mechine can be correct.

In this commit, we increase one role 'CDNS3_ROLE_END' to for
this status.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 6a2e287a6d MLK-16522-3 usb: cdns3: do not disable interrupt during role switch
After "MLK-16522-1 usb: cdns3: change cdns3_role_start work flow", the
software maintained role is current role which is doing role_start, so
it should handle its initialization routine well, just like we only has
one role and the interrupt is enabled at that time.

And disable interrupt causes one timeout problem during remove hcd, the
last command takes about 5 seconds to finish. See below for detail:

[   84.894639]  xhci-cdns3: remove, state 1
[   84.898768]  xhci-cdns3: roothub graceful disconnect
[   84.898784] usb usb2: USB disconnect, device number 1
[   84.904052] usb 2-1: USB disconnect, device number 4
[   84.909195] usb 2-1: unregistering device
[   84.909204] usb 2-1: unregistering interface 2-1:1.0
[   84.931247] usb 2-1: usb_disable_device nuking all URBs
[   84.931264]  xhci-cdns3: xhci_drop_endpoint called for udev ffff80083b755000
[   84.931274]  xhci-cdns3: drop ep 0x81, slot id 3, new drop flags = 0x8, new add flags = 0x0
[   84.931278]  xhci-cdns3: xhci_drop_endpoint called for udev ffff80083b755000
[   84.931283]  xhci-cdns3: drop ep 0x2, slot id 3, new drop flags = 0x18, new add flags = 0x0
[   84.931288]  xhci-cdns3: xhci_check_bandwidth called for udev ffff80083b755000
[   84.931302]  xhci-cdns3: New Input Control Context:
[   84.931309]  xhci-cdns3: @ffff000009aa7000 (virt) @d8288000 (dma) 0x000018 - drop flags
[   84.931314]  xhci-cdns3: @ffff000009aa7004 (virt) @d8288004 (dma) 0x000001 - add flags
[   84.931320]  xhci-cdns3: @ffff000009aa7008 (virt) @d8288008 (dma) 0x000000 - rsvd2[0]
[   84.931325]  xhci-cdns3: @ffff000009aa700c (virt) @d828800c (dma) 0x000000 - rsvd2[1]
[   84.931331]  xhci-cdns3: @ffff000009aa7010 (virt) @d8288010 (dma) 0x000000 - rsvd2[2]
[   84.931336]  xhci-cdns3: @ffff000009aa7014 (virt) @d8288014 (dma) 0x000000 - rsvd2[3]
[   84.931341]  xhci-cdns3: @ffff000009aa7018 (virt) @d8288018 (dma) 0x000000 - rsvd2[4]
[   84.931346]  xhci-cdns3: @ffff000009aa701c (virt) @d828801c (dma) 0x000000 - rsvd2[5]
[   84.931350]  xhci-cdns3: Slot Context:
[   84.931355]  xhci-cdns3: @ffff000009aa7020 (virt) @d8288020 (dma) 0x8400000 - dev_info
[   84.931360]  xhci-cdns3: @ffff000009aa7024 (virt) @d8288024 (dma) 0x020000 - dev_info2
[   84.931365]  xhci-cdns3: @ffff000009aa7028 (virt) @d8288028 (dma) 0x000000 - tt_info
[   84.931371]  xhci-cdns3: @ffff000009aa702c (virt) @d828802c (dma) 0x000000 - dev_state
[   84.931377]  xhci-cdns3: @ffff000009aa7030 (virt) @d8288030 (dma) 0x000000 - rsvd[0]
[   84.931382]  xhci-cdns3: @ffff000009aa7034 (virt) @d8288034 (dma) 0x000000 - rsvd[1]
[   84.931387]  xhci-cdns3: @ffff000009aa7038 (virt) @d8288038 (dma) 0x000000 - rsvd[2]
[   84.931392]  xhci-cdns3: @ffff000009aa703c (virt) @d828803c (dma) 0x000000 - rsvd[3]
[   84.931398]  xhci-cdns3: IN Endpoint 00 Context (ep_index 00):
[   84.931403]  xhci-cdns3: @ffff000009aa7040 (virt) @d8288040 (dma) 0x000000 - ep_info
[   84.931408]  xhci-cdns3: @ffff000009aa7044 (virt) @d8288044 (dma) 0x2000026 - ep_info2
[   84.931414]  xhci-cdns3: @ffff000009aa7048 (virt) @d8288048 (dma) 0xd828f001 - deq
[   84.931419]  xhci-cdns3: @ffff000009aa7050 (virt) @d8288050 (dma) 0x000000 - tx_info
[   84.931424]  xhci-cdns3: @ffff000009aa7054 (virt) @d8288054 (dma) 0x000000 - rsvd[0]
[   84.931429]  xhci-cdns3: @ffff000009aa7058 (virt) @d8288058 (dma) 0x000000 - rsvd[1]
[   84.931434]  xhci-cdns3: @ffff000009aa705c (virt) @d828805c (dma) 0x000000 - rsvd[2]
[   84.931447]  xhci-cdns3: // Ding dong!
[   85.096180] FAT-fs (sda1): FAT read failed (blocknr 32)
[   90.134581]  xhci-cdns3: Command timeout
[   90.134590]  xhci-cdns3: Abort command ring
[   92.150582]  xhci-cdns3: No stop event for abort, ring start fail?
[   92.150606]  xhci-cdns3: Timeout while waiting for configure endpoint command
[   92.158310] usb usb2: unregistering device
[   92.158321] usb usb2: unregistering interface 2-0:1.0
[   92.158447]  xhci-cdns3: shutdown urb ffff80083b8f0700 ep1in-intr
[   92.158704] usb usb2: usb_disable_device nuking all URBs
[   92.158715] xHCI xhci_drop_endpoint called for root hub
[   92.158719] xHCI xhci_check_bandwidth called for root hub
[   92.159067]  xhci-cdns3: // Halt the HC
[   92.159075]  xhci-cdns3: // Reset the HC
[   92.159096]  xhci-cdns3: Wait for controller to be ready for doorbell rings
[   92.159102]  xhci-cdns3: USB bus 2 deregistered
[   92.163789]  xhci-cdns3: remove, state 4
[   92.167772]  xhci-cdns3: roothub graceful disconnect
[   92.167786] usb usb1: USB disconnect, device number 1
[   92.172880] usb usb1: unregistering device
[   92.172894] usb usb1: unregistering interface 1-0:1.0
[   92.173151] usb usb1: usb_disable_device nuking all URBs

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 29ca6d5bec MLK-16522-2 usb: cdns3: host: change remove sequence for hcd
At probe, the main hcd is added first, then shared_hcd is added later,
so when we tries to remove hcds, the shared_hcd needs to remove first.

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00