Devicetree
 help / color / mirror / Atom feed
From: Minda Chen <minda.chen@starfivetech.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jose Abreu <joabreu@synopsys.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Giuseppe Cavallaro <peppe.cavallaro@st.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor@kernel.org>,
	netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	devicetree@vger.kernel.org,
	Minda Chen <minda.chen@starfivetech.com>
Subject: [net-next v1 2/6] net: stmmac: Checking whether priv->phylink if NULL in NCSI case
Date: Wed, 10 Jun 2026 15:24:16 +0800	[thread overview]
Message-ID: <20260610072420.64699-3-minda.chen@starfivetech.com> (raw)
In-Reply-To: <20260610072420.64699-1-minda.chen@starfivetech.com>

In NCSI case, RMII do not connect mdio PHY, so the phylink is NULL,
and need to checking if phylink is NULL, So add stmmac phylink
wrapper function to checking whether phylink is NULL.

Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  55 ++++-----
 .../ethernet/stmicro/stmmac/stmmac_phylink.h  | 106 ++++++++++++++++++
 2 files changed, 134 insertions(+), 27 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 35da51c26248..010802389772 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -38,7 +38,6 @@
 #include <linux/seq_file.h>
 #endif /* CONFIG_DEBUG_FS */
 #include <linux/net_tstamp.h>
-#include <linux/phylink.h>
 #include <linux/udp.h>
 #include <linux/bpf_trace.h>
 #include <net/devlink.h>
@@ -49,6 +48,7 @@
 #include "stmmac_fpe.h"
 #include "stmmac.h"
 #include "stmmac_pcs.h"
+#include "stmmac_phylink.h"
 #include "stmmac_xdp.h"
 #include <linux/reset.h>
 #include <linux/of_mdio.h>
@@ -1323,7 +1323,7 @@ static int stmmac_init_phy(struct net_device *dev)
 	u32 dev_flags = 0;
 	int ret;
 
