aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-hcd.c
diff options
context:
space:
mode:
authorJohn Youn <johnyoun@synopsys.com>2009-07-27 15:05:15 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-07-28 17:31:13 -0400
commitd115b04818e57bdbc7ccde4d0660b15e33013dc8 (patch)
tree48b699c9b81fb0570d03009f353225faad238c64 /drivers/usb/host/xhci-hcd.c
parent28c2d2efb48dec2f0b050affae6d5787d6449e47 (diff)
USB: xhci: Support for 64-byte contexts
Adds support for controllers that use 64-byte contexts. The following context data structures are affected by this: Device, Input, Input Control, Endpoint, and Slot. To accommodate the use of either 32 or 64-byte contexts, a Device or Input context can only be accessed through functions which look-up and return pointers to their contained contexts. Signed-off-by: John Youn <johnyoun@synopsys.com> Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/xhci-hcd.c')
-rw-r--r--drivers/usb/host/xhci-hcd.c121
1 files changed, 71 insertions, 50 deletions
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
index 921dd173d793..057a07e876be 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci-hcd.c
@@ -722,7 +722,9 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
722 struct usb_host_endpoint *ep) 722 struct usb_host_endpoint *ep)
723{ 723{
724 struct xhci_hcd *xhci; 724 struct xhci_hcd *xhci;
725 struct xhci_device_control *in_ctx; 725 struct xhci_container_ctx *in_ctx, *out_ctx;
726 struct xhci_input_control_ctx *ctrl_ctx;
727 struct xhci_slot_ctx *slot_ctx;
726 unsigned int last_ctx; 728 unsigned int last_ctx;
727 unsigned int ep_index; 729 unsigned int ep_index;
728 struct xhci_ep_ctx *ep_ctx; 730 struct xhci_ep_ctx *ep_ctx;
@@ -750,31 +752,34 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
750 } 752 }
751 753
752 in_ctx = xhci->devs[udev->slot_id]->in_ctx; 754 in_ctx = xhci->devs[udev->slot_id]->in_ctx;
755 out_ctx = xhci->devs[udev->slot_id]->out_ctx;
756 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
753 ep_index = xhci_get_endpoint_index(&ep->desc); 757 ep_index = xhci_get_endpoint_index(&ep->desc);
754 ep_ctx = &xhci->devs[udev->slot_id]->out_ctx->ep[ep_index]; 758 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
755 /* If the HC already knows the endpoint is disabled, 759 /* If the HC already knows the endpoint is disabled,
756 * or the HCD has noted it is disabled, ignore this request 760 * or the HCD has noted it is disabled, ignore this request
757 */ 761 */
758 if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED || 762 if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED ||
759 in_ctx->drop_flags & xhci_get_endpoint_flag(&ep->desc)) { 763 ctrl_ctx->drop_flags & xhci_get_endpoint_flag(&ep->desc)) {
760 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", 764 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n",
761 __func__, ep); 765 __func__, ep);
762 return 0; 766 return 0;
763 } 767 }
764 768
765 in_ctx->drop_flags |= drop_flag; 769 ctrl_ctx->drop_flags |= drop_flag;
766 new_drop_flags = in_ctx->drop_flags; 770 new_drop_flags = ctrl_ctx->drop_flags;
767 771
768 in_ctx->add_flags = ~drop_flag; 772 ctrl_ctx->add_flags = ~drop_flag;
769 new_add_flags = in_ctx->add_flags; 773 new_add_flags = ctrl_ctx->add_flags;
770 774
771 last_ctx = xhci_last_valid_endpoint(in_ctx->add_flags); 775 last_ctx = xhci_last_valid_endpoint(ctrl_ctx->add_flags);
776 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
772 /* Update the last valid endpoint context, if we deleted the last one */ 777 /* Update the last valid endpoint context, if we deleted the last one */
773 if ((in_ctx->slot.dev_info & LAST_CTX_MASK) > LAST_CTX(last_ctx)) { 778 if ((slot_ctx->dev_info & LAST_CTX_MASK) > LAST_CTX(last_ctx)) {
774 in_ctx->slot.dev_info &= ~LAST_CTX_MASK; 779 slot_ctx->dev_info &= ~LAST_CTX_MASK;
775 in_ctx->slot.dev_info |= LAST_CTX(last_ctx); 780 slot_ctx->dev_info |= LAST_CTX(last_ctx);
776 } 781 }
777 new_slot_info = in_ctx->slot.dev_info; 782 new_slot_info = slot_ctx->dev_info;
778 783
779 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); 784 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
780 785
@@ -804,9 +809,11 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
804 struct usb_host_endpoint *ep) 809 struct usb_host_endpoint *ep)
805{ 810{
806 struct xhci_hcd *xhci; 811 struct xhci_hcd *xhci;
807 struct xhci_device_control *in_ctx; 812 struct xhci_container_ctx *in_ctx, *out_ctx;
808 unsigned int ep_index; 813 unsigned int ep_index;
809 struct xhci_ep_ctx *ep_ctx; 814 struct xhci_ep_ctx *ep_ctx;
815 struct xhci_slot_ctx *slot_ctx;
816 struct xhci_input_control_ctx *ctrl_ctx;
810 u32 added_ctxs; 817 u32 added_ctxs;
811 unsigned int last_ctx; 818 unsigned int last_ctx;
812 u32 new_add_flags, new_drop_flags, new_slot_info; 819 u32 new_add_flags, new_drop_flags, new_slot_info;
@@ -839,12 +846,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
839 } 846 }
840 847
841 in_ctx = xhci->devs[udev->slot_id]->in_ctx; 848 in_ctx = xhci->devs[udev->slot_id]->in_ctx;
849 out_ctx = xhci->devs[udev->slot_id]->out_ctx;
850 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
842 ep_index = xhci_get_endpoint_index(&ep->desc); 851 ep_index = xhci_get_endpoint_index(&ep->desc);
843 ep_ctx = &xhci->devs[udev->slot_id]->out_ctx->ep[ep_index]; 852 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
844 /* If the HCD has already noted the endpoint is enabled, 853 /* If the HCD has already noted the endpoint is enabled,
845 * ignore this request. 854 * ignore this request.
846 */ 855 */
847 if (in_ctx->add_flags & xhci_get_endpoint_flag(&ep->desc)) { 856 if (ctrl_ctx->add_flags & xhci_get_endpoint_flag(&ep->desc)) {
848 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", 857 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n",
849 __func__, ep); 858 __func__, ep);
850 return 0; 859 return 0;
@@ -862,8 +871,8 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
862 return -ENOMEM; 871 return -ENOMEM;
863 } 872 }
864 873
865 in_ctx->add_flags |= added_ctxs; 874 ctrl_ctx->add_flags |= added_ctxs;
866 new_add_flags = in_ctx->add_flags; 875 new_add_flags = ctrl_ctx->add_flags;
867 876
868 /* If xhci_endpoint_disable() was called for this endpoint, but the 877 /* If xhci_endpoint_disable() was called for this endpoint, but the
869 * xHC hasn't been notified yet through the check_bandwidth() call, 878 * xHC hasn't been notified yet through the check_bandwidth() call,
@@ -871,14 +880,15 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
871 * descriptors. We must drop and re-add this endpoint, so we leave the 880 * descriptors. We must drop and re-add this endpoint, so we leave the
872 * drop flags alone. 881 * drop flags alone.
873 */ 882 */
874 new_drop_flags = in_ctx->drop_flags; 883 new_drop_flags = ctrl_ctx->drop_flags;
875 884
885 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
876 /* Update the last valid endpoint context, if we just added one past */ 886 /* Update the last valid endpoint context, if we just added one past */
877 if ((in_ctx->slot.dev_info & LAST_CTX_MASK) < LAST_CTX(last_ctx)) { 887 if ((slot_ctx->dev_info & LAST_CTX_MASK) < LAST_CTX(last_ctx)) {
878 in_ctx->slot.dev_info &= ~LAST_CTX_MASK; 888 slot_ctx->dev_info &= ~LAST_CTX_MASK;
879 in_ctx->slot.dev_info |= LAST_CTX(last_ctx); 889 slot_ctx->dev_info |= LAST_CTX(last_ctx);
880 } 890 }
881 new_slot_info = in_ctx->slot.dev_info; 891 new_slot_info = slot_ctx->dev_info;
882 892
883 /* Store the usb_device pointer for later use */ 893 /* Store the usb_device pointer for later use */
884 ep->hcpriv = udev; 894 ep->hcpriv = udev;
@@ -892,9 +902,11 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
892 return 0; 902 return 0;
893} 903}
894 904
895static void xhci_zero_in_ctx(struct xhci_virt_device *virt_dev) 905static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev)
896{ 906{
907 struct xhci_input_control_ctx *ctrl_ctx;
897 struct xhci_ep_ctx *ep_ctx; 908 struct xhci_ep_ctx *ep_ctx;
909 struct xhci_slot_ctx *slot_ctx;
898 int i; 910 int i;
899 911
900 /* When a device's add flag and drop flag are zero, any subsequent 912 /* When a device's add flag and drop flag are zero, any subsequent
@@ -902,13 +914,15 @@ static void xhci_zero_in_ctx(struct xhci_virt_device *virt_dev)
902 * untouched. Make sure we don't leave any old state in the input 914 * untouched. Make sure we don't leave any old state in the input
903 * endpoint contexts. 915 * endpoint contexts.
904 */ 916 */
905 virt_dev->in_ctx->drop_flags = 0; 917 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
906 virt_dev->in_ctx->add_flags = 0; 918 ctrl_ctx->drop_flags = 0;
907 virt_dev->in_ctx->slot.dev_info &= ~LAST_CTX_MASK; 919 ctrl_ctx->add_flags = 0;
920 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
921 slot_ctx->dev_info &= ~LAST_CTX_MASK;
908 /* Endpoint 0 is always valid */ 922 /* Endpoint 0 is always valid */
909 virt_dev->in_ctx->slot.dev_info |= LAST_CTX(1); 923 slot_ctx->dev_info |= LAST_CTX(1);
910 for (i = 1; i < 31; ++i) { 924 for (i = 1; i < 31; ++i) {
911 ep_ctx = &virt_dev->in_ctx->ep[i]; 925 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i);
912 ep_ctx->ep_info = 0; 926 ep_ctx->ep_info = 0;
913 ep_ctx->ep_info2 = 0; 927 ep_ctx->ep_info2 = 0;
914 ep_ctx->deq = 0; 928 ep_ctx->deq = 0;
@@ -934,6 +948,8 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
934 unsigned long flags; 948 unsigned long flags;
935 struct xhci_hcd *xhci; 949 struct xhci_hcd *xhci;
936 struct xhci_virt_device *virt_dev; 950 struct xhci_virt_device *virt_dev;
951 struct xhci_input_control_ctx *ctrl_ctx;
952 struct xhci_slot_ctx *slot_ctx;
937 953
938 ret = xhci_check_args(hcd, udev, NULL, 0, __func__); 954 ret = xhci_check_args(hcd, udev, NULL, 0, __func__);
939 if (ret <= 0) 955 if (ret <= 0)
@@ -949,16 +965,18 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
949 virt_dev = xhci->devs[udev->slot_id]; 965 virt_dev = xhci->devs[udev->slot_id];
950 966
951 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ 967 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */
952 virt_dev->in_ctx->add_flags |= SLOT_FLAG; 968 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
953 virt_dev->in_ctx->add_flags &= ~EP0_FLAG; 969 ctrl_ctx->add_flags |= SLOT_FLAG;
954 virt_dev->in_ctx->drop_flags &= ~SLOT_FLAG; 970 ctrl_ctx->add_flags &= ~EP0_FLAG;
955 virt_dev->in_ctx->drop_flags &= ~EP0_FLAG; 971 ctrl_ctx->drop_flags &= ~SLOT_FLAG;
972 ctrl_ctx->drop_flags &= ~EP0_FLAG;
956 xhci_dbg(xhci, "New Input Control Context:\n"); 973 xhci_dbg(xhci, "New Input Control Context:\n");
957 xhci_dbg_ctx(xhci, virt_dev->in_ctx, virt_dev->in_ctx_dma, 974 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
958 LAST_CTX_TO_EP_NUM(virt_dev->in_ctx->slot.dev_info)); 975 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
976 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info));
959 977
960 spin_lock_irqsave(&xhci->lock, flags); 978 spin_lock_irqsave(&xhci->lock, flags);
961 ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx_dma, 979 ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma,
962 udev->slot_id); 980 udev->slot_id);
963 if (ret < 0) { 981 if (ret < 0) {
964 spin_unlock_irqrestore(&xhci->lock, flags); 982 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -1013,10 +1031,10 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1013 } 1031 }
1014 1032
1015 xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); 1033 xhci_dbg(xhci, "Output context after successful config ep cmd:\n");
1016 xhci_dbg_device_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 1034 xhci_dbg_ctx(xhci, virt_dev->out_ctx,
1017 LAST_CTX_TO_EP_NUM(virt_dev->in_ctx->slot.dev_info)); 1035 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info));
1018 1036
1019 xhci_zero_in_ctx(virt_dev); 1037 xhci_zero_in_ctx(xhci, virt_dev);
1020 /* Free any old rings */ 1038 /* Free any old rings */
1021 for (i = 1; i < 31; ++i) { 1039 for (i = 1; i < 31; ++i) {
1022 if (virt_dev->new_ep_rings[i]) { 1040 if (virt_dev->new_ep_rings[i]) {
@@ -1054,7 +1072,7 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1054 virt_dev->new_ep_rings[i] = NULL; 1072 virt_dev->new_ep_rings[i] = NULL;
1055 } 1073 }
1056 } 1074 }
1057 xhci_zero_in_ctx(virt_dev); 1075 xhci_zero_in_ctx(xhci, virt_dev);
1058} 1076}
1059 1077
1060/* Deal with stalled endpoints. The core should have sent the control message 1078/* Deal with stalled endpoints. The core should have sent the control message
@@ -1187,6 +1205,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1187 struct xhci_virt_device *virt_dev; 1205 struct xhci_virt_device *virt_dev;
1188 int ret = 0; 1206 int ret = 0;
1189 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1207 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1208 struct xhci_slot_ctx *slot_ctx;
1209 struct xhci_input_control_ctx *ctrl_ctx;
1190 u64 temp_64; 1210 u64 temp_64;
1191 1211
1192 if (!udev->slot_id) { 1212 if (!udev->slot_id) {
@@ -1201,11 +1221,11 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1201 xhci_setup_addressable_virt_dev(xhci, udev); 1221 xhci_setup_addressable_virt_dev(xhci, udev);
1202 /* Otherwise, assume the core has the device configured how it wants */ 1222 /* Otherwise, assume the core has the device configured how it wants */
1203 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 1223 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
1204 xhci_dbg_ctx(xhci, virt_dev->in_ctx, virt_dev->in_ctx_dma, 2); 1224 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
1205 1225
1206 spin_lock_irqsave(&xhci->lock, flags); 1226 spin_lock_irqsave(&xhci->lock, flags);
1207 ret = xhci_queue_address_device(xhci, virt_dev->in_ctx_dma, 1227 ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma,
1208 udev->slot_id); 1228 udev->slot_id);
1209 if (ret) { 1229 if (ret) {
1210 spin_unlock_irqrestore(&xhci->lock, flags); 1230 spin_unlock_irqrestore(&xhci->lock, flags);
1211 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); 1231 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
@@ -1246,7 +1266,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1246 xhci_err(xhci, "ERROR: unexpected command completion " 1266 xhci_err(xhci, "ERROR: unexpected command completion "
1247 "code 0x%x.\n", virt_dev->cmd_status); 1267 "code 0x%x.\n", virt_dev->cmd_status);
1248 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 1268 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
1249 xhci_dbg_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 2); 1269 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
1250 ret = -EINVAL; 1270 ret = -EINVAL;
1251 break; 1271 break;
1252 } 1272 }
@@ -1261,19 +1281,21 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1261 (unsigned long long) 1281 (unsigned long long)
1262 xhci->dcbaa->dev_context_ptrs[udev->slot_id]); 1282 xhci->dcbaa->dev_context_ptrs[udev->slot_id]);
1263 xhci_dbg(xhci, "Output Context DMA address = %#08llx\n", 1283 xhci_dbg(xhci, "Output Context DMA address = %#08llx\n",
1264 (unsigned long long)virt_dev->out_ctx_dma); 1284 (unsigned long long)virt_dev->out_ctx->dma);
1265 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 1285 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
1266 xhci_dbg_ctx(xhci, virt_dev->in_ctx, virt_dev->in_ctx_dma, 2); 1286 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
1267 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); 1287 xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
1268 xhci_dbg_device_ctx(xhci, virt_dev->out_ctx, virt_dev->out_ctx_dma, 2); 1288 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
1269 /* 1289 /*
1270 * USB core uses address 1 for the roothubs, so we add one to the 1290 * USB core uses address 1 for the roothubs, so we add one to the
1271 * address given back to us by the HC. 1291 * address given back to us by the HC.
1272 */ 1292 */
1273 udev->devnum = (virt_dev->out_ctx->slot.dev_state & DEV_ADDR_MASK) + 1; 1293 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
1294 udev->devnum = (slot_ctx->dev_state & DEV_ADDR_MASK) + 1;
1274 /* Zero the input context control for later use */ 1295 /* Zero the input context control for later use */
1275 virt_dev->in_ctx->add_flags = 0; 1296 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1276 virt_dev->in_ctx->drop_flags = 0; 1297 ctrl_ctx->add_flags = 0;
1298 ctrl_ctx->drop_flags = 0;
1277 1299
1278 xhci_dbg(xhci, "Device address = %d\n", udev->devnum); 1300 xhci_dbg(xhci, "Device address = %d\n", udev->devnum);
1279 /* XXX Meh, not sure if anyone else but choose_address uses this. */ 1301 /* XXX Meh, not sure if anyone else but choose_address uses this. */
@@ -1315,7 +1337,6 @@ static int __init xhci_hcd_init(void)
1315 /* xhci_device_control has eight fields, and also 1337 /* xhci_device_control has eight fields, and also
1316 * embeds one xhci_slot_ctx and 31 xhci_ep_ctx 1338 * embeds one xhci_slot_ctx and 31 xhci_ep_ctx
1317 */ 1339 */
1318 BUILD_BUG_ON(sizeof(struct xhci_device_control) != (8+8+8*31)*32/8);
1319 BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4*32/8); 1340 BUILD_BUG_ON(sizeof(struct xhci_stream_ctx) != 4*32/8);
1320 BUILD_BUG_ON(sizeof(union xhci_trb) != 4*32/8); 1341 BUILD_BUG_ON(sizeof(union xhci_trb) != 4*32/8);
1321 BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4*32/8); 1342 BUILD_BUG_ON(sizeof(struct xhci_erst_entry) != 4*32/8);