aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Nyman <mathias.nyman@linux.intel.com>2014-05-08 12:26:02 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-05-19 21:03:25 -0400
commit9ea1833e4c210ac5580f63495be15502f275c578 (patch)
treef9eae8830776fa03922f49c05ec09730f01c54a2
parentc9aa1a2de4cbf7d0db6012fbf86b6ee0c3719470 (diff)
xhci: Use completion and status in global command queue
Remove 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. Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/host/xhci-hub.c11
-rw-r--r--drivers/usb/host/xhci-mem.c1
-rw-r--r--drivers/usb/host/xhci-ring.c84
-rw-r--r--drivers/usb/host/xhci.c16
-rw-r--r--drivers/usb/host/xhci.h3
5 files changed, 17 insertions, 98 deletions
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 3ce9c0ac2614..12871b5d4a2e 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -299,7 +299,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
299 suspend); 299 suspend);
300 } 300 }
301 } 301 }
302 list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list);
303 xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend); 302 xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend);
304 xhci_ring_cmd_db(xhci); 303 xhci_ring_cmd_db(xhci);
305 spin_unlock_irqrestore(&xhci->lock, flags); 304 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -311,18 +310,8 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
311 if (timeleft <= 0) { 310 if (timeleft <= 0) {
312 xhci_warn(xhci, "%s while waiting for stop endpoint command\n", 311 xhci_warn(xhci, "%s while waiting for stop endpoint command\n",
313 timeleft == 0 ? "Timeout" : "Signal"); 312 timeleft == 0 ? "Timeout" : "Signal");
314 spin_lock_irqsave(&xhci->lock, flags);
315 /* The timeout might have raced with the event ring handler, so
316 * only delete from the list if the item isn't poisoned.
317 */
318 if (cmd->cmd_list.next != LIST_POISON1)
319 list_del(&cmd->cmd_list);
320 spin_unlock_irqrestore(&xhci->lock, flags);
321 ret = -ETIME; 313 ret = -ETIME;
322 goto command_cleanup;
323 } 314 }
324
325command_cleanup:
326 xhci_free_command(xhci, cmd); 315 xhci_free_command(xhci, cmd);
327 return ret; 316 return ret;
328} 317}
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index b070a17bf53f..38dc721bc8bb 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1020,7 +1020,6 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
1020 dev->num_rings_cached = 0; 1020 dev->num_rings_cached = 0;
1021 1021
1022 init_completion(&dev->cmd_completion); 1022 init_completion(&dev->cmd_completion);
1023 INIT_LIST_HEAD(&dev->cmd_list);
1024 dev->udev = udev; 1023 dev->udev = udev;
1025 1024
1026 /* Point to output device context in dcbaa. */ 1025 /* Point to output device context in dcbaa. */
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 89b874567548..3d60865a3d8f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -69,10 +69,6 @@
69#include "xhci.h" 69#include "xhci.h"
70#include "xhci-trace.h" 70#include "xhci-trace.h"
71 71
72static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
73 struct xhci_virt_device *virt_dev,
74 struct xhci_event_cmd *event);
75
76/* 72/*
77 * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA 73 * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA
78 * address of the TRB. 74 * address of the TRB.
@@ -765,7 +761,6 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
765 union xhci_trb *trb, struct xhci_event_cmd *event) 761 union xhci_trb *trb, struct xhci_event_cmd *event)
766{ 762{
767 unsigned int ep_index; 763 unsigned int ep_index;
768 struct xhci_virt_device *virt_dev;
769 struct xhci_ring *ep_ring; 764 struct xhci_ring *ep_ring;
770 struct xhci_virt_ep *ep; 765 struct xhci_virt_ep *ep;
771 struct list_head *entry; 766 struct list_head *entry;
@@ -775,11 +770,7 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
775 struct xhci_dequeue_state deq_state; 770 struct xhci_dequeue_state deq_state;
776 771
777 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { 772 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) {
778 virt_dev = xhci->devs[slot_id]; 773 if (!xhci->devs[slot_id])
779 if (virt_dev)
780 handle_cmd_in_cmd_wait_list(xhci, virt_dev,
781 event);
782 else
783 xhci_warn(xhci, "Stop endpoint command " 774 xhci_warn(xhci, "Stop endpoint command "
784 "completion for disabled slot %u\n", 775 "completion for disabled slot %u\n",
785 slot_id); 776 slot_id);
@@ -1229,29 +1220,6 @@ static void xhci_complete_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
1229} 1220}
1230 1221
1231 1222
1232/* Check to see if a command in the device's command queue matches this one.
1233 * Signal the completion or free the command, and return 1. Return 0 if the
1234 * completed command isn't at the head of the command list.
1235 */
1236static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
1237 struct xhci_virt_device *virt_dev,
1238 struct xhci_event_cmd *event)
1239{
1240 struct xhci_command *command;
1241
1242 if (list_empty(&virt_dev->cmd_list))
1243 return 0;
1244
1245 command = list_entry(virt_dev->cmd_list.next,
1246 struct xhci_command, cmd_list);
1247 if (xhci->cmd_ring->dequeue != command->command_trb)
1248 return 0;
1249
1250 xhci_complete_cmd_in_cmd_wait_list(xhci, command,
1251 GET_COMP_CODE(le32_to_cpu(event->status)));
1252 return 1;
1253}
1254
1255/* 1223/*
1256 * Finding the command trb need to be cancelled and modifying it to 1224 * Finding the command trb need to be cancelled and modifying it to
1257 * NO OP command. And if the command is in device's command wait 1225 * NO OP command. And if the command is in device's command wait
@@ -1403,7 +1371,6 @@ static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id,
1403 xhci->slot_id = slot_id; 1371 xhci->slot_id = slot_id;
1404 else 1372 else
1405 xhci->slot_id = 0; 1373 xhci->slot_id = 0;
1406 complete(&xhci->addr_dev);
1407} 1374}
1408 1375
1409static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) 1376static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id)
@@ -1428,9 +1395,6 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1428 unsigned int ep_state; 1395 unsigned int ep_state;
1429 u32 add_flags, drop_flags; 1396 u32 add_flags, drop_flags;
1430 1397
1431 virt_dev = xhci->devs[slot_id];
1432 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1433 return;
1434 /* 1398 /*
1435 * Configure endpoint commands can come from the USB core 1399 * Configure endpoint commands can come from the USB core
1436 * configuration or alt setting changes, or because the HW 1400 * configuration or alt setting changes, or because the HW
@@ -1439,6 +1403,7 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1439 * If the command was for a halted endpoint, the xHCI driver 1403 * If the command was for a halted endpoint, the xHCI driver
1440 * is not waiting on the configure endpoint command. 1404 * is not waiting on the configure endpoint command.
1441 */ 1405 */
1406 virt_dev = xhci->devs[slot_id];
1442 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); 1407 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1443 if (!ctrl_ctx) { 1408 if (!ctrl_ctx) {
1444 xhci_warn(xhci, "Could not get input context, bad type.\n"); 1409 xhci_warn(xhci, "Could not get input context, bad type.\n");
@@ -1474,35 +1439,11 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1474 return; 1439 return;
1475} 1440}
1476 1441
1477static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id,
1478 struct xhci_event_cmd *event, u32 cmd_comp_code)
1479{
1480 struct xhci_virt_device *virt_dev;
1481
1482 virt_dev = xhci->devs[slot_id];
1483 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1484 return;
1485 virt_dev->cmd_status = cmd_comp_code;
1486 complete(&virt_dev->cmd_completion);
1487}
1488
1489static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id,
1490 u32 cmd_comp_code)
1491{
1492 xhci->devs[slot_id]->cmd_status = cmd_comp_code;
1493 complete(&xhci->addr_dev);
1494}
1495
1496static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, 1442static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id,
1497 struct xhci_event_cmd *event) 1443 struct xhci_event_cmd *event)
1498{ 1444{
1499 struct xhci_virt_device *virt_dev;
1500
1501 xhci_dbg(xhci, "Completed reset device command.\n"); 1445 xhci_dbg(xhci, "Completed reset device command.\n");
1502 virt_dev = xhci->devs[slot_id]; 1446 if (!xhci->devs[slot_id])
1503 if (virt_dev)
1504 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
1505 else
1506 xhci_warn(xhci, "Reset device command completion " 1447 xhci_warn(xhci, "Reset device command completion "
1507 "for disabled slot %u\n", slot_id); 1448 "for disabled slot %u\n", slot_id);
1508} 1449}
@@ -1520,18 +1461,23 @@ static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci,
1520 NEC_FW_MINOR(le32_to_cpu(event->status))); 1461 NEC_FW_MINOR(le32_to_cpu(event->status)));
1521} 1462}
1522 1463
1523static void xhci_del_and_free_cmd(struct xhci_command *cmd) 1464static void xhci_complete_del_and_free_cmd(struct xhci_command *cmd, u32 status)
1524{ 1465{
1525 list_del(&cmd->cmd_list); 1466 list_del(&cmd->cmd_list);
1526 if (!cmd->completion) 1467
1468 if (cmd->completion) {
1469 cmd->status = status;
1470 complete(cmd->completion);
1471 } else {
1527 kfree(cmd); 1472 kfree(cmd);
1473 }
1528} 1474}
1529 1475
1530void xhci_cleanup_command_queue(struct xhci_hcd *xhci) 1476void xhci_cleanup_command_queue(struct xhci_hcd *xhci)
1531{ 1477{
1532 struct xhci_command *cur_cmd, *tmp_cmd; 1478 struct xhci_command *cur_cmd, *tmp_cmd;
1533 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) 1479 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list)
1534 xhci_del_and_free_cmd(cur_cmd); 1480 xhci_complete_del_and_free_cmd(cur_cmd, COMP_CMD_ABORT);
1535} 1481}
1536 1482
1537static void handle_cmd_completion(struct xhci_hcd *xhci, 1483static void handle_cmd_completion(struct xhci_hcd *xhci,
@@ -1598,13 +1544,13 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1598 xhci_handle_cmd_disable_slot(xhci, slot_id); 1544 xhci_handle_cmd_disable_slot(xhci, slot_id);
1599 break; 1545 break;
1600 case TRB_CONFIG_EP: 1546 case TRB_CONFIG_EP:
1601 xhci_handle_cmd_config_ep(xhci, slot_id, event, cmd_comp_code); 1547 if (!cmd->completion)
1548 xhci_handle_cmd_config_ep(xhci, slot_id, event,
1549 cmd_comp_code);
1602 break; 1550 break;
1603 case TRB_EVAL_CONTEXT: 1551 case TRB_EVAL_CONTEXT:
1604 xhci_handle_cmd_eval_ctx(xhci, slot_id, event, cmd_comp_code);
1605 break; 1552 break;
1606 case TRB_ADDR_DEV: 1553 case TRB_ADDR_DEV:
1607 xhci_handle_cmd_addr_dev(xhci, slot_id, cmd_comp_code);
1608 break; 1554 break;
1609 case TRB_STOP_RING: 1555 case TRB_STOP_RING:
1610 WARN_ON(slot_id != TRB_TO_SLOT_ID( 1556 WARN_ON(slot_id != TRB_TO_SLOT_ID(
@@ -1637,7 +1583,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1637 break; 1583 break;
1638 } 1584 }
1639 1585
1640 xhci_del_and_free_cmd(cmd); 1586 xhci_complete_del_and_free_cmd(cmd, cmd_comp_code);
1641 1587
1642 inc_deq(xhci, xhci->cmd_ring); 1588 inc_deq(xhci, xhci->cmd_ring);
1643} 1589}
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 8dbc41032177..64c1ba353856 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -2626,8 +2626,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2626 return -ENOMEM; 2626 return -ENOMEM;
2627 } 2627 }
2628 2628
2629 list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
2630
2631 if (!ctx_change) 2629 if (!ctx_change)
2632 ret = xhci_queue_configure_endpoint(xhci, command, 2630 ret = xhci_queue_configure_endpoint(xhci, command,
2633 command->in_ctx->dma, 2631 command->in_ctx->dma,
@@ -2637,7 +2635,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2637 command->in_ctx->dma, 2635 command->in_ctx->dma,
2638 udev->slot_id, must_succeed); 2636 udev->slot_id, must_succeed);
2639 if (ret < 0) { 2637 if (ret < 0) {
2640 list_del(&command->cmd_list);
2641 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) 2638 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK))
2642 xhci_free_host_resources(xhci, ctrl_ctx); 2639 xhci_free_host_resources(xhci, ctrl_ctx);
2643 spin_unlock_irqrestore(&xhci->lock, flags); 2640 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -3499,11 +3496,9 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3499 /* Attempt to submit the Reset Device command to the command ring */ 3496 /* Attempt to submit the Reset Device command to the command ring */
3500 spin_lock_irqsave(&xhci->lock, flags); 3497 spin_lock_irqsave(&xhci->lock, flags);
3501 3498
3502 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
3503 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); 3499 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id);
3504 if (ret) { 3500 if (ret) {
3505 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); 3501 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
3506 list_del(&reset_device_cmd->cmd_list);
3507 spin_unlock_irqrestore(&xhci->lock, flags); 3502 spin_unlock_irqrestore(&xhci->lock, flags);
3508 goto command_cleanup; 3503 goto command_cleanup;
3509 } 3504 }
@@ -3517,13 +3512,6 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3517 if (timeleft <= 0) { 3512 if (timeleft <= 0) {
3518 xhci_warn(xhci, "%s while waiting for reset device command\n", 3513 xhci_warn(xhci, "%s while waiting for reset device command\n",
3519 timeleft == 0 ? "Timeout" : "Signal"); 3514 timeleft == 0 ? "Timeout" : "Signal");
3520 spin_lock_irqsave(&xhci->lock, flags);
3521 /* The timeout might have raced with the event ring handler, so
3522 * only delete from the list if the item isn't poisoned.
3523 */
3524 if (reset_device_cmd->cmd_list.next != LIST_POISON1)
3525 list_del(&reset_device_cmd->cmd_list);
3526 spin_unlock_irqrestore(&xhci->lock, flags);
3527 ret = -ETIME; 3515 ret = -ETIME;
3528 goto command_cleanup; 3516 goto command_cleanup;
3529 } 3517 }
@@ -3895,7 +3883,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
3895 return -ETIME; 3883 return -ETIME;
3896 } 3884 }
3897 3885
3898 switch (virt_dev->cmd_status) { 3886 switch (command->status) {
3899 case COMP_CTX_STATE: 3887 case COMP_CTX_STATE:
3900 case COMP_EBADSLT: 3888 case COMP_EBADSLT:
3901 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", 3889 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n",
@@ -3918,7 +3906,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
3918 default: 3906 default:
3919 xhci_err(xhci, 3907 xhci_err(xhci,
3920 "ERROR: unexpected setup %s command completion code 0x%x.\n", 3908 "ERROR: unexpected setup %s command completion code 0x%x.\n",
3921 act, virt_dev->cmd_status); 3909 act, command->status);
3922 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 3910 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
3923 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); 3911 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
3924 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); 3912 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index d33cd3750a15..fde57b09a9bd 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -937,9 +937,6 @@ struct xhci_virt_device {
937#define XHCI_MAX_RINGS_CACHED 31 937#define XHCI_MAX_RINGS_CACHED 31
938 struct xhci_virt_ep eps[31]; 938 struct xhci_virt_ep eps[31];
939 struct completion cmd_completion; 939 struct completion cmd_completion;
940 /* Status of the last command issued for this device */
941 u32 cmd_status;
942 struct list_head cmd_list;
943 u8 fake_port; 940 u8 fake_port;
944 u8 real_port; 941 u8 real_port;
945 struct xhci_interval_bw_table *bw_table; 942 struct xhci_interval_bw_table *bw_table;