diff options
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/Kconfig | 6 | ||||
-rw-r--r-- | drivers/usb/core/devices.c | 87 | ||||
-rw-r--r-- | drivers/usb/core/devio.c | 290 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 1101 | ||||
-rw-r--r-- | drivers/usb/core/endpoint.c | 2 | ||||
-rw-r--r-- | drivers/usb/core/file.c | 4 | ||||
-rw-r--r-- | drivers/usb/core/generic.c | 4 | ||||
-rw-r--r-- | drivers/usb/core/hcd-pci.c | 129 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 125 | ||||
-rw-r--r-- | drivers/usb/core/hcd.h | 34 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 301 | ||||
-rw-r--r-- | drivers/usb/core/inode.c | 5 | ||||
-rw-r--r-- | drivers/usb/core/message.c | 96 | ||||
-rw-r--r-- | drivers/usb/core/quirks.c | 18 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 156 | ||||
-rw-r--r-- | drivers/usb/core/urb.c | 30 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 130 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 44 |
18 files changed, 1553 insertions, 1009 deletions
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index ad925946f869..7e594449600e 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -91,8 +91,8 @@ config USB_DYNAMIC_MINORS | |||
91 | If you are unsure about this, say N here. | 91 | If you are unsure about this, say N here. |
92 | 92 | ||
93 | config USB_SUSPEND | 93 | config USB_SUSPEND |
94 | bool "USB selective suspend/resume and wakeup" | 94 | bool "USB runtime power management (suspend/resume and wakeup)" |
95 | depends on USB && PM | 95 | depends on USB && PM_RUNTIME |
96 | help | 96 | help |
97 | If you say Y here, you can use driver calls or the sysfs | 97 | If you say Y here, you can use driver calls or the sysfs |
98 | "power/level" file to suspend or resume individual USB | 98 | "power/level" file to suspend or resume individual USB |
@@ -109,7 +109,7 @@ config USB_SUSPEND | |||
109 | config USB_OTG | 109 | config USB_OTG |
110 | bool | 110 | bool |
111 | depends on USB && EXPERIMENTAL | 111 | depends on USB && EXPERIMENTAL |
112 | select USB_SUSPEND | 112 | depends on USB_SUSPEND |
113 | default n | 113 | default n |
114 | 114 | ||
115 | 115 | ||
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c index 96f11715cd26..19bc03a9fecf 100644 --- a/drivers/usb/core/devices.c +++ b/drivers/usb/core/devices.c | |||
@@ -50,7 +50,7 @@ | |||
50 | 50 | ||
51 | #include <linux/fs.h> | 51 | #include <linux/fs.h> |
52 | #include <linux/mm.h> | 52 | #include <linux/mm.h> |
53 | #include <linux/slab.h> | 53 | #include <linux/gfp.h> |
54 | #include <linux/poll.h> | 54 | #include <linux/poll.h> |
55 | #include <linux/usb.h> | 55 | #include <linux/usb.h> |
56 | #include <linux/smp_lock.h> | 56 | #include <linux/smp_lock.h> |
@@ -117,12 +117,20 @@ static const char *format_endpt = | |||
117 | * However, these will come from functions that return ptrs to each of them. | 117 | * However, these will come from functions that return ptrs to each of them. |
118 | */ | 118 | */ |
119 | 119 | ||
120 | static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq); | 120 | /* |
121 | static unsigned int conndiscevcnt; | 121 | * Wait for an connect/disconnect event to happen. We initialize |
122 | 122 | * the event counter with an odd number, and each event will increment | |
123 | /* this struct stores the poll state for <mountpoint>/devices pollers */ | 123 | * the event counter by two, so it will always _stay_ odd. That means |
124 | struct usb_device_status { | 124 | * that it will never be zero, so "event 0" will never match a current |
125 | unsigned int lastev; | 125 | * event, and thus 'poll' will always trigger as readable for the first |
126 | * time it gets called. | ||
127 | */ | ||
128 | static struct device_connect_event { | ||
129 | atomic_t count; | ||
130 | wait_queue_head_t wait; | ||
131 | } device_event = { | ||
132 | .count = ATOMIC_INIT(1), | ||
133 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER(device_event.wait) | ||
126 | }; | 134 | }; |
127 | 135 | ||
128 | struct class_info { | 136 | struct class_info { |
@@ -156,8 +164,8 @@ static const struct class_info clas_info[] = | |||
156 | 164 | ||
157 | void usbfs_conn_disc_event(void) | 165 | void usbfs_conn_disc_event(void) |
158 | { | 166 | { |
159 | conndiscevcnt++; | 167 | atomic_add(2, &device_event.count); |
160 | wake_up(&deviceconndiscwq); | 168 | wake_up(&device_event.wait); |
161 | } | 169 | } |
162 | 170 | ||
163 | static const char *class_decode(const int class) | 171 | static const char *class_decode(const int class) |
@@ -494,7 +502,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, | |||
494 | return 0; | 502 | return 0; |
495 | /* allocate 2^1 pages = 8K (on i386); | 503 | /* allocate 2^1 pages = 8K (on i386); |
496 | * should be more than enough for one device */ | 504 | * should be more than enough for one device */ |
497 | pages_start = (char *)__get_free_pages(GFP_KERNEL, 1); | 505 | pages_start = (char *)__get_free_pages(GFP_NOIO, 1); |
498 | if (!pages_start) | 506 | if (!pages_start) |
499 | return -ENOMEM; | 507 | return -ENOMEM; |
500 | 508 | ||
@@ -629,55 +637,16 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, | |||
629 | static unsigned int usb_device_poll(struct file *file, | 637 | static unsigned int usb_device_poll(struct file *file, |
630 | struct poll_table_struct *wait) | 638 | struct poll_table_struct *wait) |
631 | { | 639 | { |
632 | struct usb_device_status *st = file->private_data; | 640 | unsigned int event_count; |
633 | unsigned int mask = 0; | ||
634 | |||
635 | lock_kernel(); | ||
636 | if (!st) { | ||
637 | st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); | ||
638 | |||
639 | /* we may have dropped BKL - | ||
640 | * need to check for having lost the race */ | ||
641 | if (file->private_data) { | ||
642 | kfree(st); | ||
643 | st = file->private_data; | ||
644 | goto lost_race; | ||
645 | } | ||
646 | /* we haven't lost - check for allocation failure now */ | ||
647 | if (!st) { | ||
648 | unlock_kernel(); | ||
649 | return POLLIN; | ||
650 | } | ||
651 | 641 | ||
652 | /* | 642 | poll_wait(file, &device_event.wait, wait); |
653 | * need to prevent the module from being unloaded, since | ||
654 | * proc_unregister does not call the release method and | ||
655 | * we would have a memory leak | ||
656 | */ | ||
657 | st->lastev = conndiscevcnt; | ||
658 | file->private_data = st; | ||
659 | mask = POLLIN; | ||
660 | } | ||
661 | lost_race: | ||
662 | if (file->f_mode & FMODE_READ) | ||
663 | poll_wait(file, &deviceconndiscwq, wait); | ||
664 | if (st->lastev != conndiscevcnt) | ||
665 | mask |= POLLIN; | ||
666 | st->lastev = conndiscevcnt; | ||
667 | unlock_kernel(); | ||
668 | return mask; | ||
669 | } | ||
670 | 643 | ||
671 | static int usb_device_open(struct inode *inode, struct file *file) | 644 | event_count = atomic_read(&device_event.count); |
672 | { | 645 | if (file->f_version != event_count) { |
673 | file->private_data = NULL; | 646 | file->f_version = event_count; |
674 | return 0; | 647 | return POLLIN | POLLRDNORM; |
675 | } | 648 | } |
676 | 649 | ||
677 | static int usb_device_release(struct inode *inode, struct file *file) | ||
678 | { | ||
679 | kfree(file->private_data); | ||
680 | file->private_data = NULL; | ||
681 | return 0; | 650 | return 0; |
682 | } | 651 | } |
683 | 652 | ||
@@ -685,7 +654,7 @@ static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig) | |||
685 | { | 654 | { |
686 | loff_t ret; | 655 | loff_t ret; |
687 | 656 | ||
688 | lock_kernel(); | 657 | mutex_lock(&file->f_dentry->d_inode->i_mutex); |
689 | 658 | ||
690 | switch (orig) { | 659 | switch (orig) { |
691 | case 0: | 660 | case 0: |
@@ -701,7 +670,7 @@ static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig) | |||
701 | ret = -EINVAL; | 670 | ret = -EINVAL; |
702 | } | 671 | } |
703 | 672 | ||
704 | unlock_kernel(); | 673 | mutex_unlock(&file->f_dentry->d_inode->i_mutex); |
705 | return ret; | 674 | return ret; |
706 | } | 675 | } |
707 | 676 | ||
@@ -709,6 +678,4 @@ const struct file_operations usbfs_devices_fops = { | |||
709 | .llseek = usb_device_lseek, | 678 | .llseek = usb_device_lseek, |
710 | .read = usb_device_read, | 679 | .read = usb_device_read, |
711 | .poll = usb_device_poll, | 680 | .poll = usb_device_poll, |
712 | .open = usb_device_open, | ||
713 | .release = usb_device_release, | ||
714 | }; | 681 | }; |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 181f78c84105..3466fdc5bb11 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -122,7 +122,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) | |||
122 | { | 122 | { |
123 | loff_t ret; | 123 | loff_t ret; |
124 | 124 | ||
125 | lock_kernel(); | 125 | mutex_lock(&file->f_dentry->d_inode->i_mutex); |
126 | 126 | ||
127 | switch (orig) { | 127 | switch (orig) { |
128 | case 0: | 128 | case 0: |
@@ -138,7 +138,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) | |||
138 | ret = -EINVAL; | 138 | ret = -EINVAL; |
139 | } | 139 | } |
140 | 140 | ||
141 | unlock_kernel(); | 141 | mutex_unlock(&file->f_dentry->d_inode->i_mutex); |
142 | return ret; | 142 | return ret; |
143 | } | 143 | } |
144 | 144 | ||
@@ -310,7 +310,8 @@ static struct async *async_getpending(struct dev_state *ps, | |||
310 | 310 | ||
311 | static void snoop_urb(struct usb_device *udev, | 311 | static void snoop_urb(struct usb_device *udev, |
312 | void __user *userurb, int pipe, unsigned length, | 312 | void __user *userurb, int pipe, unsigned length, |
313 | int timeout_or_status, enum snoop_when when) | 313 | int timeout_or_status, enum snoop_when when, |
314 | unsigned char *data, unsigned data_len) | ||
314 | { | 315 | { |
315 | static const char *types[] = {"isoc", "int", "ctrl", "bulk"}; | 316 | static const char *types[] = {"isoc", "int", "ctrl", "bulk"}; |
316 | static const char *dirs[] = {"out", "in"}; | 317 | static const char *dirs[] = {"out", "in"}; |
@@ -344,6 +345,11 @@ static void snoop_urb(struct usb_device *udev, | |||
344 | "status %d\n", | 345 | "status %d\n", |
345 | ep, t, d, length, timeout_or_status); | 346 | ep, t, d, length, timeout_or_status); |
346 | } | 347 | } |
348 | |||
349 | if (data && data_len > 0) { | ||
350 | print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE, 32, 1, | ||
351 | data, data_len, 1); | ||
352 | } | ||
347 | } | 353 | } |
348 | 354 | ||
349 | #define AS_CONTINUATION 1 | 355 | #define AS_CONTINUATION 1 |
@@ -410,7 +416,9 @@ static void async_completed(struct urb *urb) | |||
410 | } | 416 | } |
411 | snoop(&urb->dev->dev, "urb complete\n"); | 417 | snoop(&urb->dev->dev, "urb complete\n"); |
412 | snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length, | 418 | snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length, |
413 | as->status, COMPLETE); | 419 | as->status, COMPLETE, |
420 | ((urb->transfer_flags & URB_DIR_MASK) == USB_DIR_OUT) ? | ||
421 | NULL : urb->transfer_buffer, urb->actual_length); | ||
414 | if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && | 422 | if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && |
415 | as->status != -ENOENT) | 423 | as->status != -ENOENT) |
416 | cancel_bulk_urbs(ps, as->bulk_addr); | 424 | cancel_bulk_urbs(ps, as->bulk_addr); |
@@ -653,20 +661,20 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
653 | const struct cred *cred = current_cred(); | 661 | const struct cred *cred = current_cred(); |
654 | int ret; | 662 | int ret; |
655 | 663 | ||
656 | lock_kernel(); | ||
657 | /* Protect against simultaneous removal or release */ | ||
658 | mutex_lock(&usbfs_mutex); | ||
659 | |||
660 | ret = -ENOMEM; | 664 | ret = -ENOMEM; |
661 | ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL); | 665 | ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL); |
662 | if (!ps) | 666 | if (!ps) |
663 | goto out; | 667 | goto out_free_ps; |
664 | 668 | ||
665 | ret = -ENODEV; | 669 | ret = -ENODEV; |
666 | 670 | ||
671 | /* Protect against simultaneous removal or release */ | ||
672 | mutex_lock(&usbfs_mutex); | ||
673 | |||
667 | /* usbdev device-node */ | 674 | /* usbdev device-node */ |
668 | if (imajor(inode) == USB_DEVICE_MAJOR) | 675 | if (imajor(inode) == USB_DEVICE_MAJOR) |
669 | dev = usbdev_lookup_by_devt(inode->i_rdev); | 676 | dev = usbdev_lookup_by_devt(inode->i_rdev); |
677 | |||
670 | #ifdef CONFIG_USB_DEVICEFS | 678 | #ifdef CONFIG_USB_DEVICEFS |
671 | /* procfs file */ | 679 | /* procfs file */ |
672 | if (!dev) { | 680 | if (!dev) { |
@@ -678,13 +686,19 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
678 | dev = NULL; | 686 | dev = NULL; |
679 | } | 687 | } |
680 | #endif | 688 | #endif |
681 | if (!dev || dev->state == USB_STATE_NOTATTACHED) | 689 | mutex_unlock(&usbfs_mutex); |
682 | goto out; | 690 | |
691 | if (!dev) | ||
692 | goto out_free_ps; | ||
693 | |||
694 | usb_lock_device(dev); | ||
695 | if (dev->state == USB_STATE_NOTATTACHED) | ||
696 | goto out_unlock_device; | ||
697 | |||
683 | ret = usb_autoresume_device(dev); | 698 | ret = usb_autoresume_device(dev); |
684 | if (ret) | 699 | if (ret) |
685 | goto out; | 700 | goto out_unlock_device; |
686 | 701 | ||
687 | ret = 0; | ||
688 | ps->dev = dev; | 702 | ps->dev = dev; |
689 | ps->file = file; | 703 | ps->file = file; |
690 | spin_lock_init(&ps->lock); | 704 | spin_lock_init(&ps->lock); |
@@ -702,15 +716,16 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
702 | smp_wmb(); | 716 | smp_wmb(); |
703 | list_add_tail(&ps->list, &dev->filelist); | 717 | list_add_tail(&ps->list, &dev->filelist); |
704 | file->private_data = ps; | 718 | file->private_data = ps; |
719 | usb_unlock_device(dev); | ||
705 | snoop(&dev->dev, "opened by process %d: %s\n", task_pid_nr(current), | 720 | snoop(&dev->dev, "opened by process %d: %s\n", task_pid_nr(current), |
706 | current->comm); | 721 | current->comm); |
707 | out: | 722 | return ret; |
708 | if (ret) { | 723 | |
709 | kfree(ps); | 724 | out_unlock_device: |
710 | usb_put_dev(dev); | 725 | usb_unlock_device(dev); |
711 | } | 726 | usb_put_dev(dev); |
712 | mutex_unlock(&usbfs_mutex); | 727 | out_free_ps: |
713 | unlock_kernel(); | 728 | kfree(ps); |
714 | return ret; | 729 | return ret; |
715 | } | 730 | } |
716 | 731 | ||
@@ -724,10 +739,7 @@ static int usbdev_release(struct inode *inode, struct file *file) | |||
724 | usb_lock_device(dev); | 739 | usb_lock_device(dev); |
725 | usb_hub_release_all_ports(dev, ps); | 740 | usb_hub_release_all_ports(dev, ps); |
726 | 741 | ||
727 | /* Protect against simultaneous open */ | ||
728 | mutex_lock(&usbfs_mutex); | ||
729 | list_del_init(&ps->list); | 742 | list_del_init(&ps->list); |
730 | mutex_unlock(&usbfs_mutex); | ||
731 | 743 | ||
732 | for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); | 744 | for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); |
733 | ifnum++) { | 745 | ifnum++) { |
@@ -770,6 +782,13 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
770 | if (!tbuf) | 782 | if (!tbuf) |
771 | return -ENOMEM; | 783 | return -ENOMEM; |
772 | tmo = ctrl.timeout; | 784 | tmo = ctrl.timeout; |
785 | snoop(&dev->dev, "control urb: bRequestType=%02x " | ||
786 | "bRequest=%02x wValue=%04x " | ||
787 | "wIndex=%04x wLength=%04x\n", | ||
788 | ctrl.bRequestType, ctrl.bRequest, | ||
789 | __le16_to_cpup(&ctrl.wValue), | ||
790 | __le16_to_cpup(&ctrl.wIndex), | ||
791 | __le16_to_cpup(&ctrl.wLength)); | ||
773 | if (ctrl.bRequestType & 0x80) { | 792 | if (ctrl.bRequestType & 0x80) { |
774 | if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, | 793 | if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, |
775 | ctrl.wLength)) { | 794 | ctrl.wLength)) { |
@@ -777,15 +796,15 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
777 | return -EINVAL; | 796 | return -EINVAL; |
778 | } | 797 | } |
779 | pipe = usb_rcvctrlpipe(dev, 0); | 798 | pipe = usb_rcvctrlpipe(dev, 0); |
780 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); | 799 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT, NULL, 0); |
781 | 800 | ||
782 | usb_unlock_device(dev); | 801 | usb_unlock_device(dev); |
783 | i = usb_control_msg(dev, pipe, ctrl.bRequest, | 802 | i = usb_control_msg(dev, pipe, ctrl.bRequest, |
784 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, | 803 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, |
785 | tbuf, ctrl.wLength, tmo); | 804 | tbuf, ctrl.wLength, tmo); |
786 | usb_lock_device(dev); | 805 | usb_lock_device(dev); |
787 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); | 806 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, |
788 | 807 | tbuf, i); | |
789 | if ((i > 0) && ctrl.wLength) { | 808 | if ((i > 0) && ctrl.wLength) { |
790 | if (copy_to_user(ctrl.data, tbuf, i)) { | 809 | if (copy_to_user(ctrl.data, tbuf, i)) { |
791 | free_page((unsigned long)tbuf); | 810 | free_page((unsigned long)tbuf); |
@@ -800,14 +819,15 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
800 | } | 819 | } |
801 | } | 820 | } |
802 | pipe = usb_sndctrlpipe(dev, 0); | 821 | pipe = usb_sndctrlpipe(dev, 0); |
803 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); | 822 | snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT, |
823 | tbuf, ctrl.wLength); | ||
804 | 824 | ||
805 | usb_unlock_device(dev); | 825 | usb_unlock_device(dev); |
806 | i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, | 826 | i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, |
807 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, | 827 | ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, |
808 | tbuf, ctrl.wLength, tmo); | 828 | tbuf, ctrl.wLength, tmo); |
809 | usb_lock_device(dev); | 829 | usb_lock_device(dev); |
810 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); | 830 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, NULL, 0); |
811 | } | 831 | } |
812 | free_page((unsigned long)tbuf); | 832 | free_page((unsigned long)tbuf); |
813 | if (i < 0 && i != -EPIPE) { | 833 | if (i < 0 && i != -EPIPE) { |
@@ -853,12 +873,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) | |||
853 | kfree(tbuf); | 873 | kfree(tbuf); |
854 | return -EINVAL; | 874 | return -EINVAL; |
855 | } | 875 | } |
856 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); | 876 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT, NULL, 0); |
857 | 877 | ||
858 | usb_unlock_device(dev); | 878 | usb_unlock_device(dev); |
859 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); | 879 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); |
860 | usb_lock_device(dev); | 880 | usb_lock_device(dev); |
861 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); | 881 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE, tbuf, len2); |
862 | 882 | ||
863 | if (!i && len2) { | 883 | if (!i && len2) { |
864 | if (copy_to_user(bulk.data, tbuf, len2)) { | 884 | if (copy_to_user(bulk.data, tbuf, len2)) { |
@@ -873,12 +893,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg) | |||
873 | return -EFAULT; | 893 | return -EFAULT; |
874 | } | 894 | } |
875 | } | 895 | } |
876 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); | 896 | snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT, tbuf, len1); |
877 | 897 | ||
878 | usb_unlock_device(dev); | 898 | usb_unlock_device(dev); |
879 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); | 899 | i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); |
880 | usb_lock_device(dev); | 900 | usb_lock_device(dev); |
881 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); | 901 | snoop_urb(dev, NULL, pipe, len2, i, COMPLETE, NULL, 0); |
882 | } | 902 | } |
883 | kfree(tbuf); | 903 | kfree(tbuf); |
884 | if (i < 0) | 904 | if (i < 0) |
@@ -1097,6 +1117,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1097 | is_in = 0; | 1117 | is_in = 0; |
1098 | uurb->endpoint &= ~USB_DIR_IN; | 1118 | uurb->endpoint &= ~USB_DIR_IN; |
1099 | } | 1119 | } |
1120 | snoop(&ps->dev->dev, "control urb: bRequestType=%02x " | ||
1121 | "bRequest=%02x wValue=%04x " | ||
1122 | "wIndex=%04x wLength=%04x\n", | ||
1123 | dr->bRequestType, dr->bRequest, | ||
1124 | __le16_to_cpup(&dr->wValue), | ||
1125 | __le16_to_cpup(&dr->wIndex), | ||
1126 | __le16_to_cpup(&dr->wLength)); | ||
1100 | break; | 1127 | break; |
1101 | 1128 | ||
1102 | case USBDEVFS_URB_TYPE_BULK: | 1129 | case USBDEVFS_URB_TYPE_BULK: |
@@ -1104,13 +1131,25 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1104 | case USB_ENDPOINT_XFER_CONTROL: | 1131 | case USB_ENDPOINT_XFER_CONTROL: |
1105 | case USB_ENDPOINT_XFER_ISOC: | 1132 | case USB_ENDPOINT_XFER_ISOC: |
1106 | return -EINVAL; | 1133 | return -EINVAL; |
1107 | /* allow single-shot interrupt transfers, at bogus rates */ | 1134 | case USB_ENDPOINT_XFER_INT: |
1135 | /* allow single-shot interrupt transfers */ | ||
1136 | uurb->type = USBDEVFS_URB_TYPE_INTERRUPT; | ||
1137 | goto interrupt_urb; | ||
1108 | } | 1138 | } |
1109 | uurb->number_of_packets = 0; | 1139 | uurb->number_of_packets = 0; |
1110 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | 1140 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) |
1111 | return -EINVAL; | 1141 | return -EINVAL; |
1112 | break; | 1142 | break; |
1113 | 1143 | ||
1144 | case USBDEVFS_URB_TYPE_INTERRUPT: | ||
1145 | if (!usb_endpoint_xfer_int(&ep->desc)) | ||
1146 | return -EINVAL; | ||
1147 | interrupt_urb: | ||
1148 | uurb->number_of_packets = 0; | ||
1149 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | ||
1150 | return -EINVAL; | ||
1151 | break; | ||
1152 | |||
1114 | case USBDEVFS_URB_TYPE_ISO: | 1153 | case USBDEVFS_URB_TYPE_ISO: |
1115 | /* arbitrary limit */ | 1154 | /* arbitrary limit */ |
1116 | if (uurb->number_of_packets < 1 || | 1155 | if (uurb->number_of_packets < 1 || |
@@ -1143,14 +1182,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1143 | uurb->buffer_length = totlen; | 1182 | uurb->buffer_length = totlen; |
1144 | break; | 1183 | break; |
1145 | 1184 | ||
1146 | case USBDEVFS_URB_TYPE_INTERRUPT: | ||
1147 | uurb->number_of_packets = 0; | ||
1148 | if (!usb_endpoint_xfer_int(&ep->desc)) | ||
1149 | return -EINVAL; | ||
1150 | if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) | ||
1151 | return -EINVAL; | ||
1152 | break; | ||
1153 | |||
1154 | default: | 1185 | default: |
1155 | return -EINVAL; | 1186 | return -EINVAL; |
1156 | } | 1187 | } |
@@ -1176,6 +1207,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1176 | free_async(as); | 1207 | free_async(as); |
1177 | return -ENOMEM; | 1208 | return -ENOMEM; |
1178 | } | 1209 | } |
1210 | /* Isochronous input data may end up being discontiguous | ||
1211 | * if some of the packets are short. Clear the buffer so | ||
1212 | * that the gaps don't leak kernel data to userspace. | ||
1213 | */ | ||
1214 | if (is_in && uurb->type == USBDEVFS_URB_TYPE_ISO) | ||
1215 | memset(as->urb->transfer_buffer, 0, | ||
1216 | uurb->buffer_length); | ||
1179 | } | 1217 | } |
1180 | as->urb->dev = ps->dev; | 1218 | as->urb->dev = ps->dev; |
1181 | as->urb->pipe = (uurb->type << 30) | | 1219 | as->urb->pipe = (uurb->type << 30) | |
@@ -1236,7 +1274,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1236 | } | 1274 | } |
1237 | } | 1275 | } |
1238 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, | 1276 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, |
1239 | as->urb->transfer_buffer_length, 0, SUBMIT); | 1277 | as->urb->transfer_buffer_length, 0, SUBMIT, |
1278 | is_in ? NULL : as->urb->transfer_buffer, | ||
1279 | uurb->buffer_length); | ||
1240 | async_newpending(as); | 1280 | async_newpending(as); |
1241 | 1281 | ||
1242 | if (usb_endpoint_xfer_bulk(&ep->desc)) { | 1282 | if (usb_endpoint_xfer_bulk(&ep->desc)) { |
@@ -1274,7 +1314,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1274 | dev_printk(KERN_DEBUG, &ps->dev->dev, | 1314 | dev_printk(KERN_DEBUG, &ps->dev->dev, |
1275 | "usbfs: usb_submit_urb returned %d\n", ret); | 1315 | "usbfs: usb_submit_urb returned %d\n", ret); |
1276 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, | 1316 | snoop_urb(ps->dev, as->userurb, as->urb->pipe, |
1277 | 0, ret, COMPLETE); | 1317 | 0, ret, COMPLETE, NULL, 0); |
1278 | async_removepending(as); | 1318 | async_removepending(as); |
1279 | free_async(as); | 1319 | free_async(as); |
1280 | return ret; | 1320 | return ret; |
@@ -1312,10 +1352,14 @@ static int processcompl(struct async *as, void __user * __user *arg) | |||
1312 | void __user *addr = as->userurb; | 1352 | void __user *addr = as->userurb; |
1313 | unsigned int i; | 1353 | unsigned int i; |
1314 | 1354 | ||
1315 | if (as->userbuffer) | 1355 | if (as->userbuffer && urb->actual_length) { |
1316 | if (copy_to_user(as->userbuffer, urb->transfer_buffer, | 1356 | if (urb->number_of_packets > 0) /* Isochronous */ |
1317 | urb->transfer_buffer_length)) | 1357 | i = urb->transfer_buffer_length; |
1358 | else /* Non-Isoc */ | ||
1359 | i = urb->actual_length; | ||
1360 | if (copy_to_user(as->userbuffer, urb->transfer_buffer, i)) | ||
1318 | goto err_out; | 1361 | goto err_out; |
1362 | } | ||
1319 | if (put_user(as->status, &userurb->status)) | 1363 | if (put_user(as->status, &userurb->status)) |
1320 | goto err_out; | 1364 | goto err_out; |
1321 | if (put_user(urb->actual_length, &userurb->actual_length)) | 1365 | if (put_user(urb->actual_length, &userurb->actual_length)) |
@@ -1334,14 +1378,11 @@ static int processcompl(struct async *as, void __user * __user *arg) | |||
1334 | } | 1378 | } |
1335 | } | 1379 | } |
1336 | 1380 | ||
1337 | free_async(as); | ||
1338 | |||
1339 | if (put_user(addr, (void __user * __user *)arg)) | 1381 | if (put_user(addr, (void __user * __user *)arg)) |
1340 | return -EFAULT; | 1382 | return -EFAULT; |
1341 | return 0; | 1383 | return 0; |
1342 | 1384 | ||
1343 | err_out: | 1385 | err_out: |
1344 | free_async(as); | ||
1345 | return -EFAULT; | 1386 | return -EFAULT; |
1346 | } | 1387 | } |
1347 | 1388 | ||
@@ -1371,8 +1412,11 @@ static struct async *reap_as(struct dev_state *ps) | |||
1371 | static int proc_reapurb(struct dev_state *ps, void __user *arg) | 1412 | static int proc_reapurb(struct dev_state *ps, void __user *arg) |
1372 | { | 1413 | { |
1373 | struct async *as = reap_as(ps); | 1414 | struct async *as = reap_as(ps); |
1374 | if (as) | 1415 | if (as) { |
1375 | return processcompl(as, (void __user * __user *)arg); | 1416 | int retval = processcompl(as, (void __user * __user *)arg); |
1417 | free_async(as); | ||
1418 | return retval; | ||
1419 | } | ||
1376 | if (signal_pending(current)) | 1420 | if (signal_pending(current)) |
1377 | return -EINTR; | 1421 | return -EINTR; |
1378 | return -EIO; | 1422 | return -EIO; |
@@ -1380,14 +1424,59 @@ static int proc_reapurb(struct dev_state *ps, void __user *arg) | |||
1380 | 1424 | ||
1381 | static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg) | 1425 | static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg) |
1382 | { | 1426 | { |
1427 | int retval; | ||
1383 | struct async *as; | 1428 | struct async *as; |
1384 | 1429 | ||
1385 | if (!(as = async_getcompleted(ps))) | 1430 | as = async_getcompleted(ps); |
1386 | return -EAGAIN; | 1431 | retval = -EAGAIN; |
1387 | return processcompl(as, (void __user * __user *)arg); | 1432 | if (as) { |
1433 | retval = processcompl(as, (void __user * __user *)arg); | ||
1434 | free_async(as); | ||
1435 | } | ||
1436 | return retval; | ||
1388 | } | 1437 | } |
1389 | 1438 | ||
1390 | #ifdef CONFIG_COMPAT | 1439 | #ifdef CONFIG_COMPAT |
1440 | static int proc_control_compat(struct dev_state *ps, | ||
1441 | struct usbdevfs_ctrltransfer32 __user *p32) | ||
1442 | { | ||
1443 | struct usbdevfs_ctrltransfer __user *p; | ||
1444 | __u32 udata; | ||
1445 | p = compat_alloc_user_space(sizeof(*p)); | ||
1446 | if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || | ||
1447 | get_user(udata, &p32->data) || | ||
1448 | put_user(compat_ptr(udata), &p->data)) | ||
1449 | return -EFAULT; | ||
1450 | return proc_control(ps, p); | ||
1451 | } | ||
1452 | |||
1453 | static int proc_bulk_compat(struct dev_state *ps, | ||
1454 | struct usbdevfs_bulktransfer32 __user *p32) | ||
1455 | { | ||
1456 | struct usbdevfs_bulktransfer __user *p; | ||
1457 | compat_uint_t n; | ||
1458 | compat_caddr_t addr; | ||
1459 | |||
1460 | p = compat_alloc_user_space(sizeof(*p)); | ||
1461 | |||
1462 | if (get_user(n, &p32->ep) || put_user(n, &p->ep) || | ||
1463 | get_user(n, &p32->len) || put_user(n, &p->len) || | ||
1464 | get_user(n, &p32->timeout) || put_user(n, &p->timeout) || | ||
1465 | get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) | ||
1466 | return -EFAULT; | ||
1467 | |||
1468 | return proc_bulk(ps, p); | ||
1469 | } | ||
1470 | static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg) | ||
1471 | { | ||
1472 | struct usbdevfs_disconnectsignal32 ds; | ||
1473 | |||
1474 | if (copy_from_user(&ds, arg, sizeof(ds))) | ||
1475 | return -EFAULT; | ||
1476 | ps->discsignr = ds.signr; | ||
1477 | ps->disccontext = compat_ptr(ds.context); | ||
1478 | return 0; | ||
1479 | } | ||
1391 | 1480 | ||
1392 | static int get_urb32(struct usbdevfs_urb *kurb, | 1481 | static int get_urb32(struct usbdevfs_urb *kurb, |
1393 | struct usbdevfs_urb32 __user *uurb) | 1482 | struct usbdevfs_urb32 __user *uurb) |
@@ -1435,9 +1524,9 @@ static int processcompl_compat(struct async *as, void __user * __user *arg) | |||
1435 | void __user *addr = as->userurb; | 1524 | void __user *addr = as->userurb; |
1436 | unsigned int i; | 1525 | unsigned int i; |
1437 | 1526 | ||
1438 | if (as->userbuffer) | 1527 | if (as->userbuffer && urb->actual_length) |
1439 | if (copy_to_user(as->userbuffer, urb->transfer_buffer, | 1528 | if (copy_to_user(as->userbuffer, urb->transfer_buffer, |
1440 | urb->transfer_buffer_length)) | 1529 | urb->actual_length)) |
1441 | return -EFAULT; | 1530 | return -EFAULT; |
1442 | if (put_user(as->status, &userurb->status)) | 1531 | if (put_user(as->status, &userurb->status)) |
1443 | return -EFAULT; | 1532 | return -EFAULT; |
@@ -1457,7 +1546,6 @@ static int processcompl_compat(struct async *as, void __user * __user *arg) | |||
1457 | } | 1546 | } |
1458 | } | 1547 | } |
1459 | 1548 | ||
1460 | free_async(as); | ||
1461 | if (put_user(ptr_to_compat(addr), (u32 __user *)arg)) | 1549 | if (put_user(ptr_to_compat(addr), (u32 __user *)arg)) |
1462 | return -EFAULT; | 1550 | return -EFAULT; |
1463 | return 0; | 1551 | return 0; |
@@ -1466,8 +1554,11 @@ static int processcompl_compat(struct async *as, void __user * __user *arg) | |||
1466 | static int proc_reapurb_compat(struct dev_state *ps, void __user *arg) | 1554 | static int proc_reapurb_compat(struct dev_state *ps, void __user *arg) |
1467 | { | 1555 | { |
1468 | struct async *as = reap_as(ps); | 1556 | struct async *as = reap_as(ps); |
1469 | if (as) | 1557 | if (as) { |
1470 | return processcompl_compat(as, (void __user * __user *)arg); | 1558 | int retval = processcompl_compat(as, (void __user * __user *)arg); |
1559 | free_async(as); | ||
1560 | return retval; | ||
1561 | } | ||
1471 | if (signal_pending(current)) | 1562 | if (signal_pending(current)) |
1472 | return -EINTR; | 1563 | return -EINTR; |
1473 | return -EIO; | 1564 | return -EIO; |
@@ -1475,13 +1566,19 @@ static int proc_reapurb_compat(struct dev_state *ps, void __user *arg) | |||
1475 | 1566 | ||
1476 | static int proc_reapurbnonblock_compat(struct dev_state *ps, void __user *arg) | 1567 | static int proc_reapurbnonblock_compat(struct dev_state *ps, void __user *arg) |
1477 | { | 1568 | { |
1569 | int retval; | ||
1478 | struct async *as; | 1570 | struct async *as; |
1479 | 1571 | ||
1480 | if (!(as = async_getcompleted(ps))) | 1572 | retval = -EAGAIN; |
1481 | return -EAGAIN; | 1573 | as = async_getcompleted(ps); |
1482 | return processcompl_compat(as, (void __user * __user *)arg); | 1574 | if (as) { |
1575 | retval = processcompl_compat(as, (void __user * __user *)arg); | ||
1576 | free_async(as); | ||
1577 | } | ||
1578 | return retval; | ||
1483 | } | 1579 | } |
1484 | 1580 | ||
1581 | |||
1485 | #endif | 1582 | #endif |
1486 | 1583 | ||
1487 | static int proc_disconnectsignal(struct dev_state *ps, void __user *arg) | 1584 | static int proc_disconnectsignal(struct dev_state *ps, void __user *arg) |
@@ -1575,7 +1672,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1575 | if (driver == NULL || driver->ioctl == NULL) { | 1672 | if (driver == NULL || driver->ioctl == NULL) { |
1576 | retval = -ENOTTY; | 1673 | retval = -ENOTTY; |
1577 | } else { | 1674 | } else { |
1675 | /* keep API that guarantees BKL */ | ||
1676 | lock_kernel(); | ||
1578 | retval = driver->ioctl(intf, ctl->ioctl_code, buf); | 1677 | retval = driver->ioctl(intf, ctl->ioctl_code, buf); |
1678 | unlock_kernel(); | ||
1579 | if (retval == -ENOIOCTLCMD) | 1679 | if (retval == -ENOIOCTLCMD) |
1580 | retval = -ENOTTY; | 1680 | retval = -ENOTTY; |
1581 | } | 1681 | } |
@@ -1648,16 +1748,17 @@ static int proc_release_port(struct dev_state *ps, void __user *arg) | |||
1648 | * are assuming that somehow the configuration has been prevented from | 1748 | * are assuming that somehow the configuration has been prevented from |
1649 | * changing. But there's no mechanism to ensure that... | 1749 | * changing. But there's no mechanism to ensure that... |
1650 | */ | 1750 | */ |
1651 | static int usbdev_ioctl(struct inode *inode, struct file *file, | 1751 | static long usbdev_do_ioctl(struct file *file, unsigned int cmd, |
1652 | unsigned int cmd, unsigned long arg) | 1752 | void __user *p) |
1653 | { | 1753 | { |
1654 | struct dev_state *ps = file->private_data; | 1754 | struct dev_state *ps = file->private_data; |
1755 | struct inode *inode = file->f_path.dentry->d_inode; | ||
1655 | struct usb_device *dev = ps->dev; | 1756 | struct usb_device *dev = ps->dev; |
1656 | void __user *p = (void __user *)arg; | ||
1657 | int ret = -ENOTTY; | 1757 | int ret = -ENOTTY; |
1658 | 1758 | ||
1659 | if (!(file->f_mode & FMODE_WRITE)) | 1759 | if (!(file->f_mode & FMODE_WRITE)) |
1660 | return -EPERM; | 1760 | return -EPERM; |
1761 | |||
1661 | usb_lock_device(dev); | 1762 | usb_lock_device(dev); |
1662 | if (!connected(ps)) { | 1763 | if (!connected(ps)) { |
1663 | usb_unlock_device(dev); | 1764 | usb_unlock_device(dev); |
@@ -1726,6 +1827,24 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1726 | break; | 1827 | break; |
1727 | 1828 | ||
1728 | #ifdef CONFIG_COMPAT | 1829 | #ifdef CONFIG_COMPAT |
1830 | case USBDEVFS_CONTROL32: | ||
1831 | snoop(&dev->dev, "%s: CONTROL32\n", __func__); | ||
1832 | ret = proc_control_compat(ps, p); | ||
1833 | if (ret >= 0) | ||
1834 | inode->i_mtime = CURRENT_TIME; | ||
1835 | break; | ||
1836 | |||
1837 | case USBDEVFS_BULK32: | ||
1838 | snoop(&dev->dev, "%s: BULK32\n", __func__); | ||
1839 | ret = proc_bulk_compat(ps, p); | ||
1840 | if (ret >= 0) | ||
1841 | inode->i_mtime = CURRENT_TIME; | ||
1842 | break; | ||
1843 | |||
1844 | case USBDEVFS_DISCSIGNAL32: | ||
1845 | snoop(&dev->dev, "%s: DISCSIGNAL32\n", __func__); | ||
1846 | ret = proc_disconnectsignal_compat(ps, p); | ||
1847 | break; | ||
1729 | 1848 | ||
1730 | case USBDEVFS_SUBMITURB32: | 1849 | case USBDEVFS_SUBMITURB32: |
1731 | snoop(&dev->dev, "%s: SUBMITURB32\n", __func__); | 1850 | snoop(&dev->dev, "%s: SUBMITURB32\n", __func__); |
@@ -1745,7 +1864,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1745 | break; | 1864 | break; |
1746 | 1865 | ||
1747 | case USBDEVFS_IOCTL32: | 1866 | case USBDEVFS_IOCTL32: |
1748 | snoop(&dev->dev, "%s: IOCTL\n", __func__); | 1867 | snoop(&dev->dev, "%s: IOCTL32\n", __func__); |
1749 | ret = proc_ioctl_compat(ps, ptr_to_compat(p)); | 1868 | ret = proc_ioctl_compat(ps, ptr_to_compat(p)); |
1750 | break; | 1869 | break; |
1751 | #endif | 1870 | #endif |
@@ -1801,6 +1920,28 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, | |||
1801 | return ret; | 1920 | return ret; |
1802 | } | 1921 | } |
1803 | 1922 | ||
1923 | static long usbdev_ioctl(struct file *file, unsigned int cmd, | ||
1924 | unsigned long arg) | ||
1925 | { | ||
1926 | int ret; | ||
1927 | |||
1928 | ret = usbdev_do_ioctl(file, cmd, (void __user *)arg); | ||
1929 | |||
1930 | return ret; | ||
1931 | } | ||
1932 | |||
1933 | #ifdef CONFIG_COMPAT | ||
1934 | static long usbdev_compat_ioctl(struct file *file, unsigned int cmd, | ||
1935 | unsigned long arg) | ||
1936 | { | ||
1937 | int ret; | ||
1938 | |||
1939 | ret = usbdev_do_ioctl(file, cmd, compat_ptr(arg)); | ||
1940 | |||
1941 | return ret; | ||
1942 | } | ||
1943 | #endif | ||
1944 | |||
1804 | /* No kernel lock - fine */ | 1945 | /* No kernel lock - fine */ |
1805 | static unsigned int usbdev_poll(struct file *file, | 1946 | static unsigned int usbdev_poll(struct file *file, |
1806 | struct poll_table_struct *wait) | 1947 | struct poll_table_struct *wait) |
@@ -1817,13 +1958,16 @@ static unsigned int usbdev_poll(struct file *file, | |||
1817 | } | 1958 | } |
1818 | 1959 | ||
1819 | const struct file_operations usbdev_file_operations = { | 1960 | const struct file_operations usbdev_file_operations = { |
1820 | .owner = THIS_MODULE, | 1961 | .owner = THIS_MODULE, |
1821 | .llseek = usbdev_lseek, | 1962 | .llseek = usbdev_lseek, |
1822 | .read = usbdev_read, | 1963 | .read = usbdev_read, |
1823 | .poll = usbdev_poll, | 1964 | .poll = usbdev_poll, |
1824 | .ioctl = usbdev_ioctl, | 1965 | .unlocked_ioctl = usbdev_ioctl, |
1825 | .open = usbdev_open, | 1966 | #ifdef CONFIG_COMPAT |
1826 | .release = usbdev_release, | 1967 | .compat_ioctl = usbdev_compat_ioctl, |
1968 | #endif | ||
1969 | .open = usbdev_open, | ||
1970 | .release = usbdev_release, | ||
1827 | }; | 1971 | }; |
1828 | 1972 | ||
1829 | static void usbdev_remove(struct usb_device *udev) | 1973 | static void usbdev_remove(struct usb_device *udev) |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 4f864472c5c4..2f3dc4cdf79b 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -23,9 +23,10 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/device.h> | 25 | #include <linux/device.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
27 | #include <linux/usb/quirks.h> | 28 | #include <linux/usb/quirks.h> |
28 | #include <linux/workqueue.h> | 29 | #include <linux/pm_runtime.h> |
29 | #include "hcd.h" | 30 | #include "hcd.h" |
30 | #include "usb.h" | 31 | #include "usb.h" |
31 | 32 | ||
@@ -83,6 +84,47 @@ static ssize_t store_new_id(struct device_driver *driver, | |||
83 | } | 84 | } |
84 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); | 85 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); |
85 | 86 | ||
87 | /** | ||
88 | * store_remove_id - remove a USB device ID from this driver | ||
89 | * @driver: target device driver | ||
90 | * @buf: buffer for scanning device ID data | ||
91 | * @count: input size | ||
92 | * | ||
93 | * Removes a dynamic usb device ID from this driver. | ||
94 | */ | ||
95 | static ssize_t | ||
96 | store_remove_id(struct device_driver *driver, const char *buf, size_t count) | ||
97 | { | ||
98 | struct usb_dynid *dynid, *n; | ||
99 | struct usb_driver *usb_driver = to_usb_driver(driver); | ||
100 | u32 idVendor = 0; | ||
101 | u32 idProduct = 0; | ||
102 | int fields = 0; | ||
103 | int retval = 0; | ||
104 | |||
105 | fields = sscanf(buf, "%x %x", &idVendor, &idProduct); | ||
106 | if (fields < 2) | ||
107 | return -EINVAL; | ||
108 | |||
109 | spin_lock(&usb_driver->dynids.lock); | ||
110 | list_for_each_entry_safe(dynid, n, &usb_driver->dynids.list, node) { | ||
111 | struct usb_device_id *id = &dynid->id; | ||
112 | if ((id->idVendor == idVendor) && | ||
113 | (id->idProduct == idProduct)) { | ||
114 | list_del(&dynid->node); | ||
115 | kfree(dynid); | ||
116 | retval = 0; | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | spin_unlock(&usb_driver->dynids.lock); | ||
121 | |||
122 | if (retval) | ||
123 | return retval; | ||
124 | return count; | ||
125 | } | ||
126 | static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id); | ||
127 | |||
86 | static int usb_create_newid_file(struct usb_driver *usb_drv) | 128 | static int usb_create_newid_file(struct usb_driver *usb_drv) |
87 | { | 129 | { |
88 | int error = 0; | 130 | int error = 0; |
@@ -107,6 +149,21 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv) | |||
107 | &driver_attr_new_id); | 149 | &driver_attr_new_id); |
108 | } | 150 | } |
109 | 151 | ||
152 | static int | ||
153 | usb_create_removeid_file(struct usb_driver *drv) | ||
154 | { | ||
155 | int error = 0; | ||
156 | if (drv->probe != NULL) | ||
157 | error = driver_create_file(&drv->drvwrap.driver, | ||
158 | &driver_attr_remove_id); | ||
159 | return error; | ||
160 | } | ||
161 | |||
162 | static void usb_remove_removeid_file(struct usb_driver *drv) | ||
163 | { | ||
164 | driver_remove_file(&drv->drvwrap.driver, &driver_attr_remove_id); | ||
165 | } | ||
166 | |||
110 | static void usb_free_dynids(struct usb_driver *usb_drv) | 167 | static void usb_free_dynids(struct usb_driver *usb_drv) |
111 | { | 168 | { |
112 | struct usb_dynid *dynid, *n; | 169 | struct usb_dynid *dynid, *n; |
@@ -128,6 +185,16 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv) | |||
128 | { | 185 | { |
129 | } | 186 | } |
130 | 187 | ||
188 | static int | ||
189 | usb_create_removeid_file(struct usb_driver *drv) | ||
190 | { | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static void usb_remove_removeid_file(struct usb_driver *drv) | ||
195 | { | ||
196 | } | ||
197 | |||
131 | static inline void usb_free_dynids(struct usb_driver *usb_drv) | 198 | static inline void usb_free_dynids(struct usb_driver *usb_drv) |
132 | { | 199 | { |
133 | } | 200 | } |
@@ -155,7 +222,7 @@ static int usb_probe_device(struct device *dev) | |||
155 | { | 222 | { |
156 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); | 223 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
157 | struct usb_device *udev = to_usb_device(dev); | 224 | struct usb_device *udev = to_usb_device(dev); |
158 | int error = -ENODEV; | 225 | int error = 0; |
159 | 226 | ||
160 | dev_dbg(dev, "%s\n", __func__); | 227 | dev_dbg(dev, "%s\n", __func__); |
161 | 228 | ||
@@ -164,18 +231,23 @@ static int usb_probe_device(struct device *dev) | |||
164 | /* The device should always appear to be in use | 231 | /* The device should always appear to be in use |
165 | * unless the driver suports autosuspend. | 232 | * unless the driver suports autosuspend. |
166 | */ | 233 | */ |
167 | udev->pm_usage_cnt = !(udriver->supports_autosuspend); | 234 | if (!udriver->supports_autosuspend) |
235 | error = usb_autoresume_device(udev); | ||
168 | 236 | ||
169 | error = udriver->probe(udev); | 237 | if (!error) |
238 | error = udriver->probe(udev); | ||
170 | return error; | 239 | return error; |
171 | } | 240 | } |
172 | 241 | ||
173 | /* called from driver core with dev locked */ | 242 | /* called from driver core with dev locked */ |
174 | static int usb_unbind_device(struct device *dev) | 243 | static int usb_unbind_device(struct device *dev) |
175 | { | 244 | { |
245 | struct usb_device *udev = to_usb_device(dev); | ||
176 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); | 246 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
177 | 247 | ||
178 | udriver->disconnect(to_usb_device(dev)); | 248 | udriver->disconnect(udev); |
249 | if (!udriver->supports_autosuspend) | ||
250 | usb_autosuspend_device(udev); | ||
179 | return 0; | 251 | return 0; |
180 | } | 252 | } |
181 | 253 | ||
@@ -208,60 +280,62 @@ static int usb_probe_interface(struct device *dev) | |||
208 | intf->needs_binding = 0; | 280 | intf->needs_binding = 0; |
209 | 281 | ||
210 | if (usb_device_is_owned(udev)) | 282 | if (usb_device_is_owned(udev)) |
211 | return -ENODEV; | 283 | return error; |
212 | 284 | ||
213 | if (udev->authorized == 0) { | 285 | if (udev->authorized == 0) { |
214 | dev_err(&intf->dev, "Device is not authorized for usage\n"); | 286 | dev_err(&intf->dev, "Device is not authorized for usage\n"); |
215 | return -ENODEV; | 287 | return error; |
216 | } | 288 | } |
217 | 289 | ||
218 | id = usb_match_id(intf, driver->id_table); | 290 | id = usb_match_id(intf, driver->id_table); |
219 | if (!id) | 291 | if (!id) |
220 | id = usb_match_dynamic_id(intf, driver); | 292 | id = usb_match_dynamic_id(intf, driver); |
221 | if (id) { | 293 | if (!id) |
222 | dev_dbg(dev, "%s - got id\n", __func__); | 294 | return error; |
223 | |||
224 | error = usb_autoresume_device(udev); | ||
225 | if (error) | ||
226 | return error; | ||
227 | |||
228 | /* Interface "power state" doesn't correspond to any hardware | ||
229 | * state whatsoever. We use it to record when it's bound to | ||
230 | * a driver that may start I/0: it's not frozen/quiesced. | ||
231 | */ | ||
232 | mark_active(intf); | ||
233 | intf->condition = USB_INTERFACE_BINDING; | ||
234 | 295 | ||
235 | /* The interface should always appear to be in use | 296 | dev_dbg(dev, "%s - got id\n", __func__); |
236 | * unless the driver suports autosuspend. | ||
237 | */ | ||
238 | atomic_set(&intf->pm_usage_cnt, !driver->supports_autosuspend); | ||
239 | 297 | ||
240 | /* Carry out a deferred switch to altsetting 0 */ | 298 | error = usb_autoresume_device(udev); |
241 | if (intf->needs_altsetting0) { | 299 | if (error) |
242 | error = usb_set_interface(udev, intf->altsetting[0]. | 300 | return error; |
243 | desc.bInterfaceNumber, 0); | ||
244 | if (error < 0) | ||
245 | goto err; | ||
246 | 301 | ||
247 | intf->needs_altsetting0 = 0; | 302 | intf->condition = USB_INTERFACE_BINDING; |
248 | } | ||
249 | 303 | ||
250 | error = driver->probe(intf, id); | 304 | /* Probed interfaces are initially active. They are |
251 | if (error) | 305 | * runtime-PM-enabled only if the driver has autosuspend support. |
306 | * They are sensitive to their children's power states. | ||
307 | */ | ||
308 | pm_runtime_set_active(dev); | ||
309 | pm_suspend_ignore_children(dev, false); | ||
310 | if (driver->supports_autosuspend) | ||
311 | pm_runtime_enable(dev); | ||
312 | |||
313 | /* Carry out a deferred switch to altsetting 0 */ | ||
314 | if (intf->needs_altsetting0) { | ||
315 | error = usb_set_interface(udev, intf->altsetting[0]. | ||
316 | desc.bInterfaceNumber, 0); | ||
317 | if (error < 0) | ||
252 | goto err; | 318 | goto err; |
253 | 319 | intf->needs_altsetting0 = 0; | |
254 | intf->condition = USB_INTERFACE_BOUND; | ||
255 | usb_autosuspend_device(udev); | ||
256 | } | 320 | } |
257 | 321 | ||
322 | error = driver->probe(intf, id); | ||
323 | if (error) | ||
324 | goto err; | ||
325 | |||
326 | intf->condition = USB_INTERFACE_BOUND; | ||
327 | usb_autosuspend_device(udev); | ||
258 | return error; | 328 | return error; |
259 | 329 | ||
260 | err: | 330 | err: |
261 | mark_quiesced(intf); | ||
262 | intf->needs_remote_wakeup = 0; | 331 | intf->needs_remote_wakeup = 0; |
263 | intf->condition = USB_INTERFACE_UNBOUND; | 332 | intf->condition = USB_INTERFACE_UNBOUND; |
264 | usb_cancel_queued_reset(intf); | 333 | usb_cancel_queued_reset(intf); |
334 | |||
335 | /* Unbound interfaces are always runtime-PM-disabled and -suspended */ | ||
336 | pm_runtime_disable(dev); | ||
337 | pm_runtime_set_suspended(dev); | ||
338 | |||
265 | usb_autosuspend_device(udev); | 339 | usb_autosuspend_device(udev); |
266 | return error; | 340 | return error; |
267 | } | 341 | } |
@@ -311,9 +385,17 @@ static int usb_unbind_interface(struct device *dev) | |||
311 | usb_set_intfdata(intf, NULL); | 385 | usb_set_intfdata(intf, NULL); |
312 | 386 | ||
313 | intf->condition = USB_INTERFACE_UNBOUND; | 387 | intf->condition = USB_INTERFACE_UNBOUND; |
314 | mark_quiesced(intf); | ||
315 | intf->needs_remote_wakeup = 0; | 388 | intf->needs_remote_wakeup = 0; |
316 | 389 | ||
390 | /* Unbound interfaces are always runtime-PM-disabled and -suspended */ | ||
391 | pm_runtime_disable(dev); | ||
392 | pm_runtime_set_suspended(dev); | ||
393 | |||
394 | /* Undo any residual pm_autopm_get_interface_* calls */ | ||
395 | for (r = atomic_read(&intf->pm_usage_cnt); r > 0; --r) | ||
396 | usb_autopm_put_interface_no_suspend(intf); | ||
397 | atomic_set(&intf->pm_usage_cnt, 0); | ||
398 | |||
317 | if (!error) | 399 | if (!error) |
318 | usb_autosuspend_device(udev); | 400 | usb_autosuspend_device(udev); |
319 | 401 | ||
@@ -344,7 +426,6 @@ int usb_driver_claim_interface(struct usb_driver *driver, | |||
344 | struct usb_interface *iface, void *priv) | 426 | struct usb_interface *iface, void *priv) |
345 | { | 427 | { |
346 | struct device *dev = &iface->dev; | 428 | struct device *dev = &iface->dev; |
347 | struct usb_device *udev = interface_to_usbdev(iface); | ||
348 | int retval = 0; | 429 | int retval = 0; |
349 | 430 | ||
350 | if (dev->driver) | 431 | if (dev->driver) |
@@ -354,11 +435,16 @@ int usb_driver_claim_interface(struct usb_driver *driver, | |||
354 | usb_set_intfdata(iface, priv); | 435 | usb_set_intfdata(iface, priv); |
355 | iface->needs_binding = 0; | 436 | iface->needs_binding = 0; |
356 | 437 | ||
357 | usb_pm_lock(udev); | ||
358 | iface->condition = USB_INTERFACE_BOUND; | 438 | iface->condition = USB_INTERFACE_BOUND; |
359 | mark_active(iface); | 439 | |
360 | atomic_set(&iface->pm_usage_cnt, !driver->supports_autosuspend); | 440 | /* Claimed interfaces are initially inactive (suspended). They are |
361 | usb_pm_unlock(udev); | 441 | * runtime-PM-enabled only if the driver has autosuspend support. |
442 | * They are sensitive to their children's power states. | ||
443 | */ | ||
444 | pm_runtime_set_suspended(dev); | ||
445 | pm_suspend_ignore_children(dev, false); | ||
446 | if (driver->supports_autosuspend) | ||
447 | pm_runtime_enable(dev); | ||
362 | 448 | ||
363 | /* if interface was already added, bind now; else let | 449 | /* if interface was already added, bind now; else let |
364 | * the future device_add() bind it, bypassing probe() | 450 | * the future device_add() bind it, bypassing probe() |
@@ -404,10 +490,10 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
404 | if (device_is_registered(dev)) { | 490 | if (device_is_registered(dev)) { |
405 | device_release_driver(dev); | 491 | device_release_driver(dev); |
406 | } else { | 492 | } else { |
407 | down(&dev->sem); | 493 | device_lock(dev); |
408 | usb_unbind_interface(dev); | 494 | usb_unbind_interface(dev); |
409 | dev->driver = NULL; | 495 | dev->driver = NULL; |
410 | up(&dev->sem); | 496 | device_unlock(dev); |
411 | } | 497 | } |
412 | } | 498 | } |
413 | EXPORT_SYMBOL_GPL(usb_driver_release_interface); | 499 | EXPORT_SYMBOL_GPL(usb_driver_release_interface); |
@@ -625,9 +711,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
625 | { | 711 | { |
626 | struct usb_device *usb_dev; | 712 | struct usb_device *usb_dev; |
627 | 713 | ||
628 | /* driver is often null here; dev_dbg() would oops */ | ||
629 | pr_debug("usb %s: uevent\n", dev_name(dev)); | ||
630 | |||
631 | if (is_usb_device(dev)) { | 714 | if (is_usb_device(dev)) { |
632 | usb_dev = to_usb_device(dev); | 715 | usb_dev = to_usb_device(dev); |
633 | } else if (is_usb_interface(dev)) { | 716 | } else if (is_usb_interface(dev)) { |
@@ -639,6 +722,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
639 | } | 722 | } |
640 | 723 | ||
641 | if (usb_dev->devnum < 0) { | 724 | if (usb_dev->devnum < 0) { |
725 | /* driver is often null here; dev_dbg() would oops */ | ||
642 | pr_debug("usb %s: already deleted?\n", dev_name(dev)); | 726 | pr_debug("usb %s: already deleted?\n", dev_name(dev)); |
643 | return -ENODEV; | 727 | return -ENODEV; |
644 | } | 728 | } |
@@ -774,19 +858,34 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner, | |||
774 | INIT_LIST_HEAD(&new_driver->dynids.list); | 858 | INIT_LIST_HEAD(&new_driver->dynids.list); |
775 | 859 | ||
776 | retval = driver_register(&new_driver->drvwrap.driver); | 860 | retval = driver_register(&new_driver->drvwrap.driver); |
861 | if (retval) | ||
862 | goto out; | ||
777 | 863 | ||
778 | if (!retval) { | 864 | usbfs_update_special(); |
779 | pr_info("%s: registered new interface driver %s\n", | 865 | |
866 | retval = usb_create_newid_file(new_driver); | ||
867 | if (retval) | ||
868 | goto out_newid; | ||
869 | |||
870 | retval = usb_create_removeid_file(new_driver); | ||
871 | if (retval) | ||
872 | goto out_removeid; | ||
873 | |||
874 | pr_info("%s: registered new interface driver %s\n", | ||
780 | usbcore_name, new_driver->name); | 875 | usbcore_name, new_driver->name); |
781 | usbfs_update_special(); | ||
782 | usb_create_newid_file(new_driver); | ||
783 | } else { | ||
784 | printk(KERN_ERR "%s: error %d registering interface " | ||
785 | " driver %s\n", | ||
786 | usbcore_name, retval, new_driver->name); | ||
787 | } | ||
788 | 876 | ||
877 | out: | ||
789 | return retval; | 878 | return retval; |
879 | |||
880 | out_removeid: | ||
881 | usb_remove_newid_file(new_driver); | ||
882 | out_newid: | ||
883 | driver_unregister(&new_driver->drvwrap.driver); | ||
884 | |||
885 | printk(KERN_ERR "%s: error %d registering interface " | ||
886 | " driver %s\n", | ||
887 | usbcore_name, retval, new_driver->name); | ||
888 | goto out; | ||
790 | } | 889 | } |
791 | EXPORT_SYMBOL_GPL(usb_register_driver); | 890 | EXPORT_SYMBOL_GPL(usb_register_driver); |
792 | 891 | ||
@@ -806,6 +905,7 @@ void usb_deregister(struct usb_driver *driver) | |||
806 | pr_info("%s: deregistering interface driver %s\n", | 905 | pr_info("%s: deregistering interface driver %s\n", |
807 | usbcore_name, driver->name); | 906 | usbcore_name, driver->name); |
808 | 907 | ||
908 | usb_remove_removeid_file(driver); | ||
809 | usb_remove_newid_file(driver); | 909 | usb_remove_newid_file(driver); |
810 | usb_free_dynids(driver); | 910 | usb_free_dynids(driver); |
811 | driver_unregister(&driver->drvwrap.driver); | 911 | driver_unregister(&driver->drvwrap.driver); |
@@ -901,7 +1001,6 @@ static void do_unbind_rebind(struct usb_device *udev, int action) | |||
901 | } | 1001 | } |
902 | } | 1002 | } |
903 | 1003 | ||
904 | /* Caller has locked udev's pm_mutex */ | ||
905 | static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) | 1004 | static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) |
906 | { | 1005 | { |
907 | struct usb_device_driver *udriver; | 1006 | struct usb_device_driver *udriver; |
@@ -925,7 +1024,6 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) | |||
925 | return status; | 1024 | return status; |
926 | } | 1025 | } |
927 | 1026 | ||
928 | /* Caller has locked udev's pm_mutex */ | ||
929 | static int usb_resume_device(struct usb_device *udev, pm_message_t msg) | 1027 | static int usb_resume_device(struct usb_device *udev, pm_message_t msg) |
930 | { | 1028 | { |
931 | struct usb_device_driver *udriver; | 1029 | struct usb_device_driver *udriver; |
@@ -940,6 +1038,14 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg) | |||
940 | goto done; | 1038 | goto done; |
941 | } | 1039 | } |
942 | 1040 | ||
1041 | /* Non-root devices on a full/low-speed bus must wait for their | ||
1042 | * companion high-speed root hub, in case a handoff is needed. | ||
1043 | */ | ||
1044 | if (!(msg.event & PM_EVENT_AUTO) && udev->parent && | ||
1045 | udev->bus->hs_companion) | ||
1046 | device_pm_wait_for_dev(&udev->dev, | ||
1047 | &udev->bus->hs_companion->root_hub->dev); | ||
1048 | |||
943 | if (udev->quirks & USB_QUIRK_RESET_RESUME) | 1049 | if (udev->quirks & USB_QUIRK_RESET_RESUME) |
944 | udev->reset_resume = 1; | 1050 | udev->reset_resume = 1; |
945 | 1051 | ||
@@ -948,32 +1054,23 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg) | |||
948 | 1054 | ||
949 | done: | 1055 | done: |
950 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); | 1056 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
951 | if (status == 0) | ||
952 | udev->autoresume_disabled = 0; | ||
953 | return status; | 1057 | return status; |
954 | } | 1058 | } |
955 | 1059 | ||
956 | /* Caller has locked intf's usb_device's pm mutex */ | ||
957 | static int usb_suspend_interface(struct usb_device *udev, | 1060 | static int usb_suspend_interface(struct usb_device *udev, |
958 | struct usb_interface *intf, pm_message_t msg) | 1061 | struct usb_interface *intf, pm_message_t msg) |
959 | { | 1062 | { |
960 | struct usb_driver *driver; | 1063 | struct usb_driver *driver; |
961 | int status = 0; | 1064 | int status = 0; |
962 | 1065 | ||
963 | /* with no hardware, USB interfaces only use FREEZE and ON states */ | 1066 | if (udev->state == USB_STATE_NOTATTACHED || |
964 | if (udev->state == USB_STATE_NOTATTACHED || !is_active(intf)) | 1067 | intf->condition == USB_INTERFACE_UNBOUND) |
965 | goto done; | ||
966 | |||
967 | /* This can happen; see usb_driver_release_interface() */ | ||
968 | if (intf->condition == USB_INTERFACE_UNBOUND) | ||
969 | goto done; | 1068 | goto done; |
970 | driver = to_usb_driver(intf->dev.driver); | 1069 | driver = to_usb_driver(intf->dev.driver); |
971 | 1070 | ||
972 | if (driver->suspend) { | 1071 | if (driver->suspend) { |
973 | status = driver->suspend(intf, msg); | 1072 | status = driver->suspend(intf, msg); |
974 | if (status == 0) | 1073 | if (status && !(msg.event & PM_EVENT_AUTO)) |
975 | mark_quiesced(intf); | ||
976 | else if (!(msg.event & PM_EVENT_AUTO)) | ||
977 | dev_err(&intf->dev, "%s error %d\n", | 1074 | dev_err(&intf->dev, "%s error %d\n", |
978 | "suspend", status); | 1075 | "suspend", status); |
979 | } else { | 1076 | } else { |
@@ -981,7 +1078,6 @@ static int usb_suspend_interface(struct usb_device *udev, | |||
981 | intf->needs_binding = 1; | 1078 | intf->needs_binding = 1; |
982 | dev_warn(&intf->dev, "no %s for driver %s?\n", | 1079 | dev_warn(&intf->dev, "no %s for driver %s?\n", |
983 | "suspend", driver->name); | 1080 | "suspend", driver->name); |
984 | mark_quiesced(intf); | ||
985 | } | 1081 | } |
986 | 1082 | ||
987 | done: | 1083 | done: |
@@ -989,14 +1085,13 @@ static int usb_suspend_interface(struct usb_device *udev, | |||
989 | return status; | 1085 | return status; |
990 | } | 1086 | } |
991 | 1087 | ||
992 | /* Caller has locked intf's usb_device's pm_mutex */ | ||
993 | static int usb_resume_interface(struct usb_device *udev, | 1088 | static int usb_resume_interface(struct usb_device *udev, |
994 | struct usb_interface *intf, pm_message_t msg, int reset_resume) | 1089 | struct usb_interface *intf, pm_message_t msg, int reset_resume) |
995 | { | 1090 | { |
996 | struct usb_driver *driver; | 1091 | struct usb_driver *driver; |
997 | int status = 0; | 1092 | int status = 0; |
998 | 1093 | ||
999 | if (udev->state == USB_STATE_NOTATTACHED || is_active(intf)) | 1094 | if (udev->state == USB_STATE_NOTATTACHED) |
1000 | goto done; | 1095 | goto done; |
1001 | 1096 | ||
1002 | /* Don't let autoresume interfere with unbinding */ | 1097 | /* Don't let autoresume interfere with unbinding */ |
@@ -1047,90 +1142,11 @@ static int usb_resume_interface(struct usb_device *udev, | |||
1047 | 1142 | ||
1048 | done: | 1143 | done: |
1049 | dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); | 1144 | dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); |
1050 | if (status == 0 && intf->condition == USB_INTERFACE_BOUND) | ||
1051 | mark_active(intf); | ||
1052 | 1145 | ||
1053 | /* Later we will unbind the driver and/or reprobe, if necessary */ | 1146 | /* Later we will unbind the driver and/or reprobe, if necessary */ |
1054 | return status; | 1147 | return status; |
1055 | } | 1148 | } |
1056 | 1149 | ||
1057 | #ifdef CONFIG_USB_SUSPEND | ||
1058 | |||
1059 | /* Internal routine to check whether we may autosuspend a device. */ | ||
1060 | static int autosuspend_check(struct usb_device *udev, int reschedule) | ||
1061 | { | ||
1062 | int i; | ||
1063 | struct usb_interface *intf; | ||
1064 | unsigned long suspend_time, j; | ||
1065 | |||
1066 | /* For autosuspend, fail fast if anything is in use or autosuspend | ||
1067 | * is disabled. Also fail if any interfaces require remote wakeup | ||
1068 | * but it isn't available. | ||
1069 | */ | ||
1070 | if (udev->pm_usage_cnt > 0) | ||
1071 | return -EBUSY; | ||
1072 | if (udev->autosuspend_delay < 0 || udev->autosuspend_disabled) | ||
1073 | return -EPERM; | ||
1074 | |||
1075 | suspend_time = udev->last_busy + udev->autosuspend_delay; | ||
1076 | if (udev->actconfig) { | ||
1077 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1078 | intf = udev->actconfig->interface[i]; | ||
1079 | if (!is_active(intf)) | ||
1080 | continue; | ||
1081 | if (atomic_read(&intf->pm_usage_cnt) > 0) | ||
1082 | return -EBUSY; | ||
1083 | if (intf->needs_remote_wakeup && | ||
1084 | !udev->do_remote_wakeup) { | ||
1085 | dev_dbg(&udev->dev, "remote wakeup needed " | ||
1086 | "for autosuspend\n"); | ||
1087 | return -EOPNOTSUPP; | ||
1088 | } | ||
1089 | |||
1090 | /* Don't allow autosuspend if the device will need | ||
1091 | * a reset-resume and any of its interface drivers | ||
1092 | * doesn't include support. | ||
1093 | */ | ||
1094 | if (udev->quirks & USB_QUIRK_RESET_RESUME) { | ||
1095 | struct usb_driver *driver; | ||
1096 | |||
1097 | driver = to_usb_driver(intf->dev.driver); | ||
1098 | if (!driver->reset_resume || | ||
1099 | intf->needs_remote_wakeup) | ||
1100 | return -EOPNOTSUPP; | ||
1101 | } | ||
1102 | } | ||
1103 | } | ||
1104 | |||
1105 | /* If everything is okay but the device hasn't been idle for long | ||
1106 | * enough, queue a delayed autosuspend request. If the device | ||
1107 | * _has_ been idle for long enough and the reschedule flag is set, | ||
1108 | * likewise queue a delayed (1 second) autosuspend request. | ||
1109 | */ | ||
1110 | j = jiffies; | ||
1111 | if (time_before(j, suspend_time)) | ||
1112 | reschedule = 1; | ||
1113 | else | ||
1114 | suspend_time = j + HZ; | ||
1115 | if (reschedule) { | ||
1116 | if (!timer_pending(&udev->autosuspend.timer)) { | ||
1117 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | ||
1118 | round_jiffies_up_relative(suspend_time - j)); | ||
1119 | } | ||
1120 | return -EAGAIN; | ||
1121 | } | ||
1122 | return 0; | ||
1123 | } | ||
1124 | |||
1125 | #else | ||
1126 | |||
1127 | static inline int autosuspend_check(struct usb_device *udev, int reschedule) | ||
1128 | { | ||
1129 | return 0; | ||
1130 | } | ||
1131 | |||
1132 | #endif /* CONFIG_USB_SUSPEND */ | ||
1133 | |||
1134 | /** | 1150 | /** |
1135 | * usb_suspend_both - suspend a USB device and its interfaces | 1151 | * usb_suspend_both - suspend a USB device and its interfaces |
1136 | * @udev: the usb_device to suspend | 1152 | * @udev: the usb_device to suspend |
@@ -1142,52 +1158,29 @@ static inline int autosuspend_check(struct usb_device *udev, int reschedule) | |||
1142 | * all the interfaces which were suspended are resumed so that they remain | 1158 | * all the interfaces which were suspended are resumed so that they remain |
1143 | * in the same state as the device. | 1159 | * in the same state as the device. |
1144 | * | 1160 | * |
1145 | * If an autosuspend is in progress the routine checks first to make sure | 1161 | * Autosuspend requests originating from a child device or an interface |
1146 | * that neither the device itself or any of its active interfaces is in use | 1162 | * driver may be made without the protection of @udev's device lock, but |
1147 | * (pm_usage_cnt is greater than 0). If they are, the autosuspend fails. | 1163 | * all other suspend calls will hold the lock. Usbcore will insure that |
1148 | * | 1164 | * method calls do not arrive during bind, unbind, or reset operations. |
1149 | * If the suspend succeeds, the routine recursively queues an autosuspend | 1165 | * However drivers must be prepared to handle suspend calls arriving at |
1150 | * request for @udev's parent device, thereby propagating the change up | 1166 | * unpredictable times. |
1151 | * the device tree. If all of the parent's children are now suspended, | ||
1152 | * the parent will autosuspend in turn. | ||
1153 | * | ||
1154 | * The suspend method calls are subject to mutual exclusion under control | ||
1155 | * of @udev's pm_mutex. Many of these calls are also under the protection | ||
1156 | * of @udev's device lock (including all requests originating outside the | ||
1157 | * USB subsystem), but autosuspend requests generated by a child device or | ||
1158 | * interface driver may not be. Usbcore will insure that the method calls | ||
1159 | * do not arrive during bind, unbind, or reset operations. However, drivers | ||
1160 | * must be prepared to handle suspend calls arriving at unpredictable times. | ||
1161 | * The only way to block such calls is to do an autoresume (preventing | ||
1162 | * autosuspends) while holding @udev's device lock (preventing outside | ||
1163 | * suspends). | ||
1164 | * | ||
1165 | * The caller must hold @udev->pm_mutex. | ||
1166 | * | 1167 | * |
1167 | * This routine can run only in process context. | 1168 | * This routine can run only in process context. |
1168 | */ | 1169 | */ |
1169 | static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | 1170 | static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) |
1170 | { | 1171 | { |
1171 | int status = 0; | 1172 | int status = 0; |
1172 | int i = 0; | 1173 | int i = 0, n = 0; |
1173 | struct usb_interface *intf; | 1174 | struct usb_interface *intf; |
1174 | struct usb_device *parent = udev->parent; | ||
1175 | 1175 | ||
1176 | if (udev->state == USB_STATE_NOTATTACHED || | 1176 | if (udev->state == USB_STATE_NOTATTACHED || |
1177 | udev->state == USB_STATE_SUSPENDED) | 1177 | udev->state == USB_STATE_SUSPENDED) |
1178 | goto done; | 1178 | goto done; |
1179 | 1179 | ||
1180 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | ||
1181 | |||
1182 | if (msg.event & PM_EVENT_AUTO) { | ||
1183 | status = autosuspend_check(udev, 0); | ||
1184 | if (status < 0) | ||
1185 | goto done; | ||
1186 | } | ||
1187 | |||
1188 | /* Suspend all the interfaces and then udev itself */ | 1180 | /* Suspend all the interfaces and then udev itself */ |
1189 | if (udev->actconfig) { | 1181 | if (udev->actconfig) { |
1190 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { | 1182 | n = udev->actconfig->desc.bNumInterfaces; |
1183 | for (i = n - 1; i >= 0; --i) { | ||
1191 | intf = udev->actconfig->interface[i]; | 1184 | intf = udev->actconfig->interface[i]; |
1192 | status = usb_suspend_interface(udev, intf, msg); | 1185 | status = usb_suspend_interface(udev, intf, msg); |
1193 | if (status != 0) | 1186 | if (status != 0) |
@@ -1199,35 +1192,21 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1199 | 1192 | ||
1200 | /* If the suspend failed, resume interfaces that did get suspended */ | 1193 | /* If the suspend failed, resume interfaces that did get suspended */ |
1201 | if (status != 0) { | 1194 | if (status != 0) { |
1202 | pm_message_t msg2; | 1195 | msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); |
1203 | 1196 | while (++i < n) { | |
1204 | msg2.event = msg.event ^ (PM_EVENT_SUSPEND | PM_EVENT_RESUME); | ||
1205 | while (--i >= 0) { | ||
1206 | intf = udev->actconfig->interface[i]; | 1197 | intf = udev->actconfig->interface[i]; |
1207 | usb_resume_interface(udev, intf, msg2, 0); | 1198 | usb_resume_interface(udev, intf, msg, 0); |
1208 | } | 1199 | } |
1209 | 1200 | ||
1210 | /* Try another autosuspend when the interfaces aren't busy */ | 1201 | /* If the suspend succeeded then prevent any more URB submissions |
1211 | if (msg.event & PM_EVENT_AUTO) | 1202 | * and flush any outstanding URBs. |
1212 | autosuspend_check(udev, status == -EBUSY); | ||
1213 | |||
1214 | /* If the suspend succeeded then prevent any more URB submissions, | ||
1215 | * flush any outstanding URBs, and propagate the suspend up the tree. | ||
1216 | */ | 1203 | */ |
1217 | } else { | 1204 | } else { |
1218 | cancel_delayed_work(&udev->autosuspend); | ||
1219 | udev->can_submit = 0; | 1205 | udev->can_submit = 0; |
1220 | for (i = 0; i < 16; ++i) { | 1206 | for (i = 0; i < 16; ++i) { |
1221 | usb_hcd_flush_endpoint(udev, udev->ep_out[i]); | 1207 | usb_hcd_flush_endpoint(udev, udev->ep_out[i]); |
1222 | usb_hcd_flush_endpoint(udev, udev->ep_in[i]); | 1208 | usb_hcd_flush_endpoint(udev, udev->ep_in[i]); |
1223 | } | 1209 | } |
1224 | |||
1225 | /* If this is just a FREEZE or a PRETHAW, udev might | ||
1226 | * not really be suspended. Only true suspends get | ||
1227 | * propagated up the device tree. | ||
1228 | */ | ||
1229 | if (parent && udev->state == USB_STATE_SUSPENDED) | ||
1230 | usb_autosuspend_device(parent); | ||
1231 | } | 1210 | } |
1232 | 1211 | ||
1233 | done: | 1212 | done: |
@@ -1244,23 +1223,12 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1244 | * the resume method for @udev and then calls the resume methods for all | 1223 | * the resume method for @udev and then calls the resume methods for all |
1245 | * the interface drivers in @udev. | 1224 | * the interface drivers in @udev. |
1246 | * | 1225 | * |
1247 | * Before starting the resume, the routine calls itself recursively for | 1226 | * Autoresume requests originating from a child device or an interface |
1248 | * the parent device of @udev, thereby propagating the change up the device | 1227 | * driver may be made without the protection of @udev's device lock, but |
1249 | * tree and assuring that @udev will be able to resume. If the parent is | 1228 | * all other resume calls will hold the lock. Usbcore will insure that |
1250 | * unable to resume successfully, the routine fails. | 1229 | * method calls do not arrive during bind, unbind, or reset operations. |
1251 | * | 1230 | * However drivers must be prepared to handle resume calls arriving at |
1252 | * The resume method calls are subject to mutual exclusion under control | 1231 | * unpredictable times. |
1253 | * of @udev's pm_mutex. Many of these calls are also under the protection | ||
1254 | * of @udev's device lock (including all requests originating outside the | ||
1255 | * USB subsystem), but autoresume requests generated by a child device or | ||
1256 | * interface driver may not be. Usbcore will insure that the method calls | ||
1257 | * do not arrive during bind, unbind, or reset operations. However, drivers | ||
1258 | * must be prepared to handle resume calls arriving at unpredictable times. | ||
1259 | * The only way to block such calls is to do an autoresume (preventing | ||
1260 | * other autoresumes) while holding @udev's device lock (preventing outside | ||
1261 | * resumes). | ||
1262 | * | ||
1263 | * The caller must hold @udev->pm_mutex. | ||
1264 | * | 1232 | * |
1265 | * This routine can run only in process context. | 1233 | * This routine can run only in process context. |
1266 | */ | 1234 | */ |
@@ -1269,53 +1237,18 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) | |||
1269 | int status = 0; | 1237 | int status = 0; |
1270 | int i; | 1238 | int i; |
1271 | struct usb_interface *intf; | 1239 | struct usb_interface *intf; |
1272 | struct usb_device *parent = udev->parent; | ||
1273 | 1240 | ||
1274 | cancel_delayed_work(&udev->autosuspend); | ||
1275 | if (udev->state == USB_STATE_NOTATTACHED) { | 1241 | if (udev->state == USB_STATE_NOTATTACHED) { |
1276 | status = -ENODEV; | 1242 | status = -ENODEV; |
1277 | goto done; | 1243 | goto done; |
1278 | } | 1244 | } |
1279 | udev->can_submit = 1; | 1245 | udev->can_submit = 1; |
1280 | 1246 | ||
1281 | /* Propagate the resume up the tree, if necessary */ | 1247 | /* Resume the device */ |
1282 | if (udev->state == USB_STATE_SUSPENDED) { | 1248 | if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) |
1283 | if ((msg.event & PM_EVENT_AUTO) && | ||
1284 | udev->autoresume_disabled) { | ||
1285 | status = -EPERM; | ||
1286 | goto done; | ||
1287 | } | ||
1288 | if (parent) { | ||
1289 | status = usb_autoresume_device(parent); | ||
1290 | if (status == 0) { | ||
1291 | status = usb_resume_device(udev, msg); | ||
1292 | if (status || udev->state == | ||
1293 | USB_STATE_NOTATTACHED) { | ||
1294 | usb_autosuspend_device(parent); | ||
1295 | |||
1296 | /* It's possible usb_resume_device() | ||
1297 | * failed after the port was | ||
1298 | * unsuspended, causing udev to be | ||
1299 | * logically disconnected. We don't | ||
1300 | * want usb_disconnect() to autosuspend | ||
1301 | * the parent again, so tell it that | ||
1302 | * udev disconnected while still | ||
1303 | * suspended. */ | ||
1304 | if (udev->state == | ||
1305 | USB_STATE_NOTATTACHED) | ||
1306 | udev->discon_suspended = 1; | ||
1307 | } | ||
1308 | } | ||
1309 | } else { | ||
1310 | |||
1311 | /* We can't progagate beyond the USB subsystem, | ||
1312 | * so if a root hub's controller is suspended | ||
1313 | * then we're stuck. */ | ||
1314 | status = usb_resume_device(udev, msg); | ||
1315 | } | ||
1316 | } else if (udev->reset_resume) | ||
1317 | status = usb_resume_device(udev, msg); | 1249 | status = usb_resume_device(udev, msg); |
1318 | 1250 | ||
1251 | /* Resume the interfaces */ | ||
1319 | if (status == 0 && udev->actconfig) { | 1252 | if (status == 0 && udev->actconfig) { |
1320 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | 1253 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
1321 | intf = udev->actconfig->interface[i]; | 1254 | intf = udev->actconfig->interface[i]; |
@@ -1331,56 +1264,128 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) | |||
1331 | return status; | 1264 | return status; |
1332 | } | 1265 | } |
1333 | 1266 | ||
1334 | #ifdef CONFIG_USB_SUSPEND | 1267 | static void choose_wakeup(struct usb_device *udev, pm_message_t msg) |
1268 | { | ||
1269 | int w, i; | ||
1270 | struct usb_interface *intf; | ||
1335 | 1271 | ||
1336 | /* Internal routine to adjust a device's usage counter and change | 1272 | /* Remote wakeup is needed only when we actually go to sleep. |
1337 | * its autosuspend state. | 1273 | * For things like FREEZE and QUIESCE, if the device is already |
1338 | */ | 1274 | * autosuspended then its current wakeup setting is okay. |
1339 | static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt) | 1275 | */ |
1276 | if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) { | ||
1277 | if (udev->state != USB_STATE_SUSPENDED) | ||
1278 | udev->do_remote_wakeup = 0; | ||
1279 | return; | ||
1280 | } | ||
1281 | |||
1282 | /* If remote wakeup is permitted, see whether any interface drivers | ||
1283 | * actually want it. | ||
1284 | */ | ||
1285 | w = 0; | ||
1286 | if (device_may_wakeup(&udev->dev) && udev->actconfig) { | ||
1287 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1288 | intf = udev->actconfig->interface[i]; | ||
1289 | w |= intf->needs_remote_wakeup; | ||
1290 | } | ||
1291 | } | ||
1292 | |||
1293 | /* If the device is autosuspended with the wrong wakeup setting, | ||
1294 | * autoresume now so the setting can be changed. | ||
1295 | */ | ||
1296 | if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup) | ||
1297 | pm_runtime_resume(&udev->dev); | ||
1298 | udev->do_remote_wakeup = w; | ||
1299 | } | ||
1300 | |||
1301 | /* The device lock is held by the PM core */ | ||
1302 | int usb_suspend(struct device *dev, pm_message_t msg) | ||
1340 | { | 1303 | { |
1341 | int status = 0; | 1304 | struct usb_device *udev = to_usb_device(dev); |
1342 | 1305 | ||
1343 | usb_pm_lock(udev); | 1306 | do_unbind_rebind(udev, DO_UNBIND); |
1344 | udev->auto_pm = 1; | 1307 | choose_wakeup(udev, msg); |
1345 | udev->pm_usage_cnt += inc_usage_cnt; | 1308 | return usb_suspend_both(udev, msg); |
1346 | WARN_ON(udev->pm_usage_cnt < 0); | 1309 | } |
1347 | if (inc_usage_cnt) | 1310 | |
1348 | udev->last_busy = jiffies; | 1311 | /* The device lock is held by the PM core */ |
1349 | if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { | 1312 | int usb_resume(struct device *dev, pm_message_t msg) |
1350 | if (udev->state == USB_STATE_SUSPENDED) | 1313 | { |
1351 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); | 1314 | struct usb_device *udev = to_usb_device(dev); |
1352 | if (status != 0) | 1315 | int status; |
1353 | udev->pm_usage_cnt -= inc_usage_cnt; | 1316 | |
1354 | else if (inc_usage_cnt) | 1317 | /* For PM complete calls, all we do is rebind interfaces */ |
1318 | if (msg.event == PM_EVENT_ON) { | ||
1319 | if (udev->state != USB_STATE_NOTATTACHED) | ||
1320 | do_unbind_rebind(udev, DO_REBIND); | ||
1321 | status = 0; | ||
1322 | |||
1323 | /* For all other calls, take the device back to full power and | ||
1324 | * tell the PM core in case it was autosuspended previously. | ||
1325 | */ | ||
1326 | } else { | ||
1327 | status = usb_resume_both(udev, msg); | ||
1328 | if (status == 0) { | ||
1329 | pm_runtime_disable(dev); | ||
1330 | pm_runtime_set_active(dev); | ||
1331 | pm_runtime_enable(dev); | ||
1355 | udev->last_busy = jiffies; | 1332 | udev->last_busy = jiffies; |
1356 | } else if (inc_usage_cnt <= 0 && udev->pm_usage_cnt <= 0) { | 1333 | } |
1357 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | ||
1358 | } | 1334 | } |
1359 | usb_pm_unlock(udev); | 1335 | |
1336 | /* Avoid PM error messages for devices disconnected while suspended | ||
1337 | * as we'll display regular disconnect messages just a bit later. | ||
1338 | */ | ||
1339 | if (status == -ENODEV) | ||
1340 | status = 0; | ||
1360 | return status; | 1341 | return status; |
1361 | } | 1342 | } |
1362 | 1343 | ||
1363 | /* usb_autosuspend_work - callback routine to autosuspend a USB device */ | 1344 | #endif /* CONFIG_PM */ |
1364 | void usb_autosuspend_work(struct work_struct *work) | ||
1365 | { | ||
1366 | struct usb_device *udev = | ||
1367 | container_of(work, struct usb_device, autosuspend.work); | ||
1368 | 1345 | ||
1369 | usb_autopm_do_device(udev, 0); | 1346 | #ifdef CONFIG_USB_SUSPEND |
1347 | |||
1348 | /** | ||
1349 | * usb_enable_autosuspend - allow a USB device to be autosuspended | ||
1350 | * @udev: the USB device which may be autosuspended | ||
1351 | * | ||
1352 | * This routine allows @udev to be autosuspended. An autosuspend won't | ||
1353 | * take place until the autosuspend_delay has elapsed and all the other | ||
1354 | * necessary conditions are satisfied. | ||
1355 | * | ||
1356 | * The caller must hold @udev's device lock. | ||
1357 | */ | ||
1358 | int usb_enable_autosuspend(struct usb_device *udev) | ||
1359 | { | ||
1360 | if (udev->autosuspend_disabled) { | ||
1361 | udev->autosuspend_disabled = 0; | ||
1362 | usb_autosuspend_device(udev); | ||
1363 | } | ||
1364 | return 0; | ||
1370 | } | 1365 | } |
1366 | EXPORT_SYMBOL_GPL(usb_enable_autosuspend); | ||
1371 | 1367 | ||
1372 | /* usb_autoresume_work - callback routine to autoresume a USB device */ | 1368 | /** |
1373 | void usb_autoresume_work(struct work_struct *work) | 1369 | * usb_disable_autosuspend - prevent a USB device from being autosuspended |
1370 | * @udev: the USB device which may not be autosuspended | ||
1371 | * | ||
1372 | * This routine prevents @udev from being autosuspended and wakes it up | ||
1373 | * if it is already autosuspended. | ||
1374 | * | ||
1375 | * The caller must hold @udev's device lock. | ||
1376 | */ | ||
1377 | int usb_disable_autosuspend(struct usb_device *udev) | ||
1374 | { | 1378 | { |
1375 | struct usb_device *udev = | 1379 | int rc = 0; |
1376 | container_of(work, struct usb_device, autoresume); | ||
1377 | 1380 | ||
1378 | /* Wake it up, let the drivers do their thing, and then put it | 1381 | if (!udev->autosuspend_disabled) { |
1379 | * back to sleep. | 1382 | rc = usb_autoresume_device(udev); |
1380 | */ | 1383 | if (rc == 0) |
1381 | if (usb_autopm_do_device(udev, 1) == 0) | 1384 | udev->autosuspend_disabled = 1; |
1382 | usb_autopm_do_device(udev, -1); | 1385 | } |
1386 | return rc; | ||
1383 | } | 1387 | } |
1388 | EXPORT_SYMBOL_GPL(usb_disable_autosuspend); | ||
1384 | 1389 | ||
1385 | /** | 1390 | /** |
1386 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces | 1391 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces |
@@ -1390,15 +1395,11 @@ void usb_autoresume_work(struct work_struct *work) | |||
1390 | * @udev and wants to allow it to autosuspend. Examples would be when | 1395 | * @udev and wants to allow it to autosuspend. Examples would be when |
1391 | * @udev's device file in usbfs is closed or after a configuration change. | 1396 | * @udev's device file in usbfs is closed or after a configuration change. |
1392 | * | 1397 | * |
1393 | * @udev's usage counter is decremented. If it or any of the usage counters | 1398 | * @udev's usage counter is decremented; if it drops to 0 and all the |
1394 | * for an active interface is greater than 0, no autosuspend request will be | 1399 | * interfaces are inactive then a delayed autosuspend will be attempted. |
1395 | * queued. (If an interface driver does not support autosuspend then its | 1400 | * The attempt may fail (see autosuspend_check()). |
1396 | * usage counter is permanently positive.) Furthermore, if an interface | ||
1397 | * driver requires remote-wakeup capability during autosuspend but remote | ||
1398 | * wakeup is disabled, the autosuspend will fail. | ||
1399 | * | 1401 | * |
1400 | * Often the caller will hold @udev's device lock, but this is not | 1402 | * The caller must hold @udev's device lock. |
1401 | * necessary. | ||
1402 | * | 1403 | * |
1403 | * This routine can run only in process context. | 1404 | * This routine can run only in process context. |
1404 | */ | 1405 | */ |
@@ -1406,9 +1407,11 @@ void usb_autosuspend_device(struct usb_device *udev) | |||
1406 | { | 1407 | { |
1407 | int status; | 1408 | int status; |
1408 | 1409 | ||
1409 | status = usb_autopm_do_device(udev, -1); | 1410 | udev->last_busy = jiffies; |
1410 | dev_vdbg(&udev->dev, "%s: cnt %d\n", | 1411 | status = pm_runtime_put_sync(&udev->dev); |
1411 | __func__, udev->pm_usage_cnt); | 1412 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
1413 | __func__, atomic_read(&udev->dev.power.usage_count), | ||
1414 | status); | ||
1412 | } | 1415 | } |
1413 | 1416 | ||
1414 | /** | 1417 | /** |
@@ -1418,17 +1421,22 @@ void usb_autosuspend_device(struct usb_device *udev) | |||
1418 | * This routine should be called when a core subsystem thinks @udev may | 1421 | * This routine should be called when a core subsystem thinks @udev may |
1419 | * be ready to autosuspend. | 1422 | * be ready to autosuspend. |
1420 | * | 1423 | * |
1421 | * @udev's usage counter left unchanged. If it or any of the usage counters | 1424 | * @udev's usage counter left unchanged. If it is 0 and all the interfaces |
1422 | * for an active interface is greater than 0, or autosuspend is not allowed | 1425 | * are inactive then an autosuspend will be attempted. The attempt may |
1423 | * for any other reason, no autosuspend request will be queued. | 1426 | * fail or be delayed. |
1427 | * | ||
1428 | * The caller must hold @udev's device lock. | ||
1424 | * | 1429 | * |
1425 | * This routine can run only in process context. | 1430 | * This routine can run only in process context. |
1426 | */ | 1431 | */ |
1427 | void usb_try_autosuspend_device(struct usb_device *udev) | 1432 | void usb_try_autosuspend_device(struct usb_device *udev) |
1428 | { | 1433 | { |
1429 | usb_autopm_do_device(udev, 0); | 1434 | int status; |
1430 | dev_vdbg(&udev->dev, "%s: cnt %d\n", | 1435 | |
1431 | __func__, udev->pm_usage_cnt); | 1436 | status = pm_runtime_idle(&udev->dev); |
1437 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", | ||
1438 | __func__, atomic_read(&udev->dev.power.usage_count), | ||
1439 | status); | ||
1432 | } | 1440 | } |
1433 | 1441 | ||
1434 | /** | 1442 | /** |
@@ -1437,16 +1445,15 @@ void usb_try_autosuspend_device(struct usb_device *udev) | |||
1437 | * | 1445 | * |
1438 | * This routine should be called when a core subsystem wants to use @udev | 1446 | * This routine should be called when a core subsystem wants to use @udev |
1439 | * and needs to guarantee that it is not suspended. No autosuspend will | 1447 | * and needs to guarantee that it is not suspended. No autosuspend will |
1440 | * occur until usb_autosuspend_device is called. (Note that this will not | 1448 | * occur until usb_autosuspend_device() is called. (Note that this will |
1441 | * prevent suspend events originating in the PM core.) Examples would be | 1449 | * not prevent suspend events originating in the PM core.) Examples would |
1442 | * when @udev's device file in usbfs is opened or when a remote-wakeup | 1450 | * be when @udev's device file in usbfs is opened or when a remote-wakeup |
1443 | * request is received. | 1451 | * request is received. |
1444 | * | 1452 | * |
1445 | * @udev's usage counter is incremented to prevent subsequent autosuspends. | 1453 | * @udev's usage counter is incremented to prevent subsequent autosuspends. |
1446 | * However if the autoresume fails then the usage counter is re-decremented. | 1454 | * However if the autoresume fails then the usage counter is re-decremented. |
1447 | * | 1455 | * |
1448 | * Often the caller will hold @udev's device lock, but this is not | 1456 | * The caller must hold @udev's device lock. |
1449 | * necessary (and attempting it might cause deadlock). | ||
1450 | * | 1457 | * |
1451 | * This routine can run only in process context. | 1458 | * This routine can run only in process context. |
1452 | */ | 1459 | */ |
@@ -1454,43 +1461,14 @@ int usb_autoresume_device(struct usb_device *udev) | |||
1454 | { | 1461 | { |
1455 | int status; | 1462 | int status; |
1456 | 1463 | ||
1457 | status = usb_autopm_do_device(udev, 1); | 1464 | status = pm_runtime_get_sync(&udev->dev); |
1458 | dev_vdbg(&udev->dev, "%s: status %d cnt %d\n", | 1465 | if (status < 0) |
1459 | __func__, status, udev->pm_usage_cnt); | 1466 | pm_runtime_put_sync(&udev->dev); |
1460 | return status; | 1467 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
1461 | } | 1468 | __func__, atomic_read(&udev->dev.power.usage_count), |
1462 | 1469 | status); | |
1463 | /* Internal routine to adjust an interface's usage counter and change | 1470 | if (status > 0) |
1464 | * its device's autosuspend state. | 1471 | status = 0; |
1465 | */ | ||
1466 | static int usb_autopm_do_interface(struct usb_interface *intf, | ||
1467 | int inc_usage_cnt) | ||
1468 | { | ||
1469 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1470 | int status = 0; | ||
1471 | |||
1472 | usb_pm_lock(udev); | ||
1473 | if (intf->condition == USB_INTERFACE_UNBOUND) | ||
1474 | status = -ENODEV; | ||
1475 | else { | ||
1476 | udev->auto_pm = 1; | ||
1477 | atomic_add(inc_usage_cnt, &intf->pm_usage_cnt); | ||
1478 | udev->last_busy = jiffies; | ||
1479 | if (inc_usage_cnt >= 0 && | ||
1480 | atomic_read(&intf->pm_usage_cnt) > 0) { | ||
1481 | if (udev->state == USB_STATE_SUSPENDED) | ||
1482 | status = usb_resume_both(udev, | ||
1483 | PMSG_AUTO_RESUME); | ||
1484 | if (status != 0) | ||
1485 | atomic_sub(inc_usage_cnt, &intf->pm_usage_cnt); | ||
1486 | else | ||
1487 | udev->last_busy = jiffies; | ||
1488 | } else if (inc_usage_cnt <= 0 && | ||
1489 | atomic_read(&intf->pm_usage_cnt) <= 0) { | ||
1490 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | ||
1491 | } | ||
1492 | } | ||
1493 | usb_pm_unlock(udev); | ||
1494 | return status; | 1472 | return status; |
1495 | } | 1473 | } |
1496 | 1474 | ||
@@ -1504,34 +1482,25 @@ static int usb_autopm_do_interface(struct usb_interface *intf, | |||
1504 | * closed. | 1482 | * closed. |
1505 | * | 1483 | * |
1506 | * The routine decrements @intf's usage counter. When the counter reaches | 1484 | * The routine decrements @intf's usage counter. When the counter reaches |
1507 | * 0, a delayed autosuspend request for @intf's device is queued. When | 1485 | * 0, a delayed autosuspend request for @intf's device is attempted. The |
1508 | * the delay expires, if @intf->pm_usage_cnt is still <= 0 along with all | 1486 | * attempt may fail (see autosuspend_check()). |
1509 | * the other usage counters for the sibling interfaces and @intf's | ||
1510 | * usb_device, the device and all its interfaces will be autosuspended. | ||
1511 | * | ||
1512 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The | ||
1513 | * core will not change its value other than the increment and decrement | ||
1514 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver | ||
1515 | * may use this simple counter-oriented discipline or may set the value | ||
1516 | * any way it likes. | ||
1517 | * | 1487 | * |
1518 | * If the driver has set @intf->needs_remote_wakeup then autosuspend will | 1488 | * If the driver has set @intf->needs_remote_wakeup then autosuspend will |
1519 | * take place only if the device's remote-wakeup facility is enabled. | 1489 | * take place only if the device's remote-wakeup facility is enabled. |
1520 | * | 1490 | * |
1521 | * Suspend method calls queued by this routine can arrive at any time | ||
1522 | * while @intf is resumed and its usage counter is equal to 0. They are | ||
1523 | * not protected by the usb_device's lock but only by its pm_mutex. | ||
1524 | * Drivers must provide their own synchronization. | ||
1525 | * | ||
1526 | * This routine can run only in process context. | 1491 | * This routine can run only in process context. |
1527 | */ | 1492 | */ |
1528 | void usb_autopm_put_interface(struct usb_interface *intf) | 1493 | void usb_autopm_put_interface(struct usb_interface *intf) |
1529 | { | 1494 | { |
1530 | int status; | 1495 | struct usb_device *udev = interface_to_usbdev(intf); |
1496 | int status; | ||
1531 | 1497 | ||
1532 | status = usb_autopm_do_interface(intf, -1); | 1498 | udev->last_busy = jiffies; |
1533 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1499 | atomic_dec(&intf->pm_usage_cnt); |
1534 | __func__, status, atomic_read(&intf->pm_usage_cnt)); | 1500 | status = pm_runtime_put_sync(&intf->dev); |
1501 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", | ||
1502 | __func__, atomic_read(&intf->dev.power.usage_count), | ||
1503 | status); | ||
1535 | } | 1504 | } |
1536 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | 1505 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); |
1537 | 1506 | ||
@@ -1539,11 +1508,11 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | |||
1539 | * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter | 1508 | * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter |
1540 | * @intf: the usb_interface whose counter should be decremented | 1509 | * @intf: the usb_interface whose counter should be decremented |
1541 | * | 1510 | * |
1542 | * This routine does essentially the same thing as | 1511 | * This routine does much the same thing as usb_autopm_put_interface(): |
1543 | * usb_autopm_put_interface(): it decrements @intf's usage counter and | 1512 | * It decrements @intf's usage counter and schedules a delayed |
1544 | * queues a delayed autosuspend request if the counter is <= 0. The | 1513 | * autosuspend request if the counter is <= 0. The difference is that it |
1545 | * difference is that it does not acquire the device's pm_mutex; | 1514 | * does not perform any synchronization; callers should hold a private |
1546 | * callers must handle all synchronization issues themselves. | 1515 | * lock and handle all synchronization issues themselves. |
1547 | * | 1516 | * |
1548 | * Typically a driver would call this routine during an URB's completion | 1517 | * Typically a driver would call this routine during an URB's completion |
1549 | * handler, if no more URBs were pending. | 1518 | * handler, if no more URBs were pending. |
@@ -1553,28 +1522,58 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | |||
1553 | void usb_autopm_put_interface_async(struct usb_interface *intf) | 1522 | void usb_autopm_put_interface_async(struct usb_interface *intf) |
1554 | { | 1523 | { |
1555 | struct usb_device *udev = interface_to_usbdev(intf); | 1524 | struct usb_device *udev = interface_to_usbdev(intf); |
1525 | unsigned long last_busy; | ||
1556 | int status = 0; | 1526 | int status = 0; |
1557 | 1527 | ||
1558 | if (intf->condition == USB_INTERFACE_UNBOUND) { | 1528 | last_busy = udev->last_busy; |
1559 | status = -ENODEV; | 1529 | udev->last_busy = jiffies; |
1560 | } else { | 1530 | atomic_dec(&intf->pm_usage_cnt); |
1561 | udev->last_busy = jiffies; | 1531 | pm_runtime_put_noidle(&intf->dev); |
1562 | atomic_dec(&intf->pm_usage_cnt); | 1532 | |
1563 | if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) | 1533 | if (!udev->autosuspend_disabled) { |
1564 | status = -EPERM; | 1534 | /* Optimization: Don't schedule a delayed autosuspend if |
1565 | else if (atomic_read(&intf->pm_usage_cnt) <= 0 && | 1535 | * the timer is already running and the expiration time |
1566 | !timer_pending(&udev->autosuspend.timer)) { | 1536 | * wouldn't change. |
1567 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | 1537 | * |
1538 | * We have to use the interface's timer. Attempts to | ||
1539 | * schedule a suspend for the device would fail because | ||
1540 | * the interface is still active. | ||
1541 | */ | ||
1542 | if (intf->dev.power.timer_expires == 0 || | ||
1543 | round_jiffies_up(last_busy) != | ||
1544 | round_jiffies_up(jiffies)) { | ||
1545 | status = pm_schedule_suspend(&intf->dev, | ||
1546 | jiffies_to_msecs( | ||
1568 | round_jiffies_up_relative( | 1547 | round_jiffies_up_relative( |
1569 | udev->autosuspend_delay)); | 1548 | udev->autosuspend_delay))); |
1570 | } | 1549 | } |
1571 | } | 1550 | } |
1572 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1551 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
1573 | __func__, status, atomic_read(&intf->pm_usage_cnt)); | 1552 | __func__, atomic_read(&intf->dev.power.usage_count), |
1553 | status); | ||
1574 | } | 1554 | } |
1575 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); | 1555 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); |
1576 | 1556 | ||
1577 | /** | 1557 | /** |
1558 | * usb_autopm_put_interface_no_suspend - decrement a USB interface's PM-usage counter | ||
1559 | * @intf: the usb_interface whose counter should be decremented | ||
1560 | * | ||
1561 | * This routine decrements @intf's usage counter but does not carry out an | ||
1562 | * autosuspend. | ||
1563 | * | ||
1564 | * This routine can run in atomic context. | ||
1565 | */ | ||
1566 | void usb_autopm_put_interface_no_suspend(struct usb_interface *intf) | ||
1567 | { | ||
1568 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1569 | |||
1570 | udev->last_busy = jiffies; | ||
1571 | atomic_dec(&intf->pm_usage_cnt); | ||
1572 | pm_runtime_put_noidle(&intf->dev); | ||
1573 | } | ||
1574 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface_no_suspend); | ||
1575 | |||
1576 | /** | ||
1578 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter | 1577 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter |
1579 | * @intf: the usb_interface whose counter should be incremented | 1578 | * @intf: the usb_interface whose counter should be incremented |
1580 | * | 1579 | * |
@@ -1586,25 +1585,8 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); | |||
1586 | * or @intf is unbound. A typical example would be a character-device | 1585 | * or @intf is unbound. A typical example would be a character-device |
1587 | * driver when its device file is opened. | 1586 | * driver when its device file is opened. |
1588 | * | 1587 | * |
1589 | * | 1588 | * @intf's usage counter is incremented to prevent subsequent autosuspends. |
1590 | * The routine increments @intf's usage counter. (However if the | 1589 | * However if the autoresume fails then the counter is re-decremented. |
1591 | * autoresume fails then the counter is re-decremented.) So long as the | ||
1592 | * counter is greater than 0, autosuspend will not be allowed for @intf | ||
1593 | * or its usb_device. When the driver is finished using @intf it should | ||
1594 | * call usb_autopm_put_interface() to decrement the usage counter and | ||
1595 | * queue a delayed autosuspend request (if the counter is <= 0). | ||
1596 | * | ||
1597 | * | ||
1598 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The | ||
1599 | * core will not change its value other than the increment and decrement | ||
1600 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver | ||
1601 | * may use this simple counter-oriented discipline or may set the value | ||
1602 | * any way it likes. | ||
1603 | * | ||
1604 | * Resume method calls generated by this routine can arrive at any time | ||
1605 | * while @intf is suspended. They are not protected by the usb_device's | ||
1606 | * lock but only by its pm_mutex. Drivers must provide their own | ||
1607 | * synchronization. | ||
1608 | * | 1590 | * |
1609 | * This routine can run only in process context. | 1591 | * This routine can run only in process context. |
1610 | */ | 1592 | */ |
@@ -1612,9 +1594,16 @@ int usb_autopm_get_interface(struct usb_interface *intf) | |||
1612 | { | 1594 | { |
1613 | int status; | 1595 | int status; |
1614 | 1596 | ||
1615 | status = usb_autopm_do_interface(intf, 1); | 1597 | status = pm_runtime_get_sync(&intf->dev); |
1616 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1598 | if (status < 0) |
1617 | __func__, status, atomic_read(&intf->pm_usage_cnt)); | 1599 | pm_runtime_put_sync(&intf->dev); |
1600 | else | ||
1601 | atomic_inc(&intf->pm_usage_cnt); | ||
1602 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", | ||
1603 | __func__, atomic_read(&intf->dev.power.usage_count), | ||
1604 | status); | ||
1605 | if (status > 0) | ||
1606 | status = 0; | ||
1618 | return status; | 1607 | return status; |
1619 | } | 1608 | } |
1620 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | 1609 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); |
@@ -1624,175 +1613,207 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | |||
1624 | * @intf: the usb_interface whose counter should be incremented | 1613 | * @intf: the usb_interface whose counter should be incremented |
1625 | * | 1614 | * |
1626 | * This routine does much the same thing as | 1615 | * This routine does much the same thing as |
1627 | * usb_autopm_get_interface(): it increments @intf's usage counter and | 1616 | * usb_autopm_get_interface(): It increments @intf's usage counter and |
1628 | * queues an autoresume request if the result is > 0. The differences | 1617 | * queues an autoresume request if the device is suspended. The |
1629 | * are that it does not acquire the device's pm_mutex (callers must | 1618 | * differences are that it does not perform any synchronization (callers |
1630 | * handle all synchronization issues themselves), and it does not | 1619 | * should hold a private lock and handle all synchronization issues |
1631 | * autoresume the device directly (it only queues a request). After a | 1620 | * themselves), and it does not autoresume the device directly (it only |
1632 | * successful call, the device will generally not yet be resumed. | 1621 | * queues a request). After a successful call, the device may not yet be |
1622 | * resumed. | ||
1633 | * | 1623 | * |
1634 | * This routine can run in atomic context. | 1624 | * This routine can run in atomic context. |
1635 | */ | 1625 | */ |
1636 | int usb_autopm_get_interface_async(struct usb_interface *intf) | 1626 | int usb_autopm_get_interface_async(struct usb_interface *intf) |
1637 | { | 1627 | { |
1638 | struct usb_device *udev = interface_to_usbdev(intf); | 1628 | int status = 0; |
1639 | int status = 0; | 1629 | enum rpm_status s; |
1640 | 1630 | ||
1641 | if (intf->condition == USB_INTERFACE_UNBOUND) | 1631 | /* Don't request a resume unless the interface is already suspending |
1642 | status = -ENODEV; | 1632 | * or suspended. Doing so would force a running suspend timer to be |
1643 | else if (udev->autoresume_disabled) | 1633 | * cancelled. |
1644 | status = -EPERM; | 1634 | */ |
1645 | else { | 1635 | pm_runtime_get_noresume(&intf->dev); |
1636 | s = ACCESS_ONCE(intf->dev.power.runtime_status); | ||
1637 | if (s == RPM_SUSPENDING || s == RPM_SUSPENDED) | ||
1638 | status = pm_request_resume(&intf->dev); | ||
1639 | |||
1640 | if (status < 0 && status != -EINPROGRESS) | ||
1641 | pm_runtime_put_noidle(&intf->dev); | ||
1642 | else | ||
1646 | atomic_inc(&intf->pm_usage_cnt); | 1643 | atomic_inc(&intf->pm_usage_cnt); |
1647 | if (atomic_read(&intf->pm_usage_cnt) > 0 && | 1644 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
1648 | udev->state == USB_STATE_SUSPENDED) | 1645 | __func__, atomic_read(&intf->dev.power.usage_count), |
1649 | queue_work(ksuspend_usb_wq, &udev->autoresume); | 1646 | status); |
1650 | } | 1647 | if (status > 0) |
1651 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1648 | status = 0; |
1652 | __func__, status, atomic_read(&intf->pm_usage_cnt)); | ||
1653 | return status; | 1649 | return status; |
1654 | } | 1650 | } |
1655 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); | 1651 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); |
1656 | 1652 | ||
1657 | /** | 1653 | /** |
1658 | * usb_autopm_set_interface - set a USB interface's autosuspend state | 1654 | * usb_autopm_get_interface_no_resume - increment a USB interface's PM-usage counter |
1659 | * @intf: the usb_interface whose state should be set | 1655 | * @intf: the usb_interface whose counter should be incremented |
1660 | * | 1656 | * |
1661 | * This routine sets the autosuspend state of @intf's device according | 1657 | * This routine increments @intf's usage counter but does not carry out an |
1662 | * to @intf's usage counter, which the caller must have set previously. | 1658 | * autoresume. |
1663 | * If the counter is <= 0, the device is autosuspended (if it isn't | 1659 | * |
1664 | * already suspended and if nothing else prevents the autosuspend). If | 1660 | * This routine can run in atomic context. |
1665 | * the counter is > 0, the device is autoresumed (if it isn't already | ||
1666 | * awake). | ||
1667 | */ | 1661 | */ |
1668 | int usb_autopm_set_interface(struct usb_interface *intf) | 1662 | void usb_autopm_get_interface_no_resume(struct usb_interface *intf) |
1669 | { | 1663 | { |
1670 | int status; | 1664 | struct usb_device *udev = interface_to_usbdev(intf); |
1671 | 1665 | ||
1672 | status = usb_autopm_do_interface(intf, 0); | 1666 | udev->last_busy = jiffies; |
1673 | dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", | 1667 | atomic_inc(&intf->pm_usage_cnt); |
1674 | __func__, status, atomic_read(&intf->pm_usage_cnt)); | 1668 | pm_runtime_get_noresume(&intf->dev); |
1675 | return status; | ||
1676 | } | 1669 | } |
1677 | EXPORT_SYMBOL_GPL(usb_autopm_set_interface); | 1670 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface_no_resume); |
1678 | 1671 | ||
1679 | #else | 1672 | /* Internal routine to check whether we may autosuspend a device. */ |
1673 | static int autosuspend_check(struct usb_device *udev) | ||
1674 | { | ||
1675 | int i; | ||
1676 | struct usb_interface *intf; | ||
1677 | unsigned long suspend_time, j; | ||
1680 | 1678 | ||
1681 | void usb_autosuspend_work(struct work_struct *work) | 1679 | /* Fail if autosuspend is disabled, or any interfaces are in use, or |
1682 | {} | 1680 | * any interface drivers require remote wakeup but it isn't available. |
1681 | */ | ||
1682 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | ||
1683 | if (udev->actconfig) { | ||
1684 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1685 | intf = udev->actconfig->interface[i]; | ||
1683 | 1686 | ||
1684 | void usb_autoresume_work(struct work_struct *work) | 1687 | /* We don't need to check interfaces that are |
1685 | {} | 1688 | * disabled for runtime PM. Either they are unbound |
1689 | * or else their drivers don't support autosuspend | ||
1690 | * and so they are permanently active. | ||
1691 | */ | ||
1692 | if (intf->dev.power.disable_depth) | ||
1693 | continue; | ||
1694 | if (atomic_read(&intf->dev.power.usage_count) > 0) | ||
1695 | return -EBUSY; | ||
1696 | if (intf->needs_remote_wakeup && | ||
1697 | !udev->do_remote_wakeup) { | ||
1698 | dev_dbg(&udev->dev, "remote wakeup needed " | ||
1699 | "for autosuspend\n"); | ||
1700 | return -EOPNOTSUPP; | ||
1701 | } | ||
1686 | 1702 | ||
1687 | #endif /* CONFIG_USB_SUSPEND */ | 1703 | /* Don't allow autosuspend if the device will need |
1704 | * a reset-resume and any of its interface drivers | ||
1705 | * doesn't include support or needs remote wakeup. | ||
1706 | */ | ||
1707 | if (udev->quirks & USB_QUIRK_RESET_RESUME) { | ||
1708 | struct usb_driver *driver; | ||
1688 | 1709 | ||
1689 | /** | 1710 | driver = to_usb_driver(intf->dev.driver); |
1690 | * usb_external_suspend_device - external suspend of a USB device and its interfaces | 1711 | if (!driver->reset_resume || |
1691 | * @udev: the usb_device to suspend | 1712 | intf->needs_remote_wakeup) |
1692 | * @msg: Power Management message describing this state transition | 1713 | return -EOPNOTSUPP; |
1693 | * | 1714 | } |
1694 | * This routine handles external suspend requests: ones not generated | 1715 | } |
1695 | * internally by a USB driver (autosuspend) but rather coming from the user | 1716 | } |
1696 | * (via sysfs) or the PM core (system sleep). The suspend will be carried | ||
1697 | * out regardless of @udev's usage counter or those of its interfaces, | ||
1698 | * and regardless of whether or not remote wakeup is enabled. Of course, | ||
1699 | * interface drivers still have the option of failing the suspend (if | ||
1700 | * there are unsuspended children, for example). | ||
1701 | * | ||
1702 | * The caller must hold @udev's device lock. | ||
1703 | */ | ||
1704 | int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg) | ||
1705 | { | ||
1706 | int status; | ||
1707 | 1717 | ||
1708 | do_unbind_rebind(udev, DO_UNBIND); | 1718 | /* If everything is okay but the device hasn't been idle for long |
1709 | usb_pm_lock(udev); | 1719 | * enough, queue a delayed autosuspend request. |
1710 | udev->auto_pm = 0; | 1720 | */ |
1711 | status = usb_suspend_both(udev, msg); | 1721 | j = ACCESS_ONCE(jiffies); |
1712 | usb_pm_unlock(udev); | 1722 | suspend_time = udev->last_busy + udev->autosuspend_delay; |
1713 | return status; | 1723 | if (time_before(j, suspend_time)) { |
1724 | pm_schedule_suspend(&udev->dev, jiffies_to_msecs( | ||
1725 | round_jiffies_up_relative(suspend_time - j))); | ||
1726 | return -EAGAIN; | ||
1727 | } | ||
1728 | return 0; | ||
1714 | } | 1729 | } |
1715 | 1730 | ||
1716 | /** | 1731 | static int usb_runtime_suspend(struct device *dev) |
1717 | * usb_external_resume_device - external resume of a USB device and its interfaces | ||
1718 | * @udev: the usb_device to resume | ||
1719 | * @msg: Power Management message describing this state transition | ||
1720 | * | ||
1721 | * This routine handles external resume requests: ones not generated | ||
1722 | * internally by a USB driver (autoresume) but rather coming from the user | ||
1723 | * (via sysfs), the PM core (system resume), or the device itself (remote | ||
1724 | * wakeup). @udev's usage counter is unaffected. | ||
1725 | * | ||
1726 | * The caller must hold @udev's device lock. | ||
1727 | */ | ||
1728 | int usb_external_resume_device(struct usb_device *udev, pm_message_t msg) | ||
1729 | { | 1732 | { |
1730 | int status; | 1733 | int status = 0; |
1731 | 1734 | ||
1732 | usb_pm_lock(udev); | 1735 | /* A USB device can be suspended if it passes the various autosuspend |
1733 | udev->auto_pm = 0; | 1736 | * checks. Runtime suspend for a USB device means suspending all the |
1734 | status = usb_resume_both(udev, msg); | 1737 | * interfaces and then the device itself. |
1735 | udev->last_busy = jiffies; | 1738 | */ |
1736 | usb_pm_unlock(udev); | 1739 | if (is_usb_device(dev)) { |
1737 | if (status == 0) | 1740 | struct usb_device *udev = to_usb_device(dev); |
1738 | do_unbind_rebind(udev, DO_REBIND); | ||
1739 | 1741 | ||
1740 | /* Now that the device is awake, we can start trying to autosuspend | 1742 | if (autosuspend_check(udev) != 0) |
1741 | * it again. */ | 1743 | return -EAGAIN; |
1742 | if (status == 0) | ||
1743 | usb_try_autosuspend_device(udev); | ||
1744 | return status; | ||
1745 | } | ||
1746 | 1744 | ||
1747 | int usb_suspend(struct device *dev, pm_message_t msg) | 1745 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1748 | { | ||
1749 | struct usb_device *udev; | ||
1750 | 1746 | ||
1751 | udev = to_usb_device(dev); | 1747 | /* If an interface fails the suspend, adjust the last_busy |
1748 | * time so that we don't get another suspend attempt right | ||
1749 | * away. | ||
1750 | */ | ||
1751 | if (status) { | ||
1752 | udev->last_busy = jiffies + | ||
1753 | (udev->autosuspend_delay == 0 ? | ||
1754 | HZ/2 : 0); | ||
1755 | } | ||
1752 | 1756 | ||
1753 | /* If udev is already suspended, we can skip this suspend and | 1757 | /* Prevent the parent from suspending immediately after */ |
1754 | * we should also skip the upcoming system resume. High-speed | 1758 | else if (udev->parent) { |
1755 | * root hubs are an exception; they need to resume whenever the | 1759 | udev->parent->last_busy = jiffies; |
1756 | * system wakes up in order for USB-PERSIST port handover to work | 1760 | } |
1757 | * properly. | ||
1758 | */ | ||
1759 | if (udev->state == USB_STATE_SUSPENDED) { | ||
1760 | if (udev->parent || udev->speed != USB_SPEED_HIGH) | ||
1761 | udev->skip_sys_resume = 1; | ||
1762 | return 0; | ||
1763 | } | 1761 | } |
1764 | 1762 | ||
1765 | udev->skip_sys_resume = 0; | 1763 | /* Runtime suspend for a USB interface doesn't mean anything. */ |
1766 | return usb_external_suspend_device(udev, msg); | 1764 | return status; |
1767 | } | 1765 | } |
1768 | 1766 | ||
1769 | int usb_resume(struct device *dev, pm_message_t msg) | 1767 | static int usb_runtime_resume(struct device *dev) |
1770 | { | 1768 | { |
1771 | struct usb_device *udev; | 1769 | /* Runtime resume for a USB device means resuming both the device |
1772 | int status; | 1770 | * and all its interfaces. |
1771 | */ | ||
1772 | if (is_usb_device(dev)) { | ||
1773 | struct usb_device *udev = to_usb_device(dev); | ||
1774 | int status; | ||
1775 | |||
1776 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); | ||
1777 | udev->last_busy = jiffies; | ||
1778 | return status; | ||
1779 | } | ||
1773 | 1780 | ||
1774 | udev = to_usb_device(dev); | 1781 | /* Runtime resume for a USB interface doesn't mean anything. */ |
1782 | return 0; | ||
1783 | } | ||
1775 | 1784 | ||
1776 | /* If udev->skip_sys_resume is set then udev was already suspended | 1785 | static int usb_runtime_idle(struct device *dev) |
1777 | * when the system sleep started, so we don't want to resume it | 1786 | { |
1778 | * during this system wakeup. | 1787 | /* An idle USB device can be suspended if it passes the various |
1788 | * autosuspend checks. An idle interface can be suspended at | ||
1789 | * any time. | ||
1779 | */ | 1790 | */ |
1780 | if (udev->skip_sys_resume) | 1791 | if (is_usb_device(dev)) { |
1781 | return 0; | 1792 | struct usb_device *udev = to_usb_device(dev); |
1782 | status = usb_external_resume_device(udev, msg); | ||
1783 | 1793 | ||
1784 | /* Avoid PM error messages for devices disconnected while suspended | 1794 | if (autosuspend_check(udev) != 0) |
1785 | * as we'll display regular disconnect messages just a bit later. | 1795 | return 0; |
1786 | */ | 1796 | } |
1787 | if (status == -ENODEV) | 1797 | |
1788 | return 0; | 1798 | pm_runtime_suspend(dev); |
1789 | return status; | 1799 | return 0; |
1790 | } | 1800 | } |
1791 | 1801 | ||
1792 | #endif /* CONFIG_PM */ | 1802 | static struct dev_pm_ops usb_bus_pm_ops = { |
1803 | .runtime_suspend = usb_runtime_suspend, | ||
1804 | .runtime_resume = usb_runtime_resume, | ||
1805 | .runtime_idle = usb_runtime_idle, | ||
1806 | }; | ||
1807 | |||
1808 | #else | ||
1809 | |||
1810 | #define usb_bus_pm_ops (*(struct dev_pm_ops *) NULL) | ||
1811 | |||
1812 | #endif /* CONFIG_USB_SUSPEND */ | ||
1793 | 1813 | ||
1794 | struct bus_type usb_bus_type = { | 1814 | struct bus_type usb_bus_type = { |
1795 | .name = "usb", | 1815 | .name = "usb", |
1796 | .match = usb_device_match, | 1816 | .match = usb_device_match, |
1797 | .uevent = usb_uevent, | 1817 | .uevent = usb_uevent, |
1818 | .pm = &usb_bus_pm_ops, | ||
1798 | }; | 1819 | }; |
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index fdfaa7885515..4f84a41ee7a8 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/spinlock.h> | 13 | #include <linux/spinlock.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/idr.h> | 15 | #include <linux/idr.h> |
15 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
16 | #include "usb.h" | 17 | #include "usb.h" |
@@ -186,6 +187,7 @@ int usb_create_ep_devs(struct device *parent, | |||
186 | ep_dev->dev.parent = parent; | 187 | ep_dev->dev.parent = parent; |
187 | ep_dev->dev.release = ep_device_release; | 188 | ep_dev->dev.release = ep_device_release; |
188 | dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); | 189 | dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); |
190 | device_enable_async_suspend(&ep_dev->dev); | ||
189 | 191 | ||
190 | retval = device_register(&ep_dev->dev); | 192 | retval = device_register(&ep_dev->dev); |
191 | if (retval) | 193 | if (retval) |
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c index 222ee07ea680..f06f5dbc8cdc 100644 --- a/drivers/usb/core/file.c +++ b/drivers/usb/core/file.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/rwsem.h> | 20 | #include <linux/rwsem.h> |
21 | #include <linux/slab.h> | ||
21 | #include <linux/smp_lock.h> | 22 | #include <linux/smp_lock.h> |
22 | #include <linux/usb.h> | 23 | #include <linux/usb.h> |
23 | 24 | ||
@@ -34,7 +35,6 @@ static int usb_open(struct inode * inode, struct file * file) | |||
34 | int err = -ENODEV; | 35 | int err = -ENODEV; |
35 | const struct file_operations *old_fops, *new_fops = NULL; | 36 | const struct file_operations *old_fops, *new_fops = NULL; |
36 | 37 | ||
37 | lock_kernel(); | ||
38 | down_read(&minor_rwsem); | 38 | down_read(&minor_rwsem); |
39 | c = usb_minors[minor]; | 39 | c = usb_minors[minor]; |
40 | 40 | ||
@@ -53,7 +53,6 @@ static int usb_open(struct inode * inode, struct file * file) | |||
53 | fops_put(old_fops); | 53 | fops_put(old_fops); |
54 | done: | 54 | done: |
55 | up_read(&minor_rwsem); | 55 | up_read(&minor_rwsem); |
56 | unlock_kernel(); | ||
57 | return err; | 56 | return err; |
58 | } | 57 | } |
59 | 58 | ||
@@ -99,6 +98,7 @@ static int init_usb_class(void) | |||
99 | printk(KERN_ERR "class_create failed for usb devices\n"); | 98 | printk(KERN_ERR "class_create failed for usb devices\n"); |
100 | kfree(usb_class); | 99 | kfree(usb_class); |
101 | usb_class = NULL; | 100 | usb_class = NULL; |
101 | goto exit; | ||
102 | } | 102 | } |
103 | usb_class->class->devnode = usb_devnode; | 103 | usb_class->class->devnode = usb_devnode; |
104 | 104 | ||
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c index 05e6d313961e..2c95153c0f24 100644 --- a/drivers/usb/core/generic.c +++ b/drivers/usb/core/generic.c | |||
@@ -120,7 +120,7 @@ int usb_choose_configuration(struct usb_device *udev) | |||
120 | * than a vendor-specific driver. */ | 120 | * than a vendor-specific driver. */ |
121 | else if (udev->descriptor.bDeviceClass != | 121 | else if (udev->descriptor.bDeviceClass != |
122 | USB_CLASS_VENDOR_SPEC && | 122 | USB_CLASS_VENDOR_SPEC && |
123 | (!desc || desc->bInterfaceClass != | 123 | (desc && desc->bInterfaceClass != |
124 | USB_CLASS_VENDOR_SPEC)) { | 124 | USB_CLASS_VENDOR_SPEC)) { |
125 | best = c; | 125 | best = c; |
126 | break; | 126 | break; |
@@ -139,7 +139,7 @@ int usb_choose_configuration(struct usb_device *udev) | |||
139 | 139 | ||
140 | if (best) { | 140 | if (best) { |
141 | i = best->desc.bConfigurationValue; | 141 | i = best->desc.bConfigurationValue; |
142 | dev_info(&udev->dev, | 142 | dev_dbg(&udev->dev, |
143 | "configuration #%d chosen from %d choice%s\n", | 143 | "configuration #%d chosen from %d choice%s\n", |
144 | i, num_configs, plural(num_configs)); | 144 | i, num_configs, plural(num_configs)); |
145 | } else { | 145 | } else { |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 91f2885b6ee1..15286533c15a 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
22 | #include <linux/pm_runtime.h> | ||
22 | #include <linux/usb.h> | 23 | #include <linux/usb.h> |
23 | 24 | ||
24 | #include <asm/io.h> | 25 | #include <asm/io.h> |
@@ -37,6 +38,122 @@ | |||
37 | 38 | ||
38 | /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ | 39 | /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ |
39 | 40 | ||
41 | #ifdef CONFIG_PM_SLEEP | ||
42 | |||
43 | /* Coordinate handoffs between EHCI and companion controllers | ||
44 | * during system resume | ||
45 | */ | ||
46 | |||
47 | static DEFINE_MUTEX(companions_mutex); | ||
48 | |||
49 | #define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI | ||
50 | #define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI | ||
51 | #define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI | ||
52 | |||
53 | enum companion_action { | ||
54 | SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS | ||
55 | }; | ||
56 | |||
57 | static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd, | ||
58 | enum companion_action action) | ||
59 | { | ||
60 | struct pci_dev *companion; | ||
61 | struct usb_hcd *companion_hcd; | ||
62 | unsigned int slot = PCI_SLOT(pdev->devfn); | ||
63 | |||
64 | /* Iterate through other PCI functions in the same slot. | ||
65 | * If pdev is OHCI or UHCI then we are looking for EHCI, and | ||
66 | * vice versa. | ||
67 | */ | ||
68 | companion = NULL; | ||
69 | for (;;) { | ||
70 | companion = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, companion); | ||
71 | if (!companion) | ||
72 | break; | ||
73 | if (companion->bus != pdev->bus || | ||
74 | PCI_SLOT(companion->devfn) != slot) | ||
75 | continue; | ||
76 | |||
77 | companion_hcd = pci_get_drvdata(companion); | ||
78 | if (!companion_hcd) | ||
79 | continue; | ||
80 | |||
81 | /* For SET_HS_COMPANION, store a pointer to the EHCI bus in | ||
82 | * the OHCI/UHCI companion bus structure. | ||
83 | * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus | ||
84 | * in the OHCI/UHCI companion bus structure. | ||
85 | * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI | ||
86 | * companion controllers have fully resumed. | ||
87 | */ | ||
88 | |||
89 | if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) && | ||
90 | companion->class == CL_EHCI) { | ||
91 | /* action must be SET_HS_COMPANION */ | ||
92 | dev_dbg(&companion->dev, "HS companion for %s\n", | ||
93 | dev_name(&pdev->dev)); | ||
94 | hcd->self.hs_companion = &companion_hcd->self; | ||
95 | |||
96 | } else if (pdev->class == CL_EHCI && | ||
97 | (companion->class == CL_OHCI || | ||
98 | companion->class == CL_UHCI)) { | ||
99 | switch (action) { | ||
100 | case SET_HS_COMPANION: | ||
101 | dev_dbg(&pdev->dev, "HS companion for %s\n", | ||
102 | dev_name(&companion->dev)); | ||
103 | companion_hcd->self.hs_companion = &hcd->self; | ||
104 | break; | ||
105 | case CLEAR_HS_COMPANION: | ||
106 | companion_hcd->self.hs_companion = NULL; | ||
107 | break; | ||
108 | case WAIT_FOR_COMPANIONS: | ||
109 | device_pm_wait_for_dev(&pdev->dev, | ||
110 | &companion->dev); | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) | ||
118 | { | ||
119 | mutex_lock(&companions_mutex); | ||
120 | dev_set_drvdata(&pdev->dev, hcd); | ||
121 | companion_common(pdev, hcd, SET_HS_COMPANION); | ||
122 | mutex_unlock(&companions_mutex); | ||
123 | } | ||
124 | |||
125 | static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) | ||
126 | { | ||
127 | mutex_lock(&companions_mutex); | ||
128 | dev_set_drvdata(&pdev->dev, NULL); | ||
129 | |||
130 | /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */ | ||
131 | if (pdev->class == CL_OHCI || pdev->class == CL_UHCI) | ||
132 | hcd->self.hs_companion = NULL; | ||
133 | |||
134 | /* Otherwise search for companion buses and clear their pointers */ | ||
135 | else | ||
136 | companion_common(pdev, hcd, CLEAR_HS_COMPANION); | ||
137 | mutex_unlock(&companions_mutex); | ||
138 | } | ||
139 | |||
140 | static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd) | ||
141 | { | ||
142 | /* Only EHCI controllers need to wait. | ||
143 | * No locking is needed because a controller cannot be resumed | ||
144 | * while one of its companions is getting unbound. | ||
145 | */ | ||
146 | if (pdev->class == CL_EHCI) | ||
147 | companion_common(pdev, hcd, WAIT_FOR_COMPANIONS); | ||
148 | } | ||
149 | |||
150 | #else /* !CONFIG_PM_SLEEP */ | ||
151 | |||
152 | static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} | ||
153 | static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} | ||
154 | static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {} | ||
155 | |||
156 | #endif /* !CONFIG_PM_SLEEP */ | ||
40 | 157 | ||
41 | /*-------------------------------------------------------------------------*/ | 158 | /*-------------------------------------------------------------------------*/ |
42 | 159 | ||
@@ -123,7 +240,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
123 | if (region == PCI_ROM_RESOURCE) { | 240 | if (region == PCI_ROM_RESOURCE) { |
124 | dev_dbg(&dev->dev, "no i/o regions available\n"); | 241 | dev_dbg(&dev->dev, "no i/o regions available\n"); |
125 | retval = -EBUSY; | 242 | retval = -EBUSY; |
126 | goto err1; | 243 | goto err2; |
127 | } | 244 | } |
128 | } | 245 | } |
129 | 246 | ||
@@ -132,6 +249,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
132 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 249 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
133 | if (retval != 0) | 250 | if (retval != 0) |
134 | goto err4; | 251 | goto err4; |
252 | set_hs_companion(dev, hcd); | ||
135 | return retval; | 253 | return retval; |
136 | 254 | ||
137 | err4: | 255 | err4: |
@@ -142,6 +260,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
142 | } else | 260 | } else |
143 | release_region(hcd->rsrc_start, hcd->rsrc_len); | 261 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
144 | err2: | 262 | err2: |
263 | clear_hs_companion(dev, hcd); | ||
145 | usb_put_hcd(hcd); | 264 | usb_put_hcd(hcd); |
146 | err1: | 265 | err1: |
147 | pci_disable_device(dev); | 266 | pci_disable_device(dev); |
@@ -180,6 +299,7 @@ void usb_hcd_pci_remove(struct pci_dev *dev) | |||
180 | } else { | 299 | } else { |
181 | release_region(hcd->rsrc_start, hcd->rsrc_len); | 300 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
182 | } | 301 | } |
302 | clear_hs_companion(dev, hcd); | ||
183 | usb_put_hcd(hcd); | 303 | usb_put_hcd(hcd); |
184 | pci_disable_device(dev); | 304 | pci_disable_device(dev); |
185 | } | 305 | } |
@@ -344,6 +464,11 @@ static int resume_common(struct device *dev, bool hibernated) | |||
344 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 464 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
345 | 465 | ||
346 | if (hcd->driver->pci_resume) { | 466 | if (hcd->driver->pci_resume) { |
467 | /* This call should be made only during system resume, | ||
468 | * not during runtime resume. | ||
469 | */ | ||
470 | wait_for_companions(pci_dev, hcd); | ||
471 | |||
347 | retval = hcd->driver->pci_resume(hcd, hibernated); | 472 | retval = hcd->driver->pci_resume(hcd, hibernated); |
348 | if (retval) { | 473 | if (retval) { |
349 | dev_err(dev, "PCI post-resume error %d!\n", retval); | 474 | dev_err(dev, "PCI post-resume error %d!\n", retval); |
@@ -363,7 +488,7 @@ static int hcd_pci_restore(struct device *dev) | |||
363 | return resume_common(dev, true); | 488 | return resume_common(dev, true); |
364 | } | 489 | } |
365 | 490 | ||
366 | struct dev_pm_ops usb_hcd_pci_pm_ops = { | 491 | const struct dev_pm_ops usb_hcd_pci_pm_ops = { |
367 | .suspend = hcd_pci_suspend, | 492 | .suspend = hcd_pci_suspend, |
368 | .suspend_noirq = hcd_pci_suspend_noirq, | 493 | .suspend_noirq = hcd_pci_suspend_noirq, |
369 | .resume_noirq = hcd_pci_resume_noirq, | 494 | .resume_noirq = hcd_pci_resume_noirq, |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 34de475f016e..2f8cedda8007 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -38,6 +38,8 @@ | |||
38 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
39 | #include <linux/platform_device.h> | 39 | #include <linux/platform_device.h> |
40 | #include <linux/workqueue.h> | 40 | #include <linux/workqueue.h> |
41 | #include <linux/mutex.h> | ||
42 | #include <linux/pm_runtime.h> | ||
41 | 43 | ||
42 | #include <linux/usb.h> | 44 | #include <linux/usb.h> |
43 | 45 | ||
@@ -140,7 +142,7 @@ static const u8 usb3_rh_dev_descriptor[18] = { | |||
140 | 0x09, /* __u8 bMaxPacketSize0; 2^9 = 512 Bytes */ | 142 | 0x09, /* __u8 bMaxPacketSize0; 2^9 = 512 Bytes */ |
141 | 143 | ||
142 | 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ | 144 | 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ |
143 | 0x02, 0x00, /* __le16 idProduct; device 0x0002 */ | 145 | 0x03, 0x00, /* __le16 idProduct; device 0x0003 */ |
144 | KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ | 146 | KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ |
145 | 147 | ||
146 | 0x03, /* __u8 iManufacturer; */ | 148 | 0x03, /* __u8 iManufacturer; */ |
@@ -1275,13 +1277,16 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1275 | 1277 | ||
1276 | if (usb_endpoint_xfer_control(&urb->ep->desc) | 1278 | if (usb_endpoint_xfer_control(&urb->ep->desc) |
1277 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { | 1279 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { |
1278 | if (hcd->self.uses_dma) | 1280 | if (hcd->self.uses_dma) { |
1279 | urb->setup_dma = dma_map_single( | 1281 | urb->setup_dma = dma_map_single( |
1280 | hcd->self.controller, | 1282 | hcd->self.controller, |
1281 | urb->setup_packet, | 1283 | urb->setup_packet, |
1282 | sizeof(struct usb_ctrlrequest), | 1284 | sizeof(struct usb_ctrlrequest), |
1283 | DMA_TO_DEVICE); | 1285 | DMA_TO_DEVICE); |
1284 | else if (hcd->driver->flags & HCD_LOCAL_MEM) | 1286 | if (dma_mapping_error(hcd->self.controller, |
1287 | urb->setup_dma)) | ||
1288 | return -EAGAIN; | ||
1289 | } else if (hcd->driver->flags & HCD_LOCAL_MEM) | ||
1285 | ret = hcd_alloc_coherent( | 1290 | ret = hcd_alloc_coherent( |
1286 | urb->dev->bus, mem_flags, | 1291 | urb->dev->bus, mem_flags, |
1287 | &urb->setup_dma, | 1292 | &urb->setup_dma, |
@@ -1293,13 +1298,16 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1293 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 1298 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; |
1294 | if (ret == 0 && urb->transfer_buffer_length != 0 | 1299 | if (ret == 0 && urb->transfer_buffer_length != 0 |
1295 | && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { | 1300 | && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { |
1296 | if (hcd->self.uses_dma) | 1301 | if (hcd->self.uses_dma) { |
1297 | urb->transfer_dma = dma_map_single ( | 1302 | urb->transfer_dma = dma_map_single ( |
1298 | hcd->self.controller, | 1303 | hcd->self.controller, |
1299 | urb->transfer_buffer, | 1304 | urb->transfer_buffer, |
1300 | urb->transfer_buffer_length, | 1305 | urb->transfer_buffer_length, |
1301 | dir); | 1306 | dir); |
1302 | else if (hcd->driver->flags & HCD_LOCAL_MEM) { | 1307 | if (dma_mapping_error(hcd->self.controller, |
1308 | urb->transfer_dma)) | ||
1309 | return -EAGAIN; | ||
1310 | } else if (hcd->driver->flags & HCD_LOCAL_MEM) { | ||
1303 | ret = hcd_alloc_coherent( | 1311 | ret = hcd_alloc_coherent( |
1304 | urb->dev->bus, mem_flags, | 1312 | urb->dev->bus, mem_flags, |
1305 | &urb->transfer_dma, | 1313 | &urb->transfer_dma, |
@@ -1589,19 +1597,34 @@ rescan: | |||
1589 | } | 1597 | } |
1590 | } | 1598 | } |
1591 | 1599 | ||
1592 | /* Check whether a new configuration or alt setting for an interface | 1600 | /** |
1593 | * will exceed the bandwidth for the bus (or the host controller resources). | 1601 | * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds |
1594 | * Only pass in a non-NULL config or interface, not both! | 1602 | * the bus bandwidth |
1595 | * Passing NULL for both new_config and new_intf means the device will be | 1603 | * @udev: target &usb_device |
1596 | * de-configured by issuing a set configuration 0 command. | 1604 | * @new_config: new configuration to install |
1605 | * @cur_alt: the current alternate interface setting | ||
1606 | * @new_alt: alternate interface setting that is being installed | ||
1607 | * | ||
1608 | * To change configurations, pass in the new configuration in new_config, | ||
1609 | * and pass NULL for cur_alt and new_alt. | ||
1610 | * | ||
1611 | * To reset a device's configuration (put the device in the ADDRESSED state), | ||
1612 | * pass in NULL for new_config, cur_alt, and new_alt. | ||
1613 | * | ||
1614 | * To change alternate interface settings, pass in NULL for new_config, | ||
1615 | * pass in the current alternate interface setting in cur_alt, | ||
1616 | * and pass in the new alternate interface setting in new_alt. | ||
1617 | * | ||
1618 | * Returns an error if the requested bandwidth change exceeds the | ||
1619 | * bus bandwidth or host controller internal resources. | ||
1597 | */ | 1620 | */ |
1598 | int usb_hcd_check_bandwidth(struct usb_device *udev, | 1621 | int usb_hcd_alloc_bandwidth(struct usb_device *udev, |
1599 | struct usb_host_config *new_config, | 1622 | struct usb_host_config *new_config, |
1600 | struct usb_interface *new_intf) | 1623 | struct usb_host_interface *cur_alt, |
1624 | struct usb_host_interface *new_alt) | ||
1601 | { | 1625 | { |
1602 | int num_intfs, i, j; | 1626 | int num_intfs, i, j; |
1603 | struct usb_interface_cache *intf_cache; | 1627 | struct usb_host_interface *alt = NULL; |
1604 | struct usb_host_interface *alt = 0; | ||
1605 | int ret = 0; | 1628 | int ret = 0; |
1606 | struct usb_hcd *hcd; | 1629 | struct usb_hcd *hcd; |
1607 | struct usb_host_endpoint *ep; | 1630 | struct usb_host_endpoint *ep; |
@@ -1611,7 +1634,7 @@ int usb_hcd_check_bandwidth(struct usb_device *udev, | |||
1611 | return 0; | 1634 | return 0; |
1612 | 1635 | ||
1613 | /* Configuration is being removed - set configuration 0 */ | 1636 | /* Configuration is being removed - set configuration 0 */ |
1614 | if (!new_config && !new_intf) { | 1637 | if (!new_config && !cur_alt) { |
1615 | for (i = 1; i < 16; ++i) { | 1638 | for (i = 1; i < 16; ++i) { |
1616 | ep = udev->ep_out[i]; | 1639 | ep = udev->ep_out[i]; |
1617 | if (ep) | 1640 | if (ep) |
@@ -1648,19 +1671,17 @@ int usb_hcd_check_bandwidth(struct usb_device *udev, | |||
1648 | } | 1671 | } |
1649 | } | 1672 | } |
1650 | for (i = 0; i < num_intfs; ++i) { | 1673 | for (i = 0; i < num_intfs; ++i) { |
1674 | struct usb_host_interface *first_alt; | ||
1675 | int iface_num; | ||
1676 | |||
1677 | first_alt = &new_config->intf_cache[i]->altsetting[0]; | ||
1678 | iface_num = first_alt->desc.bInterfaceNumber; | ||
1679 | /* Set up endpoints for alternate interface setting 0 */ | ||
1680 | alt = usb_find_alt_setting(new_config, iface_num, 0); | ||
1681 | if (!alt) | ||
1682 | /* No alt setting 0? Pick the first setting. */ | ||
1683 | alt = first_alt; | ||
1651 | 1684 | ||
1652 | /* Dig the endpoints for alt setting 0 out of the | ||
1653 | * interface cache for this interface | ||
1654 | */ | ||
1655 | intf_cache = new_config->intf_cache[i]; | ||
1656 | for (j = 0; j < intf_cache->num_altsetting; j++) { | ||
1657 | if (intf_cache->altsetting[j].desc.bAlternateSetting == 0) | ||
1658 | alt = &intf_cache->altsetting[j]; | ||
1659 | } | ||
1660 | if (!alt) { | ||
1661 | printk(KERN_DEBUG "Did not find alt setting 0 for intf %d\n", i); | ||
1662 | continue; | ||
1663 | } | ||
1664 | for (j = 0; j < alt->desc.bNumEndpoints; j++) { | 1685 | for (j = 0; j < alt->desc.bNumEndpoints; j++) { |
1665 | ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); | 1686 | ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); |
1666 | if (ret < 0) | 1687 | if (ret < 0) |
@@ -1668,6 +1689,40 @@ int usb_hcd_check_bandwidth(struct usb_device *udev, | |||
1668 | } | 1689 | } |
1669 | } | 1690 | } |
1670 | } | 1691 | } |
1692 | if (cur_alt && new_alt) { | ||
1693 | struct usb_interface *iface = usb_ifnum_to_if(udev, | ||
1694 | cur_alt->desc.bInterfaceNumber); | ||
1695 | |||
1696 | if (iface->resetting_device) { | ||
1697 | /* | ||
1698 | * The USB core just reset the device, so the xHCI host | ||
1699 | * and the device will think alt setting 0 is installed. | ||
1700 | * However, the USB core will pass in the alternate | ||
1701 | * setting installed before the reset as cur_alt. Dig | ||
1702 | * out the alternate setting 0 structure, or the first | ||
1703 | * alternate setting if a broken device doesn't have alt | ||
1704 | * setting 0. | ||
1705 | */ | ||
1706 | cur_alt = usb_altnum_to_altsetting(iface, 0); | ||
1707 | if (!cur_alt) | ||
1708 | cur_alt = &iface->altsetting[0]; | ||
1709 | } | ||
1710 | |||
1711 | /* Drop all the endpoints in the current alt setting */ | ||
1712 | for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) { | ||
1713 | ret = hcd->driver->drop_endpoint(hcd, udev, | ||
1714 | &cur_alt->endpoint[i]); | ||
1715 | if (ret < 0) | ||
1716 | goto reset; | ||
1717 | } | ||
1718 | /* Add all the endpoints in the new alt setting */ | ||
1719 | for (i = 0; i < new_alt->desc.bNumEndpoints; i++) { | ||
1720 | ret = hcd->driver->add_endpoint(hcd, udev, | ||
1721 | &new_alt->endpoint[i]); | ||
1722 | if (ret < 0) | ||
1723 | goto reset; | ||
1724 | } | ||
1725 | } | ||
1671 | ret = hcd->driver->check_bandwidth(hcd, udev); | 1726 | ret = hcd->driver->check_bandwidth(hcd, udev); |
1672 | reset: | 1727 | reset: |
1673 | if (ret < 0) | 1728 | if (ret < 0) |
@@ -1804,6 +1859,10 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1804 | return status; | 1859 | return status; |
1805 | } | 1860 | } |
1806 | 1861 | ||
1862 | #endif /* CONFIG_PM */ | ||
1863 | |||
1864 | #ifdef CONFIG_USB_SUSPEND | ||
1865 | |||
1807 | /* Workqueue routine for root-hub remote wakeup */ | 1866 | /* Workqueue routine for root-hub remote wakeup */ |
1808 | static void hcd_resume_work(struct work_struct *work) | 1867 | static void hcd_resume_work(struct work_struct *work) |
1809 | { | 1868 | { |
@@ -1811,8 +1870,7 @@ static void hcd_resume_work(struct work_struct *work) | |||
1811 | struct usb_device *udev = hcd->self.root_hub; | 1870 | struct usb_device *udev = hcd->self.root_hub; |
1812 | 1871 | ||
1813 | usb_lock_device(udev); | 1872 | usb_lock_device(udev); |
1814 | usb_mark_last_busy(udev); | 1873 | usb_remote_wakeup(udev); |
1815 | usb_external_resume_device(udev, PMSG_REMOTE_RESUME); | ||
1816 | usb_unlock_device(udev); | 1874 | usb_unlock_device(udev); |
1817 | } | 1875 | } |
1818 | 1876 | ||
@@ -1831,12 +1889,12 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd) | |||
1831 | 1889 | ||
1832 | spin_lock_irqsave (&hcd_root_hub_lock, flags); | 1890 | spin_lock_irqsave (&hcd_root_hub_lock, flags); |
1833 | if (hcd->rh_registered) | 1891 | if (hcd->rh_registered) |
1834 | queue_work(ksuspend_usb_wq, &hcd->wakeup_work); | 1892 | queue_work(pm_wq, &hcd->wakeup_work); |
1835 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 1893 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
1836 | } | 1894 | } |
1837 | EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); | 1895 | EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); |
1838 | 1896 | ||
1839 | #endif | 1897 | #endif /* CONFIG_USB_SUSPEND */ |
1840 | 1898 | ||
1841 | /*-------------------------------------------------------------------------*/ | 1899 | /*-------------------------------------------------------------------------*/ |
1842 | 1900 | ||
@@ -1981,9 +2039,10 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1981 | init_timer(&hcd->rh_timer); | 2039 | init_timer(&hcd->rh_timer); |
1982 | hcd->rh_timer.function = rh_timer_func; | 2040 | hcd->rh_timer.function = rh_timer_func; |
1983 | hcd->rh_timer.data = (unsigned long) hcd; | 2041 | hcd->rh_timer.data = (unsigned long) hcd; |
1984 | #ifdef CONFIG_PM | 2042 | #ifdef CONFIG_USB_SUSPEND |
1985 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); | 2043 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); |
1986 | #endif | 2044 | #endif |
2045 | mutex_init(&hcd->bandwidth_mutex); | ||
1987 | 2046 | ||
1988 | hcd->driver = driver; | 2047 | hcd->driver = driver; |
1989 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : | 2048 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : |
@@ -2180,7 +2239,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2180 | hcd->rh_registered = 0; | 2239 | hcd->rh_registered = 0; |
2181 | spin_unlock_irq (&hcd_root_hub_lock); | 2240 | spin_unlock_irq (&hcd_root_hub_lock); |
2182 | 2241 | ||
2183 | #ifdef CONFIG_PM | 2242 | #ifdef CONFIG_USB_SUSPEND |
2184 | cancel_work_sync(&hcd->wakeup_work); | 2243 | cancel_work_sync(&hcd->wakeup_work); |
2185 | #endif | 2244 | #endif |
2186 | 2245 | ||
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 79782a1c43f6..a3cdb09734ab 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -80,7 +80,7 @@ struct usb_hcd { | |||
80 | 80 | ||
81 | struct timer_list rh_timer; /* drives root-hub polling */ | 81 | struct timer_list rh_timer; /* drives root-hub polling */ |
82 | struct urb *status_urb; /* the current status urb */ | 82 | struct urb *status_urb; /* the current status urb */ |
83 | #ifdef CONFIG_PM | 83 | #ifdef CONFIG_USB_SUSPEND |
84 | struct work_struct wakeup_work; /* for remote wakeup */ | 84 | struct work_struct wakeup_work; /* for remote wakeup */ |
85 | #endif | 85 | #endif |
86 | 86 | ||
@@ -111,6 +111,20 @@ struct usb_hcd { | |||
111 | u64 rsrc_len; /* memory/io resource length */ | 111 | u64 rsrc_len; /* memory/io resource length */ |
112 | unsigned power_budget; /* in mA, 0 = no limit */ | 112 | unsigned power_budget; /* in mA, 0 = no limit */ |
113 | 113 | ||
114 | /* bandwidth_mutex should be taken before adding or removing | ||
115 | * any new bus bandwidth constraints: | ||
116 | * 1. Before adding a configuration for a new device. | ||
117 | * 2. Before removing the configuration to put the device into | ||
118 | * the addressed state. | ||
119 | * 3. Before selecting a different configuration. | ||
120 | * 4. Before selecting an alternate interface setting. | ||
121 | * | ||
122 | * bandwidth_mutex should be dropped after a successful control message | ||
123 | * to the device, or resetting the bandwidth after a failed attempt. | ||
124 | */ | ||
125 | struct mutex bandwidth_mutex; | ||
126 | |||
127 | |||
114 | #define HCD_BUFFER_POOLS 4 | 128 | #define HCD_BUFFER_POOLS 4 |
115 | struct dma_pool *pool [HCD_BUFFER_POOLS]; | 129 | struct dma_pool *pool [HCD_BUFFER_POOLS]; |
116 | 130 | ||
@@ -234,7 +248,7 @@ struct hc_driver { | |||
234 | /* xHCI specific functions */ | 248 | /* xHCI specific functions */ |
235 | /* Called by usb_alloc_dev to alloc HC device structures */ | 249 | /* Called by usb_alloc_dev to alloc HC device structures */ |
236 | int (*alloc_dev)(struct usb_hcd *, struct usb_device *); | 250 | int (*alloc_dev)(struct usb_hcd *, struct usb_device *); |
237 | /* Called by usb_release_dev to free HC device structures */ | 251 | /* Called by usb_disconnect to free HC device structures */ |
238 | void (*free_dev)(struct usb_hcd *, struct usb_device *); | 252 | void (*free_dev)(struct usb_hcd *, struct usb_device *); |
239 | 253 | ||
240 | /* Bandwidth computation functions */ | 254 | /* Bandwidth computation functions */ |
@@ -272,6 +286,7 @@ struct hc_driver { | |||
272 | */ | 286 | */ |
273 | int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev, | 287 | int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev, |
274 | struct usb_tt *tt, gfp_t mem_flags); | 288 | struct usb_tt *tt, gfp_t mem_flags); |
289 | int (*reset_device)(struct usb_hcd *, struct usb_device *); | ||
275 | }; | 290 | }; |
276 | 291 | ||
277 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | 292 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); |
@@ -290,9 +305,10 @@ extern void usb_hcd_disable_endpoint(struct usb_device *udev, | |||
290 | extern void usb_hcd_reset_endpoint(struct usb_device *udev, | 305 | extern void usb_hcd_reset_endpoint(struct usb_device *udev, |
291 | struct usb_host_endpoint *ep); | 306 | struct usb_host_endpoint *ep); |
292 | extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); | 307 | extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); |
293 | extern int usb_hcd_check_bandwidth(struct usb_device *udev, | 308 | extern int usb_hcd_alloc_bandwidth(struct usb_device *udev, |
294 | struct usb_host_config *new_config, | 309 | struct usb_host_config *new_config, |
295 | struct usb_interface *new_intf); | 310 | struct usb_host_interface *old_alt, |
311 | struct usb_host_interface *new_alt); | ||
296 | extern int usb_hcd_get_frame_number(struct usb_device *udev); | 312 | extern int usb_hcd_get_frame_number(struct usb_device *udev); |
297 | 313 | ||
298 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | 314 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, |
@@ -315,7 +331,7 @@ extern void usb_hcd_pci_remove(struct pci_dev *dev); | |||
315 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); | 331 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); |
316 | 332 | ||
317 | #ifdef CONFIG_PM_SLEEP | 333 | #ifdef CONFIG_PM_SLEEP |
318 | extern struct dev_pm_ops usb_hcd_pci_pm_ops; | 334 | extern const struct dev_pm_ops usb_hcd_pci_pm_ops; |
319 | #endif | 335 | #endif |
320 | #endif /* CONFIG_PCI */ | 336 | #endif /* CONFIG_PCI */ |
321 | 337 | ||
@@ -448,16 +464,20 @@ extern int usb_find_interface_driver(struct usb_device *dev, | |||
448 | #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) | 464 | #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) |
449 | 465 | ||
450 | #ifdef CONFIG_PM | 466 | #ifdef CONFIG_PM |
451 | extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); | ||
452 | extern void usb_root_hub_lost_power(struct usb_device *rhdev); | 467 | extern void usb_root_hub_lost_power(struct usb_device *rhdev); |
453 | extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); | 468 | extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); |
454 | extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); | 469 | extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); |
470 | #endif /* CONFIG_PM */ | ||
471 | |||
472 | #ifdef CONFIG_USB_SUSPEND | ||
473 | extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); | ||
455 | #else | 474 | #else |
456 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) | 475 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) |
457 | { | 476 | { |
458 | return; | 477 | return; |
459 | } | 478 | } |
460 | #endif /* CONFIG_PM */ | 479 | #endif /* CONFIG_USB_SUSPEND */ |
480 | |||
461 | 481 | ||
462 | /* | 482 | /* |
463 | * USB device fs stuff | 483 | * USB device fs stuff |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 0f857e645058..0940ccd6f4f4 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/kthread.h> | 22 | #include <linux/kthread.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/freezer.h> | 24 | #include <linux/freezer.h> |
25 | #include <linux/pm_runtime.h> | ||
25 | 26 | ||
26 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
27 | #include <asm/byteorder.h> | 28 | #include <asm/byteorder.h> |
@@ -45,7 +46,6 @@ struct usb_hub { | |||
45 | 46 | ||
46 | /* buffer for urb ... with extra space in case of babble */ | 47 | /* buffer for urb ... with extra space in case of babble */ |
47 | char (*buffer)[8]; | 48 | char (*buffer)[8]; |
48 | dma_addr_t buffer_dma; /* DMA address for buffer */ | ||
49 | union { | 49 | union { |
50 | struct usb_hub_status hub; | 50 | struct usb_hub_status hub; |
51 | struct usb_port_status port; | 51 | struct usb_port_status port; |
@@ -61,6 +61,8 @@ struct usb_hub { | |||
61 | status change */ | 61 | status change */ |
62 | unsigned long busy_bits[1]; /* ports being reset or | 62 | unsigned long busy_bits[1]; /* ports being reset or |
63 | resumed */ | 63 | resumed */ |
64 | unsigned long removed_bits[1]; /* ports with a "removed" | ||
65 | device present */ | ||
64 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | 66 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ |
65 | #error event_bits[] is too short! | 67 | #error event_bits[] is too short! |
66 | #endif | 68 | #endif |
@@ -374,12 +376,13 @@ static void kick_khubd(struct usb_hub *hub) | |||
374 | { | 376 | { |
375 | unsigned long flags; | 377 | unsigned long flags; |
376 | 378 | ||
377 | /* Suppress autosuspend until khubd runs */ | ||
378 | atomic_set(&to_usb_interface(hub->intfdev)->pm_usage_cnt, 1); | ||
379 | |||
380 | spin_lock_irqsave(&hub_event_lock, flags); | 379 | spin_lock_irqsave(&hub_event_lock, flags); |
381 | if (!hub->disconnected && list_empty(&hub->event_list)) { | 380 | if (!hub->disconnected && list_empty(&hub->event_list)) { |
382 | list_add_tail(&hub->event_list, &hub_event_list); | 381 | list_add_tail(&hub->event_list, &hub_event_list); |
382 | |||
383 | /* Suppress autosuspend until khubd runs */ | ||
384 | usb_autopm_get_interface_no_resume( | ||
385 | to_usb_interface(hub->intfdev)); | ||
383 | wake_up(&khubd_wait); | 386 | wake_up(&khubd_wait); |
384 | } | 387 | } |
385 | spin_unlock_irqrestore(&hub_event_lock, flags); | 388 | spin_unlock_irqrestore(&hub_event_lock, flags); |
@@ -636,8 +639,35 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | |||
636 | kick_khubd(hub); | 639 | kick_khubd(hub); |
637 | } | 640 | } |
638 | 641 | ||
642 | /** | ||
643 | * usb_remove_device - disable a device's port on its parent hub | ||
644 | * @udev: device to be disabled and removed | ||
645 | * Context: @udev locked, must be able to sleep. | ||
646 | * | ||
647 | * After @udev's port has been disabled, khubd is notified and it will | ||
648 | * see that the device has been disconnected. When the device is | ||
649 | * physically unplugged and something is plugged in, the events will | ||
650 | * be received and processed normally. | ||
651 | */ | ||
652 | int usb_remove_device(struct usb_device *udev) | ||
653 | { | ||
654 | struct usb_hub *hub; | ||
655 | struct usb_interface *intf; | ||
656 | |||
657 | if (!udev->parent) /* Can't remove a root hub */ | ||
658 | return -EINVAL; | ||
659 | hub = hdev_to_hub(udev->parent); | ||
660 | intf = to_usb_interface(hub->intfdev); | ||
661 | |||
662 | usb_autopm_get_interface(intf); | ||
663 | set_bit(udev->portnum, hub->removed_bits); | ||
664 | hub_port_logical_disconnect(hub, udev->portnum); | ||
665 | usb_autopm_put_interface(intf); | ||
666 | return 0; | ||
667 | } | ||
668 | |||
639 | enum hub_activation_type { | 669 | enum hub_activation_type { |
640 | HUB_INIT, HUB_INIT2, HUB_INIT3, | 670 | HUB_INIT, HUB_INIT2, HUB_INIT3, /* INITs must come first */ |
641 | HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME, | 671 | HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME, |
642 | }; | 672 | }; |
643 | 673 | ||
@@ -682,8 +712,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
682 | msecs_to_jiffies(delay)); | 712 | msecs_to_jiffies(delay)); |
683 | 713 | ||
684 | /* Suppress autosuspend until init is done */ | 714 | /* Suppress autosuspend until init is done */ |
685 | atomic_set(&to_usb_interface(hub->intfdev)-> | 715 | usb_autopm_get_interface_no_resume( |
686 | pm_usage_cnt, 1); | 716 | to_usb_interface(hub->intfdev)); |
687 | return; /* Continues at init2: below */ | 717 | return; /* Continues at init2: below */ |
688 | } else { | 718 | } else { |
689 | hub_power_on(hub, true); | 719 | hub_power_on(hub, true); |
@@ -731,6 +761,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
731 | USB_PORT_FEAT_C_ENABLE); | 761 | USB_PORT_FEAT_C_ENABLE); |
732 | } | 762 | } |
733 | 763 | ||
764 | /* We can forget about a "removed" device when there's a | ||
765 | * physical disconnect or the connect status changes. | ||
766 | */ | ||
767 | if (!(portstatus & USB_PORT_STAT_CONNECTION) || | ||
768 | (portchange & USB_PORT_STAT_C_CONNECTION)) | ||
769 | clear_bit(port1, hub->removed_bits); | ||
770 | |||
734 | if (!udev || udev->state == USB_STATE_NOTATTACHED) { | 771 | if (!udev || udev->state == USB_STATE_NOTATTACHED) { |
735 | /* Tell khubd to disconnect the device or | 772 | /* Tell khubd to disconnect the device or |
736 | * check for a new connection | 773 | * check for a new connection |
@@ -792,6 +829,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
792 | 829 | ||
793 | /* Scan all ports that need attention */ | 830 | /* Scan all ports that need attention */ |
794 | kick_khubd(hub); | 831 | kick_khubd(hub); |
832 | |||
833 | /* Allow autosuspend if it was suppressed */ | ||
834 | if (type <= HUB_INIT3) | ||
835 | usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); | ||
795 | } | 836 | } |
796 | 837 | ||
797 | /* Implement the continuations for the delays above */ | 838 | /* Implement the continuations for the delays above */ |
@@ -869,8 +910,7 @@ static int hub_configure(struct usb_hub *hub, | |||
869 | int maxp, ret; | 910 | int maxp, ret; |
870 | char *message = "out of memory"; | 911 | char *message = "out of memory"; |
871 | 912 | ||
872 | hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL, | 913 | hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); |
873 | &hub->buffer_dma); | ||
874 | if (!hub->buffer) { | 914 | if (!hub->buffer) { |
875 | ret = -ENOMEM; | 915 | ret = -ENOMEM; |
876 | goto fail; | 916 | goto fail; |
@@ -1111,8 +1151,6 @@ static int hub_configure(struct usb_hub *hub, | |||
1111 | 1151 | ||
1112 | usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, | 1152 | usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, |
1113 | hub, endpoint->bInterval); | 1153 | hub, endpoint->bInterval); |
1114 | hub->urb->transfer_dma = hub->buffer_dma; | ||
1115 | hub->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | ||
1116 | 1154 | ||
1117 | /* maybe cycle the hub leds */ | 1155 | /* maybe cycle the hub leds */ |
1118 | if (hub->has_indicators && blinkenlights) | 1156 | if (hub->has_indicators && blinkenlights) |
@@ -1144,7 +1182,10 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1144 | 1182 | ||
1145 | /* Take the hub off the event list and don't let it be added again */ | 1183 | /* Take the hub off the event list and don't let it be added again */ |
1146 | spin_lock_irq(&hub_event_lock); | 1184 | spin_lock_irq(&hub_event_lock); |
1147 | list_del_init(&hub->event_list); | 1185 | if (!list_empty(&hub->event_list)) { |
1186 | list_del_init(&hub->event_list); | ||
1187 | usb_autopm_put_interface_no_suspend(intf); | ||
1188 | } | ||
1148 | hub->disconnected = 1; | 1189 | hub->disconnected = 1; |
1149 | spin_unlock_irq(&hub_event_lock); | 1190 | spin_unlock_irq(&hub_event_lock); |
1150 | 1191 | ||
@@ -1162,8 +1203,7 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1162 | kfree(hub->port_owners); | 1203 | kfree(hub->port_owners); |
1163 | kfree(hub->descriptor); | 1204 | kfree(hub->descriptor); |
1164 | kfree(hub->status); | 1205 | kfree(hub->status); |
1165 | usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer, | 1206 | kfree(hub->buffer); |
1166 | hub->buffer_dma); | ||
1167 | 1207 | ||
1168 | kref_put(&hub->kref, hub_release); | 1208 | kref_put(&hub->kref, hub_release); |
1169 | } | 1209 | } |
@@ -1178,6 +1218,9 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1178 | desc = intf->cur_altsetting; | 1218 | desc = intf->cur_altsetting; |
1179 | hdev = interface_to_usbdev(intf); | 1219 | hdev = interface_to_usbdev(intf); |
1180 | 1220 | ||
1221 | /* Hubs have proper suspend/resume support */ | ||
1222 | usb_enable_autosuspend(hdev); | ||
1223 | |||
1181 | if (hdev->level == MAX_TOPO_LEVEL) { | 1224 | if (hdev->level == MAX_TOPO_LEVEL) { |
1182 | dev_err(&intf->dev, | 1225 | dev_err(&intf->dev, |
1183 | "Unsupported bus topology: hub nested too deep\n"); | 1226 | "Unsupported bus topology: hub nested too deep\n"); |
@@ -1356,10 +1399,8 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev) | |||
1356 | if (udev->children[i]) | 1399 | if (udev->children[i]) |
1357 | recursively_mark_NOTATTACHED(udev->children[i]); | 1400 | recursively_mark_NOTATTACHED(udev->children[i]); |
1358 | } | 1401 | } |
1359 | if (udev->state == USB_STATE_SUSPENDED) { | 1402 | if (udev->state == USB_STATE_SUSPENDED) |
1360 | udev->discon_suspended = 1; | ||
1361 | udev->active_duration -= jiffies; | 1403 | udev->active_duration -= jiffies; |
1362 | } | ||
1363 | udev->state = USB_STATE_NOTATTACHED; | 1404 | udev->state = USB_STATE_NOTATTACHED; |
1364 | } | 1405 | } |
1365 | 1406 | ||
@@ -1402,11 +1443,11 @@ void usb_set_device_state(struct usb_device *udev, | |||
1402 | || new_state == USB_STATE_SUSPENDED) | 1443 | || new_state == USB_STATE_SUSPENDED) |
1403 | ; /* No change to wakeup settings */ | 1444 | ; /* No change to wakeup settings */ |
1404 | else if (new_state == USB_STATE_CONFIGURED) | 1445 | else if (new_state == USB_STATE_CONFIGURED) |
1405 | device_init_wakeup(&udev->dev, | 1446 | device_set_wakeup_capable(&udev->dev, |
1406 | (udev->actconfig->desc.bmAttributes | 1447 | (udev->actconfig->desc.bmAttributes |
1407 | & USB_CONFIG_ATT_WAKEUP)); | 1448 | & USB_CONFIG_ATT_WAKEUP)); |
1408 | else | 1449 | else |
1409 | device_init_wakeup(&udev->dev, 0); | 1450 | device_set_wakeup_capable(&udev->dev, 0); |
1410 | } | 1451 | } |
1411 | if (udev->state == USB_STATE_SUSPENDED && | 1452 | if (udev->state == USB_STATE_SUSPENDED && |
1412 | new_state != USB_STATE_SUSPENDED) | 1453 | new_state != USB_STATE_SUSPENDED) |
@@ -1483,31 +1524,15 @@ static void update_address(struct usb_device *udev, int devnum) | |||
1483 | udev->devnum = devnum; | 1524 | udev->devnum = devnum; |
1484 | } | 1525 | } |
1485 | 1526 | ||
1486 | #ifdef CONFIG_USB_SUSPEND | 1527 | static void hub_free_dev(struct usb_device *udev) |
1487 | |||
1488 | static void usb_stop_pm(struct usb_device *udev) | ||
1489 | { | 1528 | { |
1490 | /* Synchronize with the ksuspend thread to prevent any more | 1529 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1491 | * autosuspend requests from being submitted, and decrement | ||
1492 | * the parent's count of unsuspended children. | ||
1493 | */ | ||
1494 | usb_pm_lock(udev); | ||
1495 | if (udev->parent && !udev->discon_suspended) | ||
1496 | usb_autosuspend_device(udev->parent); | ||
1497 | usb_pm_unlock(udev); | ||
1498 | 1530 | ||
1499 | /* Stop any autosuspend or autoresume requests already submitted */ | 1531 | /* Root hubs aren't real devices, so don't free HCD resources */ |
1500 | cancel_delayed_work_sync(&udev->autosuspend); | 1532 | if (hcd->driver->free_dev && udev->parent) |
1501 | cancel_work_sync(&udev->autoresume); | 1533 | hcd->driver->free_dev(hcd, udev); |
1502 | } | 1534 | } |
1503 | 1535 | ||
1504 | #else | ||
1505 | |||
1506 | static inline void usb_stop_pm(struct usb_device *udev) | ||
1507 | { } | ||
1508 | |||
1509 | #endif | ||
1510 | |||
1511 | /** | 1536 | /** |
1512 | * usb_disconnect - disconnect a device (usbcore-internal) | 1537 | * usb_disconnect - disconnect a device (usbcore-internal) |
1513 | * @pdev: pointer to device being disconnected | 1538 | * @pdev: pointer to device being disconnected |
@@ -1576,7 +1601,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
1576 | *pdev = NULL; | 1601 | *pdev = NULL; |
1577 | spin_unlock_irq(&device_state_lock); | 1602 | spin_unlock_irq(&device_state_lock); |
1578 | 1603 | ||
1579 | usb_stop_pm(udev); | 1604 | hub_free_dev(udev); |
1580 | 1605 | ||
1581 | put_device(&udev->dev); | 1606 | put_device(&udev->dev); |
1582 | } | 1607 | } |
@@ -1612,12 +1637,12 @@ static inline void announce_device(struct usb_device *udev) { } | |||
1612 | #endif | 1637 | #endif |
1613 | 1638 | ||
1614 | /** | 1639 | /** |
1615 | * usb_configure_device_otg - FIXME (usbcore-internal) | 1640 | * usb_enumerate_device_otg - FIXME (usbcore-internal) |
1616 | * @udev: newly addressed device (in ADDRESS state) | 1641 | * @udev: newly addressed device (in ADDRESS state) |
1617 | * | 1642 | * |
1618 | * Do configuration for On-The-Go devices | 1643 | * Finish enumeration for On-The-Go devices |
1619 | */ | 1644 | */ |
1620 | static int usb_configure_device_otg(struct usb_device *udev) | 1645 | static int usb_enumerate_device_otg(struct usb_device *udev) |
1621 | { | 1646 | { |
1622 | int err = 0; | 1647 | int err = 0; |
1623 | 1648 | ||
@@ -1630,7 +1655,7 @@ static int usb_configure_device_otg(struct usb_device *udev) | |||
1630 | if (!udev->bus->is_b_host | 1655 | if (!udev->bus->is_b_host |
1631 | && udev->config | 1656 | && udev->config |
1632 | && udev->parent == udev->bus->root_hub) { | 1657 | && udev->parent == udev->bus->root_hub) { |
1633 | struct usb_otg_descriptor *desc = 0; | 1658 | struct usb_otg_descriptor *desc = NULL; |
1634 | struct usb_bus *bus = udev->bus; | 1659 | struct usb_bus *bus = udev->bus; |
1635 | 1660 | ||
1636 | /* descriptor may appear anywhere in config */ | 1661 | /* descriptor may appear anywhere in config */ |
@@ -1688,7 +1713,7 @@ fail: | |||
1688 | 1713 | ||
1689 | 1714 | ||
1690 | /** | 1715 | /** |
1691 | * usb_configure_device - Detect and probe device intfs/otg (usbcore-internal) | 1716 | * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal) |
1692 | * @udev: newly addressed device (in ADDRESS state) | 1717 | * @udev: newly addressed device (in ADDRESS state) |
1693 | * | 1718 | * |
1694 | * This is only called by usb_new_device() and usb_authorize_device() | 1719 | * This is only called by usb_new_device() and usb_authorize_device() |
@@ -1699,7 +1724,7 @@ fail: | |||
1699 | * the string descriptors, as they will be errored out by the device | 1724 | * the string descriptors, as they will be errored out by the device |
1700 | * until it has been authorized. | 1725 | * until it has been authorized. |
1701 | */ | 1726 | */ |
1702 | static int usb_configure_device(struct usb_device *udev) | 1727 | static int usb_enumerate_device(struct usb_device *udev) |
1703 | { | 1728 | { |
1704 | int err; | 1729 | int err; |
1705 | 1730 | ||
@@ -1723,7 +1748,7 @@ static int usb_configure_device(struct usb_device *udev) | |||
1723 | udev->descriptor.iManufacturer); | 1748 | udev->descriptor.iManufacturer); |
1724 | udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); | 1749 | udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); |
1725 | } | 1750 | } |
1726 | err = usb_configure_device_otg(udev); | 1751 | err = usb_enumerate_device_otg(udev); |
1727 | fail: | 1752 | fail: |
1728 | return err; | 1753 | return err; |
1729 | } | 1754 | } |
@@ -1733,8 +1758,8 @@ fail: | |||
1733 | * usb_new_device - perform initial device setup (usbcore-internal) | 1758 | * usb_new_device - perform initial device setup (usbcore-internal) |
1734 | * @udev: newly addressed device (in ADDRESS state) | 1759 | * @udev: newly addressed device (in ADDRESS state) |
1735 | * | 1760 | * |
1736 | * This is called with devices which have been enumerated, but not yet | 1761 | * This is called with devices which have been detected but not fully |
1737 | * configured. The device descriptor is available, but not descriptors | 1762 | * enumerated. The device descriptor is available, but not descriptors |
1738 | * for any device configuration. The caller must have locked either | 1763 | * for any device configuration. The caller must have locked either |
1739 | * the parent hub (if udev is a normal device) or else the | 1764 | * the parent hub (if udev is a normal device) or else the |
1740 | * usb_bus_list_lock (if udev is a root hub). The parent's pointer to | 1765 | * usb_bus_list_lock (if udev is a root hub). The parent's pointer to |
@@ -1753,12 +1778,21 @@ int usb_new_device(struct usb_device *udev) | |||
1753 | { | 1778 | { |
1754 | int err; | 1779 | int err; |
1755 | 1780 | ||
1756 | /* Increment the parent's count of unsuspended children */ | 1781 | if (udev->parent) { |
1757 | if (udev->parent) | 1782 | /* Initialize non-root-hub device wakeup to disabled; |
1758 | usb_autoresume_device(udev->parent); | 1783 | * device (un)configuration controls wakeup capable |
1784 | * sysfs power/wakeup controls wakeup enabled/disabled | ||
1785 | */ | ||
1786 | device_init_wakeup(&udev->dev, 0); | ||
1787 | device_set_wakeup_enable(&udev->dev, 1); | ||
1788 | } | ||
1789 | |||
1790 | /* Tell the runtime-PM framework the device is active */ | ||
1791 | pm_runtime_set_active(&udev->dev); | ||
1792 | pm_runtime_enable(&udev->dev); | ||
1759 | 1793 | ||
1760 | usb_detect_quirks(udev); /* Determine quirks */ | 1794 | usb_detect_quirks(udev); |
1761 | err = usb_configure_device(udev); /* detect & probe dev/intfs */ | 1795 | err = usb_enumerate_device(udev); /* Read descriptors */ |
1762 | if (err < 0) | 1796 | if (err < 0) |
1763 | goto fail; | 1797 | goto fail; |
1764 | dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", | 1798 | dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", |
@@ -1771,6 +1805,7 @@ int usb_new_device(struct usb_device *udev) | |||
1771 | /* Tell the world! */ | 1805 | /* Tell the world! */ |
1772 | announce_device(udev); | 1806 | announce_device(udev); |
1773 | 1807 | ||
1808 | device_enable_async_suspend(&udev->dev); | ||
1774 | /* Register the device. The device driver is responsible | 1809 | /* Register the device. The device driver is responsible |
1775 | * for configuring the device and invoking the add-device | 1810 | * for configuring the device and invoking the add-device |
1776 | * notifier chain (used by usbfs and possibly others). | 1811 | * notifier chain (used by usbfs and possibly others). |
@@ -1786,7 +1821,8 @@ int usb_new_device(struct usb_device *udev) | |||
1786 | 1821 | ||
1787 | fail: | 1822 | fail: |
1788 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1823 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1789 | usb_stop_pm(udev); | 1824 | pm_runtime_disable(&udev->dev); |
1825 | pm_runtime_set_suspended(&udev->dev); | ||
1790 | return err; | 1826 | return err; |
1791 | } | 1827 | } |
1792 | 1828 | ||
@@ -1803,21 +1839,23 @@ fail: | |||
1803 | */ | 1839 | */ |
1804 | int usb_deauthorize_device(struct usb_device *usb_dev) | 1840 | int usb_deauthorize_device(struct usb_device *usb_dev) |
1805 | { | 1841 | { |
1806 | unsigned cnt; | ||
1807 | usb_lock_device(usb_dev); | 1842 | usb_lock_device(usb_dev); |
1808 | if (usb_dev->authorized == 0) | 1843 | if (usb_dev->authorized == 0) |
1809 | goto out_unauthorized; | 1844 | goto out_unauthorized; |
1845 | |||
1810 | usb_dev->authorized = 0; | 1846 | usb_dev->authorized = 0; |
1811 | usb_set_configuration(usb_dev, -1); | 1847 | usb_set_configuration(usb_dev, -1); |
1848 | |||
1849 | kfree(usb_dev->product); | ||
1812 | usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 1850 | usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
1851 | kfree(usb_dev->manufacturer); | ||
1813 | usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 1852 | usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
1853 | kfree(usb_dev->serial); | ||
1814 | usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); | 1854 | usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); |
1815 | kfree(usb_dev->config); | 1855 | |
1816 | usb_dev->config = NULL; | 1856 | usb_destroy_configuration(usb_dev); |
1817 | for (cnt = 0; cnt < usb_dev->descriptor.bNumConfigurations; cnt++) | ||
1818 | kfree(usb_dev->rawdescriptors[cnt]); | ||
1819 | usb_dev->descriptor.bNumConfigurations = 0; | 1857 | usb_dev->descriptor.bNumConfigurations = 0; |
1820 | kfree(usb_dev->rawdescriptors); | 1858 | |
1821 | out_unauthorized: | 1859 | out_unauthorized: |
1822 | usb_unlock_device(usb_dev); | 1860 | usb_unlock_device(usb_dev); |
1823 | return 0; | 1861 | return 0; |
@@ -1827,15 +1865,11 @@ out_unauthorized: | |||
1827 | int usb_authorize_device(struct usb_device *usb_dev) | 1865 | int usb_authorize_device(struct usb_device *usb_dev) |
1828 | { | 1866 | { |
1829 | int result = 0, c; | 1867 | int result = 0, c; |
1868 | |||
1830 | usb_lock_device(usb_dev); | 1869 | usb_lock_device(usb_dev); |
1831 | if (usb_dev->authorized == 1) | 1870 | if (usb_dev->authorized == 1) |
1832 | goto out_authorized; | 1871 | goto out_authorized; |
1833 | kfree(usb_dev->product); | 1872 | |
1834 | usb_dev->product = NULL; | ||
1835 | kfree(usb_dev->manufacturer); | ||
1836 | usb_dev->manufacturer = NULL; | ||
1837 | kfree(usb_dev->serial); | ||
1838 | usb_dev->serial = NULL; | ||
1839 | result = usb_autoresume_device(usb_dev); | 1873 | result = usb_autoresume_device(usb_dev); |
1840 | if (result < 0) { | 1874 | if (result < 0) { |
1841 | dev_err(&usb_dev->dev, | 1875 | dev_err(&usb_dev->dev, |
@@ -1848,10 +1882,18 @@ int usb_authorize_device(struct usb_device *usb_dev) | |||
1848 | "authorization: %d\n", result); | 1882 | "authorization: %d\n", result); |
1849 | goto error_device_descriptor; | 1883 | goto error_device_descriptor; |
1850 | } | 1884 | } |
1885 | |||
1886 | kfree(usb_dev->product); | ||
1887 | usb_dev->product = NULL; | ||
1888 | kfree(usb_dev->manufacturer); | ||
1889 | usb_dev->manufacturer = NULL; | ||
1890 | kfree(usb_dev->serial); | ||
1891 | usb_dev->serial = NULL; | ||
1892 | |||
1851 | usb_dev->authorized = 1; | 1893 | usb_dev->authorized = 1; |
1852 | result = usb_configure_device(usb_dev); | 1894 | result = usb_enumerate_device(usb_dev); |
1853 | if (result < 0) | 1895 | if (result < 0) |
1854 | goto error_configure; | 1896 | goto error_enumerate; |
1855 | /* Choose and set the configuration. This registers the interfaces | 1897 | /* Choose and set the configuration. This registers the interfaces |
1856 | * with the driver core and lets interface drivers bind to them. | 1898 | * with the driver core and lets interface drivers bind to them. |
1857 | */ | 1899 | */ |
@@ -1866,8 +1908,10 @@ int usb_authorize_device(struct usb_device *usb_dev) | |||
1866 | } | 1908 | } |
1867 | } | 1909 | } |
1868 | dev_info(&usb_dev->dev, "authorized to connect\n"); | 1910 | dev_info(&usb_dev->dev, "authorized to connect\n"); |
1869 | error_configure: | 1911 | |
1912 | error_enumerate: | ||
1870 | error_device_descriptor: | 1913 | error_device_descriptor: |
1914 | usb_autosuspend_device(usb_dev); | ||
1871 | error_autoresume: | 1915 | error_autoresume: |
1872 | out_authorized: | 1916 | out_authorized: |
1873 | usb_unlock_device(usb_dev); // complements locktree | 1917 | usb_unlock_device(usb_dev); // complements locktree |
@@ -1927,7 +1971,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
1927 | if (!(portstatus & USB_PORT_STAT_RESET) && | 1971 | if (!(portstatus & USB_PORT_STAT_RESET) && |
1928 | (portstatus & USB_PORT_STAT_ENABLE)) { | 1972 | (portstatus & USB_PORT_STAT_ENABLE)) { |
1929 | if (hub_is_wusb(hub)) | 1973 | if (hub_is_wusb(hub)) |
1930 | udev->speed = USB_SPEED_VARIABLE; | 1974 | udev->speed = USB_SPEED_WIRELESS; |
1931 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 1975 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
1932 | udev->speed = USB_SPEED_HIGH; | 1976 | udev->speed = USB_SPEED_HIGH; |
1933 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 1977 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
@@ -1953,7 +1997,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
1953 | struct usb_device *udev, unsigned int delay) | 1997 | struct usb_device *udev, unsigned int delay) |
1954 | { | 1998 | { |
1955 | int i, status; | 1999 | int i, status; |
2000 | struct usb_hcd *hcd; | ||
1956 | 2001 | ||
2002 | hcd = bus_to_hcd(udev->bus); | ||
1957 | /* Block EHCI CF initialization during the port reset. | 2003 | /* Block EHCI CF initialization during the port reset. |
1958 | * Some companion controllers don't like it when they mix. | 2004 | * Some companion controllers don't like it when they mix. |
1959 | */ | 2005 | */ |
@@ -1981,6 +2027,14 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
1981 | /* TRSTRCY = 10 ms; plus some extra */ | 2027 | /* TRSTRCY = 10 ms; plus some extra */ |
1982 | msleep(10 + 40); | 2028 | msleep(10 + 40); |
1983 | update_address(udev, 0); | 2029 | update_address(udev, 0); |
2030 | if (hcd->driver->reset_device) { | ||
2031 | status = hcd->driver->reset_device(hcd, udev); | ||
2032 | if (status < 0) { | ||
2033 | dev_err(&udev->dev, "Cannot reset " | ||
2034 | "HCD device state\n"); | ||
2035 | break; | ||
2036 | } | ||
2037 | } | ||
1984 | /* FALL THROUGH */ | 2038 | /* FALL THROUGH */ |
1985 | case -ENOTCONN: | 2039 | case -ENOTCONN: |
1986 | case -ENODEV: | 2040 | case -ENODEV: |
@@ -2123,9 +2177,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2123 | USB_DEVICE_REMOTE_WAKEUP, 0, | 2177 | USB_DEVICE_REMOTE_WAKEUP, 0, |
2124 | NULL, 0, | 2178 | NULL, 0, |
2125 | USB_CTRL_SET_TIMEOUT); | 2179 | USB_CTRL_SET_TIMEOUT); |
2126 | if (status) | 2180 | if (status) { |
2127 | dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", | 2181 | dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", |
2128 | status); | 2182 | status); |
2183 | /* bail if autosuspend is requested */ | ||
2184 | if (msg.event & PM_EVENT_AUTO) | ||
2185 | return status; | ||
2186 | } | ||
2129 | } | 2187 | } |
2130 | 2188 | ||
2131 | /* see 7.1.7.6 */ | 2189 | /* see 7.1.7.6 */ |
@@ -2134,7 +2192,8 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2134 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", | 2192 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", |
2135 | port1, status); | 2193 | port1, status); |
2136 | /* paranoia: "should not happen" */ | 2194 | /* paranoia: "should not happen" */ |
2137 | (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 2195 | if (udev->do_remote_wakeup) |
2196 | (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
2138 | USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, | 2197 | USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, |
2139 | USB_DEVICE_REMOTE_WAKEUP, 0, | 2198 | USB_DEVICE_REMOTE_WAKEUP, 0, |
2140 | NULL, 0, | 2199 | NULL, 0, |
@@ -2321,14 +2380,17 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
2321 | } | 2380 | } |
2322 | 2381 | ||
2323 | /* caller has locked udev */ | 2382 | /* caller has locked udev */ |
2324 | static int remote_wakeup(struct usb_device *udev) | 2383 | int usb_remote_wakeup(struct usb_device *udev) |
2325 | { | 2384 | { |
2326 | int status = 0; | 2385 | int status = 0; |
2327 | 2386 | ||
2328 | if (udev->state == USB_STATE_SUSPENDED) { | 2387 | if (udev->state == USB_STATE_SUSPENDED) { |
2329 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); | 2388 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
2330 | usb_mark_last_busy(udev); | 2389 | status = usb_autoresume_device(udev); |
2331 | status = usb_external_resume_device(udev, PMSG_REMOTE_RESUME); | 2390 | if (status == 0) { |
2391 | /* Let the drivers do their thing, then... */ | ||
2392 | usb_autosuspend_device(udev); | ||
2393 | } | ||
2332 | } | 2394 | } |
2333 | return status; | 2395 | return status; |
2334 | } | 2396 | } |
@@ -2365,11 +2427,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
2365 | return status; | 2427 | return status; |
2366 | } | 2428 | } |
2367 | 2429 | ||
2368 | static inline int remote_wakeup(struct usb_device *udev) | ||
2369 | { | ||
2370 | return 0; | ||
2371 | } | ||
2372 | |||
2373 | #endif | 2430 | #endif |
2374 | 2431 | ||
2375 | static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | 2432 | static int hub_suspend(struct usb_interface *intf, pm_message_t msg) |
@@ -2436,11 +2493,6 @@ EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); | |||
2436 | 2493 | ||
2437 | #else /* CONFIG_PM */ | 2494 | #else /* CONFIG_PM */ |
2438 | 2495 | ||
2439 | static inline int remote_wakeup(struct usb_device *udev) | ||
2440 | { | ||
2441 | return 0; | ||
2442 | } | ||
2443 | |||
2444 | #define hub_suspend NULL | 2496 | #define hub_suspend NULL |
2445 | #define hub_resume NULL | 2497 | #define hub_resume NULL |
2446 | #define hub_reset_resume NULL | 2498 | #define hub_reset_resume NULL |
@@ -2585,14 +2637,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2585 | 2637 | ||
2586 | mutex_lock(&usb_address0_mutex); | 2638 | mutex_lock(&usb_address0_mutex); |
2587 | 2639 | ||
2588 | if ((hcd->driver->flags & HCD_USB3) && udev->config) { | 2640 | if (!udev->config && oldspeed == USB_SPEED_SUPER) { |
2589 | /* FIXME this will need special handling by the xHCI driver. */ | ||
2590 | dev_dbg(&udev->dev, | ||
2591 | "xHCI reset of configured device " | ||
2592 | "not supported yet.\n"); | ||
2593 | retval = -EINVAL; | ||
2594 | goto fail; | ||
2595 | } else if (!udev->config && oldspeed == USB_SPEED_SUPER) { | ||
2596 | /* Don't reset USB 3.0 devices during an initial setup */ | 2641 | /* Don't reset USB 3.0 devices during an initial setup */ |
2597 | usb_set_device_state(udev, USB_STATE_DEFAULT); | 2642 | usb_set_device_state(udev, USB_STATE_DEFAULT); |
2598 | } else { | 2643 | } else { |
@@ -2618,7 +2663,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2618 | */ | 2663 | */ |
2619 | switch (udev->speed) { | 2664 | switch (udev->speed) { |
2620 | case USB_SPEED_SUPER: | 2665 | case USB_SPEED_SUPER: |
2621 | case USB_SPEED_VARIABLE: /* fixed at 512 */ | 2666 | case USB_SPEED_WIRELESS: /* fixed at 512 */ |
2622 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); | 2667 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); |
2623 | break; | 2668 | break; |
2624 | case USB_SPEED_HIGH: /* fixed at 64 */ | 2669 | case USB_SPEED_HIGH: /* fixed at 64 */ |
@@ -2646,7 +2691,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2646 | case USB_SPEED_SUPER: | 2691 | case USB_SPEED_SUPER: |
2647 | speed = "super"; | 2692 | speed = "super"; |
2648 | break; | 2693 | break; |
2649 | case USB_SPEED_VARIABLE: | 2694 | case USB_SPEED_WIRELESS: |
2650 | speed = "variable"; | 2695 | speed = "variable"; |
2651 | type = "Wireless "; | 2696 | type = "Wireless "; |
2652 | break; | 2697 | break; |
@@ -2946,7 +2991,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2946 | /* For a suspended device, treat this as a | 2991 | /* For a suspended device, treat this as a |
2947 | * remote wakeup event. | 2992 | * remote wakeup event. |
2948 | */ | 2993 | */ |
2949 | status = remote_wakeup(udev); | 2994 | status = usb_remote_wakeup(udev); |
2950 | #endif | 2995 | #endif |
2951 | 2996 | ||
2952 | } else { | 2997 | } else { |
@@ -2965,6 +3010,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2965 | usb_disconnect(&hdev->children[port1-1]); | 3010 | usb_disconnect(&hdev->children[port1-1]); |
2966 | clear_bit(port1, hub->change_bits); | 3011 | clear_bit(port1, hub->change_bits); |
2967 | 3012 | ||
3013 | /* We can forget about a "removed" device when there's a physical | ||
3014 | * disconnect or the connect status changes. | ||
3015 | */ | ||
3016 | if (!(portstatus & USB_PORT_STAT_CONNECTION) || | ||
3017 | (portchange & USB_PORT_STAT_C_CONNECTION)) | ||
3018 | clear_bit(port1, hub->removed_bits); | ||
3019 | |||
2968 | if (portchange & (USB_PORT_STAT_C_CONNECTION | | 3020 | if (portchange & (USB_PORT_STAT_C_CONNECTION | |
2969 | USB_PORT_STAT_C_ENABLE)) { | 3021 | USB_PORT_STAT_C_ENABLE)) { |
2970 | status = hub_port_debounce(hub, port1); | 3022 | status = hub_port_debounce(hub, port1); |
@@ -2978,8 +3030,11 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2978 | } | 3030 | } |
2979 | } | 3031 | } |
2980 | 3032 | ||
2981 | /* Return now if debouncing failed or nothing is connected */ | 3033 | /* Return now if debouncing failed or nothing is connected or |
2982 | if (!(portstatus & USB_PORT_STAT_CONNECTION)) { | 3034 | * the device was "removed". |
3035 | */ | ||
3036 | if (!(portstatus & USB_PORT_STAT_CONNECTION) || | ||
3037 | test_bit(port1, hub->removed_bits)) { | ||
2983 | 3038 | ||
2984 | /* maybe switch power back on (e.g. root hub was reset) */ | 3039 | /* maybe switch power back on (e.g. root hub was reset) */ |
2985 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 | 3040 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 |
@@ -3122,6 +3177,7 @@ loop_disable: | |||
3122 | loop: | 3177 | loop: |
3123 | usb_ep0_reinit(udev); | 3178 | usb_ep0_reinit(udev); |
3124 | release_address(udev); | 3179 | release_address(udev); |
3180 | hub_free_dev(udev); | ||
3125 | usb_put_dev(udev); | 3181 | usb_put_dev(udev); |
3126 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) | 3182 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) |
3127 | break; | 3183 | break; |
@@ -3189,7 +3245,7 @@ static void hub_events(void) | |||
3189 | * disconnected while waiting for the lock to succeed. */ | 3245 | * disconnected while waiting for the lock to succeed. */ |
3190 | usb_lock_device(hdev); | 3246 | usb_lock_device(hdev); |
3191 | if (unlikely(hub->disconnected)) | 3247 | if (unlikely(hub->disconnected)) |
3192 | goto loop; | 3248 | goto loop_disconnected; |
3193 | 3249 | ||
3194 | /* If the hub has died, clean up after it */ | 3250 | /* If the hub has died, clean up after it */ |
3195 | if (hdev->state == USB_STATE_NOTATTACHED) { | 3251 | if (hdev->state == USB_STATE_NOTATTACHED) { |
@@ -3278,8 +3334,11 @@ static void hub_events(void) | |||
3278 | USB_PORT_FEAT_C_SUSPEND); | 3334 | USB_PORT_FEAT_C_SUSPEND); |
3279 | udev = hdev->children[i-1]; | 3335 | udev = hdev->children[i-1]; |
3280 | if (udev) { | 3336 | if (udev) { |
3337 | /* TRSMRCY = 10 msec */ | ||
3338 | msleep(10); | ||
3339 | |||
3281 | usb_lock_device(udev); | 3340 | usb_lock_device(udev); |
3282 | ret = remote_wakeup(hdev-> | 3341 | ret = usb_remote_wakeup(hdev-> |
3283 | children[i-1]); | 3342 | children[i-1]); |
3284 | usb_unlock_device(udev); | 3343 | usb_unlock_device(udev); |
3285 | if (ret < 0) | 3344 | if (ret < 0) |
@@ -3338,11 +3397,15 @@ static void hub_events(void) | |||
3338 | } | 3397 | } |
3339 | } | 3398 | } |
3340 | 3399 | ||
3341 | loop_autopm: | 3400 | loop_autopm: |
3342 | /* Allow autosuspend if we're not going to run again */ | 3401 | /* Balance the usb_autopm_get_interface() above */ |
3343 | if (list_empty(&hub->event_list)) | 3402 | usb_autopm_put_interface_no_suspend(intf); |
3344 | usb_autopm_enable(intf); | 3403 | loop: |
3345 | loop: | 3404 | /* Balance the usb_autopm_get_interface_no_resume() in |
3405 | * kick_khubd() and allow autosuspend. | ||
3406 | */ | ||
3407 | usb_autopm_put_interface(intf); | ||
3408 | loop_disconnected: | ||
3346 | usb_unlock_device(hdev); | 3409 | usb_unlock_device(hdev); |
3347 | kref_put(&hub->kref, hub_release); | 3410 | kref_put(&hub->kref, hub_release); |
3348 | 3411 | ||
@@ -3369,7 +3432,7 @@ static int hub_thread(void *__unused) | |||
3369 | return 0; | 3432 | return 0; |
3370 | } | 3433 | } |
3371 | 3434 | ||
3372 | static struct usb_device_id hub_id_table [] = { | 3435 | static const struct usb_device_id hub_id_table[] = { |
3373 | { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS, | 3436 | { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS, |
3374 | .bDeviceClass = USB_CLASS_HUB}, | 3437 | .bDeviceClass = USB_CLASS_HUB}, |
3375 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, | 3438 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, |
@@ -3534,6 +3597,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3534 | { | 3597 | { |
3535 | struct usb_device *parent_hdev = udev->parent; | 3598 | struct usb_device *parent_hdev = udev->parent; |
3536 | struct usb_hub *parent_hub; | 3599 | struct usb_hub *parent_hub; |
3600 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
3537 | struct usb_device_descriptor descriptor = udev->descriptor; | 3601 | struct usb_device_descriptor descriptor = udev->descriptor; |
3538 | int i, ret = 0; | 3602 | int i, ret = 0; |
3539 | int port1 = udev->portnum; | 3603 | int port1 = udev->portnum; |
@@ -3577,6 +3641,16 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3577 | /* Restore the device's previous configuration */ | 3641 | /* Restore the device's previous configuration */ |
3578 | if (!udev->actconfig) | 3642 | if (!udev->actconfig) |
3579 | goto done; | 3643 | goto done; |
3644 | |||
3645 | mutex_lock(&hcd->bandwidth_mutex); | ||
3646 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); | ||
3647 | if (ret < 0) { | ||
3648 | dev_warn(&udev->dev, | ||
3649 | "Busted HC? Not enough HCD resources for " | ||
3650 | "old configuration.\n"); | ||
3651 | mutex_unlock(&hcd->bandwidth_mutex); | ||
3652 | goto re_enumerate; | ||
3653 | } | ||
3580 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 3654 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
3581 | USB_REQ_SET_CONFIGURATION, 0, | 3655 | USB_REQ_SET_CONFIGURATION, 0, |
3582 | udev->actconfig->desc.bConfigurationValue, 0, | 3656 | udev->actconfig->desc.bConfigurationValue, 0, |
@@ -3585,8 +3659,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3585 | dev_err(&udev->dev, | 3659 | dev_err(&udev->dev, |
3586 | "can't restore configuration #%d (error=%d)\n", | 3660 | "can't restore configuration #%d (error=%d)\n", |
3587 | udev->actconfig->desc.bConfigurationValue, ret); | 3661 | udev->actconfig->desc.bConfigurationValue, ret); |
3662 | mutex_unlock(&hcd->bandwidth_mutex); | ||
3588 | goto re_enumerate; | 3663 | goto re_enumerate; |
3589 | } | 3664 | } |
3665 | mutex_unlock(&hcd->bandwidth_mutex); | ||
3590 | usb_set_device_state(udev, USB_STATE_CONFIGURED); | 3666 | usb_set_device_state(udev, USB_STATE_CONFIGURED); |
3591 | 3667 | ||
3592 | /* Put interfaces back into the same altsettings as before. | 3668 | /* Put interfaces back into the same altsettings as before. |
@@ -3596,7 +3672,8 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3596 | * endpoint state. | 3672 | * endpoint state. |
3597 | */ | 3673 | */ |
3598 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | 3674 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { |
3599 | struct usb_interface *intf = udev->actconfig->interface[i]; | 3675 | struct usb_host_config *config = udev->actconfig; |
3676 | struct usb_interface *intf = config->interface[i]; | ||
3600 | struct usb_interface_descriptor *desc; | 3677 | struct usb_interface_descriptor *desc; |
3601 | 3678 | ||
3602 | desc = &intf->cur_altsetting->desc; | 3679 | desc = &intf->cur_altsetting->desc; |
@@ -3605,8 +3682,14 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3605 | usb_enable_interface(udev, intf, true); | 3682 | usb_enable_interface(udev, intf, true); |
3606 | ret = 0; | 3683 | ret = 0; |
3607 | } else { | 3684 | } else { |
3685 | /* Let the bandwidth allocation function know that this | ||
3686 | * device has been reset, and it will have to use | ||
3687 | * alternate setting 0 as the current alternate setting. | ||
3688 | */ | ||
3689 | intf->resetting_device = 1; | ||
3608 | ret = usb_set_interface(udev, desc->bInterfaceNumber, | 3690 | ret = usb_set_interface(udev, desc->bInterfaceNumber, |
3609 | desc->bAlternateSetting); | 3691 | desc->bAlternateSetting); |
3692 | intf->resetting_device = 0; | ||
3610 | } | 3693 | } |
3611 | if (ret < 0) { | 3694 | if (ret < 0) { |
3612 | dev_err(&udev->dev, "failed to restore interface %d " | 3695 | dev_err(&udev->dev, "failed to restore interface %d " |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 97b40ce133f0..111a01a747fc 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -380,6 +380,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
380 | mutex_lock(&inode->i_mutex); | 380 | mutex_lock(&inode->i_mutex); |
381 | dentry_unhash(dentry); | 381 | dentry_unhash(dentry); |
382 | if (usbfs_empty(dentry)) { | 382 | if (usbfs_empty(dentry)) { |
383 | dont_mount(dentry); | ||
383 | drop_nlink(dentry->d_inode); | 384 | drop_nlink(dentry->d_inode); |
384 | drop_nlink(dentry->d_inode); | 385 | drop_nlink(dentry->d_inode); |
385 | dput(dentry); | 386 | dput(dentry); |
@@ -515,13 +516,13 @@ static int fs_create_by_name (const char *name, mode_t mode, | |||
515 | *dentry = NULL; | 516 | *dentry = NULL; |
516 | mutex_lock(&parent->d_inode->i_mutex); | 517 | mutex_lock(&parent->d_inode->i_mutex); |
517 | *dentry = lookup_one_len(name, parent, strlen(name)); | 518 | *dentry = lookup_one_len(name, parent, strlen(name)); |
518 | if (!IS_ERR(dentry)) { | 519 | if (!IS_ERR(*dentry)) { |
519 | if ((mode & S_IFMT) == S_IFDIR) | 520 | if ((mode & S_IFMT) == S_IFDIR) |
520 | error = usbfs_mkdir (parent->d_inode, *dentry, mode); | 521 | error = usbfs_mkdir (parent->d_inode, *dentry, mode); |
521 | else | 522 | else |
522 | error = usbfs_create (parent->d_inode, *dentry, mode); | 523 | error = usbfs_create (parent->d_inode, *dentry, mode); |
523 | } else | 524 | } else |
524 | error = PTR_ERR(dentry); | 525 | error = PTR_ERR(*dentry); |
525 | mutex_unlock(&parent->d_inode->i_mutex); | 526 | mutex_unlock(&parent->d_inode->i_mutex); |
526 | 527 | ||
527 | return error; | 528 | return error; |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index da718e84d58d..cd220277c6c3 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -393,13 +393,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
393 | if (io->entries <= 0) | 393 | if (io->entries <= 0) |
394 | return io->entries; | 394 | return io->entries; |
395 | 395 | ||
396 | /* If we're running on an xHCI host controller, queue the whole scatter | 396 | if (dev->bus->sg_tablesize > 0) { |
397 | * gather list with one call to urb_enqueue(). This is only for bulk, | ||
398 | * as that endpoint type does not care how the data gets broken up | ||
399 | * across frames. | ||
400 | */ | ||
401 | if (usb_pipebulk(pipe) && | ||
402 | bus_to_hcd(dev->bus)->driver->flags & HCD_USB3) { | ||
403 | io->urbs = kmalloc(sizeof *io->urbs, mem_flags); | 397 | io->urbs = kmalloc(sizeof *io->urbs, mem_flags); |
404 | use_sg = true; | 398 | use_sg = true; |
405 | } else { | 399 | } else { |
@@ -409,7 +403,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
409 | if (!io->urbs) | 403 | if (!io->urbs) |
410 | goto nomem; | 404 | goto nomem; |
411 | 405 | ||
412 | urb_flags = URB_NO_INTERRUPT; | 406 | urb_flags = 0; |
413 | if (dma) | 407 | if (dma) |
414 | urb_flags |= URB_NO_TRANSFER_DMA_MAP; | 408 | urb_flags |= URB_NO_TRANSFER_DMA_MAP; |
415 | if (usb_pipein(pipe)) | 409 | if (usb_pipein(pipe)) |
@@ -441,6 +435,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
441 | io->urbs[0]->num_sgs = io->entries; | 435 | io->urbs[0]->num_sgs = io->entries; |
442 | io->entries = 1; | 436 | io->entries = 1; |
443 | } else { | 437 | } else { |
438 | urb_flags |= URB_NO_INTERRUPT; | ||
444 | for_each_sg(sg, sg, io->entries, i) { | 439 | for_each_sg(sg, sg, io->entries, i) { |
445 | unsigned len; | 440 | unsigned len; |
446 | 441 | ||
@@ -911,11 +906,11 @@ char *usb_cache_string(struct usb_device *udev, int index) | |||
911 | if (index <= 0) | 906 | if (index <= 0) |
912 | return NULL; | 907 | return NULL; |
913 | 908 | ||
914 | buf = kmalloc(MAX_USB_STRING_SIZE, GFP_KERNEL); | 909 | buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO); |
915 | if (buf) { | 910 | if (buf) { |
916 | len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE); | 911 | len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE); |
917 | if (len > 0) { | 912 | if (len > 0) { |
918 | smallbuf = kmalloc(++len, GFP_KERNEL); | 913 | smallbuf = kmalloc(++len, GFP_NOIO); |
919 | if (!smallbuf) | 914 | if (!smallbuf) |
920 | return buf; | 915 | return buf; |
921 | memcpy(smallbuf, buf, len); | 916 | memcpy(smallbuf, buf, len); |
@@ -1303,6 +1298,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1303 | { | 1298 | { |
1304 | struct usb_interface *iface; | 1299 | struct usb_interface *iface; |
1305 | struct usb_host_interface *alt; | 1300 | struct usb_host_interface *alt; |
1301 | struct usb_hcd *hcd = bus_to_hcd(dev->bus); | ||
1306 | int ret; | 1302 | int ret; |
1307 | int manual = 0; | 1303 | int manual = 0; |
1308 | unsigned int epaddr; | 1304 | unsigned int epaddr; |
@@ -1320,11 +1316,23 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1320 | 1316 | ||
1321 | alt = usb_altnum_to_altsetting(iface, alternate); | 1317 | alt = usb_altnum_to_altsetting(iface, alternate); |
1322 | if (!alt) { | 1318 | if (!alt) { |
1323 | dev_warn(&dev->dev, "selecting invalid altsetting %d", | 1319 | dev_warn(&dev->dev, "selecting invalid altsetting %d\n", |
1324 | alternate); | 1320 | alternate); |
1325 | return -EINVAL; | 1321 | return -EINVAL; |
1326 | } | 1322 | } |
1327 | 1323 | ||
1324 | /* Make sure we have enough bandwidth for this alternate interface. | ||
1325 | * Remove the current alt setting and add the new alt setting. | ||
1326 | */ | ||
1327 | mutex_lock(&hcd->bandwidth_mutex); | ||
1328 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); | ||
1329 | if (ret < 0) { | ||
1330 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", | ||
1331 | alternate); | ||
1332 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1333 | return ret; | ||
1334 | } | ||
1335 | |||
1328 | if (dev->quirks & USB_QUIRK_NO_SET_INTF) | 1336 | if (dev->quirks & USB_QUIRK_NO_SET_INTF) |
1329 | ret = -EPIPE; | 1337 | ret = -EPIPE; |
1330 | else | 1338 | else |
@@ -1340,8 +1348,13 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1340 | "manual set_interface for iface %d, alt %d\n", | 1348 | "manual set_interface for iface %d, alt %d\n", |
1341 | interface, alternate); | 1349 | interface, alternate); |
1342 | manual = 1; | 1350 | manual = 1; |
1343 | } else if (ret < 0) | 1351 | } else if (ret < 0) { |
1352 | /* Re-instate the old alt setting */ | ||
1353 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); | ||
1354 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1344 | return ret; | 1355 | return ret; |
1356 | } | ||
1357 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1345 | 1358 | ||
1346 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here | 1359 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here |
1347 | * when they implement async or easily-killable versions of this or | 1360 | * when they implement async or easily-killable versions of this or |
@@ -1423,6 +1436,7 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1423 | { | 1436 | { |
1424 | int i, retval; | 1437 | int i, retval; |
1425 | struct usb_host_config *config; | 1438 | struct usb_host_config *config; |
1439 | struct usb_hcd *hcd = bus_to_hcd(dev->bus); | ||
1426 | 1440 | ||
1427 | if (dev->state == USB_STATE_SUSPENDED) | 1441 | if (dev->state == USB_STATE_SUSPENDED) |
1428 | return -EHOSTUNREACH; | 1442 | return -EHOSTUNREACH; |
@@ -1438,12 +1452,46 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1438 | } | 1452 | } |
1439 | 1453 | ||
1440 | config = dev->actconfig; | 1454 | config = dev->actconfig; |
1455 | retval = 0; | ||
1456 | mutex_lock(&hcd->bandwidth_mutex); | ||
1457 | /* Make sure we have enough bandwidth for each alternate setting 0 */ | ||
1458 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | ||
1459 | struct usb_interface *intf = config->interface[i]; | ||
1460 | struct usb_host_interface *alt; | ||
1461 | |||
1462 | alt = usb_altnum_to_altsetting(intf, 0); | ||
1463 | if (!alt) | ||
1464 | alt = &intf->altsetting[0]; | ||
1465 | if (alt != intf->cur_altsetting) | ||
1466 | retval = usb_hcd_alloc_bandwidth(dev, NULL, | ||
1467 | intf->cur_altsetting, alt); | ||
1468 | if (retval < 0) | ||
1469 | break; | ||
1470 | } | ||
1471 | /* If not, reinstate the old alternate settings */ | ||
1472 | if (retval < 0) { | ||
1473 | reset_old_alts: | ||
1474 | for (i--; i >= 0; i--) { | ||
1475 | struct usb_interface *intf = config->interface[i]; | ||
1476 | struct usb_host_interface *alt; | ||
1477 | |||
1478 | alt = usb_altnum_to_altsetting(intf, 0); | ||
1479 | if (!alt) | ||
1480 | alt = &intf->altsetting[0]; | ||
1481 | if (alt != intf->cur_altsetting) | ||
1482 | usb_hcd_alloc_bandwidth(dev, NULL, | ||
1483 | alt, intf->cur_altsetting); | ||
1484 | } | ||
1485 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1486 | return retval; | ||
1487 | } | ||
1441 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1488 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
1442 | USB_REQ_SET_CONFIGURATION, 0, | 1489 | USB_REQ_SET_CONFIGURATION, 0, |
1443 | config->desc.bConfigurationValue, 0, | 1490 | config->desc.bConfigurationValue, 0, |
1444 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1491 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
1445 | if (retval < 0) | 1492 | if (retval < 0) |
1446 | return retval; | 1493 | goto reset_old_alts; |
1494 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1447 | 1495 | ||
1448 | /* re-init hc/hcd interface/endpoint state */ | 1496 | /* re-init hc/hcd interface/endpoint state */ |
1449 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1497 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
@@ -1585,7 +1633,7 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, | |||
1585 | * | 1633 | * |
1586 | * See usb_queue_reset_device() for more details | 1634 | * See usb_queue_reset_device() for more details |
1587 | */ | 1635 | */ |
1588 | void __usb_queue_reset_device(struct work_struct *ws) | 1636 | static void __usb_queue_reset_device(struct work_struct *ws) |
1589 | { | 1637 | { |
1590 | int rc; | 1638 | int rc; |
1591 | struct usb_interface *iface = | 1639 | struct usb_interface *iface = |
@@ -1652,6 +1700,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1652 | int i, ret; | 1700 | int i, ret; |
1653 | struct usb_host_config *cp = NULL; | 1701 | struct usb_host_config *cp = NULL; |
1654 | struct usb_interface **new_interfaces = NULL; | 1702 | struct usb_interface **new_interfaces = NULL; |
1703 | struct usb_hcd *hcd = bus_to_hcd(dev->bus); | ||
1655 | int n, nintf; | 1704 | int n, nintf; |
1656 | 1705 | ||
1657 | if (dev->authorized == 0 || configuration == -1) | 1706 | if (dev->authorized == 0 || configuration == -1) |
@@ -1682,7 +1731,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1682 | if (cp) { | 1731 | if (cp) { |
1683 | nintf = cp->desc.bNumInterfaces; | 1732 | nintf = cp->desc.bNumInterfaces; |
1684 | new_interfaces = kmalloc(nintf * sizeof(*new_interfaces), | 1733 | new_interfaces = kmalloc(nintf * sizeof(*new_interfaces), |
1685 | GFP_KERNEL); | 1734 | GFP_NOIO); |
1686 | if (!new_interfaces) { | 1735 | if (!new_interfaces) { |
1687 | dev_err(&dev->dev, "Out of memory\n"); | 1736 | dev_err(&dev->dev, "Out of memory\n"); |
1688 | return -ENOMEM; | 1737 | return -ENOMEM; |
@@ -1691,7 +1740,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1691 | for (; n < nintf; ++n) { | 1740 | for (; n < nintf; ++n) { |
1692 | new_interfaces[n] = kzalloc( | 1741 | new_interfaces[n] = kzalloc( |
1693 | sizeof(struct usb_interface), | 1742 | sizeof(struct usb_interface), |
1694 | GFP_KERNEL); | 1743 | GFP_NOIO); |
1695 | if (!new_interfaces[n]) { | 1744 | if (!new_interfaces[n]) { |
1696 | dev_err(&dev->dev, "Out of memory\n"); | 1745 | dev_err(&dev->dev, "Out of memory\n"); |
1697 | ret = -ENOMEM; | 1746 | ret = -ENOMEM; |
@@ -1721,12 +1770,11 @@ free_interfaces: | |||
1721 | * host controller will not allow submissions to dropped endpoints. If | 1770 | * host controller will not allow submissions to dropped endpoints. If |
1722 | * this call fails, the device state is unchanged. | 1771 | * this call fails, the device state is unchanged. |
1723 | */ | 1772 | */ |
1724 | if (cp) | 1773 | mutex_lock(&hcd->bandwidth_mutex); |
1725 | ret = usb_hcd_check_bandwidth(dev, cp, NULL); | 1774 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); |
1726 | else | ||
1727 | ret = usb_hcd_check_bandwidth(dev, NULL, NULL); | ||
1728 | if (ret < 0) { | 1775 | if (ret < 0) { |
1729 | usb_autosuspend_device(dev); | 1776 | usb_autosuspend_device(dev); |
1777 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1730 | goto free_interfaces; | 1778 | goto free_interfaces; |
1731 | } | 1779 | } |
1732 | 1780 | ||
@@ -1752,10 +1800,12 @@ free_interfaces: | |||
1752 | dev->actconfig = cp; | 1800 | dev->actconfig = cp; |
1753 | if (!cp) { | 1801 | if (!cp) { |
1754 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1802 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1755 | usb_hcd_check_bandwidth(dev, NULL, NULL); | 1803 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); |
1756 | usb_autosuspend_device(dev); | 1804 | usb_autosuspend_device(dev); |
1805 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1757 | goto free_interfaces; | 1806 | goto free_interfaces; |
1758 | } | 1807 | } |
1808 | mutex_unlock(&hcd->bandwidth_mutex); | ||
1759 | usb_set_device_state(dev, USB_STATE_CONFIGURED); | 1809 | usb_set_device_state(dev, USB_STATE_CONFIGURED); |
1760 | 1810 | ||
1761 | /* Initialize the new interface structures and the | 1811 | /* Initialize the new interface structures and the |
@@ -1793,7 +1843,6 @@ free_interfaces: | |||
1793 | intf->dev.dma_mask = dev->dev.dma_mask; | 1843 | intf->dev.dma_mask = dev->dev.dma_mask; |
1794 | INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); | 1844 | INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); |
1795 | device_initialize(&intf->dev); | 1845 | device_initialize(&intf->dev); |
1796 | mark_quiesced(intf); | ||
1797 | dev_set_name(&intf->dev, "%d-%s:%d.%d", | 1846 | dev_set_name(&intf->dev, "%d-%s:%d.%d", |
1798 | dev->bus->busnum, dev->devpath, | 1847 | dev->bus->busnum, dev->devpath, |
1799 | configuration, alt->desc.bInterfaceNumber); | 1848 | configuration, alt->desc.bInterfaceNumber); |
@@ -1817,6 +1866,7 @@ free_interfaces: | |||
1817 | "adding %s (config #%d, interface %d)\n", | 1866 | "adding %s (config #%d, interface %d)\n", |
1818 | dev_name(&intf->dev), configuration, | 1867 | dev_name(&intf->dev), configuration, |
1819 | intf->cur_altsetting->desc.bInterfaceNumber); | 1868 | intf->cur_altsetting->desc.bInterfaceNumber); |
1869 | device_enable_async_suspend(&intf->dev); | ||
1820 | ret = device_add(&intf->dev); | 1870 | ret = device_add(&intf->dev); |
1821 | if (ret != 0) { | 1871 | if (ret != 0) { |
1822 | dev_err(&dev->dev, "device_add(%s) --> %d\n", | 1872 | dev_err(&dev->dev, "device_add(%s) --> %d\n", |
@@ -1890,7 +1940,7 @@ static void cancel_async_set_config(struct usb_device *udev) | |||
1890 | * routine gets around the normal restrictions by using a work thread to | 1940 | * routine gets around the normal restrictions by using a work thread to |
1891 | * submit the change-config request. | 1941 | * submit the change-config request. |
1892 | * | 1942 | * |
1893 | * Returns 0 if the request was succesfully queued, error code otherwise. | 1943 | * Returns 0 if the request was successfully queued, error code otherwise. |
1894 | * The caller has no way to know whether the queued request will eventually | 1944 | * The caller has no way to know whether the queued request will eventually |
1895 | * succeed. | 1945 | * succeed. |
1896 | */ | 1946 | */ |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index ab93918d9207..f073c5cb4e7b 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -103,10 +103,19 @@ void usb_detect_quirks(struct usb_device *udev) | |||
103 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", | 103 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", |
104 | udev->quirks); | 104 | udev->quirks); |
105 | 105 | ||
106 | /* By default, disable autosuspend for all non-hubs */ | ||
107 | #ifdef CONFIG_USB_SUSPEND | 106 | #ifdef CONFIG_USB_SUSPEND |
108 | if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) | 107 | |
109 | udev->autosuspend_disabled = 1; | 108 | /* By default, disable autosuspend for all devices. The hub driver |
109 | * will enable it for hubs. | ||
110 | */ | ||
111 | usb_disable_autosuspend(udev); | ||
112 | |||
113 | /* Autosuspend can also be disabled if the initial autosuspend_delay | ||
114 | * is negative. | ||
115 | */ | ||
116 | if (udev->autosuspend_delay < 0) | ||
117 | usb_autoresume_device(udev); | ||
118 | |||
110 | #endif | 119 | #endif |
111 | 120 | ||
112 | /* For the present, all devices default to USB-PERSIST enabled */ | 121 | /* For the present, all devices default to USB-PERSIST enabled */ |
@@ -120,6 +129,7 @@ void usb_detect_quirks(struct usb_device *udev) | |||
120 | * for all devices. It will affect things like hub resets | 129 | * for all devices. It will affect things like hub resets |
121 | * and EMF-related port disables. | 130 | * and EMF-related port disables. |
122 | */ | 131 | */ |
123 | udev->persist_enabled = 1; | 132 | if (!(udev->quirks & USB_QUIRK_RESET_MORPHS)) |
133 | udev->persist_enabled = 1; | ||
124 | #endif /* CONFIG_PM */ | 134 | #endif /* CONFIG_PM */ |
125 | } | 135 | } |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 7ec3041ae79e..43c002e3a9aa 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -82,9 +82,13 @@ static ssize_t show_##name(struct device *dev, \ | |||
82 | struct device_attribute *attr, char *buf) \ | 82 | struct device_attribute *attr, char *buf) \ |
83 | { \ | 83 | { \ |
84 | struct usb_device *udev; \ | 84 | struct usb_device *udev; \ |
85 | int retval; \ | ||
85 | \ | 86 | \ |
86 | udev = to_usb_device(dev); \ | 87 | udev = to_usb_device(dev); \ |
87 | return sprintf(buf, "%s\n", udev->name); \ | 88 | usb_lock_device(udev); \ |
89 | retval = sprintf(buf, "%s\n", udev->name); \ | ||
90 | usb_unlock_device(udev); \ | ||
91 | return retval; \ | ||
88 | } \ | 92 | } \ |
89 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); | 93 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); |
90 | 94 | ||
@@ -111,6 +115,12 @@ show_speed(struct device *dev, struct device_attribute *attr, char *buf) | |||
111 | case USB_SPEED_HIGH: | 115 | case USB_SPEED_HIGH: |
112 | speed = "480"; | 116 | speed = "480"; |
113 | break; | 117 | break; |
118 | case USB_SPEED_WIRELESS: | ||
119 | speed = "480"; | ||
120 | break; | ||
121 | case USB_SPEED_SUPER: | ||
122 | speed = "5000"; | ||
123 | break; | ||
114 | default: | 124 | default: |
115 | speed = "unknown"; | 125 | speed = "unknown"; |
116 | } | 126 | } |
@@ -139,6 +149,16 @@ show_devnum(struct device *dev, struct device_attribute *attr, char *buf) | |||
139 | static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL); | 149 | static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL); |
140 | 150 | ||
141 | static ssize_t | 151 | static ssize_t |
152 | show_devpath(struct device *dev, struct device_attribute *attr, char *buf) | ||
153 | { | ||
154 | struct usb_device *udev; | ||
155 | |||
156 | udev = to_usb_device(dev); | ||
157 | return sprintf(buf, "%s\n", udev->devpath); | ||
158 | } | ||
159 | static DEVICE_ATTR(devpath, S_IRUGO, show_devpath, NULL); | ||
160 | |||
161 | static ssize_t | ||
142 | show_version(struct device *dev, struct device_attribute *attr, char *buf) | 162 | show_version(struct device *dev, struct device_attribute *attr, char *buf) |
143 | { | 163 | { |
144 | struct usb_device *udev; | 164 | struct usb_device *udev; |
@@ -171,6 +191,36 @@ show_quirks(struct device *dev, struct device_attribute *attr, char *buf) | |||
171 | static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); | 191 | static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); |
172 | 192 | ||
173 | static ssize_t | 193 | static ssize_t |
194 | show_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, char *buf) | ||
195 | { | ||
196 | struct usb_device *udev; | ||
197 | |||
198 | udev = to_usb_device(dev); | ||
199 | return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET_MORPHS)); | ||
200 | } | ||
201 | |||
202 | static ssize_t | ||
203 | set_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, | ||
204 | const char *buf, size_t count) | ||
205 | { | ||
206 | struct usb_device *udev = to_usb_device(dev); | ||
207 | int config; | ||
208 | |||
209 | if (sscanf(buf, "%d", &config) != 1 || config < 0 || config > 1) | ||
210 | return -EINVAL; | ||
211 | usb_lock_device(udev); | ||
212 | if (config) | ||
213 | udev->quirks |= USB_QUIRK_RESET_MORPHS; | ||
214 | else | ||
215 | udev->quirks &= ~USB_QUIRK_RESET_MORPHS; | ||
216 | usb_unlock_device(udev); | ||
217 | return count; | ||
218 | } | ||
219 | |||
220 | static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR, | ||
221 | show_avoid_reset_quirk, set_avoid_reset_quirk); | ||
222 | |||
223 | static ssize_t | ||
174 | show_urbnum(struct device *dev, struct device_attribute *attr, char *buf) | 224 | show_urbnum(struct device *dev, struct device_attribute *attr, char *buf) |
175 | { | 225 | { |
176 | struct usb_device *udev; | 226 | struct usb_device *udev; |
@@ -206,9 +256,10 @@ set_persist(struct device *dev, struct device_attribute *attr, | |||
206 | 256 | ||
207 | if (sscanf(buf, "%d", &value) != 1) | 257 | if (sscanf(buf, "%d", &value) != 1) |
208 | return -EINVAL; | 258 | return -EINVAL; |
209 | usb_pm_lock(udev); | 259 | |
260 | usb_lock_device(udev); | ||
210 | udev->persist_enabled = !!value; | 261 | udev->persist_enabled = !!value; |
211 | usb_pm_unlock(udev); | 262 | usb_unlock_device(udev); |
212 | return count; | 263 | return count; |
213 | } | 264 | } |
214 | 265 | ||
@@ -295,20 +346,34 @@ set_autosuspend(struct device *dev, struct device_attribute *attr, | |||
295 | const char *buf, size_t count) | 346 | const char *buf, size_t count) |
296 | { | 347 | { |
297 | struct usb_device *udev = to_usb_device(dev); | 348 | struct usb_device *udev = to_usb_device(dev); |
298 | int value; | 349 | int value, old_delay; |
350 | int rc; | ||
299 | 351 | ||
300 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || | 352 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || |
301 | value <= - INT_MAX/HZ) | 353 | value <= - INT_MAX/HZ) |
302 | return -EINVAL; | 354 | return -EINVAL; |
303 | value *= HZ; | 355 | value *= HZ; |
304 | 356 | ||
357 | usb_lock_device(udev); | ||
358 | old_delay = udev->autosuspend_delay; | ||
305 | udev->autosuspend_delay = value; | 359 | udev->autosuspend_delay = value; |
306 | if (value >= 0) | 360 | |
307 | usb_try_autosuspend_device(udev); | 361 | if (old_delay < 0) { /* Autosuspend wasn't allowed */ |
308 | else { | 362 | if (value >= 0) |
309 | if (usb_autoresume_device(udev) == 0) | ||
310 | usb_autosuspend_device(udev); | 363 | usb_autosuspend_device(udev); |
364 | } else { /* Autosuspend was allowed */ | ||
365 | if (value < 0) { | ||
366 | rc = usb_autoresume_device(udev); | ||
367 | if (rc < 0) { | ||
368 | count = rc; | ||
369 | udev->autosuspend_delay = old_delay; | ||
370 | } | ||
371 | } else { | ||
372 | usb_try_autosuspend_device(udev); | ||
373 | } | ||
311 | } | 374 | } |
375 | |||
376 | usb_unlock_device(udev); | ||
312 | return count; | 377 | return count; |
313 | } | 378 | } |
314 | 379 | ||
@@ -317,7 +382,6 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR, | |||
317 | 382 | ||
318 | static const char on_string[] = "on"; | 383 | static const char on_string[] = "on"; |
319 | static const char auto_string[] = "auto"; | 384 | static const char auto_string[] = "auto"; |
320 | static const char suspend_string[] = "suspend"; | ||
321 | 385 | ||
322 | static ssize_t | 386 | static ssize_t |
323 | show_level(struct device *dev, struct device_attribute *attr, char *buf) | 387 | show_level(struct device *dev, struct device_attribute *attr, char *buf) |
@@ -325,13 +389,8 @@ show_level(struct device *dev, struct device_attribute *attr, char *buf) | |||
325 | struct usb_device *udev = to_usb_device(dev); | 389 | struct usb_device *udev = to_usb_device(dev); |
326 | const char *p = auto_string; | 390 | const char *p = auto_string; |
327 | 391 | ||
328 | if (udev->state == USB_STATE_SUSPENDED) { | 392 | if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled) |
329 | if (udev->autoresume_disabled) | 393 | p = on_string; |
330 | p = suspend_string; | ||
331 | } else { | ||
332 | if (udev->autosuspend_disabled) | ||
333 | p = on_string; | ||
334 | } | ||
335 | return sprintf(buf, "%s\n", p); | 394 | return sprintf(buf, "%s\n", p); |
336 | } | 395 | } |
337 | 396 | ||
@@ -342,45 +401,25 @@ set_level(struct device *dev, struct device_attribute *attr, | |||
342 | struct usb_device *udev = to_usb_device(dev); | 401 | struct usb_device *udev = to_usb_device(dev); |
343 | int len = count; | 402 | int len = count; |
344 | char *cp; | 403 | char *cp; |
345 | int rc = 0; | 404 | int rc; |
346 | int old_autosuspend_disabled, old_autoresume_disabled; | ||
347 | 405 | ||
348 | cp = memchr(buf, '\n', count); | 406 | cp = memchr(buf, '\n', count); |
349 | if (cp) | 407 | if (cp) |
350 | len = cp - buf; | 408 | len = cp - buf; |
351 | 409 | ||
352 | usb_lock_device(udev); | 410 | usb_lock_device(udev); |
353 | old_autosuspend_disabled = udev->autosuspend_disabled; | ||
354 | old_autoresume_disabled = udev->autoresume_disabled; | ||
355 | 411 | ||
356 | /* Setting the flags without calling usb_pm_lock is a subject to | ||
357 | * races, but who cares... | ||
358 | */ | ||
359 | if (len == sizeof on_string - 1 && | 412 | if (len == sizeof on_string - 1 && |
360 | strncmp(buf, on_string, len) == 0) { | 413 | strncmp(buf, on_string, len) == 0) |
361 | udev->autosuspend_disabled = 1; | 414 | rc = usb_disable_autosuspend(udev); |
362 | udev->autoresume_disabled = 0; | 415 | |
363 | rc = usb_external_resume_device(udev, PMSG_USER_RESUME); | 416 | else if (len == sizeof auto_string - 1 && |
364 | 417 | strncmp(buf, auto_string, len) == 0) | |
365 | } else if (len == sizeof auto_string - 1 && | 418 | rc = usb_enable_autosuspend(udev); |
366 | strncmp(buf, auto_string, len) == 0) { | 419 | |
367 | udev->autosuspend_disabled = 0; | 420 | else |
368 | udev->autoresume_disabled = 0; | ||
369 | rc = usb_external_resume_device(udev, PMSG_USER_RESUME); | ||
370 | |||
371 | } else if (len == sizeof suspend_string - 1 && | ||
372 | strncmp(buf, suspend_string, len) == 0) { | ||
373 | udev->autosuspend_disabled = 0; | ||
374 | udev->autoresume_disabled = 1; | ||
375 | rc = usb_external_suspend_device(udev, PMSG_USER_SUSPEND); | ||
376 | |||
377 | } else | ||
378 | rc = -EINVAL; | 421 | rc = -EINVAL; |
379 | 422 | ||
380 | if (rc) { | ||
381 | udev->autosuspend_disabled = old_autosuspend_disabled; | ||
382 | udev->autoresume_disabled = old_autoresume_disabled; | ||
383 | } | ||
384 | usb_unlock_device(udev); | 423 | usb_unlock_device(udev); |
385 | return (rc < 0 ? rc : count); | 424 | return (rc < 0 ? rc : count); |
386 | } | 425 | } |
@@ -508,6 +547,28 @@ static ssize_t usb_dev_authorized_store(struct device *dev, | |||
508 | static DEVICE_ATTR(authorized, 0644, | 547 | static DEVICE_ATTR(authorized, 0644, |
509 | usb_dev_authorized_show, usb_dev_authorized_store); | 548 | usb_dev_authorized_show, usb_dev_authorized_store); |
510 | 549 | ||
550 | /* "Safely remove a device" */ | ||
551 | static ssize_t usb_remove_store(struct device *dev, | ||
552 | struct device_attribute *attr, | ||
553 | const char *buf, size_t count) | ||
554 | { | ||
555 | struct usb_device *udev = to_usb_device(dev); | ||
556 | int rc = 0; | ||
557 | |||
558 | usb_lock_device(udev); | ||
559 | if (udev->state != USB_STATE_NOTATTACHED) { | ||
560 | |||
561 | /* To avoid races, first unconfigure and then remove */ | ||
562 | usb_set_configuration(udev, -1); | ||
563 | rc = usb_remove_device(udev); | ||
564 | } | ||
565 | if (rc == 0) | ||
566 | rc = count; | ||
567 | usb_unlock_device(udev); | ||
568 | return rc; | ||
569 | } | ||
570 | static DEVICE_ATTR(remove, 0200, NULL, usb_remove_store); | ||
571 | |||
511 | 572 | ||
512 | static struct attribute *dev_attrs[] = { | 573 | static struct attribute *dev_attrs[] = { |
513 | /* current configuration's attributes */ | 574 | /* current configuration's attributes */ |
@@ -516,8 +577,8 @@ static struct attribute *dev_attrs[] = { | |||
516 | &dev_attr_bConfigurationValue.attr, | 577 | &dev_attr_bConfigurationValue.attr, |
517 | &dev_attr_bmAttributes.attr, | 578 | &dev_attr_bmAttributes.attr, |
518 | &dev_attr_bMaxPower.attr, | 579 | &dev_attr_bMaxPower.attr, |
519 | &dev_attr_urbnum.attr, | ||
520 | /* device attributes */ | 580 | /* device attributes */ |
581 | &dev_attr_urbnum.attr, | ||
521 | &dev_attr_idVendor.attr, | 582 | &dev_attr_idVendor.attr, |
522 | &dev_attr_idProduct.attr, | 583 | &dev_attr_idProduct.attr, |
523 | &dev_attr_bcdDevice.attr, | 584 | &dev_attr_bcdDevice.attr, |
@@ -529,10 +590,13 @@ static struct attribute *dev_attrs[] = { | |||
529 | &dev_attr_speed.attr, | 590 | &dev_attr_speed.attr, |
530 | &dev_attr_busnum.attr, | 591 | &dev_attr_busnum.attr, |
531 | &dev_attr_devnum.attr, | 592 | &dev_attr_devnum.attr, |
593 | &dev_attr_devpath.attr, | ||
532 | &dev_attr_version.attr, | 594 | &dev_attr_version.attr, |
533 | &dev_attr_maxchild.attr, | 595 | &dev_attr_maxchild.attr, |
534 | &dev_attr_quirks.attr, | 596 | &dev_attr_quirks.attr, |
597 | &dev_attr_avoid_reset_quirk.attr, | ||
535 | &dev_attr_authorized.attr, | 598 | &dev_attr_authorized.attr, |
599 | &dev_attr_remove.attr, | ||
536 | NULL, | 600 | NULL, |
537 | }; | 601 | }; |
538 | static struct attribute_group dev_attr_grp = { | 602 | static struct attribute_group dev_attr_grp = { |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 0885d4abdc62..45a32dadb406 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -387,6 +387,13 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
387 | { | 387 | { |
388 | unsigned int orig_flags = urb->transfer_flags; | 388 | unsigned int orig_flags = urb->transfer_flags; |
389 | unsigned int allowed; | 389 | unsigned int allowed; |
390 | static int pipetypes[4] = { | ||
391 | PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT | ||
392 | }; | ||
393 | |||
394 | /* Check that the pipe's type matches the endpoint's type */ | ||
395 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) | ||
396 | return -EPIPE; /* The most suitable error code :-) */ | ||
390 | 397 | ||
391 | /* enforce simple/standard policy */ | 398 | /* enforce simple/standard policy */ |
392 | allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP | | 399 | allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP | |
@@ -429,8 +436,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
429 | case USB_ENDPOINT_XFER_ISOC: | 436 | case USB_ENDPOINT_XFER_ISOC: |
430 | case USB_ENDPOINT_XFER_INT: | 437 | case USB_ENDPOINT_XFER_INT: |
431 | /* too small? */ | 438 | /* too small? */ |
432 | if (urb->interval <= 0) | 439 | switch (dev->speed) { |
433 | return -EINVAL; | 440 | case USB_SPEED_WIRELESS: |
441 | if (urb->interval < 6) | ||
442 | return -EINVAL; | ||
443 | break; | ||
444 | default: | ||
445 | if (urb->interval <= 0) | ||
446 | return -EINVAL; | ||
447 | break; | ||
448 | } | ||
434 | /* too big? */ | 449 | /* too big? */ |
435 | switch (dev->speed) { | 450 | switch (dev->speed) { |
436 | case USB_SPEED_SUPER: /* units are 125us */ | 451 | case USB_SPEED_SUPER: /* units are 125us */ |
@@ -438,6 +453,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
438 | if (urb->interval > (1 << 15)) | 453 | if (urb->interval > (1 << 15)) |
439 | return -EINVAL; | 454 | return -EINVAL; |
440 | max = 1 << 15; | 455 | max = 1 << 15; |
456 | break; | ||
457 | case USB_SPEED_WIRELESS: | ||
458 | if (urb->interval > 16) | ||
459 | return -EINVAL; | ||
460 | break; | ||
441 | case USB_SPEED_HIGH: /* units are microframes */ | 461 | case USB_SPEED_HIGH: /* units are microframes */ |
442 | /* NOTE usb handles 2^15 */ | 462 | /* NOTE usb handles 2^15 */ |
443 | if (urb->interval > (1024 * 8)) | 463 | if (urb->interval > (1024 * 8)) |
@@ -461,8 +481,10 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
461 | default: | 481 | default: |
462 | return -EINVAL; | 482 | return -EINVAL; |
463 | } | 483 | } |
464 | /* Round down to a power of 2, no more than max */ | 484 | if (dev->speed != USB_SPEED_WIRELESS) { |
465 | urb->interval = min(max, 1 << ilog2(urb->interval)); | 485 | /* Round down to a power of 2, no more than max */ |
486 | urb->interval = min(max, 1 << ilog2(urb->interval)); | ||
487 | } | ||
466 | } | 488 | } |
467 | 489 | ||
468 | return usb_hcd_submit_urb(urb, mem_flags); | 490 | return usb_hcd_submit_urb(urb, mem_flags); |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index b1b85abb9a2d..0561430f2ede 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -49,9 +49,6 @@ const char *usbcore_name = "usbcore"; | |||
49 | 49 | ||
50 | static int nousb; /* Disable USB when built into kernel image */ | 50 | static int nousb; /* Disable USB when built into kernel image */ |
51 | 51 | ||
52 | /* Workqueue for autosuspend and for remote wakeup of root hubs */ | ||
53 | struct workqueue_struct *ksuspend_usb_wq; | ||
54 | |||
55 | #ifdef CONFIG_USB_SUSPEND | 52 | #ifdef CONFIG_USB_SUSPEND |
56 | static int usb_autosuspend_delay = 2; /* Default delay value, | 53 | static int usb_autosuspend_delay = 2; /* Default delay value, |
57 | * in seconds */ | 54 | * in seconds */ |
@@ -64,6 +61,43 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay"); | |||
64 | 61 | ||
65 | 62 | ||
66 | /** | 63 | /** |
64 | * usb_find_alt_setting() - Given a configuration, find the alternate setting | ||
65 | * for the given interface. | ||
66 | * @config: the configuration to search (not necessarily the current config). | ||
67 | * @iface_num: interface number to search in | ||
68 | * @alt_num: alternate interface setting number to search for. | ||
69 | * | ||
70 | * Search the configuration's interface cache for the given alt setting. | ||
71 | */ | ||
72 | struct usb_host_interface *usb_find_alt_setting( | ||
73 | struct usb_host_config *config, | ||
74 | unsigned int iface_num, | ||
75 | unsigned int alt_num) | ||
76 | { | ||
77 | struct usb_interface_cache *intf_cache = NULL; | ||
78 | int i; | ||
79 | |||
80 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | ||
81 | if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber | ||
82 | == iface_num) { | ||
83 | intf_cache = config->intf_cache[i]; | ||
84 | break; | ||
85 | } | ||
86 | } | ||
87 | if (!intf_cache) | ||
88 | return NULL; | ||
89 | for (i = 0; i < intf_cache->num_altsetting; i++) | ||
90 | if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num) | ||
91 | return &intf_cache->altsetting[i]; | ||
92 | |||
93 | printk(KERN_DEBUG "Did not find alt setting %u for intf %u, " | ||
94 | "config %u\n", alt_num, iface_num, | ||
95 | config->desc.bConfigurationValue); | ||
96 | return NULL; | ||
97 | } | ||
98 | EXPORT_SYMBOL_GPL(usb_find_alt_setting); | ||
99 | |||
100 | /** | ||
67 | * usb_ifnum_to_if - get the interface object with a given interface number | 101 | * usb_ifnum_to_if - get the interface object with a given interface number |
68 | * @dev: the device whose current configuration is considered | 102 | * @dev: the device whose current configuration is considered |
69 | * @ifnum: the desired interface | 103 | * @ifnum: the desired interface |
@@ -132,7 +166,7 @@ EXPORT_SYMBOL_GPL(usb_altnum_to_altsetting); | |||
132 | 166 | ||
133 | struct find_interface_arg { | 167 | struct find_interface_arg { |
134 | int minor; | 168 | int minor; |
135 | struct usb_interface *interface; | 169 | struct device_driver *drv; |
136 | }; | 170 | }; |
137 | 171 | ||
138 | static int __find_interface(struct device *dev, void *data) | 172 | static int __find_interface(struct device *dev, void *data) |
@@ -143,12 +177,10 @@ static int __find_interface(struct device *dev, void *data) | |||
143 | if (!is_usb_interface(dev)) | 177 | if (!is_usb_interface(dev)) |
144 | return 0; | 178 | return 0; |
145 | 179 | ||
180 | if (dev->driver != arg->drv) | ||
181 | return 0; | ||
146 | intf = to_usb_interface(dev); | 182 | intf = to_usb_interface(dev); |
147 | if (intf->minor != -1 && intf->minor == arg->minor) { | 183 | return intf->minor == arg->minor; |
148 | arg->interface = intf; | ||
149 | return 1; | ||
150 | } | ||
151 | return 0; | ||
152 | } | 184 | } |
153 | 185 | ||
154 | /** | 186 | /** |
@@ -156,21 +188,24 @@ static int __find_interface(struct device *dev, void *data) | |||
156 | * @drv: the driver whose current configuration is considered | 188 | * @drv: the driver whose current configuration is considered |
157 | * @minor: the minor number of the desired device | 189 | * @minor: the minor number of the desired device |
158 | * | 190 | * |
159 | * This walks the driver device list and returns a pointer to the interface | 191 | * This walks the bus device list and returns a pointer to the interface |
160 | * with the matching minor. Note, this only works for devices that share the | 192 | * with the matching minor and driver. Note, this only works for devices |
161 | * USB major number. | 193 | * that share the USB major number. |
162 | */ | 194 | */ |
163 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) | 195 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) |
164 | { | 196 | { |
165 | struct find_interface_arg argb; | 197 | struct find_interface_arg argb; |
166 | int retval; | 198 | struct device *dev; |
167 | 199 | ||
168 | argb.minor = minor; | 200 | argb.minor = minor; |
169 | argb.interface = NULL; | 201 | argb.drv = &drv->drvwrap.driver; |
170 | /* eat the error, it will be in argb.interface */ | 202 | |
171 | retval = driver_for_each_device(&drv->drvwrap.driver, NULL, &argb, | 203 | dev = bus_find_device(&usb_bus_type, NULL, &argb, __find_interface); |
172 | __find_interface); | 204 | |
173 | return argb.interface; | 205 | /* Drop reference count from bus_find_device */ |
206 | put_device(dev); | ||
207 | |||
208 | return dev ? to_usb_interface(dev) : NULL; | ||
174 | } | 209 | } |
175 | EXPORT_SYMBOL_GPL(usb_find_interface); | 210 | EXPORT_SYMBOL_GPL(usb_find_interface); |
176 | 211 | ||
@@ -190,9 +225,6 @@ static void usb_release_dev(struct device *dev) | |||
190 | hcd = bus_to_hcd(udev->bus); | 225 | hcd = bus_to_hcd(udev->bus); |
191 | 226 | ||
192 | usb_destroy_configuration(udev); | 227 | usb_destroy_configuration(udev); |
193 | /* Root hubs aren't real devices, so don't free HCD resources */ | ||
194 | if (hcd->driver->free_dev && udev->parent) | ||
195 | hcd->driver->free_dev(hcd, udev); | ||
196 | usb_put_hcd(hcd); | 228 | usb_put_hcd(hcd); |
197 | kfree(udev->product); | 229 | kfree(udev->product); |
198 | kfree(udev->manufacturer); | 230 | kfree(udev->manufacturer); |
@@ -226,23 +258,6 @@ static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
226 | 258 | ||
227 | #ifdef CONFIG_PM | 259 | #ifdef CONFIG_PM |
228 | 260 | ||
229 | static int ksuspend_usb_init(void) | ||
230 | { | ||
231 | /* This workqueue is supposed to be both freezable and | ||
232 | * singlethreaded. Its job doesn't justify running on more | ||
233 | * than one CPU. | ||
234 | */ | ||
235 | ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd"); | ||
236 | if (!ksuspend_usb_wq) | ||
237 | return -ENOMEM; | ||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static void ksuspend_usb_cleanup(void) | ||
242 | { | ||
243 | destroy_workqueue(ksuspend_usb_wq); | ||
244 | } | ||
245 | |||
246 | /* USB device Power-Management thunks. | 261 | /* USB device Power-Management thunks. |
247 | * There's no need to distinguish here between quiescing a USB device | 262 | * There's no need to distinguish here between quiescing a USB device |
248 | * and powering it down; the generic_suspend() routine takes care of | 263 | * and powering it down; the generic_suspend() routine takes care of |
@@ -258,7 +273,7 @@ static int usb_dev_prepare(struct device *dev) | |||
258 | static void usb_dev_complete(struct device *dev) | 273 | static void usb_dev_complete(struct device *dev) |
259 | { | 274 | { |
260 | /* Currently used only for rebinding interfaces */ | 275 | /* Currently used only for rebinding interfaces */ |
261 | usb_resume(dev, PMSG_RESUME); /* Message event is meaningless */ | 276 | usb_resume(dev, PMSG_ON); /* FIXME: change to PMSG_COMPLETE */ |
262 | } | 277 | } |
263 | 278 | ||
264 | static int usb_dev_suspend(struct device *dev) | 279 | static int usb_dev_suspend(struct device *dev) |
@@ -291,7 +306,7 @@ static int usb_dev_restore(struct device *dev) | |||
291 | return usb_resume(dev, PMSG_RESTORE); | 306 | return usb_resume(dev, PMSG_RESTORE); |
292 | } | 307 | } |
293 | 308 | ||
294 | static struct dev_pm_ops usb_device_pm_ops = { | 309 | static const struct dev_pm_ops usb_device_pm_ops = { |
295 | .prepare = usb_dev_prepare, | 310 | .prepare = usb_dev_prepare, |
296 | .complete = usb_dev_complete, | 311 | .complete = usb_dev_complete, |
297 | .suspend = usb_dev_suspend, | 312 | .suspend = usb_dev_suspend, |
@@ -304,9 +319,7 @@ static struct dev_pm_ops usb_device_pm_ops = { | |||
304 | 319 | ||
305 | #else | 320 | #else |
306 | 321 | ||
307 | #define ksuspend_usb_init() 0 | 322 | #define usb_device_pm_ops (*(struct dev_pm_ops *) NULL) |
308 | #define ksuspend_usb_cleanup() do {} while (0) | ||
309 | #define usb_device_pm_ops (*(struct dev_pm_ops *)0) | ||
310 | 323 | ||
311 | #endif /* CONFIG_PM */ | 324 | #endif /* CONFIG_PM */ |
312 | 325 | ||
@@ -434,9 +447,6 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
434 | INIT_LIST_HEAD(&dev->filelist); | 447 | INIT_LIST_HEAD(&dev->filelist); |
435 | 448 | ||
436 | #ifdef CONFIG_PM | 449 | #ifdef CONFIG_PM |
437 | mutex_init(&dev->pm_mutex); | ||
438 | INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work); | ||
439 | INIT_WORK(&dev->autoresume, usb_autoresume_work); | ||
440 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; | 450 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; |
441 | dev->connect_time = jiffies; | 451 | dev->connect_time = jiffies; |
442 | dev->active_duration = -jiffies; | 452 | dev->active_duration = -jiffies; |
@@ -708,7 +718,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size, | |||
708 | EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); | 718 | EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); |
709 | 719 | ||
710 | /** | 720 | /** |
711 | * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP | 721 | * usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP |
712 | * @dev: device the buffer will be used with | 722 | * @dev: device the buffer will be used with |
713 | * @size: requested buffer size | 723 | * @size: requested buffer size |
714 | * @mem_flags: affect whether allocation may block | 724 | * @mem_flags: affect whether allocation may block |
@@ -727,30 +737,30 @@ EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); | |||
727 | * architectures where CPU caches are not DMA-coherent. On systems without | 737 | * architectures where CPU caches are not DMA-coherent. On systems without |
728 | * bus-snooping caches, these buffers are uncached. | 738 | * bus-snooping caches, these buffers are uncached. |
729 | * | 739 | * |
730 | * When the buffer is no longer used, free it with usb_buffer_free(). | 740 | * When the buffer is no longer used, free it with usb_free_coherent(). |
731 | */ | 741 | */ |
732 | void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags, | 742 | void *usb_alloc_coherent(struct usb_device *dev, size_t size, gfp_t mem_flags, |
733 | dma_addr_t *dma) | 743 | dma_addr_t *dma) |
734 | { | 744 | { |
735 | if (!dev || !dev->bus) | 745 | if (!dev || !dev->bus) |
736 | return NULL; | 746 | return NULL; |
737 | return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); | 747 | return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); |
738 | } | 748 | } |
739 | EXPORT_SYMBOL_GPL(usb_buffer_alloc); | 749 | EXPORT_SYMBOL_GPL(usb_alloc_coherent); |
740 | 750 | ||
741 | /** | 751 | /** |
742 | * usb_buffer_free - free memory allocated with usb_buffer_alloc() | 752 | * usb_free_coherent - free memory allocated with usb_alloc_coherent() |
743 | * @dev: device the buffer was used with | 753 | * @dev: device the buffer was used with |
744 | * @size: requested buffer size | 754 | * @size: requested buffer size |
745 | * @addr: CPU address of buffer | 755 | * @addr: CPU address of buffer |
746 | * @dma: DMA address of buffer | 756 | * @dma: DMA address of buffer |
747 | * | 757 | * |
748 | * This reclaims an I/O buffer, letting it be reused. The memory must have | 758 | * This reclaims an I/O buffer, letting it be reused. The memory must have |
749 | * been allocated using usb_buffer_alloc(), and the parameters must match | 759 | * been allocated using usb_alloc_coherent(), and the parameters must match |
750 | * those provided in that allocation request. | 760 | * those provided in that allocation request. |
751 | */ | 761 | */ |
752 | void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, | 762 | void usb_free_coherent(struct usb_device *dev, size_t size, void *addr, |
753 | dma_addr_t dma) | 763 | dma_addr_t dma) |
754 | { | 764 | { |
755 | if (!dev || !dev->bus) | 765 | if (!dev || !dev->bus) |
756 | return; | 766 | return; |
@@ -758,7 +768,7 @@ void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, | |||
758 | return; | 768 | return; |
759 | hcd_buffer_free(dev->bus, size, addr, dma); | 769 | hcd_buffer_free(dev->bus, size, addr, dma); |
760 | } | 770 | } |
761 | EXPORT_SYMBOL_GPL(usb_buffer_free); | 771 | EXPORT_SYMBOL_GPL(usb_free_coherent); |
762 | 772 | ||
763 | /** | 773 | /** |
764 | * usb_buffer_map - create DMA mapping(s) for an urb | 774 | * usb_buffer_map - create DMA mapping(s) for an urb |
@@ -1038,7 +1048,7 @@ static struct notifier_block usb_bus_nb = { | |||
1038 | struct dentry *usb_debug_root; | 1048 | struct dentry *usb_debug_root; |
1039 | EXPORT_SYMBOL_GPL(usb_debug_root); | 1049 | EXPORT_SYMBOL_GPL(usb_debug_root); |
1040 | 1050 | ||
1041 | struct dentry *usb_debug_devices; | 1051 | static struct dentry *usb_debug_devices; |
1042 | 1052 | ||
1043 | static int usb_debugfs_init(void) | 1053 | static int usb_debugfs_init(void) |
1044 | { | 1054 | { |
@@ -1079,9 +1089,6 @@ static int __init usb_init(void) | |||
1079 | if (retval) | 1089 | if (retval) |
1080 | goto out; | 1090 | goto out; |
1081 | 1091 | ||
1082 | retval = ksuspend_usb_init(); | ||
1083 | if (retval) | ||
1084 | goto out; | ||
1085 | retval = bus_register(&usb_bus_type); | 1092 | retval = bus_register(&usb_bus_type); |
1086 | if (retval) | 1093 | if (retval) |
1087 | goto bus_register_failed; | 1094 | goto bus_register_failed; |
@@ -1121,7 +1128,7 @@ major_init_failed: | |||
1121 | bus_notifier_failed: | 1128 | bus_notifier_failed: |
1122 | bus_unregister(&usb_bus_type); | 1129 | bus_unregister(&usb_bus_type); |
1123 | bus_register_failed: | 1130 | bus_register_failed: |
1124 | ksuspend_usb_cleanup(); | 1131 | usb_debugfs_cleanup(); |
1125 | out: | 1132 | out: |
1126 | return retval; | 1133 | return retval; |
1127 | } | 1134 | } |
@@ -1143,7 +1150,6 @@ static void __exit usb_exit(void) | |||
1143 | usb_hub_cleanup(); | 1150 | usb_hub_cleanup(); |
1144 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); | 1151 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); |
1145 | bus_unregister(&usb_bus_type); | 1152 | bus_unregister(&usb_bus_type); |
1146 | ksuspend_usb_cleanup(); | ||
1147 | usb_debugfs_cleanup(); | 1153 | usb_debugfs_cleanup(); |
1148 | } | 1154 | } |
1149 | 1155 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 9a8b15e6377a..cd882203ad34 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -24,6 +24,7 @@ extern void usb_disable_device(struct usb_device *dev, int skip_ep0); | |||
24 | extern int usb_deauthorize_device(struct usb_device *); | 24 | extern int usb_deauthorize_device(struct usb_device *); |
25 | extern int usb_authorize_device(struct usb_device *); | 25 | extern int usb_authorize_device(struct usb_device *); |
26 | extern void usb_detect_quirks(struct usb_device *udev); | 26 | extern void usb_detect_quirks(struct usb_device *udev); |
27 | extern int usb_remove_device(struct usb_device *udev); | ||
27 | 28 | ||
28 | extern int usb_get_device_descriptor(struct usb_device *dev, | 29 | extern int usb_get_device_descriptor(struct usb_device *dev, |
29 | unsigned int size); | 30 | unsigned int size); |
@@ -54,24 +55,8 @@ extern void usb_major_cleanup(void); | |||
54 | extern int usb_suspend(struct device *dev, pm_message_t msg); | 55 | extern int usb_suspend(struct device *dev, pm_message_t msg); |
55 | extern int usb_resume(struct device *dev, pm_message_t msg); | 56 | extern int usb_resume(struct device *dev, pm_message_t msg); |
56 | 57 | ||
57 | extern void usb_autosuspend_work(struct work_struct *work); | ||
58 | extern void usb_autoresume_work(struct work_struct *work); | ||
59 | extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); | 58 | extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); |
60 | extern int usb_port_resume(struct usb_device *dev, pm_message_t msg); | 59 | extern int usb_port_resume(struct usb_device *dev, pm_message_t msg); |
61 | extern int usb_external_suspend_device(struct usb_device *udev, | ||
62 | pm_message_t msg); | ||
63 | extern int usb_external_resume_device(struct usb_device *udev, | ||
64 | pm_message_t msg); | ||
65 | |||
66 | static inline void usb_pm_lock(struct usb_device *udev) | ||
67 | { | ||
68 | mutex_lock_nested(&udev->pm_mutex, udev->level); | ||
69 | } | ||
70 | |||
71 | static inline void usb_pm_unlock(struct usb_device *udev) | ||
72 | { | ||
73 | mutex_unlock(&udev->pm_mutex); | ||
74 | } | ||
75 | 60 | ||
76 | #else | 61 | #else |
77 | 62 | ||
@@ -85,9 +70,6 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
85 | return 0; | 70 | return 0; |
86 | } | 71 | } |
87 | 72 | ||
88 | static inline void usb_pm_lock(struct usb_device *udev) {} | ||
89 | static inline void usb_pm_unlock(struct usb_device *udev) {} | ||
90 | |||
91 | #endif | 73 | #endif |
92 | 74 | ||
93 | #ifdef CONFIG_USB_SUSPEND | 75 | #ifdef CONFIG_USB_SUSPEND |
@@ -95,6 +77,7 @@ static inline void usb_pm_unlock(struct usb_device *udev) {} | |||
95 | extern void usb_autosuspend_device(struct usb_device *udev); | 77 | extern void usb_autosuspend_device(struct usb_device *udev); |
96 | extern void usb_try_autosuspend_device(struct usb_device *udev); | 78 | extern void usb_try_autosuspend_device(struct usb_device *udev); |
97 | extern int usb_autoresume_device(struct usb_device *udev); | 79 | extern int usb_autoresume_device(struct usb_device *udev); |
80 | extern int usb_remote_wakeup(struct usb_device *dev); | ||
98 | 81 | ||
99 | #else | 82 | #else |
100 | 83 | ||
@@ -105,9 +88,13 @@ static inline int usb_autoresume_device(struct usb_device *udev) | |||
105 | return 0; | 88 | return 0; |
106 | } | 89 | } |
107 | 90 | ||
91 | static inline int usb_remote_wakeup(struct usb_device *udev) | ||
92 | { | ||
93 | return 0; | ||
94 | } | ||
95 | |||
108 | #endif | 96 | #endif |
109 | 97 | ||
110 | extern struct workqueue_struct *ksuspend_usb_wq; | ||
111 | extern struct bus_type usb_bus_type; | 98 | extern struct bus_type usb_bus_type; |
112 | extern struct device_type usb_device_type; | 99 | extern struct device_type usb_device_type; |
113 | extern struct device_type usb_if_device_type; | 100 | extern struct device_type usb_if_device_type; |
@@ -137,23 +124,6 @@ static inline int is_usb_device_driver(struct device_driver *drv) | |||
137 | for_devices; | 124 | for_devices; |
138 | } | 125 | } |
139 | 126 | ||
140 | /* Interfaces and their "power state" are owned by usbcore */ | ||
141 | |||
142 | static inline void mark_active(struct usb_interface *f) | ||
143 | { | ||
144 | f->is_active = 1; | ||
145 | } | ||
146 | |||
147 | static inline void mark_quiesced(struct usb_interface *f) | ||
148 | { | ||
149 | f->is_active = 0; | ||
150 | } | ||
151 | |||
152 | static inline int is_active(const struct usb_interface *f) | ||
153 | { | ||
154 | return f->is_active; | ||
155 | } | ||
156 | |||
157 | 127 | ||
158 | /* for labeling diagnostics */ | 128 | /* for labeling diagnostics */ |
159 | extern const char *usbcore_name; | 129 | extern const char *usbcore_name; |