aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2008-06-18 10:00:29 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-07-21 18:16:33 -0400
commit742120c63138651c898614001cb58cd607401eac (patch)
tree3aeeb95b66773ee60839c651a10d295117d87e88 /drivers/usb/core
parentdd9ca5d9be7eba99d685d733e23d5be7110e9556 (diff)
USB: fix usb_reset_device and usb_reset_composite_device(take 3)
This patch renames the existing usb_reset_device in hub.c to usb_reset_and_verify_device and renames the existing usb_reset_composite_device to usb_reset_device. Also the new usb_reset_and_verify_device does't need to be EXPORTED . The idea of the patch is that external interface driver should warn the other interfaces' driver of the same device before and after reseting the usb device. One interface driver shoud call _old_ usb_reset_composite_device instead of _old_ usb_reset_device since it can't assume the device contains only one interface. The _old_ usb_reset_composite_device is safe for single interface device also. we rename the two functions to make the change easily. This patch is under guideline from Alan Stern. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/devio.c2
-rw-r--r--drivers/usb/core/hub.c33
2 files changed, 18 insertions, 17 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index bc1cce5cf758..e09935acae80 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -872,7 +872,7 @@ static int proc_connectinfo(struct dev_state *ps, void __user *arg)
872 872
873static int proc_resetdevice(struct dev_state *ps) 873static int proc_resetdevice(struct dev_state *ps)
874{ 874{
875 return usb_reset_composite_device(ps->dev); 875 return usb_reset_device(ps->dev);
876} 876}
877 877
878static int proc_setintf(struct dev_state *ps, void __user *arg) 878static int proc_setintf(struct dev_state *ps, void __user *arg)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 207c33d369be..bb3ecc4c08f2 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -135,6 +135,8 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
135#define HUB_DEBOUNCE_STABLE 100 135#define HUB_DEBOUNCE_STABLE 100
136 136
137 137
138static int usb_reset_and_verify_device(struct usb_device *udev);
139
138static inline char *portspeed(int portstatus) 140static inline char *portspeed(int portstatus)
139{ 141{
140 if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) 142 if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
@@ -1971,7 +1973,7 @@ static int finish_port_resume(struct usb_device *udev)
1971 * resumed. 1973 * resumed.
1972 */ 1974 */
1973 if (udev->reset_resume) 1975 if (udev->reset_resume)
1974 status = usb_reset_device(udev); 1976 status = usb_reset_and_verify_device(udev);
1975 1977
1976 /* 10.5.4.5 says be sure devices in the tree are still there. 1978 /* 10.5.4.5 says be sure devices in the tree are still there.
1977 * For now let's assume the device didn't go crazy on resume, 1979 * For now let's assume the device didn't go crazy on resume,
@@ -2030,7 +2032,7 @@ static int finish_port_resume(struct usb_device *udev)
2030 * to it will be lost. Using the USB_PERSIST facility, the device can be 2032 * to it will be lost. Using the USB_PERSIST facility, the device can be
2031 * made to appear as if it had not disconnected. 2033 * made to appear as if it had not disconnected.
2032 * 2034 *
2033 * This facility can be dangerous. Although usb_reset_device() makes 2035 * This facility can be dangerous. Although usb_reset_and_verify_device() makes
2034 * every effort to insure that the same device is present after the 2036 * every effort to insure that the same device is present after the
2035 * reset as before, it cannot provide a 100% guarantee. Furthermore it's 2037 * reset as before, it cannot provide a 100% guarantee. Furthermore it's
2036 * quite possible for a device to remain unaltered but its media to be 2038 * quite possible for a device to remain unaltered but its media to be
@@ -2140,7 +2142,7 @@ int usb_port_resume(struct usb_device *udev)
2140 hub_port_logical_disconnect(hub, port1); 2142 hub_port_logical_disconnect(hub, port1);
2141 } else if (udev->reset_resume) { 2143 } else if (udev->reset_resume) {
2142 dev_dbg(&udev->dev, "reset-resume\n"); 2144 dev_dbg(&udev->dev, "reset-resume\n");
2143 status = usb_reset_device(udev); 2145 status = usb_reset_and_verify_device(udev);
2144 } 2146 }
2145 return status; 2147 return status;
2146} 2148}
@@ -2321,7 +2323,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2321 * Returns device in USB_STATE_ADDRESS, except on error. 2323 * Returns device in USB_STATE_ADDRESS, except on error.
2322 * 2324 *
2323 * If this is called for an already-existing device (as part of 2325 * If this is called for an already-existing device (as part of
2324 * usb_reset_device), the caller must own the device lock. For a 2326 * usb_reset_and_verify_device), the caller must own the device lock. For a
2325 * newly detected device that is not accessible through any global 2327 * newly detected device that is not accessible through any global
2326 * pointers, it's not necessary to lock the device. 2328 * pointers, it's not necessary to lock the device.
2327 */ 2329 */
@@ -2638,7 +2640,7 @@ hub_power_remaining (struct usb_hub *hub)
2638 * This routine is called when: 2640 * This routine is called when:
2639 * a port connection-change occurs; 2641 * a port connection-change occurs;
2640 * a port enable-change occurs (often caused by EMI); 2642 * a port enable-change occurs (often caused by EMI);
2641 * usb_reset_device() encounters changed descriptors (as from 2643 * usb_reset_and_verify_device() encounters changed descriptors (as from
2642 * a firmware download) 2644 * a firmware download)
2643 * caller already locked the hub 2645 * caller already locked the hub
2644 */ 2646 */
@@ -2712,7 +2714,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2712#endif 2714#endif
2713 2715
2714 } else { 2716 } else {
2715 status = usb_reset_composite_device(udev); 2717 status = usb_reset_device(udev);
2716 } 2718 }
2717 usb_unlock_device(udev); 2719 usb_unlock_device(udev);
2718 2720
@@ -2940,7 +2942,7 @@ static void hub_events(void)
2940 dev_dbg (hub_dev, "resetting for error %d\n", 2942 dev_dbg (hub_dev, "resetting for error %d\n",
2941 hub->error); 2943 hub->error);
2942 2944
2943 ret = usb_reset_composite_device(hdev); 2945 ret = usb_reset_device(hdev);
2944 if (ret) { 2946 if (ret) {
2945 dev_dbg (hub_dev, 2947 dev_dbg (hub_dev,
2946 "error resetting hub: %d\n", ret); 2948 "error resetting hub: %d\n", ret);
@@ -3233,12 +3235,12 @@ static int descriptors_changed(struct usb_device *udev,
3233} 3235}
3234 3236
3235/** 3237/**
3236 * usb_reset_device - perform a USB port reset to reinitialize a device 3238 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
3237 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) 3239 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
3238 * 3240 *
3239 * WARNING - don't use this routine to reset a composite device 3241 * WARNING - don't use this routine to reset a composite device
3240 * (one with multiple interfaces owned by separate drivers)! 3242 * (one with multiple interfaces owned by separate drivers)!
3241 * Use usb_reset_composite_device() instead. 3243 * Use usb_reset_device() instead.
3242 * 3244 *
3243 * Do a port reset, reassign the device's address, and establish its 3245 * Do a port reset, reassign the device's address, and establish its
3244 * former operating configuration. If the reset fails, or the device's 3246 * former operating configuration. If the reset fails, or the device's
@@ -3262,7 +3264,7 @@ static int descriptors_changed(struct usb_device *udev,
3262 * holding the device lock because these tasks should always call 3264 * holding the device lock because these tasks should always call
3263 * usb_autopm_resume_device(), thereby preventing any unwanted autoresume. 3265 * usb_autopm_resume_device(), thereby preventing any unwanted autoresume.
3264 */ 3266 */
3265int usb_reset_device(struct usb_device *udev) 3267static int usb_reset_and_verify_device(struct usb_device *udev)
3266{ 3268{
3267 struct usb_device *parent_hdev = udev->parent; 3269 struct usb_device *parent_hdev = udev->parent;
3268 struct usb_hub *parent_hub; 3270 struct usb_hub *parent_hub;
@@ -3350,24 +3352,23 @@ re_enumerate:
3350 hub_port_logical_disconnect(parent_hub, port1); 3352 hub_port_logical_disconnect(parent_hub, port1);
3351 return -ENODEV; 3353 return -ENODEV;
3352} 3354}
3353EXPORT_SYMBOL_GPL(usb_reset_device);
3354 3355
3355/** 3356/**
3356 * usb_reset_composite_device - warn interface drivers and perform a USB port reset 3357 * usb_reset_device - warn interface drivers and perform a USB port reset
3357 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) 3358 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
3358 * 3359 *
3359 * Warns all drivers bound to registered interfaces (using their pre_reset 3360 * Warns all drivers bound to registered interfaces (using their pre_reset
3360 * method), performs the port reset, and then lets the drivers know that 3361 * method), performs the port reset, and then lets the drivers know that
3361 * the reset is over (using their post_reset method). 3362 * the reset is over (using their post_reset method).
3362 * 3363 *
3363 * Return value is the same as for usb_reset_device(). 3364 * Return value is the same as for usb_reset_and_verify_device().
3364 * 3365 *
3365 * The caller must own the device lock. For example, it's safe to use 3366 * The caller must own the device lock. For example, it's safe to use
3366 * this from a driver probe() routine after downloading new firmware. 3367 * this from a driver probe() routine after downloading new firmware.
3367 * For calls that might not occur during probe(), drivers should lock 3368 * For calls that might not occur during probe(), drivers should lock
3368 * the device using usb_lock_device_for_reset(). 3369 * the device using usb_lock_device_for_reset().
3369 */ 3370 */
3370int usb_reset_composite_device(struct usb_device *udev) 3371int usb_reset_device(struct usb_device *udev)
3371{ 3372{
3372 int ret; 3373 int ret;
3373 int i; 3374 int i;
@@ -3397,7 +3398,7 @@ int usb_reset_composite_device(struct usb_device *udev)
3397 } 3398 }
3398 } 3399 }
3399 3400
3400 ret = usb_reset_device(udev); 3401 ret = usb_reset_and_verify_device(udev);
3401 3402
3402 if (config) { 3403 if (config) {
3403 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { 3404 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) {
@@ -3416,4 +3417,4 @@ int usb_reset_composite_device(struct usb_device *udev)
3416 usb_autosuspend_device(udev); 3417 usb_autosuspend_device(udev);
3417 return ret; 3418 return ret;
3418} 3419}
3419EXPORT_SYMBOL_GPL(usb_reset_composite_device); 3420EXPORT_SYMBOL_GPL(usb_reset_device);