PCI: mt7621: Sleep a bit after power on the PCIs phy ports

Message ID 20221209071703.2891714-1-sergio.paracuellos@gmail.com
State New
Headers
Series PCI: mt7621: Sleep a bit after power on the PCIs phy ports |

Commit Message

Sergio Paracuellos Dec. 9, 2022, 7:17 a.m. UTC
  Some devices like ZBT WE1326 and ZBT WF3526-P need to sleep a bit after call
to mt7621_pcie_init_port() driver function to get into reliable boots for
both warn and hard resets. The needed time for these devices to always detect
the ports seems to be from 75 to 100 milliseconds. Hence, properly add an
extra 100 milliseconds msleep() call to make also these devices work.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
Hi Bjorn / Lorenzo,

I send previous patch here [0] related with this issue. Since after a bit
of testing with these devices by openwrt community [1] we end up that there is
no need of increasing PERST_DELAY_MS definition. This is also the reason
of not sending a v2 for this but a new patch with the proper solution.
I preferred to just use the same PERST_DELAY_MS define also for this to
not perform extra changes but the needed to the driver. If you prefer
me to write new definitions for all the sleep paths you pointed out in
[0], just let me know and I will send them also.

Thanks in advance for your time.

Best regards,
    Sergio Paracuellos

[0]: https://lore.kernel.org/linux-pci/20221119110837.2419466-1-sergio.paracuellos@gmail.com/T/#u
[1]: https://github.com/openwrt/openwrt/pull/11220

 drivers/pci/controller/pcie-mt7621.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Lorenzo Pieralisi Dec. 30, 2022, 2:23 p.m. UTC | #1
On Fri, Dec 09, 2022 at 08:17:03AM +0100, Sergio Paracuellos wrote:
> Some devices like ZBT WE1326 and ZBT WF3526-P need to sleep a bit after call
> to mt7621_pcie_init_port() driver function to get into reliable boots for
> both warn and hard resets. The needed time for these devices to always detect

s/warn/warm

> the ports seems to be from 75 to 100 milliseconds. Hence, properly add an
> extra 100 milliseconds msleep() call to make also these devices work.

This sounds empirical and it probably is, is it asking too much please
to add why this delay is *actually* needed ? I think it is important
to understand that to make sure that in the future developers have a
clue about why this code was added.

At the very least add a Link: tag to the openwrt discussion.

> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
> ---
> Hi Bjorn / Lorenzo,
> 
> I send previous patch here [0] related with this issue. Since after a bit
> of testing with these devices by openwrt community [1] we end up that there is
> no need of increasing PERST_DELAY_MS definition. This is also the reason
> of not sending a v2 for this but a new patch with the proper solution.

See above, please define "proper". I don't have a problem with defining
multiple delays as long as we can define with certainty what they are
there for.

> I preferred to just use the same PERST_DELAY_MS define also for this to
> not perform extra changes but the needed to the driver.

The problem is not adding more defines, the problem is defining what
the delay is there for. Reusing the macro may even turn out to be
misleading if that has nothing to do with PERST - that's what Bjorn
pointed out already.

> If you prefer me to write new definitions for all the sleep paths you
> pointed out in [0], just let me know and I will send them also.

Yes, see above.

Thanks,
Lorenzo

> Thanks in advance for your time.
> 
> Best regards,
>     Sergio Paracuellos
> 
> [0]: https://lore.kernel.org/linux-pci/20221119110837.2419466-1-sergio.paracuellos@gmail.com/T/#u
> [1]: https://github.com/openwrt/openwrt/pull/11220
> 
>  drivers/pci/controller/pcie-mt7621.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c
> index 4bd1abf26008..3311ca64b315 100644
> --- a/drivers/pci/controller/pcie-mt7621.c
> +++ b/drivers/pci/controller/pcie-mt7621.c
> @@ -369,6 +369,7 @@ static int mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
>  		}
>  	}
>  
> +	msleep(PERST_DELAY_MS);
>  	mt7621_pcie_reset_ep_deassert(pcie);
>  
>  	tmp = NULL;
> -- 
> 2.25.1
>
  
