diff --git a/common/usb_storage.c b/common/usb_storage.c index df0b057308791f938592c3335d0362e424672d6b..a57570b73f3d0a2cafd7f6d4d9093dbc67d18140 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -98,19 +98,9 @@ struct us_data { struct scsi_cmd *srb; /* current srb */ trans_reset transport_reset; /* reset routine */ trans_cmnd transport; /* transport routine */ + unsigned short max_xfer_blk; /* maximum transfer blocks */ }; -#ifdef CONFIG_USB_EHCI_HCD -/* - * The U-Boot EHCI driver can handle any transfer length as long as there is - * enough free heap space left, but the SCSI READ(10) and WRITE(10) commands are - * limited to 65535 blocks. - */ -#define USB_MAX_XFER_BLK 65535 -#else -#define USB_MAX_XFER_BLK 20 -#endif - #ifndef CONFIG_BLK static struct us_data usb_stor[USB_MAX_STOR_DEV]; #endif @@ -949,6 +939,38 @@ do_retry: return USB_STOR_TRANSPORT_FAILED; } +static void usb_stor_set_max_xfer_blk(struct usb_device *udev, + struct us_data *us) +{ + unsigned short blk; + size_t __maybe_unused size; + int __maybe_unused ret; + +#ifndef CONFIG_DM_USB +#ifdef CONFIG_USB_EHCI_HCD + /* + * The U-Boot EHCI driver can handle any transfer length as long as + * there is enough free heap space left, but the SCSI READ(10) and + * WRITE(10) commands are limited to 65535 blocks. + */ + blk = USHRT_MAX; +#else + blk = 20; +#endif +#else + ret = usb_get_max_xfer_size(udev, (size_t *)&size); + if (ret < 0) { + /* unimplemented, let's use default 20 */ + blk = 20; + } else { + if (size > USHRT_MAX * 512) + blk = USHRT_MAX; + blk = size / 512; + } +#endif + + us->max_xfer_blk = blk; +} static int usb_inquiry(struct scsi_cmd *srb, struct us_data *ss) { @@ -1150,12 +1172,12 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr, /* XXX need some comment here */ retry = 2; srb->pdata = (unsigned char *)buf_addr; - if (blks > USB_MAX_XFER_BLK) - smallblks = USB_MAX_XFER_BLK; + if (blks > ss->max_xfer_blk) + smallblks = ss->max_xfer_blk; else smallblks = (unsigned short) blks; retry_it: - if (smallblks == USB_MAX_XFER_BLK) + if (smallblks == ss->max_xfer_blk) usb_show_progress(); srb->datalen = block_dev->blksz * smallblks; srb->pdata = (unsigned char *)buf_addr; @@ -1178,7 +1200,7 @@ retry_it: start, smallblks, buf_addr); usb_disable_asynch(0); /* asynch transfer allowed */ - if (blkcnt >= USB_MAX_XFER_BLK) + if (blkcnt >= ss->max_xfer_blk) debug("\n"); return blkcnt; } @@ -1236,12 +1258,12 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr, */ retry = 2; srb->pdata = (unsigned char *)buf_addr; - if (blks > USB_MAX_XFER_BLK) - smallblks = USB_MAX_XFER_BLK; + if (blks > ss->max_xfer_blk) + smallblks = ss->max_xfer_blk; else smallblks = (unsigned short) blks; retry_it: - if (smallblks == USB_MAX_XFER_BLK) + if (smallblks == ss->max_xfer_blk) usb_show_progress(); srb->datalen = block_dev->blksz * smallblks; srb->pdata = (unsigned char *)buf_addr; @@ -1263,7 +1285,7 @@ retry_it: PRIxPTR "\n", start, smallblks, buf_addr); usb_disable_asynch(0); /* asynch transfer allowed */ - if (blkcnt >= USB_MAX_XFER_BLK) + if (blkcnt >= ss->max_xfer_blk) debug("\n"); return blkcnt; @@ -1384,6 +1406,10 @@ int usb_storage_probe(struct usb_device *dev, unsigned int ifnum, ss->irqmaxp = usb_maxpacket(dev, ss->irqpipe); dev->irq_handle = usb_stor_irq; } + + /* Set the maximum transfer size per host controller setting */ + usb_stor_set_max_xfer_blk(dev, ss); + dev->privptr = (void *)ss; return 1; } diff --git a/configs/Cyrus_P5020_defconfig b/configs/Cyrus_P5020_defconfig index 82da854386475135a6ccb917e1c32d1a3c24e662..37f78a4811b94e23baa23d6d403af99f2bf876b6 100644 --- a/configs/Cyrus_P5020_defconfig +++ b/configs/Cyrus_P5020_defconfig @@ -34,5 +34,4 @@ CONFIG_FSL_ESPI=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_OF_LIBFDT=y diff --git a/configs/Cyrus_P5040_defconfig b/configs/Cyrus_P5040_defconfig index 0fc9a07548988f6f0899a8dee37a1e72d4b2fcfb..d33b514ee0efe99a4538e75038b3c11ae555a28d 100644 --- a/configs/Cyrus_P5040_defconfig +++ b/configs/Cyrus_P5040_defconfig @@ -34,5 +34,4 @@ CONFIG_FSL_ESPI=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_OF_LIBFDT=y diff --git a/configs/MPC8610HPCD_defconfig b/configs/MPC8610HPCD_defconfig index fde837c0115ba6c87f11c4707595480318b102c5..c71d5b18e1cebfc73765cc4720797c2247014af5 100644 --- a/configs/MPC8610HPCD_defconfig +++ b/configs/MPC8610HPCD_defconfig @@ -22,5 +22,4 @@ CONFIG_SCSI=y CONFIG_SYS_NS16550=y CONFIG_USB=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_OF_LIBFDT=y diff --git a/configs/MPC8641HPCN_36BIT_defconfig b/configs/MPC8641HPCN_36BIT_defconfig index 7318e723a8e52763c322bb0bdb4558b7d0d5201f..9949e8b6994e0914d121a5beda039652541e9b38 100644 --- a/configs/MPC8641HPCN_36BIT_defconfig +++ b/configs/MPC8641HPCN_36BIT_defconfig @@ -21,5 +21,4 @@ CONFIG_PHYLIB=y CONFIG_SYS_NS16550=y CONFIG_USB=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_OF_LIBFDT=y diff --git a/configs/MPC8641HPCN_defconfig b/configs/MPC8641HPCN_defconfig index def36e41712f306f9e99ab99a7b28df38bb3d81c..c8440d25846ff2fad9388489ae1e689d7b4ab04d 100644 --- a/configs/MPC8641HPCN_defconfig +++ b/configs/MPC8641HPCN_defconfig @@ -21,5 +21,4 @@ CONFIG_PHYLIB=y CONFIG_SYS_NS16550=y CONFIG_USB=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_OF_LIBFDT=y diff --git a/configs/apalis_imx6_defconfig b/configs/apalis_imx6_defconfig index b2284acc34a31302947a8dfdb5c41e3fc91a7cf0..13f2a3b8493ca8daebfbff831886bc0a3decbacf 100644 --- a/configs/apalis_imx6_defconfig +++ b/configs/apalis_imx6_defconfig @@ -54,7 +54,6 @@ CONFIG_NETDEVICES=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/apalis_imx6_nospl_com_defconfig b/configs/apalis_imx6_nospl_com_defconfig index 239605dadfaa4fea00ff08be25971e103b973c71..7165749cfb3cbd4c81411eaf71e91807ae9cf077 100644 --- a/configs/apalis_imx6_nospl_com_defconfig +++ b/configs/apalis_imx6_nospl_com_defconfig @@ -43,7 +43,6 @@ CONFIG_NETDEVICES=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/apalis_imx6_nospl_it_defconfig b/configs/apalis_imx6_nospl_it_defconfig index 1bc05d7266d390bf52218eecf2e59b2e87d1fcf9..0ad7674ee5d3a0bbabc365dcd845d2fffcba5323 100644 --- a/configs/apalis_imx6_nospl_it_defconfig +++ b/configs/apalis_imx6_nospl_it_defconfig @@ -43,7 +43,6 @@ CONFIG_NETDEVICES=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/colibri_imx6_defconfig b/configs/colibri_imx6_defconfig index 7d1e709d4c4782d6384f31390f1a6688636a202c..7e100869a4d56225ae2205271ae4115b756a3bc8 100644 --- a/configs/colibri_imx6_defconfig +++ b/configs/colibri_imx6_defconfig @@ -52,7 +52,6 @@ CONFIG_PHY_MICREL=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/colibri_imx6_nospl_defconfig b/configs/colibri_imx6_nospl_defconfig index 6877993088f4156f9d3eaadaf432c5a2e9d38ce6..ba4b2dd9d42be50c9d6b0970b2e173a993781766 100644 --- a/configs/colibri_imx6_nospl_defconfig +++ b/configs/colibri_imx6_nospl_defconfig @@ -41,7 +41,6 @@ CONFIG_PHY_MICREL=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/firefly-rk3288_defconfig b/configs/firefly-rk3288_defconfig index 82da6016e6540b574ad520b003f56f1b161f7ee8..178c879e2653fa24e362234fdd147ce320ec0663 100644 --- a/configs/firefly-rk3288_defconfig +++ b/configs/firefly-rk3288_defconfig @@ -73,7 +73,6 @@ CONFIG_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DWC2_OTG=y CONFIG_USB_GADGET_DOWNLOAD=y diff --git a/configs/mx6cuboxi_defconfig b/configs/mx6cuboxi_defconfig index 5490e3546bac46cc6a8f21de80807390fc21a175..27171fbddf582676bb960e7ab296380f75ac4716 100644 --- a/configs/mx6cuboxi_defconfig +++ b/configs/mx6cuboxi_defconfig @@ -34,6 +34,5 @@ CONFIG_DM_THERMAL=y CONFIG_USB=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y # CONFIG_VIDEO_SW_CURSOR is not set CONFIG_OF_LIBFDT=y diff --git a/configs/rpi_2_defconfig b/configs/rpi_2_defconfig index 23456977011356bc4fed7252786aabff17f21d4f..03705975bf2a06dc846b291aa791bb48c17c5aee 100644 --- a/configs/rpi_2_defconfig +++ b/configs/rpi_2_defconfig @@ -26,7 +26,6 @@ CONFIG_DM_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_SMSC95XX=y CONFIG_DM_VIDEO=y diff --git a/configs/rpi_3_32b_defconfig b/configs/rpi_3_32b_defconfig index bb56a9e4e10da245d1093ab57b082932f9691f06..31d67ccdc999c265657677dda9c98d3fdb1b481a 100644 --- a/configs/rpi_3_32b_defconfig +++ b/configs/rpi_3_32b_defconfig @@ -28,7 +28,6 @@ CONFIG_DM_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_SMSC95XX=y CONFIG_DM_VIDEO=y diff --git a/configs/rpi_3_defconfig b/configs/rpi_3_defconfig index 6edacd69a2b419ea282de4bb35adbada215da352..1ac3a96e250a3c2794cce1d010e3c82ea7247dde 100644 --- a/configs/rpi_3_defconfig +++ b/configs/rpi_3_defconfig @@ -28,7 +28,6 @@ CONFIG_DM_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_SMSC95XX=y CONFIG_DM_VIDEO=y diff --git a/configs/rpi_defconfig b/configs/rpi_defconfig index 2e81966c1463adaeb32500592e5b7a9245ccf217..87e88223ee6477146e4c82e55e7ae5277e1e257b 100644 --- a/configs/rpi_defconfig +++ b/configs/rpi_defconfig @@ -26,7 +26,6 @@ CONFIG_DM_USB=y CONFIG_USB_DWC2=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_SMSC95XX=y CONFIG_DM_VIDEO=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 310b8acc293a35bfea9a99dea2ebb2e758f9be5c..632e0aa0ee35da59847cf7007ff16a522bd45b42 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -175,7 +175,6 @@ CONFIG_DM_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_DM_VIDEO=y CONFIG_CONSOLE_ROTATION=y CONFIG_CONSOLE_TRUETYPE=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 50ea35e64bc72b7f09ddb5e31514e39ad0addf24..b1a341551f910e1a57049b0f340cae210de26010 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -160,7 +160,6 @@ CONFIG_DM_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_DM_VIDEO=y CONFIG_CONSOLE_ROTATION=y CONFIG_CONSOLE_TRUETYPE=y diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig index 693c14bc60034c070c8311ad694dbfaad9ee73c6..39101741b164c8d6bc3faa699faefdf94fc92448 100644 --- a/configs/sandbox_noblk_defconfig +++ b/configs/sandbox_noblk_defconfig @@ -168,7 +168,6 @@ CONFIG_DM_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_DM_VIDEO=y CONFIG_CONSOLE_ROTATION=y CONFIG_CONSOLE_TRUETYPE=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index db9129456bfad9c359977c5fd2a3672d12e83386..7f03c6ed031a93fb7b2695654c012be82a8d7a2c 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -178,7 +178,6 @@ CONFIG_DM_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_DM_VIDEO=y CONFIG_CONSOLE_ROTATION=y CONFIG_CONSOLE_TRUETYPE=y diff --git a/configs/seaboard_defconfig b/configs/seaboard_defconfig index ea4546bce4a0cc8a7fae81c7b01966fd4e9dfc5f..810cfaa498f2a386783e44c3ba58598823b5623d 100644 --- a/configs/seaboard_defconfig +++ b/configs/seaboard_defconfig @@ -36,7 +36,6 @@ CONFIG_USB_ULPI_VIEWPORT=y CONFIG_USB_ULPI=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_DM_VIDEO=y diff --git a/configs/ventana_defconfig b/configs/ventana_defconfig index 42353f034ed9f447301a3dad1c2f2f150cd3baae..b11dab11960f3e6044d14f88c69cbb97b87c0687 100644 --- a/configs/ventana_defconfig +++ b/configs/ventana_defconfig @@ -34,7 +34,6 @@ CONFIG_USB_ULPI_VIEWPORT=y CONFIG_USB_ULPI=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y -CONFIG_SYS_USB_EVENT_POLL=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_ETHER_ASIX=y CONFIG_DM_VIDEO=y diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 62126aad2fb414fac590144f9e76e264bf927dc1..e7658b4d95c9c90efb51dc726498489bc06b4aa5 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -75,7 +75,7 @@ if USB_KEYBOARD choice prompt "USB keyboard polling" - optional + default SYS_USB_EVENT_POLL ---help--- Enable a polling mechanism for USB keyboard. diff --git a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c index 0d6d2fba8a0f3f22c8f69be5531a4f9282814be9..b6164afa9245a6c78775c65a7b90e4a76bf5000d 100644 --- a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c +++ b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c @@ -111,7 +111,8 @@ static int setdma_rx(struct dwc2_ep *ep, struct dwc2_request *req) ctrl = readl(®->out_endp[ep_num].doepctl); invalidate_dcache_range((unsigned long) ep->dma_buf, - (unsigned long) ep->dma_buf + ep->len); + (unsigned long) ep->dma_buf + + ROUND(ep->len, CONFIG_SYS_CACHELINE_SIZE)); writel((unsigned int) ep->dma_buf, ®->out_endp[ep_num].doepdma); writel(DOEPT_SIZ_PKT_CNT(pktcnt) | DOEPT_SIZ_XFER_SIZE(length), diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index 64c42ac47153bd7f20b50f55e22efd3b99e02a70..0ed72d5ae71acccf68a728ee78e293f02e79ecd6 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -1245,7 +1245,7 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev) struct dwc2_priv *priv = dev_get_priv(dev); fdt_addr_t addr; - addr = devfdt_get_addr(dev); + addr = dev_read_addr(dev); if (addr == FDT_ADDR_T_NONE) return -EINVAL; priv->regs = (struct dwc2_core_regs *)addr; diff --git a/drivers/usb/host/ehci-generic.c b/drivers/usb/host/ehci-generic.c index 03f8d321af13e3ddb04c46ae9a66d16b82defe73..18e1e0ee8852a7e15ab65cb41b90512805f34ed5 100644 --- a/drivers/usb/host/ehci-generic.c +++ b/drivers/usb/host/ehci-generic.c @@ -108,7 +108,7 @@ static int ehci_usb_probe(struct udevice *dev) } } - hccr = map_physmem(devfdt_get_addr(dev), 0x100, MAP_NOCACHE); + hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE); hcor = (struct ehci_hcor *)((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 3243c1d1cf250a9de353b8c05d46acd12b1efa6d..be3e842dcc30fddb2af2f47094f6fa0cd8ab1966 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -1596,6 +1596,17 @@ static int ehci_destroy_int_queue(struct udevice *dev, struct usb_device *udev, return _ehci_destroy_int_queue(udev, queue); } +static int ehci_get_max_xfer_size(struct udevice *dev, size_t *size) +{ + /* + * EHCD can handle any transfer length as long as there is enough + * free heap space left, hence set the theoretical max number here. + */ + *size = SIZE_MAX; + + return 0; +} + int ehci_register(struct udevice *dev, struct ehci_hccr *hccr, struct ehci_hcor *hcor, const struct ehci_ops *ops, uint tweaks, enum usb_init_type init) @@ -1658,6 +1669,7 @@ struct dm_usb_ops ehci_usb_ops = { .create_int_queue = ehci_create_int_queue, .poll_int_queue = ehci_poll_int_queue, .destroy_int_queue = ehci_destroy_int_queue, + .get_max_xfer_size = ehci_get_max_xfer_size, }; #endif diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 0b8a501ce8851be7a0d0751c1f74fa7145ddf1d2..bc44fc3394dab4cda45590c52271a77d7c6d8dc5 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -150,6 +150,17 @@ int usb_update_hub_device(struct usb_device *udev) return ops->update_hub_device(bus, udev); } +int usb_get_max_xfer_size(struct usb_device *udev, size_t *size) +{ + struct udevice *bus = udev->controller_dev; + struct dm_usb_ops *ops = usb_get_ops(bus); + + if (!ops->get_max_xfer_size) + return -ENOSYS; + + return ops->get_max_xfer_size(bus, size); +} + int usb_stop(void) { struct udevice *bus; diff --git a/drivers/usb/host/xhci-rockchip.c b/drivers/usb/host/xhci-rockchip.c index ec55f4e59f75c95d12c2fedafdab64aa068c4726..ca3abffba072834aa816ab79dcc226116790d408 100644 --- a/drivers/usb/host/xhci-rockchip.c +++ b/drivers/usb/host/xhci-rockchip.c @@ -6,8 +6,6 @@ */ #include <common.h> #include <dm.h> -#include <fdtdec.h> -#include <libfdt.h> #include <malloc.h> #include <usb.h> #include <watchdog.h> @@ -46,7 +44,7 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev) /* * Get the base address for XHCI controller from the device node */ - plat->hcd_base = devfdt_get_addr(dev); + plat->hcd_base = dev_read_addr(dev); if (plat->hcd_base == FDT_ADDR_T_NONE) { error("Can't get the XHCI register base address\n"); return -ENXIO; diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 9b82ee5c602782a10876fbdd3995e5bd71be1495..04eb1eb14d13602ec1234b4b21e5ea372074664e 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 diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index a497d9d830fa7be54b05ac79c5def17e1c3a9d04..3377450fcad903480ffcff44c3f187baa6f53bf7 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1045,9 +1045,9 @@ struct xhci_scratchpad { * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table, * meaning 64 ring segments. * Initial allocated size of the ERST, in number of entries */ -#define ERST_NUM_SEGS 3 +#define ERST_NUM_SEGS 1 /* Initial number of event segment rings allocated */ -#define ERST_ENTRIES 3 +#define ERST_ENTRIES 1 /* Initial allocated size of the ERST, in number of entries */ #define ERST_SIZE 64 /* Poll every 60 seconds */ diff --git a/include/usb.h b/include/usb.h index fad04016a348fe1a8afb8f3f4783873c18a47678..0ddc0822b41009aafa91ea07a65d0867fffc8145 100644 --- a/include/usb.h +++ b/include/usb.h @@ -766,6 +766,14 @@ struct dm_usb_ops { * representation of this hub can be updated (xHCI) */ int (*update_hub_device)(struct udevice *bus, struct usb_device *udev); + + /** + * get_max_xfer_size() - Get HCD's maximum transfer bytes + * + * The HCD may have limitation on the maximum bytes to be transferred + * in a USB transfer. USB class driver needs to be aware of this. + */ + int (*get_max_xfer_size)(struct udevice *bus, size_t *size); }; #define usb_get_ops(dev) ((struct dm_usb_ops *)(dev)->driver->ops) @@ -939,7 +947,7 @@ int usb_new_device(struct usb_device *dev); int usb_alloc_device(struct usb_device *dev); /** - * update_hub_device() - Update HCD's internal representation of hub + * usb_update_hub_device() - Update HCD's internal representation of hub * * After a hub descriptor is fetched, notify HCD so that its internal * representation of this hub can be updated. @@ -949,6 +957,18 @@ int usb_alloc_device(struct usb_device *dev); */ int usb_update_hub_device(struct usb_device *dev); +/** + * usb_get_max_xfer_size() - Get HCD's maximum transfer bytes + * + * The HCD may have limitation on the maximum bytes to be transferred + * in a USB transfer. USB class driver needs to be aware of this. + * + * @dev: USB device + * @size: maximum transfer bytes + * @return 0 if OK, -ve on error + */ +int usb_get_max_xfer_size(struct usb_device *dev, size_t *size); + /** * usb_emul_setup_device() - Set up a new USB device emulation *