netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
@ 2023-04-05  9:39 Michael Sit Wei Hong
  2023-04-05 10:07 ` Shahab Vahedi
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Michael Sit Wei Hong @ 2023-04-05  9:39 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Ong Boon Leong, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux, hkallweit1, andrew,
	Martin Blumenstingl, Shahab Vahedi, Marek Szyprowski
  Cc: Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh

Some DT devices already have phy device configured in the DT/ACPI.
Current implementation scans for a phy unconditionally even though
there is a phy listed in the DT/ACPI and already attached.

We should check the fwnode if there is any phy device listed in
fwnode and decide whether to scan for a phy to attach to.y

Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index d41a5f92aee7..7ca9be7bec06 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1134,22 +1134,26 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
 static int stmmac_init_phy(struct net_device *dev)
 {
 	struct stmmac_priv *priv = netdev_priv(dev);
+	struct fwnode_handle *phy_fwnode;
 	struct fwnode_handle *fwnode;
-	bool phy_needed;
 	int ret;
 
+	if (!phylink_expects_phy(priv->phylink))
+		return 0;
+
 	fwnode = of_fwnode_handle(priv->plat->phylink_node);
 	if (!fwnode)
 		fwnode = dev_fwnode(priv->device);
 
 	if (fwnode)
-		ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
+		phy_fwnode = fwnode_get_phy_node(fwnode);
+	else
+		phy_fwnode = NULL;
 
-	phy_needed = phylink_expects_phy(priv->phylink);
 	/* Some DT bindings do not set-up the PHY handle. Let's try to
 	 * manually parse it
 	 */
-	if (!fwnode || phy_needed || ret) {
+	if (!phy_fwnode || IS_ERR(phy_fwnode)) {
 		int addr = priv->plat->phy_addr;
 		struct phy_device *phydev;
 
@@ -1165,6 +1169,9 @@ static int stmmac_init_phy(struct net_device *dev)
 		}
 
 		ret = phylink_connect_phy(priv->phylink, phydev);
+	} else {
+		fwnode_handle_put(phy_fwnode);
+		ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
 	}
 
 	if (!priv->plat->pmt) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05  9:39 [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy Michael Sit Wei Hong
@ 2023-04-05 10:07 ` Shahab Vahedi
  2023-04-05 10:10   ` Shahab Vahedi
  2023-04-05 10:53   ` Marek Szyprowski
  2023-04-05 10:18 ` Russell King (Oracle)
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Shahab Vahedi @ 2023-04-05 10:07 UTC (permalink / raw)
  To: Michael Sit Wei Hong, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Maxime Coquelin, Ong Boon Leong,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux@armlinux.org.uk,
	hkallweit1@gmail.com, andrew@lunn.ch, Martin Blumenstingl,
	Shahab Vahedi, Marek Szyprowski
  Cc: Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh@intel.com,
	Vineet Gupta, linux-snps-arc@lists.infradead.org

On 4/5/23 11:39, Michael Sit Wei Hong wrote:
> Some DT devices already have phy device configured in the DT/ACPI.
> Current implementation scans for a phy unconditionally even though
> there is a phy listed in the DT/ACPI and already attached.
> 
> We should check the fwnode if there is any phy device listed in
> fwnode and decide whether to scan for a phy to attach to.y
> 
> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> ---

Works fine on ARC HSDK board.
Tested-by: Shahab Vahedi <shahab@synopsys.com>

-- 
Shahab


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05 10:07 ` Shahab Vahedi
@ 2023-04-05 10:10   ` Shahab Vahedi
  2023-04-05 10:53   ` Marek Szyprowski
  1 sibling, 0 replies; 8+ messages in thread
From: Shahab Vahedi @ 2023-04-05 10:10 UTC (permalink / raw)
  To: Michael Sit Wei Hong, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Maxime Coquelin, Ong Boon Leong,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux@armlinux.org.uk,
	hkallweit1@gmail.com, andrew@lunn.ch, Martin Blumenstingl,
	Marek Szyprowski
  Cc: Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh@intel.com,
	linux-snps-arc@lists.infradead.org, Vineet Gupta

Cc Vineet Gupta

On 4/5/23 12:07, Shahab Vahedi wrote:
> On 4/5/23 11:39, Michael Sit Wei Hong wrote:
>> Some DT devices already have phy device configured in the DT/ACPI.
>> Current implementation scans for a phy unconditionally even though
>> there is a phy listed in the DT/ACPI and already attached.
>>
>> We should check the fwnode if there is any phy device listed in
>> fwnode and decide whether to scan for a phy to attach to.y
>>
>> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
>> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
>> ---
> 
> Works fine on ARC HSDK board.
> Tested-by: Shahab Vahedi <shahab@synopsys.com>
> 

