diff options
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/Kconfig | 16 | ||||
-rw-r--r-- | drivers/usb/core/Makefile | 21 | ||||
-rw-r--r-- | drivers/usb/core/buffer.c | 26 | ||||
-rw-r--r-- | drivers/usb/core/config.c | 2 | ||||
-rw-r--r-- | drivers/usb/core/devices.c | 44 | ||||
-rw-r--r-- | drivers/usb/core/devio.c | 10 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 190 | ||||
-rw-r--r-- | drivers/usb/core/endpoint.c | 4 | ||||
-rw-r--r-- | drivers/usb/core/file.c | 10 | ||||
-rw-r--r-- | drivers/usb/core/hcd-pci.c | 72 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 303 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 422 | ||||
-rw-r--r-- | drivers/usb/core/inode.c | 23 | ||||
-rw-r--r-- | drivers/usb/core/message.c | 61 | ||||
-rw-r--r-- | drivers/usb/core/quirks.c | 23 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 97 | ||||
-rw-r--r-- | drivers/usb/core/urb.c | 16 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 11 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 20 |
19 files changed, 825 insertions, 546 deletions
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index 9eed5b52d9de..18d02e32a3d5 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -107,17 +107,25 @@ config USB_SUSPEND | |||
107 | If you are unsure about this, say N here. | 107 | If you are unsure about this, say N here. |
108 | 108 | ||
109 | config USB_OTG | 109 | config USB_OTG |
110 | bool | 110 | bool "OTG support" |
111 | depends on USB && EXPERIMENTAL | 111 | depends on USB && EXPERIMENTAL |
112 | depends on USB_SUSPEND | 112 | depends on USB_SUSPEND |
113 | default n | 113 | default n |
114 | help | ||
115 | The most notable feature of USB OTG is support for a | ||
116 | "Dual-Role" device, which can act as either a device | ||
117 | or a host. The initial role is decided by the type of | ||
118 | plug inserted and can be changed later when two dual | ||
119 | role devices talk to each other. | ||
114 | 120 | ||
121 | Select this only if your board has Mini-AB/Micro-AB | ||
122 | connector. | ||
115 | 123 | ||
116 | config USB_OTG_WHITELIST | 124 | config USB_OTG_WHITELIST |
117 | bool "Rely on OTG Targeted Peripherals List" | 125 | bool "Rely on OTG Targeted Peripherals List" |
118 | depends on USB_OTG || EMBEDDED | 126 | depends on USB_OTG || EXPERT |
119 | default y if USB_OTG | 127 | default y if USB_OTG |
120 | default n if EMBEDDED | 128 | default n if EXPERT |
121 | help | 129 | help |
122 | If you say Y here, the "otg_whitelist.h" file will be used as a | 130 | If you say Y here, the "otg_whitelist.h" file will be used as a |
123 | product whitelist, so USB peripherals not listed there will be | 131 | product whitelist, so USB peripherals not listed there will be |
@@ -133,7 +141,7 @@ config USB_OTG_WHITELIST | |||
133 | 141 | ||
134 | config USB_OTG_BLACKLIST_HUB | 142 | config USB_OTG_BLACKLIST_HUB |
135 | bool "Disable external hubs" | 143 | bool "Disable external hubs" |
136 | depends on USB_OTG || EMBEDDED | 144 | depends on USB_OTG || EXPERT |
137 | help | 145 | help |
138 | If you say Y here, then Linux will refuse to enumerate | 146 | If you say Y here, then Linux will refuse to enumerate |
139 | external hubs. OTG hosts are allowed to reduce hardware | 147 | external hubs. OTG hosts are allowed to reduce hardware |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index ec16e6029905..507a4e1b6360 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -2,20 +2,13 @@ | |||
2 | # Makefile for USB Core files and filesystem | 2 | # Makefile for USB Core files and filesystem |
3 | # | 3 | # |
4 | 4 | ||
5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ | 5 | ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG |
6 | config.o file.o buffer.o sysfs.o endpoint.o \ | ||
7 | devio.o notify.o generic.o quirks.o devices.o | ||
8 | 6 | ||
9 | ifeq ($(CONFIG_PCI),y) | 7 | usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o |
10 | usbcore-objs += hcd-pci.o | 8 | usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o |
11 | endif | 9 | usbcore-y += devio.o notify.o generic.o quirks.o devices.o |
12 | 10 | ||
13 | ifeq ($(CONFIG_USB_DEVICEFS),y) | 11 | usbcore-$(CONFIG_PCI) += hcd-pci.o |
14 | usbcore-objs += inode.o | 12 | usbcore-$(CONFIG_USB_DEVICEFS) += inode.o |
15 | endif | ||
16 | 13 | ||
17 | obj-$(CONFIG_USB) += usbcore.o | 14 | obj-$(CONFIG_USB) += usbcore.o |
18 | |||
19 | ifeq ($(CONFIG_USB_DEBUG),y) | ||
20 | EXTRA_CFLAGS += -DDEBUG | ||
21 | endif | ||
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 2c6965484fe8..b0585e623ba9 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c | |||
@@ -10,7 +10,7 @@ | |||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/device.h> | 11 | #include <linux/device.h> |
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <asm/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
15 | #include <linux/dmapool.h> | 15 | #include <linux/dmapool.h> |
16 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
@@ -22,7 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* FIXME tune these based on pool statistics ... */ | 24 | /* FIXME tune these based on pool statistics ... */ |
25 | static const size_t pool_max [HCD_BUFFER_POOLS] = { | 25 | static const size_t pool_max[HCD_BUFFER_POOLS] = { |
26 | /* platforms without dma-friendly caches might need to | 26 | /* platforms without dma-friendly caches might need to |
27 | * prevent cacheline sharing... | 27 | * prevent cacheline sharing... |
28 | */ | 28 | */ |
@@ -51,7 +51,7 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = { | |||
51 | int hcd_buffer_create(struct usb_hcd *hcd) | 51 | int hcd_buffer_create(struct usb_hcd *hcd) |
52 | { | 52 | { |
53 | char name[16]; | 53 | char name[16]; |
54 | int i, size; | 54 | int i, size; |
55 | 55 | ||
56 | if (!hcd->self.controller->dma_mask && | 56 | if (!hcd->self.controller->dma_mask && |
57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) | 57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) |
@@ -64,7 +64,7 @@ int hcd_buffer_create(struct usb_hcd *hcd) | |||
64 | snprintf(name, sizeof name, "buffer-%d", size); | 64 | snprintf(name, sizeof name, "buffer-%d", size); |
65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, | 65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, |
66 | size, size, 0); | 66 | size, size, 0); |
67 | if (!hcd->pool [i]) { | 67 | if (!hcd->pool[i]) { |
68 | hcd_buffer_destroy(hcd); | 68 | hcd_buffer_destroy(hcd); |
69 | return -ENOMEM; | 69 | return -ENOMEM; |
70 | } | 70 | } |
@@ -99,14 +99,14 @@ void hcd_buffer_destroy(struct usb_hcd *hcd) | |||
99 | */ | 99 | */ |
100 | 100 | ||
101 | void *hcd_buffer_alloc( | 101 | void *hcd_buffer_alloc( |
102 | struct usb_bus *bus, | 102 | struct usb_bus *bus, |
103 | size_t size, | 103 | size_t size, |
104 | gfp_t mem_flags, | 104 | gfp_t mem_flags, |
105 | dma_addr_t *dma | 105 | dma_addr_t *dma |
106 | ) | 106 | ) |
107 | { | 107 | { |
108 | struct usb_hcd *hcd = bus_to_hcd(bus); | 108 | struct usb_hcd *hcd = bus_to_hcd(bus); |
109 | int i; | 109 | int i; |
110 | 110 | ||
111 | /* some USB hosts just use PIO */ | 111 | /* some USB hosts just use PIO */ |
112 | if (!bus->controller->dma_mask && | 112 | if (!bus->controller->dma_mask && |
@@ -116,21 +116,21 @@ void *hcd_buffer_alloc( | |||
116 | } | 116 | } |
117 | 117 | ||
118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
119 | if (size <= pool_max [i]) | 119 | if (size <= pool_max[i]) |
120 | return dma_pool_alloc(hcd->pool [i], mem_flags, dma); | 120 | return dma_pool_alloc(hcd->pool[i], mem_flags, dma); |
121 | } | 121 | } |
122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); | 122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | void hcd_buffer_free( | 125 | void hcd_buffer_free( |
126 | struct usb_bus *bus, | 126 | struct usb_bus *bus, |
127 | size_t size, | 127 | size_t size, |
128 | void *addr, | 128 | void *addr, |
129 | dma_addr_t dma | 129 | dma_addr_t dma |
130 | ) | 130 | ) |
131 | { | 131 | { |
132 | struct usb_hcd *hcd = bus_to_hcd(bus); | 132 | struct usb_hcd *hcd = bus_to_hcd(bus); |
133 | int i; | 133 | int i; |
134 | 134 | ||
135 | if (!addr) | 135 | if (!addr) |
136 | return; | 136 | return; |
@@ -142,8 +142,8 @@ void hcd_buffer_free( | |||
142 | } | 142 | } |
143 | 143 | ||
144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
145 | if (size <= pool_max [i]) { | 145 | if (size <= pool_max[i]) { |
146 | dma_pool_free(hcd->pool [i], addr, dma); | 146 | dma_pool_free(hcd->pool[i], addr, dma); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | } | 149 | } |
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index 83126b03e7cf..c962608b4b9a 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -129,7 +129,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, | |||
129 | max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1); | 129 | max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1); |
130 | else | 130 | else |
131 | max_tx = 999999; | 131 | max_tx = 999999; |
132 | if (desc->wBytesPerInterval > max_tx) { | 132 | if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) { |
133 | dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " | 133 | dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " |
134 | "config %d interface %d altsetting %d ep %d: " | 134 | "config %d interface %d altsetting %d ep %d: " |
135 | "setting to %d\n", | 135 | "setting to %d\n", |
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c index 3449742c00e1..0149c0976e9c 100644 --- a/drivers/usb/core/devices.c +++ b/drivers/usb/core/devices.c | |||
@@ -54,7 +54,6 @@ | |||
54 | #include <linux/gfp.h> | 54 | #include <linux/gfp.h> |
55 | #include <linux/poll.h> | 55 | #include <linux/poll.h> |
56 | #include <linux/usb.h> | 56 | #include <linux/usb.h> |
57 | #include <linux/smp_lock.h> | ||
58 | #include <linux/usbdevice_fs.h> | 57 | #include <linux/usbdevice_fs.h> |
59 | #include <linux/usb/hcd.h> | 58 | #include <linux/usb/hcd.h> |
60 | #include <linux/mutex.h> | 59 | #include <linux/mutex.h> |
@@ -65,49 +64,49 @@ | |||
65 | /* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ | 64 | /* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ |
66 | #define ALLOW_SERIAL_NUMBER | 65 | #define ALLOW_SERIAL_NUMBER |
67 | 66 | ||
68 | static const char *format_topo = | 67 | static const char format_topo[] = |
69 | /* T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=ddd MxCh=dd */ | 68 | /* T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd */ |
70 | "\nT: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%3s MxCh=%2d\n"; | 69 | "\nT: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%-4s MxCh=%2d\n"; |
71 | 70 | ||
72 | static const char *format_string_manufacturer = | 71 | static const char format_string_manufacturer[] = |
73 | /* S: Manufacturer=xxxx */ | 72 | /* S: Manufacturer=xxxx */ |
74 | "S: Manufacturer=%.100s\n"; | 73 | "S: Manufacturer=%.100s\n"; |
75 | 74 | ||
76 | static const char *format_string_product = | 75 | static const char format_string_product[] = |
77 | /* S: Product=xxxx */ | 76 | /* S: Product=xxxx */ |
78 | "S: Product=%.100s\n"; | 77 | "S: Product=%.100s\n"; |
79 | 78 | ||
80 | #ifdef ALLOW_SERIAL_NUMBER | 79 | #ifdef ALLOW_SERIAL_NUMBER |
81 | static const char *format_string_serialnumber = | 80 | static const char format_string_serialnumber[] = |
82 | /* S: SerialNumber=xxxx */ | 81 | /* S: SerialNumber=xxxx */ |
83 | "S: SerialNumber=%.100s\n"; | 82 | "S: SerialNumber=%.100s\n"; |
84 | #endif | 83 | #endif |
85 | 84 | ||
86 | static const char *format_bandwidth = | 85 | static const char format_bandwidth[] = |
87 | /* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */ | 86 | /* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */ |
88 | "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n"; | 87 | "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n"; |
89 | 88 | ||
90 | static const char *format_device1 = | 89 | static const char format_device1[] = |
91 | /* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */ | 90 | /* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */ |
92 | "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n"; | 91 | "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n"; |
93 | 92 | ||
94 | static const char *format_device2 = | 93 | static const char format_device2[] = |
95 | /* P: Vendor=xxxx ProdID=xxxx Rev=xx.xx */ | 94 | /* P: Vendor=xxxx ProdID=xxxx Rev=xx.xx */ |
96 | "P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n"; | 95 | "P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n"; |
97 | 96 | ||
98 | static const char *format_config = | 97 | static const char format_config[] = |
99 | /* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */ | 98 | /* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */ |
100 | "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n"; | 99 | "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n"; |
101 | 100 | ||
102 | static const char *format_iad = | 101 | static const char format_iad[] = |
103 | /* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */ | 102 | /* A: FirstIf#=dd IfCount=dd Cls=xx(sssss) Sub=xx Prot=xx */ |
104 | "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n"; | 103 | "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n"; |
105 | 104 | ||
106 | static const char *format_iface = | 105 | static const char format_iface[] = |
107 | /* I: If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=xxxx*/ | 106 | /* I: If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=xxxx*/ |
108 | "I:%c If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n"; | 107 | "I:%c If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n"; |
109 | 108 | ||
110 | static const char *format_endpt = | 109 | static const char format_endpt[] = |
111 | /* E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */ | 110 | /* E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */ |
112 | "E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n"; | 111 | "E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n"; |
113 | 112 | ||
@@ -222,7 +221,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end, | |||
222 | break; | 221 | break; |
223 | case USB_ENDPOINT_XFER_INT: | 222 | case USB_ENDPOINT_XFER_INT: |
224 | type = "Int."; | 223 | type = "Int."; |
225 | if (speed == USB_SPEED_HIGH) | 224 | if (speed == USB_SPEED_HIGH || speed == USB_SPEED_SUPER) |
226 | interval = 1 << (desc->bInterval - 1); | 225 | interval = 1 << (desc->bInterval - 1); |
227 | else | 226 | else |
228 | interval = desc->bInterval; | 227 | interval = desc->bInterval; |
@@ -230,7 +229,8 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end, | |||
230 | default: /* "can't happen" */ | 229 | default: /* "can't happen" */ |
231 | return start; | 230 | return start; |
232 | } | 231 | } |
233 | interval *= (speed == USB_SPEED_HIGH) ? 125 : 1000; | 232 | interval *= (speed == USB_SPEED_HIGH || |
233 | speed == USB_SPEED_SUPER) ? 125 : 1000; | ||
234 | if (interval % 1000) | 234 | if (interval % 1000) |
235 | unit = 'u'; | 235 | unit = 'u'; |
236 | else { | 236 | else { |
@@ -520,11 +520,14 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, | |||
520 | speed = "1.5"; break; | 520 | speed = "1.5"; break; |
521 | case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */ | 521 | case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */ |
522 | case USB_SPEED_FULL: | 522 | case USB_SPEED_FULL: |
523 | speed = "12 "; break; | 523 | speed = "12"; break; |
524 | case USB_SPEED_WIRELESS: /* Wireless has no real fixed speed */ | ||
524 | case USB_SPEED_HIGH: | 525 | case USB_SPEED_HIGH: |
525 | speed = "480"; break; | 526 | speed = "480"; break; |
527 | case USB_SPEED_SUPER: | ||
528 | speed = "5000"; break; | ||
526 | default: | 529 | default: |
527 | speed = "?? "; | 530 | speed = "??"; |
528 | } | 531 | } |
529 | data_end = pages_start + sprintf(pages_start, format_topo, | 532 | data_end = pages_start + sprintf(pages_start, format_topo, |
530 | bus->busnum, level, parent_devnum, | 533 | bus->busnum, level, parent_devnum, |
@@ -540,8 +543,9 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, | |||
540 | if (level == 0) { | 543 | if (level == 0) { |
541 | int max; | 544 | int max; |
542 | 545 | ||
543 | /* high speed reserves 80%, full/low reserves 90% */ | 546 | /* super/high speed reserves 80%, full/low reserves 90% */ |
544 | if (usbdev->speed == USB_SPEED_HIGH) | 547 | if (usbdev->speed == USB_SPEED_HIGH || |
548 | usbdev->speed == USB_SPEED_SUPER) | ||
545 | max = 800; | 549 | max = 800; |
546 | else | 550 | else |
547 | max = FRAME_TIME_MAX_USECS_ALLOC; | 551 | max = FRAME_TIME_MAX_USECS_ALLOC; |
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index f1aaff6202a5..37518dfdeb98 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <linux/fs.h> | 37 | #include <linux/fs.h> |
38 | #include <linux/mm.h> | 38 | #include <linux/mm.h> |
39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
40 | #include <linux/smp_lock.h> | ||
41 | #include <linux/signal.h> | 40 | #include <linux/signal.h> |
42 | #include <linux/poll.h> | 41 | #include <linux/poll.h> |
43 | #include <linux/module.h> | 42 | #include <linux/module.h> |
@@ -803,7 +802,7 @@ static int proc_control(struct dev_state *ps, void __user *arg) | |||
803 | tbuf, ctrl.wLength, tmo); | 802 | tbuf, ctrl.wLength, tmo); |
804 | usb_lock_device(dev); | 803 | usb_lock_device(dev); |
805 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, | 804 | snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, |
806 | tbuf, i); | 805 | tbuf, max(i, 0)); |
807 | if ((i > 0) && ctrl.wLength) { | 806 | if ((i > 0) && ctrl.wLength) { |
808 | if (copy_to_user(ctrl.data, tbuf, i)) { | 807 | if (copy_to_user(ctrl.data, tbuf, i)) { |
809 | free_page((unsigned long)tbuf); | 808 | free_page((unsigned long)tbuf); |
@@ -965,10 +964,11 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg) | |||
965 | 964 | ||
966 | static int proc_connectinfo(struct dev_state *ps, void __user *arg) | 965 | static int proc_connectinfo(struct dev_state *ps, void __user *arg) |
967 | { | 966 | { |
968 | struct usbdevfs_connectinfo ci; | 967 | struct usbdevfs_connectinfo ci = { |
968 | .devnum = ps->dev->devnum, | ||
969 | .slow = ps->dev->speed == USB_SPEED_LOW | ||
970 | }; | ||
969 | 971 | ||
970 | ci.devnum = ps->dev->devnum; | ||
971 | ci.slow = ps->dev->speed == USB_SPEED_LOW; | ||
972 | if (copy_to_user(arg, &ci, sizeof(ci))) | 972 | if (copy_to_user(arg, &ci, sizeof(ci))) |
973 | return -EFAULT; | 973 | return -EFAULT; |
974 | return 0; | 974 | return 0; |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index d7a4401ef019..34e3da5aa72a 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
28 | #include <linux/usb/quirks.h> | 28 | #include <linux/usb/quirks.h> |
29 | #include <linux/usb/hcd.h> | 29 | #include <linux/usb/hcd.h> |
30 | #include <linux/pm_runtime.h> | ||
31 | 30 | ||
32 | #include "usb.h" | 31 | #include "usb.h" |
33 | 32 | ||
@@ -376,7 +375,7 @@ static int usb_unbind_interface(struct device *dev) | |||
376 | * Just re-enable it without affecting the endpoint toggles. | 375 | * Just re-enable it without affecting the endpoint toggles. |
377 | */ | 376 | */ |
378 | usb_enable_interface(udev, intf, false); | 377 | usb_enable_interface(udev, intf, false); |
379 | } else if (!error && intf->dev.power.status == DPM_ON) { | 378 | } else if (!error && !intf->dev.power.is_prepared) { |
380 | r = usb_set_interface(udev, intf->altsetting[0]. | 379 | r = usb_set_interface(udev, intf->altsetting[0]. |
381 | desc.bInterfaceNumber, 0); | 380 | desc.bInterfaceNumber, 0); |
382 | if (r < 0) | 381 | if (r < 0) |
@@ -961,7 +960,7 @@ void usb_rebind_intf(struct usb_interface *intf) | |||
961 | } | 960 | } |
962 | 961 | ||
963 | /* Try to rebind the interface */ | 962 | /* Try to rebind the interface */ |
964 | if (intf->dev.power.status == DPM_ON) { | 963 | if (!intf->dev.power.is_prepared) { |
965 | intf->needs_binding = 0; | 964 | intf->needs_binding = 0; |
966 | rc = device_attach(&intf->dev); | 965 | rc = device_attach(&intf->dev); |
967 | if (rc < 0) | 966 | if (rc < 0) |
@@ -1108,8 +1107,7 @@ static int usb_resume_interface(struct usb_device *udev, | |||
1108 | if (intf->condition == USB_INTERFACE_UNBOUND) { | 1107 | if (intf->condition == USB_INTERFACE_UNBOUND) { |
1109 | 1108 | ||
1110 | /* Carry out a deferred switch to altsetting 0 */ | 1109 | /* Carry out a deferred switch to altsetting 0 */ |
1111 | if (intf->needs_altsetting0 && | 1110 | if (intf->needs_altsetting0 && !intf->dev.power.is_prepared) { |
1112 | intf->dev.power.status == DPM_ON) { | ||
1113 | usb_set_interface(udev, intf->altsetting[0]. | 1111 | usb_set_interface(udev, intf->altsetting[0]. |
1114 | desc.bInterfaceNumber, 0); | 1112 | desc.bInterfaceNumber, 0); |
1115 | intf->needs_altsetting0 = 0; | 1113 | intf->needs_altsetting0 = 0; |
@@ -1189,13 +1187,22 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) | |||
1189 | for (i = n - 1; i >= 0; --i) { | 1187 | for (i = n - 1; i >= 0; --i) { |
1190 | intf = udev->actconfig->interface[i]; | 1188 | intf = udev->actconfig->interface[i]; |
1191 | status = usb_suspend_interface(udev, intf, msg); | 1189 | status = usb_suspend_interface(udev, intf, msg); |
1190 | |||
1191 | /* Ignore errors during system sleep transitions */ | ||
1192 | if (!(msg.event & PM_EVENT_AUTO)) | ||
1193 | status = 0; | ||
1192 | if (status != 0) | 1194 | if (status != 0) |
1193 | break; | 1195 | break; |
1194 | } | 1196 | } |
1195 | } | 1197 | } |
1196 | if (status == 0) | 1198 | if (status == 0) { |
1197 | status = usb_suspend_device(udev, msg); | 1199 | status = usb_suspend_device(udev, msg); |
1198 | 1200 | ||
1201 | /* Again, ignore errors during system sleep transitions */ | ||
1202 | if (!(msg.event & PM_EVENT_AUTO)) | ||
1203 | status = 0; | ||
1204 | } | ||
1205 | |||
1199 | /* If the suspend failed, resume interfaces that did get suspended */ | 1206 | /* If the suspend failed, resume interfaces that did get suspended */ |
1200 | if (status != 0) { | 1207 | if (status != 0) { |
1201 | msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); | 1208 | msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); |
@@ -1262,6 +1269,7 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) | |||
1262 | udev->reset_resume); | 1269 | udev->reset_resume); |
1263 | } | 1270 | } |
1264 | } | 1271 | } |
1272 | usb_mark_last_busy(udev); | ||
1265 | 1273 | ||
1266 | done: | 1274 | done: |
1267 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); | 1275 | dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); |
@@ -1329,7 +1337,6 @@ int usb_resume(struct device *dev, pm_message_t msg) | |||
1329 | pm_runtime_disable(dev); | 1337 | pm_runtime_disable(dev); |
1330 | pm_runtime_set_active(dev); | 1338 | pm_runtime_set_active(dev); |
1331 | pm_runtime_enable(dev); | 1339 | pm_runtime_enable(dev); |
1332 | udev->last_busy = jiffies; | ||
1333 | do_unbind_rebind(udev, DO_REBIND); | 1340 | do_unbind_rebind(udev, DO_REBIND); |
1334 | } | 1341 | } |
1335 | } | 1342 | } |
@@ -1337,7 +1344,7 @@ int usb_resume(struct device *dev, pm_message_t msg) | |||
1337 | /* Avoid PM error messages for devices disconnected while suspended | 1344 | /* Avoid PM error messages for devices disconnected while suspended |
1338 | * as we'll display regular disconnect messages just a bit later. | 1345 | * as we'll display regular disconnect messages just a bit later. |
1339 | */ | 1346 | */ |
1340 | if (status == -ENODEV) | 1347 | if (status == -ENODEV || status == -ESHUTDOWN) |
1341 | status = 0; | 1348 | status = 0; |
1342 | return status; | 1349 | return status; |
1343 | } | 1350 | } |
@@ -1397,33 +1404,8 @@ void usb_autosuspend_device(struct usb_device *udev) | |||
1397 | { | 1404 | { |
1398 | int status; | 1405 | int status; |
1399 | 1406 | ||
1400 | udev->last_busy = jiffies; | 1407 | usb_mark_last_busy(udev); |
1401 | status = pm_runtime_put_sync(&udev->dev); | 1408 | status = pm_runtime_put_sync_autosuspend(&udev->dev); |
1402 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", | ||
1403 | __func__, atomic_read(&udev->dev.power.usage_count), | ||
1404 | status); | ||
1405 | } | ||
1406 | |||
1407 | /** | ||
1408 | * usb_try_autosuspend_device - attempt an autosuspend of a USB device and its interfaces | ||
1409 | * @udev: the usb_device to autosuspend | ||
1410 | * | ||
1411 | * This routine should be called when a core subsystem thinks @udev may | ||
1412 | * be ready to autosuspend. | ||
1413 | * | ||
1414 | * @udev's usage counter left unchanged. If it is 0 and all the interfaces | ||
1415 | * are inactive then an autosuspend will be attempted. The attempt may | ||
1416 | * fail or be delayed. | ||
1417 | * | ||
1418 | * The caller must hold @udev's device lock. | ||
1419 | * | ||
1420 | * This routine can run only in process context. | ||
1421 | */ | ||
1422 | void usb_try_autosuspend_device(struct usb_device *udev) | ||
1423 | { | ||
1424 | int status; | ||
1425 | |||
1426 | status = pm_runtime_idle(&udev->dev); | ||
1427 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", | 1409 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
1428 | __func__, atomic_read(&udev->dev.power.usage_count), | 1410 | __func__, atomic_read(&udev->dev.power.usage_count), |
1429 | status); | 1411 | status); |
@@ -1482,7 +1464,7 @@ void usb_autopm_put_interface(struct usb_interface *intf) | |||
1482 | struct usb_device *udev = interface_to_usbdev(intf); | 1464 | struct usb_device *udev = interface_to_usbdev(intf); |
1483 | int status; | 1465 | int status; |
1484 | 1466 | ||
1485 | udev->last_busy = jiffies; | 1467 | usb_mark_last_busy(udev); |
1486 | atomic_dec(&intf->pm_usage_cnt); | 1468 | atomic_dec(&intf->pm_usage_cnt); |
1487 | status = pm_runtime_put_sync(&intf->dev); | 1469 | status = pm_runtime_put_sync(&intf->dev); |
1488 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", | 1470 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
@@ -1509,32 +1491,11 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | |||
1509 | void usb_autopm_put_interface_async(struct usb_interface *intf) | 1491 | void usb_autopm_put_interface_async(struct usb_interface *intf) |
1510 | { | 1492 | { |
1511 | struct usb_device *udev = interface_to_usbdev(intf); | 1493 | struct usb_device *udev = interface_to_usbdev(intf); |
1512 | unsigned long last_busy; | 1494 | int status; |
1513 | int status = 0; | ||
1514 | 1495 | ||
1515 | last_busy = udev->last_busy; | 1496 | usb_mark_last_busy(udev); |
1516 | udev->last_busy = jiffies; | ||
1517 | atomic_dec(&intf->pm_usage_cnt); | 1497 | atomic_dec(&intf->pm_usage_cnt); |
1518 | pm_runtime_put_noidle(&intf->dev); | 1498 | status = pm_runtime_put(&intf->dev); |
1519 | |||
1520 | if (udev->dev.power.runtime_auto) { | ||
1521 | /* Optimization: Don't schedule a delayed autosuspend if | ||
1522 | * the timer is already running and the expiration time | ||
1523 | * wouldn't change. | ||
1524 | * | ||
1525 | * We have to use the interface's timer. Attempts to | ||
1526 | * schedule a suspend for the device would fail because | ||
1527 | * the interface is still active. | ||
1528 | */ | ||
1529 | if (intf->dev.power.timer_expires == 0 || | ||
1530 | round_jiffies_up(last_busy) != | ||
1531 | round_jiffies_up(jiffies)) { | ||
1532 | status = pm_schedule_suspend(&intf->dev, | ||
1533 | jiffies_to_msecs( | ||
1534 | round_jiffies_up_relative( | ||
1535 | udev->autosuspend_delay))); | ||
1536 | } | ||
1537 | } | ||
1538 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", | 1499 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
1539 | __func__, atomic_read(&intf->dev.power.usage_count), | 1500 | __func__, atomic_read(&intf->dev.power.usage_count), |
1540 | status); | 1501 | status); |
@@ -1554,7 +1515,7 @@ void usb_autopm_put_interface_no_suspend(struct usb_interface *intf) | |||
1554 | { | 1515 | { |
1555 | struct usb_device *udev = interface_to_usbdev(intf); | 1516 | struct usb_device *udev = interface_to_usbdev(intf); |
1556 | 1517 | ||
1557 | udev->last_busy = jiffies; | 1518 | usb_mark_last_busy(udev); |
1558 | atomic_dec(&intf->pm_usage_cnt); | 1519 | atomic_dec(&intf->pm_usage_cnt); |
1559 | pm_runtime_put_noidle(&intf->dev); | 1520 | pm_runtime_put_noidle(&intf->dev); |
1560 | } | 1521 | } |
@@ -1612,18 +1573,9 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface); | |||
1612 | */ | 1573 | */ |
1613 | int usb_autopm_get_interface_async(struct usb_interface *intf) | 1574 | int usb_autopm_get_interface_async(struct usb_interface *intf) |
1614 | { | 1575 | { |
1615 | int status = 0; | 1576 | int status; |
1616 | enum rpm_status s; | ||
1617 | |||
1618 | /* Don't request a resume unless the interface is already suspending | ||
1619 | * or suspended. Doing so would force a running suspend timer to be | ||
1620 | * cancelled. | ||
1621 | */ | ||
1622 | pm_runtime_get_noresume(&intf->dev); | ||
1623 | s = ACCESS_ONCE(intf->dev.power.runtime_status); | ||
1624 | if (s == RPM_SUSPENDING || s == RPM_SUSPENDED) | ||
1625 | status = pm_request_resume(&intf->dev); | ||
1626 | 1577 | ||
1578 | status = pm_runtime_get(&intf->dev); | ||
1627 | if (status < 0 && status != -EINPROGRESS) | 1579 | if (status < 0 && status != -EINPROGRESS) |
1628 | pm_runtime_put_noidle(&intf->dev); | 1580 | pm_runtime_put_noidle(&intf->dev); |
1629 | else | 1581 | else |
@@ -1650,7 +1602,7 @@ void usb_autopm_get_interface_no_resume(struct usb_interface *intf) | |||
1650 | { | 1602 | { |
1651 | struct usb_device *udev = interface_to_usbdev(intf); | 1603 | struct usb_device *udev = interface_to_usbdev(intf); |
1652 | 1604 | ||
1653 | udev->last_busy = jiffies; | 1605 | usb_mark_last_busy(udev); |
1654 | atomic_inc(&intf->pm_usage_cnt); | 1606 | atomic_inc(&intf->pm_usage_cnt); |
1655 | pm_runtime_get_noresume(&intf->dev); | 1607 | pm_runtime_get_noresume(&intf->dev); |
1656 | } | 1608 | } |
@@ -1661,7 +1613,6 @@ static int autosuspend_check(struct usb_device *udev) | |||
1661 | { | 1613 | { |
1662 | int w, i; | 1614 | int w, i; |
1663 | struct usb_interface *intf; | 1615 | struct usb_interface *intf; |
1664 | unsigned long suspend_time, j; | ||
1665 | 1616 | ||
1666 | /* Fail if autosuspend is disabled, or any interfaces are in use, or | 1617 | /* Fail if autosuspend is disabled, or any interfaces are in use, or |
1667 | * any interface drivers require remote wakeup but it isn't available. | 1618 | * any interface drivers require remote wakeup but it isn't available. |
@@ -1701,103 +1652,58 @@ static int autosuspend_check(struct usb_device *udev) | |||
1701 | return -EOPNOTSUPP; | 1652 | return -EOPNOTSUPP; |
1702 | } | 1653 | } |
1703 | udev->do_remote_wakeup = w; | 1654 | udev->do_remote_wakeup = w; |
1704 | |||
1705 | /* If everything is okay but the device hasn't been idle for long | ||
1706 | * enough, queue a delayed autosuspend request. | ||
1707 | */ | ||
1708 | j = ACCESS_ONCE(jiffies); | ||
1709 | suspend_time = udev->last_busy + udev->autosuspend_delay; | ||
1710 | if (time_before(j, suspend_time)) { | ||
1711 | pm_schedule_suspend(&udev->dev, jiffies_to_msecs( | ||
1712 | round_jiffies_up_relative(suspend_time - j))); | ||
1713 | return -EAGAIN; | ||
1714 | } | ||
1715 | return 0; | 1655 | return 0; |
1716 | } | 1656 | } |
1717 | 1657 | ||
1718 | static int usb_runtime_suspend(struct device *dev) | 1658 | int usb_runtime_suspend(struct device *dev) |
1719 | { | 1659 | { |
1720 | int status = 0; | 1660 | struct usb_device *udev = to_usb_device(dev); |
1661 | int status; | ||
1721 | 1662 | ||
1722 | /* A USB device can be suspended if it passes the various autosuspend | 1663 | /* A USB device can be suspended if it passes the various autosuspend |
1723 | * checks. Runtime suspend for a USB device means suspending all the | 1664 | * checks. Runtime suspend for a USB device means suspending all the |
1724 | * interfaces and then the device itself. | 1665 | * interfaces and then the device itself. |
1725 | */ | 1666 | */ |
1726 | if (is_usb_device(dev)) { | 1667 | if (autosuspend_check(udev) != 0) |
1727 | struct usb_device *udev = to_usb_device(dev); | 1668 | return -EAGAIN; |
1728 | |||
1729 | if (autosuspend_check(udev) != 0) | ||
1730 | return -EAGAIN; | ||
1731 | |||
1732 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | ||
1733 | |||
1734 | /* If an interface fails the suspend, adjust the last_busy | ||
1735 | * time so that we don't get another suspend attempt right | ||
1736 | * away. | ||
1737 | */ | ||
1738 | if (status) { | ||
1739 | udev->last_busy = jiffies + | ||
1740 | (udev->autosuspend_delay == 0 ? | ||
1741 | HZ/2 : 0); | ||
1742 | } | ||
1743 | |||
1744 | /* Prevent the parent from suspending immediately after */ | ||
1745 | else if (udev->parent) | ||
1746 | udev->parent->last_busy = jiffies; | ||
1747 | } | ||
1748 | 1669 | ||
1749 | /* Runtime suspend for a USB interface doesn't mean anything. */ | 1670 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1671 | /* The PM core reacts badly unless the return code is 0, | ||
1672 | * -EAGAIN, or -EBUSY, so always return -EBUSY on an error. | ||
1673 | */ | ||
1674 | if (status != 0) | ||
1675 | return -EBUSY; | ||
1750 | return status; | 1676 | return status; |
1751 | } | 1677 | } |
1752 | 1678 | ||
1753 | static int usb_runtime_resume(struct device *dev) | 1679 | int usb_runtime_resume(struct device *dev) |
1754 | { | 1680 | { |
1681 | struct usb_device *udev = to_usb_device(dev); | ||
1682 | int status; | ||
1683 | |||
1755 | /* Runtime resume for a USB device means resuming both the device | 1684 | /* Runtime resume for a USB device means resuming both the device |
1756 | * and all its interfaces. | 1685 | * and all its interfaces. |
1757 | */ | 1686 | */ |
1758 | if (is_usb_device(dev)) { | 1687 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); |
1759 | struct usb_device *udev = to_usb_device(dev); | 1688 | return status; |
1760 | int status; | ||
1761 | |||
1762 | status = usb_resume_both(udev, PMSG_AUTO_RESUME); | ||
1763 | udev->last_busy = jiffies; | ||
1764 | return status; | ||
1765 | } | ||
1766 | |||
1767 | /* Runtime resume for a USB interface doesn't mean anything. */ | ||
1768 | return 0; | ||
1769 | } | 1689 | } |
1770 | 1690 | ||
1771 | static int usb_runtime_idle(struct device *dev) | 1691 | int usb_runtime_idle(struct device *dev) |
1772 | { | 1692 | { |
1693 | struct usb_device *udev = to_usb_device(dev); | ||
1694 | |||
1773 | /* An idle USB device can be suspended if it passes the various | 1695 | /* An idle USB device can be suspended if it passes the various |
1774 | * autosuspend checks. An idle interface can be suspended at | 1696 | * autosuspend checks. |
1775 | * any time. | ||
1776 | */ | 1697 | */ |
1777 | if (is_usb_device(dev)) { | 1698 | if (autosuspend_check(udev) == 0) |
1778 | struct usb_device *udev = to_usb_device(dev); | 1699 | pm_runtime_autosuspend(dev); |
1779 | |||
1780 | if (autosuspend_check(udev) != 0) | ||
1781 | return 0; | ||
1782 | } | ||
1783 | |||
1784 | pm_runtime_suspend(dev); | ||
1785 | return 0; | 1700 | return 0; |
1786 | } | 1701 | } |
1787 | 1702 | ||
1788 | static const struct dev_pm_ops usb_bus_pm_ops = { | ||
1789 | .runtime_suspend = usb_runtime_suspend, | ||
1790 | .runtime_resume = usb_runtime_resume, | ||
1791 | .runtime_idle = usb_runtime_idle, | ||
1792 | }; | ||
1793 | |||
1794 | #endif /* CONFIG_USB_SUSPEND */ | 1703 | #endif /* CONFIG_USB_SUSPEND */ |
1795 | 1704 | ||
1796 | struct bus_type usb_bus_type = { | 1705 | struct bus_type usb_bus_type = { |
1797 | .name = "usb", | 1706 | .name = "usb", |
1798 | .match = usb_device_match, | 1707 | .match = usb_device_match, |
1799 | .uevent = usb_uevent, | 1708 | .uevent = usb_uevent, |
1800 | #ifdef CONFIG_USB_SUSPEND | ||
1801 | .pm = &usb_bus_pm_ops, | ||
1802 | #endif | ||
1803 | }; | 1709 | }; |
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index 3788e738e265..df502a98d0df 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -192,17 +192,17 @@ int usb_create_ep_devs(struct device *parent, | |||
192 | ep_dev->dev.parent = parent; | 192 | ep_dev->dev.parent = parent; |
193 | ep_dev->dev.release = ep_device_release; | 193 | ep_dev->dev.release = ep_device_release; |
194 | dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); | 194 | dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); |
195 | device_enable_async_suspend(&ep_dev->dev); | ||
196 | 195 | ||
197 | retval = device_register(&ep_dev->dev); | 196 | retval = device_register(&ep_dev->dev); |
198 | if (retval) | 197 | if (retval) |
199 | goto error_register; | 198 | goto error_register; |
200 | 199 | ||
200 | device_enable_async_suspend(&ep_dev->dev); | ||
201 | endpoint->ep_dev = ep_dev; | 201 | endpoint->ep_dev = ep_dev; |
202 | return retval; | 202 | return retval; |
203 | 203 | ||
204 | error_register: | 204 | error_register: |
205 | kfree(ep_dev); | 205 | put_device(&ep_dev->dev); |
206 | exit: | 206 | exit: |
207 | return retval; | 207 | return retval; |
208 | } | 208 | } |
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c index 1e6ccef2cf0c..99458c843d60 100644 --- a/drivers/usb/core/file.c +++ b/drivers/usb/core/file.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/rwsem.h> | 20 | #include <linux/rwsem.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/smp_lock.h> | ||
23 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
24 | 23 | ||
25 | #include "usb.h" | 24 | #include "usb.h" |
@@ -59,6 +58,7 @@ static int usb_open(struct inode * inode, struct file * file) | |||
59 | static const 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, |
61 | .llseek = noop_llseek, | ||
62 | }; | 62 | }; |
63 | 63 | ||
64 | static struct usb_class { | 64 | static struct usb_class { |
@@ -236,13 +236,6 @@ EXPORT_SYMBOL_GPL(usb_register_dev); | |||
236 | void usb_deregister_dev(struct usb_interface *intf, | 236 | void usb_deregister_dev(struct usb_interface *intf, |
237 | struct usb_class_driver *class_driver) | 237 | struct usb_class_driver *class_driver) |
238 | { | 238 | { |
239 | int minor_base = class_driver->minor_base; | ||
240 | char name[20]; | ||
241 | |||
242 | #ifdef CONFIG_USB_DYNAMIC_MINORS | ||
243 | minor_base = 0; | ||
244 | #endif | ||
245 | |||
246 | if (intf->minor == -1) | 239 | if (intf->minor == -1) |
247 | return; | 240 | return; |
248 | 241 | ||
@@ -252,7 +245,6 @@ void usb_deregister_dev(struct usb_interface *intf, | |||
252 | usb_minors[intf->minor] = NULL; | 245 | usb_minors[intf->minor] = NULL; |
253 | up_write(&minor_rwsem); | 246 | up_write(&minor_rwsem); |
254 | 247 | ||
255 | snprintf(name, sizeof(name), class_driver->name, intf->minor - minor_base); | ||
256 | device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); | 248 | device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor)); |
257 | intf->usb_dev = NULL; | 249 | intf->usb_dev = NULL; |
258 | intf->minor = -1; | 250 | intf->minor = -1; |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index c3f98543caaf..ce22f4a84ed0 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
22 | #include <linux/pm_runtime.h> | ||
23 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
24 | #include <linux/usb/hcd.h> | 23 | #include <linux/usb/hcd.h> |
25 | 24 | ||
@@ -193,13 +192,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
193 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", | 192 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", |
194 | pci_name(dev)); | 193 | pci_name(dev)); |
195 | retval = -ENODEV; | 194 | retval = -ENODEV; |
196 | goto err1; | 195 | goto disable_pci; |
197 | } | 196 | } |
198 | 197 | ||
199 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); | 198 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); |
200 | if (!hcd) { | 199 | if (!hcd) { |
201 | retval = -ENOMEM; | 200 | retval = -ENOMEM; |
202 | goto err1; | 201 | goto disable_pci; |
203 | } | 202 | } |
204 | 203 | ||
205 | if (driver->flags & HCD_MEMORY) { | 204 | if (driver->flags & HCD_MEMORY) { |
@@ -210,13 +209,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
210 | driver->description)) { | 209 | driver->description)) { |
211 | dev_dbg(&dev->dev, "controller already in use\n"); | 210 | dev_dbg(&dev->dev, "controller already in use\n"); |
212 | retval = -EBUSY; | 211 | retval = -EBUSY; |
213 | goto err2; | 212 | goto clear_companion; |
214 | } | 213 | } |
215 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | 214 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
216 | if (hcd->regs == NULL) { | 215 | if (hcd->regs == NULL) { |
217 | dev_dbg(&dev->dev, "error mapping memory\n"); | 216 | dev_dbg(&dev->dev, "error mapping memory\n"); |
218 | retval = -EFAULT; | 217 | retval = -EFAULT; |
219 | goto err3; | 218 | goto release_mem_region; |
220 | } | 219 | } |
221 | 220 | ||
222 | } else { | 221 | } else { |
@@ -237,7 +236,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
237 | if (region == PCI_ROM_RESOURCE) { | 236 | if (region == PCI_ROM_RESOURCE) { |
238 | dev_dbg(&dev->dev, "no i/o regions available\n"); | 237 | dev_dbg(&dev->dev, "no i/o regions available\n"); |
239 | retval = -EBUSY; | 238 | retval = -EBUSY; |
240 | goto err2; | 239 | goto clear_companion; |
241 | } | 240 | } |
242 | } | 241 | } |
243 | 242 | ||
@@ -245,24 +244,24 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
245 | 244 | ||
246 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 245 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
247 | if (retval != 0) | 246 | if (retval != 0) |
248 | goto err4; | 247 | goto unmap_registers; |
249 | set_hs_companion(dev, hcd); | 248 | set_hs_companion(dev, hcd); |
250 | 249 | ||
251 | if (pci_dev_run_wake(dev)) | 250 | if (pci_dev_run_wake(dev)) |
252 | pm_runtime_put_noidle(&dev->dev); | 251 | pm_runtime_put_noidle(&dev->dev); |
253 | return retval; | 252 | return retval; |
254 | 253 | ||
255 | err4: | 254 | unmap_registers: |
256 | if (driver->flags & HCD_MEMORY) { | 255 | if (driver->flags & HCD_MEMORY) { |
257 | iounmap(hcd->regs); | 256 | iounmap(hcd->regs); |
258 | err3: | 257 | release_mem_region: |
259 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 258 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
260 | } else | 259 | } else |
261 | release_region(hcd->rsrc_start, hcd->rsrc_len); | 260 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
262 | err2: | 261 | clear_companion: |
263 | clear_hs_companion(dev, hcd); | 262 | clear_hs_companion(dev, hcd); |
264 | usb_put_hcd(hcd); | 263 | usb_put_hcd(hcd); |
265 | err1: | 264 | disable_pci: |
266 | pci_disable_device(dev); | 265 | pci_disable_device(dev); |
267 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); | 266 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); |
268 | return retval; | 267 | return retval; |
@@ -329,12 +328,14 @@ void usb_hcd_pci_shutdown(struct pci_dev *dev) | |||
329 | return; | 328 | return; |
330 | 329 | ||
331 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && | 330 | if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && |
332 | hcd->driver->shutdown) | 331 | hcd->driver->shutdown) { |
333 | hcd->driver->shutdown(hcd); | 332 | hcd->driver->shutdown(hcd); |
333 | pci_disable_device(dev); | ||
334 | } | ||
334 | } | 335 | } |
335 | EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); | 336 | EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); |
336 | 337 | ||
337 | #ifdef CONFIG_PM_OPS | 338 | #ifdef CONFIG_PM |
338 | 339 | ||
339 | #ifdef CONFIG_PPC_PMAC | 340 | #ifdef CONFIG_PPC_PMAC |
340 | static void powermac_set_asic(struct pci_dev *pci_dev, int enable) | 341 | static void powermac_set_asic(struct pci_dev *pci_dev, int enable) |
@@ -362,11 +363,17 @@ static int check_root_hub_suspended(struct device *dev) | |||
362 | struct pci_dev *pci_dev = to_pci_dev(dev); | 363 | struct pci_dev *pci_dev = to_pci_dev(dev); |
363 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 364 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
364 | 365 | ||
365 | if (!(hcd->state == HC_STATE_SUSPENDED || | 366 | if (HCD_RH_RUNNING(hcd)) { |
366 | hcd->state == HC_STATE_HALT)) { | ||
367 | dev_warn(dev, "Root hub is not suspended\n"); | 367 | dev_warn(dev, "Root hub is not suspended\n"); |
368 | return -EBUSY; | 368 | return -EBUSY; |
369 | } | 369 | } |
370 | if (hcd->shared_hcd) { | ||
371 | hcd = hcd->shared_hcd; | ||
372 | if (HCD_RH_RUNNING(hcd)) { | ||
373 | dev_warn(dev, "Secondary root hub is not suspended\n"); | ||
374 | return -EBUSY; | ||
375 | } | ||
376 | } | ||
370 | return 0; | 377 | return 0; |
371 | } | 378 | } |
372 | 379 | ||
@@ -385,17 +392,22 @@ static int suspend_common(struct device *dev, bool do_wakeup) | |||
385 | if (retval) | 392 | if (retval) |
386 | return retval; | 393 | return retval; |
387 | 394 | ||
388 | if (hcd->driver->pci_suspend) { | 395 | if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) { |
389 | /* Optimization: Don't suspend if a root-hub wakeup is | 396 | /* Optimization: Don't suspend if a root-hub wakeup is |
390 | * pending and it would cause the HCD to wake up anyway. | 397 | * pending and it would cause the HCD to wake up anyway. |
391 | */ | 398 | */ |
392 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) | 399 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) |
393 | return -EBUSY; | 400 | return -EBUSY; |
401 | if (do_wakeup && hcd->shared_hcd && | ||
402 | HCD_WAKEUP_PENDING(hcd->shared_hcd)) | ||
403 | return -EBUSY; | ||
394 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); | 404 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); |
395 | suspend_report_result(hcd->driver->pci_suspend, retval); | 405 | suspend_report_result(hcd->driver->pci_suspend, retval); |
396 | 406 | ||
397 | /* Check again in case wakeup raced with pci_suspend */ | 407 | /* Check again in case wakeup raced with pci_suspend */ |
398 | if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | 408 | if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) || |
409 | (retval == 0 && do_wakeup && hcd->shared_hcd && | ||
410 | HCD_WAKEUP_PENDING(hcd->shared_hcd))) { | ||
399 | if (hcd->driver->pci_resume) | 411 | if (hcd->driver->pci_resume) |
400 | hcd->driver->pci_resume(hcd, false); | 412 | hcd->driver->pci_resume(hcd, false); |
401 | retval = -EBUSY; | 413 | retval = -EBUSY; |
@@ -404,7 +416,12 @@ static int suspend_common(struct device *dev, bool do_wakeup) | |||
404 | return retval; | 416 | return retval; |
405 | } | 417 | } |
406 | 418 | ||
407 | synchronize_irq(pci_dev->irq); | 419 | /* If MSI-X is enabled, the driver will have synchronized all vectors |
420 | * in pci_suspend(). If MSI or legacy PCI is enabled, that will be | ||
421 | * synchronized here. | ||
422 | */ | ||
423 | if (!hcd->msix_enabled) | ||
424 | synchronize_irq(pci_dev->irq); | ||
408 | 425 | ||
409 | /* Downstream ports from this root hub should already be quiesced, so | 426 | /* Downstream ports from this root hub should already be quiesced, so |
410 | * there will be no DMA activity. Now we can shut down the upstream | 427 | * there will be no DMA activity. Now we can shut down the upstream |
@@ -421,7 +438,9 @@ static int resume_common(struct device *dev, int event) | |||
421 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 438 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
422 | int retval; | 439 | int retval; |
423 | 440 | ||
424 | if (hcd->state != HC_STATE_SUSPENDED) { | 441 | if (HCD_RH_RUNNING(hcd) || |
442 | (hcd->shared_hcd && | ||
443 | HCD_RH_RUNNING(hcd->shared_hcd))) { | ||
425 | dev_dbg(dev, "can't resume, not suspended!\n"); | 444 | dev_dbg(dev, "can't resume, not suspended!\n"); |
426 | return 0; | 445 | return 0; |
427 | } | 446 | } |
@@ -435,8 +454,10 @@ static int resume_common(struct device *dev, int event) | |||
435 | pci_set_master(pci_dev); | 454 | pci_set_master(pci_dev); |
436 | 455 | ||
437 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 456 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
457 | if (hcd->shared_hcd) | ||
458 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
438 | 459 | ||
439 | if (hcd->driver->pci_resume) { | 460 | if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { |
440 | if (event != PM_EVENT_AUTO_RESUME) | 461 | if (event != PM_EVENT_AUTO_RESUME) |
441 | wait_for_companions(pci_dev, hcd); | 462 | wait_for_companions(pci_dev, hcd); |
442 | 463 | ||
@@ -444,6 +465,8 @@ static int resume_common(struct device *dev, int event) | |||
444 | event == PM_EVENT_RESTORE); | 465 | event == PM_EVENT_RESTORE); |
445 | if (retval) { | 466 | if (retval) { |
446 | dev_err(dev, "PCI post-resume error %d!\n", retval); | 467 | dev_err(dev, "PCI post-resume error %d!\n", retval); |
468 | if (hcd->shared_hcd) | ||
469 | usb_hc_died(hcd->shared_hcd); | ||
447 | usb_hc_died(hcd); | 470 | usb_hc_died(hcd); |
448 | } | 471 | } |
449 | } | 472 | } |
@@ -469,10 +492,11 @@ static int hcd_pci_suspend_noirq(struct device *dev) | |||
469 | 492 | ||
470 | pci_save_state(pci_dev); | 493 | pci_save_state(pci_dev); |
471 | 494 | ||
472 | /* If the root hub is HALTed rather than SUSPENDed, | 495 | /* If the root hub is dead rather than suspended, disallow remote |
473 | * disallow remote wakeup. | 496 | * wakeup. usb_hc_died() should ensure that both hosts are marked as |
497 | * dying, so we only need to check the primary roothub. | ||
474 | */ | 498 | */ |
475 | if (hcd->state == HC_STATE_HALT) | 499 | if (HCD_DEAD(hcd)) |
476 | device_set_wakeup_enable(dev, 0); | 500 | device_set_wakeup_enable(dev, 0); |
477 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); | 501 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); |
478 | 502 | ||
@@ -574,4 +598,4 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = { | |||
574 | }; | 598 | }; |
575 | EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); | 599 | EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); |
576 | 600 | ||
577 | #endif /* CONFIG_PM_OPS */ | 601 | #endif /* CONFIG_PM */ |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 5cca00a6d09d..ace9f8442e5d 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -38,7 +38,6 @@ | |||
38 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
39 | #include <linux/platform_device.h> | 39 | #include <linux/platform_device.h> |
40 | #include <linux/workqueue.h> | 40 | #include <linux/workqueue.h> |
41 | #include <linux/pm_runtime.h> | ||
42 | 41 | ||
43 | #include <linux/usb.h> | 42 | #include <linux/usb.h> |
44 | #include <linux/usb/hcd.h> | 43 | #include <linux/usb/hcd.h> |
@@ -298,7 +297,7 @@ static const u8 ss_rh_config_descriptor[] = { | |||
298 | /* one configuration */ | 297 | /* one configuration */ |
299 | 0x09, /* __u8 bLength; */ | 298 | 0x09, /* __u8 bLength; */ |
300 | 0x02, /* __u8 bDescriptorType; Configuration */ | 299 | 0x02, /* __u8 bDescriptorType; Configuration */ |
301 | 0x19, 0x00, /* __le16 wTotalLength; FIXME */ | 300 | 0x1f, 0x00, /* __le16 wTotalLength; */ |
302 | 0x01, /* __u8 bNumInterfaces; (1) */ | 301 | 0x01, /* __u8 bNumInterfaces; (1) */ |
303 | 0x01, /* __u8 bConfigurationValue; */ | 302 | 0x01, /* __u8 bConfigurationValue; */ |
304 | 0x00, /* __u8 iConfiguration; */ | 303 | 0x00, /* __u8 iConfiguration; */ |
@@ -328,11 +327,14 @@ static const u8 ss_rh_config_descriptor[] = { | |||
328 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) | 327 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) |
329 | * see hub.c:hub_configure() for details. */ | 328 | * see hub.c:hub_configure() for details. */ |
330 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, | 329 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, |
331 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ | 330 | 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ |
332 | /* | 331 | |
333 | * All 3.0 hubs should have an endpoint companion descriptor, | 332 | /* one SuperSpeed endpoint companion descriptor */ |
334 | * but we're ignoring that for now. FIXME? | 333 | 0x06, /* __u8 ss_bLength */ |
335 | */ | 334 | 0x30, /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */ |
335 | 0x00, /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */ | ||
336 | 0x00, /* __u8 ss_bmAttributes; 1 packet per service interval */ | ||
337 | 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */ | ||
336 | }; | 338 | }; |
337 | 339 | ||
338 | /*-------------------------------------------------------------------------*/ | 340 | /*-------------------------------------------------------------------------*/ |
@@ -505,7 +507,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
505 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | 507 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
506 | switch (wValue & 0xff00) { | 508 | switch (wValue & 0xff00) { |
507 | case USB_DT_DEVICE << 8: | 509 | case USB_DT_DEVICE << 8: |
508 | switch (hcd->driver->flags & HCD_MASK) { | 510 | switch (hcd->speed) { |
509 | case HCD_USB3: | 511 | case HCD_USB3: |
510 | bufp = usb3_rh_dev_descriptor; | 512 | bufp = usb3_rh_dev_descriptor; |
511 | break; | 513 | break; |
@@ -523,7 +525,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
523 | patch_protocol = 1; | 525 | patch_protocol = 1; |
524 | break; | 526 | break; |
525 | case USB_DT_CONFIG << 8: | 527 | case USB_DT_CONFIG << 8: |
526 | switch (hcd->driver->flags & HCD_MASK) { | 528 | switch (hcd->speed) { |
527 | case HCD_USB3: | 529 | case HCD_USB3: |
528 | bufp = ss_rh_config_descriptor; | 530 | bufp = ss_rh_config_descriptor; |
529 | len = sizeof ss_rh_config_descriptor; | 531 | len = sizeof ss_rh_config_descriptor; |
@@ -698,7 +700,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd) | |||
698 | /* The USB 2.0 spec says 256 ms. This is close enough and won't | 700 | /* The USB 2.0 spec says 256 ms. This is close enough and won't |
699 | * exceed that limit if HZ is 100. The math is more clunky than | 701 | * exceed that limit if HZ is 100. The math is more clunky than |
700 | * maybe expected, this is to make sure that all timers for USB devices | 702 | * maybe expected, this is to make sure that all timers for USB devices |
701 | * fire at the same time to give the CPU a break inbetween */ | 703 | * fire at the same time to give the CPU a break in between */ |
702 | if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : | 704 | if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : |
703 | (length == 0 && hcd->status_urb != NULL)) | 705 | (length == 0 && hcd->status_urb != NULL)) |
704 | mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); | 706 | mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); |
@@ -984,7 +986,7 @@ static int register_root_hub(struct usb_hcd *hcd) | |||
984 | spin_unlock_irq (&hcd_root_hub_lock); | 986 | spin_unlock_irq (&hcd_root_hub_lock); |
985 | 987 | ||
986 | /* Did the HC die before the root hub was registered? */ | 988 | /* Did the HC die before the root hub was registered? */ |
987 | if (hcd->state == HC_STATE_HALT) | 989 | if (HCD_DEAD(hcd)) |
988 | usb_hc_died (hcd); /* This time clean up */ | 990 | usb_hc_died (hcd); /* This time clean up */ |
989 | } | 991 | } |
990 | 992 | ||
@@ -1090,13 +1092,10 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) | |||
1090 | * Check the host controller's state and add the URB to the | 1092 | * Check the host controller's state and add the URB to the |
1091 | * endpoint's queue. | 1093 | * endpoint's queue. |
1092 | */ | 1094 | */ |
1093 | switch (hcd->state) { | 1095 | if (HCD_RH_RUNNING(hcd)) { |
1094 | case HC_STATE_RUNNING: | ||
1095 | case HC_STATE_RESUMING: | ||
1096 | urb->unlinked = 0; | 1096 | urb->unlinked = 0; |
1097 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); | 1097 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); |
1098 | break; | 1098 | } else { |
1099 | default: | ||
1100 | rc = -ESHUTDOWN; | 1099 | rc = -ESHUTDOWN; |
1101 | goto done; | 1100 | goto done; |
1102 | } | 1101 | } |
@@ -1154,6 +1153,8 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, | |||
1154 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " | 1153 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " |
1155 | "Controller is probably using the wrong IRQ.\n"); | 1154 | "Controller is probably using the wrong IRQ.\n"); |
1156 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 1155 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
1156 | if (hcd->shared_hcd) | ||
1157 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
1157 | } | 1158 | } |
1158 | 1159 | ||
1159 | return 0; | 1160 | return 0; |
@@ -1263,10 +1264,8 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle, | |||
1263 | *dma_handle = 0; | 1264 | *dma_handle = 0; |
1264 | } | 1265 | } |
1265 | 1266 | ||
1266 | static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | 1267 | void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) |
1267 | { | 1268 | { |
1268 | enum dma_data_direction dir; | ||
1269 | |||
1270 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) | 1269 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) |
1271 | dma_unmap_single(hcd->self.controller, | 1270 | dma_unmap_single(hcd->self.controller, |
1272 | urb->setup_dma, | 1271 | urb->setup_dma, |
@@ -1279,6 +1278,25 @@ static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1279 | sizeof(struct usb_ctrlrequest), | 1278 | sizeof(struct usb_ctrlrequest), |
1280 | DMA_TO_DEVICE); | 1279 | DMA_TO_DEVICE); |
1281 | 1280 | ||
1281 | /* Make it safe to call this routine more than once */ | ||
1282 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); | ||
1283 | } | ||
1284 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma); | ||
1285 | |||
1286 | static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
1287 | { | ||
1288 | if (hcd->driver->unmap_urb_for_dma) | ||
1289 | hcd->driver->unmap_urb_for_dma(hcd, urb); | ||
1290 | else | ||
1291 | usb_hcd_unmap_urb_for_dma(hcd, urb); | ||
1292 | } | ||
1293 | |||
1294 | void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
1295 | { | ||
1296 | enum dma_data_direction dir; | ||
1297 | |||
1298 | usb_hcd_unmap_urb_setup_for_dma(hcd, urb); | ||
1299 | |||
1282 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 1300 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; |
1283 | if (urb->transfer_flags & URB_DMA_MAP_SG) | 1301 | if (urb->transfer_flags & URB_DMA_MAP_SG) |
1284 | dma_unmap_sg(hcd->self.controller, | 1302 | dma_unmap_sg(hcd->self.controller, |
@@ -1303,14 +1321,23 @@ static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1303 | dir); | 1321 | dir); |
1304 | 1322 | ||
1305 | /* Make it safe to call this routine more than once */ | 1323 | /* Make it safe to call this routine more than once */ |
1306 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL | | 1324 | urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | |
1307 | URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | | ||
1308 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); | 1325 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); |
1309 | } | 1326 | } |
1327 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma); | ||
1310 | 1328 | ||
1311 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | 1329 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, |
1312 | gfp_t mem_flags) | 1330 | gfp_t mem_flags) |
1313 | { | 1331 | { |
1332 | if (hcd->driver->map_urb_for_dma) | ||
1333 | return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); | ||
1334 | else | ||
1335 | return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
1336 | } | ||
1337 | |||
1338 | int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | ||
1339 | gfp_t mem_flags) | ||
1340 | { | ||
1314 | enum dma_data_direction dir; | 1341 | enum dma_data_direction dir; |
1315 | int ret = 0; | 1342 | int ret = 0; |
1316 | 1343 | ||
@@ -1321,6 +1348,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1321 | */ | 1348 | */ |
1322 | 1349 | ||
1323 | if (usb_endpoint_xfer_control(&urb->ep->desc)) { | 1350 | if (usb_endpoint_xfer_control(&urb->ep->desc)) { |
1351 | if (hcd->self.uses_pio_for_control) | ||
1352 | return ret; | ||
1324 | if (hcd->self.uses_dma) { | 1353 | if (hcd->self.uses_dma) { |
1325 | urb->setup_dma = dma_map_single( | 1354 | urb->setup_dma = dma_map_single( |
1326 | hcd->self.controller, | 1355 | hcd->self.controller, |
@@ -1400,10 +1429,11 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1400 | } | 1429 | } |
1401 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | | 1430 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | |
1402 | URB_SETUP_MAP_LOCAL))) | 1431 | URB_SETUP_MAP_LOCAL))) |
1403 | unmap_urb_for_dma(hcd, urb); | 1432 | usb_hcd_unmap_urb_for_dma(hcd, urb); |
1404 | } | 1433 | } |
1405 | return ret; | 1434 | return ret; |
1406 | } | 1435 | } |
1436 | EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma); | ||
1407 | 1437 | ||
1408 | /*-------------------------------------------------------------------------*/ | 1438 | /*-------------------------------------------------------------------------*/ |
1409 | 1439 | ||
@@ -1878,7 +1908,7 @@ void usb_free_streams(struct usb_interface *interface, | |||
1878 | 1908 | ||
1879 | /* Streams only apply to bulk endpoints. */ | 1909 | /* Streams only apply to bulk endpoints. */ |
1880 | for (i = 0; i < num_eps; i++) | 1910 | for (i = 0; i < num_eps; i++) |
1881 | if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) | 1911 | if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) |
1882 | return; | 1912 | return; |
1883 | 1913 | ||
1884 | hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); | 1914 | hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); |
@@ -1903,7 +1933,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev) | |||
1903 | { | 1933 | { |
1904 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 1934 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1905 | 1935 | ||
1906 | if (!HC_IS_RUNNING (hcd->state)) | 1936 | if (!HCD_RH_RUNNING(hcd)) |
1907 | return -ESHUTDOWN; | 1937 | return -ESHUTDOWN; |
1908 | return hcd->driver->get_frame_number (hcd); | 1938 | return hcd->driver->get_frame_number (hcd); |
1909 | } | 1939 | } |
@@ -1920,9 +1950,15 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1920 | 1950 | ||
1921 | dev_dbg(&rhdev->dev, "bus %s%s\n", | 1951 | dev_dbg(&rhdev->dev, "bus %s%s\n", |
1922 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); | 1952 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); |
1953 | if (HCD_DEAD(hcd)) { | ||
1954 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); | ||
1955 | return 0; | ||
1956 | } | ||
1957 | |||
1923 | if (!hcd->driver->bus_suspend) { | 1958 | if (!hcd->driver->bus_suspend) { |
1924 | status = -ENOENT; | 1959 | status = -ENOENT; |
1925 | } else { | 1960 | } else { |
1961 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1926 | hcd->state = HC_STATE_QUIESCING; | 1962 | hcd->state = HC_STATE_QUIESCING; |
1927 | status = hcd->driver->bus_suspend(hcd); | 1963 | status = hcd->driver->bus_suspend(hcd); |
1928 | } | 1964 | } |
@@ -1930,7 +1966,12 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1930 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); | 1966 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); |
1931 | hcd->state = HC_STATE_SUSPENDED; | 1967 | hcd->state = HC_STATE_SUSPENDED; |
1932 | } else { | 1968 | } else { |
1933 | hcd->state = old_state; | 1969 | spin_lock_irq(&hcd_root_hub_lock); |
1970 | if (!HCD_DEAD(hcd)) { | ||
1971 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1972 | hcd->state = old_state; | ||
1973 | } | ||
1974 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1934 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 1975 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
1935 | "suspend", status); | 1976 | "suspend", status); |
1936 | } | 1977 | } |
@@ -1945,21 +1986,30 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1945 | 1986 | ||
1946 | dev_dbg(&rhdev->dev, "usb %s%s\n", | 1987 | dev_dbg(&rhdev->dev, "usb %s%s\n", |
1947 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); | 1988 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); |
1948 | clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); | 1989 | if (HCD_DEAD(hcd)) { |
1990 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); | ||
1991 | return 0; | ||
1992 | } | ||
1949 | if (!hcd->driver->bus_resume) | 1993 | if (!hcd->driver->bus_resume) |
1950 | return -ENOENT; | 1994 | return -ENOENT; |
1951 | if (hcd->state == HC_STATE_RUNNING) | 1995 | if (HCD_RH_RUNNING(hcd)) |
1952 | return 0; | 1996 | return 0; |
1953 | 1997 | ||
1954 | hcd->state = HC_STATE_RESUMING; | 1998 | hcd->state = HC_STATE_RESUMING; |
1955 | status = hcd->driver->bus_resume(hcd); | 1999 | status = hcd->driver->bus_resume(hcd); |
2000 | clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); | ||
1956 | if (status == 0) { | 2001 | if (status == 0) { |
1957 | /* TRSMRCY = 10 msec */ | 2002 | /* TRSMRCY = 10 msec */ |
1958 | msleep(10); | 2003 | msleep(10); |
1959 | usb_set_device_state(rhdev, rhdev->actconfig | 2004 | spin_lock_irq(&hcd_root_hub_lock); |
1960 | ? USB_STATE_CONFIGURED | 2005 | if (!HCD_DEAD(hcd)) { |
1961 | : USB_STATE_ADDRESS); | 2006 | usb_set_device_state(rhdev, rhdev->actconfig |
1962 | hcd->state = HC_STATE_RUNNING; | 2007 | ? USB_STATE_CONFIGURED |
2008 | : USB_STATE_ADDRESS); | ||
2009 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2010 | hcd->state = HC_STATE_RUNNING; | ||
2011 | } | ||
2012 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1963 | } else { | 2013 | } else { |
1964 | hcd->state = old_state; | 2014 | hcd->state = old_state; |
1965 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 2015 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
@@ -2070,15 +2120,14 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd) | |||
2070 | */ | 2120 | */ |
2071 | local_irq_save(flags); | 2121 | local_irq_save(flags); |
2072 | 2122 | ||
2073 | if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { | 2123 | if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) { |
2074 | rc = IRQ_NONE; | 2124 | rc = IRQ_NONE; |
2075 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { | 2125 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { |
2076 | rc = IRQ_NONE; | 2126 | rc = IRQ_NONE; |
2077 | } else { | 2127 | } else { |
2078 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 2128 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
2079 | 2129 | if (hcd->shared_hcd) | |
2080 | if (unlikely(hcd->state == HC_STATE_HALT)) | 2130 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); |
2081 | usb_hc_died(hcd); | ||
2082 | rc = IRQ_HANDLED; | 2131 | rc = IRQ_HANDLED; |
2083 | } | 2132 | } |
2084 | 2133 | ||
@@ -2095,7 +2144,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq); | |||
2095 | * | 2144 | * |
2096 | * This is called by bus glue to report a USB host controller that died | 2145 | * This is called by bus glue to report a USB host controller that died |
2097 | * while operations may still have been pending. It's called automatically | 2146 | * while operations may still have been pending. It's called automatically |
2098 | * by the PCI glue, so only glue for non-PCI busses should need to call it. | 2147 | * by the PCI glue, so only glue for non-PCI busses should need to call it. |
2148 | * | ||
2149 | * Only call this function with the primary HCD. | ||
2099 | */ | 2150 | */ |
2100 | void usb_hc_died (struct usb_hcd *hcd) | 2151 | void usb_hc_died (struct usb_hcd *hcd) |
2101 | { | 2152 | { |
@@ -2104,6 +2155,8 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2104 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); | 2155 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); |
2105 | 2156 | ||
2106 | spin_lock_irqsave (&hcd_root_hub_lock, flags); | 2157 | spin_lock_irqsave (&hcd_root_hub_lock, flags); |
2158 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2159 | set_bit(HCD_FLAG_DEAD, &hcd->flags); | ||
2107 | if (hcd->rh_registered) { | 2160 | if (hcd->rh_registered) { |
2108 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2161 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2109 | 2162 | ||
@@ -2112,17 +2165,31 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2112 | USB_STATE_NOTATTACHED); | 2165 | USB_STATE_NOTATTACHED); |
2113 | usb_kick_khubd (hcd->self.root_hub); | 2166 | usb_kick_khubd (hcd->self.root_hub); |
2114 | } | 2167 | } |
2168 | if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { | ||
2169 | hcd = hcd->shared_hcd; | ||
2170 | if (hcd->rh_registered) { | ||
2171 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
2172 | |||
2173 | /* make khubd clean up old urbs and devices */ | ||
2174 | usb_set_device_state(hcd->self.root_hub, | ||
2175 | USB_STATE_NOTATTACHED); | ||
2176 | usb_kick_khubd(hcd->self.root_hub); | ||
2177 | } | ||
2178 | } | ||
2115 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 2179 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
2180 | /* Make sure that the other roothub is also deallocated. */ | ||
2116 | } | 2181 | } |
2117 | EXPORT_SYMBOL_GPL (usb_hc_died); | 2182 | EXPORT_SYMBOL_GPL (usb_hc_died); |
2118 | 2183 | ||
2119 | /*-------------------------------------------------------------------------*/ | 2184 | /*-------------------------------------------------------------------------*/ |
2120 | 2185 | ||
2121 | /** | 2186 | /** |
2122 | * usb_create_hcd - create and initialize an HCD structure | 2187 | * usb_create_shared_hcd - create and initialize an HCD structure |
2123 | * @driver: HC driver that will use this hcd | 2188 | * @driver: HC driver that will use this hcd |
2124 | * @dev: device for this HC, stored in hcd->self.controller | 2189 | * @dev: device for this HC, stored in hcd->self.controller |
2125 | * @bus_name: value to store in hcd->self.bus_name | 2190 | * @bus_name: value to store in hcd->self.bus_name |
2191 | * @primary_hcd: a pointer to the usb_hcd structure that is sharing the | ||
2192 | * PCI device. Only allocate certain resources for the primary HCD | ||
2126 | * Context: !in_interrupt() | 2193 | * Context: !in_interrupt() |
2127 | * | 2194 | * |
2128 | * Allocate a struct usb_hcd, with extra space at the end for the | 2195 | * Allocate a struct usb_hcd, with extra space at the end for the |
@@ -2131,8 +2198,9 @@ EXPORT_SYMBOL_GPL (usb_hc_died); | |||
2131 | * | 2198 | * |
2132 | * If memory is unavailable, returns NULL. | 2199 | * If memory is unavailable, returns NULL. |
2133 | */ | 2200 | */ |
2134 | struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | 2201 | struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, |
2135 | struct device *dev, const char *bus_name) | 2202 | struct device *dev, const char *bus_name, |
2203 | struct usb_hcd *primary_hcd) | ||
2136 | { | 2204 | { |
2137 | struct usb_hcd *hcd; | 2205 | struct usb_hcd *hcd; |
2138 | 2206 | ||
@@ -2141,7 +2209,24 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2141 | dev_dbg (dev, "hcd alloc failed\n"); | 2209 | dev_dbg (dev, "hcd alloc failed\n"); |
2142 | return NULL; | 2210 | return NULL; |
2143 | } | 2211 | } |
2144 | dev_set_drvdata(dev, hcd); | 2212 | if (primary_hcd == NULL) { |
2213 | hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), | ||
2214 | GFP_KERNEL); | ||
2215 | if (!hcd->bandwidth_mutex) { | ||
2216 | kfree(hcd); | ||
2217 | dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); | ||
2218 | return NULL; | ||
2219 | } | ||
2220 | mutex_init(hcd->bandwidth_mutex); | ||
2221 | dev_set_drvdata(dev, hcd); | ||
2222 | } else { | ||
2223 | hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; | ||
2224 | hcd->primary_hcd = primary_hcd; | ||
2225 | primary_hcd->primary_hcd = primary_hcd; | ||
2226 | hcd->shared_hcd = primary_hcd; | ||
2227 | primary_hcd->shared_hcd = hcd; | ||
2228 | } | ||
2229 | |||
2145 | kref_init(&hcd->kref); | 2230 | kref_init(&hcd->kref); |
2146 | 2231 | ||
2147 | usb_bus_init(&hcd->self); | 2232 | usb_bus_init(&hcd->self); |
@@ -2155,19 +2240,53 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2155 | #ifdef CONFIG_USB_SUSPEND | 2240 | #ifdef CONFIG_USB_SUSPEND |
2156 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); | 2241 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); |
2157 | #endif | 2242 | #endif |
2158 | mutex_init(&hcd->bandwidth_mutex); | ||
2159 | 2243 | ||
2160 | hcd->driver = driver; | 2244 | hcd->driver = driver; |
2245 | hcd->speed = driver->flags & HCD_MASK; | ||
2161 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : | 2246 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : |
2162 | "USB Host Controller"; | 2247 | "USB Host Controller"; |
2163 | return hcd; | 2248 | return hcd; |
2164 | } | 2249 | } |
2250 | EXPORT_SYMBOL_GPL(usb_create_shared_hcd); | ||
2251 | |||
2252 | /** | ||
2253 | * usb_create_hcd - create and initialize an HCD structure | ||
2254 | * @driver: HC driver that will use this hcd | ||
2255 | * @dev: device for this HC, stored in hcd->self.controller | ||
2256 | * @bus_name: value to store in hcd->self.bus_name | ||
2257 | * Context: !in_interrupt() | ||
2258 | * | ||
2259 | * Allocate a struct usb_hcd, with extra space at the end for the | ||
2260 | * HC driver's private data. Initialize the generic members of the | ||
2261 | * hcd structure. | ||
2262 | * | ||
2263 | * If memory is unavailable, returns NULL. | ||
2264 | */ | ||
2265 | struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | ||
2266 | struct device *dev, const char *bus_name) | ||
2267 | { | ||
2268 | return usb_create_shared_hcd(driver, dev, bus_name, NULL); | ||
2269 | } | ||
2165 | EXPORT_SYMBOL_GPL(usb_create_hcd); | 2270 | EXPORT_SYMBOL_GPL(usb_create_hcd); |
2166 | 2271 | ||
2272 | /* | ||
2273 | * Roothubs that share one PCI device must also share the bandwidth mutex. | ||
2274 | * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is | ||
2275 | * deallocated. | ||
2276 | * | ||
2277 | * Make sure to only deallocate the bandwidth_mutex when the primary HCD is | ||
2278 | * freed. When hcd_release() is called for the non-primary HCD, set the | ||
2279 | * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be | ||
2280 | * freed shortly). | ||
2281 | */ | ||
2167 | static void hcd_release (struct kref *kref) | 2282 | static void hcd_release (struct kref *kref) |
2168 | { | 2283 | { |
2169 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | 2284 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); |
2170 | 2285 | ||
2286 | if (usb_hcd_is_primary_hcd(hcd)) | ||
2287 | kfree(hcd->bandwidth_mutex); | ||
2288 | else | ||
2289 | hcd->shared_hcd->shared_hcd = NULL; | ||
2171 | kfree(hcd); | 2290 | kfree(hcd); |
2172 | } | 2291 | } |
2173 | 2292 | ||
@@ -2186,6 +2305,54 @@ void usb_put_hcd (struct usb_hcd *hcd) | |||
2186 | } | 2305 | } |
2187 | EXPORT_SYMBOL_GPL(usb_put_hcd); | 2306 | EXPORT_SYMBOL_GPL(usb_put_hcd); |
2188 | 2307 | ||
2308 | int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) | ||
2309 | { | ||
2310 | if (!hcd->primary_hcd) | ||
2311 | return 1; | ||
2312 | return hcd == hcd->primary_hcd; | ||
2313 | } | ||
2314 | EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd); | ||
2315 | |||
2316 | static int usb_hcd_request_irqs(struct usb_hcd *hcd, | ||
2317 | unsigned int irqnum, unsigned long irqflags) | ||
2318 | { | ||
2319 | int retval; | ||
2320 | |||
2321 | if (hcd->driver->irq) { | ||
2322 | |||
2323 | /* IRQF_DISABLED doesn't work as advertised when used together | ||
2324 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2325 | * interrupts we can remove it here. | ||
2326 | */ | ||
2327 | if (irqflags & IRQF_SHARED) | ||
2328 | irqflags &= ~IRQF_DISABLED; | ||
2329 | |||
2330 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2331 | hcd->driver->description, hcd->self.busnum); | ||
2332 | retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2333 | hcd->irq_descr, hcd); | ||
2334 | if (retval != 0) { | ||
2335 | dev_err(hcd->self.controller, | ||
2336 | "request interrupt %d failed\n", | ||
2337 | irqnum); | ||
2338 | return retval; | ||
2339 | } | ||
2340 | hcd->irq = irqnum; | ||
2341 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2342 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2343 | "io mem" : "io base", | ||
2344 | (unsigned long long)hcd->rsrc_start); | ||
2345 | } else { | ||
2346 | hcd->irq = -1; | ||
2347 | if (hcd->rsrc_start) | ||
2348 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2349 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2350 | "io mem" : "io base", | ||
2351 | (unsigned long long)hcd->rsrc_start); | ||
2352 | } | ||
2353 | return 0; | ||
2354 | } | ||
2355 | |||
2189 | /** | 2356 | /** |
2190 | * usb_add_hcd - finish generic HCD structure initialization and register | 2357 | * usb_add_hcd - finish generic HCD structure initialization and register |
2191 | * @hcd: the usb_hcd structure to initialize | 2358 | * @hcd: the usb_hcd structure to initialize |
@@ -2226,7 +2393,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2226 | } | 2393 | } |
2227 | hcd->self.root_hub = rhdev; | 2394 | hcd->self.root_hub = rhdev; |
2228 | 2395 | ||
2229 | switch (hcd->driver->flags & HCD_MASK) { | 2396 | switch (hcd->speed) { |
2230 | case HCD_USB11: | 2397 | case HCD_USB11: |
2231 | rhdev->speed = USB_SPEED_FULL; | 2398 | rhdev->speed = USB_SPEED_FULL; |
2232 | break; | 2399 | break; |
@@ -2237,6 +2404,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2237 | rhdev->speed = USB_SPEED_SUPER; | 2404 | rhdev->speed = USB_SPEED_SUPER; |
2238 | break; | 2405 | break; |
2239 | default: | 2406 | default: |
2407 | retval = -EINVAL; | ||
2240 | goto err_set_rh_speed; | 2408 | goto err_set_rh_speed; |
2241 | } | 2409 | } |
2242 | 2410 | ||
@@ -2246,6 +2414,12 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2246 | */ | 2414 | */ |
2247 | device_init_wakeup(&rhdev->dev, 1); | 2415 | device_init_wakeup(&rhdev->dev, 1); |
2248 | 2416 | ||
2417 | /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is | ||
2418 | * registered. But since the controller can die at any time, | ||
2419 | * let's initialize the flag before touching the hardware. | ||
2420 | */ | ||
2421 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2422 | |||
2249 | /* "reset" is misnamed; its role is now one-time init. the controller | 2423 | /* "reset" is misnamed; its role is now one-time init. the controller |
2250 | * should already have been reset (and boot firmware kicked off etc). | 2424 | * should already have been reset (and boot firmware kicked off etc). |
2251 | */ | 2425 | */ |
@@ -2261,38 +2435,15 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2261 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | 2435 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); |
2262 | 2436 | ||
2263 | /* enable irqs just before we start the controller */ | 2437 | /* enable irqs just before we start the controller */ |
2264 | if (hcd->driver->irq) { | 2438 | if (usb_hcd_is_primary_hcd(hcd)) { |
2265 | 2439 | retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); | |
2266 | /* IRQF_DISABLED doesn't work as advertised when used together | 2440 | if (retval) |
2267 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2268 | * interrupts we can remove it here. | ||
2269 | */ | ||
2270 | if (irqflags & IRQF_SHARED) | ||
2271 | irqflags &= ~IRQF_DISABLED; | ||
2272 | |||
2273 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2274 | hcd->driver->description, hcd->self.busnum); | ||
2275 | if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2276 | hcd->irq_descr, hcd)) != 0) { | ||
2277 | dev_err(hcd->self.controller, | ||
2278 | "request interrupt %d failed\n", irqnum); | ||
2279 | goto err_request_irq; | 2441 | goto err_request_irq; |
2280 | } | ||
2281 | hcd->irq = irqnum; | ||
2282 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2283 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2284 | "io mem" : "io base", | ||
2285 | (unsigned long long)hcd->rsrc_start); | ||
2286 | } else { | ||
2287 | hcd->irq = -1; | ||
2288 | if (hcd->rsrc_start) | ||
2289 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2290 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2291 | "io mem" : "io base", | ||
2292 | (unsigned long long)hcd->rsrc_start); | ||
2293 | } | 2442 | } |
2294 | 2443 | ||
2295 | if ((retval = hcd->driver->start(hcd)) < 0) { | 2444 | hcd->state = HC_STATE_RUNNING; |
2445 | retval = hcd->driver->start(hcd); | ||
2446 | if (retval < 0) { | ||
2296 | dev_err(hcd->self.controller, "startup error %d\n", retval); | 2447 | dev_err(hcd->self.controller, "startup error %d\n", retval); |
2297 | goto err_hcd_driver_start; | 2448 | goto err_hcd_driver_start; |
2298 | } | 2449 | } |
@@ -2313,6 +2464,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2313 | return retval; | 2464 | return retval; |
2314 | 2465 | ||
2315 | error_create_attr_group: | 2466 | error_create_attr_group: |
2467 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2316 | if (HC_IS_RUNNING(hcd->state)) | 2468 | if (HC_IS_RUNNING(hcd->state)) |
2317 | hcd->state = HC_STATE_QUIESCING; | 2469 | hcd->state = HC_STATE_QUIESCING; |
2318 | spin_lock_irq(&hcd_root_hub_lock); | 2470 | spin_lock_irq(&hcd_root_hub_lock); |
@@ -2334,7 +2486,7 @@ err_register_root_hub: | |||
2334 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2486 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2335 | del_timer_sync(&hcd->rh_timer); | 2487 | del_timer_sync(&hcd->rh_timer); |
2336 | err_hcd_driver_start: | 2488 | err_hcd_driver_start: |
2337 | if (hcd->irq >= 0) | 2489 | if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0) |
2338 | free_irq(irqnum, hcd); | 2490 | free_irq(irqnum, hcd); |
2339 | err_request_irq: | 2491 | err_request_irq: |
2340 | err_hcd_driver_setup: | 2492 | err_hcd_driver_setup: |
@@ -2365,6 +2517,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2365 | usb_get_dev(rhdev); | 2517 | usb_get_dev(rhdev); |
2366 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); | 2518 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); |
2367 | 2519 | ||
2520 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2368 | if (HC_IS_RUNNING (hcd->state)) | 2521 | if (HC_IS_RUNNING (hcd->state)) |
2369 | hcd->state = HC_STATE_QUIESCING; | 2522 | hcd->state = HC_STATE_QUIESCING; |
2370 | 2523 | ||
@@ -2397,8 +2550,10 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2397 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2550 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2398 | del_timer_sync(&hcd->rh_timer); | 2551 | del_timer_sync(&hcd->rh_timer); |
2399 | 2552 | ||
2400 | if (hcd->irq >= 0) | 2553 | if (usb_hcd_is_primary_hcd(hcd)) { |
2401 | free_irq(hcd->irq, hcd); | 2554 | if (hcd->irq >= 0) |
2555 | free_irq(hcd->irq, hcd); | ||
2556 | } | ||
2402 | 2557 | ||
2403 | usb_put_dev(hcd->self.root_hub); | 2558 | usb_put_dev(hcd->self.root_hub); |
2404 | usb_deregister_bus(&hcd->self); | 2559 | usb_deregister_bus(&hcd->self); |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 84c1897188d2..a428aa080a36 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/kthread.h> | 24 | #include <linux/kthread.h> |
25 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
26 | #include <linux/freezer.h> | 26 | #include <linux/freezer.h> |
27 | #include <linux/pm_runtime.h> | ||
28 | 27 | ||
29 | #include <asm/uaccess.h> | 28 | #include <asm/uaccess.h> |
30 | #include <asm/byteorder.h> | 29 | #include <asm/byteorder.h> |
@@ -83,6 +82,10 @@ struct usb_hub { | |||
83 | void **port_owners; | 82 | void **port_owners; |
84 | }; | 83 | }; |
85 | 84 | ||
85 | static inline int hub_is_superspeed(struct usb_device *hdev) | ||
86 | { | ||
87 | return (hdev->descriptor.bDeviceProtocol == 3); | ||
88 | } | ||
86 | 89 | ||
87 | /* Protect struct usb_device->state and ->children members | 90 | /* Protect struct usb_device->state and ->children members |
88 | * Note: Both are also protected by ->dev.sem, except that ->state can | 91 | * Note: Both are also protected by ->dev.sem, except that ->state can |
@@ -152,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); | |||
152 | 155 | ||
153 | static int usb_reset_and_verify_device(struct usb_device *udev); | 156 | static int usb_reset_and_verify_device(struct usb_device *udev); |
154 | 157 | ||
155 | static inline char *portspeed(int portstatus) | 158 | static inline char *portspeed(struct usb_hub *hub, int portstatus) |
156 | { | 159 | { |
160 | if (hub_is_superspeed(hub->hdev)) | ||
161 | return "5.0 Gb/s"; | ||
157 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 162 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
158 | return "480 Mb/s"; | 163 | return "480 Mb/s"; |
159 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 164 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
160 | return "1.5 Mb/s"; | 165 | return "1.5 Mb/s"; |
161 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | ||
162 | return "5.0 Gb/s"; | ||
163 | else | 166 | else |
164 | return "12 Mb/s"; | 167 | return "12 Mb/s"; |
165 | } | 168 | } |
@@ -173,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev) | |||
173 | } | 176 | } |
174 | 177 | ||
175 | /* USB 2.0 spec Section 11.24.4.5 */ | 178 | /* USB 2.0 spec Section 11.24.4.5 */ |
176 | static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) | 179 | static int get_hub_descriptor(struct usb_device *hdev, void *data) |
177 | { | 180 | { |
178 | int i, ret; | 181 | int i, ret, size; |
182 | unsigned dtype; | ||
183 | |||
184 | if (hub_is_superspeed(hdev)) { | ||
185 | dtype = USB_DT_SS_HUB; | ||
186 | size = USB_DT_SS_HUB_SIZE; | ||
187 | } else { | ||
188 | dtype = USB_DT_HUB; | ||
189 | size = sizeof(struct usb_hub_descriptor); | ||
190 | } | ||
179 | 191 | ||
180 | for (i = 0; i < 3; i++) { | 192 | for (i = 0; i < 3; i++) { |
181 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | 193 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), |
182 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, | 194 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, |
183 | USB_DT_HUB << 8, 0, data, size, | 195 | dtype << 8, 0, data, size, |
184 | USB_CTRL_GET_TIMEOUT); | 196 | USB_CTRL_GET_TIMEOUT); |
185 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) | 197 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) |
186 | return ret; | 198 | return ret; |
@@ -327,7 +339,8 @@ static int get_hub_status(struct usb_device *hdev, | |||
327 | { | 339 | { |
328 | int i, status = -ETIMEDOUT; | 340 | int i, status = -ETIMEDOUT; |
329 | 341 | ||
330 | for (i = 0; i < USB_STS_RETRIES && status == -ETIMEDOUT; i++) { | 342 | for (i = 0; i < USB_STS_RETRIES && |
343 | (status == -ETIMEDOUT || status == -EPIPE); i++) { | ||
331 | status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | 344 | status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), |
332 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, | 345 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, |
333 | data, sizeof(*data), USB_STS_TIMEOUT); | 346 | data, sizeof(*data), USB_STS_TIMEOUT); |
@@ -343,7 +356,8 @@ static int get_port_status(struct usb_device *hdev, int port1, | |||
343 | { | 356 | { |
344 | int i, status = -ETIMEDOUT; | 357 | int i, status = -ETIMEDOUT; |
345 | 358 | ||
346 | for (i = 0; i < USB_STS_RETRIES && status == -ETIMEDOUT; i++) { | 359 | for (i = 0; i < USB_STS_RETRIES && |
360 | (status == -ETIMEDOUT || status == -EPIPE); i++) { | ||
347 | status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | 361 | status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), |
348 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port1, | 362 | USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port1, |
349 | data, sizeof(*data), USB_STS_TIMEOUT); | 363 | data, sizeof(*data), USB_STS_TIMEOUT); |
@@ -366,6 +380,7 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
366 | } else { | 380 | } else { |
367 | *status = le16_to_cpu(hub->status->port.wPortStatus); | 381 | *status = le16_to_cpu(hub->status->port.wPortStatus); |
368 | *change = le16_to_cpu(hub->status->port.wPortChange); | 382 | *change = le16_to_cpu(hub->status->port.wPortChange); |
383 | |||
369 | ret = 0; | 384 | ret = 0; |
370 | } | 385 | } |
371 | mutex_unlock(&hub->status_mutex); | 386 | mutex_unlock(&hub->status_mutex); |
@@ -608,7 +623,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
608 | if (hdev->children[port1-1] && set_state) | 623 | if (hdev->children[port1-1] && set_state) |
609 | usb_set_device_state(hdev->children[port1-1], | 624 | usb_set_device_state(hdev->children[port1-1], |
610 | USB_STATE_NOTATTACHED); | 625 | USB_STATE_NOTATTACHED); |
611 | if (!hub->error) | 626 | if (!hub->error && !hub_is_superspeed(hub->hdev)) |
612 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); | 627 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); |
613 | if (ret) | 628 | if (ret) |
614 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", | 629 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", |
@@ -617,7 +632,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
617 | } | 632 | } |
618 | 633 | ||
619 | /* | 634 | /* |
620 | * Disable a port and mark a logical connnect-change event, so that some | 635 | * Disable a port and mark a logical connect-change event, so that some |
621 | * time later khubd will disconnect() any existing usb_device on the port | 636 | * time later khubd will disconnect() any existing usb_device on the port |
622 | * and will re-enumerate if there actually is a device attached. | 637 | * and will re-enumerate if there actually is a device attached. |
623 | */ | 638 | */ |
@@ -677,6 +692,8 @@ static void hub_init_func3(struct work_struct *ws); | |||
677 | static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | 692 | static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) |
678 | { | 693 | { |
679 | struct usb_device *hdev = hub->hdev; | 694 | struct usb_device *hdev = hub->hdev; |
695 | struct usb_hcd *hcd; | ||
696 | int ret; | ||
680 | int port1; | 697 | int port1; |
681 | int status; | 698 | int status; |
682 | bool need_debounce_delay = false; | 699 | bool need_debounce_delay = false; |
@@ -715,6 +732,25 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
715 | usb_autopm_get_interface_no_resume( | 732 | usb_autopm_get_interface_no_resume( |
716 | to_usb_interface(hub->intfdev)); | 733 | to_usb_interface(hub->intfdev)); |
717 | return; /* Continues at init2: below */ | 734 | return; /* Continues at init2: below */ |
735 | } else if (type == HUB_RESET_RESUME) { | ||
736 | /* The internal host controller state for the hub device | ||
737 | * may be gone after a host power loss on system resume. | ||
738 | * Update the device's info so the HW knows it's a hub. | ||
739 | */ | ||
740 | hcd = bus_to_hcd(hdev->bus); | ||
741 | if (hcd->driver->update_hub_device) { | ||
742 | ret = hcd->driver->update_hub_device(hcd, hdev, | ||
743 | &hub->tt, GFP_NOIO); | ||
744 | if (ret < 0) { | ||
745 | dev_err(hub->intfdev, "Host not " | ||
746 | "accepting hub info " | ||
747 | "update.\n"); | ||
748 | dev_err(hub->intfdev, "LS/FS devices " | ||
749 | "and hubs may not work " | ||
750 | "under this hub\n."); | ||
751 | } | ||
752 | } | ||
753 | hub_power_on(hub, true); | ||
718 | } else { | 754 | } else { |
719 | hub_power_on(hub, true); | 755 | hub_power_on(hub, true); |
720 | } | 756 | } |
@@ -749,15 +785,14 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
749 | * USB3 protocol ports will automatically transition | 785 | * USB3 protocol ports will automatically transition |
750 | * to Enabled state when detect an USB3.0 device attach. | 786 | * to Enabled state when detect an USB3.0 device attach. |
751 | * Do not disable USB3 protocol ports. | 787 | * Do not disable USB3 protocol ports. |
752 | * FIXME: USB3 root hub and external hubs are treated | ||
753 | * differently here. | ||
754 | */ | 788 | */ |
755 | if (hdev->descriptor.bDeviceProtocol != 3 || | 789 | if (!hub_is_superspeed(hdev)) { |
756 | (!hdev->parent && | ||
757 | !(portstatus & USB_PORT_STAT_SUPER_SPEED))) { | ||
758 | clear_port_feature(hdev, port1, | 790 | clear_port_feature(hdev, port1, |
759 | USB_PORT_FEAT_ENABLE); | 791 | USB_PORT_FEAT_ENABLE); |
760 | portstatus &= ~USB_PORT_STAT_ENABLE; | 792 | portstatus &= ~USB_PORT_STAT_ENABLE; |
793 | } else { | ||
794 | /* Pretend that power was lost for USB3 devs */ | ||
795 | portstatus &= ~USB_PORT_STAT_ENABLE; | ||
761 | } | 796 | } |
762 | } | 797 | } |
763 | 798 | ||
@@ -772,6 +807,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
772 | clear_port_feature(hub->hdev, port1, | 807 | clear_port_feature(hub->hdev, port1, |
773 | USB_PORT_FEAT_C_ENABLE); | 808 | USB_PORT_FEAT_C_ENABLE); |
774 | } | 809 | } |
810 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
811 | need_debounce_delay = true; | ||
812 | clear_port_feature(hub->hdev, port1, | ||
813 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
814 | } | ||
775 | 815 | ||
776 | /* We can forget about a "removed" device when there's a | 816 | /* We can forget about a "removed" device when there's a |
777 | * physical disconnect or the connect status changes. | 817 | * physical disconnect or the connect status changes. |
@@ -941,12 +981,23 @@ static int hub_configure(struct usb_hub *hub, | |||
941 | goto fail; | 981 | goto fail; |
942 | } | 982 | } |
943 | 983 | ||
984 | if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) { | ||
985 | ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), | ||
986 | HUB_SET_DEPTH, USB_RT_HUB, | ||
987 | hdev->level - 1, 0, NULL, 0, | ||
988 | USB_CTRL_SET_TIMEOUT); | ||
989 | |||
990 | if (ret < 0) { | ||
991 | message = "can't set hub depth"; | ||
992 | goto fail; | ||
993 | } | ||
994 | } | ||
995 | |||
944 | /* Request the entire hub descriptor. | 996 | /* Request the entire hub descriptor. |
945 | * hub->descriptor can handle USB_MAXCHILDREN ports, | 997 | * hub->descriptor can handle USB_MAXCHILDREN ports, |
946 | * but the hub can/will return fewer bytes here. | 998 | * but the hub can/will return fewer bytes here. |
947 | */ | 999 | */ |
948 | ret = get_hub_descriptor(hdev, hub->descriptor, | 1000 | ret = get_hub_descriptor(hdev, hub->descriptor); |
949 | sizeof(*hub->descriptor)); | ||
950 | if (ret < 0) { | 1001 | if (ret < 0) { |
951 | message = "can't read hub descriptor"; | 1002 | message = "can't read hub descriptor"; |
952 | goto fail; | 1003 | goto fail; |
@@ -968,12 +1019,14 @@ static int hub_configure(struct usb_hub *hub, | |||
968 | 1019 | ||
969 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); | 1020 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); |
970 | 1021 | ||
971 | if (wHubCharacteristics & HUB_CHAR_COMPOUND) { | 1022 | /* FIXME for USB 3.0, skip for now */ |
1023 | if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && | ||
1024 | !(hub_is_superspeed(hdev))) { | ||
972 | int i; | 1025 | int i; |
973 | char portstr [USB_MAXCHILDREN + 1]; | 1026 | char portstr [USB_MAXCHILDREN + 1]; |
974 | 1027 | ||
975 | for (i = 0; i < hdev->maxchild; i++) | 1028 | for (i = 0; i < hdev->maxchild; i++) |
976 | portstr[i] = hub->descriptor->DeviceRemovable | 1029 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable |
977 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) | 1030 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) |
978 | ? 'F' : 'R'; | 1031 | ? 'F' : 'R'; |
979 | portstr[hdev->maxchild] = 0; | 1032 | portstr[hdev->maxchild] = 0; |
@@ -1230,8 +1283,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1230 | desc = intf->cur_altsetting; | 1283 | desc = intf->cur_altsetting; |
1231 | hdev = interface_to_usbdev(intf); | 1284 | hdev = interface_to_usbdev(intf); |
1232 | 1285 | ||
1233 | /* Hubs have proper suspend/resume support */ | 1286 | /* Hubs have proper suspend/resume support. USB 3.0 device suspend is |
1234 | usb_enable_autosuspend(hdev); | 1287 | * different from USB 2.0/1.1 device suspend, and unfortunately we |
1288 | * don't support it yet. So leave autosuspend disabled for USB 3.0 | ||
1289 | * external hubs for now. Enable autosuspend for USB 3.0 roothubs, | ||
1290 | * since that isn't a "real" hub. | ||
1291 | */ | ||
1292 | if (!hub_is_superspeed(hdev) || !hdev->parent) | ||
1293 | usb_enable_autosuspend(hdev); | ||
1235 | 1294 | ||
1236 | if (hdev->level == MAX_TOPO_LEVEL) { | 1295 | if (hdev->level == MAX_TOPO_LEVEL) { |
1237 | dev_err(&intf->dev, | 1296 | dev_err(&intf->dev, |
@@ -1442,6 +1501,7 @@ void usb_set_device_state(struct usb_device *udev, | |||
1442 | enum usb_device_state new_state) | 1501 | enum usb_device_state new_state) |
1443 | { | 1502 | { |
1444 | unsigned long flags; | 1503 | unsigned long flags; |
1504 | int wakeup = -1; | ||
1445 | 1505 | ||
1446 | spin_lock_irqsave(&device_state_lock, flags); | 1506 | spin_lock_irqsave(&device_state_lock, flags); |
1447 | if (udev->state == USB_STATE_NOTATTACHED) | 1507 | if (udev->state == USB_STATE_NOTATTACHED) |
@@ -1456,11 +1516,10 @@ void usb_set_device_state(struct usb_device *udev, | |||
1456 | || new_state == USB_STATE_SUSPENDED) | 1516 | || new_state == USB_STATE_SUSPENDED) |
1457 | ; /* No change to wakeup settings */ | 1517 | ; /* No change to wakeup settings */ |
1458 | else if (new_state == USB_STATE_CONFIGURED) | 1518 | else if (new_state == USB_STATE_CONFIGURED) |
1459 | device_set_wakeup_capable(&udev->dev, | 1519 | wakeup = udev->actconfig->desc.bmAttributes |
1460 | (udev->actconfig->desc.bmAttributes | 1520 | & USB_CONFIG_ATT_WAKEUP; |
1461 | & USB_CONFIG_ATT_WAKEUP)); | ||
1462 | else | 1521 | else |
1463 | device_set_wakeup_capable(&udev->dev, 0); | 1522 | wakeup = 0; |
1464 | } | 1523 | } |
1465 | if (udev->state == USB_STATE_SUSPENDED && | 1524 | if (udev->state == USB_STATE_SUSPENDED && |
1466 | new_state != USB_STATE_SUSPENDED) | 1525 | new_state != USB_STATE_SUSPENDED) |
@@ -1472,10 +1531,19 @@ void usb_set_device_state(struct usb_device *udev, | |||
1472 | } else | 1531 | } else |
1473 | recursively_mark_NOTATTACHED(udev); | 1532 | recursively_mark_NOTATTACHED(udev); |
1474 | spin_unlock_irqrestore(&device_state_lock, flags); | 1533 | spin_unlock_irqrestore(&device_state_lock, flags); |
1534 | if (wakeup >= 0) | ||
1535 | device_set_wakeup_capable(&udev->dev, wakeup); | ||
1475 | } | 1536 | } |
1476 | EXPORT_SYMBOL_GPL(usb_set_device_state); | 1537 | EXPORT_SYMBOL_GPL(usb_set_device_state); |
1477 | 1538 | ||
1478 | /* | 1539 | /* |
1540 | * Choose a device number. | ||
1541 | * | ||
1542 | * Device numbers are used as filenames in usbfs. On USB-1.1 and | ||
1543 | * USB-2.0 buses they are also used as device addresses, however on | ||
1544 | * USB-3.0 buses the address is assigned by the controller hardware | ||
1545 | * and it usually is not the same as the device number. | ||
1546 | * | ||
1479 | * WUSB devices are simple: they have no hubs behind, so the mapping | 1547 | * WUSB devices are simple: they have no hubs behind, so the mapping |
1480 | * device <-> virtual port number becomes 1:1. Why? to simplify the | 1548 | * device <-> virtual port number becomes 1:1. Why? to simplify the |
1481 | * life of the device connection logic in | 1549 | * life of the device connection logic in |
@@ -1497,7 +1565,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state); | |||
1497 | * the HCD must setup data structures before issuing a set address | 1565 | * the HCD must setup data structures before issuing a set address |
1498 | * command to the hardware. | 1566 | * command to the hardware. |
1499 | */ | 1567 | */ |
1500 | static void choose_address(struct usb_device *udev) | 1568 | static void choose_devnum(struct usb_device *udev) |
1501 | { | 1569 | { |
1502 | int devnum; | 1570 | int devnum; |
1503 | struct usb_bus *bus = udev->bus; | 1571 | struct usb_bus *bus = udev->bus; |
@@ -1522,7 +1590,7 @@ static void choose_address(struct usb_device *udev) | |||
1522 | } | 1590 | } |
1523 | } | 1591 | } |
1524 | 1592 | ||
1525 | static void release_address(struct usb_device *udev) | 1593 | static void release_devnum(struct usb_device *udev) |
1526 | { | 1594 | { |
1527 | if (udev->devnum > 0) { | 1595 | if (udev->devnum > 0) { |
1528 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); | 1596 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); |
@@ -1530,7 +1598,7 @@ static void release_address(struct usb_device *udev) | |||
1530 | } | 1598 | } |
1531 | } | 1599 | } |
1532 | 1600 | ||
1533 | static void update_address(struct usb_device *udev, int devnum) | 1601 | static void update_devnum(struct usb_device *udev, int devnum) |
1534 | { | 1602 | { |
1535 | /* The address for a WUSB device is managed by wusbcore. */ | 1603 | /* The address for a WUSB device is managed by wusbcore. */ |
1536 | if (!udev->wusb) | 1604 | if (!udev->wusb) |
@@ -1566,6 +1634,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
1566 | { | 1634 | { |
1567 | struct usb_device *udev = *pdev; | 1635 | struct usb_device *udev = *pdev; |
1568 | int i; | 1636 | int i; |
1637 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1569 | 1638 | ||
1570 | if (!udev) { | 1639 | if (!udev) { |
1571 | pr_debug ("%s nodev\n", __func__); | 1640 | pr_debug ("%s nodev\n", __func__); |
@@ -1574,10 +1643,11 @@ void usb_disconnect(struct usb_device **pdev) | |||
1574 | 1643 | ||
1575 | /* mark the device as inactive, so any further urb submissions for | 1644 | /* mark the device as inactive, so any further urb submissions for |
1576 | * this device (and any of its children) will fail immediately. | 1645 | * this device (and any of its children) will fail immediately. |
1577 | * this quiesces everyting except pending urbs. | 1646 | * this quiesces everything except pending urbs. |
1578 | */ | 1647 | */ |
1579 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1648 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1580 | dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); | 1649 | dev_info(&udev->dev, "USB disconnect, device number %d\n", |
1650 | udev->devnum); | ||
1581 | 1651 | ||
1582 | usb_lock_device(udev); | 1652 | usb_lock_device(udev); |
1583 | 1653 | ||
@@ -1592,7 +1662,9 @@ void usb_disconnect(struct usb_device **pdev) | |||
1592 | * so that the hardware is now fully quiesced. | 1662 | * so that the hardware is now fully quiesced. |
1593 | */ | 1663 | */ |
1594 | dev_dbg (&udev->dev, "unregistering device\n"); | 1664 | dev_dbg (&udev->dev, "unregistering device\n"); |
1665 | mutex_lock(hcd->bandwidth_mutex); | ||
1595 | usb_disable_device(udev, 0); | 1666 | usb_disable_device(udev, 0); |
1667 | mutex_unlock(hcd->bandwidth_mutex); | ||
1596 | usb_hcd_synchronize_unlinks(udev); | 1668 | usb_hcd_synchronize_unlinks(udev); |
1597 | 1669 | ||
1598 | usb_remove_ep_devs(&udev->ep0); | 1670 | usb_remove_ep_devs(&udev->ep0); |
@@ -1607,7 +1679,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
1607 | /* Free the device number and delete the parent's children[] | 1679 | /* Free the device number and delete the parent's children[] |
1608 | * (or root_hub) pointer. | 1680 | * (or root_hub) pointer. |
1609 | */ | 1681 | */ |
1610 | release_address(udev); | 1682 | release_devnum(udev); |
1611 | 1683 | ||
1612 | /* Avoid races with recursively_mark_NOTATTACHED() */ | 1684 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1613 | spin_lock_irq(&device_state_lock); | 1685 | spin_lock_irq(&device_state_lock); |
@@ -1801,8 +1873,15 @@ int usb_new_device(struct usb_device *udev) | |||
1801 | 1873 | ||
1802 | /* Tell the runtime-PM framework the device is active */ | 1874 | /* Tell the runtime-PM framework the device is active */ |
1803 | pm_runtime_set_active(&udev->dev); | 1875 | pm_runtime_set_active(&udev->dev); |
1876 | pm_runtime_get_noresume(&udev->dev); | ||
1877 | pm_runtime_use_autosuspend(&udev->dev); | ||
1804 | pm_runtime_enable(&udev->dev); | 1878 | pm_runtime_enable(&udev->dev); |
1805 | 1879 | ||
1880 | /* By default, forbid autosuspend for all devices. It will be | ||
1881 | * allowed for hubs during binding. | ||
1882 | */ | ||
1883 | usb_disable_autosuspend(udev); | ||
1884 | |||
1806 | err = usb_enumerate_device(udev); /* Read descriptors */ | 1885 | err = usb_enumerate_device(udev); /* Read descriptors */ |
1807 | if (err < 0) | 1886 | if (err < 0) |
1808 | goto fail; | 1887 | goto fail; |
@@ -1828,6 +1907,8 @@ int usb_new_device(struct usb_device *udev) | |||
1828 | } | 1907 | } |
1829 | 1908 | ||
1830 | (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); | 1909 | (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); |
1910 | usb_mark_last_busy(udev); | ||
1911 | pm_runtime_put_sync_autosuspend(&udev->dev); | ||
1831 | return err; | 1912 | return err; |
1832 | 1913 | ||
1833 | fail: | 1914 | fail: |
@@ -1983,7 +2064,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
1983 | (portstatus & USB_PORT_STAT_ENABLE)) { | 2064 | (portstatus & USB_PORT_STAT_ENABLE)) { |
1984 | if (hub_is_wusb(hub)) | 2065 | if (hub_is_wusb(hub)) |
1985 | udev->speed = USB_SPEED_WIRELESS; | 2066 | udev->speed = USB_SPEED_WIRELESS; |
1986 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | 2067 | else if (hub_is_superspeed(hub->hdev)) |
1987 | udev->speed = USB_SPEED_SUPER; | 2068 | udev->speed = USB_SPEED_SUPER; |
1988 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 2069 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
1989 | udev->speed = USB_SPEED_HIGH; | 2070 | udev->speed = USB_SPEED_HIGH; |
@@ -2039,7 +2120,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2039 | case 0: | 2120 | case 0: |
2040 | /* TRSTRCY = 10 ms; plus some extra */ | 2121 | /* TRSTRCY = 10 ms; plus some extra */ |
2041 | msleep(10 + 40); | 2122 | msleep(10 + 40); |
2042 | update_address(udev, 0); | 2123 | update_devnum(udev, 0); |
2043 | if (hcd->driver->reset_device) { | 2124 | if (hcd->driver->reset_device) { |
2044 | status = hcd->driver->reset_device(hcd, udev); | 2125 | status = hcd->driver->reset_device(hcd, udev); |
2045 | if (status < 0) { | 2126 | if (status < 0) { |
@@ -2075,11 +2156,76 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2075 | return status; | 2156 | return status; |
2076 | } | 2157 | } |
2077 | 2158 | ||
2159 | /* Warm reset a USB3 protocol port */ | ||
2160 | static int hub_port_warm_reset(struct usb_hub *hub, int port) | ||
2161 | { | ||
2162 | int ret; | ||
2163 | u16 portstatus, portchange; | ||
2164 | |||
2165 | if (!hub_is_superspeed(hub->hdev)) { | ||
2166 | dev_err(hub->intfdev, "only USB3 hub support warm reset\n"); | ||
2167 | return -EINVAL; | ||
2168 | } | ||
2169 | |||
2170 | /* Warm reset the port */ | ||
2171 | ret = set_port_feature(hub->hdev, | ||
2172 | port, USB_PORT_FEAT_BH_PORT_RESET); | ||
2173 | if (ret) { | ||
2174 | dev_err(hub->intfdev, "cannot warm reset port %d\n", port); | ||
2175 | return ret; | ||
2176 | } | ||
2177 | |||
2178 | msleep(20); | ||
2179 | ret = hub_port_status(hub, port, &portstatus, &portchange); | ||
2180 | |||
2181 | if (portchange & USB_PORT_STAT_C_RESET) | ||
2182 | clear_port_feature(hub->hdev, port, USB_PORT_FEAT_C_RESET); | ||
2183 | |||
2184 | if (portchange & USB_PORT_STAT_C_BH_RESET) | ||
2185 | clear_port_feature(hub->hdev, port, | ||
2186 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
2187 | |||
2188 | if (portchange & USB_PORT_STAT_C_LINK_STATE) | ||
2189 | clear_port_feature(hub->hdev, port, | ||
2190 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
2191 | |||
2192 | return ret; | ||
2193 | } | ||
2194 | |||
2195 | /* Check if a port is power on */ | ||
2196 | static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) | ||
2197 | { | ||
2198 | int ret = 0; | ||
2199 | |||
2200 | if (hub_is_superspeed(hub->hdev)) { | ||
2201 | if (portstatus & USB_SS_PORT_STAT_POWER) | ||
2202 | ret = 1; | ||
2203 | } else { | ||
2204 | if (portstatus & USB_PORT_STAT_POWER) | ||
2205 | ret = 1; | ||
2206 | } | ||
2207 | |||
2208 | return ret; | ||
2209 | } | ||
2210 | |||
2078 | #ifdef CONFIG_PM | 2211 | #ifdef CONFIG_PM |
2079 | 2212 | ||
2080 | #define MASK_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION | \ | 2213 | /* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */ |
2081 | USB_PORT_STAT_SUSPEND) | 2214 | static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) |
2082 | #define WANT_BITS (USB_PORT_STAT_POWER | USB_PORT_STAT_CONNECTION) | 2215 | { |
2216 | int ret = 0; | ||
2217 | |||
2218 | if (hub_is_superspeed(hub->hdev)) { | ||
2219 | if ((portstatus & USB_PORT_STAT_LINK_STATE) | ||
2220 | == USB_SS_PORT_LS_U3) | ||
2221 | ret = 1; | ||
2222 | } else { | ||
2223 | if (portstatus & USB_PORT_STAT_SUSPEND) | ||
2224 | ret = 1; | ||
2225 | } | ||
2226 | |||
2227 | return ret; | ||
2228 | } | ||
2083 | 2229 | ||
2084 | /* Determine whether the device on a port is ready for a normal resume, | 2230 | /* Determine whether the device on a port is ready for a normal resume, |
2085 | * is ready for a reset-resume, or should be disconnected. | 2231 | * is ready for a reset-resume, or should be disconnected. |
@@ -2089,7 +2235,9 @@ static int check_port_resume_type(struct usb_device *udev, | |||
2089 | int status, unsigned portchange, unsigned portstatus) | 2235 | int status, unsigned portchange, unsigned portstatus) |
2090 | { | 2236 | { |
2091 | /* Is the device still present? */ | 2237 | /* Is the device still present? */ |
2092 | if (status || (portstatus & MASK_BITS) != WANT_BITS) { | 2238 | if (status || port_is_suspended(hub, portstatus) || |
2239 | !port_is_power_on(hub, portstatus) || | ||
2240 | !(portstatus & USB_PORT_STAT_CONNECTION)) { | ||
2093 | if (status >= 0) | 2241 | if (status >= 0) |
2094 | status = -ENODEV; | 2242 | status = -ENODEV; |
2095 | } | 2243 | } |
@@ -2200,7 +2348,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2200 | } | 2348 | } |
2201 | 2349 | ||
2202 | /* see 7.1.7.6 */ | 2350 | /* see 7.1.7.6 */ |
2203 | status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); | 2351 | if (hub_is_superspeed(hub->hdev)) |
2352 | status = set_port_feature(hub->hdev, | ||
2353 | port1 | (USB_SS_PORT_LS_U3 << 3), | ||
2354 | USB_PORT_FEAT_LINK_STATE); | ||
2355 | else | ||
2356 | status = set_port_feature(hub->hdev, port1, | ||
2357 | USB_PORT_FEAT_SUSPEND); | ||
2204 | if (status) { | 2358 | if (status) { |
2205 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", | 2359 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", |
2206 | port1, status); | 2360 | port1, status); |
@@ -2211,6 +2365,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2211 | USB_DEVICE_REMOTE_WAKEUP, 0, | 2365 | USB_DEVICE_REMOTE_WAKEUP, 0, |
2212 | NULL, 0, | 2366 | NULL, 0, |
2213 | USB_CTRL_SET_TIMEOUT); | 2367 | USB_CTRL_SET_TIMEOUT); |
2368 | |||
2369 | /* System sleep transitions should never fail */ | ||
2370 | if (!(msg.event & PM_EVENT_AUTO)) | ||
2371 | status = 0; | ||
2214 | } else { | 2372 | } else { |
2215 | /* device has up to 10 msec to fully suspend */ | 2373 | /* device has up to 10 msec to fully suspend */ |
2216 | dev_dbg(&udev->dev, "usb %ssuspend\n", | 2374 | dev_dbg(&udev->dev, "usb %ssuspend\n", |
@@ -2218,6 +2376,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2218 | usb_set_device_state(udev, USB_STATE_SUSPENDED); | 2376 | usb_set_device_state(udev, USB_STATE_SUSPENDED); |
2219 | msleep(10); | 2377 | msleep(10); |
2220 | } | 2378 | } |
2379 | usb_mark_last_busy(hub->hdev); | ||
2221 | return status; | 2380 | return status; |
2222 | } | 2381 | } |
2223 | 2382 | ||
@@ -2343,7 +2502,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
2343 | 2502 | ||
2344 | /* Skip the initial Clear-Suspend step for a remote wakeup */ | 2503 | /* Skip the initial Clear-Suspend step for a remote wakeup */ |
2345 | status = hub_port_status(hub, port1, &portstatus, &portchange); | 2504 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
2346 | if (status == 0 && !(portstatus & USB_PORT_STAT_SUSPEND)) | 2505 | if (status == 0 && !port_is_suspended(hub, portstatus)) |
2347 | goto SuspendCleared; | 2506 | goto SuspendCleared; |
2348 | 2507 | ||
2349 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); | 2508 | // dev_dbg(hub->intfdev, "resume port %d\n", port1); |
@@ -2351,8 +2510,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
2351 | set_bit(port1, hub->busy_bits); | 2510 | set_bit(port1, hub->busy_bits); |
2352 | 2511 | ||
2353 | /* see 7.1.7.7; affects power usage, but not budgeting */ | 2512 | /* see 7.1.7.7; affects power usage, but not budgeting */ |
2354 | status = clear_port_feature(hub->hdev, | 2513 | if (hub_is_superspeed(hub->hdev)) |
2355 | port1, USB_PORT_FEAT_SUSPEND); | 2514 | status = set_port_feature(hub->hdev, |
2515 | port1 | (USB_SS_PORT_LS_U0 << 3), | ||
2516 | USB_PORT_FEAT_LINK_STATE); | ||
2517 | else | ||
2518 | status = clear_port_feature(hub->hdev, | ||
2519 | port1, USB_PORT_FEAT_SUSPEND); | ||
2356 | if (status) { | 2520 | if (status) { |
2357 | dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", | 2521 | dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", |
2358 | port1, status); | 2522 | port1, status); |
@@ -2374,9 +2538,15 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
2374 | 2538 | ||
2375 | SuspendCleared: | 2539 | SuspendCleared: |
2376 | if (status == 0) { | 2540 | if (status == 0) { |
2377 | if (portchange & USB_PORT_STAT_C_SUSPEND) | 2541 | if (hub_is_superspeed(hub->hdev)) { |
2378 | clear_port_feature(hub->hdev, port1, | 2542 | if (portchange & USB_PORT_STAT_C_LINK_STATE) |
2379 | USB_PORT_FEAT_C_SUSPEND); | 2543 | clear_port_feature(hub->hdev, port1, |
2544 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
2545 | } else { | ||
2546 | if (portchange & USB_PORT_STAT_C_SUSPEND) | ||
2547 | clear_port_feature(hub->hdev, port1, | ||
2548 | USB_PORT_FEAT_C_SUSPEND); | ||
2549 | } | ||
2380 | } | 2550 | } |
2381 | 2551 | ||
2382 | clear_bit(port1, hub->busy_bits); | 2552 | clear_bit(port1, hub->busy_bits); |
@@ -2448,16 +2618,15 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
2448 | struct usb_device *hdev = hub->hdev; | 2618 | struct usb_device *hdev = hub->hdev; |
2449 | unsigned port1; | 2619 | unsigned port1; |
2450 | 2620 | ||
2451 | /* fail if children aren't already suspended */ | 2621 | /* Warn if children aren't already suspended */ |
2452 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { | 2622 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { |
2453 | struct usb_device *udev; | 2623 | struct usb_device *udev; |
2454 | 2624 | ||
2455 | udev = hdev->children [port1-1]; | 2625 | udev = hdev->children [port1-1]; |
2456 | if (udev && udev->can_submit) { | 2626 | if (udev && udev->can_submit) { |
2457 | if (!(msg.event & PM_EVENT_AUTO)) | 2627 | dev_warn(&intf->dev, "port %d nyet suspended\n", port1); |
2458 | dev_dbg(&intf->dev, "port %d nyet suspended\n", | 2628 | if (msg.event & PM_EVENT_AUTO) |
2459 | port1); | 2629 | return -EBUSY; |
2460 | return -EBUSY; | ||
2461 | } | 2630 | } |
2462 | } | 2631 | } |
2463 | 2632 | ||
@@ -2594,16 +2763,14 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
2594 | return 0; | 2763 | return 0; |
2595 | if (udev->state != USB_STATE_DEFAULT) | 2764 | if (udev->state != USB_STATE_DEFAULT) |
2596 | return -EINVAL; | 2765 | return -EINVAL; |
2597 | if (hcd->driver->address_device) { | 2766 | if (hcd->driver->address_device) |
2598 | retval = hcd->driver->address_device(hcd, udev); | 2767 | retval = hcd->driver->address_device(hcd, udev); |
2599 | } else { | 2768 | else |
2600 | retval = usb_control_msg(udev, usb_sndaddr0pipe(), | 2769 | retval = usb_control_msg(udev, usb_sndaddr0pipe(), |
2601 | USB_REQ_SET_ADDRESS, 0, devnum, 0, | 2770 | USB_REQ_SET_ADDRESS, 0, devnum, 0, |
2602 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 2771 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
2603 | if (retval == 0) | ||
2604 | update_address(udev, devnum); | ||
2605 | } | ||
2606 | if (retval == 0) { | 2772 | if (retval == 0) { |
2773 | update_devnum(udev, devnum); | ||
2607 | /* Device now using proper address. */ | 2774 | /* Device now using proper address. */ |
2608 | usb_set_device_state(udev, USB_STATE_ADDRESS); | 2775 | usb_set_device_state(udev, USB_STATE_ADDRESS); |
2609 | usb_ep0_reinit(udev); | 2776 | usb_ep0_reinit(udev); |
@@ -2650,17 +2817,13 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2650 | 2817 | ||
2651 | mutex_lock(&usb_address0_mutex); | 2818 | mutex_lock(&usb_address0_mutex); |
2652 | 2819 | ||
2653 | if (!udev->config && oldspeed == USB_SPEED_SUPER) { | 2820 | /* Reset the device; full speed may morph to high speed */ |
2654 | /* Don't reset USB 3.0 devices during an initial setup */ | 2821 | /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ |
2655 | usb_set_device_state(udev, USB_STATE_DEFAULT); | 2822 | retval = hub_port_reset(hub, port1, udev, delay); |
2656 | } else { | 2823 | if (retval < 0) /* error or disconnect */ |
2657 | /* Reset the device; full speed may morph to high speed */ | 2824 | goto fail; |
2658 | /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ | 2825 | /* success, speed is known */ |
2659 | retval = hub_port_reset(hub, port1, udev, delay); | 2826 | |
2660 | if (retval < 0) /* error or disconnect */ | ||
2661 | goto fail; | ||
2662 | /* success, speed is known */ | ||
2663 | } | ||
2664 | retval = -ENODEV; | 2827 | retval = -ENODEV; |
2665 | 2828 | ||
2666 | if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) { | 2829 | if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) { |
@@ -2712,9 +2875,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2712 | } | 2875 | } |
2713 | if (udev->speed != USB_SPEED_SUPER) | 2876 | if (udev->speed != USB_SPEED_SUPER) |
2714 | dev_info(&udev->dev, | 2877 | dev_info(&udev->dev, |
2715 | "%s %s speed %sUSB device using %s and address %d\n", | 2878 | "%s %s speed %sUSB device number %d using %s\n", |
2716 | (udev->config) ? "reset" : "new", speed, type, | 2879 | (udev->config) ? "reset" : "new", speed, type, |
2717 | udev->bus->controller->driver->name, devnum); | 2880 | devnum, udev->bus->controller->driver->name); |
2718 | 2881 | ||
2719 | /* Set up TT records, if needed */ | 2882 | /* Set up TT records, if needed */ |
2720 | if (hdev->tt) { | 2883 | if (hdev->tt) { |
@@ -2722,6 +2885,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2722 | udev->ttport = hdev->ttport; | 2885 | udev->ttport = hdev->ttport; |
2723 | } else if (udev->speed != USB_SPEED_HIGH | 2886 | } else if (udev->speed != USB_SPEED_HIGH |
2724 | && hdev->speed == USB_SPEED_HIGH) { | 2887 | && hdev->speed == USB_SPEED_HIGH) { |
2888 | if (!hub->tt.hub) { | ||
2889 | dev_err(&udev->dev, "parent hub has no TT\n"); | ||
2890 | retval = -EINVAL; | ||
2891 | goto fail; | ||
2892 | } | ||
2725 | udev->tt = &hub->tt; | 2893 | udev->tt = &hub->tt; |
2726 | udev->ttport = port1; | 2894 | udev->ttport = port1; |
2727 | } | 2895 | } |
@@ -2739,10 +2907,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2739 | * value. | 2907 | * value. |
2740 | */ | 2908 | */ |
2741 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { | 2909 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { |
2742 | /* | ||
2743 | * An xHCI controller cannot send any packets to a device until | ||
2744 | * a set address command successfully completes. | ||
2745 | */ | ||
2746 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { | 2910 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { |
2747 | struct usb_device_descriptor *buf; | 2911 | struct usb_device_descriptor *buf; |
2748 | int r = 0; | 2912 | int r = 0; |
@@ -2825,9 +2989,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2825 | if (udev->speed == USB_SPEED_SUPER) { | 2989 | if (udev->speed == USB_SPEED_SUPER) { |
2826 | devnum = udev->devnum; | 2990 | devnum = udev->devnum; |
2827 | dev_info(&udev->dev, | 2991 | dev_info(&udev->dev, |
2828 | "%s SuperSpeed USB device using %s and address %d\n", | 2992 | "%s SuperSpeed USB device number %d using %s\n", |
2829 | (udev->config) ? "reset" : "new", | 2993 | (udev->config) ? "reset" : "new", |
2830 | udev->bus->controller->driver->name, devnum); | 2994 | devnum, udev->bus->controller->driver->name); |
2831 | } | 2995 | } |
2832 | 2996 | ||
2833 | /* cope with hardware quirkiness: | 2997 | /* cope with hardware quirkiness: |
@@ -2860,13 +3024,16 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2860 | else | 3024 | else |
2861 | i = udev->descriptor.bMaxPacketSize0; | 3025 | i = udev->descriptor.bMaxPacketSize0; |
2862 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { | 3026 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { |
2863 | if (udev->speed != USB_SPEED_FULL || | 3027 | if (udev->speed == USB_SPEED_LOW || |
2864 | !(i == 8 || i == 16 || i == 32 || i == 64)) { | 3028 | !(i == 8 || i == 16 || i == 32 || i == 64)) { |
2865 | dev_err(&udev->dev, "ep0 maxpacket = %d\n", i); | 3029 | dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); |
2866 | retval = -EMSGSIZE; | 3030 | retval = -EMSGSIZE; |
2867 | goto fail; | 3031 | goto fail; |
2868 | } | 3032 | } |
2869 | dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); | 3033 | if (udev->speed == USB_SPEED_FULL) |
3034 | dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); | ||
3035 | else | ||
3036 | dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); | ||
2870 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); | 3037 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); |
2871 | usb_ep0_reinit(udev); | 3038 | usb_ep0_reinit(udev); |
2872 | } | 3039 | } |
@@ -2887,7 +3054,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2887 | fail: | 3054 | fail: |
2888 | if (retval) { | 3055 | if (retval) { |
2889 | hub_port_disable(hub, port1, 0); | 3056 | hub_port_disable(hub, port1, 0); |
2890 | update_address(udev, devnum); /* for disconnect processing */ | 3057 | update_devnum(udev, devnum); /* for disconnect processing */ |
2891 | } | 3058 | } |
2892 | mutex_unlock(&usb_address0_mutex); | 3059 | mutex_unlock(&usb_address0_mutex); |
2893 | return retval; | 3060 | return retval; |
@@ -2978,7 +3145,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2978 | 3145 | ||
2979 | dev_dbg (hub_dev, | 3146 | dev_dbg (hub_dev, |
2980 | "port %d, status %04x, change %04x, %s\n", | 3147 | "port %d, status %04x, change %04x, %s\n", |
2981 | port1, portstatus, portchange, portspeed (portstatus)); | 3148 | port1, portstatus, portchange, portspeed(hub, portstatus)); |
2982 | 3149 | ||
2983 | if (hub->has_indicators) { | 3150 | if (hub->has_indicators) { |
2984 | set_port_led(hub, port1, HUB_LED_AUTO); | 3151 | set_port_led(hub, port1, HUB_LED_AUTO); |
@@ -3053,7 +3220,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3053 | 3220 | ||
3054 | /* maybe switch power back on (e.g. root hub was reset) */ | 3221 | /* maybe switch power back on (e.g. root hub was reset) */ |
3055 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 | 3222 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 |
3056 | && !(portstatus & USB_PORT_STAT_POWER)) | 3223 | && !port_is_power_on(hub, portstatus)) |
3057 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); | 3224 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); |
3058 | 3225 | ||
3059 | if (portstatus & USB_PORT_STAT_ENABLE) | 3226 | if (portstatus & USB_PORT_STAT_ENABLE) |
@@ -3079,34 +3246,16 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3079 | udev->level = hdev->level + 1; | 3246 | udev->level = hdev->level + 1; |
3080 | udev->wusb = hub_is_wusb(hub); | 3247 | udev->wusb = hub_is_wusb(hub); |
3081 | 3248 | ||
3082 | /* | 3249 | /* Only USB 3.0 devices are connected to SuperSpeed hubs. */ |
3083 | * USB 3.0 devices are reset automatically before the connect | 3250 | if (hub_is_superspeed(hub->hdev)) |
3084 | * port status change appears, and the root hub port status | ||
3085 | * shows the correct speed. We also get port change | ||
3086 | * notifications for USB 3.0 devices from the USB 3.0 portion of | ||
3087 | * an external USB 3.0 hub, but this isn't handled correctly yet | ||
3088 | * FIXME. | ||
3089 | */ | ||
3090 | |||
3091 | if (!(hcd->driver->flags & HCD_USB3)) | ||
3092 | udev->speed = USB_SPEED_UNKNOWN; | ||
3093 | else if ((hdev->parent == NULL) && | ||
3094 | (portstatus & USB_PORT_STAT_SUPER_SPEED)) | ||
3095 | udev->speed = USB_SPEED_SUPER; | 3251 | udev->speed = USB_SPEED_SUPER; |
3096 | else | 3252 | else |
3097 | udev->speed = USB_SPEED_UNKNOWN; | 3253 | udev->speed = USB_SPEED_UNKNOWN; |
3098 | 3254 | ||
3099 | /* | 3255 | choose_devnum(udev); |
3100 | * xHCI needs to issue an address device command later | 3256 | if (udev->devnum <= 0) { |
3101 | * in the hub_port_init sequence for SS/HS/FS/LS devices. | 3257 | status = -ENOTCONN; /* Don't retry */ |
3102 | */ | 3258 | goto loop; |
3103 | if (!(hcd->driver->flags & HCD_USB3)) { | ||
3104 | /* set the address */ | ||
3105 | choose_address(udev); | ||
3106 | if (udev->devnum <= 0) { | ||
3107 | status = -ENOTCONN; /* Don't retry */ | ||
3108 | goto loop; | ||
3109 | } | ||
3110 | } | 3259 | } |
3111 | 3260 | ||
3112 | /* reset (non-USB 3.0 devices) and get descriptor */ | 3261 | /* reset (non-USB 3.0 devices) and get descriptor */ |
@@ -3195,7 +3344,7 @@ loop_disable: | |||
3195 | hub_port_disable(hub, port1, 1); | 3344 | hub_port_disable(hub, port1, 1); |
3196 | loop: | 3345 | loop: |
3197 | usb_ep0_reinit(udev); | 3346 | usb_ep0_reinit(udev); |
3198 | release_address(udev); | 3347 | release_devnum(udev); |
3199 | hub_free_dev(udev); | 3348 | hub_free_dev(udev); |
3200 | usb_put_dev(udev); | 3349 | usb_put_dev(udev); |
3201 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) | 3350 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) |
@@ -3372,12 +3521,19 @@ static void hub_events(void) | |||
3372 | } | 3521 | } |
3373 | 3522 | ||
3374 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { | 3523 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { |
3375 | dev_err (hub_dev, | 3524 | u16 status = 0; |
3376 | "over-current change on port %d\n", | 3525 | u16 unused; |
3377 | i); | 3526 | |
3527 | dev_dbg(hub_dev, "over-current change on port " | ||
3528 | "%d\n", i); | ||
3378 | clear_port_feature(hdev, i, | 3529 | clear_port_feature(hdev, i, |
3379 | USB_PORT_FEAT_C_OVER_CURRENT); | 3530 | USB_PORT_FEAT_C_OVER_CURRENT); |
3531 | msleep(100); /* Cool down */ | ||
3380 | hub_power_on(hub, true); | 3532 | hub_power_on(hub, true); |
3533 | hub_port_status(hub, i, &status, &unused); | ||
3534 | if (status & USB_PORT_STAT_OVERCURRENT) | ||
3535 | dev_err(hub_dev, "over-current " | ||
3536 | "condition on port %d\n", i); | ||
3381 | } | 3537 | } |
3382 | 3538 | ||
3383 | if (portchange & USB_PORT_STAT_C_RESET) { | 3539 | if (portchange & USB_PORT_STAT_C_RESET) { |
@@ -3387,6 +3543,35 @@ static void hub_events(void) | |||
3387 | clear_port_feature(hdev, i, | 3543 | clear_port_feature(hdev, i, |
3388 | USB_PORT_FEAT_C_RESET); | 3544 | USB_PORT_FEAT_C_RESET); |
3389 | } | 3545 | } |
3546 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | ||
3547 | hub_is_superspeed(hub->hdev)) { | ||
3548 | dev_dbg(hub_dev, | ||
3549 | "warm reset change on port %d\n", | ||
3550 | i); | ||
3551 | clear_port_feature(hdev, i, | ||
3552 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
3553 | } | ||
3554 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
3555 | clear_port_feature(hub->hdev, i, | ||
3556 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
3557 | } | ||
3558 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | ||
3559 | dev_warn(hub_dev, | ||
3560 | "config error on port %d\n", | ||
3561 | i); | ||
3562 | clear_port_feature(hub->hdev, i, | ||
3563 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | ||
3564 | } | ||
3565 | |||
3566 | /* Warm reset a USB3 protocol port if it's in | ||
3567 | * SS.Inactive state. | ||
3568 | */ | ||
3569 | if (hub_is_superspeed(hub->hdev) && | ||
3570 | (portstatus & USB_PORT_STAT_LINK_STATE) | ||
3571 | == USB_SS_PORT_LS_SS_INACTIVE) { | ||
3572 | dev_dbg(hub_dev, "warm reset port %d\n", i); | ||
3573 | hub_port_warm_reset(hub, i); | ||
3574 | } | ||
3390 | 3575 | ||
3391 | if (connect_change) | 3576 | if (connect_change) |
3392 | hub_port_connect_change(hub, i, | 3577 | hub_port_connect_change(hub, i, |
@@ -3409,10 +3594,17 @@ static void hub_events(void) | |||
3409 | hub->limited_power = 0; | 3594 | hub->limited_power = 0; |
3410 | } | 3595 | } |
3411 | if (hubchange & HUB_CHANGE_OVERCURRENT) { | 3596 | if (hubchange & HUB_CHANGE_OVERCURRENT) { |
3412 | dev_dbg (hub_dev, "overcurrent change\n"); | 3597 | u16 status = 0; |
3413 | msleep(500); /* Cool down */ | 3598 | u16 unused; |
3599 | |||
3600 | dev_dbg(hub_dev, "over-current change\n"); | ||
3414 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); | 3601 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); |
3602 | msleep(500); /* Cool down */ | ||
3415 | hub_power_on(hub, true); | 3603 | hub_power_on(hub, true); |
3604 | hub_hub_status(hub, &status, &unused); | ||
3605 | if (status & HUB_STATUS_OVERCURRENT) | ||
3606 | dev_err(hub_dev, "over-current " | ||
3607 | "condition\n"); | ||
3416 | } | 3608 | } |
3417 | } | 3609 | } |
3418 | 3610 | ||
@@ -3629,7 +3821,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3629 | } | 3821 | } |
3630 | 3822 | ||
3631 | if (!parent_hdev) { | 3823 | if (!parent_hdev) { |
3632 | /* this requires hcd-specific logic; see OHCI hc_restart() */ | 3824 | /* this requires hcd-specific logic; see ohci_restart() */ |
3633 | dev_dbg(&udev->dev, "%s for root hub!\n", __func__); | 3825 | dev_dbg(&udev->dev, "%s for root hub!\n", __func__); |
3634 | return -EISDIR; | 3826 | return -EISDIR; |
3635 | } | 3827 | } |
@@ -3661,13 +3853,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3661 | if (!udev->actconfig) | 3853 | if (!udev->actconfig) |
3662 | goto done; | 3854 | goto done; |
3663 | 3855 | ||
3664 | mutex_lock(&hcd->bandwidth_mutex); | 3856 | mutex_lock(hcd->bandwidth_mutex); |
3665 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); | 3857 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); |
3666 | if (ret < 0) { | 3858 | if (ret < 0) { |
3667 | dev_warn(&udev->dev, | 3859 | dev_warn(&udev->dev, |
3668 | "Busted HC? Not enough HCD resources for " | 3860 | "Busted HC? Not enough HCD resources for " |
3669 | "old configuration.\n"); | 3861 | "old configuration.\n"); |
3670 | mutex_unlock(&hcd->bandwidth_mutex); | 3862 | mutex_unlock(hcd->bandwidth_mutex); |
3671 | goto re_enumerate; | 3863 | goto re_enumerate; |
3672 | } | 3864 | } |
3673 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 3865 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
@@ -3678,10 +3870,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3678 | dev_err(&udev->dev, | 3870 | dev_err(&udev->dev, |
3679 | "can't restore configuration #%d (error=%d)\n", | 3871 | "can't restore configuration #%d (error=%d)\n", |
3680 | udev->actconfig->desc.bConfigurationValue, ret); | 3872 | udev->actconfig->desc.bConfigurationValue, ret); |
3681 | mutex_unlock(&hcd->bandwidth_mutex); | 3873 | mutex_unlock(hcd->bandwidth_mutex); |
3682 | goto re_enumerate; | 3874 | goto re_enumerate; |
3683 | } | 3875 | } |
3684 | mutex_unlock(&hcd->bandwidth_mutex); | 3876 | mutex_unlock(hcd->bandwidth_mutex); |
3685 | usb_set_device_state(udev, USB_STATE_CONFIGURED); | 3877 | usb_set_device_state(udev, USB_STATE_CONFIGURED); |
3686 | 3878 | ||
3687 | /* Put interfaces back into the same altsettings as before. | 3879 | /* Put interfaces back into the same altsettings as before. |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 095fa5366690..2278dad886e2 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <linux/parser.h> | 39 | #include <linux/parser.h> |
40 | #include <linux/notifier.h> | 40 | #include <linux/notifier.h> |
41 | #include <linux/seq_file.h> | 41 | #include <linux/seq_file.h> |
42 | #include <linux/smp_lock.h> | ||
43 | #include <linux/usb/hcd.h> | 42 | #include <linux/usb/hcd.h> |
44 | #include <asm/byteorder.h> | 43 | #include <asm/byteorder.h> |
45 | #include "usb.h" | 44 | #include "usb.h" |
@@ -276,6 +275,7 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t de | |||
276 | struct inode *inode = new_inode(sb); | 275 | struct inode *inode = new_inode(sb); |
277 | 276 | ||
278 | if (inode) { | 277 | if (inode) { |
278 | inode->i_ino = get_next_ino(); | ||
279 | inode->i_mode = mode; | 279 | inode->i_mode = mode; |
280 | inode->i_uid = current_fsuid(); | 280 | inode->i_uid = current_fsuid(); |
281 | inode->i_gid = current_fsgid(); | 281 | inode->i_gid = current_fsgid(); |
@@ -343,17 +343,19 @@ static int usbfs_empty (struct dentry *dentry) | |||
343 | { | 343 | { |
344 | struct list_head *list; | 344 | struct list_head *list; |
345 | 345 | ||
346 | spin_lock(&dcache_lock); | 346 | spin_lock(&dentry->d_lock); |
347 | |||
348 | list_for_each(list, &dentry->d_subdirs) { | 347 | list_for_each(list, &dentry->d_subdirs) { |
349 | struct dentry *de = list_entry(list, struct dentry, d_u.d_child); | 348 | struct dentry *de = list_entry(list, struct dentry, d_u.d_child); |
349 | |||
350 | spin_lock_nested(&de->d_lock, DENTRY_D_LOCK_NESTED); | ||
350 | if (usbfs_positive(de)) { | 351 | if (usbfs_positive(de)) { |
351 | spin_unlock(&dcache_lock); | 352 | spin_unlock(&de->d_lock); |
353 | spin_unlock(&dentry->d_lock); | ||
352 | return 0; | 354 | return 0; |
353 | } | 355 | } |
356 | spin_unlock(&de->d_lock); | ||
354 | } | 357 | } |
355 | 358 | spin_unlock(&dentry->d_lock); | |
356 | spin_unlock(&dcache_lock); | ||
357 | return 1; | 359 | return 1; |
358 | } | 360 | } |
359 | 361 | ||
@@ -387,7 +389,6 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
387 | mutex_unlock(&inode->i_mutex); | 389 | mutex_unlock(&inode->i_mutex); |
388 | if (!error) | 390 | if (!error) |
389 | d_delete(dentry); | 391 | d_delete(dentry); |
390 | dput(dentry); | ||
391 | return error; | 392 | return error; |
392 | } | 393 | } |
393 | 394 | ||
@@ -573,16 +574,16 @@ static void fs_remove_file (struct dentry *dentry) | |||
573 | 574 | ||
574 | /* --------------------------------------------------------------------- */ | 575 | /* --------------------------------------------------------------------- */ |
575 | 576 | ||
576 | static int usb_get_sb(struct file_system_type *fs_type, | 577 | static struct dentry *usb_mount(struct file_system_type *fs_type, |
577 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | 578 | int flags, const char *dev_name, void *data) |
578 | { | 579 | { |
579 | return get_sb_single(fs_type, flags, data, usbfs_fill_super, mnt); | 580 | return mount_single(fs_type, flags, data, usbfs_fill_super); |
580 | } | 581 | } |
581 | 582 | ||
582 | static struct file_system_type usb_fs_type = { | 583 | static struct file_system_type usb_fs_type = { |
583 | .owner = THIS_MODULE, | 584 | .owner = THIS_MODULE, |
584 | .name = "usbfs", | 585 | .name = "usbfs", |
585 | .get_sb = usb_get_sb, | 586 | .mount = usb_mount, |
586 | .kill_sb = kill_litter_super, | 587 | .kill_sb = kill_litter_super, |
587 | }; | 588 | }; |
588 | 589 | ||
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 9f0ce7de0e36..0b5ec234c787 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1135,22 +1135,26 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf, | |||
1135 | * Deallocates hcd/hardware state for the endpoints (nuking all or most | 1135 | * Deallocates hcd/hardware state for the endpoints (nuking all or most |
1136 | * pending urbs) and usbcore state for the interfaces, so that usbcore | 1136 | * pending urbs) and usbcore state for the interfaces, so that usbcore |
1137 | * must usb_set_configuration() before any interfaces could be used. | 1137 | * must usb_set_configuration() before any interfaces could be used. |
1138 | * | ||
1139 | * Must be called with hcd->bandwidth_mutex held. | ||
1138 | */ | 1140 | */ |
1139 | void usb_disable_device(struct usb_device *dev, int skip_ep0) | 1141 | void usb_disable_device(struct usb_device *dev, int skip_ep0) |
1140 | { | 1142 | { |
1141 | int i; | 1143 | int i; |
1142 | 1144 | struct usb_hcd *hcd = bus_to_hcd(dev->bus); | |
1143 | dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__, | ||
1144 | skip_ep0 ? "non-ep0" : "all"); | ||
1145 | for (i = skip_ep0; i < 16; ++i) { | ||
1146 | usb_disable_endpoint(dev, i, true); | ||
1147 | usb_disable_endpoint(dev, i + USB_DIR_IN, true); | ||
1148 | } | ||
1149 | 1145 | ||
1150 | /* getting rid of interfaces will disconnect | 1146 | /* getting rid of interfaces will disconnect |
1151 | * any drivers bound to them (a key side effect) | 1147 | * any drivers bound to them (a key side effect) |
1152 | */ | 1148 | */ |
1153 | if (dev->actconfig) { | 1149 | if (dev->actconfig) { |
1150 | /* | ||
1151 | * FIXME: In order to avoid self-deadlock involving the | ||
1152 | * bandwidth_mutex, we have to mark all the interfaces | ||
1153 | * before unregistering any of them. | ||
1154 | */ | ||
1155 | for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) | ||
1156 | dev->actconfig->interface[i]->unregistering = 1; | ||
1157 | |||
1154 | for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { | 1158 | for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { |
1155 | struct usb_interface *interface; | 1159 | struct usb_interface *interface; |
1156 | 1160 | ||
@@ -1160,7 +1164,6 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) | |||
1160 | continue; | 1164 | continue; |
1161 | dev_dbg(&dev->dev, "unregistering interface %s\n", | 1165 | dev_dbg(&dev->dev, "unregistering interface %s\n", |
1162 | dev_name(&interface->dev)); | 1166 | dev_name(&interface->dev)); |
1163 | interface->unregistering = 1; | ||
1164 | remove_intf_ep_devs(interface); | 1167 | remove_intf_ep_devs(interface); |
1165 | device_del(&interface->dev); | 1168 | device_del(&interface->dev); |
1166 | } | 1169 | } |
@@ -1176,6 +1179,23 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) | |||
1176 | if (dev->state == USB_STATE_CONFIGURED) | 1179 | if (dev->state == USB_STATE_CONFIGURED) |
1177 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1180 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1178 | } | 1181 | } |
1182 | |||
1183 | dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__, | ||
1184 | skip_ep0 ? "non-ep0" : "all"); | ||
1185 | if (hcd->driver->check_bandwidth) { | ||
1186 | /* First pass: Cancel URBs, leave endpoint pointers intact. */ | ||
1187 | for (i = skip_ep0; i < 16; ++i) { | ||
1188 | usb_disable_endpoint(dev, i, false); | ||
1189 | usb_disable_endpoint(dev, i + USB_DIR_IN, false); | ||
1190 | } | ||
1191 | /* Remove endpoints from the host controller internal state */ | ||
1192 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); | ||
1193 | /* Second pass: remove endpoint pointers */ | ||
1194 | } | ||
1195 | for (i = skip_ep0; i < 16; ++i) { | ||
1196 | usb_disable_endpoint(dev, i, true); | ||
1197 | usb_disable_endpoint(dev, i + USB_DIR_IN, true); | ||
1198 | } | ||
1179 | } | 1199 | } |
1180 | 1200 | ||
1181 | /** | 1201 | /** |
@@ -1273,6 +1293,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1273 | interface); | 1293 | interface); |
1274 | return -EINVAL; | 1294 | return -EINVAL; |
1275 | } | 1295 | } |
1296 | if (iface->unregistering) | ||
1297 | return -ENODEV; | ||
1276 | 1298 | ||
1277 | alt = usb_altnum_to_altsetting(iface, alternate); | 1299 | alt = usb_altnum_to_altsetting(iface, alternate); |
1278 | if (!alt) { | 1300 | if (!alt) { |
@@ -1284,12 +1306,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1284 | /* Make sure we have enough bandwidth for this alternate interface. | 1306 | /* Make sure we have enough bandwidth for this alternate interface. |
1285 | * Remove the current alt setting and add the new alt setting. | 1307 | * Remove the current alt setting and add the new alt setting. |
1286 | */ | 1308 | */ |
1287 | mutex_lock(&hcd->bandwidth_mutex); | 1309 | mutex_lock(hcd->bandwidth_mutex); |
1288 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); | 1310 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); |
1289 | if (ret < 0) { | 1311 | if (ret < 0) { |
1290 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", | 1312 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", |
1291 | alternate); | 1313 | alternate); |
1292 | mutex_unlock(&hcd->bandwidth_mutex); | 1314 | mutex_unlock(hcd->bandwidth_mutex); |
1293 | return ret; | 1315 | return ret; |
1294 | } | 1316 | } |
1295 | 1317 | ||
@@ -1311,10 +1333,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1311 | } else if (ret < 0) { | 1333 | } else if (ret < 0) { |
1312 | /* Re-instate the old alt setting */ | 1334 | /* Re-instate the old alt setting */ |
1313 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); | 1335 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); |
1314 | mutex_unlock(&hcd->bandwidth_mutex); | 1336 | mutex_unlock(hcd->bandwidth_mutex); |
1315 | return ret; | 1337 | return ret; |
1316 | } | 1338 | } |
1317 | mutex_unlock(&hcd->bandwidth_mutex); | 1339 | mutex_unlock(hcd->bandwidth_mutex); |
1318 | 1340 | ||
1319 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here | 1341 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here |
1320 | * when they implement async or easily-killable versions of this or | 1342 | * when they implement async or easily-killable versions of this or |
@@ -1413,7 +1435,7 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1413 | 1435 | ||
1414 | config = dev->actconfig; | 1436 | config = dev->actconfig; |
1415 | retval = 0; | 1437 | retval = 0; |
1416 | mutex_lock(&hcd->bandwidth_mutex); | 1438 | mutex_lock(hcd->bandwidth_mutex); |
1417 | /* Make sure we have enough bandwidth for each alternate setting 0 */ | 1439 | /* Make sure we have enough bandwidth for each alternate setting 0 */ |
1418 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1440 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
1419 | struct usb_interface *intf = config->interface[i]; | 1441 | struct usb_interface *intf = config->interface[i]; |
@@ -1442,7 +1464,7 @@ reset_old_alts: | |||
1442 | usb_hcd_alloc_bandwidth(dev, NULL, | 1464 | usb_hcd_alloc_bandwidth(dev, NULL, |
1443 | alt, intf->cur_altsetting); | 1465 | alt, intf->cur_altsetting); |
1444 | } | 1466 | } |
1445 | mutex_unlock(&hcd->bandwidth_mutex); | 1467 | mutex_unlock(hcd->bandwidth_mutex); |
1446 | return retval; | 1468 | return retval; |
1447 | } | 1469 | } |
1448 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1470 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
@@ -1451,7 +1473,7 @@ reset_old_alts: | |||
1451 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1473 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
1452 | if (retval < 0) | 1474 | if (retval < 0) |
1453 | goto reset_old_alts; | 1475 | goto reset_old_alts; |
1454 | mutex_unlock(&hcd->bandwidth_mutex); | 1476 | mutex_unlock(hcd->bandwidth_mutex); |
1455 | 1477 | ||
1456 | /* re-init hc/hcd interface/endpoint state */ | 1478 | /* re-init hc/hcd interface/endpoint state */ |
1457 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1479 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
@@ -1727,6 +1749,7 @@ free_interfaces: | |||
1727 | /* if it's already configured, clear out old state first. | 1749 | /* if it's already configured, clear out old state first. |
1728 | * getting rid of old interfaces means unbinding their drivers. | 1750 | * getting rid of old interfaces means unbinding their drivers. |
1729 | */ | 1751 | */ |
1752 | mutex_lock(hcd->bandwidth_mutex); | ||
1730 | if (dev->state != USB_STATE_ADDRESS) | 1753 | if (dev->state != USB_STATE_ADDRESS) |
1731 | usb_disable_device(dev, 1); /* Skip ep0 */ | 1754 | usb_disable_device(dev, 1); /* Skip ep0 */ |
1732 | 1755 | ||
@@ -1739,10 +1762,9 @@ free_interfaces: | |||
1739 | * host controller will not allow submissions to dropped endpoints. If | 1762 | * host controller will not allow submissions to dropped endpoints. If |
1740 | * this call fails, the device state is unchanged. | 1763 | * this call fails, the device state is unchanged. |
1741 | */ | 1764 | */ |
1742 | mutex_lock(&hcd->bandwidth_mutex); | ||
1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); | 1765 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); |
1744 | if (ret < 0) { | 1766 | if (ret < 0) { |
1745 | mutex_unlock(&hcd->bandwidth_mutex); | 1767 | mutex_unlock(hcd->bandwidth_mutex); |
1746 | usb_autosuspend_device(dev); | 1768 | usb_autosuspend_device(dev); |
1747 | goto free_interfaces; | 1769 | goto free_interfaces; |
1748 | } | 1770 | } |
@@ -1761,11 +1783,11 @@ free_interfaces: | |||
1761 | if (!cp) { | 1783 | if (!cp) { |
1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1784 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); | 1785 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); |
1764 | mutex_unlock(&hcd->bandwidth_mutex); | 1786 | mutex_unlock(hcd->bandwidth_mutex); |
1765 | usb_autosuspend_device(dev); | 1787 | usb_autosuspend_device(dev); |
1766 | goto free_interfaces; | 1788 | goto free_interfaces; |
1767 | } | 1789 | } |
1768 | mutex_unlock(&hcd->bandwidth_mutex); | 1790 | mutex_unlock(hcd->bandwidth_mutex); |
1769 | usb_set_device_state(dev, USB_STATE_CONFIGURED); | 1791 | usb_set_device_state(dev, USB_STATE_CONFIGURED); |
1770 | 1792 | ||
1771 | /* Initialize the new interface structures and the | 1793 | /* Initialize the new interface structures and the |
@@ -1804,6 +1826,7 @@ free_interfaces: | |||
1804 | INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); | 1826 | INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); |
1805 | intf->minor = -1; | 1827 | intf->minor = -1; |
1806 | device_initialize(&intf->dev); | 1828 | device_initialize(&intf->dev); |
1829 | pm_runtime_no_callbacks(&intf->dev); | ||
1807 | dev_set_name(&intf->dev, "%d-%s:%d.%d", | 1830 | dev_set_name(&intf->dev, "%d-%s:%d.%d", |
1808 | dev->bus->busnum, dev->devpath, | 1831 | dev->bus->busnum, dev->devpath, |
1809 | configuration, alt->desc.bInterfaceNumber); | 1832 | configuration, alt->desc.bInterfaceNumber); |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index 25719da45e33..81ce6a8e1d94 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -48,6 +48,10 @@ static const struct usb_device_id usb_quirk_list[] = { | |||
48 | { USB_DEVICE(0x04b4, 0x0526), .driver_info = | 48 | { USB_DEVICE(0x04b4, 0x0526), .driver_info = |
49 | USB_QUIRK_CONFIG_INTF_STRINGS }, | 49 | USB_QUIRK_CONFIG_INTF_STRINGS }, |
50 | 50 | ||
51 | /* Samsung Android phone modem - ID conflict with SPH-I500 */ | ||
52 | { USB_DEVICE(0x04e8, 0x6601), .driver_info = | ||
53 | USB_QUIRK_CONFIG_INTF_STRINGS }, | ||
54 | |||
51 | /* Roland SC-8820 */ | 55 | /* Roland SC-8820 */ |
52 | { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, | 56 | { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, |
53 | 57 | ||
@@ -68,6 +72,10 @@ static const struct usb_device_id usb_quirk_list[] = { | |||
68 | /* M-Systems Flash Disk Pioneers */ | 72 | /* M-Systems Flash Disk Pioneers */ |
69 | { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME }, | 73 | { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME }, |
70 | 74 | ||
75 | /* Keytouch QWERTY Panel keyboard */ | ||
76 | { USB_DEVICE(0x0926, 0x3333), .driver_info = | ||
77 | USB_QUIRK_CONFIG_INTF_STRINGS }, | ||
78 | |||
71 | /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */ | 79 | /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */ |
72 | { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF }, | 80 | { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF }, |
73 | 81 | ||
@@ -117,21 +125,6 @@ void usb_detect_quirks(struct usb_device *udev) | |||
117 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", | 125 | dev_dbg(&udev->dev, "USB quirks for this device: %x\n", |
118 | udev->quirks); | 126 | udev->quirks); |
119 | 127 | ||
120 | #ifdef CONFIG_USB_SUSPEND | ||
121 | |||
122 | /* By default, disable autosuspend for all devices. The hub driver | ||
123 | * will enable it for hubs. | ||
124 | */ | ||
125 | usb_disable_autosuspend(udev); | ||
126 | |||
127 | /* Autosuspend can also be disabled if the initial autosuspend_delay | ||
128 | * is negative. | ||
129 | */ | ||
130 | if (udev->autosuspend_delay < 0) | ||
131 | usb_autoresume_device(udev); | ||
132 | |||
133 | #endif | ||
134 | |||
135 | /* For the present, all devices default to USB-PERSIST enabled */ | 128 | /* For the present, all devices default to USB-PERSIST enabled */ |
136 | #if 0 /* was: #ifdef CONFIG_PM */ | 129 | #if 0 /* was: #ifdef CONFIG_PM */ |
137 | /* Hubs are automatically enabled for USB-PERSIST */ | 130 | /* Hubs are automatically enabled for USB-PERSIST */ |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 448f5b47fc48..cf05b97693ea 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -233,8 +233,6 @@ static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); | |||
233 | 233 | ||
234 | #ifdef CONFIG_PM | 234 | #ifdef CONFIG_PM |
235 | 235 | ||
236 | static const char power_group[] = "power"; | ||
237 | |||
238 | static ssize_t | 236 | static ssize_t |
239 | show_persist(struct device *dev, struct device_attribute *attr, char *buf) | 237 | show_persist(struct device *dev, struct device_attribute *attr, char *buf) |
240 | { | 238 | { |
@@ -278,7 +276,7 @@ static int add_persist_attributes(struct device *dev) | |||
278 | if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) | 276 | if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) |
279 | rc = sysfs_add_file_to_group(&dev->kobj, | 277 | rc = sysfs_add_file_to_group(&dev->kobj, |
280 | &dev_attr_persist.attr, | 278 | &dev_attr_persist.attr, |
281 | power_group); | 279 | power_group_name); |
282 | } | 280 | } |
283 | return rc; | 281 | return rc; |
284 | } | 282 | } |
@@ -287,7 +285,7 @@ static void remove_persist_attributes(struct device *dev) | |||
287 | { | 285 | { |
288 | sysfs_remove_file_from_group(&dev->kobj, | 286 | sysfs_remove_file_from_group(&dev->kobj, |
289 | &dev_attr_persist.attr, | 287 | &dev_attr_persist.attr, |
290 | power_group); | 288 | power_group_name); |
291 | } | 289 | } |
292 | #else | 290 | #else |
293 | 291 | ||
@@ -336,44 +334,20 @@ static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL); | |||
336 | static ssize_t | 334 | static ssize_t |
337 | show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) | 335 | show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) |
338 | { | 336 | { |
339 | struct usb_device *udev = to_usb_device(dev); | 337 | return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000); |
340 | |||
341 | return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ); | ||
342 | } | 338 | } |
343 | 339 | ||
344 | static ssize_t | 340 | static ssize_t |
345 | set_autosuspend(struct device *dev, struct device_attribute *attr, | 341 | set_autosuspend(struct device *dev, struct device_attribute *attr, |
346 | const char *buf, size_t count) | 342 | const char *buf, size_t count) |
347 | { | 343 | { |
348 | struct usb_device *udev = to_usb_device(dev); | 344 | int value; |
349 | int value, old_delay; | ||
350 | int rc; | ||
351 | 345 | ||
352 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || | 346 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 || |
353 | value <= - INT_MAX/HZ) | 347 | value <= -INT_MAX/1000) |
354 | return -EINVAL; | 348 | return -EINVAL; |
355 | value *= HZ; | ||
356 | |||
357 | usb_lock_device(udev); | ||
358 | old_delay = udev->autosuspend_delay; | ||
359 | udev->autosuspend_delay = value; | ||
360 | |||
361 | if (old_delay < 0) { /* Autosuspend wasn't allowed */ | ||
362 | if (value >= 0) | ||
363 | usb_autosuspend_device(udev); | ||
364 | } else { /* Autosuspend was allowed */ | ||
365 | if (value < 0) { | ||
366 | rc = usb_autoresume_device(udev); | ||
367 | if (rc < 0) { | ||
368 | count = rc; | ||
369 | udev->autosuspend_delay = old_delay; | ||
370 | } | ||
371 | } else { | ||
372 | usb_try_autosuspend_device(udev); | ||
373 | } | ||
374 | } | ||
375 | 349 | ||
376 | usb_unlock_device(udev); | 350 | pm_runtime_set_autosuspend_delay(dev, value * 1000); |
377 | return count; | 351 | return count; |
378 | } | 352 | } |
379 | 353 | ||
@@ -438,44 +412,30 @@ set_level(struct device *dev, struct device_attribute *attr, | |||
438 | 412 | ||
439 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); | 413 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); |
440 | 414 | ||
415 | static struct attribute *power_attrs[] = { | ||
416 | &dev_attr_autosuspend.attr, | ||
417 | &dev_attr_level.attr, | ||
418 | &dev_attr_connected_duration.attr, | ||
419 | &dev_attr_active_duration.attr, | ||
420 | NULL, | ||
421 | }; | ||
422 | static struct attribute_group power_attr_group = { | ||
423 | .name = power_group_name, | ||
424 | .attrs = power_attrs, | ||
425 | }; | ||
426 | |||
441 | static int add_power_attributes(struct device *dev) | 427 | static int add_power_attributes(struct device *dev) |
442 | { | 428 | { |
443 | int rc = 0; | 429 | int rc = 0; |
444 | 430 | ||
445 | if (is_usb_device(dev)) { | 431 | if (is_usb_device(dev)) |
446 | rc = sysfs_add_file_to_group(&dev->kobj, | 432 | rc = sysfs_merge_group(&dev->kobj, &power_attr_group); |
447 | &dev_attr_autosuspend.attr, | ||
448 | power_group); | ||
449 | if (rc == 0) | ||
450 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
451 | &dev_attr_level.attr, | ||
452 | power_group); | ||
453 | if (rc == 0) | ||
454 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
455 | &dev_attr_connected_duration.attr, | ||
456 | power_group); | ||
457 | if (rc == 0) | ||
458 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
459 | &dev_attr_active_duration.attr, | ||
460 | power_group); | ||
461 | } | ||
462 | return rc; | 433 | return rc; |
463 | } | 434 | } |
464 | 435 | ||
465 | static void remove_power_attributes(struct device *dev) | 436 | static void remove_power_attributes(struct device *dev) |
466 | { | 437 | { |
467 | sysfs_remove_file_from_group(&dev->kobj, | 438 | sysfs_unmerge_group(&dev->kobj, &power_attr_group); |
468 | &dev_attr_active_duration.attr, | ||
469 | power_group); | ||
470 | sysfs_remove_file_from_group(&dev->kobj, | ||
471 | &dev_attr_connected_duration.attr, | ||
472 | power_group); | ||
473 | sysfs_remove_file_from_group(&dev->kobj, | ||
474 | &dev_attr_level.attr, | ||
475 | power_group); | ||
476 | sysfs_remove_file_from_group(&dev->kobj, | ||
477 | &dev_attr_autosuspend.attr, | ||
478 | power_group); | ||
479 | } | 439 | } |
480 | 440 | ||
481 | #else | 441 | #else |
@@ -882,22 +842,19 @@ const struct attribute_group *usb_interface_groups[] = { | |||
882 | NULL | 842 | NULL |
883 | }; | 843 | }; |
884 | 844 | ||
885 | int usb_create_sysfs_intf_files(struct usb_interface *intf) | 845 | void usb_create_sysfs_intf_files(struct usb_interface *intf) |
886 | { | 846 | { |
887 | struct usb_device *udev = interface_to_usbdev(intf); | 847 | struct usb_device *udev = interface_to_usbdev(intf); |
888 | struct usb_host_interface *alt = intf->cur_altsetting; | 848 | struct usb_host_interface *alt = intf->cur_altsetting; |
889 | int retval; | ||
890 | 849 | ||
891 | if (intf->sysfs_files_created || intf->unregistering) | 850 | if (intf->sysfs_files_created || intf->unregistering) |
892 | return 0; | 851 | return; |
893 | 852 | ||
894 | if (alt->string == NULL && | 853 | if (!alt->string && !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS)) |
895 | !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS)) | ||
896 | alt->string = usb_cache_string(udev, alt->desc.iInterface); | 854 | alt->string = usb_cache_string(udev, alt->desc.iInterface); |
897 | if (alt->string) | 855 | if (alt->string && device_create_file(&intf->dev, &dev_attr_interface)) |
898 | retval = device_create_file(&intf->dev, &dev_attr_interface); | 856 | ; /* We don't actually care if the function fails. */ |
899 | intf->sysfs_files_created = 1; | 857 | intf->sysfs_files_created = 1; |
900 | return 0; | ||
901 | } | 858 | } |
902 | 859 | ||
903 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) | 860 | 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 419e6b34e2fe..ae334b067c13 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -366,7 +366,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { | 366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { |
367 | int n, len; | 367 | int n, len; |
368 | 368 | ||
369 | /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ | 369 | /* SuperSpeed isoc endpoints have up to 16 bursts of up to |
370 | * 3 packets each | ||
371 | */ | ||
372 | if (dev->speed == USB_SPEED_SUPER) { | ||
373 | int burst = 1 + ep->ss_ep_comp.bMaxBurst; | ||
374 | int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); | ||
375 | max *= burst; | ||
376 | max *= mult; | ||
377 | } | ||
378 | |||
370 | /* "high bandwidth" mode, 1-3 packets/uframe? */ | 379 | /* "high bandwidth" mode, 1-3 packets/uframe? */ |
371 | if (dev->speed == USB_SPEED_HIGH) { | 380 | if (dev->speed == USB_SPEED_HIGH) { |
372 | int mult = 1 + ((max >> 11) & 0x03); | 381 | int mult = 1 + ((max >> 11) & 0x03); |
@@ -401,8 +410,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
401 | }; | 410 | }; |
402 | 411 | ||
403 | /* Check that the pipe's type matches the endpoint's type */ | 412 | /* Check that the pipe's type matches the endpoint's type */ |
404 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) | 413 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) { |
414 | dev_err(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", | ||
415 | usb_pipetype(urb->pipe), pipetypes[xfertype]); | ||
405 | return -EPIPE; /* The most suitable error code :-) */ | 416 | return -EPIPE; /* The most suitable error code :-) */ |
417 | } | ||
406 | 418 | ||
407 | /* enforce simple/standard policy */ | 419 | /* enforce simple/standard policy */ |
408 | allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK | | 420 | allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK | |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index fdd4130fbb7d..8706fc97e60f 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -315,6 +315,11 @@ static const struct dev_pm_ops usb_device_pm_ops = { | |||
315 | .thaw = usb_dev_thaw, | 315 | .thaw = usb_dev_thaw, |
316 | .poweroff = usb_dev_poweroff, | 316 | .poweroff = usb_dev_poweroff, |
317 | .restore = usb_dev_restore, | 317 | .restore = usb_dev_restore, |
318 | #ifdef CONFIG_USB_SUSPEND | ||
319 | .runtime_suspend = usb_runtime_suspend, | ||
320 | .runtime_resume = usb_runtime_resume, | ||
321 | .runtime_idle = usb_runtime_idle, | ||
322 | #endif | ||
318 | }; | 323 | }; |
319 | 324 | ||
320 | #endif /* CONFIG_PM */ | 325 | #endif /* CONFIG_PM */ |
@@ -445,7 +450,8 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
445 | INIT_LIST_HEAD(&dev->filelist); | 450 | INIT_LIST_HEAD(&dev->filelist); |
446 | 451 | ||
447 | #ifdef CONFIG_PM | 452 | #ifdef CONFIG_PM |
448 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; | 453 | pm_runtime_set_autosuspend_delay(&dev->dev, |
454 | usb_autosuspend_delay * 1000); | ||
449 | dev->connect_time = jiffies; | 455 | dev->connect_time = jiffies; |
450 | dev->active_duration = -jiffies; | 456 | dev->active_duration = -jiffies; |
451 | #endif | 457 | #endif |
@@ -947,8 +953,7 @@ static int usb_bus_notify(struct notifier_block *nb, unsigned long action, | |||
947 | if (dev->type == &usb_device_type) | 953 | if (dev->type == &usb_device_type) |
948 | (void) usb_create_sysfs_dev_files(to_usb_device(dev)); | 954 | (void) usb_create_sysfs_dev_files(to_usb_device(dev)); |
949 | else if (dev->type == &usb_if_device_type) | 955 | else if (dev->type == &usb_if_device_type) |
950 | (void) usb_create_sysfs_intf_files( | 956 | usb_create_sysfs_intf_files(to_usb_interface(dev)); |
951 | to_usb_interface(dev)); | ||
952 | break; | 957 | break; |
953 | 958 | ||
954 | case BUS_NOTIFY_DEL_DEVICE: | 959 | case BUS_NOTIFY_DEL_DEVICE: |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index cd882203ad34..d44d4b7bbf17 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | extern int usb_create_sysfs_dev_files(struct usb_device *dev); | 5 | extern int usb_create_sysfs_dev_files(struct usb_device *dev); |
6 | extern void usb_remove_sysfs_dev_files(struct usb_device *dev); | 6 | extern void usb_remove_sysfs_dev_files(struct usb_device *dev); |
7 | extern int usb_create_sysfs_intf_files(struct usb_interface *intf); | 7 | extern void usb_create_sysfs_intf_files(struct usb_interface *intf); |
8 | extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); | 8 | extern void usb_remove_sysfs_intf_files(struct usb_interface *intf); |
9 | extern int usb_create_ep_devs(struct device *parent, | 9 | extern int usb_create_ep_devs(struct device *parent, |
10 | struct usb_host_endpoint *endpoint, | 10 | struct usb_host_endpoint *endpoint, |
@@ -75,14 +75,15 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
75 | #ifdef CONFIG_USB_SUSPEND | 75 | #ifdef CONFIG_USB_SUSPEND |
76 | 76 | ||
77 | extern void usb_autosuspend_device(struct usb_device *udev); | 77 | extern void usb_autosuspend_device(struct usb_device *udev); |
78 | extern void usb_try_autosuspend_device(struct usb_device *udev); | ||
79 | extern int usb_autoresume_device(struct usb_device *udev); | 78 | extern int usb_autoresume_device(struct usb_device *udev); |
80 | extern int usb_remote_wakeup(struct usb_device *dev); | 79 | extern int usb_remote_wakeup(struct usb_device *dev); |
80 | extern int usb_runtime_suspend(struct device *dev); | ||
81 | extern int usb_runtime_resume(struct device *dev); | ||
82 | extern int usb_runtime_idle(struct device *dev); | ||
81 | 83 | ||
82 | #else | 84 | #else |
83 | 85 | ||
84 | #define usb_autosuspend_device(udev) do {} while (0) | 86 | #define usb_autosuspend_device(udev) do {} while (0) |
85 | #define usb_try_autosuspend_device(udev) do {} while (0) | ||
86 | static inline int usb_autoresume_device(struct usb_device *udev) | 87 | static inline int usb_autoresume_device(struct usb_device *udev) |
87 | { | 88 | { |
88 | return 0; | 89 | return 0; |
@@ -124,6 +125,19 @@ static inline int is_usb_device_driver(struct device_driver *drv) | |||
124 | for_devices; | 125 | for_devices; |
125 | } | 126 | } |
126 | 127 | ||
128 | /* translate USB error codes to codes user space understands */ | ||
129 | static inline int usb_translate_errors(int error_code) | ||
130 | { | ||
131 | switch (error_code) { | ||
132 | case 0: | ||
133 | case -ENOMEM: | ||
134 | case -ENODEV: | ||
135 | return error_code; | ||
136 | default: | ||
137 | return -EIO; | ||
138 | } | ||
139 | } | ||
140 | |||
127 | 141 | ||
128 | /* for labeling diagnostics */ | 142 | /* for labeling diagnostics */ |
129 | extern const char *usbcore_name; | 143 | extern const char *usbcore_name; |