aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/xhci-dbg.c5
-rw-r--r--drivers/usb/host/xhci-mem.c61
-rw-r--r--drivers/usb/host/xhci-ring.c4
-rw-r--r--drivers/usb/host/xhci.c148
4 files changed, 151 insertions, 67 deletions
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index f2e7689e11a3..5d5e58fdeccc 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -553,6 +553,11 @@ void xhci_dbg_ctx(struct xhci_hcd *xhci,
553 if (ctx->type == XHCI_CTX_TYPE_INPUT) { 553 if (ctx->type == XHCI_CTX_TYPE_INPUT) {
554 struct xhci_input_control_ctx *ctrl_ctx = 554 struct xhci_input_control_ctx *ctrl_ctx =
555 xhci_get_input_control_ctx(xhci, ctx); 555 xhci_get_input_control_ctx(xhci, ctx);
556 if (!ctrl_ctx) {
557 xhci_warn(xhci, "Could not get input context, bad type.\n");
558 return;
559 }
560
556 xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - drop flags\n", 561 xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - drop flags\n",
557 &ctrl_ctx->drop_flags, (unsigned long long)dma, 562 &ctrl_ctx->drop_flags, (unsigned long long)dma,
558 ctrl_ctx->drop_flags); 563 ctrl_ctx->drop_flags);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 8c0e119efa4e..b0d789e31f96 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -358,11 +358,15 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
358static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, 358static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
359 int type, gfp_t flags) 359 int type, gfp_t flags)
360{ 360{
361 struct xhci_container_ctx *ctx = kzalloc(sizeof(*ctx), flags); 361 struct xhci_container_ctx *ctx;
362
363 if ((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT))
364 return NULL;
365
366 ctx = kzalloc(sizeof(*ctx), flags);
362 if (!ctx) 367 if (!ctx)
363 return NULL; 368 return NULL;
364 369
365 BUG_ON((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT));
366 ctx->type = type; 370 ctx->type = type;
367 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; 371 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024;
368 if (type == XHCI_CTX_TYPE_INPUT) 372 if (type == XHCI_CTX_TYPE_INPUT)
@@ -385,7 +389,9 @@ static void xhci_free_container_ctx(struct xhci_hcd *xhci,
385struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, 389struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci,
386 struct xhci_container_ctx *ctx) 390 struct xhci_container_ctx *ctx)
387{ 391{
388 BUG_ON(ctx->type != XHCI_CTX_TYPE_INPUT); 392 if (ctx->type != XHCI_CTX_TYPE_INPUT)
393 return NULL;
394
389 return (struct xhci_input_control_ctx *)ctx->bytes; 395 return (struct xhci_input_control_ctx *)ctx->bytes;
390} 396}
391 397
@@ -1049,6 +1055,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
1049 struct xhci_ep_ctx *ep0_ctx; 1055 struct xhci_ep_ctx *ep0_ctx;
1050 struct xhci_slot_ctx *slot_ctx; 1056 struct xhci_slot_ctx *slot_ctx;
1051 u32 port_num; 1057 u32 port_num;
1058 u32 max_packets;
1052 struct usb_device *top_dev; 1059 struct usb_device *top_dev;
1053 1060
1054 dev = xhci->devs[udev->slot_id]; 1061 dev = xhci->devs[udev->slot_id];
@@ -1066,15 +1073,20 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
1066 switch (udev->speed) { 1073 switch (udev->speed) {
1067 case USB_SPEED_SUPER: 1074 case USB_SPEED_SUPER:
1068 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); 1075 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS);
1076 max_packets = MAX_PACKET(512);
1069 break; 1077 break;
1070 case USB_SPEED_HIGH: 1078 case USB_SPEED_HIGH:
1071 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); 1079 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS);
1080 max_packets = MAX_PACKET(64);
1072 break; 1081 break;
1082 /* USB core guesses at a 64-byte max packet first for FS devices */
1073 case USB_SPEED_FULL: 1083 case USB_SPEED_FULL:
1074 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); 1084 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS);
1085 max_packets = MAX_PACKET(64);
1075 break; 1086 break;
1076 case USB_SPEED_LOW: 1087 case USB_SPEED_LOW:
1077 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); 1088 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS);
1089 max_packets = MAX_PACKET(8);
1078 break; 1090 break;
1079 case USB_SPEED_WIRELESS: 1091 case USB_SPEED_WIRELESS:
1080 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 1092 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -1082,7 +1094,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
1082 break; 1094 break;
1083 default: 1095 default:
1084 /* Speed was set earlier, this shouldn't happen. */ 1096 /* Speed was set earlier, this shouldn't happen. */
1085 BUG(); 1097 return -EINVAL;
1086 } 1098 }
1087 /* Find the root hub port this device is under */ 1099 /* Find the root hub port this device is under */
1088 port_num = xhci_find_real_port_number(xhci, udev); 1100 port_num = xhci_find_real_port_number(xhci, udev);
@@ -1141,31 +1153,10 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
1141 /* Step 4 - ring already allocated */ 1153 /* Step 4 - ring already allocated */
1142 /* Step 5 */ 1154 /* Step 5 */
1143 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); 1155 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP));
1144 /* 1156
1145 * XXX: Not sure about wireless USB devices.
1146 */
1147 switch (udev->speed) {
1148 case USB_SPEED_SUPER:
1149 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(512));
1150 break;
1151 case USB_SPEED_HIGH:
1152 /* USB core guesses at a 64-byte max packet first for FS devices */
1153 case USB_SPEED_FULL:
1154 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(64));
1155 break;
1156 case USB_SPEED_LOW:
1157 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(8));
1158 break;
1159 case USB_SPEED_WIRELESS:
1160 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
1161 return -EINVAL;
1162 break;
1163 default:
1164 /* New speed? */
1165 BUG();
1166 }
1167 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ 1157 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
1168 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3)); 1158 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) |
1159 max_packets);
1169 1160
1170 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | 1161 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma |
1171 dev->eps[0].ring->cycle_state); 1162 dev->eps[0].ring->cycle_state);
@@ -1338,7 +1329,7 @@ static u32 xhci_get_endpoint_type(struct usb_device *udev,
1338 else 1329 else
1339 type = EP_TYPE(INT_OUT_EP); 1330 type = EP_TYPE(INT_OUT_EP);
1340 } else { 1331 } else {
1341 BUG(); 1332 type = 0;
1342 } 1333 }
1343 return type; 1334 return type;
1344} 1335}
@@ -1384,10 +1375,16 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1384 unsigned int max_burst; 1375 unsigned int max_burst;
1385 enum xhci_ring_type type; 1376 enum xhci_ring_type type;
1386 u32 max_esit_payload; 1377 u32 max_esit_payload;
1378 u32 endpoint_type;
1387 1379
1388 ep_index = xhci_get_endpoint_index(&ep->desc); 1380 ep_index = xhci_get_endpoint_index(&ep->desc);
1389 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 1381 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1390 1382
1383 endpoint_type = xhci_get_endpoint_type(udev, ep);
1384 if (!endpoint_type)
1385 return -EINVAL;
1386 ep_ctx->ep_info2 = cpu_to_le32(endpoint_type);
1387
1391 type = usb_endpoint_type(&ep->desc); 1388 type = usb_endpoint_type(&ep->desc);
1392 /* Set up the endpoint ring */ 1389 /* Set up the endpoint ring */
1393 virt_dev->eps[ep_index].new_ring = 1390 virt_dev->eps[ep_index].new_ring =
@@ -1416,11 +1413,9 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1416 * CErr shall be set to 0 for Isoch endpoints. 1413 * CErr shall be set to 0 for Isoch endpoints.
1417 */ 1414 */
1418 if (!usb_endpoint_xfer_isoc(&ep->desc)) 1415 if (!usb_endpoint_xfer_isoc(&ep->desc))
1419 ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(3)); 1416 ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(3));
1420 else 1417 else
1421 ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(0)); 1418 ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(0));
1422
1423 ep_ctx->ep_info2 |= cpu_to_le32(xhci_get_endpoint_type(udev, ep));
1424 1419
1425 /* Set the max packet size and max burst */ 1420 /* Set the max packet size and max burst */
1426 max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)); 1421 max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc));
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index e02b90746e84..1e57eafa6910 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1424,6 +1424,10 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1424 */ 1424 */
1425 ctrl_ctx = xhci_get_input_control_ctx(xhci, 1425 ctrl_ctx = xhci_get_input_control_ctx(xhci,
1426 virt_dev->in_ctx); 1426 virt_dev->in_ctx);
1427 if (!ctrl_ctx) {
1428 xhci_warn(xhci, "Could not get input context, bad type.\n");
1429 break;
1430 }
1427 /* Input ctx add_flags are the endpoint index plus one */ 1431 /* Input ctx add_flags are the endpoint index plus one */
1428 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1; 1432 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
1429 /* A usb_set_interface() call directly after clearing a halted 1433 /* A usb_set_interface() call directly after clearing a halted
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 77113c1fcb96..6779c926e3b0 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1235,19 +1235,25 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
1235 hw_max_packet_size); 1235 hw_max_packet_size);
1236 xhci_dbg(xhci, "Issuing evaluate context command.\n"); 1236 xhci_dbg(xhci, "Issuing evaluate context command.\n");
1237 1237
1238 /* Set up the input context flags for the command */
1239 /* FIXME: This won't work if a non-default control endpoint
1240 * changes max packet sizes.
1241 */
1242 in_ctx = xhci->devs[slot_id]->in_ctx;
1243 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1244 if (!ctrl_ctx) {
1245 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
1246 __func__);
1247 return -ENOMEM;
1248 }
1238 /* Set up the modified control endpoint 0 */ 1249 /* Set up the modified control endpoint 0 */
1239 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, 1250 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx,
1240 xhci->devs[slot_id]->out_ctx, ep_index); 1251 xhci->devs[slot_id]->out_ctx, ep_index);
1241 in_ctx = xhci->devs[slot_id]->in_ctx; 1252
1242 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); 1253 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
1243 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); 1254 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK);
1244 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); 1255 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size));
1245 1256
1246 /* Set up the input context flags for the command */
1247 /* FIXME: This won't work if a non-default control endpoint
1248 * changes max packet sizes.
1249 */
1250 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1251 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); 1257 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG);
1252 ctrl_ctx->drop_flags = 0; 1258 ctrl_ctx->drop_flags = 0;
1253 1259
@@ -1607,6 +1613,12 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1607 in_ctx = xhci->devs[udev->slot_id]->in_ctx; 1613 in_ctx = xhci->devs[udev->slot_id]->in_ctx;
1608 out_ctx = xhci->devs[udev->slot_id]->out_ctx; 1614 out_ctx = xhci->devs[udev->slot_id]->out_ctx;
1609 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1615 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1616 if (!ctrl_ctx) {
1617 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
1618 __func__);
1619 return 0;
1620 }
1621
1610 ep_index = xhci_get_endpoint_index(&ep->desc); 1622 ep_index = xhci_get_endpoint_index(&ep->desc);
1611 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); 1623 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
1612 /* If the HC already knows the endpoint is disabled, 1624 /* If the HC already knows the endpoint is disabled,
@@ -1701,8 +1713,13 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1701 in_ctx = virt_dev->in_ctx; 1713 in_ctx = virt_dev->in_ctx;
1702 out_ctx = virt_dev->out_ctx; 1714 out_ctx = virt_dev->out_ctx;
1703 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 1715 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1704 ep_index = xhci_get_endpoint_index(&ep->desc); 1716 if (!ctrl_ctx) {
1717 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
1718 __func__);
1719 return 0;
1720 }
1705 1721
1722 ep_index = xhci_get_endpoint_index(&ep->desc);
1706 /* If this endpoint is already in use, and the upper layers are trying 1723 /* If this endpoint is already in use, and the upper layers are trying
1707 * to add it again without dropping it, reject the addition. 1724 * to add it again without dropping it, reject the addition.
1708 */ 1725 */
@@ -1775,12 +1792,18 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir
1775 struct xhci_slot_ctx *slot_ctx; 1792 struct xhci_slot_ctx *slot_ctx;
1776 int i; 1793 int i;
1777 1794
1795 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1796 if (!ctrl_ctx) {
1797 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
1798 __func__);
1799 return;
1800 }
1801
1778 /* When a device's add flag and drop flag are zero, any subsequent 1802 /* When a device's add flag and drop flag are zero, any subsequent
1779 * configure endpoint command will leave that endpoint's state 1803 * configure endpoint command will leave that endpoint's state
1780 * untouched. Make sure we don't leave any old state in the input 1804 * untouched. Make sure we don't leave any old state in the input
1781 * endpoint contexts. 1805 * endpoint contexts.
1782 */ 1806 */
1783 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1784 ctrl_ctx->drop_flags = 0; 1807 ctrl_ctx->drop_flags = 0;
1785 ctrl_ctx->add_flags = 0; 1808 ctrl_ctx->add_flags = 0;
1786 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 1809 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
@@ -1887,13 +1910,11 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1887} 1910}
1888 1911
1889static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, 1912static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci,
1890 struct xhci_container_ctx *in_ctx) 1913 struct xhci_input_control_ctx *ctrl_ctx)
1891{ 1914{
1892 struct xhci_input_control_ctx *ctrl_ctx;
1893 u32 valid_add_flags; 1915 u32 valid_add_flags;
1894 u32 valid_drop_flags; 1916 u32 valid_drop_flags;
1895 1917
1896 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1897 /* Ignore the slot flag (bit 0), and the default control endpoint flag 1918 /* Ignore the slot flag (bit 0), and the default control endpoint flag
1898 * (bit 1). The default control endpoint is added during the Address 1919 * (bit 1). The default control endpoint is added during the Address
1899 * Device command and is never removed until the slot is disabled. 1920 * Device command and is never removed until the slot is disabled.
@@ -1910,13 +1931,11 @@ static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci,
1910} 1931}
1911 1932
1912static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, 1933static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci,
1913 struct xhci_container_ctx *in_ctx) 1934 struct xhci_input_control_ctx *ctrl_ctx)
1914{ 1935{
1915 struct xhci_input_control_ctx *ctrl_ctx;
1916 u32 valid_add_flags; 1936 u32 valid_add_flags;
1917 u32 valid_drop_flags; 1937 u32 valid_drop_flags;
1918 1938
1919 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1920 valid_add_flags = ctrl_ctx->add_flags >> 2; 1939 valid_add_flags = ctrl_ctx->add_flags >> 2;
1921 valid_drop_flags = ctrl_ctx->drop_flags >> 2; 1940 valid_drop_flags = ctrl_ctx->drop_flags >> 2;
1922 1941
@@ -1938,11 +1957,11 @@ static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci,
1938 * Must be called with xhci->lock held. 1957 * Must be called with xhci->lock held.
1939 */ 1958 */
1940static int xhci_reserve_host_resources(struct xhci_hcd *xhci, 1959static int xhci_reserve_host_resources(struct xhci_hcd *xhci,
1941 struct xhci_container_ctx *in_ctx) 1960 struct xhci_input_control_ctx *ctrl_ctx)
1942{ 1961{
1943 u32 added_eps; 1962 u32 added_eps;
1944 1963
1945 added_eps = xhci_count_num_new_endpoints(xhci, in_ctx); 1964 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx);
1946 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { 1965 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) {
1947 xhci_dbg(xhci, "Not enough ep ctxs: " 1966 xhci_dbg(xhci, "Not enough ep ctxs: "
1948 "%u active, need to add %u, limit is %u.\n", 1967 "%u active, need to add %u, limit is %u.\n",
@@ -1963,11 +1982,11 @@ static int xhci_reserve_host_resources(struct xhci_hcd *xhci,
1963 * Must be called with xhci->lock held. 1982 * Must be called with xhci->lock held.
1964 */ 1983 */
1965static void xhci_free_host_resources(struct xhci_hcd *xhci, 1984static void xhci_free_host_resources(struct xhci_hcd *xhci,
1966 struct xhci_container_ctx *in_ctx) 1985 struct xhci_input_control_ctx *ctrl_ctx)
1967{ 1986{
1968 u32 num_failed_eps; 1987 u32 num_failed_eps;
1969 1988
1970 num_failed_eps = xhci_count_num_new_endpoints(xhci, in_ctx); 1989 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx);
1971 xhci->num_active_eps -= num_failed_eps; 1990 xhci->num_active_eps -= num_failed_eps;
1972 xhci_dbg(xhci, "Removing %u failed ep ctxs, %u now active.\n", 1991 xhci_dbg(xhci, "Removing %u failed ep ctxs, %u now active.\n",
1973 num_failed_eps, 1992 num_failed_eps,
@@ -1981,11 +2000,11 @@ static void xhci_free_host_resources(struct xhci_hcd *xhci,
1981 * Must be called with xhci->lock held. 2000 * Must be called with xhci->lock held.
1982 */ 2001 */
1983static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, 2002static void xhci_finish_resource_reservation(struct xhci_hcd *xhci,
1984 struct xhci_container_ctx *in_ctx) 2003 struct xhci_input_control_ctx *ctrl_ctx)
1985{ 2004{
1986 u32 num_dropped_eps; 2005 u32 num_dropped_eps;
1987 2006
1988 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, in_ctx); 2007 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx);
1989 xhci->num_active_eps -= num_dropped_eps; 2008 xhci->num_active_eps -= num_dropped_eps;
1990 if (num_dropped_eps) 2009 if (num_dropped_eps)
1991 xhci_dbg(xhci, "Removing %u dropped ep ctxs, %u now active.\n", 2010 xhci_dbg(xhci, "Removing %u dropped ep ctxs, %u now active.\n",
@@ -2480,6 +2499,11 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci,
2480 old_active_eps = virt_dev->tt_info->active_eps; 2499 old_active_eps = virt_dev->tt_info->active_eps;
2481 2500
2482 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); 2501 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
2502 if (!ctrl_ctx) {
2503 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
2504 __func__);
2505 return -ENOMEM;
2506 }
2483 2507
2484 for (i = 0; i < 31; i++) { 2508 for (i = 0; i < 31; i++) {
2485 if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i)) 2509 if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i))
@@ -2564,6 +2588,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2564 int timeleft; 2588 int timeleft;
2565 unsigned long flags; 2589 unsigned long flags;
2566 struct xhci_container_ctx *in_ctx; 2590 struct xhci_container_ctx *in_ctx;
2591 struct xhci_input_control_ctx *ctrl_ctx;
2567 struct completion *cmd_completion; 2592 struct completion *cmd_completion;
2568 u32 *cmd_status; 2593 u32 *cmd_status;
2569 struct xhci_virt_device *virt_dev; 2594 struct xhci_virt_device *virt_dev;
@@ -2576,9 +2601,15 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2576 in_ctx = command->in_ctx; 2601 in_ctx = command->in_ctx;
2577 else 2602 else
2578 in_ctx = virt_dev->in_ctx; 2603 in_ctx = virt_dev->in_ctx;
2604 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
2605 if (!ctrl_ctx) {
2606 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
2607 __func__);
2608 return -ENOMEM;
2609 }
2579 2610
2580 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && 2611 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) &&
2581 xhci_reserve_host_resources(xhci, in_ctx)) { 2612 xhci_reserve_host_resources(xhci, ctrl_ctx)) {
2582 spin_unlock_irqrestore(&xhci->lock, flags); 2613 spin_unlock_irqrestore(&xhci->lock, flags);
2583 xhci_warn(xhci, "Not enough host resources, " 2614 xhci_warn(xhci, "Not enough host resources, "
2584 "active endpoint contexts = %u\n", 2615 "active endpoint contexts = %u\n",
@@ -2588,7 +2619,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2588 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && 2619 if ((xhci->quirks & XHCI_SW_BW_CHECKING) &&
2589 xhci_reserve_bandwidth(xhci, virt_dev, in_ctx)) { 2620 xhci_reserve_bandwidth(xhci, virt_dev, in_ctx)) {
2590 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) 2621 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK))
2591 xhci_free_host_resources(xhci, in_ctx); 2622 xhci_free_host_resources(xhci, ctrl_ctx);
2592 spin_unlock_irqrestore(&xhci->lock, flags); 2623 spin_unlock_irqrestore(&xhci->lock, flags);
2593 xhci_warn(xhci, "Not enough bandwidth\n"); 2624 xhci_warn(xhci, "Not enough bandwidth\n");
2594 return -ENOMEM; 2625 return -ENOMEM;
@@ -2624,7 +2655,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2624 if (command) 2655 if (command)
2625 list_del(&command->cmd_list); 2656 list_del(&command->cmd_list);
2626 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) 2657 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK))
2627 xhci_free_host_resources(xhci, in_ctx); 2658 xhci_free_host_resources(xhci, ctrl_ctx);
2628 spin_unlock_irqrestore(&xhci->lock, flags); 2659 spin_unlock_irqrestore(&xhci->lock, flags);
2629 xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); 2660 xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
2630 return -ENOMEM; 2661 return -ENOMEM;
@@ -2660,9 +2691,9 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2660 * Otherwise, clean up the estimate to include dropped eps. 2691 * Otherwise, clean up the estimate to include dropped eps.
2661 */ 2692 */
2662 if (ret) 2693 if (ret)
2663 xhci_free_host_resources(xhci, in_ctx); 2694 xhci_free_host_resources(xhci, ctrl_ctx);
2664 else 2695 else
2665 xhci_finish_resource_reservation(xhci, in_ctx); 2696 xhci_finish_resource_reservation(xhci, ctrl_ctx);
2666 spin_unlock_irqrestore(&xhci->lock, flags); 2697 spin_unlock_irqrestore(&xhci->lock, flags);
2667 } 2698 }
2668 return ret; 2699 return ret;
@@ -2699,6 +2730,11 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
2699 2730
2700 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ 2731 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */
2701 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); 2732 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
2733 if (!ctrl_ctx) {
2734 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
2735 __func__);
2736 return -ENOMEM;
2737 }
2702 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); 2738 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
2703 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); 2739 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG);
2704 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); 2740 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG));
@@ -2777,10 +2813,9 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
2777static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, 2813static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci,
2778 struct xhci_container_ctx *in_ctx, 2814 struct xhci_container_ctx *in_ctx,
2779 struct xhci_container_ctx *out_ctx, 2815 struct xhci_container_ctx *out_ctx,
2816 struct xhci_input_control_ctx *ctrl_ctx,
2780 u32 add_flags, u32 drop_flags) 2817 u32 add_flags, u32 drop_flags)
2781{ 2818{
2782 struct xhci_input_control_ctx *ctrl_ctx;
2783 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
2784 ctrl_ctx->add_flags = cpu_to_le32(add_flags); 2819 ctrl_ctx->add_flags = cpu_to_le32(add_flags);
2785 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); 2820 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags);
2786 xhci_slot_copy(xhci, in_ctx, out_ctx); 2821 xhci_slot_copy(xhci, in_ctx, out_ctx);
@@ -2794,14 +2829,22 @@ static void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
2794 unsigned int slot_id, unsigned int ep_index, 2829 unsigned int slot_id, unsigned int ep_index,
2795 struct xhci_dequeue_state *deq_state) 2830 struct xhci_dequeue_state *deq_state)
2796{ 2831{
2832 struct xhci_input_control_ctx *ctrl_ctx;
2797 struct xhci_container_ctx *in_ctx; 2833 struct xhci_container_ctx *in_ctx;
2798 struct xhci_ep_ctx *ep_ctx; 2834 struct xhci_ep_ctx *ep_ctx;
2799 u32 added_ctxs; 2835 u32 added_ctxs;
2800 dma_addr_t addr; 2836 dma_addr_t addr;
2801 2837
2838 in_ctx = xhci->devs[slot_id]->in_ctx;
2839 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
2840 if (!ctrl_ctx) {
2841 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
2842 __func__);
2843 return;
2844 }
2845
2802 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, 2846 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx,
2803 xhci->devs[slot_id]->out_ctx, ep_index); 2847 xhci->devs[slot_id]->out_ctx, ep_index);
2804 in_ctx = xhci->devs[slot_id]->in_ctx;
2805 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); 2848 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
2806 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg, 2849 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg,
2807 deq_state->new_deq_ptr); 2850 deq_state->new_deq_ptr);
@@ -2817,7 +2860,8 @@ static void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
2817 2860
2818 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index); 2861 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index);
2819 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx, 2862 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx,
2820 xhci->devs[slot_id]->out_ctx, added_ctxs, added_ctxs); 2863 xhci->devs[slot_id]->out_ctx, ctrl_ctx,
2864 added_ctxs, added_ctxs);
2821} 2865}
2822 2866
2823void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, 2867void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
@@ -3075,6 +3119,7 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
3075 struct xhci_hcd *xhci; 3119 struct xhci_hcd *xhci;
3076 struct xhci_virt_device *vdev; 3120 struct xhci_virt_device *vdev;
3077 struct xhci_command *config_cmd; 3121 struct xhci_command *config_cmd;
3122 struct xhci_input_control_ctx *ctrl_ctx;
3078 unsigned int ep_index; 3123 unsigned int ep_index;
3079 unsigned int num_stream_ctxs; 3124 unsigned int num_stream_ctxs;
3080 unsigned long flags; 3125 unsigned long flags;
@@ -3096,6 +3141,13 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
3096 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n"); 3141 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n");
3097 return -ENOMEM; 3142 return -ENOMEM;
3098 } 3143 }
3144 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx);
3145 if (!ctrl_ctx) {
3146 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
3147 __func__);
3148 xhci_free_command(xhci, config_cmd);
3149 return -ENOMEM;
3150 }
3099 3151
3100 /* Check to make sure all endpoints are not already configured for 3152 /* Check to make sure all endpoints are not already configured for
3101 * streams. While we're at it, find the maximum number of streams that 3153 * streams. While we're at it, find the maximum number of streams that
@@ -3162,7 +3214,8 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
3162 * and add the updated copy from the input context. 3214 * and add the updated copy from the input context.
3163 */ 3215 */
3164 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, 3216 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx,
3165 vdev->out_ctx, changed_ep_bitmask, changed_ep_bitmask); 3217 vdev->out_ctx, ctrl_ctx,
3218 changed_ep_bitmask, changed_ep_bitmask);
3166 3219
3167 /* Issue and wait for the configure endpoint command */ 3220 /* Issue and wait for the configure endpoint command */
3168 ret = xhci_configure_endpoint(xhci, udev, config_cmd, 3221 ret = xhci_configure_endpoint(xhci, udev, config_cmd,
@@ -3220,6 +3273,7 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
3220 struct xhci_hcd *xhci; 3273 struct xhci_hcd *xhci;
3221 struct xhci_virt_device *vdev; 3274 struct xhci_virt_device *vdev;
3222 struct xhci_command *command; 3275 struct xhci_command *command;
3276 struct xhci_input_control_ctx *ctrl_ctx;
3223 unsigned int ep_index; 3277 unsigned int ep_index;
3224 unsigned long flags; 3278 unsigned long flags;
3225 u32 changed_ep_bitmask; 3279 u32 changed_ep_bitmask;
@@ -3242,6 +3296,13 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
3242 */ 3296 */
3243 ep_index = xhci_get_endpoint_index(&eps[0]->desc); 3297 ep_index = xhci_get_endpoint_index(&eps[0]->desc);
3244 command = vdev->eps[ep_index].stream_info->free_streams_command; 3298 command = vdev->eps[ep_index].stream_info->free_streams_command;
3299 ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx);
3300 if (!ctrl_ctx) {
3301 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
3302 __func__);
3303 return -EINVAL;
3304 }
3305
3245 for (i = 0; i < num_eps; i++) { 3306 for (i = 0; i < num_eps; i++) {
3246 struct xhci_ep_ctx *ep_ctx; 3307 struct xhci_ep_ctx *ep_ctx;
3247 3308
@@ -3256,7 +3317,8 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
3256 &vdev->eps[ep_index]); 3317 &vdev->eps[ep_index]);
3257 } 3318 }
3258 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, 3319 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx,
3259 vdev->out_ctx, changed_ep_bitmask, changed_ep_bitmask); 3320 vdev->out_ctx, ctrl_ctx,
3321 changed_ep_bitmask, changed_ep_bitmask);
3260 spin_unlock_irqrestore(&xhci->lock, flags); 3322 spin_unlock_irqrestore(&xhci->lock, flags);
3261 3323
3262 /* Issue and wait for the configure endpoint command, 3324 /* Issue and wait for the configure endpoint command,
@@ -3696,6 +3758,12 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3696 } 3758 }
3697 3759
3698 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 3760 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
3761 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
3762 if (!ctrl_ctx) {
3763 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
3764 __func__);
3765 return -EINVAL;
3766 }
3699 /* 3767 /*
3700 * If this is the first Set Address since device plug-in or 3768 * If this is the first Set Address since device plug-in or
3701 * virt_device realloaction after a resume with an xHCI power loss, 3769 * virt_device realloaction after a resume with an xHCI power loss,
@@ -3706,7 +3774,6 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3706 /* Otherwise, update the control endpoint ring enqueue pointer. */ 3774 /* Otherwise, update the control endpoint ring enqueue pointer. */
3707 else 3775 else
3708 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); 3776 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev);
3709 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
3710 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); 3777 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
3711 ctrl_ctx->drop_flags = 0; 3778 ctrl_ctx->drop_flags = 0;
3712 3779
@@ -3848,10 +3915,17 @@ static int xhci_change_max_exit_latency(struct xhci_hcd *xhci,
3848 /* Attempt to issue an Evaluate Context command to change the MEL. */ 3915 /* Attempt to issue an Evaluate Context command to change the MEL. */
3849 virt_dev = xhci->devs[udev->slot_id]; 3916 virt_dev = xhci->devs[udev->slot_id];
3850 command = xhci->lpm_command; 3917 command = xhci->lpm_command;
3918 ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx);
3919 if (!ctrl_ctx) {
3920 spin_unlock_irqrestore(&xhci->lock, flags);
3921 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
3922 __func__);
3923 return -ENOMEM;
3924 }
3925
3851 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); 3926 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx);
3852 spin_unlock_irqrestore(&xhci->lock, flags); 3927 spin_unlock_irqrestore(&xhci->lock, flags);
3853 3928
3854 ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx);
3855 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); 3929 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
3856 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); 3930 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx);
3857 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); 3931 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT));
@@ -4677,6 +4751,13 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
4677 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n"); 4751 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n");
4678 return -ENOMEM; 4752 return -ENOMEM;
4679 } 4753 }
4754 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx);
4755 if (!ctrl_ctx) {
4756 xhci_warn(xhci, "%s: Could not get input context, bad type.\n",
4757 __func__);
4758 xhci_free_command(xhci, config_cmd);
4759 return -ENOMEM;
4760 }
4680 4761
4681 spin_lock_irqsave(&xhci->lock, flags); 4762 spin_lock_irqsave(&xhci->lock, flags);
4682 if (hdev->speed == USB_SPEED_HIGH && 4763 if (hdev->speed == USB_SPEED_HIGH &&
@@ -4688,7 +4769,6 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
4688 } 4769 }
4689 4770
4690 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); 4771 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx);
4691 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx);
4692 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); 4772 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
4693 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); 4773 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx);
4694 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); 4774 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB);