panther: libpayload: usb: xhci: Fix TD size if it overflows 5 bits

xHCI Spec says TD Size (5 bits) field shall be forced to 31,
if the number of packets to be scheduled is greater than 31.
BUG=chrome-os-partner:30263
BRANCH=tricky
TEST=Manual: Ensure recovery boot with USB 2.0 media

Change-Id: Ia70c7db963d7e41421ea0abef4eaa4016abf0adb
Signed-off-by: Justin Tsai <Justin_Tsai@quantatw.com>
Reviewed-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-by: Wei Shun <wei.shun.chang@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/206767
Reviewed-by: Wei Shun Chang <wei.shun.chang@intel.com>
(cherry picked from commit 2ad67bed79d9d7950844065e413ebc84d7afe0aa)
Reviewed-on: https://chromium-review.googlesource.com/223423
Reviewed-by: Shawn Nematbakhsh <shawnn@chromium.org>
Commit-Queue: Shawn Nematbakhsh <shawnn@chromium.org>
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
diff --git a/payloads/libpayload/drivers/usb/xhci.c b/payloads/libpayload/drivers/usb/xhci.c
index 6a9939c..d8771b3 100644
--- a/payloads/libpayload/drivers/usb/xhci.c
+++ b/payloads/libpayload/drivers/usb/xhci.c
@@ -535,7 +535,7 @@
 		xhci_clear_trb(trb, tr->pcs);
 		trb->ptr_low = virt_to_phys(cur_start);
 		TRB_SET(TL, trb, cur_length);
-		TRB_SET(TDS, trb, packets);
+		TRB_SET(TDS, trb,((packets > TRB_MAX_TD_SIZE) ? TRB_MAX_TD_SIZE : packets));
 		TRB_SET(CH, trb, 1);
 
 		/* Check for first, data stage TRB */
diff --git a/payloads/libpayload/drivers/usb/xhci_private.h b/payloads/libpayload/drivers/usb/xhci_private.h
index 34f6285..779ac1d 100644
--- a/payloads/libpayload/drivers/usb/xhci_private.h
+++ b/payloads/libpayload/drivers/usb/xhci_private.h
@@ -140,6 +140,8 @@
 	u32 control;
 } trb_t;
 
+#define TRB_MAX_TD_SIZE	0x1F			/* bits 21:17 of TD Size in TRB */
+
 #define EVENT_RING_SIZE 64
 typedef struct {
 	trb_t *ring;