diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-16 18:04:26 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-16 18:04:26 -0400 |
commit | 971f115a50afbe409825c9f3399d5a3b9aca4381 (patch) | |
tree | cb42dc07a032e325f22b64d961587c081225c6d6 /drivers/usb/core | |
parent | 2e270d84223262a38d4755c61d55f5c73ea89e56 (diff) | |
parent | 500132a0f26ad7d9916102193cbc6c1b1becb373 (diff) |
Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (172 commits)
USB: Add support for SuperSpeed isoc endpoints
xhci: Clean up cycle bit math used during stalls.
xhci: Fix cycle bit calculation during stall handling.
xhci: Update internal dequeue pointers after stalls.
USB: Disable auto-suspend for USB 3.0 hubs.
USB: Remove bogus USB_PORT_STAT_SUPER_SPEED symbol.
xhci: Return canceled URBs immediately when host is halted.
xhci: Fixes for suspend/resume of shared HCDs.
xhci: Fix re-init on power loss after resume.
xhci: Make roothub functions deal with device removal.
xhci: Limit roothub ports to 15 USB3 & 31 USB2 ports.
xhci: Return a USB 3.0 hub descriptor for USB3 roothub.
xhci: Register second xHCI roothub.
xhci: Change xhci_find_slot_id_by_port() API.
xhci: Refactor bus suspend state into a struct.
xhci: Index with a port array instead of PORTSC addresses.
USB: Set usb_hcd->state and flags for shared roothubs.
usb: Make core allocate resources per PCI-device.
usb: Store bus type in usb_hcd, not in driver flags.
usb: Change usb_hcd->bandwidth_mutex to a pointer.
...
Diffstat (limited to 'drivers/usb/core')
-rw-r--r-- | drivers/usb/core/buffer.c | 26 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 5 | ||||
-rw-r--r-- | drivers/usb/core/hcd-pci.c | 56 | ||||
-rw-r--r-- | drivers/usb/core/hcd.c | 281 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 199 | ||||
-rw-r--r-- | drivers/usb/core/message.c | 22 | ||||
-rw-r--r-- | drivers/usb/core/urb.c | 11 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 13 |
8 files changed, 433 insertions, 180 deletions
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 2c6965484fe8..b0585e623ba9 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c | |||
@@ -10,7 +10,7 @@ | |||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/device.h> | 11 | #include <linux/device.h> |
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <asm/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
15 | #include <linux/dmapool.h> | 15 | #include <linux/dmapool.h> |
16 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
@@ -22,7 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* FIXME tune these based on pool statistics ... */ | 24 | /* FIXME tune these based on pool statistics ... */ |
25 | static const size_t pool_max [HCD_BUFFER_POOLS] = { | 25 | static const size_t pool_max[HCD_BUFFER_POOLS] = { |
26 | /* platforms without dma-friendly caches might need to | 26 | /* platforms without dma-friendly caches might need to |
27 | * prevent cacheline sharing... | 27 | * prevent cacheline sharing... |
28 | */ | 28 | */ |
@@ -51,7 +51,7 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = { | |||
51 | int hcd_buffer_create(struct usb_hcd *hcd) | 51 | int hcd_buffer_create(struct usb_hcd *hcd) |
52 | { | 52 | { |
53 | char name[16]; | 53 | char name[16]; |
54 | int i, size; | 54 | int i, size; |
55 | 55 | ||
56 | if (!hcd->self.controller->dma_mask && | 56 | if (!hcd->self.controller->dma_mask && |
57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) | 57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) |
@@ -64,7 +64,7 @@ int hcd_buffer_create(struct usb_hcd *hcd) | |||
64 | snprintf(name, sizeof name, "buffer-%d", size); | 64 | snprintf(name, sizeof name, "buffer-%d", size); |
65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, | 65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, |
66 | size, size, 0); | 66 | size, size, 0); |
67 | if (!hcd->pool [i]) { | 67 | if (!hcd->pool[i]) { |
68 | hcd_buffer_destroy(hcd); | 68 | hcd_buffer_destroy(hcd); |
69 | return -ENOMEM; | 69 | return -ENOMEM; |
70 | } | 70 | } |
@@ -99,14 +99,14 @@ void hcd_buffer_destroy(struct usb_hcd *hcd) | |||
99 | */ | 99 | */ |
100 | 100 | ||
101 | void *hcd_buffer_alloc( | 101 | void *hcd_buffer_alloc( |
102 | struct usb_bus *bus, | 102 | struct usb_bus *bus, |
103 | size_t size, | 103 | size_t size, |
104 | gfp_t mem_flags, | 104 | gfp_t mem_flags, |
105 | dma_addr_t *dma | 105 | dma_addr_t *dma |
106 | ) | 106 | ) |
107 | { | 107 | { |
108 | struct usb_hcd *hcd = bus_to_hcd(bus); | 108 | struct usb_hcd *hcd = bus_to_hcd(bus); |
109 | int i; | 109 | int i; |
110 | 110 | ||
111 | /* some USB hosts just use PIO */ | 111 | /* some USB hosts just use PIO */ |
112 | if (!bus->controller->dma_mask && | 112 | if (!bus->controller->dma_mask && |
@@ -116,21 +116,21 @@ void *hcd_buffer_alloc( | |||
116 | } | 116 | } |
117 | 117 | ||
118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
119 | if (size <= pool_max [i]) | 119 | if (size <= pool_max[i]) |
120 | return dma_pool_alloc(hcd->pool [i], mem_flags, dma); | 120 | return dma_pool_alloc(hcd->pool[i], mem_flags, dma); |
121 | } | 121 | } |
122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); | 122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | void hcd_buffer_free( | 125 | void hcd_buffer_free( |
126 | struct usb_bus *bus, | 126 | struct usb_bus *bus, |
127 | size_t size, | 127 | size_t size, |
128 | void *addr, | 128 | void *addr, |
129 | dma_addr_t dma | 129 | dma_addr_t dma |
130 | ) | 130 | ) |
131 | { | 131 | { |
132 | struct usb_hcd *hcd = bus_to_hcd(bus); | 132 | struct usb_hcd *hcd = bus_to_hcd(bus); |
133 | int i; | 133 | int i; |
134 | 134 | ||
135 | if (!addr) | 135 | if (!addr) |
136 | return; | 136 | return; |
@@ -142,8 +142,8 @@ void hcd_buffer_free( | |||
142 | } | 142 | } |
143 | 143 | ||
144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
145 | if (size <= pool_max [i]) { | 145 | if (size <= pool_max[i]) { |
146 | dma_pool_free(hcd->pool [i], addr, dma); | 146 | dma_pool_free(hcd->pool[i], addr, dma); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | } | 149 | } |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index fca61720b873..38072e4e74bd 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -1659,6 +1659,11 @@ static int usb_runtime_suspend(struct device *dev) | |||
1659 | return -EAGAIN; | 1659 | return -EAGAIN; |
1660 | 1660 | ||
1661 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | 1661 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1662 | /* The PM core reacts badly unless the return code is 0, | ||
1663 | * -EAGAIN, or -EBUSY, so always return -EBUSY on an error. | ||
1664 | */ | ||
1665 | if (status != 0) | ||
1666 | return -EBUSY; | ||
1662 | return status; | 1667 | return status; |
1663 | } | 1668 | } |
1664 | 1669 | ||
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 64a035ba2eab..ce22f4a84ed0 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -192,13 +192,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
192 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", | 192 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", |
193 | pci_name(dev)); | 193 | pci_name(dev)); |
194 | retval = -ENODEV; | 194 | retval = -ENODEV; |
195 | goto err1; | 195 | goto disable_pci; |
196 | } | 196 | } |
197 | 197 | ||
198 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); | 198 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); |
199 | if (!hcd) { | 199 | if (!hcd) { |
200 | retval = -ENOMEM; | 200 | retval = -ENOMEM; |
201 | goto err1; | 201 | goto disable_pci; |
202 | } | 202 | } |
203 | 203 | ||
204 | if (driver->flags & HCD_MEMORY) { | 204 | if (driver->flags & HCD_MEMORY) { |
@@ -209,13 +209,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
209 | driver->description)) { | 209 | driver->description)) { |
210 | dev_dbg(&dev->dev, "controller already in use\n"); | 210 | dev_dbg(&dev->dev, "controller already in use\n"); |
211 | retval = -EBUSY; | 211 | retval = -EBUSY; |
212 | goto err2; | 212 | goto clear_companion; |
213 | } | 213 | } |
214 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | 214 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
215 | if (hcd->regs == NULL) { | 215 | if (hcd->regs == NULL) { |
216 | dev_dbg(&dev->dev, "error mapping memory\n"); | 216 | dev_dbg(&dev->dev, "error mapping memory\n"); |
217 | retval = -EFAULT; | 217 | retval = -EFAULT; |
218 | goto err3; | 218 | goto release_mem_region; |
219 | } | 219 | } |
220 | 220 | ||
221 | } else { | 221 | } else { |
@@ -236,7 +236,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
236 | if (region == PCI_ROM_RESOURCE) { | 236 | if (region == PCI_ROM_RESOURCE) { |
237 | dev_dbg(&dev->dev, "no i/o regions available\n"); | 237 | dev_dbg(&dev->dev, "no i/o regions available\n"); |
238 | retval = -EBUSY; | 238 | retval = -EBUSY; |
239 | goto err2; | 239 | goto clear_companion; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
@@ -244,24 +244,24 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
244 | 244 | ||
245 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 245 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
246 | if (retval != 0) | 246 | if (retval != 0) |
247 | goto err4; | 247 | goto unmap_registers; |
248 | set_hs_companion(dev, hcd); | 248 | set_hs_companion(dev, hcd); |
249 | 249 | ||
250 | if (pci_dev_run_wake(dev)) | 250 | if (pci_dev_run_wake(dev)) |
251 | pm_runtime_put_noidle(&dev->dev); | 251 | pm_runtime_put_noidle(&dev->dev); |
252 | return retval; | 252 | return retval; |
253 | 253 | ||
254 | err4: | 254 | unmap_registers: |
255 | if (driver->flags & HCD_MEMORY) { | 255 | if (driver->flags & HCD_MEMORY) { |
256 | iounmap(hcd->regs); | 256 | iounmap(hcd->regs); |
257 | err3: | 257 | release_mem_region: |
258 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 258 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
259 | } else | 259 | } else |
260 | release_region(hcd->rsrc_start, hcd->rsrc_len); | 260 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
261 | err2: | 261 | clear_companion: |
262 | clear_hs_companion(dev, hcd); | 262 | clear_hs_companion(dev, hcd); |
263 | usb_put_hcd(hcd); | 263 | usb_put_hcd(hcd); |
264 | err1: | 264 | disable_pci: |
265 | pci_disable_device(dev); | 265 | pci_disable_device(dev); |
266 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); | 266 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); |
267 | return retval; | 267 | return retval; |
@@ -363,11 +363,17 @@ static int check_root_hub_suspended(struct device *dev) | |||
363 | struct pci_dev *pci_dev = to_pci_dev(dev); | 363 | struct pci_dev *pci_dev = to_pci_dev(dev); |
364 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 364 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
365 | 365 | ||
366 | if (!(hcd->state == HC_STATE_SUSPENDED || | 366 | if (HCD_RH_RUNNING(hcd)) { |
367 | hcd->state == HC_STATE_HALT)) { | ||
368 | dev_warn(dev, "Root hub is not suspended\n"); | 367 | dev_warn(dev, "Root hub is not suspended\n"); |
369 | return -EBUSY; | 368 | return -EBUSY; |
370 | } | 369 | } |
370 | if (hcd->shared_hcd) { | ||
371 | hcd = hcd->shared_hcd; | ||
372 | if (HCD_RH_RUNNING(hcd)) { | ||
373 | dev_warn(dev, "Secondary root hub is not suspended\n"); | ||
374 | return -EBUSY; | ||
375 | } | ||
376 | } | ||
371 | return 0; | 377 | return 0; |
372 | } | 378 | } |
373 | 379 | ||
@@ -386,17 +392,22 @@ static int suspend_common(struct device *dev, bool do_wakeup) | |||
386 | if (retval) | 392 | if (retval) |
387 | return retval; | 393 | return retval; |
388 | 394 | ||
389 | if (hcd->driver->pci_suspend) { | 395 | if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) { |
390 | /* Optimization: Don't suspend if a root-hub wakeup is | 396 | /* Optimization: Don't suspend if a root-hub wakeup is |
391 | * pending and it would cause the HCD to wake up anyway. | 397 | * pending and it would cause the HCD to wake up anyway. |
392 | */ | 398 | */ |
393 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) | 399 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) |
394 | return -EBUSY; | 400 | return -EBUSY; |
401 | if (do_wakeup && hcd->shared_hcd && | ||
402 | HCD_WAKEUP_PENDING(hcd->shared_hcd)) | ||
403 | return -EBUSY; | ||
395 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); | 404 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); |
396 | suspend_report_result(hcd->driver->pci_suspend, retval); | 405 | suspend_report_result(hcd->driver->pci_suspend, retval); |
397 | 406 | ||
398 | /* Check again in case wakeup raced with pci_suspend */ | 407 | /* Check again in case wakeup raced with pci_suspend */ |
399 | if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | 408 | if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) || |
409 | (retval == 0 && do_wakeup && hcd->shared_hcd && | ||
410 | HCD_WAKEUP_PENDING(hcd->shared_hcd))) { | ||
400 | if (hcd->driver->pci_resume) | 411 | if (hcd->driver->pci_resume) |
401 | hcd->driver->pci_resume(hcd, false); | 412 | hcd->driver->pci_resume(hcd, false); |
402 | retval = -EBUSY; | 413 | retval = -EBUSY; |
@@ -427,7 +438,9 @@ static int resume_common(struct device *dev, int event) | |||
427 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 438 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
428 | int retval; | 439 | int retval; |
429 | 440 | ||
430 | if (hcd->state != HC_STATE_SUSPENDED) { | 441 | if (HCD_RH_RUNNING(hcd) || |
442 | (hcd->shared_hcd && | ||
443 | HCD_RH_RUNNING(hcd->shared_hcd))) { | ||
431 | dev_dbg(dev, "can't resume, not suspended!\n"); | 444 | dev_dbg(dev, "can't resume, not suspended!\n"); |
432 | return 0; | 445 | return 0; |
433 | } | 446 | } |
@@ -441,8 +454,10 @@ static int resume_common(struct device *dev, int event) | |||
441 | pci_set_master(pci_dev); | 454 | pci_set_master(pci_dev); |
442 | 455 | ||
443 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 456 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
457 | if (hcd->shared_hcd) | ||
458 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
444 | 459 | ||
445 | if (hcd->driver->pci_resume) { | 460 | if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { |
446 | if (event != PM_EVENT_AUTO_RESUME) | 461 | if (event != PM_EVENT_AUTO_RESUME) |
447 | wait_for_companions(pci_dev, hcd); | 462 | wait_for_companions(pci_dev, hcd); |
448 | 463 | ||
@@ -450,6 +465,8 @@ static int resume_common(struct device *dev, int event) | |||
450 | event == PM_EVENT_RESTORE); | 465 | event == PM_EVENT_RESTORE); |
451 | if (retval) { | 466 | if (retval) { |
452 | dev_err(dev, "PCI post-resume error %d!\n", retval); | 467 | dev_err(dev, "PCI post-resume error %d!\n", retval); |
468 | if (hcd->shared_hcd) | ||
469 | usb_hc_died(hcd->shared_hcd); | ||
453 | usb_hc_died(hcd); | 470 | usb_hc_died(hcd); |
454 | } | 471 | } |
455 | } | 472 | } |
@@ -475,10 +492,11 @@ static int hcd_pci_suspend_noirq(struct device *dev) | |||
475 | 492 | ||
476 | pci_save_state(pci_dev); | 493 | pci_save_state(pci_dev); |
477 | 494 | ||
478 | /* If the root hub is HALTed rather than SUSPENDed, | 495 | /* If the root hub is dead rather than suspended, disallow remote |
479 | * disallow remote wakeup. | 496 | * wakeup. usb_hc_died() should ensure that both hosts are marked as |
497 | * dying, so we only need to check the primary roothub. | ||
480 | */ | 498 | */ |
481 | if (hcd->state == HC_STATE_HALT) | 499 | if (HCD_DEAD(hcd)) |
482 | device_set_wakeup_enable(dev, 0); | 500 | device_set_wakeup_enable(dev, 0); |
483 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); | 501 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); |
484 | 502 | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index e935f71d7a34..02b4dbfa488a 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -297,7 +297,7 @@ static const u8 ss_rh_config_descriptor[] = { | |||
297 | /* one configuration */ | 297 | /* one configuration */ |
298 | 0x09, /* __u8 bLength; */ | 298 | 0x09, /* __u8 bLength; */ |
299 | 0x02, /* __u8 bDescriptorType; Configuration */ | 299 | 0x02, /* __u8 bDescriptorType; Configuration */ |
300 | 0x19, 0x00, /* __le16 wTotalLength; FIXME */ | 300 | 0x1f, 0x00, /* __le16 wTotalLength; */ |
301 | 0x01, /* __u8 bNumInterfaces; (1) */ | 301 | 0x01, /* __u8 bNumInterfaces; (1) */ |
302 | 0x01, /* __u8 bConfigurationValue; */ | 302 | 0x01, /* __u8 bConfigurationValue; */ |
303 | 0x00, /* __u8 iConfiguration; */ | 303 | 0x00, /* __u8 iConfiguration; */ |
@@ -327,11 +327,14 @@ static const u8 ss_rh_config_descriptor[] = { | |||
327 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) | 327 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) |
328 | * see hub.c:hub_configure() for details. */ | 328 | * see hub.c:hub_configure() for details. */ |
329 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, | 329 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, |
330 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ | 330 | 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ |
331 | /* | 331 | |
332 | * All 3.0 hubs should have an endpoint companion descriptor, | 332 | /* one SuperSpeed endpoint companion descriptor */ |
333 | * but we're ignoring that for now. FIXME? | 333 | 0x06, /* __u8 ss_bLength */ |
334 | */ | 334 | 0x30, /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */ |
335 | 0x00, /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */ | ||
336 | 0x00, /* __u8 ss_bmAttributes; 1 packet per service interval */ | ||
337 | 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */ | ||
335 | }; | 338 | }; |
336 | 339 | ||
337 | /*-------------------------------------------------------------------------*/ | 340 | /*-------------------------------------------------------------------------*/ |
@@ -504,7 +507,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
504 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | 507 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
505 | switch (wValue & 0xff00) { | 508 | switch (wValue & 0xff00) { |
506 | case USB_DT_DEVICE << 8: | 509 | case USB_DT_DEVICE << 8: |
507 | switch (hcd->driver->flags & HCD_MASK) { | 510 | switch (hcd->speed) { |
508 | case HCD_USB3: | 511 | case HCD_USB3: |
509 | bufp = usb3_rh_dev_descriptor; | 512 | bufp = usb3_rh_dev_descriptor; |
510 | break; | 513 | break; |
@@ -522,7 +525,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
522 | patch_protocol = 1; | 525 | patch_protocol = 1; |
523 | break; | 526 | break; |
524 | case USB_DT_CONFIG << 8: | 527 | case USB_DT_CONFIG << 8: |
525 | switch (hcd->driver->flags & HCD_MASK) { | 528 | switch (hcd->speed) { |
526 | case HCD_USB3: | 529 | case HCD_USB3: |
527 | bufp = ss_rh_config_descriptor; | 530 | bufp = ss_rh_config_descriptor; |
528 | len = sizeof ss_rh_config_descriptor; | 531 | len = sizeof ss_rh_config_descriptor; |
@@ -983,7 +986,7 @@ static int register_root_hub(struct usb_hcd *hcd) | |||
983 | spin_unlock_irq (&hcd_root_hub_lock); | 986 | spin_unlock_irq (&hcd_root_hub_lock); |
984 | 987 | ||
985 | /* Did the HC die before the root hub was registered? */ | 988 | /* Did the HC die before the root hub was registered? */ |
986 | if (hcd->state == HC_STATE_HALT) | 989 | if (HCD_DEAD(hcd) || hcd->state == HC_STATE_HALT) |
987 | usb_hc_died (hcd); /* This time clean up */ | 990 | usb_hc_died (hcd); /* This time clean up */ |
988 | } | 991 | } |
989 | 992 | ||
@@ -1089,13 +1092,10 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) | |||
1089 | * Check the host controller's state and add the URB to the | 1092 | * Check the host controller's state and add the URB to the |
1090 | * endpoint's queue. | 1093 | * endpoint's queue. |
1091 | */ | 1094 | */ |
1092 | switch (hcd->state) { | 1095 | if (HCD_RH_RUNNING(hcd)) { |
1093 | case HC_STATE_RUNNING: | ||
1094 | case HC_STATE_RESUMING: | ||
1095 | urb->unlinked = 0; | 1096 | urb->unlinked = 0; |
1096 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); | 1097 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); |
1097 | break; | 1098 | } else { |
1098 | default: | ||
1099 | rc = -ESHUTDOWN; | 1099 | rc = -ESHUTDOWN; |
1100 | goto done; | 1100 | goto done; |
1101 | } | 1101 | } |
@@ -1153,6 +1153,8 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, | |||
1153 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " | 1153 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " |
1154 | "Controller is probably using the wrong IRQ.\n"); | 1154 | "Controller is probably using the wrong IRQ.\n"); |
1155 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 1155 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
1156 | if (hcd->shared_hcd) | ||
1157 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
1156 | } | 1158 | } |
1157 | 1159 | ||
1158 | return 0; | 1160 | return 0; |
@@ -1262,7 +1264,7 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle, | |||
1262 | *dma_handle = 0; | 1264 | *dma_handle = 0; |
1263 | } | 1265 | } |
1264 | 1266 | ||
1265 | void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) | 1267 | void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) |
1266 | { | 1268 | { |
1267 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) | 1269 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) |
1268 | dma_unmap_single(hcd->self.controller, | 1270 | dma_unmap_single(hcd->self.controller, |
@@ -1279,13 +1281,21 @@ void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1279 | /* Make it safe to call this routine more than once */ | 1281 | /* Make it safe to call this routine more than once */ |
1280 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); | 1282 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); |
1281 | } | 1283 | } |
1282 | EXPORT_SYMBOL_GPL(unmap_urb_setup_for_dma); | 1284 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma); |
1283 | 1285 | ||
1284 | void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | 1286 | static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) |
1287 | { | ||
1288 | if (hcd->driver->unmap_urb_for_dma) | ||
1289 | hcd->driver->unmap_urb_for_dma(hcd, urb); | ||
1290 | else | ||
1291 | usb_hcd_unmap_urb_for_dma(hcd, urb); | ||
1292 | } | ||
1293 | |||
1294 | void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
1285 | { | 1295 | { |
1286 | enum dma_data_direction dir; | 1296 | enum dma_data_direction dir; |
1287 | 1297 | ||
1288 | unmap_urb_setup_for_dma(hcd, urb); | 1298 | usb_hcd_unmap_urb_setup_for_dma(hcd, urb); |
1289 | 1299 | ||
1290 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 1300 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; |
1291 | if (urb->transfer_flags & URB_DMA_MAP_SG) | 1301 | if (urb->transfer_flags & URB_DMA_MAP_SG) |
@@ -1314,11 +1324,20 @@ void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1314 | urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | | 1324 | urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | |
1315 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); | 1325 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); |
1316 | } | 1326 | } |
1317 | EXPORT_SYMBOL_GPL(unmap_urb_for_dma); | 1327 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma); |
1318 | 1328 | ||
1319 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | 1329 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, |
1320 | gfp_t mem_flags) | 1330 | gfp_t mem_flags) |
1321 | { | 1331 | { |
1332 | if (hcd->driver->map_urb_for_dma) | ||
1333 | return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); | ||
1334 | else | ||
1335 | return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
1336 | } | ||
1337 | |||
1338 | int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | ||
1339 | gfp_t mem_flags) | ||
1340 | { | ||
1322 | enum dma_data_direction dir; | 1341 | enum dma_data_direction dir; |
1323 | int ret = 0; | 1342 | int ret = 0; |
1324 | 1343 | ||
@@ -1410,10 +1429,11 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1410 | } | 1429 | } |
1411 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | | 1430 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | |
1412 | URB_SETUP_MAP_LOCAL))) | 1431 | URB_SETUP_MAP_LOCAL))) |
1413 | unmap_urb_for_dma(hcd, urb); | 1432 | usb_hcd_unmap_urb_for_dma(hcd, urb); |
1414 | } | 1433 | } |
1415 | return ret; | 1434 | return ret; |
1416 | } | 1435 | } |
1436 | EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma); | ||
1417 | 1437 | ||
1418 | /*-------------------------------------------------------------------------*/ | 1438 | /*-------------------------------------------------------------------------*/ |
1419 | 1439 | ||
@@ -1913,7 +1933,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev) | |||
1913 | { | 1933 | { |
1914 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 1934 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1915 | 1935 | ||
1916 | if (!HC_IS_RUNNING (hcd->state)) | 1936 | if (!HCD_RH_RUNNING(hcd)) |
1917 | return -ESHUTDOWN; | 1937 | return -ESHUTDOWN; |
1918 | return hcd->driver->get_frame_number (hcd); | 1938 | return hcd->driver->get_frame_number (hcd); |
1919 | } | 1939 | } |
@@ -1930,9 +1950,15 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1930 | 1950 | ||
1931 | dev_dbg(&rhdev->dev, "bus %s%s\n", | 1951 | dev_dbg(&rhdev->dev, "bus %s%s\n", |
1932 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); | 1952 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); |
1953 | if (HCD_DEAD(hcd)) { | ||
1954 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); | ||
1955 | return 0; | ||
1956 | } | ||
1957 | |||
1933 | if (!hcd->driver->bus_suspend) { | 1958 | if (!hcd->driver->bus_suspend) { |
1934 | status = -ENOENT; | 1959 | status = -ENOENT; |
1935 | } else { | 1960 | } else { |
1961 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1936 | hcd->state = HC_STATE_QUIESCING; | 1962 | hcd->state = HC_STATE_QUIESCING; |
1937 | status = hcd->driver->bus_suspend(hcd); | 1963 | status = hcd->driver->bus_suspend(hcd); |
1938 | } | 1964 | } |
@@ -1940,7 +1966,12 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1940 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); | 1966 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); |
1941 | hcd->state = HC_STATE_SUSPENDED; | 1967 | hcd->state = HC_STATE_SUSPENDED; |
1942 | } else { | 1968 | } else { |
1943 | hcd->state = old_state; | 1969 | spin_lock_irq(&hcd_root_hub_lock); |
1970 | if (!HCD_DEAD(hcd)) { | ||
1971 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1972 | hcd->state = old_state; | ||
1973 | } | ||
1974 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1944 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 1975 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
1945 | "suspend", status); | 1976 | "suspend", status); |
1946 | } | 1977 | } |
@@ -1955,9 +1986,13 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1955 | 1986 | ||
1956 | dev_dbg(&rhdev->dev, "usb %s%s\n", | 1987 | dev_dbg(&rhdev->dev, "usb %s%s\n", |
1957 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); | 1988 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); |
1989 | if (HCD_DEAD(hcd)) { | ||
1990 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); | ||
1991 | return 0; | ||
1992 | } | ||
1958 | if (!hcd->driver->bus_resume) | 1993 | if (!hcd->driver->bus_resume) |
1959 | return -ENOENT; | 1994 | return -ENOENT; |
1960 | if (hcd->state == HC_STATE_RUNNING) | 1995 | if (HCD_RH_RUNNING(hcd)) |
1961 | return 0; | 1996 | return 0; |
1962 | 1997 | ||
1963 | hcd->state = HC_STATE_RESUMING; | 1998 | hcd->state = HC_STATE_RESUMING; |
@@ -1966,10 +2001,15 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1966 | if (status == 0) { | 2001 | if (status == 0) { |
1967 | /* TRSMRCY = 10 msec */ | 2002 | /* TRSMRCY = 10 msec */ |
1968 | msleep(10); | 2003 | msleep(10); |
1969 | usb_set_device_state(rhdev, rhdev->actconfig | 2004 | spin_lock_irq(&hcd_root_hub_lock); |
1970 | ? USB_STATE_CONFIGURED | 2005 | if (!HCD_DEAD(hcd)) { |
1971 | : USB_STATE_ADDRESS); | 2006 | usb_set_device_state(rhdev, rhdev->actconfig |
1972 | hcd->state = HC_STATE_RUNNING; | 2007 | ? USB_STATE_CONFIGURED |
2008 | : USB_STATE_ADDRESS); | ||
2009 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2010 | hcd->state = HC_STATE_RUNNING; | ||
2011 | } | ||
2012 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1973 | } else { | 2013 | } else { |
1974 | hcd->state = old_state; | 2014 | hcd->state = old_state; |
1975 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 2015 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
@@ -2080,12 +2120,14 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd) | |||
2080 | */ | 2120 | */ |
2081 | local_irq_save(flags); | 2121 | local_irq_save(flags); |
2082 | 2122 | ||
2083 | if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { | 2123 | if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) { |
2084 | rc = IRQ_NONE; | 2124 | rc = IRQ_NONE; |
2085 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { | 2125 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { |
2086 | rc = IRQ_NONE; | 2126 | rc = IRQ_NONE; |
2087 | } else { | 2127 | } else { |
2088 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 2128 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
2129 | if (hcd->shared_hcd) | ||
2130 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
2089 | 2131 | ||
2090 | if (unlikely(hcd->state == HC_STATE_HALT)) | 2132 | if (unlikely(hcd->state == HC_STATE_HALT)) |
2091 | usb_hc_died(hcd); | 2133 | usb_hc_died(hcd); |
@@ -2105,7 +2147,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq); | |||
2105 | * | 2147 | * |
2106 | * This is called by bus glue to report a USB host controller that died | 2148 | * This is called by bus glue to report a USB host controller that died |
2107 | * while operations may still have been pending. It's called automatically | 2149 | * while operations may still have been pending. It's called automatically |
2108 | * by the PCI glue, so only glue for non-PCI busses should need to call it. | 2150 | * by the PCI glue, so only glue for non-PCI busses should need to call it. |
2151 | * | ||
2152 | * Only call this function with the primary HCD. | ||
2109 | */ | 2153 | */ |
2110 | void usb_hc_died (struct usb_hcd *hcd) | 2154 | void usb_hc_died (struct usb_hcd *hcd) |
2111 | { | 2155 | { |
@@ -2114,6 +2158,8 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2114 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); | 2158 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); |
2115 | 2159 | ||
2116 | spin_lock_irqsave (&hcd_root_hub_lock, flags); | 2160 | spin_lock_irqsave (&hcd_root_hub_lock, flags); |
2161 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2162 | set_bit(HCD_FLAG_DEAD, &hcd->flags); | ||
2117 | if (hcd->rh_registered) { | 2163 | if (hcd->rh_registered) { |
2118 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2164 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2119 | 2165 | ||
@@ -2122,17 +2168,31 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2122 | USB_STATE_NOTATTACHED); | 2168 | USB_STATE_NOTATTACHED); |
2123 | usb_kick_khubd (hcd->self.root_hub); | 2169 | usb_kick_khubd (hcd->self.root_hub); |
2124 | } | 2170 | } |
2171 | if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { | ||
2172 | hcd = hcd->shared_hcd; | ||
2173 | if (hcd->rh_registered) { | ||
2174 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
2175 | |||
2176 | /* make khubd clean up old urbs and devices */ | ||
2177 | usb_set_device_state(hcd->self.root_hub, | ||
2178 | USB_STATE_NOTATTACHED); | ||
2179 | usb_kick_khubd(hcd->self.root_hub); | ||
2180 | } | ||
2181 | } | ||
2125 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 2182 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
2183 | /* Make sure that the other roothub is also deallocated. */ | ||
2126 | } | 2184 | } |
2127 | EXPORT_SYMBOL_GPL (usb_hc_died); | 2185 | EXPORT_SYMBOL_GPL (usb_hc_died); |
2128 | 2186 | ||
2129 | /*-------------------------------------------------------------------------*/ | 2187 | /*-------------------------------------------------------------------------*/ |
2130 | 2188 | ||
2131 | /** | 2189 | /** |
2132 | * usb_create_hcd - create and initialize an HCD structure | 2190 | * usb_create_shared_hcd - create and initialize an HCD structure |
2133 | * @driver: HC driver that will use this hcd | 2191 | * @driver: HC driver that will use this hcd |
2134 | * @dev: device for this HC, stored in hcd->self.controller | 2192 | * @dev: device for this HC, stored in hcd->self.controller |
2135 | * @bus_name: value to store in hcd->self.bus_name | 2193 | * @bus_name: value to store in hcd->self.bus_name |
2194 | * @primary_hcd: a pointer to the usb_hcd structure that is sharing the | ||
2195 | * PCI device. Only allocate certain resources for the primary HCD | ||
2136 | * Context: !in_interrupt() | 2196 | * Context: !in_interrupt() |
2137 | * | 2197 | * |
2138 | * Allocate a struct usb_hcd, with extra space at the end for the | 2198 | * Allocate a struct usb_hcd, with extra space at the end for the |
@@ -2141,8 +2201,9 @@ EXPORT_SYMBOL_GPL (usb_hc_died); | |||
2141 | * | 2201 | * |
2142 | * If memory is unavailable, returns NULL. | 2202 | * If memory is unavailable, returns NULL. |
2143 | */ | 2203 | */ |
2144 | struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | 2204 | struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, |
2145 | struct device *dev, const char *bus_name) | 2205 | struct device *dev, const char *bus_name, |
2206 | struct usb_hcd *primary_hcd) | ||
2146 | { | 2207 | { |
2147 | struct usb_hcd *hcd; | 2208 | struct usb_hcd *hcd; |
2148 | 2209 | ||
@@ -2151,7 +2212,24 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2151 | dev_dbg (dev, "hcd alloc failed\n"); | 2212 | dev_dbg (dev, "hcd alloc failed\n"); |
2152 | return NULL; | 2213 | return NULL; |
2153 | } | 2214 | } |
2154 | dev_set_drvdata(dev, hcd); | 2215 | if (primary_hcd == NULL) { |
2216 | hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), | ||
2217 | GFP_KERNEL); | ||
2218 | if (!hcd->bandwidth_mutex) { | ||
2219 | kfree(hcd); | ||
2220 | dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); | ||
2221 | return NULL; | ||
2222 | } | ||
2223 | mutex_init(hcd->bandwidth_mutex); | ||
2224 | dev_set_drvdata(dev, hcd); | ||
2225 | } else { | ||
2226 | hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; | ||
2227 | hcd->primary_hcd = primary_hcd; | ||
2228 | primary_hcd->primary_hcd = primary_hcd; | ||
2229 | hcd->shared_hcd = primary_hcd; | ||
2230 | primary_hcd->shared_hcd = hcd; | ||
2231 | } | ||
2232 | |||
2155 | kref_init(&hcd->kref); | 2233 | kref_init(&hcd->kref); |
2156 | 2234 | ||
2157 | usb_bus_init(&hcd->self); | 2235 | usb_bus_init(&hcd->self); |
@@ -2165,19 +2243,53 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2165 | #ifdef CONFIG_USB_SUSPEND | 2243 | #ifdef CONFIG_USB_SUSPEND |
2166 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); | 2244 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); |
2167 | #endif | 2245 | #endif |
2168 | mutex_init(&hcd->bandwidth_mutex); | ||
2169 | 2246 | ||
2170 | hcd->driver = driver; | 2247 | hcd->driver = driver; |
2248 | hcd->speed = driver->flags & HCD_MASK; | ||
2171 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : | 2249 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : |
2172 | "USB Host Controller"; | 2250 | "USB Host Controller"; |
2173 | return hcd; | 2251 | return hcd; |
2174 | } | 2252 | } |
2253 | EXPORT_SYMBOL_GPL(usb_create_shared_hcd); | ||
2254 | |||
2255 | /** | ||
2256 | * usb_create_hcd - create and initialize an HCD structure | ||
2257 | * @driver: HC driver that will use this hcd | ||
2258 | * @dev: device for this HC, stored in hcd->self.controller | ||
2259 | * @bus_name: value to store in hcd->self.bus_name | ||
2260 | * Context: !in_interrupt() | ||
2261 | * | ||
2262 | * Allocate a struct usb_hcd, with extra space at the end for the | ||
2263 | * HC driver's private data. Initialize the generic members of the | ||
2264 | * hcd structure. | ||
2265 | * | ||
2266 | * If memory is unavailable, returns NULL. | ||
2267 | */ | ||
2268 | struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | ||
2269 | struct device *dev, const char *bus_name) | ||
2270 | { | ||
2271 | return usb_create_shared_hcd(driver, dev, bus_name, NULL); | ||
2272 | } | ||
2175 | EXPORT_SYMBOL_GPL(usb_create_hcd); | 2273 | EXPORT_SYMBOL_GPL(usb_create_hcd); |
2176 | 2274 | ||
2275 | /* | ||
2276 | * Roothubs that share one PCI device must also share the bandwidth mutex. | ||
2277 | * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is | ||
2278 | * deallocated. | ||
2279 | * | ||
2280 | * Make sure to only deallocate the bandwidth_mutex when the primary HCD is | ||
2281 | * freed. When hcd_release() is called for the non-primary HCD, set the | ||
2282 | * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be | ||
2283 | * freed shortly). | ||
2284 | */ | ||
2177 | static void hcd_release (struct kref *kref) | 2285 | static void hcd_release (struct kref *kref) |
2178 | { | 2286 | { |
2179 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | 2287 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); |
2180 | 2288 | ||
2289 | if (usb_hcd_is_primary_hcd(hcd)) | ||
2290 | kfree(hcd->bandwidth_mutex); | ||
2291 | else | ||
2292 | hcd->shared_hcd->shared_hcd = NULL; | ||
2181 | kfree(hcd); | 2293 | kfree(hcd); |
2182 | } | 2294 | } |
2183 | 2295 | ||
@@ -2196,6 +2308,54 @@ void usb_put_hcd (struct usb_hcd *hcd) | |||
2196 | } | 2308 | } |
2197 | EXPORT_SYMBOL_GPL(usb_put_hcd); | 2309 | EXPORT_SYMBOL_GPL(usb_put_hcd); |
2198 | 2310 | ||
2311 | int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) | ||
2312 | { | ||
2313 | if (!hcd->primary_hcd) | ||
2314 | return 1; | ||
2315 | return hcd == hcd->primary_hcd; | ||
2316 | } | ||
2317 | EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd); | ||
2318 | |||
2319 | static int usb_hcd_request_irqs(struct usb_hcd *hcd, | ||
2320 | unsigned int irqnum, unsigned long irqflags) | ||
2321 | { | ||
2322 | int retval; | ||
2323 | |||
2324 | if (hcd->driver->irq) { | ||
2325 | |||
2326 | /* IRQF_DISABLED doesn't work as advertised when used together | ||
2327 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2328 | * interrupts we can remove it here. | ||
2329 | */ | ||
2330 | if (irqflags & IRQF_SHARED) | ||
2331 | irqflags &= ~IRQF_DISABLED; | ||
2332 | |||
2333 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2334 | hcd->driver->description, hcd->self.busnum); | ||
2335 | retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2336 | hcd->irq_descr, hcd); | ||
2337 | if (retval != 0) { | ||
2338 | dev_err(hcd->self.controller, | ||
2339 | "request interrupt %d failed\n", | ||
2340 | irqnum); | ||
2341 | return retval; | ||
2342 | } | ||
2343 | hcd->irq = irqnum; | ||
2344 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2345 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2346 | "io mem" : "io base", | ||
2347 | (unsigned long long)hcd->rsrc_start); | ||
2348 | } else { | ||
2349 | hcd->irq = -1; | ||
2350 | if (hcd->rsrc_start) | ||
2351 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2352 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2353 | "io mem" : "io base", | ||
2354 | (unsigned long long)hcd->rsrc_start); | ||
2355 | } | ||
2356 | return 0; | ||
2357 | } | ||
2358 | |||
2199 | /** | 2359 | /** |
2200 | * usb_add_hcd - finish generic HCD structure initialization and register | 2360 | * usb_add_hcd - finish generic HCD structure initialization and register |
2201 | * @hcd: the usb_hcd structure to initialize | 2361 | * @hcd: the usb_hcd structure to initialize |
@@ -2236,7 +2396,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2236 | } | 2396 | } |
2237 | hcd->self.root_hub = rhdev; | 2397 | hcd->self.root_hub = rhdev; |
2238 | 2398 | ||
2239 | switch (hcd->driver->flags & HCD_MASK) { | 2399 | switch (hcd->speed) { |
2240 | case HCD_USB11: | 2400 | case HCD_USB11: |
2241 | rhdev->speed = USB_SPEED_FULL; | 2401 | rhdev->speed = USB_SPEED_FULL; |
2242 | break; | 2402 | break; |
@@ -2256,6 +2416,12 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2256 | */ | 2416 | */ |
2257 | device_init_wakeup(&rhdev->dev, 1); | 2417 | device_init_wakeup(&rhdev->dev, 1); |
2258 | 2418 | ||
2419 | /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is | ||
2420 | * registered. But since the controller can die at any time, | ||
2421 | * let's initialize the flag before touching the hardware. | ||
2422 | */ | ||
2423 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2424 | |||
2259 | /* "reset" is misnamed; its role is now one-time init. the controller | 2425 | /* "reset" is misnamed; its role is now one-time init. the controller |
2260 | * should already have been reset (and boot firmware kicked off etc). | 2426 | * should already have been reset (and boot firmware kicked off etc). |
2261 | */ | 2427 | */ |
@@ -2271,38 +2437,15 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2271 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | 2437 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); |
2272 | 2438 | ||
2273 | /* enable irqs just before we start the controller */ | 2439 | /* enable irqs just before we start the controller */ |
2274 | if (hcd->driver->irq) { | 2440 | if (usb_hcd_is_primary_hcd(hcd)) { |
2275 | 2441 | retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); | |
2276 | /* IRQF_DISABLED doesn't work as advertised when used together | 2442 | if (retval) |
2277 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2278 | * interrupts we can remove it here. | ||
2279 | */ | ||
2280 | if (irqflags & IRQF_SHARED) | ||
2281 | irqflags &= ~IRQF_DISABLED; | ||
2282 | |||
2283 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2284 | hcd->driver->description, hcd->self.busnum); | ||
2285 | if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2286 | hcd->irq_descr, hcd)) != 0) { | ||
2287 | dev_err(hcd->self.controller, | ||
2288 | "request interrupt %d failed\n", irqnum); | ||
2289 | goto err_request_irq; | 2443 | goto err_request_irq; |
2290 | } | ||
2291 | hcd->irq = irqnum; | ||
2292 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2293 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2294 | "io mem" : "io base", | ||
2295 | (unsigned long long)hcd->rsrc_start); | ||
2296 | } else { | ||
2297 | hcd->irq = -1; | ||
2298 | if (hcd->rsrc_start) | ||
2299 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2300 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2301 | "io mem" : "io base", | ||
2302 | (unsigned long long)hcd->rsrc_start); | ||
2303 | } | 2444 | } |
2304 | 2445 | ||
2305 | if ((retval = hcd->driver->start(hcd)) < 0) { | 2446 | hcd->state = HC_STATE_RUNNING; |
2447 | retval = hcd->driver->start(hcd); | ||
2448 | if (retval < 0) { | ||
2306 | dev_err(hcd->self.controller, "startup error %d\n", retval); | 2449 | dev_err(hcd->self.controller, "startup error %d\n", retval); |
2307 | goto err_hcd_driver_start; | 2450 | goto err_hcd_driver_start; |
2308 | } | 2451 | } |
@@ -2323,6 +2466,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2323 | return retval; | 2466 | return retval; |
2324 | 2467 | ||
2325 | error_create_attr_group: | 2468 | error_create_attr_group: |
2469 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2326 | if (HC_IS_RUNNING(hcd->state)) | 2470 | if (HC_IS_RUNNING(hcd->state)) |
2327 | hcd->state = HC_STATE_QUIESCING; | 2471 | hcd->state = HC_STATE_QUIESCING; |
2328 | spin_lock_irq(&hcd_root_hub_lock); | 2472 | spin_lock_irq(&hcd_root_hub_lock); |
@@ -2344,7 +2488,7 @@ err_register_root_hub: | |||
2344 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2488 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2345 | del_timer_sync(&hcd->rh_timer); | 2489 | del_timer_sync(&hcd->rh_timer); |
2346 | err_hcd_driver_start: | 2490 | err_hcd_driver_start: |
2347 | if (hcd->irq >= 0) | 2491 | if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0) |
2348 | free_irq(irqnum, hcd); | 2492 | free_irq(irqnum, hcd); |
2349 | err_request_irq: | 2493 | err_request_irq: |
2350 | err_hcd_driver_setup: | 2494 | err_hcd_driver_setup: |
@@ -2375,6 +2519,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2375 | usb_get_dev(rhdev); | 2519 | usb_get_dev(rhdev); |
2376 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); | 2520 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); |
2377 | 2521 | ||
2522 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2378 | if (HC_IS_RUNNING (hcd->state)) | 2523 | if (HC_IS_RUNNING (hcd->state)) |
2379 | hcd->state = HC_STATE_QUIESCING; | 2524 | hcd->state = HC_STATE_QUIESCING; |
2380 | 2525 | ||
@@ -2407,8 +2552,10 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2407 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2552 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2408 | del_timer_sync(&hcd->rh_timer); | 2553 | del_timer_sync(&hcd->rh_timer); |
2409 | 2554 | ||
2410 | if (hcd->irq >= 0) | 2555 | if (usb_hcd_is_primary_hcd(hcd)) { |
2411 | free_irq(hcd->irq, hcd); | 2556 | if (hcd->irq >= 0) |
2557 | free_irq(hcd->irq, hcd); | ||
2558 | } | ||
2412 | 2559 | ||
2413 | usb_put_dev(hcd->self.root_hub); | 2560 | usb_put_dev(hcd->self.root_hub); |
2414 | usb_deregister_bus(&hcd->self); | 2561 | usb_deregister_bus(&hcd->self); |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 19d3435e6140..564eaa5525d7 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -82,6 +82,10 @@ struct usb_hub { | |||
82 | void **port_owners; | 82 | void **port_owners; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | static inline int hub_is_superspeed(struct usb_device *hdev) | ||
86 | { | ||
87 | return (hdev->descriptor.bDeviceProtocol == 3); | ||
88 | } | ||
85 | 89 | ||
86 | /* Protect struct usb_device->state and ->children members | 90 | /* Protect struct usb_device->state and ->children members |
87 | * Note: Both are also protected by ->dev.sem, except that ->state can | 91 | * Note: Both are also protected by ->dev.sem, except that ->state can |
@@ -151,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); | |||
151 | 155 | ||
152 | static int usb_reset_and_verify_device(struct usb_device *udev); | 156 | static int usb_reset_and_verify_device(struct usb_device *udev); |
153 | 157 | ||
154 | static inline char *portspeed(int portstatus) | 158 | static inline char *portspeed(struct usb_hub *hub, int portstatus) |
155 | { | 159 | { |
160 | if (hub_is_superspeed(hub->hdev)) | ||
161 | return "5.0 Gb/s"; | ||
156 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 162 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
157 | return "480 Mb/s"; | 163 | return "480 Mb/s"; |
158 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 164 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
159 | return "1.5 Mb/s"; | 165 | return "1.5 Mb/s"; |
160 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | ||
161 | return "5.0 Gb/s"; | ||
162 | else | 166 | else |
163 | return "12 Mb/s"; | 167 | return "12 Mb/s"; |
164 | } | 168 | } |
@@ -172,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev) | |||
172 | } | 176 | } |
173 | 177 | ||
174 | /* USB 2.0 spec Section 11.24.4.5 */ | 178 | /* USB 2.0 spec Section 11.24.4.5 */ |
175 | static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) | 179 | static int get_hub_descriptor(struct usb_device *hdev, void *data) |
176 | { | 180 | { |
177 | int i, ret; | 181 | int i, ret, size; |
182 | unsigned dtype; | ||
183 | |||
184 | if (hub_is_superspeed(hdev)) { | ||
185 | dtype = USB_DT_SS_HUB; | ||
186 | size = USB_DT_SS_HUB_SIZE; | ||
187 | } else { | ||
188 | dtype = USB_DT_HUB; | ||
189 | size = sizeof(struct usb_hub_descriptor); | ||
190 | } | ||
178 | 191 | ||
179 | for (i = 0; i < 3; i++) { | 192 | for (i = 0; i < 3; i++) { |
180 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | 193 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), |
181 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, | 194 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, |
182 | USB_DT_HUB << 8, 0, data, size, | 195 | dtype << 8, 0, data, size, |
183 | USB_CTRL_GET_TIMEOUT); | 196 | USB_CTRL_GET_TIMEOUT); |
184 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) | 197 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) |
185 | return ret; | 198 | return ret; |
@@ -365,6 +378,16 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
365 | } else { | 378 | } else { |
366 | *status = le16_to_cpu(hub->status->port.wPortStatus); | 379 | *status = le16_to_cpu(hub->status->port.wPortStatus); |
367 | *change = le16_to_cpu(hub->status->port.wPortChange); | 380 | *change = le16_to_cpu(hub->status->port.wPortChange); |
381 | |||
382 | if ((hub->hdev->parent != NULL) && | ||
383 | hub_is_superspeed(hub->hdev)) { | ||
384 | /* Translate the USB 3 port status */ | ||
385 | u16 tmp = *status & USB_SS_PORT_STAT_MASK; | ||
386 | if (*status & USB_SS_PORT_STAT_POWER) | ||
387 | tmp |= USB_PORT_STAT_POWER; | ||
388 | *status = tmp; | ||
389 | } | ||
390 | |||
368 | ret = 0; | 391 | ret = 0; |
369 | } | 392 | } |
370 | mutex_unlock(&hub->status_mutex); | 393 | mutex_unlock(&hub->status_mutex); |
@@ -607,7 +630,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
607 | if (hdev->children[port1-1] && set_state) | 630 | if (hdev->children[port1-1] && set_state) |
608 | usb_set_device_state(hdev->children[port1-1], | 631 | usb_set_device_state(hdev->children[port1-1], |
609 | USB_STATE_NOTATTACHED); | 632 | USB_STATE_NOTATTACHED); |
610 | if (!hub->error) | 633 | if (!hub->error && !hub_is_superspeed(hub->hdev)) |
611 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); | 634 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); |
612 | if (ret) | 635 | if (ret) |
613 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", | 636 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", |
@@ -616,7 +639,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
616 | } | 639 | } |
617 | 640 | ||
618 | /* | 641 | /* |
619 | * Disable a port and mark a logical connnect-change event, so that some | 642 | * Disable a port and mark a logical connect-change event, so that some |
620 | * time later khubd will disconnect() any existing usb_device on the port | 643 | * time later khubd will disconnect() any existing usb_device on the port |
621 | * and will re-enumerate if there actually is a device attached. | 644 | * and will re-enumerate if there actually is a device attached. |
622 | */ | 645 | */ |
@@ -769,12 +792,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
769 | * USB3 protocol ports will automatically transition | 792 | * USB3 protocol ports will automatically transition |
770 | * to Enabled state when detect an USB3.0 device attach. | 793 | * to Enabled state when detect an USB3.0 device attach. |
771 | * Do not disable USB3 protocol ports. | 794 | * Do not disable USB3 protocol ports. |
772 | * FIXME: USB3 root hub and external hubs are treated | ||
773 | * differently here. | ||
774 | */ | 795 | */ |
775 | if (hdev->descriptor.bDeviceProtocol != 3 || | 796 | if (!hub_is_superspeed(hdev)) { |
776 | (!hdev->parent && | ||
777 | !(portstatus & USB_PORT_STAT_SUPER_SPEED))) { | ||
778 | clear_port_feature(hdev, port1, | 797 | clear_port_feature(hdev, port1, |
779 | USB_PORT_FEAT_ENABLE); | 798 | USB_PORT_FEAT_ENABLE); |
780 | portstatus &= ~USB_PORT_STAT_ENABLE; | 799 | portstatus &= ~USB_PORT_STAT_ENABLE; |
@@ -795,6 +814,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
795 | clear_port_feature(hub->hdev, port1, | 814 | clear_port_feature(hub->hdev, port1, |
796 | USB_PORT_FEAT_C_ENABLE); | 815 | USB_PORT_FEAT_C_ENABLE); |
797 | } | 816 | } |
817 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
818 | need_debounce_delay = true; | ||
819 | clear_port_feature(hub->hdev, port1, | ||
820 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
821 | } | ||
798 | 822 | ||
799 | /* We can forget about a "removed" device when there's a | 823 | /* We can forget about a "removed" device when there's a |
800 | * physical disconnect or the connect status changes. | 824 | * physical disconnect or the connect status changes. |
@@ -964,12 +988,23 @@ static int hub_configure(struct usb_hub *hub, | |||
964 | goto fail; | 988 | goto fail; |
965 | } | 989 | } |
966 | 990 | ||
991 | if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) { | ||
992 | ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), | ||
993 | HUB_SET_DEPTH, USB_RT_HUB, | ||
994 | hdev->level - 1, 0, NULL, 0, | ||
995 | USB_CTRL_SET_TIMEOUT); | ||
996 | |||
997 | if (ret < 0) { | ||
998 | message = "can't set hub depth"; | ||
999 | goto fail; | ||
1000 | } | ||
1001 | } | ||
1002 | |||
967 | /* Request the entire hub descriptor. | 1003 | /* Request the entire hub descriptor. |
968 | * hub->descriptor can handle USB_MAXCHILDREN ports, | 1004 | * hub->descriptor can handle USB_MAXCHILDREN ports, |
969 | * but the hub can/will return fewer bytes here. | 1005 | * but the hub can/will return fewer bytes here. |
970 | */ | 1006 | */ |
971 | ret = get_hub_descriptor(hdev, hub->descriptor, | 1007 | ret = get_hub_descriptor(hdev, hub->descriptor); |
972 | sizeof(*hub->descriptor)); | ||
973 | if (ret < 0) { | 1008 | if (ret < 0) { |
974 | message = "can't read hub descriptor"; | 1009 | message = "can't read hub descriptor"; |
975 | goto fail; | 1010 | goto fail; |
@@ -991,12 +1026,14 @@ static int hub_configure(struct usb_hub *hub, | |||
991 | 1026 | ||
992 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); | 1027 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); |
993 | 1028 | ||
994 | if (wHubCharacteristics & HUB_CHAR_COMPOUND) { | 1029 | /* FIXME for USB 3.0, skip for now */ |
1030 | if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && | ||
1031 | !(hub_is_superspeed(hdev))) { | ||
995 | int i; | 1032 | int i; |
996 | char portstr [USB_MAXCHILDREN + 1]; | 1033 | char portstr [USB_MAXCHILDREN + 1]; |
997 | 1034 | ||
998 | for (i = 0; i < hdev->maxchild; i++) | 1035 | for (i = 0; i < hdev->maxchild; i++) |
999 | portstr[i] = hub->descriptor->DeviceRemovable | 1036 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable |
1000 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) | 1037 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) |
1001 | ? 'F' : 'R'; | 1038 | ? 'F' : 'R'; |
1002 | portstr[hdev->maxchild] = 0; | 1039 | portstr[hdev->maxchild] = 0; |
@@ -1253,8 +1290,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1253 | desc = intf->cur_altsetting; | 1290 | desc = intf->cur_altsetting; |
1254 | hdev = interface_to_usbdev(intf); | 1291 | hdev = interface_to_usbdev(intf); |
1255 | 1292 | ||
1256 | /* Hubs have proper suspend/resume support */ | 1293 | /* Hubs have proper suspend/resume support. USB 3.0 device suspend is |
1257 | usb_enable_autosuspend(hdev); | 1294 | * different from USB 2.0/1.1 device suspend, and unfortunately we |
1295 | * don't support it yet. So leave autosuspend disabled for USB 3.0 | ||
1296 | * external hubs for now. Enable autosuspend for USB 3.0 roothubs, | ||
1297 | * since that isn't a "real" hub. | ||
1298 | */ | ||
1299 | if (!hub_is_superspeed(hdev) || !hdev->parent) | ||
1300 | usb_enable_autosuspend(hdev); | ||
1258 | 1301 | ||
1259 | if (hdev->level == MAX_TOPO_LEVEL) { | 1302 | if (hdev->level == MAX_TOPO_LEVEL) { |
1260 | dev_err(&intf->dev, | 1303 | dev_err(&intf->dev, |
@@ -1501,6 +1544,13 @@ void usb_set_device_state(struct usb_device *udev, | |||
1501 | EXPORT_SYMBOL_GPL(usb_set_device_state); | 1544 | EXPORT_SYMBOL_GPL(usb_set_device_state); |
1502 | 1545 | ||
1503 | /* | 1546 | /* |
1547 | * Choose a device number. | ||
1548 | * | ||
1549 | * Device numbers are used as filenames in usbfs. On USB-1.1 and | ||
1550 | * USB-2.0 buses they are also used as device addresses, however on | ||
1551 | * USB-3.0 buses the address is assigned by the controller hardware | ||
1552 | * and it usually is not the same as the device number. | ||
1553 | * | ||
1504 | * WUSB devices are simple: they have no hubs behind, so the mapping | 1554 | * WUSB devices are simple: they have no hubs behind, so the mapping |
1505 | * device <-> virtual port number becomes 1:1. Why? to simplify the | 1555 | * device <-> virtual port number becomes 1:1. Why? to simplify the |
1506 | * life of the device connection logic in | 1556 | * life of the device connection logic in |
@@ -1522,7 +1572,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state); | |||
1522 | * the HCD must setup data structures before issuing a set address | 1572 | * the HCD must setup data structures before issuing a set address |
1523 | * command to the hardware. | 1573 | * command to the hardware. |
1524 | */ | 1574 | */ |
1525 | static void choose_address(struct usb_device *udev) | 1575 | static void choose_devnum(struct usb_device *udev) |
1526 | { | 1576 | { |
1527 | int devnum; | 1577 | int devnum; |
1528 | struct usb_bus *bus = udev->bus; | 1578 | struct usb_bus *bus = udev->bus; |
@@ -1547,7 +1597,7 @@ static void choose_address(struct usb_device *udev) | |||
1547 | } | 1597 | } |
1548 | } | 1598 | } |
1549 | 1599 | ||
1550 | static void release_address(struct usb_device *udev) | 1600 | static void release_devnum(struct usb_device *udev) |
1551 | { | 1601 | { |
1552 | if (udev->devnum > 0) { | 1602 | if (udev->devnum > 0) { |
1553 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); | 1603 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); |
@@ -1555,7 +1605,7 @@ static void release_address(struct usb_device *udev) | |||
1555 | } | 1605 | } |
1556 | } | 1606 | } |
1557 | 1607 | ||
1558 | static void update_address(struct usb_device *udev, int devnum) | 1608 | static void update_devnum(struct usb_device *udev, int devnum) |
1559 | { | 1609 | { |
1560 | /* The address for a WUSB device is managed by wusbcore. */ | 1610 | /* The address for a WUSB device is managed by wusbcore. */ |
1561 | if (!udev->wusb) | 1611 | if (!udev->wusb) |
@@ -1602,7 +1652,8 @@ void usb_disconnect(struct usb_device **pdev) | |||
1602 | * this quiesces everyting except pending urbs. | 1652 | * this quiesces everyting except pending urbs. |
1603 | */ | 1653 | */ |
1604 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1654 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1605 | dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); | 1655 | dev_info(&udev->dev, "USB disconnect, device number %d\n", |
1656 | udev->devnum); | ||
1606 | 1657 | ||
1607 | usb_lock_device(udev); | 1658 | usb_lock_device(udev); |
1608 | 1659 | ||
@@ -1632,7 +1683,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
1632 | /* Free the device number and delete the parent's children[] | 1683 | /* Free the device number and delete the parent's children[] |
1633 | * (or root_hub) pointer. | 1684 | * (or root_hub) pointer. |
1634 | */ | 1685 | */ |
1635 | release_address(udev); | 1686 | release_devnum(udev); |
1636 | 1687 | ||
1637 | /* Avoid races with recursively_mark_NOTATTACHED() */ | 1688 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1638 | spin_lock_irq(&device_state_lock); | 1689 | spin_lock_irq(&device_state_lock); |
@@ -2017,7 +2068,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
2017 | (portstatus & USB_PORT_STAT_ENABLE)) { | 2068 | (portstatus & USB_PORT_STAT_ENABLE)) { |
2018 | if (hub_is_wusb(hub)) | 2069 | if (hub_is_wusb(hub)) |
2019 | udev->speed = USB_SPEED_WIRELESS; | 2070 | udev->speed = USB_SPEED_WIRELESS; |
2020 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | 2071 | else if (hub_is_superspeed(hub->hdev)) |
2021 | udev->speed = USB_SPEED_SUPER; | 2072 | udev->speed = USB_SPEED_SUPER; |
2022 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 2073 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
2023 | udev->speed = USB_SPEED_HIGH; | 2074 | udev->speed = USB_SPEED_HIGH; |
@@ -2073,7 +2124,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2073 | case 0: | 2124 | case 0: |
2074 | /* TRSTRCY = 10 ms; plus some extra */ | 2125 | /* TRSTRCY = 10 ms; plus some extra */ |
2075 | msleep(10 + 40); | 2126 | msleep(10 + 40); |
2076 | update_address(udev, 0); | 2127 | update_devnum(udev, 0); |
2077 | if (hcd->driver->reset_device) { | 2128 | if (hcd->driver->reset_device) { |
2078 | status = hcd->driver->reset_device(hcd, udev); | 2129 | status = hcd->driver->reset_device(hcd, udev); |
2079 | if (status < 0) { | 2130 | if (status < 0) { |
@@ -2636,7 +2687,7 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
2636 | USB_REQ_SET_ADDRESS, 0, devnum, 0, | 2687 | USB_REQ_SET_ADDRESS, 0, devnum, 0, |
2637 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 2688 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
2638 | if (retval == 0) { | 2689 | if (retval == 0) { |
2639 | update_address(udev, devnum); | 2690 | update_devnum(udev, devnum); |
2640 | /* Device now using proper address. */ | 2691 | /* Device now using proper address. */ |
2641 | usb_set_device_state(udev, USB_STATE_ADDRESS); | 2692 | usb_set_device_state(udev, USB_STATE_ADDRESS); |
2642 | usb_ep0_reinit(udev); | 2693 | usb_ep0_reinit(udev); |
@@ -2741,9 +2792,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2741 | } | 2792 | } |
2742 | if (udev->speed != USB_SPEED_SUPER) | 2793 | if (udev->speed != USB_SPEED_SUPER) |
2743 | dev_info(&udev->dev, | 2794 | dev_info(&udev->dev, |
2744 | "%s %s speed %sUSB device using %s and address %d\n", | 2795 | "%s %s speed %sUSB device number %d using %s\n", |
2745 | (udev->config) ? "reset" : "new", speed, type, | 2796 | (udev->config) ? "reset" : "new", speed, type, |
2746 | udev->bus->controller->driver->name, devnum); | 2797 | devnum, udev->bus->controller->driver->name); |
2747 | 2798 | ||
2748 | /* Set up TT records, if needed */ | 2799 | /* Set up TT records, if needed */ |
2749 | if (hdev->tt) { | 2800 | if (hdev->tt) { |
@@ -2773,10 +2824,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2773 | * value. | 2824 | * value. |
2774 | */ | 2825 | */ |
2775 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { | 2826 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { |
2776 | /* | ||
2777 | * An xHCI controller cannot send any packets to a device until | ||
2778 | * a set address command successfully completes. | ||
2779 | */ | ||
2780 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { | 2827 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { |
2781 | struct usb_device_descriptor *buf; | 2828 | struct usb_device_descriptor *buf; |
2782 | int r = 0; | 2829 | int r = 0; |
@@ -2859,9 +2906,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2859 | if (udev->speed == USB_SPEED_SUPER) { | 2906 | if (udev->speed == USB_SPEED_SUPER) { |
2860 | devnum = udev->devnum; | 2907 | devnum = udev->devnum; |
2861 | dev_info(&udev->dev, | 2908 | dev_info(&udev->dev, |
2862 | "%s SuperSpeed USB device using %s and address %d\n", | 2909 | "%s SuperSpeed USB device number %d using %s\n", |
2863 | (udev->config) ? "reset" : "new", | 2910 | (udev->config) ? "reset" : "new", |
2864 | udev->bus->controller->driver->name, devnum); | 2911 | devnum, udev->bus->controller->driver->name); |
2865 | } | 2912 | } |
2866 | 2913 | ||
2867 | /* cope with hardware quirkiness: | 2914 | /* cope with hardware quirkiness: |
@@ -2924,7 +2971,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2924 | fail: | 2971 | fail: |
2925 | if (retval) { | 2972 | if (retval) { |
2926 | hub_port_disable(hub, port1, 0); | 2973 | hub_port_disable(hub, port1, 0); |
2927 | update_address(udev, devnum); /* for disconnect processing */ | 2974 | update_devnum(udev, devnum); /* for disconnect processing */ |
2928 | } | 2975 | } |
2929 | mutex_unlock(&usb_address0_mutex); | 2976 | mutex_unlock(&usb_address0_mutex); |
2930 | return retval; | 2977 | return retval; |
@@ -3015,7 +3062,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3015 | 3062 | ||
3016 | dev_dbg (hub_dev, | 3063 | dev_dbg (hub_dev, |
3017 | "port %d, status %04x, change %04x, %s\n", | 3064 | "port %d, status %04x, change %04x, %s\n", |
3018 | port1, portstatus, portchange, portspeed (portstatus)); | 3065 | port1, portstatus, portchange, portspeed(hub, portstatus)); |
3019 | 3066 | ||
3020 | if (hub->has_indicators) { | 3067 | if (hub->has_indicators) { |
3021 | set_port_led(hub, port1, HUB_LED_AUTO); | 3068 | set_port_led(hub, port1, HUB_LED_AUTO); |
@@ -3116,32 +3163,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3116 | udev->level = hdev->level + 1; | 3163 | udev->level = hdev->level + 1; |
3117 | udev->wusb = hub_is_wusb(hub); | 3164 | udev->wusb = hub_is_wusb(hub); |
3118 | 3165 | ||
3119 | /* | 3166 | /* Only USB 3.0 devices are connected to SuperSpeed hubs. */ |
3120 | * USB 3.0 devices are reset automatically before the connect | 3167 | if (hub_is_superspeed(hub->hdev)) |
3121 | * port status change appears, and the root hub port status | ||
3122 | * shows the correct speed. We also get port change | ||
3123 | * notifications for USB 3.0 devices from the USB 3.0 portion of | ||
3124 | * an external USB 3.0 hub, but this isn't handled correctly yet | ||
3125 | * FIXME. | ||
3126 | */ | ||
3127 | |||
3128 | if (!(hcd->driver->flags & HCD_USB3)) | ||
3129 | udev->speed = USB_SPEED_UNKNOWN; | ||
3130 | else if ((hdev->parent == NULL) && | ||
3131 | (portstatus & USB_PORT_STAT_SUPER_SPEED)) | ||
3132 | udev->speed = USB_SPEED_SUPER; | 3168 | udev->speed = USB_SPEED_SUPER; |
3133 | else | 3169 | else |
3134 | udev->speed = USB_SPEED_UNKNOWN; | 3170 | udev->speed = USB_SPEED_UNKNOWN; |
3135 | 3171 | ||
3136 | /* | 3172 | choose_devnum(udev); |
3137 | * Set the address. | ||
3138 | * Note xHCI needs to issue an address device command later | ||
3139 | * in the hub_port_init sequence for SS/HS/FS/LS devices, | ||
3140 | * and xHC will assign an address to the device. But use | ||
3141 | * kernel assigned address here, to avoid any address conflict | ||
3142 | * issue. | ||
3143 | */ | ||
3144 | choose_address(udev); | ||
3145 | if (udev->devnum <= 0) { | 3173 | if (udev->devnum <= 0) { |
3146 | status = -ENOTCONN; /* Don't retry */ | 3174 | status = -ENOTCONN; /* Don't retry */ |
3147 | goto loop; | 3175 | goto loop; |
@@ -3233,7 +3261,7 @@ loop_disable: | |||
3233 | hub_port_disable(hub, port1, 1); | 3261 | hub_port_disable(hub, port1, 1); |
3234 | loop: | 3262 | loop: |
3235 | usb_ep0_reinit(udev); | 3263 | usb_ep0_reinit(udev); |
3236 | release_address(udev); | 3264 | release_devnum(udev); |
3237 | hub_free_dev(udev); | 3265 | hub_free_dev(udev); |
3238 | usb_put_dev(udev); | 3266 | usb_put_dev(udev); |
3239 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) | 3267 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) |
@@ -3410,12 +3438,19 @@ static void hub_events(void) | |||
3410 | } | 3438 | } |
3411 | 3439 | ||
3412 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { | 3440 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { |
3413 | dev_err (hub_dev, | 3441 | u16 status = 0; |
3414 | "over-current change on port %d\n", | 3442 | u16 unused; |
3415 | i); | 3443 | |
3444 | dev_dbg(hub_dev, "over-current change on port " | ||
3445 | "%d\n", i); | ||
3416 | clear_port_feature(hdev, i, | 3446 | clear_port_feature(hdev, i, |
3417 | USB_PORT_FEAT_C_OVER_CURRENT); | 3447 | USB_PORT_FEAT_C_OVER_CURRENT); |
3448 | msleep(100); /* Cool down */ | ||
3418 | hub_power_on(hub, true); | 3449 | hub_power_on(hub, true); |
3450 | hub_port_status(hub, i, &status, &unused); | ||
3451 | if (status & USB_PORT_STAT_OVERCURRENT) | ||
3452 | dev_err(hub_dev, "over-current " | ||
3453 | "condition on port %d\n", i); | ||
3419 | } | 3454 | } |
3420 | 3455 | ||
3421 | if (portchange & USB_PORT_STAT_C_RESET) { | 3456 | if (portchange & USB_PORT_STAT_C_RESET) { |
@@ -3425,6 +3460,25 @@ static void hub_events(void) | |||
3425 | clear_port_feature(hdev, i, | 3460 | clear_port_feature(hdev, i, |
3426 | USB_PORT_FEAT_C_RESET); | 3461 | USB_PORT_FEAT_C_RESET); |
3427 | } | 3462 | } |
3463 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | ||
3464 | hub_is_superspeed(hub->hdev)) { | ||
3465 | dev_dbg(hub_dev, | ||
3466 | "warm reset change on port %d\n", | ||
3467 | i); | ||
3468 | clear_port_feature(hdev, i, | ||
3469 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
3470 | } | ||
3471 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
3472 | clear_port_feature(hub->hdev, i, | ||
3473 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
3474 | } | ||
3475 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | ||
3476 | dev_warn(hub_dev, | ||
3477 | "config error on port %d\n", | ||
3478 | i); | ||
3479 | clear_port_feature(hub->hdev, i, | ||
3480 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | ||
3481 | } | ||
3428 | 3482 | ||
3429 | if (connect_change) | 3483 | if (connect_change) |
3430 | hub_port_connect_change(hub, i, | 3484 | hub_port_connect_change(hub, i, |
@@ -3447,10 +3501,17 @@ static void hub_events(void) | |||
3447 | hub->limited_power = 0; | 3501 | hub->limited_power = 0; |
3448 | } | 3502 | } |
3449 | if (hubchange & HUB_CHANGE_OVERCURRENT) { | 3503 | if (hubchange & HUB_CHANGE_OVERCURRENT) { |
3450 | dev_dbg (hub_dev, "overcurrent change\n"); | 3504 | u16 status = 0; |
3451 | msleep(500); /* Cool down */ | 3505 | u16 unused; |
3506 | |||
3507 | dev_dbg(hub_dev, "over-current change\n"); | ||
3452 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); | 3508 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); |
3509 | msleep(500); /* Cool down */ | ||
3453 | hub_power_on(hub, true); | 3510 | hub_power_on(hub, true); |
3511 | hub_hub_status(hub, &status, &unused); | ||
3512 | if (status & HUB_STATUS_OVERCURRENT) | ||
3513 | dev_err(hub_dev, "over-current " | ||
3514 | "condition\n"); | ||
3454 | } | 3515 | } |
3455 | } | 3516 | } |
3456 | 3517 | ||
@@ -3699,13 +3760,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3699 | if (!udev->actconfig) | 3760 | if (!udev->actconfig) |
3700 | goto done; | 3761 | goto done; |
3701 | 3762 | ||
3702 | mutex_lock(&hcd->bandwidth_mutex); | 3763 | mutex_lock(hcd->bandwidth_mutex); |
3703 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); | 3764 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); |
3704 | if (ret < 0) { | 3765 | if (ret < 0) { |
3705 | dev_warn(&udev->dev, | 3766 | dev_warn(&udev->dev, |
3706 | "Busted HC? Not enough HCD resources for " | 3767 | "Busted HC? Not enough HCD resources for " |
3707 | "old configuration.\n"); | 3768 | "old configuration.\n"); |
3708 | mutex_unlock(&hcd->bandwidth_mutex); | 3769 | mutex_unlock(hcd->bandwidth_mutex); |
3709 | goto re_enumerate; | 3770 | goto re_enumerate; |
3710 | } | 3771 | } |
3711 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 3772 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
@@ -3716,10 +3777,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3716 | dev_err(&udev->dev, | 3777 | dev_err(&udev->dev, |
3717 | "can't restore configuration #%d (error=%d)\n", | 3778 | "can't restore configuration #%d (error=%d)\n", |
3718 | udev->actconfig->desc.bConfigurationValue, ret); | 3779 | udev->actconfig->desc.bConfigurationValue, ret); |
3719 | mutex_unlock(&hcd->bandwidth_mutex); | 3780 | mutex_unlock(hcd->bandwidth_mutex); |
3720 | goto re_enumerate; | 3781 | goto re_enumerate; |
3721 | } | 3782 | } |
3722 | mutex_unlock(&hcd->bandwidth_mutex); | 3783 | mutex_unlock(hcd->bandwidth_mutex); |
3723 | usb_set_device_state(udev, USB_STATE_CONFIGURED); | 3784 | usb_set_device_state(udev, USB_STATE_CONFIGURED); |
3724 | 3785 | ||
3725 | /* Put interfaces back into the same altsettings as before. | 3786 | /* Put interfaces back into the same altsettings as before. |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 832487423826..5701e857392b 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1284,12 +1284,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1284 | /* Make sure we have enough bandwidth for this alternate interface. | 1284 | /* Make sure we have enough bandwidth for this alternate interface. |
1285 | * Remove the current alt setting and add the new alt setting. | 1285 | * Remove the current alt setting and add the new alt setting. |
1286 | */ | 1286 | */ |
1287 | mutex_lock(&hcd->bandwidth_mutex); | 1287 | mutex_lock(hcd->bandwidth_mutex); |
1288 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); | 1288 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); |
1289 | if (ret < 0) { | 1289 | if (ret < 0) { |
1290 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", | 1290 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", |
1291 | alternate); | 1291 | alternate); |
1292 | mutex_unlock(&hcd->bandwidth_mutex); | 1292 | mutex_unlock(hcd->bandwidth_mutex); |
1293 | return ret; | 1293 | return ret; |
1294 | } | 1294 | } |
1295 | 1295 | ||
@@ -1311,10 +1311,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1311 | } else if (ret < 0) { | 1311 | } else if (ret < 0) { |
1312 | /* Re-instate the old alt setting */ | 1312 | /* Re-instate the old alt setting */ |
1313 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); | 1313 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); |
1314 | mutex_unlock(&hcd->bandwidth_mutex); | 1314 | mutex_unlock(hcd->bandwidth_mutex); |
1315 | return ret; | 1315 | return ret; |
1316 | } | 1316 | } |
1317 | mutex_unlock(&hcd->bandwidth_mutex); | 1317 | mutex_unlock(hcd->bandwidth_mutex); |
1318 | 1318 | ||
1319 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here | 1319 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here |
1320 | * when they implement async or easily-killable versions of this or | 1320 | * when they implement async or easily-killable versions of this or |
@@ -1413,7 +1413,7 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1413 | 1413 | ||
1414 | config = dev->actconfig; | 1414 | config = dev->actconfig; |
1415 | retval = 0; | 1415 | retval = 0; |
1416 | mutex_lock(&hcd->bandwidth_mutex); | 1416 | mutex_lock(hcd->bandwidth_mutex); |
1417 | /* Make sure we have enough bandwidth for each alternate setting 0 */ | 1417 | /* Make sure we have enough bandwidth for each alternate setting 0 */ |
1418 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1418 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
1419 | struct usb_interface *intf = config->interface[i]; | 1419 | struct usb_interface *intf = config->interface[i]; |
@@ -1442,7 +1442,7 @@ reset_old_alts: | |||
1442 | usb_hcd_alloc_bandwidth(dev, NULL, | 1442 | usb_hcd_alloc_bandwidth(dev, NULL, |
1443 | alt, intf->cur_altsetting); | 1443 | alt, intf->cur_altsetting); |
1444 | } | 1444 | } |
1445 | mutex_unlock(&hcd->bandwidth_mutex); | 1445 | mutex_unlock(hcd->bandwidth_mutex); |
1446 | return retval; | 1446 | return retval; |
1447 | } | 1447 | } |
1448 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1448 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
@@ -1451,7 +1451,7 @@ reset_old_alts: | |||
1451 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1451 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
1452 | if (retval < 0) | 1452 | if (retval < 0) |
1453 | goto reset_old_alts; | 1453 | goto reset_old_alts; |
1454 | mutex_unlock(&hcd->bandwidth_mutex); | 1454 | mutex_unlock(hcd->bandwidth_mutex); |
1455 | 1455 | ||
1456 | /* re-init hc/hcd interface/endpoint state */ | 1456 | /* re-init hc/hcd interface/endpoint state */ |
1457 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1457 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
@@ -1739,10 +1739,10 @@ free_interfaces: | |||
1739 | * host controller will not allow submissions to dropped endpoints. If | 1739 | * host controller will not allow submissions to dropped endpoints. If |
1740 | * this call fails, the device state is unchanged. | 1740 | * this call fails, the device state is unchanged. |
1741 | */ | 1741 | */ |
1742 | mutex_lock(&hcd->bandwidth_mutex); | 1742 | mutex_lock(hcd->bandwidth_mutex); |
1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); | 1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); |
1744 | if (ret < 0) { | 1744 | if (ret < 0) { |
1745 | mutex_unlock(&hcd->bandwidth_mutex); | 1745 | mutex_unlock(hcd->bandwidth_mutex); |
1746 | usb_autosuspend_device(dev); | 1746 | usb_autosuspend_device(dev); |
1747 | goto free_interfaces; | 1747 | goto free_interfaces; |
1748 | } | 1748 | } |
@@ -1761,11 +1761,11 @@ free_interfaces: | |||
1761 | if (!cp) { | 1761 | if (!cp) { |
1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); | 1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); |
1764 | mutex_unlock(&hcd->bandwidth_mutex); | 1764 | mutex_unlock(hcd->bandwidth_mutex); |
1765 | usb_autosuspend_device(dev); | 1765 | usb_autosuspend_device(dev); |
1766 | goto free_interfaces; | 1766 | goto free_interfaces; |
1767 | } | 1767 | } |
1768 | mutex_unlock(&hcd->bandwidth_mutex); | 1768 | mutex_unlock(hcd->bandwidth_mutex); |
1769 | usb_set_device_state(dev, USB_STATE_CONFIGURED); | 1769 | usb_set_device_state(dev, USB_STATE_CONFIGURED); |
1770 | 1770 | ||
1771 | /* Initialize the new interface structures and the | 1771 | /* Initialize the new interface structures and the |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index c14fc082864f..ae334b067c13 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -366,7 +366,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { | 366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { |
367 | int n, len; | 367 | int n, len; |
368 | 368 | ||
369 | /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ | 369 | /* SuperSpeed isoc endpoints have up to 16 bursts of up to |
370 | * 3 packets each | ||
371 | */ | ||
372 | if (dev->speed == USB_SPEED_SUPER) { | ||
373 | int burst = 1 + ep->ss_ep_comp.bMaxBurst; | ||
374 | int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); | ||
375 | max *= burst; | ||
376 | max *= mult; | ||
377 | } | ||
378 | |||
370 | /* "high bandwidth" mode, 1-3 packets/uframe? */ | 379 | /* "high bandwidth" mode, 1-3 packets/uframe? */ |
371 | if (dev->speed == USB_SPEED_HIGH) { | 380 | if (dev->speed == USB_SPEED_HIGH) { |
372 | int mult = 1 + ((max >> 11) & 0x03); | 381 | int mult = 1 + ((max >> 11) & 0x03); |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index b975450f403e..a9cf484ecae4 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -122,6 +122,19 @@ static inline int is_usb_device_driver(struct device_driver *drv) | |||
122 | for_devices; | 122 | for_devices; |
123 | } | 123 | } |
124 | 124 | ||
125 | /* translate USB error codes to codes user space understands */ | ||
126 | static inline int usb_translate_errors(int error_code) | ||
127 | { | ||
128 | switch (error_code) { | ||
129 | case 0: | ||
130 | case -ENOMEM: | ||
131 | case -ENODEV: | ||
132 | return error_code; | ||
133 | default: | ||
134 | return -EIO; | ||
135 | } | ||
136 | } | ||
137 | |||
125 | 138 | ||
126 | /* for labeling diagnostics */ | 139 | /* for labeling diagnostics */ |
127 | extern const char *usbcore_name; | 140 | extern const char *usbcore_name; |