Merge 5.17-rc6 into usb-next
[platform/kernel/linux-starfive.git] / drivers / usb / host / xhci.c
index 2d37854..a1c781f 100644 (file)
@@ -695,7 +695,7 @@ int xhci_run(struct usb_hcd *hcd)
        xhci_dbg_trace(xhci, trace_xhci_dbg_init,
                        "Finished xhci_run for USB2 roothub");
 
-       xhci_dbc_init(xhci);
+       xhci_create_dbc_dev(xhci);
 
        xhci_debugfs_init(xhci);
 
@@ -725,7 +725,7 @@ static void xhci_stop(struct usb_hcd *hcd)
                return;
        }
 
-       xhci_dbc_exit(xhci);
+       xhci_remove_dbc_dev(xhci);
 
        spin_lock_irq(&xhci->lock);
        xhci->xhc_state |= XHCI_STATE_HALTED;
@@ -3160,8 +3160,6 @@ rescan:
 
        ep_index = xhci_get_endpoint_index(&host_ep->desc);
        ep = &vdev->eps[ep_index];
-       if (!ep)
-               goto done;
 
        /* wait for hub_tt_work to finish clearing hub TT */
        if (ep->ep_state & EP_CLEARING_TT) {
@@ -3219,8 +3217,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
                return;
        ep_index = xhci_get_endpoint_index(&host_ep->desc);
        ep = &vdev->eps[ep_index];
-       if (!ep)
-               return;
 
        /* Bail out if toggle is already being cleared by a endpoint reset */
        spin_lock_irqsave(&xhci->lock, flags);
@@ -4354,6 +4350,10 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
        unsigned long flags;
        int ret;
 
+       command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL);
+       if (!command)
+               return -ENOMEM;
+
        spin_lock_irqsave(&xhci->lock, flags);
 
        virt_dev = xhci->devs[udev->slot_id];
@@ -4370,10 +4370,10 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
        }
 
        /* Attempt to issue an Evaluate Context command to change the MEL. */
-       command = xhci->lpm_command;
        ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx);
        if (!ctrl_ctx) {
                spin_unlock_irqrestore(&xhci->lock, flags);
+               xhci_free_command(xhci, command);
                xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
                                __func__);
                return -ENOMEM;
@@ -4400,6 +4400,9 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
                virt_dev->current_mel = max_exit_latency;
                spin_unlock_irqrestore(&xhci->lock, flags);
        }
+
+       xhci_free_command(xhci, command);
+
        return ret;
 }
 
@@ -4520,18 +4523,8 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
                        exit_latency = xhci_besl_encoding[hird];
                        spin_unlock_irqrestore(&xhci->lock, flags);
 
-                       /* USB 3.0 code dedicate one xhci->lpm_command->in_ctx
-                        * input context for link powermanagement evaluate
-                        * context commands. It is protected by hcd->bandwidth
-                        * mutex and is shared by all devices. We need to set
-                        * the max ext latency in USB 2 BESL LPM as well, so
-                        * use the same mutex and xhci_change_max_exit_latency()
-                        */
-                       mutex_lock(hcd->bandwidth_mutex);
                        ret = xhci_change_max_exit_latency(xhci, udev,
                                                           exit_latency);
-                       mutex_unlock(hcd->bandwidth_mutex);
-
                        if (ret < 0)
                                return ret;
                        spin_lock_irqsave(&xhci->lock, flags);
@@ -4559,9 +4552,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
                readl(pm_addr);
                if (udev->usb2_hw_lpm_besl_capable) {
                        spin_unlock_irqrestore(&xhci->lock, flags);
-                       mutex_lock(hcd->bandwidth_mutex);
                        xhci_change_max_exit_latency(xhci, udev, 0);
-                       mutex_unlock(hcd->bandwidth_mutex);
                        readl_poll_timeout(ports[port_num]->addr, pm_val,
                                           (pm_val & PORT_PLS_MASK) == XDEV_U0,
                                           100, 10000);
@@ -5505,6 +5496,7 @@ static int __init xhci_hcd_init(void)
                return -ENODEV;
 
        xhci_debugfs_create_root();
+       xhci_dbc_init();
 
        return 0;
 }
@@ -5516,6 +5508,7 @@ static int __init xhci_hcd_init(void)
 static void __exit xhci_hcd_fini(void)
 {
        xhci_debugfs_remove_root();
+       xhci_dbc_exit();
 }
 
 module_init(xhci_hcd_init);