297
297
/* one configuration */
298
298
0x09, /* __u8 bLength; */
299
299
0x02, /* __u8 bDescriptorType; Configuration */
300
0x19, 0x00, /* __le16 wTotalLength; FIXME */
300
0x1f, 0x00, /* __le16 wTotalLength; */
301
301
0x01, /* __u8 bNumInterfaces; (1) */
302
302
0x01, /* __u8 bConfigurationValue; */
303
303
0x00, /* __u8 iConfiguration; */
327
327
/* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
328
328
* see hub.c:hub_configure() for details. */
329
329
(USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
330
0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
332
* All 3.0 hubs should have an endpoint companion descriptor,
333
* but we're ignoring that for now. FIXME?
330
0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
332
/* one SuperSpeed endpoint companion descriptor */
333
0x06, /* __u8 ss_bLength */
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 */
337
340
/*-------------------------------------------------------------------------*/
983
986
spin_unlock_irq (&hcd_root_hub_lock);
985
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
990
usb_hc_died (hcd); /* This time clean up */
1153
1153
dev_warn(hcd->self.controller, "Unlink after no-IRQ? "
1154
1154
"Controller is probably using the wrong IRQ.\n");
1155
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);
1262
1264
*dma_handle = 0;
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)
1267
1269
if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1268
1270
dma_unmap_single(hcd->self.controller,
1279
1281
/* Make it safe to call this routine more than once */
1280
1282
urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL);
1282
EXPORT_SYMBOL_GPL(unmap_urb_setup_for_dma);
1284
void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1284
EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma);
1286
static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1288
if (hcd->driver->unmap_urb_for_dma)
1289
hcd->driver->unmap_urb_for_dma(hcd, urb);
1291
usb_hcd_unmap_urb_for_dma(hcd, urb);
1294
void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1286
1296
enum dma_data_direction dir;
1288
unmap_urb_setup_for_dma(hcd, urb);
1298
usb_hcd_unmap_urb_setup_for_dma(hcd, urb);
1290
1300
dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1291
1301
if (urb->transfer_flags & URB_DMA_MAP_SG)
1314
1324
urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1315
1325
URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1317
EXPORT_SYMBOL_GPL(unmap_urb_for_dma);
1327
EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma);
1319
1329
static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1320
1330
gfp_t mem_flags)
1332
if (hcd->driver->map_urb_for_dma)
1333
return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags);
1335
return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
1338
int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1322
1341
enum dma_data_direction dir;
1411
1430
if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1412
1431
URB_SETUP_MAP_LOCAL)))
1413
unmap_urb_for_dma(hcd, urb);
1432
usb_hcd_unmap_urb_for_dma(hcd, urb);
1436
EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma);
1418
1438
/*-------------------------------------------------------------------------*/
1931
1951
dev_dbg(&rhdev->dev, "bus %s%s\n",
1932
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");
1933
1958
if (!hcd->driver->bus_suspend) {
1934
1959
status = -ENOENT;
1961
clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1936
1962
hcd->state = HC_STATE_QUIESCING;
1937
1963
status = hcd->driver->bus_suspend(hcd);
1940
1966
usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
1941
1967
hcd->state = HC_STATE_SUSPENDED;
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;
1974
spin_unlock_irq(&hcd_root_hub_lock);
1944
1975
dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
1945
1976
"suspend", status);
1956
1987
dev_dbg(&rhdev->dev, "usb %s%s\n",
1957
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");
1958
1993
if (!hcd->driver->bus_resume)
1959
1994
return -ENOENT;
1960
if (hcd->state == HC_STATE_RUNNING)
1995
if (HCD_RH_RUNNING(hcd))
1963
1998
hcd->state = HC_STATE_RESUMING;
1966
2001
if (status == 0) {
1967
2002
/* TRSMRCY = 10 msec */
1969
usb_set_device_state(rhdev, rhdev->actconfig
1970
? USB_STATE_CONFIGURED
1971
: USB_STATE_ADDRESS);
1972
hcd->state = HC_STATE_RUNNING;
2004
spin_lock_irq(&hcd_root_hub_lock);
2005
if (!HCD_DEAD(hcd)) {
2006
usb_set_device_state(rhdev, rhdev->actconfig
2007
? USB_STATE_CONFIGURED
2008
: USB_STATE_ADDRESS);
2009
set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2010
hcd->state = HC_STATE_RUNNING;
2012
spin_unlock_irq(&hcd_root_hub_lock);
1974
2014
hcd->state = old_state;
1975
2015
dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
2081
2121
local_irq_save(flags);
2083
if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) {
2123
if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) {
2085
2125
} else if (hcd->driver->irq(hcd) == IRQ_NONE) {
2088
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);
2090
2132
if (unlikely(hcd->state == HC_STATE_HALT))
2091
2133
usb_hc_died(hcd);
2106
2148
* This is called by bus glue to report a USB host controller that died
2107
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.
2152
* Only call this function with the primary HCD.
2110
2154
void usb_hc_died (struct usb_hcd *hcd)
2114
2158
dev_err (hcd->self.controller, "HC died; cleaning up\n");
2116
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
2163
if (hcd->rh_registered) {
2118
2164
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2122
2168
USB_STATE_NOTATTACHED);
2123
2169
usb_kick_khubd (hcd->self.root_hub);
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);
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);
2125
2182
spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2183
/* Make sure that the other roothub is also deallocated. */
2127
2185
EXPORT_SYMBOL_GPL (usb_hc_died);
2129
2187
/*-------------------------------------------------------------------------*/
2132
* usb_create_hcd - create and initialize an HCD structure
2190
* usb_create_shared_hcd - create and initialize an HCD structure
2133
2191
* @driver: HC driver that will use this hcd
2134
2192
* @dev: device for this HC, stored in hcd->self.controller
2135
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
2196
* Context: !in_interrupt()
2138
2198
* Allocate a struct usb_hcd, with extra space at the end for the
2142
2202
* If memory is unavailable, returns NULL.
2144
struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
2145
struct device *dev, const char *bus_name)
2204
struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2205
struct device *dev, const char *bus_name,
2206
struct usb_hcd *primary_hcd)
2147
2208
struct usb_hcd *hcd;
2151
2212
dev_dbg (dev, "hcd alloc failed\n");
2154
dev_set_drvdata(dev, hcd);
2215
if (primary_hcd == NULL) {
2216
hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex),
2218
if (!hcd->bandwidth_mutex) {
2220
dev_dbg(dev, "hcd bandwidth mutex alloc failed\n");
2223
mutex_init(hcd->bandwidth_mutex);
2224
dev_set_drvdata(dev, hcd);
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;
2155
2233
kref_init(&hcd->kref);
2157
2235
usb_bus_init(&hcd->self);
2165
2243
#ifdef CONFIG_USB_SUSPEND
2166
2244
INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2168
mutex_init(&hcd->bandwidth_mutex);
2170
2247
hcd->driver = driver;
2248
hcd->speed = driver->flags & HCD_MASK;
2171
2249
hcd->product_desc = (driver->product_desc) ? driver->product_desc :
2172
2250
"USB Host Controller";
2253
EXPORT_SYMBOL_GPL(usb_create_shared_hcd);
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()
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
2266
* If memory is unavailable, returns NULL.
2268
struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
2269
struct device *dev, const char *bus_name)
2271
return usb_create_shared_hcd(driver, dev, bus_name, NULL);
2175
2273
EXPORT_SYMBOL_GPL(usb_create_hcd);
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
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
2177
2285
static void hcd_release (struct kref *kref)
2179
2287
struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
2289
if (usb_hcd_is_primary_hcd(hcd))
2290
kfree(hcd->bandwidth_mutex);
2292
hcd->shared_hcd->shared_hcd = NULL;
2197
2309
EXPORT_SYMBOL_GPL(usb_put_hcd);
2311
int usb_hcd_is_primary_hcd(struct usb_hcd *hcd)
2313
if (!hcd->primary_hcd)
2315
return hcd == hcd->primary_hcd;
2317
EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd);
2319
static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2320
unsigned int irqnum, unsigned long irqflags)
2324
if (hcd->driver->irq) {
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.
2330
if (irqflags & IRQF_SHARED)
2331
irqflags &= ~IRQF_DISABLED;
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);
2338
dev_err(hcd->self.controller,
2339
"request interrupt %d failed\n",
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);
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);
2200
2360
* usb_add_hcd - finish generic HCD structure initialization and register
2201
2361
* @hcd: the usb_hcd structure to initialize
2257
2417
device_init_wakeup(&rhdev->dev, 1);
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.
2423
set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2259
2425
/* "reset" is misnamed; its role is now one-time init. the controller
2260
2426
* should already have been reset (and boot firmware kicked off etc).
2271
2437
dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
2273
2439
/* enable irqs just before we start the controller */
2274
if (hcd->driver->irq) {
2276
/* IRQF_DISABLED doesn't work as advertised when used together
2277
* with IRQF_SHARED. As usb_hcd_irq() will always disable
2278
* interrupts we can remove it here.
2280
if (irqflags & IRQF_SHARED)
2281
irqflags &= ~IRQF_DISABLED;
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);
2440
if (usb_hcd_is_primary_hcd(hcd)) {
2441
retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
2289
2443
goto err_request_irq;
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);
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);
2305
if ((retval = hcd->driver->start(hcd)) < 0) {
2446
hcd->state = HC_STATE_RUNNING;
2447
retval = hcd->driver->start(hcd);
2306
2449
dev_err(hcd->self.controller, "startup error %d\n", retval);
2307
2450
goto err_hcd_driver_start;
2325
2468
error_create_attr_group:
2469
clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2326
2470
if (HC_IS_RUNNING(hcd->state))
2327
2471
hcd->state = HC_STATE_QUIESCING;
2328
2472
spin_lock_irq(&hcd_root_hub_lock);
2375
2519
usb_get_dev(rhdev);
2376
2520
sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2522
clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2378
2523
if (HC_IS_RUNNING (hcd->state))
2379
2524
hcd->state = HC_STATE_QUIESCING;
2407
2552
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2408
2553
del_timer_sync(&hcd->rh_timer);
2411
free_irq(hcd->irq, hcd);
2555
if (usb_hcd_is_primary_hcd(hcd)) {
2557
free_irq(hcd->irq, hcd);
2413
2560
usb_put_dev(hcd->self.root_hub);
2414
2561
usb_deregister_bus(&hcd->self);