libpayload/usb: add USB 3.1 GEN2 support

USB 3.1 GEN2 report speed type 4, add into speed enum.

BUG=b:139787920
BRANCH=N/A
TEST=Build libpayload and depthcharge on sarien and boot with
USB GEN2 HUB with USB disk. Check ultra speed device in cbmem log.

Signed-off-by: Eric Lai <ericr_lai@compal.corp-partner.google.com>
Change-Id: Ia0ef12b2f0d91bf0d0db766bbc9019de1614a4f4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35023
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Eric Lai 2019-08-22 12:41:12 +08:00 committed by Patrick Georgi
parent 1458777c3b
commit da10b9224a
4 changed files with 22 additions and 6 deletions

View File

@ -265,6 +265,8 @@ usb_decode_mps0(usb_speed speed, u8 bMaxPacketSize0)
} }
return bMaxPacketSize0; return bMaxPacketSize0;
case SUPER_SPEED: case SUPER_SPEED:
/* Intentional fallthrough */
case SUPER_SPEED_PLUS:
if (bMaxPacketSize0 != 9) { if (bMaxPacketSize0 != 9) {
usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0); usb_debug("Invalid MPS0: 0x%02x\n", bMaxPacketSize0);
bMaxPacketSize0 = 9; bMaxPacketSize0 = 9;
@ -284,6 +286,8 @@ int speed_to_default_mps(usb_speed speed)
case HIGH_SPEED: case HIGH_SPEED:
return 64; return 64;
case SUPER_SPEED: case SUPER_SPEED:
/* Intentional fallthrough */
case SUPER_SPEED_PLUS:
default: default:
return 512; return 512;
} }
@ -319,6 +323,8 @@ usb_decode_interval(usb_speed speed, const endpoint_type type, const unsigned ch
return LOG2(bInterval); return LOG2(bInterval);
} }
case SUPER_SPEED: case SUPER_SPEED:
/* Intentional fallthrough */
case SUPER_SPEED_PLUS:
switch (type) { switch (type) {
case ISOCHRONOUS: case INTERRUPT: case ISOCHRONOUS: case INTERRUPT:
return bInterval - 1; return bInterval - 1;
@ -657,7 +663,7 @@ usb_detach_device(hci_t *controller, int devno)
int int
usb_attach_device(hci_t *controller, int hubaddress, int port, usb_speed speed) usb_attach_device(hci_t *controller, int hubaddress, int port, usb_speed speed)
{ {
static const char* speeds[] = { "full", "low", "high", "super" }; static const char *speeds[] = { "full", "low", "high", "super", "ultra" };
usb_debug ("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*)) usb_debug ("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*))
? speeds[speed] : "invalid value - no"); ? speeds[speed] : "invalid value - no");
int newdev = set_address (controller, speed, port, hubaddress); int newdev = set_address (controller, speed, port, hubaddress);
@ -692,6 +698,14 @@ usb_generic_init (usbdev_t *dev)
} }
} }
/*
* returns the speed is above SUPER_SPEED or not
*/
_Bool is_usb_speed_ss(usb_speed speed)
{
return (speed == SUPER_SPEED || speed == SUPER_SPEED_PLUS);
}
/* /*
* returns the address of the closest USB2.0 hub, which is responsible for * returns the address of the closest USB2.0 hub, which is responsible for
* split transactions, along with the number of the used downstream port * split transactions, along with the number of the used downstream port

View File

@ -96,8 +96,8 @@ usb_hub_port_speed(usbdev_t *const dev, const int port)
int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf); int ret = get_status (dev, port, DR_PORT, sizeof(buf), buf);
if (ret >= 0 && (buf[0] & PORT_ENABLE)) { if (ret >= 0 && (buf[0] & PORT_ENABLE)) {
/* SuperSpeed hubs can only have SuperSpeed devices. */ /* SuperSpeed hubs can only have SuperSpeed devices. */
if (dev->speed == SUPER_SPEED) if (is_usb_speed_ss(dev->speed))
return SUPER_SPEED; return dev->speed;
/*[bit] 10 9 (USB 2.0 port status word) /*[bit] 10 9 (USB 2.0 port status word)
* 0 0 full speed * 0 0 full speed
@ -176,7 +176,7 @@ usb_hub_port_initialize(usbdev_t *const dev, const int port)
void void
usb_hub_init(usbdev_t *const dev) usb_hub_init(usbdev_t *const dev)
{ {
int type = dev->speed == SUPER_SPEED ? 0x2a : 0x29; /* similar enough */ int type = is_usb_speed_ss(dev->speed) ? 0x2a : 0x29; /* similar enough */
hub_descriptor_t desc; /* won't fit the whole thing, we don't care */ hub_descriptor_t desc; /* won't fit the whole thing, we don't care */
if (get_descriptor(dev, gen_bmRequestType(device_to_host, class_type, if (get_descriptor(dev, gen_bmRequestType(device_to_host, class_type,
dev_recp), type, 0, &desc, sizeof(desc)) != sizeof(desc)) { dev_recp), type, 0, &desc, sizeof(desc)) != sizeof(desc)) {
@ -185,7 +185,7 @@ usb_hub_init(usbdev_t *const dev)
return; return;
} }
if (dev->speed == SUPER_SPEED) if (is_usb_speed_ss(dev->speed))
usb_hub_set_hub_depth(dev); usb_hub_set_hub_depth(dev);
if (generic_hub_init(dev, desc.bNbrPorts, &usb_hub_ops) < 0) if (generic_hub_init(dev, desc.bNbrPorts, &usb_hub_ops) < 0)
return; return;

View File

@ -267,7 +267,7 @@ _free_ic_return:
static int static int
xhci_finish_hub_config(usbdev_t *const dev, inputctx_t *const ic) xhci_finish_hub_config(usbdev_t *const dev, inputctx_t *const ic)
{ {
int type = dev->speed == SUPER_SPEED ? 0x2a : 0x29; /* similar enough */ int type = is_usb_speed_ss(dev->speed) ? 0x2a : 0x29; /* similar enough */
hub_descriptor_t desc; hub_descriptor_t desc;
if (get_descriptor(dev, gen_bmRequestType(device_to_host, class_type, if (get_descriptor(dev, gen_bmRequestType(device_to_host, class_type,

View File

@ -210,6 +210,7 @@ typedef enum {
LOW_SPEED = 1, LOW_SPEED = 1,
HIGH_SPEED = 2, HIGH_SPEED = 2,
SUPER_SPEED = 3, SUPER_SPEED = 3,
SUPER_SPEED_PLUS = 4,
} usb_speed; } usb_speed;
struct usbdev { struct usbdev {
@ -293,6 +294,7 @@ int get_descriptor (usbdev_t *dev, int rtype, int descType, int descIdx,
int set_configuration (usbdev_t *dev); int set_configuration (usbdev_t *dev);
int clear_feature (usbdev_t *dev, int endp, int feature, int rtype); int clear_feature (usbdev_t *dev, int endp, int feature, int rtype);
int clear_stall (endpoint_t *ep); int clear_stall (endpoint_t *ep);
_Bool is_usb_speed_ss(usb_speed speed);
void usb_nop_init (usbdev_t *dev); void usb_nop_init (usbdev_t *dev);
void usb_hub_init (usbdev_t *dev); void usb_hub_init (usbdev_t *dev);