usb: storage: Only clear READY flag on error
Subsystems (2)
RFC PATCH 1/2 usb: storage: Only clear READY flag on error
Clear the USB_READY flag in the storage driver only in case there is an error, otherwise usb_stor_BBB_transport() waits 5 mS before doing anything every single time.
This is because the USB_READY flag is only ever set in usb_test_unit_ready(), which is called only upon storage device probe, not between each and every request. However, the device cannot move out of USB_READY state once it was initialized.
--- common/usb_storage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
common/usb_storage.c +3 -3
@@ -1180,6 +1180,7 @@ retry_it: srb->pdata = (unsigned char *)buf_addr;if (usb_read_10 (srb, ss, start, smallblks)) {debug ("Read ERROR\n" ); + ss->flags &= ~USB_READY ;usb_request_sense (srb, ss);if (retry--) goto retry_it;
@@ -1190,7 +1191,6 @@ retry_it: blks -= smallblks; buf_addr += srb->datalen; }while (blks !=0 ); - ss->flags &= ~USB_READY ;debug ("usb_read: end startblk " LBAF ", blccnt %x buffer %lx\n" , start, smallblks, buf_addr);
@@ -1265,6 +1265,7 @@ retry_it: srb->pdata = (unsigned char *)buf_addr;if (usb_write_10 (srb, ss, start, smallblks)) {debug ("Write ERROR\n" ); + ss->flags &= ~USB_READY ;usb_request_sense (srb, ss);if (retry--) goto retry_it;
@@ -1275,7 +1276,6 @@ retry_it: blks -= smallblks; buf_addr += srb->datalen; }while (blks !=0 ); - ss->flags &= ~USB_READY ;debug ("usb_write: end startblk " LBAF ", blccnt %x buffer %lx\n" , start, smallblks, buf_addr);
@@ -1470,10 +1470,10 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,memset (pccb->pdata,0 ,8 );if (usb_read_capacity (pccb, ss) !=0 ) {printf ("READ_CAP ERROR\n" ); + ss->flags &= ~USB_READY ; cap[0 ] =2880 ; cap[1 ] =0x200 ; } - ss->flags &= ~USB_READY ;debug ("Read Capacity returns: 0x%08x, 0x%08x\n" , cap[0 ], cap[1 ]);#if 0 if (cap[0 ] > (0x200000 *10 ))/* greater than 10 GByte */
Signature · 1 line
2.23.0
RFC PATCH 2/2 usb: ehci-hcd: Keep async schedule running
Profiling the EHCI driver shows a significant performance problem in ehci_submit_async(). Specifically, this function keeps enabling and disabling async schedule back and forth for every single transaction. However, enabling/disabling the async schedule does not take effect immediatelly, but instead may take up to 1 mS (8 uFrames) to complete.
This impacts USB storage significantly, esp. since the recent reduction of maximum transfer size to support more USB storage devices. This in turn results in sharp increase in the number of ehci_submit_async() calls. Since one USB storage BBB transfer does three such calls and the maximum transfer size is 120 kiB, the overhead is 6 mS per 120 kiB, which is unacceptable.
However, this overhead can be removed simply by keeping the async schedule running. Specifically, the first transfer starts the async schedule and then each and every subsequent transfer only adds a new QH into that schedule, waits until the QH is completed and does NOT disable the async schedule. The async schedule is stopped only by shutting down the controller, which must happen before moving out of U-Boot, otherwise the controller will corrupt memory.
--- drivers/usb/host/ehci-hcd.c | 51 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-)
drivers/usb/host/ehci-hcd.c +21 -30
@@ -307,7 +307,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,volatile struct qTD *vtd;unsigned long ts;uint32_t *tdp; -uint32_t endpt, maxpacket, token, usbsts; +uint32_t endpt, maxpacket, token, usbsts, qhtoken;uint32_t c, toggle;uint32_t cmd;int timeout;
@@ -551,22 +551,21 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,flush_dcache_range ((unsigned long )qtd, ALIGN_END_ADDR(struct qTD, qtd, qtd_count)); -/* Set async. queue head pointer. */ -ehci_writel (&ctrl->hcor->or_asynclistaddr,virt_to_phys (&ctrl->qh_list)); - usbsts =ehci_readl (&ctrl->hcor->or_usbsts);ehci_writel (&ctrl->hcor->or_usbsts, (usbsts &0x3f ));/* Enable async. schedule. */ cmd =ehci_readl (&ctrl->hcor->or_usbcmd); - cmd |=CMD_ASE ; -ehci_writel (&ctrl->hcor->or_usbcmd, cmd); +if (!(cmd &CMD_ASE )) { + cmd |=CMD_ASE ; +ehci_writel (&ctrl->hcor->or_usbcmd, cmd); - ret =handshake ((uint32_t *)&ctrl->hcor->or_usbsts,STS_ASS ,STS_ASS , -100 *1000 ); -if (ret <0 ) { -printf ("EHCI fail timeout STS_ASS set\n" ); - goto fail; + ret =handshake ((uint32_t *)&ctrl->hcor->or_usbsts,STS_ASS ,STS_ASS , +100 *1000 ); +if (ret <0 ) { +printf ("EHCI fail timeout STS_ASS set\n" ); + goto fail; + } }/* Wait for TDs to be processed. */
@@ -587,6 +586,11 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,break ;WATCHDOG_RESET (); }while (get_timer (ts) < timeout); + qhtoken =hc32_to_cpu (qh->qh_overlay.qt_token); + + ctrl->qh_list.qh_link =cpu_to_hc32 (virt_to_phys (&ctrl->qh_list) |QH_LINK_TYPE_QH ); +flush_dcache_range ((unsigned long )&ctrl->qh_list, + ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1));/* * Invalidate the memory area occupied by buffer
@@ -605,25 +609,12 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,if (QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_ACTIVE )printf ("EHCI timed out on TD - token=%#x\n" , token); -/* Disable async schedule. */ - cmd =ehci_readl (&ctrl->hcor->or_usbcmd); - cmd &= ~CMD_ASE ; -ehci_writel (&ctrl->hcor->or_usbcmd, cmd); - - ret =handshake ((uint32_t *)&ctrl->hcor->or_usbsts,STS_ASS ,0 , -100 *1000 ); -if (ret <0 ) { -printf ("EHCI fail timeout STS_ASS reset\n" ); - goto fail; - } - - token =hc32_to_cpu (qh->qh_overlay.qt_token); -if (!(QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_ACTIVE )) { -debug ("TOKEN=%#x\n" , token); -switch (QT_TOKEN_GET_STATUS (token) & +if (!(QT_TOKEN_GET_STATUS (qhtoken) &QT_TOKEN_STATUS_ACTIVE )) { +debug ("TOKEN=%#x\n" , qhtoken); +switch (QT_TOKEN_GET_STATUS (qhtoken) & ~(QT_TOKEN_STATUS_SPLITXSTATE |QT_TOKEN_STATUS_PERR )) {case 0 : - toggle =QT_TOKEN_GET_DT (token); + toggle =QT_TOKEN_GET_DT (qhtoken);usb_settoggle (dev,usb_pipeendpoint (pipe),usb_pipeout (pipe), toggle); dev->status =0 ;
@@ -641,11 +632,11 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,break ;default : dev->status =USB_ST_CRC_ERR ; -if (QT_TOKEN_GET_STATUS (token) &QT_TOKEN_STATUS_HALTED ) +if (QT_TOKEN_GET_STATUS (qhtoken) &QT_TOKEN_STATUS_HALTED ) dev->status |=USB_ST_STALLED ;break ; } - dev->act_len = length -QT_TOKEN_GET_TOTALBYTES (token); + dev->act_len = length -QT_TOKEN_GET_TOTALBYTES (qhtoken); }else { dev->act_len =0 ;#ifndef CONFIG_USB_EHCI_FARADAY
Signature · 1 line
2.23.0