diff options
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/Kconfig | 16 | ||||
-rw-r--r-- | drivers/usb/core/Makefile | 4 | ||||
-rw-r--r-- | drivers/usb/core/config.c | 192 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 56 | ||||
-rw-r--r-- | drivers/usb/core/endpoint.c | 160 | ||||
-rw-r--r-- | drivers/usb/core/hcd-pci.c | 244 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 220 | ||||
-rw-r--r-- | drivers/usb/core/hcd.h | 55 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 134 | ||||
-rw-r--r-- | drivers/usb/core/hub.h | 3 | ||||
-rw-r--r-- | drivers/usb/core/message.c | 194 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 12 | ||||
-rw-r--r-- | drivers/usb/core/urb.c | 12 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 76 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 13 |
15 files changed, 907 insertions, 484 deletions
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index e1759d17ac5..69280c35b5c 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -28,7 +28,7 @@ comment "Miscellaneous USB options" | |||
28 | depends on USB | 28 | depends on USB |
29 | 29 | ||
30 | config USB_DEVICEFS | 30 | config USB_DEVICEFS |
31 | bool "USB device filesystem" | 31 | bool "USB device filesystem (DEPRECATED)" if EMBEDDED |
32 | depends on USB | 32 | depends on USB |
33 | ---help--- | 33 | ---help--- |
34 | If you say Y here (and to "/proc file system support" in the "File | 34 | If you say Y here (and to "/proc file system support" in the "File |
@@ -46,11 +46,15 @@ config USB_DEVICEFS | |||
46 | For the format of the various /proc/bus/usb/ files, please read | 46 | For the format of the various /proc/bus/usb/ files, please read |
47 | <file:Documentation/usb/proc_usb_info.txt>. | 47 | <file:Documentation/usb/proc_usb_info.txt>. |
48 | 48 | ||
49 | Usbfs files can't handle Access Control Lists (ACL), which are the | 49 | Modern Linux systems do not use this. |
50 | default way to grant access to USB devices for untrusted users of a | 50 | |
51 | desktop system. The usbfs functionality is replaced by real | 51 | Usbfs entries are files and not character devices; usbfs can't |
52 | device-nodes managed by udev. These nodes live in /dev/bus/usb and | 52 | handle Access Control Lists (ACL) which are the default way to |
53 | are used by libusb. | 53 | grant access to USB devices for untrusted users of a desktop |
54 | system. | ||
55 | |||
56 | The usbfs functionality is replaced by real device-nodes managed by | ||
57 | udev. These nodes lived in /dev/bus/usb and are used by libusb. | ||
54 | 58 | ||
55 | config USB_DEVICE_CLASS | 59 | config USB_DEVICE_CLASS |
56 | bool "USB device class-devices (DEPRECATED)" | 60 | bool "USB device class-devices (DEPRECATED)" |
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index b6078706fb9..ec16e602990 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -4,14 +4,14 @@ | |||
4 | 4 | ||
5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ | 5 | usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \ |
6 | config.o file.o buffer.o sysfs.o endpoint.o \ | 6 | config.o file.o buffer.o sysfs.o endpoint.o \ |
7 | devio.o notify.o generic.o quirks.o | 7 | devio.o notify.o generic.o quirks.o devices.o |
8 | 8 | ||
9 | ifeq ($(CONFIG_PCI),y) | 9 | ifeq ($(CONFIG_PCI),y) |
10 | usbcore-objs += hcd-pci.o | 10 | usbcore-objs += hcd-pci.o |
11 | endif | 11 | endif |
12 | 12 | ||
13 | ifeq ($(CONFIG_USB_DEVICEFS),y) | 13 | ifeq ($(CONFIG_USB_DEVICEFS),y) |
14 | usbcore-objs += inode.o devices.o | 14 | usbcore-objs += inode.o |
15 | endif | 15 | endif |
16 | 16 | ||
17 | obj-$(CONFIG_USB) += usbcore.o | 17 | obj-$(CONFIG_USB) += usbcore.o |
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c index 568244c99bd..24dfb33f90c 100644 --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c | |||
@@ -19,6 +19,32 @@ static inline const char *plural(int n) | |||
19 | return (n == 1 ? "" : "s"); | 19 | return (n == 1 ? "" : "s"); |
20 | } | 20 | } |
21 | 21 | ||
22 | /* FIXME: this is a kludge */ | ||
23 | static int find_next_descriptor_more(unsigned char *buffer, int size, | ||
24 | int dt1, int dt2, int dt3, int *num_skipped) | ||
25 | { | ||
26 | struct usb_descriptor_header *h; | ||
27 | int n = 0; | ||
28 | unsigned char *buffer0 = buffer; | ||
29 | |||
30 | /* Find the next descriptor of type dt1 or dt2 or dt3 */ | ||
31 | while (size > 0) { | ||
32 | h = (struct usb_descriptor_header *) buffer; | ||
33 | if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2 || | ||
34 | h->bDescriptorType == dt3) | ||
35 | break; | ||
36 | buffer += h->bLength; | ||
37 | size -= h->bLength; | ||
38 | ++n; | ||
39 | } | ||
40 | |||
41 | /* Store the number of descriptors skipped and return the | ||
42 | * number of bytes skipped */ | ||
43 | if (num_skipped) | ||
44 | *num_skipped = n; | ||
45 | return buffer - buffer0; | ||
46 | } | ||
47 | |||
22 | static int find_next_descriptor(unsigned char *buffer, int size, | 48 | static int find_next_descriptor(unsigned char *buffer, int size, |
23 | int dt1, int dt2, int *num_skipped) | 49 | int dt1, int dt2, int *num_skipped) |
24 | { | 50 | { |
@@ -43,6 +69,129 @@ static int find_next_descriptor(unsigned char *buffer, int size, | |||
43 | return buffer - buffer0; | 69 | return buffer - buffer0; |
44 | } | 70 | } |
45 | 71 | ||
72 | static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, | ||
73 | int inum, int asnum, struct usb_host_endpoint *ep, | ||
74 | int num_ep, unsigned char *buffer, int size) | ||
75 | { | ||
76 | unsigned char *buffer_start = buffer; | ||
77 | struct usb_ss_ep_comp_descriptor *desc; | ||
78 | int retval; | ||
79 | int num_skipped; | ||
80 | int max_tx; | ||
81 | int i; | ||
82 | |||
83 | /* Allocate space for the SS endpoint companion descriptor */ | ||
84 | ep->ss_ep_comp = kzalloc(sizeof(struct usb_host_ss_ep_comp), | ||
85 | GFP_KERNEL); | ||
86 | if (!ep->ss_ep_comp) | ||
87 | return -ENOMEM; | ||
88 | desc = (struct usb_ss_ep_comp_descriptor *) buffer; | ||
89 | if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP) { | ||
90 | dev_warn(ddev, "No SuperSpeed endpoint companion for config %d " | ||
91 | " interface %d altsetting %d ep %d: " | ||
92 | "using minimum values\n", | ||
93 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
94 | ep->ss_ep_comp->desc.bLength = USB_DT_SS_EP_COMP_SIZE; | ||
95 | ep->ss_ep_comp->desc.bDescriptorType = USB_DT_SS_ENDPOINT_COMP; | ||
96 | ep->ss_ep_comp->desc.bMaxBurst = 0; | ||
97 | /* | ||
98 | * Leave bmAttributes as zero, which will mean no streams for | ||
99 | * bulk, and isoc won't support multiple bursts of packets. | ||
100 | * With bursts of only one packet, and a Mult of 1, the max | ||
101 | * amount of data moved per endpoint service interval is one | ||
102 | * packet. | ||
103 | */ | ||
104 | if (usb_endpoint_xfer_isoc(&ep->desc) || | ||
105 | usb_endpoint_xfer_int(&ep->desc)) | ||
106 | ep->ss_ep_comp->desc.wBytesPerInterval = | ||
107 | ep->desc.wMaxPacketSize; | ||
108 | /* | ||
109 | * The next descriptor is for an Endpoint or Interface, | ||
110 | * no extra descriptors to copy into the companion structure, | ||
111 | * and we didn't eat up any of the buffer. | ||
112 | */ | ||
113 | retval = 0; | ||
114 | goto valid; | ||
115 | } | ||
116 | memcpy(&ep->ss_ep_comp->desc, desc, USB_DT_SS_EP_COMP_SIZE); | ||
117 | desc = &ep->ss_ep_comp->desc; | ||
118 | buffer += desc->bLength; | ||
119 | size -= desc->bLength; | ||
120 | |||
121 | /* Eat up the other descriptors we don't care about */ | ||
122 | ep->ss_ep_comp->extra = buffer; | ||
123 | i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT, | ||
124 | USB_DT_INTERFACE, &num_skipped); | ||
125 | ep->ss_ep_comp->extralen = i; | ||
126 | buffer += i; | ||
127 | size -= i; | ||
128 | retval = buffer - buffer_start + i; | ||
129 | if (num_skipped > 0) | ||
130 | dev_dbg(ddev, "skipped %d descriptor%s after %s\n", | ||
131 | num_skipped, plural(num_skipped), | ||
132 | "SuperSpeed endpoint companion"); | ||
133 | |||
134 | /* Check the various values */ | ||
135 | if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) { | ||
136 | dev_warn(ddev, "Control endpoint with bMaxBurst = %d in " | ||
137 | "config %d interface %d altsetting %d ep %d: " | ||
138 | "setting to zero\n", desc->bMaxBurst, | ||
139 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
140 | desc->bMaxBurst = 0; | ||
141 | } | ||
142 | if (desc->bMaxBurst > 15) { | ||
143 | dev_warn(ddev, "Endpoint with bMaxBurst = %d in " | ||
144 | "config %d interface %d altsetting %d ep %d: " | ||
145 | "setting to 15\n", desc->bMaxBurst, | ||
146 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
147 | desc->bMaxBurst = 15; | ||
148 | } | ||
149 | if ((usb_endpoint_xfer_control(&ep->desc) || usb_endpoint_xfer_int(&ep->desc)) | ||
150 | && desc->bmAttributes != 0) { | ||
151 | dev_warn(ddev, "%s endpoint with bmAttributes = %d in " | ||
152 | "config %d interface %d altsetting %d ep %d: " | ||
153 | "setting to zero\n", | ||
154 | usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk", | ||
155 | desc->bmAttributes, | ||
156 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
157 | desc->bmAttributes = 0; | ||
158 | } | ||
159 | if (usb_endpoint_xfer_bulk(&ep->desc) && desc->bmAttributes > 16) { | ||
160 | dev_warn(ddev, "Bulk endpoint with more than 65536 streams in " | ||
161 | "config %d interface %d altsetting %d ep %d: " | ||
162 | "setting to max\n", | ||
163 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
164 | desc->bmAttributes = 16; | ||
165 | } | ||
166 | if (usb_endpoint_xfer_isoc(&ep->desc) && desc->bmAttributes > 2) { | ||
167 | dev_warn(ddev, "Isoc endpoint has Mult of %d in " | ||
168 | "config %d interface %d altsetting %d ep %d: " | ||
169 | "setting to 3\n", desc->bmAttributes + 1, | ||
170 | cfgno, inum, asnum, ep->desc.bEndpointAddress); | ||
171 | desc->bmAttributes = 2; | ||
172 | } | ||
173 | if (usb_endpoint_xfer_isoc(&ep->desc)) { | ||
174 | max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1) * | ||
175 | (desc->bmAttributes + 1); | ||
176 | } else if (usb_endpoint_xfer_int(&ep->desc)) { | ||
177 | max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1); | ||
178 | } else { | ||
179 | goto valid; | ||
180 | } | ||
181 | if (desc->wBytesPerInterval > max_tx) { | ||
182 | dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " | ||
183 | "config %d interface %d altsetting %d ep %d: " | ||
184 | "setting to %d\n", | ||
185 | usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int", | ||
186 | desc->wBytesPerInterval, | ||
187 | cfgno, inum, asnum, ep->desc.bEndpointAddress, | ||
188 | max_tx); | ||
189 | desc->wBytesPerInterval = max_tx; | ||
190 | } | ||
191 | valid: | ||
192 | return retval; | ||
193 | } | ||
194 | |||
46 | static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, | 195 | static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, |
47 | int asnum, struct usb_host_interface *ifp, int num_ep, | 196 | int asnum, struct usb_host_interface *ifp, int num_ep, |
48 | unsigned char *buffer, int size) | 197 | unsigned char *buffer, int size) |
@@ -50,7 +199,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, | |||
50 | unsigned char *buffer0 = buffer; | 199 | unsigned char *buffer0 = buffer; |
51 | struct usb_endpoint_descriptor *d; | 200 | struct usb_endpoint_descriptor *d; |
52 | struct usb_host_endpoint *endpoint; | 201 | struct usb_host_endpoint *endpoint; |
53 | int n, i, j; | 202 | int n, i, j, retval; |
54 | 203 | ||
55 | d = (struct usb_endpoint_descriptor *) buffer; | 204 | d = (struct usb_endpoint_descriptor *) buffer; |
56 | buffer += d->bLength; | 205 | buffer += d->bLength; |
@@ -92,6 +241,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, | |||
92 | if (usb_endpoint_xfer_int(d)) { | 241 | if (usb_endpoint_xfer_int(d)) { |
93 | i = 1; | 242 | i = 1; |
94 | switch (to_usb_device(ddev)->speed) { | 243 | switch (to_usb_device(ddev)->speed) { |
244 | case USB_SPEED_SUPER: | ||
95 | case USB_SPEED_HIGH: | 245 | case USB_SPEED_HIGH: |
96 | /* Many device manufacturers are using full-speed | 246 | /* Many device manufacturers are using full-speed |
97 | * bInterval values in high-speed interrupt endpoint | 247 | * bInterval values in high-speed interrupt endpoint |
@@ -161,17 +311,39 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, | |||
161 | cfgno, inum, asnum, d->bEndpointAddress, | 311 | cfgno, inum, asnum, d->bEndpointAddress, |
162 | maxp); | 312 | maxp); |
163 | } | 313 | } |
164 | 314 | /* Allocate room for and parse any SS endpoint companion descriptors */ | |
165 | /* Skip over any Class Specific or Vendor Specific descriptors; | 315 | if (to_usb_device(ddev)->speed == USB_SPEED_SUPER) { |
166 | * find the next endpoint or interface descriptor */ | 316 | endpoint->extra = buffer; |
167 | endpoint->extra = buffer; | 317 | i = find_next_descriptor_more(buffer, size, USB_DT_SS_ENDPOINT_COMP, |
168 | i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT, | 318 | USB_DT_ENDPOINT, USB_DT_INTERFACE, &n); |
169 | USB_DT_INTERFACE, &n); | 319 | endpoint->extralen = i; |
170 | endpoint->extralen = i; | 320 | buffer += i; |
321 | size -= i; | ||
322 | |||
323 | if (size > 0) { | ||
324 | retval = usb_parse_ss_endpoint_companion(ddev, cfgno, | ||
325 | inum, asnum, endpoint, num_ep, buffer, | ||
326 | size); | ||
327 | if (retval >= 0) { | ||
328 | buffer += retval; | ||
329 | retval = buffer - buffer0; | ||
330 | } | ||
331 | } else { | ||
332 | retval = buffer - buffer0; | ||
333 | } | ||
334 | } else { | ||
335 | /* Skip over any Class Specific or Vendor Specific descriptors; | ||
336 | * find the next endpoint or interface descriptor */ | ||
337 | endpoint->extra = buffer; | ||
338 | i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT, | ||
339 | USB_DT_INTERFACE, &n); | ||
340 | endpoint->extralen = i; | ||
341 | retval = buffer - buffer0 + i; | ||
342 | } | ||
171 | if (n > 0) | 343 | if (n > 0) |
172 | dev_dbg(ddev, "skipped %d descriptor%s after %s\n", | 344 | dev_dbg(ddev, "skipped %d descriptor%s after %s\n", |
173 | n, plural(n), "endpoint"); | 345 | n, plural(n), "endpoint"); |
174 | return buffer - buffer0 + i; | 346 | return retval; |
175 | 347 | ||
176 | skip_to_next_endpoint_or_interface_descriptor: | 348 | skip_to_next_endpoint_or_interface_descriptor: |
177 | i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT, | 349 | i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT, |
@@ -452,6 +624,8 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx, | |||
452 | kref_init(&intfc->ref); | 624 | kref_init(&intfc->ref); |
453 | } | 625 | } |
454 | 626 | ||
627 | /* FIXME: parse the BOS descriptor */ | ||
628 | |||
455 | /* Skip over any Class Specific or Vendor Specific descriptors; | 629 | /* Skip over any Class Specific or Vendor Specific descriptors; |
456 | * find the first interface descriptor */ | 630 | * find the first interface descriptor */ |
457 | config->extra = buffer; | 631 | config->extra = buffer; |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index d0a21a5f820..69e5773abfc 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -154,16 +154,11 @@ static const struct usb_device_id *usb_match_dynamic_id(struct usb_interface *in | |||
154 | static int usb_probe_device(struct device *dev) | 154 | static int usb_probe_device(struct device *dev) |
155 | { | 155 | { |
156 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); | 156 | struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); |
157 | struct usb_device *udev; | 157 | struct usb_device *udev = to_usb_device(dev); |
158 | int error = -ENODEV; | 158 | int error = -ENODEV; |
159 | 159 | ||
160 | dev_dbg(dev, "%s\n", __func__); | 160 | dev_dbg(dev, "%s\n", __func__); |
161 | 161 | ||
162 | if (!is_usb_device(dev)) /* Sanity check */ | ||
163 | return error; | ||
164 | |||
165 | udev = to_usb_device(dev); | ||
166 | |||
167 | /* TODO: Add real matching code */ | 162 | /* TODO: Add real matching code */ |
168 | 163 | ||
169 | /* The device should always appear to be in use | 164 | /* The device should always appear to be in use |
@@ -203,18 +198,13 @@ static void usb_cancel_queued_reset(struct usb_interface *iface) | |||
203 | static int usb_probe_interface(struct device *dev) | 198 | static int usb_probe_interface(struct device *dev) |
204 | { | 199 | { |
205 | struct usb_driver *driver = to_usb_driver(dev->driver); | 200 | struct usb_driver *driver = to_usb_driver(dev->driver); |
206 | struct usb_interface *intf; | 201 | struct usb_interface *intf = to_usb_interface(dev); |
207 | struct usb_device *udev; | 202 | struct usb_device *udev = interface_to_usbdev(intf); |
208 | const struct usb_device_id *id; | 203 | const struct usb_device_id *id; |
209 | int error = -ENODEV; | 204 | int error = -ENODEV; |
210 | 205 | ||
211 | dev_dbg(dev, "%s\n", __func__); | 206 | dev_dbg(dev, "%s\n", __func__); |
212 | 207 | ||
213 | if (is_usb_device(dev)) /* Sanity check */ | ||
214 | return error; | ||
215 | |||
216 | intf = to_usb_interface(dev); | ||
217 | udev = interface_to_usbdev(intf); | ||
218 | intf->needs_binding = 0; | 208 | intf->needs_binding = 0; |
219 | 209 | ||
220 | if (udev->authorized == 0) { | 210 | if (udev->authorized == 0) { |
@@ -385,7 +375,6 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
385 | struct usb_interface *iface) | 375 | struct usb_interface *iface) |
386 | { | 376 | { |
387 | struct device *dev = &iface->dev; | 377 | struct device *dev = &iface->dev; |
388 | struct usb_device *udev = interface_to_usbdev(iface); | ||
389 | 378 | ||
390 | /* this should never happen, don't release something that's not ours */ | 379 | /* this should never happen, don't release something that's not ours */ |
391 | if (!dev->driver || dev->driver != &driver->drvwrap.driver) | 380 | if (!dev->driver || dev->driver != &driver->drvwrap.driver) |
@@ -394,23 +383,19 @@ void usb_driver_release_interface(struct usb_driver *driver, | |||
394 | /* don't release from within disconnect() */ | 383 | /* don't release from within disconnect() */ |
395 | if (iface->condition != USB_INTERFACE_BOUND) | 384 | if (iface->condition != USB_INTERFACE_BOUND) |
396 | return; | 385 | return; |
386 | iface->condition = USB_INTERFACE_UNBINDING; | ||
397 | 387 | ||
398 | /* don't release if the interface hasn't been added yet */ | 388 | /* Release via the driver core only if the interface |
389 | * has already been registered | ||
390 | */ | ||
399 | if (device_is_registered(dev)) { | 391 | if (device_is_registered(dev)) { |
400 | iface->condition = USB_INTERFACE_UNBINDING; | ||
401 | device_release_driver(dev); | 392 | device_release_driver(dev); |
402 | } else { | 393 | } else { |
403 | iface->condition = USB_INTERFACE_UNBOUND; | 394 | down(&dev->sem); |
404 | usb_cancel_queued_reset(iface); | 395 | usb_unbind_interface(dev); |
396 | dev->driver = NULL; | ||
397 | up(&dev->sem); | ||
405 | } | 398 | } |
406 | dev->driver = NULL; | ||
407 | usb_set_intfdata(iface, NULL); | ||
408 | |||
409 | usb_pm_lock(udev); | ||
410 | iface->condition = USB_INTERFACE_UNBOUND; | ||
411 | mark_quiesced(iface); | ||
412 | iface->needs_remote_wakeup = 0; | ||
413 | usb_pm_unlock(udev); | ||
414 | } | 399 | } |
415 | EXPORT_SYMBOL_GPL(usb_driver_release_interface); | 400 | EXPORT_SYMBOL_GPL(usb_driver_release_interface); |
416 | 401 | ||
@@ -598,7 +583,7 @@ static int usb_device_match(struct device *dev, struct device_driver *drv) | |||
598 | /* TODO: Add real matching code */ | 583 | /* TODO: Add real matching code */ |
599 | return 1; | 584 | return 1; |
600 | 585 | ||
601 | } else { | 586 | } else if (is_usb_interface(dev)) { |
602 | struct usb_interface *intf; | 587 | struct usb_interface *intf; |
603 | struct usb_driver *usb_drv; | 588 | struct usb_driver *usb_drv; |
604 | const struct usb_device_id *id; | 589 | const struct usb_device_id *id; |
@@ -630,11 +615,14 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
630 | /* driver is often null here; dev_dbg() would oops */ | 615 | /* driver is often null here; dev_dbg() would oops */ |
631 | pr_debug("usb %s: uevent\n", dev_name(dev)); | 616 | pr_debug("usb %s: uevent\n", dev_name(dev)); |
632 | 617 | ||
633 | if (is_usb_device(dev)) | 618 | if (is_usb_device(dev)) { |
634 | usb_dev = to_usb_device(dev); | 619 | usb_dev = to_usb_device(dev); |
635 | else { | 620 | } else if (is_usb_interface(dev)) { |
636 | struct usb_interface *intf = to_usb_interface(dev); | 621 | struct usb_interface *intf = to_usb_interface(dev); |
622 | |||
637 | usb_dev = interface_to_usbdev(intf); | 623 | usb_dev = interface_to_usbdev(intf); |
624 | } else { | ||
625 | return 0; | ||
638 | } | 626 | } |
639 | 627 | ||
640 | if (usb_dev->devnum < 0) { | 628 | if (usb_dev->devnum < 0) { |
@@ -1762,6 +1750,7 @@ int usb_suspend(struct device *dev, pm_message_t msg) | |||
1762 | int usb_resume(struct device *dev, pm_message_t msg) | 1750 | int usb_resume(struct device *dev, pm_message_t msg) |
1763 | { | 1751 | { |
1764 | struct usb_device *udev; | 1752 | struct usb_device *udev; |
1753 | int status; | ||
1765 | 1754 | ||
1766 | udev = to_usb_device(dev); | 1755 | udev = to_usb_device(dev); |
1767 | 1756 | ||
@@ -1771,7 +1760,14 @@ int usb_resume(struct device *dev, pm_message_t msg) | |||
1771 | */ | 1760 | */ |
1772 | if (udev->skip_sys_resume) | 1761 | if (udev->skip_sys_resume) |
1773 | return 0; | 1762 | return 0; |
1774 | return usb_external_resume_device(udev, msg); | 1763 | status = usb_external_resume_device(udev, msg); |
1764 | |||
1765 | /* Avoid PM error messages for devices disconnected while suspended | ||
1766 | * as we'll display regular disconnect messages just a bit later. | ||
1767 | */ | ||
1768 | if (status == -ENODEV) | ||
1769 | return 0; | ||
1770 | return status; | ||
1775 | } | 1771 | } |
1776 | 1772 | ||
1777 | #endif /* CONFIG_PM */ | 1773 | #endif /* CONFIG_PM */ |
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index 40dee2ac013..bc39fc40bbd 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c | |||
@@ -15,19 +15,18 @@ | |||
15 | #include <linux/usb.h> | 15 | #include <linux/usb.h> |
16 | #include "usb.h" | 16 | #include "usb.h" |
17 | 17 | ||
18 | #define MAX_ENDPOINT_MINORS (64*128*32) | ||
19 | static int usb_endpoint_major; | ||
20 | static DEFINE_IDR(endpoint_idr); | ||
21 | |||
22 | struct ep_device { | 18 | struct ep_device { |
23 | struct usb_endpoint_descriptor *desc; | 19 | struct usb_endpoint_descriptor *desc; |
24 | struct usb_device *udev; | 20 | struct usb_device *udev; |
25 | struct device dev; | 21 | struct device dev; |
26 | int minor; | ||
27 | }; | 22 | }; |
28 | #define to_ep_device(_dev) \ | 23 | #define to_ep_device(_dev) \ |
29 | container_of(_dev, struct ep_device, dev) | 24 | container_of(_dev, struct ep_device, dev) |
30 | 25 | ||
26 | struct device_type usb_ep_device_type = { | ||
27 | .name = "usb_endpoint", | ||
28 | }; | ||
29 | |||
31 | struct ep_attribute { | 30 | struct ep_attribute { |
32 | struct attribute attr; | 31 | struct attribute attr; |
33 | ssize_t (*show)(struct usb_device *, | 32 | ssize_t (*show)(struct usb_device *, |
@@ -160,118 +159,10 @@ static struct attribute_group *ep_dev_groups[] = { | |||
160 | NULL | 159 | NULL |
161 | }; | 160 | }; |
162 | 161 | ||
163 | static int usb_endpoint_major_init(void) | ||
164 | { | ||
165 | dev_t dev; | ||
166 | int error; | ||
167 | |||
168 | error = alloc_chrdev_region(&dev, 0, MAX_ENDPOINT_MINORS, | ||
169 | "usb_endpoint"); | ||
170 | if (error) { | ||
171 | printk(KERN_ERR "Unable to get a dynamic major for " | ||
172 | "usb endpoints.\n"); | ||
173 | return error; | ||
174 | } | ||
175 | usb_endpoint_major = MAJOR(dev); | ||
176 | |||
177 | return error; | ||
178 | } | ||
179 | |||
180 | static void usb_endpoint_major_cleanup(void) | ||
181 | { | ||
182 | unregister_chrdev_region(MKDEV(usb_endpoint_major, 0), | ||
183 | MAX_ENDPOINT_MINORS); | ||
184 | } | ||
185 | |||
186 | static int endpoint_get_minor(struct ep_device *ep_dev) | ||
187 | { | ||
188 | static DEFINE_MUTEX(minor_lock); | ||
189 | int retval = -ENOMEM; | ||
190 | int id; | ||
191 | |||
192 | mutex_lock(&minor_lock); | ||
193 | if (idr_pre_get(&endpoint_idr, GFP_KERNEL) == 0) | ||
194 | goto exit; | ||
195 | |||
196 | retval = idr_get_new(&endpoint_idr, ep_dev, &id); | ||
197 | if (retval < 0) { | ||
198 | if (retval == -EAGAIN) | ||
199 | retval = -ENOMEM; | ||
200 | goto exit; | ||
201 | } | ||
202 | ep_dev->minor = id & MAX_ID_MASK; | ||
203 | exit: | ||
204 | mutex_unlock(&minor_lock); | ||
205 | return retval; | ||
206 | } | ||
207 | |||
208 | static void endpoint_free_minor(struct ep_device *ep_dev) | ||
209 | { | ||
210 | idr_remove(&endpoint_idr, ep_dev->minor); | ||
211 | } | ||
212 | |||
213 | static struct endpoint_class { | ||
214 | struct kref kref; | ||
215 | struct class *class; | ||
216 | } *ep_class; | ||
217 | |||
218 | static int init_endpoint_class(void) | ||
219 | { | ||
220 | int result = 0; | ||
221 | |||
222 | if (ep_class != NULL) { | ||
223 | kref_get(&ep_class->kref); | ||
224 | goto exit; | ||
225 | } | ||
226 | |||
227 | ep_class = kmalloc(sizeof(*ep_class), GFP_KERNEL); | ||
228 | if (!ep_class) { | ||
229 | result = -ENOMEM; | ||
230 | goto exit; | ||
231 | } | ||
232 | |||
233 | kref_init(&ep_class->kref); | ||
234 | ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); | ||
235 | if (IS_ERR(ep_class->class)) { | ||
236 | result = PTR_ERR(ep_class->class); | ||
237 | goto class_create_error; | ||
238 | } | ||
239 | |||
240 | result = usb_endpoint_major_init(); | ||
241 | if (result) | ||
242 | goto endpoint_major_error; | ||
243 | |||
244 | goto exit; | ||
245 | |||
246 | endpoint_major_error: | ||
247 | class_destroy(ep_class->class); | ||
248 | class_create_error: | ||
249 | kfree(ep_class); | ||
250 | ep_class = NULL; | ||
251 | exit: | ||
252 | return result; | ||
253 | } | ||
254 | |||
255 | static void release_endpoint_class(struct kref *kref) | ||
256 | { | ||
257 | /* Ok, we cheat as we know we only have one ep_class */ | ||
258 | class_destroy(ep_class->class); | ||
259 | kfree(ep_class); | ||
260 | ep_class = NULL; | ||
261 | usb_endpoint_major_cleanup(); | ||
262 | } | ||
263 | |||
264 | static void destroy_endpoint_class(void) | ||
265 | { | ||
266 | if (ep_class) | ||
267 | kref_put(&ep_class->kref, release_endpoint_class); | ||
268 | } | ||
269 | |||
270 | static void ep_device_release(struct device *dev) | 162 | static void ep_device_release(struct device *dev) |
271 | { | 163 | { |
272 | struct ep_device *ep_dev = to_ep_device(dev); | 164 | struct ep_device *ep_dev = to_ep_device(dev); |
273 | 165 | ||
274 | endpoint_free_minor(ep_dev); | ||
275 | kfree(ep_dev); | 166 | kfree(ep_dev); |
276 | } | 167 | } |
277 | 168 | ||
@@ -279,62 +170,32 @@ int usb_create_ep_devs(struct device *parent, | |||
279 | struct usb_host_endpoint *endpoint, | 170 | struct usb_host_endpoint *endpoint, |
280 | struct usb_device *udev) | 171 | struct usb_device *udev) |
281 | { | 172 | { |
282 | char name[8]; | ||
283 | struct ep_device *ep_dev; | 173 | struct ep_device *ep_dev; |
284 | int retval; | 174 | int retval; |
285 | 175 | ||
286 | retval = init_endpoint_class(); | ||
287 | if (retval) | ||
288 | goto exit; | ||
289 | |||
290 | ep_dev = kzalloc(sizeof(*ep_dev), GFP_KERNEL); | 176 | ep_dev = kzalloc(sizeof(*ep_dev), GFP_KERNEL); |
291 | if (!ep_dev) { | 177 | if (!ep_dev) { |
292 | retval = -ENOMEM; | 178 | retval = -ENOMEM; |
293 | goto error_alloc; | 179 | goto exit; |
294 | } | ||
295 | |||
296 | retval = endpoint_get_minor(ep_dev); | ||
297 | if (retval) { | ||
298 | dev_err(parent, "can not allocate minor number for %s\n", | ||
299 | dev_name(&ep_dev->dev)); | ||
300 | goto error_register; | ||
301 | } | 180 | } |
302 | 181 | ||
303 | ep_dev->desc = &endpoint->desc; | 182 | ep_dev->desc = &endpoint->desc; |
304 | ep_dev->udev = udev; | 183 | ep_dev->udev = udev; |
305 | ep_dev->dev.groups = ep_dev_groups; | 184 | ep_dev->dev.groups = ep_dev_groups; |
306 | ep_dev->dev.devt = MKDEV(usb_endpoint_major, ep_dev->minor); | 185 | ep_dev->dev.type = &usb_ep_device_type; |
307 | ep_dev->dev.class = ep_class->class; | ||
308 | ep_dev->dev.parent = parent; | 186 | ep_dev->dev.parent = parent; |
309 | ep_dev->dev.release = ep_device_release; | 187 | ep_dev->dev.release = ep_device_release; |
310 | dev_set_name(&ep_dev->dev, "usbdev%d.%d_ep%02x", | 188 | dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); |
311 | udev->bus->busnum, udev->devnum, | ||
312 | endpoint->desc.bEndpointAddress); | ||
313 | 189 | ||
314 | retval = device_register(&ep_dev->dev); | 190 | retval = device_register(&ep_dev->dev); |
315 | if (retval) | 191 | if (retval) |
316 | goto error_chrdev; | 192 | goto error_register; |
317 | 193 | ||
318 | /* create the symlink to the old-style "ep_XX" directory */ | ||
319 | sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); | ||
320 | retval = sysfs_create_link(&parent->kobj, &ep_dev->dev.kobj, name); | ||
321 | if (retval) | ||
322 | goto error_link; | ||
323 | endpoint->ep_dev = ep_dev; | 194 | endpoint->ep_dev = ep_dev; |
324 | return retval; | 195 | return retval; |
325 | 196 | ||
326 | error_link: | ||
327 | device_unregister(&ep_dev->dev); | ||
328 | destroy_endpoint_class(); | ||
329 | return retval; | ||
330 | |||
331 | error_chrdev: | ||
332 | endpoint_free_minor(ep_dev); | ||
333 | |||
334 | error_register: | 197 | error_register: |
335 | kfree(ep_dev); | 198 | kfree(ep_dev); |
336 | error_alloc: | ||
337 | destroy_endpoint_class(); | ||
338 | exit: | 199 | exit: |
339 | return retval; | 200 | return retval; |
340 | } | 201 | } |
@@ -344,12 +205,7 @@ void usb_remove_ep_devs(struct usb_host_endpoint *endpoint) | |||
344 | struct ep_device *ep_dev = endpoint->ep_dev; | 205 | struct ep_device *ep_dev = endpoint->ep_dev; |
345 | 206 | ||
346 | if (ep_dev) { | 207 | if (ep_dev) { |
347 | char name[8]; | ||
348 | |||
349 | sprintf(name, "ep_%02x", endpoint->desc.bEndpointAddress); | ||
350 | sysfs_remove_link(&ep_dev->dev.parent->kobj, name); | ||
351 | device_unregister(&ep_dev->dev); | 208 | device_unregister(&ep_dev->dev); |
352 | endpoint->ep_dev = NULL; | 209 | endpoint->ep_dev = NULL; |
353 | destroy_endpoint_class(); | ||
354 | } | 210 | } |
355 | } | 211 | } |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index a4301dc02d2..91f2885b6ee 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -185,194 +185,198 @@ void usb_hcd_pci_remove(struct pci_dev *dev) | |||
185 | } | 185 | } |
186 | EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); | 186 | EXPORT_SYMBOL_GPL(usb_hcd_pci_remove); |
187 | 187 | ||
188 | |||
189 | #ifdef CONFIG_PM | ||
190 | |||
191 | /** | 188 | /** |
192 | * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD | 189 | * usb_hcd_pci_shutdown - shutdown host controller |
193 | * @dev: USB Host Controller being suspended | 190 | * @dev: USB Host Controller being shutdown |
194 | * @message: Power Management message describing this state transition | ||
195 | * | ||
196 | * Store this function in the HCD's struct pci_driver as .suspend. | ||
197 | */ | 191 | */ |
198 | int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t message) | 192 | void usb_hcd_pci_shutdown(struct pci_dev *dev) |
193 | { | ||
194 | struct usb_hcd *hcd; | ||
195 | |||
196 | hcd = pci_get_drvdata(dev); | ||
197 | if (!hcd) | ||
198 | return; | ||
199 | |||
200 | if (hcd->driver->shutdown) | ||
201 | hcd->driver->shutdown(hcd); | ||
202 | } | ||
203 | EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); | ||
204 | |||
205 | #ifdef CONFIG_PM_SLEEP | ||
206 | |||
207 | static int check_root_hub_suspended(struct device *dev) | ||
208 | { | ||
209 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
210 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | ||
211 | |||
212 | if (!(hcd->state == HC_STATE_SUSPENDED || | ||
213 | hcd->state == HC_STATE_HALT)) { | ||
214 | dev_warn(dev, "Root hub is not suspended\n"); | ||
215 | return -EBUSY; | ||
216 | } | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static int hcd_pci_suspend(struct device *dev) | ||
199 | { | 221 | { |
200 | struct usb_hcd *hcd = pci_get_drvdata(dev); | 222 | struct pci_dev *pci_dev = to_pci_dev(dev); |
201 | int retval = 0; | 223 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
202 | int wake, w; | 224 | int retval; |
203 | int has_pci_pm; | ||
204 | 225 | ||
205 | /* Root hub suspend should have stopped all downstream traffic, | 226 | /* Root hub suspend should have stopped all downstream traffic, |
206 | * and all bus master traffic. And done so for both the interface | 227 | * and all bus master traffic. And done so for both the interface |
207 | * and the stub usb_device (which we check here). But maybe it | 228 | * and the stub usb_device (which we check here). But maybe it |
208 | * didn't; writing sysfs power/state files ignores such rules... | 229 | * didn't; writing sysfs power/state files ignores such rules... |
209 | * | ||
210 | * We must ignore the FREEZE vs SUSPEND distinction here, because | ||
211 | * otherwise the swsusp will save (and restore) garbage state. | ||
212 | */ | 230 | */ |
213 | if (!(hcd->state == HC_STATE_SUSPENDED || | 231 | retval = check_root_hub_suspended(dev); |
214 | hcd->state == HC_STATE_HALT)) { | 232 | if (retval) |
215 | dev_warn(&dev->dev, "Root hub is not suspended\n"); | 233 | return retval; |
216 | retval = -EBUSY; | ||
217 | goto done; | ||
218 | } | ||
219 | 234 | ||
220 | /* We might already be suspended (runtime PM -- not yet written) */ | 235 | /* We might already be suspended (runtime PM -- not yet written) */ |
221 | if (dev->current_state != PCI_D0) | 236 | if (pci_dev->current_state != PCI_D0) |
222 | goto done; | 237 | return retval; |
223 | 238 | ||
224 | if (hcd->driver->pci_suspend) { | 239 | if (hcd->driver->pci_suspend) { |
225 | retval = hcd->driver->pci_suspend(hcd, message); | 240 | retval = hcd->driver->pci_suspend(hcd); |
226 | suspend_report_result(hcd->driver->pci_suspend, retval); | 241 | suspend_report_result(hcd->driver->pci_suspend, retval); |
227 | if (retval) | 242 | if (retval) |
228 | goto done; | 243 | return retval; |
229 | } | 244 | } |
230 | 245 | ||
231 | synchronize_irq(dev->irq); | 246 | synchronize_irq(pci_dev->irq); |
232 | 247 | ||
233 | /* Downstream ports from this root hub should already be quiesced, so | 248 | /* Downstream ports from this root hub should already be quiesced, so |
234 | * there will be no DMA activity. Now we can shut down the upstream | 249 | * there will be no DMA activity. Now we can shut down the upstream |
235 | * link (except maybe for PME# resume signaling) and enter some PCI | 250 | * link (except maybe for PME# resume signaling). We'll enter a |
236 | * low power state, if the hardware allows. | 251 | * low power state during suspend_noirq, if the hardware allows. |
237 | */ | 252 | */ |
238 | pci_disable_device(dev); | 253 | pci_disable_device(pci_dev); |
254 | return retval; | ||
255 | } | ||
256 | |||
257 | static int hcd_pci_suspend_noirq(struct device *dev) | ||
258 | { | ||
259 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
260 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | ||
261 | int retval; | ||
262 | |||
263 | retval = check_root_hub_suspended(dev); | ||
264 | if (retval) | ||
265 | return retval; | ||
239 | 266 | ||
240 | pci_save_state(dev); | 267 | pci_save_state(pci_dev); |
241 | 268 | ||
242 | /* Don't fail on error to enable wakeup. We rely on pci code | 269 | /* If the root hub is HALTed rather than SUSPENDed, |
243 | * to reject requests the hardware can't implement, rather | 270 | * disallow remote wakeup. |
244 | * than coding the same thing. | ||
245 | */ | 271 | */ |
246 | wake = (hcd->state == HC_STATE_SUSPENDED && | 272 | if (hcd->state == HC_STATE_HALT) |
247 | device_may_wakeup(&dev->dev)); | 273 | device_set_wakeup_enable(dev, 0); |
248 | w = pci_wake_from_d3(dev, wake); | 274 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); |
249 | if (w < 0) | ||
250 | wake = w; | ||
251 | dev_dbg(&dev->dev, "wakeup: %d\n", wake); | ||
252 | |||
253 | /* Don't change state if we don't need to */ | ||
254 | if (message.event == PM_EVENT_FREEZE || | ||
255 | message.event == PM_EVENT_PRETHAW) { | ||
256 | dev_dbg(&dev->dev, "--> no state change\n"); | ||
257 | goto done; | ||
258 | } | ||
259 | 275 | ||
260 | has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); | 276 | /* Possibly enable remote wakeup, |
261 | if (!has_pci_pm) { | 277 | * choose the appropriate low-power state, and go to that state. |
262 | dev_dbg(&dev->dev, "--> PCI D0 legacy\n"); | 278 | */ |
279 | retval = pci_prepare_to_sleep(pci_dev); | ||
280 | if (retval == -EIO) { /* Low-power not supported */ | ||
281 | dev_dbg(dev, "--> PCI D0 legacy\n"); | ||
282 | retval = 0; | ||
283 | } else if (retval == 0) { | ||
284 | dev_dbg(dev, "--> PCI %s\n", | ||
285 | pci_power_name(pci_dev->current_state)); | ||
263 | } else { | 286 | } else { |
264 | 287 | suspend_report_result(pci_prepare_to_sleep, retval); | |
265 | /* NOTE: dev->current_state becomes nonzero only here, and | 288 | return retval; |
266 | * only for devices that support PCI PM. Also, exiting | ||
267 | * PCI_D3 (but not PCI_D1 or PCI_D2) is allowed to reset | ||
268 | * some device state (e.g. as part of clock reinit). | ||
269 | */ | ||
270 | retval = pci_set_power_state(dev, PCI_D3hot); | ||
271 | suspend_report_result(pci_set_power_state, retval); | ||
272 | if (retval == 0) { | ||
273 | dev_dbg(&dev->dev, "--> PCI D3\n"); | ||
274 | } else { | ||
275 | dev_dbg(&dev->dev, "PCI D3 suspend fail, %d\n", | ||
276 | retval); | ||
277 | pci_restore_state(dev); | ||
278 | } | ||
279 | } | 289 | } |
280 | 290 | ||
281 | #ifdef CONFIG_PPC_PMAC | 291 | #ifdef CONFIG_PPC_PMAC |
282 | if (retval == 0) { | 292 | /* Disable ASIC clocks for USB */ |
283 | /* Disable ASIC clocks for USB */ | 293 | if (machine_is(powermac)) { |
284 | if (machine_is(powermac)) { | 294 | struct device_node *of_node; |
285 | struct device_node *of_node; | 295 | |
286 | 296 | of_node = pci_device_to_OF_node(pci_dev); | |
287 | of_node = pci_device_to_OF_node(dev); | 297 | if (of_node) |
288 | if (of_node) | 298 | pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0); |
289 | pmac_call_feature(PMAC_FTR_USB_ENABLE, | ||
290 | of_node, 0, 0); | ||
291 | } | ||
292 | } | 299 | } |
293 | #endif | 300 | #endif |
294 | |||
295 | done: | ||
296 | return retval; | 301 | return retval; |
297 | } | 302 | } |
298 | EXPORT_SYMBOL_GPL(usb_hcd_pci_suspend); | ||
299 | 303 | ||
300 | /** | 304 | static int hcd_pci_resume_noirq(struct device *dev) |
301 | * usb_hcd_pci_resume - power management resume of a PCI-based HCD | ||
302 | * @dev: USB Host Controller being resumed | ||
303 | * | ||
304 | * Store this function in the HCD's struct pci_driver as .resume. | ||
305 | */ | ||
306 | int usb_hcd_pci_resume(struct pci_dev *dev) | ||
307 | { | 305 | { |
308 | struct usb_hcd *hcd; | 306 | struct pci_dev *pci_dev = to_pci_dev(dev); |
309 | int retval; | ||
310 | 307 | ||
311 | #ifdef CONFIG_PPC_PMAC | 308 | #ifdef CONFIG_PPC_PMAC |
312 | /* Reenable ASIC clocks for USB */ | 309 | /* Reenable ASIC clocks for USB */ |
313 | if (machine_is(powermac)) { | 310 | if (machine_is(powermac)) { |
314 | struct device_node *of_node; | 311 | struct device_node *of_node; |
315 | 312 | ||
316 | of_node = pci_device_to_OF_node(dev); | 313 | of_node = pci_device_to_OF_node(pci_dev); |
317 | if (of_node) | 314 | if (of_node) |
318 | pmac_call_feature(PMAC_FTR_USB_ENABLE, | 315 | pmac_call_feature(PMAC_FTR_USB_ENABLE, |
319 | of_node, 0, 1); | 316 | of_node, 0, 1); |
320 | } | 317 | } |
321 | #endif | 318 | #endif |
322 | 319 | ||
323 | pci_restore_state(dev); | 320 | /* Go back to D0 and disable remote wakeup */ |
321 | pci_back_from_sleep(pci_dev); | ||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static int resume_common(struct device *dev, bool hibernated) | ||
326 | { | ||
327 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
328 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | ||
329 | int retval; | ||
324 | 330 | ||
325 | hcd = pci_get_drvdata(dev); | ||
326 | if (hcd->state != HC_STATE_SUSPENDED) { | 331 | if (hcd->state != HC_STATE_SUSPENDED) { |
327 | dev_dbg(hcd->self.controller, | 332 | dev_dbg(dev, "can't resume, not suspended!\n"); |
328 | "can't resume, not suspended!\n"); | ||
329 | return 0; | 333 | return 0; |
330 | } | 334 | } |
331 | 335 | ||
332 | pci_enable_wake(dev, PCI_D0, false); | 336 | retval = pci_enable_device(pci_dev); |
333 | |||
334 | retval = pci_enable_device(dev); | ||
335 | if (retval < 0) { | 337 | if (retval < 0) { |
336 | dev_err(&dev->dev, "can't re-enable after resume, %d!\n", | 338 | dev_err(dev, "can't re-enable after resume, %d!\n", retval); |
337 | retval); | ||
338 | return retval; | 339 | return retval; |
339 | } | 340 | } |
340 | 341 | ||
341 | pci_set_master(dev); | 342 | pci_set_master(pci_dev); |
342 | |||
343 | /* yes, ignore this result too... */ | ||
344 | (void) pci_wake_from_d3(dev, 0); | ||
345 | 343 | ||
346 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 344 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
347 | 345 | ||
348 | if (hcd->driver->pci_resume) { | 346 | if (hcd->driver->pci_resume) { |
349 | retval = hcd->driver->pci_resume(hcd); | 347 | retval = hcd->driver->pci_resume(hcd, hibernated); |
350 | if (retval) { | 348 | if (retval) { |
351 | dev_err(hcd->self.controller, | 349 | dev_err(dev, "PCI post-resume error %d!\n", retval); |
352 | "PCI post-resume error %d!\n", retval); | ||
353 | usb_hc_died(hcd); | 350 | usb_hc_died(hcd); |
354 | } | 351 | } |
355 | } | 352 | } |
356 | return retval; | 353 | return retval; |
357 | } | 354 | } |
358 | EXPORT_SYMBOL_GPL(usb_hcd_pci_resume); | ||
359 | 355 | ||
360 | #endif /* CONFIG_PM */ | 356 | static int hcd_pci_resume(struct device *dev) |
361 | |||
362 | /** | ||
363 | * usb_hcd_pci_shutdown - shutdown host controller | ||
364 | * @dev: USB Host Controller being shutdown | ||
365 | */ | ||
366 | void usb_hcd_pci_shutdown(struct pci_dev *dev) | ||
367 | { | 357 | { |
368 | struct usb_hcd *hcd; | 358 | return resume_common(dev, false); |
369 | 359 | } | |
370 | hcd = pci_get_drvdata(dev); | ||
371 | if (!hcd) | ||
372 | return; | ||
373 | 360 | ||
374 | if (hcd->driver->shutdown) | 361 | static int hcd_pci_restore(struct device *dev) |
375 | hcd->driver->shutdown(hcd); | 362 | { |
363 | return resume_common(dev, true); | ||
376 | } | 364 | } |
377 | EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); | ||
378 | 365 | ||
366 | struct dev_pm_ops usb_hcd_pci_pm_ops = { | ||
367 | .suspend = hcd_pci_suspend, | ||
368 | .suspend_noirq = hcd_pci_suspend_noirq, | ||
369 | .resume_noirq = hcd_pci_resume_noirq, | ||
370 | .resume = hcd_pci_resume, | ||
371 | .freeze = check_root_hub_suspended, | ||
372 | .freeze_noirq = check_root_hub_suspended, | ||
373 | .thaw_noirq = NULL, | ||
374 | .thaw = NULL, | ||
375 | .poweroff = hcd_pci_suspend, | ||
376 | .poweroff_noirq = hcd_pci_suspend_noirq, | ||
377 | .restore_noirq = hcd_pci_resume_noirq, | ||
378 | .restore = hcd_pci_restore, | ||
379 | }; | ||
380 | EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); | ||
381 | |||
382 | #endif /* CONFIG_PM_SLEEP */ | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 42b93da1085..ce3f453f02e 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -128,6 +128,27 @@ static inline int is_root_hub(struct usb_device *udev) | |||
128 | #define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff) | 128 | #define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff) |
129 | #define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff) | 129 | #define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff) |
130 | 130 | ||
131 | /* usb 3.0 root hub device descriptor */ | ||
132 | static const u8 usb3_rh_dev_descriptor[18] = { | ||
133 | 0x12, /* __u8 bLength; */ | ||
134 | 0x01, /* __u8 bDescriptorType; Device */ | ||
135 | 0x00, 0x03, /* __le16 bcdUSB; v3.0 */ | ||
136 | |||
137 | 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ | ||
138 | 0x00, /* __u8 bDeviceSubClass; */ | ||
139 | 0x03, /* __u8 bDeviceProtocol; USB 3.0 hub */ | ||
140 | 0x09, /* __u8 bMaxPacketSize0; 2^9 = 512 Bytes */ | ||
141 | |||
142 | 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ | ||
143 | 0x02, 0x00, /* __le16 idProduct; device 0x0002 */ | ||
144 | KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ | ||
145 | |||
146 | 0x03, /* __u8 iManufacturer; */ | ||
147 | 0x02, /* __u8 iProduct; */ | ||
148 | 0x01, /* __u8 iSerialNumber; */ | ||
149 | 0x01 /* __u8 bNumConfigurations; */ | ||
150 | }; | ||
151 | |||
131 | /* usb 2.0 root hub device descriptor */ | 152 | /* usb 2.0 root hub device descriptor */ |
132 | static const u8 usb2_rh_dev_descriptor [18] = { | 153 | static const u8 usb2_rh_dev_descriptor [18] = { |
133 | 0x12, /* __u8 bLength; */ | 154 | 0x12, /* __u8 bLength; */ |
@@ -273,6 +294,47 @@ static const u8 hs_rh_config_descriptor [] = { | |||
273 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ | 294 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ |
274 | }; | 295 | }; |
275 | 296 | ||
297 | static const u8 ss_rh_config_descriptor[] = { | ||
298 | /* one configuration */ | ||
299 | 0x09, /* __u8 bLength; */ | ||
300 | 0x02, /* __u8 bDescriptorType; Configuration */ | ||
301 | 0x19, 0x00, /* __le16 wTotalLength; FIXME */ | ||
302 | 0x01, /* __u8 bNumInterfaces; (1) */ | ||
303 | 0x01, /* __u8 bConfigurationValue; */ | ||
304 | 0x00, /* __u8 iConfiguration; */ | ||
305 | 0xc0, /* __u8 bmAttributes; | ||
306 | Bit 7: must be set, | ||
307 | 6: Self-powered, | ||
308 | 5: Remote wakeup, | ||
309 | 4..0: resvd */ | ||
310 | 0x00, /* __u8 MaxPower; */ | ||
311 | |||
312 | /* one interface */ | ||
313 | 0x09, /* __u8 if_bLength; */ | ||
314 | 0x04, /* __u8 if_bDescriptorType; Interface */ | ||
315 | 0x00, /* __u8 if_bInterfaceNumber; */ | ||
316 | 0x00, /* __u8 if_bAlternateSetting; */ | ||
317 | 0x01, /* __u8 if_bNumEndpoints; */ | ||
318 | 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */ | ||
319 | 0x00, /* __u8 if_bInterfaceSubClass; */ | ||
320 | 0x00, /* __u8 if_bInterfaceProtocol; */ | ||
321 | 0x00, /* __u8 if_iInterface; */ | ||
322 | |||
323 | /* one endpoint (status change endpoint) */ | ||
324 | 0x07, /* __u8 ep_bLength; */ | ||
325 | 0x05, /* __u8 ep_bDescriptorType; Endpoint */ | ||
326 | 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ | ||
327 | 0x03, /* __u8 ep_bmAttributes; Interrupt */ | ||
328 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) | ||
329 | * see hub.c:hub_configure() for details. */ | ||
330 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, | ||
331 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ | ||
332 | /* | ||
333 | * All 3.0 hubs should have an endpoint companion descriptor, | ||
334 | * but we're ignoring that for now. FIXME? | ||
335 | */ | ||
336 | }; | ||
337 | |||
276 | /*-------------------------------------------------------------------------*/ | 338 | /*-------------------------------------------------------------------------*/ |
277 | 339 | ||
278 | /* | 340 | /* |
@@ -426,23 +488,39 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
426 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | 488 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
427 | switch (wValue & 0xff00) { | 489 | switch (wValue & 0xff00) { |
428 | case USB_DT_DEVICE << 8: | 490 | case USB_DT_DEVICE << 8: |
429 | if (hcd->driver->flags & HCD_USB2) | 491 | switch (hcd->driver->flags & HCD_MASK) { |
492 | case HCD_USB3: | ||
493 | bufp = usb3_rh_dev_descriptor; | ||
494 | break; | ||
495 | case HCD_USB2: | ||
430 | bufp = usb2_rh_dev_descriptor; | 496 | bufp = usb2_rh_dev_descriptor; |
431 | else if (hcd->driver->flags & HCD_USB11) | 497 | break; |
498 | case HCD_USB11: | ||
432 | bufp = usb11_rh_dev_descriptor; | 499 | bufp = usb11_rh_dev_descriptor; |
433 | else | 500 | break; |
501 | default: | ||
434 | goto error; | 502 | goto error; |
503 | } | ||
435 | len = 18; | 504 | len = 18; |
436 | if (hcd->has_tt) | 505 | if (hcd->has_tt) |
437 | patch_protocol = 1; | 506 | patch_protocol = 1; |
438 | break; | 507 | break; |
439 | case USB_DT_CONFIG << 8: | 508 | case USB_DT_CONFIG << 8: |
440 | if (hcd->driver->flags & HCD_USB2) { | 509 | switch (hcd->driver->flags & HCD_MASK) { |
510 | case HCD_USB3: | ||
511 | bufp = ss_rh_config_descriptor; | ||
512 | len = sizeof ss_rh_config_descriptor; | ||
513 | break; | ||
514 | case HCD_USB2: | ||
441 | bufp = hs_rh_config_descriptor; | 515 | bufp = hs_rh_config_descriptor; |
442 | len = sizeof hs_rh_config_descriptor; | 516 | len = sizeof hs_rh_config_descriptor; |
443 | } else { | 517 | break; |
518 | case HCD_USB11: | ||
444 | bufp = fs_rh_config_descriptor; | 519 | bufp = fs_rh_config_descriptor; |
445 | len = sizeof fs_rh_config_descriptor; | 520 | len = sizeof fs_rh_config_descriptor; |
521 | break; | ||
522 | default: | ||
523 | goto error; | ||
446 | } | 524 | } |
447 | if (device_can_wakeup(&hcd->self.root_hub->dev)) | 525 | if (device_can_wakeup(&hcd->self.root_hub->dev)) |
448 | patch_wakeup = 1; | 526 | patch_wakeup = 1; |
@@ -755,23 +833,6 @@ static struct attribute_group usb_bus_attr_group = { | |||
755 | 833 | ||
756 | /*-------------------------------------------------------------------------*/ | 834 | /*-------------------------------------------------------------------------*/ |
757 | 835 | ||
758 | static struct class *usb_host_class; | ||
759 | |||
760 | int usb_host_init(void) | ||
761 | { | ||
762 | int retval = 0; | ||
763 | |||
764 | usb_host_class = class_create(THIS_MODULE, "usb_host"); | ||
765 | if (IS_ERR(usb_host_class)) | ||
766 | retval = PTR_ERR(usb_host_class); | ||
767 | return retval; | ||
768 | } | ||
769 | |||
770 | void usb_host_cleanup(void) | ||
771 | { | ||
772 | class_destroy(usb_host_class); | ||
773 | } | ||
774 | |||
775 | /** | 836 | /** |
776 | * usb_bus_init - shared initialization code | 837 | * usb_bus_init - shared initialization code |
777 | * @bus: the bus structure being initialized | 838 | * @bus: the bus structure being initialized |
@@ -818,12 +879,6 @@ static int usb_register_bus(struct usb_bus *bus) | |||
818 | set_bit (busnum, busmap.busmap); | 879 | set_bit (busnum, busmap.busmap); |
819 | bus->busnum = busnum; | 880 | bus->busnum = busnum; |
820 | 881 | ||
821 | bus->dev = device_create(usb_host_class, bus->controller, MKDEV(0, 0), | ||
822 | bus, "usb_host%d", busnum); | ||
823 | result = PTR_ERR(bus->dev); | ||
824 | if (IS_ERR(bus->dev)) | ||
825 | goto error_create_class_dev; | ||
826 | |||
827 | /* Add it to the local list of buses */ | 882 | /* Add it to the local list of buses */ |
828 | list_add (&bus->bus_list, &usb_bus_list); | 883 | list_add (&bus->bus_list, &usb_bus_list); |
829 | mutex_unlock(&usb_bus_list_lock); | 884 | mutex_unlock(&usb_bus_list_lock); |
@@ -834,8 +889,6 @@ static int usb_register_bus(struct usb_bus *bus) | |||
834 | "number %d\n", bus->busnum); | 889 | "number %d\n", bus->busnum); |
835 | return 0; | 890 | return 0; |
836 | 891 | ||
837 | error_create_class_dev: | ||
838 | clear_bit(busnum, busmap.busmap); | ||
839 | error_find_busnum: | 892 | error_find_busnum: |
840 | mutex_unlock(&usb_bus_list_lock); | 893 | mutex_unlock(&usb_bus_list_lock); |
841 | return result; | 894 | return result; |
@@ -865,8 +918,6 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
865 | usb_notify_remove_bus(bus); | 918 | usb_notify_remove_bus(bus); |
866 | 919 | ||
867 | clear_bit (bus->busnum, busmap.busmap); | 920 | clear_bit (bus->busnum, busmap.busmap); |
868 | |||
869 | device_unregister(bus->dev); | ||
870 | } | 921 | } |
871 | 922 | ||
872 | /** | 923 | /** |
@@ -1199,7 +1250,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1199 | 1250 | ||
1200 | /* Map the URB's buffers for DMA access. | 1251 | /* Map the URB's buffers for DMA access. |
1201 | * Lower level HCD code should use *_dma exclusively, | 1252 | * Lower level HCD code should use *_dma exclusively, |
1202 | * unless it uses pio or talks to another transport. | 1253 | * unless it uses pio or talks to another transport, |
1254 | * or uses the provided scatter gather list for bulk. | ||
1203 | */ | 1255 | */ |
1204 | if (is_root_hub(urb->dev)) | 1256 | if (is_root_hub(urb->dev)) |
1205 | return 0; | 1257 | return 0; |
@@ -1520,6 +1572,92 @@ rescan: | |||
1520 | } | 1572 | } |
1521 | } | 1573 | } |
1522 | 1574 | ||
1575 | /* Check whether a new configuration or alt setting for an interface | ||
1576 | * will exceed the bandwidth for the bus (or the host controller resources). | ||
1577 | * Only pass in a non-NULL config or interface, not both! | ||
1578 | * Passing NULL for both new_config and new_intf means the device will be | ||
1579 | * de-configured by issuing a set configuration 0 command. | ||
1580 | */ | ||
1581 | int usb_hcd_check_bandwidth(struct usb_device *udev, | ||
1582 | struct usb_host_config *new_config, | ||
1583 | struct usb_interface *new_intf) | ||
1584 | { | ||
1585 | int num_intfs, i, j; | ||
1586 | struct usb_interface_cache *intf_cache; | ||
1587 | struct usb_host_interface *alt = 0; | ||
1588 | int ret = 0; | ||
1589 | struct usb_hcd *hcd; | ||
1590 | struct usb_host_endpoint *ep; | ||
1591 | |||
1592 | hcd = bus_to_hcd(udev->bus); | ||
1593 | if (!hcd->driver->check_bandwidth) | ||
1594 | return 0; | ||
1595 | |||
1596 | /* Configuration is being removed - set configuration 0 */ | ||
1597 | if (!new_config && !new_intf) { | ||
1598 | for (i = 1; i < 16; ++i) { | ||
1599 | ep = udev->ep_out[i]; | ||
1600 | if (ep) | ||
1601 | hcd->driver->drop_endpoint(hcd, udev, ep); | ||
1602 | ep = udev->ep_in[i]; | ||
1603 | if (ep) | ||
1604 | hcd->driver->drop_endpoint(hcd, udev, ep); | ||
1605 | } | ||
1606 | hcd->driver->check_bandwidth(hcd, udev); | ||
1607 | return 0; | ||
1608 | } | ||
1609 | /* Check if the HCD says there's enough bandwidth. Enable all endpoints | ||
1610 | * each interface's alt setting 0 and ask the HCD to check the bandwidth | ||
1611 | * of the bus. There will always be bandwidth for endpoint 0, so it's | ||
1612 | * ok to exclude it. | ||
1613 | */ | ||
1614 | if (new_config) { | ||
1615 | num_intfs = new_config->desc.bNumInterfaces; | ||
1616 | /* Remove endpoints (except endpoint 0, which is always on the | ||
1617 | * schedule) from the old config from the schedule | ||
1618 | */ | ||
1619 | for (i = 1; i < 16; ++i) { | ||
1620 | ep = udev->ep_out[i]; | ||
1621 | if (ep) { | ||
1622 | ret = hcd->driver->drop_endpoint(hcd, udev, ep); | ||
1623 | if (ret < 0) | ||
1624 | goto reset; | ||
1625 | } | ||
1626 | ep = udev->ep_in[i]; | ||
1627 | if (ep) { | ||
1628 | ret = hcd->driver->drop_endpoint(hcd, udev, ep); | ||
1629 | if (ret < 0) | ||
1630 | goto reset; | ||
1631 | } | ||
1632 | } | ||
1633 | for (i = 0; i < num_intfs; ++i) { | ||
1634 | |||
1635 | /* Dig the endpoints for alt setting 0 out of the | ||
1636 | * interface cache for this interface | ||
1637 | */ | ||
1638 | intf_cache = new_config->intf_cache[i]; | ||
1639 | for (j = 0; j < intf_cache->num_altsetting; j++) { | ||
1640 | if (intf_cache->altsetting[j].desc.bAlternateSetting == 0) | ||
1641 | alt = &intf_cache->altsetting[j]; | ||
1642 | } | ||
1643 | if (!alt) { | ||
1644 | printk(KERN_DEBUG "Did not find alt setting 0 for intf %d\n", i); | ||
1645 | continue; | ||
1646 | } | ||
1647 | for (j = 0; j < alt->desc.bNumEndpoints; j++) { | ||
1648 | ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); | ||
1649 | if (ret < 0) | ||
1650 | goto reset; | ||
1651 | } | ||
1652 | } | ||
1653 | } | ||
1654 | ret = hcd->driver->check_bandwidth(hcd, udev); | ||
1655 | reset: | ||
1656 | if (ret < 0) | ||
1657 | hcd->driver->reset_bandwidth(hcd, udev); | ||
1658 | return ret; | ||
1659 | } | ||
1660 | |||
1523 | /* Disables the endpoint: synchronizes with the hcd to make sure all | 1661 | /* Disables the endpoint: synchronizes with the hcd to make sure all |
1524 | * endpoint state is gone from hardware. usb_hcd_flush_endpoint() must | 1662 | * endpoint state is gone from hardware. usb_hcd_flush_endpoint() must |
1525 | * have been called previously. Use for set_configuration, set_interface, | 1663 | * have been called previously. Use for set_configuration, set_interface, |
@@ -1897,8 +2035,20 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1897 | retval = -ENOMEM; | 2035 | retval = -ENOMEM; |
1898 | goto err_allocate_root_hub; | 2036 | goto err_allocate_root_hub; |
1899 | } | 2037 | } |
1900 | rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : | 2038 | |
1901 | USB_SPEED_FULL; | 2039 | switch (hcd->driver->flags & HCD_MASK) { |
2040 | case HCD_USB11: | ||
2041 | rhdev->speed = USB_SPEED_FULL; | ||
2042 | break; | ||
2043 | case HCD_USB2: | ||
2044 | rhdev->speed = USB_SPEED_HIGH; | ||
2045 | break; | ||
2046 | case HCD_USB3: | ||
2047 | rhdev->speed = USB_SPEED_SUPER; | ||
2048 | break; | ||
2049 | default: | ||
2050 | goto err_allocate_root_hub; | ||
2051 | } | ||
1902 | hcd->self.root_hub = rhdev; | 2052 | hcd->self.root_hub = rhdev; |
1903 | 2053 | ||
1904 | /* wakeup flag init defaults to "everything works" for root hubs, | 2054 | /* wakeup flag init defaults to "everything works" for root hubs, |
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h index e7d4479de41..d397ecfd5b1 100644 --- a/drivers/usb/core/hcd.h +++ b/drivers/usb/core/hcd.h | |||
@@ -173,6 +173,8 @@ struct hc_driver { | |||
173 | #define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ | 173 | #define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ |
174 | #define HCD_USB11 0x0010 /* USB 1.1 */ | 174 | #define HCD_USB11 0x0010 /* USB 1.1 */ |
175 | #define HCD_USB2 0x0020 /* USB 2.0 */ | 175 | #define HCD_USB2 0x0020 /* USB 2.0 */ |
176 | #define HCD_USB3 0x0040 /* USB 3.0 */ | ||
177 | #define HCD_MASK 0x0070 | ||
176 | 178 | ||
177 | /* called to init HCD and root hub */ | 179 | /* called to init HCD and root hub */ |
178 | int (*reset) (struct usb_hcd *hcd); | 180 | int (*reset) (struct usb_hcd *hcd); |
@@ -182,10 +184,10 @@ struct hc_driver { | |||
182 | * a whole, not just the root hub; they're for PCI bus glue. | 184 | * a whole, not just the root hub; they're for PCI bus glue. |
183 | */ | 185 | */ |
184 | /* called after suspending the hub, before entering D3 etc */ | 186 | /* called after suspending the hub, before entering D3 etc */ |
185 | int (*pci_suspend) (struct usb_hcd *hcd, pm_message_t message); | 187 | int (*pci_suspend)(struct usb_hcd *hcd); |
186 | 188 | ||
187 | /* called after entering D0 (etc), before resuming the hub */ | 189 | /* called after entering D0 (etc), before resuming the hub */ |
188 | int (*pci_resume) (struct usb_hcd *hcd); | 190 | int (*pci_resume)(struct usb_hcd *hcd, bool hibernated); |
189 | 191 | ||
190 | /* cleanly make HCD stop writing memory and doing I/O */ | 192 | /* cleanly make HCD stop writing memory and doing I/O */ |
191 | void (*stop) (struct usb_hcd *hcd); | 193 | void (*stop) (struct usb_hcd *hcd); |
@@ -224,6 +226,43 @@ struct hc_driver { | |||
224 | void (*relinquish_port)(struct usb_hcd *, int); | 226 | void (*relinquish_port)(struct usb_hcd *, int); |
225 | /* has a port been handed over to a companion? */ | 227 | /* has a port been handed over to a companion? */ |
226 | int (*port_handed_over)(struct usb_hcd *, int); | 228 | int (*port_handed_over)(struct usb_hcd *, int); |
229 | |||
230 | /* xHCI specific functions */ | ||
231 | /* Called by usb_alloc_dev to alloc HC device structures */ | ||
232 | int (*alloc_dev)(struct usb_hcd *, struct usb_device *); | ||
233 | /* Called by usb_release_dev to free HC device structures */ | ||
234 | void (*free_dev)(struct usb_hcd *, struct usb_device *); | ||
235 | |||
236 | /* Bandwidth computation functions */ | ||
237 | /* Note that add_endpoint() can only be called once per endpoint before | ||
238 | * check_bandwidth() or reset_bandwidth() must be called. | ||
239 | * drop_endpoint() can only be called once per endpoint also. | ||
240 | * A call to xhci_drop_endpoint() followed by a call to xhci_add_endpoint() will | ||
241 | * add the endpoint to the schedule with possibly new parameters denoted by a | ||
242 | * different endpoint descriptor in usb_host_endpoint. | ||
243 | * A call to xhci_add_endpoint() followed by a call to xhci_drop_endpoint() is | ||
244 | * not allowed. | ||
245 | */ | ||
246 | /* Allocate endpoint resources and add them to a new schedule */ | ||
247 | int (*add_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *); | ||
248 | /* Drop an endpoint from a new schedule */ | ||
249 | int (*drop_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *); | ||
250 | /* Check that a new hardware configuration, set using | ||
251 | * endpoint_enable and endpoint_disable, does not exceed bus | ||
252 | * bandwidth. This must be called before any set configuration | ||
253 | * or set interface requests are sent to the device. | ||
254 | */ | ||
255 | int (*check_bandwidth)(struct usb_hcd *, struct usb_device *); | ||
256 | /* Reset the device schedule to the last known good schedule, | ||
257 | * which was set from a previous successful call to | ||
258 | * check_bandwidth(). This reverts any add_endpoint() and | ||
259 | * drop_endpoint() calls since that last successful call. | ||
260 | * Used for when a check_bandwidth() call fails due to resource | ||
261 | * or bandwidth constraints. | ||
262 | */ | ||
263 | void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); | ||
264 | /* Returns the hardware-chosen device address */ | ||
265 | int (*address_device)(struct usb_hcd *, struct usb_device *udev); | ||
227 | }; | 266 | }; |
228 | 267 | ||
229 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | 268 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); |
@@ -242,6 +281,9 @@ extern void usb_hcd_disable_endpoint(struct usb_device *udev, | |||
242 | extern void usb_hcd_reset_endpoint(struct usb_device *udev, | 281 | extern void usb_hcd_reset_endpoint(struct usb_device *udev, |
243 | struct usb_host_endpoint *ep); | 282 | struct usb_host_endpoint *ep); |
244 | extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); | 283 | extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); |
284 | extern int usb_hcd_check_bandwidth(struct usb_device *udev, | ||
285 | struct usb_host_config *new_config, | ||
286 | struct usb_interface *new_intf); | ||
245 | extern int usb_hcd_get_frame_number(struct usb_device *udev); | 287 | extern int usb_hcd_get_frame_number(struct usb_device *udev); |
246 | 288 | ||
247 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | 289 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, |
@@ -261,14 +303,11 @@ struct pci_device_id; | |||
261 | extern int usb_hcd_pci_probe(struct pci_dev *dev, | 303 | extern int usb_hcd_pci_probe(struct pci_dev *dev, |
262 | const struct pci_device_id *id); | 304 | const struct pci_device_id *id); |
263 | extern void usb_hcd_pci_remove(struct pci_dev *dev); | 305 | extern void usb_hcd_pci_remove(struct pci_dev *dev); |
264 | |||
265 | #ifdef CONFIG_PM | ||
266 | extern int usb_hcd_pci_suspend(struct pci_dev *dev, pm_message_t msg); | ||
267 | extern int usb_hcd_pci_resume(struct pci_dev *dev); | ||
268 | #endif /* CONFIG_PM */ | ||
269 | |||
270 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); | 306 | extern void usb_hcd_pci_shutdown(struct pci_dev *dev); |
271 | 307 | ||
308 | #ifdef CONFIG_PM_SLEEP | ||
309 | extern struct dev_pm_ops usb_hcd_pci_pm_ops; | ||
310 | #endif | ||
272 | #endif /* CONFIG_PCI */ | 311 | #endif /* CONFIG_PCI */ |
273 | 312 | ||
274 | /* pci-ish (pdev null is ok) buffer alloc/mapping support */ | 313 | /* pci-ish (pdev null is ok) buffer alloc/mapping support */ |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index be86ae3f408..2af3b4f0605 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -155,6 +155,8 @@ static inline char *portspeed(int portstatus) | |||
155 | return "480 Mb/s"; | 155 | return "480 Mb/s"; |
156 | else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) | 156 | else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) |
157 | return "1.5 Mb/s"; | 157 | return "1.5 Mb/s"; |
158 | else if (portstatus & (1 << USB_PORT_FEAT_SUPERSPEED)) | ||
159 | return "5.0 Gb/s"; | ||
158 | else | 160 | else |
159 | return "12 Mb/s"; | 161 | return "12 Mb/s"; |
160 | } | 162 | } |
@@ -457,13 +459,13 @@ static void hub_tt_kevent (struct work_struct *work) | |||
457 | 459 | ||
458 | spin_lock_irqsave (&hub->tt.lock, flags); | 460 | spin_lock_irqsave (&hub->tt.lock, flags); |
459 | while (--limit && !list_empty (&hub->tt.clear_list)) { | 461 | while (--limit && !list_empty (&hub->tt.clear_list)) { |
460 | struct list_head *temp; | 462 | struct list_head *next; |
461 | struct usb_tt_clear *clear; | 463 | struct usb_tt_clear *clear; |
462 | struct usb_device *hdev = hub->hdev; | 464 | struct usb_device *hdev = hub->hdev; |
463 | int status; | 465 | int status; |
464 | 466 | ||
465 | temp = hub->tt.clear_list.next; | 467 | next = hub->tt.clear_list.next; |
466 | clear = list_entry (temp, struct usb_tt_clear, clear_list); | 468 | clear = list_entry (next, struct usb_tt_clear, clear_list); |
467 | list_del (&clear->clear_list); | 469 | list_del (&clear->clear_list); |
468 | 470 | ||
469 | /* drop lock so HCD can concurrently report other TT errors */ | 471 | /* drop lock so HCD can concurrently report other TT errors */ |
@@ -951,6 +953,9 @@ static int hub_configure(struct usb_hub *hub, | |||
951 | ret); | 953 | ret); |
952 | hub->tt.hub = hdev; | 954 | hub->tt.hub = hdev; |
953 | break; | 955 | break; |
956 | case 3: | ||
957 | /* USB 3.0 hubs don't have a TT */ | ||
958 | break; | ||
954 | default: | 959 | default: |
955 | dev_dbg(hub_dev, "Unrecognized hub protocol %d\n", | 960 | dev_dbg(hub_dev, "Unrecognized hub protocol %d\n", |
956 | hdev->descriptor.bDeviceProtocol); | 961 | hdev->descriptor.bDeviceProtocol); |
@@ -1323,6 +1328,11 @@ EXPORT_SYMBOL_GPL(usb_set_device_state); | |||
1323 | * 0 is reserved by USB for default address; (b) Linux's USB stack | 1328 | * 0 is reserved by USB for default address; (b) Linux's USB stack |
1324 | * uses always #1 for the root hub of the controller. So USB stack's | 1329 | * uses always #1 for the root hub of the controller. So USB stack's |
1325 | * port #1, which is wusb virtual-port #0 has address #2. | 1330 | * port #1, which is wusb virtual-port #0 has address #2. |
1331 | * | ||
1332 | * Devices connected under xHCI are not as simple. The host controller | ||
1333 | * supports virtualization, so the hardware assigns device addresses and | ||
1334 | * the HCD must setup data structures before issuing a set address | ||
1335 | * command to the hardware. | ||
1326 | */ | 1336 | */ |
1327 | static void choose_address(struct usb_device *udev) | 1337 | static void choose_address(struct usb_device *udev) |
1328 | { | 1338 | { |
@@ -1642,6 +1652,9 @@ int usb_new_device(struct usb_device *udev) | |||
1642 | err = usb_configure_device(udev); /* detect & probe dev/intfs */ | 1652 | err = usb_configure_device(udev); /* detect & probe dev/intfs */ |
1643 | if (err < 0) | 1653 | if (err < 0) |
1644 | goto fail; | 1654 | goto fail; |
1655 | dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", | ||
1656 | udev->devnum, udev->bus->busnum, | ||
1657 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); | ||
1645 | /* export the usbdev device-node for libusb */ | 1658 | /* export the usbdev device-node for libusb */ |
1646 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, | 1659 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, |
1647 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); | 1660 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); |
@@ -2395,19 +2408,29 @@ EXPORT_SYMBOL_GPL(usb_ep0_reinit); | |||
2395 | static int hub_set_address(struct usb_device *udev, int devnum) | 2408 | static int hub_set_address(struct usb_device *udev, int devnum) |
2396 | { | 2409 | { |
2397 | int retval; | 2410 | int retval; |
2411 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
2398 | 2412 | ||
2399 | if (devnum <= 1) | 2413 | /* |
2414 | * The host controller will choose the device address, | ||
2415 | * instead of the core having chosen it earlier | ||
2416 | */ | ||
2417 | if (!hcd->driver->address_device && devnum <= 1) | ||
2400 | return -EINVAL; | 2418 | return -EINVAL; |
2401 | if (udev->state == USB_STATE_ADDRESS) | 2419 | if (udev->state == USB_STATE_ADDRESS) |
2402 | return 0; | 2420 | return 0; |
2403 | if (udev->state != USB_STATE_DEFAULT) | 2421 | if (udev->state != USB_STATE_DEFAULT) |
2404 | return -EINVAL; | 2422 | return -EINVAL; |
2405 | retval = usb_control_msg(udev, usb_sndaddr0pipe(), | 2423 | if (hcd->driver->address_device) { |
2406 | USB_REQ_SET_ADDRESS, 0, devnum, 0, | 2424 | retval = hcd->driver->address_device(hcd, udev); |
2407 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 2425 | } else { |
2426 | retval = usb_control_msg(udev, usb_sndaddr0pipe(), | ||
2427 | USB_REQ_SET_ADDRESS, 0, devnum, 0, | ||
2428 | NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
2429 | if (retval == 0) | ||
2430 | update_address(udev, devnum); | ||
2431 | } | ||
2408 | if (retval == 0) { | 2432 | if (retval == 0) { |
2409 | /* Device now using proper address. */ | 2433 | /* Device now using proper address. */ |
2410 | update_address(udev, devnum); | ||
2411 | usb_set_device_state(udev, USB_STATE_ADDRESS); | 2434 | usb_set_device_state(udev, USB_STATE_ADDRESS); |
2412 | usb_ep0_reinit(udev); | 2435 | usb_ep0_reinit(udev); |
2413 | } | 2436 | } |
@@ -2430,6 +2453,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2430 | static DEFINE_MUTEX(usb_address0_mutex); | 2453 | static DEFINE_MUTEX(usb_address0_mutex); |
2431 | 2454 | ||
2432 | struct usb_device *hdev = hub->hdev; | 2455 | struct usb_device *hdev = hub->hdev; |
2456 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | ||
2433 | int i, j, retval; | 2457 | int i, j, retval; |
2434 | unsigned delay = HUB_SHORT_RESET_TIME; | 2458 | unsigned delay = HUB_SHORT_RESET_TIME; |
2435 | enum usb_device_speed oldspeed = udev->speed; | 2459 | enum usb_device_speed oldspeed = udev->speed; |
@@ -2452,11 +2476,24 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2452 | 2476 | ||
2453 | mutex_lock(&usb_address0_mutex); | 2477 | mutex_lock(&usb_address0_mutex); |
2454 | 2478 | ||
2455 | /* Reset the device; full speed may morph to high speed */ | 2479 | if ((hcd->driver->flags & HCD_USB3) && udev->config) { |
2456 | retval = hub_port_reset(hub, port1, udev, delay); | 2480 | /* FIXME this will need special handling by the xHCI driver. */ |
2457 | if (retval < 0) /* error or disconnect */ | 2481 | dev_dbg(&udev->dev, |
2482 | "xHCI reset of configured device " | ||
2483 | "not supported yet.\n"); | ||
2484 | retval = -EINVAL; | ||
2458 | goto fail; | 2485 | goto fail; |
2459 | /* success, speed is known */ | 2486 | } else if (!udev->config && oldspeed == USB_SPEED_SUPER) { |
2487 | /* Don't reset USB 3.0 devices during an initial setup */ | ||
2488 | usb_set_device_state(udev, USB_STATE_DEFAULT); | ||
2489 | } else { | ||
2490 | /* Reset the device; full speed may morph to high speed */ | ||
2491 | /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ | ||
2492 | retval = hub_port_reset(hub, port1, udev, delay); | ||
2493 | if (retval < 0) /* error or disconnect */ | ||
2494 | goto fail; | ||
2495 | /* success, speed is known */ | ||
2496 | } | ||
2460 | retval = -ENODEV; | 2497 | retval = -ENODEV; |
2461 | 2498 | ||
2462 | if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) { | 2499 | if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) { |
@@ -2471,6 +2508,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2471 | * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. | 2508 | * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. |
2472 | */ | 2509 | */ |
2473 | switch (udev->speed) { | 2510 | switch (udev->speed) { |
2511 | case USB_SPEED_SUPER: | ||
2474 | case USB_SPEED_VARIABLE: /* fixed at 512 */ | 2512 | case USB_SPEED_VARIABLE: /* fixed at 512 */ |
2475 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); | 2513 | udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); |
2476 | break; | 2514 | break; |
@@ -2496,16 +2534,20 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2496 | case USB_SPEED_LOW: speed = "low"; break; | 2534 | case USB_SPEED_LOW: speed = "low"; break; |
2497 | case USB_SPEED_FULL: speed = "full"; break; | 2535 | case USB_SPEED_FULL: speed = "full"; break; |
2498 | case USB_SPEED_HIGH: speed = "high"; break; | 2536 | case USB_SPEED_HIGH: speed = "high"; break; |
2537 | case USB_SPEED_SUPER: | ||
2538 | speed = "super"; | ||
2539 | break; | ||
2499 | case USB_SPEED_VARIABLE: | 2540 | case USB_SPEED_VARIABLE: |
2500 | speed = "variable"; | 2541 | speed = "variable"; |
2501 | type = "Wireless "; | 2542 | type = "Wireless "; |
2502 | break; | 2543 | break; |
2503 | default: speed = "?"; break; | 2544 | default: speed = "?"; break; |
2504 | } | 2545 | } |
2505 | dev_info (&udev->dev, | 2546 | if (udev->speed != USB_SPEED_SUPER) |
2506 | "%s %s speed %sUSB device using %s and address %d\n", | 2547 | dev_info(&udev->dev, |
2507 | (udev->config) ? "reset" : "new", speed, type, | 2548 | "%s %s speed %sUSB device using %s and address %d\n", |
2508 | udev->bus->controller->driver->name, devnum); | 2549 | (udev->config) ? "reset" : "new", speed, type, |
2550 | udev->bus->controller->driver->name, devnum); | ||
2509 | 2551 | ||
2510 | /* Set up TT records, if needed */ | 2552 | /* Set up TT records, if needed */ |
2511 | if (hdev->tt) { | 2553 | if (hdev->tt) { |
@@ -2530,7 +2572,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2530 | * value. | 2572 | * value. |
2531 | */ | 2573 | */ |
2532 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { | 2574 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { |
2533 | if (USE_NEW_SCHEME(retry_counter)) { | 2575 | /* |
2576 | * An xHCI controller cannot send any packets to a device until | ||
2577 | * a set address command successfully completes. | ||
2578 | */ | ||
2579 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { | ||
2534 | struct usb_device_descriptor *buf; | 2580 | struct usb_device_descriptor *buf; |
2535 | int r = 0; | 2581 | int r = 0; |
2536 | 2582 | ||
@@ -2596,7 +2642,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2596 | * unauthorized address in the Connect Ack sequence; | 2642 | * unauthorized address in the Connect Ack sequence; |
2597 | * authorization will assign the final address. | 2643 | * authorization will assign the final address. |
2598 | */ | 2644 | */ |
2599 | if (udev->wusb == 0) { | 2645 | if (udev->wusb == 0) { |
2600 | for (j = 0; j < SET_ADDRESS_TRIES; ++j) { | 2646 | for (j = 0; j < SET_ADDRESS_TRIES; ++j) { |
2601 | retval = hub_set_address(udev, devnum); | 2647 | retval = hub_set_address(udev, devnum); |
2602 | if (retval >= 0) | 2648 | if (retval >= 0) |
@@ -2609,13 +2655,20 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2609 | devnum, retval); | 2655 | devnum, retval); |
2610 | goto fail; | 2656 | goto fail; |
2611 | } | 2657 | } |
2658 | if (udev->speed == USB_SPEED_SUPER) { | ||
2659 | devnum = udev->devnum; | ||
2660 | dev_info(&udev->dev, | ||
2661 | "%s SuperSpeed USB device using %s and address %d\n", | ||
2662 | (udev->config) ? "reset" : "new", | ||
2663 | udev->bus->controller->driver->name, devnum); | ||
2664 | } | ||
2612 | 2665 | ||
2613 | /* cope with hardware quirkiness: | 2666 | /* cope with hardware quirkiness: |
2614 | * - let SET_ADDRESS settle, some device hardware wants it | 2667 | * - let SET_ADDRESS settle, some device hardware wants it |
2615 | * - read ep0 maxpacket even for high and low speed, | 2668 | * - read ep0 maxpacket even for high and low speed, |
2616 | */ | 2669 | */ |
2617 | msleep(10); | 2670 | msleep(10); |
2618 | if (USE_NEW_SCHEME(retry_counter)) | 2671 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) |
2619 | break; | 2672 | break; |
2620 | } | 2673 | } |
2621 | 2674 | ||
@@ -2634,8 +2687,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2634 | if (retval) | 2687 | if (retval) |
2635 | goto fail; | 2688 | goto fail; |
2636 | 2689 | ||
2637 | i = udev->descriptor.bMaxPacketSize0 == 0xff? /* wusb device? */ | 2690 | if (udev->descriptor.bMaxPacketSize0 == 0xff || |
2638 | 512 : udev->descriptor.bMaxPacketSize0; | 2691 | udev->speed == USB_SPEED_SUPER) |
2692 | i = 512; | ||
2693 | else | ||
2694 | i = udev->descriptor.bMaxPacketSize0; | ||
2639 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { | 2695 | if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { |
2640 | if (udev->speed != USB_SPEED_FULL || | 2696 | if (udev->speed != USB_SPEED_FULL || |
2641 | !(i == 8 || i == 16 || i == 32 || i == 64)) { | 2697 | !(i == 8 || i == 16 || i == 32 || i == 64)) { |
@@ -2847,19 +2903,41 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
2847 | } | 2903 | } |
2848 | 2904 | ||
2849 | usb_set_device_state(udev, USB_STATE_POWERED); | 2905 | usb_set_device_state(udev, USB_STATE_POWERED); |
2850 | udev->speed = USB_SPEED_UNKNOWN; | ||
2851 | udev->bus_mA = hub->mA_per_port; | 2906 | udev->bus_mA = hub->mA_per_port; |
2852 | udev->level = hdev->level + 1; | 2907 | udev->level = hdev->level + 1; |
2853 | udev->wusb = hub_is_wusb(hub); | 2908 | udev->wusb = hub_is_wusb(hub); |
2854 | 2909 | ||
2855 | /* set the address */ | 2910 | /* |
2856 | choose_address(udev); | 2911 | * USB 3.0 devices are reset automatically before the connect |
2857 | if (udev->devnum <= 0) { | 2912 | * port status change appears, and the root hub port status |
2858 | status = -ENOTCONN; /* Don't retry */ | 2913 | * shows the correct speed. We also get port change |
2859 | goto loop; | 2914 | * notifications for USB 3.0 devices from the USB 3.0 portion of |
2915 | * an external USB 3.0 hub, but this isn't handled correctly yet | ||
2916 | * FIXME. | ||
2917 | */ | ||
2918 | |||
2919 | if (!(hcd->driver->flags & HCD_USB3)) | ||
2920 | udev->speed = USB_SPEED_UNKNOWN; | ||
2921 | else if ((hdev->parent == NULL) && | ||
2922 | (portstatus & (1 << USB_PORT_FEAT_SUPERSPEED))) | ||
2923 | udev->speed = USB_SPEED_SUPER; | ||
2924 | else | ||
2925 | udev->speed = USB_SPEED_UNKNOWN; | ||
2926 | |||
2927 | /* | ||
2928 | * xHCI needs to issue an address device command later | ||
2929 | * in the hub_port_init sequence for SS/HS/FS/LS devices. | ||
2930 | */ | ||
2931 | if (!(hcd->driver->flags & HCD_USB3)) { | ||
2932 | /* set the address */ | ||
2933 | choose_address(udev); | ||
2934 | if (udev->devnum <= 0) { | ||
2935 | status = -ENOTCONN; /* Don't retry */ | ||
2936 | goto loop; | ||
2937 | } | ||
2860 | } | 2938 | } |
2861 | 2939 | ||
2862 | /* reset and get descriptor */ | 2940 | /* reset (non-USB 3.0 devices) and get descriptor */ |
2863 | status = hub_port_init(hub, udev, port1, i); | 2941 | status = hub_port_init(hub, udev, port1, i); |
2864 | if (status < 0) | 2942 | if (status < 0) |
2865 | goto loop; | 2943 | goto loop; |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 2a116ce53c9..889c0f32a40 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -47,7 +47,10 @@ | |||
47 | #define USB_PORT_FEAT_L1 5 /* L1 suspend */ | 47 | #define USB_PORT_FEAT_L1 5 /* L1 suspend */ |
48 | #define USB_PORT_FEAT_POWER 8 | 48 | #define USB_PORT_FEAT_POWER 8 |
49 | #define USB_PORT_FEAT_LOWSPEED 9 | 49 | #define USB_PORT_FEAT_LOWSPEED 9 |
50 | /* This value was never in Table 11-17 */ | ||
50 | #define USB_PORT_FEAT_HIGHSPEED 10 | 51 | #define USB_PORT_FEAT_HIGHSPEED 10 |
52 | /* This value is also fake */ | ||
53 | #define USB_PORT_FEAT_SUPERSPEED 11 | ||
51 | #define USB_PORT_FEAT_C_CONNECTION 16 | 54 | #define USB_PORT_FEAT_C_CONNECTION 16 |
52 | #define USB_PORT_FEAT_C_ENABLE 17 | 55 | #define USB_PORT_FEAT_C_ENABLE 17 |
53 | #define USB_PORT_FEAT_C_SUSPEND 18 | 56 | #define USB_PORT_FEAT_C_SUSPEND 18 |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index b6262837765..2bed83caacb 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
11 | #include <linux/timer.h> | 11 | #include <linux/timer.h> |
12 | #include <linux/ctype.h> | 12 | #include <linux/ctype.h> |
13 | #include <linux/nls.h> | ||
13 | #include <linux/device.h> | 14 | #include <linux/device.h> |
14 | #include <linux/scatterlist.h> | 15 | #include <linux/scatterlist.h> |
15 | #include <linux/usb/quirks.h> | 16 | #include <linux/usb/quirks.h> |
@@ -364,6 +365,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
364 | int i; | 365 | int i; |
365 | int urb_flags; | 366 | int urb_flags; |
366 | int dma; | 367 | int dma; |
368 | int use_sg; | ||
367 | 369 | ||
368 | if (!io || !dev || !sg | 370 | if (!io || !dev || !sg |
369 | || usb_pipecontrol(pipe) | 371 | || usb_pipecontrol(pipe) |
@@ -391,7 +393,19 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
391 | if (io->entries <= 0) | 393 | if (io->entries <= 0) |
392 | return io->entries; | 394 | return io->entries; |
393 | 395 | ||
394 | io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags); | 396 | /* If we're running on an xHCI host controller, queue the whole scatter |
397 | * gather list with one call to urb_enqueue(). This is only for bulk, | ||
398 | * as that endpoint type does not care how the data gets broken up | ||
399 | * across frames. | ||
400 | */ | ||
401 | if (usb_pipebulk(pipe) && | ||
402 | bus_to_hcd(dev->bus)->driver->flags & HCD_USB3) { | ||
403 | io->urbs = kmalloc(sizeof *io->urbs, mem_flags); | ||
404 | use_sg = true; | ||
405 | } else { | ||
406 | io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags); | ||
407 | use_sg = false; | ||
408 | } | ||
395 | if (!io->urbs) | 409 | if (!io->urbs) |
396 | goto nomem; | 410 | goto nomem; |
397 | 411 | ||
@@ -401,62 +415,92 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, | |||
401 | if (usb_pipein(pipe)) | 415 | if (usb_pipein(pipe)) |
402 | urb_flags |= URB_SHORT_NOT_OK; | 416 | urb_flags |= URB_SHORT_NOT_OK; |
403 | 417 | ||
404 | for_each_sg(sg, sg, io->entries, i) { | 418 | if (use_sg) { |
405 | unsigned len; | 419 | io->urbs[0] = usb_alloc_urb(0, mem_flags); |
406 | 420 | if (!io->urbs[0]) { | |
407 | io->urbs[i] = usb_alloc_urb(0, mem_flags); | 421 | io->entries = 0; |
408 | if (!io->urbs[i]) { | ||
409 | io->entries = i; | ||
410 | goto nomem; | 422 | goto nomem; |
411 | } | 423 | } |
412 | 424 | ||
413 | io->urbs[i]->dev = NULL; | 425 | io->urbs[0]->dev = NULL; |
414 | io->urbs[i]->pipe = pipe; | 426 | io->urbs[0]->pipe = pipe; |
415 | io->urbs[i]->interval = period; | 427 | io->urbs[0]->interval = period; |
416 | io->urbs[i]->transfer_flags = urb_flags; | 428 | io->urbs[0]->transfer_flags = urb_flags; |
417 | 429 | ||
418 | io->urbs[i]->complete = sg_complete; | 430 | io->urbs[0]->complete = sg_complete; |
419 | io->urbs[i]->context = io; | 431 | io->urbs[0]->context = io; |
420 | 432 | /* A length of zero means transfer the whole sg list */ | |
421 | /* | 433 | io->urbs[0]->transfer_buffer_length = length; |
422 | * Some systems need to revert to PIO when DMA is temporarily | 434 | if (length == 0) { |
423 | * unavailable. For their sakes, both transfer_buffer and | 435 | for_each_sg(sg, sg, io->entries, i) { |
424 | * transfer_dma are set when possible. However this can only | 436 | io->urbs[0]->transfer_buffer_length += |
425 | * work on systems without: | 437 | sg_dma_len(sg); |
426 | * | 438 | } |
427 | * - HIGHMEM, since DMA buffers located in high memory are | 439 | } |
428 | * not directly addressable by the CPU for PIO; | 440 | io->urbs[0]->sg = io; |
429 | * | 441 | io->urbs[0]->num_sgs = io->entries; |
430 | * - IOMMU, since dma_map_sg() is allowed to use an IOMMU to | 442 | io->entries = 1; |
431 | * make virtually discontiguous buffers be "dma-contiguous" | 443 | } else { |
432 | * so that PIO and DMA need diferent numbers of URBs. | 444 | for_each_sg(sg, sg, io->entries, i) { |
433 | * | 445 | unsigned len; |
434 | * So when HIGHMEM or IOMMU are in use, transfer_buffer is NULL | 446 | |
435 | * to prevent stale pointers and to help spot bugs. | 447 | io->urbs[i] = usb_alloc_urb(0, mem_flags); |
436 | */ | 448 | if (!io->urbs[i]) { |
437 | if (dma) { | 449 | io->entries = i; |
438 | io->urbs[i]->transfer_dma = sg_dma_address(sg); | 450 | goto nomem; |
439 | len = sg_dma_len(sg); | 451 | } |
452 | |||
453 | io->urbs[i]->dev = NULL; | ||
454 | io->urbs[i]->pipe = pipe; | ||
455 | io->urbs[i]->interval = period; | ||
456 | io->urbs[i]->transfer_flags = urb_flags; | ||
457 | |||
458 | io->urbs[i]->complete = sg_complete; | ||
459 | io->urbs[i]->context = io; | ||
460 | |||
461 | /* | ||
462 | * Some systems need to revert to PIO when DMA is | ||
463 | * temporarily unavailable. For their sakes, both | ||
464 | * transfer_buffer and transfer_dma are set when | ||
465 | * possible. However this can only work on systems | ||
466 | * without: | ||
467 | * | ||
468 | * - HIGHMEM, since DMA buffers located in high memory | ||
469 | * are not directly addressable by the CPU for PIO; | ||
470 | * | ||
471 | * - IOMMU, since dma_map_sg() is allowed to use an | ||
472 | * IOMMU to make virtually discontiguous buffers be | ||
473 | * "dma-contiguous" so that PIO and DMA need diferent | ||
474 | * numbers of URBs. | ||
475 | * | ||
476 | * So when HIGHMEM or IOMMU are in use, transfer_buffer | ||
477 | * is NULL to prevent stale pointers and to help spot | ||
478 | * bugs. | ||
479 | */ | ||
480 | if (dma) { | ||
481 | io->urbs[i]->transfer_dma = sg_dma_address(sg); | ||
482 | len = sg_dma_len(sg); | ||
440 | #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) | 483 | #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) |
441 | io->urbs[i]->transfer_buffer = NULL; | 484 | io->urbs[i]->transfer_buffer = NULL; |
442 | #else | 485 | #else |
443 | io->urbs[i]->transfer_buffer = sg_virt(sg); | 486 | io->urbs[i]->transfer_buffer = sg_virt(sg); |
444 | #endif | 487 | #endif |
445 | } else { | 488 | } else { |
446 | /* hc may use _only_ transfer_buffer */ | 489 | /* hc may use _only_ transfer_buffer */ |
447 | io->urbs[i]->transfer_buffer = sg_virt(sg); | 490 | io->urbs[i]->transfer_buffer = sg_virt(sg); |
448 | len = sg->length; | 491 | len = sg->length; |
449 | } | 492 | } |
450 | 493 | ||
451 | if (length) { | 494 | if (length) { |
452 | len = min_t(unsigned, len, length); | 495 | len = min_t(unsigned, len, length); |
453 | length -= len; | 496 | length -= len; |
454 | if (length == 0) | 497 | if (length == 0) |
455 | io->entries = i + 1; | 498 | io->entries = i + 1; |
499 | } | ||
500 | io->urbs[i]->transfer_buffer_length = len; | ||
456 | } | 501 | } |
457 | io->urbs[i]->transfer_buffer_length = len; | 502 | io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; |
458 | } | 503 | } |
459 | io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; | ||
460 | 504 | ||
461 | /* transaction state */ | 505 | /* transaction state */ |
462 | io->count = io->entries; | 506 | io->count = io->entries; |
@@ -509,6 +553,10 @@ EXPORT_SYMBOL_GPL(usb_sg_init); | |||
509 | * could be transferred. That capability is less useful for low or full | 553 | * could be transferred. That capability is less useful for low or full |
510 | * speed interrupt endpoints, which allow at most one packet per millisecond, | 554 | * speed interrupt endpoints, which allow at most one packet per millisecond, |
511 | * of at most 8 or 64 bytes (respectively). | 555 | * of at most 8 or 64 bytes (respectively). |
556 | * | ||
557 | * It is not necessary to call this function to reserve bandwidth for devices | ||
558 | * under an xHCI host controller, as the bandwidth is reserved when the | ||
559 | * configuration or interface alt setting is selected. | ||
512 | */ | 560 | */ |
513 | void usb_sg_wait(struct usb_sg_request *io) | 561 | void usb_sg_wait(struct usb_sg_request *io) |
514 | { | 562 | { |
@@ -759,7 +807,7 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, | |||
759 | } | 807 | } |
760 | 808 | ||
761 | /** | 809 | /** |
762 | * usb_string - returns ISO 8859-1 version of a string descriptor | 810 | * usb_string - returns UTF-8 version of a string descriptor |
763 | * @dev: the device whose string descriptor is being retrieved | 811 | * @dev: the device whose string descriptor is being retrieved |
764 | * @index: the number of the descriptor | 812 | * @index: the number of the descriptor |
765 | * @buf: where to put the string | 813 | * @buf: where to put the string |
@@ -767,17 +815,10 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, | |||
767 | * Context: !in_interrupt () | 815 | * Context: !in_interrupt () |
768 | * | 816 | * |
769 | * This converts the UTF-16LE encoded strings returned by devices, from | 817 | * This converts the UTF-16LE encoded strings returned by devices, from |
770 | * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones | 818 | * usb_get_string_descriptor(), to null-terminated UTF-8 encoded ones |
771 | * that are more usable in most kernel contexts. Note that all characters | 819 | * that are more usable in most kernel contexts. Note that this function |
772 | * in the chosen descriptor that can't be encoded using ISO-8859-1 | ||
773 | * are converted to the question mark ("?") character, and this function | ||
774 | * chooses strings in the first language supported by the device. | 820 | * chooses strings in the first language supported by the device. |
775 | * | 821 | * |
776 | * The ASCII (or, redundantly, "US-ASCII") character set is the seven-bit | ||
777 | * subset of ISO 8859-1. ISO-8859-1 is the eight-bit subset of Unicode, | ||
778 | * and is appropriate for use many uses of English and several other | ||
779 | * Western European languages. (But it doesn't include the "Euro" symbol.) | ||
780 | * | ||
781 | * This call is synchronous, and may not be used in an interrupt context. | 822 | * This call is synchronous, and may not be used in an interrupt context. |
782 | * | 823 | * |
783 | * Returns length of the string (>= 0) or usb_control_msg status (< 0). | 824 | * Returns length of the string (>= 0) or usb_control_msg status (< 0). |
@@ -786,7 +827,6 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) | |||
786 | { | 827 | { |
787 | unsigned char *tbuf; | 828 | unsigned char *tbuf; |
788 | int err; | 829 | int err; |
789 | unsigned int u, idx; | ||
790 | 830 | ||
791 | if (dev->state == USB_STATE_SUSPENDED) | 831 | if (dev->state == USB_STATE_SUSPENDED) |
792 | return -EHOSTUNREACH; | 832 | return -EHOSTUNREACH; |
@@ -821,16 +861,9 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) | |||
821 | goto errout; | 861 | goto errout; |
822 | 862 | ||
823 | size--; /* leave room for trailing NULL char in output buffer */ | 863 | size--; /* leave room for trailing NULL char in output buffer */ |
824 | for (idx = 0, u = 2; u < err; u += 2) { | 864 | err = utf16s_to_utf8s((wchar_t *) &tbuf[2], (err - 2) / 2, |
825 | if (idx >= size) | 865 | UTF16_LITTLE_ENDIAN, buf, size); |
826 | break; | 866 | buf[err] = 0; |
827 | if (tbuf[u+1]) /* high byte */ | ||
828 | buf[idx++] = '?'; /* non ISO-8859-1 character */ | ||
829 | else | ||
830 | buf[idx++] = tbuf[u]; | ||
831 | } | ||
832 | buf[idx] = 0; | ||
833 | err = idx; | ||
834 | 867 | ||
835 | if (tbuf[1] != USB_DT_STRING) | 868 | if (tbuf[1] != USB_DT_STRING) |
836 | dev_dbg(&dev->dev, | 869 | dev_dbg(&dev->dev, |
@@ -843,6 +876,9 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) | |||
843 | } | 876 | } |
844 | EXPORT_SYMBOL_GPL(usb_string); | 877 | EXPORT_SYMBOL_GPL(usb_string); |
845 | 878 | ||
879 | /* one UTF-8-encoded 16-bit character has at most three bytes */ | ||
880 | #define MAX_USB_STRING_SIZE (127 * 3 + 1) | ||
881 | |||
846 | /** | 882 | /** |
847 | * usb_cache_string - read a string descriptor and cache it for later use | 883 | * usb_cache_string - read a string descriptor and cache it for later use |
848 | * @udev: the device whose string descriptor is being read | 884 | * @udev: the device whose string descriptor is being read |
@@ -860,9 +896,9 @@ char *usb_cache_string(struct usb_device *udev, int index) | |||
860 | if (index <= 0) | 896 | if (index <= 0) |
861 | return NULL; | 897 | return NULL; |
862 | 898 | ||
863 | buf = kmalloc(256, GFP_KERNEL); | 899 | buf = kmalloc(MAX_USB_STRING_SIZE, GFP_KERNEL); |
864 | if (buf) { | 900 | if (buf) { |
865 | len = usb_string(udev, index, buf, 256); | 901 | len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE); |
866 | if (len > 0) { | 902 | if (len > 0) { |
867 | smallbuf = kmalloc(++len, GFP_KERNEL); | 903 | smallbuf = kmalloc(++len, GFP_KERNEL); |
868 | if (!smallbuf) | 904 | if (!smallbuf) |
@@ -1664,6 +1700,21 @@ free_interfaces: | |||
1664 | if (ret) | 1700 | if (ret) |
1665 | goto free_interfaces; | 1701 | goto free_interfaces; |
1666 | 1702 | ||
1703 | /* Make sure we have bandwidth (and available HCD resources) for this | ||
1704 | * configuration. Remove endpoints from the schedule if we're dropping | ||
1705 | * this configuration to set configuration 0. After this point, the | ||
1706 | * host controller will not allow submissions to dropped endpoints. If | ||
1707 | * this call fails, the device state is unchanged. | ||
1708 | */ | ||
1709 | if (cp) | ||
1710 | ret = usb_hcd_check_bandwidth(dev, cp, NULL); | ||
1711 | else | ||
1712 | ret = usb_hcd_check_bandwidth(dev, NULL, NULL); | ||
1713 | if (ret < 0) { | ||
1714 | usb_autosuspend_device(dev); | ||
1715 | goto free_interfaces; | ||
1716 | } | ||
1717 | |||
1667 | /* if it's already configured, clear out old state first. | 1718 | /* if it's already configured, clear out old state first. |
1668 | * getting rid of old interfaces means unbinding their drivers. | 1719 | * getting rid of old interfaces means unbinding their drivers. |
1669 | */ | 1720 | */ |
@@ -1686,6 +1737,7 @@ free_interfaces: | |||
1686 | dev->actconfig = cp; | 1737 | dev->actconfig = cp; |
1687 | if (!cp) { | 1738 | if (!cp) { |
1688 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1739 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1740 | usb_hcd_check_bandwidth(dev, NULL, NULL); | ||
1689 | usb_autosuspend_device(dev); | 1741 | usb_autosuspend_device(dev); |
1690 | goto free_interfaces; | 1742 | goto free_interfaces; |
1691 | } | 1743 | } |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index c6678919792..b5c72e45894 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -552,8 +552,8 @@ static struct attribute *dev_string_attrs[] = { | |||
552 | static mode_t dev_string_attrs_are_visible(struct kobject *kobj, | 552 | static mode_t dev_string_attrs_are_visible(struct kobject *kobj, |
553 | struct attribute *a, int n) | 553 | struct attribute *a, int n) |
554 | { | 554 | { |
555 | struct usb_device *udev = to_usb_device( | 555 | struct device *dev = container_of(kobj, struct device, kobj); |
556 | container_of(kobj, struct device, kobj)); | 556 | struct usb_device *udev = to_usb_device(dev); |
557 | 557 | ||
558 | if (a == &dev_attr_manufacturer.attr) { | 558 | if (a == &dev_attr_manufacturer.attr) { |
559 | if (udev->manufacturer == NULL) | 559 | if (udev->manufacturer == NULL) |
@@ -585,8 +585,8 @@ static ssize_t | |||
585 | read_descriptors(struct kobject *kobj, struct bin_attribute *attr, | 585 | read_descriptors(struct kobject *kobj, struct bin_attribute *attr, |
586 | char *buf, loff_t off, size_t count) | 586 | char *buf, loff_t off, size_t count) |
587 | { | 587 | { |
588 | struct usb_device *udev = to_usb_device( | 588 | struct device *dev = container_of(kobj, struct device, kobj); |
589 | container_of(kobj, struct device, kobj)); | 589 | struct usb_device *udev = to_usb_device(dev); |
590 | size_t nleft = count; | 590 | size_t nleft = count; |
591 | size_t srclen, n; | 591 | size_t srclen, n; |
592 | int cfgno; | 592 | int cfgno; |
@@ -786,8 +786,8 @@ static struct attribute *intf_assoc_attrs[] = { | |||
786 | static mode_t intf_assoc_attrs_are_visible(struct kobject *kobj, | 786 | static mode_t intf_assoc_attrs_are_visible(struct kobject *kobj, |
787 | struct attribute *a, int n) | 787 | struct attribute *a, int n) |
788 | { | 788 | { |
789 | struct usb_interface *intf = to_usb_interface( | 789 | struct device *dev = container_of(kobj, struct device, kobj); |
790 | container_of(kobj, struct device, kobj)); | 790 | struct usb_interface *intf = to_usb_interface(dev); |
791 | 791 | ||
792 | if (intf->intf_assoc == NULL) | 792 | if (intf->intf_assoc == NULL) |
793 | return 0; | 793 | return 0; |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 3376055f36e..0885d4abdc6 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -241,6 +241,12 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); | |||
241 | * If the USB subsystem can't allocate sufficient bandwidth to perform | 241 | * If the USB subsystem can't allocate sufficient bandwidth to perform |
242 | * the periodic request, submitting such a periodic request should fail. | 242 | * the periodic request, submitting such a periodic request should fail. |
243 | * | 243 | * |
244 | * For devices under xHCI, the bandwidth is reserved at configuration time, or | ||
245 | * when the alt setting is selected. If there is not enough bus bandwidth, the | ||
246 | * configuration/alt setting request will fail. Therefore, submissions to | ||
247 | * periodic endpoints on devices under xHCI should never fail due to bandwidth | ||
248 | * constraints. | ||
249 | * | ||
244 | * Device drivers must explicitly request that repetition, by ensuring that | 250 | * Device drivers must explicitly request that repetition, by ensuring that |
245 | * some URB is always on the endpoint's queue (except possibly for short | 251 | * some URB is always on the endpoint's queue (except possibly for short |
246 | * periods during completion callacks). When there is no longer an urb | 252 | * periods during completion callacks). When there is no longer an urb |
@@ -351,6 +357,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
351 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { | 357 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { |
352 | int n, len; | 358 | int n, len; |
353 | 359 | ||
360 | /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ | ||
354 | /* "high bandwidth" mode, 1-3 packets/uframe? */ | 361 | /* "high bandwidth" mode, 1-3 packets/uframe? */ |
355 | if (dev->speed == USB_SPEED_HIGH) { | 362 | if (dev->speed == USB_SPEED_HIGH) { |
356 | int mult = 1 + ((max >> 11) & 0x03); | 363 | int mult = 1 + ((max >> 11) & 0x03); |
@@ -426,6 +433,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
426 | return -EINVAL; | 433 | return -EINVAL; |
427 | /* too big? */ | 434 | /* too big? */ |
428 | switch (dev->speed) { | 435 | switch (dev->speed) { |
436 | case USB_SPEED_SUPER: /* units are 125us */ | ||
437 | /* Handle up to 2^(16-1) microframes */ | ||
438 | if (urb->interval > (1 << 15)) | ||
439 | return -EINVAL; | ||
440 | max = 1 << 15; | ||
429 | case USB_SPEED_HIGH: /* units are microframes */ | 441 | case USB_SPEED_HIGH: /* units are microframes */ |
430 | /* NOTE usb handles 2^15 */ | 442 | /* NOTE usb handles 2^15 */ |
431 | if (urb->interval > (1024 * 8)) | 443 | if (urb->interval > (1024 * 8)) |
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 927a27dd2f8..a26f73880c3 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/usb.h> | 34 | #include <linux/usb.h> |
35 | #include <linux/mutex.h> | 35 | #include <linux/mutex.h> |
36 | #include <linux/workqueue.h> | 36 | #include <linux/workqueue.h> |
37 | #include <linux/debugfs.h> | ||
37 | 38 | ||
38 | #include <asm/io.h> | 39 | #include <asm/io.h> |
39 | #include <linux/scatterlist.h> | 40 | #include <linux/scatterlist.h> |
@@ -139,8 +140,7 @@ static int __find_interface(struct device *dev, void *data) | |||
139 | struct find_interface_arg *arg = data; | 140 | struct find_interface_arg *arg = data; |
140 | struct usb_interface *intf; | 141 | struct usb_interface *intf; |
141 | 142 | ||
142 | /* can't look at usb devices, only interfaces */ | 143 | if (!is_usb_interface(dev)) |
143 | if (is_usb_device(dev)) | ||
144 | return 0; | 144 | return 0; |
145 | 145 | ||
146 | intf = to_usb_interface(dev); | 146 | intf = to_usb_interface(dev); |
@@ -184,11 +184,16 @@ EXPORT_SYMBOL_GPL(usb_find_interface); | |||
184 | static void usb_release_dev(struct device *dev) | 184 | static void usb_release_dev(struct device *dev) |
185 | { | 185 | { |
186 | struct usb_device *udev; | 186 | struct usb_device *udev; |
187 | struct usb_hcd *hcd; | ||
187 | 188 | ||
188 | udev = to_usb_device(dev); | 189 | udev = to_usb_device(dev); |
190 | hcd = bus_to_hcd(udev->bus); | ||
189 | 191 | ||
190 | usb_destroy_configuration(udev); | 192 | usb_destroy_configuration(udev); |
191 | usb_put_hcd(bus_to_hcd(udev->bus)); | 193 | /* Root hubs aren't real devices, so don't free HCD resources */ |
194 | if (hcd->driver->free_dev && udev->parent) | ||
195 | hcd->driver->free_dev(hcd, udev); | ||
196 | usb_put_hcd(hcd); | ||
192 | kfree(udev->product); | 197 | kfree(udev->product); |
193 | kfree(udev->manufacturer); | 198 | kfree(udev->manufacturer); |
194 | kfree(udev->serial); | 199 | kfree(udev->serial); |
@@ -359,6 +364,13 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
359 | kfree(dev); | 364 | kfree(dev); |
360 | return NULL; | 365 | return NULL; |
361 | } | 366 | } |
367 | /* Root hubs aren't true devices, so don't allocate HCD resources */ | ||
368 | if (usb_hcd->driver->alloc_dev && parent && | ||
369 | !usb_hcd->driver->alloc_dev(usb_hcd, dev)) { | ||
370 | usb_put_hcd(bus_to_hcd(bus)); | ||
371 | kfree(dev); | ||
372 | return NULL; | ||
373 | } | ||
362 | 374 | ||
363 | device_initialize(&dev->dev); | 375 | device_initialize(&dev->dev); |
364 | dev->dev.bus = &usb_bus_type; | 376 | dev->dev.bus = &usb_bus_type; |
@@ -386,18 +398,24 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
386 | */ | 398 | */ |
387 | if (unlikely(!parent)) { | 399 | if (unlikely(!parent)) { |
388 | dev->devpath[0] = '0'; | 400 | dev->devpath[0] = '0'; |
401 | dev->route = 0; | ||
389 | 402 | ||
390 | dev->dev.parent = bus->controller; | 403 | dev->dev.parent = bus->controller; |
391 | dev_set_name(&dev->dev, "usb%d", bus->busnum); | 404 | dev_set_name(&dev->dev, "usb%d", bus->busnum); |
392 | root_hub = 1; | 405 | root_hub = 1; |
393 | } else { | 406 | } else { |
394 | /* match any labeling on the hubs; it's one-based */ | 407 | /* match any labeling on the hubs; it's one-based */ |
395 | if (parent->devpath[0] == '0') | 408 | if (parent->devpath[0] == '0') { |
396 | snprintf(dev->devpath, sizeof dev->devpath, | 409 | snprintf(dev->devpath, sizeof dev->devpath, |
397 | "%d", port1); | 410 | "%d", port1); |
398 | else | 411 | /* Root ports are not counted in route string */ |
412 | dev->route = 0; | ||
413 | } else { | ||
399 | snprintf(dev->devpath, sizeof dev->devpath, | 414 | snprintf(dev->devpath, sizeof dev->devpath, |
400 | "%s.%d", parent->devpath, port1); | 415 | "%s.%d", parent->devpath, port1); |
416 | dev->route = parent->route + | ||
417 | (port1 << ((parent->level - 1)*4)); | ||
418 | } | ||
401 | 419 | ||
402 | dev->dev.parent = &parent->dev; | 420 | dev->dev.parent = &parent->dev; |
403 | dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); | 421 | dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); |
@@ -810,12 +828,12 @@ void usb_buffer_dmasync(struct urb *urb) | |||
810 | return; | 828 | return; |
811 | 829 | ||
812 | if (controller->dma_mask) { | 830 | if (controller->dma_mask) { |
813 | dma_sync_single(controller, | 831 | dma_sync_single_for_cpu(controller, |
814 | urb->transfer_dma, urb->transfer_buffer_length, | 832 | urb->transfer_dma, urb->transfer_buffer_length, |
815 | usb_pipein(urb->pipe) | 833 | usb_pipein(urb->pipe) |
816 | ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | 834 | ? DMA_FROM_DEVICE : DMA_TO_DEVICE); |
817 | if (usb_pipecontrol(urb->pipe)) | 835 | if (usb_pipecontrol(urb->pipe)) |
818 | dma_sync_single(controller, | 836 | dma_sync_single_for_cpu(controller, |
819 | urb->setup_dma, | 837 | urb->setup_dma, |
820 | sizeof(struct usb_ctrlrequest), | 838 | sizeof(struct usb_ctrlrequest), |
821 | DMA_TO_DEVICE); | 839 | DMA_TO_DEVICE); |
@@ -933,8 +951,8 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in, | |||
933 | || !controller->dma_mask) | 951 | || !controller->dma_mask) |
934 | return; | 952 | return; |
935 | 953 | ||
936 | dma_sync_sg(controller, sg, n_hw_ents, | 954 | dma_sync_sg_for_cpu(controller, sg, n_hw_ents, |
937 | is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | 955 | is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); |
938 | } | 956 | } |
939 | EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg); | 957 | EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg); |
940 | #endif | 958 | #endif |
@@ -1012,6 +1030,35 @@ static struct notifier_block usb_bus_nb = { | |||
1012 | .notifier_call = usb_bus_notify, | 1030 | .notifier_call = usb_bus_notify, |
1013 | }; | 1031 | }; |
1014 | 1032 | ||
1033 | struct dentry *usb_debug_root; | ||
1034 | EXPORT_SYMBOL_GPL(usb_debug_root); | ||
1035 | |||
1036 | struct dentry *usb_debug_devices; | ||
1037 | |||
1038 | static int usb_debugfs_init(void) | ||
1039 | { | ||
1040 | usb_debug_root = debugfs_create_dir("usb", NULL); | ||
1041 | if (!usb_debug_root) | ||
1042 | return -ENOENT; | ||
1043 | |||
1044 | usb_debug_devices = debugfs_create_file("devices", 0444, | ||
1045 | usb_debug_root, NULL, | ||
1046 | &usbfs_devices_fops); | ||
1047 | if (!usb_debug_devices) { | ||
1048 | debugfs_remove(usb_debug_root); | ||
1049 | usb_debug_root = NULL; | ||
1050 | return -ENOENT; | ||
1051 | } | ||
1052 | |||
1053 | return 0; | ||
1054 | } | ||
1055 | |||
1056 | static void usb_debugfs_cleanup(void) | ||
1057 | { | ||
1058 | debugfs_remove(usb_debug_devices); | ||
1059 | debugfs_remove(usb_debug_root); | ||
1060 | } | ||
1061 | |||
1015 | /* | 1062 | /* |
1016 | * Init | 1063 | * Init |
1017 | */ | 1064 | */ |
@@ -1023,6 +1070,10 @@ static int __init usb_init(void) | |||
1023 | return 0; | 1070 | return 0; |
1024 | } | 1071 | } |
1025 | 1072 | ||
1073 | retval = usb_debugfs_init(); | ||
1074 | if (retval) | ||
1075 | goto out; | ||
1076 | |||
1026 | retval = ksuspend_usb_init(); | 1077 | retval = ksuspend_usb_init(); |
1027 | if (retval) | 1078 | if (retval) |
1028 | goto out; | 1079 | goto out; |
@@ -1032,9 +1083,6 @@ static int __init usb_init(void) | |||
1032 | retval = bus_register_notifier(&usb_bus_type, &usb_bus_nb); | 1083 | retval = bus_register_notifier(&usb_bus_type, &usb_bus_nb); |
1033 | if (retval) | 1084 | if (retval) |
1034 | goto bus_notifier_failed; | 1085 | goto bus_notifier_failed; |
1035 | retval = usb_host_init(); | ||
1036 | if (retval) | ||
1037 | goto host_init_failed; | ||
1038 | retval = usb_major_init(); | 1086 | retval = usb_major_init(); |
1039 | if (retval) | 1087 | if (retval) |
1040 | goto major_init_failed; | 1088 | goto major_init_failed; |
@@ -1064,8 +1112,6 @@ usb_devio_init_failed: | |||
1064 | driver_register_failed: | 1112 | driver_register_failed: |
1065 | usb_major_cleanup(); | 1113 | usb_major_cleanup(); |
1066 | major_init_failed: | 1114 | major_init_failed: |
1067 | usb_host_cleanup(); | ||
1068 | host_init_failed: | ||
1069 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); | 1115 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); |
1070 | bus_notifier_failed: | 1116 | bus_notifier_failed: |
1071 | bus_unregister(&usb_bus_type); | 1117 | bus_unregister(&usb_bus_type); |
@@ -1090,10 +1136,10 @@ static void __exit usb_exit(void) | |||
1090 | usb_deregister(&usbfs_driver); | 1136 | usb_deregister(&usbfs_driver); |
1091 | usb_devio_cleanup(); | 1137 | usb_devio_cleanup(); |
1092 | usb_hub_cleanup(); | 1138 | usb_hub_cleanup(); |
1093 | usb_host_cleanup(); | ||
1094 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); | 1139 | bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); |
1095 | bus_unregister(&usb_bus_type); | 1140 | bus_unregister(&usb_bus_type); |
1096 | ksuspend_usb_cleanup(); | 1141 | ksuspend_usb_cleanup(); |
1142 | usb_debugfs_cleanup(); | ||
1097 | } | 1143 | } |
1098 | 1144 | ||
1099 | subsys_initcall(usb_init); | 1145 | subsys_initcall(usb_init); |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 79d8a9ea559..e2a8cfaade1 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -41,8 +41,6 @@ extern int usb_hub_init(void); | |||
41 | extern void usb_hub_cleanup(void); | 41 | extern void usb_hub_cleanup(void); |
42 | extern int usb_major_init(void); | 42 | extern int usb_major_init(void); |
43 | extern void usb_major_cleanup(void); | 43 | extern void usb_major_cleanup(void); |
44 | extern int usb_host_init(void); | ||
45 | extern void usb_host_cleanup(void); | ||
46 | 44 | ||
47 | #ifdef CONFIG_PM | 45 | #ifdef CONFIG_PM |
48 | 46 | ||
@@ -106,6 +104,7 @@ extern struct workqueue_struct *ksuspend_usb_wq; | |||
106 | extern struct bus_type usb_bus_type; | 104 | extern struct bus_type usb_bus_type; |
107 | extern struct device_type usb_device_type; | 105 | extern struct device_type usb_device_type; |
108 | extern struct device_type usb_if_device_type; | 106 | extern struct device_type usb_if_device_type; |
107 | extern struct device_type usb_ep_device_type; | ||
109 | extern struct usb_device_driver usb_generic_driver; | 108 | extern struct usb_device_driver usb_generic_driver; |
110 | 109 | ||
111 | static inline int is_usb_device(const struct device *dev) | 110 | static inline int is_usb_device(const struct device *dev) |
@@ -113,6 +112,16 @@ static inline int is_usb_device(const struct device *dev) | |||
113 | return dev->type == &usb_device_type; | 112 | return dev->type == &usb_device_type; |
114 | } | 113 | } |
115 | 114 | ||
115 | static inline int is_usb_interface(const struct device *dev) | ||
116 | { | ||
117 | return dev->type == &usb_if_device_type; | ||
118 | } | ||
119 | |||
120 | static inline int is_usb_endpoint(const struct device *dev) | ||
121 | { | ||
122 | return dev->type == &usb_ep_device_type; | ||
123 | } | ||
124 | |||
116 | /* Do the same for device drivers and interface drivers. */ | 125 | /* Do the same for device drivers and interface drivers. */ |
117 | 126 | ||
118 | static inline int is_usb_device_driver(struct device_driver *drv) | 127 | static inline int is_usb_device_driver(struct device_driver *drv) |