aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-07-18 12:14:24 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-19 20:46:08 -0400
commit809a58b896ba07e771adc76a47c83e4ca1969da8 (patch)
tree6d62ebd0671e38403011d87ed03a127a151c7f46
parent32aca5600526189dd876e6c92b64fd88cf052c8d (diff)
USB: change name of spinlock in hcd.c
This patch (as940 renames hcd_data_lock in hcd.c to hcd_urb_list_lock, which is more descriptive of the lock's job. It also introduces a convenient inline routine for testing whether a particular USB device is a root hub. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/core/hcd.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 032b118c2883..42ef1d5f6c8a 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 */
100static DEFINE_SPINLOCK(hcd_root_hub_lock); 100static DEFINE_SPINLOCK(hcd_root_hub_lock);
101 101
102/* used when updating hcd data */ 102/* used when updating an endpoint's URB list */
103static DEFINE_SPINLOCK(hcd_data_lock); 103static DEFINE_SPINLOCK(hcd_urb_list_lock);
104 104
105/* wait queue for synchronous unlinks */ 105/* wait queue for synchronous unlinks */
106DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); 106DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
107 107
108static 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);
906static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) 911static 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
@@ -1043,7 +1047,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb)
1043{ 1047{
1044 int value; 1048 int value;
1045 1049
1046 if (urb->dev == hcd->self.root_hub) 1050 if (is_root_hub(urb->dev))
1047 value = usb_rh_urb_dequeue (hcd, urb); 1051 value = usb_rh_urb_dequeue (hcd, urb);
1048 else { 1052 else {
1049 1053
@@ -1091,11 +1095,11 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1091 * 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
1092 * not it's already been unlinked ... so we respect the reversed 1096 * not it's already been unlinked ... so we respect the reversed
1093 * lock sequence needed for the usb_hcd_giveback_urb() code paths 1097 * lock sequence needed for the usb_hcd_giveback_urb() code paths
1094 * (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
1095 * unlinking it. 1099 * unlinking it.
1096 */ 1100 */
1097 spin_lock_irqsave (&urb->lock, flags); 1101 spin_lock_irqsave (&urb->lock, flags);
1098 spin_lock (&hcd_data_lock); 1102 spin_lock(&hcd_urb_list_lock);
1099 1103
1100 sys = &urb->dev->dev; 1104 sys = &urb->dev->dev;
1101 hcd = bus_to_hcd(urb->dev->bus); 1105 hcd = bus_to_hcd(urb->dev->bus);
@@ -1127,17 +1131,16 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1127 * finish unlinking the initial failed usb_set_address() 1131 * finish unlinking the initial failed usb_set_address()
1128 * or device descriptor fetch. 1132 * or device descriptor fetch.
1129 */ 1133 */
1130 if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) 1134 if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) &&
1131 && hcd->self.root_hub != urb->dev) { 1135 !is_root_hub(urb->dev)) {
1132 dev_warn (hcd->self.controller, "Unlink after no-IRQ? " 1136 dev_warn (hcd->self.controller, "Unlink after no-IRQ? "
1133 "Controller is probably using the wrong IRQ." 1137 "Controller is probably using the wrong IRQ.\n");
1134 "\n");
1135 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1138 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
1136 } 1139 }
1137 1140
1138 urb->status = status; 1141 urb->status = status;
1139 1142
1140 spin_unlock (&hcd_data_lock); 1143 spin_unlock(&hcd_urb_list_lock);
1141 spin_unlock_irqrestore (&urb->lock, flags); 1144 spin_unlock_irqrestore (&urb->lock, flags);
1142 1145
1143 retval = unlink1 (hcd, urb); 1146 retval = unlink1 (hcd, urb);
@@ -1146,7 +1149,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1146 return retval; 1149 return retval;
1147 1150
1148done: 1151done:
1149 spin_unlock (&hcd_data_lock); 1152 spin_unlock(&hcd_urb_list_lock);
1150 spin_unlock_irqrestore (&urb->lock, flags); 1153 spin_unlock_irqrestore (&urb->lock, flags);
1151 if (retval != -EIDRM && sys && sys->driver) 1154 if (retval != -EIDRM && sys && sys->driver)
1152 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);
@@ -1203,7 +1206,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev,
1203 1206
1204 /* 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 */
1205rescan: 1208rescan:
1206 spin_lock (&hcd_data_lock); 1209 spin_lock(&hcd_urb_list_lock);
1207 list_for_each_entry (urb, &ep->urb_list, urb_list) { 1210 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1208 int tmp; 1211 int tmp;
1209 1212
@@ -1211,7 +1214,7 @@ rescan:
1211 if (urb->status != -EINPROGRESS) 1214 if (urb->status != -EINPROGRESS)
1212 continue; 1215 continue;
1213 usb_get_urb (urb); 1216 usb_get_urb (urb);
1214 spin_unlock (&hcd_data_lock); 1217 spin_unlock(&hcd_urb_list_lock);
1215 1218
1216 spin_lock (&urb->lock); 1219 spin_lock (&urb->lock);
1217 tmp = urb->status; 1220 tmp = urb->status;
@@ -1240,7 +1243,7 @@ rescan:
1240 /* list contents may have changed */ 1243 /* list contents may have changed */
1241 goto rescan; 1244 goto rescan;
1242 } 1245 }
1243 spin_unlock (&hcd_data_lock); 1246 spin_unlock(&hcd_urb_list_lock);
1244 local_irq_enable (); 1247 local_irq_enable ();
1245 1248
1246 /* synchronize with the hardware, so old configuration state 1249 /* synchronize with the hardware, so old configuration state
@@ -1257,7 +1260,7 @@ rescan:
1257 * endpoint_disable methods. 1260 * endpoint_disable methods.
1258 */ 1261 */
1259 while (!list_empty (&ep->urb_list)) { 1262 while (!list_empty (&ep->urb_list)) {
1260 spin_lock_irq (&hcd_data_lock); 1263 spin_lock_irq(&hcd_urb_list_lock);
1261 1264
1262 /* The list may have changed while we acquired the spinlock */ 1265 /* The list may have changed while we acquired the spinlock */
1263 urb = NULL; 1266 urb = NULL;
@@ -1266,7 +1269,7 @@ rescan:
1266 urb_list); 1269 urb_list);
1267 usb_get_urb (urb); 1270 usb_get_urb (urb);
1268 } 1271 }
1269 spin_unlock_irq (&hcd_data_lock); 1272 spin_unlock_irq(&hcd_urb_list_lock);
1270 1273
1271 if (urb) { 1274 if (urb) {
1272 usb_kill_urb (urb); 1275 usb_kill_urb (urb);