diff mbox series

[U-Boot,2/5] dm: usb: xhci: Implement get_max_xfer_size() operation

Message ID 1504790001-24715-2-git-send-email-bmeng.cn@gmail.com
State Accepted
Commit 022ceacaf8a6a67f86f0a5ed8f6ce6b2f6ab73a4
Delegated to: Marek Vasut
Headers show
Series [U-Boot,1/5] dm: usb: Add a new USB controller operation 'get_max_xfer_size' | expand

Commit Message

Bin Meng Sept. 7, 2017, 1:13 p.m. UTC
xHCD allocates one segment which includes 64 TRBs for each endpoint
and the last TRB in this segment is configured as a link TRB to form
a TRB ring. Each TRB can transfer up to 64K bytes, however data
buffers referenced by transfer TRBs shall not span 64KB boundaries.
Hence the maximum number of TRBs we can use in one transfer is 62.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 drivers/usb/host/xhci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Stefan Roese Sept. 7, 2017, 1:21 p.m. UTC | #1
On 07.09.2017 15:13, Bin Meng wrote:
> xHCD allocates one segment which includes 64 TRBs for each endpoint
> and the last TRB in this segment is configured as a link TRB to form
> a TRB ring. Each TRB can transfer up to 64K bytes, however data
> buffers referenced by transfer TRBs shall not span 64KB boundaries.
> Hence the maximum number of TRBs we can use in one transfer is 62.
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Tested-by: Stefan Roese <sr@denx.de>

Thank,
Stefan
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 9b82ee5..04eb1eb 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1228,6 +1228,20 @@  static int xhci_update_hub_device(struct udevice *dev, struct usb_device *udev)
 	return xhci_configure_endpoints(udev, false);
 }
 
+static int xhci_get_max_xfer_size(struct udevice *dev, size_t *size)
+{
+	/*
+	 * xHCD allocates one segment which includes 64 TRBs for each endpoint
+	 * and the last TRB in this segment is configured as a link TRB to form
+	 * a TRB ring. Each TRB can transfer up to 64K bytes, however data
+	 * buffers referenced by transfer TRBs shall not span 64KB boundaries.
+	 * Hence the maximum number of TRBs we can use in one transfer is 62.
+	 */
+	*size = (TRBS_PER_SEGMENT - 2) * TRB_MAX_BUFF_SIZE;
+
+	return 0;
+}
+
 int xhci_register(struct udevice *dev, struct xhci_hccr *hccr,
 		  struct xhci_hcor *hcor)
 {
@@ -1281,6 +1295,7 @@  struct dm_usb_ops xhci_usb_ops = {
 	.interrupt = xhci_submit_int_msg,
 	.alloc_device = xhci_alloc_device,
 	.update_hub_device = xhci_update_hub_device,
+	.get_max_xfer_size  = xhci_get_max_xfer_size,
 };
 
 #endif