aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorXenia Ragiadakou <burzalodowa@gmail.com>2013-09-09 06:29:55 -0400
committerSarah Sharp <sarah.a.sharp@linux.intel.com>2013-10-16 15:24:33 -0400
commit6ed46d3337b1f4a8f9fa7438589cab5f1bb75e98 (patch)
treeef4b9a6b1bac305c6794e31322fc8bce79b8fd49 /drivers/usb/host
parentfd54498733f8c372deca99892ae8cae0799dfe68 (diff)
xhci: refactor TRB_CONFIG_EP case into function
The function that handles xHCI command completion is much too long and there is need to be broken up into individual functions for each command completion to improve code readablity. This patch refactors the code in TRB_CONFIG_EP switch case, in handle_cmd_completion(), into a fuction named xhci_handle_cmd_config_ep(). There were added two additional variables, 'add_flags' and 'drop_flags', to reduce line length below 80 chars and improve code readability. Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/xhci-ring.c114
1 files changed, 62 insertions, 52 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 0bef11b3dd22..3e8053284752 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1407,6 +1407,66 @@ static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id)
1407 xhci_free_virt_device(xhci, slot_id); 1407 xhci_free_virt_device(xhci, slot_id);
1408} 1408}
1409 1409
1410static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1411 struct xhci_event_cmd *event, u32 cmd_comp_code)
1412{
1413 struct xhci_virt_device *virt_dev;
1414 struct xhci_input_control_ctx *ctrl_ctx;
1415 unsigned int ep_index;
1416 unsigned int ep_state;
1417 u32 add_flags, drop_flags;
1418
1419 virt_dev = xhci->devs[slot_id];
1420 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1421 return;
1422 /*
1423 * Configure endpoint commands can come from the USB core
1424 * configuration or alt setting changes, or because the HW
1425 * needed an extra configure endpoint command after a reset
1426 * endpoint command or streams were being configured.
1427 * If the command was for a halted endpoint, the xHCI driver
1428 * is not waiting on the configure endpoint command.
1429 */
1430 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1431 if (!ctrl_ctx) {
1432 xhci_warn(xhci, "Could not get input context, bad type.\n");
1433 return;
1434 }
1435
1436 add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1437 drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1438 /* Input ctx add_flags are the endpoint index plus one */
1439 ep_index = xhci_last_valid_endpoint(add_flags) - 1;
1440
1441 /* A usb_set_interface() call directly after clearing a halted
1442 * condition may race on this quirky hardware. Not worth
1443 * worrying about, since this is prototype hardware. Not sure
1444 * if this will work for streams, but streams support was
1445 * untested on this prototype.
1446 */
1447 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1448 ep_index != (unsigned int) -1 &&
1449 add_flags - SLOT_FLAG == drop_flags) {
1450 ep_state = virt_dev->eps[ep_index].ep_state;
1451 if (!(ep_state & EP_HALTED))
1452 goto bandwidth_change;
1453 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1454 "Completed config ep cmd - "
1455 "last ep index = %d, state = %d",
1456 ep_index, ep_state);
1457 /* Clear internal halted state and restart ring(s) */
1458 virt_dev->eps[ep_index].ep_state &= ~EP_HALTED;
1459 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1460 return;
1461 }
1462bandwidth_change:
1463 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1464 "Completed config ep cmd");
1465 virt_dev->cmd_status = cmd_comp_code;
1466 complete(&virt_dev->cmd_completion);
1467 return;
1468}
1469
1410static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id, 1470static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id,
1411 struct xhci_event_cmd *event, u32 cmd_comp_code) 1471 struct xhci_event_cmd *event, u32 cmd_comp_code)
1412{ 1472{
@@ -1459,10 +1519,6 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1459 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1519 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1460 u64 cmd_dma; 1520 u64 cmd_dma;
1461 dma_addr_t cmd_dequeue_dma; 1521 dma_addr_t cmd_dequeue_dma;
1462 struct xhci_input_control_ctx *ctrl_ctx;
1463 struct xhci_virt_device *virt_dev;
1464 unsigned int ep_index;
1465 unsigned int ep_state;
1466 1522
1467 cmd_dma = le64_to_cpu(event->cmd_trb); 1523 cmd_dma = le64_to_cpu(event->cmd_trb);
1468 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 1524 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
@@ -1512,54 +1568,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1512 xhci_handle_cmd_disable_slot(xhci, slot_id); 1568 xhci_handle_cmd_disable_slot(xhci, slot_id);
1513 break; 1569 break;
1514 case TRB_TYPE(TRB_CONFIG_EP): 1570 case TRB_TYPE(TRB_CONFIG_EP):
1515 virt_dev = xhci->devs[slot_id]; 1571 xhci_handle_cmd_config_ep(xhci, slot_id, event,
1516 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) 1572 GET_COMP_CODE(le32_to_cpu(event->status)));
1517 break;
1518 /*
1519 * Configure endpoint commands can come from the USB core
1520 * configuration or alt setting changes, or because the HW
1521 * needed an extra configure endpoint command after a reset
1522 * endpoint command or streams were being configured.
1523 * If the command was for a halted endpoint, the xHCI driver
1524 * is not waiting on the configure endpoint command.
1525 */
1526 ctrl_ctx = xhci_get_input_control_ctx(xhci,
1527 virt_dev->in_ctx);
1528 if (!ctrl_ctx) {
1529 xhci_warn(xhci, "Could not get input context, bad type.\n");
1530 break;
1531 }
1532 /* Input ctx add_flags are the endpoint index plus one */
1533 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
1534 /* A usb_set_interface() call directly after clearing a halted
1535 * condition may race on this quirky hardware. Not worth
1536 * worrying about, since this is prototype hardware. Not sure
1537 * if this will work for streams, but streams support was
1538 * untested on this prototype.
1539 */
1540 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1541 ep_index != (unsigned int) -1 &&
1542 le32_to_cpu(ctrl_ctx->add_flags) - SLOT_FLAG ==
1543 le32_to_cpu(ctrl_ctx->drop_flags)) {
1544 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1545 if (!(ep_state & EP_HALTED))
1546 goto bandwidth_change;
1547 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1548 "Completed config ep cmd - "
1549 "last ep index = %d, state = %d",
1550 ep_index, ep_state);
1551 /* Clear internal halted state and restart ring(s) */
1552 xhci->devs[slot_id]->eps[ep_index].ep_state &=
1553 ~EP_HALTED;
1554 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1555 break;
1556 }
1557bandwidth_change:
1558 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1559 "Completed config ep cmd");
1560 xhci->devs[slot_id]->cmd_status =
1561 GET_COMP_CODE(le32_to_cpu(event->status));
1562 complete(&xhci->devs[slot_id]->cmd_completion);
1563 break; 1573 break;
1564 case TRB_TYPE(TRB_EVAL_CONTEXT): 1574 case TRB_TYPE(TRB_EVAL_CONTEXT):
1565 xhci_handle_cmd_eval_ctx(xhci, slot_id, event, 1575 xhci_handle_cmd_eval_ctx(xhci, slot_id, event,