xhci: re-work command queue management
Subsystems (2)
v5 cover xhci: re-work command queue management
changes since v4:
Handle command timeouts on a stopped command ring properly. A stopped ring can't be aborted and send "command ring stopped" events, if ring was stopped at command timeout call the command ring stopped handler manually.
changes since v3:
* Use GFP_ATOMIC in xhci_stop_device() because we hold a spinlock
* Don't queue commands if host is dying.
* Flush command queue when host is dying (delete all commands in queue, call pending completions/free commands).
changes since v2:
squash first 7 patches together that all just created commands and avoid some nasty mid-patch series memory leaking
changes since v1:
Fixing smatch warnings and errors.
Check for null return from alloc_command, release lock in error path and don't dereference possible null pointer in error path.
release lock in xhci_stop_dev() error path.
This is the fourth attempt to re-work and solve the issues in xhci command queue management that Sarah has described earlier:
Right now, the command management in the xHCI driver is rather ad-hock. Different parts of the driver all submit commands, including interrupt handling routines, functions called from the USB core (with or without the bus bandwidth mutex held).
Some times they need to wait for the command to complete, and sometimes they just issue the command and don't care about the result of the command.
The places that wait on a command all time the command for five seconds, and then attempt to cancel the command.
Unfortunately, that means if several commands are issued at once, and one of them times out, all the commands timeout, even though the host hasn't gotten a chance to service them yet.
This is apparent with some devices that take a long time to respond to the Set Address command during device enumeration (when the device is plugged in). If a driver for a different device attempts to change alternate interface settings at the same time (causing a Configure Endpoint command to be issued), both commands timeout.
Instead of having each command timeout after five seconds, the driver should wait indefinitely in an uninterruptible sleep on the command completion. A global command queue manager should time whatever command is currently running, and cancel that command after five seconds.
If the commands were in a list, like TDs currently are, it may be easier to keep track of where the command ring dequeue pointer is, and avoid racing with events. We may need to have parts of the driver that issue commands without waiting on them still put the commands in the command list.
The Implementation:
-------------------
First step is to create a list of the commands submitted to the command queue. To accomplish this each command is required to be submitted with a properly filled command structure containing completion, status variable and a pointer to the command TRB that will be used.
The first patch is all about creating these command structures and submitting them when we queue commands.
The command structures are allocated on the fly, the commands that are submitted in interrupt context are allocated with GFP_ATOMIC.
Next, the global command queue is introduced. Commands structures are added to the queue when trb's are queued, and removed when the command completes. Also switch to use the status variable and completion in the command struct.
A new timer handles command timeout, the timer is kicked every time when a command finishes and there's a new command waiting in the queue, or when a new command is submitted to an _empty_ command queue.
Timer is deleted when the the last command on the queue finishes (empty queue)
The old cancel_cmd_list is removed.
When the timer expires we simply tag the current command as "ABORTED" and start the ring abortion process. Functions waiting for an aborted command to finish are called after the command abortion is completed.
Mathias Nyman (4):
xhci: Use command structures when queuing commands on the command ring
xhci: Add a global command queue
xhci: Use completion and status in global command queue
xhci: rework command timeout and cancellation,
drivers/usb/host/xhci-hub.c | 43 ++-- drivers/usb/host/xhci-mem.c | 17 +- drivers/usb/host/xhci-ring.c | 586 ++++++++++++++++--------------------------- drivers/usb/host/xhci.c | 264 ++++++++++--------- drivers/usb/host/xhci.h | 44 ++-- 5 files changed, 414 insertions(+), 540 deletions(-)
Signature · 1 line
1.8.3.2
RFC v5 1/4 xhci: Use command structures when queuing commands on the command ring
To create a global command queue we require that each command put on the command ring is submitted with a command structure.
Functions that queue commands and wait for completion need to allocate a command before submitting it, and free it once completed. The following command queuing functions need to be modified.
xhci_configure_endpoint()xhci_address_device()xhci_queue_slot_control()xhci_queue_stop_endpoint()xhci_queue_new_dequeue_state()xhci_queue_reset_ep()xhci_configure_endpoint()
xhci_configure_endpoint() could already be called with a command structure, and only xhci_check_maxpacket and xhci_check_bandwidth did not do so. These are changed and a command structure is now required. This change also simplifies the configure endpoint command completion handling and the "goto bandwidth_change" handling code can be removed.
In some cases the command queuing function is called in interrupt context. These commands needs to be allocated atomically, and they can't wait for completion. These commands will in this patch be freed directly after queuing, but freeing will be moved to the command completion event handler in a later patch once we get the global command queue up.(Just so that we won't leak memory in the middle of the patch set)
--- drivers/usb/host/xhci-hub.c | 21 +++-- drivers/usb/host/xhci-ring.c | 106 ++++++++++++----------- drivers/usb/host/xhci.c | 194 ++++++++++++++++++++++++++++--------------- drivers/usb/host/xhci.h | 31 +++---- 4 files changed, 215 insertions(+), 137 deletions(-)
drivers/usb/host/xhci-hub.c +16 -5
@@ -20,7 +20,8 @@* Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/gfp.h> + +#include <linux/slab.h> #include <asm/unaligned.h> #include "xhci.h"
@@ -284,12 +285,22 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)spin_lock_irqsave (&xhci->lock, flags);for (i =LAST_EP_INDEX ; i >0 ; i--) { -if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) -xhci_queue_stop_endpoint (xhci, slot_id, i, suspend); +if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { +struct xhci_command *command; + command =xhci_alloc_command (xhci, false, false, +GFP_NOIO ); +if (!command) { +spin_unlock_irqrestore (&xhci->lock, flags); +xhci_free_command (xhci, cmd); +return -ENOMEM ; + + } +xhci_queue_stop_endpoint (xhci, command, slot_id, i, + suspend); + } } - cmd->command_trb =xhci_find_next_enqueue (xhci->cmd_ring);list_add_tail (&cmd->cmd_list, &virt_dev->cmd_list); -xhci_queue_stop_endpoint (xhci, slot_id,0 , suspend); +xhci_queue_stop_endpoint (xhci, cmd, slot_id,0 , suspend);xhci_ring_cmd_db (xhci);spin_unlock_irqrestore (&xhci->lock, flags);
drivers/usb/host/xhci-ring.c +56 -50
252 lines not on this page · raw message
drivers/usb/host/xhci.c +126 -68
489 lines not on this page · raw message
drivers/usb/host/xhci.h +17 -14
@@ -1810,13 +1810,14 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, dma_addr_t suspect_dma);int xhci_is_vendor_info_code (struct xhci_hcd *xhci,unsigned int trb_comp_code);void xhci_ring_cmd_db (struct xhci_hcd *xhci); -int xhci_queue_slot_control (struct xhci_hcd *xhci,u32 trb_type,u32 slot_id); -int xhci_queue_address_device (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,enum xhci_setup_dev ); -int xhci_queue_vendor_command (struct xhci_hcd *xhci, +int xhci_queue_slot_control (struct xhci_hcd *xhci,struct xhci_command *cmd, +u32 trb_type,u32 slot_id); +int xhci_queue_address_device (struct xhci_hcd *xhci,struct xhci_command *cmd, +dma_addr_t in_ctx_ptr,u32 slot_id,enum xhci_setup_dev ); +int xhci_queue_vendor_command (struct xhci_hcd *xhci,struct xhci_command *cmd,u32 field1,u32 field2,u32 field3,u32 field4); -int xhci_queue_stop_endpoint (struct xhci_hcd *xhci,int slot_id, -unsigned int ep_index,int suspend); +int xhci_queue_stop_endpoint (struct xhci_hcd *xhci,struct xhci_command *cmd, +int slot_id,unsigned int ep_index,int suspend);int xhci_queue_ctrl_tx (struct xhci_hcd *xhci,gfp_t mem_flags,struct urb *urb,int slot_id,unsigned int ep_index); int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
@@ -1825,18 +1826,21 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, int slot_id, unsigned int ep_index);int xhci_queue_isoc_tx_prepare (struct xhci_hcd *xhci,gfp_t mem_flags,struct urb *urb,int slot_id,unsigned int ep_index); -int xhci_queue_configure_endpoint (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,bool command_must_succeed); -int xhci_queue_evaluate_context (struct xhci_hcd *xhci,dma_addr_t in_ctx_ptr, -u32 slot_id,bool command_must_succeed); -int xhci_queue_reset_ep (struct xhci_hcd *xhci,int slot_id, -unsigned int ep_index); -int xhci_queue_reset_device (struct xhci_hcd *xhci,u32 slot_id); +int xhci_queue_configure_endpoint (struct xhci_hcd *xhci, +struct xhci_command *cmd,dma_addr_t in_ctx_ptr,u32 slot_id, +bool command_must_succeed); +int xhci_queue_evaluate_context (struct xhci_hcd *xhci,struct xhci_command *cmd, +dma_addr_t in_ctx_ptr,u32 slot_id,bool command_must_succeed); +int xhci_queue_reset_ep (struct xhci_hcd *xhci,struct xhci_command *cmd, +int slot_id,unsigned int ep_index); +int xhci_queue_reset_device (struct xhci_hcd *xhci,struct xhci_command *cmd, +u32 slot_id);void xhci_find_new_dequeue_state (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id,struct xhci_td *cur_td,struct xhci_dequeue_state *state);void xhci_queue_new_dequeue_state (struct xhci_hcd *xhci, +struct xhci_command *cmd,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id,struct xhci_dequeue_state *deq_state);
@@ -1850,7 +1854,6 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, union xhci_trb *cmd_trb);void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id); -union xhci_trb *xhci_find_next_enqueue (struct xhci_ring *ring);/* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
Signature · 1 line
1.8.3.2
RFC v5 2/4 xhci: Add a global command queue
In reply to Mathias NymanCreate a list to store command structures, add a structure to it every time a command is submitted, and remove it from the list once we get a command completion event matching the command.
Callers that wait for completion will free their command structures themselves. The other command structures are freed in the command completion event handler.
Also add a check that prevents queuing commands if host is dying
--- drivers/usb/host/xhci-mem.c | 2 ++ drivers/usb/host/xhci-ring.c | 34 ++++++++++++++++++++++++++++++---- drivers/usb/host/xhci.c | 2 -- drivers/usb/host/xhci.h | 2 ++ 4 files changed, 34 insertions(+), 6 deletions(-)
drivers/usb/host/xhci-mem.c +2 -0
@@ -1821,6 +1821,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)list_del (&cur_cd->cancel_cmd_list);kfree (cur_cd); } +xhci_cleanup_command_queue (xhci);for (i =1 ; i <MAX_HC_SLOTS ; ++i)xhci_free_virt_device (xhci, i);
@@ -2324,6 +2325,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)int i;INIT_LIST_HEAD (&xhci->cancel_cmd_list); +INIT_LIST_HEAD (&xhci->cmd_list); page_size =readl (&xhci->op_regs->page_size); xhci_dbg_trace(xhci, trace_xhci_dbg_init,
drivers/usb/host/xhci-ring.c +30 -4
@@ -1521,6 +1521,20 @@ static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, NEC_FW_MINOR(le32_to_cpu(event->status))); } +static void xhci_del_and_free_cmd (struct xhci_command *cmd) +{ +list_del (&cmd->cmd_list); +if (!cmd->completion) +kfree (cmd); +} + +void xhci_cleanup_command_queue (struct xhci_hcd *xhci) +{ +struct xhci_command *cur_cmd, *tmp_cmd; +list_for_each_entry_safe (cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) +xhci_del_and_free_cmd (cur_cmd); +} +static void handle_cmd_completion (struct xhci_hcd *xhci,struct xhci_event_cmd *event) {
@@ -1529,6 +1543,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,dma_addr_t cmd_dequeue_dma;u32 cmd_comp_code;union xhci_trb *cmd_trb; +struct xhci_command *cmd;u32 cmd_type; cmd_dma =le64_to_cpu (event->cmd_trb);
@@ -1546,6 +1561,13 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,return ; } + cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); + +if (cmd->command_trb != xhci->cmd_ring->dequeue) { +xhci_err (xhci, +"Command completion event does not match command\n" ); +return ; + }trace_xhci_cmd_completion (cmd_trb, (struct xhci_generic_trb *) event); cmd_comp_code =GET_COMP_CODE (le32_to_cpu (event->status));
@@ -1615,6 +1637,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, xhci->error_bitmask |=1 <<6 ;break ; } + +xhci_del_and_free_cmd (cmd); +inc_deq (xhci, xhci->cmd_ring); }
@@ -4002,6 +4027,8 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, {int reserved_trbs = xhci->cmd_ring_reserved_trbs;int ret; +if (xhci->xhc_state &XHCI_STATE_DYING ) +return -ESHUTDOWN ;if (!command_must_succeed) reserved_trbs++;
@@ -4015,10 +4042,9 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, "unfailable commands failed.\n");return ret; } -if (cmd->completion) - cmd->command_trb = xhci->cmd_ring->enqueue; -else -kfree (cmd); + + cmd->command_trb = xhci->cmd_ring->enqueue; +list_add_tail (&cmd->cmd_list, &xhci->cmd_list);queue_trb (xhci, xhci->cmd_ring, false, field1, field2, field3, field4 | xhci->cmd_ring->cycle_state);
drivers/usb/host/xhci.c +0 -2
@@ -3733,7 +3733,6 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) timeleft == 0 ? "Timeout" : "Signal");/* cancel the enable slot request */ ret =xhci_cancel_cmd (xhci,NULL , command->command_trb); -kfree (command);return ret; }
@@ -3889,7 +3888,6 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, timeleft == 0 ? "Timeout" : "Signal", act);/* cancel the address device command */ ret =xhci_cancel_cmd (xhci,NULL , command->command_trb); -kfree (command);if (ret <0 )return ret;return -ETIME ;
drivers/usb/host/xhci.h +2 -0
@@ -1486,6 +1486,7 @@ struct xhci_hcd {#define CMD_RING_STATE_ABORTED (1 << 1)#define CMD_RING_STATE_STOPPED (1 << 2)struct list_head cancel_cmd_list; +struct list_head cmd_list;unsigned int cmd_ring_reserved_trbs;struct xhci_ring *event_ring;struct xhci_erst erst;
@@ -1854,6 +1855,7 @@ int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, union xhci_trb *cmd_trb);void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id); +void xhci_cleanup_command_queue (struct xhci_hcd *xhci);/* xHCI roothub code */ void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
Signature · 1 line
1.8.3.2
RFC v5 3/4 xhci: Use completion and status in global command queue
In reply to Mathias NymanRemove the per-device command list and handle_cmd_in_cmd_wait_list() and use the completion and status variables found in the command structure in the global command list.
--- drivers/usb/host/xhci-hub.c | 11 ------ drivers/usb/host/xhci-mem.c | 1 - drivers/usb/host/xhci-ring.c | 84 ++++++++------------------------------------ drivers/usb/host/xhci.c | 16 ++------- drivers/usb/host/xhci.h | 3 -- 5 files changed, 17 insertions(+), 98 deletions(-)
drivers/usb/host/xhci-hub.c +0 -11
@@ -299,7 +299,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) suspend); } } -list_add_tail (&cmd->cmd_list, &virt_dev->cmd_list);xhci_queue_stop_endpoint (xhci, cmd, slot_id,0 , suspend);xhci_ring_cmd_db (xhci);spin_unlock_irqrestore (&xhci->lock, flags);
@@ -311,18 +310,8 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)if (timeleft <=0 ) {xhci_warn (xhci,"%s while waiting for stop endpoint command\n" , timeleft ==0 ?"Timeout" :"Signal" ); -spin_lock_irqsave (&xhci->lock, flags); -/* The timeout might have raced with the event ring handler, so -* only delete from the list if the item isn't poisoned. -*/ -if (cmd->cmd_list.next !=LIST_POISON1 ) -list_del (&cmd->cmd_list); -spin_unlock_irqrestore (&xhci->lock, flags); ret = -ETIME ; - goto command_cleanup; } - -command_cleanup:xhci_free_command (xhci, cmd);return ret; }
drivers/usb/host/xhci-mem.c +0 -1
@@ -1020,7 +1020,6 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, dev->num_rings_cached =0 ;init_completion (&dev->cmd_completion); -INIT_LIST_HEAD (&dev->cmd_list); dev->udev = udev;/* Point to output device context in dcbaa. */
drivers/usb/host/xhci-ring.c +15 -69
167 lines not on this page · raw message
drivers/usb/host/xhci.c +2 -14
@@ -2626,8 +2626,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,return -ENOMEM ; } -list_add_tail (&command->cmd_list, &virt_dev->cmd_list); -if (!ctx_change) ret = xhci_queue_configure_endpoint(xhci, command, command->in_ctx->dma,
@@ -2637,7 +2635,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, command->in_ctx->dma, udev->slot_id, must_succeed);if (ret <0 ) { -list_del (&command->cmd_list);if ((xhci->quirks &XHCI_EP_LIMIT_QUIRK ))xhci_free_host_resources (xhci, ctrl_ctx);spin_unlock_irqrestore (&xhci->lock, flags);
@@ -3500,11 +3497,9 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)/* Attempt to submit the Reset Device command to the command ring */ spin_lock_irqsave (&xhci->lock, flags); -list_add_tail (&reset_device_cmd->cmd_list, &virt_dev->cmd_list); ret =xhci_queue_reset_device (xhci, reset_device_cmd, slot_id);if (ret) {xhci_dbg (xhci,"FIXME: allocate a command ring segment\n" ); -list_del (&reset_device_cmd->cmd_list);spin_unlock_irqrestore (&xhci->lock, flags); goto command_cleanup; }
@@ -3518,13 +3513,6 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)if (timeleft <=0 ) {xhci_warn (xhci,"%s while waiting for reset device command\n" , timeleft ==0 ?"Timeout" :"Signal" ); -spin_lock_irqsave (&xhci->lock, flags); -/* The timeout might have raced with the event ring handler, so -* only delete from the list if the item isn't poisoned. -*/ -if (reset_device_cmd->cmd_list.next !=LIST_POISON1 ) -list_del (&reset_device_cmd->cmd_list); -spin_unlock_irqrestore (&xhci->lock, flags); ret = -ETIME ; goto command_cleanup; }
@@ -3893,7 +3881,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,return -ETIME ; } -switch (virt_dev->cmd_status) { +switch (command->status) {case COMP_CTX_STATE :case COMP_EBADSLT : xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n",
@@ -3916,7 +3904,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,default :xhci_err (xhci,"ERROR: unexpected setup %s command completion code 0x%x.\n" , - act, virt_dev->cmd_status); + act, command->status);xhci_dbg (xhci,"Slot ID %d Output Context:\n" , udev->slot_id);xhci_dbg_ctx (xhci, virt_dev->out_ctx,2 );trace_xhci_address_ctx (xhci, virt_dev->out_ctx,1 );
drivers/usb/host/xhci.h +0 -3
@@ -939,9 +939,6 @@ struct xhci_virt_device {#define XHCI_MAX_RINGS_CACHED 31struct xhci_virt_ep eps[31 ];struct completion cmd_completion; -/* Status of the last command issued for this device */ -u32 cmd_status; -struct list_head cmd_list;u8 fake_port;u8 real_port;struct xhci_interval_bw_table *bw_table;
Signature · 1 line
1.8.3.2
RFC v5 4/4 xhci: rework command timeout and cancellation,
In reply to Mathias NymanUse one timer to control command timeout.
start/kick the timer every time a command is completed and a new command is waiting, or a new command is added to a empty list.
If the timer runs out, then tag the current command as "aborted", and start the xhci command abortion process.
Previously each function that submitted a command had its own timer. If that command timed out, a new command structure for the command was created and it was put on a cancel_cmd_list list, then a pci write to abort the command ring was issued.
when the ring was aborted, it checked if the current command was the one to be canceled, later when the ring was stopped the driver got ownership of the TRBs in the command ring, compared then to the TRBs in the cancel_cmd_list,
and turned them into No-ops.
Now, instead, at timeout we tag the status of the command in the command queue to be aborted, and start the ring abortion. Ring abortion stops the command ring and gives control of the commands to us.
All the aborted commands are now turned into No-ops.
If the ring is already stopped when the command times outs its not possible to start the ring abortion, in this case the command is turnd to No-op right away.
All these changes allows us to remove the entire cancel_cmd_list code.
The functions waiting for a command to finish no longer have their own timeouts. They will wait either until the command completes normally,
or until the whole command abortion is done.
--- drivers/usb/host/xhci-hub.c | 11 +- drivers/usb/host/xhci-mem.c | 14 +- drivers/usb/host/xhci-ring.c | 378 +++++++++++++++---------------------------- drivers/usb/host/xhci.c | 78 +++------ drivers/usb/host/xhci.h | 8 +- 5 files changed, 169 insertions(+), 320 deletions(-)
drivers/usb/host/xhci-hub.c +4 -7
@@ -271,7 +271,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)struct xhci_virt_device *virt_dev;struct xhci_command *cmd;unsigned long flags; -int timeleft;int ret;int i;
@@ -304,12 +303,10 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)spin_unlock_irqrestore (&xhci->lock, flags);/* Wait for last stop endpoint command to finish */ - timeleft =wait_for_completion_interruptible_timeout ( - cmd->completion, -XHCI_CMD_DEFAULT_TIMEOUT ); -if (timeleft <=0 ) { -xhci_warn (xhci,"%s while waiting for stop endpoint command\n" , - timeleft ==0 ?"Timeout" :"Signal" ); +wait_for_completion (cmd->completion); + +if (cmd->status ==COMP_CMD_ABORT || cmd->status ==COMP_CMD_STOP ) { +xhci_warn (xhci,"Timeout while waiting for stop endpoint command\n" ); ret = -ETIME ; }xhci_free_command (xhci, cmd);
drivers/usb/host/xhci-mem.c +7 -7
@@ -1793,10 +1793,11 @@ void xhci_free_command(struct xhci_hcd *xhci,void xhci_mem_cleanup (struct xhci_hcd *xhci) {struct device *dev =xhci_to_hcd (xhci)->self.controller; -struct xhci_cd *cur_cd, *next_cd;int size;int i, j, num_ports; +del_timer_sync (&xhci->cmd_timer); +/* Free the Event Ring Segment Table and the actual Event Ring */ size =sizeof (struct xhci_erst_entry )*(xhci->erst.num_entries);if (xhci->erst.entries)
@@ -1815,11 +1816,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)xhci_ring_free (xhci, xhci->cmd_ring); xhci->cmd_ring =NULL ;xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Freed command ring" ); -list_for_each_entry_safe (cur_cd, next_cd, - &xhci->cancel_cmd_list, cancel_cmd_list) { -list_del (&cur_cd->cancel_cmd_list); -kfree (cur_cd); - }xhci_cleanup_command_queue (xhci);for (i =1 ; i <MAX_HC_SLOTS ; ++i)
@@ -2323,7 +2319,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)u32 page_size, temp;int i; -INIT_LIST_HEAD (&xhci->cancel_cmd_list);INIT_LIST_HEAD (&xhci->cmd_list); page_size =readl (&xhci->op_regs->page_size);
@@ -2510,6 +2505,11 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) "Wrote ERST address to ir_set 0.");xhci_print_ir_set (xhci,0 ); +/* init command timeout timer */ +init_timer (&xhci->cmd_timer); + xhci->cmd_timer.data = (unsigned long ) xhci; + xhci->cmd_timer.function = xhci_handle_command_timeout; +/* * XXX: Might need to set the Interrupter Moderation Register to * something other than the default (~1ms minimum between interrupts).
drivers/usb/host/xhci-ring.c +128 -250
430 lines not on this page · raw message
drivers/usb/host/xhci.c +26 -52
150 lines not on this page · raw message
drivers/usb/host/xhci.h +4 -4
@@ -1297,7 +1297,6 @@ struct xhci_td {/* command descriptor */ struct xhci_cd { -struct list_head cancel_cmd_list;struct xhci_command *command;union xhci_trb *cmd_trb; };
@@ -1482,9 +1481,10 @@ struct xhci_hcd {#define CMD_RING_STATE_RUNNING (1 << 0)#define CMD_RING_STATE_ABORTED (1 << 1)#define CMD_RING_STATE_STOPPED (1 << 2) -struct list_head cancel_cmd_list;struct list_head cmd_list;unsigned int cmd_ring_reserved_trbs; +struct timer_list cmd_timer; +struct xhci_command *current_cmd;struct xhci_ring *event_ring;struct xhci_erst erst;/* Scratchpad */
@@ -1848,8 +1848,8 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, struct xhci_dequeue_state *deq_state);void xhci_stop_endpoint_command_watchdog (unsigned long arg); -int xhci_cancel_cmd (struct xhci_hcd *xhci,struct xhci_command *command, -union xhci_trb *cmd_trb); +void xhci_handle_command_timeout (unsigned long data); +void xhci_ring_ep_doorbell (struct xhci_hcd *xhci,unsigned int slot_id,unsigned int ep_index,unsigned int stream_id);void xhci_cleanup_command_queue (struct xhci_hcd *xhci);
Signature · 1 line
1.8.3.2