Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'usb-for-v4.1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-testing

Felipe writes:

usb: generic resume timeout for v4.1

This part 2 pull request contains only the patches
which make sure everybody on linux uses the same
resume timeout value.

Signed-off-by: Felipe Balbi <balbi@ti.com>

+59 -28
+2 -2
drivers/usb/core/hub.c
··· 3406 3406 if (status) { 3407 3407 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); 3408 3408 } else { 3409 - /* drive resume for at least 20 msec */ 3409 + /* drive resume for USB_RESUME_TIMEOUT msec */ 3410 3410 dev_dbg(&udev->dev, "usb %sresume\n", 3411 3411 (PMSG_IS_AUTO(msg) ? "auto-" : "")); 3412 - msleep(25); 3412 + msleep(USB_RESUME_TIMEOUT); 3413 3413 3414 3414 /* Virtual root hubs can trigger on GET_PORT_STATUS to 3415 3415 * stop resume signaling. Then finish the resume
+1 -1
drivers/usb/dwc2/hcd.c
··· 1529 1529 dev_dbg(hsotg->dev, 1530 1530 "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); 1531 1531 writel(0, hsotg->regs + PCGCTL); 1532 - usleep_range(20000, 40000); 1532 + msleep(USB_RESUME_TIMEOUT); 1533 1533 1534 1534 hprt0 = dwc2_read_hprt0(hsotg); 1535 1535 hprt0 |= HPRT0_RES;
+5 -5
drivers/usb/host/ehci-hcd.c
··· 792 792 ehci->reset_done[i] == 0)) 793 793 continue; 794 794 795 - /* start 20 msec resume signaling from this port, 796 - * and make hub_wq collect PORT_STAT_C_SUSPEND to 797 - * stop that signaling. Use 5 ms extra for safety, 798 - * like usb_port_resume() does. 795 + /* start USB_RESUME_TIMEOUT msec resume signaling from 796 + * this port, and make hub_wq collect 797 + * PORT_STAT_C_SUSPEND to stop that signaling. 799 798 */ 800 - ehci->reset_done[i] = jiffies + msecs_to_jiffies(25); 799 + ehci->reset_done[i] = jiffies + 800 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 801 801 set_bit(i, &ehci->resuming_ports); 802 802 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); 803 803 usb_hcd_start_port_resume(&hcd->self, i);
+6 -3
drivers/usb/host/ehci-hub.c
··· 471 471 ehci_writel(ehci, temp, &ehci->regs->port_status [i]); 472 472 } 473 473 474 - /* msleep for 20ms only if code is trying to resume port */ 474 + /* 475 + * msleep for USB_RESUME_TIMEOUT ms only if code is trying to resume 476 + * port 477 + */ 475 478 if (resume_needed) { 476 479 spin_unlock_irq(&ehci->lock); 477 - msleep(20); 480 + msleep(USB_RESUME_TIMEOUT); 478 481 spin_lock_irq(&ehci->lock); 479 482 if (ehci->shutdown) 480 483 goto shutdown; ··· 945 942 temp &= ~PORT_WAKE_BITS; 946 943 ehci_writel(ehci, temp | PORT_RESUME, status_reg); 947 944 ehci->reset_done[wIndex] = jiffies 948 - + msecs_to_jiffies(20); 945 + + msecs_to_jiffies(USB_RESUME_TIMEOUT); 949 946 set_bit(wIndex, &ehci->resuming_ports); 950 947 usb_hcd_start_port_resume(&hcd->self, wIndex); 951 948 break;
+1 -1
drivers/usb/host/fotg210-hcd.c
··· 1595 1595 /* resume signaling for 20 msec */ 1596 1596 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg); 1597 1597 fotg210->reset_done[wIndex] = jiffies 1598 - + msecs_to_jiffies(20); 1598 + + msecs_to_jiffies(USB_RESUME_TIMEOUT); 1599 1599 break; 1600 1600 case USB_PORT_FEAT_C_SUSPEND: 1601 1601 clear_bit(wIndex, &fotg210->port_c_suspend);
+1 -2
drivers/usb/host/fusbh200-hcd.c
··· 1550 1550 if ((temp & PORT_PE) == 0) 1551 1551 goto error; 1552 1552 1553 - /* resume signaling for 20 msec */ 1554 1553 fusbh200_writel(fusbh200, temp | PORT_RESUME, status_reg); 1555 1554 fusbh200->reset_done[wIndex] = jiffies 1556 - + msecs_to_jiffies(20); 1555 + + msecs_to_jiffies(USB_RESUME_TIMEOUT); 1557 1556 break; 1558 1557 case USB_PORT_FEAT_C_SUSPEND: 1559 1558 clear_bit(wIndex, &fusbh200->port_c_suspend);
+1 -1
drivers/usb/host/isp116x-hcd.c
··· 1490 1490 spin_unlock_irq(&isp116x->lock); 1491 1491 1492 1492 hcd->state = HC_STATE_RESUMING; 1493 - msleep(20); 1493 + msleep(USB_RESUME_TIMEOUT); 1494 1494 1495 1495 /* Go operational */ 1496 1496 spin_lock_irq(&isp116x->lock);
+4 -3
drivers/usb/host/oxu210hp-hcd.c
··· 2500 2500 || oxu->reset_done[i] != 0) 2501 2501 continue; 2502 2502 2503 - /* start 20 msec resume signaling from this port, 2504 - * and make hub_wq collect PORT_STAT_C_SUSPEND to 2503 + /* start USB_RESUME_TIMEOUT resume signaling from this 2504 + * port, and make hub_wq collect PORT_STAT_C_SUSPEND to 2505 2505 * stop that signaling. 2506 2506 */ 2507 - oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); 2507 + oxu->reset_done[i] = jiffies + 2508 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 2508 2509 oxu_dbg(oxu, "port %d remote wakeup\n", i + 1); 2509 2510 mod_timer(&hcd->rh_timer, oxu->reset_done[i]); 2510 2511 }
+1 -1
drivers/usb/host/r8a66597-hcd.c
··· 2301 2301 rh->port &= ~USB_PORT_STAT_SUSPEND; 2302 2302 rh->port |= USB_PORT_STAT_C_SUSPEND << 16; 2303 2303 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); 2304 - msleep(50); 2304 + msleep(USB_RESUME_TIMEOUT); 2305 2305 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg); 2306 2306 } 2307 2307
+1 -1
drivers/usb/host/sl811-hcd.c
··· 1259 1259 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1); 1260 1260 1261 1261 mod_timer(&sl811->timer, jiffies 1262 - + msecs_to_jiffies(20)); 1262 + + msecs_to_jiffies(USB_RESUME_TIMEOUT)); 1263 1263 break; 1264 1264 case USB_PORT_FEAT_POWER: 1265 1265 port_power(sl811, 0);
+3 -2
drivers/usb/host/uhci-hub.c
··· 166 166 /* Port received a wakeup request */ 167 167 set_bit(port, &uhci->resuming_ports); 168 168 uhci->ports_timeout = jiffies + 169 - msecs_to_jiffies(25); 169 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 170 170 usb_hcd_start_port_resume( 171 171 &uhci_to_hcd(uhci)->self, port); 172 172 ··· 338 338 uhci_finish_suspend(uhci, port, port_addr); 339 339 340 340 /* USB v2.0 7.1.7.5 */ 341 - uhci->ports_timeout = jiffies + msecs_to_jiffies(50); 341 + uhci->ports_timeout = jiffies + 342 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 342 343 break; 343 344 case USB_PORT_FEAT_POWER: 344 345 /* UHCI has no power switching */
+1 -1
drivers/usb/host/xhci-ring.c
··· 1574 1574 } else { 1575 1575 xhci_dbg(xhci, "resume HS port %d\n", port_id); 1576 1576 bus_state->resume_done[faked_port_index] = jiffies + 1577 - msecs_to_jiffies(20); 1577 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 1578 1578 set_bit(faked_port_index, &bus_state->resuming_ports); 1579 1579 mod_timer(&hcd->rh_timer, 1580 1580 bus_state->resume_done[faked_port_index]);
+1 -1
drivers/usb/isp1760/isp1760-hcd.c
··· 1869 1869 reg_write32(hcd->regs, HC_PORTSC1, 1870 1870 temp | PORT_RESUME); 1871 1871 priv->reset_done = jiffies + 1872 - msecs_to_jiffies(20); 1872 + msecs_to_jiffies(USB_RESUME_TIMEOUT); 1873 1873 } 1874 1874 break; 1875 1875 case USB_PORT_FEAT_C_SUSPEND:
+4 -3
drivers/usb/musb/musb_core.c
··· 99 99 #include <linux/platform_device.h> 100 100 #include <linux/io.h> 101 101 #include <linux/dma-mapping.h> 102 + #include <linux/usb.h> 102 103 103 104 #include "musb_core.h" 104 105 ··· 550 549 (USB_PORT_STAT_C_SUSPEND << 16) 551 550 | MUSB_PORT_STAT_RESUME; 552 551 musb->rh_timer = jiffies 553 - + msecs_to_jiffies(20); 552 + + msecs_to_jiffies(USB_RESUME_TIMEOUT); 554 553 musb->need_finish_resume = 1; 555 554 556 555 musb->xceiv->otg->state = OTG_STATE_A_HOST; ··· 2464 2463 if (musb->need_finish_resume) { 2465 2464 musb->need_finish_resume = 0; 2466 2465 schedule_delayed_work(&musb->finish_resume_work, 2467 - msecs_to_jiffies(20)); 2466 + msecs_to_jiffies(USB_RESUME_TIMEOUT)); 2468 2467 } 2469 2468 2470 2469 /* ··· 2507 2506 if (musb->need_finish_resume) { 2508 2507 musb->need_finish_resume = 0; 2509 2508 schedule_delayed_work(&musb->finish_resume_work, 2510 - msecs_to_jiffies(20)); 2509 + msecs_to_jiffies(USB_RESUME_TIMEOUT)); 2511 2510 } 2512 2511 2513 2512 return 0;
+1 -1
drivers/usb/musb/musb_virthub.c
··· 136 136 /* later, GetPortStatus will stop RESUME signaling */ 137 137 musb->port1_status |= MUSB_PORT_STAT_RESUME; 138 138 schedule_delayed_work(&musb->finish_resume_work, 139 - msecs_to_jiffies(20)); 139 + msecs_to_jiffies(USB_RESUME_TIMEOUT)); 140 140 } 141 141 } 142 142
+26
include/linux/usb.h
··· 205 205 #define USB_MAXINTERFACES 32 206 206 #define USB_MAXIADS (USB_MAXINTERFACES/2) 207 207 208 + /* 209 + * USB Resume Timer: Every Host controller driver should drive the resume 210 + * signalling on the bus for the amount of time defined by this macro. 211 + * 212 + * That way we will have a 'stable' behavior among all HCDs supported by Linux. 213 + * 214 + * Note that the USB Specification states we should drive resume for *at least* 215 + * 20 ms, but it doesn't give an upper bound. This creates two possible 216 + * situations which we want to avoid: 217 + * 218 + * (a) sometimes an msleep(20) might expire slightly before 20 ms, which causes 219 + * us to fail USB Electrical Tests, thus failing Certification 220 + * 221 + * (b) Some (many) devices actually need more than 20 ms of resume signalling, 222 + * and while we can argue that's against the USB Specification, we don't have 223 + * control over which devices a certification laboratory will be using for 224 + * certification. If CertLab uses a device which was tested against Windows and 225 + * that happens to have relaxed resume signalling rules, we might fall into 226 + * situations where we fail interoperability and electrical tests. 227 + * 228 + * In order to avoid both conditions, we're using a 40 ms resume timeout, which 229 + * should cope with both LPJ calibration errors and devices not following every 230 + * detail of the USB Specification. 231 + */ 232 + #define USB_RESUME_TIMEOUT 40 /* ms */ 233 + 208 234 /** 209 235 * struct usb_interface_cache - long-term representation of a device interface 210 236 * @num_altsetting: number of altsettings defined.