Sergio Paracuellos Dec. 30, 2022, 2:42 p.m. UTC | #2
Hi Lorenzo,

On Fri, Dec 30, 2022 at 3:23 PM Lorenzo Pieralisi <lpieralisi@kernel.org> wrote:
>
> On Fri, Dec 09, 2022 at 08:17:03AM +0100, Sergio Paracuellos wrote:
> > Some devices like ZBT WE1326 and ZBT WF3526-P need to sleep a bit after call
> > to mt7621_pcie_init_port() driver function to get into reliable boots for
> > both warn and hard resets. The needed time for these devices to always detect
>
> s/warn/warm

Sure, I will fix this in v2.

>
> > the ports seems to be from 75 to 100 milliseconds. Hence, properly add an
> > extra 100 milliseconds msleep() call to make also these devices work.
>
> This sounds empirical and it probably is, is it asking too much please
> to add why this delay is *actually* needed ? I think it is important
> to understand that to make sure that in the future developers have a
> clue about why this code was added.
>
> At the very least add a Link: tag to the openwrt discussion.

Most mt7621 boards don't need this extra time after initializing pci
phy related ports registers.
Devices like the two commented here (and some netgear models) seem to
need it to reliably
detect pci ports in both warm and cold resets. I don't have the
devices but the time added by
this patch has been tested on those devices. Since there is no
datasheet or something similar
that says what is this needed in the particular devices I will add the
following link to the commit
message pointing out the openwrt discussion:

https://github.com/openwrt/openwrt/pull/11220

>
> > Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
> > ---
> > Hi Bjorn / Lorenzo,
> >
> > I send previous patch here [0] related with this issue. Since after a bit
> > of testing with these devices by openwrt community [1] we end up that there is
> > no need of increasing PERST_DELAY_MS definition. This is also the reason
> > of not sending a v2 for this but a new patch with the proper solution.
>
> See above, please define "proper". I don't have a problem with defining
> multiple delays as long as we can define with certainty what they are
> there for.

Well, "proper" here was referring to having an always working solution
for these particular devices.

>
> > I preferred to just use the same PERST_DELAY_MS define also for this to
> > not perform extra changes but the needed to the driver.
>
> The problem is not adding more defines, the problem is defining what
> the delay is there for. Reusing the macro may even turn out to be
> misleading if that has nothing to do with PERST - that's what Bjorn
> pointed out already.

Pretty clear, thanks. Will add them and send v2.

>
> > If you prefer me to write new definitions for all the sleep paths you
> > pointed out in [0], just let me know and I will send them also.
>
> Yes, see above.
>
> Thanks,
> Lorenzo

Thanks,
    Sergio Paracuellos

>
> > Thanks in advance for your time.
> >
> > Best regards,
> >     Sergio Paracuellos
> >
> > [0]: https://lore.kernel.org/linux-pci/20221119110837.2419466-1-sergio.paracuellos@gmail.com/T/#u
> > [1]: https://github.com/openwrt/openwrt/pull/11220
> >
> >  drivers/pci/controller/pcie-mt7621.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c
> > index 4bd1abf26008..3311ca64b315 100644
> > --- a/drivers/pci/controller/pcie-mt7621.c
> > +++ b/drivers/pci/controller/pcie-mt7621.c
> > @@ -369,6 +369,7 @@ static int mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
> >               }
> >       }
> >
> > +     msleep(PERST_DELAY_MS);
> >       mt7621_pcie_reset_ep_deassert(pcie);
> >
> >       tmp = NULL;
> > --
> > 2.25.1
> >
  

Patch

diff --git a/drivers/pci/controller/pcie-mt7621.c b/drivers/pci/controller/pcie-mt7621.c
index 4bd1abf26008..3311ca64b315 100644
--- a/drivers/pci/controller/pcie-mt7621.c
+++ b/drivers/pci/controller/pcie-mt7621.c
@@ -369,6 +369,7 @@  static int mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
 		}
 	}
 
+	msleep(PERST_DELAY_MS);
 	mt7621_pcie_reset_ep_deassert(pcie);
 
 	tmp = NULL;