diff mbox series

[net-next] net: stmmac: Fix the case when PHY handle is not present

Message ID 351cce38d1c572d8b171044f2856c7fae9f89cbc.1561450696.git.joabreu@synopsys.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [net-next] net: stmmac: Fix the case when PHY handle is not present | expand

Commit Message

Jose Abreu June 25, 2019, 8:19 a.m. UTC
Some DT bindings do not have the PHY handle. Let's fallback to manually
discovery in case phylink_of_phy_connect() fails.

Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
---
Hello Katsuhiro,

Can you please test this patch ?
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Sergei Shtylyov June 25, 2019, 10:29 a.m. UTC | #1
Hello!

On 25.06.2019 11:19, Jose Abreu wrote:

> Some DT bindings do not have the PHY handle. Let's fallback to manually
> discovery in case phylink_of_phy_connect() fails.
> 
> Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
> Cc: Joao Pinto <jpinto@synopsys.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> ---
> Hello Katsuhiro,
> 
> Can you please test this patch ?
> ---
>   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a48751989fa6..f4593d2d9d20 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -950,9 +950,12 @@ static int stmmac_init_phy(struct net_device *dev)
>   
>   	node = priv->plat->phylink_node;
>   
> -	if (node) {
> +	if (node)
>   		ret = phylink_of_phy_connect(priv->phylink, node, 0);
> -	} else {
> +
> +	/* Some DT bindings do not set-up the PHY handle. Let's try to
> +	 * manually parse it */

    The multi-line comments inb the networking code should be formatted like 
below:

	/*
	 * bla
	 * bla
	 */

> +	if (!node || ret) {
>   		int addr = priv->plat->phy_addr;
>   		struct phy_device *phydev;
>   

MBR, Sergei
Sergei Shtylyov June 25, 2019, 10:51 a.m. UTC | #2
On 25.06.2019 13:29, Sergei Shtylyov wrote:

>> Some DT bindings do not have the PHY handle. Let's fallback to manually
>> discovery in case phylink_of_phy_connect() fails.
>>
>> Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
>> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
>> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
>> Cc: Joao Pinto <jpinto@synopsys.com>
>> Cc: David S. Miller <davem@davemloft.net>
>> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
>> Cc: Alexandre Torgue <alexandre.torgue@st.com>
>> ---
>> Hello Katsuhiro,
>>
>> Can you please test this patch ?
>> ---
>>   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
>> b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> index a48751989fa6..f4593d2d9d20 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> @@ -950,9 +950,12 @@ static int stmmac_init_phy(struct net_device *dev)
>>       node = priv->plat->phylink_node;
>> -    if (node) {
>> +    if (node)
>>           ret = phylink_of_phy_connect(priv->phylink, node, 0);
>> -    } else {
>> +
>> +    /* Some DT bindings do not set-up the PHY handle. Let's try to
>> +     * manually parse it */
> 
>     The multi-line comments inb the networking code should be formatted like 
> below:
> 
>      /*
>       * bla

    Oops, that was the general comment format, networking code starts without 
the leading empty line:\

	/* bla
>        * bla
>        */
[...]

MBR, Sergei
Jose Abreu June 25, 2019, 1:11 p.m. UTC | #3
++ Katsuhiro

From: Jose Abreu <joabreu@synopsys.com>

> Some DT bindings do not have the PHY handle. Let's fallback to manually
> discovery in case phylink_of_phy_connect() fails.
> 
> Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
> Cc: Joao Pinto <jpinto@synopsys.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
> Cc: Alexandre Torgue <alexandre.torgue@st.com>
> ---
> Hello Katsuhiro,
> 
> Can you please test this patch ?
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index a48751989fa6..f4593d2d9d20 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -950,9 +950,12 @@ static int stmmac_init_phy(struct net_device *dev)
>  
>  	node = priv->plat->phylink_node;
>  
> -	if (node) {
> +	if (node)
>  		ret = phylink_of_phy_connect(priv->phylink, node, 0);
> -	} else {
> +
> +	/* Some DT bindings do not set-up the PHY handle. Let's try to
> +	 * manually parse it */
> +	if (!node || ret) {
>  		int addr = priv->plat->phy_addr;
>  		struct phy_device *phydev;
>  
> -- 
> 2.7.4
Katsuhiro Suzuki June 25, 2019, 2:40 p.m. UTC | #4
Hello Jose,

This patch works fine with my Tinker Board. Thanks a lot!

Tested-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>


BTW, from network guys point of view, is it better to add a phy node
into device trees that have no phy node such as the Tinker Board?


Best Regards,
Katsuhiro Suzuki


On 2019/06/25 22:11, Jose Abreu wrote:
> ++ Katsuhiro
> 
> From: Jose Abreu <joabreu@synopsys.com>
> 
>> Some DT bindings do not have the PHY handle. Let's fallback to manually
>> discovery in case phylink_of_phy_connect() fails.
>>
>> Reported-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
>> Fixes: 74371272f97f ("net: stmmac: Convert to phylink and remove phylib logic")
>> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
>> Cc: Joao Pinto <jpinto@synopsys.com>
>> Cc: David S. Miller <davem@davemloft.net>
>> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
>> Cc: Alexandre Torgue <alexandre.torgue@st.com>
>> ---
>> Hello Katsuhiro,
>>
>> Can you please test this patch ?
>> ---
>>   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> index a48751989fa6..f4593d2d9d20 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
>> @@ -950,9 +950,12 @@ static int stmmac_init_phy(struct net_device *dev)
>>   
>>   	node = priv->plat->phylink_node;
>>   
>> -	if (node) {
>> +	if (node)
>>   		ret = phylink_of_phy_connect(priv->phylink, node, 0);
>> -	} else {
>> +
>> +	/* Some DT bindings do not set-up the PHY handle. Let's try to
>> +	 * manually parse it */
>> +	if (!node || ret) {
>>   		int addr = priv->plat->phy_addr;
>>   		struct phy_device *phydev;
>>   
>> -- 
>> 2.7.4
> 
> 
> 
>
Andrew Lunn June 25, 2019, 2:51 p.m. UTC | #5
On Tue, Jun 25, 2019 at 11:40:00PM +0900, Katsuhiro Suzuki wrote:
> Hello Jose,
> 
> This patch works fine with my Tinker Board. Thanks a lot!
> 
> Tested-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
> 
> 
> BTW, from network guys point of view, is it better to add a phy node
> into device trees that have no phy node such as the Tinker Board?

Hi Katsuhiro

It makes it less ambiguous if there is a phy-handle. It is then very
clear which PHY should be used. For a development board, which people
can be tinkering around with, there is a chance they add a second PHY
to the MDIO bus, or an Ethernet switch, etc. Without explicitly
listing the PHY, it might get the wrong one. However this is generally
a problem if phy_find_first() is used. I think in this case, something
is setting priv->plat->phy_addr, so it is also clearly defined which
PHY to use.

	  Andrew
Katsuhiro Suzuki June 25, 2019, 3:26 p.m. UTC | #6
Hello Andrew,

On 2019/06/25 23:51, Andrew Lunn wrote:
> On Tue, Jun 25, 2019 at 11:40:00PM +0900, Katsuhiro Suzuki wrote:
>> Hello Jose,
>>
>> This patch works fine with my Tinker Board. Thanks a lot!
>>
>> Tested-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
>>
>>
>> BTW, from network guys point of view, is it better to add a phy node
>> into device trees that have no phy node such as the Tinker Board?
> 
> Hi Katsuhiro
> 
> It makes it less ambiguous if there is a phy-handle. It is then very
> clear which PHY should be used. For a development board, which people
> can be tinkering around with, there is a chance they add a second PHY
> to the MDIO bus, or an Ethernet switch, etc. Without explicitly
> listing the PHY, it might get the wrong one. However this is generally
> a problem if phy_find_first() is used. I think in this case, something
> is setting priv->plat->phy_addr, so it is also clearly defined which
> PHY to use.
> 
> 	  Andrew
> 

Hmm, I see. This stmmac driver can choose PHY by the kernel module
parameter 'phyaddr' (if no one set this parameter, priv->plat->phy_addr
goes to 0). So there is no ambiguous in this case and need no changes
for device tree.

Thank you for your comment.

Best Regards,
Katsuhiro Suzuki
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a48751989fa6..f4593d2d9d20 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -950,9 +950,12 @@  static int stmmac_init_phy(struct net_device *dev)
 
 	node = priv->plat->phylink_node;
 
-	if (node) {
+	if (node)
 		ret = phylink_of_phy_connect(priv->phylink, node, 0);
-	} else {
+
+	/* Some DT bindings do not set-up the PHY handle. Let's try to
+	 * manually parse it */
+	if (!node || ret) {
 		int addr = priv->plat->phy_addr;
 		struct phy_device *phydev;