-- 
Shahab


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05  9:39 [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy Michael Sit Wei Hong
  2023-04-05 10:07 ` Shahab Vahedi
@ 2023-04-05 10:18 ` Russell King (Oracle)
  2023-04-05 10:39 ` Martin Blumenstingl
  2023-04-05 19:02 ` Guenter Roeck
  3 siblings, 0 replies; 8+ messages in thread
From: Russell King (Oracle) @ 2023-04-05 10:18 UTC (permalink / raw)
  To: Michael Sit Wei Hong
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Ong Boon Leong, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, hkallweit1, andrew,
	Martin Blumenstingl, Shahab Vahedi, Marek Szyprowski,
	Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh

On Wed, Apr 05, 2023 at 05:39:45PM +0800, Michael Sit Wei Hong wrote:
> Some DT devices already have phy device configured in the DT/ACPI.
> Current implementation scans for a phy unconditionally even though
> there is a phy listed in the DT/ACPI and already attached.
> 
> We should check the fwnode if there is any phy device listed in
> fwnode and decide whether to scan for a phy to attach to.y
> 
> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index d41a5f92aee7..7ca9be7bec06 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -1134,22 +1134,26 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
>  static int stmmac_init_phy(struct net_device *dev)
>  {
>  	struct stmmac_priv *priv = netdev_priv(dev);
> +	struct fwnode_handle *phy_fwnode;
>  	struct fwnode_handle *fwnode;
> -	bool phy_needed;
>  	int ret;
>  
> +	if (!phylink_expects_phy(priv->phylink))
> +		return 0;
> +
>  	fwnode = of_fwnode_handle(priv->plat->phylink_node);
>  	if (!fwnode)
>  		fwnode = dev_fwnode(priv->device);
>  
>  	if (fwnode)
> -		ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
> +		phy_fwnode = fwnode_get_phy_node(fwnode);
> +	else
> +		phy_fwnode = NULL;
>  
> -	phy_needed = phylink_expects_phy(priv->phylink);
>  	/* Some DT bindings do not set-up the PHY handle. Let's try to
>  	 * manually parse it
>  	 */
> -	if (!fwnode || phy_needed || ret) {
> +	if (!phy_fwnode || IS_ERR(phy_fwnode)) {
>  		int addr = priv->plat->phy_addr;
>  		struct phy_device *phydev;
>  
> @@ -1165,6 +1169,9 @@ static int stmmac_init_phy(struct net_device *dev)
>  		}
>  
>  		ret = phylink_connect_phy(priv->phylink, phydev);
> +	} else {
> +		fwnode_handle_put(phy_fwnode);
> +		ret = phylink_fwnode_phy_connect(priv->phylink, fwnode, 0);
>  	}
>  
>  	if (!priv->plat->pmt) {

LGTM, thanks for taking on board my suggestion.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05  9:39 [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy Michael Sit Wei Hong
  2023-04-05 10:07 ` Shahab Vahedi
  2023-04-05 10:18 ` Russell King (Oracle)
@ 2023-04-05 10:39 ` Martin Blumenstingl
  2023-04-05 19:02 ` Guenter Roeck
  3 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2023-04-05 10:39 UTC (permalink / raw)
  To: Michael Sit Wei Hong
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Ong Boon Leong, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux, hkallweit1, andrew,
	Shahab Vahedi, Marek Szyprowski, Looi Hong Aun, Voon Weifeng,
	Lai Peter Jun Ann, Zulkifli Muhammad Husaini, Tan Tee Min,
	hock.leong.kweh

On Wed, Apr 5, 2023 at 11:40 AM Michael Sit Wei Hong
<michael.wei.hong.sit@intel.com> wrote:
>
> Some DT devices already have phy device configured in the DT/ACPI.
> Current implementation scans for a phy unconditionally even though
> there is a phy listed in the DT/ACPI and already attached.
>
> We should check the fwnode if there is any phy device listed in
> fwnode and decide whether to scan for a phy to attach to.y
>
> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
This also works great on my X96 Air (and I presume it will fix all
other Amlogic boards):
Tested-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>


Thanks a lot for being so quick with this fix!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05 10:07 ` Shahab Vahedi
  2023-04-05 10:10   ` Shahab Vahedi
@ 2023-04-05 10:53   ` Marek Szyprowski
  2023-04-05 13:03     ` Looi, Hong Aun
  1 sibling, 1 reply; 8+ messages in thread
From: Marek Szyprowski @ 2023-04-05 10:53 UTC (permalink / raw)
  To: Shahab Vahedi, Michael Sit Wei Hong, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Ong Boon Leong,
	netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux@armlinux.org.uk,
	hkallweit1@gmail.com, andrew@lunn.ch, Martin Blumenstingl
  Cc: Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh@intel.com,
	Vineet Gupta, linux-snps-arc@lists.infradead.org

On 05.04.2023 12:07, Shahab Vahedi wrote:
> On 4/5/23 11:39, Michael Sit Wei Hong wrote:
>> Some DT devices already have phy device configured in the DT/ACPI.
>> Current implementation scans for a phy unconditionally even though
>> there is a phy listed in the DT/ACPI and already attached.
>>
>> We should check the fwnode if there is any phy device listed in
>> fwnode and decide whether to scan for a phy to attach to.y
>>
>> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
>> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
>> ---
> Works fine on ARC HSDK board.
> Tested-by: Shahab Vahedi <shahab@synopsys.com>

Tested-by: Marek Szyprowski

Works fine on Khadas VIM3, Odroid-C4 and Odroid-M1.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05 10:53   ` Marek Szyprowski
@ 2023-04-05 13:03     ` Looi, Hong Aun
  0 siblings, 0 replies; 8+ messages in thread
From: Looi, Hong Aun @ 2023-04-05 13:03 UTC (permalink / raw)
  To: Marek Szyprowski, Shahab Vahedi, Sit, Michael Wei Hong,
	Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Ong, Boon Leong, netdev@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux@armlinux.org.uk,
	hkallweit1@gmail.com, andrew@lunn.ch, Martin Blumenstingl
  Cc: Voon, Weifeng, Lai, Peter Jun Ann, Zulkifli, Muhammad Husaini,
	Tan, Tee Min, Kweh, Hock Leong, Vineet Gupta,
	linux-snps-arc@lists.infradead.org

> On 05.04.2023 12:07, Shahab Vahedi wrote:
> > On 4/5/23 11:39, Michael Sit Wei Hong wrote:
> >> Some DT devices already have phy device configured in the DT/ACPI.
> >> Current implementation scans for a phy unconditionally even though
> >> there is a phy listed in the DT/ACPI and already attached.
> >>
> >> We should check the fwnode if there is any phy device listed in
> >> fwnode and decide whether to scan for a phy to attach to.y
> >>
> >> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> >> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a
> >> PHY")
> >> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> >> ---
> > Works fine on ARC HSDK board.
> > Tested-by: Shahab Vahedi <shahab@synopsys.com>
> 
> Tested-by: Marek Szyprowski
> 
> Works fine on Khadas VIM3, Odroid-C4 and Odroid-M1.
> 
> Best regards
> --
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland

Please fix the minor typo at the end of your commit message.

Regards, 
Hong Aun


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy
  2023-04-05  9:39 [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy Michael Sit Wei Hong
                   ` (2 preceding siblings ...)
  2023-04-05 10:39 ` Martin Blumenstingl
@ 2023-04-05 19:02 ` Guenter Roeck
  3 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2023-04-05 19:02 UTC (permalink / raw)
  To: Michael Sit Wei Hong
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Ong Boon Leong, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux, hkallweit1, andrew,
	Martin Blumenstingl, Shahab Vahedi, Marek Szyprowski,
	Looi Hong Aun, Voon Weifeng, Lai Peter Jun Ann,
	Zulkifli Muhammad Husaini, Tan Tee Min, hock.leong.kweh

On Wed, Apr 05, 2023 at 05:39:45PM +0800, Michael Sit Wei Hong wrote:
> Some DT devices already have phy device configured in the DT/ACPI.
> Current implementation scans for a phy unconditionally even though
> there is a phy listed in the DT/ACPI and already attached.
> 
> We should check the fwnode if there is any phy device listed in
> fwnode and decide whether to scan for a phy to attach to.y
> 
> Reported-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Fixes: fe2cfbc96803 ("net: stmmac: check if MAC needs to attach to a PHY")
> Signed-off-by: Michael Sit Wei Hong <michael.wei.hong.sit@intel.com>
> Tested-by: Shahab Vahedi <shahab@synopsys.com>
> Tested-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> Tested-by: Marek Szyprowski

Tested-by: Guenter Roeck <linux@roeck-us.net>

Guenter

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-05 19:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05  9:39 [PATCH net 1/1] net: stmmac: check fwnode for phy device before scanning for phy Michael Sit Wei Hong
2023-04-05 10:07 ` Shahab Vahedi
2023-04-05 10:10   ` Shahab Vahedi
2023-04-05 10:53   ` Marek Szyprowski
2023-04-05 13:03     ` Looi, Hong Aun
2023-04-05 10:18 ` Russell King (Oracle)
2023-04-05 10:39 ` Martin Blumenstingl
2023-04-05 19:02 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).