Commit 3191a6f7 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'for-usb-next-2013-12-10' of...

Merge tag 'for-usb-next-2013-12-10' of git://git.kernel.org/pub/scm/linux/kernel/git/sarah/xhci into usb-next

Sarah Writes:

usb: Enumeration change under xHCI for 3.14.

Hi Greg,

Here's two patches for 3.14.

There are buggy USB devices that don't enumerate under xHCI because
they expect a 64-byte Get Descriptor request before the Set Address control
transfer.  David Moore has a USB 2.0 webcam that exhibits this behavior:

http://marc.info/?l=linux-usb&m=135879694716380&w=2

These patches change the way USB 2.0 devices are enumerated under xHCI, to try
the Windows enumeration scheme first.  The USB 3.0 device enumeration scheme is
unchanged.  This should allow these buggy USB 2.0 devices to enumerate under xHCI.

I've tested this code with USB 3.0 hubs and mass storage devices, and many
different USB 2.0 devices (webcam, headset, ethernet, serial, mouse, keyboard,
etc).  They all work, so these patches are ready for wider testing.

Sarah Sharp
parents 40fcd88b 6f8ffc0b
...@@ -2498,6 +2498,21 @@ static unsigned hub_is_wusb(struct usb_hub *hub) ...@@ -2498,6 +2498,21 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
#define HUB_LONG_RESET_TIME 200 #define HUB_LONG_RESET_TIME 200
#define HUB_RESET_TIMEOUT 800 #define HUB_RESET_TIMEOUT 800
/*
* "New scheme" enumeration causes an extra state transition to be
* exposed to an xhci host and causes USB3 devices to receive control
* commands in the default state. This has been seen to cause
* enumeration failures, so disable this enumeration scheme for USB3
* devices.
*/
static bool use_new_scheme(struct usb_device *udev, int retry)
{
if (udev->speed == USB_SPEED_SUPER)
return false;
return USE_NEW_SCHEME(retry);
}
static int hub_port_reset(struct usb_hub *hub, int port1, static int hub_port_reset(struct usb_hub *hub, int port1,
struct usb_device *udev, unsigned int delay, bool warm); struct usb_device *udev, unsigned int delay, bool warm);
...@@ -3956,6 +3971,20 @@ static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) ...@@ -3956,6 +3971,20 @@ static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev)
} }
} }
static int hub_enable_device(struct usb_device *udev)
{
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
if (!hcd->driver->enable_device)
return 0;
if (udev->state == USB_STATE_ADDRESS)
return 0;
if (udev->state != USB_STATE_DEFAULT)
return -EINVAL;
return hcd->driver->enable_device(hcd, udev);
}
/* Reset device, (re)assign address, get device descriptor. /* Reset device, (re)assign address, get device descriptor.
* Device connection must be stable, no more debouncing needed. * Device connection must be stable, no more debouncing needed.
* Returns device in USB_STATE_ADDRESS, except on error. * Returns device in USB_STATE_ADDRESS, except on error.
...@@ -4068,7 +4097,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, ...@@ -4068,7 +4097,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
* this area, and this is how Linux has done it for ages. * this area, and this is how Linux has done it for ages.
* Change it cautiously. * Change it cautiously.
* *
* NOTE: If USE_NEW_SCHEME() is true we will start by issuing * NOTE: If use_new_scheme() is true we will start by issuing
* a 64-byte GET_DESCRIPTOR request. This is what Windows does, * a 64-byte GET_DESCRIPTOR request. This is what Windows does,
* so it may help with some non-standards-compliant devices. * so it may help with some non-standards-compliant devices.
* Otherwise we start with SET_ADDRESS and then try to read the * Otherwise we start with SET_ADDRESS and then try to read the
...@@ -4076,10 +4105,17 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, ...@@ -4076,10 +4105,17 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
* value. * value.
*/ */
for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) {
if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { bool did_new_scheme = false;
if (use_new_scheme(udev, retry_counter)) {
struct usb_device_descriptor *buf; struct usb_device_descriptor *buf;
int r = 0; int r = 0;
did_new_scheme = true;
retval = hub_enable_device(udev);
if (retval < 0)
goto fail;
#define GET_DESCRIPTOR_BUFSIZE 64 #define GET_DESCRIPTOR_BUFSIZE 64
buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO);
if (!buf) { if (!buf) {
...@@ -4168,7 +4204,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, ...@@ -4168,7 +4204,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
* - read ep0 maxpacket even for high and low speed, * - read ep0 maxpacket even for high and low speed,
*/ */
msleep(10); msleep(10);
if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) /* use_new_scheme() checks the speed which may have
* changed since the initial look so we cache the result
* in did_new_scheme
*/
if (did_new_scheme)
break; break;
} }
......
...@@ -331,6 +331,7 @@ static const struct hc_driver xhci_pci_hc_driver = { ...@@ -331,6 +331,7 @@ static const struct hc_driver xhci_pci_hc_driver = {
.check_bandwidth = xhci_check_bandwidth, .check_bandwidth = xhci_check_bandwidth,
.reset_bandwidth = xhci_reset_bandwidth, .reset_bandwidth = xhci_reset_bandwidth,
.address_device = xhci_address_device, .address_device = xhci_address_device,
.enable_device = xhci_enable_device,
.update_hub_device = xhci_update_hub_device, .update_hub_device = xhci_update_hub_device,
.reset_device = xhci_discover_or_reset_device, .reset_device = xhci_discover_or_reset_device,
......
...@@ -69,6 +69,7 @@ static const struct hc_driver xhci_plat_xhci_driver = { ...@@ -69,6 +69,7 @@ static const struct hc_driver xhci_plat_xhci_driver = {
.check_bandwidth = xhci_check_bandwidth, .check_bandwidth = xhci_check_bandwidth,
.reset_bandwidth = xhci_reset_bandwidth, .reset_bandwidth = xhci_reset_bandwidth,
.address_device = xhci_address_device, .address_device = xhci_address_device,
.enable_device = xhci_enable_device,
.update_hub_device = xhci_update_hub_device, .update_hub_device = xhci_update_hub_device,
.reset_device = xhci_discover_or_reset_device, .reset_device = xhci_discover_or_reset_device,
......
...@@ -4004,12 +4004,12 @@ int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) ...@@ -4004,12 +4004,12 @@ int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id)
/* Queue an address device command TRB */ /* Queue an address device command TRB */
int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
u32 slot_id) u32 slot_id, enum xhci_setup_dev setup)
{ {
return queue_command(xhci, lower_32_bits(in_ctx_ptr), return queue_command(xhci, lower_32_bits(in_ctx_ptr),
upper_32_bits(in_ctx_ptr), 0, upper_32_bits(in_ctx_ptr), 0,
TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id), TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id)
false); | (setup == SETUP_CONTEXT_ONLY ? TRB_BSR : 0), false);
} }
int xhci_queue_vendor_command(struct xhci_hcd *xhci, int xhci_queue_vendor_command(struct xhci_hcd *xhci,
......
...@@ -3709,13 +3709,15 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3709,13 +3709,15 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
} }
/* /*
* Issue an Address Device command (which will issue a SetAddress request to * Issue an Address Device command and optionally send a corresponding
* the device). * SetAddress request to the device.
* We should be protected by the usb_address0_mutex in khubd's hub_port_init, so * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so
* we should only issue and wait on one address command at the same time. * we should only issue and wait on one address command at the same time.
*/ */
int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
enum xhci_setup_dev setup)
{ {
const char *act = setup == SETUP_CONTEXT_ONLY ? "context" : "address";
unsigned long flags; unsigned long flags;
int timeleft; int timeleft;
struct xhci_virt_device *virt_dev; struct xhci_virt_device *virt_dev;
...@@ -3773,7 +3775,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3773,7 +3775,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring);
ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma,
udev->slot_id); udev->slot_id, setup);
if (ret) { if (ret) {
spin_unlock_irqrestore(&xhci->lock, flags); spin_unlock_irqrestore(&xhci->lock, flags);
xhci_dbg_trace(xhci, trace_xhci_dbg_address, xhci_dbg_trace(xhci, trace_xhci_dbg_address,
...@@ -3791,8 +3793,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3791,8 +3793,8 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
* command on a timeout. * command on a timeout.
*/ */
if (timeleft <= 0) { if (timeleft <= 0) {
xhci_warn(xhci, "%s while waiting for address device command\n", xhci_warn(xhci, "%s while waiting for setup %s command\n",
timeleft == 0 ? "Timeout" : "Signal"); timeleft == 0 ? "Timeout" : "Signal", act);
/* cancel the address device command */ /* cancel the address device command */
ret = xhci_cancel_cmd(xhci, NULL, cmd_trb); ret = xhci_cancel_cmd(xhci, NULL, cmd_trb);
if (ret < 0) if (ret < 0)
...@@ -3803,26 +3805,27 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3803,26 +3805,27 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
switch (virt_dev->cmd_status) { switch (virt_dev->cmd_status) {
case COMP_CTX_STATE: case COMP_CTX_STATE:
case COMP_EBADSLT: case COMP_EBADSLT:
xhci_err(xhci, "Setup ERROR: address device command for slot %d.\n", xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n",
udev->slot_id); act, udev->slot_id);
ret = -EINVAL; ret = -EINVAL;
break; break;
case COMP_TX_ERR: case COMP_TX_ERR:
dev_warn(&udev->dev, "Device not responding to set address.\n"); dev_warn(&udev->dev, "Device not responding to setup %s.\n", act);
ret = -EPROTO; ret = -EPROTO;
break; break;
case COMP_DEV_ERR: case COMP_DEV_ERR:
dev_warn(&udev->dev, "ERROR: Incompatible device for address " dev_warn(&udev->dev,
"device command.\n"); "ERROR: Incompatible device for setup %s command\n", act);
ret = -ENODEV; ret = -ENODEV;
break; break;
case COMP_SUCCESS: case COMP_SUCCESS:
xhci_dbg_trace(xhci, trace_xhci_dbg_address, xhci_dbg_trace(xhci, trace_xhci_dbg_address,
"Successful Address Device command"); "Successful setup %s command", act);
break; break;
default: default:
xhci_err(xhci, "ERROR: unexpected command completion " xhci_err(xhci,
"code 0x%x.\n", virt_dev->cmd_status); "ERROR: unexpected setup %s command completion code 0x%x.\n",
act, virt_dev->cmd_status);
xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id);
xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2);
trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1);
...@@ -3868,6 +3871,16 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) ...@@ -3868,6 +3871,16 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
return 0; return 0;
} }
int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
{
return xhci_setup_device(hcd, udev, SETUP_CONTEXT_ADDRESS);
}
int xhci_enable_device(struct usb_hcd *hcd, struct usb_device *udev)
{
return xhci_setup_device(hcd, udev, SETUP_CONTEXT_ONLY);
}
/* /*
* Transfer the port index into real index in the HW port status * Transfer the port index into real index in the HW port status
* registers. Caculate offset between the port's PORTSC register * registers. Caculate offset between the port's PORTSC register
......
...@@ -1108,6 +1108,14 @@ struct xhci_event_cmd { ...@@ -1108,6 +1108,14 @@ struct xhci_event_cmd {
}; };
/* flags bitmasks */ /* flags bitmasks */
/* Address device - disable SetAddress */
#define TRB_BSR (1<<9)
enum xhci_setup_dev {
SETUP_CONTEXT_ONLY,
SETUP_CONTEXT_ADDRESS,
};
/* bits 16:23 are the virtual function ID */ /* bits 16:23 are the virtual function ID */
/* bits 24:31 are the slot ID */ /* bits 24:31 are the slot ID */
#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24) #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
...@@ -1760,6 +1768,7 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, ...@@ -1760,6 +1768,7 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
struct usb_host_endpoint **eps, unsigned int num_eps, struct usb_host_endpoint **eps, unsigned int num_eps,
gfp_t mem_flags); gfp_t mem_flags);
int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
int xhci_enable_device(struct usb_hcd *hcd, struct usb_device *udev);
int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev); int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev);
int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
struct usb_device *udev, int enable); struct usb_device *udev, int enable);
...@@ -1783,7 +1792,7 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); ...@@ -1783,7 +1792,7 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
void xhci_ring_cmd_db(struct xhci_hcd *xhci); void xhci_ring_cmd_db(struct xhci_hcd *xhci);
int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
u32 slot_id); u32 slot_id, enum xhci_setup_dev);
int xhci_queue_vendor_command(struct xhci_hcd *xhci, int xhci_queue_vendor_command(struct xhci_hcd *xhci,
u32 field1, u32 field2, u32 field3, u32 field4); u32 field1, u32 field2, u32 field3, u32 field4);
int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
......
...@@ -353,6 +353,8 @@ struct hc_driver { ...@@ -353,6 +353,8 @@ struct hc_driver {
void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
/* Returns the hardware-chosen device address */ /* Returns the hardware-chosen device address */
int (*address_device)(struct usb_hcd *, struct usb_device *udev); int (*address_device)(struct usb_hcd *, struct usb_device *udev);
/* prepares the hardware to send commands to the device */
int (*enable_device)(struct usb_hcd *, struct usb_device *udev);
/* Notifies the HCD after a hub descriptor is fetched. /* Notifies the HCD after a hub descriptor is fetched.
* Will block. * Will block.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment