Commit f9e609b8 authored by Guoqing Zhang's avatar Guoqing Zhang Committed by Greg Kroah-Hartman

usb: xhci: Add helper function xhci_disable_slot().

Refactoring slot disable related code into a helper
function xhci_disable_slot() which can be used when
enabling test mode.
Signed-off-by: default avatarGuoqing Zhang <guoqing.zhang@intel.com>
Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a6ff6cbf
...@@ -3561,8 +3561,6 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3561,8 +3561,6 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
{ {
struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_virt_device *virt_dev; struct xhci_virt_device *virt_dev;
unsigned long flags;
u32 state;
int i, ret; int i, ret;
struct xhci_command *command; struct xhci_command *command;
...@@ -3597,30 +3595,50 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3597,30 +3595,50 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
} }
xhci_disable_slot(xhci, command, udev->slot_id);
/*
* Event command completion handler will free any data structures
* associated with the slot. XXX Can free sleep?
*/
}
int xhci_disable_slot(struct xhci_hcd *xhci, struct xhci_command *command,
u32 slot_id)
{
unsigned long flags;
u32 state;
int ret = 0;
struct xhci_virt_device *virt_dev;
virt_dev = xhci->devs[slot_id];
if (!virt_dev)
return -EINVAL;
if (!command)
command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
if (!command)
return -ENOMEM;
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
/* Don't disable the slot if the host controller is dead. */ /* Don't disable the slot if the host controller is dead. */
state = readl(&xhci->op_regs->status); state = readl(&xhci->op_regs->status);
if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
(xhci->xhc_state & XHCI_STATE_HALTED)) { (xhci->xhc_state & XHCI_STATE_HALTED)) {
xhci_free_virt_device(xhci, udev->slot_id); xhci_free_virt_device(xhci, slot_id);
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
kfree(command); kfree(command);
return; return ret;
} }
if (xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
udev->slot_id)) { slot_id);
if (ret) {
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
return; return ret;
} }
xhci_ring_cmd_db(xhci); xhci_ring_cmd_db(xhci);
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
return ret;
/*
* Event command completion handler will free any data structures
* associated with the slot. XXX Can free sleep?
*/
} }
/* /*
...@@ -3727,15 +3745,10 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3727,15 +3745,10 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
disable_slot: disable_slot:
/* Disable slot, if we can do it without mem alloc */ /* Disable slot, if we can do it without mem alloc */
spin_lock_irqsave(&xhci->lock, flags);
kfree(command->completion); kfree(command->completion);
command->completion = NULL; command->completion = NULL;
command->status = 0; command->status = 0;
if (!xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, return xhci_disable_slot(xhci, command, udev->slot_id);
udev->slot_id))
xhci_ring_cmd_db(xhci);
spin_unlock_irqrestore(&xhci->lock, flags);
return 0;
} }
/* /*
......
...@@ -2018,6 +2018,8 @@ void xhci_shutdown(struct usb_hcd *hcd); ...@@ -2018,6 +2018,8 @@ void xhci_shutdown(struct usb_hcd *hcd);
int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
void xhci_init_driver(struct hc_driver *drv, void xhci_init_driver(struct hc_driver *drv,
const struct xhci_driver_overrides *over); const struct xhci_driver_overrides *over);
int xhci_disable_slot(struct xhci_hcd *xhci,
struct xhci_command *command, u32 slot_id);
#ifdef CONFIG_PM #ifdef CONFIG_PM
int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup); int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment