diff options
-rw-r--r-- | drivers/usb/host/xhci-dbg.c | 19 | ||||
-rw-r--r-- | drivers/usb/host/xhci-hcd.c | 125 | ||||
-rw-r--r-- | drivers/usb/host/xhci-ring.c | 19 | ||||
-rw-r--r-- | drivers/usb/host/xhci.h | 3 |
4 files changed, 166 insertions, 0 deletions
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c index 33128d52f212..b2915aea47ee 100644 --- a/drivers/usb/host/xhci-dbg.c +++ b/drivers/usb/host/xhci-dbg.c | |||
@@ -406,6 +406,25 @@ static void dbg_rsvd64(struct xhci_hcd *xhci, u64 *ctx, dma_addr_t dma) | |||
406 | } | 406 | } |
407 | } | 407 | } |
408 | 408 | ||
409 | inline char *xhci_get_slot_state(struct xhci_hcd *xhci, | ||
410 | struct xhci_container_ctx *ctx) | ||
411 | { | ||
412 | struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx); | ||
413 | |||
414 | switch (GET_SLOT_STATE(slot_ctx->dev_state)) { | ||
415 | case 0: | ||
416 | return "enabled/disabled"; | ||
417 | case 1: | ||
418 | return "default"; | ||
419 | case 2: | ||
420 | return "addressed"; | ||
421 | case 3: | ||
422 | return "configured"; | ||
423 | default: | ||
424 | return "reserved"; | ||
425 | } | ||
426 | } | ||
427 | |||
409 | void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) | 428 | void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) |
410 | { | 429 | { |
411 | /* Fields are 32 bits wide, DMA addresses are in bytes */ | 430 | /* Fields are 32 bits wide, DMA addresses are in bytes */ |
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c index 17f1caf2af64..c8573f874ec4 100644 --- a/drivers/usb/host/xhci-hcd.c +++ b/drivers/usb/host/xhci-hcd.c | |||
@@ -1443,6 +1443,131 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
1443 | } | 1443 | } |
1444 | 1444 | ||
1445 | /* | 1445 | /* |
1446 | * This submits a Reset Device Command, which will set the device state to 0, | ||
1447 | * set the device address to 0, and disable all the endpoints except the default | ||
1448 | * control endpoint. The USB core should come back and call | ||
1449 | * xhci_address_device(), and then re-set up the configuration. If this is | ||
1450 | * called because of a usb_reset_and_verify_device(), then the old alternate | ||
1451 | * settings will be re-installed through the normal bandwidth allocation | ||
1452 | * functions. | ||
1453 | * | ||
1454 | * Wait for the Reset Device command to finish. Remove all structures | ||
1455 | * associated with the endpoints that were disabled. Clear the input device | ||
1456 | * structure? Cache the rings? Reset the control endpoint 0 max packet size? | ||
1457 | */ | ||
1458 | int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
1459 | { | ||
1460 | int ret, i; | ||
1461 | unsigned long flags; | ||
1462 | struct xhci_hcd *xhci; | ||
1463 | unsigned int slot_id; | ||
1464 | struct xhci_virt_device *virt_dev; | ||
1465 | struct xhci_command *reset_device_cmd; | ||
1466 | int timeleft; | ||
1467 | int last_freed_endpoint; | ||
1468 | |||
1469 | ret = xhci_check_args(hcd, udev, NULL, 0, __func__); | ||
1470 | if (ret <= 0) | ||
1471 | return ret; | ||
1472 | xhci = hcd_to_xhci(hcd); | ||
1473 | slot_id = udev->slot_id; | ||
1474 | virt_dev = xhci->devs[slot_id]; | ||
1475 | if (!virt_dev) { | ||
1476 | xhci_dbg(xhci, "%s called with invalid slot ID %u\n", | ||
1477 | __func__, slot_id); | ||
1478 | return -EINVAL; | ||
1479 | } | ||
1480 | |||
1481 | xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); | ||
1482 | /* Allocate the command structure that holds the struct completion. | ||
1483 | * Assume we're in process context, since the normal device reset | ||
1484 | * process has to wait for the device anyway. Storage devices are | ||
1485 | * reset as part of error handling, so use GFP_NOIO instead of | ||
1486 | * GFP_KERNEL. | ||
1487 | */ | ||
1488 | reset_device_cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO); | ||
1489 | if (!reset_device_cmd) { | ||
1490 | xhci_dbg(xhci, "Couldn't allocate command structure.\n"); | ||
1491 | return -ENOMEM; | ||
1492 | } | ||
1493 | |||
1494 | /* Attempt to submit the Reset Device command to the command ring */ | ||
1495 | spin_lock_irqsave(&xhci->lock, flags); | ||
1496 | reset_device_cmd->command_trb = xhci->cmd_ring->enqueue; | ||
1497 | list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list); | ||
1498 | ret = xhci_queue_reset_device(xhci, slot_id); | ||
1499 | if (ret) { | ||
1500 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); | ||
1501 | list_del(&reset_device_cmd->cmd_list); | ||
1502 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1503 | goto command_cleanup; | ||
1504 | } | ||
1505 | xhci_ring_cmd_db(xhci); | ||
1506 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1507 | |||
1508 | /* Wait for the Reset Device command to finish */ | ||
1509 | timeleft = wait_for_completion_interruptible_timeout( | ||
1510 | reset_device_cmd->completion, | ||
1511 | USB_CTRL_SET_TIMEOUT); | ||
1512 | if (timeleft <= 0) { | ||
1513 | xhci_warn(xhci, "%s while waiting for reset device command\n", | ||
1514 | timeleft == 0 ? "Timeout" : "Signal"); | ||
1515 | spin_lock_irqsave(&xhci->lock, flags); | ||
1516 | /* The timeout might have raced with the event ring handler, so | ||
1517 | * only delete from the list if the item isn't poisoned. | ||
1518 | */ | ||
1519 | if (reset_device_cmd->cmd_list.next != LIST_POISON1) | ||
1520 | list_del(&reset_device_cmd->cmd_list); | ||
1521 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1522 | ret = -ETIME; | ||
1523 | goto command_cleanup; | ||
1524 | } | ||
1525 | |||
1526 | /* The Reset Device command can't fail, according to the 0.95/0.96 spec, | ||
1527 | * unless we tried to reset a slot ID that wasn't enabled, | ||
1528 | * or the device wasn't in the addressed or configured state. | ||
1529 | */ | ||
1530 | ret = reset_device_cmd->status; | ||
1531 | switch (ret) { | ||
1532 | case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */ | ||
1533 | case COMP_CTX_STATE: /* 0.96 completion code for same thing */ | ||
1534 | xhci_info(xhci, "Can't reset device (slot ID %u) in %s state\n", | ||
1535 | slot_id, | ||
1536 | xhci_get_slot_state(xhci, virt_dev->out_ctx)); | ||
1537 | xhci_info(xhci, "Not freeing device rings.\n"); | ||
1538 | /* Don't treat this as an error. May change my mind later. */ | ||
1539 | ret = 0; | ||
1540 | goto command_cleanup; | ||
1541 | case COMP_SUCCESS: | ||
1542 | xhci_dbg(xhci, "Successful reset device command.\n"); | ||
1543 | break; | ||
1544 | default: | ||
1545 | if (xhci_is_vendor_info_code(xhci, ret)) | ||
1546 | break; | ||
1547 | xhci_warn(xhci, "Unknown completion code %u for " | ||
1548 | "reset device command.\n", ret); | ||
1549 | ret = -EINVAL; | ||
1550 | goto command_cleanup; | ||
1551 | } | ||
1552 | |||
1553 | /* Everything but endpoint 0 is disabled, so free or cache the rings. */ | ||
1554 | last_freed_endpoint = 1; | ||
1555 | for (i = 1; i < 31; ++i) { | ||
1556 | if (!virt_dev->eps[i].ring) | ||
1557 | continue; | ||
1558 | xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); | ||
1559 | last_freed_endpoint = i; | ||
1560 | } | ||
1561 | xhci_dbg(xhci, "Output context after successful reset device cmd:\n"); | ||
1562 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint); | ||
1563 | ret = 0; | ||
1564 | |||
1565 | command_cleanup: | ||
1566 | xhci_free_command(xhci, reset_device_cmd); | ||
1567 | return ret; | ||
1568 | } | ||
1569 | |||
1570 | /* | ||
1446 | * At this point, the struct usb_device is about to go away, the device has | 1571 | * At this point, the struct usb_device is about to go away, the device has |
1447 | * disconnected, and all traffic has been stopped and the endpoints have been | 1572 | * disconnected, and all traffic has been stopped and the endpoints have been |
1448 | * disabled. Free any HC data structures associated with that device. | 1573 | * disabled. Free any HC data structures associated with that device. |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index f43e073dee96..6ba841bca4a2 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -953,6 +953,17 @@ bandwidth_change: | |||
953 | case TRB_TYPE(TRB_RESET_EP): | 953 | case TRB_TYPE(TRB_RESET_EP): |
954 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); | 954 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); |
955 | break; | 955 | break; |
956 | case TRB_TYPE(TRB_RESET_DEV): | ||
957 | xhci_dbg(xhci, "Completed reset device command.\n"); | ||
958 | slot_id = TRB_TO_SLOT_ID( | ||
959 | xhci->cmd_ring->dequeue->generic.field[3]); | ||
960 | virt_dev = xhci->devs[slot_id]; | ||
961 | if (virt_dev) | ||
962 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, event); | ||
963 | else | ||
964 | xhci_warn(xhci, "Reset device command completion " | ||
965 | "for disabled slot %u\n", slot_id); | ||
966 | break; | ||
956 | default: | 967 | default: |
957 | /* Skip over unknown commands on the event ring */ | 968 | /* Skip over unknown commands on the event ring */ |
958 | xhci->error_bitmask |= 1 << 6; | 969 | xhci->error_bitmask |= 1 << 6; |
@@ -2189,6 +2200,14 @@ int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | |||
2189 | false); | 2200 | false); |
2190 | } | 2201 | } |
2191 | 2202 | ||
2203 | /* Queue a reset device command TRB */ | ||
2204 | int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id) | ||
2205 | { | ||
2206 | return queue_command(xhci, 0, 0, 0, | ||
2207 | TRB_TYPE(TRB_RESET_DEV) | SLOT_ID_FOR_TRB(slot_id), | ||
2208 | false); | ||
2209 | } | ||
2210 | |||
2192 | /* Queue a configure endpoint command TRB */ | 2211 | /* Queue a configure endpoint command TRB */ |
2193 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 2212 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
2194 | u32 slot_id, bool command_must_succeed) | 2213 | u32 slot_id, bool command_must_succeed) |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 20122ec75d94..feb0101f91eb 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -1210,6 +1210,8 @@ void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst); | |||
1210 | void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci); | 1210 | void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci); |
1211 | void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); | 1211 | void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); |
1212 | void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); | 1212 | void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); |
1213 | inline char *xhci_get_slot_state(struct xhci_hcd *xhci, | ||
1214 | struct xhci_container_ctx *ctx); | ||
1213 | 1215 | ||
1214 | /* xHCI memory management */ | 1216 | /* xHCI memory management */ |
1215 | void xhci_mem_cleanup(struct xhci_hcd *xhci); | 1217 | void xhci_mem_cleanup(struct xhci_hcd *xhci); |
@@ -1298,6 +1300,7 @@ int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | |||
1298 | u32 slot_id); | 1300 | u32 slot_id); |
1299 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | 1301 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, |
1300 | unsigned int ep_index); | 1302 | unsigned int ep_index); |
1303 | int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); | ||
1301 | void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | 1304 | void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, |
1302 | unsigned int slot_id, unsigned int ep_index, | 1305 | unsigned int slot_id, unsigned int ep_index, |
1303 | struct xhci_td *cur_td, struct xhci_dequeue_state *state); | 1306 | struct xhci_td *cur_td, struct xhci_dequeue_state *state); |