diff options
Diffstat (limited to 'drivers/usb/core/hcd.c')
-rw-r--r-- | drivers/usb/core/hcd.c | 131 |
1 files changed, 67 insertions, 64 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 963520fbef9..42ef1d5f6c8 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -99,12 +99,17 @@ EXPORT_SYMBOL_GPL (usb_bus_list_lock); | |||
99 | /* used for controlling access to virtual root hubs */ | 99 | /* used for controlling access to virtual root hubs */ |
100 | static DEFINE_SPINLOCK(hcd_root_hub_lock); | 100 | static DEFINE_SPINLOCK(hcd_root_hub_lock); |
101 | 101 | ||
102 | /* used when updating hcd data */ | 102 | /* used when updating an endpoint's URB list */ |
103 | static DEFINE_SPINLOCK(hcd_data_lock); | 103 | static DEFINE_SPINLOCK(hcd_urb_list_lock); |
104 | 104 | ||
105 | /* wait queue for synchronous unlinks */ | 105 | /* wait queue for synchronous unlinks */ |
106 | DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); | 106 | DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); |
107 | 107 | ||
108 | static inline int is_root_hub(struct usb_device *udev) | ||
109 | { | ||
110 | return (udev->parent == NULL); | ||
111 | } | ||
112 | |||
108 | /*-------------------------------------------------------------------------*/ | 113 | /*-------------------------------------------------------------------------*/ |
109 | 114 | ||
110 | /* | 115 | /* |
@@ -906,14 +911,13 @@ EXPORT_SYMBOL (usb_calc_bus_time); | |||
906 | static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) | 911 | static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) |
907 | { | 912 | { |
908 | unsigned long flags; | 913 | unsigned long flags; |
909 | int at_root_hub = (urb->dev == hcd->self.root_hub); | ||
910 | 914 | ||
911 | /* clear all state linking urb to this dev (and hcd) */ | 915 | /* clear all state linking urb to this dev (and hcd) */ |
912 | spin_lock_irqsave (&hcd_data_lock, flags); | 916 | spin_lock_irqsave(&hcd_urb_list_lock, flags); |
913 | list_del_init (&urb->urb_list); | 917 | list_del_init (&urb->urb_list); |
914 | spin_unlock_irqrestore (&hcd_data_lock, flags); | 918 | spin_unlock_irqrestore(&hcd_urb_list_lock, flags); |
915 | 919 | ||
916 | if (hcd->self.uses_dma && !at_root_hub) { | 920 | if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { |
917 | if (usb_pipecontrol (urb->pipe) | 921 | if (usb_pipecontrol (urb->pipe) |
918 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) | 922 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) |
919 | dma_unmap_single (hcd->self.controller, urb->setup_dma, | 923 | dma_unmap_single (hcd->self.controller, urb->setup_dma, |
@@ -955,7 +959,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
955 | 959 | ||
956 | // FIXME: verify that quiescing hc works right (RH cleans up) | 960 | // FIXME: verify that quiescing hc works right (RH cleans up) |
957 | 961 | ||
958 | spin_lock_irqsave (&hcd_data_lock, flags); | 962 | spin_lock_irqsave(&hcd_urb_list_lock, flags); |
959 | ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out) | 963 | ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out) |
960 | [usb_pipeendpoint(urb->pipe)]; | 964 | [usb_pipeendpoint(urb->pipe)]; |
961 | if (unlikely (!ep)) | 965 | if (unlikely (!ep)) |
@@ -972,7 +976,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
972 | status = -ESHUTDOWN; | 976 | status = -ESHUTDOWN; |
973 | break; | 977 | break; |
974 | } | 978 | } |
975 | spin_unlock_irqrestore (&hcd_data_lock, flags); | 979 | spin_unlock_irqrestore(&hcd_urb_list_lock, flags); |
976 | if (status) { | 980 | if (status) { |
977 | INIT_LIST_HEAD (&urb->urb_list); | 981 | INIT_LIST_HEAD (&urb->urb_list); |
978 | usbmon_urb_submit_error(&hcd->self, urb, status); | 982 | usbmon_urb_submit_error(&hcd->self, urb, status); |
@@ -986,7 +990,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
986 | urb = usb_get_urb (urb); | 990 | urb = usb_get_urb (urb); |
987 | atomic_inc (&urb->use_count); | 991 | atomic_inc (&urb->use_count); |
988 | 992 | ||
989 | if (urb->dev == hcd->self.root_hub) { | 993 | if (is_root_hub(urb->dev)) { |
990 | /* NOTE: requirement on hub callers (usbfs and the hub | 994 | /* NOTE: requirement on hub callers (usbfs and the hub |
991 | * driver, for now) that URBs' urb->transfer_buffer be | 995 | * driver, for now) that URBs' urb->transfer_buffer be |
992 | * valid and usb_buffer_{sync,unmap}() not be needed, since | 996 | * valid and usb_buffer_{sync,unmap}() not be needed, since |
@@ -1033,18 +1037,6 @@ done: | |||
1033 | 1037 | ||
1034 | /*-------------------------------------------------------------------------*/ | 1038 | /*-------------------------------------------------------------------------*/ |
1035 | 1039 | ||
1036 | /* called in any context */ | ||
1037 | int usb_hcd_get_frame_number (struct usb_device *udev) | ||
1038 | { | ||
1039 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1040 | |||
1041 | if (!HC_IS_RUNNING (hcd->state)) | ||
1042 | return -ESHUTDOWN; | ||
1043 | return hcd->driver->get_frame_number (hcd); | ||
1044 | } | ||
1045 | |||
1046 | /*-------------------------------------------------------------------------*/ | ||
1047 | |||
1048 | /* this makes the hcd giveback() the urb more quickly, by kicking it | 1040 | /* this makes the hcd giveback() the urb more quickly, by kicking it |
1049 | * off hardware queues (which may take a while) and returning it as | 1041 | * off hardware queues (which may take a while) and returning it as |
1050 | * soon as practical. we've already set up the urb's return status, | 1042 | * soon as practical. we've already set up the urb's return status, |
@@ -1055,7 +1047,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb) | |||
1055 | { | 1047 | { |
1056 | int value; | 1048 | int value; |
1057 | 1049 | ||
1058 | if (urb->dev == hcd->self.root_hub) | 1050 | if (is_root_hub(urb->dev)) |
1059 | value = usb_rh_urb_dequeue (hcd, urb); | 1051 | value = usb_rh_urb_dequeue (hcd, urb); |
1060 | else { | 1052 | else { |
1061 | 1053 | ||
@@ -1103,11 +1095,11 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1103 | * that it was submitted. But as a rule it can't know whether or | 1095 | * that it was submitted. But as a rule it can't know whether or |
1104 | * not it's already been unlinked ... so we respect the reversed | 1096 | * not it's already been unlinked ... so we respect the reversed |
1105 | * lock sequence needed for the usb_hcd_giveback_urb() code paths | 1097 | * lock sequence needed for the usb_hcd_giveback_urb() code paths |
1106 | * (urb lock, then hcd_data_lock) in case some other CPU is now | 1098 | * (urb lock, then hcd_urb_list_lock) in case some other CPU is now |
1107 | * unlinking it. | 1099 | * unlinking it. |
1108 | */ | 1100 | */ |
1109 | spin_lock_irqsave (&urb->lock, flags); | 1101 | spin_lock_irqsave (&urb->lock, flags); |
1110 | spin_lock (&hcd_data_lock); | 1102 | spin_lock(&hcd_urb_list_lock); |
1111 | 1103 | ||
1112 | sys = &urb->dev->dev; | 1104 | sys = &urb->dev->dev; |
1113 | hcd = bus_to_hcd(urb->dev->bus); | 1105 | hcd = bus_to_hcd(urb->dev->bus); |
@@ -1139,17 +1131,16 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1139 | * finish unlinking the initial failed usb_set_address() | 1131 | * finish unlinking the initial failed usb_set_address() |
1140 | * or device descriptor fetch. | 1132 | * or device descriptor fetch. |
1141 | */ | 1133 | */ |
1142 | if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) | 1134 | if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) && |
1143 | && hcd->self.root_hub != urb->dev) { | 1135 | !is_root_hub(urb->dev)) { |
1144 | dev_warn (hcd->self.controller, "Unlink after no-IRQ? " | 1136 | dev_warn (hcd->self.controller, "Unlink after no-IRQ? " |
1145 | "Controller is probably using the wrong IRQ." | 1137 | "Controller is probably using the wrong IRQ.\n"); |
1146 | "\n"); | ||
1147 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 1138 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
1148 | } | 1139 | } |
1149 | 1140 | ||
1150 | urb->status = status; | 1141 | urb->status = status; |
1151 | 1142 | ||
1152 | spin_unlock (&hcd_data_lock); | 1143 | spin_unlock(&hcd_urb_list_lock); |
1153 | spin_unlock_irqrestore (&urb->lock, flags); | 1144 | spin_unlock_irqrestore (&urb->lock, flags); |
1154 | 1145 | ||
1155 | retval = unlink1 (hcd, urb); | 1146 | retval = unlink1 (hcd, urb); |
@@ -1158,7 +1149,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1158 | return retval; | 1149 | return retval; |
1159 | 1150 | ||
1160 | done: | 1151 | done: |
1161 | spin_unlock (&hcd_data_lock); | 1152 | spin_unlock(&hcd_urb_list_lock); |
1162 | spin_unlock_irqrestore (&urb->lock, flags); | 1153 | spin_unlock_irqrestore (&urb->lock, flags); |
1163 | if (retval != -EIDRM && sys && sys->driver) | 1154 | if (retval != -EIDRM && sys && sys->driver) |
1164 | dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval); | 1155 | dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval); |
@@ -1167,6 +1158,35 @@ done: | |||
1167 | 1158 | ||
1168 | /*-------------------------------------------------------------------------*/ | 1159 | /*-------------------------------------------------------------------------*/ |
1169 | 1160 | ||
1161 | /** | ||
1162 | * usb_hcd_giveback_urb - return URB from HCD to device driver | ||
1163 | * @hcd: host controller returning the URB | ||
1164 | * @urb: urb being returned to the USB device driver. | ||
1165 | * Context: in_interrupt() | ||
1166 | * | ||
1167 | * This hands the URB from HCD to its USB device driver, using its | ||
1168 | * completion function. The HCD has freed all per-urb resources | ||
1169 | * (and is done using urb->hcpriv). It also released all HCD locks; | ||
1170 | * the device driver won't cause problems if it frees, modifies, | ||
1171 | * or resubmits this URB. | ||
1172 | */ | ||
1173 | void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) | ||
1174 | { | ||
1175 | urb_unlink(hcd, urb); | ||
1176 | usbmon_urb_complete (&hcd->self, urb); | ||
1177 | usb_unanchor_urb(urb); | ||
1178 | |||
1179 | /* pass ownership to the completion handler */ | ||
1180 | urb->complete (urb); | ||
1181 | atomic_dec (&urb->use_count); | ||
1182 | if (unlikely (urb->reject)) | ||
1183 | wake_up (&usb_kill_urb_queue); | ||
1184 | usb_put_urb (urb); | ||
1185 | } | ||
1186 | EXPORT_SYMBOL (usb_hcd_giveback_urb); | ||
1187 | |||
1188 | /*-------------------------------------------------------------------------*/ | ||
1189 | |||
1170 | /* disables the endpoint: cancels any pending urbs, then synchronizes with | 1190 | /* disables the endpoint: cancels any pending urbs, then synchronizes with |
1171 | * the hcd to make sure all endpoint state is gone from hardware, and then | 1191 | * the hcd to make sure all endpoint state is gone from hardware, and then |
1172 | * waits until the endpoint's queue is completely drained. use for | 1192 | * waits until the endpoint's queue is completely drained. use for |
@@ -1186,7 +1206,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev, | |||
1186 | 1206 | ||
1187 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ | 1207 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ |
1188 | rescan: | 1208 | rescan: |
1189 | spin_lock (&hcd_data_lock); | 1209 | spin_lock(&hcd_urb_list_lock); |
1190 | list_for_each_entry (urb, &ep->urb_list, urb_list) { | 1210 | list_for_each_entry (urb, &ep->urb_list, urb_list) { |
1191 | int tmp; | 1211 | int tmp; |
1192 | 1212 | ||
@@ -1194,7 +1214,7 @@ rescan: | |||
1194 | if (urb->status != -EINPROGRESS) | 1214 | if (urb->status != -EINPROGRESS) |
1195 | continue; | 1215 | continue; |
1196 | usb_get_urb (urb); | 1216 | usb_get_urb (urb); |
1197 | spin_unlock (&hcd_data_lock); | 1217 | spin_unlock(&hcd_urb_list_lock); |
1198 | 1218 | ||
1199 | spin_lock (&urb->lock); | 1219 | spin_lock (&urb->lock); |
1200 | tmp = urb->status; | 1220 | tmp = urb->status; |
@@ -1223,7 +1243,7 @@ rescan: | |||
1223 | /* list contents may have changed */ | 1243 | /* list contents may have changed */ |
1224 | goto rescan; | 1244 | goto rescan; |
1225 | } | 1245 | } |
1226 | spin_unlock (&hcd_data_lock); | 1246 | spin_unlock(&hcd_urb_list_lock); |
1227 | local_irq_enable (); | 1247 | local_irq_enable (); |
1228 | 1248 | ||
1229 | /* synchronize with the hardware, so old configuration state | 1249 | /* synchronize with the hardware, so old configuration state |
@@ -1240,7 +1260,7 @@ rescan: | |||
1240 | * endpoint_disable methods. | 1260 | * endpoint_disable methods. |
1241 | */ | 1261 | */ |
1242 | while (!list_empty (&ep->urb_list)) { | 1262 | while (!list_empty (&ep->urb_list)) { |
1243 | spin_lock_irq (&hcd_data_lock); | 1263 | spin_lock_irq(&hcd_urb_list_lock); |
1244 | 1264 | ||
1245 | /* The list may have changed while we acquired the spinlock */ | 1265 | /* The list may have changed while we acquired the spinlock */ |
1246 | urb = NULL; | 1266 | urb = NULL; |
@@ -1249,7 +1269,7 @@ rescan: | |||
1249 | urb_list); | 1269 | urb_list); |
1250 | usb_get_urb (urb); | 1270 | usb_get_urb (urb); |
1251 | } | 1271 | } |
1252 | spin_unlock_irq (&hcd_data_lock); | 1272 | spin_unlock_irq(&hcd_urb_list_lock); |
1253 | 1273 | ||
1254 | if (urb) { | 1274 | if (urb) { |
1255 | usb_kill_urb (urb); | 1275 | usb_kill_urb (urb); |
@@ -1260,6 +1280,18 @@ rescan: | |||
1260 | 1280 | ||
1261 | /*-------------------------------------------------------------------------*/ | 1281 | /*-------------------------------------------------------------------------*/ |
1262 | 1282 | ||
1283 | /* called in any context */ | ||
1284 | int usb_hcd_get_frame_number (struct usb_device *udev) | ||
1285 | { | ||
1286 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1287 | |||
1288 | if (!HC_IS_RUNNING (hcd->state)) | ||
1289 | return -ESHUTDOWN; | ||
1290 | return hcd->driver->get_frame_number (hcd); | ||
1291 | } | ||
1292 | |||
1293 | /*-------------------------------------------------------------------------*/ | ||
1294 | |||
1263 | #ifdef CONFIG_PM | 1295 | #ifdef CONFIG_PM |
1264 | 1296 | ||
1265 | int hcd_bus_suspend(struct usb_device *rhdev) | 1297 | int hcd_bus_suspend(struct usb_device *rhdev) |
@@ -1395,35 +1427,6 @@ EXPORT_SYMBOL (usb_bus_start_enum); | |||
1395 | /*-------------------------------------------------------------------------*/ | 1427 | /*-------------------------------------------------------------------------*/ |
1396 | 1428 | ||
1397 | /** | 1429 | /** |
1398 | * usb_hcd_giveback_urb - return URB from HCD to device driver | ||
1399 | * @hcd: host controller returning the URB | ||
1400 | * @urb: urb being returned to the USB device driver. | ||
1401 | * Context: in_interrupt() | ||
1402 | * | ||
1403 | * This hands the URB from HCD to its USB device driver, using its | ||
1404 | * completion function. The HCD has freed all per-urb resources | ||
1405 | * (and is done using urb->hcpriv). It also released all HCD locks; | ||
1406 | * the device driver won't cause problems if it frees, modifies, | ||
1407 | * or resubmits this URB. | ||
1408 | */ | ||
1409 | void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) | ||
1410 | { | ||
1411 | urb_unlink(hcd, urb); | ||
1412 | usbmon_urb_complete (&hcd->self, urb); | ||
1413 | usb_unanchor_urb(urb); | ||
1414 | |||
1415 | /* pass ownership to the completion handler */ | ||
1416 | urb->complete (urb); | ||
1417 | atomic_dec (&urb->use_count); | ||
1418 | if (unlikely (urb->reject)) | ||
1419 | wake_up (&usb_kill_urb_queue); | ||
1420 | usb_put_urb (urb); | ||
1421 | } | ||
1422 | EXPORT_SYMBOL (usb_hcd_giveback_urb); | ||
1423 | |||
1424 | /*-------------------------------------------------------------------------*/ | ||
1425 | |||
1426 | /** | ||
1427 | * usb_hcd_irq - hook IRQs to HCD framework (bus glue) | 1430 | * usb_hcd_irq - hook IRQs to HCD framework (bus glue) |
1428 | * @irq: the IRQ being raised | 1431 | * @irq: the IRQ being raised |
1429 | * @__hcd: pointer to the HCD whose IRQ is being signaled | 1432 | * @__hcd: pointer to the HCD whose IRQ is being signaled |