Add synopsys designware GMAC NCSI support
Subsystems (5)
Re: [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property
In reply to Minda ChenQuoted 3 lines · Minda Chen
Add snps,use-ncsi dts bindings property for Synopsys designware ethernet MAC with RMII interface and used as sideband interface network controller(NCSI).
Please use standard email subjects, so with the PATCH keyword in the title. git format-patch -vX helps here to create proper versioned patches. Another useful tool is b4. Skipping the PATCH keyword makes filtering of emails more difficult thus making the review process less convenient.
Quoted 11 lines
Signed-off-by Minda Chen <[email protected]>--- Documentation/devicetree/bindings/net/snps,dwmac.yaml | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/devicetree/bindings/net/snps,dwmac.yaml +0
-0
Documentation/devicetree/bindings/net/snps,dwmac.yaml properties: · line 551
Quoted 7 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +4
-0@@ -545,6 +545,13 @@ properties: Enables the TSO feature otherwise it will be managed by MAC HW capability register. + snps,use-ncsi: + $ref: /schemas/types.yaml#/definitions/flag + description: + Use the NC-SI stack instead of an MDIO PHY. Currently assumes
You described the desired Linux feature or behavior, not the actual hardware. The bindings are about the latter, so instead you need to rephrase the property and its description to match actual hardware capabilities/features/configuration etc.
Best regards,
Krzysztof
PATCH 2/6 net: stmmac: Checking whether priv->phylink if NULL in NCSI case
In reply to Minda ChenIn 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.
--- .../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
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +28 -27
@@ -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);
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 1/6 dt-bindings: net: dwmac: Add snps,use-ncsi property
In reply to Minda ChenAdd snps,use-ncsi dts bindings property for Synopsys designware ethernet MAC with RMII interface and used as sideband interface network controller(NCSI).
--- Documentation/devicetree/bindings/net/snps,dwmac.yaml | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/net/snps,dwmac.yaml +7 -0
@@ -545,6 +545,13 @@ properties: Enables the TSO feature otherwise it will be managed by MAC HW capability register. + snps,use-ncsi: + $ref: /schemas/types.yaml#/definitions/flag + description: + Use the NC-SI stack instead of an MDIO PHY. Currently assumes + rmii (100bT) but kept as a separate property in case NC-SI grows support + for a gigabit link. + mdio: $ref: mdio.yaml# unevaluatedProperties: false
Signature · 1 line
2.17.1
PATCH 6/6 net: stmmac: ethtool: Do NOT call phylink function in NCSI mode.
In reply to Minda Chenstmmac ethtool module do not call phylink function while GMAC NCSI mode. stmmac_ethtool_get_link_ksettings() return NCSI defaut speed and duplex setting, except that most cases return -EOPNOTSUPP error code.
--- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +31 -1
@@ -322,6 +322,12 @@ static int stmmac_ethtool_get_link_ksettings(struct net_device *dev, {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) { + cmd->base.speed =SPEED_100 ; + cmd->base.duplex =DUPLEX_FULL ; +return 0 ; + } +return phylink_ethtool_ksettings_get (priv->phylink, cmd); }
@@ -331,6 +337,9 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev, {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_ksettings_set (priv->phylink, cmd); }
@@ -384,6 +393,9 @@ static int stmmac_nway_reset(struct net_device *dev) {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_nway_reset (priv->phylink); }
@@ -424,6 +436,9 @@ stmmac_get_pauseparam(struct net_device *netdev, {struct stmmac_priv *priv =netdev_priv (netdev); +if (priv->plat->use_ncsi) +return ; +phylink_ethtool_get_pauseparam (priv->phylink, pause); }
@@ -433,6 +448,9 @@ stmmac_set_pauseparam(struct net_device *netdev, {struct stmmac_priv *priv =netdev_priv (netdev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_set_pauseparam (priv->phylink, pause); }
@@ -547,7 +565,7 @@ static void stmmac_get_ethtool_stats(struct net_device *dev, (*(u32 *)p); } } -if (priv->dma_cap.eee) { +if (priv->dma_cap.eee && !priv->plat->use_ncsi) {int val =phylink_get_eee_err (priv->phylink);if (val) priv->xstats.phy_eee_wakeup_error_n = val;
@@ -723,6 +741,9 @@ static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return ; +return phylink_ethtool_get_wol (priv->phylink, wol); }
@@ -730,6 +751,9 @@ static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_set_wol (priv->phylink, wol); }
@@ -738,6 +762,9 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev, {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_get_eee (priv->phylink, edata); }
@@ -746,6 +773,9 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, {struct stmmac_priv *priv =netdev_priv (dev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_set_eee (priv->phylink, edata); }
Signature · 1 line
2.17.1
Re: [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property
In reply to Minda ChenQuoted 1 line · Minda Chen
Add snps,use-ncsi dts bindings property for Synopsys designware
Is there anything SNPS specific in how NCSI is implemented? Should this be a generic option which any Ethernet interface can use?
Andrew
Re: [net-next v1 2/6] net: stmmac: Checking whether priv->phylink if NULL in NCSI case
In reply to Minda ChenQuoted 17 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h new file +17
-0+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)
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h line 36
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h new file +10
-0+{ +if (link) +phylink_start (link); +} + +static inline void stmmac_phylink_stop (struct phylink *link) +{ +if (link) +phylink_stop (link); +}
Please take a step back and think about the Linux big picture architecture.
What is stmmac specific here? If you were to add NCSI support to another driver which uses phylink, would it need to replicate all this?
When you consider how the MAC is configured, does it need to know it is connected to an NCSI? Can the MAC tell the difference between NSCI, fixed-link, a PHY or an SFP? Or does the MAC just need to know RGMII, the link is up, send frames?
Please look at adding generic support for NSCI in phylink, and see if the existing phylink mac ops covers everything needed for configuring the MAC.
Andrew
Re: [net-next v1 6/6] net: stmmac: ethtool: Do NOT call phylink function in NCSI mode.
In reply to Minda ChenQuoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3
-0@@ -424,6 +436,9 @@ stmmac_get_pauseparam(struct net_device *netdev, {struct stmmac_priv *priv =netdev_priv (netdev); +if (priv->plat->use_ncsi) +return ; +phylink_ethtool_get_pauseparam (priv->phylink, pause); }
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c stmmac_set_pauseparam(struct net_device *netdev, · line 455
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +3
-0@@ -433,6 +448,9 @@ stmmac_set_pauseparam(struct net_device *netdev, {struct stmmac_priv *priv =netdev_priv (netdev); +if (priv->plat->use_ncsi) +return -EOPNOTSUPP ; +return phylink_ethtool_set_pauseparam (priv->phylink, pause); }
Why is pause not supported with NCSI? There are two modes for Pause. It can be negotiated, or it can be forced. Negotiation cannot be used, there is not a link peer as such, but it should be possible to force the configuration.
I am however assuming that pause frames do get forwarded by the other end of the link. Does the NCSI standard say anything about that?
Andrew
cover Add synopsys designware GMAC NCSI support
This patch set is for adding jhb100 GMAC NCSI function. jhb100 is a Starfive new RISC-V SoC for datacenter BMC (BaseBoard Managent Controller). Similar with Aspeed 27x0.
jhb100 contains 2 synopsys RMII(RGMII can be use as RMII) interfaces GMAC, can be use as NCSI GMAC (network controller sideband interface), do not connect with mdio PHY but connect with host server OCP network device and share with network port.
The code which calling NCSI netdevice API is similar with driver/net/ethernet/faraday/ftgmac100.c
The NCSI example:
_________________ _______________
| | | | ___________
| CLK_50M |---------------->| |<--------->| |
| TX_EN |---------------->| |<--------->| |
| TXD0 |---------------->| OCP network|<--------->| RJ45 |
|BMC TXD1 |---------------->| device |<--------->| port |
|RMII CRS_DV |<----------------| |<--------->| |
|port RX_D0 |<----------------| |<--------->| |
| RX_D1 |<----------------| |<--------->|_________|
|_______________| |_____________|
| | | | |
| | | | |host server PCIe interface
The jhb100 minimal system upstream is in progress:
https://patchwork.kernel.org/project/linux-riscv/cover/[email protected]/
The patch base net-next (base commit list below)
Minda Chen (6):
dt-bindings: net: dwmac: Add snps,use-ncsi property
net: stmmac: Checking whether priv->phylink if NULL in NCSI case
net: stmmac: Add register NCSI device support
net: stmmac: Add NCSI VLAN setting
net: dwmac4: Add NCSI mac speed and duplex setting in NCSI case
net: stmmac: ethtool: Do NOT call phylink function in NCSI mode.
.../devicetree/bindings/net/snps,dwmac.yaml | 7 ++ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 15 ++- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 32 +++++- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 108 +++++++++++++----- .../ethernet/stmicro/stmmac/stmmac_phylink.h | 106 +++++++++++++++++ .../ethernet/stmicro/stmmac/stmmac_platform.c | 10 +- include/linux/stmmac.h | 1 + 8 files changed, 246 insertions(+), 34 deletions(-) create mode 100644 drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h
base-commit: 903db046d5579bef0ea699eae4b279dd6455fc9f
Signature · 1 line
2.17.1
PATCH 5/6 net: dwmac4: Add NCSI mac speed and duplex setting in NCSI case
Add dwmac4 mac speed config and duplex setting in NCSI case because NCSI lack of PHY, will not call stmmac_mac_link_up().
--- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +14 -1
@@ -46,7 +46,20 @@ static void dwmac4_core_init(struct mac_device_info *hw,u32 value; value =readl (ioaddr +GMAC_CONFIG ); -writel (value |GMAC_CORE_INIT , ioaddr +GMAC_CONFIG ); +if (priv->plat->use_ncsi) { +/* +* In NCSI case, because lack of PHY, will NOT +* set the mac speed config and mac duplex +* in stmmac_mac_link_up(). Now set these in +* core init function. +*/ + value |=GMAC_CORE_INIT ; + value &= ~priv->hw->link.speed_mask; + value |= priv->hw->link.duplex | priv->hw->link.speed100; +writel (value, ioaddr +GMAC_CONFIG ); + }else { +writel (value |GMAC_CORE_INIT , ioaddr +GMAC_CONFIG ); + }/* Configure LPI 1us counter to number of CSR clock ticks in 1us - 1 */ clk_rate =clk_get_rate (priv->plat->stmmac_clk);
Signature · 1 line
2.17.1
PATCH 3/6 net: stmmac: Add register NCSI device support
In reply to Minda ChenAdd stmmac register support. The register NCSI code is almost from faraday ftgmac100.c
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 44 +++++++++++++++++-- .../ethernet/stmicro/stmmac/stmmac_platform.c | 10 ++++- include/linux/stmmac.h | 1 + 4 files changed, 51 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
@@ -383,6 +383,7 @@ struct stmmac_priv {struct bpf_prog *xdp_prog;struct devlink *devlink; +struct ncsi_dev *nsdev; };enum stmmac_state {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +40 -4
86 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +9 -1
@@ -348,7 +348,7 @@ static int stmmac_mdio_setup(struct plat_stmmacenet_data *plat,* described assume this is the case since there must be something * connected to the MAC. */ - legacy_mdio = !of_phy_is_fixed_link (np) && !plat->phy_node; + legacy_mdio = !of_phy_is_fixed_link (np) && !plat->phy_node && !plat->use_ncsi;if (legacy_mdio)dev_info (dev,"Deprecated MDIO bus assumption used\n" );
@@ -451,6 +451,14 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)* they are not converted to phylink. */ plat->phy_node =of_parse_phandle (np,"phy-handle" ,0 ); +if (of_property_read_bool (np,"snps,use-ncsi" )) { +if (!IS_ENABLED (CONFIG_NET_NCSI )) { +dev_err (&pdev->dev,"NCSI stack not enabled\n" ); +return ERR_PTR (-EINVAL ); + } + plat->use_ncsi = true; + } +/* Get max speed of operation from device tree */ of_property_read_u32 (np,"max-speed" , &plat->max_speed);
include/linux/stmmac.h +1 -0
@@ -348,6 +348,7 @@ struct plat_stmmacenet_data {int mac_port_sel_speed;u8 vlan_fail_q;bool provide_bus_info; +bool use_ncsi;int int_snapshot_num;int msi_mac_vec;int msi_wol_vec;
Signature · 1 line
2.17.1
PATCH 4/6 net: stmmac: Add NCSI VLAN setting
In reply to Minda ChenAdd NCSI vlan setting while in NCSI cases,
The code process is like NCSI mode in faradayftgmac100.c.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +9 -0
@@ -6866,6 +6866,9 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vidbool is_double = false;int ret; +if (priv->plat->use_ncsi) +return ncsi_vlan_rx_add_vid (ndev, proto, vid); + ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret;
@@ -6908,6 +6911,9 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vibool is_double = false;int ret; +if (priv->plat->use_ncsi) +return ncsi_vlan_rx_kill_vid (ndev, proto, vid); + ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret;
@@ -7943,6 +7949,9 @@ static int __stmmac_dvr_probe(struct device *device, ndev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_XSK_ZEROCOPY ; +if (priv->plat->use_ncsi) + ndev->hw_features |=NETIF_F_HW_VLAN_CTAG_FILTER ; + ret =stmmac_tc_init (priv, priv);if (!ret) { ndev->hw_features |=NETIF_F_HW_TC ;
Signature · 1 line
2.17.1
[email protected]
AI reviewRe: [net-next v1 4/6] net: stmmac: Add NCSI VLAN setting
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Bypassing STMMAC VLAN filter programming while enabling NETIF_F_HW_VLAN_CTAG_FILTER causes the host MAC to drop all VLAN-tagged packets.
Pre-existing issues:
- [High] Missing RCU grace period in NCSI VLAN kill path causes a Use-After-Free when traversing the VLAN list.
- [High] NCSI request timers can fire after the NCSI device is freed during unregistration. --
commit f9348a76862879b362b9eac34abff037e5482a9e
Author: Minda Chen <[email protected]>
net: stmmac: Add NCSI VLAN setting
This commit adds NCSI VLAN setting support for STMMAC when the platform uses NCSI. It modifies the driver to delegate VLAN addition and removal to the NCSI subsystem and enables the hardware VLAN CTAG filter feature.
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-0@@ -6866,6 +6866,9 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vidbool is_double = false;int ret; +if (priv->plat->use_ncsi) +return ncsi_vlan_rx_add_vid (ndev, proto, vid); +
[ ... ]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi · line 6916
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-0@@ -6908,6 +6911,9 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vibool is_double = false;int ret; +if (priv->plat->use_ncsi) +return ncsi_vlan_rx_kill_vid (ndev, proto, vid); +
[Severity: High]
This isn't a bug introduced by this patch, but looking at the NCSI subsystem this delegates to, does ncsi_vlan_rx_kill_vid() have an RCU grace period issue?
net/ncsi/ncsi-manage.c:ncsi_vlan_rx_kill_vid() {
...
list_del_rcu(&vlan->list);
found = true;
kfree(vlan);
...
}Since concurrent NCSI workqueue tasks like set_one_vid() iterate over this list using list_for_each_entry_rcu() inside an rcu_read_lock(), could failing to wait for an RCU grace period before the kfree() lead to a use-after-free when dynamic VLAN reconfiguration occurs?
[Severity: High]
This is a pre-existing issue, but since we are relying on NCSI, does the NCSI core handle unregistration safely with respect to pending request timers?
net/ncsi/ncsi-manage.c:ncsi_unregister_dev() {
...
disable_work_sync(&ndp->work);
kfree(ndp);
}If an NCSI command is pending during module removal or interface teardown, the timer isn't canceled. Could ndp->requests[i].timer fire after ndp is freed, causing a use-after-free in the ncsi_request_timeout() callback?
[ ... ]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_dvr_probe(struct device *device, · line 7954
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-0@@ -7943,6 +7949,9 @@ static int __stmmac_dvr_probe(struct device *device, ndev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_XSK_ZEROCOPY ; +if (priv->plat->use_ncsi) + ndev->hw_features |=NETIF_F_HW_VLAN_CTAG_FILTER ; +
[Severity: High]
Does enabling NETIF_F_HW_VLAN_CTAG_FILTER here cause the networking stack to turn on the MAC's hardware VLAN filtering (VTFE)?
Since stmmac_vlan_rx_add_vid() and stmmac_vlan_rx_kill_vid() were modified to return early and bypass the STMMAC hardware filter programming, the filter list will remain empty. Could this result in the MAC hardware aggressively dropping all incoming VLAN-tagged packets, thereby breaking VLAN reception for both the host OS and the NCSI subsystem?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [net-next v1 3/6] net: stmmac: Add register NCSI device support
In reply to Minda ChenThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Unregistering the NCSI device before the netdevice in `stmmac_dvr_remove` causes a use-after-free.…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Unregistering the NCSI device before the netdevice in stmmac_dvr_remove causes a use-after-free.
- [Medium] IRQs requested in __stmmac_open are leaked if ncsi_start_dev() fails.
- [Medium] Early error return in stmmac_probe_config_dt leaks the OF node reference for phy-handle.
- [Low] Unbalanced netif_carrier_on() when ncsi_start_dev() fails.
--
commit cde45e5227e87c535d6fe7fb8ee4f8048e15a5e6
Author: Minda Chen <[email protected]>
net: stmmac: Add register NCSI device support
Add stmmac register support. The register NCSI code is almost from faraday ftgmac100.c
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0
-0@@ -4167,6 +4168,16 @@ static int __stmmac_open(struct net_device *dev,if (ret)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int __stmmac_open(struct net_device *dev, · line 4178
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +8
-0goto irq_error; +if (priv->plat->use_ncsi) { +/* If using NC-SI, set our carrier on and start the stack */ +netif_carrier_on (priv->dev); + +/* Start the NCSI device */ + ret =ncsi_start_dev (priv->nsdev); +if (ret) + goto irq_error;
[Severity: Medium]
Are the IRQs leaked if ncsi_start_dev() fails?
The code successfully allocated IRQs right before this via stmmac_request_irq(). If ncsi_start_dev() fails, it jumps to the irq_error label:
irq_error:
stmmac_phylink_stop(priv->phylink);
But stmmac_free_irq() is not called in this error path. Could this leave the IRQs permanently allocated, causing future attempts to bring the interface UP to fail with -EBUSY?
[Severity: Low]
Additionally, if ncsi_start_dev() fails, is there a missing call to netif_carrier_off() in the error path to revert the carrier state?
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2
-0+ } +stmmac_enable_all_queues (priv);netif_tx_start_all_queues (priv->dev);
[ ... ]
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c void stmmac_dvr_remove(struct device *dev) · line 8180
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2
-0@@ -8141,6 +8175,8 @@ void stmmac_dvr_remove(struct device *dev)pm_runtime_get_sync (dev); +if (priv->nsdev) +ncsi_unregister_dev (priv->nsdev);unregister_netdev (ndev);
[Severity: High]
Does unregistering the NCSI device before the netdevice cause a use-after-free?
If the network interface is UP when the driver is removed, unregister_netdev() synchronously halts the interface by invoking the driver's ndo_stop callback (__stmmac_release()).
Inside __stmmac_release(), the code calls ncsi_stop_dev(priv->nsdev), but priv->nsdev was already freed by ncsi_unregister_dev().
Should unregister_netdev() be called before ncsi_unregister_dev()?
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac) · line 458
Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +5
-0@@ -451,6 +451,14 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)* they are not converted to phylink. */ plat->phy_node =of_parse_phandle (np,"phy-handle" ,0 ); +if (of_property_read_bool (np,"snps,use-ncsi" )) { +if (!IS_ENABLED (CONFIG_NET_NCSI )) { +dev_err (&pdev->dev,"NCSI stack not enabled\n" ); +return ERR_PTR (-EINVAL ); + }
[Severity: Medium]
Could this early return leak the OF node reference acquired just above?
plat->phy_node is set via of_parse_phandle() right before this check. Returning ERR_PTR(-EINVAL) directly bypasses the error_put_phy cleanup label, which drops the reference via of_node_put().
Would it be better to use goto error_put_phy instead of returning directly?
Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +2
-0+ plat->use_ncsi = true; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property
In reply to Minda ChenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Introduces a vendor-prefixed property (`snps,use-ncsi`) for a generic, standard hardware feature…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Introduces a vendor-prefixed property (snps,use-ncsi) for a generic, standard hardware feature (NC-SI) that is already widely used without a prefix. --
commit 9f79574dbd128266dea8e1a64bd86e9a7c9ea506
Author: Minda Chen <[email protected]>
dt-bindings: net: dwmac: Add snps,use-ncsi property
Add snps,use-ncsi dts bindings property for Synopsys designware ethernet MAC with RMII interface and used as sideband interface network controller(NCSI).
Documentation/devicetree/bindings/net/snps,dwmac.yaml properties: · line 548
Quoted 9 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +1
-0@@ -545,6 +545,13 @@ properties: Enables the TSO feature otherwise it will be managed by MAC HW capability register. + snps,use-ncsi:
[Severity: Medium]
Is a vendor prefix appropriate for this hardware feature?
NC-SI is a standard protocol supported by the kernel's core net/ncsi/ subsystem. It appears the boolean property use-ncsi is already a de-facto standard used across the tree for this concept (such as in the ftgmac100 driver and ASPEED device trees).
Should this be formally documented as a generic property in Documentation/devicetree/bindings/net/ethernet-controller.yaml and used here without the vendor prefix to prevent fragmenting the ecosystem?
Quoted 5 lines
Documentation/devicetree/bindings/net/snps,dwmac.yaml +5
-0+ $ref: /schemas/types.yaml#/definitions/flag + description: + Use the NC-SI stack instead of an MDIO PHY. Currently assumes + rmii (100bT) but kept as a separate property in case NC-SI grows support + for a gigabit link.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
回复: [net-next v1 1/6] dt-bindings: net: dwmac: Add snps,use-ncsi property
In reply to Andrew LunnQuoted 10 lines · Minda Chen
Quoted 1 line
Add snps,use-ncsi dts bindings property for Synopsys designware
Is there anything SNPS specific in how NCSI is implemented? Should this be a generic option which any Ethernet interface can use?
Andrew
I will remove this. NCSI actually not generic function. Now just faraday ftgmac100 support this.
Re: [net-next v1 2/6] net: stmmac: Checking whether priv->phylink if NULL in NCSI case
In reply to Andrew LunnQuoted 38 lines
Quoted 17 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h new file +14
-0+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 ; +}drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h line 36
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_phylink.h new file +10
-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); +}Please take a step back and think about the Linux big picture architecture.
What is stmmac specific here? If you were to add NCSI support to another driver which uses phylink, would it need to replicate all this?
When you consider how the MAC is configured, does it need to know it is connected to an NCSI? Can the MAC tell the difference between NSCI, fixed-link, a PHY or an SFP? Or does the MAC just need to know RGMII, the link is up, send frames?
Quoted 4 lines
Please look at adding generic support for NSCI in phylink, and see if the existing phylink mac ops covers everything needed for configuring the MAC.
Andrew
Thanks. I will try to use fix-PHY link.