[PATCH] xhci: Fix use of 'reserved' command ring entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The xhci driver allows some command ring entries to be 'reserved' so
that some requests won't fail because the command ring is full.

However queue_command() would never allow the last few ring entries to
be used even if the caller indicated that it could use a reserved slot.

If 'command_must_succeed' is set, only check that a single entry is
available.

Note that entries are not dynamically reserved and then consumed later.
Initially one entry is reserved, later another is reserved for each active
stream.

Signed-off-by: David Laight <david.laight@xxxxxxxxxx>
---
 drivers/usb/host/xhci-ring.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 53c2e29..c021708 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -4018,23 +4018,20 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
 
 /* Generic function for queueing a command TRB on the command ring.
  * Check to make sure there's room on the command ring for one command TRB.
- * Also check that there's room reserved for commands that must not fail.
- * If this is a command that must not fail, meaning command_must_succeed = TRUE,
- * then only check for the number of reserved spots.
- * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
- * because the command event handler may want to resubmit a failed command.
+ * If this isn't one of the commands that can use a reserved slot then ensure
+ * that there are enough slots for all the reserved commands to be started.
  */
 static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2,
 		u32 field3, u32 field4, bool command_must_succeed)
 {
-	int reserved_trbs = xhci->cmd_ring_reserved_trbs;
+	int trbs_needed = 1;
 	int ret;
 
 	if (!command_must_succeed)
-		reserved_trbs++;
+		trbs_needed += xhci->cmd_ring_reserved_trbs;
 
 	ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING,
-			reserved_trbs, GFP_ATOMIC);
+			trbs_needed, GFP_ATOMIC);
 	if (ret < 0) {
 		xhci_err(xhci, "ERR: No room for command on command ring\n");
 		if (command_must_succeed)
-- 
1.8.1.2



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux