diff options
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/Kconfig | 3 | ||||
-rw-r--r-- | drivers/usb/core/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/core/buffer.c | 5 | ||||
-rw-r--r-- | drivers/usb/core/config.c | 5 | ||||
-rw-r--r-- | drivers/usb/core/devices.c | 6 | ||||
-rw-r--r-- | drivers/usb/core/devio.c | 102 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 1013 | ||||
-rw-r--r-- | drivers/usb/core/endpoint.c | 30 | ||||
-rw-r--r-- | drivers/usb/core/file.c | 16 | ||||
-rw-r--r-- | drivers/usb/core/generic.c | 208 | ||||
-rw-r--r-- | drivers/usb/core/hcd-pci.c | 21 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 251 | ||||
-rw-r--r-- | drivers/usb/core/hcd.h | 60 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 566 | ||||
-rw-r--r-- | drivers/usb/core/hub.h | 3 | ||||
-rw-r--r-- | drivers/usb/core/inode.c | 24 | ||||
-rw-r--r-- | drivers/usb/core/message.c | 149 | ||||
-rw-r--r-- | drivers/usb/core/notify.c | 4 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 61 | ||||
-rw-r--r-- | drivers/usb/core/urb.c | 16 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 570 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 94 |
22 files changed, 2045 insertions, 1164 deletions
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index a08787e253aa..6e3b5358a760 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -31,9 +31,6 @@ config USB_DEVICEFS | |||
31 | For the format of the various /proc/bus/usb/ files, please read | 31 | For the format of the various /proc/bus/usb/ files, please read |
32 | <file:Documentation/usb/proc_usb_info.txt>. | 32 | <file:Documentation/usb/proc_usb_info.txt>. |
33 | 33 | ||
34 | Please note that this code is completely unrelated to devfs, the | ||
35 | "/dev file system support". | ||
36 | |||
37 | Most users want to say Y here. | 34 | Most users want to say Y here. |
38 | 35 | ||
39 | config USB_BANDWIDTH | 36 | config USB_BANDWIDTH |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index ec510922af63..34e9bac319b4 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ | 5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ |
6 | config.o file.o buffer.o sysfs.o endpoint.o \ | 6 | config.o file.o buffer.o sysfs.o endpoint.o \ |
7 | devio.o notify.o | 7 | devio.o notify.o generic.o |
8 | 8 | ||
9 | ifeq ($(CONFIG_PCI),y) | 9 | ifeq ($(CONFIG_PCI),y) |
10 | usbcore-objs += hcd-pci.o | 10 | usbcore-objs += hcd-pci.o |
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index ad742cec94fa..840442a25b61 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c | |||
@@ -5,7 +5,6 @@ | |||
5 | * and should work with all USB controllers, regardles of bus type. | 5 | * and should work with all USB controllers, regardles of bus type. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/config.h> | ||
9 | #include <linux/module.h> | 8 | #include <linux/module.h> |
10 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
11 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
@@ -105,7 +104,7 @@ void *hcd_buffer_alloc ( | |||
105 | dma_addr_t *dma | 104 | dma_addr_t *dma |
106 | ) | 105 | ) |
107 | { | 106 | { |
108 | struct usb_hcd *hcd = bus->hcpriv; | 107 | struct usb_hcd *hcd = bus_to_hcd(bus); |
109 | int i; | 108 | int i; |
110 | 109 | ||
111 | /* some USB hosts just use PIO */ | 110 | /* some USB hosts just use PIO */ |
@@ -128,7 +127,7 @@ void hcd_buffer_free ( | |||
128 | dma_addr_t dma | 127 | dma_addr_t dma |
129 | ) | 128 | ) |
130 | { | 129 | { |
131 | struct usb_hcd *hcd = bus->hcpriv; | 130 | struct usb_hcd *hcd = bus_to_hcd(bus); |
132 | int i; | 131 | int i; |
133 | 132 | ||
134 | if (!addr) | 133 | if (!addr) |
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index a9d89c78cc20..bfb3731d42db 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #include <linux/config.h> | ||
2 | #include <linux/usb.h> | 1 | #include <linux/usb.h> |
3 | #include <linux/module.h> | 2 | #include <linux/module.h> |
4 | #include <linux/init.h> | 3 | #include <linux/init.h> |
@@ -476,7 +475,9 @@ int usb_get_configuration(struct usb_device *dev) | |||
476 | if (result < 0) { | 475 | if (result < 0) { |
477 | dev_err(ddev, "unable to read config index %d " | 476 | dev_err(ddev, "unable to read config index %d " |
478 | "descriptor/%s\n", cfgno, "start"); | 477 | "descriptor/%s\n", cfgno, "start"); |
479 | goto err; | 478 | dev_err(ddev, "chopping to %d config(s)\n", cfgno); |
479 | dev->descriptor.bNumConfigurations = cfgno; | ||
480 | break; | ||
480 | } else if (result < 4) { | 481 | } else if (result < 4) { |
481 | dev_err(ddev, "config index %d descriptor too short " | 482 | dev_err(ddev, "config index %d descriptor too short " |
482 | "(expected %i, got %i)\n", cfgno, | 483 | "(expected %i, got %i)\n", cfgno, |
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c index c0f37343a276..3538c2fdadfe 100644 --- a/drivers/usb/core/devices.c +++ b/drivers/usb/core/devices.c | |||
@@ -593,7 +593,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte | |||
593 | /* Kernel lock for "lastev" protection */ | 593 | /* Kernel lock for "lastev" protection */ |
594 | static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait) | 594 | static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait) |
595 | { | 595 | { |
596 | struct usb_device_status *st = (struct usb_device_status *)file->private_data; | 596 | struct usb_device_status *st = file->private_data; |
597 | unsigned int mask = 0; | 597 | unsigned int mask = 0; |
598 | 598 | ||
599 | lock_kernel(); | 599 | lock_kernel(); |
@@ -603,7 +603,7 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct | |||
603 | unlock_kernel(); | 603 | unlock_kernel(); |
604 | return POLLIN; | 604 | return POLLIN; |
605 | } | 605 | } |
606 | 606 | ||
607 | /* we may have dropped BKL - need to check for having lost the race */ | 607 | /* we may have dropped BKL - need to check for having lost the race */ |
608 | if (file->private_data) { | 608 | if (file->private_data) { |
609 | kfree(st); | 609 | kfree(st); |
@@ -667,7 +667,7 @@ static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig) | |||
667 | return ret; | 667 | return ret; |
668 | } | 668 | } |
669 | 669 | ||
670 | struct file_operations usbfs_devices_fops = { | 670 | const struct file_operations usbfs_devices_fops = { |
671 | .llseek = usb_device_lseek, | 671 | .llseek = usb_device_lseek, |
672 | .read = usb_device_read, | 672 | .read = usb_device_read, |
673 | .poll = usb_device_poll, | 673 | .poll = usb_device_poll, |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 3f8e06279c92..a94c63bef632 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/usbdevice_fs.h> | 47 | #include <linux/usbdevice_fs.h> |
48 | #include <linux/cdev.h> | 48 | #include <linux/cdev.h> |
49 | #include <linux/notifier.h> | 49 | #include <linux/notifier.h> |
50 | #include <linux/security.h> | ||
50 | #include <asm/uaccess.h> | 51 | #include <asm/uaccess.h> |
51 | #include <asm/byteorder.h> | 52 | #include <asm/byteorder.h> |
52 | #include <linux/moduleparam.h> | 53 | #include <linux/moduleparam.h> |
@@ -58,6 +59,9 @@ | |||
58 | #define USB_DEVICE_MAX USB_MAXBUS * 128 | 59 | #define USB_DEVICE_MAX USB_MAXBUS * 128 |
59 | static struct class *usb_device_class; | 60 | static struct class *usb_device_class; |
60 | 61 | ||
62 | /* Mutual exclusion for removal, open, and release */ | ||
63 | DEFINE_MUTEX(usbfs_mutex); | ||
64 | |||
61 | struct async { | 65 | struct async { |
62 | struct list_head asynclist; | 66 | struct list_head asynclist; |
63 | struct dev_state *ps; | 67 | struct dev_state *ps; |
@@ -68,6 +72,7 @@ struct async { | |||
68 | void __user *userbuffer; | 72 | void __user *userbuffer; |
69 | void __user *userurb; | 73 | void __user *userurb; |
70 | struct urb *urb; | 74 | struct urb *urb; |
75 | u32 secid; | ||
71 | }; | 76 | }; |
72 | 77 | ||
73 | static int usbfs_snoop = 0; | 78 | static int usbfs_snoop = 0; |
@@ -85,9 +90,10 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic"); | |||
85 | 90 | ||
86 | #define MAX_USBFS_BUFFER_SIZE 16384 | 91 | #define MAX_USBFS_BUFFER_SIZE 16384 |
87 | 92 | ||
88 | static inline int connected (struct usb_device *dev) | 93 | static inline int connected (struct dev_state *ps) |
89 | { | 94 | { |
90 | return dev->state != USB_STATE_NOTATTACHED; | 95 | return (!list_empty(&ps->list) && |
96 | ps->dev->state != USB_STATE_NOTATTACHED); | ||
91 | } | 97 | } |
92 | 98 | ||
93 | static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) | 99 | static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) |
@@ -116,7 +122,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig) | |||
116 | 122 | ||
117 | static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) | 123 | static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
118 | { | 124 | { |
119 | struct dev_state *ps = (struct dev_state *)file->private_data; | 125 | struct dev_state *ps = file->private_data; |
120 | struct usb_device *dev = ps->dev; | 126 | struct usb_device *dev = ps->dev; |
121 | ssize_t ret = 0; | 127 | ssize_t ret = 0; |
122 | unsigned len; | 128 | unsigned len; |
@@ -125,7 +131,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes, l | |||
125 | 131 | ||
126 | pos = *ppos; | 132 | pos = *ppos; |
127 | usb_lock_device(dev); | 133 | usb_lock_device(dev); |
128 | if (!connected(dev)) { | 134 | if (!connected(ps)) { |
129 | ret = -ENODEV; | 135 | ret = -ENODEV; |
130 | goto err; | 136 | goto err; |
131 | } else if (pos < 0) { | 137 | } else if (pos < 0) { |
@@ -299,7 +305,7 @@ static void snoop_urb(struct urb *urb, void __user *userurb) | |||
299 | 305 | ||
300 | static void async_completed(struct urb *urb, struct pt_regs *regs) | 306 | static void async_completed(struct urb *urb, struct pt_regs *regs) |
301 | { | 307 | { |
302 | struct async *as = (struct async *)urb->context; | 308 | struct async *as = urb->context; |
303 | struct dev_state *ps = as->ps; | 309 | struct dev_state *ps = as->ps; |
304 | struct siginfo sinfo; | 310 | struct siginfo sinfo; |
305 | 311 | ||
@@ -312,7 +318,7 @@ static void async_completed(struct urb *urb, struct pt_regs *regs) | |||
312 | sinfo.si_code = SI_ASYNCIO; | 318 | sinfo.si_code = SI_ASYNCIO; |
313 | sinfo.si_addr = as->userurb; | 319 | sinfo.si_addr = as->userurb; |
314 | kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid, | 320 | kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid, |
315 | as->euid); | 321 | as->euid, as->secid); |
316 | } | 322 | } |
317 | snoop(&urb->dev->dev, "urb complete\n"); | 323 | snoop(&urb->dev->dev, "urb complete\n"); |
318 | snoop_urb(urb, as->userurb); | 324 | snoop_urb(urb, as->userurb); |
@@ -515,19 +521,19 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig | |||
515 | 521 | ||
516 | static struct usb_device *usbdev_lookup_minor(int minor) | 522 | static struct usb_device *usbdev_lookup_minor(int minor) |
517 | { | 523 | { |
518 | struct device *device; | 524 | struct class_device *class_dev; |
519 | struct usb_device *udev = NULL; | 525 | struct usb_device *dev = NULL; |
520 | 526 | ||
521 | down(&usb_device_class->sem); | 527 | down(&usb_device_class->sem); |
522 | list_for_each_entry(device, &usb_device_class->devices, node) { | 528 | list_for_each_entry(class_dev, &usb_device_class->children, node) { |
523 | if (device->devt == MKDEV(USB_DEVICE_MAJOR, minor)) { | 529 | if (class_dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) { |
524 | udev = device->platform_data; | 530 | dev = class_dev->class_data; |
525 | break; | 531 | break; |
526 | } | 532 | } |
527 | } | 533 | } |
528 | up(&usb_device_class->sem); | 534 | up(&usb_device_class->sem); |
529 | 535 | ||
530 | return udev; | 536 | return dev; |
531 | }; | 537 | }; |
532 | 538 | ||
533 | /* | 539 | /* |
@@ -539,25 +545,25 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
539 | struct dev_state *ps; | 545 | struct dev_state *ps; |
540 | int ret; | 546 | int ret; |
541 | 547 | ||
542 | /* | 548 | /* Protect against simultaneous removal or release */ |
543 | * no locking necessary here, as chrdev_open has the kernel lock | 549 | mutex_lock(&usbfs_mutex); |
544 | * (still acquire the kernel lock for safety) | 550 | |
545 | */ | ||
546 | ret = -ENOMEM; | 551 | ret = -ENOMEM; |
547 | if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL))) | 552 | if (!(ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL))) |
548 | goto out_nolock; | 553 | goto out; |
549 | 554 | ||
550 | lock_kernel(); | ||
551 | ret = -ENOENT; | 555 | ret = -ENOENT; |
552 | /* check if we are called from a real node or usbfs */ | 556 | /* check if we are called from a real node or usbfs */ |
553 | if (imajor(inode) == USB_DEVICE_MAJOR) | 557 | if (imajor(inode) == USB_DEVICE_MAJOR) |
554 | dev = usbdev_lookup_minor(iminor(inode)); | 558 | dev = usbdev_lookup_minor(iminor(inode)); |
555 | if (!dev) | 559 | if (!dev) |
556 | dev = inode->u.generic_ip; | 560 | dev = inode->i_private; |
557 | if (!dev) { | 561 | if (!dev) |
558 | kfree(ps); | ||
559 | goto out; | 562 | goto out; |
560 | } | 563 | ret = usb_autoresume_device(dev, 1); |
564 | if (ret) | ||
565 | goto out; | ||
566 | |||
561 | usb_get_dev(dev); | 567 | usb_get_dev(dev); |
562 | ret = 0; | 568 | ret = 0; |
563 | ps->dev = dev; | 569 | ps->dev = dev; |
@@ -572,34 +578,41 @@ static int usbdev_open(struct inode *inode, struct file *file) | |||
572 | ps->disc_euid = current->euid; | 578 | ps->disc_euid = current->euid; |
573 | ps->disccontext = NULL; | 579 | ps->disccontext = NULL; |
574 | ps->ifclaimed = 0; | 580 | ps->ifclaimed = 0; |
581 | security_task_getsecid(current, &ps->secid); | ||
575 | wmb(); | 582 | wmb(); |
576 | list_add_tail(&ps->list, &dev->filelist); | 583 | list_add_tail(&ps->list, &dev->filelist); |
577 | file->private_data = ps; | 584 | file->private_data = ps; |
578 | out: | 585 | out: |
579 | unlock_kernel(); | 586 | if (ret) |
580 | out_nolock: | 587 | kfree(ps); |
581 | return ret; | 588 | mutex_unlock(&usbfs_mutex); |
589 | return ret; | ||
582 | } | 590 | } |
583 | 591 | ||
584 | static int usbdev_release(struct inode *inode, struct file *file) | 592 | static int usbdev_release(struct inode *inode, struct file *file) |
585 | { | 593 | { |
586 | struct dev_state *ps = (struct dev_state *)file->private_data; | 594 | struct dev_state *ps = file->private_data; |
587 | struct usb_device *dev = ps->dev; | 595 | struct usb_device *dev = ps->dev; |
588 | unsigned int ifnum; | 596 | unsigned int ifnum; |
589 | 597 | ||
590 | usb_lock_device(dev); | 598 | usb_lock_device(dev); |
599 | |||
600 | /* Protect against simultaneous open */ | ||
601 | mutex_lock(&usbfs_mutex); | ||
591 | list_del_init(&ps->list); | 602 | list_del_init(&ps->list); |
603 | mutex_unlock(&usbfs_mutex); | ||
604 | |||
592 | for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); | 605 | for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); |
593 | ifnum++) { | 606 | ifnum++) { |
594 | if (test_bit(ifnum, &ps->ifclaimed)) | 607 | if (test_bit(ifnum, &ps->ifclaimed)) |
595 | releaseintf(ps, ifnum); | 608 | releaseintf(ps, ifnum); |
596 | } | 609 | } |
597 | destroy_all_async(ps); | 610 | destroy_all_async(ps); |
611 | usb_autosuspend_device(dev, 1); | ||
598 | usb_unlock_device(dev); | 612 | usb_unlock_device(dev); |
599 | usb_put_dev(dev); | 613 | usb_put_dev(dev); |
600 | ps->dev = NULL; | ||
601 | kfree(ps); | 614 | kfree(ps); |
602 | return 0; | 615 | return 0; |
603 | } | 616 | } |
604 | 617 | ||
605 | static int proc_control(struct dev_state *ps, void __user *arg) | 618 | static int proc_control(struct dev_state *ps, void __user *arg) |
@@ -1053,6 +1066,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, | |||
1053 | as->pid = current->pid; | 1066 | as->pid = current->pid; |
1054 | as->uid = current->uid; | 1067 | as->uid = current->uid; |
1055 | as->euid = current->euid; | 1068 | as->euid = current->euid; |
1069 | security_task_getsecid(current, &as->secid); | ||
1056 | if (!(uurb->endpoint & USB_DIR_IN)) { | 1070 | if (!(uurb->endpoint & USB_DIR_IN)) { |
1057 | if (copy_from_user(as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) { | 1071 | if (copy_from_user(as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) { |
1058 | free_async(as); | 1072 | free_async(as); |
@@ -1078,9 +1092,7 @@ static int proc_submiturb(struct dev_state *ps, void __user *arg) | |||
1078 | if (copy_from_user(&uurb, arg, sizeof(uurb))) | 1092 | if (copy_from_user(&uurb, arg, sizeof(uurb))) |
1079 | return -EFAULT; | 1093 | return -EFAULT; |
1080 | 1094 | ||
1081 | return proc_do_submiturb(ps, &uurb, | 1095 | return proc_do_submiturb(ps, &uurb, (((struct usbdevfs_urb __user *)arg)->iso_frame_desc), arg); |
1082 | (struct usbdevfs_iso_packet_desc __user *)uurb.iso_frame_desc, | ||
1083 | arg); | ||
1084 | } | 1096 | } |
1085 | 1097 | ||
1086 | static int proc_unlinkurb(struct dev_state *ps, void __user *arg) | 1098 | static int proc_unlinkurb(struct dev_state *ps, void __user *arg) |
@@ -1205,9 +1217,7 @@ static int proc_submiturb_compat(struct dev_state *ps, void __user *arg) | |||
1205 | if (get_urb32(&uurb,(struct usbdevfs_urb32 *)arg)) | 1217 | if (get_urb32(&uurb,(struct usbdevfs_urb32 *)arg)) |
1206 | return -EFAULT; | 1218 | return -EFAULT; |
1207 | 1219 | ||
1208 | return proc_do_submiturb(ps, &uurb, | 1220 | return proc_do_submiturb(ps, &uurb, ((struct usbdevfs_urb32 __user *)arg)->iso_frame_desc, arg); |
1209 | (struct usbdevfs_iso_packet_desc __user *)uurb.iso_frame_desc, | ||
1210 | arg); | ||
1211 | } | 1221 | } |
1212 | 1222 | ||
1213 | static int processcompl_compat(struct async *as, void __user * __user *arg) | 1223 | static int processcompl_compat(struct async *as, void __user * __user *arg) |
@@ -1322,7 +1332,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1322 | } | 1332 | } |
1323 | } | 1333 | } |
1324 | 1334 | ||
1325 | if (!connected(ps->dev)) { | 1335 | if (!connected(ps)) { |
1326 | kfree(buf); | 1336 | kfree(buf); |
1327 | return -ENODEV; | 1337 | return -ENODEV; |
1328 | } | 1338 | } |
@@ -1349,7 +1359,7 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl) | |||
1349 | /* let kernel drivers try to (re)bind to the interface */ | 1359 | /* let kernel drivers try to (re)bind to the interface */ |
1350 | case USBDEVFS_CONNECT: | 1360 | case USBDEVFS_CONNECT: |
1351 | usb_unlock_device(ps->dev); | 1361 | usb_unlock_device(ps->dev); |
1352 | bus_rescan_devices(intf->dev.bus); | 1362 | retval = bus_rescan_devices(intf->dev.bus); |
1353 | usb_lock_device(ps->dev); | 1363 | usb_lock_device(ps->dev); |
1354 | break; | 1364 | break; |
1355 | 1365 | ||
@@ -1413,7 +1423,7 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg) | |||
1413 | */ | 1423 | */ |
1414 | static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | 1424 | static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) |
1415 | { | 1425 | { |
1416 | struct dev_state *ps = (struct dev_state *)file->private_data; | 1426 | struct dev_state *ps = file->private_data; |
1417 | struct usb_device *dev = ps->dev; | 1427 | struct usb_device *dev = ps->dev; |
1418 | void __user *p = (void __user *)arg; | 1428 | void __user *p = (void __user *)arg; |
1419 | int ret = -ENOTTY; | 1429 | int ret = -ENOTTY; |
@@ -1421,7 +1431,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
1421 | if (!(file->f_mode & FMODE_WRITE)) | 1431 | if (!(file->f_mode & FMODE_WRITE)) |
1422 | return -EPERM; | 1432 | return -EPERM; |
1423 | usb_lock_device(dev); | 1433 | usb_lock_device(dev); |
1424 | if (!connected(dev)) { | 1434 | if (!connected(ps)) { |
1425 | usb_unlock_device(dev); | 1435 | usb_unlock_device(dev); |
1426 | return -ENODEV; | 1436 | return -ENODEV; |
1427 | } | 1437 | } |
@@ -1556,18 +1566,18 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
1556 | /* No kernel lock - fine */ | 1566 | /* No kernel lock - fine */ |
1557 | static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait) | 1567 | static unsigned int usbdev_poll(struct file *file, struct poll_table_struct *wait) |
1558 | { | 1568 | { |
1559 | struct dev_state *ps = (struct dev_state *)file->private_data; | 1569 | struct dev_state *ps = file->private_data; |
1560 | unsigned int mask = 0; | 1570 | unsigned int mask = 0; |
1561 | 1571 | ||
1562 | poll_wait(file, &ps->wait, wait); | 1572 | poll_wait(file, &ps->wait, wait); |
1563 | if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed)) | 1573 | if (file->f_mode & FMODE_WRITE && !list_empty(&ps->async_completed)) |
1564 | mask |= POLLOUT | POLLWRNORM; | 1574 | mask |= POLLOUT | POLLWRNORM; |
1565 | if (!connected(ps->dev)) | 1575 | if (!connected(ps)) |
1566 | mask |= POLLERR | POLLHUP; | 1576 | mask |= POLLERR | POLLHUP; |
1567 | return mask; | 1577 | return mask; |
1568 | } | 1578 | } |
1569 | 1579 | ||
1570 | struct file_operations usbfs_device_file_operations = { | 1580 | const struct file_operations usbfs_device_file_operations = { |
1571 | .llseek = usbdev_lseek, | 1581 | .llseek = usbdev_lseek, |
1572 | .read = usbdev_read, | 1582 | .read = usbdev_read, |
1573 | .poll = usbdev_poll, | 1583 | .poll = usbdev_poll, |
@@ -1580,16 +1590,16 @@ static void usbdev_add(struct usb_device *dev) | |||
1580 | { | 1590 | { |
1581 | int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); | 1591 | int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); |
1582 | 1592 | ||
1583 | dev->usbfs_dev = device_create(usb_device_class, &dev->dev, | 1593 | dev->class_dev = class_device_create(usb_device_class, NULL, |
1584 | MKDEV(USB_DEVICE_MAJOR, minor), | 1594 | MKDEV(USB_DEVICE_MAJOR, minor), &dev->dev, |
1585 | "usbdev%d.%d", dev->bus->busnum, dev->devnum); | 1595 | "usbdev%d.%d", dev->bus->busnum, dev->devnum); |
1586 | 1596 | ||
1587 | dev->usbfs_dev->platform_data = dev; | 1597 | dev->class_dev->class_data = dev; |
1588 | } | 1598 | } |
1589 | 1599 | ||
1590 | static void usbdev_remove(struct usb_device *dev) | 1600 | static void usbdev_remove(struct usb_device *dev) |
1591 | { | 1601 | { |
1592 | device_unregister(dev->usbfs_dev); | 1602 | class_device_unregister(dev->class_dev); |
1593 | } | 1603 | } |
1594 | 1604 | ||
1595 | static int usbdev_notify(struct notifier_block *self, unsigned long action, | 1605 | static int usbdev_notify(struct notifier_block *self, unsigned long action, |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index c196f3845305..113e484c763e 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -17,13 +17,14 @@ | |||
17 | * | 17 | * |
18 | * NOTE! This is not actually a driver at all, rather this is | 18 | * NOTE! This is not actually a driver at all, rather this is |
19 | * just a collection of helper routines that implement the | 19 | * just a collection of helper routines that implement the |
20 | * generic USB things that the real drivers can use.. | 20 | * matching, probing, releasing, suspending and resuming for |
21 | * real drivers. | ||
21 | * | 22 | * |
22 | */ | 23 | */ |
23 | 24 | ||
24 | #include <linux/config.h> | ||
25 | #include <linux/device.h> | 25 | #include <linux/device.h> |
26 | #include <linux/usb.h> | 26 | #include <linux/usb.h> |
27 | #include <linux/workqueue.h> | ||
27 | #include "hcd.h" | 28 | #include "hcd.h" |
28 | #include "usb.h" | 29 | #include "usb.h" |
29 | 30 | ||
@@ -35,38 +36,6 @@ struct usb_dynid { | |||
35 | struct usb_device_id id; | 36 | struct usb_device_id id; |
36 | }; | 37 | }; |
37 | 38 | ||
38 | |||
39 | static int generic_probe(struct device *dev) | ||
40 | { | ||
41 | return 0; | ||
42 | } | ||
43 | static int generic_remove(struct device *dev) | ||
44 | { | ||
45 | struct usb_device *udev = to_usb_device(dev); | ||
46 | |||
47 | /* if this is only an unbind, not a physical disconnect, then | ||
48 | * unconfigure the device */ | ||
49 | if (udev->state == USB_STATE_CONFIGURED) | ||
50 | usb_set_configuration(udev, 0); | ||
51 | |||
52 | /* in case the call failed or the device was suspended */ | ||
53 | if (udev->state >= USB_STATE_CONFIGURED) | ||
54 | usb_disable_device(udev, 0); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | struct device_driver usb_generic_driver = { | ||
59 | .owner = THIS_MODULE, | ||
60 | .name = "usb", | ||
61 | .bus = &usb_bus_type, | ||
62 | .probe = generic_probe, | ||
63 | .remove = generic_remove, | ||
64 | }; | ||
65 | |||
66 | /* Fun hack to determine if the struct device is a | ||
67 | * usb device or a usb interface. */ | ||
68 | int usb_generic_driver_data; | ||
69 | |||
70 | #ifdef CONFIG_HOTPLUG | 39 | #ifdef CONFIG_HOTPLUG |
71 | 40 | ||
72 | /* | 41 | /* |
@@ -81,6 +50,7 @@ static ssize_t store_new_id(struct device_driver *driver, | |||
81 | u32 idVendor = 0; | 50 | u32 idVendor = 0; |
82 | u32 idProduct = 0; | 51 | u32 idProduct = 0; |
83 | int fields = 0; | 52 | int fields = 0; |
53 | int retval = 0; | ||
84 | 54 | ||
85 | fields = sscanf(buf, "%x %x", &idVendor, &idProduct); | 55 | fields = sscanf(buf, "%x %x", &idVendor, &idProduct); |
86 | if (fields < 2) | 56 | if (fields < 2) |
@@ -100,10 +70,12 @@ static ssize_t store_new_id(struct device_driver *driver, | |||
100 | spin_unlock(&usb_drv->dynids.lock); | 70 | spin_unlock(&usb_drv->dynids.lock); |
101 | 71 | ||
102 | if (get_driver(driver)) { | 72 | if (get_driver(driver)) { |
103 | driver_attach(driver); | 73 | retval = driver_attach(driver); |
104 | put_driver(driver); | 74 | put_driver(driver); |
105 | } | 75 | } |
106 | 76 | ||
77 | if (retval) | ||
78 | return retval; | ||
107 | return count; | 79 | return count; |
108 | } | 80 | } |
109 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); | 81 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); |
@@ -116,7 +88,7 @@ static int usb_create_newid_file(struct usb_driver *usb_drv) | |||
116 | goto exit; | 88 | goto exit; |
117 | 89 | ||
118 | if (usb_drv->probe != NULL) | 90 | if (usb_drv->probe != NULL) |
119 | error = sysfs_create_file(&usb_drv->driver.kobj, | 91 | error = sysfs_create_file(&usb_drv->drvwrap.driver.kobj, |
120 | &driver_attr_new_id.attr); | 92 | &driver_attr_new_id.attr); |
121 | exit: | 93 | exit: |
122 | return error; | 94 | return error; |
@@ -128,7 +100,7 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv) | |||
128 | return; | 100 | return; |
129 | 101 | ||
130 | if (usb_drv->probe != NULL) | 102 | if (usb_drv->probe != NULL) |
131 | sysfs_remove_file(&usb_drv->driver.kobj, | 103 | sysfs_remove_file(&usb_drv->drvwrap.driver.kobj, |
132 | &driver_attr_new_id.attr); | 104 | &driver_attr_new_id.attr); |
133 | } | 105 | } |
134 | 106 | ||
@@ -175,21 +147,57 @@ static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *in | |||
175 | } | 147 | } |
176 | 148 | ||
177 | 149 | ||
178 | /* called from driver core with usb_bus_type.subsys writelock */ | 150 | /* called from driver core with dev locked */ |
151 | static int usb_probe_device(struct device *dev) | ||
152 | { | ||
153 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); | ||
154 | struct usb_device *udev; | ||
155 | int error = -ENODEV; | ||
156 | |||
157 | dev_dbg(dev, "%s\n", __FUNCTION__); | ||
158 | |||
159 | if (!is_usb_device(dev)) /* Sanity check */ | ||
160 | return error; | ||
161 | |||
162 | udev = to_usb_device(dev); | ||
163 | |||
164 | /* TODO: Add real matching code */ | ||
165 | |||
166 | /* The device should always appear to be in use | ||
167 | * unless the driver suports autosuspend. | ||
168 | */ | ||
169 | udev->pm_usage_cnt = !(udriver->supports_autosuspend); | ||
170 | |||
171 | error = udriver->probe(udev); | ||
172 | return error; | ||
173 | } | ||
174 | |||
175 | /* called from driver core with dev locked */ | ||
176 | static int usb_unbind_device(struct device *dev) | ||
177 | { | ||
178 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); | ||
179 | |||
180 | udriver->disconnect(to_usb_device(dev)); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | |||
185 | /* called from driver core with dev locked */ | ||
179 | static int usb_probe_interface(struct device *dev) | 186 | static int usb_probe_interface(struct device *dev) |
180 | { | 187 | { |
181 | struct usb_interface * intf = to_usb_interface(dev); | 188 | struct usb_driver *driver = to_usb_driver(dev->driver); |
182 | struct usb_driver * driver = to_usb_driver(dev->driver); | 189 | struct usb_interface *intf; |
190 | struct usb_device *udev; | ||
183 | const struct usb_device_id *id; | 191 | const struct usb_device_id *id; |
184 | int error = -ENODEV; | 192 | int error = -ENODEV; |
185 | 193 | ||
186 | dev_dbg(dev, "%s\n", __FUNCTION__); | 194 | dev_dbg(dev, "%s\n", __FUNCTION__); |
187 | 195 | ||
188 | if (!driver->probe) | 196 | if (is_usb_device(dev)) /* Sanity check */ |
189 | return error; | 197 | return error; |
190 | /* FIXME we'd much prefer to just resume it ... */ | 198 | |
191 | if (interface_to_usbdev(intf)->state == USB_STATE_SUSPENDED) | 199 | intf = to_usb_interface(dev); |
192 | return -EHOSTUNREACH; | 200 | udev = interface_to_usbdev(intf); |
193 | 201 | ||
194 | id = usb_match_id(intf, driver->id_table); | 202 | id = usb_match_id(intf, driver->id_table); |
195 | if (!id) | 203 | if (!id) |
@@ -197,48 +205,165 @@ static int usb_probe_interface(struct device *dev) | |||
197 | if (id) { | 205 | if (id) { |
198 | dev_dbg(dev, "%s - got id\n", __FUNCTION__); | 206 | dev_dbg(dev, "%s - got id\n", __FUNCTION__); |
199 | 207 | ||
208 | error = usb_autoresume_device(udev, 1); | ||
209 | if (error) | ||
210 | return error; | ||
211 | |||
200 | /* Interface "power state" doesn't correspond to any hardware | 212 | /* Interface "power state" doesn't correspond to any hardware |
201 | * state whatsoever. We use it to record when it's bound to | 213 | * state whatsoever. We use it to record when it's bound to |
202 | * a driver that may start I/0: it's not frozen/quiesced. | 214 | * a driver that may start I/0: it's not frozen/quiesced. |
203 | */ | 215 | */ |
204 | mark_active(intf); | 216 | mark_active(intf); |
205 | intf->condition = USB_INTERFACE_BINDING; | 217 | intf->condition = USB_INTERFACE_BINDING; |
218 | |||
219 | /* The interface should always appear to be in use | ||
220 | * unless the driver suports autosuspend. | ||
221 | */ | ||
222 | intf->pm_usage_cnt = !(driver->supports_autosuspend); | ||
223 | |||
206 | error = driver->probe(intf, id); | 224 | error = driver->probe(intf, id); |
207 | if (error) { | 225 | if (error) { |
208 | mark_quiesced(intf); | 226 | mark_quiesced(intf); |
227 | intf->needs_remote_wakeup = 0; | ||
209 | intf->condition = USB_INTERFACE_UNBOUND; | 228 | intf->condition = USB_INTERFACE_UNBOUND; |
210 | } else | 229 | } else |
211 | intf->condition = USB_INTERFACE_BOUND; | 230 | intf->condition = USB_INTERFACE_BOUND; |
231 | |||
232 | usb_autosuspend_device(udev, 1); | ||
212 | } | 233 | } |
213 | 234 | ||
214 | return error; | 235 | return error; |
215 | } | 236 | } |
216 | 237 | ||
217 | /* called from driver core with usb_bus_type.subsys writelock */ | 238 | /* called from driver core with dev locked */ |
218 | static int usb_unbind_interface(struct device *dev) | 239 | static int usb_unbind_interface(struct device *dev) |
219 | { | 240 | { |
241 | struct usb_driver *driver = to_usb_driver(dev->driver); | ||
220 | struct usb_interface *intf = to_usb_interface(dev); | 242 | struct usb_interface *intf = to_usb_interface(dev); |
221 | struct usb_driver *driver = to_usb_driver(intf->dev.driver); | 243 | struct usb_device *udev; |
244 | int error; | ||
222 | 245 | ||
223 | intf->condition = USB_INTERFACE_UNBINDING; | 246 | intf->condition = USB_INTERFACE_UNBINDING; |
224 | 247 | ||
248 | /* Autoresume for set_interface call below */ | ||
249 | udev = interface_to_usbdev(intf); | ||
250 | error = usb_autoresume_device(udev, 1); | ||
251 | |||
225 | /* release all urbs for this interface */ | 252 | /* release all urbs for this interface */ |
226 | usb_disable_interface(interface_to_usbdev(intf), intf); | 253 | usb_disable_interface(interface_to_usbdev(intf), intf); |
227 | 254 | ||
228 | if (driver && driver->disconnect) | 255 | driver->disconnect(intf); |
229 | driver->disconnect(intf); | ||
230 | 256 | ||
231 | /* reset other interface state */ | 257 | /* reset other interface state */ |
232 | usb_set_interface(interface_to_usbdev(intf), | 258 | usb_set_interface(interface_to_usbdev(intf), |
233 | intf->altsetting[0].desc.bInterfaceNumber, | 259 | intf->altsetting[0].desc.bInterfaceNumber, |
234 | 0); | 260 | 0); |
235 | usb_set_intfdata(intf, NULL); | 261 | usb_set_intfdata(intf, NULL); |
262 | |||
236 | intf->condition = USB_INTERFACE_UNBOUND; | 263 | intf->condition = USB_INTERFACE_UNBOUND; |
237 | mark_quiesced(intf); | 264 | mark_quiesced(intf); |
265 | intf->needs_remote_wakeup = 0; | ||
266 | |||
267 | if (!error) | ||
268 | usb_autosuspend_device(udev, 1); | ||
238 | 269 | ||
239 | return 0; | 270 | return 0; |
240 | } | 271 | } |
241 | 272 | ||
273 | /** | ||
274 | * usb_driver_claim_interface - bind a driver to an interface | ||
275 | * @driver: the driver to be bound | ||
276 | * @iface: the interface to which it will be bound; must be in the | ||
277 | * usb device's active configuration | ||
278 | * @priv: driver data associated with that interface | ||
279 | * | ||
280 | * This is used by usb device drivers that need to claim more than one | ||
281 | * interface on a device when probing (audio and acm are current examples). | ||
282 | * No device driver should directly modify internal usb_interface or | ||
283 | * usb_device structure members. | ||
284 | * | ||
285 | * Few drivers should need to use this routine, since the most natural | ||
286 | * way to bind to an interface is to return the private data from | ||
287 | * the driver's probe() method. | ||
288 | * | ||
289 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | ||
290 | * writelock. So driver probe() entries don't need extra locking, | ||
291 | * but other call contexts may need to explicitly claim those locks. | ||
292 | */ | ||
293 | int usb_driver_claim_interface(struct usb_driver *driver, | ||
294 | struct usb_interface *iface, void* priv) | ||
295 | { | ||
296 | struct device *dev = &iface->dev; | ||
297 | struct usb_device *udev = interface_to_usbdev(iface); | ||
298 | int retval = 0; | ||
299 | |||
300 | if (dev->driver) | ||
301 | return -EBUSY; | ||
302 | |||
303 | dev->driver = &driver->drvwrap.driver; | ||
304 | usb_set_intfdata(iface, priv); | ||
305 | |||
306 | usb_pm_lock(udev); | ||
307 | iface->condition = USB_INTERFACE_BOUND; | ||
308 | mark_active(iface); | ||
309 | iface->pm_usage_cnt = !(driver->supports_autosuspend); | ||
310 | usb_pm_unlock(udev); | ||
311 | |||
312 | /* if interface was already added, bind now; else let | ||
313 | * the future device_add() bind it, bypassing probe() | ||
314 | */ | ||
315 | if (device_is_registered(dev)) | ||
316 | retval = device_bind_driver(dev); | ||
317 | |||
318 | return retval; | ||
319 | } | ||
320 | EXPORT_SYMBOL(usb_driver_claim_interface); | ||
321 | |||
322 | /** | ||
323 | * usb_driver_release_interface - unbind a driver from an interface | ||
324 | * @driver: the driver to be unbound | ||
325 | * @iface: the interface from which it will be unbound | ||
326 | * | ||
327 | * This can be used by drivers to release an interface without waiting | ||
328 | * for their disconnect() methods to be called. In typical cases this | ||
329 | * also causes the driver disconnect() method to be called. | ||
330 | * | ||
331 | * This call is synchronous, and may not be used in an interrupt context. | ||
332 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | ||
333 | * writelock. So driver disconnect() entries don't need extra locking, | ||
334 | * but other call contexts may need to explicitly claim those locks. | ||
335 | */ | ||
336 | void usb_driver_release_interface(struct usb_driver *driver, | ||
337 | struct usb_interface *iface) | ||
338 | { | ||
339 | struct device *dev = &iface->dev; | ||
340 | struct usb_device *udev = interface_to_usbdev(iface); | ||
341 | |||
342 | /* this should never happen, don't release something that's not ours */ | ||
343 | if (!dev->driver || dev->driver != &driver->drvwrap.driver) | ||
344 | return; | ||
345 | |||
346 | /* don't release from within disconnect() */ | ||
347 | if (iface->condition != USB_INTERFACE_BOUND) | ||
348 | return; | ||
349 | |||
350 | /* don't release if the interface hasn't been added yet */ | ||
351 | if (device_is_registered(dev)) { | ||
352 | iface->condition = USB_INTERFACE_UNBINDING; | ||
353 | device_release_driver(dev); | ||
354 | } | ||
355 | |||
356 | dev->driver = NULL; | ||
357 | usb_set_intfdata(iface, NULL); | ||
358 | |||
359 | usb_pm_lock(udev); | ||
360 | iface->condition = USB_INTERFACE_UNBOUND; | ||
361 | mark_quiesced(iface); | ||
362 | iface->needs_remote_wakeup = 0; | ||
363 | usb_pm_unlock(udev); | ||
364 | } | ||
365 | EXPORT_SYMBOL(usb_driver_release_interface); | ||
366 | |||
242 | /* returns 0 if no match, 1 if match */ | 367 | /* returns 0 if no match, 1 if match */ |
243 | static int usb_match_one_id(struct usb_interface *interface, | 368 | static int usb_match_one_id(struct usb_interface *interface, |
244 | const struct usb_device_id *id) | 369 | const struct usb_device_id *id) |
@@ -382,35 +507,223 @@ EXPORT_SYMBOL_GPL_FUTURE(usb_match_id); | |||
382 | 507 | ||
383 | int usb_device_match(struct device *dev, struct device_driver *drv) | 508 | int usb_device_match(struct device *dev, struct device_driver *drv) |
384 | { | 509 | { |
510 | /* devices and interfaces are handled separately */ | ||
511 | if (is_usb_device(dev)) { | ||
512 | |||
513 | /* interface drivers never match devices */ | ||
514 | if (!is_usb_device_driver(drv)) | ||
515 | return 0; | ||
516 | |||
517 | /* TODO: Add real matching code */ | ||
518 | return 1; | ||
519 | |||
520 | } else { | ||
521 | struct usb_interface *intf; | ||
522 | struct usb_driver *usb_drv; | ||
523 | const struct usb_device_id *id; | ||
524 | |||
525 | /* device drivers never match interfaces */ | ||
526 | if (is_usb_device_driver(drv)) | ||
527 | return 0; | ||
528 | |||
529 | intf = to_usb_interface(dev); | ||
530 | usb_drv = to_usb_driver(drv); | ||
531 | |||
532 | id = usb_match_id(intf, usb_drv->id_table); | ||
533 | if (id) | ||
534 | return 1; | ||
535 | |||
536 | id = usb_match_dynamic_id(intf, usb_drv); | ||
537 | if (id) | ||
538 | return 1; | ||
539 | } | ||
540 | |||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | #ifdef CONFIG_HOTPLUG | ||
545 | |||
546 | /* | ||
547 | * This sends an uevent to userspace, typically helping to load driver | ||
548 | * or other modules, configure the device, and more. Drivers can provide | ||
549 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. | ||
550 | * | ||
551 | * We're called either from khubd (the typical case) or from root hub | ||
552 | * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle | ||
553 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the | ||
554 | * device (and this configuration!) are still present. | ||
555 | */ | ||
556 | static int usb_uevent(struct device *dev, char **envp, int num_envp, | ||
557 | char *buffer, int buffer_size) | ||
558 | { | ||
385 | struct usb_interface *intf; | 559 | struct usb_interface *intf; |
386 | struct usb_driver *usb_drv; | 560 | struct usb_device *usb_dev; |
387 | const struct usb_device_id *id; | 561 | struct usb_host_interface *alt; |
562 | int i = 0; | ||
563 | int length = 0; | ||
388 | 564 | ||
389 | /* check for generic driver, which we don't match any device with */ | 565 | if (!dev) |
390 | if (drv == &usb_generic_driver) | 566 | return -ENODEV; |
391 | return 0; | ||
392 | 567 | ||
393 | intf = to_usb_interface(dev); | 568 | /* driver is often null here; dev_dbg() would oops */ |
394 | usb_drv = to_usb_driver(drv); | 569 | pr_debug ("usb %s: uevent\n", dev->bus_id); |
395 | 570 | ||
396 | id = usb_match_id(intf, usb_drv->id_table); | 571 | if (is_usb_device(dev)) { |
397 | if (id) | 572 | usb_dev = to_usb_device(dev); |
398 | return 1; | 573 | alt = NULL; |
574 | } else { | ||
575 | intf = to_usb_interface(dev); | ||
576 | usb_dev = interface_to_usbdev(intf); | ||
577 | alt = intf->cur_altsetting; | ||
578 | } | ||
579 | |||
580 | if (usb_dev->devnum < 0) { | ||
581 | pr_debug ("usb %s: already deleted?\n", dev->bus_id); | ||
582 | return -ENODEV; | ||
583 | } | ||
584 | if (!usb_dev->bus) { | ||
585 | pr_debug ("usb %s: bus removed?\n", dev->bus_id); | ||
586 | return -ENODEV; | ||
587 | } | ||
588 | |||
589 | #ifdef CONFIG_USB_DEVICEFS | ||
590 | /* If this is available, userspace programs can directly read | ||
591 | * all the device descriptors we don't tell them about. Or | ||
592 | * even act as usermode drivers. | ||
593 | * | ||
594 | * FIXME reduce hardwired intelligence here | ||
595 | */ | ||
596 | if (add_uevent_var(envp, num_envp, &i, | ||
597 | buffer, buffer_size, &length, | ||
598 | "DEVICE=/proc/bus/usb/%03d/%03d", | ||
599 | usb_dev->bus->busnum, usb_dev->devnum)) | ||
600 | return -ENOMEM; | ||
601 | #endif | ||
602 | |||
603 | /* per-device configurations are common */ | ||
604 | if (add_uevent_var(envp, num_envp, &i, | ||
605 | buffer, buffer_size, &length, | ||
606 | "PRODUCT=%x/%x/%x", | ||
607 | le16_to_cpu(usb_dev->descriptor.idVendor), | ||
608 | le16_to_cpu(usb_dev->descriptor.idProduct), | ||
609 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) | ||
610 | return -ENOMEM; | ||
611 | |||
612 | /* class-based driver binding models */ | ||
613 | if (add_uevent_var(envp, num_envp, &i, | ||
614 | buffer, buffer_size, &length, | ||
615 | "TYPE=%d/%d/%d", | ||
616 | usb_dev->descriptor.bDeviceClass, | ||
617 | usb_dev->descriptor.bDeviceSubClass, | ||
618 | usb_dev->descriptor.bDeviceProtocol)) | ||
619 | return -ENOMEM; | ||
620 | |||
621 | if (!is_usb_device(dev)) { | ||
622 | |||
623 | if (add_uevent_var(envp, num_envp, &i, | ||
624 | buffer, buffer_size, &length, | ||
625 | "INTERFACE=%d/%d/%d", | ||
626 | alt->desc.bInterfaceClass, | ||
627 | alt->desc.bInterfaceSubClass, | ||
628 | alt->desc.bInterfaceProtocol)) | ||
629 | return -ENOMEM; | ||
630 | |||
631 | if (add_uevent_var(envp, num_envp, &i, | ||
632 | buffer, buffer_size, &length, | ||
633 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", | ||
634 | le16_to_cpu(usb_dev->descriptor.idVendor), | ||
635 | le16_to_cpu(usb_dev->descriptor.idProduct), | ||
636 | le16_to_cpu(usb_dev->descriptor.bcdDevice), | ||
637 | usb_dev->descriptor.bDeviceClass, | ||
638 | usb_dev->descriptor.bDeviceSubClass, | ||
639 | usb_dev->descriptor.bDeviceProtocol, | ||
640 | alt->desc.bInterfaceClass, | ||
641 | alt->desc.bInterfaceSubClass, | ||
642 | alt->desc.bInterfaceProtocol)) | ||
643 | return -ENOMEM; | ||
644 | } | ||
645 | |||
646 | envp[i] = NULL; | ||
399 | 647 | ||
400 | id = usb_match_dynamic_id(intf, usb_drv); | ||
401 | if (id) | ||
402 | return 1; | ||
403 | return 0; | 648 | return 0; |
404 | } | 649 | } |
405 | 650 | ||
651 | #else | ||
652 | |||
653 | static int usb_uevent(struct device *dev, char **envp, | ||
654 | int num_envp, char *buffer, int buffer_size) | ||
655 | { | ||
656 | return -ENODEV; | ||
657 | } | ||
658 | |||
659 | #endif /* CONFIG_HOTPLUG */ | ||
660 | |||
661 | /** | ||
662 | * usb_register_device_driver - register a USB device (not interface) driver | ||
663 | * @new_udriver: USB operations for the device driver | ||
664 | * @owner: module owner of this driver. | ||
665 | * | ||
666 | * Registers a USB device driver with the USB core. The list of | ||
667 | * unattached devices will be rescanned whenever a new driver is | ||
668 | * added, allowing the new driver to attach to any recognized devices. | ||
669 | * Returns a negative error code on failure and 0 on success. | ||
670 | */ | ||
671 | int usb_register_device_driver(struct usb_device_driver *new_udriver, | ||
672 | struct module *owner) | ||
673 | { | ||
674 | int retval = 0; | ||
675 | |||
676 | if (usb_disabled()) | ||
677 | return -ENODEV; | ||
678 | |||
679 | new_udriver->drvwrap.for_devices = 1; | ||
680 | new_udriver->drvwrap.driver.name = (char *) new_udriver->name; | ||
681 | new_udriver->drvwrap.driver.bus = &usb_bus_type; | ||
682 | new_udriver->drvwrap.driver.probe = usb_probe_device; | ||
683 | new_udriver->drvwrap.driver.remove = usb_unbind_device; | ||
684 | new_udriver->drvwrap.driver.owner = owner; | ||
685 | |||
686 | retval = driver_register(&new_udriver->drvwrap.driver); | ||
687 | |||
688 | if (!retval) { | ||
689 | pr_info("%s: registered new device driver %s\n", | ||
690 | usbcore_name, new_udriver->name); | ||
691 | usbfs_update_special(); | ||
692 | } else { | ||
693 | printk(KERN_ERR "%s: error %d registering device " | ||
694 | " driver %s\n", | ||
695 | usbcore_name, retval, new_udriver->name); | ||
696 | } | ||
697 | |||
698 | return retval; | ||
699 | } | ||
700 | EXPORT_SYMBOL_GPL(usb_register_device_driver); | ||
701 | |||
702 | /** | ||
703 | * usb_deregister_device_driver - unregister a USB device (not interface) driver | ||
704 | * @udriver: USB operations of the device driver to unregister | ||
705 | * Context: must be able to sleep | ||
706 | * | ||
707 | * Unlinks the specified driver from the internal USB driver list. | ||
708 | */ | ||
709 | void usb_deregister_device_driver(struct usb_device_driver *udriver) | ||
710 | { | ||
711 | pr_info("%s: deregistering device driver %s\n", | ||
712 | usbcore_name, udriver->name); | ||
713 | |||
714 | driver_unregister(&udriver->drvwrap.driver); | ||
715 | usbfs_update_special(); | ||
716 | } | ||
717 | EXPORT_SYMBOL_GPL(usb_deregister_device_driver); | ||
718 | |||
406 | /** | 719 | /** |
407 | * usb_register_driver - register a USB driver | 720 | * usb_register_driver - register a USB interface driver |
408 | * @new_driver: USB operations for the driver | 721 | * @new_driver: USB operations for the interface driver |
409 | * @owner: module owner of this driver. | 722 | * @owner: module owner of this driver. |
410 | * | 723 | * |
411 | * Registers a USB driver with the USB core. The list of unattached | 724 | * Registers a USB interface driver with the USB core. The list of |
412 | * interfaces will be rescanned whenever a new driver is added, allowing | 725 | * unattached interfaces will be rescanned whenever a new driver is |
413 | * the new driver to attach to any recognized devices. | 726 | * added, allowing the new driver to attach to any recognized interfaces. |
414 | * Returns a negative error code on failure and 0 on success. | 727 | * Returns a negative error code on failure and 0 on success. |
415 | * | 728 | * |
416 | * NOTE: if you want your driver to use the USB major number, you must call | 729 | * NOTE: if you want your driver to use the USB major number, you must call |
@@ -424,23 +737,25 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner) | |||
424 | if (usb_disabled()) | 737 | if (usb_disabled()) |
425 | return -ENODEV; | 738 | return -ENODEV; |
426 | 739 | ||
427 | new_driver->driver.name = (char *)new_driver->name; | 740 | new_driver->drvwrap.for_devices = 0; |
428 | new_driver->driver.bus = &usb_bus_type; | 741 | new_driver->drvwrap.driver.name = (char *) new_driver->name; |
429 | new_driver->driver.probe = usb_probe_interface; | 742 | new_driver->drvwrap.driver.bus = &usb_bus_type; |
430 | new_driver->driver.remove = usb_unbind_interface; | 743 | new_driver->drvwrap.driver.probe = usb_probe_interface; |
431 | new_driver->driver.owner = owner; | 744 | new_driver->drvwrap.driver.remove = usb_unbind_interface; |
745 | new_driver->drvwrap.driver.owner = owner; | ||
432 | spin_lock_init(&new_driver->dynids.lock); | 746 | spin_lock_init(&new_driver->dynids.lock); |
433 | INIT_LIST_HEAD(&new_driver->dynids.list); | 747 | INIT_LIST_HEAD(&new_driver->dynids.list); |
434 | 748 | ||
435 | retval = driver_register(&new_driver->driver); | 749 | retval = driver_register(&new_driver->drvwrap.driver); |
436 | 750 | ||
437 | if (!retval) { | 751 | if (!retval) { |
438 | pr_info("%s: registered new driver %s\n", | 752 | pr_info("%s: registered new interface driver %s\n", |
439 | usbcore_name, new_driver->name); | 753 | usbcore_name, new_driver->name); |
440 | usbfs_update_special(); | 754 | usbfs_update_special(); |
441 | usb_create_newid_file(new_driver); | 755 | usb_create_newid_file(new_driver); |
442 | } else { | 756 | } else { |
443 | printk(KERN_ERR "%s: error %d registering driver %s\n", | 757 | printk(KERN_ERR "%s: error %d registering interface " |
758 | " driver %s\n", | ||
444 | usbcore_name, retval, new_driver->name); | 759 | usbcore_name, retval, new_driver->name); |
445 | } | 760 | } |
446 | 761 | ||
@@ -449,8 +764,8 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner) | |||
449 | EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); | 764 | EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); |
450 | 765 | ||
451 | /** | 766 | /** |
452 | * usb_deregister - unregister a USB driver | 767 | * usb_deregister - unregister a USB interface driver |
453 | * @driver: USB operations of the driver to unregister | 768 | * @driver: USB operations of the interface driver to unregister |
454 | * Context: must be able to sleep | 769 | * Context: must be able to sleep |
455 | * | 770 | * |
456 | * Unlinks the specified driver from the internal USB driver list. | 771 | * Unlinks the specified driver from the internal USB driver list. |
@@ -461,12 +776,554 @@ EXPORT_SYMBOL_GPL_FUTURE(usb_register_driver); | |||
461 | */ | 776 | */ |
462 | void usb_deregister(struct usb_driver *driver) | 777 | void usb_deregister(struct usb_driver *driver) |
463 | { | 778 | { |
464 | pr_info("%s: deregistering driver %s\n", usbcore_name, driver->name); | 779 | pr_info("%s: deregistering interface driver %s\n", |
780 | usbcore_name, driver->name); | ||
465 | 781 | ||
466 | usb_remove_newid_file(driver); | 782 | usb_remove_newid_file(driver); |
467 | usb_free_dynids(driver); | 783 | usb_free_dynids(driver); |
468 | driver_unregister(&driver->driver); | 784 | driver_unregister(&driver->drvwrap.driver); |
469 | 785 | ||
470 | usbfs_update_special(); | 786 | usbfs_update_special(); |
471 | } | 787 | } |
472 | EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); | 788 | EXPORT_SYMBOL_GPL_FUTURE(usb_deregister); |
789 | |||
790 | #ifdef CONFIG_PM | ||
791 | |||
792 | /* Caller has locked udev's pm_mutex */ | ||
793 | static int suspend_device(struct usb_device *udev, pm_message_t msg) | ||
794 | { | ||
795 | struct usb_device_driver *udriver; | ||
796 | int status = 0; | ||
797 | |||
798 | if (udev->state == USB_STATE_NOTATTACHED || | ||
799 | udev->state == USB_STATE_SUSPENDED) | ||
800 | goto done; | ||
801 | |||
802 | /* For devices that don't have a driver, we do a standard suspend. */ | ||
803 | if (udev->dev.driver == NULL) { | ||
804 | udev->do_remote_wakeup = 0; | ||
805 | status = usb_port_suspend(udev); | ||
806 | goto done; | ||
807 | } | ||
808 | |||
809 | udriver = to_usb_device_driver(udev->dev.driver); | ||
810 | status = udriver->suspend(udev, msg); | ||
811 | |||
812 | done: | ||
813 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | ||
814 | if (status == 0) | ||
815 | udev->dev.power.power_state.event = msg.event; | ||
816 | return status; | ||
817 | } | ||
818 | |||
819 | /* Caller has locked udev's pm_mutex */ | ||
820 | static int resume_device(struct usb_device *udev) | ||
821 | { | ||
822 | struct usb_device_driver *udriver; | ||
823 | int status = 0; | ||
824 | |||
825 | if (udev->state == USB_STATE_NOTATTACHED || | ||
826 | udev->state != USB_STATE_SUSPENDED) | ||
827 | goto done; | ||
828 | |||
829 | /* Can't resume it if it doesn't have a driver. */ | ||
830 | if (udev->dev.driver == NULL) { | ||
831 | status = -ENOTCONN; | ||
832 | goto done; | ||
833 | } | ||
834 | |||
835 | udriver = to_usb_device_driver(udev->dev.driver); | ||
836 | status = udriver->resume(udev); | ||
837 | |||
838 | done: | ||
839 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | ||
840 | if (status == 0) | ||
841 | udev->dev.power.power_state.event = PM_EVENT_ON; | ||
842 | return status; | ||
843 | } | ||
844 | |||
845 | /* Caller has locked intf's usb_device's pm mutex */ | ||
846 | static int suspend_interface(struct usb_interface *intf, pm_message_t msg) | ||
847 | { | ||
848 | struct usb_driver *driver; | ||
849 | int status = 0; | ||
850 | |||
851 | /* with no hardware, USB interfaces only use FREEZE and ON states */ | ||
852 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || | ||
853 | !is_active(intf)) | ||
854 | goto done; | ||
855 | |||
856 | if (intf->condition == USB_INTERFACE_UNBOUND) /* This can't happen */ | ||
857 | goto done; | ||
858 | driver = to_usb_driver(intf->dev.driver); | ||
859 | |||
860 | if (driver->suspend && driver->resume) { | ||
861 | status = driver->suspend(intf, msg); | ||
862 | if (status == 0) | ||
863 | mark_quiesced(intf); | ||
864 | else if (!interface_to_usbdev(intf)->auto_pm) | ||
865 | dev_err(&intf->dev, "%s error %d\n", | ||
866 | "suspend", status); | ||
867 | } else { | ||
868 | // FIXME else if there's no suspend method, disconnect... | ||
869 | // Not possible if auto_pm is set... | ||
870 | dev_warn(&intf->dev, "no suspend for driver %s?\n", | ||
871 | driver->name); | ||
872 | mark_quiesced(intf); | ||
873 | } | ||
874 | |||
875 | done: | ||
876 | // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); | ||
877 | if (status == 0) | ||
878 | intf->dev.power.power_state.event = msg.event; | ||
879 | return status; | ||
880 | } | ||
881 | |||
882 | /* Caller has locked intf's usb_device's pm_mutex */ | ||
883 | static int resume_interface(struct usb_interface *intf) | ||
884 | { | ||
885 | struct usb_driver *driver; | ||
886 | int status = 0; | ||
887 | |||
888 | if (interface_to_usbdev(intf)->state == USB_STATE_NOTATTACHED || | ||
889 | is_active(intf)) | ||
890 | goto done; | ||
891 | |||
892 | /* Don't let autoresume interfere with unbinding */ | ||
893 | if (intf->condition == USB_INTERFACE_UNBINDING) | ||
894 | goto done; | ||
895 | |||
896 | /* Can't resume it if it doesn't have a driver. */ | ||
897 | if (intf->condition == USB_INTERFACE_UNBOUND) { | ||
898 | status = -ENOTCONN; | ||
899 | goto done; | ||
900 | } | ||
901 | driver = to_usb_driver(intf->dev.driver); | ||
902 | |||
903 | if (driver->resume) { | ||
904 | status = driver->resume(intf); | ||
905 | if (status) | ||
906 | dev_err(&intf->dev, "%s error %d\n", | ||
907 | "resume", status); | ||
908 | else | ||
909 | mark_active(intf); | ||
910 | } else { | ||
911 | dev_warn(&intf->dev, "no resume for driver %s?\n", | ||
912 | driver->name); | ||
913 | mark_active(intf); | ||
914 | } | ||
915 | |||
916 | done: | ||
917 | // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status); | ||
918 | if (status == 0) | ||
919 | intf->dev.power.power_state.event = PM_EVENT_ON; | ||
920 | return status; | ||
921 | } | ||
922 | |||
923 | /** | ||
924 | * usb_suspend_both - suspend a USB device and its interfaces | ||
925 | * @udev: the usb_device to suspend | ||
926 | * @msg: Power Management message describing this state transition | ||
927 | * | ||
928 | * This is the central routine for suspending USB devices. It calls the | ||
929 | * suspend methods for all the interface drivers in @udev and then calls | ||
930 | * the suspend method for @udev itself. If an error occurs at any stage, | ||
931 | * all the interfaces which were suspended are resumed so that they remain | ||
932 | * in the same state as the device. | ||
933 | * | ||
934 | * If an autosuspend is in progress (@udev->auto_pm is set), the routine | ||
935 | * checks first to make sure that neither the device itself or any of its | ||
936 | * active interfaces is in use (pm_usage_cnt is greater than 0). If they | ||
937 | * are, the autosuspend fails. | ||
938 | * | ||
939 | * If the suspend succeeds, the routine recursively queues an autosuspend | ||
940 | * request for @udev's parent device, thereby propagating the change up | ||
941 | * the device tree. If all of the parent's children are now suspended, | ||
942 | * the parent will autosuspend in turn. | ||
943 | * | ||
944 | * The suspend method calls are subject to mutual exclusion under control | ||
945 | * of @udev's pm_mutex. Many of these calls are also under the protection | ||
946 | * of @udev's device lock (including all requests originating outside the | ||
947 | * USB subsystem), but autosuspend requests generated by a child device or | ||
948 | * interface driver may not be. Usbcore will insure that the method calls | ||
949 | * do not arrive during bind, unbind, or reset operations. However, drivers | ||
950 | * must be prepared to handle suspend calls arriving at unpredictable times. | ||
951 | * The only way to block such calls is to do an autoresume (preventing | ||
952 | * autosuspends) while holding @udev's device lock (preventing outside | ||
953 | * suspends). | ||
954 | * | ||
955 | * The caller must hold @udev->pm_mutex. | ||
956 | * | ||
957 | * This routine can run only in process context. | ||
958 | */ | ||
959 | int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | ||
960 | { | ||
961 | int status = 0; | ||
962 | int i = 0; | ||
963 | struct usb_interface *intf; | ||
964 | struct usb_device *parent = udev->parent; | ||
965 | |||
966 | cancel_delayed_work(&udev->autosuspend); | ||
967 | if (udev->state == USB_STATE_NOTATTACHED) | ||
968 | return 0; | ||
969 | if (udev->state == USB_STATE_SUSPENDED) | ||
970 | return 0; | ||
971 | |||
972 | udev->do_remote_wakeup = device_may_wakeup(&udev->dev); | ||
973 | |||
974 | /* For autosuspend, fail fast if anything is in use. | ||
975 | * Also fail if any interfaces require remote wakeup but it | ||
976 | * isn't available. */ | ||
977 | if (udev->auto_pm) { | ||
978 | if (udev->pm_usage_cnt > 0) | ||
979 | return -EBUSY; | ||
980 | if (udev->actconfig) { | ||
981 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
982 | intf = udev->actconfig->interface[i]; | ||
983 | if (!is_active(intf)) | ||
984 | continue; | ||
985 | if (intf->pm_usage_cnt > 0) | ||
986 | return -EBUSY; | ||
987 | if (intf->needs_remote_wakeup && | ||
988 | !udev->do_remote_wakeup) { | ||
989 | dev_dbg(&udev->dev, | ||
990 | "remote wakeup needed for autosuspend\n"); | ||
991 | return -EOPNOTSUPP; | ||
992 | } | ||
993 | } | ||
994 | i = 0; | ||
995 | } | ||
996 | } | ||
997 | |||
998 | /* Suspend all the interfaces and then udev itself */ | ||
999 | if (udev->actconfig) { | ||
1000 | for (; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1001 | intf = udev->actconfig->interface[i]; | ||
1002 | status = suspend_interface(intf, msg); | ||
1003 | if (status != 0) | ||
1004 | break; | ||
1005 | } | ||
1006 | } | ||
1007 | if (status == 0) | ||
1008 | status = suspend_device(udev, msg); | ||
1009 | |||
1010 | /* If the suspend failed, resume interfaces that did get suspended */ | ||
1011 | if (status != 0) { | ||
1012 | while (--i >= 0) { | ||
1013 | intf = udev->actconfig->interface[i]; | ||
1014 | resume_interface(intf); | ||
1015 | } | ||
1016 | |||
1017 | /* If the suspend succeeded, propagate it up the tree */ | ||
1018 | } else if (parent) | ||
1019 | usb_autosuspend_device(parent, 0); | ||
1020 | |||
1021 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | ||
1022 | return status; | ||
1023 | } | ||
1024 | |||
1025 | /** | ||
1026 | * usb_resume_both - resume a USB device and its interfaces | ||
1027 | * @udev: the usb_device to resume | ||
1028 | * | ||
1029 | * This is the central routine for resuming USB devices. It calls the | ||
1030 | * the resume method for @udev and then calls the resume methods for all | ||
1031 | * the interface drivers in @udev. | ||
1032 | * | ||
1033 | * Before starting the resume, the routine calls itself recursively for | ||
1034 | * the parent device of @udev, thereby propagating the change up the device | ||
1035 | * tree and assuring that @udev will be able to resume. If the parent is | ||
1036 | * unable to resume successfully, the routine fails. | ||
1037 | * | ||
1038 | * The resume method calls are subject to mutual exclusion under control | ||
1039 | * of @udev's pm_mutex. Many of these calls are also under the protection | ||
1040 | * of @udev's device lock (including all requests originating outside the | ||
1041 | * USB subsystem), but autoresume requests generated by a child device or | ||
1042 | * interface driver may not be. Usbcore will insure that the method calls | ||
1043 | * do not arrive during bind, unbind, or reset operations. However, drivers | ||
1044 | * must be prepared to handle resume calls arriving at unpredictable times. | ||
1045 | * The only way to block such calls is to do an autoresume (preventing | ||
1046 | * other autoresumes) while holding @udev's device lock (preventing outside | ||
1047 | * resumes). | ||
1048 | * | ||
1049 | * The caller must hold @udev->pm_mutex. | ||
1050 | * | ||
1051 | * This routine can run only in process context. | ||
1052 | */ | ||
1053 | int usb_resume_both(struct usb_device *udev) | ||
1054 | { | ||
1055 | int status = 0; | ||
1056 | int i; | ||
1057 | struct usb_interface *intf; | ||
1058 | struct usb_device *parent = udev->parent; | ||
1059 | |||
1060 | cancel_delayed_work(&udev->autosuspend); | ||
1061 | if (udev->state == USB_STATE_NOTATTACHED) | ||
1062 | return -ENODEV; | ||
1063 | |||
1064 | /* Propagate the resume up the tree, if necessary */ | ||
1065 | if (udev->state == USB_STATE_SUSPENDED) { | ||
1066 | if (parent) { | ||
1067 | usb_pm_lock(parent); | ||
1068 | parent->auto_pm = 1; | ||
1069 | status = usb_resume_both(parent); | ||
1070 | } else { | ||
1071 | |||
1072 | /* We can't progagate beyond the USB subsystem, | ||
1073 | * so if a root hub's controller is suspended | ||
1074 | * then we're stuck. */ | ||
1075 | if (udev->dev.parent->power.power_state.event != | ||
1076 | PM_EVENT_ON) | ||
1077 | status = -EHOSTUNREACH; | ||
1078 | } | ||
1079 | if (status == 0) | ||
1080 | status = resume_device(udev); | ||
1081 | if (parent) | ||
1082 | usb_pm_unlock(parent); | ||
1083 | } else { | ||
1084 | |||
1085 | /* Needed only for setting udev->dev.power.power_state.event | ||
1086 | * and for possible debugging message. */ | ||
1087 | status = resume_device(udev); | ||
1088 | } | ||
1089 | |||
1090 | /* Now the parent won't suspend until we are finished */ | ||
1091 | |||
1092 | if (status == 0 && udev->actconfig) { | ||
1093 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1094 | intf = udev->actconfig->interface[i]; | ||
1095 | resume_interface(intf); | ||
1096 | } | ||
1097 | } | ||
1098 | |||
1099 | // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status); | ||
1100 | return status; | ||
1101 | } | ||
1102 | |||
1103 | #ifdef CONFIG_USB_SUSPEND | ||
1104 | |||
1105 | /** | ||
1106 | * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces | ||
1107 | * @udev: the usb_device to autosuspend | ||
1108 | * @dec_usage_cnt: flag to decrement @udev's PM-usage counter | ||
1109 | * | ||
1110 | * This routine should be called when a core subsystem is finished using | ||
1111 | * @udev and wants to allow it to autosuspend. Examples would be when | ||
1112 | * @udev's device file in usbfs is closed or after a configuration change. | ||
1113 | * | ||
1114 | * @dec_usage_cnt should be 1 if the subsystem previously incremented | ||
1115 | * @udev's usage counter (such as by passing 1 to usb_autoresume_device); | ||
1116 | * otherwise it should be 0. | ||
1117 | * | ||
1118 | * If the usage counter for @udev or any of its active interfaces is greater | ||
1119 | * than 0, the autosuspend request will not be queued. (If an interface | ||
1120 | * driver does not support autosuspend then its usage counter is permanently | ||
1121 | * positive.) Likewise, if an interface driver requires remote-wakeup | ||
1122 | * capability during autosuspend but remote wakeup is disabled, the | ||
1123 | * autosuspend will fail. | ||
1124 | * | ||
1125 | * Often the caller will hold @udev's device lock, but this is not | ||
1126 | * necessary. | ||
1127 | * | ||
1128 | * This routine can run only in process context. | ||
1129 | */ | ||
1130 | void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt) | ||
1131 | { | ||
1132 | usb_pm_lock(udev); | ||
1133 | udev->pm_usage_cnt -= dec_usage_cnt; | ||
1134 | if (udev->pm_usage_cnt <= 0) | ||
1135 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | ||
1136 | USB_AUTOSUSPEND_DELAY); | ||
1137 | usb_pm_unlock(udev); | ||
1138 | // dev_dbg(&udev->dev, "%s: cnt %d\n", | ||
1139 | // __FUNCTION__, udev->pm_usage_cnt); | ||
1140 | } | ||
1141 | |||
1142 | /** | ||
1143 | * usb_autoresume_device - immediately autoresume a USB device and its interfaces | ||
1144 | * @udev: the usb_device to autoresume | ||
1145 | * @inc_usage_cnt: flag to increment @udev's PM-usage counter | ||
1146 | * | ||
1147 | * This routine should be called when a core subsystem wants to use @udev | ||
1148 | * and needs to guarantee that it is not suspended. In addition, the | ||
1149 | * caller can prevent @udev from being autosuspended subsequently. (Note | ||
1150 | * that this will not prevent suspend events originating in the PM core.) | ||
1151 | * Examples would be when @udev's device file in usbfs is opened (autosuspend | ||
1152 | * should be prevented until the file is closed) or when a remote-wakeup | ||
1153 | * request is received (later autosuspends should not be prevented). | ||
1154 | * | ||
1155 | * @inc_usage_cnt should be 1 to increment @udev's usage counter and prevent | ||
1156 | * autosuspends. This prevention will persist until the usage counter is | ||
1157 | * decremented again (such as by passing 1 to usb_autosuspend_device). | ||
1158 | * Otherwise @inc_usage_cnt should be 0 to leave the usage counter unchanged. | ||
1159 | * Regardless, if the autoresume fails then the usage counter is not | ||
1160 | * incremented. | ||
1161 | * | ||
1162 | * Often the caller will hold @udev's device lock, but this is not | ||
1163 | * necessary (and attempting it might cause deadlock). | ||
1164 | * | ||
1165 | * This routine can run only in process context. | ||
1166 | */ | ||
1167 | int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt) | ||
1168 | { | ||
1169 | int status; | ||
1170 | |||
1171 | usb_pm_lock(udev); | ||
1172 | udev->pm_usage_cnt += inc_usage_cnt; | ||
1173 | udev->auto_pm = 1; | ||
1174 | status = usb_resume_both(udev); | ||
1175 | if (status != 0) | ||
1176 | udev->pm_usage_cnt -= inc_usage_cnt; | ||
1177 | usb_pm_unlock(udev); | ||
1178 | // dev_dbg(&udev->dev, "%s: status %d cnt %d\n", | ||
1179 | // __FUNCTION__, status, udev->pm_usage_cnt); | ||
1180 | return status; | ||
1181 | } | ||
1182 | |||
1183 | /** | ||
1184 | * usb_autopm_put_interface - decrement a USB interface's PM-usage counter | ||
1185 | * @intf: the usb_interface whose counter should be decremented | ||
1186 | * | ||
1187 | * This routine should be called by an interface driver when it is | ||
1188 | * finished using @intf and wants to allow it to autosuspend. A typical | ||
1189 | * example would be a character-device driver when its device file is | ||
1190 | * closed. | ||
1191 | * | ||
1192 | * The routine decrements @intf's usage counter. When the counter reaches | ||
1193 | * 0, a delayed autosuspend request for @intf's device is queued. When | ||
1194 | * the delay expires, if @intf->pm_usage_cnt is still <= 0 along with all | ||
1195 | * the other usage counters for the sibling interfaces and @intf's | ||
1196 | * usb_device, the device and all its interfaces will be autosuspended. | ||
1197 | * | ||
1198 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The | ||
1199 | * core will not change its value other than the increment and decrement | ||
1200 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver | ||
1201 | * may use this simple counter-oriented discipline or may set the value | ||
1202 | * any way it likes. | ||
1203 | * | ||
1204 | * If the driver has set @intf->needs_remote_wakeup then autosuspend will | ||
1205 | * take place only if the device's remote-wakeup facility is enabled. | ||
1206 | * | ||
1207 | * Suspend method calls queued by this routine can arrive at any time | ||
1208 | * while @intf is resumed and its usage counter is equal to 0. They are | ||
1209 | * not protected by the usb_device's lock but only by its pm_mutex. | ||
1210 | * Drivers must provide their own synchronization. | ||
1211 | * | ||
1212 | * This routine can run only in process context. | ||
1213 | */ | ||
1214 | void usb_autopm_put_interface(struct usb_interface *intf) | ||
1215 | { | ||
1216 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1217 | |||
1218 | usb_pm_lock(udev); | ||
1219 | if (intf->condition != USB_INTERFACE_UNBOUND && | ||
1220 | --intf->pm_usage_cnt <= 0) { | ||
1221 | queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, | ||
1222 | USB_AUTOSUSPEND_DELAY); | ||
1223 | } | ||
1224 | usb_pm_unlock(udev); | ||
1225 | // dev_dbg(&intf->dev, "%s: cnt %d\n", | ||
1226 | // __FUNCTION__, intf->pm_usage_cnt); | ||
1227 | } | ||
1228 | EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | ||
1229 | |||
1230 | /** | ||
1231 | * usb_autopm_get_interface - increment a USB interface's PM-usage counter | ||
1232 | * @intf: the usb_interface whose counter should be incremented | ||
1233 | * | ||
1234 | * This routine should be called by an interface driver when it wants to | ||
1235 | * use @intf and needs to guarantee that it is not suspended. In addition, | ||
1236 | * the routine prevents @intf from being autosuspended subsequently. (Note | ||
1237 | * that this will not prevent suspend events originating in the PM core.) | ||
1238 | * This prevention will persist until usb_autopm_put_interface() is called | ||
1239 | * or @intf is unbound. A typical example would be a character-device | ||
1240 | * driver when its device file is opened. | ||
1241 | * | ||
1242 | * The routine increments @intf's usage counter. So long as the counter | ||
1243 | * is greater than 0, autosuspend will not be allowed for @intf or its | ||
1244 | * usb_device. When the driver is finished using @intf it should call | ||
1245 | * usb_autopm_put_interface() to decrement the usage counter and queue | ||
1246 | * a delayed autosuspend request (if the counter is <= 0). | ||
1247 | * | ||
1248 | * Note that @intf->pm_usage_cnt is owned by the interface driver. The | ||
1249 | * core will not change its value other than the increment and decrement | ||
1250 | * in usb_autopm_get_interface and usb_autopm_put_interface. The driver | ||
1251 | * may use this simple counter-oriented discipline or may set the value | ||
1252 | * any way it likes. | ||
1253 | * | ||
1254 | * Resume method calls generated by this routine can arrive at any time | ||
1255 | * while @intf is suspended. They are not protected by the usb_device's | ||
1256 | * lock but only by its pm_mutex. Drivers must provide their own | ||
1257 | * synchronization. | ||
1258 | * | ||
1259 | * This routine can run only in process context. | ||
1260 | */ | ||
1261 | int usb_autopm_get_interface(struct usb_interface *intf) | ||
1262 | { | ||
1263 | struct usb_device *udev = interface_to_usbdev(intf); | ||
1264 | int status; | ||
1265 | |||
1266 | usb_pm_lock(udev); | ||
1267 | if (intf->condition == USB_INTERFACE_UNBOUND) | ||
1268 | status = -ENODEV; | ||
1269 | else { | ||
1270 | ++intf->pm_usage_cnt; | ||
1271 | udev->auto_pm = 1; | ||
1272 | status = usb_resume_both(udev); | ||
1273 | if (status != 0) | ||
1274 | --intf->pm_usage_cnt; | ||
1275 | } | ||
1276 | usb_pm_unlock(udev); | ||
1277 | // dev_dbg(&intf->dev, "%s: status %d cnt %d\n", | ||
1278 | // __FUNCTION__, status, intf->pm_usage_cnt); | ||
1279 | return status; | ||
1280 | } | ||
1281 | EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | ||
1282 | |||
1283 | #endif /* CONFIG_USB_SUSPEND */ | ||
1284 | |||
1285 | static int usb_suspend(struct device *dev, pm_message_t message) | ||
1286 | { | ||
1287 | int status; | ||
1288 | |||
1289 | if (is_usb_device(dev)) { | ||
1290 | struct usb_device *udev = to_usb_device(dev); | ||
1291 | |||
1292 | usb_pm_lock(udev); | ||
1293 | udev->auto_pm = 0; | ||
1294 | status = usb_suspend_both(udev, message); | ||
1295 | usb_pm_unlock(udev); | ||
1296 | } else | ||
1297 | status = 0; | ||
1298 | return status; | ||
1299 | } | ||
1300 | |||
1301 | static int usb_resume(struct device *dev) | ||
1302 | { | ||
1303 | int status; | ||
1304 | |||
1305 | if (is_usb_device(dev)) { | ||
1306 | struct usb_device *udev = to_usb_device(dev); | ||
1307 | |||
1308 | usb_pm_lock(udev); | ||
1309 | udev->auto_pm = 0; | ||
1310 | status = usb_resume_both(udev); | ||
1311 | usb_pm_unlock(udev); | ||
1312 | |||
1313 | /* Rebind drivers that had no suspend method? */ | ||
1314 | } else | ||
1315 | status = 0; | ||
1316 | return status; | ||
1317 | } | ||
1318 | |||
1319 | #endif /* CONFIG_PM */ | ||
1320 | |||
1321 | struct bus_type usb_bus_type = { | ||
1322 | .name = "usb", | ||
1323 | .match = usb_device_match, | ||
1324 | .uevent = usb_uevent, | ||
1325 | #ifdef CONFIG_PM | ||
1326 | .suspend = usb_suspend, | ||
1327 | .resume = usb_resume, | ||
1328 | #endif | ||
1329 | }; | ||
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index 247b5a4913a8..3ebb90149e93 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -207,9 +207,9 @@ static void ep_device_release(struct device *dev) | |||
207 | kfree(ep_dev); | 207 | kfree(ep_dev); |
208 | } | 208 | } |
209 | 209 | ||
210 | void usb_create_ep_files(struct device *parent, | 210 | int usb_create_ep_files(struct device *parent, |
211 | struct usb_host_endpoint *endpoint, | 211 | struct usb_host_endpoint *endpoint, |
212 | struct usb_device *udev) | 212 | struct usb_device *udev) |
213 | { | 213 | { |
214 | char name[8]; | 214 | char name[8]; |
215 | struct ep_device *ep_dev; | 215 | struct ep_device *ep_dev; |
@@ -242,19 +242,33 @@ void usb_create_ep_files(struct device *parent, | |||
242 | retval = device_register(&ep_dev->dev); | 242 | retval = device_register(&ep_dev->dev); |
243 | if (retval) | 243 | if (retval) |
244 | goto error; | 244 | goto error; |
245 | sysfs_create_group(&ep_dev->dev.kobj, &ep_dev_attr_grp); | 245 | retval = sysfs_create_group(&ep_dev->dev.kobj, &ep_dev_attr_grp); |
246 | if (retval) | ||
247 | goto error_group; | ||
246 | 248 | ||
247 | endpoint->ep_dev = ep_dev; | 249 | endpoint->ep_dev = ep_dev; |
248 | 250 | ||
249 | /* create the symlink to the old-style "ep_XX" directory */ | 251 | /* create the symlink to the old-style "ep_XX" directory */ |
250 | sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); | 252 | sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); |
251 | sysfs_create_link(&parent->kobj, &endpoint->ep_dev->dev.kobj, name); | 253 | retval = sysfs_create_link(&parent->kobj, |
252 | 254 | &endpoint->ep_dev->dev.kobj, name); | |
255 | if (retval) | ||
256 | goto error_link; | ||
253 | exit: | 257 | exit: |
254 | return; | 258 | return retval; |
259 | |||
260 | error_link: | ||
261 | sysfs_remove_group(&ep_dev->dev.kobj, &ep_dev_attr_grp); | ||
262 | |||
263 | error_group: | ||
264 | device_unregister(&ep_dev->dev); | ||
265 | endpoint->ep_dev = NULL; | ||
266 | destroy_endpoint_class(); | ||
267 | return retval; | ||
255 | error: | 268 | error: |
256 | kfree(ep_dev); | 269 | kfree(ep_dev); |
257 | return; | 270 | destroy_endpoint_class(); |
271 | return retval; | ||
258 | } | 272 | } |
259 | 273 | ||
260 | void usb_remove_ep_files(struct usb_host_endpoint *endpoint) | 274 | void usb_remove_ep_files(struct usb_host_endpoint *endpoint) |
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c index f65b193cde3d..c376c655c5de 100644 --- a/drivers/usb/core/file.c +++ b/drivers/usb/core/file.c | |||
@@ -15,7 +15,6 @@ | |||
15 | * | 15 | * |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/config.h> | ||
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
20 | #include <linux/spinlock.h> | 19 | #include <linux/spinlock.h> |
21 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
@@ -56,7 +55,7 @@ static int usb_open(struct inode * inode, struct file * file) | |||
56 | return err; | 55 | return err; |
57 | } | 56 | } |
58 | 57 | ||
59 | static struct file_operations usb_fops = { | 58 | static const struct file_operations usb_fops = { |
60 | .owner = THIS_MODULE, | 59 | .owner = THIS_MODULE, |
61 | .open = usb_open, | 60 | .open = usb_open, |
62 | }; | 61 | }; |
@@ -195,13 +194,14 @@ int usb_register_dev(struct usb_interface *intf, | |||
195 | ++temp; | 194 | ++temp; |
196 | else | 195 | else |
197 | temp = name; | 196 | temp = name; |
198 | intf->usb_dev = device_create(usb_class->class, &intf->dev, | 197 | intf->class_dev = class_device_create(usb_class->class, NULL, |
199 | MKDEV(USB_MAJOR, minor), "%s", temp); | 198 | MKDEV(USB_MAJOR, minor), |
200 | if (IS_ERR(intf->usb_dev)) { | 199 | &intf->dev, "%s", temp); |
200 | if (IS_ERR(intf->class_dev)) { | ||
201 | spin_lock (&minor_lock); | 201 | spin_lock (&minor_lock); |
202 | usb_minors[intf->minor] = NULL; | 202 | usb_minors[intf->minor] = NULL; |
203 | spin_unlock (&minor_lock); | 203 | spin_unlock (&minor_lock); |
204 | retval = PTR_ERR(intf->usb_dev); | 204 | retval = PTR_ERR(intf->class_dev); |
205 | } | 205 | } |
206 | exit: | 206 | exit: |
207 | return retval; | 207 | return retval; |
@@ -242,8 +242,8 @@ void usb_deregister_dev(struct usb_interface *intf, | |||
242 | spin_unlock (&minor_lock); | 242 | spin_unlock (&minor_lock); |
243 | 243 | ||
244 | snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base); | 244 | snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base); |
245 | device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); | 245 | class_device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); |
246 | intf->usb_dev = NULL; | 246 | intf->class_dev = NULL; |
247 | intf->minor = -1; | 247 | intf->minor = -1; |
248 | destroy_usb_class(); | 248 | destroy_usb_class(); |
249 | } | 249 | } |
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c new file mode 100644 index 000000000000..16332cc57946 --- /dev/null +++ b/drivers/usb/core/generic.c | |||
@@ -0,0 +1,208 @@ | |||
1 | /* | ||
2 | * drivers/usb/generic.c - generic driver for USB devices (not interfaces) | ||
3 | * | ||
4 | * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de> | ||
5 | * | ||
6 | * based on drivers/usb/usb.c which had the following copyrights: | ||
7 | * (C) Copyright Linus Torvalds 1999 | ||
8 | * (C) Copyright Johannes Erdfelt 1999-2001 | ||
9 | * (C) Copyright Andreas Gal 1999 | ||
10 | * (C) Copyright Gregory P. Smith 1999 | ||
11 | * (C) Copyright Deti Fliegl 1999 (new USB architecture) | ||
12 | * (C) Copyright Randy Dunlap 2000 | ||
13 | * (C) Copyright David Brownell 2000-2004 | ||
14 | * (C) Copyright Yggdrasil Computing, Inc. 2000 | ||
15 | * (usb_device_id matching changes by Adam J. Richter) | ||
16 | * (C) Copyright Greg Kroah-Hartman 2002-2003 | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #include <linux/config.h> | ||
21 | #include <linux/usb.h> | ||
22 | #include "usb.h" | ||
23 | |||
24 | static inline const char *plural(int n) | ||
25 | { | ||
26 | return (n == 1 ? "" : "s"); | ||
27 | } | ||
28 | |||
29 | static int choose_configuration(struct usb_device *udev) | ||
30 | { | ||
31 | int i; | ||
32 | int num_configs; | ||
33 | int insufficient_power = 0; | ||
34 | struct usb_host_config *c, *best; | ||
35 | |||
36 | best = NULL; | ||
37 | c = udev->config; | ||
38 | num_configs = udev->descriptor.bNumConfigurations; | ||
39 | for (i = 0; i < num_configs; (i++, c++)) { | ||
40 | struct usb_interface_descriptor *desc = NULL; | ||
41 | |||
42 | /* It's possible that a config has no interfaces! */ | ||
43 | if (c->desc.bNumInterfaces > 0) | ||
44 | desc = &c->intf_cache[0]->altsetting->desc; | ||
45 | |||
46 | /* | ||
47 | * HP's USB bus-powered keyboard has only one configuration | ||
48 | * and it claims to be self-powered; other devices may have | ||
49 | * similar errors in their descriptors. If the next test | ||
50 | * were allowed to execute, such configurations would always | ||
51 | * be rejected and the devices would not work as expected. | ||
52 | * In the meantime, we run the risk of selecting a config | ||
53 | * that requires external power at a time when that power | ||
54 | * isn't available. It seems to be the lesser of two evils. | ||
55 | * | ||
56 | * Bugzilla #6448 reports a device that appears to crash | ||
57 | * when it receives a GET_DEVICE_STATUS request! We don't | ||
58 | * have any other way to tell whether a device is self-powered, | ||
59 | * but since we don't use that information anywhere but here, | ||
60 | * the call has been removed. | ||
61 | * | ||
62 | * Maybe the GET_DEVICE_STATUS call and the test below can | ||
63 | * be reinstated when device firmwares become more reliable. | ||
64 | * Don't hold your breath. | ||
65 | */ | ||
66 | #if 0 | ||
67 | /* Rule out self-powered configs for a bus-powered device */ | ||
68 | if (bus_powered && (c->desc.bmAttributes & | ||
69 | USB_CONFIG_ATT_SELFPOWER)) | ||
70 | continue; | ||
71 | #endif | ||
72 | |||
73 | /* | ||
74 | * The next test may not be as effective as it should be. | ||
75 | * Some hubs have errors in their descriptor, claiming | ||
76 | * to be self-powered when they are really bus-powered. | ||
77 | * We will overestimate the amount of current such hubs | ||
78 | * make available for each port. | ||
79 | * | ||
80 | * This is a fairly benign sort of failure. It won't | ||
81 | * cause us to reject configurations that we should have | ||
82 | * accepted. | ||
83 | */ | ||
84 | |||
85 | /* Rule out configs that draw too much bus current */ | ||
86 | if (c->desc.bMaxPower * 2 > udev->bus_mA) { | ||
87 | insufficient_power++; | ||
88 | continue; | ||
89 | } | ||
90 | |||
91 | /* If the first config's first interface is COMM/2/0xff | ||
92 | * (MSFT RNDIS), rule it out unless Linux has host-side | ||
93 | * RNDIS support. */ | ||
94 | if (i == 0 && desc | ||
95 | && desc->bInterfaceClass == USB_CLASS_COMM | ||
96 | && desc->bInterfaceSubClass == 2 | ||
97 | && desc->bInterfaceProtocol == 0xff) { | ||
98 | #ifndef CONFIG_USB_NET_RNDIS_HOST | ||
99 | continue; | ||
100 | #else | ||
101 | best = c; | ||
102 | #endif | ||
103 | } | ||
104 | |||
105 | /* From the remaining configs, choose the first one whose | ||
106 | * first interface is for a non-vendor-specific class. | ||
107 | * Reason: Linux is more likely to have a class driver | ||
108 | * than a vendor-specific driver. */ | ||
109 | else if (udev->descriptor.bDeviceClass != | ||
110 | USB_CLASS_VENDOR_SPEC && | ||
111 | (!desc || desc->bInterfaceClass != | ||
112 | USB_CLASS_VENDOR_SPEC)) { | ||
113 | best = c; | ||
114 | break; | ||
115 | } | ||
116 | |||
117 | /* If all the remaining configs are vendor-specific, | ||
118 | * choose the first one. */ | ||
119 | else if (!best) | ||
120 | best = c; | ||
121 | } | ||
122 | |||
123 | if (insufficient_power > 0) | ||
124 | dev_info(&udev->dev, "rejected %d configuration%s " | ||
125 | "due to insufficient available bus power\n", | ||
126 | insufficient_power, plural(insufficient_power)); | ||
127 | |||
128 | if (best) { | ||
129 | i = best->desc.bConfigurationValue; | ||
130 | dev_info(&udev->dev, | ||
131 | "configuration #%d chosen from %d choice%s\n", | ||
132 | i, num_configs, plural(num_configs)); | ||
133 | } else { | ||
134 | i = -1; | ||
135 | dev_warn(&udev->dev, | ||
136 | "no configuration chosen from %d choice%s\n", | ||
137 | num_configs, plural(num_configs)); | ||
138 | } | ||
139 | return i; | ||
140 | } | ||
141 | |||
142 | static int generic_probe(struct usb_device *udev) | ||
143 | { | ||
144 | int err, c; | ||
145 | |||
146 | /* put device-specific files into sysfs */ | ||
147 | usb_create_sysfs_dev_files(udev); | ||
148 | |||
149 | /* Choose and set the configuration. This registers the interfaces | ||
150 | * with the driver core and lets interface drivers bind to them. | ||
151 | */ | ||
152 | c = choose_configuration(udev); | ||
153 | if (c >= 0) { | ||
154 | err = usb_set_configuration(udev, c); | ||
155 | if (err) { | ||
156 | dev_err(&udev->dev, "can't set config #%d, error %d\n", | ||
157 | c, err); | ||
158 | /* This need not be fatal. The user can try to | ||
159 | * set other configurations. */ | ||
160 | } | ||
161 | } | ||
162 | |||
163 | /* USB device state == configured ... usable */ | ||
164 | usb_notify_add_device(udev); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static void generic_disconnect(struct usb_device *udev) | ||
170 | { | ||
171 | usb_notify_remove_device(udev); | ||
172 | |||
173 | /* if this is only an unbind, not a physical disconnect, then | ||
174 | * unconfigure the device */ | ||
175 | if (udev->actconfig) | ||
176 | usb_set_configuration(udev, 0); | ||
177 | |||
178 | usb_remove_sysfs_dev_files(udev); | ||
179 | } | ||
180 | |||
181 | #ifdef CONFIG_PM | ||
182 | |||
183 | static int generic_suspend(struct usb_device *udev, pm_message_t msg) | ||
184 | { | ||
185 | /* USB devices enter SUSPEND state through their hubs, but can be | ||
186 | * marked for FREEZE as soon as their children are already idled. | ||
187 | * But those semantics are useless, so we equate the two (sigh). | ||
188 | */ | ||
189 | return usb_port_suspend(udev); | ||
190 | } | ||
191 | |||
192 | static int generic_resume(struct usb_device *udev) | ||
193 | { | ||
194 | return usb_port_resume(udev); | ||
195 | } | ||
196 | |||
197 | #endif /* CONFIG_PM */ | ||
198 | |||
199 | struct usb_device_driver usb_generic_driver = { | ||
200 | .name = "usb", | ||
201 | .probe = generic_probe, | ||
202 | .disconnect = generic_disconnect, | ||
203 | #ifdef CONFIG_PM | ||
204 | .suspend = generic_suspend, | ||
205 | .resume = generic_resume, | ||
206 | #endif | ||
207 | .supports_autosuspend = 1, | ||
208 | }; | ||
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 66b78404ab34..edf4300a3f7a 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -16,7 +16,6 @@ | |||
16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/config.h> | ||
20 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
22 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
@@ -126,7 +125,7 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) | |||
126 | 125 | ||
127 | pci_set_master (dev); | 126 | pci_set_master (dev); |
128 | 127 | ||
129 | retval = usb_add_hcd (hcd, dev->irq, SA_SHIRQ); | 128 | retval = usb_add_hcd (hcd, dev->irq, IRQF_SHARED); |
130 | if (retval != 0) | 129 | if (retval != 0) |
131 | goto err4; | 130 | goto err4; |
132 | return retval; | 131 | return retval; |
@@ -282,7 +281,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) | |||
282 | (void) usb_hcd_pci_resume (dev); | 281 | (void) usb_hcd_pci_resume (dev); |
283 | } | 282 | } |
284 | 283 | ||
285 | } else { | 284 | } else if (hcd->state != HC_STATE_HALT) { |
286 | dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", | 285 | dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", |
287 | hcd->state); | 286 | hcd->state); |
288 | WARN_ON(1); | 287 | WARN_ON(1); |
@@ -414,4 +413,20 @@ EXPORT_SYMBOL (usb_hcd_pci_resume); | |||
414 | 413 | ||
415 | #endif /* CONFIG_PM */ | 414 | #endif /* CONFIG_PM */ |
416 | 415 | ||
416 | /** | ||
417 | * usb_hcd_pci_shutdown - shutdown host controller | ||
418 | * @dev: USB Host Controller being shutdown | ||
419 | */ | ||
420 | void usb_hcd_pci_shutdown (struct pci_dev *dev) | ||
421 | { | ||
422 | struct usb_hcd *hcd; | ||
423 | |||
424 | hcd = pci_get_drvdata(dev); | ||
425 | if (!hcd) | ||
426 | return; | ||
427 | |||
428 | if (hcd->driver->shutdown) | ||
429 | hcd->driver->shutdown(hcd); | ||
430 | } | ||
431 | EXPORT_SYMBOL (usb_hcd_pci_shutdown); | ||
417 | 432 | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 4bf914d00a14..37f9f5e7425d 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -22,7 +22,6 @@ | |||
22 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 22 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <linux/config.h> | ||
26 | #include <linux/module.h> | 25 | #include <linux/module.h> |
27 | #include <linux/version.h> | 26 | #include <linux/version.h> |
28 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
@@ -37,6 +36,7 @@ | |||
37 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
38 | #include <asm/irq.h> | 37 | #include <asm/irq.h> |
39 | #include <asm/byteorder.h> | 38 | #include <asm/byteorder.h> |
39 | #include <linux/platform_device.h> | ||
40 | 40 | ||
41 | #include <linux/usb.h> | 41 | #include <linux/usb.h> |
42 | 42 | ||
@@ -345,7 +345,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
345 | struct usb_ctrlrequest *cmd; | 345 | struct usb_ctrlrequest *cmd; |
346 | u16 typeReq, wValue, wIndex, wLength; | 346 | u16 typeReq, wValue, wIndex, wLength; |
347 | u8 *ubuf = urb->transfer_buffer; | 347 | u8 *ubuf = urb->transfer_buffer; |
348 | u8 tbuf [sizeof (struct usb_hub_descriptor)]; | 348 | u8 tbuf [sizeof (struct usb_hub_descriptor)] |
349 | __attribute__((aligned(4))); | ||
349 | const u8 *bufp = tbuf; | 350 | const u8 *bufp = tbuf; |
350 | int len = 0; | 351 | int len = 0; |
351 | int patch_wakeup = 0; | 352 | int patch_wakeup = 0; |
@@ -633,31 +634,20 @@ static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) | |||
633 | 634 | ||
634 | /*-------------------------------------------------------------------------*/ | 635 | /*-------------------------------------------------------------------------*/ |
635 | 636 | ||
636 | /* Asynchronous unlinks of root-hub control URBs are legal, but they | 637 | /* Unlinks of root-hub control URBs are legal, but they don't do anything |
637 | * don't do anything. Status URB unlinks must be made in process context | 638 | * since these URBs always execute synchronously. |
638 | * with interrupts enabled. | ||
639 | */ | 639 | */ |
640 | static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) | 640 | static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) |
641 | { | 641 | { |
642 | if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */ | 642 | unsigned long flags; |
643 | if (in_interrupt()) | ||
644 | return 0; /* nothing to do */ | ||
645 | |||
646 | spin_lock_irq(&urb->lock); /* from usb_kill_urb */ | ||
647 | ++urb->reject; | ||
648 | spin_unlock_irq(&urb->lock); | ||
649 | |||
650 | wait_event(usb_kill_urb_queue, | ||
651 | atomic_read(&urb->use_count) == 0); | ||
652 | 643 | ||
653 | spin_lock_irq(&urb->lock); | 644 | if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */ |
654 | --urb->reject; | 645 | ; /* Do nothing */ |
655 | spin_unlock_irq(&urb->lock); | ||
656 | 646 | ||
657 | } else { /* Status URB */ | 647 | } else { /* Status URB */ |
658 | if (!hcd->uses_new_polling) | 648 | if (!hcd->uses_new_polling) |
659 | del_timer_sync (&hcd->rh_timer); | 649 | del_timer (&hcd->rh_timer); |
660 | local_irq_disable (); | 650 | local_irq_save (flags); |
661 | spin_lock (&hcd_root_hub_lock); | 651 | spin_lock (&hcd_root_hub_lock); |
662 | if (urb == hcd->status_urb) { | 652 | if (urb == hcd->status_urb) { |
663 | hcd->status_urb = NULL; | 653 | hcd->status_urb = NULL; |
@@ -667,7 +657,7 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) | |||
667 | spin_unlock (&hcd_root_hub_lock); | 657 | spin_unlock (&hcd_root_hub_lock); |
668 | if (urb) | 658 | if (urb) |
669 | usb_hcd_giveback_urb (hcd, urb, NULL); | 659 | usb_hcd_giveback_urb (hcd, urb, NULL); |
670 | local_irq_enable (); | 660 | local_irq_restore (flags); |
671 | } | 661 | } |
672 | 662 | ||
673 | return 0; | 663 | return 0; |
@@ -675,31 +665,6 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) | |||
675 | 665 | ||
676 | /*-------------------------------------------------------------------------*/ | 666 | /*-------------------------------------------------------------------------*/ |
677 | 667 | ||
678 | /* exported only within usbcore */ | ||
679 | struct usb_bus *usb_bus_get(struct usb_bus *bus) | ||
680 | { | ||
681 | if (bus) | ||
682 | kref_get(&bus->kref); | ||
683 | return bus; | ||
684 | } | ||
685 | |||
686 | static void usb_host_release(struct kref *kref) | ||
687 | { | ||
688 | struct usb_bus *bus = container_of(kref, struct usb_bus, kref); | ||
689 | |||
690 | if (bus->release) | ||
691 | bus->release(bus); | ||
692 | } | ||
693 | |||
694 | /* exported only within usbcore */ | ||
695 | void usb_bus_put(struct usb_bus *bus) | ||
696 | { | ||
697 | if (bus) | ||
698 | kref_put(&bus->kref, usb_host_release); | ||
699 | } | ||
700 | |||
701 | /*-------------------------------------------------------------------------*/ | ||
702 | |||
703 | static struct class *usb_host_class; | 668 | static struct class *usb_host_class; |
704 | 669 | ||
705 | int usb_host_init(void) | 670 | int usb_host_init(void) |
@@ -731,39 +696,12 @@ static void usb_bus_init (struct usb_bus *bus) | |||
731 | bus->devnum_next = 1; | 696 | bus->devnum_next = 1; |
732 | 697 | ||
733 | bus->root_hub = NULL; | 698 | bus->root_hub = NULL; |
734 | bus->hcpriv = NULL; | ||
735 | bus->busnum = -1; | 699 | bus->busnum = -1; |
736 | bus->bandwidth_allocated = 0; | 700 | bus->bandwidth_allocated = 0; |
737 | bus->bandwidth_int_reqs = 0; | 701 | bus->bandwidth_int_reqs = 0; |
738 | bus->bandwidth_isoc_reqs = 0; | 702 | bus->bandwidth_isoc_reqs = 0; |
739 | 703 | ||
740 | INIT_LIST_HEAD (&bus->bus_list); | 704 | INIT_LIST_HEAD (&bus->bus_list); |
741 | |||
742 | kref_init(&bus->kref); | ||
743 | } | ||
744 | |||
745 | /** | ||
746 | * usb_alloc_bus - creates a new USB host controller structure | ||
747 | * @op: pointer to a struct usb_operations that this bus structure should use | ||
748 | * Context: !in_interrupt() | ||
749 | * | ||
750 | * Creates a USB host controller bus structure with the specified | ||
751 | * usb_operations and initializes all the necessary internal objects. | ||
752 | * | ||
753 | * If no memory is available, NULL is returned. | ||
754 | * | ||
755 | * The caller should call usb_put_bus() when it is finished with the structure. | ||
756 | */ | ||
757 | struct usb_bus *usb_alloc_bus (struct usb_operations *op) | ||
758 | { | ||
759 | struct usb_bus *bus; | ||
760 | |||
761 | bus = kzalloc (sizeof *bus, GFP_KERNEL); | ||
762 | if (!bus) | ||
763 | return NULL; | ||
764 | usb_bus_init (bus); | ||
765 | bus->op = op; | ||
766 | return bus; | ||
767 | } | 705 | } |
768 | 706 | ||
769 | /*-------------------------------------------------------------------------*/ | 707 | /*-------------------------------------------------------------------------*/ |
@@ -898,8 +836,7 @@ void usb_enable_root_hub_irq (struct usb_bus *bus) | |||
898 | struct usb_hcd *hcd; | 836 | struct usb_hcd *hcd; |
899 | 837 | ||
900 | hcd = container_of (bus, struct usb_hcd, self); | 838 | hcd = container_of (bus, struct usb_hcd, self); |
901 | if (hcd->driver->hub_irq_enable && !hcd->poll_rh && | 839 | if (hcd->driver->hub_irq_enable && hcd->state != HC_STATE_HALT) |
902 | hcd->state != HC_STATE_HALT) | ||
903 | hcd->driver->hub_irq_enable (hcd); | 840 | hcd->driver->hub_irq_enable (hcd); |
904 | } | 841 | } |
905 | 842 | ||
@@ -1113,10 +1050,10 @@ static void urb_unlink (struct urb *urb) | |||
1113 | * expects usb_submit_urb() to have sanity checked and conditioned all | 1050 | * expects usb_submit_urb() to have sanity checked and conditioned all |
1114 | * inputs in the urb | 1051 | * inputs in the urb |
1115 | */ | 1052 | */ |
1116 | static int hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | 1053 | int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) |
1117 | { | 1054 | { |
1118 | int status; | 1055 | int status; |
1119 | struct usb_hcd *hcd = urb->dev->bus->hcpriv; | 1056 | struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); |
1120 | struct usb_host_endpoint *ep; | 1057 | struct usb_host_endpoint *ep; |
1121 | unsigned long flags; | 1058 | unsigned long flags; |
1122 | 1059 | ||
@@ -1187,7 +1124,7 @@ doit: | |||
1187 | /* lower level hcd code should use *_dma exclusively, | 1124 | /* lower level hcd code should use *_dma exclusively, |
1188 | * unless it uses pio or talks to another transport. | 1125 | * unless it uses pio or talks to another transport. |
1189 | */ | 1126 | */ |
1190 | if (hcd->self.controller->dma_mask) { | 1127 | if (hcd->self.uses_dma) { |
1191 | if (usb_pipecontrol (urb->pipe) | 1128 | if (usb_pipecontrol (urb->pipe) |
1192 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) | 1129 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) |
1193 | urb->setup_dma = dma_map_single ( | 1130 | urb->setup_dma = dma_map_single ( |
@@ -1222,9 +1159,10 @@ done: | |||
1222 | /*-------------------------------------------------------------------------*/ | 1159 | /*-------------------------------------------------------------------------*/ |
1223 | 1160 | ||
1224 | /* called in any context */ | 1161 | /* called in any context */ |
1225 | static int hcd_get_frame_number (struct usb_device *udev) | 1162 | int usb_hcd_get_frame_number (struct usb_device *udev) |
1226 | { | 1163 | { |
1227 | struct usb_hcd *hcd = (struct usb_hcd *)udev->bus->hcpriv; | 1164 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1165 | |||
1228 | if (!HC_IS_RUNNING (hcd->state)) | 1166 | if (!HC_IS_RUNNING (hcd->state)) |
1229 | return -ESHUTDOWN; | 1167 | return -ESHUTDOWN; |
1230 | return hcd->driver->get_frame_number (hcd); | 1168 | return hcd->driver->get_frame_number (hcd); |
@@ -1264,7 +1202,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb) | |||
1264 | * caller guarantees urb won't be recycled till both unlink() | 1202 | * caller guarantees urb won't be recycled till both unlink() |
1265 | * and the urb's completion function return | 1203 | * and the urb's completion function return |
1266 | */ | 1204 | */ |
1267 | static int hcd_unlink_urb (struct urb *urb, int status) | 1205 | int usb_hcd_unlink_urb (struct urb *urb, int status) |
1268 | { | 1206 | { |
1269 | struct usb_host_endpoint *ep; | 1207 | struct usb_host_endpoint *ep; |
1270 | struct usb_hcd *hcd = NULL; | 1208 | struct usb_hcd *hcd = NULL; |
@@ -1297,7 +1235,7 @@ static int hcd_unlink_urb (struct urb *urb, int status) | |||
1297 | spin_lock (&hcd_data_lock); | 1235 | spin_lock (&hcd_data_lock); |
1298 | 1236 | ||
1299 | sys = &urb->dev->dev; | 1237 | sys = &urb->dev->dev; |
1300 | hcd = urb->dev->bus->hcpriv; | 1238 | hcd = bus_to_hcd(urb->dev->bus); |
1301 | if (hcd == NULL) { | 1239 | if (hcd == NULL) { |
1302 | retval = -ENODEV; | 1240 | retval = -ENODEV; |
1303 | goto done; | 1241 | goto done; |
@@ -1355,41 +1293,33 @@ done: | |||
1355 | /*-------------------------------------------------------------------------*/ | 1293 | /*-------------------------------------------------------------------------*/ |
1356 | 1294 | ||
1357 | /* disables the endpoint: cancels any pending urbs, then synchronizes with | 1295 | /* disables the endpoint: cancels any pending urbs, then synchronizes with |
1358 | * the hcd to make sure all endpoint state is gone from hardware. use for | 1296 | * the hcd to make sure all endpoint state is gone from hardware, and then |
1297 | * waits until the endpoint's queue is completely drained. use for | ||
1359 | * set_configuration, set_interface, driver removal, physical disconnect. | 1298 | * set_configuration, set_interface, driver removal, physical disconnect. |
1360 | * | 1299 | * |
1361 | * example: a qh stored in ep->hcpriv, holding state related to endpoint | 1300 | * example: a qh stored in ep->hcpriv, holding state related to endpoint |
1362 | * type, maxpacket size, toggle, halt status, and scheduling. | 1301 | * type, maxpacket size, toggle, halt status, and scheduling. |
1363 | */ | 1302 | */ |
1364 | static void | 1303 | void usb_hcd_endpoint_disable (struct usb_device *udev, |
1365 | hcd_endpoint_disable (struct usb_device *udev, struct usb_host_endpoint *ep) | 1304 | struct usb_host_endpoint *ep) |
1366 | { | 1305 | { |
1367 | struct usb_hcd *hcd; | 1306 | struct usb_hcd *hcd; |
1368 | struct urb *urb; | 1307 | struct urb *urb; |
1369 | 1308 | ||
1370 | hcd = udev->bus->hcpriv; | 1309 | hcd = bus_to_hcd(udev->bus); |
1371 | 1310 | ||
1372 | WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && | 1311 | WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && |
1373 | udev->state != USB_STATE_NOTATTACHED); | 1312 | udev->state != USB_STATE_NOTATTACHED); |
1374 | 1313 | ||
1375 | local_irq_disable (); | 1314 | local_irq_disable (); |
1376 | 1315 | ||
1377 | /* FIXME move most of this into message.c as part of its | ||
1378 | * endpoint disable logic | ||
1379 | */ | ||
1380 | |||
1381 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ | 1316 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ |
1382 | rescan: | 1317 | rescan: |
1383 | spin_lock (&hcd_data_lock); | 1318 | spin_lock (&hcd_data_lock); |
1384 | list_for_each_entry (urb, &ep->urb_list, urb_list) { | 1319 | list_for_each_entry (urb, &ep->urb_list, urb_list) { |
1385 | int tmp; | 1320 | int tmp; |
1386 | 1321 | ||
1387 | /* another cpu may be in hcd, spinning on hcd_data_lock | 1322 | /* the urb may already have been unlinked */ |
1388 | * to giveback() this urb. the races here should be | ||
1389 | * small, but a full fix needs a new "can't submit" | ||
1390 | * urb state. | ||
1391 | * FIXME urb->reject should allow that... | ||
1392 | */ | ||
1393 | if (urb->status != -EINPROGRESS) | 1323 | if (urb->status != -EINPROGRESS) |
1394 | continue; | 1324 | continue; |
1395 | usb_get_urb (urb); | 1325 | usb_get_urb (urb); |
@@ -1431,6 +1361,30 @@ rescan: | |||
1431 | might_sleep (); | 1361 | might_sleep (); |
1432 | if (hcd->driver->endpoint_disable) | 1362 | if (hcd->driver->endpoint_disable) |
1433 | hcd->driver->endpoint_disable (hcd, ep); | 1363 | hcd->driver->endpoint_disable (hcd, ep); |
1364 | |||
1365 | /* Wait until the endpoint queue is completely empty. Most HCDs | ||
1366 | * will have done this already in their endpoint_disable method, | ||
1367 | * but some might not. And there could be root-hub control URBs | ||
1368 | * still pending since they aren't affected by the HCDs' | ||
1369 | * endpoint_disable methods. | ||
1370 | */ | ||
1371 | while (!list_empty (&ep->urb_list)) { | ||
1372 | spin_lock_irq (&hcd_data_lock); | ||
1373 | |||
1374 | /* The list may have changed while we acquired the spinlock */ | ||
1375 | urb = NULL; | ||
1376 | if (!list_empty (&ep->urb_list)) { | ||
1377 | urb = list_entry (ep->urb_list.prev, struct urb, | ||
1378 | urb_list); | ||
1379 | usb_get_urb (urb); | ||
1380 | } | ||
1381 | spin_unlock_irq (&hcd_data_lock); | ||
1382 | |||
1383 | if (urb) { | ||
1384 | usb_kill_urb (urb); | ||
1385 | usb_put_urb (urb); | ||
1386 | } | ||
1387 | } | ||
1434 | } | 1388 | } |
1435 | 1389 | ||
1436 | /*-------------------------------------------------------------------------*/ | 1390 | /*-------------------------------------------------------------------------*/ |
@@ -1477,50 +1431,6 @@ int hcd_bus_resume (struct usb_bus *bus) | |||
1477 | return status; | 1431 | return status; |
1478 | } | 1432 | } |
1479 | 1433 | ||
1480 | /* | ||
1481 | * usb_hcd_suspend_root_hub - HCD autosuspends downstream ports | ||
1482 | * @hcd: host controller for this root hub | ||
1483 | * | ||
1484 | * This call arranges that usb_hcd_resume_root_hub() is safe to call later; | ||
1485 | * that the HCD's root hub polling is deactivated; and that the root's hub | ||
1486 | * driver is suspended. HCDs may call this to autosuspend when their root | ||
1487 | * hub's downstream ports are all inactive: unpowered, disconnected, | ||
1488 | * disabled, or suspended. | ||
1489 | * | ||
1490 | * The HCD will autoresume on device connect change detection (using SRP | ||
1491 | * or a D+/D- pullup). The HCD also autoresumes on remote wakeup signaling | ||
1492 | * from any ports that are suspended (if that is enabled). In most cases, | ||
1493 | * overcurrent signaling (on powered ports) will also start autoresume. | ||
1494 | * | ||
1495 | * Always called with IRQs blocked. | ||
1496 | */ | ||
1497 | void usb_hcd_suspend_root_hub (struct usb_hcd *hcd) | ||
1498 | { | ||
1499 | struct urb *urb; | ||
1500 | |||
1501 | spin_lock (&hcd_root_hub_lock); | ||
1502 | usb_suspend_root_hub (hcd->self.root_hub); | ||
1503 | |||
1504 | /* force status urb to complete/unlink while suspended */ | ||
1505 | if (hcd->status_urb) { | ||
1506 | urb = hcd->status_urb; | ||
1507 | urb->status = -ECONNRESET; | ||
1508 | urb->hcpriv = NULL; | ||
1509 | urb->actual_length = 0; | ||
1510 | |||
1511 | del_timer (&hcd->rh_timer); | ||
1512 | hcd->poll_pending = 0; | ||
1513 | hcd->status_urb = NULL; | ||
1514 | } else | ||
1515 | urb = NULL; | ||
1516 | spin_unlock (&hcd_root_hub_lock); | ||
1517 | hcd->state = HC_STATE_SUSPENDED; | ||
1518 | |||
1519 | if (urb) | ||
1520 | usb_hcd_giveback_urb (hcd, urb, NULL); | ||
1521 | } | ||
1522 | EXPORT_SYMBOL_GPL(usb_hcd_suspend_root_hub); | ||
1523 | |||
1524 | /** | 1434 | /** |
1525 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub | 1435 | * usb_hcd_resume_root_hub - called by HCD to resume its root hub |
1526 | * @hcd: host controller for this root hub | 1436 | * @hcd: host controller for this root hub |
@@ -1584,20 +1494,6 @@ EXPORT_SYMBOL (usb_bus_start_enum); | |||
1584 | 1494 | ||
1585 | /*-------------------------------------------------------------------------*/ | 1495 | /*-------------------------------------------------------------------------*/ |
1586 | 1496 | ||
1587 | /* | ||
1588 | * usb_hcd_operations - adapts usb_bus framework to HCD framework (bus glue) | ||
1589 | */ | ||
1590 | static struct usb_operations usb_hcd_operations = { | ||
1591 | .get_frame_number = hcd_get_frame_number, | ||
1592 | .submit_urb = hcd_submit_urb, | ||
1593 | .unlink_urb = hcd_unlink_urb, | ||
1594 | .buffer_alloc = hcd_buffer_alloc, | ||
1595 | .buffer_free = hcd_buffer_free, | ||
1596 | .disable = hcd_endpoint_disable, | ||
1597 | }; | ||
1598 | |||
1599 | /*-------------------------------------------------------------------------*/ | ||
1600 | |||
1601 | /** | 1497 | /** |
1602 | * usb_hcd_giveback_urb - return URB from HCD to device driver | 1498 | * usb_hcd_giveback_urb - return URB from HCD to device driver |
1603 | * @hcd: host controller returning the URB | 1499 | * @hcd: host controller returning the URB |
@@ -1618,8 +1514,9 @@ void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs | |||
1618 | at_root_hub = (urb->dev == hcd->self.root_hub); | 1514 | at_root_hub = (urb->dev == hcd->self.root_hub); |
1619 | urb_unlink (urb); | 1515 | urb_unlink (urb); |
1620 | 1516 | ||
1621 | /* lower level hcd code should use *_dma exclusively */ | 1517 | /* lower level hcd code should use *_dma exclusively if the |
1622 | if (hcd->self.controller->dma_mask && !at_root_hub) { | 1518 | * host controller does DMA */ |
1519 | if (hcd->self.uses_dma && !at_root_hub) { | ||
1623 | if (usb_pipecontrol (urb->pipe) | 1520 | if (usb_pipecontrol (urb->pipe) |
1624 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) | 1521 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) |
1625 | dma_unmap_single (hcd->self.controller, urb->setup_dma, | 1522 | dma_unmap_single (hcd->self.controller, urb->setup_dma, |
@@ -1705,14 +1602,6 @@ EXPORT_SYMBOL_GPL (usb_hc_died); | |||
1705 | 1602 | ||
1706 | /*-------------------------------------------------------------------------*/ | 1603 | /*-------------------------------------------------------------------------*/ |
1707 | 1604 | ||
1708 | static void hcd_release (struct usb_bus *bus) | ||
1709 | { | ||
1710 | struct usb_hcd *hcd; | ||
1711 | |||
1712 | hcd = container_of(bus, struct usb_hcd, self); | ||
1713 | kfree(hcd); | ||
1714 | } | ||
1715 | |||
1716 | /** | 1605 | /** |
1717 | * usb_create_hcd - create and initialize an HCD structure | 1606 | * usb_create_hcd - create and initialize an HCD structure |
1718 | * @driver: HC driver that will use this hcd | 1607 | * @driver: HC driver that will use this hcd |
@@ -1737,13 +1626,12 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1737 | return NULL; | 1626 | return NULL; |
1738 | } | 1627 | } |
1739 | dev_set_drvdata(dev, hcd); | 1628 | dev_set_drvdata(dev, hcd); |
1629 | kref_init(&hcd->kref); | ||
1740 | 1630 | ||
1741 | usb_bus_init(&hcd->self); | 1631 | usb_bus_init(&hcd->self); |
1742 | hcd->self.op = &usb_hcd_operations; | ||
1743 | hcd->self.hcpriv = hcd; | ||
1744 | hcd->self.release = &hcd_release; | ||
1745 | hcd->self.controller = dev; | 1632 | hcd->self.controller = dev; |
1746 | hcd->self.bus_name = bus_name; | 1633 | hcd->self.bus_name = bus_name; |
1634 | hcd->self.uses_dma = (dev->dma_mask != NULL); | ||
1747 | 1635 | ||
1748 | init_timer(&hcd->rh_timer); | 1636 | init_timer(&hcd->rh_timer); |
1749 | hcd->rh_timer.function = rh_timer_func; | 1637 | hcd->rh_timer.function = rh_timer_func; |
@@ -1757,10 +1645,25 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1757 | } | 1645 | } |
1758 | EXPORT_SYMBOL (usb_create_hcd); | 1646 | EXPORT_SYMBOL (usb_create_hcd); |
1759 | 1647 | ||
1648 | static void hcd_release (struct kref *kref) | ||
1649 | { | ||
1650 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | ||
1651 | |||
1652 | kfree(hcd); | ||
1653 | } | ||
1654 | |||
1655 | struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) | ||
1656 | { | ||
1657 | if (hcd) | ||
1658 | kref_get (&hcd->kref); | ||
1659 | return hcd; | ||
1660 | } | ||
1661 | EXPORT_SYMBOL (usb_get_hcd); | ||
1662 | |||
1760 | void usb_put_hcd (struct usb_hcd *hcd) | 1663 | void usb_put_hcd (struct usb_hcd *hcd) |
1761 | { | 1664 | { |
1762 | dev_set_drvdata(hcd->self.controller, NULL); | 1665 | if (hcd) |
1763 | usb_bus_put(&hcd->self); | 1666 | kref_put (&hcd->kref, hcd_release); |
1764 | } | 1667 | } |
1765 | EXPORT_SYMBOL (usb_put_hcd); | 1668 | EXPORT_SYMBOL (usb_put_hcd); |
1766 | 1669 | ||
@@ -1916,6 +1819,16 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
1916 | } | 1819 | } |
1917 | EXPORT_SYMBOL (usb_remove_hcd); | 1820 | EXPORT_SYMBOL (usb_remove_hcd); |
1918 | 1821 | ||
1822 | void | ||
1823 | usb_hcd_platform_shutdown(struct platform_device* dev) | ||
1824 | { | ||
1825 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
1826 | |||
1827 | if (hcd->driver->shutdown) | ||
1828 | hcd->driver->shutdown(hcd); | ||
1829 | } | ||
1830 | EXPORT_SYMBOL (usb_hcd_platform_shutdown); | ||
1831 | |||
1919 | /*-------------------------------------------------------------------------*/ | 1832 | /*-------------------------------------------------------------------------*/ |
1920 | 1833 | ||
1921 | #if defined(CONFIG_USB_MON) | 1834 | #if defined(CONFIG_USB_MON) |
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index 7022aafb2ae8..676877c15f81 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -55,12 +55,13 @@ | |||
55 | 55 | ||
56 | /*-------------------------------------------------------------------------*/ | 56 | /*-------------------------------------------------------------------------*/ |
57 | 57 | ||
58 | struct usb_hcd { /* usb_bus.hcpriv points to this */ | 58 | struct usb_hcd { |
59 | 59 | ||
60 | /* | 60 | /* |
61 | * housekeeping | 61 | * housekeeping |
62 | */ | 62 | */ |
63 | struct usb_bus self; /* hcd is-a bus */ | 63 | struct usb_bus self; /* hcd is-a bus */ |
64 | struct kref kref; /* reference counter */ | ||
64 | 65 | ||
65 | const char *product_desc; /* product/vendor string */ | 66 | const char *product_desc; /* product/vendor string */ |
66 | char irq_descr[24]; /* driver + bus # */ | 67 | char irq_descr[24]; /* driver + bus # */ |
@@ -85,6 +86,7 @@ struct usb_hcd { /* usb_bus.hcpriv points to this */ | |||
85 | unsigned uses_new_polling:1; | 86 | unsigned uses_new_polling:1; |
86 | unsigned poll_rh:1; /* poll for rh status? */ | 87 | unsigned poll_rh:1; /* poll for rh status? */ |
87 | unsigned poll_pending:1; /* status has changed? */ | 88 | unsigned poll_pending:1; /* status has changed? */ |
89 | unsigned wireless:1; /* Wireless USB HCD */ | ||
88 | 90 | ||
89 | int irq; /* irq allocated */ | 91 | int irq; /* irq allocated */ |
90 | void __iomem *regs; /* device memory/io */ | 92 | void __iomem *regs; /* device memory/io */ |
@@ -128,8 +130,10 @@ static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd) | |||
128 | return &hcd->self; | 130 | return &hcd->self; |
129 | } | 131 | } |
130 | 132 | ||
131 | 133 | static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus) | |
132 | // urb.hcpriv is really hardware-specific | 134 | { |
135 | return container_of(bus, struct usb_hcd, self); | ||
136 | } | ||
133 | 137 | ||
134 | struct hcd_timeout { /* timeouts we allocate */ | 138 | struct hcd_timeout { /* timeouts we allocate */ |
135 | struct list_head timeout_list; | 139 | struct list_head timeout_list; |
@@ -138,28 +142,6 @@ struct hcd_timeout { /* timeouts we allocate */ | |||
138 | 142 | ||
139 | /*-------------------------------------------------------------------------*/ | 143 | /*-------------------------------------------------------------------------*/ |
140 | 144 | ||
141 | /* | ||
142 | * FIXME usb_operations should vanish or become hc_driver, | ||
143 | * when usb_bus and usb_hcd become the same thing. | ||
144 | */ | ||
145 | |||
146 | struct usb_operations { | ||
147 | int (*get_frame_number) (struct usb_device *usb_dev); | ||
148 | int (*submit_urb) (struct urb *urb, gfp_t mem_flags); | ||
149 | int (*unlink_urb) (struct urb *urb, int status); | ||
150 | |||
151 | /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */ | ||
152 | void *(*buffer_alloc)(struct usb_bus *bus, size_t size, | ||
153 | gfp_t mem_flags, | ||
154 | dma_addr_t *dma); | ||
155 | void (*buffer_free)(struct usb_bus *bus, size_t size, | ||
156 | void *addr, dma_addr_t dma); | ||
157 | |||
158 | void (*disable)(struct usb_device *udev, | ||
159 | struct usb_host_endpoint *ep); | ||
160 | }; | ||
161 | |||
162 | /* each driver provides one of these, and hardware init support */ | ||
163 | 145 | ||
164 | struct pt_regs; | 146 | struct pt_regs; |
165 | 147 | ||
@@ -192,6 +174,9 @@ struct hc_driver { | |||
192 | /* cleanly make HCD stop writing memory and doing I/O */ | 174 | /* cleanly make HCD stop writing memory and doing I/O */ |
193 | void (*stop) (struct usb_hcd *hcd); | 175 | void (*stop) (struct usb_hcd *hcd); |
194 | 176 | ||
177 | /* shutdown HCD */ | ||
178 | void (*shutdown) (struct usb_hcd *hcd); | ||
179 | |||
195 | /* return current frame number */ | 180 | /* return current frame number */ |
196 | int (*get_frame_number) (struct usb_hcd *hcd); | 181 | int (*get_frame_number) (struct usb_hcd *hcd); |
197 | 182 | ||
@@ -218,15 +203,25 @@ struct hc_driver { | |||
218 | /* Needed only if port-change IRQs are level-triggered */ | 203 | /* Needed only if port-change IRQs are level-triggered */ |
219 | }; | 204 | }; |
220 | 205 | ||
221 | extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs); | 206 | extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags); |
207 | extern int usb_hcd_unlink_urb (struct urb *urb, int status); | ||
208 | extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, | ||
209 | struct pt_regs *regs); | ||
210 | extern void usb_hcd_endpoint_disable (struct usb_device *udev, | ||
211 | struct usb_host_endpoint *ep); | ||
212 | extern int usb_hcd_get_frame_number (struct usb_device *udev); | ||
222 | 213 | ||
223 | extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | 214 | extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, |
224 | struct device *dev, char *bus_name); | 215 | struct device *dev, char *bus_name); |
216 | extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd); | ||
225 | extern void usb_put_hcd (struct usb_hcd *hcd); | 217 | extern void usb_put_hcd (struct usb_hcd *hcd); |
226 | extern int usb_add_hcd(struct usb_hcd *hcd, | 218 | extern int usb_add_hcd(struct usb_hcd *hcd, |
227 | unsigned int irqnum, unsigned long irqflags); | 219 | unsigned int irqnum, unsigned long irqflags); |
228 | extern void usb_remove_hcd(struct usb_hcd *hcd); | 220 | extern void usb_remove_hcd(struct usb_hcd *hcd); |
229 | 221 | ||
222 | struct platform_device; | ||
223 | extern void usb_hcd_platform_shutdown(struct platform_device* dev); | ||
224 | |||
230 | #ifdef CONFIG_PCI | 225 | #ifdef CONFIG_PCI |
231 | struct pci_dev; | 226 | struct pci_dev; |
232 | struct pci_device_id; | 227 | struct pci_device_id; |
@@ -239,6 +234,8 @@ extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state); | |||
239 | extern int usb_hcd_pci_resume (struct pci_dev *dev); | 234 | extern int usb_hcd_pci_resume (struct pci_dev *dev); |
240 | #endif /* CONFIG_PM */ | 235 | #endif /* CONFIG_PM */ |
241 | 236 | ||
237 | extern void usb_hcd_pci_shutdown (struct pci_dev *dev); | ||
238 | |||
242 | #endif /* CONFIG_PCI */ | 239 | #endif /* CONFIG_PCI */ |
243 | 240 | ||
244 | /* pci-ish (pdev null is ok) buffer alloc/mapping support */ | 241 | /* pci-ish (pdev null is ok) buffer alloc/mapping support */ |
@@ -352,8 +349,6 @@ extern long usb_calc_bus_time (int speed, int is_input, | |||
352 | 349 | ||
353 | /*-------------------------------------------------------------------------*/ | 350 | /*-------------------------------------------------------------------------*/ |
354 | 351 | ||
355 | extern struct usb_bus *usb_alloc_bus (struct usb_operations *); | ||
356 | |||
357 | extern void usb_set_device_state(struct usb_device *udev, | 352 | extern void usb_set_device_state(struct usb_device *udev, |
358 | enum usb_device_state new_state); | 353 | enum usb_device_state new_state); |
359 | 354 | ||
@@ -365,9 +360,6 @@ extern struct list_head usb_bus_list; | |||
365 | extern struct mutex usb_bus_list_lock; | 360 | extern struct mutex usb_bus_list_lock; |
366 | extern wait_queue_head_t usb_kill_urb_queue; | 361 | extern wait_queue_head_t usb_kill_urb_queue; |
367 | 362 | ||
368 | extern struct usb_bus *usb_bus_get (struct usb_bus *bus); | ||
369 | extern void usb_bus_put (struct usb_bus *bus); | ||
370 | |||
371 | extern void usb_enable_root_hub_irq (struct usb_bus *bus); | 363 | extern void usb_enable_root_hub_irq (struct usb_bus *bus); |
372 | 364 | ||
373 | extern int usb_find_interface_driver (struct usb_device *dev, | 365 | extern int usb_find_interface_driver (struct usb_device *dev, |
@@ -376,17 +368,11 @@ extern int usb_find_interface_driver (struct usb_device *dev, | |||
376 | #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) | 368 | #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) |
377 | 369 | ||
378 | #ifdef CONFIG_PM | 370 | #ifdef CONFIG_PM |
379 | extern void usb_hcd_suspend_root_hub (struct usb_hcd *hcd); | ||
380 | extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); | 371 | extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); |
381 | extern void usb_root_hub_lost_power (struct usb_device *rhdev); | 372 | extern void usb_root_hub_lost_power (struct usb_device *rhdev); |
382 | extern int hcd_bus_suspend (struct usb_bus *bus); | 373 | extern int hcd_bus_suspend (struct usb_bus *bus); |
383 | extern int hcd_bus_resume (struct usb_bus *bus); | 374 | extern int hcd_bus_resume (struct usb_bus *bus); |
384 | #else | 375 | #else |
385 | static inline void usb_hcd_suspend_root_hub(struct usb_hcd *hcd) | ||
386 | { | ||
387 | return; | ||
388 | } | ||
389 | |||
390 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) | 376 | static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) |
391 | { | 377 | { |
392 | return; | 378 | return; |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index e1731ff8af4d..7676690a0386 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
13 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -294,7 +293,7 @@ void usb_kick_khubd(struct usb_device *hdev) | |||
294 | /* completion function, fires on port status changes and various faults */ | 293 | /* completion function, fires on port status changes and various faults */ |
295 | static void hub_irq(struct urb *urb, struct pt_regs *regs) | 294 | static void hub_irq(struct urb *urb, struct pt_regs *regs) |
296 | { | 295 | { |
297 | struct usb_hub *hub = (struct usb_hub *)urb->context; | 296 | struct usb_hub *hub = urb->context; |
298 | int status; | 297 | int status; |
299 | int i; | 298 | int i; |
300 | unsigned long bits; | 299 | unsigned long bits; |
@@ -312,7 +311,7 @@ static void hub_irq(struct urb *urb, struct pt_regs *regs) | |||
312 | goto resubmit; | 311 | goto resubmit; |
313 | hub->error = urb->status; | 312 | hub->error = urb->status; |
314 | /* FALL THROUGH */ | 313 | /* FALL THROUGH */ |
315 | 314 | ||
316 | /* let khubd handle things */ | 315 | /* let khubd handle things */ |
317 | case 0: /* we got data: port status changed */ | 316 | case 0: /* we got data: port status changed */ |
318 | bits = 0; | 317 | bits = 0; |
@@ -453,18 +452,14 @@ static void hub_power_on(struct usb_hub *hub) | |||
453 | msleep(max(pgood_delay, (unsigned) 100)); | 452 | msleep(max(pgood_delay, (unsigned) 100)); |
454 | } | 453 | } |
455 | 454 | ||
456 | static inline void __hub_quiesce(struct usb_hub *hub) | 455 | static void hub_quiesce(struct usb_hub *hub) |
457 | { | 456 | { |
458 | /* (nonblocking) khubd and related activity won't re-trigger */ | 457 | /* (nonblocking) khubd and related activity won't re-trigger */ |
459 | hub->quiescing = 1; | 458 | hub->quiescing = 1; |
460 | hub->activating = 0; | 459 | hub->activating = 0; |
461 | hub->resume_root_hub = 0; | 460 | hub->resume_root_hub = 0; |
462 | } | ||
463 | 461 | ||
464 | static void hub_quiesce(struct usb_hub *hub) | ||
465 | { | ||
466 | /* (blocking) stop khubd and related activity */ | 462 | /* (blocking) stop khubd and related activity */ |
467 | __hub_quiesce(hub); | ||
468 | usb_kill_urb(hub->urb); | 463 | usb_kill_urb(hub->urb); |
469 | if (hub->has_indicators) | 464 | if (hub->has_indicators) |
470 | cancel_delayed_work(&hub->leds); | 465 | cancel_delayed_work(&hub->leds); |
@@ -869,13 +864,8 @@ descriptor_error: | |||
869 | 864 | ||
870 | endpoint = &desc->endpoint[0].desc; | 865 | endpoint = &desc->endpoint[0].desc; |
871 | 866 | ||
872 | /* Output endpoint? Curiouser and curiouser.. */ | 867 | /* If it's not an interrupt in endpoint, we'd better punt! */ |
873 | if (!(endpoint->bEndpointAddress & USB_DIR_IN)) | 868 | if (!usb_endpoint_is_int_in(endpoint)) |
874 | goto descriptor_error; | ||
875 | |||
876 | /* If it's not an interrupt endpoint, we'd better punt! */ | ||
877 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | ||
878 | != USB_ENDPOINT_XFER_INT) | ||
879 | goto descriptor_error; | 869 | goto descriptor_error; |
880 | 870 | ||
881 | /* We found a hub */ | 871 | /* We found a hub */ |
@@ -1023,26 +1013,29 @@ void usb_set_device_state(struct usb_device *udev, | |||
1023 | if (udev->state == USB_STATE_NOTATTACHED) | 1013 | if (udev->state == USB_STATE_NOTATTACHED) |
1024 | ; /* do nothing */ | 1014 | ; /* do nothing */ |
1025 | else if (new_state != USB_STATE_NOTATTACHED) { | 1015 | else if (new_state != USB_STATE_NOTATTACHED) { |
1026 | udev->state = new_state; | ||
1027 | 1016 | ||
1028 | /* root hub wakeup capabilities are managed out-of-band | 1017 | /* root hub wakeup capabilities are managed out-of-band |
1029 | * and may involve silicon errata ... ignore them here. | 1018 | * and may involve silicon errata ... ignore them here. |
1030 | */ | 1019 | */ |
1031 | if (udev->parent) { | 1020 | if (udev->parent) { |
1032 | if (new_state == USB_STATE_CONFIGURED) | 1021 | if (udev->state == USB_STATE_SUSPENDED |
1022 | || new_state == USB_STATE_SUSPENDED) | ||
1023 | ; /* No change to wakeup settings */ | ||
1024 | else if (new_state == USB_STATE_CONFIGURED) | ||
1033 | device_init_wakeup(&udev->dev, | 1025 | device_init_wakeup(&udev->dev, |
1034 | (udev->actconfig->desc.bmAttributes | 1026 | (udev->actconfig->desc.bmAttributes |
1035 | & USB_CONFIG_ATT_WAKEUP)); | 1027 | & USB_CONFIG_ATT_WAKEUP)); |
1036 | else if (new_state != USB_STATE_SUSPENDED) | 1028 | else |
1037 | device_init_wakeup(&udev->dev, 0); | 1029 | device_init_wakeup(&udev->dev, 0); |
1038 | } | 1030 | } |
1031 | udev->state = new_state; | ||
1039 | } else | 1032 | } else |
1040 | recursively_mark_NOTATTACHED(udev); | 1033 | recursively_mark_NOTATTACHED(udev); |
1041 | spin_unlock_irqrestore(&device_state_lock, flags); | 1034 | spin_unlock_irqrestore(&device_state_lock, flags); |
1042 | } | 1035 | } |
1043 | 1036 | ||
1044 | 1037 | ||
1045 | #ifdef CONFIG_PM | 1038 | #ifdef CONFIG_PM |
1046 | 1039 | ||
1047 | /** | 1040 | /** |
1048 | * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power | 1041 | * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power |
@@ -1060,6 +1053,12 @@ void usb_root_hub_lost_power(struct usb_device *rhdev) | |||
1060 | unsigned long flags; | 1053 | unsigned long flags; |
1061 | 1054 | ||
1062 | dev_warn(&rhdev->dev, "root hub lost power or was reset\n"); | 1055 | dev_warn(&rhdev->dev, "root hub lost power or was reset\n"); |
1056 | |||
1057 | /* Make sure no potential wakeup events get lost, | ||
1058 | * by forcing the root hub to be resumed. | ||
1059 | */ | ||
1060 | rhdev->dev.power.prev_state.event = PM_EVENT_ON; | ||
1061 | |||
1063 | spin_lock_irqsave(&device_state_lock, flags); | 1062 | spin_lock_irqsave(&device_state_lock, flags); |
1064 | hub = hdev_to_hub(rhdev); | 1063 | hub = hdev_to_hub(rhdev); |
1065 | for (port1 = 1; port1 <= rhdev->maxchild; ++port1) { | 1064 | for (port1 = 1; port1 <= rhdev->maxchild; ++port1) { |
@@ -1073,7 +1072,7 @@ void usb_root_hub_lost_power(struct usb_device *rhdev) | |||
1073 | } | 1072 | } |
1074 | EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); | 1073 | EXPORT_SYMBOL_GPL(usb_root_hub_lost_power); |
1075 | 1074 | ||
1076 | #endif | 1075 | #endif /* CONFIG_PM */ |
1077 | 1076 | ||
1078 | static void choose_address(struct usb_device *udev) | 1077 | static void choose_address(struct usb_device *udev) |
1079 | { | 1078 | { |
@@ -1149,144 +1148,28 @@ void usb_disconnect(struct usb_device **pdev) | |||
1149 | * cleaning up all state associated with the current configuration | 1148 | * cleaning up all state associated with the current configuration |
1150 | * so that the hardware is now fully quiesced. | 1149 | * so that the hardware is now fully quiesced. |
1151 | */ | 1150 | */ |
1151 | dev_dbg (&udev->dev, "unregistering device\n"); | ||
1152 | usb_disable_device(udev, 0); | 1152 | usb_disable_device(udev, 0); |
1153 | 1153 | ||
1154 | usb_notify_remove_device(udev); | 1154 | usb_unlock_device(udev); |
1155 | 1155 | ||
1156 | /* Free the device number, remove the /proc/bus/usb entry and | 1156 | /* Unregister the device. The device driver is responsible |
1157 | * the sysfs attributes, and delete the parent's children[] | 1157 | * for removing the device files from usbfs and sysfs and for |
1158 | * de-configuring the device. | ||
1159 | */ | ||
1160 | device_del(&udev->dev); | ||
1161 | |||
1162 | /* Free the device number and delete the parent's children[] | ||
1158 | * (or root_hub) pointer. | 1163 | * (or root_hub) pointer. |
1159 | */ | 1164 | */ |
1160 | dev_dbg (&udev->dev, "unregistering device\n"); | ||
1161 | release_address(udev); | 1165 | release_address(udev); |
1162 | usb_remove_sysfs_dev_files(udev); | ||
1163 | 1166 | ||
1164 | /* Avoid races with recursively_mark_NOTATTACHED() */ | 1167 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1165 | spin_lock_irq(&device_state_lock); | 1168 | spin_lock_irq(&device_state_lock); |
1166 | *pdev = NULL; | 1169 | *pdev = NULL; |
1167 | spin_unlock_irq(&device_state_lock); | 1170 | spin_unlock_irq(&device_state_lock); |
1168 | 1171 | ||
1169 | usb_unlock_device(udev); | 1172 | put_device(&udev->dev); |
1170 | |||
1171 | device_unregister(&udev->dev); | ||
1172 | } | ||
1173 | |||
1174 | static inline const char *plural(int n) | ||
1175 | { | ||
1176 | return (n == 1 ? "" : "s"); | ||
1177 | } | ||
1178 | |||
1179 | static int choose_configuration(struct usb_device *udev) | ||
1180 | { | ||
1181 | int i; | ||
1182 | int num_configs; | ||
1183 | int insufficient_power = 0; | ||
1184 | struct usb_host_config *c, *best; | ||
1185 | |||
1186 | best = NULL; | ||
1187 | c = udev->config; | ||
1188 | num_configs = udev->descriptor.bNumConfigurations; | ||
1189 | for (i = 0; i < num_configs; (i++, c++)) { | ||
1190 | struct usb_interface_descriptor *desc = NULL; | ||
1191 | |||
1192 | /* It's possible that a config has no interfaces! */ | ||
1193 | if (c->desc.bNumInterfaces > 0) | ||
1194 | desc = &c->intf_cache[0]->altsetting->desc; | ||
1195 | |||
1196 | /* | ||
1197 | * HP's USB bus-powered keyboard has only one configuration | ||
1198 | * and it claims to be self-powered; other devices may have | ||
1199 | * similar errors in their descriptors. If the next test | ||
1200 | * were allowed to execute, such configurations would always | ||
1201 | * be rejected and the devices would not work as expected. | ||
1202 | * In the meantime, we run the risk of selecting a config | ||
1203 | * that requires external power at a time when that power | ||
1204 | * isn't available. It seems to be the lesser of two evils. | ||
1205 | * | ||
1206 | * Bugzilla #6448 reports a device that appears to crash | ||
1207 | * when it receives a GET_DEVICE_STATUS request! We don't | ||
1208 | * have any other way to tell whether a device is self-powered, | ||
1209 | * but since we don't use that information anywhere but here, | ||
1210 | * the call has been removed. | ||
1211 | * | ||
1212 | * Maybe the GET_DEVICE_STATUS call and the test below can | ||
1213 | * be reinstated when device firmwares become more reliable. | ||
1214 | * Don't hold your breath. | ||
1215 | */ | ||
1216 | #if 0 | ||
1217 | /* Rule out self-powered configs for a bus-powered device */ | ||
1218 | if (bus_powered && (c->desc.bmAttributes & | ||
1219 | USB_CONFIG_ATT_SELFPOWER)) | ||
1220 | continue; | ||
1221 | #endif | ||
1222 | |||
1223 | /* | ||
1224 | * The next test may not be as effective as it should be. | ||
1225 | * Some hubs have errors in their descriptor, claiming | ||
1226 | * to be self-powered when they are really bus-powered. | ||
1227 | * We will overestimate the amount of current such hubs | ||
1228 | * make available for each port. | ||
1229 | * | ||
1230 | * This is a fairly benign sort of failure. It won't | ||
1231 | * cause us to reject configurations that we should have | ||
1232 | * accepted. | ||
1233 | */ | ||
1234 | |||
1235 | /* Rule out configs that draw too much bus current */ | ||
1236 | if (c->desc.bMaxPower * 2 > udev->bus_mA) { | ||
1237 | insufficient_power++; | ||
1238 | continue; | ||
1239 | } | ||
1240 | |||
1241 | /* If the first config's first interface is COMM/2/0xff | ||
1242 | * (MSFT RNDIS), rule it out unless Linux has host-side | ||
1243 | * RNDIS support. */ | ||
1244 | if (i == 0 && desc | ||
1245 | && desc->bInterfaceClass == USB_CLASS_COMM | ||
1246 | && desc->bInterfaceSubClass == 2 | ||
1247 | && desc->bInterfaceProtocol == 0xff) { | ||
1248 | #ifndef CONFIG_USB_NET_RNDIS_HOST | ||
1249 | continue; | ||
1250 | #else | ||
1251 | best = c; | ||
1252 | #endif | ||
1253 | } | ||
1254 | |||
1255 | /* From the remaining configs, choose the first one whose | ||
1256 | * first interface is for a non-vendor-specific class. | ||
1257 | * Reason: Linux is more likely to have a class driver | ||
1258 | * than a vendor-specific driver. */ | ||
1259 | else if (udev->descriptor.bDeviceClass != | ||
1260 | USB_CLASS_VENDOR_SPEC && | ||
1261 | (!desc || desc->bInterfaceClass != | ||
1262 | USB_CLASS_VENDOR_SPEC)) { | ||
1263 | best = c; | ||
1264 | break; | ||
1265 | } | ||
1266 | |||
1267 | /* If all the remaining configs are vendor-specific, | ||
1268 | * choose the first one. */ | ||
1269 | else if (!best) | ||
1270 | best = c; | ||
1271 | } | ||
1272 | |||
1273 | if (insufficient_power > 0) | ||
1274 | dev_info(&udev->dev, "rejected %d configuration%s " | ||
1275 | "due to insufficient available bus power\n", | ||
1276 | insufficient_power, plural(insufficient_power)); | ||
1277 | |||
1278 | if (best) { | ||
1279 | i = best->desc.bConfigurationValue; | ||
1280 | dev_info(&udev->dev, | ||
1281 | "configuration #%d chosen from %d choice%s\n", | ||
1282 | i, num_configs, plural(num_configs)); | ||
1283 | } else { | ||
1284 | i = -1; | ||
1285 | dev_warn(&udev->dev, | ||
1286 | "no configuration chosen from %d choice%s\n", | ||
1287 | num_configs, plural(num_configs)); | ||
1288 | } | ||
1289 | return i; | ||
1290 | } | 1173 | } |
1291 | 1174 | ||
1292 | #ifdef DEBUG | 1175 | #ifdef DEBUG |
@@ -1329,7 +1212,6 @@ static inline void show_string(struct usb_device *udev, char *id, char *string) | |||
1329 | int usb_new_device(struct usb_device *udev) | 1212 | int usb_new_device(struct usb_device *udev) |
1330 | { | 1213 | { |
1331 | int err; | 1214 | int err; |
1332 | int c; | ||
1333 | 1215 | ||
1334 | err = usb_get_configuration(udev); | 1216 | err = usb_get_configuration(udev); |
1335 | if (err < 0) { | 1217 | if (err < 0) { |
@@ -1372,8 +1254,7 @@ int usb_new_device(struct usb_device *udev) | |||
1372 | USB_DT_OTG, (void **) &desc) == 0) { | 1254 | USB_DT_OTG, (void **) &desc) == 0) { |
1373 | if (desc->bmAttributes & USB_OTG_HNP) { | 1255 | if (desc->bmAttributes & USB_OTG_HNP) { |
1374 | unsigned port1 = udev->portnum; | 1256 | unsigned port1 = udev->portnum; |
1375 | struct usb_device *root = udev->parent; | 1257 | |
1376 | |||
1377 | dev_info(&udev->dev, | 1258 | dev_info(&udev->dev, |
1378 | "Dual-Role OTG device on %sHNP port\n", | 1259 | "Dual-Role OTG device on %sHNP port\n", |
1379 | (port1 == bus->otg_port) | 1260 | (port1 == bus->otg_port) |
@@ -1408,9 +1289,9 @@ int usb_new_device(struct usb_device *udev) | |||
1408 | * (Includes HNP test device.) | 1289 | * (Includes HNP test device.) |
1409 | */ | 1290 | */ |
1410 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { | 1291 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { |
1411 | static int __usb_suspend_device(struct usb_device *, | 1292 | static int __usb_port_suspend(struct usb_device *, |
1412 | int port1); | 1293 | int port1); |
1413 | err = __usb_suspend_device(udev, udev->bus->otg_port); | 1294 | err = __usb_port_suspend(udev, udev->bus->otg_port); |
1414 | if (err < 0) | 1295 | if (err < 0) |
1415 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); | 1296 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); |
1416 | } | 1297 | } |
@@ -1419,34 +1300,15 @@ int usb_new_device(struct usb_device *udev) | |||
1419 | } | 1300 | } |
1420 | #endif | 1301 | #endif |
1421 | 1302 | ||
1422 | /* put device-specific files into sysfs */ | 1303 | /* Register the device. The device driver is responsible |
1304 | * for adding the device files to usbfs and sysfs and for | ||
1305 | * configuring the device. | ||
1306 | */ | ||
1423 | err = device_add (&udev->dev); | 1307 | err = device_add (&udev->dev); |
1424 | if (err) { | 1308 | if (err) { |
1425 | dev_err(&udev->dev, "can't device_add, error %d\n", err); | 1309 | dev_err(&udev->dev, "can't device_add, error %d\n", err); |
1426 | goto fail; | 1310 | goto fail; |
1427 | } | 1311 | } |
1428 | usb_create_sysfs_dev_files (udev); | ||
1429 | |||
1430 | usb_lock_device(udev); | ||
1431 | |||
1432 | /* choose and set the configuration. that registers the interfaces | ||
1433 | * with the driver core, and lets usb device drivers bind to them. | ||
1434 | */ | ||
1435 | c = choose_configuration(udev); | ||
1436 | if (c >= 0) { | ||
1437 | err = usb_set_configuration(udev, c); | ||
1438 | if (err) { | ||
1439 | dev_err(&udev->dev, "can't set config #%d, error %d\n", | ||
1440 | c, err); | ||
1441 | /* This need not be fatal. The user can try to | ||
1442 | * set other configurations. */ | ||
1443 | } | ||
1444 | } | ||
1445 | |||
1446 | /* USB device state == configured ... usable */ | ||
1447 | usb_notify_add_device(udev); | ||
1448 | |||
1449 | usb_unlock_device(udev); | ||
1450 | 1312 | ||
1451 | return 0; | 1313 | return 0; |
1452 | 1314 | ||
@@ -1473,6 +1335,18 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
1473 | return ret; | 1335 | return ret; |
1474 | } | 1336 | } |
1475 | 1337 | ||
1338 | |||
1339 | /* Returns 1 if @hub is a WUSB root hub, 0 otherwise */ | ||
1340 | static unsigned hub_is_wusb(struct usb_hub *hub) | ||
1341 | { | ||
1342 | struct usb_hcd *hcd; | ||
1343 | if (hub->hdev->parent != NULL) /* not a root hub? */ | ||
1344 | return 0; | ||
1345 | hcd = container_of(hub->hdev->bus, struct usb_hcd, self); | ||
1346 | return hcd->wireless; | ||
1347 | } | ||
1348 | |||
1349 | |||
1476 | #define PORT_RESET_TRIES 5 | 1350 | #define PORT_RESET_TRIES 5 |
1477 | #define SET_ADDRESS_TRIES 2 | 1351 | #define SET_ADDRESS_TRIES 2 |
1478 | #define GET_DESCRIPTOR_TRIES 2 | 1352 | #define GET_DESCRIPTOR_TRIES 2 |
@@ -1513,7 +1387,9 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
1513 | /* if we`ve finished resetting, then break out of the loop */ | 1387 | /* if we`ve finished resetting, then break out of the loop */ |
1514 | if (!(portstatus & USB_PORT_STAT_RESET) && | 1388 | if (!(portstatus & USB_PORT_STAT_RESET) && |
1515 | (portstatus & USB_PORT_STAT_ENABLE)) { | 1389 | (portstatus & USB_PORT_STAT_ENABLE)) { |
1516 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 1390 | if (hub_is_wusb(hub)) |
1391 | udev->speed = USB_SPEED_VARIABLE; | ||
1392 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) | ||
1517 | udev->speed = USB_SPEED_HIGH; | 1393 | udev->speed = USB_SPEED_HIGH; |
1518 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 1394 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
1519 | udev->speed = USB_SPEED_LOW; | 1395 | udev->speed = USB_SPEED_LOW; |
@@ -1608,6 +1484,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | |||
1608 | kick_khubd(hub); | 1484 | kick_khubd(hub); |
1609 | } | 1485 | } |
1610 | 1486 | ||
1487 | #ifdef CONFIG_PM | ||
1611 | 1488 | ||
1612 | #ifdef CONFIG_USB_SUSPEND | 1489 | #ifdef CONFIG_USB_SUSPEND |
1613 | 1490 | ||
@@ -1634,7 +1511,7 @@ static int hub_port_suspend(struct usb_hub *hub, int port1, | |||
1634 | * NOTE: OTG devices may issue remote wakeup (or SRP) even when | 1511 | * NOTE: OTG devices may issue remote wakeup (or SRP) even when |
1635 | * we don't explicitly enable it here. | 1512 | * we don't explicitly enable it here. |
1636 | */ | 1513 | */ |
1637 | if (device_may_wakeup(&udev->dev)) { | 1514 | if (udev->do_remote_wakeup) { |
1638 | status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 1515 | status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
1639 | USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, | 1516 | USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, |
1640 | USB_DEVICE_REMOTE_WAKEUP, 0, | 1517 | USB_DEVICE_REMOTE_WAKEUP, 0, |
@@ -1660,7 +1537,8 @@ static int hub_port_suspend(struct usb_hub *hub, int port1, | |||
1660 | USB_CTRL_SET_TIMEOUT); | 1537 | USB_CTRL_SET_TIMEOUT); |
1661 | } else { | 1538 | } else { |
1662 | /* device has up to 10 msec to fully suspend */ | 1539 | /* device has up to 10 msec to fully suspend */ |
1663 | dev_dbg(&udev->dev, "usb suspend\n"); | 1540 | dev_dbg(&udev->dev, "usb %ssuspend\n", |
1541 | udev->auto_pm ? "auto-" : ""); | ||
1664 | usb_set_device_state(udev, USB_STATE_SUSPENDED); | 1542 | usb_set_device_state(udev, USB_STATE_SUSPENDED); |
1665 | msleep(10); | 1543 | msleep(10); |
1666 | } | 1544 | } |
@@ -1685,7 +1563,7 @@ static int hub_port_suspend(struct usb_hub *hub, int port1, | |||
1685 | * the root hub for their bus goes into global suspend ... so we don't | 1563 | * the root hub for their bus goes into global suspend ... so we don't |
1686 | * (falsely) update the device power state to say it suspended. | 1564 | * (falsely) update the device power state to say it suspended. |
1687 | */ | 1565 | */ |
1688 | static int __usb_suspend_device (struct usb_device *udev, int port1) | 1566 | static int __usb_port_suspend (struct usb_device *udev, int port1) |
1689 | { | 1567 | { |
1690 | int status = 0; | 1568 | int status = 0; |
1691 | 1569 | ||
@@ -1693,49 +1571,29 @@ static int __usb_suspend_device (struct usb_device *udev, int port1) | |||
1693 | if (port1 < 0) | 1571 | if (port1 < 0) |
1694 | return port1; | 1572 | return port1; |
1695 | 1573 | ||
1696 | if (udev->state == USB_STATE_SUSPENDED | 1574 | /* we change the device's upstream USB link, |
1697 | || udev->state == USB_STATE_NOTATTACHED) { | 1575 | * but root hubs have no upstream USB link. |
1698 | return 0; | ||
1699 | } | ||
1700 | |||
1701 | /* all interfaces must already be suspended */ | ||
1702 | if (udev->actconfig) { | ||
1703 | int i; | ||
1704 | |||
1705 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1706 | struct usb_interface *intf; | ||
1707 | |||
1708 | intf = udev->actconfig->interface[i]; | ||
1709 | if (is_active(intf)) { | ||
1710 | dev_dbg(&intf->dev, "nyet suspended\n"); | ||
1711 | return -EBUSY; | ||
1712 | } | ||
1713 | } | ||
1714 | } | ||
1715 | |||
1716 | /* we only change a device's upstream USB link. | ||
1717 | * root hubs have no upstream USB link. | ||
1718 | */ | 1576 | */ |
1719 | if (udev->parent) | 1577 | if (udev->parent) |
1720 | status = hub_port_suspend(hdev_to_hub(udev->parent), port1, | 1578 | status = hub_port_suspend(hdev_to_hub(udev->parent), port1, |
1721 | udev); | 1579 | udev); |
1722 | 1580 | else { | |
1723 | if (status == 0) | 1581 | dev_dbg(&udev->dev, "usb %ssuspend\n", |
1724 | udev->dev.power.power_state = PMSG_SUSPEND; | 1582 | udev->auto_pm ? "auto-" : ""); |
1583 | usb_set_device_state(udev, USB_STATE_SUSPENDED); | ||
1584 | } | ||
1725 | return status; | 1585 | return status; |
1726 | } | 1586 | } |
1727 | 1587 | ||
1728 | #endif | ||
1729 | |||
1730 | /* | 1588 | /* |
1731 | * usb_suspend_device - suspend a usb device | 1589 | * usb_port_suspend - suspend a usb device's upstream port |
1732 | * @udev: device that's no longer in active use | 1590 | * @udev: device that's no longer in active use |
1733 | * Context: must be able to sleep; device not locked; pm locks held | 1591 | * Context: must be able to sleep; device not locked; pm locks held |
1734 | * | 1592 | * |
1735 | * Suspends a USB device that isn't in active use, conserving power. | 1593 | * Suspends a USB device that isn't in active use, conserving power. |
1736 | * Devices may wake out of a suspend, if anything important happens, | 1594 | * Devices may wake out of a suspend, if anything important happens, |
1737 | * using the remote wakeup mechanism. They may also be taken out of | 1595 | * using the remote wakeup mechanism. They may also be taken out of |
1738 | * suspend by the host, using usb_resume_device(). It's also routine | 1596 | * suspend by the host, using usb_port_resume(). It's also routine |
1739 | * to disconnect devices while they are suspended. | 1597 | * to disconnect devices while they are suspended. |
1740 | * | 1598 | * |
1741 | * This only affects the USB hardware for a device; its interfaces | 1599 | * This only affects the USB hardware for a device; its interfaces |
@@ -1747,17 +1605,9 @@ static int __usb_suspend_device (struct usb_device *udev, int port1) | |||
1747 | * | 1605 | * |
1748 | * Returns 0 on success, else negative errno. | 1606 | * Returns 0 on success, else negative errno. |
1749 | */ | 1607 | */ |
1750 | int usb_suspend_device(struct usb_device *udev) | 1608 | int usb_port_suspend(struct usb_device *udev) |
1751 | { | 1609 | { |
1752 | #ifdef CONFIG_USB_SUSPEND | 1610 | return __usb_port_suspend(udev, udev->portnum); |
1753 | if (udev->state == USB_STATE_NOTATTACHED) | ||
1754 | return -ENODEV; | ||
1755 | return __usb_suspend_device(udev, udev->portnum); | ||
1756 | #else | ||
1757 | /* NOTE: udev->state unchanged, it's not lying ... */ | ||
1758 | udev->dev.power.power_state = PMSG_SUSPEND; | ||
1759 | return 0; | ||
1760 | #endif | ||
1761 | } | 1611 | } |
1762 | 1612 | ||
1763 | /* | 1613 | /* |
@@ -1768,7 +1618,7 @@ int usb_suspend_device(struct usb_device *udev) | |||
1768 | * resume (by host) or remote wakeup (by device) ... now see what changed | 1618 | * resume (by host) or remote wakeup (by device) ... now see what changed |
1769 | * in the tree that's rooted at this device. | 1619 | * in the tree that's rooted at this device. |
1770 | */ | 1620 | */ |
1771 | static int finish_device_resume(struct usb_device *udev) | 1621 | static int finish_port_resume(struct usb_device *udev) |
1772 | { | 1622 | { |
1773 | int status; | 1623 | int status; |
1774 | u16 devstatus; | 1624 | u16 devstatus; |
@@ -1784,21 +1634,20 @@ static int finish_device_resume(struct usb_device *udev) | |||
1784 | usb_set_device_state(udev, udev->actconfig | 1634 | usb_set_device_state(udev, udev->actconfig |
1785 | ? USB_STATE_CONFIGURED | 1635 | ? USB_STATE_CONFIGURED |
1786 | : USB_STATE_ADDRESS); | 1636 | : USB_STATE_ADDRESS); |
1787 | udev->dev.power.power_state = PMSG_ON; | ||
1788 | 1637 | ||
1789 | /* 10.5.4.5 says be sure devices in the tree are still there. | 1638 | /* 10.5.4.5 says be sure devices in the tree are still there. |
1790 | * For now let's assume the device didn't go crazy on resume, | 1639 | * For now let's assume the device didn't go crazy on resume, |
1791 | * and device drivers will know about any resume quirks. | 1640 | * and device drivers will know about any resume quirks. |
1792 | */ | 1641 | */ |
1793 | status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); | 1642 | status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); |
1794 | if (status < 2) | 1643 | if (status >= 0) |
1644 | status = (status == 2 ? 0 : -ENODEV); | ||
1645 | |||
1646 | if (status) | ||
1795 | dev_dbg(&udev->dev, | 1647 | dev_dbg(&udev->dev, |
1796 | "gone after usb resume? status %d\n", | 1648 | "gone after usb resume? status %d\n", |
1797 | status); | 1649 | status); |
1798 | else if (udev->actconfig) { | 1650 | else if (udev->actconfig) { |
1799 | unsigned i; | ||
1800 | int (*resume)(struct device *); | ||
1801 | |||
1802 | le16_to_cpus(&devstatus); | 1651 | le16_to_cpus(&devstatus); |
1803 | if ((devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) | 1652 | if ((devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) |
1804 | && udev->parent) { | 1653 | && udev->parent) { |
@@ -1809,24 +1658,9 @@ static int finish_device_resume(struct usb_device *udev) | |||
1809 | USB_DEVICE_REMOTE_WAKEUP, 0, | 1658 | USB_DEVICE_REMOTE_WAKEUP, 0, |
1810 | NULL, 0, | 1659 | NULL, 0, |
1811 | USB_CTRL_SET_TIMEOUT); | 1660 | USB_CTRL_SET_TIMEOUT); |
1812 | if (status) { | 1661 | if (status) |
1813 | dev_dbg(&udev->dev, "disable remote " | 1662 | dev_dbg(&udev->dev, "disable remote " |
1814 | "wakeup, status %d\n", status); | 1663 | "wakeup, status %d\n", status); |
1815 | status = 0; | ||
1816 | } | ||
1817 | } | ||
1818 | |||
1819 | /* resume interface drivers; if this is a hub, it | ||
1820 | * may have a child resume event to deal with soon | ||
1821 | */ | ||
1822 | resume = udev->dev.bus->resume; | ||
1823 | for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { | ||
1824 | struct device *dev = | ||
1825 | &udev->actconfig->interface[i]->dev; | ||
1826 | |||
1827 | down(&dev->sem); | ||
1828 | (void) resume(dev); | ||
1829 | up(&dev->sem); | ||
1830 | } | 1664 | } |
1831 | status = 0; | 1665 | status = 0; |
1832 | 1666 | ||
@@ -1837,8 +1671,6 @@ static int finish_device_resume(struct usb_device *udev) | |||
1837 | return status; | 1671 | return status; |
1838 | } | 1672 | } |
1839 | 1673 | ||
1840 | #ifdef CONFIG_USB_SUSPEND | ||
1841 | |||
1842 | static int | 1674 | static int |
1843 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | 1675 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) |
1844 | { | 1676 | { |
@@ -1846,6 +1678,8 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1846 | 1678 | ||
1847 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); | 1679 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); |
1848 | 1680 | ||
1681 | set_bit(port1, hub->busy_bits); | ||
1682 | |||
1849 | /* see 7.1.7.7; affects power usage, but not budgeting */ | 1683 | /* see 7.1.7.7; affects power usage, but not budgeting */ |
1850 | status = clear_port_feature(hub->hdev, | 1684 | status = clear_port_feature(hub->hdev, |
1851 | port1, USB_PORT_FEAT_SUSPEND); | 1685 | port1, USB_PORT_FEAT_SUSPEND); |
@@ -1859,7 +1693,8 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1859 | 1693 | ||
1860 | /* drive resume for at least 20 msec */ | 1694 | /* drive resume for at least 20 msec */ |
1861 | if (udev) | 1695 | if (udev) |
1862 | dev_dbg(&udev->dev, "RESUME\n"); | 1696 | dev_dbg(&udev->dev, "usb %sresume\n", |
1697 | udev->auto_pm ? "auto-" : ""); | ||
1863 | msleep(25); | 1698 | msleep(25); |
1864 | 1699 | ||
1865 | #define LIVE_FLAGS ( USB_PORT_STAT_POWER \ | 1700 | #define LIVE_FLAGS ( USB_PORT_STAT_POWER \ |
@@ -1880,23 +1715,30 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1880 | dev_dbg(hub->intfdev, | 1715 | dev_dbg(hub->intfdev, |
1881 | "port %d status %04x.%04x after resume, %d\n", | 1716 | "port %d status %04x.%04x after resume, %d\n", |
1882 | port1, portchange, devstatus, status); | 1717 | port1, portchange, devstatus, status); |
1718 | if (status >= 0) | ||
1719 | status = -ENODEV; | ||
1883 | } else { | 1720 | } else { |
1721 | if (portchange & USB_PORT_STAT_C_SUSPEND) | ||
1722 | clear_port_feature(hub->hdev, port1, | ||
1723 | USB_PORT_FEAT_C_SUSPEND); | ||
1884 | /* TRSMRCY = 10 msec */ | 1724 | /* TRSMRCY = 10 msec */ |
1885 | msleep(10); | 1725 | msleep(10); |
1886 | if (udev) | 1726 | if (udev) |
1887 | status = finish_device_resume(udev); | 1727 | status = finish_port_resume(udev); |
1888 | } | 1728 | } |
1889 | } | 1729 | } |
1890 | if (status < 0) | 1730 | if (status < 0) |
1891 | hub_port_logical_disconnect(hub, port1); | 1731 | hub_port_logical_disconnect(hub, port1); |
1892 | 1732 | ||
1733 | clear_bit(port1, hub->busy_bits); | ||
1734 | if (!hub->hdev->parent && !hub->busy_bits[0]) | ||
1735 | usb_enable_root_hub_irq(hub->hdev->bus); | ||
1736 | |||
1893 | return status; | 1737 | return status; |
1894 | } | 1738 | } |
1895 | 1739 | ||
1896 | #endif | ||
1897 | |||
1898 | /* | 1740 | /* |
1899 | * usb_resume_device - re-activate a suspended usb device | 1741 | * usb_port_resume - re-activate a suspended usb device's upstream port |
1900 | * @udev: device to re-activate | 1742 | * @udev: device to re-activate |
1901 | * Context: must be able to sleep; device not locked; pm locks held | 1743 | * Context: must be able to sleep; device not locked; pm locks held |
1902 | * | 1744 | * |
@@ -1908,36 +1750,24 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1908 | * | 1750 | * |
1909 | * Returns 0 on success, else negative errno. | 1751 | * Returns 0 on success, else negative errno. |
1910 | */ | 1752 | */ |
1911 | int usb_resume_device(struct usb_device *udev) | 1753 | int usb_port_resume(struct usb_device *udev) |
1912 | { | 1754 | { |
1913 | int status; | 1755 | int status; |
1914 | 1756 | ||
1915 | if (udev->state == USB_STATE_NOTATTACHED) | 1757 | /* we change the device's upstream USB link, |
1916 | return -ENODEV; | 1758 | * but root hubs have no upstream USB link. |
1917 | 1759 | */ | |
1918 | /* selective resume of one downstream hub-to-device port */ | ||
1919 | if (udev->parent) { | 1760 | if (udev->parent) { |
1920 | #ifdef CONFIG_USB_SUSPEND | 1761 | // NOTE this fails if parent is also suspended... |
1921 | if (udev->state == USB_STATE_SUSPENDED) { | 1762 | status = hub_port_resume(hdev_to_hub(udev->parent), |
1922 | // NOTE swsusp may bork us, device state being wrong... | 1763 | udev->portnum, udev); |
1923 | // NOTE this fails if parent is also suspended... | 1764 | } else { |
1924 | status = hub_port_resume(hdev_to_hub(udev->parent), | 1765 | dev_dbg(&udev->dev, "usb %sresume\n", |
1925 | udev->portnum, udev); | 1766 | udev->auto_pm ? "auto-" : ""); |
1926 | } else | 1767 | status = finish_port_resume(udev); |
1927 | #endif | ||
1928 | status = 0; | ||
1929 | } else | ||
1930 | status = finish_device_resume(udev); | ||
1931 | if (status < 0) | ||
1932 | dev_dbg(&udev->dev, "can't resume, status %d\n", | ||
1933 | status); | ||
1934 | |||
1935 | /* rebind drivers that had no suspend() */ | ||
1936 | if (status == 0) { | ||
1937 | usb_unlock_device(udev); | ||
1938 | bus_rescan_devices(&usb_bus_type); | ||
1939 | usb_lock_device(udev); | ||
1940 | } | 1768 | } |
1769 | if (status < 0) | ||
1770 | dev_dbg(&udev->dev, "can't resume, status %d\n", status); | ||
1941 | return status; | 1771 | return status; |
1942 | } | 1772 | } |
1943 | 1773 | ||
@@ -1945,23 +1775,60 @@ static int remote_wakeup(struct usb_device *udev) | |||
1945 | { | 1775 | { |
1946 | int status = 0; | 1776 | int status = 0; |
1947 | 1777 | ||
1948 | #ifdef CONFIG_USB_SUSPEND | 1778 | /* All this just to avoid sending a port-resume message |
1779 | * to the parent hub! */ | ||
1949 | 1780 | ||
1950 | /* don't repeat RESUME sequence if this device | ||
1951 | * was already woken up by some other task | ||
1952 | */ | ||
1953 | usb_lock_device(udev); | 1781 | usb_lock_device(udev); |
1782 | usb_pm_lock(udev); | ||
1954 | if (udev->state == USB_STATE_SUSPENDED) { | 1783 | if (udev->state == USB_STATE_SUSPENDED) { |
1955 | dev_dbg(&udev->dev, "RESUME (wakeup)\n"); | 1784 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
1956 | /* TRSMRCY = 10 msec */ | 1785 | /* TRSMRCY = 10 msec */ |
1957 | msleep(10); | 1786 | msleep(10); |
1958 | status = finish_device_resume(udev); | 1787 | status = finish_port_resume(udev); |
1788 | if (status == 0) | ||
1789 | udev->dev.power.power_state.event = PM_EVENT_ON; | ||
1959 | } | 1790 | } |
1791 | usb_pm_unlock(udev); | ||
1792 | |||
1793 | if (status == 0) | ||
1794 | usb_autoresume_device(udev, 0); | ||
1960 | usb_unlock_device(udev); | 1795 | usb_unlock_device(udev); |
1961 | #endif | ||
1962 | return status; | 1796 | return status; |
1963 | } | 1797 | } |
1964 | 1798 | ||
1799 | #else /* CONFIG_USB_SUSPEND */ | ||
1800 | |||
1801 | /* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */ | ||
1802 | |||
1803 | int usb_port_suspend(struct usb_device *udev) | ||
1804 | { | ||
1805 | return 0; | ||
1806 | } | ||
1807 | |||
1808 | static inline int | ||
1809 | finish_port_resume(struct usb_device *udev) | ||
1810 | { | ||
1811 | return 0; | ||
1812 | } | ||
1813 | |||
1814 | static inline int | ||
1815 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | ||
1816 | { | ||
1817 | return 0; | ||
1818 | } | ||
1819 | |||
1820 | int usb_port_resume(struct usb_device *udev) | ||
1821 | { | ||
1822 | return 0; | ||
1823 | } | ||
1824 | |||
1825 | static inline int remote_wakeup(struct usb_device *udev) | ||
1826 | { | ||
1827 | return 0; | ||
1828 | } | ||
1829 | |||
1830 | #endif | ||
1831 | |||
1965 | static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | 1832 | static int hub_suspend(struct usb_interface *intf, pm_message_t msg) |
1966 | { | 1833 | { |
1967 | struct usb_hub *hub = usb_get_intfdata (intf); | 1834 | struct usb_hub *hub = usb_get_intfdata (intf); |
@@ -1973,13 +1840,17 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
1973 | struct usb_device *udev; | 1840 | struct usb_device *udev; |
1974 | 1841 | ||
1975 | udev = hdev->children [port1-1]; | 1842 | udev = hdev->children [port1-1]; |
1976 | if (udev && (udev->dev.power.power_state.event | 1843 | if (udev && msg.event == PM_EVENT_SUSPEND && |
1977 | == PM_EVENT_ON | ||
1978 | #ifdef CONFIG_USB_SUSPEND | 1844 | #ifdef CONFIG_USB_SUSPEND |
1979 | || udev->state != USB_STATE_SUSPENDED | 1845 | udev->state != USB_STATE_SUSPENDED |
1846 | #else | ||
1847 | udev->dev.power.power_state.event | ||
1848 | == PM_EVENT_ON | ||
1980 | #endif | 1849 | #endif |
1981 | )) { | 1850 | ) { |
1982 | dev_dbg(&intf->dev, "port %d nyet suspended\n", port1); | 1851 | if (!hdev->auto_pm) |
1852 | dev_dbg(&intf->dev, "port %d nyet suspended\n", | ||
1853 | port1); | ||
1983 | return -EBUSY; | 1854 | return -EBUSY; |
1984 | } | 1855 | } |
1985 | } | 1856 | } |
@@ -2028,66 +1899,22 @@ static int hub_resume(struct usb_interface *intf) | |||
2028 | } | 1899 | } |
2029 | } | 1900 | } |
2030 | 1901 | ||
1902 | /* tell khubd to look for changes on this hub */ | ||
2031 | hub_activate(hub); | 1903 | hub_activate(hub); |
2032 | |||
2033 | /* REVISIT: this recursion probably shouldn't exist. Remove | ||
2034 | * this code sometime, after retesting with different root and | ||
2035 | * external hubs. | ||
2036 | */ | ||
2037 | #ifdef CONFIG_USB_SUSPEND | ||
2038 | { | ||
2039 | unsigned port1; | ||
2040 | |||
2041 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { | ||
2042 | struct usb_device *udev; | ||
2043 | u16 portstat, portchange; | ||
2044 | |||
2045 | udev = hdev->children [port1-1]; | ||
2046 | status = hub_port_status(hub, port1, &portstat, &portchange); | ||
2047 | if (status == 0) { | ||
2048 | if (portchange & USB_PORT_STAT_C_SUSPEND) { | ||
2049 | clear_port_feature(hdev, port1, | ||
2050 | USB_PORT_FEAT_C_SUSPEND); | ||
2051 | portchange &= ~USB_PORT_STAT_C_SUSPEND; | ||
2052 | } | ||
2053 | |||
2054 | /* let khubd handle disconnects etc */ | ||
2055 | if (portchange) | ||
2056 | continue; | ||
2057 | } | ||
2058 | |||
2059 | if (!udev || status < 0) | ||
2060 | continue; | ||
2061 | usb_lock_device(udev); | ||
2062 | if (portstat & USB_PORT_STAT_SUSPEND) | ||
2063 | status = hub_port_resume(hub, port1, udev); | ||
2064 | else { | ||
2065 | status = finish_device_resume(udev); | ||
2066 | if (status < 0) { | ||
2067 | dev_dbg(&intf->dev, "resume port %d --> %d\n", | ||
2068 | port1, status); | ||
2069 | hub_port_logical_disconnect(hub, port1); | ||
2070 | } | ||
2071 | } | ||
2072 | usb_unlock_device(udev); | ||
2073 | } | ||
2074 | } | ||
2075 | #endif | ||
2076 | return 0; | 1904 | return 0; |
2077 | } | 1905 | } |
2078 | 1906 | ||
2079 | void usb_suspend_root_hub(struct usb_device *hdev) | 1907 | #else /* CONFIG_PM */ |
2080 | { | ||
2081 | struct usb_hub *hub = hdev_to_hub(hdev); | ||
2082 | 1908 | ||
2083 | /* This also makes any led blinker stop retriggering. We're called | 1909 | static inline int remote_wakeup(struct usb_device *udev) |
2084 | * from irq, so the blinker might still be scheduled. Caller promises | 1910 | { |
2085 | * that the root hub status URB will be canceled. | 1911 | return 0; |
2086 | */ | ||
2087 | __hub_quiesce(hub); | ||
2088 | mark_quiesced(to_usb_interface(hub->intfdev)); | ||
2089 | } | 1912 | } |
2090 | 1913 | ||
1914 | #define hub_suspend NULL | ||
1915 | #define hub_resume NULL | ||
1916 | #endif | ||
1917 | |||
2091 | void usb_resume_root_hub(struct usb_device *hdev) | 1918 | void usb_resume_root_hub(struct usb_device *hdev) |
2092 | { | 1919 | { |
2093 | struct usb_hub *hub = hdev_to_hub(hdev); | 1920 | struct usb_hub *hub = hdev_to_hub(hdev); |
@@ -2207,6 +2034,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2207 | int i, j, retval; | 2034 | int i, j, retval; |
2208 | unsigned delay = HUB_SHORT_RESET_TIME; | 2035 | unsigned delay = HUB_SHORT_RESET_TIME; |
2209 | enum usb_device_speed oldspeed = udev->speed; | 2036 | enum usb_device_speed oldspeed = udev->speed; |
2037 | char *speed, *type; | ||
2210 | 2038 | ||
2211 | /* root hub ports have a slightly longer reset period | 2039 | /* root hub ports have a slightly longer reset period |
2212 | * (from USB 2.0 spec, section 7.1.7.5) | 2040 | * (from USB 2.0 spec, section 7.1.7.5) |
@@ -2239,8 +2067,13 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2239 | 2067 | ||
2240 | /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... | 2068 | /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... |
2241 | * it's fixed size except for full speed devices. | 2069 | * it's fixed size except for full speed devices. |
2070 | * For Wireless USB devices, ep0 max packet is always 512 (tho | ||
2071 | * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. | ||
2242 | */ | 2072 | */ |
2243 | switch (udev->speed) { | 2073 | switch (udev->speed) { |
2074 | case USB_SPEED_VARIABLE: /* fixed at 512 */ | ||
2075 | udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(512); | ||
2076 | break; | ||
2244 | case USB_SPEED_HIGH: /* fixed at 64 */ | 2077 | case USB_SPEED_HIGH: /* fixed at 64 */ |
2245 | udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); | 2078 | udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); |
2246 | break; | 2079 | break; |
@@ -2258,17 +2091,21 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2258 | goto fail; | 2091 | goto fail; |
2259 | } | 2092 | } |
2260 | 2093 | ||
2094 | type = ""; | ||
2095 | switch (udev->speed) { | ||
2096 | case USB_SPEED_LOW: speed = "low"; break; | ||
2097 | case USB_SPEED_FULL: speed = "full"; break; | ||
2098 | case USB_SPEED_HIGH: speed = "high"; break; | ||
2099 | case USB_SPEED_VARIABLE: | ||
2100 | speed = "variable"; | ||
2101 | type = "Wireless "; | ||
2102 | break; | ||
2103 | default: speed = "?"; break; | ||
2104 | } | ||
2261 | dev_info (&udev->dev, | 2105 | dev_info (&udev->dev, |
2262 | "%s %s speed USB device using %s and address %d\n", | 2106 | "%s %s speed %sUSB device using %s and address %d\n", |
2263 | (udev->config) ? "reset" : "new", | 2107 | (udev->config) ? "reset" : "new", speed, type, |
2264 | ({ char *speed; switch (udev->speed) { | 2108 | udev->bus->controller->driver->name, udev->devnum); |
2265 | case USB_SPEED_LOW: speed = "low"; break; | ||
2266 | case USB_SPEED_FULL: speed = "full"; break; | ||
2267 | case USB_SPEED_HIGH: speed = "high"; break; | ||
2268 | default: speed = "?"; break; | ||
2269 | }; speed;}), | ||
2270 | udev->bus->controller->driver->name, | ||
2271 | udev->devnum); | ||
2272 | 2109 | ||
2273 | /* Set up TT records, if needed */ | 2110 | /* Set up TT records, if needed */ |
2274 | if (hdev->tt) { | 2111 | if (hdev->tt) { |
@@ -2310,6 +2147,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2310 | * down tremendously by NAKing the unexpectedly | 2147 | * down tremendously by NAKing the unexpectedly |
2311 | * early status stage. Also, retry on all errors; | 2148 | * early status stage. Also, retry on all errors; |
2312 | * some devices are flakey. | 2149 | * some devices are flakey. |
2150 | * 255 is for WUSB devices, we actually need to use 512. | ||
2151 | * WUSB1.0[4.8.1]. | ||
2313 | */ | 2152 | */ |
2314 | for (j = 0; j < 3; ++j) { | 2153 | for (j = 0; j < 3; ++j) { |
2315 | buf->bMaxPacketSize0 = 0; | 2154 | buf->bMaxPacketSize0 = 0; |
@@ -2319,7 +2158,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2319 | buf, GET_DESCRIPTOR_BUFSIZE, | 2158 | buf, GET_DESCRIPTOR_BUFSIZE, |
2320 | (i ? USB_CTRL_GET_TIMEOUT : 1000)); | 2159 | (i ? USB_CTRL_GET_TIMEOUT : 1000)); |
2321 | switch (buf->bMaxPacketSize0) { | 2160 | switch (buf->bMaxPacketSize0) { |
2322 | case 8: case 16: case 32: case 64: | 2161 | case 8: case 16: case 32: case 64: case 255: |
2323 | if (buf->bDescriptorType == | 2162 | if (buf->bDescriptorType == |
2324 | USB_DT_DEVICE) { | 2163 | USB_DT_DEVICE) { |
2325 | r = 0; | 2164 | r = 0; |
@@ -2393,7 +2232,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2393 | if (retval) | 2232 | if (retval) |
2394 | goto fail; | 2233 | goto fail; |
2395 | 2234 | ||
2396 | i = udev->descriptor.bMaxPacketSize0; | 2235 | i = udev->descriptor.bMaxPacketSize0 == 0xff? |
2236 | 512 : udev->descriptor.bMaxPacketSize0; | ||
2397 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { | 2237 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { |
2398 | if (udev->speed != USB_SPEED_FULL || | 2238 | if (udev->speed != USB_SPEED_FULL || |
2399 | !(i == 8 || i == 16 || i == 32 || i == 64)) { | 2239 | !(i == 8 || i == 16 || i == 32 || i == 64)) { |
@@ -2578,6 +2418,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2578 | usb_set_device_state(udev, USB_STATE_POWERED); | 2418 | usb_set_device_state(udev, USB_STATE_POWERED); |
2579 | udev->speed = USB_SPEED_UNKNOWN; | 2419 | udev->speed = USB_SPEED_UNKNOWN; |
2580 | udev->bus_mA = hub->mA_per_port; | 2420 | udev->bus_mA = hub->mA_per_port; |
2421 | udev->level = hdev->level + 1; | ||
2581 | 2422 | ||
2582 | /* set the address */ | 2423 | /* set the address */ |
2583 | choose_address(udev); | 2424 | choose_address(udev); |
@@ -2729,17 +2570,6 @@ static void hub_events(void) | |||
2729 | usb_get_intf(intf); | 2570 | usb_get_intf(intf); |
2730 | spin_unlock_irq(&hub_event_lock); | 2571 | spin_unlock_irq(&hub_event_lock); |
2731 | 2572 | ||
2732 | /* Is this is a root hub wanting to reactivate the downstream | ||
2733 | * ports? If so, be sure the interface resumes even if its | ||
2734 | * stub "device" node was never suspended. | ||
2735 | */ | ||
2736 | if (i) { | ||
2737 | dpm_runtime_resume(&hdev->dev); | ||
2738 | dpm_runtime_resume(&intf->dev); | ||
2739 | usb_put_intf(intf); | ||
2740 | continue; | ||
2741 | } | ||
2742 | |||
2743 | /* Lock the device, then check to see if we were | 2573 | /* Lock the device, then check to see if we were |
2744 | * disconnected while waiting for the lock to succeed. */ | 2574 | * disconnected while waiting for the lock to succeed. */ |
2745 | if (locktree(hdev) < 0) { | 2575 | if (locktree(hdev) < 0) { |
@@ -2756,6 +2586,13 @@ static void hub_events(void) | |||
2756 | goto loop; | 2586 | goto loop; |
2757 | } | 2587 | } |
2758 | 2588 | ||
2589 | /* Is this is a root hub wanting to reactivate the downstream | ||
2590 | * ports? If so, be sure the interface resumes even if its | ||
2591 | * stub "device" node was never suspended. | ||
2592 | */ | ||
2593 | if (i) | ||
2594 | usb_autoresume_device(hdev, 0); | ||
2595 | |||
2759 | /* If this is an inactive or suspended hub, do nothing */ | 2596 | /* If this is an inactive or suspended hub, do nothing */ |
2760 | if (hub->quiescing) | 2597 | if (hub->quiescing) |
2761 | goto loop; | 2598 | goto loop; |
@@ -2893,7 +2730,7 @@ static void hub_events(void) | |||
2893 | 2730 | ||
2894 | /* If this is a root hub, tell the HCD it's okay to | 2731 | /* If this is a root hub, tell the HCD it's okay to |
2895 | * re-enable port-change interrupts now. */ | 2732 | * re-enable port-change interrupts now. */ |
2896 | if (!hdev->parent) | 2733 | if (!hdev->parent && !hub->busy_bits[0]) |
2897 | usb_enable_root_hub_irq(hdev->bus); | 2734 | usb_enable_root_hub_irq(hdev->bus); |
2898 | 2735 | ||
2899 | loop: | 2736 | loop: |
@@ -3068,6 +2905,9 @@ int usb_reset_device(struct usb_device *udev) | |||
3068 | break; | 2905 | break; |
3069 | } | 2906 | } |
3070 | clear_bit(port1, parent_hub->busy_bits); | 2907 | clear_bit(port1, parent_hub->busy_bits); |
2908 | if (!parent_hdev->parent && !parent_hub->busy_bits[0]) | ||
2909 | usb_enable_root_hub_irq(parent_hdev->bus); | ||
2910 | |||
3071 | if (ret < 0) | 2911 | if (ret < 0) |
3072 | goto re_enumerate; | 2912 | goto re_enumerate; |
3073 | 2913 | ||
@@ -3121,6 +2961,7 @@ re_enumerate: | |||
3121 | hub_port_logical_disconnect(parent_hub, port1); | 2961 | hub_port_logical_disconnect(parent_hub, port1); |
3122 | return -ENODEV; | 2962 | return -ENODEV; |
3123 | } | 2963 | } |
2964 | EXPORT_SYMBOL(usb_reset_device); | ||
3124 | 2965 | ||
3125 | /** | 2966 | /** |
3126 | * usb_reset_composite_device - warn interface drivers and perform a USB port reset | 2967 | * usb_reset_composite_device - warn interface drivers and perform a USB port reset |
@@ -3156,6 +2997,9 @@ int usb_reset_composite_device(struct usb_device *udev, | |||
3156 | return -EINVAL; | 2997 | return -EINVAL; |
3157 | } | 2998 | } |
3158 | 2999 | ||
3000 | /* Prevent autosuspend during the reset */ | ||
3001 | usb_autoresume_device(udev, 1); | ||
3002 | |||
3159 | if (iface && iface->condition != USB_INTERFACE_BINDING) | 3003 | if (iface && iface->condition != USB_INTERFACE_BINDING) |
3160 | iface = NULL; | 3004 | iface = NULL; |
3161 | 3005 | ||
@@ -3197,5 +3041,7 @@ int usb_reset_composite_device(struct usb_device *udev, | |||
3197 | } | 3041 | } |
3198 | } | 3042 | } |
3199 | 3043 | ||
3044 | usb_autosuspend_device(udev, 1); | ||
3200 | return ret; | 3045 | return ret; |
3201 | } | 3046 | } |
3047 | EXPORT_SYMBOL(usb_reset_composite_device); | ||
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 29d5f45a8456..0f8e82a4d480 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -212,7 +212,8 @@ struct usb_hub { | |||
212 | unsigned long event_bits[1]; /* status change bitmask */ | 212 | unsigned long event_bits[1]; /* status change bitmask */ |
213 | unsigned long change_bits[1]; /* ports with logical connect | 213 | unsigned long change_bits[1]; /* ports with logical connect |
214 | status change */ | 214 | status change */ |
215 | unsigned long busy_bits[1]; /* ports being reset */ | 215 | unsigned long busy_bits[1]; /* ports being reset or |
216 | resumed */ | ||
216 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | 217 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ |
217 | #error event_bits[] is too short! | 218 | #error event_bits[] is too short! |
218 | #endif | 219 | #endif |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 95f5ad923b0f..df3d152f0493 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | /*****************************************************************************/ | 28 | /*****************************************************************************/ |
29 | 29 | ||
30 | #include <linux/config.h> | ||
31 | #include <linux/module.h> | 30 | #include <linux/module.h> |
32 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
33 | #include <linux/mount.h> | 32 | #include <linux/mount.h> |
@@ -45,7 +44,7 @@ | |||
45 | #include "hcd.h" | 44 | #include "hcd.h" |
46 | 45 | ||
47 | static struct super_operations usbfs_ops; | 46 | static struct super_operations usbfs_ops; |
48 | static struct file_operations default_file_operations; | 47 | static const struct file_operations default_file_operations; |
49 | static struct vfsmount *usbfs_mount; | 48 | static struct vfsmount *usbfs_mount; |
50 | static int usbfs_mount_count; /* = 0 */ | 49 | static int usbfs_mount_count; /* = 0 */ |
51 | static int ignore_mount = 0; | 50 | static int ignore_mount = 0; |
@@ -201,7 +200,7 @@ static void update_sb(struct super_block *sb) | |||
201 | if (!root) | 200 | if (!root) |
202 | return; | 201 | return; |
203 | 202 | ||
204 | mutex_lock(&root->d_inode->i_mutex); | 203 | mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT); |
205 | 204 | ||
206 | list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) { | 205 | list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) { |
207 | if (bus->d_inode) { | 206 | if (bus->d_inode) { |
@@ -250,7 +249,6 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t de | |||
250 | inode->i_mode = mode; | 249 | inode->i_mode = mode; |
251 | inode->i_uid = current->fsuid; | 250 | inode->i_uid = current->fsuid; |
252 | inode->i_gid = current->fsgid; | 251 | inode->i_gid = current->fsgid; |
253 | inode->i_blksize = PAGE_CACHE_SIZE; | ||
254 | inode->i_blocks = 0; | 252 | inode->i_blocks = 0; |
255 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 253 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
256 | switch (mode & S_IFMT) { | 254 | switch (mode & S_IFMT) { |
@@ -403,13 +401,13 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig) | |||
403 | 401 | ||
404 | static int default_open (struct inode *inode, struct file *file) | 402 | static int default_open (struct inode *inode, struct file *file) |
405 | { | 403 | { |
406 | if (inode->u.generic_ip) | 404 | if (inode->i_private) |
407 | file->private_data = inode->u.generic_ip; | 405 | file->private_data = inode->i_private; |
408 | 406 | ||
409 | return 0; | 407 | return 0; |
410 | } | 408 | } |
411 | 409 | ||
412 | static struct file_operations default_file_operations = { | 410 | static const struct file_operations default_file_operations = { |
413 | .read = default_read_file, | 411 | .read = default_read_file, |
414 | .write = default_write_file, | 412 | .write = default_write_file, |
415 | .open = default_open, | 413 | .open = default_open, |
@@ -496,7 +494,7 @@ static int fs_create_by_name (const char *name, mode_t mode, | |||
496 | 494 | ||
497 | static struct dentry *fs_create_file (const char *name, mode_t mode, | 495 | static struct dentry *fs_create_file (const char *name, mode_t mode, |
498 | struct dentry *parent, void *data, | 496 | struct dentry *parent, void *data, |
499 | struct file_operations *fops, | 497 | const struct file_operations *fops, |
500 | uid_t uid, gid_t gid) | 498 | uid_t uid, gid_t gid) |
501 | { | 499 | { |
502 | struct dentry *dentry; | 500 | struct dentry *dentry; |
@@ -510,7 +508,7 @@ static struct dentry *fs_create_file (const char *name, mode_t mode, | |||
510 | } else { | 508 | } else { |
511 | if (dentry->d_inode) { | 509 | if (dentry->d_inode) { |
512 | if (data) | 510 | if (data) |
513 | dentry->d_inode->u.generic_ip = data; | 511 | dentry->d_inode->i_private = data; |
514 | if (fops) | 512 | if (fops) |
515 | dentry->d_inode->i_fop = fops; | 513 | dentry->d_inode->i_fop = fops; |
516 | dentry->d_inode->i_uid = uid; | 514 | dentry->d_inode->i_uid = uid; |
@@ -528,7 +526,7 @@ static void fs_remove_file (struct dentry *dentry) | |||
528 | if (!parent || !parent->d_inode) | 526 | if (!parent || !parent->d_inode) |
529 | return; | 527 | return; |
530 | 528 | ||
531 | mutex_lock(&parent->d_inode->i_mutex); | 529 | mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_PARENT); |
532 | if (usbfs_positive(dentry)) { | 530 | if (usbfs_positive(dentry)) { |
533 | if (dentry->d_inode) { | 531 | if (dentry->d_inode) { |
534 | if (S_ISDIR(dentry->d_inode->i_mode)) | 532 | if (S_ISDIR(dentry->d_inode->i_mode)) |
@@ -569,7 +567,7 @@ static int create_special_files (void) | |||
569 | ignore_mount = 1; | 567 | ignore_mount = 1; |
570 | 568 | ||
571 | /* create the devices special file */ | 569 | /* create the devices special file */ |
572 | retval = simple_pin_fs("usbfs", &usbfs_mount, &usbfs_mount_count); | 570 | retval = simple_pin_fs(&usb_fs_type, &usbfs_mount, &usbfs_mount_count); |
573 | if (retval) { | 571 | if (retval) { |
574 | err ("Unable to get usbfs mount"); | 572 | err ("Unable to get usbfs mount"); |
575 | goto exit; | 573 | goto exit; |
@@ -696,11 +694,11 @@ static void usbfs_remove_device(struct usb_device *dev) | |||
696 | wake_up_all(&ds->wait); | 694 | wake_up_all(&ds->wait); |
697 | list_del_init(&ds->list); | 695 | list_del_init(&ds->list); |
698 | if (ds->discsignr) { | 696 | if (ds->discsignr) { |
699 | sinfo.si_signo = SIGPIPE; | 697 | sinfo.si_signo = ds->discsignr; |
700 | sinfo.si_errno = EPIPE; | 698 | sinfo.si_errno = EPIPE; |
701 | sinfo.si_code = SI_ASYNCIO; | 699 | sinfo.si_code = SI_ASYNCIO; |
702 | sinfo.si_addr = ds->disccontext; | 700 | sinfo.si_addr = ds->disccontext; |
703 | kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid); | 701 | kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid, ds->secid); |
704 | } | 702 | } |
705 | } | 703 | } |
706 | } | 704 | } |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 8569600f3130..85b1cd18336f 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -2,7 +2,6 @@ | |||
2 | * message.c - synchronous message handling | 2 | * message.c - synchronous message handling |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <linux/config.h> | ||
6 | #include <linux/pci.h> /* for scatterlist macros */ | 5 | #include <linux/pci.h> /* for scatterlist macros */ |
7 | #include <linux/usb.h> | 6 | #include <linux/usb.h> |
8 | #include <linux/module.h> | 7 | #include <linux/module.h> |
@@ -24,59 +23,44 @@ static void usb_api_blocking_completion(struct urb *urb, struct pt_regs *regs) | |||
24 | } | 23 | } |
25 | 24 | ||
26 | 25 | ||
27 | static void timeout_kill(unsigned long data) | 26 | /* |
28 | { | 27 | * Starts urb and waits for completion or timeout. Note that this call |
29 | struct urb *urb = (struct urb *) data; | 28 | * is NOT interruptible. Many device driver i/o requests should be |
30 | 29 | * interruptible and therefore these drivers should implement their | |
31 | usb_unlink_urb(urb); | 30 | * own interruptible routines. |
32 | } | 31 | */ |
33 | 32 | static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) | |
34 | // Starts urb and waits for completion or timeout | ||
35 | // note that this call is NOT interruptible, while | ||
36 | // many device driver i/o requests should be interruptible | ||
37 | static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length) | ||
38 | { | 33 | { |
39 | struct completion done; | 34 | struct completion done; |
40 | struct timer_list timer; | 35 | unsigned long expire; |
41 | int status; | 36 | int status; |
42 | 37 | ||
43 | init_completion(&done); | 38 | init_completion(&done); |
44 | urb->context = &done; | 39 | urb->context = &done; |
45 | urb->actual_length = 0; | 40 | urb->actual_length = 0; |
46 | status = usb_submit_urb(urb, GFP_NOIO); | 41 | status = usb_submit_urb(urb, GFP_NOIO); |
47 | 42 | if (unlikely(status)) | |
48 | if (status == 0) { | 43 | goto out; |
49 | if (timeout > 0) { | 44 | |
50 | init_timer(&timer); | 45 | expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; |
51 | timer.expires = jiffies + msecs_to_jiffies(timeout); | 46 | if (!wait_for_completion_timeout(&done, expire)) { |
52 | timer.data = (unsigned long)urb; | 47 | |
53 | timer.function = timeout_kill; | 48 | dev_dbg(&urb->dev->dev, |
54 | /* grr. timeout _should_ include submit delays. */ | 49 | "%s timed out on ep%d%s len=%d/%d\n", |
55 | add_timer(&timer); | 50 | current->comm, |
56 | } | 51 | usb_pipeendpoint(urb->pipe), |
57 | wait_for_completion(&done); | 52 | usb_pipein(urb->pipe) ? "in" : "out", |
53 | urb->actual_length, | ||
54 | urb->transfer_buffer_length); | ||
55 | |||
56 | usb_kill_urb(urb); | ||
57 | status = urb->status == -ENOENT ? -ETIMEDOUT : urb->status; | ||
58 | } else | ||
58 | status = urb->status; | 59 | status = urb->status; |
59 | /* note: HCDs return ETIMEDOUT for other reasons too */ | 60 | out: |
60 | if (status == -ECONNRESET) { | ||
61 | dev_dbg(&urb->dev->dev, | ||
62 | "%s timed out on ep%d%s len=%d/%d\n", | ||
63 | current->comm, | ||
64 | usb_pipeendpoint(urb->pipe), | ||
65 | usb_pipein(urb->pipe) ? "in" : "out", | ||
66 | urb->actual_length, | ||
67 | urb->transfer_buffer_length | ||
68 | ); | ||
69 | if (urb->actual_length > 0) | ||
70 | status = 0; | ||
71 | else | ||
72 | status = -ETIMEDOUT; | ||
73 | } | ||
74 | if (timeout > 0) | ||
75 | del_timer_sync(&timer); | ||
76 | } | ||
77 | |||
78 | if (actual_length) | 61 | if (actual_length) |
79 | *actual_length = urb->actual_length; | 62 | *actual_length = urb->actual_length; |
63 | |||
80 | usb_free_urb(urb); | 64 | usb_free_urb(urb); |
81 | return status; | 65 | return status; |
82 | } | 66 | } |
@@ -264,7 +248,7 @@ static void sg_clean (struct usb_sg_request *io) | |||
264 | 248 | ||
265 | static void sg_complete (struct urb *urb, struct pt_regs *regs) | 249 | static void sg_complete (struct urb *urb, struct pt_regs *regs) |
266 | { | 250 | { |
267 | struct usb_sg_request *io = (struct usb_sg_request *) urb->context; | 251 | struct usb_sg_request *io = urb->context; |
268 | 252 | ||
269 | spin_lock (&io->lock); | 253 | spin_lock (&io->lock); |
270 | 254 | ||
@@ -1000,8 +984,8 @@ void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr) | |||
1000 | ep = dev->ep_in[epnum]; | 984 | ep = dev->ep_in[epnum]; |
1001 | dev->ep_in[epnum] = NULL; | 985 | dev->ep_in[epnum] = NULL; |
1002 | } | 986 | } |
1003 | if (ep && dev->bus && dev->bus->op && dev->bus->op->disable) | 987 | if (ep && dev->bus) |
1004 | dev->bus->op->disable(dev, ep); | 988 | usb_hcd_endpoint_disable(dev, ep); |
1005 | } | 989 | } |
1006 | 990 | ||
1007 | /** | 991 | /** |
@@ -1382,9 +1366,6 @@ int usb_set_configuration(struct usb_device *dev, int configuration) | |||
1382 | if (cp && configuration == 0) | 1366 | if (cp && configuration == 0) |
1383 | dev_warn(&dev->dev, "config 0 descriptor??\n"); | 1367 | dev_warn(&dev->dev, "config 0 descriptor??\n"); |
1384 | 1368 | ||
1385 | if (dev->state == USB_STATE_SUSPENDED) | ||
1386 | return -EHOSTUNREACH; | ||
1387 | |||
1388 | /* Allocate memory for new interfaces before doing anything else, | 1369 | /* Allocate memory for new interfaces before doing anything else, |
1389 | * so that if we run out then nothing will have changed. */ | 1370 | * so that if we run out then nothing will have changed. */ |
1390 | n = nintf = 0; | 1371 | n = nintf = 0; |
@@ -1419,6 +1400,11 @@ free_interfaces: | |||
1419 | configuration, -i); | 1400 | configuration, -i); |
1420 | } | 1401 | } |
1421 | 1402 | ||
1403 | /* Wake up the device so we can send it the Set-Config request */ | ||
1404 | ret = usb_autoresume_device(dev, 1); | ||
1405 | if (ret) | ||
1406 | goto free_interfaces; | ||
1407 | |||
1422 | /* if it's already configured, clear out old state first. | 1408 | /* if it's already configured, clear out old state first. |
1423 | * getting rid of old interfaces means unbinding their drivers. | 1409 | * getting rid of old interfaces means unbinding their drivers. |
1424 | */ | 1410 | */ |
@@ -1438,6 +1424,7 @@ free_interfaces: | |||
1438 | dev->actconfig = cp; | 1424 | dev->actconfig = cp; |
1439 | if (!cp) { | 1425 | if (!cp) { |
1440 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1426 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1427 | usb_autosuspend_device(dev, 1); | ||
1441 | goto free_interfaces; | 1428 | goto free_interfaces; |
1442 | } | 1429 | } |
1443 | usb_set_device_state(dev, USB_STATE_CONFIGURED); | 1430 | usb_set_device_state(dev, USB_STATE_CONFIGURED); |
@@ -1506,8 +1493,68 @@ free_interfaces: | |||
1506 | usb_create_sysfs_intf_files (intf); | 1493 | usb_create_sysfs_intf_files (intf); |
1507 | } | 1494 | } |
1508 | 1495 | ||
1496 | usb_autosuspend_device(dev, 1); | ||
1497 | return 0; | ||
1498 | } | ||
1499 | |||
1500 | struct set_config_request { | ||
1501 | struct usb_device *udev; | ||
1502 | int config; | ||
1503 | struct work_struct work; | ||
1504 | }; | ||
1505 | |||
1506 | /* Worker routine for usb_driver_set_configuration() */ | ||
1507 | static void driver_set_config_work(void *_req) | ||
1508 | { | ||
1509 | struct set_config_request *req = _req; | ||
1510 | |||
1511 | usb_lock_device(req->udev); | ||
1512 | usb_set_configuration(req->udev, req->config); | ||
1513 | usb_unlock_device(req->udev); | ||
1514 | usb_put_dev(req->udev); | ||
1515 | kfree(req); | ||
1516 | } | ||
1517 | |||
1518 | /** | ||
1519 | * usb_driver_set_configuration - Provide a way for drivers to change device configurations | ||
1520 | * @udev: the device whose configuration is being updated | ||
1521 | * @config: the configuration being chosen. | ||
1522 | * Context: In process context, must be able to sleep | ||
1523 | * | ||
1524 | * Device interface drivers are not allowed to change device configurations. | ||
1525 | * This is because changing configurations will destroy the interface the | ||
1526 | * driver is bound to and create new ones; it would be like a floppy-disk | ||
1527 | * driver telling the computer to replace the floppy-disk drive with a | ||
1528 | * tape drive! | ||
1529 | * | ||
1530 | * Still, in certain specialized circumstances the need may arise. This | ||
1531 | * routine gets around the normal restrictions by using a work thread to | ||
1532 | * submit the change-config request. | ||
1533 | * | ||
1534 | * Returns 0 if the request was succesfully queued, error code otherwise. | ||
1535 | * The caller has no way to know whether the queued request will eventually | ||
1536 | * succeed. | ||
1537 | */ | ||
1538 | int usb_driver_set_configuration(struct usb_device *udev, int config) | ||
1539 | { | ||
1540 | struct set_config_request *req; | ||
1541 | |||
1542 | req = kmalloc(sizeof(*req), GFP_KERNEL); | ||
1543 | if (!req) | ||
1544 | return -ENOMEM; | ||
1545 | req->udev = udev; | ||
1546 | req->config = config; | ||
1547 | INIT_WORK(&req->work, driver_set_config_work, req); | ||
1548 | |||
1549 | usb_get_dev(udev); | ||
1550 | if (!schedule_work(&req->work)) { | ||
1551 | usb_put_dev(udev); | ||
1552 | kfree(req); | ||
1553 | return -EINVAL; | ||
1554 | } | ||
1509 | return 0; | 1555 | return 0; |
1510 | } | 1556 | } |
1557 | EXPORT_SYMBOL_GPL(usb_driver_set_configuration); | ||
1511 | 1558 | ||
1512 | // synchronous request completion model | 1559 | // synchronous request completion model |
1513 | EXPORT_SYMBOL(usb_control_msg); | 1560 | EXPORT_SYMBOL(usb_control_msg); |
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c index fe0ed54fa0ae..6b36897ca151 100644 --- a/drivers/usb/core/notify.c +++ b/drivers/usb/core/notify.c | |||
@@ -9,7 +9,6 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | 11 | ||
12 | #include <linux/config.h> | ||
13 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
14 | #include <linux/notifier.h> | 13 | #include <linux/notifier.h> |
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
@@ -51,8 +50,11 @@ void usb_notify_add_device(struct usb_device *udev) | |||
51 | 50 | ||
52 | void usb_notify_remove_device(struct usb_device *udev) | 51 | void usb_notify_remove_device(struct usb_device *udev) |
53 | { | 52 | { |
53 | /* Protect against simultaneous usbfs open */ | ||
54 | mutex_lock(&usbfs_mutex); | ||
54 | blocking_notifier_call_chain(&usb_notifier_list, | 55 | blocking_notifier_call_chain(&usb_notifier_list, |
55 | USB_DEVICE_REMOVE, udev); | 56 | USB_DEVICE_REMOVE, udev); |
57 | mutex_unlock(&usbfs_mutex); | ||
56 | } | 58 | } |
57 | 59 | ||
58 | void usb_notify_add_bus(struct usb_bus *ubus) | 60 | void usb_notify_add_bus(struct usb_bus *ubus) |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 3f49bf51cff7..55d8f575206d 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -10,7 +10,6 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | 12 | ||
13 | #include <linux/config.h> | ||
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
15 | #include <linux/usb.h> | 14 | #include <linux/usb.h> |
16 | #include "usb.h" | 15 | #include "usb.h" |
@@ -61,7 +60,7 @@ static ssize_t | |||
61 | set_bConfigurationValue (struct device *dev, struct device_attribute *attr, | 60 | set_bConfigurationValue (struct device *dev, struct device_attribute *attr, |
62 | const char *buf, size_t count) | 61 | const char *buf, size_t count) |
63 | { | 62 | { |
64 | struct usb_device *udev = udev = to_usb_device (dev); | 63 | struct usb_device *udev = to_usb_device (dev); |
65 | int config, value; | 64 | int config, value; |
66 | 65 | ||
67 | if (sscanf (buf, "%u", &config) != 1 || config > 255) | 66 | if (sscanf (buf, "%u", &config) != 1 || config > 255) |
@@ -187,6 +186,7 @@ usb_descriptor_attr (bMaxPacketSize0, "%d\n") | |||
187 | 186 | ||
188 | static struct attribute *dev_attrs[] = { | 187 | static struct attribute *dev_attrs[] = { |
189 | /* current configuration's attributes */ | 188 | /* current configuration's attributes */ |
189 | &dev_attr_configuration.attr, | ||
190 | &dev_attr_bNumInterfaces.attr, | 190 | &dev_attr_bNumInterfaces.attr, |
191 | &dev_attr_bConfigurationValue.attr, | 191 | &dev_attr_bConfigurationValue.attr, |
192 | &dev_attr_bmAttributes.attr, | 192 | &dev_attr_bmAttributes.attr, |
@@ -210,20 +210,40 @@ static struct attribute_group dev_attr_grp = { | |||
210 | .attrs = dev_attrs, | 210 | .attrs = dev_attrs, |
211 | }; | 211 | }; |
212 | 212 | ||
213 | void usb_create_sysfs_dev_files (struct usb_device *udev) | 213 | int usb_create_sysfs_dev_files(struct usb_device *udev) |
214 | { | 214 | { |
215 | struct device *dev = &udev->dev; | 215 | struct device *dev = &udev->dev; |
216 | int retval; | ||
216 | 217 | ||
217 | sysfs_create_group(&dev->kobj, &dev_attr_grp); | 218 | retval = sysfs_create_group(&dev->kobj, &dev_attr_grp); |
219 | if (retval) | ||
220 | return retval; | ||
218 | 221 | ||
219 | if (udev->manufacturer) | 222 | if (udev->manufacturer) { |
220 | device_create_file (dev, &dev_attr_manufacturer); | 223 | retval = device_create_file (dev, &dev_attr_manufacturer); |
221 | if (udev->product) | 224 | if (retval) |
222 | device_create_file (dev, &dev_attr_product); | 225 | goto error; |
223 | if (udev->serial) | 226 | } |
224 | device_create_file (dev, &dev_attr_serial); | 227 | if (udev->product) { |
225 | device_create_file (dev, &dev_attr_configuration); | 228 | retval = device_create_file (dev, &dev_attr_product); |
226 | usb_create_ep_files(dev, &udev->ep0, udev); | 229 | if (retval) |
230 | goto error; | ||
231 | } | ||
232 | if (udev->serial) { | ||
233 | retval = device_create_file (dev, &dev_attr_serial); | ||
234 | if (retval) | ||
235 | goto error; | ||
236 | } | ||
237 | retval = usb_create_ep_files(dev, &udev->ep0, udev); | ||
238 | if (retval) | ||
239 | goto error; | ||
240 | return 0; | ||
241 | error: | ||
242 | usb_remove_ep_files(&udev->ep0); | ||
243 | device_remove_file(dev, &dev_attr_manufacturer); | ||
244 | device_remove_file(dev, &dev_attr_product); | ||
245 | device_remove_file(dev, &dev_attr_serial); | ||
246 | return retval; | ||
227 | } | 247 | } |
228 | 248 | ||
229 | void usb_remove_sysfs_dev_files (struct usb_device *udev) | 249 | void usb_remove_sysfs_dev_files (struct usb_device *udev) |
@@ -239,7 +259,6 @@ void usb_remove_sysfs_dev_files (struct usb_device *udev) | |||
239 | device_remove_file(dev, &dev_attr_product); | 259 | device_remove_file(dev, &dev_attr_product); |
240 | if (udev->serial) | 260 | if (udev->serial) |
241 | device_remove_file(dev, &dev_attr_serial); | 261 | device_remove_file(dev, &dev_attr_serial); |
242 | device_remove_file (dev, &dev_attr_configuration); | ||
243 | } | 262 | } |
244 | 263 | ||
245 | /* Interface fields */ | 264 | /* Interface fields */ |
@@ -341,18 +360,28 @@ static inline void usb_remove_intf_ep_files(struct usb_interface *intf) | |||
341 | usb_remove_ep_files(&iface_desc->endpoint[i]); | 360 | usb_remove_ep_files(&iface_desc->endpoint[i]); |
342 | } | 361 | } |
343 | 362 | ||
344 | void usb_create_sysfs_intf_files (struct usb_interface *intf) | 363 | int usb_create_sysfs_intf_files(struct usb_interface *intf) |
345 | { | 364 | { |
346 | struct usb_device *udev = interface_to_usbdev(intf); | 365 | struct usb_device *udev = interface_to_usbdev(intf); |
347 | struct usb_host_interface *alt = intf->cur_altsetting; | 366 | struct usb_host_interface *alt = intf->cur_altsetting; |
367 | int retval; | ||
348 | 368 | ||
349 | sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); | 369 | retval = sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); |
370 | if (retval) | ||
371 | goto error; | ||
350 | 372 | ||
351 | if (alt->string == NULL) | 373 | if (alt->string == NULL) |
352 | alt->string = usb_cache_string(udev, alt->desc.iInterface); | 374 | alt->string = usb_cache_string(udev, alt->desc.iInterface); |
353 | if (alt->string) | 375 | if (alt->string) |
354 | device_create_file(&intf->dev, &dev_attr_interface); | 376 | retval = device_create_file(&intf->dev, &dev_attr_interface); |
355 | usb_create_intf_ep_files(intf, udev); | 377 | usb_create_intf_ep_files(intf, udev); |
378 | return 0; | ||
379 | error: | ||
380 | if (alt->string) | ||
381 | device_remove_file(&intf->dev, &dev_attr_interface); | ||
382 | sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp); | ||
383 | usb_remove_intf_ep_files(intf); | ||
384 | return retval; | ||
356 | } | 385 | } |
357 | 386 | ||
358 | void usb_remove_sysfs_intf_files (struct usb_interface *intf) | 387 | void usb_remove_sysfs_intf_files (struct usb_interface *intf) |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index dad4d8fd8180..9801d08edacf 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #include <linux/config.h> | ||
2 | #include <linux/module.h> | 1 | #include <linux/module.h> |
3 | #include <linux/string.h> | 2 | #include <linux/string.h> |
4 | #include <linux/bitops.h> | 3 | #include <linux/bitops.h> |
@@ -58,7 +57,7 @@ struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags) | |||
58 | { | 57 | { |
59 | struct urb *urb; | 58 | struct urb *urb; |
60 | 59 | ||
61 | urb = (struct urb *)kmalloc(sizeof(struct urb) + | 60 | urb = kmalloc(sizeof(struct urb) + |
62 | iso_packets * sizeof(struct usb_iso_packet_descriptor), | 61 | iso_packets * sizeof(struct usb_iso_packet_descriptor), |
63 | mem_flags); | 62 | mem_flags); |
64 | if (!urb) { | 63 | if (!urb) { |
@@ -222,7 +221,6 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
222 | { | 221 | { |
223 | int pipe, temp, max; | 222 | int pipe, temp, max; |
224 | struct usb_device *dev; | 223 | struct usb_device *dev; |
225 | struct usb_operations *op; | ||
226 | int is_out; | 224 | int is_out; |
227 | 225 | ||
228 | if (!urb || urb->hcpriv || !urb->complete) | 226 | if (!urb || urb->hcpriv || !urb->complete) |
@@ -234,8 +232,6 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
234 | if (dev->bus->controller->power.power_state.event != PM_EVENT_ON | 232 | if (dev->bus->controller->power.power_state.event != PM_EVENT_ON |
235 | || dev->state == USB_STATE_SUSPENDED) | 233 | || dev->state == USB_STATE_SUSPENDED) |
236 | return -EHOSTUNREACH; | 234 | return -EHOSTUNREACH; |
237 | if (!(op = dev->bus->op) || !op->submit_urb) | ||
238 | return -ENODEV; | ||
239 | 235 | ||
240 | urb->status = -EINPROGRESS; | 236 | urb->status = -EINPROGRESS; |
241 | urb->actual_length = 0; | 237 | urb->actual_length = 0; |
@@ -377,7 +373,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
377 | urb->interval = temp; | 373 | urb->interval = temp; |
378 | } | 374 | } |
379 | 375 | ||
380 | return op->submit_urb (urb, mem_flags); | 376 | return usb_hcd_submit_urb (urb, mem_flags); |
381 | } | 377 | } |
382 | 378 | ||
383 | /*-------------------------------------------------------------------*/ | 379 | /*-------------------------------------------------------------------*/ |
@@ -441,9 +437,9 @@ int usb_unlink_urb(struct urb *urb) | |||
441 | { | 437 | { |
442 | if (!urb) | 438 | if (!urb) |
443 | return -EINVAL; | 439 | return -EINVAL; |
444 | if (!(urb->dev && urb->dev->bus && urb->dev->bus->op)) | 440 | if (!(urb->dev && urb->dev->bus)) |
445 | return -ENODEV; | 441 | return -ENODEV; |
446 | return urb->dev->bus->op->unlink_urb(urb, -ECONNRESET); | 442 | return usb_hcd_unlink_urb(urb, -ECONNRESET); |
447 | } | 443 | } |
448 | 444 | ||
449 | /** | 445 | /** |
@@ -469,13 +465,13 @@ int usb_unlink_urb(struct urb *urb) | |||
469 | void usb_kill_urb(struct urb *urb) | 465 | void usb_kill_urb(struct urb *urb) |
470 | { | 466 | { |
471 | might_sleep(); | 467 | might_sleep(); |
472 | if (!(urb && urb->dev && urb->dev->bus && urb->dev->bus->op)) | 468 | if (!(urb && urb->dev && urb->dev->bus)) |
473 | return; | 469 | return; |
474 | spin_lock_irq(&urb->lock); | 470 | spin_lock_irq(&urb->lock); |
475 | ++urb->reject; | 471 | ++urb->reject; |
476 | spin_unlock_irq(&urb->lock); | 472 | spin_unlock_irq(&urb->lock); |
477 | 473 | ||
478 | urb->dev->bus->op->unlink_urb(urb, -ENOENT); | 474 | usb_hcd_unlink_urb(urb, -ENOENT); |
479 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); | 475 | wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); |
480 | 476 | ||
481 | spin_lock_irq(&urb->lock); | 477 | spin_lock_irq(&urb->lock); |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index fb488c8a860c..e4df9edf1bc0 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -21,7 +21,6 @@ | |||
21 | * are evil. | 21 | * are evil. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/config.h> | ||
25 | #include <linux/module.h> | 24 | #include <linux/module.h> |
26 | #include <linux/string.h> | 25 | #include <linux/string.h> |
27 | #include <linux/bitops.h> | 26 | #include <linux/bitops.h> |
@@ -34,6 +33,7 @@ | |||
34 | #include <linux/smp_lock.h> | 33 | #include <linux/smp_lock.h> |
35 | #include <linux/usb.h> | 34 | #include <linux/usb.h> |
36 | #include <linux/mutex.h> | 35 | #include <linux/mutex.h> |
36 | #include <linux/workqueue.h> | ||
37 | 37 | ||
38 | #include <asm/io.h> | 38 | #include <asm/io.h> |
39 | #include <asm/scatterlist.h> | 39 | #include <asm/scatterlist.h> |
@@ -48,6 +48,8 @@ const char *usbcore_name = "usbcore"; | |||
48 | 48 | ||
49 | static int nousb; /* Disable USB when built into kernel image */ | 49 | static int nousb; /* Disable USB when built into kernel image */ |
50 | 50 | ||
51 | struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */ | ||
52 | |||
51 | 53 | ||
52 | /** | 54 | /** |
53 | * usb_ifnum_to_if - get the interface object with a given interface number | 55 | * usb_ifnum_to_if - get the interface object with a given interface number |
@@ -68,7 +70,8 @@ static int nousb; /* Disable USB when built into kernel image */ | |||
68 | * Don't call this function unless you are bound to one of the interfaces | 70 | * Don't call this function unless you are bound to one of the interfaces |
69 | * on this device or you have locked the device! | 71 | * on this device or you have locked the device! |
70 | */ | 72 | */ |
71 | struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) | 73 | struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev, |
74 | unsigned ifnum) | ||
72 | { | 75 | { |
73 | struct usb_host_config *config = dev->actconfig; | 76 | struct usb_host_config *config = dev->actconfig; |
74 | int i; | 77 | int i; |
@@ -101,8 +104,8 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) | |||
101 | * Don't call this function unless you are bound to the intf interface | 104 | * Don't call this function unless you are bound to the intf interface |
102 | * or you have locked the device! | 105 | * or you have locked the device! |
103 | */ | 106 | */ |
104 | struct usb_host_interface *usb_altnum_to_altsetting(struct usb_interface *intf, | 107 | struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf, |
105 | unsigned int altnum) | 108 | unsigned int altnum) |
106 | { | 109 | { |
107 | int i; | 110 | int i; |
108 | 111 | ||
@@ -113,87 +116,6 @@ struct usb_host_interface *usb_altnum_to_altsetting(struct usb_interface *intf, | |||
113 | return NULL; | 116 | return NULL; |
114 | } | 117 | } |
115 | 118 | ||
116 | /** | ||
117 | * usb_driver_claim_interface - bind a driver to an interface | ||
118 | * @driver: the driver to be bound | ||
119 | * @iface: the interface to which it will be bound; must be in the | ||
120 | * usb device's active configuration | ||
121 | * @priv: driver data associated with that interface | ||
122 | * | ||
123 | * This is used by usb device drivers that need to claim more than one | ||
124 | * interface on a device when probing (audio and acm are current examples). | ||
125 | * No device driver should directly modify internal usb_interface or | ||
126 | * usb_device structure members. | ||
127 | * | ||
128 | * Few drivers should need to use this routine, since the most natural | ||
129 | * way to bind to an interface is to return the private data from | ||
130 | * the driver's probe() method. | ||
131 | * | ||
132 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | ||
133 | * writelock. So driver probe() entries don't need extra locking, | ||
134 | * but other call contexts may need to explicitly claim those locks. | ||
135 | */ | ||
136 | int usb_driver_claim_interface(struct usb_driver *driver, | ||
137 | struct usb_interface *iface, void* priv) | ||
138 | { | ||
139 | struct device *dev = &iface->dev; | ||
140 | |||
141 | if (dev->driver) | ||
142 | return -EBUSY; | ||
143 | |||
144 | dev->driver = &driver->driver; | ||
145 | usb_set_intfdata(iface, priv); | ||
146 | iface->condition = USB_INTERFACE_BOUND; | ||
147 | mark_active(iface); | ||
148 | |||
149 | /* if interface was already added, bind now; else let | ||
150 | * the future device_add() bind it, bypassing probe() | ||
151 | */ | ||
152 | if (device_is_registered(dev)) | ||
153 | device_bind_driver(dev); | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * usb_driver_release_interface - unbind a driver from an interface | ||
160 | * @driver: the driver to be unbound | ||
161 | * @iface: the interface from which it will be unbound | ||
162 | * | ||
163 | * This can be used by drivers to release an interface without waiting | ||
164 | * for their disconnect() methods to be called. In typical cases this | ||
165 | * also causes the driver disconnect() method to be called. | ||
166 | * | ||
167 | * This call is synchronous, and may not be used in an interrupt context. | ||
168 | * Callers must own the device lock and the driver model's usb_bus_type.subsys | ||
169 | * writelock. So driver disconnect() entries don't need extra locking, | ||
170 | * but other call contexts may need to explicitly claim those locks. | ||
171 | */ | ||
172 | void usb_driver_release_interface(struct usb_driver *driver, | ||
173 | struct usb_interface *iface) | ||
174 | { | ||
175 | struct device *dev = &iface->dev; | ||
176 | |||
177 | /* this should never happen, don't release something that's not ours */ | ||
178 | if (!dev->driver || dev->driver != &driver->driver) | ||
179 | return; | ||
180 | |||
181 | /* don't release from within disconnect() */ | ||
182 | if (iface->condition != USB_INTERFACE_BOUND) | ||
183 | return; | ||
184 | |||
185 | /* don't release if the interface hasn't been added yet */ | ||
186 | if (device_is_registered(dev)) { | ||
187 | iface->condition = USB_INTERFACE_UNBINDING; | ||
188 | device_release_driver(dev); | ||
189 | } | ||
190 | |||
191 | dev->driver = NULL; | ||
192 | usb_set_intfdata(iface, NULL); | ||
193 | iface->condition = USB_INTERFACE_UNBOUND; | ||
194 | mark_quiesced(iface); | ||
195 | } | ||
196 | |||
197 | struct find_interface_arg { | 119 | struct find_interface_arg { |
198 | int minor; | 120 | int minor; |
199 | struct usb_interface *interface; | 121 | struct usb_interface *interface; |
@@ -205,7 +127,7 @@ static int __find_interface(struct device * dev, void * data) | |||
205 | struct usb_interface *intf; | 127 | struct usb_interface *intf; |
206 | 128 | ||
207 | /* can't look at usb devices, only interfaces */ | 129 | /* can't look at usb devices, only interfaces */ |
208 | if (dev->driver == &usb_generic_driver) | 130 | if (is_usb_device(dev)) |
209 | return 0; | 131 | return 0; |
210 | 132 | ||
211 | intf = to_usb_interface(dev); | 133 | intf = to_usb_interface(dev); |
@@ -228,147 +150,82 @@ static int __find_interface(struct device * dev, void * data) | |||
228 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) | 150 | struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) |
229 | { | 151 | { |
230 | struct find_interface_arg argb; | 152 | struct find_interface_arg argb; |
153 | int retval; | ||
231 | 154 | ||
232 | argb.minor = minor; | 155 | argb.minor = minor; |
233 | argb.interface = NULL; | 156 | argb.interface = NULL; |
234 | driver_for_each_device(&drv->driver, NULL, &argb, __find_interface); | 157 | /* eat the error, it will be in argb.interface */ |
158 | retval = driver_for_each_device(&drv->drvwrap.driver, NULL, &argb, | ||
159 | __find_interface); | ||
235 | return argb.interface; | 160 | return argb.interface; |
236 | } | 161 | } |
237 | 162 | ||
238 | #ifdef CONFIG_HOTPLUG | 163 | /** |
239 | 164 | * usb_release_dev - free a usb device structure when all users of it are finished. | |
240 | /* | 165 | * @dev: device that's been disconnected |
241 | * This sends an uevent to userspace, typically helping to load driver | ||
242 | * or other modules, configure the device, and more. Drivers can provide | ||
243 | * a MODULE_DEVICE_TABLE to help with module loading subtasks. | ||
244 | * | 166 | * |
245 | * We're called either from khubd (the typical case) or from root hub | 167 | * Will be called only by the device core when all users of this usb device are |
246 | * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle | 168 | * done. |
247 | * delays in event delivery. Use sysfs (and DEVPATH) to make sure the | ||
248 | * device (and this configuration!) are still present. | ||
249 | */ | 169 | */ |
250 | static int usb_uevent(struct device *dev, char **envp, int num_envp, | 170 | static void usb_release_dev(struct device *dev) |
251 | char *buffer, int buffer_size) | ||
252 | { | 171 | { |
253 | struct usb_interface *intf; | 172 | struct usb_device *udev; |
254 | struct usb_device *usb_dev; | ||
255 | struct usb_host_interface *alt; | ||
256 | int i = 0; | ||
257 | int length = 0; | ||
258 | |||
259 | if (!dev) | ||
260 | return -ENODEV; | ||
261 | |||
262 | /* driver is often null here; dev_dbg() would oops */ | ||
263 | pr_debug ("usb %s: uevent\n", dev->bus_id); | ||
264 | |||
265 | /* Must check driver_data here, as on remove driver is always NULL */ | ||
266 | if ((dev->driver == &usb_generic_driver) || | ||
267 | (dev->driver_data == &usb_generic_driver_data)) | ||
268 | return 0; | ||
269 | |||
270 | intf = to_usb_interface(dev); | ||
271 | usb_dev = interface_to_usbdev (intf); | ||
272 | alt = intf->cur_altsetting; | ||
273 | 173 | ||
274 | if (usb_dev->devnum < 0) { | 174 | udev = to_usb_device(dev); |
275 | pr_debug ("usb %s: already deleted?\n", dev->bus_id); | ||
276 | return -ENODEV; | ||
277 | } | ||
278 | if (!usb_dev->bus) { | ||
279 | pr_debug ("usb %s: bus removed?\n", dev->bus_id); | ||
280 | return -ENODEV; | ||
281 | } | ||
282 | 175 | ||
283 | #ifdef CONFIG_USB_DEVICEFS | 176 | #ifdef CONFIG_USB_SUSPEND |
284 | /* If this is available, userspace programs can directly read | 177 | cancel_delayed_work(&udev->autosuspend); |
285 | * all the device descriptors we don't tell them about. Or | 178 | flush_workqueue(ksuspend_usb_wq); |
286 | * even act as usermode drivers. | ||
287 | * | ||
288 | * FIXME reduce hardwired intelligence here | ||
289 | */ | ||
290 | if (add_uevent_var(envp, num_envp, &i, | ||
291 | buffer, buffer_size, &length, | ||
292 | "DEVICE=/proc/bus/usb/%03d/%03d", | ||
293 | usb_dev->bus->busnum, usb_dev->devnum)) | ||
294 | return -ENOMEM; | ||
295 | #endif | 179 | #endif |
180 | usb_destroy_configuration(udev); | ||
181 | usb_put_hcd(bus_to_hcd(udev->bus)); | ||
182 | kfree(udev->product); | ||
183 | kfree(udev->manufacturer); | ||
184 | kfree(udev->serial); | ||
185 | kfree(udev); | ||
186 | } | ||
296 | 187 | ||
297 | /* per-device configurations are common */ | 188 | #ifdef CONFIG_PM |
298 | if (add_uevent_var(envp, num_envp, &i, | ||
299 | buffer, buffer_size, &length, | ||
300 | "PRODUCT=%x/%x/%x", | ||
301 | le16_to_cpu(usb_dev->descriptor.idVendor), | ||
302 | le16_to_cpu(usb_dev->descriptor.idProduct), | ||
303 | le16_to_cpu(usb_dev->descriptor.bcdDevice))) | ||
304 | return -ENOMEM; | ||
305 | 189 | ||
306 | /* class-based driver binding models */ | 190 | static int ksuspend_usb_init(void) |
307 | if (add_uevent_var(envp, num_envp, &i, | 191 | { |
308 | buffer, buffer_size, &length, | 192 | ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd"); |
309 | "TYPE=%d/%d/%d", | 193 | if (!ksuspend_usb_wq) |
310 | usb_dev->descriptor.bDeviceClass, | ||
311 | usb_dev->descriptor.bDeviceSubClass, | ||
312 | usb_dev->descriptor.bDeviceProtocol)) | ||
313 | return -ENOMEM; | 194 | return -ENOMEM; |
195 | return 0; | ||
196 | } | ||
314 | 197 | ||
315 | if (add_uevent_var(envp, num_envp, &i, | 198 | static void ksuspend_usb_cleanup(void) |
316 | buffer, buffer_size, &length, | 199 | { |
317 | "INTERFACE=%d/%d/%d", | 200 | destroy_workqueue(ksuspend_usb_wq); |
318 | alt->desc.bInterfaceClass, | 201 | } |
319 | alt->desc.bInterfaceSubClass, | ||
320 | alt->desc.bInterfaceProtocol)) | ||
321 | return -ENOMEM; | ||
322 | 202 | ||
323 | if (add_uevent_var(envp, num_envp, &i, | 203 | #else |
324 | buffer, buffer_size, &length, | ||
325 | "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", | ||
326 | le16_to_cpu(usb_dev->descriptor.idVendor), | ||
327 | le16_to_cpu(usb_dev->descriptor.idProduct), | ||
328 | le16_to_cpu(usb_dev->descriptor.bcdDevice), | ||
329 | usb_dev->descriptor.bDeviceClass, | ||
330 | usb_dev->descriptor.bDeviceSubClass, | ||
331 | usb_dev->descriptor.bDeviceProtocol, | ||
332 | alt->desc.bInterfaceClass, | ||
333 | alt->desc.bInterfaceSubClass, | ||
334 | alt->desc.bInterfaceProtocol)) | ||
335 | return -ENOMEM; | ||
336 | 204 | ||
337 | envp[i] = NULL; | 205 | #define ksuspend_usb_init() 0 |
206 | #define ksuspend_usb_cleanup() do {} while (0) | ||
338 | 207 | ||
339 | return 0; | 208 | #endif |
340 | } | ||
341 | 209 | ||
342 | #else | 210 | #ifdef CONFIG_USB_SUSPEND |
343 | 211 | ||
344 | static int usb_uevent(struct device *dev, char **envp, | 212 | /* usb_autosuspend_work - callback routine to autosuspend a USB device */ |
345 | int num_envp, char *buffer, int buffer_size) | 213 | static void usb_autosuspend_work(void *_udev) |
346 | { | 214 | { |
347 | return -ENODEV; | 215 | struct usb_device *udev = _udev; |
348 | } | ||
349 | 216 | ||
350 | #endif /* CONFIG_HOTPLUG */ | 217 | usb_pm_lock(udev); |
218 | udev->auto_pm = 1; | ||
219 | usb_suspend_both(udev, PMSG_SUSPEND); | ||
220 | usb_pm_unlock(udev); | ||
221 | } | ||
351 | 222 | ||
352 | /** | 223 | #else |
353 | * usb_release_dev - free a usb device structure when all users of it are finished. | ||
354 | * @dev: device that's been disconnected | ||
355 | * | ||
356 | * Will be called only by the device core when all users of this usb device are | ||
357 | * done. | ||
358 | */ | ||
359 | static void usb_release_dev(struct device *dev) | ||
360 | { | ||
361 | struct usb_device *udev; | ||
362 | 224 | ||
363 | udev = to_usb_device(dev); | 225 | static void usb_autosuspend_work(void *_udev) |
226 | {} | ||
364 | 227 | ||
365 | usb_destroy_configuration(udev); | 228 | #endif |
366 | usb_bus_put(udev->bus); | ||
367 | kfree(udev->product); | ||
368 | kfree(udev->manufacturer); | ||
369 | kfree(udev->serial); | ||
370 | kfree(udev); | ||
371 | } | ||
372 | 229 | ||
373 | /** | 230 | /** |
374 | * usb_alloc_dev - usb device constructor (usbcore-internal) | 231 | * usb_alloc_dev - usb device constructor (usbcore-internal) |
@@ -391,8 +248,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
391 | if (!dev) | 248 | if (!dev) |
392 | return NULL; | 249 | return NULL; |
393 | 250 | ||
394 | bus = usb_bus_get(bus); | 251 | if (!usb_get_hcd(bus_to_hcd(bus))) { |
395 | if (!bus) { | ||
396 | kfree(dev); | 252 | kfree(dev); |
397 | return NULL; | 253 | return NULL; |
398 | } | 254 | } |
@@ -400,11 +256,12 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
400 | device_initialize(&dev->dev); | 256 | device_initialize(&dev->dev); |
401 | dev->dev.bus = &usb_bus_type; | 257 | dev->dev.bus = &usb_bus_type; |
402 | dev->dev.dma_mask = bus->controller->dma_mask; | 258 | dev->dev.dma_mask = bus->controller->dma_mask; |
403 | dev->dev.driver_data = &usb_generic_driver_data; | ||
404 | dev->dev.driver = &usb_generic_driver; | ||
405 | dev->dev.release = usb_release_dev; | 259 | dev->dev.release = usb_release_dev; |
406 | dev->state = USB_STATE_ATTACHED; | 260 | dev->state = USB_STATE_ATTACHED; |
407 | 261 | ||
262 | /* This magic assignment distinguishes devices from interfaces */ | ||
263 | dev->dev.platform_data = &usb_generic_driver; | ||
264 | |||
408 | INIT_LIST_HEAD(&dev->ep0.urb_list); | 265 | INIT_LIST_HEAD(&dev->ep0.urb_list); |
409 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; | 266 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; |
410 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; | 267 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; |
@@ -445,6 +302,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
445 | dev->parent = parent; | 302 | dev->parent = parent; |
446 | INIT_LIST_HEAD(&dev->filelist); | 303 | INIT_LIST_HEAD(&dev->filelist); |
447 | 304 | ||
305 | #ifdef CONFIG_PM | ||
306 | mutex_init(&dev->pm_mutex); | ||
307 | INIT_WORK(&dev->autosuspend, usb_autosuspend_work, dev); | ||
308 | #endif | ||
448 | return dev; | 309 | return dev; |
449 | } | 310 | } |
450 | 311 | ||
@@ -550,7 +411,7 @@ void usb_put_intf(struct usb_interface *intf) | |||
550 | * case the driver already owns the device lock.) | 411 | * case the driver already owns the device lock.) |
551 | */ | 412 | */ |
552 | int usb_lock_device_for_reset(struct usb_device *udev, | 413 | int usb_lock_device_for_reset(struct usb_device *udev, |
553 | struct usb_interface *iface) | 414 | const struct usb_interface *iface) |
554 | { | 415 | { |
555 | unsigned long jiffies_expire = jiffies + HZ; | 416 | unsigned long jiffies_expire = jiffies + HZ; |
556 | 417 | ||
@@ -673,7 +534,139 @@ exit: | |||
673 | */ | 534 | */ |
674 | int usb_get_current_frame_number(struct usb_device *dev) | 535 | int usb_get_current_frame_number(struct usb_device *dev) |
675 | { | 536 | { |
676 | return dev->bus->op->get_frame_number (dev); | 537 | return usb_hcd_get_frame_number (dev); |
538 | } | ||
539 | |||
540 | /** | ||
541 | * usb_endpoint_dir_in - check if the endpoint has IN direction | ||
542 | * @epd: endpoint to be checked | ||
543 | * | ||
544 | * Returns true if the endpoint is of type IN, otherwise it returns false. | ||
545 | */ | ||
546 | int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) | ||
547 | { | ||
548 | return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); | ||
549 | } | ||
550 | |||
551 | /** | ||
552 | * usb_endpoint_dir_out - check if the endpoint has OUT direction | ||
553 | * @epd: endpoint to be checked | ||
554 | * | ||
555 | * Returns true if the endpoint is of type OUT, otherwise it returns false. | ||
556 | */ | ||
557 | int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) | ||
558 | { | ||
559 | return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); | ||
560 | } | ||
561 | |||
562 | /** | ||
563 | * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type | ||
564 | * @epd: endpoint to be checked | ||
565 | * | ||
566 | * Returns true if the endpoint is of type bulk, otherwise it returns false. | ||
567 | */ | ||
568 | int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) | ||
569 | { | ||
570 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | ||
571 | USB_ENDPOINT_XFER_BULK); | ||
572 | } | ||
573 | |||
574 | /** | ||
575 | * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type | ||
576 | * @epd: endpoint to be checked | ||
577 | * | ||
578 | * Returns true if the endpoint is of type interrupt, otherwise it returns | ||
579 | * false. | ||
580 | */ | ||
581 | int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) | ||
582 | { | ||
583 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | ||
584 | USB_ENDPOINT_XFER_INT); | ||
585 | } | ||
586 | |||
587 | /** | ||
588 | * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type | ||
589 | * @epd: endpoint to be checked | ||
590 | * | ||
591 | * Returns true if the endpoint is of type isochronous, otherwise it returns | ||
592 | * false. | ||
593 | */ | ||
594 | int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) | ||
595 | { | ||
596 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == | ||
597 | USB_ENDPOINT_XFER_ISOC); | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN | ||
602 | * @epd: endpoint to be checked | ||
603 | * | ||
604 | * Returns true if the endpoint has bulk transfer type and IN direction, | ||
605 | * otherwise it returns false. | ||
606 | */ | ||
607 | int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) | ||
608 | { | ||
609 | return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd)); | ||
610 | } | ||
611 | |||
612 | /** | ||
613 | * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT | ||
614 | * @epd: endpoint to be checked | ||
615 | * | ||
616 | * Returns true if the endpoint has bulk transfer type and OUT direction, | ||
617 | * otherwise it returns false. | ||
618 | */ | ||
619 | int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) | ||
620 | { | ||
621 | return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd)); | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * usb_endpoint_is_int_in - check if the endpoint is interrupt IN | ||
626 | * @epd: endpoint to be checked | ||
627 | * | ||
628 | * Returns true if the endpoint has interrupt transfer type and IN direction, | ||
629 | * otherwise it returns false. | ||
630 | */ | ||
631 | int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) | ||
632 | { | ||
633 | return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd)); | ||
634 | } | ||
635 | |||
636 | /** | ||
637 | * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT | ||
638 | * @epd: endpoint to be checked | ||
639 | * | ||
640 | * Returns true if the endpoint has interrupt transfer type and OUT direction, | ||
641 | * otherwise it returns false. | ||
642 | */ | ||
643 | int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) | ||
644 | { | ||
645 | return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd)); | ||
646 | } | ||
647 | |||
648 | /** | ||
649 | * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN | ||
650 | * @epd: endpoint to be checked | ||
651 | * | ||
652 | * Returns true if the endpoint has isochronous transfer type and IN direction, | ||
653 | * otherwise it returns false. | ||
654 | */ | ||
655 | int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) | ||
656 | { | ||
657 | return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd)); | ||
658 | } | ||
659 | |||
660 | /** | ||
661 | * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT | ||
662 | * @epd: endpoint to be checked | ||
663 | * | ||
664 | * Returns true if the endpoint has isochronous transfer type and OUT direction, | ||
665 | * otherwise it returns false. | ||
666 | */ | ||
667 | int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) | ||
668 | { | ||
669 | return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd)); | ||
677 | } | 670 | } |
678 | 671 | ||
679 | /*-------------------------------------------------------------------*/ | 672 | /*-------------------------------------------------------------------*/ |
@@ -738,9 +731,9 @@ void *usb_buffer_alloc ( | |||
738 | dma_addr_t *dma | 731 | dma_addr_t *dma |
739 | ) | 732 | ) |
740 | { | 733 | { |
741 | if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_alloc) | 734 | if (!dev || !dev->bus) |
742 | return NULL; | 735 | return NULL; |
743 | return dev->bus->op->buffer_alloc (dev->bus, size, mem_flags, dma); | 736 | return hcd_buffer_alloc (dev->bus, size, mem_flags, dma); |
744 | } | 737 | } |
745 | 738 | ||
746 | /** | 739 | /** |
@@ -761,9 +754,11 @@ void usb_buffer_free ( | |||
761 | dma_addr_t dma | 754 | dma_addr_t dma |
762 | ) | 755 | ) |
763 | { | 756 | { |
764 | if (!dev || !dev->bus || !dev->bus->op || !dev->bus->op->buffer_free) | 757 | if (!dev || !dev->bus) |
765 | return; | 758 | return; |
766 | dev->bus->op->buffer_free (dev->bus, size, addr, dma); | 759 | if (!addr) |
760 | return; | ||
761 | hcd_buffer_free (dev->bus, size, addr, dma); | ||
767 | } | 762 | } |
768 | 763 | ||
769 | /** | 764 | /** |
@@ -912,8 +907,8 @@ void usb_buffer_unmap (struct urb *urb) | |||
912 | * | 907 | * |
913 | * Reverse the effect of this call with usb_buffer_unmap_sg(). | 908 | * Reverse the effect of this call with usb_buffer_unmap_sg(). |
914 | */ | 909 | */ |
915 | int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe, | 910 | int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe, |
916 | struct scatterlist *sg, int nents) | 911 | struct scatterlist *sg, int nents) |
917 | { | 912 | { |
918 | struct usb_bus *bus; | 913 | struct usb_bus *bus; |
919 | struct device *controller; | 914 | struct device *controller; |
@@ -947,8 +942,8 @@ int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe, | |||
947 | * Use this when you are re-using a scatterlist's data buffers for | 942 | * Use this when you are re-using a scatterlist's data buffers for |
948 | * another USB request. | 943 | * another USB request. |
949 | */ | 944 | */ |
950 | void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe, | 945 | void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe, |
951 | struct scatterlist *sg, int n_hw_ents) | 946 | struct scatterlist *sg, int n_hw_ents) |
952 | { | 947 | { |
953 | struct usb_bus *bus; | 948 | struct usb_bus *bus; |
954 | struct device *controller; | 949 | struct device *controller; |
@@ -973,8 +968,8 @@ void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe, | |||
973 | * | 968 | * |
974 | * Reverses the effect of usb_buffer_map_sg(). | 969 | * Reverses the effect of usb_buffer_map_sg(). |
975 | */ | 970 | */ |
976 | void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe, | 971 | void usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe, |
977 | struct scatterlist *sg, int n_hw_ents) | 972 | struct scatterlist *sg, int n_hw_ents) |
978 | { | 973 | { |
979 | struct usb_bus *bus; | 974 | struct usb_bus *bus; |
980 | struct device *controller; | 975 | struct device *controller; |
@@ -989,116 +984,6 @@ void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe, | |||
989 | usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | 984 | usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE); |
990 | } | 985 | } |
991 | 986 | ||
992 | static int verify_suspended(struct device *dev, void *unused) | ||
993 | { | ||
994 | if (dev->driver == NULL) | ||
995 | return 0; | ||
996 | return (dev->power.power_state.event == PM_EVENT_ON) ? -EBUSY : 0; | ||
997 | } | ||
998 | |||
999 | static int usb_generic_suspend(struct device *dev, pm_message_t message) | ||
1000 | { | ||
1001 | struct usb_interface *intf; | ||
1002 | struct usb_driver *driver; | ||
1003 | int status; | ||
1004 | |||
1005 | /* USB devices enter SUSPEND state through their hubs, but can be | ||
1006 | * marked for FREEZE as soon as their children are already idled. | ||
1007 | * But those semantics are useless, so we equate the two (sigh). | ||
1008 | */ | ||
1009 | if (dev->driver == &usb_generic_driver) { | ||
1010 | if (dev->power.power_state.event == message.event) | ||
1011 | return 0; | ||
1012 | /* we need to rule out bogus requests through sysfs */ | ||
1013 | status = device_for_each_child(dev, NULL, verify_suspended); | ||
1014 | if (status) | ||
1015 | return status; | ||
1016 | return usb_suspend_device (to_usb_device(dev)); | ||
1017 | } | ||
1018 | |||
1019 | if ((dev->driver == NULL) || | ||
1020 | (dev->driver_data == &usb_generic_driver_data)) | ||
1021 | return 0; | ||
1022 | |||
1023 | intf = to_usb_interface(dev); | ||
1024 | driver = to_usb_driver(dev->driver); | ||
1025 | |||
1026 | /* with no hardware, USB interfaces only use FREEZE and ON states */ | ||
1027 | if (!is_active(intf)) | ||
1028 | return 0; | ||
1029 | |||
1030 | if (driver->suspend && driver->resume) { | ||
1031 | status = driver->suspend(intf, message); | ||
1032 | if (status) | ||
1033 | dev_err(dev, "%s error %d\n", "suspend", status); | ||
1034 | else | ||
1035 | mark_quiesced(intf); | ||
1036 | } else { | ||
1037 | // FIXME else if there's no suspend method, disconnect... | ||
1038 | dev_warn(dev, "no suspend for driver %s?\n", driver->name); | ||
1039 | mark_quiesced(intf); | ||
1040 | status = 0; | ||
1041 | } | ||
1042 | return status; | ||
1043 | } | ||
1044 | |||
1045 | static int usb_generic_resume(struct device *dev) | ||
1046 | { | ||
1047 | struct usb_interface *intf; | ||
1048 | struct usb_driver *driver; | ||
1049 | struct usb_device *udev; | ||
1050 | int status; | ||
1051 | |||
1052 | if (dev->power.power_state.event == PM_EVENT_ON) | ||
1053 | return 0; | ||
1054 | |||
1055 | /* mark things as "on" immediately, no matter what errors crop up */ | ||
1056 | dev->power.power_state.event = PM_EVENT_ON; | ||
1057 | |||
1058 | /* devices resume through their hubs */ | ||
1059 | if (dev->driver == &usb_generic_driver) { | ||
1060 | udev = to_usb_device(dev); | ||
1061 | if (udev->state == USB_STATE_NOTATTACHED) | ||
1062 | return 0; | ||
1063 | return usb_resume_device (to_usb_device(dev)); | ||
1064 | } | ||
1065 | |||
1066 | if ((dev->driver == NULL) || | ||
1067 | (dev->driver_data == &usb_generic_driver_data)) { | ||
1068 | dev->power.power_state.event = PM_EVENT_FREEZE; | ||
1069 | return 0; | ||
1070 | } | ||
1071 | |||
1072 | intf = to_usb_interface(dev); | ||
1073 | driver = to_usb_driver(dev->driver); | ||
1074 | |||
1075 | udev = interface_to_usbdev(intf); | ||
1076 | if (udev->state == USB_STATE_NOTATTACHED) | ||
1077 | return 0; | ||
1078 | |||
1079 | /* if driver was suspended, it has a resume method; | ||
1080 | * however, sysfs can wrongly mark things as suspended | ||
1081 | * (on the "no suspend method" FIXME path above) | ||
1082 | */ | ||
1083 | if (driver->resume) { | ||
1084 | status = driver->resume(intf); | ||
1085 | if (status) { | ||
1086 | dev_err(dev, "%s error %d\n", "resume", status); | ||
1087 | mark_quiesced(intf); | ||
1088 | } | ||
1089 | } else | ||
1090 | dev_warn(dev, "no resume for driver %s?\n", driver->name); | ||
1091 | return 0; | ||
1092 | } | ||
1093 | |||
1094 | struct bus_type usb_bus_type = { | ||
1095 | .name = "usb", | ||
1096 | .match = usb_device_match, | ||
1097 | .uevent = usb_uevent, | ||
1098 | .suspend = usb_generic_suspend, | ||
1099 | .resume = usb_generic_resume, | ||
1100 | }; | ||
1101 | |||
1102 | /* format to disable USB on kernel command line is: nousb */ | 987 | /* format to disable USB on kernel command line is: nousb */ |
1103 | __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); | 988 | __module_param_call("", nousb, param_set_bool, param_get_bool, &nousb, 0444); |
1104 | 989 | ||
@@ -1121,9 +1006,12 @@ static int __init usb_init(void) | |||
1121 | return 0; | 1006 | return 0; |
1122 | } | 1007 | } |
1123 | 1008 | ||
1009 | retval = ksuspend_usb_init(); | ||
1010 | if (retval) | ||
1011 | goto out; | ||
1124 | retval = bus_register(&usb_bus_type); | 1012 | retval = bus_register(&usb_bus_type); |
1125 | if (retval) | 1013 | if (retval) |
1126 | goto out; | 1014 | goto bus_register_failed; |
1127 | retval = usb_host_init(); | 1015 | retval = usb_host_init(); |
1128 | if (retval) | 1016 | if (retval) |
1129 | goto host_init_failed; | 1017 | goto host_init_failed; |
@@ -1142,7 +1030,7 @@ static int __init usb_init(void) | |||
1142 | retval = usb_hub_init(); | 1030 | retval = usb_hub_init(); |
1143 | if (retval) | 1031 | if (retval) |
1144 | goto hub_init_failed; | 1032 | goto hub_init_failed; |
1145 | retval = driver_register(&usb_generic_driver); | 1033 | retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE); |
1146 | if (!retval) | 1034 | if (!retval) |
1147 | goto out; | 1035 | goto out; |
1148 | 1036 | ||
@@ -1159,6 +1047,8 @@ major_init_failed: | |||
1159 | usb_host_cleanup(); | 1047 | usb_host_cleanup(); |
1160 | host_init_failed: | 1048 | host_init_failed: |
1161 | bus_unregister(&usb_bus_type); | 1049 | bus_unregister(&usb_bus_type); |
1050 | bus_register_failed: | ||
1051 | ksuspend_usb_cleanup(); | ||
1162 | out: | 1052 | out: |
1163 | return retval; | 1053 | return retval; |
1164 | } | 1054 | } |
@@ -1172,7 +1062,7 @@ static void __exit usb_exit(void) | |||
1172 | if (nousb) | 1062 | if (nousb) |
1173 | return; | 1063 | return; |
1174 | 1064 | ||
1175 | driver_unregister(&usb_generic_driver); | 1065 | usb_deregister_device_driver(&usb_generic_driver); |
1176 | usb_major_cleanup(); | 1066 | usb_major_cleanup(); |
1177 | usbfs_cleanup(); | 1067 | usbfs_cleanup(); |
1178 | usb_deregister(&usbfs_driver); | 1068 | usb_deregister(&usbfs_driver); |
@@ -1180,6 +1070,7 @@ static void __exit usb_exit(void) | |||
1180 | usb_hub_cleanup(); | 1070 | usb_hub_cleanup(); |
1181 | usb_host_cleanup(); | 1071 | usb_host_cleanup(); |
1182 | bus_unregister(&usb_bus_type); | 1072 | bus_unregister(&usb_bus_type); |
1073 | ksuspend_usb_cleanup(); | ||
1183 | } | 1074 | } |
1184 | 1075 | ||
1185 | subsys_initcall(usb_init); | 1076 | subsys_initcall(usb_init); |
@@ -1202,20 +1093,27 @@ EXPORT_SYMBOL(usb_hub_tt_clear_buffer); | |||
1202 | 1093 | ||
1203 | EXPORT_SYMBOL(usb_lock_device_for_reset); | 1094 | EXPORT_SYMBOL(usb_lock_device_for_reset); |
1204 | 1095 | ||
1205 | EXPORT_SYMBOL(usb_driver_claim_interface); | ||
1206 | EXPORT_SYMBOL(usb_driver_release_interface); | ||
1207 | EXPORT_SYMBOL(usb_find_interface); | 1096 | EXPORT_SYMBOL(usb_find_interface); |
1208 | EXPORT_SYMBOL(usb_ifnum_to_if); | 1097 | EXPORT_SYMBOL(usb_ifnum_to_if); |
1209 | EXPORT_SYMBOL(usb_altnum_to_altsetting); | 1098 | EXPORT_SYMBOL(usb_altnum_to_altsetting); |
1210 | 1099 | ||
1211 | EXPORT_SYMBOL(usb_reset_device); | ||
1212 | EXPORT_SYMBOL(usb_reset_composite_device); | ||
1213 | |||
1214 | EXPORT_SYMBOL(__usb_get_extra_descriptor); | 1100 | EXPORT_SYMBOL(__usb_get_extra_descriptor); |
1215 | 1101 | ||
1216 | EXPORT_SYMBOL(usb_find_device); | 1102 | EXPORT_SYMBOL(usb_find_device); |
1217 | EXPORT_SYMBOL(usb_get_current_frame_number); | 1103 | EXPORT_SYMBOL(usb_get_current_frame_number); |
1218 | 1104 | ||
1105 | EXPORT_SYMBOL_GPL(usb_endpoint_dir_in); | ||
1106 | EXPORT_SYMBOL_GPL(usb_endpoint_dir_out); | ||
1107 | EXPORT_SYMBOL_GPL(usb_endpoint_xfer_bulk); | ||
1108 | EXPORT_SYMBOL_GPL(usb_endpoint_xfer_int); | ||
1109 | EXPORT_SYMBOL_GPL(usb_endpoint_xfer_isoc); | ||
1110 | EXPORT_SYMBOL_GPL(usb_endpoint_is_bulk_in); | ||
1111 | EXPORT_SYMBOL_GPL(usb_endpoint_is_bulk_out); | ||
1112 | EXPORT_SYMBOL_GPL(usb_endpoint_is_int_in); | ||
1113 | EXPORT_SYMBOL_GPL(usb_endpoint_is_int_out); | ||
1114 | EXPORT_SYMBOL_GPL(usb_endpoint_is_isoc_in); | ||
1115 | EXPORT_SYMBOL_GPL(usb_endpoint_is_isoc_out); | ||
1116 | |||
1219 | EXPORT_SYMBOL (usb_buffer_alloc); | 1117 | EXPORT_SYMBOL (usb_buffer_alloc); |
1220 | EXPORT_SYMBOL (usb_buffer_free); | 1118 | EXPORT_SYMBOL (usb_buffer_free); |
1221 | 1119 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 7a650c763a62..f69df137ec0e 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -1,10 +1,10 @@ | |||
1 | /* Functions local to drivers/usb/core/ */ | 1 | /* Functions local to drivers/usb/core/ */ |
2 | 2 | ||
3 | extern void usb_create_sysfs_dev_files (struct usb_device *dev); | 3 | extern int usb_create_sysfs_dev_files (struct usb_device *dev); |
4 | extern void usb_remove_sysfs_dev_files (struct usb_device *dev); | 4 | extern void usb_remove_sysfs_dev_files (struct usb_device *dev); |
5 | extern void usb_create_sysfs_intf_files (struct usb_interface *intf); | 5 | extern int usb_create_sysfs_intf_files (struct usb_interface *intf); |
6 | extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); | 6 | extern void usb_remove_sysfs_intf_files (struct usb_interface *intf); |
7 | extern void usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint, | 7 | extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint, |
8 | struct usb_device *udev); | 8 | struct usb_device *udev); |
9 | extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); | 9 | extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint); |
10 | 10 | ||
@@ -20,7 +20,6 @@ extern char *usb_cache_string(struct usb_device *udev, int index); | |||
20 | extern int usb_set_configuration(struct usb_device *dev, int configuration); | 20 | extern int usb_set_configuration(struct usb_device *dev, int configuration); |
21 | 21 | ||
22 | extern void usb_kick_khubd(struct usb_device *dev); | 22 | extern void usb_kick_khubd(struct usb_device *dev); |
23 | extern void usb_suspend_root_hub(struct usb_device *hdev); | ||
24 | extern void usb_resume_root_hub(struct usb_device *dev); | 23 | extern void usb_resume_root_hub(struct usb_device *dev); |
25 | 24 | ||
26 | extern int usb_hub_init(void); | 25 | extern int usb_hub_init(void); |
@@ -30,28 +29,91 @@ extern void usb_major_cleanup(void); | |||
30 | extern int usb_host_init(void); | 29 | extern int usb_host_init(void); |
31 | extern void usb_host_cleanup(void); | 30 | extern void usb_host_cleanup(void); |
32 | 31 | ||
33 | extern int usb_suspend_device(struct usb_device *dev); | 32 | #ifdef CONFIG_PM |
34 | extern int usb_resume_device(struct usb_device *dev); | ||
35 | 33 | ||
36 | extern struct device_driver usb_generic_driver; | 34 | extern int usb_suspend_both(struct usb_device *udev, pm_message_t msg); |
37 | extern int usb_generic_driver_data; | 35 | extern int usb_resume_both(struct usb_device *udev); |
38 | extern int usb_device_match(struct device *dev, struct device_driver *drv); | 36 | extern int usb_port_suspend(struct usb_device *dev); |
37 | extern int usb_port_resume(struct usb_device *dev); | ||
38 | |||
39 | static inline void usb_pm_lock(struct usb_device *udev) | ||
40 | { | ||
41 | mutex_lock_nested(&udev->pm_mutex, udev->level); | ||
42 | } | ||
43 | |||
44 | static inline void usb_pm_unlock(struct usb_device *udev) | ||
45 | { | ||
46 | mutex_unlock(&udev->pm_mutex); | ||
47 | } | ||
48 | |||
49 | #else | ||
50 | |||
51 | #define usb_suspend_both(udev, msg) 0 | ||
52 | static inline int usb_resume_both(struct usb_device *udev) | ||
53 | { | ||
54 | return 0; | ||
55 | } | ||
56 | #define usb_port_suspend(dev) 0 | ||
57 | #define usb_port_resume(dev) 0 | ||
58 | static inline void usb_pm_lock(struct usb_device *udev) {} | ||
59 | static inline void usb_pm_unlock(struct usb_device *udev) {} | ||
60 | |||
61 | #endif | ||
62 | |||
63 | #ifdef CONFIG_USB_SUSPEND | ||
64 | |||
65 | #define USB_AUTOSUSPEND_DELAY (HZ*2) | ||
66 | |||
67 | extern void usb_autosuspend_device(struct usb_device *udev, int dec_busy_cnt); | ||
68 | extern int usb_autoresume_device(struct usb_device *udev, int inc_busy_cnt); | ||
69 | |||
70 | #else | ||
71 | |||
72 | #define usb_autosuspend_device(udev, dec_busy_cnt) do {} while (0) | ||
73 | static inline int usb_autoresume_device(struct usb_device *udev, | ||
74 | int inc_busy_cnt) | ||
75 | { | ||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | #endif | ||
80 | |||
81 | extern struct workqueue_struct *ksuspend_usb_wq; | ||
82 | extern struct bus_type usb_bus_type; | ||
83 | extern struct usb_device_driver usb_generic_driver; | ||
84 | |||
85 | /* Here's how we tell apart devices and interfaces. Luckily there's | ||
86 | * no such thing as a platform USB device, so we can steal the use | ||
87 | * of the platform_data field. */ | ||
88 | |||
89 | static inline int is_usb_device(const struct device *dev) | ||
90 | { | ||
91 | return dev->platform_data == &usb_generic_driver; | ||
92 | } | ||
93 | |||
94 | /* Do the same for device drivers and interface drivers. */ | ||
95 | |||
96 | static inline int is_usb_device_driver(struct device_driver *drv) | ||
97 | { | ||
98 | return container_of(drv, struct usbdrv_wrap, driver)-> | ||
99 | for_devices; | ||
100 | } | ||
39 | 101 | ||
40 | /* Interfaces and their "power state" are owned by usbcore */ | 102 | /* Interfaces and their "power state" are owned by usbcore */ |
41 | 103 | ||
42 | static inline void mark_active(struct usb_interface *f) | 104 | static inline void mark_active(struct usb_interface *f) |
43 | { | 105 | { |
44 | f->dev.power.power_state.event = PM_EVENT_ON; | 106 | f->is_active = 1; |
45 | } | 107 | } |
46 | 108 | ||
47 | static inline void mark_quiesced(struct usb_interface *f) | 109 | static inline void mark_quiesced(struct usb_interface *f) |
48 | { | 110 | { |
49 | f->dev.power.power_state.event = PM_EVENT_FREEZE; | 111 | f->is_active = 0; |
50 | } | 112 | } |
51 | 113 | ||
52 | static inline int is_active(struct usb_interface *f) | 114 | static inline int is_active(const struct usb_interface *f) |
53 | { | 115 | { |
54 | return f->dev.power.power_state.event == PM_EVENT_ON; | 116 | return f->is_active; |
55 | } | 117 | } |
56 | 118 | ||
57 | 119 | ||
@@ -59,9 +121,10 @@ static inline int is_active(struct usb_interface *f) | |||
59 | extern const char *usbcore_name; | 121 | extern const char *usbcore_name; |
60 | 122 | ||
61 | /* usbfs stuff */ | 123 | /* usbfs stuff */ |
124 | extern struct mutex usbfs_mutex; | ||
62 | extern struct usb_driver usbfs_driver; | 125 | extern struct usb_driver usbfs_driver; |
63 | extern struct file_operations usbfs_devices_fops; | 126 | extern const struct file_operations usbfs_devices_fops; |
64 | extern struct file_operations usbfs_device_file_operations; | 127 | extern const struct file_operations usbfs_device_file_operations; |
65 | extern void usbfs_conn_disc_event(void); | 128 | extern void usbfs_conn_disc_event(void); |
66 | 129 | ||
67 | extern int usbdev_init(void); | 130 | extern int usbdev_init(void); |
@@ -80,6 +143,7 @@ struct dev_state { | |||
80 | uid_t disc_uid, disc_euid; | 143 | uid_t disc_uid, disc_euid; |
81 | void __user *disccontext; | 144 | void __user *disccontext; |
82 | unsigned long ifclaimed; | 145 | unsigned long ifclaimed; |
146 | u32 secid; | ||
83 | }; | 147 | }; |
84 | 148 | ||
85 | /* internal notify stuff */ | 149 | /* internal notify stuff */ |