-	if (!phylink_expects_phy(priv->phylink))
+	if (!stmmac_phylink_expects_phy(priv->phylink))
 		return 0;
 
 	if (priv->hw->xpcs &&
@@ -3655,7 +3655,7 @@ static int stmmac_hw_setup(struct net_device *dev)
 
 	/* Make sure RX clock is enabled */
 	if (priv->hw->phylink_pcs)
-		phylink_pcs_pre_init(priv->phylink, priv->hw->phylink_pcs);
+		stmmac_phylink_pcs_pre_init(priv->phylink, priv->hw->phylink_pcs);
 
 	/* Note that clk_rx_i must be running for reset to complete. This
 	 * clock may also be required when setting the MAC address.
@@ -3663,12 +3663,12 @@ static int stmmac_hw_setup(struct net_device *dev)
 	 * Block the receive clock stop for LPI mode at the PHY in case
 	 * the link is established with EEE mode active.
 	 */
-	phylink_rx_clk_stop_block(priv->phylink);
+	stmmac_phylink_rx_clk_stop_block(priv->phylink);
 
 	/* DMA initialization and SW reset */
 	ret = stmmac_init_dma_engine(priv);
 	if (ret < 0) {
-		phylink_rx_clk_stop_unblock(priv->phylink);
+		stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 		netdev_err(priv->dev, "%s: DMA engine initialization failed\n",
 			   __func__);
 		return ret;
@@ -3676,7 +3676,7 @@ static int stmmac_hw_setup(struct net_device *dev)
 
 	/* Copy the MAC addr into the HW  */
 	stmmac_set_umac_addr(priv, priv->hw, dev->dev_addr, 0);
-	phylink_rx_clk_stop_unblock(priv->phylink);
+	stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 
 	/* Initialize the MAC Core */
 	stmmac_core_init(priv, priv->hw, dev);
@@ -3752,9 +3752,9 @@ static int stmmac_hw_setup(struct net_device *dev)
 	/* Start the ball rolling... */
 	stmmac_start_all_dma(priv);
 
-	phylink_rx_clk_stop_block(priv->phylink);
+	stmmac_phylink_rx_clk_stop_block(priv->phylink);
 	stmmac_set_hw_vlan_mode(priv, priv->hw);
-	phylink_rx_clk_stop_unblock(priv->phylink);
+	stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 
 	return 0;
 }
@@ -4159,7 +4159,7 @@ static int __stmmac_open(struct net_device *dev,
 
 	stmmac_init_coalesce(priv);
 
-	phylink_start(priv->phylink);
+	stmmac_phylink_start(priv->phylink);
 
 	stmmac_vlan_restore(priv);
 
@@ -4174,7 +4174,7 @@ static int __stmmac_open(struct net_device *dev,
 	return 0;
 
 irq_error:
-	phylink_stop(priv->phylink);
+	stmmac_phylink_stop(priv->phylink);
 
 	for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
 		hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
@@ -4219,14 +4219,14 @@ static int stmmac_open(struct net_device *dev)
 	kfree(dma_conf);
 
 	/* We may have called phylink_speed_down before */
-	phylink_speed_up(priv->phylink);
+	stmmac_phylink_speed_up(priv->phylink);
 
 	return ret;
 
 err_serdes:
 	stmmac_legacy_serdes_power_down(priv);
 err_disconnect_phy:
-	phylink_disconnect_phy(priv->phylink);
+	stmmac_phylink_disconnect_phy(priv->phylink);
 err_runtime_pm:
 	pm_runtime_put(priv->device);
 err_dma_resources:
@@ -4241,7 +4241,7 @@ static void __stmmac_release(struct net_device *dev)
 	u8 chan;
 
 	/* Stop and disconnect the PHY */
-	phylink_stop(priv->phylink);
+	stmmac_phylink_stop(priv->phylink);
 
 	stmmac_disable_all_queues(priv);
 
@@ -4280,12 +4280,12 @@ static int stmmac_release(struct net_device *dev)
 	 * to its slowest speed to save power.
 	 */
 	if (device_may_wakeup(priv->device))
-		phylink_speed_down(priv->phylink, false);
+		stmmac_phylink_speed_down(priv->phylink, false);
 
 	__stmmac_release(dev);
 
 	stmmac_legacy_serdes_power_down(priv);
-	phylink_disconnect_phy(priv->phylink);
+	stmmac_phylink_disconnect_phy(priv->phylink);
 	pm_runtime_put(priv->device);
 
 	return 0;
@@ -6209,9 +6209,9 @@ static int stmmac_set_features(struct net_device *netdev,
 	else
 		priv->hw->hw_vlan_en = false;
 
-	phylink_rx_clk_stop_block(priv->phylink);
+	stmmac_phylink_rx_clk_stop_block(priv->phylink);
 	stmmac_set_hw_vlan_mode(priv, priv->hw);
-	phylink_rx_clk_stop_unblock(priv->phylink);
+	stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 
 	return 0;
 }
@@ -6386,7 +6386,8 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 	case SIOCGMIIPHY:
 	case SIOCGMIIREG:
 	case SIOCSMIIREG:
-		ret = phylink_mii_ioctl(priv->phylink, rq, cmd);
+		if (priv->phylink)
+			ret = phylink_mii_ioctl(priv->phylink, rq, cmd);
 		break;
 	default:
 		break;
@@ -6480,9 +6481,9 @@ static int stmmac_set_mac_address(struct net_device *ndev, void *addr)
 	if (ret)
 		goto set_mac_error;
 
-	phylink_rx_clk_stop_block(priv->phylink);
+	stmmac_phylink_rx_clk_stop_block(priv->phylink);
 	stmmac_set_umac_addr(priv, priv->hw, ndev->dev_addr, 0);
-	phylink_rx_clk_stop_unblock(priv->phylink);
+	stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 
 set_mac_error:
 	pm_runtime_put(priv->device);
@@ -8081,7 +8082,7 @@ static int __stmmac_dvr_probe(struct device *device,
 error_netdev_register:
 	stmmac_unregister_devlink(priv);
 error_devlink_setup:
-	phylink_destroy(priv->phylink);
+	stmmac_phylink_destroy(priv->phylink);
 error_phy_setup:
 	stmmac_pcs_clean(ndev);
 error_pcs_setup:
@@ -8147,7 +8148,7 @@ void stmmac_dvr_remove(struct device *dev)
 #endif
 	stmmac_unregister_devlink(priv);
 
-	phylink_destroy(priv->phylink);
+	stmmac_phylink_destroy(priv->phylink);
 	if (priv->plat->stmmac_rst)
 		reset_control_assert(priv->plat->stmmac_rst);
 	reset_control_assert(priv->plat->stmmac_ahb_rst);
@@ -8214,7 +8215,7 @@ int stmmac_suspend(struct device *dev)
 	mutex_unlock(&priv->lock);
 
 	rtnl_lock();
-	phylink_suspend(priv->phylink, !!priv->wolopts);
+	stmmac_phylink_suspend(priv->phylink, !!priv->wolopts);
 	rtnl_unlock();
 
 	if (stmmac_fpe_supported(priv))
@@ -8314,7 +8315,7 @@ int stmmac_resume(struct device *dev)
 	/* Prepare the PHY to resume, ensuring that its clocks which are
 	 * necessary for the MAC DMA reset to complete are running
 	 */
-	phylink_prepare_resume(priv->phylink);
+	stmmac_phylink_prepare_resume(priv->phylink);
 
 	mutex_lock(&priv->lock);
 
@@ -8335,9 +8336,9 @@ int stmmac_resume(struct device *dev)
 	stmmac_init_timestamping(priv);
 
 	stmmac_init_coalesce(priv);
-	phylink_rx_clk_stop_block(priv->phylink);
+	stmmac_phylink_rx_clk_stop_block(priv->phylink);
 	stmmac_set_rx_mode(ndev);
-	phylink_rx_clk_stop_unblock(priv->phylink);
+	stmmac_phylink_rx_clk_stop_unblock(priv->phylink);
 
 	stmmac_vlan_restore(priv);
 
@@ -8350,7 +8351,7 @@ int stmmac_resume(struct device *dev)
 	 * initialised because it may bring the link up immediately in a
 	 * workqueue thread, which will race with initialisation.
 	 */
-	phylink_resume(priv->phylink);
+	stmmac_phylink_resume(priv->phylink);
 	rtnl_unlock();
 
 	netif_device_attach(ndev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h
new file mode 100644
index 000000000000..046a3e91fb2a
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2026, StarFive Corporation. */
+
+#ifndef _STMMAC_PHYLINK_H_
+#define _STMMAC_PHYLINK_H_
+
+#include <linux/phylink.h>
+
+#ifdef CONFIG_NET_NCSI
+static inline bool stmmac_phylink_expects_phy(struct phylink *link)
+{
+	if (link)
+		return phylink_expects_phy(link);
+
+	return false;
+}
+
+static inline int stmmac_phylink_pcs_pre_init(struct phylink *link, struct phylink_pcs *pcs)
+{
+	if (link)
+		return phylink_pcs_pre_init(link, pcs);
+
+	return 0;
+}
+
+static inline void stmmac_phylink_start(struct phylink *link)
+{
+	if (link)
+		phylink_start(link);
+}
+
+static inline void stmmac_phylink_stop(struct phylink *link)
+{
+	if (link)
+		phylink_stop(link);
+}
+
+static inline void stmmac_phylink_speed_up(struct phylink *link)
+{
+	if (link)
+		phylink_speed_up(link);
+}
+
+static inline void stmmac_phylink_speed_down(struct phylink *link, bool sync)
+{
+	if (link)
+		phylink_speed_down(link, sync);
+}
+
+static inline void stmmac_phylink_disconnect_phy(struct phylink *link)
+{
+	if (link)
+		phylink_disconnect_phy(link);
+}
+
+static inline void stmmac_phylink_destroy(struct phylink *link)
+{
+	if (link)
+		phylink_destroy(link);
+}
+
+static inline void stmmac_phylink_suspend(struct phylink *link, bool mac_wol)
+{
+	if (link)
+		phylink_suspend(link, mac_wol);
+}
+
+static inline void stmmac_phylink_prepare_resume(struct phylink *link)
+{
+	if (link)
+		phylink_prepare_resume(link);
+}
+
+static inline void stmmac_phylink_resume(struct phylink *link)
+{
+	if (link)
+		phylink_resume(link);
+}
+
+static inline void stmmac_phylink_rx_clk_stop_block(struct phylink *link)
+{
+	if (link)
+		phylink_rx_clk_stop_block(link);
+}
+
+static inline void stmmac_phylink_rx_clk_stop_unblock(struct phylink *link)
+{
+	if (link)
+		phylink_rx_clk_stop_unblock(link);
+}
+#else
+#define stmmac_phylink_expects_phy		phylink_expects_phy
+#define stmmac_phylink_pcs_pre_init		phylink_pcs_pre_init
+#define stmmac_phylink_start			phylink_start
+#define stmmac_phylink_stop			phylink_stop
+#define stmmac_phylink_speed_up			phylink_speed_up
+#define stmmac_phylink_speed_down		phylink_speed_down
+#define stmmac_phylink_disconnect_phy		phylink_disconnect_phy
+#define stmmac_phylink_destroy			phylink_destroy
+#define stmmac_phylink_suspend			phylink_suspend
+#define stmmac_phylink_prepare_resume		phylink_prepare_resume
+#define stmmac_phylink_resume			phylink_resume
+#define stmmac_phylink_rx_clk_stop_block	phylink_rx_clk_stop_block
+#define stmmac_phylink_rx_clk_stop_unblock	phylink_rx_clk_stop_unblock
+#endif /* NET_NCSI */
+#endif /* _STMMAC_PHYLINK_H_ */
-- 
2.17.1


  parent reply	other threads:[~2026-06-10  7:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10  7:24 [net-next v1 0/6] Add synopsys designware GMAC NCSI support Minda Chen
2026-06-10  7:24 ` [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property Minda Chen
2026-06-10  7:50   ` Krzysztof Kozlowski
2026-06-10  8:17   ` Andrew Lunn
2026-06-10  7:24 ` Minda Chen [this message]
2026-06-10  8:26   ` [net-next v1 2/6] net: stmmac: Checking whether priv->phylink if NULL in NCSI case Andrew Lunn
2026-06-10  7:24 ` [net-next v1 3/6] net: stmmac: Add register NCSI device support Minda Chen
2026-06-10  7:24 ` [net-next v1 4/6] net: stmmac: Add NCSI VLAN setting Minda Chen
2026-06-10  7:24 ` [net-next v1 5/6] net: dwmac4: Add NCSI mac speed and duplex setting in NCSI case Minda Chen
2026-06-10  7:24 ` [net-next v1 6/6] net: stmmac: ethtool: Do NOT call phylink function in NCSI mode Minda Chen
2026-06-10  8:31   ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260610072420.64699-3-minda.chen@starfivetech.com \
    --to=minda.chen@starfivetech.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=joabreu@synopsys.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peppe.cavallaro@st.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox