usb: Fix usb_xfer_time() to work when called in 16bit mode.

Make sure to wrap accesses to the usb_pipe struct with GET_LOWFLAT so
that it works in 16bit mode.  This bug impacts both ehci and uhci usb
controllers (it should not impact ohci and xhci as those never call
the function in 16bit mode).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Call usb_desc2pipe() on xhci_update_pipe().

Make sure to call usb_desc2pipe() when updating a pipe settings.  This
ensures that pipe->devaddr is properly updated.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Remove 16bit code wrappers.

The usb-xhci.c file is only compiled in 32bit mode now, so remove all
the 16bit macros.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Use high memory instead of low memory for internal storage.

Now that the driver runs exclusively in 32bit mode, avoid using the
scarce low memory resource.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Move root hub and setup code to top of file.

Move the setup code to the top of the file so that like code is
together and to make the code layout more similar to the other usb
controllers.

This change is purely code movement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Add xhci_check_ports() and xhci_free_pipes() functions.

Add these two functions so that the xhci code is more similar to the
other USB controllers.  Also, store the temporary hub structure on the
stack instead of in struct usb_xhci_s.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
ehci: Move port power up from ehci_hub_detect() to check_ehci_ports().

Don't perform port power up in the detect code.  Instead do it prior
to calling usb_enumerate().  This makes the code more similar to the
ohci and xhci drivers.  It can also reduce the total boot time when
threads are disabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
usb-hub: Enable power to all ports prior to calling usb_enumerate().

Don't perform port power up in the detect code.  Instead do it prior
to calling usb_enumerate().  This makes the code more similar to the
usb root hub drivers.  It can also reduce the total boot time when
threads are disabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
xhci: Change xhci_hub_detect() to use connect status instead of link state.

Use the connect status bit to determine if a device is connected
instead of the port link state state machine status.  This makes the
driver more similar to the other drivers and may help diagnose devices
that take longer to boot up.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
uhci: Repeatedly poll for device detect for 100ms.

According to the USB2 specification, a device may take up to 100ms
(USB_TIME_SIGATT) after port power stabilizes to be detected.  So,
continually recheck for a device connection event.

Technically, the uhci root hub ports are always powered up, but it's
not possible to know how long the machine has been on, so it's better
to be safe here.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
ohci: Repeatedly poll for device detect for 100ms.

According to the USB2 specification, a device may take up to 100ms
(USB_TIME_SIGATT) after port power stabilizes to be detected.  So,
continually recheck for a device connection event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
ehci: Stall uhci/ohci init only until default port routing is done.

Now that uhci and ohci will continually poll for a device connect, the
ehci controller only needs to ensure that the default routing is setup
properly before allowing uhci and ohci to be initialized.

This also fixes two error paths in configure_ehci() that were not
properly updating PendingEHCIPorts.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
usb: Perform device detect polling on all usb controllers.

Move the 100ms (USB_TIME_SIGATT) device detect polling from the
ohci/uhci/usb-hub code to the generic usb_hub_port_setup() code.  This
extends the 100ms polling to ehci and xhci controllers.  The code in
usb_hub_port_setup() now compares USB_TIME_SIGATT to the start of
usb_enumerate(), which may make boots faster when threads are
disabled.

This patch also changes the meaning of the return code for
hub->op->detect() calls.  Now 1 indicates device found, 0 indicates
device not found, and -1 indicates permanent failure.

Also, the xhci controller generic delay of 100ms is replaced with a
20ms root hub power stabilize time.  This in combination with the
100ms for USB_TIME_SIGATT should be closer to the USB2 spec (the USB3
spec does not seem to declare an equivalent of USB_TIME_SIGATT).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
ehci: Fix bug in hub port assignment

The usbdev->port field is zero indexed, while the USB spec expects the
port values to start at one.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>