* [PATCH master] usb: dwc2: increase timeout for waiting on host mode @ 2021-04-21 7:27 Ahmad Fatoum 2021-04-21 8:47 ` Jules Maselbas 0 siblings, 1 reply; 6+ messages in thread From: Ahmad Fatoum @ 2021-04-21 7:27 UTC (permalink / raw) To: barebox; +Cc: jmaselbas, Ahmad Fatoum Commit 26459ab7803a ("usb: dwc2: Rework wait for host mode during core reset") effectively reduced the timeout on switch to host mode from 200ms to 110 us, which is insufficient for the IP on the Raspberry Pi 3b, leading to: dwc2 3f980000.usb@7e980000.of: dwc2_wait_for_mode: Couldn't set host mode and an unusable USB (and Ethernet) after. Bump up the timeout to 200ms and help future debugging by logging how much time it actually took. For the Raspberry 3b I got a value of 49ms. Note that this is also called from dwc2_force_mode, so worst case is that a stuck IP delays barebox startup by 200ms. An error message would alert to this fact, so it can be corrected. Fixes: 26459ab7803a ("usb: dwc2: Rework wait for host mode during core reset") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- drivers/usb/dwc2/core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 5d04a07b0393..7813344ffa65 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -688,19 +688,23 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) */ void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) { - unsigned int timeout = 110 * USECOND; - int ret; + unsigned int timeout = 200 * MSECOND; + uint64_t start; dev_vdbg(dwc2->dev, "Waiting for %s mode\n", host_mode ? "host" : "device"); - ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode); - if (ret) - dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", - __func__, host_mode ? "host" : "device"); + start = get_time_ns(); + while (dwc2_is_host_mode(dwc2) != host_mode) { + if (is_timeout(start, timeout)) { + dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", + __func__, host_mode ? "host" : "device"); + return; + } + } - dev_vdbg(dwc2->dev, "%s mode set\n", - host_mode ? "Host" : "Device"); + dev_vdbg(dwc2->dev, "%s mode set after %lluns\n", + host_mode ? "Host" : "Device", get_time_ns() - start); } /** -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH master] usb: dwc2: increase timeout for waiting on host mode 2021-04-21 7:27 [PATCH master] usb: dwc2: increase timeout for waiting on host mode Ahmad Fatoum @ 2021-04-21 8:47 ` Jules Maselbas 2021-04-21 8:50 ` Ahmad Fatoum 0 siblings, 1 reply; 6+ messages in thread From: Jules Maselbas @ 2021-04-21 8:47 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: barebox Hi Ahmad, On Wed, Apr 21, 2021 at 09:27:04AM +0200, Ahmad Fatoum wrote: > Commit 26459ab7803a ("usb: dwc2: Rework wait for host mode during > core reset") effectively reduced the timeout on switch to host mode > from 200ms to 110 us, which is insufficient for the IP on the Raspberry > Pi 3b, leading to: > > dwc2 3f980000.usb@7e980000.of: dwc2_wait_for_mode: Couldn't set host mode > > and an unusable USB (and Ethernet) after. > > Bump up the timeout to 200ms and help future debugging by logging how > much time it actually took. For the Raspberry 3b I got a value of 49ms. Indeed, I've changed the timeout in Commit 26459ab7803a, I've tried to follow what's done in Linux in drivers/usb/dwc2/core.c, see https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/core.c#L385 Turns out I've made a mistake, Linux is using 110 ms and not µs. So maybe we can use 110 * MSECOND ? it will still be greater than what's required for the Raspberry 3b. In the other hand the wait will stop as soon as the mode is set. it will only make the worst case faster... which is not a big deal. > > Note that this is also called from dwc2_force_mode, so worst case is > that a stuck IP delays barebox startup by 200ms. > An error message would alert to this fact, so it can be corrected. Ok, this can be useful. > Fixes: 26459ab7803a ("usb: dwc2: Rework wait for host mode during core reset") > Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > --- > drivers/usb/dwc2/core.c | 20 ++++++++++++-------- > 1 file changed, 12 insertions(+), 8 deletions(-) > > diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c > index 5d04a07b0393..7813344ffa65 100644 > --- a/drivers/usb/dwc2/core.c > +++ b/drivers/usb/dwc2/core.c > @@ -688,19 +688,23 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) > */ > void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) > { > - unsigned int timeout = 110 * USECOND; > - int ret; > + unsigned int timeout = 200 * MSECOND; > + uint64_t start; > > dev_vdbg(dwc2->dev, "Waiting for %s mode\n", > host_mode ? "host" : "device"); > > - ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode); > - if (ret) > - dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", > - __func__, host_mode ? "host" : "device"); > + start = get_time_ns(); > + while (dwc2_is_host_mode(dwc2) != host_mode) { > + if (is_timeout(start, timeout)) { > + dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", > + __func__, host_mode ? "host" : "device"); > + return; > + } > + } > > - dev_vdbg(dwc2->dev, "%s mode set\n", > - host_mode ? "Host" : "Device"); > + dev_vdbg(dwc2->dev, "%s mode set after %lluns\n", > + host_mode ? "Host" : "Device", get_time_ns() - start); > } > > /** > -- > 2.29.2 > > _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH master] usb: dwc2: increase timeout for waiting on host mode 2021-04-21 8:47 ` Jules Maselbas @ 2021-04-21 8:50 ` Ahmad Fatoum 2021-04-21 9:11 ` Jules Maselbas 2021-05-07 8:07 ` Sascha Hauer 0 siblings, 2 replies; 6+ messages in thread From: Ahmad Fatoum @ 2021-04-21 8:50 UTC (permalink / raw) To: Jules Maselbas; +Cc: barebox Hello Jules, On 21.04.21 10:47, Jules Maselbas wrote: > Hi Ahmad, > > On Wed, Apr 21, 2021 at 09:27:04AM +0200, Ahmad Fatoum wrote: >> Commit 26459ab7803a ("usb: dwc2: Rework wait for host mode during >> core reset") effectively reduced the timeout on switch to host mode >> from 200ms to 110 us, which is insufficient for the IP on the Raspberry >> Pi 3b, leading to: >> >> dwc2 3f980000.usb@7e980000.of: dwc2_wait_for_mode: Couldn't set host mode >> >> and an unusable USB (and Ethernet) after. >> >> Bump up the timeout to 200ms and help future debugging by logging how >> much time it actually took. For the Raspberry 3b I got a value of 49ms. > Indeed, I've changed the timeout in Commit 26459ab7803a, I've tried to > follow what's done in Linux in drivers/usb/dwc2/core.c, see > https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/core.c#L385 > > Turns out I've made a mistake, Linux is using 110 ms and not µs. > So maybe we can use 110 * MSECOND ? it will still be greater than what's > required for the Raspberry 3b. In the other hand the wait will stop as > soon as the mode is set. it will only make the worst case faster... > which is not a big deal. I am fine with aligning ourselves with what Linux is doing. Can you post that as a separate patch? That way this here can go into v2021.05.0 to fix the immediate breakage and yours can go into v2020.06.0, which will hopefully afford users some more time to test. Cheers, Ahmad >> >> Note that this is also called from dwc2_force_mode, so worst case is >> that a stuck IP delays barebox startup by 200ms. >> An error message would alert to this fact, so it can be corrected. > Ok, this can be useful. > >> Fixes: 26459ab7803a ("usb: dwc2: Rework wait for host mode during core reset") >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> >> --- >> drivers/usb/dwc2/core.c | 20 ++++++++++++-------- >> 1 file changed, 12 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c >> index 5d04a07b0393..7813344ffa65 100644 >> --- a/drivers/usb/dwc2/core.c >> +++ b/drivers/usb/dwc2/core.c >> @@ -688,19 +688,23 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) >> */ >> void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) >> { >> - unsigned int timeout = 110 * USECOND; >> - int ret; >> + unsigned int timeout = 200 * MSECOND; >> + uint64_t start; >> >> dev_vdbg(dwc2->dev, "Waiting for %s mode\n", >> host_mode ? "host" : "device"); >> >> - ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode); >> - if (ret) >> - dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", >> - __func__, host_mode ? "host" : "device"); >> + start = get_time_ns(); >> + while (dwc2_is_host_mode(dwc2) != host_mode) { >> + if (is_timeout(start, timeout)) { >> + dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", >> + __func__, host_mode ? "host" : "device"); >> + return; >> + } >> + } >> >> - dev_vdbg(dwc2->dev, "%s mode set\n", >> - host_mode ? "Host" : "Device"); >> + dev_vdbg(dwc2->dev, "%s mode set after %lluns\n", >> + host_mode ? "Host" : "Device", get_time_ns() - start); >> } >> >> /** >> -- >> 2.29.2 >> >> > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH master] usb: dwc2: increase timeout for waiting on host mode 2021-04-21 8:50 ` Ahmad Fatoum @ 2021-04-21 9:11 ` Jules Maselbas 2021-05-07 8:07 ` Sascha Hauer 1 sibling, 0 replies; 6+ messages in thread From: Jules Maselbas @ 2021-04-21 9:11 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: barebox On Wed, Apr 21, 2021 at 10:50:52AM +0200, Ahmad Fatoum wrote: > Hello Jules, > > On 21.04.21 10:47, Jules Maselbas wrote: > > Hi Ahmad, > > > > On Wed, Apr 21, 2021 at 09:27:04AM +0200, Ahmad Fatoum wrote: > >> Commit 26459ab7803a ("usb: dwc2: Rework wait for host mode during > >> core reset") effectively reduced the timeout on switch to host mode > >> from 200ms to 110 us, which is insufficient for the IP on the Raspberry > >> Pi 3b, leading to: > >> > >> dwc2 3f980000.usb@7e980000.of: dwc2_wait_for_mode: Couldn't set host mode > >> > >> and an unusable USB (and Ethernet) after. > >> > >> Bump up the timeout to 200ms and help future debugging by logging how > >> much time it actually took. For the Raspberry 3b I got a value of 49ms. > > Indeed, I've changed the timeout in Commit 26459ab7803a, I've tried to > > follow what's done in Linux in drivers/usb/dwc2/core.c, see > > https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/core.c#L385 > > > > Turns out I've made a mistake, Linux is using 110 ms and not µs. > > So maybe we can use 110 * MSECOND ? it will still be greater than what's > > required for the Raspberry 3b. In the other hand the wait will stop as > > soon as the mode is set. it will only make the worst case faster... > > which is not a big deal. > > I am fine with aligning ourselves with what Linux is doing. > Can you post that as a separate patch? That way this here can go into > v2021.05.0 to fix the immediate breakage and yours can go into v2020.06.0, > which will hopefully afford users some more time to test. Yes, sure I'll send a patch for this, and maybe with some more for dwc2. > > Cheers, > Ahmad > > >> > >> Note that this is also called from dwc2_force_mode, so worst case is > >> that a stuck IP delays barebox startup by 200ms. > >> An error message would alert to this fact, so it can be corrected. > > Ok, this can be useful. > > > >> Fixes: 26459ab7803a ("usb: dwc2: Rework wait for host mode during core reset") > >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > >> --- > >> drivers/usb/dwc2/core.c | 20 ++++++++++++-------- > >> 1 file changed, 12 insertions(+), 8 deletions(-) > >> > >> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c > >> index 5d04a07b0393..7813344ffa65 100644 > >> --- a/drivers/usb/dwc2/core.c > >> +++ b/drivers/usb/dwc2/core.c > >> @@ -688,19 +688,23 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) > >> */ > >> void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) > >> { > >> - unsigned int timeout = 110 * USECOND; > >> - int ret; > >> + unsigned int timeout = 200 * MSECOND; > >> + uint64_t start; > >> > >> dev_vdbg(dwc2->dev, "Waiting for %s mode\n", > >> host_mode ? "host" : "device"); > >> > >> - ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode); > >> - if (ret) > >> - dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", > >> - __func__, host_mode ? "host" : "device"); > >> + start = get_time_ns(); > >> + while (dwc2_is_host_mode(dwc2) != host_mode) { > >> + if (is_timeout(start, timeout)) { > >> + dev_err(dwc2->dev, "%s: Couldn't set %s mode\n", > >> + __func__, host_mode ? "host" : "device"); > >> + return; > >> + } > >> + } > >> > >> - dev_vdbg(dwc2->dev, "%s mode set\n", > >> - host_mode ? "Host" : "Device"); > >> + dev_vdbg(dwc2->dev, "%s mode set after %lluns\n", > >> + host_mode ? "Host" : "Device", get_time_ns() - start); > >> } > >> > >> /** > >> -- > >> 2.29.2 > >> > >> > > > > > > -- > Pengutronix e.K. | | > Steuerwalder Str. 21 | http://www.pengutronix.de/ | > 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | > _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH master] usb: dwc2: increase timeout for waiting on host mode 2021-04-21 8:50 ` Ahmad Fatoum 2021-04-21 9:11 ` Jules Maselbas @ 2021-05-07 8:07 ` Sascha Hauer 2021-06-02 11:21 ` Ahmad Fatoum 1 sibling, 1 reply; 6+ messages in thread From: Sascha Hauer @ 2021-05-07 8:07 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: Jules Maselbas, barebox On Wed, Apr 21, 2021 at 10:50:52AM +0200, Ahmad Fatoum wrote: > Hello Jules, > > On 21.04.21 10:47, Jules Maselbas wrote: > > Hi Ahmad, > > > > On Wed, Apr 21, 2021 at 09:27:04AM +0200, Ahmad Fatoum wrote: > >> Commit 26459ab7803a ("usb: dwc2: Rework wait for host mode during > >> core reset") effectively reduced the timeout on switch to host mode > >> from 200ms to 110 us, which is insufficient for the IP on the Raspberry > >> Pi 3b, leading to: > >> > >> dwc2 3f980000.usb@7e980000.of: dwc2_wait_for_mode: Couldn't set host mode > >> > >> and an unusable USB (and Ethernet) after. > >> > >> Bump up the timeout to 200ms and help future debugging by logging how > >> much time it actually took. For the Raspberry 3b I got a value of 49ms. > > Indeed, I've changed the timeout in Commit 26459ab7803a, I've tried to > > follow what's done in Linux in drivers/usb/dwc2/core.c, see > > https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/core.c#L385 > > > > Turns out I've made a mistake, Linux is using 110 ms and not µs. > > So maybe we can use 110 * MSECOND ? it will still be greater than what's > > required for the Raspberry 3b. In the other hand the wait will stop as > > soon as the mode is set. it will only make the worst case faster... > > which is not a big deal. > > I am fine with aligning ourselves with what Linux is doing. > Can you post that as a separate patch? That way this here can go into > v2021.05.0 to fix the immediate breakage and yours can go into v2020.06.0, > which will hopefully afford users some more time to test. Instead of applying two patches I suggest we go with the following oneliner which is fine for master. Sascha ------------------------------8<-------------------------------- >From 9fc2b0364c4b686d110b772be2245be3a513407d Mon Sep 17 00:00:00 2001 From: Sascha Hauer <s.hauer@pengutronix.de> Date: Fri, 7 May 2021 09:58:43 +0200 Subject: [PATCH] usb: dwc2: Fix wait for mode timeout The timeout waiting for host mode should be 110ms instead of 110us. The timeout is the same as in Linux now and the same it was before fdd30cc251. It takes 49ms to go to host mode on the Raspberry Pi 3b, so host mode stopped working with 26459ab780 which removed an additional 100ms delay before dwc2_wait_for_mode() was actually called. Fixes: fdd30cc251 ("usb: dwc2: Rework dwc2_wait_for_mode to use wait_on_timeout") Fixes: 26459ab780 ("usb: dwc2: Rework wait for host mode during core reset") Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- drivers/usb/dwc2/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 5d04a07b03..8a78d8199e 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -688,7 +688,7 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) */ void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) { - unsigned int timeout = 110 * USECOND; + unsigned int timeout = 110 * MSECOND; int ret; dev_vdbg(dwc2->dev, "Waiting for %s mode\n", -- 2.29.2 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH master] usb: dwc2: increase timeout for waiting on host mode 2021-05-07 8:07 ` Sascha Hauer @ 2021-06-02 11:21 ` Ahmad Fatoum 0 siblings, 0 replies; 6+ messages in thread From: Ahmad Fatoum @ 2021-06-02 11:21 UTC (permalink / raw) To: Sascha Hauer; +Cc: Jules Maselbas, barebox On 07.05.21 10:07, Sascha Hauer wrote: > Instead of applying two patches I suggest we go with the following > oneliner which is fine for master. I'd have preferred two patches, because then I've more time to procrastinate before testing the second one. ;) FTR: I just tested v2021.05.0 and USB now works (tested by DHCP over the USB-Ethernet controller). Thanks, Ahmad > > Sascha > > ------------------------------8<-------------------------------- > > From 9fc2b0364c4b686d110b772be2245be3a513407d Mon Sep 17 00:00:00 2001 > From: Sascha Hauer <s.hauer@pengutronix.de> > Date: Fri, 7 May 2021 09:58:43 +0200 > Subject: [PATCH] usb: dwc2: Fix wait for mode timeout > > The timeout waiting for host mode should be 110ms instead of 110us. > The timeout is the same as in Linux now and the same it was before > fdd30cc251. It takes 49ms to go to host mode on the Raspberry Pi 3b, > so host mode stopped working with 26459ab780 which removed an additional > 100ms delay before dwc2_wait_for_mode() was actually called. > > Fixes: fdd30cc251 ("usb: dwc2: Rework dwc2_wait_for_mode to use wait_on_timeout") > Fixes: 26459ab780 ("usb: dwc2: Rework wait for host mode during core reset") > Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> > --- > drivers/usb/dwc2/core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c > index 5d04a07b03..8a78d8199e 100644 > --- a/drivers/usb/dwc2/core.c > +++ b/drivers/usb/dwc2/core.c > @@ -688,7 +688,7 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2) > */ > void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode) > { > - unsigned int timeout = 110 * USECOND; > + unsigned int timeout = 110 * MSECOND; > int ret; > > dev_vdbg(dwc2->dev, "Waiting for %s mode\n", > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-02 11:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-04-21 7:27 [PATCH master] usb: dwc2: increase timeout for waiting on host mode Ahmad Fatoum 2021-04-21 8:47 ` Jules Maselbas 2021-04-21 8:50 ` Ahmad Fatoum 2021-04-21 9:11 ` Jules Maselbas 2021-05-07 8:07 ` Sascha Hauer 2021-06-02 11:21 ` Ahmad Fatoum
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox