Re: [PATCH v5] phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context

From: Manivannan Sadhasivam

Date: Tue Sep 08 2026 - 03:48:31 EST


On Thu, Jul 16, 2026 at 09:32:46PM +0300, Claudiu Beznea wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>
>
> The OTG PHY initialization sequence needs to wait for 20 ms at a specific
> step, as described in commit 72c0339c115b ("phy: renesas:
> rcar-gen3-usb2: follow the hardware manual procedure").
>
> Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware
> registers and driver data") tried to address various problems in the
> rcar-gen3-usb2 driver and converted the mutex protecting HW register
> accesses to a spin lock, leaving, however, a long delay in the critical
> section protected by the spin lock. This may become a problem,
> especially on RT kernels.
>
> To address this, release the spin lock before sleeping for 20 ms as
> required by the HW manual and reacquire it afterwards. To avoid other
> threads entering the critical section and configuring the HW while the
> software is waiting for the OTG initialization to complete, introduce the
> otg_initializing variable alongside the otg_init_done wait queue. Any
> other thread trying to configure the HW while the OTG PHY initialization
> is in progress waits for the wait queue instead of immediately returning
> errors to PHY users. The IRQs were also disabled while waiting for the OTG
> PHY initialization to complete, as the interrupt handler may also apply HW
> settings.
>
> The OTG can only be initialized once. It is initialized by the first PHY
> that calls struct phy_ops::rcar_gen3_phy_usb2_init().
>
> To avoid failures when multiple PHYs call struct
> phy_ops::rcar_gen3_phy_usb2_init() simultaneously, and the PHY responsible
> for initializing the OTG either fails or deinit quiqly and another PHY
> takes over the PHY init role), the code waiting for the
> channel->otg_init_done wait queue retries up to NUM_OF_PHYS times.
>
> Fixes: 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Pavel Machek <pavel@xxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/afhkX2Ys2BG1gnqy@xxxxxxxxxx
> Reported-by: Nobuhiro Iwamatsu <iwamatsu@xxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/afhkX2Ys2BG1gnqy@xxxxxxxxxx
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@xxxxxxxxxxxxxx>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>

- Mani

--
மணிவண்ணன் சதாசிவம்