Browse Source

[usb] Fix USB timeouts to match specification

Several of the USB timeouts were chosen on the principle of "pick an
arbitrary but ridiculously large value, just to be safe".  It turns
out that some of the timeouts permitted by the USB specification are
even larger: for example, control transactions are allowed to take up
to five seconds to complete.

Fix up these USB timeout values to match those found in the USB2
specification.

Debugged-by: Robin Smidsrød <robin@smidsrod.no>
Tested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
acc27b9005
3 changed files with 37 additions and 7 deletions
  1. 6
    0
      src/drivers/bus/usb.c
  2. 4
    2
      src/drivers/usb/xhci.h
  3. 27
    5
      src/include/ipxe/usb.h

+ 6
- 0
src/drivers/bus/usb.c View File

1281
 		goto err_enable;
1281
 		goto err_enable;
1282
 	}
1282
 	}
1283
 
1283
 
1284
+	/* Allow recovery interval since port may have been reset */
1285
+	mdelay ( USB_RESET_RECOVER_DELAY_MS );
1286
+
1284
 	/* Get device speed */
1287
 	/* Get device speed */
1285
 	if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) {
1288
 	if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) {
1286
 		DBGC ( hub, "USB hub %s port %d could not get speed: %s\n",
1289
 		DBGC ( hub, "USB hub %s port %d could not get speed: %s\n",
1316
 	}
1319
 	}
1317
 	DBGC2 ( usb, "USB %s assigned address %d\n", usb->name, usb->address );
1320
 	DBGC2 ( usb, "USB %s assigned address %d\n", usb->name, usb->address );
1318
 
1321
 
1322
+	/* Allow recovery interval after Set Address command */
1323
+	mdelay ( USB_SET_ADDRESS_RECOVER_DELAY_MS );
1324
+
1319
 	/* Read first part of device descriptor to get EP0 MTU */
1325
 	/* Read first part of device descriptor to get EP0 MTU */
1320
 	if ( ( rc = usb_get_mtu ( usb, &usb->device ) ) != 0 ) {
1326
 	if ( ( rc = usb_get_mtu ( usb, &usb->device ) ) != 0 ) {
1321
 		DBGC ( usb, "USB %s could not get MTU: %s\n",
1327
 		DBGC ( usb, "USB %s could not get MTU: %s\n",

+ 4
- 2
src/drivers/usb/xhci.h View File

991
 
991
 
992
 /** Maximum time to wait for a command to complete
992
 /** Maximum time to wait for a command to complete
993
  *
993
  *
994
- * This is a policy decision.
994
+ * The "address device" command involves waiting for a response to a
995
+ * USB control transaction, and so we must wait for up to the 5000ms
996
+ * that USB allows for devices to respond to control transactions.
995
  */
997
  */
996
-#define XHCI_COMMAND_MAX_WAIT_MS 500
998
+#define XHCI_COMMAND_MAX_WAIT_MS USB_CONTROL_MAX_WAIT_MS
997
 
999
 
998
 /** Time to delay after aborting a command
1000
 /** Time to delay after aborting a command
999
  *
1001
  *

+ 27
- 5
src/include/ipxe/usb.h View File

1178
 extern unsigned int usb_depth ( struct usb_device *usb );
1178
 extern unsigned int usb_depth ( struct usb_device *usb );
1179
 extern struct usb_port * usb_root_hub_port ( struct usb_device *usb );
1179
 extern struct usb_port * usb_root_hub_port ( struct usb_device *usb );
1180
 
1180
 
1181
-/** Minimum reset time */
1181
+/** Minimum reset time
1182
+ *
1183
+ * Section 7.1.7.5 of the USB2 specification states that root hub
1184
+ * ports should assert reset signalling for at least 50ms.
1185
+ */
1182
 #define USB_RESET_DELAY_MS 50
1186
 #define USB_RESET_DELAY_MS 50
1183
 
1187
 
1188
+/** Reset recovery time
1189
+ *
1190
+ * Section 9.2.6.2 of the USB2 specification states that the
1191
+ * "recovery" interval after a port reset is 10ms.
1192
+ */
1193
+#define USB_RESET_RECOVER_DELAY_MS 10
1194
+
1184
 /** Maximum time to wait for a control transaction to complete
1195
 /** Maximum time to wait for a control transaction to complete
1185
  *
1196
  *
1186
- * This is a policy decision.
1197
+ * Section 9.2.6.1 of the USB2 specification states that the upper
1198
+ * limit for commands to be processed is 5 seconds.
1199
+ */
1200
+#define USB_CONTROL_MAX_WAIT_MS 5000
1201
+
1202
+/** Set address recovery time
1203
+ *
1204
+ * Section 9.2.6.3 of the USB2 specification states that devices are
1205
+ * allowed a 2ms recovery interval after receiving a new address.
1187
  */
1206
  */
1188
-#define USB_CONTROL_MAX_WAIT_MS 100
1207
+#define USB_SET_ADDRESS_RECOVER_DELAY_MS 2
1189
 
1208
 
1190
 /** Time to wait for ports to stabilise
1209
 /** Time to wait for ports to stabilise
1191
  *
1210
  *
1192
- * This is a policy decision.
1211
+ * Section 7.1.7.3 of the USB specification states that we must allow
1212
+ * 100ms for devices to signal attachment, and an additional 100ms for
1213
+ * connection debouncing.  (This delay is parallelised across all
1214
+ * ports on a hub; we do not delay separately for each port.)
1193
  */
1215
  */
1194
-#define USB_PORT_DELAY_MS 100
1216
+#define USB_PORT_DELAY_MS 200
1195
 
1217
 
1196
 /** A USB device ID */
1218
 /** A USB device ID */
1197
 struct usb_device_id {
1219
 struct usb_device_id {

Loading…
Cancel
Save