.. | .. |
---|
180 | 180 | list_del(&req->list); |
---|
181 | 181 | req->remaining = 0; |
---|
182 | 182 | req->needs_extra_trb = false; |
---|
| 183 | + req->num_trbs = 0; |
---|
183 | 184 | |
---|
184 | 185 | if (req->request.status == -EINPROGRESS) |
---|
185 | 186 | req->request.status = status; |
---|
.. | .. |
---|
1823 | 1824 | */ |
---|
1824 | 1825 | static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt) |
---|
1825 | 1826 | { |
---|
| 1827 | + struct dwc3 *dwc = dep->dwc; |
---|
1826 | 1828 | struct dwc3_gadget_ep_cmd_params params; |
---|
1827 | 1829 | u32 cmd; |
---|
1828 | 1830 | int ret; |
---|
.. | .. |
---|
1846 | 1848 | WARN_ON_ONCE(ret); |
---|
1847 | 1849 | dep->resource_index = 0; |
---|
1848 | 1850 | |
---|
1849 | | - if (!interrupt) |
---|
| 1851 | + if (!interrupt) { |
---|
| 1852 | + if (!DWC3_IP_IS(DWC3) || DWC3_VER_IS_PRIOR(DWC3, 310A)) |
---|
| 1853 | + mdelay(1); |
---|
1850 | 1854 | dep->flags &= ~DWC3_EP_TRANSFER_STARTED; |
---|
1851 | | - else |
---|
| 1855 | + } else { |
---|
1852 | 1856 | dep->flags |= DWC3_EP_END_TRANSFER_PENDING; |
---|
| 1857 | + } |
---|
1853 | 1858 | |
---|
| 1859 | + dep->flags &= ~DWC3_EP_DELAY_STOP; |
---|
1854 | 1860 | return ret; |
---|
1855 | 1861 | } |
---|
1856 | 1862 | |
---|
.. | .. |
---|
2656 | 2662 | static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) |
---|
2657 | 2663 | { |
---|
2658 | 2664 | unsigned long flags; |
---|
| 2665 | + int ret; |
---|
2659 | 2666 | |
---|
2660 | 2667 | spin_lock_irqsave(&dwc->lock, flags); |
---|
2661 | 2668 | dwc->connected = false; |
---|
2662 | 2669 | |
---|
2663 | 2670 | /* |
---|
2664 | | - * Per databook, when we want to stop the gadget, if a control transfer |
---|
2665 | | - * is still in process, complete it and get the core into setup phase. |
---|
| 2671 | + * Attempt to end pending SETUP status phase, and not wait for the |
---|
| 2672 | + * function to do so. |
---|
2666 | 2673 | */ |
---|
2667 | | - if (dwc->ep0state != EP0_SETUP_PHASE && |
---|
2668 | | - dwc->ep0state != EP0_UNCONNECTED) { |
---|
2669 | | - int ret; |
---|
2670 | | - |
---|
2671 | | - if (dwc->delayed_status) |
---|
2672 | | - dwc3_ep0_send_delayed_status(dwc); |
---|
2673 | | - |
---|
2674 | | - reinit_completion(&dwc->ep0_in_setup); |
---|
2675 | | - |
---|
2676 | | - spin_unlock_irqrestore(&dwc->lock, flags); |
---|
2677 | | - ret = wait_for_completion_timeout(&dwc->ep0_in_setup, |
---|
2678 | | - msecs_to_jiffies(DWC3_PULL_UP_TIMEOUT)); |
---|
2679 | | - spin_lock_irqsave(&dwc->lock, flags); |
---|
2680 | | - if (ret == 0) |
---|
2681 | | - dev_warn(dwc->dev, "timed out waiting for SETUP phase\n"); |
---|
2682 | | - } |
---|
| 2674 | + if (dwc->delayed_status) |
---|
| 2675 | + dwc3_ep0_send_delayed_status(dwc); |
---|
2683 | 2676 | |
---|
2684 | 2677 | /* |
---|
2685 | 2678 | * In the Synopsys DesignWare Cores USB3 Databook Rev. 3.30a |
---|
.. | .. |
---|
2689 | 2682 | * bit. |
---|
2690 | 2683 | */ |
---|
2691 | 2684 | dwc3_stop_active_transfers(dwc); |
---|
2692 | | - __dwc3_gadget_stop(dwc); |
---|
2693 | 2685 | spin_unlock_irqrestore(&dwc->lock, flags); |
---|
| 2686 | + |
---|
| 2687 | + /* |
---|
| 2688 | + * Per databook, when we want to stop the gadget, if a control transfer |
---|
| 2689 | + * is still in process, complete it and get the core into setup phase. |
---|
| 2690 | + * In case the host is unresponsive to a SETUP transaction, forcefully |
---|
| 2691 | + * stall the transfer, and move back to the SETUP phase, so that any |
---|
| 2692 | + * pending endxfers can be executed. |
---|
| 2693 | + */ |
---|
| 2694 | + if (dwc->ep0state != EP0_SETUP_PHASE && |
---|
| 2695 | + dwc->ep0state != EP0_UNCONNECTED) { |
---|
| 2696 | + reinit_completion(&dwc->ep0_in_setup); |
---|
| 2697 | + |
---|
| 2698 | + ret = wait_for_completion_timeout(&dwc->ep0_in_setup, |
---|
| 2699 | + msecs_to_jiffies(DWC3_PULL_UP_TIMEOUT)); |
---|
| 2700 | + if (ret == 0) { |
---|
| 2701 | + unsigned int dir; |
---|
| 2702 | + |
---|
| 2703 | + dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); |
---|
| 2704 | + spin_lock_irqsave(&dwc->lock, flags); |
---|
| 2705 | + dir = !!dwc->ep0_expect_in; |
---|
| 2706 | + if (dwc->ep0state == EP0_DATA_PHASE) |
---|
| 2707 | + dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); |
---|
| 2708 | + else |
---|
| 2709 | + dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); |
---|
| 2710 | + dwc3_ep0_stall_and_restart(dwc); |
---|
| 2711 | + spin_unlock_irqrestore(&dwc->lock, flags); |
---|
| 2712 | + } |
---|
| 2713 | + } |
---|
2694 | 2714 | |
---|
2695 | 2715 | /* |
---|
2696 | 2716 | * Note: if the GEVNTCOUNT indicates events in the event buffer, the |
---|
.. | .. |
---|
2699 | 2719 | * remaining event generated by the controller while polling for |
---|
2700 | 2720 | * DSTS.DEVCTLHLT. |
---|
2701 | 2721 | */ |
---|
2702 | | - return dwc3_gadget_run_stop(dwc, false, false); |
---|
| 2722 | + ret = dwc3_gadget_run_stop(dwc, false, false); |
---|
| 2723 | + |
---|
| 2724 | + /* |
---|
| 2725 | + * Stop the gadget after controller is halted, so that if needed, the |
---|
| 2726 | + * events to update EP0 state can still occur while the run/stop |
---|
| 2727 | + * routine polls for the halted state. DEVTEN is cleared as part of |
---|
| 2728 | + * gadget stop. |
---|
| 2729 | + */ |
---|
| 2730 | + spin_lock_irqsave(&dwc->lock, flags); |
---|
| 2731 | + __dwc3_gadget_stop(dwc); |
---|
| 2732 | + spin_unlock_irqrestore(&dwc->lock, flags); |
---|
| 2733 | + |
---|
| 2734 | + return ret; |
---|
2703 | 2735 | } |
---|
2704 | 2736 | |
---|
2705 | 2737 | static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) |
---|
.. | .. |
---|
2731 | 2763 | ret = pm_runtime_get_sync(dwc->dev); |
---|
2732 | 2764 | if (!ret || ret < 0) { |
---|
2733 | 2765 | pm_runtime_put(dwc->dev); |
---|
2734 | | - return 0; |
---|
| 2766 | + if (ret < 0) |
---|
| 2767 | + pm_runtime_set_suspended(dwc->dev); |
---|
| 2768 | + return ret; |
---|
2735 | 2769 | } |
---|
2736 | 2770 | |
---|
2737 | 2771 | if (dwc->pullups_connected == is_on) { |
---|
.. | .. |
---|
2750 | 2784 | * device-initiated disconnect requires a core soft reset |
---|
2751 | 2785 | * (DCTL.CSftRst) before enabling the run/stop bit. |
---|
2752 | 2786 | */ |
---|
2753 | | - dwc3_core_soft_reset(dwc); |
---|
| 2787 | + ret = dwc3_core_soft_reset(dwc); |
---|
| 2788 | + if (ret) |
---|
| 2789 | + goto done; |
---|
2754 | 2790 | |
---|
2755 | 2791 | dwc3_event_buffers_setup(dwc); |
---|
2756 | 2792 | __dwc3_gadget_start(dwc); |
---|
2757 | 2793 | ret = dwc3_gadget_run_stop(dwc, true, false); |
---|
2758 | 2794 | } |
---|
2759 | 2795 | |
---|
| 2796 | +done: |
---|
2760 | 2797 | pm_runtime_put(dwc->dev); |
---|
2761 | 2798 | |
---|
2762 | 2799 | return ret; |
---|
.. | .. |
---|
3960 | 3997 | if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) |
---|
3961 | 3998 | return; |
---|
3962 | 3999 | |
---|
| 4000 | + if (interrupt && (dep->flags & DWC3_EP_DELAY_STOP)) |
---|
| 4001 | + return; |
---|
| 4002 | + |
---|
3963 | 4003 | if (!(dep->flags & DWC3_EP_TRANSFER_STARTED) || |
---|
3964 | | - (dep->flags & DWC3_EP_DELAY_STOP) || |
---|
3965 | 4004 | (dep->flags & DWC3_EP_END_TRANSFER_PENDING)) |
---|
3966 | 4005 | return; |
---|
3967 | 4006 | |
---|
.. | .. |
---|
4001 | 4040 | * enabled, the EndTransfer command will have completed upon |
---|
4002 | 4041 | * returning from this function. |
---|
4003 | 4042 | * |
---|
4004 | | - * This mode is NOT available on the DWC_usb31 IP. |
---|
| 4043 | + * This mode is NOT available on the DWC_usb31 IP. In this |
---|
| 4044 | + * case, if the IOC bit is not set, then delay by 1ms |
---|
| 4045 | + * after issuing the EndTransfer command. This allows for the |
---|
| 4046 | + * controller to handle the command completely before DWC3 |
---|
| 4047 | + * remove requests attempts to unmap USB request buffers. |
---|
4005 | 4048 | */ |
---|
4006 | 4049 | |
---|
4007 | 4050 | __dwc3_stop_active_transfer(dep, force, interrupt); |
---|
.. | .. |
---|
4475 | 4518 | break; |
---|
4476 | 4519 | case DWC3_DEVICE_EVENT_SUSPEND: |
---|
4477 | 4520 | /* It changed to be suspend event for version 2.30a and above */ |
---|
4478 | | - if (!DWC3_VER_IS_PRIOR(DWC3, 230A)) { |
---|
4479 | | - /* |
---|
4480 | | - * Ignore suspend event until the gadget enters into |
---|
4481 | | - * USB_STATE_CONFIGURED state. |
---|
4482 | | - */ |
---|
4483 | | - if (dwc->gadget->state >= USB_STATE_CONFIGURED) |
---|
4484 | | - dwc3_gadget_suspend_interrupt(dwc, |
---|
4485 | | - event->event_info); |
---|
4486 | | - } |
---|
| 4521 | + if (!DWC3_VER_IS_PRIOR(DWC3, 230A)) |
---|
| 4522 | + dwc3_gadget_suspend_interrupt(dwc, event->event_info); |
---|
4487 | 4523 | break; |
---|
4488 | 4524 | case DWC3_DEVICE_EVENT_SOF: |
---|
4489 | 4525 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: |
---|
.. | .. |
---|
4580 | 4616 | u32 count; |
---|
4581 | 4617 | |
---|
4582 | 4618 | if (pm_runtime_suspended(dwc->dev)) { |
---|
| 4619 | + dwc->pending_events = true; |
---|
| 4620 | + /* |
---|
| 4621 | + * Trigger runtime resume. The get() function will be balanced |
---|
| 4622 | + * after processing the pending events in dwc3_process_pending |
---|
| 4623 | + * events(). |
---|
| 4624 | + */ |
---|
4583 | 4625 | pm_runtime_get(dwc->dev); |
---|
4584 | 4626 | disable_irq_nosync(dwc->irq_gadget); |
---|
4585 | | - dwc->pending_events = true; |
---|
4586 | 4627 | return IRQ_HANDLED; |
---|
4587 | 4628 | } |
---|
4588 | 4629 | |
---|
.. | .. |
---|
4851 | 4892 | { |
---|
4852 | 4893 | if (dwc->pending_events) { |
---|
4853 | 4894 | dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); |
---|
| 4895 | + dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf); |
---|
| 4896 | + pm_runtime_put(dwc->dev); |
---|
4854 | 4897 | dwc->pending_events = false; |
---|
4855 | 4898 | enable_irq(dwc->irq_gadget); |
---|
4856 | 4899 | } |
---|