diff options
Diffstat (limited to 'drivers/usb/core/hcd.c')
-rw-r--r-- | drivers/usb/core/hcd.c | 281 |
1 files changed, 214 insertions, 67 deletions
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); |